-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·164 lines (148 loc) · 2.77 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
TMP=/tmp/cheetah-build-last
LAST=native
CORES=`nproc`
THREADS=`expr $CORES \* 2`
MAKE="/usr/bin/make -j$THREADS"
CLEAN="/usr/bin/make clean"
DIR=./Release
MACHINE_NAME=`uname -m`
case ${MACHINE_NAME} in
i486|i586|i686)
MACHINE_NAME=32
;;
x86_64)
MACHINE_NAME=64
;;
*)
MACHINE_NAME=
;;
esac
OS=linux
EXE=cheetah
COMPILER=gcc
FLAGS_THIRDPARTY=""
if [ "$1" == "clean" ]
then
cd src
make clean
exit 0
fi
if [ "$1" == "win" -o "$1" == "windows" ]
then
MINGWGCC=`ls /usr/bin/*mingw*gcc | head -1`
if [ ! -f "$MINGWGCC" ]
then
echo "You must install mingw32 - Minimalist GNU win32 (cross) compiler"
exit 1
fi
COMPILER=$MINGWGCC
OS=win
MACHINE_NAME=32
LIB=cheetah.dll
EXE=luajit.exe
LAST=win
fi
GCC_VERSION=$($COMPILER -v |& tail -1 | awk '{print $3}' | sed s/\\.//g)
FLAGS_OPTIMIZE_GENERAL="-fomit-frame-pointer -mtune=generic"
# FLAGS_OPTIMIZE_GENERAL="$FLAGS_OPTIMIZE_GENERAL -ftree-vectorize"
FLAGS_OPTIMIZE="-O2 $FLAGS_OPTIMIZE_GENERAL"
if [ "$2" == "release" -o "$2" == "final" ]
then
FLAGS="$FLAGS_OPTIMIZE"
else
if [ "$2" == "debug" ]
then
FLAGS=-g
else
FLAGS=""
fi
#clang has faster compile time than gcc and produces good code w/o -O3
which clang > /dev/null 2>&1
if [ "$?" = "0" ]
then
COMPILER=clang
echo "Using clang"
fi
fi
#~ which ccache > /dev/null 2>&1
#~ if [ "$?" = "0" ]
#~ then
#~ COMPILER="ccache $COMPILER"
#~ echo "Using ccache"
#~ fi
export CC="$COMPILER"
if [ "$1" == "linux32" ]
then
FLAGS="$FLAGS -m32"
MACHINE_NAME=32
FLAGS_THIRDPARTY="-m32"
LAST=linux32
fi
LIBPATH="$DIR/bin/$OS$MACHINE_NAME/$LIB"
EXEPATH="$DIR/bin/$OS$MACHINE_NAME/$EXE"
# if [ ! -f "$DIR/bin/$OS$MACHINE_NAME/$EXE" ]
# then
# echo "Building luajit..."
# (
# cd thirdparty/LuaJIT
# make clean
# if [ "$1" == "win" -o "$1" == "windows" ]
# then
# make HOST_CC="gcc -m32" CROSS=${MINGWGCC%-gcc} TARGET_SYS=Windows
# cp src/luajit.dll "../../$DIR/bin/$OS$MACHINE_NAME/"
# else
# if [ "$1" == "linux32" ]
# then
# make CC="gcc -m32"
# else
# make
# fi
# cp src/$EXE "../../$DIR/bin/$OS$MACHINE_NAME/"
# fi
# )
# fi
if [ "$CFLAGS" ]
then FLAGS="$FLAGS $CFLAGS"
fi
echo "Building on $CORES cores with flags: $FLAGS"
if [ "`cat $TMP`" != "$LAST $2" ]
then
(cd src; $CLEAN)
fi
echo "$LAST $2" > $TMP
if [ "$2" == "final" ]
then
if [ $GCC_VERSION -ge 450 ]
then
FLAGS="$FLAGS -flto"
fi
(cd src; $CLEAN)
CFLAGS="$FLAGS -fprofile-generate" $MAKE && mv $EXE ../$EXEPATH
pushd .
cd $DIR
pushd .
cd Demos/Tests/LoadImages
$EXEPATH main.lua
popd
pushd .
cd Demos/Tests/Math
$EXEPATH main.lua
popd
popd
(
cd src
$CLEAN
CFLAGS="$FLAGS -fprofile-use" $MAKE && $EXE ../$EXEPATH
)
else
(
cd src
CFLAGS="$FLAGS" $MAKE && mv $EXE ../$EXEPATH
)
fi
if [ "$2" != "debug" ]
then
strip -s $EXEPATH
fi
sh genheader.sh