Compare commits
3 Commits
023f0b1d40
...
7d60219c33
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d60219c33 | |||
| de9a63f84b | |||
| b7109ef9fa |
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,8 +1,13 @@
|
|||||||
|
# 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
|
||||||
+ fixed bugs in `myprint.sh`, `--new-project`, task execution
|
|
||||||
+ updated `.gitignore`
|
+ updated `.gitignore`
|
||||||
+ added `pwd` call to `valgrind` task in config
|
+ **config**: added `pwd` call to `valgrind` task
|
||||||
+ added `""` empty task check in config
|
+ **config**: added `""` empty task check
|
||||||
|
|
||||||
# 2.0.0
|
# 2.0.0
|
||||||
+ updated setup.sh to do system-wide installation
|
+ updated setup.sh to do system-wide installation
|
||||||
|
|||||||
38
cbuild.sh
38
cbuild.sh
@ -5,7 +5,7 @@ tabs 4
|
|||||||
# exit on errors
|
# exit on errors
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
INSTALLED_CBUILD_VERSION=2.0.1
|
INSTALLED_CBUILD_VERSION=2.0.2
|
||||||
|
|
||||||
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||||
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
||||||
@ -95,10 +95,10 @@ function call_task {
|
|||||||
local current_config_path="$1"
|
local current_config_path="$1"
|
||||||
local default_config_path="$2"
|
local default_config_path="$2"
|
||||||
local task="$3"
|
local task="$3"
|
||||||
|
TASK_ARGS="$4"
|
||||||
|
|
||||||
print_header "${CYAN}" "─" "$task"
|
print_header "${CYAN}" "─" "$PROJECT/$task"
|
||||||
load_config "$current_config_path" "$default_config_path" "$task"
|
load_config "$current_config_path" "$default_config_path" "$task" true
|
||||||
resolve_dependencies "$DEPS_BASEDIR" "$DEPS"
|
|
||||||
|
|
||||||
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
|
if [ ! -z "$PRE_TASK_SCRIPT" ]; then
|
||||||
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
myprint "${BLUE}executing ${WHITE}$TASK_SCRIPT"
|
||||||
@ -116,27 +116,23 @@ function call_task {
|
|||||||
|
|
||||||
function call_tasks {
|
function call_tasks {
|
||||||
local tasks="$@"
|
local tasks="$@"
|
||||||
load_config "$current_config_path" "$default_config_path"
|
load_config "$current_config_path" "$default_config_path" "" false
|
||||||
print_header "${WHITE}" "═" "$PROJECT"
|
print_header "${WHITE}" "═" "$PROJECT"
|
||||||
for task in $tasks ; do
|
project_dir="$(pwd)"
|
||||||
call_task "$current_config_path" "$default_config_path" "$task"
|
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 "$current_config_path" "$default_config_path" "$task" "${args_array[@]}"
|
||||||
|
cd "$project_dir"
|
||||||
done
|
done
|
||||||
print_hline "${WHITE}" "═"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_hline "${WHITE}" "═"
|
||||||
selected_tasks_count=${#selected_tasks_array[@]}
|
selected_tasks_count=${#selected_tasks_array[@]}
|
||||||
if [ $selected_tasks_count -gt 0 ]; then
|
if [ $selected_tasks_count -gt 0 ]; then
|
||||||
time call_tasks "${selected_tasks_array[@]}" #2>&1 | tee cbuild.log
|
call_tasks "${selected_tasks_array[@]}"
|
||||||
fi
|
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
|
|
||||||
58
config.sh
58
config.sh
@ -4,10 +4,32 @@ include cbuild/myprint.sh
|
|||||||
include cbuild/functions.sh
|
include cbuild/functions.sh
|
||||||
include cbuild/detect_os.sh
|
include cbuild/detect_os.sh
|
||||||
|
|
||||||
|
function myprint_quiet {
|
||||||
|
local quiet=$1
|
||||||
|
local text="$2"
|
||||||
|
if [ "$quiet" != true ]; then
|
||||||
|
myprint "$text"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function exec_script_line {
|
||||||
|
local script="$1"
|
||||||
|
local line_num="$2"
|
||||||
|
local quiet=$3
|
||||||
|
myprint_quiet $quiet "${BLUE}reading line $line_num from $script"
|
||||||
|
local line_str="$(sed $line_num'!d' $script)"
|
||||||
|
myprint_quiet $quiet "$line_str"
|
||||||
|
eval "$line_str"
|
||||||
|
}
|
||||||
|
|
||||||
function load_config {
|
function load_config {
|
||||||
local current_config_path="$1"
|
local current_config_path="$1"
|
||||||
local default_config_path="$2"
|
local default_config_path="$2"
|
||||||
TASK="$3"
|
TASK="$3"
|
||||||
|
local quiet=$4
|
||||||
|
|
||||||
|
myprint "${BLUE}loading config current='$(realpath $current_config_path)' default='$(realpath $default_config_path)'"
|
||||||
|
|
||||||
if [ -z "$current_config_path" ]; then
|
if [ -z "$current_config_path" ]; then
|
||||||
error "current_config_path is null"
|
error "current_config_path is null"
|
||||||
fi
|
fi
|
||||||
@ -16,16 +38,7 @@ function load_config {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
OS=$(detect_os)
|
OS=$(detect_os)
|
||||||
myprint "${GREEN}detected OS: $OS"
|
myprint_quiet $quiet "${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
|
# getting version of cbuild installation
|
||||||
if [ -z "$INSTALLED_CBUILD_VERSION" ]; then
|
if [ -z "$INSTALLED_CBUILD_VERSION" ]; then
|
||||||
@ -33,7 +46,7 @@ function load_config {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# getting version of default config
|
# getting version of default config
|
||||||
exec_script_line "$default_config_path" 3
|
exec_script_line "$default_config_path" 3 $quiet
|
||||||
DEFAULT_CONFIG_VERSION="$CONFIG_VERSION"
|
DEFAULT_CONFIG_VERSION="$CONFIG_VERSION"
|
||||||
unset CONFIG_VERSION
|
unset CONFIG_VERSION
|
||||||
|
|
||||||
@ -50,31 +63,32 @@ function load_config {
|
|||||||
myprint "${YELLOW}Created copy (${current_config_path}) of default config (${default_config_path})"
|
myprint "${YELLOW}Created copy (${current_config_path}) of default config (${default_config_path})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
myprint "${BLUE}reading $current_config_path"
|
myprint_quiet $quiet "${BLUE}reading $current_config_path"
|
||||||
include "$current_config_path"
|
include "$current_config_path"
|
||||||
|
|
||||||
myprint "${WHITE}project: ${CYAN}$PROJECT"
|
myprint_quiet $quiet "${WHITE}project: ${CYAN}$PROJECT"
|
||||||
|
|
||||||
myprint "${WHITE}${current_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
myprint_quiet $quiet "${WHITE}${current_config_path} cbuild version: ${CYAN}$CBUILD_VERSION"
|
||||||
myprint "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
||||||
myprint "${WHITE}${current_config_path} version: ${CYAN}$CONFIG_VERSION"
|
myprint_quiet $quiet "${WHITE}${current_config_path} version: ${CYAN}$CONFIG_VERSION"
|
||||||
myprint "${WHITE}${default_config_path} version: ${CYAN}$DEFAULT_CONFIG_VERSION"
|
myprint_quiet $quiet "${WHITE}${default_config_path} version: ${CYAN}$DEFAULT_CONFIG_VERSION"
|
||||||
|
|
||||||
# checking versions
|
# checking versions
|
||||||
if [ ! "$CBUILD_VERSION" -eq "$INSTALLED_CBUILD_VERSION" ]; then
|
if [ "$CBUILD_VERSION" != "$INSTALLED_CBUILD_VERSION" ]; then
|
||||||
error "config was created for outdated cbuild version"
|
error "config was created for outdated cbuild version"
|
||||||
fi
|
fi
|
||||||
if [ ! "$CONFIG_VERSION" -eq "$DEFAULT_CONFIG_VERSION" ]; then
|
if [ "$CONFIG_VERSION" != "$DEFAULT_CONFIG_VERSION" ]; then
|
||||||
error "config version isn't correct"
|
error "current config version doesn't match default config version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$OUTDIR"
|
mkdir -p "$OUTDIR"
|
||||||
mkdir -p "$OBJDIR/libs"
|
|
||||||
mkdir -p "$OBJDIR/objects"
|
mkdir -p "$OBJDIR/objects"
|
||||||
|
mkdir -p "$OBJDIR/static_libs"
|
||||||
|
mkdir -p "$OBJDIR/dynamic_libs"
|
||||||
mkdir -p "$OBJDIR/profile"
|
mkdir -p "$OBJDIR/profile"
|
||||||
|
|
||||||
# dont thorw error on undefined variable
|
# dont thorw error on undefined variable
|
||||||
set +u
|
set +u
|
||||||
|
|
||||||
myprint "${GREEN}cbuild initialized!"
|
myprint_quiet $quiet "${GREEN}loaded cbuild config"
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
CBUILD_VERSION=2.0.1
|
CBUILD_VERSION=2.0.2
|
||||||
CONFIG_VERSION=1
|
CONFIG_VERSION=1
|
||||||
|
|
||||||
PROJECT="%PROJECT_NAME%"
|
PROJECT="%PROJECT_NAME%"
|
||||||
@ -14,20 +14,17 @@ SRC_CPP="$( find src -name '*.cpp')"
|
|||||||
TESTS_C="$( find tests -name '*.c')"
|
TESTS_C="$( find tests -name '*.c')"
|
||||||
TESTS_CPP="$(find tests -name '*.cpp')"
|
TESTS_CPP="$(find tests -name '*.cpp')"
|
||||||
|
|
||||||
# dir with dependeicy dirs
|
# Directory with dependency configs.
|
||||||
DEPS_BASEDIR="."
|
# See cbuild/example_dependency_configs
|
||||||
# EXAMPLE: "dependency_dir='build_task out_dir lib_file'
|
DEPENDENCY_CONFIGS_DIR='.'
|
||||||
# other_depndency_dir=..."
|
# List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space.
|
||||||
# Dependencies must be declared on separate lines
|
ENABLED_DEPENDENCIES=''
|
||||||
# Values can be override by resetting one of dependencies:
|
|
||||||
# DEPS="$DEPS
|
|
||||||
# dependency_dir='...'"
|
|
||||||
DEPS=""
|
|
||||||
|
|
||||||
# OBJDIR structure:
|
# OBJDIR structure:
|
||||||
# ├── objects/ - dir where compiled *.o files are stored. cleans every call of build task
|
# ├── objects/ - Compiled object files. Cleans on each call of build task
|
||||||
# ├── profile/ - dir where gcc *.gcda profiling info files stored
|
# ├── static_libs/ - Symbolic links to static libraries used by linker. Cleans on each call of build task.
|
||||||
# └── libs/ - there you can put static libs and linker will find them
|
# ├── 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"
|
OBJDIR="obj"
|
||||||
OUTDIR="bin"
|
OUTDIR="bin"
|
||||||
STATIC_LIB_FILE="lib$PROJECT.a"
|
STATIC_LIB_FILE="lib$PROJECT.a"
|
||||||
@ -172,6 +169,12 @@ case "$TASK" in
|
|||||||
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
||||||
POST_TASK_SCRIPT=
|
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
|
# deletes generated files
|
||||||
clean)
|
clean)
|
||||||
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
||||||
@ -181,6 +184,6 @@ case "$TASK" in
|
|||||||
;;
|
;;
|
||||||
# unknown task
|
# unknown task
|
||||||
*)
|
*)
|
||||||
error "task <$TASK> not found"
|
error "task <$PROJECT/$TASK> not found"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -5,21 +5,10 @@ try_delete_dir_or_file "$OUTDIR"
|
|||||||
myprint "${WHITE}deleting build logs"
|
myprint "${WHITE}deleting build logs"
|
||||||
rm -rf *.log
|
rm -rf *.log
|
||||||
|
|
||||||
for tmpfile in $(ls -a | grep -e '\.rebuild.*\.tmp'); do
|
project_dir="$(pwd)"
|
||||||
try_delete_dir_or_file "$tmpfile"
|
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
|
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
|
|
||||||
11
default_tasks/rebuild_dependencies.sh
Normal file
11
default_tasks/rebuild_dependencies.sh
Normal 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
|
||||||
10
example_dependency_configs/libexample1.config
Normal file
10
example_dependency_configs/libexample1.config
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
DEP_WORKING_DIR='depencencies/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
|
||||||
|
DEP_DYNAMIC_OUT_FILES='libexample1.config.json'
|
||||||
19
example_dependency_configs/libexample2.config
Normal file
19
example_dependency_configs/libexample2.config
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
DEP_WORKING_DIR='depencencies/libexample2'
|
||||||
|
DEP_PRE_BUILD_COMMAND=''
|
||||||
|
DEP_POST_BUILD_COMMAND=''
|
||||||
|
DEP_CLEAN_COMMAND='make clean'
|
||||||
|
DEP_STATIC_OUT_FILES=''
|
||||||
|
case $OS in
|
||||||
|
WINDOWS)
|
||||||
|
DEP_BUILD_COMMAND='make libexample2.dll'
|
||||||
|
DEP_DYNAMIC_OUT_FILES='libexample2.dll'
|
||||||
|
;;
|
||||||
|
LINUX)
|
||||||
|
DEP_BUILD_COMMAND='make libexample2.so'
|
||||||
|
DEP_DYNAMIC_OUT_FILES='libexample2.so'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "operating system $OS has no configuration variants"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
181
functions.sh
181
functions.sh
@ -23,7 +23,85 @@ function try_delete_dir_or_file {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exec_command {
|
||||||
|
local command="$@"
|
||||||
|
if [ ! -z "$command" ]; then
|
||||||
|
myprint "${GRAY}$command"
|
||||||
|
$command || error "command returned eror"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_dependency_config {
|
||||||
|
local dependency_config_file="$1"
|
||||||
|
myprint "${BLUE}loading dependency config ${WHITE}${dependency_config_file}${BLUE}"
|
||||||
|
include "$dependency_config_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"
|
||||||
|
# true or false
|
||||||
|
local force_build="$2"
|
||||||
|
load_dependency_config "$dependency_config_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; 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
|
||||||
|
# copy each file to $OUTDIR
|
||||||
|
cp -rv $DEP_DYNAMIC_OUT_FILES "$proj_root_dir/$OUTDIR"
|
||||||
|
# symlink each file to $OBJDIR/dynamic_libs
|
||||||
|
for file in $DEP_DYNAMIC_OUT_FILES; do
|
||||||
|
ln -sfv $(realpath $file) "$proj_root_dir/$OBJDIR/dynamic_libs"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ ! -z "$DEP_STATIC_OUT_FILES" ]; then
|
||||||
|
# symlink each file to $OBJDIR/static_libs
|
||||||
|
for file in $DEP_STATIC_OUT_FILES; do
|
||||||
|
ln -sfv $(realpath $file) "$proj_root_dir/$OBJDIR/static_libs"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$proj_root_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
function compile {
|
||||||
|
build_dependencies "$ENABLED_DEPENDENCIES"
|
||||||
|
print_hline "${BLUE}" "─"
|
||||||
|
|
||||||
local cmp="$1"
|
local cmp="$1"
|
||||||
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
||||||
local std="$2"
|
local std="$2"
|
||||||
@ -50,91 +128,50 @@ function compile {
|
|||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_c {
|
function compile_c {
|
||||||
print_header "${CYAN}" "─" "compile_c"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_c"
|
||||||
compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$INCLUDE" "$2"
|
compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$INCLUDE" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_cpp {
|
function compile_cpp {
|
||||||
print_header "${CYAN}" "─" "compile_cpp"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_cpp"
|
||||||
compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$INCLUDE" "$2"
|
compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$INCLUDE" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (outfile)
|
# (outfile)
|
||||||
function pack_static_lib {
|
function pack_static_lib {
|
||||||
print_header "${CYAN}" "─" "pack_static_lib"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/pack_static_lib"
|
||||||
local outfile="$1"
|
local outfile="$1"
|
||||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||||
local objects="$(find $OBJDIR/objects -name *.o)
|
local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')"
|
||||||
$(find $OBJDIR/libs -name '*.a')"
|
|
||||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
if ar rcs "$OUTDIR/$outfile" $(safeprint "$objects" | tr '\n' ' ')
|
local command="ar rcs $OUTDIR/$outfile $objects"
|
||||||
then
|
myprint "$command"
|
||||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
if $command
|
||||||
else
|
then
|
||||||
error "some error happened"
|
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||||
fi
|
else
|
||||||
}
|
error "some error happened"
|
||||||
|
fi
|
||||||
|
}
|
||||||
# if $lib_file doesn't exist or rebuild_* task was executed, builds static lib
|
|
||||||
function handle_static_dependency {
|
function link {
|
||||||
local deps_basedir="${1%/}"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/link"
|
||||||
local lib_project_dir="$2"
|
local args="$1"
|
||||||
local lib_build_task="$3"
|
local outfile="$2"
|
||||||
local lib_build_dir="$4"
|
myprint "${BLUE}args: ${GRAY}$args"
|
||||||
local lib_file="$5"
|
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||||
if [ ! -f "$OBJDIR/libs/$lib_file" ] || [ -f .rebuild_$lib_file.tmp ]; then
|
local objects="$(find $OBJDIR/objects -type f,l | tr '\n' ' ')"
|
||||||
[[ -z "$lib_build_task" ]] && error "lib_build_task is empty"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
myprint "${BLUE}making $lib_file by task $lib_build_task"
|
local static_libs="$(find $OBJDIR/static_libs -type f,l | tr '\n' ' ')"
|
||||||
|
myprint "${BLUE}static libraries: ${GRAY}$static_libs"
|
||||||
local proj_root_dir="$(pwd)"
|
local dynamic_libs="$(find $OBJDIR/dynamic_libs -type f,l | tr '\n' ' ')"
|
||||||
cd "$deps_basedir/$lib_project_dir"
|
myprint "${BLUE}dynamic libraries: ${GRAY}$dynamic_libs"
|
||||||
if ! make "$lib_build_task"; then
|
local dynamic_libs_args="-L $OBJDIR/dynamic_libs"
|
||||||
exit 1
|
for lib in $dynamic_libs; do
|
||||||
fi
|
dynamic_libs_args="$dynamic_libs_args -l:$lib"
|
||||||
cd "$proj_root_dir"
|
done
|
||||||
|
local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile"
|
||||||
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"
|
myprint "$command"
|
||||||
if $command
|
if $command
|
||||||
then
|
then
|
||||||
|
|||||||
@ -23,7 +23,7 @@ function myprint {
|
|||||||
|
|
||||||
# print message and exit
|
# print message and exit
|
||||||
function error {
|
function error {
|
||||||
myprint "$@"
|
myprint "${RED}$@"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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"
|
|
||||||
2
setup.sh
2
setup.sh
@ -12,4 +12,4 @@ if [ "$CBUILD_INSTALL_DIR" != "." ]; then
|
|||||||
cp -r ./ "$CBUILD_INSTALL_DIR"
|
cp -r ./ "$CBUILD_INSTALL_DIR"
|
||||||
rm -rf "$CBUILD_INSTALL_DIR/.git"
|
rm -rf "$CBUILD_INSTALL_DIR/.git"
|
||||||
fi
|
fi
|
||||||
ln -sfv "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "/usr/local/bin/cbuild"
|
ln -sf "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "/usr/local/bin/cbuild"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user