This commit is contained in:
timerix 2022-09-09 21:51:50 +06:00
parent bab334b928
commit 99aa4a4a03
3 changed files with 29 additions and 29 deletions

View File

@ -2,14 +2,14 @@
tabs 4 tabs 4
TASK=$1 TASK=$1
print "${CYAN}===========[$TASK]===========\n" myprint "${CYAN}===========[$TASK]===========\n"
source cbuild/init.sh source cbuild/init.sh
#pre_build #pre_build
clear_dir $OBJDIR clear_dir $OBJDIR
clear_dir $OUTDIR clear_dir $OUTDIR
if [ -f "$PRE_BUILD_SCRIPT" ]; then if [ -f "$PRE_BUILD_SCRIPT" ]; then
print "${BLUE}executing $PRE_BUILD_SCRIPT" myprint "${BLUE}executing $PRE_BUILD_SCRIPT"
source "$PRE_BUILD_SCRIPT" source "$PRE_BUILD_SCRIPT"
fi fi

View File

@ -1,26 +1,26 @@
#!/bin/bash #!/bin/bash
function print { function myprint {
printf "$1$GRAY" myprintf "$1$GRAY"
} }
function clear_dir { function clear_dir {
print "${BLUE}clearing $1\n" myprint "${BLUE}clearing $1\n"
rm -rf $1 rm -rf $1
mkdir $1 mkdir $1
} }
function compile { function compile {
local cmp=$1 local cmp=$1
print "${BLUE}compiler: ${GRAY}$cmp\n" myprint "${BLUE}compiler: ${GRAY}$cmp\n"
local std=$2 local std=$2
print "${BLUE}standard: ${GRAY}$std\n" myprint "${BLUE}standard: ${GRAY}$std\n"
local warn=$3 local warn=$3
print "${BLUE}warnings: ${GRAY}$warn\n" myprint "${BLUE}warnings: ${GRAY}$warn\n"
local args=$4 local args=$4
print "${BLUE}args: ${GRAY}$args\n" myprint "${BLUE}args: ${GRAY}$args\n"
local sources=$5 local sources=$5
print "${BLUE}sources: ${GRAY}$sources\n" myprint "${BLUE}sources: ${GRAY}$sources\n"
local compilation_error=0 local compilation_error=0
for srcfile in $sources for srcfile in $sources
@ -28,7 +28,7 @@ function compile {
local object="$OBJDIR/$(basename $srcfile).o" local object="$OBJDIR/$(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
print "${RED}some error happened\n" myprint "${RED}some error happened\n"
compilation_error=1 compilation_error=1
fi fi
) & done ) & done
@ -42,49 +42,49 @@ function compile {
# (args, sources) # (args, sources)
function compile_c { function compile_c {
print "${CYAN}-------------[compile_c]--------------\n" myprint "${CYAN}-------------[compile_c]--------------\n"
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 {
print "${CYAN}------------[compile_cpp]-------------\n" myprint "${CYAN}------------[compile_cpp]-------------\n"
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 {
print "${CYAN}----------------[link]----------------\n" myprint "${CYAN}----------------[link]----------------\n"
local args=$1 local args=$1
print "${BLUE}args: ${GRAY}$args\n" myprint "${BLUE}args: ${GRAY}$args\n"
local outfile=$OUTDIR/$2 local outfile=$OUTDIR/$2
print "${BLUE}outfile: ${GRAY}$outfile\n" myprint "${BLUE}outfile: ${GRAY}$outfile\n"
local objects="$(find $OBJDIR -name '*.o') local objects="$(find $OBJDIR -name '*.o')
$(find $OBJDIR -name '*.a')" $(find $OBJDIR -name '*.a')"
print "${BLUE}objects: ${GRAY}$objects\n" myprint "${BLUE}objects: ${GRAY}$objects\n"
if $CMP_CPP $args -o $outfile $(echo $objects | tr '\n' ' ') if $CMP_CPP $args -o $outfile $(echo $objects | tr '\n' ' ')
then then
print "${GREEN}file $CYAN$outfile ${GREEN}created\n" myprint "${GREEN}file $CYAN$outfile ${GREEN}created\n"
rm -rf $OBJDIR rm -rf $OBJDIR
else else
print "${RED}some error happened\n" myprint "${RED}some error happened\n"
exit 1 exit 1
fi fi
} }
# (outfile) # (outfile)
function pack_static_lib { function pack_static_lib {
print "${CYAN}----------------[link]----------------\n" myprint "${CYAN}----------------[link]----------------\n"
local outfile=$OUTDIR/$1 local outfile=$OUTDIR/$1
print "${BLUE}outfile: ${GRAY}$outfile\n" myprint "${BLUE}outfile: ${GRAY}$outfile\n"
local objects="$(find $OBJDIR -name *.o)" local objects="$(find $OBJDIR -name *.o)"
print "${BLUE}objects: ${GRAY}$objects\n" myprint "${BLUE}objects: ${GRAY}$objects\n"
if ar rcs $outfile $(echo $objects | tr '\n' ' ') if ar rcs $outfile $(echo $objects | tr '\n' ' ')
then then
print "${GREEN}file $CYAN$outfile ${GREEN}created\n" myprint "${GREEN}file $CYAN$outfile ${GREEN}created\n"
rm -rf $OBJDIR rm -rf $OBJDIR
else else
print "${RED}some error happened\n" myprint "${RED}some error happened\n"
exit 1 exit 1
fi fi
} }

10
init.sh
View File

@ -9,12 +9,12 @@ function create_default_config(){
else else
cp cbuild/default.config .config cp cbuild/default.config .config
fi fi
print "${YELLOW}Default config created.\nEdit it.\n" myprint "${YELLOW}Default config created.\nEdit it.\n"
} }
#.config #.config
if [ ! -f ".config" ]; then if [ ! -f ".config" ]; then
print "${YELLOW}./.config doesn't exist\n" myprint "${YELLOW}./.config doesn't exist\n"
create_default_config create_default_config
exit exit
fi fi
@ -22,9 +22,9 @@ source .config
#version check #version check
if [ ! $CONFIG_VER -eq 2 ]; then if [ ! $CONFIG_VER -eq 2 ]; then
print "${RED}Your config version isn't correct\n" myprint "${RED}Your config version isn't correct\n"
while true; do while true; do
print "${WHITE}Backup current config and create default one? (y/n) " myprint "${WHITE}Backup current config and create default one? (y/n) "
read answ read answ
case $answ in case $answ in
[Yy] ) [Yy] )
@ -32,7 +32,7 @@ if [ ! $CONFIG_VER -eq 2 ]; then
create_default_config create_default_config
exit;; exit;;
[Nn] ) exit;; [Nn] ) exit;;
* ) print "${RED}incorrect answer\n";; * ) myprint "${RED}incorrect answer\n";;
esac esac
done done
fi fi