|
|
@@ -1,19 +1,28 @@
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
CBUILD_VERSION=2.2.3
|
|
|
|
CBUILD_VERSION=2.3.0
|
|
|
|
|
|
|
|
|
|
|
|
PROJECT="tlibc"
|
|
|
|
PROJECT="tlibc"
|
|
|
|
CMP_C="gcc"
|
|
|
|
CMP_C="gcc"
|
|
|
|
CMP_CPP="g++"
|
|
|
|
CMP_CPP="g++"
|
|
|
|
STD_C="c99"
|
|
|
|
STD_C="c99"
|
|
|
|
STD_CPP="c++11"
|
|
|
|
STD_CPP="c++11"
|
|
|
|
WARN_C="-Wall -Wextra -Werror=return-type -Werror=pointer-arith"
|
|
|
|
WARN_C="-Wall -Wextra
|
|
|
|
WARN_CPP="-Wall -Wextra -Werror=return-type -Werror=pointer-arith"
|
|
|
|
-Wduplicated-branches
|
|
|
|
|
|
|
|
-Wduplicated-cond
|
|
|
|
|
|
|
|
-Wformat=2
|
|
|
|
|
|
|
|
-Wmissing-include-dirs
|
|
|
|
|
|
|
|
-Wshadow
|
|
|
|
|
|
|
|
-Werror=return-type
|
|
|
|
|
|
|
|
-Werror=pointer-arith
|
|
|
|
|
|
|
|
-Werror=init-self
|
|
|
|
|
|
|
|
-Werror=incompatible-pointer-types"
|
|
|
|
|
|
|
|
WARN_CPP="$WARN_C"
|
|
|
|
SRC_C="$(find src -name '*.c')"
|
|
|
|
SRC_C="$(find src -name '*.c')"
|
|
|
|
SRC_CPP="$(find src -name '*.cpp')"
|
|
|
|
SRC_CPP="$(find src -name '*.cpp')"
|
|
|
|
|
|
|
|
|
|
|
|
# Directory with dependency configs.
|
|
|
|
# Directory with dependency configs.
|
|
|
|
# See cbuild/example_dependency_configs
|
|
|
|
# See cbuild/example_dependency_configs
|
|
|
|
DEPENDENCY_CONFIGS_DIR='.'
|
|
|
|
DEPENDENCY_CONFIGS_DIR='dependencies'
|
|
|
|
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
|
|
|
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
|
|
|
ENABLED_DEPENDENCIES=''
|
|
|
|
ENABLED_DEPENDENCIES=''
|
|
|
|
|
|
|
|
|
|
|
@@ -60,61 +69,61 @@ case "$TASK" in
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# creates executable with debug info and no optimizations
|
|
|
|
# creates executable with debug info and no optimizations
|
|
|
|
build_exec_dbg)
|
|
|
|
build_exec_dbg)
|
|
|
|
C_ARGS="-O0 -g3"
|
|
|
|
C_ARGS="-O0 -g3"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# creates shared library
|
|
|
|
# creates shared library
|
|
|
|
build_shared_lib)
|
|
|
|
build_shared_lib)
|
|
|
|
C_ARGS="-O2 -fpic -flto -shared"
|
|
|
|
C_ARGS="-O2 -fpic -flto -shared"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_shared_lib.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# creates shared library with debug symbols and no optimizations
|
|
|
|
# creates shared library with debug symbols and no optimizations
|
|
|
|
build_shared_lib_dbg)
|
|
|
|
build_shared_lib_dbg)
|
|
|
|
C_ARGS="-O0 -g3 -fpic -shared"
|
|
|
|
C_ARGS="-O0 -g3 -fpic -shared"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_shared_lib.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# creates static library
|
|
|
|
# creates static library
|
|
|
|
build_static_lib)
|
|
|
|
build_static_lib)
|
|
|
|
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections"
|
|
|
|
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# creates static library with debug symbols and no optimizations
|
|
|
|
# creates static library with debug symbols and no optimizations
|
|
|
|
build_static_lib_dbg)
|
|
|
|
build_static_lib_dbg)
|
|
|
|
C_ARGS="-O0 -g3"
|
|
|
|
C_ARGS="-O0 -g3"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
PRE_TASK_SCRIPT=
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# executes $EXEC_FILE
|
|
|
|
# executes $EXEC_FILE
|
|
|
|
exec)
|
|
|
|
exec)
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/exec.sh"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# executes $EXEC_FILE with valgrind memory checker
|
|
|
|
# executes $EXEC_FILE with valgrind memory checker
|
|
|
|
valgrind)
|
|
|
|
valgrind)
|
|
|
|
VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$(pwd)/ --leak-check=full --show-leak-kinds=all"
|
|
|
|
VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$(pwd)/ --leak-check=full --show-leak-kinds=all"
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/valgrind.sh"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# generates profiling info
|
|
|
|
# generates profiling info
|
|
|
|
profile)
|
|
|
|
profile)
|
|
|
@@ -128,22 +137,25 @@ case "$TASK" in
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/profile.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# compiles program with -pg and runs it with gprof
|
|
|
|
# compiles program with -pg and runs it with gprof
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
|
|
|
# requires graphviz (https://www.graphviz.org/download/source/)
|
|
|
|
gprof)
|
|
|
|
gprof)
|
|
|
|
OUTDIR="$OUTDIR/gprof"
|
|
|
|
OUTDIR="$OUTDIR/gprof"
|
|
|
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
|
|
|
# arguments that emit some call counter code and disable optimizations to see function names
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg"
|
|
|
|
# https://github.com/msys2/MINGW-packages/issues/8503#issuecomment-1365475205
|
|
|
|
|
|
|
|
C_ARGS="-O0 -g -pg -no-pie -fno-omit-frame-pointer
|
|
|
|
|
|
|
|
-fno-inline-functions -fno-inline-functions-called-once
|
|
|
|
|
|
|
|
-fno-optimize-sibling-calls -fopenmp"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/gprof.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/gprof.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# compiles program and runs it with callgrind (part of valgrind)
|
|
|
|
# compiles program and runs it with callgrind (part of valgrind)
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
@@ -155,9 +167,9 @@ case "$TASK" in
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/callgrind.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/callgrind.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
|
|
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
|
|
|
sanitize)
|
|
|
|
sanitize)
|
|
|
@@ -165,19 +177,19 @@ case "$TASK" in
|
|
|
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
|
|
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/exec.sh"
|
|
|
|
POST_TASK_SCRIPT=
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# rebuilds specified dependencies
|
|
|
|
# rebuilds specified dependencies
|
|
|
|
# EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts`
|
|
|
|
# EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts`
|
|
|
|
# 'all' can be specified to rebuild all dependencies
|
|
|
|
# 'all' can be specified to rebuild all dependencies
|
|
|
|
rebuild_dependencies)
|
|
|
|
rebuild_dependencies)
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/rebuild_dependencies.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/rebuild_dependencies.sh"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# deletes generated files
|
|
|
|
# deletes generated files
|
|
|
|
clean)
|
|
|
|
clean)
|
|
|
|
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/clean.sh"
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
# nothing to do
|
|
|
|
# nothing to do
|
|
|
|
"" | no_task)
|
|
|
|
"" | no_task)
|
|
|
|