-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·320 lines (260 loc) · 7.78 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/bin/sh
#
# Step 1: Detect the operating system
#
MAC="Mac OS X"
WIN="Windows"
LIN="Linux"
if [ -f /System/Library/Frameworks/Cocoa.framework/Cocoa ]; then
OS=$MAC
elif [ -d /c/Windows ]; then
OS=$WIN
else
OS=$LIN
fi
# Move to src dir
APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
APP_PATH=`cd "$APP_PATH"; pwd`
cd "$APP_PATH"
#Set the basic paths
OUT_DIR="${APP_PATH}/out"
TMP_DIR="${APP_PATH}/tmp"
SRC_DIR="${APP_PATH}/src"
LIB_DIR="${APP_PATH}/lib"
LOG_FILE="${APP_PATH}/out.log"
PAS_FLAGS="-O3 -vw -gl"
SG_INC="-Fu${LIB_DIR}/"
FPC_BIN=`which fpc`
GAME_NAME="asteroids" #${APP_PATH##*/}
ICON=SwinGame
CLEAN="N"
Usage()
{
echo "Usage: [-c] [-h] [name]"
echo
echo "Compiles your game into an executable application."
echo "Output is located in $OUT_DIR."
echo
echo "Options:"
echo " -c Perform a clean rather than a build"
echo " -h Show this help message "
echo " -i [icon] Change the icon file"
exit 0
}
while getopts chdi: o
do
case "$o" in
c) CLEAN="Y" ;;
h) Usage ;;
d) DEBUG="Y" ;;
i) ICON="$OPTARG";;
esac
done
shift $((${OPTIND}-1))
#
# Change directories based on release or debug builds
#
if [ "a${DEBUG}a" != "aa" ]; then
if [ "$OS" = "$MAC" ]; then
PAS_FLAGS="-gw -vw"
else
PAS_FLAGS="-g -vw"
fi
OUT_DIR="${OUT_DIR}.debug"
fi
if [ ! -d ${TMP_DIR} ]; then
mkdir -p ${TMP_DIR}
fi
if [ -f "${LOG_FILE}" ]; then
rm -f "${LOG_FILE}"
fi
DoExitCompile ()
{
echo "An error occurred while compiling";
cat out.log
exit 1;
}
DoExitLink ()
{
echo "An error occurred while linking";
cat out.log
exit 1;
}
CleanTmp()
{
if [ -d "${TMP_DIR}" ]
then
rm -rf "${TMP_DIR}"
fi
mkdir "${TMP_DIR}"
}
#
# Compile for Mac - manually assembles and links files
# argument 1 is arch
#
doMacCompile()
{
mkdir -p ${TMP_DIR}/${1}
echo " ... Compiling $GAME_NAME - $1"
${FPC_BIN} $PAS_FLAGS ${SG_INC} -Mobjfpc -Sh -FE${TMP_DIR}/${1} -FU${TMP_DIR}/${1} -Fu${LIB_DIR} -Fi${SRC_DIR} -s ${SRC_DIR}/GameMain.pas > ${LOG_FILE}
if [ $? != 0 ]; then DoExitCompile; fi
rm -f ${LOG_FILE}
#Remove the pascal assembler script
rm ${TMP_DIR}/${1}/ppas.sh
echo " ... Assembling for $1"
#Assemble all of the .s files
for file in `find ${TMP_DIR}/${1} | grep [.]s$`
do
/usr/bin/as -o ${file%.s}.o $file -arch $1
if [ $? != 0 ]; then DoExitAsm $file; fi
rm $file
done
echo " ... Linking ${GAME_NAME}"
FRAMEWORKS=`ls -d ${LIB_DIR}/*.framework | awk -F . '{split($1,patharr,"/"); idx=1; while(patharr[idx+1] != "") { idx++ } printf("-framework %s ", patharr[idx]) }'`
/usr/bin/ld /usr/lib/crt1.o -F${LIB_DIR} -L/usr/X11R6/lib -L/usr/lib -search_paths_first -multiply_defined suppress -o "${TMP_DIR}/${1}/${GAME_NAME}" `cat ${TMP_DIR}/${1}/link.res` -framework Cocoa ${FRAMEWORKS}
if [ $? != 0 ]; then DoExitLink ${GAME_NAME}; fi
}
#
# Create fat executable (i386 + ppc)
#
doLipo()
{
echo " ... Creating Universal Binary"
lipo -arch ${1} "${TMP_DIR}/${1}/${GAME_NAME}" -output "${OUT_DIR}/${GAME_NAME}" -create #-arch ${2} "${TMP_DIR}/${2}/${GAME_NAME}"
}
doMacPackage()
{
GAMEAPP_PATH="${OUT_DIR}/${GAME_NAME}.app"
if [ -d "${GAMEAPP_PATH}" ]
then
echo " ... Removing old application"
rm -rf "${GAMEAPP_PATH}"
fi
echo " ... Creating Application Bundle"
mkdir "${GAMEAPP_PATH}"
mkdir "${GAMEAPP_PATH}/Contents"
mkdir "${GAMEAPP_PATH}/Contents/MacOS"
mkdir "${GAMEAPP_PATH}/Contents/Resources"
mkdir "${GAMEAPP_PATH}/Contents/Frameworks"
echo " ... Added Private Frameworks"
cp -R -p "${LIB_DIR}/"*.framework "${GAMEAPP_PATH}/Contents/Frameworks/"
mv "${OUT_DIR}/${GAME_NAME}" "${GAMEAPP_PATH}/Contents/MacOS/"
echo "<?xml version='1.0' encoding='UTF-8'?>\
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\
<plist version=\"1.0\">\
<dict>\
<key>CFBundleDevelopmentRegion</key>\
<string>English</string>\
<key>CFBundleExecutable</key>\
<string>${GAME_NAME}</string>\
<key>CFBundleIconFile</key>\
<string>${ICON}</string>\
<key>CFBundleIdentifier</key>\
<string>au.edu.swinburne.${GAME_NAME}</string>\
<key>CFBundleInfoDictionaryVersion</key>\
<string>6.0</string>\
<key>CFBundleName</key>\
<string>${GAME_NAME}</string>\
<key>CFBundlePackageType</key>\
<string>APPL</string>\
<key>CFBundleSignature</key>\
<string>SWIN</string>\
<key>CFBundleVersion</key>\
<string>1.0</string>\
<key>CSResourcesFileMapped</key>\
<true/>\
</dict>\
</plist>" >> "${GAMEAPP_PATH}/Contents/Info.plist"
echo "APPLSWIN" >> "${GAMEAPP_PATH}/Contents/PkgInfo"
RESOURCE_DIR="${GAMEAPP_PATH}/Contents/Resources"
}
doLinuxCompile()
{
mkdir -p ${TMP_DIR}
echo " ... Compiling $GAME_NAME"
${FPC_BIN} ${PAS_FLAGS} ${SG_INC} -Mobjfpc -Sh -FE${OUT_DIR} -FU${TMP_DIR} -Fu${LIB_DIR} -Fi${SRC_DIR} -o${GAME_NAME} ${SRC_DIR}/GameMain.pas > ${LOG_FILE}
if [ $? != 0 ]; then DoExitCompile; fi
}
doLinuxPackage()
{
RESOURCE_DIR="${OUT_DIR}/Resources"
}
doWindowsCompile()
{
mkdir -p ${TMP_DIR}
echo " ... Compiling $GAME_NAME"
LIB_DIR=$(cygpath -w "$LIB_DIR")
TMP_DIR=$(cygpath -w "$TMP_DIR")
SRC_DIR=$(cygpath -w "$SRC_DIR")
OUT_DIR=$(cygpath -w "$OUT_DIR")
SG_INC="-Fu${LIB_DIR}/"
echo " ... Creating Resources"
windres ${SRC_DIR}/SwinGame.rc ${SRC_DIR}/GameLauncher.res
if [ $? != 0 ]; then DoExitCompile; fi
${FPC_BIN} ${PAS_FLAGS} ${SG_INC} -Mobjfpc -Sh -FE${OUT_DIR} -FU${TMP_DIR} -Fu${LIB_DIR} -Fi${SRC_DIR} -o${GAME_NAME}.exe ${SRC_DIR}/GameMain.pas > ${LOG_FILE}
if [ $? != 0 ]; then DoExitCompile; fi
}
doWindowsPackage()
{
RESOURCE_DIR=${OUT_DIR}/Resources
echo " ... Copying libraries"
cp -p -f "${LIB_DIR}"/*.dll "${OUT_DIR}"
}
copyWithoutSVN()
{
FROM_DIR=$1
TO_DIR=$2
cd "${FROM_DIR}"
# Create directory structure
find . -mindepth 1 ! -path \*.svn\* ! -path \*/. -type d -exec mkdir -p "${TO_DIR}/{}" \;
# Copy files and links
find . ! -path \*.svn\* ! -name \*.DS_Store ! -type d -exec cp -R -p {} "${TO_DIR}/{}" \;
}
#
# Copy Resources from standard location to $RESOURCE_DIR
#
doCopyResources()
{
echo " ... Copying Resources into $GAME_NAME"
copyWithoutSVN "${APP_PATH}/Resources" "${RESOURCE_DIR}"
}
if [ $CLEAN = "N" ]
then
if [ ! -d "${OUT_DIR}" ]
then
mkdir -p "${OUT_DIR}"
fi
echo "--------------------------------------------------"
echo " Creating $GAME_NAME"
echo " for $OS"
echo "--------------------------------------------------"
echo " Running script from $APP_PATH"
echo " Saving output to $OUT_DIR"
echo " Compiler flags ${SG_INC} ${C_FLAGS}"
echo "--------------------------------------------------"
echo " ... Creating ${GAME_NAME}"
if [ "$OS" = "$MAC" ]; then
FPC_BIN="/usr/local/bin/ppc386" #old: `which ppc386`
doMacCompile "i386"
#FPC_BIN="/usr/local/bin/ppcppc"
#doMacCompile "ppc"
doLipo "i386" "ppc"
doMacPackage
elif [ "$OS" = "$LIN" ]; then
doLinuxCompile
doLinuxPackage
else
doWindowsCompile
doWindowsPackage
fi
doCopyResources
else
CleanTmp
rm -rf "${OUT_DIR}"
mkdir "${OUT_DIR}"
echo ... Cleaned
fi
#remove temp files on success
rm -f ${LOG_FILE} 2>> /dev/null
echo " Finished"
echo "--------------------------------------------------"