diff options
Diffstat (limited to 'configure.sh')
| -rwxr-xr-x | configure.sh | 135 |
1 files changed, 1 insertions, 134 deletions
diff --git a/configure.sh b/configure.sh index 4a60ed4..b5604ee 100755 --- a/configure.sh +++ b/configure.sh | |||
| @@ -1,136 +1,3 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | # The following environment variables can be used to configure the build: | 3 | echo "The build system for nissy has changed, use ./build" |
| 4 | # | ||
| 5 | # CC="compiler" | ||
| 6 | # Specify the compiler to use. | ||
| 7 | # By default, cc will be used. | ||
| 8 | # The string "compiler" must be the name of an executable in $PATH. | ||
| 9 | # | ||
| 10 | # ARCH="architecture" | ||
| 11 | # You can use this variable to build for a different architecture, for example | ||
| 12 | # if you want to cross-compile or to use the portable version. | ||
| 13 | # By default, the build script will detect which architecture it is running on. | ||
| 14 | # The string "architecture" must be one of "AVX2", "NEON" or "PORTABLE". | ||
| 15 | # | ||
| 16 | # THREADS=n | ||
| 17 | # The maximum number of threads to use for multi-threaded operations. | ||
| 18 | # This is also used as default value in case an operation allows | ||
| 19 | # specifying how many threads to use. | ||
| 20 | # By default, 8 threads will be used (TODO: in the future this will be | ||
| 21 | # determined base on the system). | ||
| 22 | # The number n must be between 1 and 128. | ||
| 23 | # | ||
| 24 | # SANITIZE="option1,option2,..." | ||
| 25 | # Add the options "-fsanitize=option1", "-fsanitize=option2", ... to the | ||
| 26 | # compilation command when compiling in debug mode. | ||
| 27 | # By default, no sanitizer is used. | ||
| 28 | # | ||
| 29 | # Examples | ||
| 30 | # | ||
| 31 | # 1. Build using clang and 4 threads | ||
| 32 | # CC=clang THREADS=4 ./configure.sh && make | ||
| 33 | # | ||
| 34 | # 2. Build using thread and undefined behavior sanitizers when in debug mode | ||
| 35 | # SANITIZE="thread,undefined" ./configure.sh && make | ||
| 36 | |||
| 37 | greparch() { | ||
| 38 | $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" | ||
| 39 | } | ||
| 40 | |||
| 41 | detectthreads() { | ||
| 42 | echo 8 # TODO: choose based on system | ||
| 43 | } | ||
| 44 | |||
| 45 | detectarch() { | ||
| 46 | [ -n "$(greparch __AVX2__)" ] && detected="AVX2" | ||
| 47 | [ -n "$(greparch __ARM_NEON)" ] && detected="NEON" | ||
| 48 | [ -z "$detected" ] && detected="PORTABLE" | ||
| 49 | |||
| 50 | echo "$detected" | ||
| 51 | } | ||
| 52 | |||
| 53 | validatecc() { | ||
| 54 | if ! (command -v "$CC" >/dev/null 2>&1) ; then | ||
| 55 | echo "Error: compiler '$CC' not found" | ||
| 56 | exit 1 | ||
| 57 | fi | ||
| 58 | } | ||
| 59 | |||
| 60 | validatethreads() { | ||
| 61 | if [ "$THREADS" -le 0 ] || [ "$THREADS" -gt 128 ]; then | ||
| 62 | echo "Error: number of threads must be between 1 and 128" | ||
| 63 | exit 1 | ||
| 64 | fi | ||
| 65 | } | ||
| 66 | |||
| 67 | validatearch() { | ||
| 68 | case "$ARCH" in | ||
| 69 | AVX2|NEON|PORTABLE) | ||
| 70 | ;; | ||
| 71 | *) | ||
| 72 | echo "Error: architecture '$ARCH' not supported" | ||
| 73 | echo "Supported architectures: AVX2, NEON, PORTABLE" | ||
| 74 | exit 1 | ||
| 75 | ;; | ||
| 76 | esac | ||
| 77 | } | ||
| 78 | |||
| 79 | CC=${CC:-cc} | ||
| 80 | THREADS=${THREADS-"$(detectthreads)"} | ||
| 81 | ARCH=${ARCH-"$(detectarch)"} | ||
| 82 | |||
| 83 | validatecc | ||
| 84 | validatethreads | ||
| 85 | validatearch | ||
| 86 | |||
| 87 | STD="-std=c11" | ||
| 88 | POSIX="-D_POSIX_C_SOURCE=199309L" | ||
| 89 | WFLAGS="-pedantic -Wall -Wextra" | ||
| 90 | WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" | ||
| 91 | WNOFLAGS="$WNOFLAGS -Wno-unused-command-line-argument" | ||
| 92 | |||
| 93 | [ "$ARCH" = "AVX2" ] && AVX="-mavx2" | ||
| 94 | |||
| 95 | if [ -n "$SANITIZE" ]; then | ||
| 96 | # Use the user-specified comma-separated sanitizers | ||
| 97 | for san in $(echo "$SANITIZE" | tr ',' '\n'); do | ||
| 98 | SAN="$SAN -fsanitize=$san" | ||
| 99 | done | ||
| 100 | fi | ||
| 101 | LIBS="-lpthread" | ||
| 102 | |||
| 103 | CFLAGS="$STD $POSIX $LIBS $WFLAGS $WNOFLAGS $AVX -O3 -fPIC -D$ARCH" | ||
| 104 | DBGFLAGS="$STD $POSIX $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG -fPIC -D$ARCH" | ||
| 105 | WASMFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS -O3 -fPIC" | ||
| 106 | MACROS="-DTHREADS=$THREADS" | ||
| 107 | |||
| 108 | if (command -v "python3-config" >/dev/null 2>&1) ; then | ||
| 109 | PYTHON3_INCLUDES="$(python3-config --includes)" | ||
| 110 | PYTHON3="version $(echo "$PYTHON3_INCLUDES" | sed 's/.*3\./3./')" | ||
| 111 | else | ||
| 112 | PYTHON3_INCLUDES="" | ||
| 113 | PYTHON3="Not found, Python shell won't be available" | ||
| 114 | fi | ||
| 115 | |||
| 116 | echo "Compiler: $CC" | ||
| 117 | echo "Selected architecture: $ARCH" | ||
| 118 | echo "Number of threads: $THREADS" | ||
| 119 | echo "Sanitizer options (debug build only): $SAN" | ||
| 120 | echo "Python3 development libraries: $PYTHON3" | ||
| 121 | |||
| 122 | { | ||
| 123 | echo "ARCH = $ARCH"; | ||
| 124 | echo ""; | ||
| 125 | echo "CFLAGS = $CFLAGS"; | ||
| 126 | echo ""; | ||
| 127 | echo "DBGFLAGS = $DBGFLAGS"; | ||
| 128 | echo ""; | ||
| 129 | echo "WASMFLAGS = $WASMFLAGS"; | ||
| 130 | echo ""; | ||
| 131 | echo "MACROS = $MACROS" | ||
| 132 | echo ""; | ||
| 133 | echo "PYTHON3_INCLUDES = $PYTHON3_INCLUDES" | ||
| 134 | echo "CC = $CC" | ||
| 135 | echo "EMCC = emcc" | ||
| 136 | } > config.mk | ||
