aboutsummaryrefslogtreecommitdiff
path: root/configure.sh
diff options
context:
space:
mode:
Diffstat (limited to 'configure.sh')
-rwxr-xr-xconfigure.sh55
1 files changed, 50 insertions, 5 deletions
diff --git a/configure.sh b/configure.sh
index fcf2dce..e61a163 100755
--- a/configure.sh
+++ b/configure.sh
@@ -1,5 +1,40 @@
1#!/bin/sh 1#!/bin/sh
2 2
3# The following environment variables can be used to configure the 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# Choose how many threads to use for multi-threaded oerations.
18# By default, 16 threads will be used (TODO: in the future this will be
19# determined base on the system).
20# The number n must be between 1 and 128.
21#
22# SANITIZE="option1,option2,..."
23# Add the options "-fsanitize=option1", "-fsanitize=option2", ... to the
24# compilation command when compiling in debug mode.
25# By default, "-fsanitize=address" and "-fsanitize=undefined" will be used,
26# if available. If this variable is set, the default is overridden.
27# No check is performed on the given sanitizers, make sure that the ones you
28# choose are available on your system and compatible with each other.
29#
30# Examples
31#
32# 1. Build using clang and 8 threads
33# CC=clang THREADS=8 ./configure.sh && make
34#
35# 2. Build using thread and undefined behavior sanitizers when in debug mode
36# SANITIZE="thread,undefined" ./configures && make
37
3greparch() { 38greparch() {
4 $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" 39 $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1"
5} 40}
@@ -53,23 +88,33 @@ validatecc
53validatethreads 88validatethreads
54validatearch 89validatearch
55 90
56STD="-std=c99" 91STD="-std=c11"
57WFLAGS="-pedantic -Wall -Wextra" 92WFLAGS="-pedantic -Wall -Wextra"
58WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" 93WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas"
59 94
60[ "$ARCH" = "AVX2" ] && AVX="-mavx2" 95[ "$ARCH" = "AVX2" ] && AVX="-mavx2"
61[ -n "$(grepsan address)" ] && ADDR="-fsanitize=address" 96
62[ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined" 97if [ -n "$SANITIZE" ]; then
63SAN="$ADDR $UNDEF" 98 # Use the user-specified comma-separated sanitizers
99 for san in $(echo "$SANITIZE" | tr ',' '\n'); do
100 SAN="$SAN -fsanitize=$san"
101 done
102else
103 # No sanitizer specified, use "address" and "undefined" if present
104 [ -n "$(grepsan address)" ] && ADDR="-fsanitize=address"
105 [ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined"
106 SAN="$ADDR $UNDEF"
107fi
64LIBS="-lpthread" 108LIBS="-lpthread"
65 109
66CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" 110CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3"
67DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" 111DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG"
68MACROS="-DTHREADS=$THREADS -D$ARCH" 112MACROS="-DTHREADS=$THREADS -D$ARCH"
69 113
114echo "Compiler: $CC"
70echo "Selected architecture: $ARCH" 115echo "Selected architecture: $ARCH"
71echo "Number of threads: $THREADS" 116echo "Number of threads: $THREADS"
72echo "Compiler: $CC" 117echo "Sanitizer options (debug build only): $SAN"
73 118
74{ 119{
75echo "ARCH = $ARCH"; 120echo "ARCH = $ARCH";

Generated with cgit - Back to sebastiano.tronto.net