#!/bin/bash CBUILD_VERSION=5 CONFIG_VERSION=1 PROJECT="NULL" CMP_C=gcc CMP_CPP=g++ STD_C=c11 STD_CPP=c++17 WARN_C="-Wall -Wno-discarded-qualifiers" WARN_CPP="-Wall" SRC_C="$( find src -name '*.c')" SRC_CPP="$( find src -name '*.cpp')" #TESTS_C="$( find tests -name '*.c')" #TESTS_CPP="$(find tests -name '*.cpp')" # 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" STATIC_LIB_FILE="$PROJECT.a" # OS-specific options case "$OS" in WINDOWS) EXEC_FILE="$PROJECT.exe" SHARED_LIB_FILE="$PROJECT.dll" ;; LINUX) EXEC_FILE="$PROJECT.P" SHARED_LIB_FILE="$PROJECT.so" ;; *) error "operating system $OS has no configuration variants" ;; esac # TASKS case "$TASK" in # 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="$CPP_ARGS" PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh TASK_SCRIPT=cbuild/default_tasks/profile.sh POST_TASK_SCRIPT= ;; # 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= TASK_SCRIPT=cbuild/default_tasks/build_exec.sh POST_TASK_SCRIPT= ;; # creates executable with debug info and no optimizations build_exec_dbg) C_ARGS="-O0 -g" CPP_ARGS="$C_ARGS" LINKER_ARGS="$CPP_ARGS" PRE_TASK_SCRIPT= TASK_SCRIPT=cbuild/default_tasks/build_exec.sh POST_TASK_SCRIPT= ;; # creates shared library build_shared_lib) C_ARGS="-O2 -fpic -flto -shared" CPP_ARGS="$C_ARGS" LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" PRE_TASK_SCRIPT= TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh POST_TASK_SCRIPT= ;; # creates shared library with debug symbols and no optimizations build_shared_lib_dbg) C_ARGS="-O0 -g -fpic -shared" CPP_ARGS="$C_ARGS" LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE" PRE_TASK_SCRIPT= TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh POST_TASK_SCRIPT= ;; # creates static library build_static_lib) C_ARGS="-O2 -fpic" CPP_ARGS="$C_ARGS" PRE_TASK_SCRIPT= TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh POST_TASK_SCRIPT= ;; # creates static library with debug symbols and no optimizations build_static_lib_dbg) C_ARGS="-O0 -g" CPP_ARGS="$C_ARGS" PRE_TASK_SCRIPT= TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh POST_TASK_SCRIPT= ;; # 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