v2.0.0
This commit is contained in:
parent
6d285a88d8
commit
9b1bbffbc4
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,4 +1,16 @@
|
|||||||
# v7
|
# 2.0.0
|
||||||
|
+ updated setup.sh to do system-wide installation
|
||||||
|
+ deleted makefile (call `./cbuild.sh` or installed `cbuild`)
|
||||||
|
+ added command line arguments:
|
||||||
|
+ `--help`
|
||||||
|
+ `--current-config`
|
||||||
|
+ `--default-config`
|
||||||
|
+ `--new-project`
|
||||||
|
+ all shebang changed to `#!/usr/bin/env bash`
|
||||||
|
+ `init.sh` became `config.sh` with function `load_config`
|
||||||
|
+ moved color variables and print functions to `myprint.sh`
|
||||||
|
|
||||||
|
# v1.7.0
|
||||||
+ added function `resolve_dependencies` to `link`
|
+ added function `resolve_dependencies` to `link`
|
||||||
+ added variables `DEPS_BASEDIR` and `DEPS` to config
|
+ added variables `DEPS_BASEDIR` and `DEPS` to config
|
||||||
+ added script `rebuild_dep.sh` which can be called through `Makefile`
|
+ added script `rebuild_dep.sh` which can be called through `Makefile`
|
||||||
@ -7,7 +19,7 @@
|
|||||||
+ added task `no_task` which is been set in `init.sh` when `TASK` is empty
|
+ added task `no_task` which is been set in `init.sh` when `TASK` is empty
|
||||||
+ now `STATIC_LIB_FILE` starts with "lib"
|
+ now `STATIC_LIB_FILE` starts with "lib"
|
||||||
|
|
||||||
# v6
|
# v1.6.0
|
||||||
+ `build_profile` task was split to `profile` and `gprof`
|
+ `build_profile` task was split to `profile` and `gprof`
|
||||||
+ added task `sanitize`
|
+ added task `sanitize`
|
||||||
+ default C++ standard set to `c++11`
|
+ default C++ standard set to `c++11`
|
||||||
@ -16,7 +28,7 @@
|
|||||||
+ added function `try_delete_dir_or_file` for `clean` task
|
+ added function `try_delete_dir_or_file` for `clean` task
|
||||||
+ dead code removal in `build_exec` and `build_static_lib`
|
+ dead code removal in `build_exec` and `build_static_lib`
|
||||||
|
|
||||||
# v5
|
# v1.5.0
|
||||||
+ added task `clean`
|
+ added task `clean`
|
||||||
+ added task `exec_dbg`
|
+ added task `exec_dbg`
|
||||||
+ added task `build_profile`
|
+ added task `build_profile`
|
||||||
|
|||||||
26
call_task.sh
26
call_task.sh
@ -1,26 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
function exec_script {
|
|
||||||
myprint "${BLUE}executing $1"
|
|
||||||
source "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function try_exec_script {
|
|
||||||
if [ -f "$1" ]; then
|
|
||||||
exec_script "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function call_task {
|
|
||||||
TASK="$1"
|
|
||||||
source cbuild/init.sh
|
|
||||||
myprint "${CYAN}===========[$TASK]==========="
|
|
||||||
myprint "${WHITE}project: ${CYAN}$PROJECT"
|
|
||||||
try_exec_script "$PRE_TASK_SCRIPT"
|
|
||||||
exec_script "$TASK_SCRIPT"
|
|
||||||
try_exec_script "$POST_TASK_SCRIPT"
|
|
||||||
}
|
|
||||||
|
|
||||||
time call_task "$1"
|
|
||||||
# new line
|
|
||||||
echo
|
|
||||||
134
cbuild.sh
Normal file
134
cbuild.sh
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
tabs 4
|
||||||
|
|
||||||
|
# exit on errors
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
INSTALLED_CBUILD_VERSION=2.0.0
|
||||||
|
|
||||||
|
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||||
|
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function include {
|
||||||
|
local script_path="$1"
|
||||||
|
if [[ "$script_path" == cbuild/* ]]; then
|
||||||
|
script_path="$CBUILD_INSTALL_DIR/$(safeprint $script_path | sed 's,^cbuild/,,')"
|
||||||
|
fi
|
||||||
|
# echp "including script $script_path"
|
||||||
|
. "$script_path"
|
||||||
|
}
|
||||||
|
|
||||||
|
function include_if_not_null {
|
||||||
|
if [ ! -z "$1" ]; then
|
||||||
|
include "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
include "cbuild/myprint.sh"
|
||||||
|
include "cbuild/functions.sh"
|
||||||
|
include "cbuild/config.sh"
|
||||||
|
|
||||||
|
function print_help_and_exit {
|
||||||
|
myprint "Usage: cbuild [OPTIONS] [TASK]"
|
||||||
|
myprint " -h, --help Show this message"
|
||||||
|
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)"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
current_config_path="./current.config"
|
||||||
|
default_config_path="./default.config"
|
||||||
|
args=($@)
|
||||||
|
args_len=${#args[@]}
|
||||||
|
selected_tasks_array=()
|
||||||
|
i=0
|
||||||
|
if [ $args_len -eq 0 ]; then
|
||||||
|
print_help_and_exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
function get_next_arg {
|
||||||
|
i=$((i+1))
|
||||||
|
safeprint "${args[i]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
while [ $i -lt $args_len ]
|
||||||
|
do
|
||||||
|
case "${args[i]}" in
|
||||||
|
'-h' | '--help')
|
||||||
|
print_help_and_exit
|
||||||
|
;;
|
||||||
|
'-c' | '--current-config')
|
||||||
|
i=$((i+1))
|
||||||
|
current_config_path="${args[i]}"
|
||||||
|
myprint "<$current_config_path>"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
'-d' | '--default-config')
|
||||||
|
default_config_path="$(get_next_arg)"
|
||||||
|
;;
|
||||||
|
'-n' | '--new-project')
|
||||||
|
new_project_dir="$(get_next_arg)"
|
||||||
|
if [ -z "$new_project_dir" ]; then
|
||||||
|
new_project_dir="./"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ask_yn "create default.config?"; then
|
||||||
|
cp "$CBUILD_INSTALL_DIR/default.config" "$new_project_dir"
|
||||||
|
project_name="$(ask 'Enter project name')"
|
||||||
|
sed -i "s,\%PROJECT_NAME\%,$project_name,g"
|
||||||
|
fi
|
||||||
|
if ask_yn "Copy default .gitignore?"; then
|
||||||
|
cp "$CBUILD_INSTALL_DIR/.gitignore" "$new_project_dir"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
selected_tasks_array+=(${args[i]})
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
function call_task {
|
||||||
|
local current_config_path="$1"
|
||||||
|
local default_config_path="$2"
|
||||||
|
local task="$3"
|
||||||
|
|
||||||
|
print_header "${CYAN}" "─" "$task"
|
||||||
|
load_config "$task" "$current_config_path" "$default_config_path"
|
||||||
|
resolve_dependencies "$DEPS_BASEDIR" "$DEPS"
|
||||||
|
|
||||||
|
myprint "${BLUE}executing $PRE_TASK_SCRIPT"
|
||||||
|
# include_if_not_null "$PRE_TASK_SCRIPT"
|
||||||
|
|
||||||
|
myprint "${BLUE}executing $TASK_SCRIPT"
|
||||||
|
# include "$TASK_SCRIPT"
|
||||||
|
|
||||||
|
myprint "${BLUE}executing $POST_TASK_SCRIPT"
|
||||||
|
# include_if_not_null "$POST_TASK_SCRIPT"
|
||||||
|
myprint "error"
|
||||||
|
}
|
||||||
|
|
||||||
|
function call_tasks {
|
||||||
|
local tasks="$@"
|
||||||
|
myprint "$tasks"
|
||||||
|
|
||||||
|
print_header "${WHITE}" "═" "$PROJECT"
|
||||||
|
for task in $tasks ; do
|
||||||
|
call_task "$task"
|
||||||
|
done
|
||||||
|
print_hline "${WHITE}" "═"
|
||||||
|
}
|
||||||
|
|
||||||
|
time call_tasks "${selected_tasks_array[@]}" #2>&1 | tee cbuild.log
|
||||||
|
# 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
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
SCRIPTS="$(find ./ -name '*.sh')"
|
|
||||||
for F in $SCRIPTS
|
for f in $(find ./ -name '*.sh')
|
||||||
do
|
do
|
||||||
echo "$F"
|
chmod a+x "$f"
|
||||||
chmod +x "$F"
|
ls -lh "$f"
|
||||||
done
|
done
|
||||||
|
|||||||
11
colors.sh
11
colors.sh
@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
BLACK='\033[0;30m'
|
|
||||||
GRAY='\033[0;37m'
|
|
||||||
WHITE='\033[0;97m'
|
|
||||||
RED='\033[0;91m'
|
|
||||||
GREEN='\033[0;92m'
|
|
||||||
YELLOW='\033[0;93m'
|
|
||||||
BLUE='\033[0;94m'
|
|
||||||
PURPLE='\033[0;95m'
|
|
||||||
CYAN='\033[0;96m'
|
|
||||||
74
config.sh
Normal file
74
config.sh
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
include cbuild/myprint.sh
|
||||||
|
include cbuild/functions.sh
|
||||||
|
include cbuild/detect_os.sh
|
||||||
|
|
||||||
|
function load_config {
|
||||||
|
TASK="$1"
|
||||||
|
local current_config_path="$2"
|
||||||
|
local default_config_path="$3"
|
||||||
|
|
||||||
|
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!"
|
||||||
|
}
|
||||||
@ -1,95 +0,0 @@
|
|||||||
######################################
|
|
||||||
###### Build tasks #######
|
|
||||||
######################################
|
|
||||||
|
|
||||||
all: build_exec_dbg
|
|
||||||
|
|
||||||
# creates executable using profiling info generated by profile
|
|
||||||
build_exec: profile
|
|
||||||
@cbuild/call_task.sh build_exec 2>&1 | tee -a make_raw.log
|
|
||||||
|
|
||||||
# creates executable with debug info and no optimizations
|
|
||||||
build_exec_dbg:
|
|
||||||
@cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# creates shared library
|
|
||||||
build_shared_lib:
|
|
||||||
@cbuild/call_task.sh build_shared_lib 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# creates shared library with debug symbols and no optimizations
|
|
||||||
build_shared_lib_dbg:
|
|
||||||
@cbuild/call_task.sh build_shared_lib_dbg 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# creates static library
|
|
||||||
build_static_lib:
|
|
||||||
@cbuild/call_task.sh build_static_lib 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# creates static library with debug symbols and no optimizations
|
|
||||||
build_static_lib_dbg:
|
|
||||||
@cbuild/call_task.sh build_static_lib_dbg 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Rebuild dependencies #######
|
|
||||||
######################################
|
|
||||||
|
|
||||||
# recompile libsome.a in the next build task
|
|
||||||
#rebuild_some_dep:
|
|
||||||
# @cbuild/rebuild_dep.sh libsome.a 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
#rebuild_all: rebuild_some_dep
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Launch tasks #######
|
|
||||||
######################################
|
|
||||||
|
|
||||||
# executes $EXEC_FILE
|
|
||||||
exec: build_exec
|
|
||||||
@cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log
|
|
||||||
|
|
||||||
# executes $EXEC_FILE
|
|
||||||
exec_dbg: build_exec_dbg
|
|
||||||
@cbuild/call_task.sh exec 2>&1 | tee -a make_raw.log
|
|
||||||
|
|
||||||
# executes $EXEC_FILE with valgrind memory checker
|
|
||||||
valgrind: build_exec_dbg
|
|
||||||
@cbuild/call_task.sh valgrind 2>&1 | tee -a make_raw.log
|
|
||||||
|
|
||||||
# generates profiling info
|
|
||||||
profile:
|
|
||||||
@cbuild/call_task.sh profile 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
@cbuild/call_task.sh gprof 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# compiles program and runs it with callgrind (part of valgrind)
|
|
||||||
# uses gprof2dot python script to generate function call tree (pip install gprof2dot)
|
|
||||||
# requires graphviz (https://www.graphviz.org/download/source/)
|
|
||||||
# P.S. detailed results can be viewed in KCacheGrind
|
|
||||||
callgrind:
|
|
||||||
@cbuild/call_task.sh callgrind 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# compiles executable with sanitizers and executes it to find errors and warnings
|
|
||||||
sanitize:
|
|
||||||
@cbuild/call_task.sh sanitize 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
######################################
|
|
||||||
###### Other tasks #######
|
|
||||||
######################################
|
|
||||||
|
|
||||||
# deletes generated files
|
|
||||||
clean:
|
|
||||||
@cbuild/call_task.sh clean 2>&1 | tee make_raw.log
|
|
||||||
|
|
||||||
# removes all unreadable characters copied from stdio
|
|
||||||
fix_log:
|
|
||||||
sed 's/[^[:blank:][:print:]]//g' make_raw.log \
|
|
||||||
| sed 's/\[0;[0-9][0-9]m//g' \
|
|
||||||
| sed 's/\[0;[0-9]m//g' \
|
|
||||||
| sed 's/\[[0-9][0-9]m//g' \
|
|
||||||
| sed 's/\[[0-9]m//g' \
|
|
||||||
| sed 's/ H //g' \
|
|
||||||
| sed 's/\[3gH //g' \
|
|
||||||
> make_fixed.log
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
CBUILD_VERSION=7
|
CBUILD_VERSION=2.0.0
|
||||||
CONFIG_VERSION=1
|
CONFIG_VERSION=1
|
||||||
|
|
||||||
PROJECT="NULL"
|
PROJECT="%PROJECT_NAME%"
|
||||||
CMP_C="gcc"
|
CMP_C="gcc"
|
||||||
CMP_CPP="g++"
|
CMP_CPP="g++"
|
||||||
STD_C="c11"
|
STD_C="c11"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# delete old objects
|
# delete old objects
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# delete old objects
|
# delete old objects
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# delete old objects
|
# delete old objects
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$OUTDIR"
|
cd "$OUTDIR"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
try_delete_dir_or_file "$OBJDIR"
|
try_delete_dir_or_file "$OBJDIR"
|
||||||
try_delete_dir_or_file "$OUTDIR"
|
try_delete_dir_or_file "$OUTDIR"
|
||||||
@ -14,8 +14,8 @@ OLDIFS="$IFS"
|
|||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
cd "$DEPS_BASEDIR"
|
cd "$DEPS_BASEDIR"
|
||||||
for dep in $DEPS; do
|
for dep in $DEPS; do
|
||||||
dep_dir=$(echo ${dep/=*/} | tr -d '[:blank:]')
|
dep_dir=$(safeprint ${dep/=*/} | tr -d '[:blank:]')
|
||||||
myprint "${CYAN}--------------[$dep_dir]--------------"
|
print_header "${CYAN}" "─" "$dep_dir"
|
||||||
cd "$dep_dir"
|
cd "$dep_dir"
|
||||||
make clean
|
make clean
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$OUTDIR"
|
cd "$OUTDIR"
|
||||||
./$EXEC_FILE
|
./$EXEC_FILE
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$OUTDIR"
|
cd "$OUTDIR"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$OUTDIR"
|
cd "$OUTDIR"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$OUTDIR"
|
cd "$OUTDIR"
|
||||||
rm -f "valgrind.log"
|
rm -f "valgrind.log"
|
||||||
|
|||||||
27
detect_os.sh
27
detect_os.sh
@ -1,26 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
source cbuild/colors.sh
|
include "cbuild/myprint.sh"
|
||||||
|
|
||||||
uname_result="$(uname -o)"
|
function detect_os {
|
||||||
myprint "${GRAY}uname result: '$uname_result'"
|
local uname_rezult="$(uname -o)"
|
||||||
|
# myprint "uname rezult: '$uname_rezult'"
|
||||||
case "$uname_result" in
|
case "$uname_rezult" in
|
||||||
Msys | Cygwin | "MS/Windows")
|
Msys | Cygwin | MS/Windows)
|
||||||
OS=WINDOWS
|
safeprint WINDOWS
|
||||||
;;
|
;;
|
||||||
Linux | GNU/Linux | Android)
|
Linux | GNU/Linux | Android)
|
||||||
OS=LINUX
|
safeprint LINUX
|
||||||
;;
|
;;
|
||||||
FreeBSD)
|
FreeBSD)
|
||||||
OS=FREEBSD
|
safeprint FREEBSD
|
||||||
;;
|
;;
|
||||||
Darwin)
|
Darwin)
|
||||||
OS=MACOS
|
safeprint MACOS
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "unknown operating system: $uname_result"
|
error "unknown operating system: $uname_rezult"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
myprint "${GREEN}detected OS: $OS"
|
|
||||||
|
|||||||
28
functions.sh
28
functions.sh
@ -1,14 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
function myprint {
|
include "cbuild/myprint.sh"
|
||||||
# first gray is needed to print string trarting with -
|
|
||||||
printf "${GRAY}$@${GRAY}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function error {
|
|
||||||
myprint "${RED}$1"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function clean_dir {
|
function clean_dir {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
@ -31,7 +23,6 @@ function try_delete_dir_or_file {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function compile {
|
function compile {
|
||||||
local cmp="$1"
|
local cmp="$1"
|
||||||
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
||||||
@ -59,25 +50,25 @@ function compile {
|
|||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_c {
|
function compile_c {
|
||||||
myprint "${CYAN}-------------[compile_c]--------------"
|
print_header "${CYAN}" "─" "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 {
|
||||||
myprint "${CYAN}------------[compile_cpp]-------------"
|
print_header "${CYAN}" "─" "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 {
|
||||||
myprint "${CYAN}----------[pack_static_lib]-----------"
|
print_header "${CYAN}" "─" "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 -name *.o)
|
||||||
$(find $OBJDIR/libs -name '*.a')"
|
$(find $OBJDIR/libs -name '*.a')"
|
||||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
if ar rcs "$OUTDIR/$outfile" $(echo "$objects" | tr '\n' ' ')
|
if ar rcs "$OUTDIR/$outfile" $(safeprint "$objects" | tr '\n' ' ')
|
||||||
then
|
then
|
||||||
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||||
else
|
else
|
||||||
@ -124,7 +115,7 @@ function resolve_dependencies {
|
|||||||
# handling dependencies
|
# handling dependencies
|
||||||
for dep in $deps; do
|
for dep in $deps; do
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
dep_dir=$(echo ${dep/=*/} | tr -d '[:blank:]')
|
dep_dir=$(safeprint ${dep/=*/} | tr -d '[:blank:]')
|
||||||
eval 'dep_params=$'$dep_dir
|
eval 'dep_params=$'$dep_dir
|
||||||
f_args="$deps_basedir $dep_dir $dep_params"
|
f_args="$deps_basedir $dep_dir $dep_params"
|
||||||
myprint "${BLUE}resolving dependency ${WHITE}$dep_dir${BLUE}: ${GRAY}$f_args"
|
myprint "${BLUE}resolving dependency ${WHITE}$dep_dir${BLUE}: ${GRAY}$f_args"
|
||||||
@ -135,16 +126,15 @@ function resolve_dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function link {
|
function link {
|
||||||
myprint "${CYAN}----------------[link]----------------"
|
print_header "${CYAN}" "─" "link"
|
||||||
local args="$1"
|
local args="$1"
|
||||||
local outfile="$2"
|
local outfile="$2"
|
||||||
resolve_dependencies "$DEPS_BASEDIR" "$DEPS"
|
|
||||||
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 -name '*.o')
|
local objects="$(find $OBJDIR/objects -name '*.o')
|
||||||
$(find $OBJDIR/libs -name '*.a')"
|
$(find $OBJDIR/libs -name '*.a')"
|
||||||
myprint "${BLUE}objects: ${GRAY}$objects"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
local command="$CMP_CPP $(echo "$objects" | tr '\n' ' ') $args -o $OUTDIR/$outfile"
|
local command="$CMP_CPP $(safeprint "$objects" | tr '\n' ' ') $args -o $OUTDIR/$outfile"
|
||||||
myprint "$command"
|
myprint "$command"
|
||||||
if $command
|
if $command
|
||||||
then
|
then
|
||||||
|
|||||||
78
init.sh
78
init.sh
@ -1,78 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
tabs 4
|
|
||||||
|
|
||||||
# exit on errors
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
source cbuild/colors.sh
|
|
||||||
source cbuild/functions.sh
|
|
||||||
source cbuild/detect_os.sh
|
|
||||||
|
|
||||||
|
|
||||||
# copying default config from cbuild if it not exists
|
|
||||||
if [ ! -f default.config ]; then
|
|
||||||
cp cbuild/default.config default.config
|
|
||||||
myprint "${YELLOW}Default config didn't exist, copied from cbuild."
|
|
||||||
fi
|
|
||||||
|
|
||||||
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
|
|
||||||
exec_script_line cbuild/default.config 2
|
|
||||||
INSTALLED_CBUILD_VERSION="$CBUILD_VERSION"
|
|
||||||
unset CBUILD_VERSION
|
|
||||||
|
|
||||||
# getting version of default config
|
|
||||||
exec_script_line default.config 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 ]; then
|
|
||||||
myprint "${YELLOW}./current.config doesn't exist"
|
|
||||||
cp default.config current.config
|
|
||||||
myprint "${YELLOW}New config created from the default.\nEdit it."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
myprint "${BLUE}reading ./current.config"
|
|
||||||
source current.config
|
|
||||||
|
|
||||||
myprint "${WHITE}project: ${CYAN}$PROJECT"
|
|
||||||
|
|
||||||
myprint "${WHITE}current.config cbuild version: ${CYAN}$CBUILD_VERSION"
|
|
||||||
myprint "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
|
|
||||||
myprint "${WHITE}current.config version: ${CYAN}$CONFIG_VERSION"
|
|
||||||
myprint "${WHITE}default.config 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!"
|
|
||||||
82
myprint.sh
Normal file
82
myprint.sh
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
BLACK='\033[0;30m'
|
||||||
|
GRAY='\033[0;37m'
|
||||||
|
WHITE='\033[0;97m'
|
||||||
|
RED='\033[0;91m'
|
||||||
|
GREEN='\033[0;92m'
|
||||||
|
YELLOW='\033[0;93m'
|
||||||
|
BLUE='\033[0;94m'
|
||||||
|
PURPLE='\033[0;95m'
|
||||||
|
CYAN='\033[0;96m'
|
||||||
|
|
||||||
|
# prints text without new line
|
||||||
|
# use it to return string values from functions
|
||||||
|
function safeprint {
|
||||||
|
printf "%s" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prints text with new line and resets color
|
||||||
|
function myprint {
|
||||||
|
safeprint "$@${GRAY}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# print message and exit
|
||||||
|
function error {
|
||||||
|
myprint "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# asks a question with two options and returns 0 or 1
|
||||||
|
# usage: `if ask_yn "do something?"`
|
||||||
|
function ask_yn {
|
||||||
|
local answ=""
|
||||||
|
myprint "$@ [y/n]"
|
||||||
|
read -r answ
|
||||||
|
return $([[ "$answ" = [Yy] ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
# asks a question and prints answer
|
||||||
|
function ask {
|
||||||
|
local answ=""
|
||||||
|
myprint "$@: "
|
||||||
|
read -r answ
|
||||||
|
safeprint "$answ"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prints horizontal line occupying whole terminal row
|
||||||
|
# https://en.wikipedia.org/wiki/Box-drawing_characters
|
||||||
|
function print_hline {
|
||||||
|
local color="$1"
|
||||||
|
local character="$2"
|
||||||
|
if [ -z "$color" ]; then
|
||||||
|
color="${GRAY}"
|
||||||
|
fi
|
||||||
|
if [ -z "$character" ]; then
|
||||||
|
character="-";
|
||||||
|
fi
|
||||||
|
printf "${color}%.s${character}" $(seq 2 $(tput cols))
|
||||||
|
printf "${GRAY}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prints horizontal line occupying whole terminal row with a given label
|
||||||
|
function print_header {
|
||||||
|
local color="$1"
|
||||||
|
local character="$2"
|
||||||
|
local label="$3"
|
||||||
|
if [ -z "$color" ]; then
|
||||||
|
color="${GRAY}"
|
||||||
|
fi
|
||||||
|
if [ -z "$character" ]; then
|
||||||
|
character="-";
|
||||||
|
fi
|
||||||
|
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)
|
||||||
|
printf "${GRAY}\n"
|
||||||
|
}
|
||||||
@ -1,7 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
source "cbuild/init.sh"
|
echo "ERROR: rebuild_dep.sh IS OBSOLETE"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
include "cbuild/config.sh"
|
||||||
|
|
||||||
|
load_config
|
||||||
target_file="$1"
|
target_file="$1"
|
||||||
touch ".rebuild_$target_file.tmp"
|
touch ".rebuild_$target_file.tmp"
|
||||||
rm -fv "$OBJDIR/libs/$target_file"
|
rm -fv "$OBJDIR/libs/$target_file"
|
||||||
myprint "${YELLOW}dependency ${WHITE}$target_file ${YELLOW}will be rebuilt with the next build task"
|
myprint "${YELLOW}dependency ${WHITE}$target_file ${YELLOW}will be rebuilt during the next build task"
|
||||||
|
|||||||
35
setup.sh
35
setup.sh
@ -1,32 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# exit on errors
|
# exit on errors
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
set -x
|
||||||
|
|
||||||
# help
|
if [ -z "$CBUILD_INSTALL_DIR" ]; then
|
||||||
if [ $# -eq 0 ] || [ "$1" = "h" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "/?" ]; then
|
CBUILD_INSTALL_DIR="/usr/local/share/cbuild"
|
||||||
echo "usage: setup.sh [ submodule | standalone ]"
|
|
||||||
echo " submodule - add to existing git repo as submodule"
|
|
||||||
echo " standalone - keep independent git repo"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$1" in
|
if [ "$CBUILD_INSTALL_DIR" != "." ]; then
|
||||||
submodule)
|
cp -r ./ "$CBUILD_INSTALL_DIR"
|
||||||
echo "mode - $1"
|
rm -rf "$CBUILD_INSTALL_DIR/.git"
|
||||||
git submodule add ./cbuild
|
fi
|
||||||
;;
|
ln -sfv "$(realpath $CBUILD_INSTALL_DIR/cbuild.sh)" -T "/usr/local/bin/cbuild"
|
||||||
standalone)
|
|
||||||
echo "mode - $1"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "invalid argument: $1"
|
|
||||||
exit -1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cp cbuild/default.Makefile Makefile
|
|
||||||
cp cbuild/default.config ./
|
|
||||||
|
|
||||||
echo "copy default .gitignore? [y/any]"
|
|
||||||
read answ
|
|
||||||
[[ "$answ"="y" ]] && cp cbuild/.gitignore ./
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user