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
TASK=$1
print "${CYAN}===========[$TASK]===========\n"
myprint "${CYAN}===========[$TASK]===========\n"
source cbuild/init.sh
#pre_build
clear_dir $OBJDIR
clear_dir $OUTDIR
if [ -f "$PRE_BUILD_SCRIPT" ]; then
print "${BLUE}executing $PRE_BUILD_SCRIPT"
myprint "${BLUE}executing $PRE_BUILD_SCRIPT"
source "$PRE_BUILD_SCRIPT"
fi

View File

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

10
init.sh
View File

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