aboutsummaryrefslogtreecommitdiff
path: root/configure.sh
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-12 16:55:28 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-12 16:55:28 +0200
commitca68b59475f6b1773fa62e6dbc4b68349602b441 (patch)
treea03251fefc3e39b209770cd96b974150163d9df9 /configure.sh
parent762d285f3b914c877887469de06a70cee9028159 (diff)
downloadnissy-core-ca68b59475f6b1773fa62e6dbc4b68349602b441.tar.gz
nissy-core-ca68b59475f6b1773fa62e6dbc4b68349602b441.zip
Update build files to enable multithreading
Diffstat (limited to 'configure.sh')
-rwxr-xr-xconfigure.sh73
1 files changed, 52 insertions, 21 deletions
diff --git a/configure.sh b/configure.sh
index 34da488..03873e5 100755
--- a/configure.sh
+++ b/configure.sh
@@ -1,51 +1,82 @@
1#!/bin/sh 1#!/bin/sh
2 2
3cc=${CC:-cc} 3greparch() {
4 $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1"
5}
6
7grepsan() {
8 $CC -fsanitize=$1 -dM -E -x c - </dev/null 2>/dev/null | grep "SANITIZE"
9}
10
11detectthreads() {
12 echo 16 # TODO: choose based on system
13}
4 14
5detectarch() { 15detectarch() {
6 ${cc} -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" 16 [ -n "$(greparch __AVX2__)" ] && detected="AVX2"
17 [ -n "$(greparch __ARM_NEON)" ] && detected="NEON"
18 [ -z "$detected" ] && detected="PORTABLE"
19
20 echo "$detected"
7} 21}
8detectsan() { 22
9 ${cc} -fsanitize=$1 -dM -E -x c - </dev/null 2>/dev/null \ 23validatecc() {
10 | grep "SANITIZE" 24 if ! (which "$CC" >/dev/null 2>&1) ; then
25 echo "Error: compiler '$CC' not found"
26 exit 1
27 fi
11} 28}
12 29
13[ -n "$(detectarch __AVX2__)" ] && detected="AVX2" 30validatethreads() {
14[ -n "$(detectarch __ARM_NEON)" ] && detected="NEON" 31 if [ "$THREADS" -le 0 ] || [ "$THREADS" -gt 128 ]; then
15[ -z "$detected" ] && detected="PORTABLE" 32 echo "Error: number of threads must be between 1 and 128"
33 exit 1
34 fi
35}
36
37validatearch() {
38 case "$ARCH" in
39 AVX2|NEON|PORTABLE)
40 ;;
41 *)
42 echo "Error: architecture '$ARCH' not supported"
43 exit 1
44 ;;
45 esac
46}
16 47
17ARCH=${ARCH-"$detected"} 48CC=${CC:-cc}
49THREADS=${THREADS-"$(detectthreads)"}
50ARCH=${ARCH-"$(detectarch)"}
18 51
19case "$ARCH" in 52validatecc
20AVX2|NEON|PORTABLE) 53validatethreads
21 ;; 54validatearch
22*)
23 echo "Error: architecture $ARCH not supported"
24 exit 1
25 ;;
26esac
27 55
28STD="-std=c99" 56STD="-std=c99"
29WFLAGS="-pedantic -Wall -Wextra" 57WFLAGS="-pedantic -Wall -Wextra"
30WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas" 58WNOFLAGS="-Wno-unused-parameter -Wno-unused-function -Wno-unknown-pragmas"
31 59
32[ "$ARCH" = "AVX2" ] && AVX="-mavx2" 60[ "$ARCH" = "AVX2" ] && AVX="-mavx2"
33[ -n "$(detectsan address)" ] && ADDR="-fsanitize=address" 61[ -n "$(grepsan address)" ] && ADDR="-fsanitize=address"
34[ -n "$(detectsan undefined)" ] && UNDEF="-fsanitize=undefined" 62[ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined"
35SAN="$ADDR $UNDEF" 63SAN="$ADDR $UNDEF"
36LIBS="-lpthread" 64LIBS="-lpthread"
37 65
38CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" 66CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3"
39DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" 67DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG"
68MACROS="-DTHREADS=$THREADS -D$ARCH"
40 69
41echo "Selected architecture: $ARCH" 70echo "Selected architecture: $ARCH"
42echo "Compiler: ${CC:-cc}" 71echo "Number of threads: $THREADS"
72echo "Compiler: $CC"
43 73
44{ 74{
45echo "ARCH = $ARCH"; 75echo "ARCH = $ARCH";
46echo ""; 76echo "";
47echo "CFLAGS = $CFLAGS"; 77echo "CFLAGS = $CFLAGS";
48echo "DBGFLAGS = $DBGFLAGS"; 78echo "DBGFLAGS = $DBGFLAGS";
79echo "MACROS = $MACROS"
49echo ""; 80echo "";
50echo "CC = ${cc}" 81echo "CC = $CC"
51} > config.mk 82} > config.mk

Generated with cgit - Back to sebastiano.tronto.net