2026-01-26 18:35:08 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
# build_and_test.sh - Automates build and test for 42sh with pretty output
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Colors
|
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
|
RED="\033[1;31m"
|
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
|
RESET="\033[0m"
|
|
|
|
|
|
|
|
|
|
VERBOSE=0
|
|
|
|
|
if [[ "$1" == "--verbose" ]]; then
|
|
|
|
|
VERBOSE=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
run_cmd() {
|
|
|
|
|
local desc="$1"
|
|
|
|
|
shift
|
|
|
|
|
if [[ $VERBOSE -eq 1 ]]; then
|
|
|
|
|
echo -e "${YELLOW}${desc}...${RESET}"
|
|
|
|
|
"$@"
|
|
|
|
|
else
|
|
|
|
|
echo -ne "${YELLOW}${desc}...${RESET}"
|
|
|
|
|
"$@" &> /dev/null && echo -e " ${GREEN}done${RESET}" || { echo -e " ${RED}failed${RESET}"; exit 1; }
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run_cmd "Running autoreconf" autoreconf --force --verbose --install
|
|
|
|
|
|
|
|
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
|
|
|
run_cmd "Configuring for MacOS" ./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla -I/opt/homebrew/include' LDFLAGS='-L/opt/homebrew/lib'
|
|
|
|
|
else
|
2026-01-27 21:10:24 +01:00
|
|
|
run_cmd "Configuring for Linux" ./configure CFLAGS='-std=c99 -Werror -Wall -Wextra -Wvla -g'
|
2026-01-26 18:35:08 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
run_cmd "Cleaning build" make clean
|
|
|
|
|
if [[ $VERBOSE -eq 1 ]]; then
|
|
|
|
|
echo -e "${YELLOW}Running tests...${RESET}"
|
|
|
|
|
make check
|
|
|
|
|
else
|
|
|
|
|
echo -ne "${YELLOW}Running tests...${RESET}"
|
|
|
|
|
echo
|
|
|
|
|
make check
|
|
|
|
|
fi
|