26 Commits

Author SHA1 Message Date
49ccc76933 added default_vscode/c_cpp_properties.json 2025-11-09 20:32:34 +05:00
d1660e05cb v2.2.4 2025-11-09 19:47:52 +05:00
259d9873fb c99 and more warnings 2025-11-09 19:44:18 +05:00
46029cd01f typo fixes 2025-07-18 02:21:12 +03:00
5953b84cff fixed detect_os.sh again 2025-06-20 19:29:52 +05:00
4c34c127a6 removed '\r' AGAIN 2025-06-20 19:21:34 +05:00
cae29d6395 removed \r characters from detect_os.sh 2025-06-20 19:11:08 +05:00
596c570756 v2.2.2 2025-04-26 03:58:53 +05:00
1c93d4eb73 bootstrap can show help for cbuild installations again 2025-04-26 03:57:09 +05:00
6126001e5a copy dependency's out files only if they are newer or don't exist 2025-04-26 00:23:13 +05:00
912b348f57 v2.2.1 2025-04-25 21:11:12 +05:00
d3d7867736 bootstrap v1.0.2 2025-04-25 21:09:52 +05:00
4488776afe v2.2.0 2025-04-25 20:40:52 +05:00
683414c59b removed CONFIG_VERSION variable from config 2025-04-25 20:34:23 +05:00
c7b590907d added LINKER_LIBS variable to config 2025-04-25 20:33:57 +05:00
653d459999 added default vscode launch config 2025-04-25 20:29:19 +05:00
f0038dd7c7 refactored sed calls to not use -i 2025-04-25 19:49:09 +05:00
4d06f57758 added detect_arch function and ARCH global variable 2025-04-25 19:23:41 +05:00
fa15e15758 fixed valgrind sources path trimming 2025-04-21 18:46:12 +05:00
d60c86ec3b readme fix 2024-09-13 21:12:25 +05:00
1576021cf7 v2.1.4 2024-08-09 22:05:34 +03:00
646773f574 rpath 2024-08-09 21:05:30 +03:00
3b7f72c8b3 2.1.3 2024-08-09 05:59:19 +03:00
144b333b60 v2.1.2 2024-07-21 06:35:00 +03:00
0b5eed8b4c bootstrap help and version list 2024-07-21 05:01:40 +03:00
5c1b063399 objects deletion after link and pack_static_lib 2024-07-21 02:49:42 +03:00
17 changed files with 348 additions and 90 deletions

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# git add --renormalize .
*.sh text eol=lf

1
CBUILD_VERSION Normal file
View File

@@ -0,0 +1 @@
2.2.4

View File

