Compare commits
10 Commits
d021389637
...
2.1.4
| Author | SHA1 | Date | |
|---|---|---|---|
| fa15e15758 | |||
| d60c86ec3b | |||
| 1576021cf7 | |||
| 646773f574 | |||
| 3b7f72c8b3 | |||
| 144b333b60 | |||
| 0b5eed8b4c | |||
| 5c1b063399 | |||
| c5f8f6ee09 | |||
| 91dfc8bc74 |
1
CBUILD_VERSION
Normal file
1
CBUILD_VERSION
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2.1.4
|
||||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,16 @@
|
|||||||
|
# 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
|
# v2.1.1
|
||||||
+ removed `TESTS_C` and `TESTS_CPP`
|
+ **config**: removed `TESTS_C` and `TESTS_CPP` compilation
|
||||||
|
|
||||||
# v2.1.0
|
# v2.1.0
|
||||||
+ **config**: no more `current.config` and `default.config`, just `project.config`
|
+ **config**: no more `current.config` and `default.config`, just `project.config`
|
||||||
|
|||||||
22
README.md
22
README.md
@@ -1,23 +1,31 @@
|
|||||||
# cbuild
|
# cbuild
|
||||||
My C/C++ build system written in bash.
|
My C/C++ build system written in sh.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
```bash
|
```sh
|
||||||
git clone https://timerix.ddns.net:3322/cbuild.git
|
git clone https://timerix.ddns.net:3322/Timerix/cbuild.git
|
||||||
cd cbuild
|
cd cbuild
|
||||||
sudo ./setup.sh
|
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
|
## Usage
|
||||||
1. Initialize cbuild project in some directory:
|
1. Initialize cbuild project in some directory:
|
||||||
```bash
|
```sh
|
||||||
cd some_project
|
cd some_project
|
||||||
cbuild --new-project
|
cbuild --new-project
|
||||||
```
|
```
|
||||||
|
2. Edit `project.config`.
|
||||||
2. Edit `default.config`.
|
|
||||||
3. Call some tasks:
|
3. Call some tasks:
|
||||||
```bash
|
```sh
|
||||||
cbuild build_exec_dbg exec
|
cbuild build_exec_dbg exec
|
||||||
```
|
```
|
||||||
|
P.S. See help
|
||||||
|
```sh
|
||||||
|
cbuild -h
|
||||||
|
```
|
||||||
|
|||||||
67
bootstrap.sh
67
bootstrap.sh
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
CBUILD_BOOTSTRAP_VERSION=1.0.0
|
CBUILD_BOOTSTRAP_VERSION=1.0.1
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
function version_parse {
|
function version_parse {
|
||||||
@@ -29,29 +29,56 @@ function exec_script_line {
|
|||||||
eval "$line_str"
|
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 -name 'CBUILD_VERSION')"
|
||||||
|
fi
|
||||||
|
if [ -d "$dir_global" ]; then
|
||||||
|
files+="$(find $dir_global -name 'CBUILD_VERSION')"
|
||||||
|
fi
|
||||||
|
for f in $files; do
|
||||||
|
cat $f | sed '$a\'
|
||||||
|
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
|
# parse command line arguments
|
||||||
project_config_path="./project.config"
|
project_config_path="./project.config"
|
||||||
args=($@)
|
args=($@)
|
||||||
args_count=${#args[@]}
|
args_count=${#args[@]}
|
||||||
i=0
|
i=0
|
||||||
|
if [ $args_count -eq 0 ]; then
|
||||||
function get_next_arg {
|
print_help
|
||||||
i=$((i+1))
|
fi
|
||||||
safeprint "${args[i]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
while [ $i -lt $args_count ]
|
while [ $i -lt $args_count ]
|
||||||
do
|
do
|
||||||
case "${args[i]}" in
|
case "${args[i]}" in
|
||||||
'-v' | '--version')
|
'-v' | '--version')
|
||||||
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
|
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
|
||||||
;;
|
;;
|
||||||
'-c' | '--config')
|
'-h' | '--help')
|
||||||
project_config_path="$(get_next_arg)"
|
print_help
|
||||||
;;
|
;;
|
||||||
'-n' | '--new-project')
|
'-c' | '--config')
|
||||||
echo "enter project cbuild version (example: 2.1.0)"
|
i=$((i+1))
|
||||||
read -r CBUILD_VERSION
|
project_config_path="${args[i]}"
|
||||||
|
;;
|
||||||
|
'--list-versions')
|
||||||
|
print_version_list
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
@@ -59,9 +86,21 @@ do
|
|||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# read version from project config if not specified
|
|
||||||
if [ -z "$CBUILD_VERSION" ]; then
|
if [ -z "$CBUILD_VERSION" ]; then
|
||||||
exec_script_line "$project_config_path" 2
|
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:"
|
||||||
|
versions=$(print_version_list)
|
||||||
|
|
||||||
|
echo "$versions"
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
version_parse "$CBUILD_VERSION"
|
version_parse "$CBUILD_VERSION"
|
||||||
|
|||||||
27
cbuild.sh
27
cbuild.sh
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
INSTALLED_CBUILD_VERSION=2.1.1
|
INSTALLED_CBUILD_VERSION=2.1.4
|
||||||
|
|
||||||
# set \t size to 4 spaces
|
# set \t size to 4 spaces
|
||||||
tabs 4
|
tabs 4
|
||||||
@@ -47,11 +47,12 @@ include "cbuild/config.sh"
|
|||||||
function print_help {
|
function print_help {
|
||||||
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
|
myprint "cbuild v$INSTALLED_CBUILD_VERSION"
|
||||||
myprint "C/C++ project build system written in bash."
|
myprint "C/C++ project build system written in bash."
|
||||||
myprint "Usage: cbuild [OPTIONS] [TASK]"
|
myprint "Usage: cbuild [OPTIONS] [TASKS]"
|
||||||
myprint " -h, --help Show this message"
|
myprint "Options:"
|
||||||
myprint " -v, --version Shows version"
|
myprint " -h, --help Show this message"
|
||||||
myprint " -n, --new-project [PROJ_DIR] Initialize new cbuild project directory (default=./)"
|
myprint " -v, --version Shows version"
|
||||||
myprint " -c, --config FILE Set project config file path (default=./project.config)"
|
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
|
# parse command line arguments
|
||||||
@@ -62,13 +63,9 @@ selected_tasks_array=()
|
|||||||
i=0
|
i=0
|
||||||
if [ $args_count -eq 0 ]; then
|
if [ $args_count -eq 0 ]; then
|
||||||
print_help
|
print_help
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function get_next_arg {
|
|
||||||
i=$((i+1))
|
|
||||||
safeprint "${args[i]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
while [ $i -lt $args_count ]
|
while [ $i -lt $args_count ]
|
||||||
do
|
do
|
||||||
case "${args[i]}" in
|
case "${args[i]}" in
|
||||||
@@ -81,12 +78,16 @@ do
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
'-c' | '--config')
|
'-c' | '--config')
|
||||||
project_config_path="$(get_next_arg)"
|
i=$((i+1))
|
||||||
|
project_config_path="${args[i]}"
|
||||||
;;
|
;;
|
||||||
'-n' | '--new-project')
|
'-n' | '--new-project')
|
||||||
new_project_dir="$(get_next_arg)"
|
i=$((i+1))
|
||||||
|
new_project_dir="${args[i]}"
|
||||||
if [ -z "$new_project_dir" ]; then
|
if [ -z "$new_project_dir" ]; then
|
||||||
new_project_dir="."
|
new_project_dir="."
|
||||||
|
else
|
||||||
|
mkdir -p "$new_project_dir"
|
||||||
fi
|
fi
|
||||||
if ask_yn "create default cbuild project config?"; then
|
if ask_yn "create default cbuild project config?"; then
|
||||||
project_config_path="$new_project_dir/project.config"
|
project_config_path="$new_project_dir/project.config"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function load_config {
|
|||||||
TASK="$2"
|
TASK="$2"
|
||||||
local quiet=$3
|
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
|
if [ -z "$project_config_path" ]; then
|
||||||
error "config path is null"
|
error "config path is null"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
CBUILD_VERSION=2.1.1
|
CBUILD_VERSION=2.1.4
|
||||||
CONFIG_VERSION=1
|
CONFIG_VERSION=1
|
||||||
|
|
||||||
PROJECT="%PROJECT_NAME%"
|
PROJECT="%PROJECT_NAME%"
|
||||||
@@ -111,7 +111,7 @@ case "$TASK" in
|
|||||||
;;
|
;;
|
||||||
# executes $EXEC_FILE with valgrind memory checker
|
# executes $EXEC_FILE with valgrind memory checker
|
||||||
valgrind)
|
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
|
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
||||||
;;
|
;;
|
||||||
# generates profiling info
|
# generates profiling info
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ else
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||||
link "$LINKER_ARGS" "$EXEC_FILE"
|
link "$LINKER_ARGS" "$EXEC_FILE"
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
# delete old objects
|
# delete old objects
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||||
link "$LINKER_ARGS" "$SHARED_LIB_FILE"
|
link "$LINKER_ARGS" "$SHARED_LIB_FILE"
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
# delete old objects
|
# delete old objects
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
[ ! -z "$SRC_C" ] && compile_c "$CMP_C" "$STD_C" "$WARN_C" "$C_ARGS" "$INCLUDE" "$SRC_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
[ ! -z "$SRC_CPP" ] && compile_cpp "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$CPP_ARGS" "$INCLUDE" "$SRC_CPP"
|
||||||
pack_static_lib "$STATIC_LIB_FILE"
|
pack_static_lib "$STATIC_LIB_FILE"
|
||||||
|
|||||||
@@ -6,5 +6,8 @@ DEP_POST_BUILD_COMMAND=''
|
|||||||
DEP_CLEAN_COMMAND='make clean'
|
DEP_CLEAN_COMMAND='make clean'
|
||||||
# won't be copied to project $OUTDIR
|
# won't be copied to project $OUTDIR
|
||||||
DEP_STATIC_OUT_FILES='libexample1.a libexample1_addon.a'
|
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'
|
DEP_DYNAMIC_OUT_FILES='libexample1.config.json'
|
||||||
|
# will be copied to project $OUTDIR
|
||||||
|
DEP_OTHER_OUT_FILES=''
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ DEP_PRE_BUILD_COMMAND=''
|
|||||||
DEP_POST_BUILD_COMMAND=''
|
DEP_POST_BUILD_COMMAND=''
|
||||||
DEP_CLEAN_COMMAND='make clean'
|
DEP_CLEAN_COMMAND='make clean'
|
||||||
DEP_STATIC_OUT_FILES=''
|
DEP_STATIC_OUT_FILES=''
|
||||||
|
DEP_OTHER_OUT_FILES=''
|
||||||
case $OS in
|
case $OS in
|
||||||
WINDOWS)
|
WINDOWS)
|
||||||
DEP_BUILD_COMMAND='make libexample2.dll'
|
DEP_BUILD_COMMAND='make libexample2.dll && mkdir -p win-x64 && mv libexample.dll win-x64'
|
||||||
DEP_DYNAMIC_OUT_FILES='libexample2.dll'
|
DEP_DYNAMIC_OUT_FILES='win-x64/libexample2.dll'
|
||||||
|
PRESERVE_OUT_DIRECTORY_STRUCTURE=true # library will be copied to $OUTDIR/win-x64
|
||||||
;;
|
;;
|
||||||
LINUX)
|
LINUX)
|
||||||
DEP_BUILD_COMMAND='make libexample2.so'
|
DEP_BUILD_COMMAND='make libexample2.so && mkdir -p linux-x64 && mv libexample.so linux-x64'
|
||||||
DEP_DYNAMIC_OUT_FILES='libexample2.so'
|
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"
|
error "operating system $OS has no configuration variants"
|
||||||
|
|||||||
101
functions.sh
101
functions.sh
@@ -64,7 +64,7 @@ function build_dependency {
|
|||||||
|
|
||||||
local build_needed="$force_build"
|
local build_needed="$force_build"
|
||||||
if [ "$build_needed" != true ]; then
|
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
|
if [ ! -f "$file" ]; then
|
||||||
myprint "${GRAY}missing file '$file'"
|
myprint "${GRAY}missing file '$file'"
|
||||||
local build_needed=true
|
local build_needed=true
|
||||||
@@ -82,21 +82,55 @@ function build_dependency {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$DEP_DYNAMIC_OUT_FILES" ]; then
|
if [ ! -z "$DEP_DYNAMIC_OUT_FILES" ]; then
|
||||||
# copy each file to $OUTDIR
|
# copies each file to $OUTDIR and creates symbolic link in $OBJDIR/dynamic_libs
|
||||||
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
|
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 "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||||
|
ln -sfv "$real_file" "$proj_root_dir/$OBJDIR/dynamic_libs/$file"
|
||||||
|
else
|
||||||
|
cp -v "$file" "$proj_root_dir/$OUTDIR/"
|
||||||
|
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 "$file" "$proj_root_dir/$OUTDIR/$file"
|
||||||
|
else
|
||||||
|
cp -v "$file" "$proj_root_dir/$OUTDIR/"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ ! -z "$DEP_STATIC_OUT_FILES" ]; then
|
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
|
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
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$proj_root_dir"
|
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 {
|
function build_dependencies {
|
||||||
@@ -116,16 +150,16 @@ function compile {
|
|||||||
print_hline "${BLUE}" "─"
|
print_hline "${BLUE}" "─"
|
||||||
|
|
||||||
local cmp="$1"
|
local cmp="$1"
|
||||||
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
|
||||||
local std="$2"
|
local std="$2"
|
||||||
myprint "${BLUE}standard: ${GRAY}$std"
|
|
||||||
local warn="$3"
|
local warn="$3"
|
||||||
myprint "${BLUE}warnings: ${GRAY}$warn"
|
|
||||||
local args="$4"
|
local args="$4"
|
||||||
myprint "${BLUE}args: ${GRAY}$args"
|
|
||||||
local include="$5"
|
local include="$5"
|
||||||
myprint "${BLUE}include dirs: ${GRAY}$include"
|
|
||||||
local sources="$6"
|
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"
|
myprint "${BLUE}sources: ${GRAY}$sources"
|
||||||
for srcfile in $sources
|
for srcfile in $sources
|
||||||
do (
|
do (
|
||||||
@@ -141,14 +175,26 @@ function compile {
|
|||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_c {
|
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"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_c"
|
||||||
compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$INCLUDE" "$2"
|
compile "$cmp" "$std" "$warn" "$args" "$include" "$sources"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_cpp {
|
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"
|
print_header "${CYAN}" "─" "$PROJECT/$TASK/compile_cpp"
|
||||||
compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$INCLUDE" "$2"
|
compile "$cmp" "$std" "$warn" "$args" "$include" "$sources"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (outfile)
|
# (outfile)
|
||||||
@@ -156,8 +202,13 @@ function pack_static_lib {
|
|||||||
print_header "${CYAN}" "─" "$PROJECT/$TASK/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 -type f,l | tr '\n' ' ')"
|
|
||||||
|
local objects=$(find $OBJDIR/objects -type f,l | tr '\n' ' ')
|
||||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
|
if [ -z "$objects" ]; then
|
||||||
|
error "no compiled objects found"
|
||||||
|
fi
|
||||||
|
|
||||||
local command="ar rcs $OUTDIR/$outfile $objects"
|
local command="ar rcs $OUTDIR/$outfile $objects"
|
||||||
myprint "$command"
|
myprint "$command"
|
||||||
if $command
|
if $command
|
||||||
@@ -166,6 +217,7 @@ function pack_static_lib {
|
|||||||
else
|
else
|
||||||
error "some error happened"
|
error "some error happened"
|
||||||
fi
|
fi
|
||||||
|
clean_dir "$OBJDIR/objects"
|
||||||
}
|
}
|
||||||
|
|
||||||
function link {
|
function link {
|
||||||
@@ -174,16 +226,24 @@ function link {
|
|||||||
local outfile="$2"
|
local outfile="$2"
|
||||||
myprint "${BLUE}args: ${GRAY}$args"
|
myprint "${BLUE}args: ${GRAY}$args"
|
||||||
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
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"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
local static_libs="$(find $OBJDIR/static_libs -type f,l | tr '\n' ' ')"
|
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"
|
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"
|
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
|
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
|
done
|
||||||
|
|
||||||
local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile"
|
local command="$CMP_CPP $objects $static_libs $args $dynamic_libs_args -o $OUTDIR/$outfile"
|
||||||
myprint "$command"
|
myprint "$command"
|
||||||
if $command
|
if $command
|
||||||
@@ -192,4 +252,5 @@ function link {
|
|||||||
else
|
else
|
||||||
error "some error happened"
|
error "some error happened"
|
||||||
fi
|
fi
|
||||||
|
clean_dir "$OBJDIR/objects"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user