switch to shell scripts
[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="i686-w64-mingw32-"
20 asan=""
21 }
22
23 target_os_gnu_linux(){
24 exe_ext=""
25 lib_ext=".so"
26 compiler_prefix=""
27
28 asan="-fsanitize=address"
29 }
30
31 compile(){
32 cmd="$compiler_prefix$@"
33
34 echo $cmd
35 $compiler_cache $cmd
36
37 if [ $? -ne 0 ]; then
38 error "Compile failed"
39 exit 1
40 fi
41 }
42
43 # Commandline arguments
44 # ---------------------
45 if [[ $1 == "windows" ]]; then
46 target_os_windows
47 else
48 target_os_gnu_linux
49 fi
50
51 # Actual compiler commands
52 # format:
53 # <compiler> optimisation level, output type
54 # warning flags
55 # defines
56 # include directories
57 # input files
58 # output file
59 # library links
60
61 mkdir -p nbvtf/obj
62 compile $C -O1 -ggdb -fPIC -shared \
63 -Wall -Wno-unused-variable -Wno-unused-function -std=c99 -pedantic \
64 -DCXR_SO -DCXR_DEBUG -DCXR_VALVE_MAP_FILE \
65 -xc cxr/cxr.h \
66 -o libcxr$lib_ext \
67 -lm
68
69 compile $CXX -O3 -c \
70 nbvtf/librgbcx.cpp \
71 -o nbvtf/obj/librgbcx.o
72
73 compile $C -O3 -c \
74 -DUSE_LIBRGBCX \
75 -I./nbvtf/ \
76 nbvtf/vtf_cmd.c \
77 -o nbvtf/obj/tovtf.o
78
79 compile $CXX -O3 -fPIC -c \
80 -DUSE_LIBRGBCX -DNBVTF_AS_SO \
81 -xc nbvtf/nbvtf.h \
82 -o nbvtf/obj/libnbvtf.o
83
84 compile $CXX -O3 -shared \
85 nbvtf/obj/librgbcx.o nbvtf/obj/libnbvtf.o \
86 -o libnbvtf$lib_ext
87
88 compile $C -O3 \
89 -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
90 nbvtf/obj/tovtf.o nbvtf/obj/librgbcx.o \
91 -o tovtf$exe_ext \
92 -lm
93
94 # This is for testing with asan on linux
95 # compile gcc -ggdb -O1 -Wall \
96 # -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
97 # cxr/test.c \
98 # -o test$exe_ext \
99 # -lm