From 13a1fdecf96b1490dab49d5c6fa6637821aaa859 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Sat, 23 Jul 2022 01:05:55 -0400 Subject: [PATCH] Move to recipe-based make script, to allow for tests, releases, etc. --- make.sh | 61 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/make.sh b/make.sh index dc24dd2..ef0fd0d 100644 --- a/make.sh +++ b/make.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh TELODENDRIA_VERSION="0.0.1" +CVS_TAG="Telodendria-$(echo $TELODENDRIA_VERSION | sed 's/\./_/g')" HEADERS="-D_POSIX_C_SOURCE=199506L -DTELODENDRIA_VERSION=\"$TELODENDRIA_VERSION\"" INCLUDES="-Isrc/include" @@ -28,30 +29,46 @@ mod_time() { fi } -mkdir -p build +recipe_build() { + mkdir -p build -do_rebuild=0 -objs="" -for src in $(find src -name '*.c'); do - obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/') - objs="$objs $obj" + do_rebuild=0 + objs="" + for src in $(find src -name '*.c'); do + obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/') + objs="$objs $obj" - if [ $(mod_time "$src") -gt $(mod_time "$obj") ]; then - echo "CC $obj" - obj_dir=$(dirname "$obj") - mkdir -p "$obj_dir" - if ! $CC $CFLAGS -c -o "$obj" "$src"; then - exit 1 - fi - do_rebuild=1 - fi + if [ $(mod_time "$src") -gt $(mod_time "$obj") ]; then + echo "CC $obj" + obj_dir=$(dirname "$obj") + mkdir -p "$obj_dir" + if ! $CC $CFLAGS -c -o "$obj" "$src"; then + exit 1 + fi + do_rebuild=1 + fi + done + + if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then + echo "LD build/$PROG" + $CC $LDFLAGS -o "build/$PROG" $objs + else + echo "Up to date." + fi +} + +recipe_clean() { + rm -rv build +} + +recipe_test() { + echo "Unit tests are not implemented yet." +} + +for recipe in $@; do + recipe_$recipe done -if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then - echo "LD build/$PROG" - $CC $LDFLAGS -o "build/$PROG" $objs -else - echo "Up to date." +if [ -z "$1" ]; then + recipe_build fi - -ls -lh "build/$PROG"