#!/bin/sh # Usage: make.sh [build|check] [--norun] [--debug] [--color] # Options: # build Build the library and app (default if no mode is provided). # watch Build the library and app and watch for changes. # run Build and run the app. # check Build tests; runs them unless --norun is specified. # --norun (check only) Build tests but do not run them. # --debug Build with -O0 (debug mode). # --color Pass -fdiagnostics-color=always to compiler. # help, --help Show this help message. check_dependencies() { for dep in cc ar pager; do if ! command -v "$dep" >/dev/null 2>&1; then echo "Error: Required dependency '$dep' not found." >&2 exit 1 fi done } check_dependencies print_help() { cat <&1 ;; build) build ;; run) build && ./target/hmpl ;; check) mkdir -p target/test for test_file in test/*.c; do exe="target/test/$(basename "${test_file%.c}")" # shellcheck disable=SC2086 cc $CFLAGS $OPTFLAGS -pedantic -I. "$test_file" -Ltarget -lhmpl $LDFLAGS -o "$exe" if [ "$RUN_TESTS" -eq 1 ]; then LOG_LEVEL=TRACE ./"$exe" fi done ;; *) print_help exit 1 ;; esac