--- /dev/null
+#!/bin/bash
+
+# Compilers, and cache wrapper
+# ----------------------------
+C="gcc"
+CXX="g++"
+compiler_cache="ccache"
+
+# Autodetect ccache unavailible
+if ! [ -x "$( command -v $compiler_cache )" ]; then
+ compiler_cache=""
+fi
+
+# Platform specific
+# -----------------
+target_os_windows(){
+ exe_ext=".exe"
+ lib_ext=".dll"
+ compiler_prefix="i686-w64-mingw32-"
+ asan=""
+}
+
+target_os_gnu_linux(){
+ exe_ext=""
+ lib_ext=".so"
+ compiler_prefix=""
+
+ asan="-fsanitize=address"
+}
+
+compile(){
+ cmd="$compiler_prefix$@"
+
+ echo $cmd
+ $compiler_cache $cmd
+
+ if [ $? -ne 0 ]; then
+ error "Compile failed"
+ exit 1
+ fi
+}
+
+# Commandline arguments
+# ---------------------
+if [[ $1 == "windows" ]]; then
+ target_os_windows
+else
+ target_os_gnu_linux
+fi
+
+# Actual compiler commands
+# format:
+# <compiler> optimisation level, output type
+# warning flags
+# defines
+# include directories
+# input files
+# output file
+# library links
+
+mkdir -p nbvtf/obj
+compile $C -O1 -ggdb -fPIC -shared \
+ -Wall -Wno-unused-variable -Wno-unused-function -std=c99 -pedantic \
+ -DCXR_SO -DCXR_DEBUG -DCXR_VALVE_MAP_FILE \
+ -xc cxr/cxr.h \
+ -o libcxr$lib_ext \
+ -lm
+
+compile $CXX -O3 -c \
+ nbvtf/librgbcx.cpp \
+ -o nbvtf/obj/librgbcx.o
+
+compile $C -O3 -c \
+ -DUSE_LIBRGBCX \
+ -I./nbvtf/ \
+ nbvtf/vtf_cmd.c \
+ -o nbvtf/obj/tovtf.o
+
+compile $CXX -O3 -fPIC -c \
+ -DUSE_LIBRGBCX -DNBVTF_AS_SO \
+ -xc nbvtf/nbvtf.h \
+ -o nbvtf/obj/libnbvtf.o
+
+compile $CXX -O3 -shared \
+ nbvtf/obj/librgbcx.o nbvtf/obj/libnbvtf.o \
+ -o libnbvtf$lib_ext
+
+compile $C -O3 \
+ -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
+ nbvtf/obj/tovtf.o nbvtf/obj/librgbcx.o \
+ -o tovtf$exe_ext \
+ -lm
+
+# This is for testing with asan on linux
+# compile gcc -ggdb -O1 -Wall \
+# -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
+# cxr/test.c \
+# -o test$exe_ext \
+# -lm