configure.sh (1108B)
1 #!/bin/sh 2 3 cc=${CC:-cc} 4 5 detectarch() { 6 ${cc} -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" 7 } 8 detectsan() { 9 ${cc} -fsanitize=$1 -dM -E -x c - </dev/null 2>/dev/null \ 10 | grep "SANITIZE" 11 } 12 13 [ -n "$(detectarch __AVX2__)" ] && detected="AVX2" 14 [ -n "$(detectarch __ARM_NEON)" ] && detected="NEON" 15 [ -z "$detected" ] && detected="PORTABLE" 16 17 ARCH=${ARCH-"$detected"} 18 19 case "$ARCH" in 20 AVX2|NEON|PORTABLE) 21 ;; 22 *) 23 echo "Error: architecture $ARCH not supported" 24 exit 1 25 ;; 26 esac 27 28 STD="-std=c99" 29 WFLAGS="-pedantic -Wall -Wextra" 30 WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" 31 32 [ "$ARCH" = "AVX2" ] && AVX="-mavx2" 33 [ -n "$(detectsan address)" ] && ADDR="-fsanitize=address" 34 [ -n "$(detectsan undefined)" ] && UNDEF="-fsanitize=undefined" 35 SAN="$ADDR $UNDEF" 36 LIBS="-lpthread" 37 38 CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" 39 DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" 40 41 echo "Selected architecture: $ARCH" 42 echo "Compiler: ${CC:-cc}" 43 44 { 45 echo "ARCH = $ARCH"; 46 echo ""; 47 echo "CFLAGS = $CFLAGS"; 48 echo "DBGFLAGS = $DBGFLAGS"; 49 echo ""; 50 echo "CC = ${cc}" 51 } > config.mk