build_profile, make.log and other stuff
This commit is contained in:
parent
1b38b43c54
commit
a0cdbf5522
35
call_task.sh
35
call_task.sh
@ -1,24 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function call_task {
|
function exec_script {
|
||||||
TASK=$1
|
myprint "${BLUE}executing $1"
|
||||||
printf "${CYAN}===========[$TASK]===========\n"
|
source "$1"
|
||||||
source cbuild/init.sh
|
}
|
||||||
|
|
||||||
clear_dir $OBJDIR
|
function try_exec_script {
|
||||||
|
if [ -f "$1" ]; then
|
||||||
if [ -f "$PRE_TASK_SCRIPT" ]; then
|
exec_script "$1"
|
||||||
printf "${BLUE}executing $PRE_TASK_SCRIPT\n"
|
|
||||||
source "$PRE_TASK_SCRIPT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
source $TASK_SCRIPT
|
|
||||||
printf "${GRAY}"
|
|
||||||
|
|
||||||
if [ -f "$POST_TASK_SCRIPT" ]; then
|
|
||||||
printf "${BLUE}executing $POST_TASK_SCRIPT\n"
|
|
||||||
source "$POST_TASK_SCRIPT"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
time call_task $1
|
function call_task {
|
||||||
|
TASK="$1"
|
||||||
|
source cbuild/init.sh
|
||||||
|
myprint "${CYAN}===========[$TASK]==========="
|
||||||
|
try_exec_script "$PRE_TASK_SCRIPT"
|
||||||
|
exec_script "$TASK_SCRIPT"
|
||||||
|
try_exec_script "$POST_TASK_SCRIPT"
|
||||||
|
}
|
||||||
|
|
||||||
|
time call_task "$1"
|
||||||
|
|||||||
@ -2,6 +2,6 @@
|
|||||||
SCRIPTS="$(find ./ -name '*.sh')"
|
SCRIPTS="$(find ./ -name '*.sh')"
|
||||||
for F in $SCRIPTS
|
for F in $SCRIPTS
|
||||||
do
|
do
|
||||||
echo $F
|
echo "$F"
|
||||||
chmod +x $F
|
chmod +x "$F"
|
||||||
done
|
done
|
||||||
|
|||||||
@ -1,24 +1,68 @@
|
|||||||
all: build_exec
|
######################################
|
||||||
|
###### Build tasks #######
|
||||||
|
######################################
|
||||||
|
|
||||||
###### Build cbuild/default_tasks #######
|
all: build_exec_dbg
|
||||||
build_exec:
|
|
||||||
@cbuild/call_task.sh build_exec
|
# generates different profile info
|
||||||
|
build_profile:
|
||||||
|
@cbuild/call_task.sh build_profile 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates executable using profile info generated by build_profile
|
||||||
|
build_exec: build_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:
|
build_exec_dbg:
|
||||||
@cbuild/call_task.sh build_exec_dbg
|
@cbuild/call_task.sh build_exec_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates shared library
|
||||||
build_shared_lib:
|
build_shared_lib:
|
||||||
@cbuild/call_task.sh 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:
|
build_shared_lib_dbg:
|
||||||
@cbuild/call_task.sh build_shared_lib_dbg
|
@cbuild/call_task.sh build_shared_lib_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
|
# creates static library
|
||||||
build_static_lib:
|
build_static_lib:
|
||||||
@cbuild/call_task.sh 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:
|
build_static_lib_dbg:
|
||||||
@cbuild/call_task.sh build_static_lib_dbg
|
@cbuild/call_task.sh build_static_lib_dbg 2>&1 | tee make_raw.log
|
||||||
|
|
||||||
###### Launch cbuild/default_tasks #######
|
######################################
|
||||||
|
###### Launch tasks #######
|
||||||
|
######################################
|
||||||
|
|
||||||
|
# executes $EXEC_FILE
|
||||||
exec: build_exec
|
exec: build_exec
|
||||||
@cbuild/call_task.sh 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_dbg 2>&1 | tee -a make_raw.log
|
||||||
|
|
||||||
|
# executes $EXEC_FILE with valgrind memory checker
|
||||||
valgrind: build_exec_dbg
|
valgrind: build_exec_dbg
|
||||||
@cbuild/call_task.sh valgrind
|
@cbuild/call_task.sh valgrind 2>&1 | tee -a 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,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CBUILD_VERSION=4
|
CBUILD_VERSION=5
|
||||||
CONFIG_VERSION=1
|
CONFIG_VERSION=1
|
||||||
|
|
||||||
PROJECT="NULL"
|
PROJECT="NULL"
|
||||||
@ -14,77 +14,117 @@ 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')"
|
||||||
|
|
||||||
OUTDIR=bin
|
# OBJDIR structure:
|
||||||
OBJDIR=obj
|
# ├── objects - dir where compiled *.o files are stored. cleans every call of build task
|
||||||
STATIC_LIB_FILE=$PROJECT.a
|
# ├── profile - dir where gcc *.gcda profiling info files stored
|
||||||
|
# ├── libs - there you can put static libs and linker will find them
|
||||||
|
# └── out - output files are created here and then copied to OUTDIR
|
||||||
|
OBJDIR="obj"
|
||||||
|
OUTDIR="bin"
|
||||||
|
STATIC_LIB_FILE="$PROJECT.a"
|
||||||
|
|
||||||
case $OS in
|
# OS-specific options
|
||||||
|
case "$OS" in
|
||||||
WINDOWS)
|
WINDOWS)
|
||||||
EXEC_FILE=$PROJECT.exe
|
EXEC_FILE="$PROJECT.exe"
|
||||||
SHARED_LIB_FILE=$PROJECT.dll
|
SHARED_LIB_FILE="$PROJECT.dll"
|
||||||
;;
|
;;
|
||||||
LINUX)
|
LINUX)
|
||||||
EXEC_FILE=$PROJECT
|
EXEC_FILE="$PROJECT.P"
|
||||||
SHARED_LIB_FILE=$PROJECT.so
|
SHARED_LIB_FILE="$PROJECT.so"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "${RED}operating system $OS has no configuration variants\n"
|
error "operating system $OS has no configuration variants"
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $TASK in
|
# TASKS
|
||||||
build_exec)
|
case "$TASK" in
|
||||||
C_ARGS="-O2"
|
# generates different profile info
|
||||||
|
build_profile)
|
||||||
|
OUTDIR="$OUTDIR/profile"
|
||||||
|
# -flto applies more optimizations across object files
|
||||||
|
# -flto=auto is needed to multithreaded copilation
|
||||||
|
# -fuse-linker-plugin is required to use static libs with lto, it strips away all
|
||||||
|
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
||||||
|
# -fprofile-generate
|
||||||
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -pg -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS=""
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
PRE_TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
PRE_TASK_SCRIPT=
|
TASK_SCRIPT=cbuild/default_tasks/profile.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# creates executable using profile info generated by build_profile
|
||||||
|
build_exec)
|
||||||
|
# -flto applies more optimizations across object files
|
||||||
|
# -flto=auto is needed to multithreaded copilation
|
||||||
|
# -fuse-linker-plugin is required to use static libs with lto, it strips away all
|
||||||
|
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
||||||
|
CPP_ARGS="$C_ARGS"
|
||||||
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
|
POST_TASK_SCRIPT=
|
||||||
|
;;
|
||||||
|
# creates executable with debug info and no optimizations
|
||||||
build_exec_dbg)
|
build_exec_dbg)
|
||||||
C_ARGS="-O0 -g"
|
C_ARGS="-O0 -g"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS=""
|
LINKER_ARGS="$CPP_ARGS"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_exec.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# creates shared library
|
||||||
build_shared_lib)
|
build_shared_lib)
|
||||||
C_ARGS="-O2 -fpic -flto -shared"
|
C_ARGS="-O2 -fpic -flto -shared"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="-Wl,-soname,$SHARED_LIB_FILE"
|
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# creates shared library with debug symbols and no optimizations
|
||||||
build_shared_lib_dbg)
|
build_shared_lib_dbg)
|
||||||
C_ARGS="-O0 -g -fpic -shared"
|
C_ARGS="-O0 -g -fpic -shared"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
LINKER_ARGS="-Wl,-soname,$SHARED_LIB_FILE"
|
LINKER_ARGS="$CPP_ARGS -Wl,-soname,$SHARED_LIB_FILE"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_shared_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# creates static library
|
||||||
build_static_lib)
|
build_static_lib)
|
||||||
C_ARGS="-O2 -fpic"
|
C_ARGS="-O2 -fpic"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# creates static library with debug symbols and no optimizations
|
||||||
build_static_lib_dbg)
|
build_static_lib_dbg)
|
||||||
C_ARGS="-O0 -g"
|
C_ARGS="-O0 -g"
|
||||||
CPP_ARGS="$C_ARGS"
|
CPP_ARGS="$C_ARGS"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
|
||||||
PRE_TASK_SCRIPT=
|
PRE_TASK_SCRIPT=
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/build_static_lib.sh
|
||||||
POST_TASK_SCRIPT=
|
POST_TASK_SCRIPT=
|
||||||
;;
|
;;
|
||||||
|
# executes $EXEC_FILE
|
||||||
exec)
|
exec)
|
||||||
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
TASK_SCRIPT=cbuild/default_tasks/exec.sh
|
||||||
;;
|
;;
|
||||||
|
# executes $EXEC_FILE with valgrind memory checker
|
||||||
valgrind)
|
valgrind)
|
||||||
VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all"
|
VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all"
|
||||||
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
TASK_SCRIPT=cbuild/default_tasks/valgrind.sh
|
||||||
;;
|
;;
|
||||||
|
# deletes generated files
|
||||||
|
clean)
|
||||||
|
TASK_SCRIPT=cbuild/default_tasks/clean.sh
|
||||||
|
;;
|
||||||
|
# unknown task
|
||||||
|
*)
|
||||||
|
error "task <$TASK> not found"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -1,5 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# delete old objects
|
||||||
|
clean_dir "$OBJDIR/objects"
|
||||||
|
|
||||||
|
# copy profiling info
|
||||||
|
prof_files=$(find "$OBJDIR/profile/" -name '*.gcda')
|
||||||
|
if [ -z "$prof_files" ]; then
|
||||||
|
myprint "${YELLOW}no profiling info found"
|
||||||
|
else
|
||||||
|
for prof_file in $prof_files; do
|
||||||
|
myprint "${GRAY}$(basename $prof_file)"
|
||||||
|
cp $prof_file "$OBJDIR/objects/"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
compile_c "$C_ARGS" "$SRC_C $TESTS_C"
|
compile_c "$C_ARGS" "$SRC_C $TESTS_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP $TESTS_CPP"
|
compile_cpp "$CPP_ARGS" "$SRC_CPP $TESTS_CPP"
|
||||||
link "$CPP_ARGS" "$EXEC_FILE"
|
link "$LINKER_ARGS" "$EXEC_FILE"
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# delete old objects
|
||||||
|
clean_dir "$OBJDIR/objects"
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
compile_c "$C_ARGS" "$SRC_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
||||||
link "$CPP_ARGS" "$SHARED_LIB_FILE"
|
link "$LINKER_ARGS" "$SHARED_LIB_FILE"
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# delete old objects
|
||||||
|
clean_dir "$OBJDIR/objects"
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
compile_c "$C_ARGS" "$SRC_C"
|
||||||
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
compile_cpp "$CPP_ARGS" "$SRC_CPP"
|
||||||
pack_static_lib "$STATIC_LIB_FILE"
|
pack_static_lib "$STATIC_LIB_FILE"
|
||||||
|
|||||||
4
default_tasks/clean.sh
Normal file
4
default_tasks/clean.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
delete_dir "$OBJDIR"
|
||||||
|
delete_dir "$OUTDIR"
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd $OUTDIR
|
cd "$OUTDIR"
|
||||||
./$EXEC_FILE
|
./$EXEC_FILE
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
25
default_tasks/profile.sh
Normal file
25
default_tasks/profile.sh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd "$OUTDIR"
|
||||||
|
|
||||||
|
# deleting all files except excutable
|
||||||
|
echo "$(find . ! -name $EXEC_FILE -type f -delete)"
|
||||||
|
|
||||||
|
# executing file compiled with -pg and -fprofile-gen
|
||||||
|
myprint "${BLUE}executing $OUTDIR/$EXEC_FILE"
|
||||||
|
./$EXEC_FILE > exec.log
|
||||||
|
myprint "${GREEN}execution log saved to ${CYAN}$OUTDIR/exec.log"
|
||||||
|
|
||||||
|
# moving *.gcda files from $OBJDIR/objects to $OBJDIR/profile
|
||||||
|
clean_dir ../../$OBJDIR/profile
|
||||||
|
mv ../../$OBJDIR/objects/*.gcda ../../$OBJDIR/profile/
|
||||||
|
myprint "${GREEN}$(ls ../../$OBJDIR/profile | wc -l) *.gcda profiling files have written to $OBJDIR/profile"
|
||||||
|
|
||||||
|
# generating function call graph
|
||||||
|
myprint "${BLUE}generating function call graph..."
|
||||||
|
gprof ./$EXEC_FILE > gprof.log
|
||||||
|
gprof2dot gprof.log > gprof2dot.graph
|
||||||
|
dot gprof2dot.graph -Tpng -Gdpi=300 -o gprof2dot.png
|
||||||
|
myprint "${GREEN}function call graph saved to ${CYAN}$OUTDIR/gprof2dot.png"
|
||||||
|
|
||||||
|
cd ../..
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd $OUTDIR
|
cd "$OUTDIR"
|
||||||
valgrind $VALGRIND_ARGS ./$EXEC_FILE
|
valgrind $VALGRIND_ARGS ./$EXEC_FILE
|
||||||
cat "valgrind.log"
|
cat "valgrind.log"
|
||||||
|
myprint "${GREEN}valgrind log saved to ${CYAN}$OUTDIR/exec.log"
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
11
detect_os.sh
11
detect_os.sh
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
source cbuild/colors.sh
|
source cbuild/colors.sh
|
||||||
|
|
||||||
uname_rezult=$(uname -o);
|
uname_rezult="$(uname -o)"
|
||||||
printf "${GRAY}uname rezult: '$uname_rezult'\n"
|
myprint "${GRAY}uname rezult: '$uname_rezult'"
|
||||||
|
|
||||||
case $uname_rezult in
|
case "$uname_rezult" in
|
||||||
Msys | Cygwin | "MS/Windows")
|
Msys | Cygwin | "MS/Windows")
|
||||||
OS=WINDOWS
|
OS=WINDOWS
|
||||||
;;
|
;;
|
||||||
@ -19,9 +19,8 @@ case $uname_rezult in
|
|||||||
OS=MACOS
|
OS=MACOS
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "${RED}unknown operating system: $uname_rezult\n"
|
error "unknown operating system: $uname_rezult"
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
printf "${GREEN}detected OS: $OS\n"
|
myprint "${GREEN}detected OS: $OS"
|
||||||
|
|||||||
107
functions.sh
107
functions.sh
@ -1,88 +1,107 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
function clear_dir {
|
function myprint {
|
||||||
printf "${BLUE}clearing $1\n${GRAY}"
|
printf "$@${GRAY}\n"
|
||||||
rm -rf $1
|
|
||||||
mkdir $1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error {
|
||||||
|
myprint "${RED}$1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function clean_dir {
|
||||||
|
local dir="$1"
|
||||||
|
myprint "${WHITE}cleaning $dir"
|
||||||
|
rm -rf "$dir"
|
||||||
|
mkdir "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete_dir {
|
||||||
|
local dir="$1"
|
||||||
|
myprint "${WHITE}deleting $dir"
|
||||||
|
rm -rf "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function compile {
|
function compile {
|
||||||
local cmp=$1
|
local cmp="$1"
|
||||||
printf "${BLUE}compiler: ${GRAY}$cmp\n"
|
myprint "${BLUE}compiler: ${GRAY}$cmp"
|
||||||
local std=$2
|
local std="$2"
|
||||||
printf "${BLUE}standard: ${GRAY}$std\n"
|
myprint "${BLUE}standard: ${GRAY}$std"
|
||||||
local warn=$3
|
local warn="$3"
|
||||||
printf "${BLUE}warnings: ${GRAY}$warn\n"
|
myprint "${BLUE}warnings: ${GRAY}$warn"
|
||||||
local args=$4
|
local args="$4"
|
||||||
printf "${BLUE}args: ${GRAY}$args\n"
|
myprint "${BLUE}args: ${GRAY}$args"
|
||||||
local sources=$5
|
local sources="$5"
|
||||||
printf "${BLUE}sources: ${GRAY}$sources\n"
|
myprint "${BLUE}sources: ${GRAY}$sources"
|
||||||
local compilation_error=0
|
local compilation_error=0
|
||||||
|
|
||||||
for srcfile in $sources
|
for srcfile in $sources
|
||||||
do (
|
do (
|
||||||
local object="$OBJDIR/$(basename $srcfile).o"
|
local object="$OBJDIR/objects/$(basename $srcfile).o"
|
||||||
if ! $($cmp -std=$std $warn $args -c -o $object $srcfile)
|
if ! $($cmp -std=$std $warn $args -c -o $object $srcfile)
|
||||||
then
|
then
|
||||||
printf "${RED}some error happened\n"
|
error "some error happened"
|
||||||
#TODO parallel variable assignement doesnt work in bash
|
#TODO parallel variable assignement doesnt work in bash
|
||||||
compilation_error=1
|
compilation_error=1
|
||||||
fi
|
fi
|
||||||
) & done
|
) & done
|
||||||
wait
|
wait
|
||||||
|
|
||||||
printf "${GRAY}"
|
#TODO doesnt work with multithreading
|
||||||
if [ $compilation_error != 0 ]
|
if [ $compilation_error != 0 ]
|
||||||
then
|
then
|
||||||
exit 1
|
exit -50
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_c {
|
function compile_c {
|
||||||
printf "${CYAN}-------------[compile_c]--------------\n"
|
myprint "${CYAN}-------------[compile_c]--------------"
|
||||||
compile $CMP_C $STD_C "$WARN_C" "$1" "$2"
|
compile "$CMP_C" "$STD_C" "$WARN_C" "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (args, sources)
|
# (args, sources)
|
||||||
function compile_cpp {
|
function compile_cpp {
|
||||||
printf "${CYAN}------------[compile_cpp]-------------\n"
|
myprint "${CYAN}------------[compile_cpp]-------------"
|
||||||
compile $CMP_CPP $STD_CPP "$WARN_CPP" "$1" "$2"
|
compile "$CMP_CPP" "$STD_CPP" "$WARN_CPP" "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# (args, outfile)
|
# (args, outfile)
|
||||||
function link {
|
function link {
|
||||||
printf "${CYAN}----------------[link]----------------\n"
|
myprint "${CYAN}----------------[link]----------------"
|
||||||
local args=$1
|
local args="$1"
|
||||||
printf "${BLUE}args: ${GRAY}$args\n"
|
myprint "${BLUE}args: ${GRAY}$args"
|
||||||
local outfile=$OUTDIR/$2
|
local outfile="$2"
|
||||||
printf "${BLUE}outfile: ${GRAY}$outfile\n"
|
clean_dir $OBJDIR/out
|
||||||
local objects="$(find $OBJDIR -name '*.o')
|
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||||
$(find $OBJDIR -name '*.a')"
|
local objects="$(find $OBJDIR/objects -name '*.o')
|
||||||
printf "${BLUE}objects: ${GRAY}$objects\n"
|
$(find $OBJDIR/libs -name '*.a')"
|
||||||
local command="$CMP_CPP $args $(echo $objects | tr '\n' ' ') $LINKER_ARGS -o $outfile"
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
printf "$command\n"
|
local command="$CMP_CPP $args $(echo "$objects" | tr '\n' ' ') -o $OBJDIR/out/$outfile"
|
||||||
|
myprint "$command"
|
||||||
if $command
|
if $command
|
||||||
then
|
then
|
||||||
printf "${GREEN}file $CYAN$outfile ${GREEN}created\n${GRAY}"
|
cp "$OBJDIR/out/$outfile" "$OUTDIR/$outfile"
|
||||||
|
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||||
else
|
else
|
||||||
printf "${RED}some error happened\n${GRAY}"
|
error "some error happened"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# (outfile)
|
# (outfile)
|
||||||
function pack_static_lib {
|
function pack_static_lib {
|
||||||
printf "${CYAN}----------[pack_static_lib]-----------\n"
|
myprint "${CYAN}----------[pack_static_lib]-----------"
|
||||||
local outfile=$OUTDIR/$1
|
local outfile="$OUTDIR/$1"
|
||||||
printf "${BLUE}outfile: ${GRAY}$outfile\n"
|
myprint "${BLUE}outfile: ${GRAY}$outfile"
|
||||||
local objects="$(find $OBJDIR -name *.o)"
|
local objects="$(find $OBJDIR/objects -name *.o)
|
||||||
printf "${BLUE}objects: ${GRAY}$objects\n"
|
$(find $OBJDIR/libs -name '*.a')"
|
||||||
if ar rcs $outfile $(echo $objects | tr '\n' ' ')
|
myprint "${BLUE}objects: ${GRAY}$objects"
|
||||||
|
if gcc-ar rcs -o "$OBJDIR/out/$outfile" $(echo "$objects" | tr '\n' ' ')
|
||||||
then
|
then
|
||||||
printf "${GREEN}file $CYAN$outfile ${GREEN}created\n${GRAY}"
|
cp "$OBJDIR/out/$outfile" "$OUTDIR/$outfile"
|
||||||
|
myprint "${GREEN}file $CYAN$outfile ${GREEN}created"
|
||||||
else
|
else
|
||||||
printf "${RED}some error happened\n${GRAY}"
|
error "some error happened"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
59
init.sh
59
init.sh
@ -1,24 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# exit on errors
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
tabs 4
|
tabs 4
|
||||||
|
|
||||||
source cbuild/colors.sh
|
source cbuild/colors.sh
|
||||||
source cbuild/functions.sh
|
source cbuild/functions.sh
|
||||||
source cbuild/detect_os.sh
|
source cbuild/detect_os.sh
|
||||||
|
|
||||||
# exit on errors
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
# copying default config from cbuild if it not exists
|
# copying default config from cbuild if it not exists
|
||||||
if [ ! -f default.config ]; then
|
if [ ! -f default.config ]; then
|
||||||
cp cbuild/default.config default.config
|
cp cbuild/default.config default.config
|
||||||
printf "${YELLOW}Default config didn't exist, copied from cbuild.\n"
|
myprint "${YELLOW}Default config didn't exist, copied from cbuild."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source ./default.config
|
function exec_script_line {
|
||||||
# getting some values from default config
|
local script="$1"
|
||||||
DEFAULT_CONFIG_VERSION=$CONFIG_VERSION
|
local line_num="$2"
|
||||||
source cbuild/default.config
|
myprint "${BLUE}reading line $line_num from $script"
|
||||||
DEFAULT_CBUILD_VERSION=$CBUILD_VERSION
|
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
|
||||||
|
|
||||||
|
|
||||||
# error on undefined
|
# error on undefined
|
||||||
@ -26,26 +41,34 @@ set -u
|
|||||||
|
|
||||||
# reading current config or creating default
|
# reading current config or creating default
|
||||||
if [ ! -f current.config ]; then
|
if [ ! -f current.config ]; then
|
||||||
printf "${YELLOW}./current.config doesn't exist\n"
|
myprint "${YELLOW}./current.config doesn't exist"
|
||||||
cp default.config current.config
|
cp default.config current.config
|
||||||
printf "${YELLOW}New config created from the default.\nEdit it.\n${GRAY}"
|
myprint "${YELLOW}New config created from the default.\nEdit it."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
printf "Reading ./current.config\n"
|
myprint "${BLUE}reading ./current.config"
|
||||||
source current.config
|
source current.config
|
||||||
|
|
||||||
|
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
|
# checking versions
|
||||||
if [ ! $CBUILD_VERSION -eq $DEFAULT_CBUILD_VERSION ]; then
|
if [ ! "$CBUILD_VERSION" -eq "$INSTALLED_CBUILD_VERSION" ]; then
|
||||||
printf "${RED}config was created for outdated cbuild version\n${GRAY}"
|
error "config was created for outdated cbuild version"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
if [ ! $CONFIG_VERSION -eq $DEFAULT_CONFIG_VERSION ]; then
|
if [ ! "$CONFIG_VERSION" -eq "$DEFAULT_CONFIG_VERSION" ]; then
|
||||||
printf "${RED}config version isn't correct\n${GRAY}"
|
error "config version isn't correct"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$OUTDIR"
|
mkdir -p "$OUTDIR"
|
||||||
mkdir -p "$OBJDIR"
|
mkdir -p "$OBJDIR/libs"
|
||||||
|
mkdir -p "$OBJDIR/objects"
|
||||||
|
mkdir -p "$OBJDIR/profile"
|
||||||
|
mkdir -p "$OBJDIR/out"
|
||||||
|
|
||||||
# dont thorw error on undefined variable
|
# dont thorw error on undefined variable
|
||||||
set +u
|
set +u
|
||||||
|
|
||||||
|
myprint "${GREEN}cbuild initialized!"
|
||||||
|
|||||||
9
setup.sh
9
setup.sh
@ -1,12 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# exit on errors
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
# help
|
||||||
if [ $# -eq 0 ] || [ "$1" = "h" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "/?" ]; then
|
if [ $# -eq 0 ] || [ "$1" = "h" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "/?" ]; then
|
||||||
echo "usage: setup.sh [ submodule | standalone ]"
|
echo "usage: setup.sh [ submodule | standalone ]"
|
||||||
echo " submodule - add to existing git repo as submodule"
|
echo " submodule - add to existing git repo as submodule"
|
||||||
echo " standalone - keep independent git repo"
|
echo " standalone - keep independent git repo"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $1 in
|
case "$1" in
|
||||||
submodule)
|
submodule)
|
||||||
echo "mode - $1"
|
echo "mode - $1"
|
||||||
git submodule add cbuild
|
git submodule add cbuild
|
||||||
@ -16,10 +20,9 @@ case $1 in
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "invalid argument: $1"
|
echo "invalid argument: $1"
|
||||||
exit 1
|
exit -1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
cp cbuild/default.Makefile Makefile
|
cp cbuild/default.Makefile Makefile
|
||||||
cp cbuild/default.config ./
|
cp cbuild/default.config ./
|
||||||
#bash cbuild/chmod_scripts.sh
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user