From 9ac597d24336586421d994a8b1201aa3f0127827 Mon Sep 17 00:00:00 2001 From: kartofen Date: Sat, 28 Jan 2023 00:36:27 +0200 Subject: now using libmagic and its optional --- build.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 11 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index 370c378..6b2713c 100755 --- a/build.sh +++ b/build.sh @@ -3,20 +3,53 @@ cd ${0%/*} # go to project root NAME="web-server" -FLAGS="-std=c99 -Wall -Wextra -g -pedantic -D_POSIX_C_SOURCE=200112L" +FLAGS="-std=c99 -Wall -Wextra -g -pedantic" + SRCD="src" ODIR="obj" BIN="bin" FILES="files" RUN=0 +LIBS=("magic") +INC_LIBS= +INC_MACROS="-D_POSIX_C_SOURCE=200112L -DFILES=\"$FILES\" " + +function add_libs { + for lib in ${LIBS[@]}; do + INC_LIBS+="-l$lib " + INC_MACROS+="-DUSE_LIB${lib^^} " + done +} + +function __help__ { + echo "Usage:" + echo " ./build.sh [command | option] ..." + echo "" + echo "Options:" + echo " -(library) add the libarary into the list of libraries" + echo "" + echo "Commands:" + echo " help print this text" + echo " run will run the program after all commands are interpreted" + echo " valgrind use valgrind when running" + echo " -, nolib clear the list of libraries that are going to be loaded" + echo " clean will clean the temporary folders like 'obj' or 'bin'" + echo "" + echo "Note: Each command and option is interpreted in order" + exit 0 +} + +function __nolib__ { + LIBS=() +} + function __run__ { RUN=1 } -function __leak__ { +function __valgrind__ { VALGRND="valgrind --leak-check=full --show-leak-kinds=all -s" - RUN=1 } function __clean__ { @@ -25,23 +58,37 @@ function __clean__ { exit 0 } + +if ! [[ $# -eq 0 ]] +then + for cmd in "$@"; do + if [ $(cut -c1-1 <<< $cmd) == "-" ]; then + if [ $(expr length $cmd) == 1 ]; then + __nolib__ + else + LIBS+=("$(cut -c2- <<< $cmd)") + fi + else + __"$cmd"__ + fi + done +fi + set -xe mkdir -p $BIN mkdir -p $ODIR mkdir -p $FILES -if ! { [[ $# -eq 0 ]]; } 2> /dev/null -then - __$1__ -fi +{ add_libs; } 2> /dev/null -gcc -c $SRCD/server.c -o $ODIR/server.o $FLAGS -gcc -c $SRCD/main.c -o $ODIR/main.o $FLAGS -DFILES=\"$FILES\" - -gcc -o $BIN/$NAME $ODIR/main.o $ODIR/server.o $FLAGS +gcc -c $SRCD/server.c -o $ODIR/server.o $FLAGS $INC_MACROS +gcc -c $SRCD/main.c -o $ODIR/main.o $FLAGS $INC_MACROS +gcc -o $BIN/$NAME $ODIR/main.o $ODIR/server.o $FLAGS $INC_MACROS $INC_LIBS if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null then $VALGRND $BIN/$NAME fi + +exit 0 -- cgit v1.2.3