diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-01-28 00:36:27 +0200 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-01-28 00:36:27 +0200 |
commit | 9ac597d24336586421d994a8b1201aa3f0127827 (patch) | |
tree | c228f5902ba1c8d8a67b4ee7027806b4a8e2974e /build.sh | |
parent | e0a039ad08fc16773cee43e68f92b632a4540bce (diff) |
now using libmagic and its optional
Diffstat (limited to 'build.sh')
-rwxr-xr-x | build.sh | 69 |
1 files changed, 58 insertions, 11 deletions
@@ -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 |