Skip to content

Commit ad93f14

Browse files
authored
Merge pull request #1 from NeoTerm/master
Make: Support environment variables
2 parents 5127702 + e9102e3 commit ad93f14

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

make.sh

100644100755
Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
1+
#!/bin/bash
2+
3+
set -e
4+
SELF_DIR="$(dirname $(readlink -f $0))"
5+
cd "$SELF_DIR"
6+
7+
function set_flag() {
8+
local append=false
9+
10+
if [[ "$1" == "--append" ]]; then
11+
shift
12+
append=true
13+
fi
14+
15+
local var="$1"; shift
16+
declare -n ref="$var"
17+
if [[ "$ref" == "" ]]; then
18+
ref="$@"
19+
elif [[ "$append" == true ]]; then
20+
ref="$ref $@"
21+
fi
22+
}
23+
24+
COMMON_FLAGS="-I ../include -shared -fPIC -s -O3 -ldl"
25+
DEFAULT_CXXFLAGS="-std=c++11 $COMMON_FLAGS"
26+
DEFAULT_CFLAGS="$COMMON_FLAGS"
27+
DEFAULT_LDFLAGS=""
28+
DEFAULT_CXX=g++
29+
DEFAULT_CC=gcc
30+
31+
set_flag CC $DEFAULT_CC
32+
set_flag CXX $DEFAULT_CXX
33+
set_flag --append CFLAGS $DEFAULT_CFLAGS
34+
set_flag --append CXXFLAGS $DEFAULT_CXXFLAGS
35+
set_flag --append LDFLAGS $DEFAULT_LDFLAGS
36+
37+
while [[ "$1"x != ""x ]]; do
38+
arg="$1"; shift
39+
case "$arg" in
40+
--cxxflags=* ) CXXFLAGS="${arg##--cxxflags=}" ;;
41+
--ldflags=* ) LDFLAGS="${arg##--ldflags=}" ;;
42+
"--" ) break ;;
43+
esac
44+
done
45+
146
mkdir -p build
247
cd build
348
mkdir -p imports
4-
gcc -I ../include -fPIC -s -O3 -c ../sqlite3.c
5-
g++ -std=c++11 -I ../include -shared -fPIC -s -O3 ../sqlite.cpp ./sqlite3.o -o ./imports/sqlite.cse
6-
rm sqlite3.o
49+
$CC $CFLAGS -c ../sqlite3.c
50+
$CXX $CXXFLAGS ../sqlite.cpp ./sqlite3.o $LDFLAGS -o ./imports/sqlite.cse
51+
rm ./sqlite3.o
52+

0 commit comments

Comments
 (0)