-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcompile_nfs
executable file
·180 lines (166 loc) · 4.39 KB
/
compile_nfs
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
BUILD="x86"
BUILD_TYPE="release"
BUILD_WINDOWS="no"
OPENGL_DEFINE=""
OPENGL_LIBS="-lGL"
ANDROID_INSTALL="no"
ANDROID_RUN="no"
BUILD_CPP="yes"
REMOVE_CPP_OBJ="yes"
CPP_LTO="-flto"
OS=$(uname)
function compile_x86
{
CPU_FLAGS='-mno-sse2 -mno-sse -mno-mmx'
COMMON_FLAGS='-Wall -m32 -std=gnu89'
echo -n "Building"
if [[ $BUILD_TYPE == "debug" ]]; then
echo -n " debug"
WIN_SUBSYSTEM='console'
DEBUG_ASM='-g dwarf2'
C_FLAGS="$COMMON_FLAGS -g $CPU_FLAGS"
else
echo -n " release"
WIN_SUBSYSTEM='windows'
C_FLAGS="$COMMON_FLAGS -O2 $CPU_FLAGS"
STRIP='-s'
fi
rm -f *.o
echo -n " for"
if [[ $BUILD_WINDOWS == "yes" ]]; then
echo -n " Windows... "
i686-w64-mingw32-windres Windows/nfs2se.rc icon.o &&
i686-w64-mingw32-gcc $C_FLAGS $OPENGL_DEFINE -c *.c &&
yasm -f win32 Asm/NFS2SE.asm -o NFS2SE.Win32.o $DEBUG_ASM --prefix=_ &&
i686-w64-mingw32-ld --enable-stdcall-fixup -o "../Need For Speed II SE/nfs2se.exe" *.o --stack=0x7D00,0x7D00 --heap=0x2000,0x1000 -lws2_32 -lwinmm -lkernel32 -lmingwex -lmsvcrt -lopengl32 -lSDL2 -subsystem=$WIN_SUBSYSTEM $STRIP -e _start &&
rm -f *.o &&
echo "OK!"
else
if [ $OS == "Darwin" ]; then
echo -n " macOS... "
clang $C_FLAGS $OPENGL_DEFINE -DSTACK_REALIGN -DSWAP_WINDOW_AND_GL_THREAD -c *.c -mmacosx-version-min=10.6 &&
yasm -f macho Asm/NFS2SE.asm -o NFS2SE.OSX.o --prefix=_ -DSWAP_WINDOW_AND_GL_THREAD &&
ld -o "../Need For Speed II SE/nfs2se" *.o -lc -lSDL2 -framework OpenGL -macosx_version_min 10.6 -e _start &&
rm -f *.o &&
echo "OK!"
else
if [ -z $CC ]; then
CC=gcc
fi
echo -n " $OS ($CC)... "
yasm -f elf32 Asm/NFS2SE.asm -o NFS2SE.Elf32.o $DEBUG_ASM &&
$CC -no-pie -nostartfiles $C_FLAGS -DNEED_DSO_HANDLE -DSTACK_REALIGN $OPENGL_DEFINE -o "../Need For Speed II SE/nfs2se" NFS2SE.Elf32.o *.c -lSDL2 $OPENGL_LIBS $STRIP -Wl,-rpath=\$ORIGIN -Wl,-estart &&
rm -f NFS2SE.Elf32.o &&
echo "OK!"
fi
fi
}
function compile_cpp
{
if [ $(uname -m) == "x86_64" ]; then
CPU_FLAGS="-m32"
fi
echo "Compiling C++ translation. It can take a long time and consume a lot of memory!"
if [[ $BUILD_TYPE == "debug" ]]; then
FLAGS="-O0 -g"
echo "Compiling debug..."
else
FLAGS="-Ofast $CPP_LTO -s -march=native -DNDEBUG"
echo "Compiling release..."
fi
if [[ $BUILD_CPP == "yes" ]]; then
gcc -c -std=c++14 $CPU_FLAGS $FLAGS -w Cpp/NFS2SE.cpp -fpermissive -fno-rtti -fno-exceptions || exit 1
fi
gcc -no-pie -o "../Need For Speed II SE/nfs2se" -std=gnu89 $CPU_FLAGS $FLAGS $OPENGL_DEFINE -DNFS_CPP -w *.c NFS2SE.o -lSDL2 $OPENGL_LIBS -lm
if [[ $REMOVE_CPP_OBJ == "yes" ]]; then
rm -f NFS2SE.o
fi
}
while (( $# > 0 ))
do
key=$1
case $key in
cpp|android)
BUILD=$key
;;
debug)
BUILD_TYPE="debug"
;;
win32)
BUILD_WINDOWS="yes"
;;
gl1)
OPENGL_DEFINE="-DOPENGL1X"
;;
gles2)
OPENGL_DEFINE="-DGLES2"
OPENGL_LIBS="-lGLESv2"
;;
install)
ANDROID_INSTALL="yes"
ANDROID_RUN="no"
;;
install-run)
ANDROID_INSTALL="yes"
ANDROID_RUN="yes"
;;
dont-build-cpp)
BUILD_CPP="no"
REMOVE_CPP_OBJ="no"
;;
dont-remove-cpp-obj)
REMOVE_CPP_OBJ="no"
;;
dont-use-lto)
CPP_LTO=""
;;
esac
shift
done
cd src || exit 1
if [[ $BUILD != "android" ]]; then
if [[ $OPENGL_DEFINE == "-DOPENGL1X" ]]; then
echo "Building OpenGL 1"
elif [[ $OPENGL_DEFINE == "-DGLES2" ]]; then
if [[ $OS == "Darwin" ]]; then
echo "OpenGL|ES 2 is not supported on macOS"
exit 1
fi
if [[ $BUILD_WINDOWS == "yes" ]]; then
echo "OpenGL|ES 2 is not supported on Windows"
exit 1
fi
echo "Building OpenGL|ES 2"
else
echo "Building OpenGL 2"
fi
fi
if [[ $BUILD == "cpp" ]]; then
if [[ $OS == "Darwin" ]]; then
echo "C++ translation is not supported on macOS"
exit 1
fi
if [[ $BUILD_WINDOWS == "yes" ]]; then
echo "C++ translation is not supported on Windows"
exit 1
fi
compile_cpp $@
elif [[ $BUILD == "android" ]]; then
VERSION=`../version`
echo "Wrapper version: $VERSION"
cd Android || exit 1
sed "s/@VERSION@/$VERSION/" AndroidManifest.xml.in > AndroidManifest.xml
$ANDROID_NDK_ROOT/ndk-build || exit 1
$ANDROID_HOME/tools/android update project -p . -t android-16 --subprojects || exit 1
ant debug || exit 1
if [[ $ANDROID_INSTALL == "yes" ]]; then
adb install -r bin/NFSIISE-debug.apk || exit 1
if [[ $ANDROID_RUN == "yes" ]]; then
sleep 0.25
adb shell am start -n org.zaps166.NFSIISE/org.zaps166.NFSIISE.NFSIISE
fi
fi
else
compile_x86 $@
fi