#!/bin/sh # Usage: make.sh [build|check] [--norun] [--debug] [--color] # Options: # build Build the library and app (default if no mode is provided). # 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; 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 </dev/null 2>&1; then echo "Error: Required dependency '$dep' not found." >&2 exit 1 fi OPTFLAGS="-O0 -gdwarf-2 -g3" DEBUG=1 ;; --color) COLOR_FLAG="-fdiagnostics-color=always" ;; *) echo "Unknown option: $1" print_help exit 1 ;; esac shift done if [ -n "$COLOR_FLAG" ]; then CFLAGS="$CFLAGS $COLOR_FLAG" fi case "$MODE" in build) mkdir -p target echo "# Build library" # shellcheck disable=SC2086 cc $CFLAGS $OPTFLAGS $STD_FLAGS -c hectic.c -lhectic -o target/hectic.o ar rcs target/libhectic.a target/hectic.o ;; check) mkdir -p target/test export LOG_LEVEL=TRACE 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 -lhectic $LDFLAGS -o "$exe" if [ "$?" -ne 0 ]; then exit 1 fi if [ "$RUN_TESTS" -eq 1 ]; then if [ "$DEBUG" -eq 1 ]; then gdb -tui "$exe" fi "$exe" fi done ;; *) print_help exit 1 ;; esac