191 lines
5.4 KiB
Bash
191 lines
5.4 KiB
Bash
#!/usr/bin/env bash
|
|
CBUILD_VERSION=2.3.2
|
|
|
|
PROJECT="tim"
|
|
CMP_C="gcc"
|
|
CMP_CPP="g++"
|
|
STD_C="c99"
|
|
STD_CPP="c++11"
|
|
WARN_C="-Wall -Wextra
|
|
-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_CPP="$(find src -name '*.cpp')"
|
|
|
|
# Directory with dependency configs.
|
|
# See cbuild/example_dependency_configs
|
|
DEPENDENCY_CONFIGS_DIR='dependencies'
|
|
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
|
ENABLED_DEPENDENCIES=''
|
|
|
|
# OBJDIR structure:
|
|
# ├── objects/ - Compiled object files. Cleans on each call of build task
|
|
# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task.
|
|
# ├── static_libs/ - Symbolic links to dynamic libraries used by linker. Cleans on each call of build task.
|
|
# └── profile/ - gcc *.gcda profiling info files
|
|
OBJDIR="obj"
|
|
OUTDIR="bin"
|
|
STATIC_LIB_FILE="$PROJECT.a"
|
|
|
|
# example: "-I./include -I$DEPENDENCIES_DIR/libexample"
|
|
INCLUDE="-Iinclude -Isrc"
|
|
|
|
EXEC_FILE=""
|
|
EXEC_EXT=""
|
|
|
|
# OS-specific options
|
|
case "$OS" in
|
|
WINDOWS)
|
|
EXEC_EXT=".exe"
|
|
SHARED_LIB_FILE="$PROJECT.dll"
|
|
INCLUDE="$INCLUDE "
|
|
# example: "-lSDL2 -lSDL2_image"
|
|
LINKER_LIBS=""
|
|
;;
|
|
LINUX)
|
|
SHARED_LIB_FILE="$PROJECT.so"
|
|
INCLUDE="$INCLUDE "
|
|
LINKER_LIBS=""
|
|
;;
|
|
*)
|
|
error "operating system $OS has no configuration variants"
|
|
;;
|
|
esac
|
|
|
|
TEST_C_ARGS="-O0 -g3"
|
|
|
|
# TASKS
|
|
case "$TASK" in
|
|
# ./ask question?
|
|
ask)
|
|
EXEC_FILE="ask$EXEC_EXT"
|
|
SRC_C="example/ask.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# hello world
|
|
hello)
|
|
EXEC_FILE="hello$EXEC_EXT"
|
|
SRC_C="example/hello.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# snake game
|
|
snek)
|
|
EXEC_FILE="snek$EXEC_EXT"
|
|
SRC_C="example/snek.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# test
|
|
test)
|
|
EXEC_FILE="test$EXEC_EXT"
|
|
SRC_C="test/test.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# color
|
|
color)
|
|
EXEC_FILE="color$EXEC_EXT"
|
|
SRC_C="test/color.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# string
|
|
string)
|
|
EXEC_FILE="string$EXEC_EXT"
|
|
SRC_C="test/string.c"
|
|
LINKER_LIBS="bin/tim.a"
|
|
C_ARGS="$TEST_C_ARGS"
|
|
CPP_ARGS="$C_ARGS"
|
|
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
|
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 $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"
|
|
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"
|
|
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"
|
|
CPP_ARGS="$C_ARGS"
|
|
PRE_TASK_SCRIPT=""
|
|
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
|
POST_TASK_SCRIPT=""
|
|
;;
|
|
# rebuilds specified dependencies
|
|
# EXAMPLE: `cbuild rebuild_dependencies=libexample1,fonts`
|
|
# 'all' can be specified to rebuild all dependencies
|
|
rebuild_dependencies)
|
|
TASK_SCRIPT="@cbuild/default_tasks/rebuild_dependencies.sh"
|
|
;;
|
|
# deletes generated files
|
|
clean)
|
|
TASK_SCRIPT="@cbuild/default_tasks/clean.sh"
|
|
;;
|
|
# nothing to do
|
|
"" | no_task)
|
|
;;
|
|
# unknown task
|
|
*)
|
|
error "task <$PROJECT/$TASK> not found"
|
|
;;
|
|
esac
|