the asumptions were of course, incorrect
[convexer.git] / build.sh
1 #!/bin/bash
2
3 # Compilers, and cache wrapper
4 # ----------------------------
5 C="gcc"
6 CXX="g++"
7 compiler_cache="ccache"
8
9 # Autodetect ccache unavailible
10 if ! [ -x "$( command -v $compiler_cache )" ]; then
11 compiler_cache=""
12 fi
13
14 # Platform specific
15 # -----------------
16 target_os_windows(){
17 exe_ext=".exe"
18 lib_ext=".dll"
19 compiler_prefix="x86_64-w64-mingw32-"
20 asan=""
21
22 echo "CXR_GNU_LINUX=0" > platform.py
23 }
24
25 target_os_gnu_linux(){
26 exe_ext=""
27 lib_ext=".so"
28 compiler_prefix=""
29
30 asan="-fsanitize=address"
31
32 echo "CXR_GNU_LINUX=1" > platform.py
33 }
34
35 compile(){
36 cmd="$compiler_prefix$@"
37
38 echo $cmd
39 $compiler_cache $cmd
40
41 if [ $? -ne 0 ]; then
42 error "Compile failed"
43 exit 1
44 fi
45 }
46
47 # Commandline arguments
48 # ---------------------
49 if [[ $1 == "windows" ]]; then
50 target_os_windows
51 else
52 target_os_gnu_linux
53 fi
54
55 # Actual compiler commands
56 # format:
57 # <compiler> optimisation level, output type
58 # warning flags
59 # defines
60 # include directories
61 # input files
62 # output file
63 # library links
64
65 mkdir -p nbvtf/obj
66 compile $C -O1 -ggdb -fPIC -shared \
67 -Wall -Wno-unused-variable -Wno-unused-function -std=c99 -pedantic \
68 -DCXR_SO -DCXR_DEBUG -DCXR_VALVE_MAP_FILE -DCXR_VALVE_BIN \
69 -xc cxr/cxr.h \
70 -o libcxr$lib_ext \
71 -lm
72
73 compile $CXX -O3 -c \
74 nbvtf/librgbcx.cpp \
75 -o nbvtf/obj/librgbcx.o
76
77 compile $C -O3 -c \
78 -DUSE_LIBRGBCX \
79 -I./nbvtf/ \
80 nbvtf/vtf_cmd.c \
81 -o nbvtf/obj/tovtf.o
82
83 compile $CXX -O3 -fPIC -c \
84 -DUSE_LIBRGBCX -DNBVTF_AS_SO \
85 -xc nbvtf/nbvtf.h \
86 -o nbvtf/obj/libnbvtf.o
87
88 compile $CXX -O3 -shared \
89 nbvtf/obj/librgbcx.o nbvtf/obj/libnbvtf.o \
90 -o libnbvtf$lib_ext
91
92 compile $C -O3 \
93 -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
94 nbvtf/obj/tovtf.o nbvtf/obj/librgbcx.o \
95 -o tovtf$exe_ext \
96 -lm
97
98 # This is for testing with asan on linux
99 compile $C -ggdb -O0 -Wall \
100 -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
101 -DCXR_SO -DCXR_DEBUG -DCXR_VALVE_MAP_FILE \
102 cxr/test.c \
103 -o test$exe_ext \
104 -lm