@@ -1,24 +1,59 @@
# v2.1.1
+ removed `TESTS_C` and `TESTS_CPP`
## 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
# v2.1.0
## 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
## 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
## v2.0.1
+ updated `.gitignore`
+ **config**: added `pwd` call to `valgrind` task
+ **config**: added `""` empty task check
# 2.0.0
## 2.0.0
+ updated setup.sh to do system-wide installation
+ deleted makefile (call `./cbuild.sh` or installed `cbuild`)
+ added command line arguments:
@@ -31,7 +66,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`
@@ -40,7 +75,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`
@@ -49,7 +84,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`

View File

@@ -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
```

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
CBUILD_BOOTSTRAP_VERSION=1.0.0
CBUILD_BOOTSTRAP_VERSION=1.0.3
set -eo pipefail
function version_parse {
@@ -29,29 +29,56 @@ function exec_script_line {
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
function get_next_arg {
i=$((i+1))
safeprint "${args[i]}"
}
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')
project_config_path="$(get_next_arg)"
;;
'-n' | '--new-project')
echo "enter project cbuild version (example: 2.1.0)"
read -r CBUILD_VERSION
i=$((i+1))
project_config_path="${args[i]}"
;;
*)
;;
@@ -59,9 +86,21 @@ do
i=$((i+1))
done
# read version from project config if not specified
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"
@@ -81,5 +120,6 @@ if [ -f "$LOG_FILE" ]; then
-e 's/\[[0-9]m//g' \
-e 's/ H //g' \
-e 's/\[3gH //g' \
-i "$LOG_FILE"
"$LOG_FILE" > "$LOG_FILE.clean"
mv "$LOG_FILE.clean" "$LOG_FILE"
fi

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
INSTALLED_CBUILD_VERSION=2.1.1
INSTALLED_CBUILD_VERSION=2.2.4
# set \t size to 4 spaces
tabs 4
@@ -47,11 +47,12 @@ include "cbuild/config.sh"
function print_help {
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
myprint "C/C++ project build system written in bash."
myprint "Usage: cbuild [OPTIONS] [TASK]"
myprint "Usage: cbuild [OPTIONS] [TASKS]"
myprint "Options:"
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, --config FILE Set project config file path (default=./project.config)"
myprint " -n, --new-project [DIR] Initialize new cbuild project directory (default=./)"
}
# parse command line arguments
@@ -62,6 +63,7 @@ selected_tasks_array=()
i=0
if [ $args_count -eq 0 ]; then
print_help
exit 1
fi
while [ $i -lt $args_count ]
@@ -84,18 +86,35 @@ do
new_project_dir="${args[i]}"
if [ -z "$new_project_dir" ]; then
new_project_dir="."
else
mkdir -p "$new_project_dir"
fi
if ask_yn "create default cbuild project config?"; then
# create project config
project_config_path="$new_project_dir/project.config"
cp "$CBUILD_INSTALL_DIR/default.config" "$project_config_path"
cp "$CBUILD_INSTALL_DIR/default.config" "$project_config_path.temp"
myprint "Enter project name: "
read -r project_name
sed -i "s,\%PROJECT_NAME\%,$project_name,g" "$project_config_path"
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'"
fi
if ask_yn "Copy default .gitignore?"; then
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
cp -v "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir/"
fi
if ask_yn "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
;;
*)

View File

@@ -9,7 +9,7 @@ function load_config {
TASK="$2"
local quiet=$3
myprint "${BLUE}loading config '$(realpath $project_config_path)'"
myprint "${BLUE}loading config ${WHITE}'$(realpath $project_config_path)'"
if [ -z "$project_config_path" ]; then
error "config path is null"
@@ -19,6 +19,7 @@ function load_config {
fi
OS=$(detect_os)
ARCH=$(detect_arch)
myprint_quiet $quiet "${GREEN}detected OS: $OS"
# getting version of cbuild installation

View File

@@ -1,14 +1,22 @@
#!/usr/bin/env bash
CBUILD_VERSION=2.1.1
CONFIG_VERSION=1
CBUILD_VERSION=2.2.4
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')"
@@ -25,20 +33,25 @@ 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"
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"
@@ -57,7 +70,7 @@ 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"
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
PRE_TASK_SCRIPT=
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
POST_TASK_SCRIPT=
@@ -66,7 +79,7 @@ case "$TASK" in
build_exec_dbg)
C_ARGS="-O0 -g3"
CPP_ARGS="$C_ARGS"
LINKER_ARGS="$CPP_ARGS"
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
PRE_TASK_SCRIPT=
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
POST_TASK_SCRIPT=
@@ -75,7 +88,7 @@ case "$TASK" in
build_shared_lib)
C_ARGS="-O2 -fpic -flto -shared"
CPP_ARGS="$C_ARGS"
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
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=
@@ -84,7 +97,7 @@ case "$TASK" in
build_shared_lib_dbg)
C_ARGS="-O0 -g3 -fpic -shared"
CPP_ARGS="$C_ARGS"
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
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=
@@ -111,7 +124,7 @@ case "$TASK" in
;;
# 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"
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
@@ -125,7 +138,7 @@ 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"
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=
@@ -138,7 +151,7 @@ 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 -pg"
CPP_ARGS="$C_ARGS"
LINKER_ARGS="$CPP_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=
@@ -152,7 +165,7 @@ 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"
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=
@@ -162,7 +175,7 @@ case "$TASK" in
OUTDIR="$OUTDIR/sanitize"
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
CPP_ARGS="$C_ARGS"
LINKER_ARGS="$CPP_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=

1
default_vscode/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
settings.json

View File

