This commit is contained in:
timerix 2022-09-09 21:53:56 +06:00
parent 99aa4a4a03
commit 01ce7c6a45
3 changed files with 27 additions and 31 deletions

View File

@ -2,14 +2,14 @@
tabs 4 tabs 4
TASK=$1 TASK=$1
myprint "${CYAN}===========[$TASK]===========\n" myprintf "${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
myprint "${BLUE}executing $PRE_BUILD_SCRIPT" myprintf "${BLUE}executing $PRE_BUILD_SCRIPT"
source "$PRE_BUILD_SCRIPT" source "$PRE_BUILD_SCRIPT"
fi fi

View File

@ -1,26 +1,22 @@
#!/bin/bash #!/bin/bash
function myprint {
myprintf "$1$GRAY"
}
function clear_dir { function clear_dir {
myprint "${BLUE}clearing $1\n" myprintf "${BLUE}clearing $1\n"
rm -rf $1 rm -rf $1
mkdir $1 mkdir $1
} }
function compile { function compile {
local cmp=$1 local cmp=$1
myprint "${BLUE}compiler: ${GRAY}$cmp\n" myprintf "${BLUE}compiler: ${GRAY}$cmp\n"
local std=$2 local std=$2
myprint "${BLUE}standard: ${GRAY}$std\n" myprintf "${BLUE}standard: ${GRAY}$std\n"
local warn=$3 local warn=$3
myprint "${BLUE}warnings: ${GRAY}$warn\n" myprintf "${BLUE}warnings: ${GRAY}$warn\n"
local args=$4 local args=$4
myprint "${BLUE}args: ${GRAY}$args\n" myprintf "${BLUE}args: ${GRAY}$args\n"
local sources=$5 local sources=$5
myprint "${BLUE}sources: ${GRAY}$sources\n" myprintf "${BLUE}sources: ${GRAY}$sources\n"
local compilation_error=0 local compilation_error=0
for srcfile in $sources for srcfile in $sources
@ -28,7 +24,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
myprint "${RED}some error happened\n" myprintf "${RED}some error happened\n"
compilation_error=1 compilation_error=1
fi fi
) & done ) & done
@ -42,49 +38,49 @@ function compile {
# (args, sources) # (args, sources)
function compile_c { function compile_c {
myprint "${CYAN}-------------[compile_c]--------------\n" myprintf "${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 {
myprint "${CYAN}------------[compile_cpp]-------------\n" myprintf "${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 {
myprint "${CYAN}----------------[link]----------------\n" myprintf "${CYAN}----------------[link]----------------\n"
local args=$1 local args=$1
myprint "${BLUE}args: ${GRAY}$args\n" myprintf "${BLUE}args: ${GRAY}$args\n"
local outfile=$OUTDIR/$2 local outfile=$OUTDIR/$2
myprint "${BLUE}outfile: ${GRAY}$outfile\n" myprintf "${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')"
myprint "${BLUE}objects: ${GRAY}$objects\n" myprintf "${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
myprint "${GREEN}file $CYAN$outfile ${GREEN}created\n" myprintf "${GREEN}file $CYAN$outfile ${GREEN}created\n"
rm -rf $OBJDIR rm -rf $OBJDIR
else else
myprint "${RED}some error happened\n" myprintf "${RED}some error happened\n"
exit 1 exit 1
fi fi
} }
# (outfile) # (outfile)
function pack_static_lib { function pack_static_lib {
myprint "${CYAN}----------------[link]----------------\n" myprintf "${CYAN}----------------[link]----------------\n"
local outfile=$OUTDIR/$1 local outfile=$OUTDIR/$1
myprint "${BLUE}outfile: ${GRAY}$outfile\n" myprintf "${BLUE}outfile: ${GRAY}$outfile\n"
local objects="$(find $OBJDIR -name *.o)" local objects="$(find $OBJDIR -name *.o)"
myprint "${BLUE}objects: ${GRAY}$objects\n" myprintf "${BLUE}objects: ${GRAY}$objects\n"
if ar rcs $outfile $(echo $objects | tr '\n' ' ') if ar rcs $outfile $(echo $objects | tr '\n' ' ')
then then
myprint "${GREEN}file $CYAN$outfile ${GREEN}created\n" myprintf "${GREEN}file $CYAN$outfile ${GREEN}created\n"
rm -rf $OBJDIR rm -rf $OBJDIR
else else
myprint "${RED}some error happened\n" myprintf "${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
myprint "${YELLOW}Default config created.\nEdit it.\n" myprintf "${YELLOW}Default config created.\nEdit it.\n"
} }
#.config #.config
if [ ! -f ".config" ]; then if [ ! -f ".config" ]; then
myprint "${YELLOW}./.config doesn't exist\n" myprintf "${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
myprint "${RED}Your config version isn't correct\n" myprintf "${RED}Your config version isn't correct\n"
while true; do while true; do
myprint "${WHITE}Backup current config and create default one? (y/n) " myprintf "${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;;
* ) myprint "${RED}incorrect answer\n";; * ) myprintf "${RED}incorrect answer\n";;
esac esac
done done
fi fi