forked from supranational/blst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·77 lines (68 loc) · 2.27 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh -e
#
# The script allows to override 'CC', 'CFLAGS' and 'flavour' at command
# line, as well as specify additional compiler flags. For example to
# compile for x32:
#
# /some/where/build.sh flavour=elf32 -mx32
#
# To cross-compile for mingw/Windows:
#
# /some/where/build.sh flavour=mingw64 CC=x86_64-w64-mingw32-gcc
#
# In addition script recognizes -shared flag and creates shared library
# alongside libblst.lib.
TOP=`dirname $0`
if [ "x$CC" = "x" ]; then
CC=gcc
which cc >/dev/null 2>&1 && CC=cc
fi
# if -Werror stands in the way, bypass with -Wno-error on command line
CFLAGS=${CFLAGS:--O -fno-builtin-memcpy -fPIC -Wall -Wextra -Werror}
PERL=${PERL:-perl}
unset cflags shared
case `uname -s` in
Darwin) flavour=macosx
if (sysctl machdep.cpu.features) 2>/dev/null | grep -q ADX; then
cflags="-D__ADX__"
fi
;;
CYGWIN*) flavour=mingw64;;
MINGW*) flavour=mingw64;;
*) flavour=elf;;
esac
while [ "x$1" != "x" ]; do
case $1 in
-shared) shared=1;;
-target*) CFLAGS="$CFLAGS $1";;
-*) cflags="$cflags $1";;
*=*) eval "$1";;
esac
shift
done
if (${CC} ${CFLAGS} -dM -E -x c /dev/null) 2>/dev/null | grep -q x86_64; then
cflags="$cflags -mno-avx" # avoid costly transitions
if (grep -q -e '^flags.*\badx\b' /proc/cpuinfo) 2>/dev/null; then
cflags="-D__ADX__ $cflags"
fi
fi
CFLAGS="$CFLAGS $cflags"
rm -f libblst.a
trap '[ $? -ne 0 ] && rm -f libblst.a; rm -f *.o' 0
(set -x; ${CC} ${CFLAGS} -c ${TOP}/src/server.c)
(set -x; ${CC} ${CFLAGS} -c ${TOP}/build/assembly.S)
(set -x; ${AR:-ar} rc libblst.a *.o)
if [ $shared ]; then
case $flavour in
macosx) (set -x; ${CC} -dynamiclib -o libblst.dylib \
-all_load libblst.a ${CFLAGS}); exit 0;;
mingw*) sharedlib=blst.dll
CFLAGS="${CFLAGS} --entry=DllMain ${TOP}/build/win64/dll.c"
CFLAGS="${CFLAGS} -nostdlib -lgcc";;
*) sharedlib=libblst.so;;
esac
echo "{ global: blst_*; BLS12_381_*; local: *; };" |\
(set -x; ${CC} -shared -o $sharedlib libblst.a ${CFLAGS} \
-Wl,-Bsymbolic,--require-defined=blst_keygen \
-Wl,--version-script=/dev/fd/0)
fi