first commit
This commit is contained in:
commit
990af1d10c
15
README.md
Normal file
15
README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# cbuild
|
||||
My C/C++ build system written in bash.
|
||||
|
||||
Repo contains some scripts (functions, init, etc.), which can be used in your custom task scripts. There are also some default tasks.
|
||||
|
||||
All tasks should be launched through `Makefile`. Tasks can be configured in `.config` file (it is automatically created by init.sh).
|
||||
|
||||
## How to set up
|
||||
|
||||
```bash
|
||||
cd some_project
|
||||
git clone http://github.com/Timerix22/cbuild.git
|
||||
cp cbuild/default.Makefile Makefile
|
||||
make
|
||||
```
|
||||
11
colors.sh
Normal file
11
colors.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/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'
|
||||
24
default.Makefile
Normal file
24
default.Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
###### Build cbuild/default_tasks #######
|
||||
build_exec:
|
||||
@cbuild/default_tasks/build_exec.sh
|
||||
build_exec_dbg:
|
||||
@cbuild/default_tasks/build_exec_dbg.sh
|
||||
|
||||
build_shared_lib:
|
||||
@cbuild/default_tasks/build_shared_lib.sh
|
||||
build_shared_lib_dbg:
|
||||
@cbuild/default_tasks/build_shared_lib_dbg.sh
|
||||
|
||||
build_static_lib:
|
||||
@cbuild/default_tasks/build_static_lib.sh
|
||||
build_static_lib_dbg:
|
||||
@cbuild/default_tasks/build_static_lib_dbg.sh
|
||||
|
||||
###### Launch cbuild/default_tasks #######
|
||||
exec: build_exec
|
||||
@cbuild/default_tasks/exec.sh
|
||||
|
||||
valgrind: build_exec_dbg
|
||||
@cbuild/default_tasks/valgrind.sh
|
||||
|
||||
all: build_exec
|
||||
40
default.config.sh
Normal file
40
default.config.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
PROJECT=some_project
|
||||
OUTDIR=bin
|
||||
OBJDIR=obj
|
||||
CMP_C=gcc
|
||||
CMP_CPP=g++
|
||||
STD_C=c11
|
||||
STD_CPP=c++17
|
||||
WARN_C="-Wall -Wno-discarded-qualifiers"
|
||||
WARN_CPP="-Wall"
|
||||
SRC_C="$( find src -name '*.c')"
|
||||
SRC_CPP="$( find src -name '*.cpp')"
|
||||
TESTS_C="$( find tests -name '*.c')"
|
||||
TESTS_CPP="$(find tests -name '*.cpp')"
|
||||
VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$POJECT/ --leak-check=full --show-leak-kinds=all"
|
||||
|
||||
# build_exec
|
||||
EXEC_FILE=$POJECT.com
|
||||
BUILD_EXEC_C_ARGS="-O2"
|
||||
BUILD_EXEC_CPP_ARGS="$BUILD_EXEC_C_ARGS"
|
||||
BUILD_EXEC_LINKER_ARGS=""
|
||||
# build_exec_dbg
|
||||
BUILD_EXEC_DBG_C_ARGS="-O0 -g"
|
||||
BUILD_EXEC_DBG_CPP_ARGS="$BUILD_EXEC_DBG_C_ARGS"
|
||||
BUILD_EXEC_DBG_LINKER_ARGS=""
|
||||
|
||||
# build_shared_lib
|
||||
SHARED_LIB_FILE=$POJECT.so
|
||||
BUILD_SHARED_LIB_C_ARGS="-O2 -fpic -flto -shared"
|
||||
BUILD_SHARED_LIB_CPP_ARGS="$BUILD_SHARED_LIB_C_ARGS"
|
||||
BUILD_SHARED_LIB_LINKER_ARGS="-Wl,-soname,$SHARED_LIB_FILE"
|
||||
|
||||
# build_static_lib
|
||||
STATIC_LIB_FILE=$POJECT.a
|
||||
BUILD_STATIC_LIB_C_ARGS="-O2 -fpic"
|
||||
BUILD_STATIC_LIB_CPP_ARGS="$BUILD_STATIC_LIB_C_ARGS"
|
||||
# build_static_lib_dbg
|
||||
BUILD_STATIC_LIB_DBG_C_ARGS="-O0 -g"
|
||||
BUILD_STATIC_LIB_DBG_CPP_ARGS="$BUILD_STATIC_LIB_DBG_C_ARGS"
|
||||
10
default_tasks/build_exec.sh
Normal file
10
default_tasks/build_exec.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}=============[build_exec]=============\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_EXEC_C_ARGS" "$SRC_C $TESTS_C"
|
||||
compile_cpp "$BUILD_EXEC_CPP_ARGS" "$SRC_CPP $TESTS_CPP"
|
||||
link "$BUILD_EXEC_CPP_ARGS $BUILD_EXEC_LINKER_ARGS" "$EXEC_FILE"
|
||||
10
default_tasks/build_exec_dbg.sh
Normal file
10
default_tasks/build_exec_dbg.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}===========[build_exec_dbg]===========\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_EXEC_DBG_C_ARGS" "$SRC_C $TESTS_C"
|
||||
compile_cpp "$BUILD_EXEC_DBG_CPP_ARGS" "$SRC_CPP $TESTS_CPP"
|
||||
link "$BUILD_EXEC_DBG_CPP_ARGS $BUILD_EXEC_DBG_LINKER_ARGS" "$EXEC_FILE"
|
||||
10
default_tasks/build_shared_lib.sh
Normal file
10
default_tasks/build_shared_lib.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}==========[build_shared_lib]==========\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_SHARED_LIB_C_ARGS" "$SRC_C"
|
||||
compile_cpp "$BUILD_SHARED_LIB_CPP_ARGS" "$SRC_CPP"
|
||||
link "$BUILD_SHARED_LIB_CPP_ARGS $BUILD_SHARED_LIB_LINKER_ARGS" "$SHARED_LIB_FILE"
|
||||
10
default_tasks/build_shared_lib_dbg.sh
Normal file
10
default_tasks/build_shared_lib_dbg.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}========[build_shared_lib_dbg]========\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_SHARED_LIB_DBG_C_ARGS" "$SRC_C"
|
||||
compile_cpp "$BUILD_SHARED_LIB_DBG_CPP_ARGS" "$SRC_CPP"
|
||||
link "$BUILD_SHARED_LIB_DBG_CPP_ARGS $BUILD_SHARED_LIB_DBG_LINKER_ARGS" "$SHARED_LIB_FILE"
|
||||
10
default_tasks/build_static_lib.sh
Normal file
10
default_tasks/build_static_lib.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}==========[build_static_lib]==========\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_STATIC_LIB_C_ARGS" "$SRC_C"
|
||||
compile_cpp "$BUILD_STATIC_LIB_CPP_ARGS" "$SRC_CPP"
|
||||
pack_static_lib "$STATIC_LIB_FILE"
|
||||
10
default_tasks/build_static_lib_dbg.sh
Normal file
10
default_tasks/build_static_lib_dbg.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}==========[build_static_lib_dbg]==========\n"
|
||||
clear_dir "$OUTDIR"
|
||||
clear_dir "$OBJDIR"
|
||||
compile_c "$BUILD_STATIC_LIB_DBG_C_ARGS" "$SRC_C"
|
||||
compile_cpp "$BUILD_STATIC_LIB_DBG_CPP_ARGS" "$SRC_CPP"
|
||||
pack_static_lib "$STATIC_LIB_FILE"
|
||||
8
default_tasks/exec.sh
Normal file
8
default_tasks/exec.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}================[exec]================\n"
|
||||
cd $OUTDIR
|
||||
./$EXEC_FILE
|
||||
cd ..
|
||||
9
default_tasks/valgrind.sh
Normal file
9
default_tasks/valgrind.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
source cbuild/init.sh
|
||||
|
||||
print "${CYAN}==============[valgrind]==============\n"
|
||||
cd $OUTDIR
|
||||
valgrind $VALGRIND_ARGS ./$EXEC_FILE
|
||||
cat "valgrind.log"
|
||||
cd ..
|
||||
90
functions.sh
Normal file
90
functions.sh
Normal file
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
function print {
|
||||
printf "$1$GRAY"
|
||||
}
|
||||
|
||||
function clear_dir {
|
||||
print "${BLUE}clearing $1\n"
|
||||
rm -rf $1
|
||||
mkdir $1
|
||||
}
|
||||
|
||||
function compile {
|
||||
local cmp=$1
|
||||
print "${BLUE}compiler: ${GRAY}$cmp\n"
|
||||
local std=$2
|
||||
print "${BLUE}standard: ${GRAY}$std\n"
|
||||
local warn=$3
|
||||
print "${BLUE}warnings: ${GRAY}$warn\n"
|
||||
local args=$4
|
||||
print "${BLUE}args: ${GRAY}$args\n"
|
||||
local sources=$5
|
||||
print "${BLUE}sources: ${GRAY}$sources\n"
|
||||
local compilation_error=0
|
||||
|
||||
for srcfile in $sources
|
||||
do (
|
||||
local object="$OBJDIR/$(basename $srcfile).o"
|
||||
if ! $($cmp -std=$std $warn $args -c -o $object $srcfile)
|
||||
then
|
||||
print "${RED}some error happened\n"
|
||||
compilation_error=1
|
||||
fi
|
||||
) & done
|
||||
wait
|
||||
|
||||
if [ $compilation_error != 0 ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_c {
|
||||
print "${CYAN}-------------[compile_c]--------------\n"
|
||||
compile $CMP_C $STD_C "$WARN_C" "$1" "$2"
|
||||
}
|
||||
|
||||
# (args, sources)
|
||||
function compile_cpp {
|
||||
print "${CYAN}------------[compile_cpp]-------------\n"
|
||||
compile $CMP_CPP $STD_CPP "$WARN_CPP" "$1" "$2"
|
||||
}
|
||||
|
||||
# (args, outfile)
|
||||
function link {
|
||||
print "${CYAN}----------------[link]----------------\n"
|
||||
local args=$1
|
||||
print "${BLUE}args: ${GRAY}$args\n"
|
||||
local outfile=$OUTDIR/$2
|
||||
print "${BLUE}outfile: ${GRAY}$outfile\n"
|
||||
local objects="$(find $OBJDIR -name '*.o')
|
||||
$(find $OBJDIR -name '*.a')"
|
||||
print "${BLUE}objects: ${GRAY}$objects\n"
|
||||
if $CMP_CPP $args -o $outfile $(echo $objects | tr '\n' ' ')
|
||||
then
|
||||
print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
|
||||
rm -rf $OBJDIR
|
||||
else
|
||||
print "${RED}some error happened\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# (outfile)
|
||||
function pack_static_lib {
|
||||
print "${CYAN}----------------[link]----------------\n"
|
||||
local outfile=$OUTDIR/$1
|
||||
print "${BLUE}outfile: ${GRAY}$outfile\n"
|
||||
local objects="$(find $OBJDIR -name *.o)"
|
||||
print "${BLUE}objects: ${GRAY}$objects\n"
|
||||
if ar rcs $outfile $(echo $objects | tr '\n' ' ')
|
||||
then
|
||||
print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
|
||||
rm -rf $OBJDIR
|
||||
else
|
||||
print "${RED}some error happened\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
25
init.sh
Normal file
25
init.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
tabs 4
|
||||
|
||||
source cbuild/colors.sh
|
||||
source cbuild/functions.sh
|
||||
|
||||
#config
|
||||
if [ ! -f ".config" ]; then
|
||||
print "${YELLOW}./.config doesn't exist\n"
|
||||
cp cbuild/default.config.sh .config
|
||||
print "${YELLOW}Default config created.\nEdit it's values and continue."
|
||||
while true; do
|
||||
print "${WHITE}continue? (y/n) "
|
||||
read answ
|
||||
case $answ in
|
||||
[Yy] ) break;;
|
||||
[Nn] ) exit;;
|
||||
* ) print "${RED}incorrect answer\n";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
source .config
|
||||
Loading…
Reference in New Issue
Block a user