aboutsummaryrefslogtreecommitdiff
path: root/configure.sh
diff options
context:
space:
mode:
Diffstat (limited to 'configure.sh')
-rwxr-xr-xconfigure.sh135
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: 3echo "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
37greparch() {
38 $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1"
39}
40
41detectthreads() {
42 echo 8 # TODO: choose based on system
43}
44
45detectarch() {
46 [ -n "$(greparch __AVX2__)" ] && detected="AVX2"
47 [ -n "$(greparch __ARM_NEON)" ] && detected="NEON"
48 [ -z "$detected" ] && detected="PORTABLE"
49
50 echo "$detected"
51}
52
53validatecc() {
54 if ! (command -v "$CC" >/dev/null 2>&1) ; then
55 echo "Error: compiler '$CC' not found"
56 exit 1
57 fi
58}
59
60validatethreads() {
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
67validatearch() {
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
79CC=${CC:-cc}
80THREADS=${THREADS-"$(detectthreads)"}
81ARCH=${ARCH-"$(detectarch)"}
82
83validatecc
84validatethreads
85validatearch
86
87STD="-std=c11"
88POSIX="-D_POSIX_C_SOURCE=199309L"
89WFLAGS="-pedantic -Wall -Wextra"
90WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas"
91WNOFLAGS="$WNOFLAGS -Wno-unused-command-line-argument"
92
93[ "$ARCH" = "AVX2" ] && AVX="-mavx2"
94
95if [ -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
100fi
101LIBS="-lpthread"
102
103CFLAGS="$STD $POSIX $LIBS $WFLAGS $WNOFLAGS $AVX -O3 -fPIC -D$ARCH"
104DBGFLAGS="$STD $POSIX $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG -fPIC -D$ARCH"
105WASMFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS -O3 -fPIC"
106MACROS="-DTHREADS=$THREADS"
107
108if (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./')"
111else
112 PYTHON3_INCLUDES=""
113 PYTHON3="Not found, Python shell won't be available"
114fi
115
116echo "Compiler: $CC"
117echo "Selected architecture: $ARCH"
118echo "Number of threads: $THREADS"
119echo "Sanitizer options (debug build only): $SAN"
120echo "Python3 development libraries: $PYTHON3"
121
122{
123echo "ARCH = $ARCH";
124echo "";
125echo "CFLAGS = $CFLAGS";
126echo "";
127echo "DBGFLAGS = $DBGFLAGS";
128echo "";
129echo "WASMFLAGS = $WASMFLAGS";
130echo "";
131echo "MACROS = $MACROS"
132echo "";
133echo "PYTHON3_INCLUDES = $PYTHON3_INCLUDES"
134echo "CC = $CC"
135echo "EMCC = emcc"
136} > config.mk

Generated with cgit - Back to sebastiano.tronto.net