Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3198f8905e | |||
| 458652d0c5 | |||
| 7ef47c567c | |||
| 1a4ad2a3f0 | |||
| f0ee39084e | |||
| e655f05da6 | |||
| 5cc2e1c2ad | |||
| fca94ffe4c | |||
| 7197f09ca4 | |||
| f884925788 | |||
| baf45a4b10 | |||
| 6bfc0f5e9a | |||
| 579dd5916e | |||
| 05f3b9a0a0 | |||
| 49ccc76933 | |||
| d1660e05cb | |||
| 259d9873fb | |||
| 46029cd01f | |||
| 5953b84cff | |||
| 4c34c127a6 | |||
| cae29d6395 | |||
| 596c570756 | |||
| 1c93d4eb73 | |||
| 6126001e5a |
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# git add --renormalize .
|
||||
*.sh text eol=lf
|
||||
@ -1 +1 @@
|
||||
2.2.1
|
||||
2.3.2
|
||||
32
CHANGELOG.md
32
CHANGELOG.md
@ -1,3 +1,35 @@
|
||||
## 2.3.2
|
||||
+ fixed symlink creation in `OBJDIR/static_libs`
|
||||
|
||||
## 2.3.1
|
||||
+ user config loads before project config
|
||||
|
||||
## 2.3.0
|
||||
+ **CONFIG:** Added new file `./project.config.user.default`.
|
||||
+ **CONFIG:** Changed `cbuild/default_tasks` to `@cbuild/default_tasks`.
|
||||
+ **CONFIG:** Updated `gprof` task.
|
||||
+ Changed `include` function: replaced prefix `cbuild/` with `@cbuild/`.
|
||||
+ Moved most scripts to `include/`.
|
||||
+ Renamed default config to `./project.config.default`.
|
||||
+ Added functions:
|
||||
+ `file_copy_default_if_not_present()`
|
||||
+ `replace_var_value_in_script()`
|
||||
+ Added task scripts:
|
||||
+ `strip_exec.sh` - enabled in default config in task `build_exec`
|
||||
|
||||
## 2.2.4
|
||||
+ *default config*: C standard changed to C99
|
||||
+ *default config*: enabled more warnings
|
||||
+ added file `default_vscode/c_cpp_properties.json`
|
||||
+ fixed copying of `default_vscode` files
|
||||
|
||||
## 2.2.3
|
||||
+ removed `\r` characters from `detect_os.sh`
|
||||
|
||||
## 2.2.2
|
||||
+ `bootstrap.sh` can show help for cbuild installations again
|
||||
+ copy dependency out files only if they are newer or don't exist
|
||||
|
||||
## 2.2.1
|
||||
+ updated `bootsrap.sh` to 1.0.2
|
||||
|
||||
|
||||
3
bootstrap.sh
Normal file → Executable file
3
bootstrap.sh
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_BOOTSTRAP_VERSION=1.0.2
|
||||
CBUILD_BOOTSTRAP_VERSION=1.0.3
|
||||
set -eo pipefail
|
||||
|
||||
function version_parse {
|
||||
@ -75,7 +75,6 @@ do
|
||||
;;
|
||||
'-h' | '--help')
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
'-c' | '--config')
|
||||
i=$((i+1))
|
||||
|
||||
44
cbuild.sh
Normal file → Executable file
44
cbuild.sh
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
INSTALLED_CBUILD_VERSION=2.2.1
|
||||
INSTALLED_CBUILD_VERSION=2.3.2
|
||||
|
||||
# set \t size to 4 spaces
|
||||
tabs 4
|
||||
@ -33,19 +33,19 @@ fi
|
||||
|
||||
function include {
|
||||
local script_path="$1"
|
||||
if [[ "$script_path" == cbuild/* ]]; then
|
||||
script_path="$CBUILD_INSTALL_DIR/$(echo $script_path | sed 's,^cbuild/,,')"
|
||||
if [[ "$script_path" == @cbuild/* ]]; then
|
||||
script_path="$CBUILD_INSTALL_DIR/$(echo $script_path | sed 's,^@cbuild/,,')"
|
||||
fi
|
||||
# echp "including script $script_path"
|
||||
. "$script_path"
|
||||
}
|
||||
|
||||
include "cbuild/myprint.sh"
|
||||
include "cbuild/functions.sh"
|
||||
include "cbuild/config.sh"
|
||||
include "@cbuild/include/myprint.sh"
|
||||
include "@cbuild/include/functions.sh"
|
||||
include "@cbuild/include/config.sh"
|
||||
|
||||
function print_help {
|
||||
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
|
||||
myprint "${GRAY}cbuild v$INSTALLED_CBUILD_VERSION"
|
||||
myprint "C/C++ project build system written in bash."
|
||||
myprint "Usage: cbuild [OPTIONS] [TASKS]"
|
||||
myprint "Options:"
|
||||
@ -74,7 +74,7 @@ do
|
||||
exit 0
|
||||
;;
|
||||
'-v' | '--version')
|
||||
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
|
||||
myprint "${GRAY}cbuild v$INSTALLED_CBUILD_VERSION"
|
||||
exit 0
|
||||
;;
|
||||
'-c' | '--config')
|
||||
@ -92,22 +92,28 @@ do
|
||||
|
||||
# create project config
|
||||
project_config_path="$new_project_dir/project.config"
|
||||
cp "$CBUILD_INSTALL_DIR/default.config" "$project_config_path.temp"
|
||||
myprint "Enter project name: "
|
||||
cp "$CBUILD_INSTALL_DIR/project.config.default" "$project_config_path.temp"
|
||||
myprint "${WHITE}Enter project name: "
|
||||
read -r project_name
|
||||
sed "s,\%PROJECT_NAME\%,$project_name,g" \
|
||||
"$project_config_path.temp" > "$project_config_path"
|
||||
rm "$project_config_path.temp"
|
||||
myprint "${GREEN}created config at '$project_config_path'"
|
||||
myprint "${GREEN}Created '$project_config_path'"
|
||||
# create project user default config
|
||||
project_user_config_path="$new_project_dir/project.config.user.default"
|
||||
cp "$CBUILD_INSTALL_DIR/project.config.user.default" "$project_user_config_path"
|
||||
myprint "${GREEN}Created '$project_user_config_path'"
|
||||
|
||||
if ask_yn "Copy default .gitignore?"; then
|
||||
if ask_yn "${WHITE}Copy default .gitignore?"; then
|
||||
cp -v "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
|
||||
fi
|
||||
|
||||
if ask_yn "Copy default .vscode launch tasks?"; then
|
||||
if ask_yn "${WHITE}Copy default .vscode launch tasks?"; then
|
||||
new_project_vscode_dir="$new_project_dir/.vscode"
|
||||
mkdir -p "$new_project_vscode_dir"
|
||||
cp -vr "$CBUILD_INSTALL_DIR/default_vscode/"* "$new_project_vscode_dir/"
|
||||
mkdir -pv "$new_project_vscode_dir"
|
||||
for vscode_dir_f in $(find "$CBUILD_INSTALL_DIR/default_vscode/" -type f); do
|
||||
cp -vr "$vscode_dir_f" "$new_project_vscode_dir/"
|
||||
done
|
||||
sed "s,\%PROJECT_NAME\%,$project_name,g" \
|
||||
"$new_project_vscode_dir/launch.json" > "$new_project_vscode_dir/launch.json.temp"
|
||||
mv "$new_project_vscode_dir/launch.json.temp" "$new_project_vscode_dir/launch.json"
|
||||
@ -131,15 +137,17 @@ function call_task {
|
||||
load_config "$project_config_path" "$task" true
|
||||
|
||||
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
|
||||
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
||||
myprint "${BLUE}executing ${WHITE}'$PRE_TASK_SCRIPT'"
|
||||
include "$PRE_TASK_SCRIPT"
|
||||
fi
|
||||
|
||||
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
||||
if [ ! -z "$TASK_SCRIPT" ]; then
|
||||
myprint "${BLUE}executing ${WHITE}'$TASK_SCRIPT'"
|
||||
include "$TASK_SCRIPT"
|
||||
fi
|
||||
|
||||
if [ ! -z "$POST_TASK_SCRIPT" ]; then
|
||||
myprint "${BLUE}executing ${WHITE}$POST_TASK_SCRIPT"
|
||||
myprint "${BLUE}executing ${WHITE}'$POST_TASK_SCRIPT'"
|
||||
include "$POST_TASK_SCRIPT"
|
||||
fi
|
||||
}
|
||||
|
||||
0
default_tasks/callgrind.sh
Normal file → Executable file
0
default_tasks/callgrind.sh
Normal file → Executable file
0
default_tasks/clean.sh
Normal file → Executable file
0
default_tasks/clean.sh
Normal file → Executable file
0
default_tasks/gprof.sh
Normal file → Executable file
0
default_tasks/gprof.sh
Normal file → Executable file
0
default_tasks/profile.sh
Normal file → Executable file
0
default_tasks/profile.sh
Normal file → Executable file
0
default_tasks/rebuild_dependencies.sh
Normal file → Executable file
0
default_tasks/rebuild_dependencies.sh
Normal file → Executable file
4
default_tasks/strip_exec.sh
Executable file
4
default_tasks/strip_exec.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
exe_path="$OUTDIR/$EXEC_FILE"
|
||||
myprint "${BLUE}stripping symbols from ${WHITE}$exe_path"
|
||||
strip -s "$exe_path"
|
||||
14
default_vscode/c_cpp_properties.json
Normal file
14
default_vscode/c_cpp_properties.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "all",
|
||||
"defines": [],
|
||||
"includePath": [
|
||||
// "include",
|
||||
"${default}"
|
||||
],
|
||||
"cStandard": "c99"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
2
example_dependency_configs/libexample1.config
Normal file → Executable file
2
example_dependency_configs/libexample1.config
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
DEP_WORKING_DIR='depencencies/libexample1'
|
||||
DEP_WORKING_DIR='dependencies/libexample1'
|
||||
DEP_PRE_BUILD_COMMAND=''
|
||||
DEP_BUILD_COMMAND='make libexample1.a'
|
||||
DEP_POST_BUILD_COMMAND=''
|
||||
|
||||
2
example_dependency_configs/libexample2.config
Normal file → Executable file
2
example_dependency_configs/libexample2.config
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
DEP_WORKING_DIR='depencencies/libexample2'
|
||||
DEP_WORKING_DIR='dependencies/libexample2'
|
||||
DEP_PRE_BUILD_COMMAND=''
|
||||
DEP_POST_BUILD_COMMAND=''
|
||||
DEP_CLEAN_COMMAND='make clean'
|
||||
|
||||
39
config.sh → include/config.sh
Normal file → Executable file
39
config.sh → include/config.sh
Normal file → Executable file
@ -1,23 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include cbuild/myprint.sh
|
||||
include cbuild/functions.sh
|
||||
include cbuild/detect_os.sh
|
||||
include "@cbuild/include/myprint.sh"
|
||||
include "@cbuild/include/functions.sh"
|
||||
include "@cbuild/include/detect_os.sh"
|
||||
|
||||
function load_config {
|
||||
local project_config_path="$1"
|
||||
local proj_conf_file="$1"
|
||||
TASK="$2"
|
||||
#true or false
|
||||
local quiet=$3
|
||||
|
||||
myprint "${BLUE}loading config ${WHITE}'$(realpath $project_config_path)'"
|
||||
|
||||
if [ -z "$project_config_path" ]; then
|
||||
if [ -z "$proj_conf_file" ]; then
|
||||
error "config path is null"
|
||||
fi
|
||||
if [ ! -f "$project_config_path" ]; then
|
||||
error "${YELLOW}$project_config_path doesn't exist"
|
||||
if [ ! -f "$proj_conf_file" ]; then
|
||||
error "${YELLOW}$proj_conf_file doesn't exist"
|
||||
fi
|
||||
|
||||
# load project user config
|
||||
local proj_conf_user_file="$proj_conf_file.user"
|
||||
file_copy_default_if_not_present "$proj_conf_user_file" "$proj_conf_user_file.default"
|
||||
myprint "${BLUE}loading ${WHITE}'$proj_conf_user_file'"
|
||||
# throw error on undefined variable usage
|
||||
set -u
|
||||
include "$proj_conf_user_file"
|
||||
# don't throw error on undefined variable usage
|
||||
set +u
|
||||
|
||||
myprint "${BLUE}loading ${WHITE}'$proj_conf_file'"
|
||||
|
||||
OS=$(detect_os)
|
||||
ARCH=$(detect_arch)
|
||||
myprint_quiet $quiet "${GREEN}detected OS: $OS"
|
||||
@ -31,9 +42,9 @@ function load_config {
|
||||
[ -z "$TASK" ] && TASK="no_task"
|
||||
|
||||
# getting cbuild version from config (CBUILD_VERSION declaration is at line 2)
|
||||
exec_script_line "$project_config_path" 2 $quiet
|
||||
exec_script_line "$proj_conf_file" 2 $quiet
|
||||
|
||||
myprint_quiet $quiet "${WHITE}${project_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
||||
myprint_quiet $quiet "${WHITE}'${proj_conf_file}' cbuild version: ${CYAN}$CBUILD_VERSION"
|
||||
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
||||
|
||||
# checking versions
|
||||
@ -47,9 +58,8 @@ function load_config {
|
||||
myprint "${YELLOW}Install it to get latest bugfixes."
|
||||
fi
|
||||
|
||||
# throw error on undefined variable usage
|
||||
set -u
|
||||
include "$project_config_path"
|
||||
include "$proj_conf_file"
|
||||
|
||||
mkdir -p "$OUTDIR"
|
||||
mkdir -p "$OBJDIR/objects"
|
||||
@ -57,8 +67,7 @@ function load_config {
|
||||
mkdir -p "$OBJDIR/dynamic_libs"
|
||||
mkdir -p "$OBJDIR/profile"
|
||||
|
||||
# dont thorw error on undefined variable
|
||||
set +u
|
||||
|
||||
myprint_quiet $quiet "${GREEN}loaded cbuild config"
|
||||
myprint_quiet $quiet "${GREEN}config loading completed"
|
||||
}
|
||||
3
detect_os.sh → include/detect_os.sh
Normal file → Executable file
3
detect_os.sh → include/detect_os.sh
Normal file → Executable file
@ -1,10 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "cbuild/myprint.sh"
|
||||
include "@cbuild/include/myprint.sh"
|
||||
|
||||
function detect_os {
|
||||
local uname_result="$(uname -o)"
|
||||
# myprint "uname result: '$uname_result'"
|
||||
case "$uname_result" in
|
||||
Msys | Cygwin | MS/Windows)
|
||||
safeprint WINDOWS
|
||||
@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "cbuild/myprint.sh"
|
||||
include "@cbuild/include/myprint.sh"
|
||||
|
||||
function exec_script_line {
|
||||
local script="$1"
|
||||
local line_num="$2"
|
||||
#true or false
|
||||
local quiet=$3
|
||||
|
||||
myprint_quiet $quiet "${BLUE}reading line $line_num from $script"
|
||||
local line_str="$(sed $line_num'!d' $script)"
|
||||
if [ -z "$line_str" ]; then
|
||||
@ -15,16 +17,28 @@ function exec_script_line {
|
||||
eval "$line_str"
|
||||
}
|
||||
|
||||
function replace_var_value_in_script(){
|
||||
local script="$1"
|
||||
local var_name="$2"
|
||||
local new_value="$3"
|
||||
|
||||
myprint "${BLUE}setting $var_name to ${CYAN}'$new_value' in '$script'"
|
||||
cp "$script" "$script.tmp"
|
||||
sed "s,$var_name=\".*\",$var_name=\"$new_value\",g" \
|
||||
"$script.tmp" > "$script"
|
||||
rm "$script.tmp"
|
||||
}
|
||||
|
||||
function clean_dir {
|
||||
local dir="$1"
|
||||
myprint "${WHITE}cleaning $dir"
|
||||
myprint "${BLUE}cleaning ${WHITE}'$dir'"
|
||||
rm -rf "$dir"
|
||||
mkdir "$dir"
|
||||
}
|
||||
|
||||
function delete_dir {
|
||||
local dir="$1"
|
||||
myprint "${WHITE}deleting $dir"
|
||||
myprint "${BLUE}deleting ${WHITE}'$dir'"
|
||||
rm -rf "$dir"
|
||||
}
|
||||
|
||||
@ -32,7 +46,16 @@ function try_delete_dir_or_file {
|
||||
local path="$1"
|
||||
if [ -f "$path" ] || [ -d "$path" ]; then
|
||||
rm -rf "$path"
|
||||
myprint "${WHITE}deleting $path"
|
||||
myprint "${BLUE}deleting ${WHITE}'$path'"
|
||||
fi
|
||||
}
|
||||
|
||||
file_copy_default_if_not_present(){
|
||||
local file="$1"
|
||||
local file_default="$2"
|
||||
if [ ! -f "$file" ]; then
|
||||
myprint "${YELLOW}creating default ${WHITE}'$file'"
|
||||
cp -r "$file_default" "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -45,18 +68,18 @@ function exec_command {
|
||||
}
|
||||
|
||||
function load_dependency_config {
|
||||
local dependency_config_file="$1"
|
||||
myprint "${BLUE}loading dependency config ${WHITE}${dependency_config_file}${BLUE}"
|
||||
include "$dependency_config_file"
|
||||
local dep_conf_file="$1"
|
||||
myprint "${BLUE}loading dependency config ${WHITE}'${dep_conf_file}'"
|
||||
include "$dep_conf_file"
|
||||
}
|
||||
|
||||
# builds a dependency when $dep_out_files dont exist or rebuild task is executed
|
||||
function build_dependency {
|
||||
# path to *.config file
|
||||
local dependency_config_file="$1"
|
||||
local dep_conf_file="$1"
|
||||
# true or false
|
||||
local force_build="$2"
|
||||
load_dependency_config "$dependency_config_file"
|
||||
load_dependency_config "$dep_conf_file"
|
||||
|
||||
local proj_root_dir="$(pwd)"
|
||||
myprint "${BLUE}entering dependency directory '${DEP_WORKING_DIR}'"
|
||||
@ -90,10 +113,10 @@ function build_dependency {
|
||||
if [ "$PRESERVE_OUT_DIRECTORY_STRUCTURE" = true ] && [ "$file_dir" != '.' ]; then
|
||||
mkdir -p "$proj_root_dir/$OUTDIR/$file_dir"
|
||||
mkdir -p "$proj_root_dir/$OBJDIR/dynamic_libs/$file_dir"
|
||||
cp -v "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/dynamic_libs/$file"
|
||||
else
|
||||
cp -v "$file" "$proj_root_dir/$OUTDIR/"
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/"
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/dynamic_libs/"
|
||||
fi
|
||||
done
|
||||
@ -104,9 +127,9 @@ function build_dependency {
|
||||
if [ "$PRESERVE_OUT_DIRECTORY_STRUCTURE" = true ]; then
|
||||
file_dir=$(dirname $file)
|
||||
mkdir -p "$proj_root_dir/$OUTDIR/$file_dir"
|
||||
cp -v "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
else
|
||||
cp -v "$file" "$proj_root_dir/$OUTDIR/"
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@ -114,8 +137,8 @@ function build_dependency {
|
||||
# creates symbolic link to each file in $OBJDIR/static_libs
|
||||
for file in $DEP_STATIC_OUT_FILES; do
|
||||
# doesnt return error if called not like this
|
||||
f=$(realpath $file)
|
||||
ln -sfv $f "$proj_root_dir/$OBJDIR/static_libs"
|
||||
real_file=$(realpath $file)
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/static_libs/"
|
||||
done
|
||||
fi
|
||||
|
||||
@ -210,7 +233,9 @@ function pack_static_lib {
|
||||
fi
|
||||
|
||||
local command="ar rcs $OUTDIR/$outfile $objects"
|
||||
myprint "$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
myprint "${GRAY}$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
if $command
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
@ -245,7 +270,9 @@ function link {
|
||||
done
|
||||
|
||||
local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile"
|
||||
myprint "$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
myprint "${GRAY}$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
if $command
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
3
myprint.sh → include/myprint.sh
Normal file → Executable file
3
myprint.sh → include/myprint.sh
Normal file → Executable file
@ -18,10 +18,11 @@ function safeprint {
|
||||
|
||||
# prints text with special characters and resets color
|
||||
function myprint {
|
||||
printf "${GRAY}$@${GRAY}\n"
|
||||
printf "$@${GRAY}\n"
|
||||
}
|
||||
|
||||
function myprint_quiet {
|
||||
#true or false
|
||||
local quiet=$1
|
||||
local text="$2"
|
||||
if [ "$quiet" != true ]; then
|
||||
104
default.config → project.config.default
Normal file → Executable file
104
default.config → project.config.default
Normal file → Executable file
@ -1,19 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_VERSION=2.2.1
|
||||
CBUILD_VERSION=2.3.2
|
||||
|
||||
PROJECT="%PROJECT_NAME%"
|
||||
CMP_C="gcc"
|
||||
CMP_CPP="g++"
|
||||
STD_C="c11"
|
||||
STD_C="c99"
|
||||
STD_CPP="c++11"
|
||||
WARN_C="-Wall -Wno-discarded-qualifiers -Wextra -Wno-unused-parameter"
|
||||
WARN_CPP="-Wall -Wextra -Wno-unused-parameter"
|
||||
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='.'
|
||||
DEPENDENCY_CONFIGS_DIR='dependencies'
|
||||
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
||||
ENABLED_DEPENDENCIES=''
|
||||
|
||||
@ -24,22 +33,24 @@ ENABLED_DEPENDENCIES=''
|
||||
# └── profile/ - gcc *.gcda profiling info files
|
||||
OBJDIR="obj"
|
||||
OUTDIR="bin"
|
||||
STATIC_LIB_FILE="lib$PROJECT.a"
|
||||
STATIC_LIB_FILE="$PROJECT.a"
|
||||
|
||||
# example: "-I./include -I$DEPENDENCIES_DIR/libexample"
|
||||
INCLUDE=""
|
||||
|
||||
# OS-specific options
|
||||
case "$OS" in
|
||||
WINDOWS)
|
||||
EXEC_FILE="$PROJECT.exe"
|
||||
SHARED_LIB_FILE="$PROJECT.dll"
|
||||
# example: "-I./dependencies/include/SDL2"
|
||||
INCLUDE=""
|
||||
INCLUDE="$INCLUDE "
|
||||
# example: "-lSDL2 -lSDL2_image"
|
||||
LINKER_LIBS=""
|
||||
;;
|
||||
LINUX)
|
||||
EXEC_FILE="$PROJECT"
|
||||
SHARED_LIB_FILE="$PROJECT.so"
|
||||
INCLUDE=""
|
||||
INCLUDE="$INCLUDE "
|
||||
LINKER_LIBS=""
|
||||
;;
|
||||
*)
|
||||
@ -60,61 +71,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"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
POST_TASK_SCRIPT=
|
||||
PRE_TASK_SCRIPT=""
|
||||
TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||
POST_TASK_SCRIPT="@cbuild/default_tasks/strip_exec.sh"
|
||||
;;
|
||||
# creates executable with debug info and no optimizations
|
||||
build_exec_dbg)
|
||||
C_ARGS="-O0 -g3"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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=
|
||||
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=
|
||||
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=
|
||||
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=
|
||||
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
|
||||
TASK_SCRIPT="@cbuild/default_tasks/exec.sh"
|
||||
;;
|
||||
# executes $EXEC_FILE with valgrind memory checker
|
||||
valgrind)
|
||||
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
|
||||
profile)
|
||||
@ -128,22 +139,25 @@ case "$TASK" in
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
||||
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=
|
||||
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)
|
||||
# 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"
|
||||
# arguments that emit some call counter code and disable optimizations to see function names
|
||||
# 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"
|
||||
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=
|
||||
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)
|
||||
@ -155,9 +169,9 @@ case "$TASK" in
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
||||
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=
|
||||
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)
|
||||
@ -165,19 +179,19 @@ case "$TASK" in
|
||||
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
||||
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=
|
||||
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`
|
||||
# 'all' can be specified to rebuild all dependencies
|
||||
rebuild_dependencies)
|
||||
TASK_SCRIPT=cbuild/default_tasks/rebuild_dependencies.sh
|
||||
TASK_SCRIPT="@cbuild/default_tasks/rebuild_dependencies.sh"
|
||||
;;
|
||||
# deletes generated files
|
||||
clean)
|
||||
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
||||
TASK_SCRIPT="@cbuild/default_tasks/clean.sh"
|
||||
;;
|
||||
# nothing to do
|
||||
"" | no_task)
|
||||
11
project.config.user.default
Executable file
11
project.config.user.default
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Project user config is ignored by git.
|
||||
# Here you can add variables that users might want to change
|
||||
# on their local machine, without commiting to the repository.
|
||||
|
||||
# Directory where you install dependencies.
|
||||
# Do not confuse with DEPENDENCY_CONFIGS_DIR
|
||||
# Example:
|
||||
# libexample source code is at `../libexample`, and dependency config
|
||||
# that specifies how to build this lib is at `dependencies/libexample.config`
|
||||
DEPENDENCIES_DIR=".."
|
||||
3
setup.sh
Normal file → Executable file
3
setup.sh
Normal file → Executable file
@ -66,9 +66,12 @@ if [ -f "$bootstrap_install_path" ]; then
|
||||
local_bootstrap_version_int=$(echo $local_bootstrap_version | sed 's/\.//g')
|
||||
|
||||
if [[ $local_bootstrap_version_int > $installed_bootstrap_version_int ]]; then
|
||||
echo "Found outdated bootstrap.sh in '$CBUILD_INSTALL_DIR', updating"
|
||||
ln -sf "$(realpath $CBUILD_INSTALL_DIR/bootstrap.sh)" -T "$bootstrap_install_path"
|
||||
fi
|
||||
else
|
||||
echo "Not found bootstrap.sh in '$CBUILD_INSTALL_DIR', installing"
|
||||
ln -sf "$(realpath $CBUILD_INSTALL_DIR/bootstrap.sh)" -T "$bootstrap_install_path"
|
||||
fi
|
||||
echo "Link bootstrap.sh to $CBUILD_BIN_DIR"
|
||||
ln -sf "$(realpath $bootstrap_install_path)" -T "$CBUILD_BIN_DIR/cbuild"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user