diff --git a/.gitignore b/.gitignore index cab1d1a..4be6400 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,16 @@ -# Build results +# build results bin/ obj/ +*.log +*.tmp -# user files -.old*/ +# IDE files .vs/ .vshistory/ .editorconfig *.user *.vcxproj.filters + +# other files +.old*/ current.config diff --git a/Makefile b/Makefile index 3f31069..03b6418 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,56 @@ -all: build_exec +###################################### +###### Build tasks ####### +###################################### -##### Build cbuild/default_tasks ###### -build_exec: - @cbuild/call_task.sh build_exec -build_exec_dbg: - @cbuild/call_task.sh build_exec_dbg +all: build_exec_dbg -##### Launch cbuild/default_tasks ###### +# generates different profile info +build_profile: + @cbuild/call_task.sh build_profile 2>&1 | tee make_raw.log + +# creates executable using profile info generated by build_profile +build_exec: build_profile + @cbuild/call_task.sh build_exec 2>&1 | tee -a make_raw.log + +# creates executable with debug info and no optimizations +build_exec_dbg: + @cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log + +###################################### +###### Launch tasks ####### +###################################### + +# executes $EXEC_FILE exec: build_exec - @cbuild/call_task.sh exec + @cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log +# executes $EXEC_FILE +exec_dbg: build_exec_dbg + @cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log + +# executes $EXEC_FILE with valgrind memory checker valgrind: build_exec_dbg - @cbuild/call_task.sh valgrind + @cbuild/call_task.sh valgrind 2>&1 | tee -a make_raw.log -##### Recompile kerep.a ###### +###################################### +###### Other tasks ####### +###################################### + +# deletes generated files +clean: + @cbuild/call_task.sh clean 2>&1 | tee make_raw.log + +# removes all unreadable characters copied from stdio +fix_log: + sed 's/[^[:blank:][:print:]]//g' make_raw.log \ + | sed 's/\[0;[0-9][0-9]m//g' \ + | sed 's/\[0;[0-9]m//g' \ + | sed 's/\[[0-9][0-9]m//g' \ + | sed 's/\[[0-9]m//g' \ + | sed 's/ H //g' \ + | sed 's/\[3gH //g' \ + > make_fixed.log + +# recompile kerep.a in the next build task rebuild_kerep: @cbuild/call_task.sh rebuild_kerep diff --git a/cbuild b/cbuild index 81358b7..112fcc0 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 81358b72f8dc602d694f46ea42c2b64d9b0b41c6 +Subproject commit 112fcc04652d6ce65fbde215cd3d1f8935db2a7c diff --git a/default.config b/default.config index ed2159b..5603f05 100644 --- a/default.config +++ b/default.config @@ -1,6 +1,6 @@ #!/bin/bash -CBUILD_VERSION=4 -CONFIG_VERSION=1 +CBUILD_VERSION=5 +CONFIG_VERSION=2 PROJECT=scolte CMP_C=gcc @@ -14,44 +14,85 @@ SRC_CPP="$( find src -name '*.cpp')" #TESTS_C="$( find tests -name '*.c')" #TESTS_CPP="$(find tests -name '*.cpp')" -OUTDIR=bin -OBJDIR=obj -PRE_TASK_SCRIPT=tasks/pre_build.sh -POST_TASK_SCRIPT= +# 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 +# ├── libs - there you can put static libs and linker will find them +# └── out - output files are created here and then copied to OUTDIR +OBJDIR="obj" +OUTDIR="bin" -case $OS in +# OS-specific options +case "$OS" in WINDOWS) - EXEC_FILE=$PROJECT.exe + EXEC_FILE="$PROJECT.exe" + SHARED_LIB_FILE="$PROJECT.dll" ;; LINUX) - EXEC_FILE=$PROJECT + EXEC_FILE="$PROJECT" ;; *) - printf "${RED}operating system $OS has no configuration variants\n" - exit 1 + error "operating system $OS has no configuration variants" ;; esac -case $TASK in - build_exec) - C_ARGS="-O2" +# TASKS +case "$TASK" in + rebuild_kerep) + TASK_SCRIPT=tasks/rebuild_kerep.sh + ;; + # generates different profile info + build_profile) + OUTDIR="$OUTDIR/profile" + # -flto applies more optimizations across object files + # -flto=auto is needed to multithreaded copilation + # -fuse-linker-plugin is required to use static libs with lto, it strips away all + # -pg adds code to executable, that generates file containing function call info (gmon.out) + # -fprofile-generate + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects" CPP_ARGS="$C_ARGS" - LINKER_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/profile.sh + KEREP_BUILD_TASK=build_static_lib + ;; + # creates executable using profile info generated by build_profile + build_exec) + # -flto applies more optimizations across object files + # -flto=auto is needed to multithreaded copilation + # -fuse-linker-plugin is required to use static libs with lto, it strips away all + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects" + CPP_ARGS="$C_ARGS" + LINKER_ARGS="$CPP_ARGS" + PRE_TASK_SCRIPT=tasks/pre_build.sh TASK_SCRIPT=cbuild/default_tasks/build_exec.sh KEREP_BUILD_TASK=build_static_lib ;; + # creates executable with debug info and no optimizations build_exec_dbg) C_ARGS="-O0 -g" CPP_ARGS="$C_ARGS" - LINKER_ARGS="" + LINKER_ARGS="$CPP_ARGS" + PRE_TASK_SCRIPT=tasks/pre_build.sh TASK_SCRIPT=cbuild/default_tasks/build_exec.sh KEREP_BUILD_TASK=build_static_lib_dbg ;; + # executes $EXEC_FILE exec) TASK_SCRIPT=cbuild/default_tasks/exec.sh ;; + # executes $EXEC_FILE with valgrind memory checker valgrind) VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all" TASK_SCRIPT=cbuild/default_tasks/valgrind.sh ;; + # deletes generated files + clean) + TASK_SCRIPT=cbuild/default_tasks/clean.sh + ;; + # unknown task + *) + error "task <$TASK> not found" + ;; esac diff --git a/kerep b/kerep index d2eb241..dbf2c27 160000 --- a/kerep +++ b/kerep @@ -1 +1 @@ -Subproject commit d2eb241d0df5c88958888afa9f577c3dd1414d21 +Subproject commit dbf2c2772c832bbb6f8f56b9741a21722daa01a2 diff --git a/tasks/clean_additions.sh b/tasks/clean_additions.sh new file mode 100644 index 0000000..85a607e --- /dev/null +++ b/tasks/clean_additions.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +myprint "${WHITE}deleting .kerep_rebuild.tmp" +rm -rf .kerep_rebuild.tmp diff --git a/tasks/pre_build.sh b/tasks/pre_build.sh index 4f3a298..60439dd 100644 --- a/tasks/pre_build.sh +++ b/tasks/pre_build.sh @@ -1,13 +1,17 @@ #!/bin/bash -if [ ! -f "kerep/bin/kerep.a" ] || [ -f .rebuild_kerep ] -then +# check if kerep static lib exists or kerep_rebuild task was executed +if [ ! -f "$OBJDIR/libs/kerep.a" ] || [ -f .rebuild_kerep.tmp ]; then + [[ -z "$KEREP_BUILD_TASK" ]] && error "KEREP_BUILD_TASK is empty" + myprint "${BLUE}making kerep task <$KEREP_BUILD_TASK>" + cd kerep if ! make "$KEREP_BUILD_TASK"; then exit 1 fi cd .. - rm -rf .rebuild_kerep + + cp kerep/bin/kerep.a $OBJDIR/libs/ + myprint "${GREEN}copied ${CYAN}kerep.a" + rm .rebuild_kerep.tmp fi -cp kerep/bin/kerep.a obj/ -printf "${GREEN}copied ${CYAN}kerep.a\n" diff --git a/tasks/rebuild_kerep.sh b/tasks/rebuild_kerep.sh index ea7e93b..7698a61 100644 --- a/tasks/rebuild_kerep.sh +++ b/tasks/rebuild_kerep.sh @@ -1,3 +1,3 @@ #!/bin/bash -touch .rebuild_kerep -printf "kerep.a will be rebuilt in the next build task" +touch .rebuild_kerep.tmp +myprint "${YELLOW}kerep.a will be rebuilt in the next build task"