#!/bin/csh -f

touch mus-config.h
cp tools/ffitest.c .
cp tools/tauto.scm .
cp ~/cl/t923.scm .
cp ~/cl/t101.scm .
cp tools/*.scm .
# cp ~/cl/make-repl .
cp ~/cl/low-primes.scm .
cp ~/cl/full-s7test.scm .
cp ~/cl/lt.scm .
cp ~/cl/peak-phases.scm .
cp ~/cl/arbtest.scm .

echo ' '
echo '-------- base case --------'
echo ' '
gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
sed 's/(define full-s7test #f)/(define full-s7test #t)/g' s7test.scm > fulltest.scm
repl fulltest.scm
repl tauto.scm

echo ' '
echo '-------- base case + nrepl --------'
echo ' '
gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic
gcc -o nrepl nrepl.c -g3 -Wall s7.o -I. -Wl,-export-dynamic -lnotcurses-core -lm -ldl
nrepl s7test.scm

echo ' '
echo '-------- with-gmp --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- with-gmp precision --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP -DDEFAULT_BIGNUM_PRECISION=512 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- libarb/flint --------'
echo ' '
gcc s7.c -c -I. -g3 -DWITH_GMP -DDEFAULT_BIGNUM_PRECISION=512 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lgmp -lmpfr -lmpc -lm -ldl -Wl,-export-dynamic
gcc -fPIC -c libarb_s7.c
gcc libarb_s7.o -shared -o libarb_s7.so -L/usr/local/lib -lflint
repl arbtest.scm

echo ' '
echo '-------- s7-debugging/system-extras --------'
echo ' '
gcc s7.c -c -I. -DS7_DEBUGGING -DWITH_SYSTEM_EXTRAS -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
repl t101.scm

echo ' '
echo '-------- with-pure-s7 --------'
echo ' '
gcc s7.c -c -I. -DWITH_PURE_S7 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
repl fulltest.scm

echo ' '
echo '-------- with-history --------'
echo ' '
gcc s7.c -c -I. -DWITH_HISTORY -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- with-history size --------'
echo ' '
gcc s7.c -c -I. -DWITH_HISTORY -DDEFAULT_HISTORY_SIZE=32 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- initial sizes --------'
echo ' '
gcc s7.c -c -I. -g3 -DINITIAL_HEAP_SIZE=32768 -DINITIAL_STACK_SIZE=512 -DINITIAL_PROTECTED_OBJECTS_SIZE=4 -DGC_TEMPS_SIZE=512 -DSYMBOL_TABLE_SIZE=10009 -DNUM_SMALL_INTS=256 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- optimized/disable-deprecated --------'
echo ' '
gcc s7.c -c -I. -O2 -g -DDISABLE_DEPRECATED -fomit-frame-pointer -funroll-loops -Wall -march=native -ldl -lm -Wl,-export-dynamic 
gcc -o repl repl.c -g -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm
repl fulltest.scm

echo ' '
echo '-------- with-main --------'
echo ' '
gcc s7.c -o repl -DWITH_MAIN -DUSE_SND=0 -I. -g3 -ldl -lm -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- max-string-input --------'
echo ' '
gcc s7.c -c -I. -DMAX_SIZE_FOR_STRING_PORT=1024 -DDEFAULT_PRINT_LENGTH=8 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl fulltest.scm

echo ' '
echo '-------- number-separator --------'
echo ' '
gcc s7.c -c -I. -DWITH_NUMBER_SEPARATOR=1 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl fulltest.scm

echo ' '
echo '-------- disable-autoload --------'
echo ' '
gcc s7.c -c -I. -DDISABLE_AUTOLOAD=1 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl fulltest.scm

echo ' '
echo '-------- silly stuff --------'
echo ' '
gcc s7.c -c -I. -DEXTRA_EXPONENT_MARKERS=1 -DS7_ALIGNED=1 -DWITH_VECTORIZE=0 -DWITH_MULTITHREAD_CHECKS=0 -DWITH_DTOA=0 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- gc --------'
echo ' '
gcc s7.c -c -I. -DGC_RESIZE_HEAP_FRACTION=0.72 -DOUTPUT_PORT_DATA_SIZE=128 -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
repl s7test.scm

echo ' '
echo '-------- disable-file-output --------'
echo ' '
gcc s7.c -c -I. -DDISABLE_FILE_OUTPUT=1 -g3 -ldl -lm -Wl,-export-dynamic
# gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
# repl s7test.scm

echo ' '
echo '-------- valgrind --------'
echo ' '
gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic
gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic
valgrind repl s7test.scm
valgrind repl fulltest.scm

gcc -o nrepl s7.c -O2 -I. -Wl,-export-dynamic -lm -ldl -DWITH_MAIN -DWITH_NOTCURSES -lnotcurses-core

echo ' '
echo '-------- tcc --------'
echo ' '
tcc -o repl s7.c -I. -g3 -lm -DWITH_MAIN -ldl -rdynamic -DWITH_C_LOADER -DS7_DEBUGGING
repl s7test.scm

echo ' '
echo '-------- fortify flags --------'
echo ' '
gcc -o repl s7.c -O2 -I. -g -DWITH_MAIN -Wl,-export-dynamic -lm -ldl -DWITH_C_LOADER -Wall -Wformat=2 -Wtrampolines -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -fstack-protector-strong -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fcf-protection=full
repl s7test.scm

echo ' '
echo '-------- main version --------'
echo ' '
gcc s7.c -c -DS7_DEBUGGING=1 -DWITH_HISTORY=1 -DGSL_DISABLE_DEPRECATED -DDISABLE_DEPRECATED -Wall -Wextra -I. -g3 -Wduplicated-cond -Wlogical-op -Wjump-misses-init -Wfatal-errors -Wformat -Wno-implicit-fallthrough -Wpointer-arith -Wduplicated-branches -Wdangling-else -Wno-unused-parameter -Wunused-function -DTRAP_SEGFAULT -DS7_ALIGNED=1 -DINITIAL_HEAP_SIZE=6400 -DNUM_SMALL_INTS=256 -DWITH_NUMBER_SEPARATOR -DWITH_IMMUTABLE_UNQUOTE=1 -Wunreachable-code -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wmissing-include-dirs -Wuninitialized -Wwrite-strings -Wdouble-promotion -DWITH_ALLOC_COUNTERS=0
gcc -o repl repl.c -g3 -Wall s7.o -I. -Wl,-export-dynamic -lm -ldl
repl s7test.scm

# echo ' '
# echo '-------- fsanitize=address --------'
# echo ' '
# gcc s7.c -c -I. -g3 -ldl -lm -Wl,-export-dynamic -fsanitize=address
# gcc -o repl repl.c -g3 -Wall s7.o -I. -lm -ldl -Wl,-export-dynamic -fsanitize=address -lasan
# repl s7test.scm
# 
# -fsanitize=leak
# -fsanitize=undefined