@@ -0,0 +1,14 @@
{
"configurations": [
{
"name": "all",
"defines": [],
"includePath": [
// "include",
"${default}"
],
"cStandard": "c99"
}
],
"version": 4
}

View 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
View 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
}
}
]
}

View File

@@ -3,9 +3,9 @@
include "cbuild/myprint.sh"
function detect_os {
local uname_rezult="$(uname -o)"
# myprint "uname rezult: '$uname_rezult'"
case "$uname_rezult" in
local uname_result="$(uname -o)"
# myprint "uname result: '$uname_result'"
case "$uname_result" in
Msys | Cygwin | MS/Windows)
safeprint WINDOWS
;;
@@ -19,7 +19,28 @@ function detect_os {
safeprint MACOS
;;
*)
error "unknown operating system: $uname_rezult"
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
}

View File

@@ -1,10 +1,13 @@
#!/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=''
DEP_CLEAN_COMMAND='make clean'
# won't be copied to project $OUTDIR
DEP_STATIC_OUT_FILES='libexample1.a libexample1_addon.a'
# will be copied tp project $OUTDIR
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=''

View File

@@ -1,17 +1,20 @@
#!/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'
DEP_STATIC_OUT_FILES=''
DEP_OTHER_OUT_FILES=''
case $OS in
WINDOWS)
DEP_BUILD_COMMAND='make libexample2.dll'
DEP_DYNAMIC_OUT_FILES='libexample2.dll'
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'
DEP_DYNAMIC_OUT_FILES='libexample2.so'
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"

View File

@@ -64,7 +64,7 @@ function build_dependency {
local build_needed="$force_build"
if [ "$build_needed" != true ]; then
for file in $DEP_STATIC_OUT_FILES $DEP_DYNAMIC_OUT_FILES; do
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
@@ -82,21 +82,55 @@ function build_dependency {
fi
if [ ! -z "$DEP_DYNAMIC_OUT_FILES" ]; then
# copy each file to $OUTDIR
cp -rv $DEP_DYNAMIC_OUT_FILES "$proj_root_dir/$OUTDIR"
# symlink each file to $OBJDIR/dynamic_libs
# copies each file to $OUTDIR and creates symbolic link in $OBJDIR/dynamic_libs
for file in $DEP_DYNAMIC_OUT_FILES; do
ln -sfv $(realpath $file) "$proj_root_dir/$OBJDIR/dynamic_libs"
# 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
# symlink each file to $OBJDIR/static_libs
# creates symbolic link to each file in $OBJDIR/static_libs
for file in $DEP_STATIC_OUT_FILES; do
ln -sfv $(realpath $file) "$proj_root_dir/$OBJDIR/static_libs"
# doesnt return error if called not like this
f=$(realpath $file)
ln -sfv $f "$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 {
@@ -169,7 +203,7 @@ function pack_static_lib {
local outfile="$1"
myprint "${BLUE}outfile: ${GRAY}$outfile"
local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')"
local objects=$(find $OBJDIR/objects -type f,l | tr '\n' ' ')
myprint "${BLUE}objects: ${GRAY}$objects"
if [ -z "$objects" ]; then
error "no compiled objects found"
@@ -183,6 +217,7 @@ function pack_static_lib {
else
error "some error happened"
fi
clean_dir "$OBJDIR/objects"
}
function link {
@@ -192,20 +227,21 @@ function link {
myprint "${BLUE}args: ${GRAY}$args"
myprint "${BLUE}outfile: ${GRAY}$outfile"
local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')"
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' ' ')"
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' ' ')"
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"
local dynamic_libs_args="-L./$OBJDIR/dynamic_libs -Wl,-Bdynamic"
for lib in $dynamic_libs; do
dynamic_libs_args="$dynamic_libs_args -l:$lib"
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"
@@ -216,4 +252,5 @@ function link {
else
error "some error happened"
fi
clean_dir "$OBJDIR/objects"
}

View File

@@ -4,7 +4,7 @@
# exit on errors
set -xeo pipefail
CBUILD_VERSION=2.1.1
CBUILD_VERSION=$(<CBUILD_VERSION)
function version_parse {
local value="$1"