Compare commits
50 Commits
023f0b1d40
...
2.3.2
| 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 | |||
| 912b348f57 | |||
| d3d7867736 | |||
| 4488776afe | |||
| 683414c59b | |||
| c7b590907d | |||
| 653d459999 | |||
| f0038dd7c7 | |||
| 4d06f57758 | |||
| fa15e15758 | |||
| d60c86ec3b | |||
| 1576021cf7 | |||
| 646773f574 | |||
| 3b7f72c8b3 | |||
| 144b333b60 | |||
| 0b5eed8b4c | |||
| 5c1b063399 | |||
| c5f8f6ee09 | |||
| 91dfc8bc74 | |||
| d021389637 | |||
| 9c4959d51e | |||
| 4fc62f65b4 | |||
| f4c12e9b0e | |||
| 4b4794e253 | |||
| 7d60219c33 | |||
| de9a63f84b | |||
| b7109ef9fa |
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# git add --renormalize .
|
||||
*.sh text eol=lf
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -9,10 +9,6 @@ obj/
|
||||
*.user
|
||||
*.vcxproj.filters
|
||||
|
||||
# local cbuild config giles
|
||||
current.config
|
||||
*.current.config
|
||||
|
||||
# other files
|
||||
.old*/
|
||||
old/
|
||||
|
||||
1
CBUILD_VERSION
Normal file
1
CBUILD_VERSION
Normal file
@@ -0,0 +1 @@
|
||||
2.3.2
|
||||
86
CHANGELOG.md
86
CHANGELOG.md
@@ -1,10 +1,78 @@
|
||||
# v2.0.1
|
||||
+ fixed bugs in `myprint.sh`, `--new-project`, task execution
|
||||
+ updated `.gitignore`
|
||||
+ added `pwd` call to `valgrind` task in config
|
||||
+ added `""` empty task check in config
|
||||
## 2.3.2
|
||||
+ fixed symlink creation in `OBJDIR/static_libs`
|
||||
|
||||
# 2.0.0
|
||||
## 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
|
||||
|
||||
## 2.2.0
|
||||
+ **config**: removed slash after `--fullpath-after` in `VALGRIND_ARGS`
|
||||
+ **config**: removed `CONFIG_VERSION` variable
|
||||
+ **config**: added `LINKER_LIBS` variable
|
||||
+ added `detect_arch` function and `ARCH` global variable
|
||||
+ added [default vscode launch config](./default_vscode/)
|
||||
+ refactored `sed` calls to not use `-i` argument because it caused errors on NTFS
|
||||
|
||||
## v2.1.4
|
||||
+ added `-Wl,-rpath` argument generation in `link()`. It forces ld to link to local shared library in `OUTDIR`
|
||||
|
||||
## v2.1.3
|
||||
+ added `DEP_OTHER_OUT_FILES` to dependency configs
|
||||
+ if `PRESERVE_OUT_DIRECTORY_STRUCTURE=true` then `DEP_DYNAMIC_OUT_FILES` and `DEP_OTHER_OUT_FILES` are copied to `OUTDIR` preserving directory structure (example_dir/lib1.so -> $OUTDIR/example_dir/lib1.so)
|
||||
|
||||
## v2.1.2
|
||||
+ changed compile_c and compile_cpp functions
|
||||
+ bootstrap now can print help and list of installed versions
|
||||
|
||||
## v2.1.1
|
||||
+ **config**: removed `TESTS_C` and `TESTS_CPP` compilation
|
||||
|
||||
## v2.1.0
|
||||
+ **config**: no more `current.config` and `default.config`, just `project.config`
|
||||
+ improved version checking
|
||||
+ `setup.sh` now installs each minor version in separate dicectory
|
||||
+ added `bootstrap.sh` which automaticly selects cbuild version specified in project config
|
||||
|
||||
## v2.0.2
|
||||
+ new dependency resolution system (see **config** and `example_dependency_configs`)
|
||||
+ **config**: changed description of `OBJDIR`
|
||||
+ **config**: added task `rebuild_dependencies`
|
||||
+ added variable `TASK_ARGS` which can be used in task scripts
|
||||
|
||||
## v2.0.1
|
||||
+ updated `.gitignore`
|
||||
+ **config**: added `pwd` call to `valgrind` task
|
||||
+ **config**: added `""` empty task check
|
||||
|
||||
## 2.0.0
|
||||
+ updated setup.sh to do system-wide installation
|
||||
+ deleted makefile (call `./cbuild.sh` or installed `cbuild`)
|
||||
+ added command line arguments:
|
||||
@@ -17,7 +85,7 @@
|
||||
+ `init.sh` became `config.sh` with function `load_config`
|
||||
+ moved color variables and print functions to `myprint.sh`
|
||||
|
||||
# v1.7.0
|
||||
## v1.7.0
|
||||
+ added function `resolve_dependencies` to `link`
|
||||
+ added variables `DEPS_BASEDIR` and `DEPS` to config
|
||||
+ added script `rebuild_dep.sh` which can be called through `Makefile`
|
||||
@@ -26,7 +94,7 @@
|
||||
+ added task `no_task` which is been set in `init.sh` when `TASK` is empty
|
||||
+ now `STATIC_LIB_FILE` starts with "lib"
|
||||
|
||||
# v1.6.0
|
||||
## v1.6.0
|
||||
+ `build_profile` task was split to `profile` and `gprof`
|
||||
+ added task `sanitize`
|
||||
+ default C++ standard set to `c++11`
|
||||
@@ -35,7 +103,7 @@
|
||||
+ added function `try_delete_dir_or_file` for `clean` task
|
||||
+ dead code removal in `build_exec` and `build_static_lib`
|
||||
|
||||
# v1.5.0
|
||||
## v1.5.0
|
||||
+ added task `clean`
|
||||
+ added task `exec_dbg`
|
||||
+ added task `build_profile`
|
||||
|
||||
22
README.md
22
README.md
@@ -1,23 +1,31 @@
|
||||
# cbuild
|
||||
My C/C++ build system written in bash.
|
||||
My C/C++ build system written in sh.
|
||||
|
||||
|
||||
## Installation
|
||||
```bash
|
||||
git clone https://timerix.ddns.net:3322/cbuild.git
|
||||
```sh
|
||||
git clone https://timerix.ddns.net:3322/Timerix/cbuild.git
|
||||
cd cbuild
|
||||
sudo ./setup.sh
|
||||
```
|
||||
Can be installed to `~/.local/` if you have no root rights.
|
||||
- ```sh
|
||||
./setup.sh --local
|
||||
```
|
||||
- Then add `~/.local/bin` to `PATH` in your shell config.
|
||||
|
||||
## Usage
|
||||
1. Initialize cbuild project in some directory:
|
||||
```bash
|
||||
```sh
|
||||
cd some_project
|
||||
cbuild --new-project
|
||||
```
|
||||
|
||||
2. Edit `default.config`.
|
||||
2. Edit `project.config`.
|
||||
3. Call some tasks:
|
||||
```bash
|
||||
```sh
|
||||
cbuild build_exec_dbg exec
|
||||
```
|
||||
P.S. See help
|
||||
```sh
|
||||
cbuild -h
|
||||
```
|
||||
|
||||
125
bootstrap.sh
Executable file
125
bootstrap.sh
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_BOOTSTRAP_VERSION=1.0.3
|
||||
set -eo pipefail
|
||||
|
||||
function version_parse {
|
||||
local value="$1"
|
||||
var_name="$2"
|
||||
IFS_backup="$IFS"
|
||||
IFS='.'
|
||||
local v_array=($value)
|
||||
IFS="$IFS_backup"
|
||||
eval ${var_name}_version_major=${v_array[0]}
|
||||
eval ${var_name}_version_minor=${v_array[1]}
|
||||
eval ${var_name}_version_patch=${v_array[2]}
|
||||
}
|
||||
|
||||
function safeprint {
|
||||
printf "%s" "$@"
|
||||
}
|
||||
|
||||
function exec_script_line {
|
||||
local script="$1"
|
||||
local line_num="$2"
|
||||
local line_str="$(sed $line_num'!d' $script)"
|
||||
if [ -z "$line_str" ]; then
|
||||
echo "script line is empty"
|
||||
exit 1
|
||||
fi
|
||||
eval "$line_str"
|
||||
}
|
||||
|
||||
function print_version_list {
|
||||
dir_local="$HOME/.local/share/cbuild"
|
||||
dir_global="/usr/local/share/cbuild"
|
||||
files=""
|
||||
if [ -d "$dir_local" ]; then
|
||||
files+=$(find "$dir_local" -maxdepth 2 -name 'CBUILD_VERSION')
|
||||
fi
|
||||
if [ -d "$dir_global" ]; then
|
||||
files+=$(find "$dir_global" -maxdepth 2 -name 'CBUILD_VERSION')
|
||||
fi
|
||||
for f in $files; do
|
||||
cat $f
|
||||
echo " at $(dirname $f)"
|
||||
done | sort -V
|
||||
}
|
||||
|
||||
function print_help {
|
||||
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
|
||||
echo "Script that launches a specific cbuild version selected by user or defined in a project config."
|
||||
echo "Usage: cbuild [OPTIONS]"
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this message"
|
||||
echo " -v, --version Shows version"
|
||||
echo " -c, --config FILE Set project config file path (default=./project.config)"
|
||||
echo " --list-versions Shows list of installed cbuild versions"
|
||||
}
|
||||
|
||||
# parse command line arguments
|
||||
project_config_path="./project.config"
|
||||
args=($@)
|
||||
args_count=${#args[@]}
|
||||
i=0
|
||||
if [ $args_count -eq 0 ]; then
|
||||
print_help
|
||||
fi
|
||||
while [ $i -lt $args_count ]
|
||||
do
|
||||
case "${args[i]}" in
|
||||
'-v' | '--version')
|
||||
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
|
||||
echo "list of installed cbuild versions:"
|
||||
print_version_list
|
||||
exit 0
|
||||
;;
|
||||
'-h' | '--help')
|
||||
print_help
|
||||
;;
|
||||
'-c' | '--config')
|
||||
i=$((i+1))
|
||||
project_config_path="${args[i]}"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
if [ -z "$CBUILD_VERSION" ]; then
|
||||
if [ -f "$project_config_path" ]; then
|
||||
# read version from project config
|
||||
exec_script_line "$project_config_path" 2
|
||||
else
|
||||
echo "project config not found"
|
||||
echo "list of installed cbuild versions:"
|
||||
print_version_list
|
||||
# cut installation directories from list
|
||||
versions=$(print_version_list | cut -d ' ' -f 1)
|
||||
latest_version=$(echo "$versions" | tail -n 1)
|
||||
echo "select version (default=$latest_version):"
|
||||
read -r CBUILD_VERSION
|
||||
[ -z "$CBUILD_VERSION" ] && CBUILD_VERSION=$latest_version
|
||||
fi
|
||||
fi
|
||||
|
||||
version_parse "$CBUILD_VERSION"
|
||||
cbuild_ommand="cbuild${_version_major}.${_version_minor} $@"
|
||||
|
||||
LOG_FILE="$(realpath cbuild.log)"
|
||||
set +eo pipefail
|
||||
# enable logging stdout and stderr to file
|
||||
$cbuild_ommand 2>&1 | tee "$LOG_FILE"
|
||||
# log file can be deleted by clean task
|
||||
if [ -f "$LOG_FILE" ]; then
|
||||
# remove terminal escape codes
|
||||
sed -e 's/[^[:blank:][:print:]]//g' \
|
||||
-e 's/\[0;[0-9][0-9]m//g' \
|
||||
-e 's/\[0;[0-9]m//g' \
|
||||
-e 's/\[[0-9][0-9]m//g' \
|
||||
-e 's/\[[0-9]m//g' \
|
||||
-e 's/ H //g' \
|
||||
-e 's/\[3gH //g' \
|
||||
"$LOG_FILE" > "$LOG_FILE.clean"
|
||||
mv "$LOG_FILE.clean" "$LOG_FILE"
|
||||
fi
|
||||
166
cbuild.sh
Normal file → Executable file
166
cbuild.sh
Normal file → Executable file
@@ -1,88 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
INSTALLED_CBUILD_VERSION=2.3.2
|
||||
|
||||
# set \t size to 4 spaces
|
||||
tabs 4
|
||||
|
||||
# exit on errors
|
||||
set -eo pipefail
|
||||
|
||||
INSTALLED_CBUILD_VERSION=2.0.1
|
||||
function version_parse {
|
||||
local value="$1"
|
||||
var_name="$2"
|
||||
IFS_backup="$IFS"
|
||||
IFS='.'
|
||||
local v_array=($value)
|
||||
IFS="$IFS_backup"
|
||||
eval ${var_name}_version_major=${v_array[0]}
|
||||
eval ${var_name}_version_minor=${v_array[1]}
|
||||
eval ${var_name}_version_patch=${v_array[2]}
|
||||
}
|
||||
|
||||
version_parse $INSTALLED_CBUILD_VERSION installed
|
||||
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
||||
CBUILD_INSTALL_DIR="$HOME/.local/share/cbuild/${installed_version_major}.${installed_version_minor}"
|
||||
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
|
||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${installed_version_major}.${installed_version_minor}"
|
||||
if [ ! -f "$CBUILD_INSTALL_DIR/cbuild.sh" ]; then
|
||||
echo "CBUILD_INSTALL_DIR '$CBUILD_INSTALL_DIR' doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
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] [TASK]"
|
||||
myprint " -h, --help Show this message"
|
||||
myprint " -v, --version Shows version"
|
||||
myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)"
|
||||
myprint " -c, --current-config FILE Set current config file path (default=./current.config)"
|
||||
myprint " -d, --default-config FILE Set default config file path (default=./current.config)"
|
||||
myprint "Usage: cbuild [OPTIONS] [TASKS]"
|
||||
myprint "Options:"
|
||||
myprint " -h, --help Show this message"
|
||||
myprint " -v, --version Shows version"
|
||||
myprint " -c, --config FILE Set project config file path (default=./project.config)"
|
||||
myprint " -n, --new-project [DIR] Initialize new cbuild project directory (default=./)"
|
||||
}
|
||||
|
||||
current_config_path="./current.config"
|
||||
default_config_path="./default.config"
|
||||
# parse command line arguments
|
||||
project_config_path="./project.config"
|
||||
args=($@)
|
||||
args_count=${#args[@]}
|
||||
selected_tasks_array=()
|
||||
i=0
|
||||
if [ $args_count -eq 0 ]; then
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function get_next_arg {
|
||||
i=$((i+1))
|
||||
safeprint "${args[i]}"
|
||||
}
|
||||
|
||||
while [ $i -lt $args_count ]
|
||||
do
|
||||
case "${args[i]}" in
|
||||
'-h' | '--help')
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
'-v' | '--version')
|
||||
myprint $INSTALLED_CBUILD_VERSION
|
||||
myprint "${GRAY}cbuild v$INSTALLED_CBUILD_VERSION"
|
||||
exit 0
|
||||
;;
|
||||
'-c' | '--current-config')
|
||||
'-c' | '--config')
|
||||
i=$((i+1))
|
||||
current_config_path="${args[i]}"
|
||||
myprint "<$current_config_path>"
|
||||
exit
|
||||
;;
|
||||
'-d' | '--default-config')
|
||||
default_config_path="$(get_next_arg)"
|
||||
project_config_path="${args[i]}"
|
||||
;;
|
||||
'-n' | '--new-project')
|
||||
new_project_dir="$(get_next_arg)"
|
||||
i=$((i+1))
|
||||
new_project_dir="${args[i]}"
|
||||
if [ -z "$new_project_dir" ]; then
|
||||
new_project_dir="./"
|
||||
new_project_dir="."
|
||||
else
|
||||
mkdir -p "$new_project_dir"
|
||||
fi
|
||||
|
||||
if ask_yn "create default.config?"; then
|
||||
cp "$CBUILD_INSTALL_DIR/default.config" "$new_project_dir"
|
||||
myprint "Enter project name: "
|
||||
read -r project_name
|
||||
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "default.config"
|
||||
|
||||
# create project config
|
||||
project_config_path="$new_project_dir/project.config"
|
||||
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 '$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 "${WHITE}Copy default .gitignore?"; then
|
||||
cp -v "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
|
||||
fi
|
||||
if ask_yn "Copy default .gitignore?"; then
|
||||
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir"
|
||||
|
||||
if ask_yn "${WHITE}Copy default .vscode launch tasks?"; then
|
||||
new_project_vscode_dir="$new_project_dir/.vscode"
|
||||
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"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
selected_tasks_array+=(${args[i]})
|
||||
@@ -92,51 +129,48 @@ do
|
||||
done
|
||||
|
||||
function call_task {
|
||||
local current_config_path="$1"
|
||||
local default_config_path="$2"
|
||||
local task="$3"
|
||||
local project_config_path="$1"
|
||||
local task="$2"
|
||||
TASK_ARGS="$3"
|
||||
|
||||
print_header "${CYAN}" "─" "$task"
|
||||
load_config "$current_config_path" "$default_config_path" "$task"
|
||||
resolve_dependencies "$DEPS_BASEDIR" "$DEPS"
|
||||
print_header "${CYAN}" "─" "$PROJECT/$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"
|
||||
include "$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
|
||||
}
|
||||
|
||||
function call_tasks {
|
||||
local tasks="$@"
|
||||
load_config "$current_config_path" "$default_config_path"
|
||||
load_config "$project_config_path" "" false
|
||||
print_header "${WHITE}" "═" "$PROJECT"
|
||||
for task in $tasks ; do
|
||||
call_task "$current_config_path" "$default_config_path" "$task"
|
||||
project_dir="$(pwd)"
|
||||
for task_str in $tasks ; do
|
||||
task=$(safeprint "$task_str" | sed 's/=.*//g')
|
||||
local args_str=$(safeprint "$task_str" | grep -oP '(?<=\=).*' || echo "")
|
||||
IFS_backup="$IFS"
|
||||
IFS=',;'
|
||||
args_array=($args_str)
|
||||
IFS="$IFS_backup"
|
||||
call_task "$project_config_path" "$task" "${args_array[@]}"
|
||||
cd "$project_dir"
|
||||
done
|
||||
print_hline "${WHITE}" "═"
|
||||
}
|
||||
|
||||
print_hline "${WHITE}" "═"
|
||||
selected_tasks_count=${#selected_tasks_array[@]}
|
||||
if [ $selected_tasks_count -gt 0 ]; then
|
||||
time call_tasks "${selected_tasks_array[@]}" #2>&1 | tee cbuild.log
|
||||
call_tasks "${selected_tasks_array[@]}"
|
||||
fi
|
||||
|
||||
if [ -f cbuild.log ]; then
|
||||
# remove terminal escape codes
|
||||
sed -e 's/[^[:blank:][:print:]]//g' \
|
||||
-e 's/\[0;[0-9][0-9]m//g' \
|
||||
-e 's/\[0;[0-9]m//g' \
|
||||
-e 's/\[[0-9][0-9]m//g' \
|
||||
-e 's/\[[0-9]m//g' \
|
||||
-e 's/ H //g' \
|
||||
-e 's/\[3gH //g' \
|
||||
-i cbuild.log
|
||||
fi
|
||||
80
config.sh
80
config.sh
@@ -1,80 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include cbuild/myprint.sh
|
||||
include cbuild/functions.sh
|
||||
include cbuild/detect_os.sh
|
||||
|
||||
function load_config {
|
||||
local current_config_path="$1"
|
||||
local default_config_path="$2"
|
||||
TASK="$3"
|
||||
if [ -z "$current_config_path" ]; then
|
||||
error "current_config_path is null"
|
||||
fi
|
||||
if [ -z "$default_config_path" ]; then
|
||||
error "default_config_path is null"
|
||||
fi
|
||||
|
||||
OS=$(detect_os)
|
||||
myprint "${GREEN}detected OS: $OS"
|
||||
|
||||
function exec_script_line {
|
||||
local script="$1"
|
||||
local line_num="$2"
|
||||
myprint "${BLUE}reading line $line_num from $script"
|
||||
local line_str="$(sed $line_num'!d' $script)"
|
||||
myprint "$line_str"
|
||||
eval "$line_str"
|
||||
}
|
||||
|
||||
# getting version of cbuild installation
|
||||
if [ -z "$INSTALLED_CBUILD_VERSION" ]; then
|
||||
error "couldnt get current cbuild installation version"
|
||||
fi
|
||||
|
||||
# getting version of default config
|
||||
exec_script_line "$default_config_path" 3
|
||||
DEFAULT_CONFIG_VERSION="$CONFIG_VERSION"
|
||||
unset CONFIG_VERSION
|
||||
|
||||
# undefined task
|
||||
[ -z "$TASK" ] && TASK="no_task"
|
||||
|
||||
# error on undefined
|
||||
set -u
|
||||
|
||||
# reading current config or creating default
|
||||
if [ ! -f "$current_config_path" ]; then
|
||||
myprint "${YELLOW}$current_config_path doesn't exist"
|
||||
cp "$default_config_path" "$current_config_path"
|
||||
myprint "${YELLOW}Created copy (${current_config_path}) of default config (${default_config_path})"
|
||||
fi
|
||||
|
||||
myprint "${BLUE}reading $current_config_path"
|
||||
include "$current_config_path"
|
||||
|
||||
myprint "${WHITE}project: ${CYAN}$PROJECT"
|
||||
|
||||
myprint "${WHITE}${current_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
||||
myprint "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
||||
myprint "${WHITE}${current_config_path} version: ${CYAN}$CONFIG_VERSION"
|
||||
myprint "${WHITE}${default_config_path} version: ${CYAN}$DEFAULT_CONFIG_VERSION"
|
||||
|
||||
# checking versions
|
||||
if [ ! "$CBUILD_VERSION" -eq "$INSTALLED_CBUILD_VERSION" ]; then
|
||||
error "config was created for outdated cbuild version"
|
||||
fi
|
||||
if [ ! "$CONFIG_VERSION" -eq "$DEFAULT_CONFIG_VERSION" ]; then
|
||||
error "config version isn't correct"
|
||||
fi
|
||||
|
||||
mkdir -p "$OUTDIR"
|
||||
mkdir -p "$OBJDIR/libs"
|
||||
mkdir -p "$OBJDIR/objects"
|
||||
mkdir -p "$OBJDIR/profile"
|
||||
|
||||
# dont thorw error on undefined variable
|
||||
set +u
|
||||
|
||||
myprint "${GREEN}cbuild initialized!"
|
||||
}
|
||||
@@ -15,6 +15,6 @@ else
|
||||
done
|
||||
fi
|
||||
|
||||
compile_c "$C_ARGS" "$SRC_C $TESTS_C"
|
||||
compile_cpp "$CPP_ARGS" "$SRC_CPP $TESTS_CPP"
|
||||
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||
link "$LINKER_ARGS" "$EXEC_FILE"
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
# delete old objects
|
||||
clean_dir "$OBJDIR/objects"
|
||||
compile_c "$C_ARGS" "$SRC_C"
|
||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
||||
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||
link "$LINKER_ARGS" "$SHARED_LIB_FILE"
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
# delete old objects
|
||||
clean_dir "$OBJDIR/objects"
|
||||
compile_c "$C_ARGS" "$SRC_C"
|
||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
||||
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||
pack_static_lib "$STATIC_LIB_FILE"
|
||||
|
||||
0
default_tasks/callgrind.sh
Normal file → Executable file
0
default_tasks/callgrind.sh
Normal file → Executable file
23
default_tasks/clean.sh
Normal file → Executable file
23
default_tasks/clean.sh
Normal file → Executable file
@@ -5,21 +5,10 @@ try_delete_dir_or_file "$OUTDIR"
|
||||
myprint "${WHITE}deleting build logs"
|
||||
rm -rf *.log
|
||||
|
||||
for tmpfile in $(ls -a | grep -e '\.rebuild.*\.tmp'); do
|
||||
try_delete_dir_or_file "$tmpfile"
|
||||
project_dir="$(pwd)"
|
||||
for dep in $ENABLED_DEPENDENCIES; do
|
||||
load_dependency_config "$DEPENDENCY_CONFIGS_DIR/$dep.config"
|
||||
cd "$DEP_WORKING_DIR"
|
||||
exec_command "$DEP_CLEAN_COMMAND"
|
||||
cd "$project_dir"
|
||||
done
|
||||
|
||||
set +e
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n'
|
||||
cd "$DEPS_BASEDIR"
|
||||
for dep in $DEPS; do
|
||||
dep_dir=$(safeprint ${dep/=*/} | tr -d '[:blank:]')
|
||||
print_header "${CYAN}" "─" "$dep_dir"
|
||||
cd "$dep_dir"
|
||||
make clean
|
||||
cd ..
|
||||
done
|
||||
IFS="$OLDIFS"
|
||||
cd ..
|
||||
set -e
|
||||
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
11
default_tasks/rebuild_dependencies.sh
Executable file
11
default_tasks/rebuild_dependencies.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
dependencies="$TASK_ARGS"
|
||||
if [ "$dependencies" = 'all' ]; then
|
||||
dependencies="$ENABLED_DEPENDENCIES"
|
||||
fi
|
||||
if [ ! -z "$dependencies" ]; then
|
||||
myprint "${BLUE}dependencies to be rebuild: $dependencies"
|
||||
build_dependencies "$dependencies" true
|
||||
else
|
||||
myprint "${YELLOW}no dependencies specified"
|
||||
fi
|
||||
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"
|
||||
1
default_vscode/.gitignore
vendored
Normal file
1
default_vscode/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
settings.json
|
||||
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
|
||||
}
|
||||
29
default_vscode/launch.json
Normal file
29
default_vscode/launch.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "gdb_debug",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/bin/%PROJECT_NAME%",
|
||||
"windows": { "program": "${workspaceFolder}/bin/%PROJECT_NAME%.exe" },
|
||||
"preLaunchTask": "build_exec_dbg",
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}/bin",
|
||||
"externalConsole": false,
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
31
default_vscode/tasks.json
Normal file
31
default_vscode/tasks.json
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build_exec_dbg",
|
||||
"detail": "build project with debug symbols",
|
||||
"type": "cppbuild",
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"cbuild build_exec_dbg"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": ["$gcc"],
|
||||
"group": {
|
||||
"kind": "build"
|
||||
},
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": true,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false,
|
||||
"clear": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
25
detect_os.sh
25
detect_os.sh
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "cbuild/myprint.sh"
|
||||
|
||||
function detect_os {
|
||||
local uname_rezult="$(uname -o)"
|
||||
# myprint "uname rezult: '$uname_rezult'"
|
||||
case "$uname_rezult" in
|
||||
Msys | Cygwin | MS/Windows)
|
||||
safeprint WINDOWS
|
||||
;;
|
||||
Linux | GNU/Linux | Android)
|
||||
safeprint LINUX
|
||||
;;
|
||||
FreeBSD)
|
||||
safeprint FREEBSD
|
||||
;;
|
||||
Darwin)
|
||||
safeprint MACOS
|
||||
;;
|
||||
*)
|
||||
error "unknown operating system: $uname_rezult"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
13
example_dependency_configs/libexample1.config
Executable file
13
example_dependency_configs/libexample1.config
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
DEP_WORKING_DIR='dependencies/libexample1'
|
||||
DEP_PRE_BUILD_COMMAND=''
|
||||
DEP_BUILD_COMMAND='make libexample1.a'
|
||||
DEP_POST_BUILD_COMMAND=''
|
||||
DEP_CLEAN_COMMAND='make clean'
|
||||
# won't be copied to project $OUTDIR
|
||||
DEP_STATIC_OUT_FILES='libexample1.a libexample1_addon.a'
|
||||
PRESERVE_OUT_DIRECTORY_STRUCTURE=false;
|
||||
# will be copied to project $OUTDIR
|
||||
DEP_DYNAMIC_OUT_FILES='libexample1.config.json'
|
||||
# will be copied to project $OUTDIR
|
||||
DEP_OTHER_OUT_FILES=''
|
||||
22
example_dependency_configs/libexample2.config
Executable file
22
example_dependency_configs/libexample2.config
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
DEP_WORKING_DIR='dependencies/libexample2'
|
||||
DEP_PRE_BUILD_COMMAND=''
|
||||
DEP_POST_BUILD_COMMAND=''
|
||||
DEP_CLEAN_COMMAND='make clean'
|
||||
DEP_STATIC_OUT_FILES=''
|
||||
DEP_OTHER_OUT_FILES=''
|
||||
case $OS in
|
||||
WINDOWS)
|
||||
DEP_BUILD_COMMAND='make libexample2.dll && mkdir -p win-x64 && mv libexample.dll win-x64'
|
||||
DEP_DYNAMIC_OUT_FILES='win-x64/libexample2.dll'
|
||||
PRESERVE_OUT_DIRECTORY_STRUCTURE=true # library will be copied to $OUTDIR/win-x64
|
||||
;;
|
||||
LINUX)
|
||||
DEP_BUILD_COMMAND='make libexample2.so && mkdir -p linux-x64 && mv libexample.so linux-x64'
|
||||
DEP_DYNAMIC_OUT_FILES='linux-x64/libexample2.so'
|
||||
PRESERVE_OUT_DIRECTORY_STRUCTURE=true # library will be copied to $OUTDIR/linux-x64
|
||||
;;
|
||||
*)
|
||||
error "operating system $OS has no configuration variants"
|
||||
;;
|
||||
esac
|
||||
145
functions.sh
145
functions.sh
@@ -1,145 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "cbuild/myprint.sh"
|
||||
|
||||
function clean_dir {
|
||||
local dir="$1"
|
||||
myprint "${WHITE}cleaning $dir"
|
||||
rm -rf "$dir"
|
||||
mkdir "$dir"
|
||||
}
|
||||
|
||||
function delete_dir {
|
||||
local dir="$1"
|
||||
myprint "${WHITE}deleting $dir"
|
||||
rm -rf "$dir"
|
||||
}
|
||||
|
||||
function try_delete_dir_or_file {
|
||||
local path="$1"
|
||||
if [ -f "$path" ] || [ -d "$path" ]; then
|
||||
rm -rf "$path"
|
||||
myprint "${WHITE}deleting $path"
|
||||
fi
|
||||
}
|
||||
|
||||
function compile {
|
||||
local cmp="$1"
|
||||
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
||||
local std="$2"
|
||||
myprint "${BLUE}standard: ${GRAY}$std"
|
||||
local warn="$3"
|
||||
myprint "${BLUE}warnings: ${GRAY}$warn"
|
||||
local args="$4"
|
||||
myprint "${BLUE}args: ${GRAY}$args"
|
||||
local include="$5"
|
||||
myprint "${BLUE}include dirs: ${GRAY}$include"
|
||||
local sources="$6"
|
||||
myprint "${BLUE}sources: ${GRAY}$sources"
|
||||
for srcfile in $sources
|
||||
do (
|
||||
local object="$OBJDIR/objects/$(basename $srcfile).o"
|
||||
if ! $($cmp -std=$std $warn $args $include -c -o $object $srcfile)
|
||||
then
|
||||
error "some error happened"
|
||||
# TODO stop all threads
|
||||
fi
|
||||
) & done
|
||||
wait
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_c {
|
||||
print_header "${CYAN}" "─" "compile_c"
|
||||
compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$INCLUDE" "$2"
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_cpp {
|
||||
print_header "${CYAN}" "─" "compile_cpp"
|
||||
compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$INCLUDE" "$2"
|
||||
}
|
||||
|
||||
# (outfile)
|
||||
function pack_static_lib {
|
||||
print_header "${CYAN}" "─" "pack_static_lib"
|
||||
local outfile="$1"
|
||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||
local objects="$(find $OBJDIR/objects -name *.o)
|
||||
$(find $OBJDIR/libs -name '*.a')"
|
||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||
if ar rcs "$OUTDIR/$outfile" $(safeprint "$objects" | tr '\n' ' ')
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
else
|
||||
error "some error happened"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# if $lib_file doesn't exist or rebuild_* task was executed, builds static lib
|
||||
function handle_static_dependency {
|
||||
local deps_basedir="${1%/}"
|
||||
local lib_project_dir="$2"
|
||||
local lib_build_task="$3"
|
||||
local lib_build_dir="$4"
|
||||
local lib_file="$5"
|
||||
if [ ! -f "$OBJDIR/libs/$lib_file" ] || [ -f .rebuild_$lib_file.tmp ]; then
|
||||
[[ -z "$lib_build_task" ]] && error "lib_build_task is empty"
|
||||
myprint "${BLUE}making $lib_file by task $lib_build_task"
|
||||
|
||||
local proj_root_dir="$(pwd)"
|
||||
cd "$deps_basedir/$lib_project_dir"
|
||||
if ! make "$lib_build_task"; then
|
||||
exit 1
|
||||
fi
|
||||
cd "$proj_root_dir"
|
||||
|
||||
cp "$deps_basedir/$lib_project_dir/$lib_build_dir/$lib_file" "$OBJDIR/libs/"
|
||||
myprint "${GREEN}copied ${CYAN}$lib_file to $OBJDIR/libs/"
|
||||
rm -f .rebuild_$lib_file.tmp
|
||||
fi
|
||||
}
|
||||
|
||||
function resolve_dependencies {
|
||||
deps_basedir=$1
|
||||
deps=$2
|
||||
[[ -z "$deps_basedir" ]] && deps_basedir="."
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n'
|
||||
# Evalueting dependency expressions.
|
||||
# Necessary for overriding dependency configurations.
|
||||
for dep in $deps; do
|
||||
eval $dep
|
||||
done
|
||||
# handling dependencies
|
||||
for dep in $deps; do
|
||||
IFS="$OLDIFS"
|
||||
dep_dir=$(safeprint ${dep/=*/} | tr -d '[:blank:]')
|
||||
eval 'dep_params=$'$dep_dir
|
||||
f_args="$deps_basedir $dep_dir $dep_params"
|
||||
myprint "${BLUE}resolving dependency ${WHITE}$dep_dir${BLUE}: ${GRAY}$f_args"
|
||||
handle_static_dependency $f_args
|
||||
IFS=$'\n'
|
||||
done
|
||||
IFS="$OLDIFS"
|
||||
}
|
||||
|
||||
function link {
|
||||
print_header "${CYAN}" "─" "link"
|
||||
local args="$1"
|
||||
local outfile="$2"
|
||||
myprint "${BLUE}args: ${GRAY}$args"
|
||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||
local objects="$(find $OBJDIR/objects -name '*.o')
|
||||
$(find $OBJDIR/libs -name '*.a')"
|
||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||
local command="$CMP_CPP $(safeprint "$objects" | tr '\n' ' ') $args -o $OUTDIR/$outfile"
|
||||
myprint "$command"
|
||||
if $command
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
else
|
||||
error "some error happened"
|
||||
fi
|
||||
}
|
||||
73
include/config.sh
Executable file
73
include/config.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "@cbuild/include/myprint.sh"
|
||||
include "@cbuild/include/functions.sh"
|
||||
include "@cbuild/include/detect_os.sh"
|
||||
|
||||
function load_config {
|
||||
local proj_conf_file="$1"
|
||||
TASK="$2"
|
||||
#true or false
|
||||
local quiet=$3
|
||||
|
||||
if [ -z "$proj_conf_file" ]; then
|
||||
error "config path is null"
|
||||
fi
|
||||
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"
|
||||
|
||||
# getting version of cbuild installation
|
||||
if [ -z "$INSTALLED_CBUILD_VERSION" ]; then
|
||||
error "couldnt get current cbuild installation version"
|
||||
fi
|
||||
|
||||
# undefined task
|
||||
[ -z "$TASK" ] && TASK="no_task"
|
||||
|
||||
# getting cbuild version from config (CBUILD_VERSION declaration is at line 2)
|
||||
exec_script_line "$proj_conf_file" 2 $quiet
|
||||
|
||||
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
|
||||
version_parse $INSTALLED_CBUILD_VERSION installed
|
||||
version_parse $CBUILD_VERSION config
|
||||
if [ "$installed_version_major.$installed_version_minor" != "$config_version_major.$config_version_minor" ]; then
|
||||
error "config was created for cbuild$config_version_major.$config_version_minor, but loaded whith cbuild$installed_version_major.$installed_version_minor which is incompatible"
|
||||
fi
|
||||
if [[ $installed_version_patch < $config_version_patch ]]; then
|
||||
myprint "${YELLOW}New patch for cbuild$installed_version_major.$installed_version_minor is abaliable."
|
||||
myprint "${YELLOW}Install it to get latest bugfixes."
|
||||
fi
|
||||
|
||||
set -u
|
||||
include "$proj_conf_file"
|
||||
|
||||
mkdir -p "$OUTDIR"
|
||||
mkdir -p "$OBJDIR/objects"
|
||||
mkdir -p "$OBJDIR/static_libs"
|
||||
mkdir -p "$OBJDIR/dynamic_libs"
|
||||
mkdir -p "$OBJDIR/profile"
|
||||
|
||||
set +u
|
||||
|
||||
myprint_quiet $quiet "${GREEN}config loading completed"
|
||||
}
|
||||
45
include/detect_os.sh
Executable file
45
include/detect_os.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
include "@cbuild/include/myprint.sh"
|
||||
|
||||
function detect_os {
|
||||
local uname_result="$(uname -o)"
|
||||
case "$uname_result" in
|
||||
Msys | Cygwin | MS/Windows)
|
||||
safeprint WINDOWS
|
||||
;;
|
||||
Linux | GNU/Linux | Android)
|
||||
safeprint LINUX
|
||||
;;
|
||||
FreeBSD)
|
||||
safeprint FREEBSD
|
||||
;;
|
||||
Darwin)
|
||||
safeprint MACOS
|
||||
;;
|
||||
*)
|
||||
error "unknown operating system: $uname_result"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function detect_arch {
|
||||
local uname_result="$(uname -m)"
|
||||
case "$uname_result" in
|
||||
arm | arm32 | armhf | aarch32)
|
||||
safeprint arm32
|
||||
;;
|
||||
arm64 | aarch64 | aarch64_be | armv8b | armv8l)
|
||||
safeprint arm64
|
||||
;;
|
||||
x86 | i386 | i486 | i686)
|
||||
safeprint x86
|
||||
;;
|
||||
x64 | x86_64 | amd64)
|
||||
safeprint x64
|
||||
;;
|
||||
*)
|
||||
error "unknown CPU architecture: $uname_result"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
283
include/functions.sh
Executable file
283
include/functions.sh
Executable file
@@ -0,0 +1,283 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
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
|
||||
error "script line is empty"
|
||||
fi
|
||||
myprint_quiet $quiet "$line_str"
|
||||
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 "${BLUE}cleaning ${WHITE}'$dir'"
|
||||
rm -rf "$dir"
|
||||
mkdir "$dir"
|
||||
}
|
||||
|
||||
function delete_dir {
|
||||
local dir="$1"
|
||||
myprint "${BLUE}deleting ${WHITE}'$dir'"
|
||||
rm -rf "$dir"
|
||||
}
|
||||
|
||||
function try_delete_dir_or_file {
|
||||
local path="$1"
|
||||
if [ -f "$path" ] || [ -d "$path" ]; then
|
||||
rm -rf "$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
|
||||
}
|
||||
|
||||
function exec_command {
|
||||
local command="$@"
|
||||
if [ ! -z "$command" ]; then
|
||||
myprint "${GRAY}$command"
|
||||
$command || error "command returned eror"
|
||||
fi
|
||||
}
|
||||
|
||||
function load_dependency_config {
|
||||
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 dep_conf_file="$1"
|
||||
# true or false
|
||||
local force_build="$2"
|
||||
load_dependency_config "$dep_conf_file"
|
||||
|
||||
local proj_root_dir="$(pwd)"
|
||||
myprint "${BLUE}entering dependency directory '${DEP_WORKING_DIR}'"
|
||||
cd "$DEP_WORKING_DIR"
|
||||
|
||||
local build_needed="$force_build"
|
||||
if [ "$build_needed" != true ]; then
|
||||
for file in $DEP_STATIC_OUT_FILES $DEP_DYNAMIC_OUT_FILES $DEP_OTHER_OUT_FILES; do
|
||||
if [ ! -f "$file" ]; then
|
||||
myprint "${GRAY}missing file '$file'"
|
||||
local build_needed=true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$build_needed" = true ]; then
|
||||
exec_command "$DEP_PRE_BUILD_COMMAND"
|
||||
exec_command "$DEP_BUILD_COMMAND"
|
||||
exec_command "$DEP_POST_BUILD_COMMAND"
|
||||
myprint "${GRAY}dependency build finished"
|
||||
else
|
||||
myprint "${GRAY}dependency was built already"
|
||||
fi
|
||||
|
||||
if [ ! -z "$DEP_DYNAMIC_OUT_FILES" ]; then
|
||||
# copies each file to $OUTDIR and creates symbolic link in $OBJDIR/dynamic_libs
|
||||
for file in $DEP_DYNAMIC_OUT_FILES; do
|
||||
# doesnt return error if called not like this
|
||||
real_file=$(realpath $file)
|
||||
file_dir=$(dirname $file)
|
||||
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 -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/dynamic_libs/$file"
|
||||
else
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/"
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/dynamic_libs/"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ ! -z "$DEP_OTHER_OUT_FILES" ]; then
|
||||
# copies each file to $OUTDIR
|
||||
for file in $DEP_OTHER_OUT_FILES; do
|
||||
if [ "$PRESERVE_OUT_DIRECTORY_STRUCTURE" = true ]; then
|
||||
file_dir=$(dirname $file)
|
||||
mkdir -p "$proj_root_dir/$OUTDIR/$file_dir"
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||
else
|
||||
cp -v -u --preserve=timestamps "$file" "$proj_root_dir/$OUTDIR/"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ ! -z "$DEP_STATIC_OUT_FILES" ]; then
|
||||
# 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
|
||||
real_file=$(realpath $file)
|
||||
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/static_libs/"
|
||||
done
|
||||
fi
|
||||
|
||||
cd "$proj_root_dir"
|
||||
|
||||
# unsed all dependency config variables to not mess with next dependencies
|
||||
unset DEP_WORKING_DIR
|
||||
unset DEP_PRE_BUILD_COMMAND
|
||||
unset DEP_BUILD_COMMAND
|
||||
unset DEP_POST_BUILD_COMMAND
|
||||
unset DEP_CLEAN_COMMAND
|
||||
unset DEP_STATIC_OUT_FILES
|
||||
unset PRESERVE_OUT_DIRECTORY_STRUCTURE
|
||||
unset DEP_DYNAMIC_OUT_FILES
|
||||
unset DEP_OTHER_OUT_FILES
|
||||
}
|
||||
|
||||
function build_dependencies {
|
||||
local dependencies="$1"
|
||||
# true or false
|
||||
local force_build="$2"
|
||||
myprint "${BLUE}resolving dependencies"
|
||||
clean_dir "$OBJDIR/static_libs"
|
||||
clean_dir "$OBJDIR/dynamic_libs"
|
||||
for dep in $dependencies; do
|
||||
build_dependency "$DEPENDENCY_CONFIGS_DIR/$dep.config" "$force_build"
|
||||
done
|
||||
}
|
||||
|
||||
function compile {
|
||||
build_dependencies "$ENABLED_DEPENDENCIES"
|
||||
print_hline "${BLUE}" "─"
|
||||
|
||||
local cmp="$1"
|
||||
local std="$2"
|
||||
local warn="$3"
|
||||
local args="$4"
|
||||
local include="$5"
|
||||
local sources="$6"
|
||||
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
||||
myprint "${BLUE}standard: ${GRAY}$std"
|
||||
myprint "${BLUE}warnings: ${GRAY}$warn"
|
||||
myprint "${BLUE}args: ${GRAY}$args"
|
||||
myprint "${BLUE}include dirs: ${GRAY}$include"
|
||||
myprint "${BLUE}sources: ${GRAY}$sources"
|
||||
for srcfile in $sources
|
||||
do (
|
||||
local object="$OBJDIR/objects/$(basename $srcfile).o"
|
||||
if ! $($cmp -std=$std $warn $args $include -c -o $object $srcfile)
|
||||
then
|
||||
error "some error happened"
|
||||
# TODO stop all threads
|
||||
fi
|
||||
) & done
|
||||
wait
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_c {
|
||||
local cmp="$1"
|
||||
local std="$2"
|
||||
local warn="$3"
|
||||
local args="$4"
|
||||
local include="$5"
|
||||
local sources="$6"
|
||||
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_c"
|
||||
compile "$cmp" "$std" "$warn" "$args" "$include" "$sources"
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_cpp {
|
||||
local cmp="$1"
|
||||
local std="$2"
|
||||
local warn="$3"
|
||||
local args="$4"
|
||||
local include="$5"
|
||||
local sources="$6"
|
||||
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_cpp"
|
||||
compile "$cmp" "$std" "$warn" "$args" "$include" "$sources"
|
||||
}
|
||||
|
||||
# (outfile)
|
||||
function pack_static_lib {
|
||||
print_header "${CYAN}" "─" "$PROJECT/$TASK/pack_static_lib"
|
||||
local outfile="$1"
|
||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||
|
||||
local objects=$(find $OBJDIR/objects -type f,l | tr '\n' ' ')
|
||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||
if [ -z "$objects" ]; then
|
||||
error "no compiled objects found"
|
||||
fi
|
||||
|
||||
local command="ar rcs $OUTDIR/$outfile $objects"
|
||||
print_hline "${GRAY}" "─"
|
||||
myprint "${GRAY}$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
if $command
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
else
|
||||
error "some error happened"
|
||||
fi
|
||||
clean_dir "$OBJDIR/objects"
|
||||
}
|
||||
|
||||
function link {
|
||||
print_header "${CYAN}" "─" "$PROJECT/$TASK/link"
|
||||
local args="$1"
|
||||
local outfile="$2"
|
||||
myprint "${BLUE}args: ${GRAY}$args"
|
||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||
|
||||
local objects=$(find $OBJDIR/objects -type f,l | tr '\n' ' ')
|
||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||
if [ -z "$objects" ]; then
|
||||
error "no compiled objects found"
|
||||
fi
|
||||
|
||||
local static_libs=$(find $OBJDIR/static_libs -type f,l | tr '\n' ' ')
|
||||
myprint "${BLUE}static libraries: ${GRAY}$static_libs"
|
||||
|
||||
local dynamic_libs=$(find $OBJDIR/dynamic_libs -type f,l | tr '\n' ' '\
|
||||
| sed "s,$OBJDIR/dynamic_libs/,,g")
|
||||
myprint "${BLUE}dynamic libraries: ${GRAY}$dynamic_libs"
|
||||
local dynamic_libs_args="-L./$OBJDIR/dynamic_libs -Wl,-Bdynamic"
|
||||
for lib in $dynamic_libs; do
|
||||
dynamic_libs_args="$dynamic_libs_args -Wl,-rpath=$(dirname $lib) -l:$lib"
|
||||
done
|
||||
|
||||
local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile"
|
||||
print_hline "${GRAY}" "─"
|
||||
myprint "${GRAY}$command"
|
||||
print_hline "${GRAY}" "─"
|
||||
if $command
|
||||
then
|
||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||
else
|
||||
error "some error happened"
|
||||
fi
|
||||
clean_dir "$OBJDIR/objects"
|
||||
}
|
||||
39
myprint.sh → include/myprint.sh
Normal file → Executable file
39
myprint.sh → include/myprint.sh
Normal file → Executable file
@@ -18,12 +18,21 @@ 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
|
||||
myprint "$text"
|
||||
fi
|
||||
}
|
||||
|
||||
# print message and exit
|
||||
function error {
|
||||
myprint "$@"
|
||||
myprint "${RED}$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -36,6 +45,16 @@ function ask_yn {
|
||||
return $([[ "$answ" = [Yy] ]]);
|
||||
}
|
||||
|
||||
function char_multiply {
|
||||
local character="$1"
|
||||
local length="$2"
|
||||
i=0
|
||||
while [ $i -lt $length ]; do
|
||||
printf $character
|
||||
i=$((i+1))
|
||||
done
|
||||
}
|
||||
|
||||
# prints horizontal line occupying whole terminal row
|
||||
# https://en.wikipedia.org/wiki/Box-drawing_characters
|
||||
function print_hline {
|
||||
@@ -47,7 +66,10 @@ function print_hline {
|
||||
if [ -z "$character" ]; then
|
||||
character="-";
|
||||
fi
|
||||
printf "${color}%.s${character}" $(seq 2 $(tput cols))
|
||||
local term_width=$(tput cols)
|
||||
local line_length=$((term_width - 1))
|
||||
printf "${color}"
|
||||
char_multiply "$character" $line_length
|
||||
printf "${GRAY}\n"
|
||||
}
|
||||
|
||||
@@ -65,10 +87,11 @@ function print_header {
|
||||
local term_width=$(tput cols)
|
||||
local label_length=${#label}
|
||||
local line_characters_count=$((term_width - label_length - 2))
|
||||
local letf_line_length=$(( line_characters_count / 2 ))
|
||||
local right_line_length=$(( letf_line_length + line_characters_count % 2 ))
|
||||
printf "${color}%.s${character}" $(seq 1 $letf_line_length)
|
||||
printf "[${label}]"
|
||||
printf "${color}%.s${character}" $(seq 2 $right_line_length)
|
||||
local left_line_length=$(( line_characters_count / 2 ))
|
||||
local right_line_length=$(( left_line_length - 1 + line_characters_count % 2 ))
|
||||
printf "${color}"
|
||||
char_multiply "$character" $left_line_length
|
||||
printf "[${label}]${color}"
|
||||
char_multiply "$character" $right_line_length
|
||||
printf "${GRAY}\n"
|
||||
}
|
||||
157
default.config → project.config.default
Normal file → Executable file
157
default.config → project.config.default
Normal file → Executable file
@@ -1,49 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_VERSION=2.0.1
|
||||
CONFIG_VERSION=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"
|
||||
SRC_C="$( find src -name '*.c')"
|
||||
SRC_CPP="$( find src -name '*.cpp')"
|
||||
TESTS_C="$( find tests -name '*.c')"
|
||||
TESTS_CPP="$(find tests -name '*.cpp')"
|
||||
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')"
|
||||
|
||||
# dir with dependeicy dirs
|
||||
DEPS_BASEDIR="."
|
||||
# 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=""
|
||||
# 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/ - 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
|
||||
# ├── 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="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./"
|
||||
INCLUDE=""
|
||||
INCLUDE="$INCLUDE "
|
||||
# example: "-lSDL2 -lSDL2_image"
|
||||
LINKER_LIBS=""
|
||||
;;
|
||||
LINUX)
|
||||
EXEC_FILE="$PROJECT"
|
||||
SHARED_LIB_FILE="$PROJECT.so"
|
||||
INCLUDE=""
|
||||
INCLUDE="$INCLUDE "
|
||||
LINKER_LIBS=""
|
||||
;;
|
||||
*)
|
||||
error "operating system $OS has no configuration variants"
|
||||
@@ -62,62 +70,62 @@ case "$TASK" in
|
||||
# -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"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
POST_TASK_SCRIPT=
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
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"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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 -Wl,-soname,$SHARED_LIB_FILE"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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 -Wl,-soname,$SHARED_LIB_FILE"
|
||||
PRE_TASK_SCRIPT=
|
||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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=
|
||||
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
|
||||
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"
|
||||
;;
|
||||
# generates profiling info
|
||||
profile)
|
||||
@@ -130,23 +138,26 @@ case "$TASK" in
|
||||
# -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=cbuild/default_tasks/build_exec.sh
|
||||
TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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)
|
||||
# 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"
|
||||
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
TASK_SCRIPT=cbuild/default_tasks/gprof.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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)
|
||||
@@ -157,30 +168,36 @@ case "$TASK" in
|
||||
# -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
|
||||
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"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS"
|
||||
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
||||
POST_TASK_SCRIPT=
|
||||
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`
|
||||
# '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
|
||||
TASK_SCRIPT="@cbuild/default_tasks/clean.sh"
|
||||
;;
|
||||
# nothing to do
|
||||
"" | no_task)
|
||||
;;
|
||||
# unknown task
|
||||
*)
|
||||
error "task <$TASK> not found"
|
||||
error "task <$PROJECT/$TASK> not found"
|
||||
;;
|
||||
esac
|
||||
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=".."
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "ERROR: rebuild_dep.sh IS OBSOLETE"
|
||||
exit 1
|
||||
|
||||
include "cbuild/config.sh"
|
||||
|
||||
load_config
|
||||
target_file="$1"
|
||||
touch ".rebuild_$target_file.tmp"
|
||||
rm -fv "$OBJDIR/libs/$target_file"
|
||||
myprint "${YELLOW}dependency ${WHITE}$target_file ${YELLOW}will be rebuilt during the next build task"
|
||||
76
setup.sh
Normal file → Executable file
76
setup.sh
Normal file → Executable file
@@ -1,15 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
# USAGE: ./setup.sh install cbuild to /usr/local
|
||||
# ./setup.sh --local install cbuild to $HOME/.local
|
||||
|
||||
# exit on errors
|
||||
set -eo pipefail
|
||||
set -x
|
||||
set -xeo pipefail
|
||||
CBUILD_VERSION=$(<CBUILD_VERSION)
|
||||
|
||||
function version_parse {
|
||||
local value="$1"
|
||||
var_name="$2"
|
||||
IFS_backup="$IFS"
|
||||
IFS='.'
|
||||
local v_array=($value)
|
||||
IFS="$IFS_backup"
|
||||
eval ${var_name}_version_major=${v_array[0]}
|
||||
eval ${var_name}_version_minor=${v_array[1]}
|
||||
eval ${var_name}_version_patch=${v_array[2]}
|
||||
}
|
||||
|
||||
function exec_script_line {
|
||||
local script="$1"
|
||||
local line_num="$2"
|
||||
local line_str="$(sed $line_num'!d' $script)"
|
||||
if [ -z "$line_str" ]; then
|
||||
echo "script line is empty"
|
||||
exit 1
|
||||
fi
|
||||
eval "$line_str"
|
||||
}
|
||||
|
||||
version_parse $CBUILD_VERSION local
|
||||
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
||||
if [ "$1" = "--local" ]; then
|
||||
if [ ! -d "$HOME" ]; then
|
||||
echo "ERROR: home directory '$HOME' doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
CBUILD_INSTALL_DIR="$HOME/.local/share/cbuild/${local_version_major}.${local_version_minor}"
|
||||
CBUILD_BIN_DIR="$HOME/.local/bin"
|
||||
mkdir -p "$HOME/.local"
|
||||
mkdir -p "$HOME/.local/share"
|
||||
mkdir -p "$HOME/.local/share/cbuild"
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
else
|
||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild/${local_version_major}.${local_version_minor}"
|
||||
CBUILD_BIN_DIR="/usr/local/bin"
|
||||
mkdir -p "/usr/local/share"
|
||||
mkdir -p "/usr/local/share/cbuild"
|
||||
mkdir -p "/usr/local/bin"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$CBUILD_INSTALL_DIR" != "." ]; then
|
||||
cp -r ./ "$CBUILD_INSTALL_DIR"
|
||||
rm -rf "$CBUILD_INSTALL_DIR/.git"
|
||||
rm -rf "$CBUILD_INSTALL_DIR"
|
||||
cp -r ./ "$CBUILD_INSTALL_DIR"
|
||||
rm -rf "$CBUILD_INSTALL_DIR/.git"
|
||||
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "$CBUILD_BIN_DIR/cbuild${local_version_major}.${local_version_minor}"
|
||||
|
||||
bootstrap_install_path="$CBUILD_INSTALL_DIR/../bootstrap.sh"
|
||||
if [ -f "$bootstrap_install_path" ]; then
|
||||
exec_script_line "$bootstrap_install_path" 2
|
||||
installed_bootstrap_version=$CBUILD_BOOTSTRAP_VERSION
|
||||
installed_bootstrap_version_int=$(echo $installed_bootstrap_version | sed 's/\.//g')
|
||||
exec_script_line "./bootstrap.sh" 2
|
||||
local_bootstrap_version=$CBUILD_BOOTSTRAP_VERSION
|
||||
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
|
||||
ln -sfv "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "/usr/local/bin/cbuild"
|
||||
echo "Link bootstrap.sh to $CBUILD_BIN_DIR"
|
||||
ln -sf "$(realpath $bootstrap_install_path)" -T "$CBUILD_BIN_DIR/cbuild"
|
||||
|
||||
Reference in New Issue
Block a user