168 lines
6.4 KiB
Bash
168 lines
6.4 KiB
Bash
#!/bin/bash
|
|
CBUILD_VERSION=7
|
|
CONFIG_VERSION=6
|
|
|
|
PROJECT="GraphC"
|
|
CMP_C="gcc"
|
|
CMP_CPP="g++"
|
|
STD_C="c11"
|
|
STD_CPP="c++17"
|
|
WARN_C="-Wall -Wno-discarded-qualifiers -Wextra -Wno-unused-parameter"
|
|
WARN_CPP="-Wall -Wextra -Wno-unused-parameter"
|
|
SRC_C="$(find src -name '*.c')"
|
|
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'"
|
|
|
|
# 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"
|
|
|
|
# OS-specific options
|
|
case "$OS" in
|
|
WINDOWS)
|
|
EXEC_FILE="$PROJECT.exe"
|
|
INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include"
|
|
LINKER_LIBS="-L./libs/ -l:SDL2.dll -lopengl32 -lpthread -lws2_32"
|
|
;;
|
|
LINUX)
|
|
EXEC_FILE="$PROJECT"
|
|
INCLUDE="-I./dependencies/imgui -I./dependencies/SDL2/include"
|
|
LINKER_LIBS="-L./libs/ -lSDL2 -lGL"
|
|
;;
|
|
*)
|
|
error "operating system $OS has no configuration variants"
|
|
;;
|
|
esac
|
|
|
|
# TASKS
|
|
case "$TASK" in
|
|
# writes ttf fonts fron ./fonts/ to C compressed arrays in C source files
|
|
# builds static library from font arrays definitions
|
|
embed_fonts)
|
|
SRC_CPP=""
|
|
SRC_C=""
|
|
C_ARGS="-O0 -fpic"
|
|
WARN_C="-Wno-unused-const-variable"
|
|
CPP_ARGS="$C_ARGS"
|
|
STATIC_LIB_FILE="fonts_embedded.a"
|
|
TASK_SCRIPT=tasks/embed_fonts.sh
|
|
;;
|
|
|
|
# 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 $LINKER_LIBS"
|
|
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)
|
|
C_ARGS="-O0 -g -DDEBUG=1"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=tasks/pre_build.sh
|
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
DEPS_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
|
|
;;
|
|
# generates profiling info
|
|
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
|
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
|
# -fprofile-generate generates executable with profiling code
|
|
# -fprofile-prefix-path sets path where profiling info about objects will be saved
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -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
|
|
POST_TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
|
DEPS_BUILD_TASK=build_static_lib
|
|
;;
|
|
# compiles program with -pg and runs it with gprof
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
|
gprof)
|
|
OUTDIR="$OUTDIR/gprof"
|
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg"
|
|
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/gprof.sh
|
|
DEPS_BUILD_TASK=build_static_lib
|
|
;;
|
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
|
sanitize)
|
|
OUTDIR="$OUTDIR/sanitize"
|
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
|
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/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"
|
|
;;
|
|
esac
|