#!/bin/tcsh -e
# build - build awk on Mac OS X or FreeBSD or Linux.
# build is Copyright Daniel K. Allen, 2026.
# All rights reserved.
#

if ("$OSTYPE" == "darwin") then
  if (`uname -m` == "arm64" || `uname -m` == "aarch64") then
    set opt="-Os -target arm64-apple-darwin21 -fno-threadsafe-statics -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-debug-types-section -fno-exceptions -fno-pic" # Monterey
  else
    set opt="-Os -mtune=skylake -mmacosx-version-min=10.8 -fno-threadsafe-statics -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-debug-types-section -fno-exceptions -fno-pic" # Mountain Lion
  endif
else
  set opt="-Os"
endif
if ("$1" != "") set opt="$*"
echo "Building awk $opt..."
time cc -o awk $opt -ansi -w -lm awkgram.tab.c b.c lex.c lib.c main.c parse.c proctab.c run.c tran.c
strip awk
ls -l awk
./awk --version
