build.sh (2767B)
1 #!/bin/sh 2 3 cc=${CC:-cc} 4 build=release 5 6 for arg in $@; do 7 case "$arg" in 8 clang) cc=clang ;; 9 gcc) cc=gcc ;; 10 debug) build=debug ;; 11 optimized_debug) build=optimized_debug ;; 12 fuzz) build=fuzz ;; 13 fuzz_llvm) build=fuzz_llvm ;; 14 fuzz_results) build=fuzz_results ;; 15 release) build=release ;; 16 *) echo "usage: $0 [release|debug|optimized_debug|fuzz] [gcc|clang]"; exit 1 ;; 17 esac 18 done 19 20 version="$(git describe --dirty --always)-${build}" 21 22 cflags="-march=native -Wall -Wextra -Wno-unused-parameter -DVERSION=\"${version}\"" 23 #cflags="${cflags} -fproc-stat-report" 24 #cflags="${cflags} -Rpass-missed=.*" 25 #cflags="${cflags} -fsanitize=address,undefined" 26 ldflags="-lm -lGL -lglfw -lX11" 27 28 testcflags="-march=native -Wall -ggdb -D_DEBUG -DVERSION=test -I." 29 testcflags="${testcflags} -Wno-unused-variable -Wno-unused-function -Wno-undefined-internal" 30 testcflags="${testcflags} -fsanitize=address,undefined" 31 32 export ASAN_OPTIONS="abort_on_error=1:halt_on_error=1:symbolize=0:max_malloc_fill_size=$((1<<30))" 33 34 [ ! -s "./config.h" ] && cp config.def.h config.h 35 36 case ${build} in 37 debug) 38 cflags="${cflags} -O0 -ggdb -D_DEBUG -Wno-unused-function -Wno-undefined-internal" 39 build_lib=1 40 ;; 41 optimized_debug) 42 cflags="${cflags} -O3 -ggdb -D_DEBUG -Wno-unused-function -Wno-undefined-internal" 43 build_lib=1 44 ;; 45 release) 46 cflags="${cflags} -O3" 47 ;; 48 fuzz) 49 input=tests/llvm_fuzz_corpus 50 [ ! -d ${input} ] && input=tests/fuzz_in 51 afl-clang-fast ${testcflags} -O3 -o tests/test-fuzz tests/test-fuzz.c 52 AFL_SKIP_CPUFREQ=1 AFL_AUTORESUME=1 afl-fuzz -o tests/fuzz_out -i tests/llvm_fuzz_corpus ./tests/test-fuzz 53 exit 0 54 ;; 55 fuzz_llvm) 56 clang ${testcflags} -O0 -fsanitize=fuzzer,address,undefined -o tests/test-fuzz tests/test-fuzz.c 57 input=tests/llvm_fuzz_corpus 58 if [ ! -d ${input} ]; then 59 mkdir -p tests/llvm_fuzz_corpus 60 # NOTE(rnp): libFuzzer can't handle arbitrary utf-8 inputs and seems 61 # to leak memory at startup (gg llvm devs) 62 ./tests/test-fuzz -detect_leaks=0 -merge=1 tests/llvm_fuzz_corpus tests/fuzz_in 63 else 64 ./tests/test-fuzz tests/llvm_fuzz_corpus 65 fi 66 exit 0 67 ;; 68 fuzz_results) 69 ${cc} ${testcflags} -DFUZZ_RESULTS -O0 tests/test-fuzz.c -o tests/test-fuzz-results 70 set -e 71 for file in tests/fuzz_out/default/crashes/id*; do 72 echo ${file} 73 ./tests/test-fuzz-results "${file}" 74 done 75 #for file in tests/llvm_fuzz_corpus/*; do 76 # echo ${file} 77 # ./tests/test-fuzz-results "${file}" 78 #done 79 exit 0 80 ;; 81 *) 82 echo unsupported build type: ${build} 83 exit 1 84 ;; 85 esac 86 87 [ ${build_lib} ] && ${cc} ${cflags} -fPIC vtgl.c -o vtgl.so ${ldflags} -shared 88 ${cc} ${cflags} -o vtgl platform_linux_x11.c ${ldflags} 89 ${cc} ${testcflags} -O0 -o tests/test tests/test.c