|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
CBUILD_VERSION=2.3.4
|
|
|
|
|
CBUILD_VERSION=2.3.5
|
|
|
|
|
|
|
|
|
|
PROJECT="%PROJECT_NAME%"
|
|
|
|
|
CMP_C="gcc"
|
|
|
|
|
@@ -38,21 +38,24 @@ STATIC_LIB_FILE="$PROJECT.a"
|
|
|
|
|
|
|
|
|
|
# example: "-I./include -I$DEPENDENCIES_DIR/libexample"
|
|
|
|
|
INCLUDE=""
|
|
|
|
|
DEFINES=""
|
|
|
|
|
|
|
|
|
|
# OS-specific options
|
|
|
|
|
case "$OS" in
|
|
|
|
|
WINDOWS)
|
|
|
|
|
EXEC_FILE="$PROJECT.exe"
|
|
|
|
|
SHARED_LIB_FILE="$PROJECT.dll"
|
|
|
|
|
INCLUDE="$INCLUDE "
|
|
|
|
|
# example: "-lSDL2 -lSDL2_image"
|
|
|
|
|
LINKER_LIBS=""
|
|
|
|
|
INCLUDE="$INCLUDE "
|
|
|
|
|
DEFINES="$DEFINES "
|
|
|
|
|
;;
|
|
|
|
|
LINUX)
|
|
|
|
|
EXEC_FILE="$PROJECT"
|
|
|
|
|
SHARED_LIB_FILE="$PROJECT.so"
|
|
|
|
|
INCLUDE="$INCLUDE "
|
|
|
|
|
LINKER_LIBS=""
|
|
|
|
|
INCLUDE="$INCLUDE "
|
|
|
|
|
DEFINES="$DEFINES "
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
error "operating system $OS has no configuration variants"
|
|
|
|
|
@@ -69,7 +72,7 @@ case "$TASK" in
|
|
|
|
|
# -fprofile-use enables compiler to use profiling info files to optimize executable
|
|
|
|
|
# -fprofile-prefix-path sets path where profiling info about objects are be saved
|
|
|
|
|
# -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code
|
|
|
|
|
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 $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
|
@@ -78,7 +81,7 @@ case "$TASK" in
|
|
|
|
|
;;
|
|
|
|
|
# creates executable with debug info and no optimizations
|
|
|
|
|
build_exec_dbg)
|
|
|
|
|
C_ARGS="-O0 -g3"
|
|
|
|
|
C_ARGS="-O0 -g3 $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
|
@@ -87,37 +90,29 @@ case "$TASK" in
|
|
|
|
|
;;
|
|
|
|
|
# creates shared library
|
|
|
|
|
build_shared_lib)
|
|
|
|
|
C_ARGS="-O2 -fpic -flto -shared"
|
|
|
|
|
C_ARGS="-O2 -fpic -flto -shared $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -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 -g3 -fpic -shared"
|
|
|
|
|
C_ARGS="-O0 -g3 -fpic -shared $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -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 -fdata-sections -ffunction-sections"
|
|
|
|
|
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections $DEFINES"
|
|
|
|
|
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 -g3"
|
|
|
|
|
C_ARGS="-O0 -g3 $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
PRE_TASK_SCRIPT=""
|
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
|
;;
|
|
|
|
|
# executes $EXEC_FILE
|
|
|
|
|
exec)
|
|
|
|
|
@@ -137,12 +132,12 @@ case "$TASK" in
|
|
|
|
|
# -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"
|
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate
|
|
|
|
|
-fprofile-prefix-path=$(realpath $OBJDIR)/objects $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/profile.sh"
|
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
|
;;
|
|
|
|
|
# compiles program with -pg and runs it with gprof
|
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
|
|
@@ -153,12 +148,11 @@ case "$TASK" in
|
|
|
|
|
# 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"
|
|
|
|
|
-fno-optimize-sibling-calls -fopenmp $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/gprof.sh"
|
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
|
;;
|
|
|
|
|
# compiles program and runs it with callgrind (part of valgrind)
|
|
|
|
|
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
|
|
|
@@ -167,22 +161,20 @@ case "$TASK" in
|
|
|
|
|
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"
|
|
|
|
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/callgrind.sh"
|
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
|
;;
|
|
|
|
|
# compiles executable with sanitizers and executes it to find errors and warnings
|
|
|
|
|
sanitize)
|
|
|
|
|
OUTDIR="$OUTDIR/sanitize"
|
|
|
|
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
|
|
|
|
C_ARGS="-O0 -g3 -fsanitize=undefined,address $DEFINES"
|
|
|
|
|
CPP_ARGS="$C_ARGS"
|
|
|
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
|
|
|
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
|
|
|
TASK_SCRIPT="@cbuild/default_tasks/exec.sh"
|
|
|
|
|
POST_TASK_SCRIPT=""
|
|
|
|
|
;;
|
|
|
|
|
# rebuilds specified dependencies
|
|
|
|
|
# EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts`
|
|
|
|
|
|