diff --git a/.gitmodules b/.gitmodules index b58552b..20dc557 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,7 +13,7 @@ url = https://github.com/Timerix22/imgui.git branch = docking_cbuild [submodule "imgui-node-editor"] - path = dependencies/imgui-node-editor + path = dependencies/imgui_node_editor url = https://github.com/Timerix22/imgui-node-editor.git branch = develop_cbuild [submodule "imnodes"] diff --git a/Makefile b/Makefile index 9da40d9..97e64fa 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,31 @@ build_exec: rebuild_all # profile build_exec_dbg: @cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log +###################################### +###### Rebuild dependencies ####### +###################################### + +# recompile kerep.a in the next build task +rebuild_kerep: + @cbuild/rebuild_dep.sh libkerep.a 2>&1 | tee make_raw.log + +# recompile imgui.a in the next build task +rebuild_imgui: + @cbuild/rebuild_dep.sh libimgui.a 2>&1 | tee make_raw.log + +rebuild_imgui_node_editor: + @cbuild/rebuild_dep.sh libimgui-node-editor.a 2>&1 | tee make_raw.log + +rebuild_imnodes: + @cbuild/rebuild_dep.sh libimnodes.a 2>&1 | tee make_raw.log + +# writes ttf fonts fron ./fonts/ to C compressed arrays in C source files +# builds static library from font arrays definitions +embed_fonts: + @cbuild/call_task.sh embed_fonts + +rebuild_all: rebuild_kerep rebuild_imgui rebuild_imgui_node_editor rebuild_imnodes embed_fonts + ###################################### ###### Launch tasks ####### ###################################### @@ -33,10 +58,18 @@ profile: @cbuild/call_task.sh profile 2>&1 | tee make_raw.log # compiles program with -pg and runs it with gprof -# uses gprof2dot python script to generate function call tree +# uses gprof2dot python script to generate function call tree (pip install gprof2dot) +# requires graphviz (https://www.graphviz.org/download/source/) gprof: @cbuild/call_task.sh gprof 2>&1 | tee make_raw.log - + +# compiles program and runs it with callgrind (part of valgrind) +# uses gprof2dot python script to generate function call tree (pip install gprof2dot) +# requires graphviz (https://www.graphviz.org/download/source/) +# P.S. detailed results can be viewed in KCacheGrind +callgrind: + @cbuild/call_task.sh callgrind 2>&1 | tee make_raw.log + # compiles executable with sanitizers and executes it to find errors and warnings sanitize: @cbuild/call_task.sh sanitize 2>&1 | tee make_raw.log @@ -59,23 +92,3 @@ fix_log: | sed 's/ H //g' \ | sed 's/\[3gH //g' \ > make_fixed.log - -# recompile kerep.a in the next build task -rebuild_kerep: - @tasks/rebuild_lib.sh kerep - -# recompile imgui.a in the next build task -rebuild_imgui: - @tasks/rebuild_lib.sh imgui - -rebuild_imgui-node-editor: - @tasks/rebuild_lib.sh imgui-node-editor -rebuild_imnodes: - @tasks/rebuild_lib.sh imnodes - -# writes ttf fonts fron ./fonts/ to C compressed arrays in C source files -# builds static library from font arrays definitions -embed_fonts: - @cbuild/call_task.sh embed_fonts - -rebuild_all: rebuild_kerep rebuild_imgui rebuild_imgui-node-editor rebuild_imnodes embed_fonts diff --git a/cbuild b/cbuild index 60fa8c1..574ce6e 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 60fa8c11c2673a10f8afbe37bcea13c9be3317b8 +Subproject commit 574ce6eab3b65e05888adad95a0211f532dd1125 diff --git a/default.config b/default.config index 6d829ca..b85ecb1 100644 --- a/default.config +++ b/default.config @@ -1,6 +1,6 @@ #!/bin/bash -CBUILD_VERSION=6 -CONFIG_VERSION=4 +CBUILD_VERSION=7 +CONFIG_VERSION=6 PROJECT="GraphC" CMP_C="gcc" @@ -14,6 +14,19 @@ SRC_CPP="$(find src -name '*.cpp')" #TESTS_C="$( find tests -name '*.c')" #TESTS_CPP="$(find tests -name '*.cpp')" +# dir with dependeicy dirs +DEPS_BASEDIR="dependencies" +# EXAMPLE: "dependency_dir='build_task out_dir lib_file' +# other_depndency_dir=..." +# Dependencies must be declared on separate lines +# Values can be override by resetting one of dependencies: +# DEPS="$DEPS +# dependency_dir='...'" +DEPS="kerep='build_static_lib bin libkerep.a' + imgui='build_static_lib bin libimgui.a' + imnodes='build_static_lib bin libimnodes.a' + imgui_node_editor='build_static_lib bin libimgui-node-editor.a'" + # OBJDIR structure: # ├── objects - dir where compiled *.o files are stored. cleans every call of build task # ├── profile - dir where gcc *.gcda profiling info files stored @@ -26,13 +39,13 @@ OUTDIR="bin" case "$OS" in WINDOWS) EXEC_FILE="$PROJECT.exe" - INCLUDE="-I./imgui -I/usr/include/SDL2" - LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lopengl32" + INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include" + LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lopengl32 -lpthread -lws2_32" ;; LINUX) EXEC_FILE="$PROJECT" - INCLUDE="-I./imgui -I/usr/include/SDL2" - LINKER_LIBS="-lSDL2 -lGL" + INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include" + LINKER_LIBS="-L./$OBJDIR/libs/ -lSDL2 -lGL" ;; *) error "operating system $OS has no configuration variants" @@ -126,11 +139,28 @@ case "$TASK" in POST_TASK_SCRIPT=cbuild/default_tasks/exec.sh DEPS_BUILD_TASK=build_static_lib ;; + # compiles program and runs it with callgrind (part of valgrind) + # uses gprof2dot python script to generate function call tree (pip install gprof2dot) + # requires graphviz (https://www.graphviz.org/download/source/) + # P.S. detailed results can be viewed in KCacheGrind + callgrind) + OUTDIR="$OUTDIR/callgrind" + # -pg adds code to executable, that generates file containing function call info (gmon.out) + C_ARGS="-O2 -flto=auto -fuse-linker-plugin" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS" + PRE_TASK_SCRIPT=tasks/pre_build.sh + TASK_SCRIPT=cbuild/default_tasks/build_exec.sh + POST_TASK_SCRIPT=cbuild/default_tasks/callgrind.sh + ;; # deletes generated files clean) TASK_SCRIPT=cbuild/default_tasks/clean.sh POST_TASK_SCRIPT=tasks/clean_additions.sh ;; + # nothing to do + no_task) + ;; # unknown task *) error "task <$TASK> not found" diff --git a/dependencies/imgui b/dependencies/imgui index 109735a..00263d9 160000 --- a/dependencies/imgui +++ b/dependencies/imgui @@ -1 +1 @@ -Subproject commit 109735a0d10c55d95c569bae2aa4c2adbfcf9056 +Subproject commit 00263d9c22ab255d1886493c7f058d9e22128dd3 diff --git a/dependencies/imgui-node-editor b/dependencies/imgui-node-editor deleted file mode 160000 index 50ba284..0000000 --- a/dependencies/imgui-node-editor +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 50ba2846746af233922da40694380fd090b304ab diff --git a/dependencies/imgui_node_editor b/dependencies/imgui_node_editor new file mode 160000 index 0000000..50f3936 --- /dev/null +++ b/dependencies/imgui_node_editor @@ -0,0 +1 @@ +Subproject commit 50f39362c22fb7d21312adb07cea66d56da3166a diff --git a/dependencies/imnodes b/dependencies/imnodes index 1bff83f..83af906 160000 --- a/dependencies/imnodes +++ b/dependencies/imnodes @@ -1 +1 @@ -Subproject commit 1bff83fbd0fe749b28df5af6844ec0e036320305 +Subproject commit 83af9066dbf8dceef44009ef21ac1d6d042db2a3 diff --git a/dependencies/kerep b/dependencies/kerep index 53cf987..dd5788f 160000 --- a/dependencies/kerep +++ b/dependencies/kerep @@ -1 +1 @@ -Subproject commit 53cf9875e6785a30b2313cf294acb89061a92713 +Subproject commit dd5788f72a909b602592da7861ba717d529be9f3 diff --git a/src/gui/gui.h b/src/gui/gui.h index c4a0f60..7e0e8b6 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "../../kerep/src/base/base.h" +#include "../../dependencies/kerep/src/base/base.h" Maybe main_window_open(const char* window_title); Maybe main_window_loop_start(); diff --git a/src/gui/gui_internal.hpp b/src/gui/gui_internal.hpp index 01078b3..b45300f 100644 --- a/src/gui/gui_internal.hpp +++ b/src/gui/gui_internal.hpp @@ -1,12 +1,12 @@ #pragma once #include "gui.h" -#include "SDL2/SDL.h" -#include "SDL2/SDL_opengl.h" -#include "../../imgui/imgui.h" -#include "../../imgui/backends/imgui_impl_sdl2.h" -#include "../../imgui/backends/imgui_impl_opengl3.h" -#include "../../kerep/src/Filesystem/filesystem.h" +#include "../../dependencies/SDL2/include/SDL.h" +#include "../../dependencies/SDL2/include/SDL_opengl.h" +#include "../../dependencies/imgui/imgui.h" +#include "../../dependencies/imgui/backends/imgui_impl_sdl2.h" +#include "../../dependencies/imgui/backends/imgui_impl_opengl3.h" +#include "../../dependencies/kerep/src/Filesystem/filesystem.h" ////////////////////////////////////// // Fonts // diff --git a/src/gui/node_editor.cpp_ b/src/gui/node_editor.cpp_ index 9885f3c..82a3288 100644 --- a/src/gui/node_editor.cpp_ +++ b/src/gui/node_editor.cpp_ @@ -1,5 +1,5 @@ #include "gui_internal.hpp" -#include "../../imgui-node-editor/imgui_node_editor.h" +#include "../../dependencies/imgui_node_editor/imgui_node_editor.h" namespace NE = ax::NodeEditor; NE::EditorContext* editor_context=nullptr; diff --git a/src/gui/node_editor2.cpp b/src/gui/node_editor2.cpp index 2ffc191..57e4ff8 100644 --- a/src/gui/node_editor2.cpp +++ b/src/gui/node_editor2.cpp @@ -1,5 +1,5 @@ #include "gui_internal.hpp" -#include "../../imnodes/imnodes.h" +#include "../../dependencies/imnodes/imnodes.h" #include #include diff --git a/src/main.c b/src/main.c index 72e481e..67f4445 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -#include "../kerep/src/base/base.h" +#include "../dependencies/kerep/src/base/base.h" #include "gui/gui.h" void kt_initGraphCTypes(){ @@ -9,7 +9,7 @@ int main(const int argc, const char* const* argv){ if(setlocale(LC_CTYPE, "C.UTF-8")!=0) kprintf("\e[93msetlocale failed!\n"); - kt_beginInit(); + kt_beginInit(true); kt_initKerepTypes(); kt_initGraphCTypes(); kt_endInit(); @@ -19,9 +19,9 @@ int main(const int argc, const char* const* argv){ kprintf(" %s", argv[i]); kprintf("\n"); - tryLast(main_window_open("GraphC"),_1); - tryLast(main_window_loop_start(),_2); - tryLast(main_window_close(),_3); + tryLast(main_window_open("GraphC"),_1, ;); + tryLast(main_window_loop_start(),_2, ;); + tryLast(main_window_close(),_3, ;); kt_free(); return 0; diff --git a/tasks/clean_additions.sh b/tasks/clean_additions.sh index 4c59ad6..c20e009 100644 --- a/tasks/clean_additions.sh +++ b/tasks/clean_additions.sh @@ -1,6 +1,4 @@ #!/usr/bin/bash -for tmpfile in $(ls -a | grep -e '\.rebuild.*\.tmp'); do - try_delete_dir_or_file "$tmpfile" -done + try_delete_dir_or_file fonts/generated try_delete_dir_or_file libs/fonts_embedded.a diff --git a/tasks/embed_fonts.sh b/tasks/embed_fonts.sh index 240d9cd..b526fcc 100644 --- a/tasks/embed_fonts.sh +++ b/tasks/embed_fonts.sh @@ -1,5 +1,4 @@ #!/bin/bash - cd fonts SRC_C="" HEADER="generated/fonts_embedded.h" @@ -30,17 +29,12 @@ mkdir -p src/generated/ cp -v fonts/$HEADER src/$HEADER myprint "${GREEN}font arrays external definitions have been written to ${CYAN}src/$HEADER" +# delete old objects clean_dir "$OBJDIR/objects" -myprint "${BLUE}hiding libs" -mv "$OBJDIR/libs" "$OBJDIR/libs_" -mkdir -p "$OBJDIR/libs" # compiling compile_c "$C_ARGS" "$SRC_C" pack_static_lib "$STATIC_LIB_FILE" -rm -rf $OUTDIR/fonts_embedded.a -myprint "${BLUE}restoring libs" -rm -rf "$OBJDIR/libs" -mv "$OBJDIR/libs_" "$OBJDIR/libs" - -cp "$OBJDIR/out/fonts_embedded.a" libs/ -myprint "$OBJDIR/out/fonts_embedded.a -> libs/" +# moving lib file +mv "$OUTDIR/$STATIC_LIB_FILE" libs/ +mkdir -p "libs" +myprint "$OUTDIR/$STATIC_LIB_FILE -> libs/" diff --git a/tasks/pre_build.sh b/tasks/pre_build.sh index dd9d65c..579e4bd 100644 --- a/tasks/pre_build.sh +++ b/tasks/pre_build.sh @@ -1,35 +1,11 @@ #!/bin/bash -# if $lib_project.a doesn't exist or rebuild_* task was executed, builds static lib -function handle_static_dependency { - local lib_project="$1" - local lib_build_task="$2" - if [ ! -f "$OBJDIR/libs/$lib_project.a" ] || [ -f .rebuild_$lib_project.tmp ]; then - [[ -z "$lib_build_task" ]] && error "lib_build_task is empty" - myprint "${BLUE}making $lib_project task <$lib_build_task>" - - cd $lib_project - if ! make "$lib_build_task"; then - exit 1 - fi - cd .. - - cp $lib_project/bin/$lib_project.a $OBJDIR/libs/ - myprint "${GREEN}copied ${CYAN}$lib_project.a" - rm -f .rebuild_$lib_project.tmp - fi -} - +# compile fonts if [ ! -f libs/fonts_embedded.a ]; then if ! make embed_fonts; then exit 1 fi fi -handle_static_dependency kerep $DEPS_BUILD_TASK -handle_static_dependency imgui $DEPS_BUILD_TASK -handle_static_dependency imgui-node-editor $DEPS_BUILD_TASK -handle_static_dependency imnodes $DEPS_BUILD_TASK - # copy all precompiled libs cp libs/* $OBJDIR/libs/ diff --git a/tasks/rebuild_lib.sh b/tasks/rebuild_lib.sh deleted file mode 100644 index 3c62a17..0000000 --- a/tasks/rebuild_lib.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -source cbuild/colors.sh -source cbuild/functions.sh -touch ".rebuild_$1.tmp" -myprint "${YELLOW}$1.a will be rebuilt in the next build task"