diff --git a/Makefile b/Makefile index 00dd7f4..7f1d678 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,12 @@ build_exec: profile build_exec_dbg: @cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log -# recompile kerep.a in the next build task +# recompile libkerep.a in the next build task rebuild_kerep: - @tasks/rebuild_lib.sh kerep -# recompile utf8proc.a in the next build task + @cbuild/rebuild_dep.sh libkerep.a 2>&1 | tee make_raw.log +# recompile libutf8proc.a in the next build task rebuild_utf8proc: - @tasks/rebuild_lib.sh utf8proc + @cbuild/rebuild_dep.sh libutf8proc.a 2>&1 | tee make_raw.log rebuild_all: rebuild_kerep rebuild_utf8proc @@ -45,7 +45,14 @@ profile: # uses gprof2dot python script to generate function call tree 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 rezults 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 diff --git a/cbuild b/cbuild index 5e23ef8..ef6a3f8 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 5e23ef8156a85a981d60152990bde53d6e8eefe9 +Subproject commit ef6a3f82c429ec232e1b910eecbdece76de933b3 diff --git a/default.config b/default.config index d49a3e4..b4fea16 100644 --- a/default.config +++ b/default.config @@ -1,6 +1,6 @@ #!/bin/bash -CBUILD_VERSION=6 -CONFIG_VERSION=3 +CBUILD_VERSION=7 +CONFIG_VERSION=4 PROJECT="scolte" CMP_C="gcc" @@ -14,6 +14,17 @@ SRC_CPP="$( find src -name '*.cpp')" #TESTS_C="$( find tests -name '*.c')" #TESTS_CPP="$(find tests -name '*.cpp')" +# dir with dependeicy dirs +DEPS_BASEDIR="." +# 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' + utf8proc='libutf8proc.a . libutf8proc.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 @@ -47,7 +58,6 @@ case "$TASK" in LINKER_ARGS="$CPP_ARGS" PRE_TASK_SCRIPT=tasks/pre_build.sh TASK_SCRIPT=cbuild/default_tasks/build_exec.sh - DEPS_BUILD_TASK=build_static_lib ;; # creates executable with debug info and no optimizations build_exec_dbg) @@ -56,7 +66,8 @@ case "$TASK" in LINKER_ARGS="$CPP_ARGS" PRE_TASK_SCRIPT=tasks/pre_build.sh TASK_SCRIPT=cbuild/default_tasks/build_exec.sh - DEPS_BUILD_TASK=build_static_lib_dbg + DEPS="$DEPS + kerep='build_static_lib_dbg bin libkerep.a'" ;; # executes $EXEC_FILE exec) @@ -64,7 +75,7 @@ case "$TASK" in ;; # executes $EXEC_FILE with valgrind memory checker valgrind) - VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all" + VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all" TASK_SCRIPT=cbuild/default_tasks/valgrind.sh ;; # generates profiling info @@ -96,6 +107,20 @@ case "$TASK" in TASK_SCRIPT=cbuild/default_tasks/build_exec.sh POST_TASK_SCRIPT=cbuild/default_tasks/gprof.sh ;; + # 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 rezults 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 + ;; # compiles executable with sanitizers and executes it to find errors and warnings sanitize) OUTDIR="$OUTDIR/sanitize" @@ -111,6 +136,9 @@ case "$TASK" in 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/tasks/clean_additions.sh b/tasks/clean_additions.sh index 3b4ee55..45bb270 100644 --- a/tasks/clean_additions.sh +++ b/tasks/clean_additions.sh @@ -1,14 +1,4 @@ #!/usr/bin/bash set -eo pipefail -for tmpfile in $(ls -a | grep -e '\.rebuild.*\.tmp'); do - try_delete_dir_or_file "$tmpfile" -done - -for submodule in kerep utf8proc; do - cd "$submodule" - make clean - cd .. -done - try_delete_dir_or_file src/generated diff --git a/tasks/pre_build.sh b/tasks/pre_build.sh index b193cea..eca2fa2 100644 --- a/tasks/pre_build.sh +++ b/tasks/pre_build.sh @@ -1,28 +1,5 @@ #!/bin/bash set -eo pipefail -# 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" - local lib_build_rezults="$3" - 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_build_rezults $OBJDIR/libs/ - myprint "${GREEN}copied ${CYAN}$lib_project.a" - rm -f .rebuild_$lib_project.tmp - fi -} - -handle_static_dependency kerep "$DEPS_BUILD_TASK" kerep/bin/kerep.a -handle_static_dependency utf8proc libutf8proc.a utf8proc/libutf8proc.a - +# generate source code for views/*.tui.dtsod source tasks/build_view.sh diff --git a/tasks/rebuild_lib.sh b/tasks/rebuild_lib.sh deleted file mode 100644 index 407ec56..0000000 --- a/tasks/rebuild_lib.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -eo pipefail - -source cbuild/colors.sh -source cbuild/functions.sh -touch ".rebuild_$1.tmp" -rm -fv "obj/libs/$1.a" -myprint "${YELLOW}$1.a will be rebuilt in the next build task"