Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
#!/bin/sh
rm NAR
rm src/RuleTable.c
rm -f NAR
rm -f src/RuleTable.c
set -e
Str=`ls src/*.c src/NetworkNAR/*.c | xargs`
echo $Str

ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
echo "Detected ARM64 (Apple Silicon) - using ARM64 build configuration"
SSEFLAGS=""
else
echo "Detected x86_64 - using SSE2 build configuration"
SSEFLAGS="-mfpmath=sse -msse2"
fi

Str=$(ls src/*.c src/NetworkNAR/*.c | xargs)
echo "Compiling source files: $Str"
echo "Compilation started:"
BaseFlags="-flto -g -pthread -lpthread -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR"

BaseFlags="-flto -g -pthread -lpthread -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -o NAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-strict-prototypes"

gcc $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
echo "First stage done, generating RuleTable.c now, and finishing compilation."
echo "Stage 1 done, generating RuleTable.c..."

./NAR NAL_GenerateRuleTable > ./src/RuleTable.c
gcc $@ -mfpmath=sse -msse2 -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c || (echo "Error with SSE, hence compiling without SSE:" && gcc $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c)
echo "Done."

echo "Stage 2: compiling with RuleTable.c..."
if [ -n "$SSEFLAGS" ]; then
gcc $@ $SSEFLAGS -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c || (echo "Error with SSE, compiling without SSE..." && gcc $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c)
else
gcc $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c
fi

echo "Done."