-
Notifications
You must be signed in to change notification settings - Fork 46
/
compile_nfs
executable file
·170 lines (153 loc) · 4.32 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
#!/usr/bin/env bash
BUILD="x86"
BUILD_TYPE="release"
BUILD_WINDOWS="no"
OPENGL_DEFINE=""
OPENGL_LIBS="-lGL"
ANDROID_INSTALL="no"
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 -lmingwex -lmsvcrt -lkernel32 -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 -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
if [[ $BUILD_TYPE == "debug" ]]; then
FLAGS="-O0 -g"
CPP_LTO=""
echo "Debug"
else
FLAGS="-O3 -DNDEBUG"
echo "Release"
fi
echo -n "Compiling C++ code... "
clang -c -std=c++14 $CPU_FLAGS $CPP_LTO $FLAGS -Wno-c++11-narrowing -Wextra Cpp/NFS2SE.cpp -fno-rtti -fno-exceptions || exit
echo "OK!"
echo -n "Compiling C code... "
clang -c -std=gnu89 -Wno-incompatible-function-pointer-types -Wno-int-conversion -Wall $CPU_FLAGS $FLAGS $OPENGL_DEFINE -DNFS_CPP *.c || exit
echo "OK!"
echo -n "Linking... "
clang -fuse-ld=lld -o "../Need For Speed II SE/nfs2se" $CPU_FLAGS $CPP_LTO *.o -lSDL2 $OPENGL_LIBS -lm || exit
echo "OK!"
if [[ $BUILD_TYPE != "debug" ]]; then
echo -n "Stripping... "
strip "../Need For Speed II SE/nfs2se" || exit
echo "OK!"
fi
rm -f *.o
}
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"
;;
esac
shift
done
cd src || exit
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=$(grep WRAPPER_VERSION "Version" | cut -c26-30 | grep "\.") || exit
cd Android || exit
echo "Building OpenGL|ES 2 for Android, wrapper version: $VERSION"
sed "s/@VERSION@/$VERSION/" app/src/main/AndroidManifest.xml.in > app/src/main/AndroidManifest.xml || exit
rm -f app/build/outputs/apk/debug/app-debug.apk || exit
./gradlew packageDebug || exit # packageRelease if you want to sign it
if [[ $ANDROID_INSTALL == "yes" ]]; then
adb install -r app/build/outputs/apk/debug/app-debug.apk || exit
sleep 0.25
adb shell am start -n org.zaps166.NFSIISE/org.zaps166.NFSIISE.NFSIISE
fi
else
compile_x86 $@
fi