-
Notifications
You must be signed in to change notification settings - Fork 896
/
build.sh
executable file
·335 lines (284 loc) · 8.59 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/sh
MAC="Mac OS X"
WIN="Windows"
LIN="Linux"
if [ `uname` = "Darwin" ]; then
OS=$MAC
elif [ `uname` = "Linux" ]; then
OS=$LIN
else
OS=$WIN
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"
GAME_NAME=${APP_PATH##*/}
FULL_APP_PATH=$APP_PATH
APP_PATH="."
#Set the basic paths
OUT_DIR="${APP_PATH}/bin"
FULL_OUT_DIR="${FULL_APP_PATH}/bin"
BIN_DIR="${APP_PATH}/bin"
SRC_DIR="${APP_PATH}/src"
LIB_DIR="${APP_PATH}/lib"
LOG_FILE="${APP_PATH}/out.log"
CS_FLAGS="-optimize+"
SG_INC="-I${APP_PATH}/lib/"
if [ "$OS" = "$WIN" ]; then
export PATH=$APP_PATH/lib:/c/Program\ Files\ \(x86\)/Mono/bin/:/c/Program\ Files/Mono/bin/:$PATH:/c/Windows/Microsoft.NET/Framework/v4.0.30319
GMCS_FLAGS="-target:exe -r:.\lib\SwinGame.dll,.\packages\NUnit.2.6.4\lib\nunit.framework.dll"
GMCS_FLAGS="$GMCS_FLAGS -platform:x86"
else
GMCS_FLAGS="-target:exe -r:./lib/SwinGame.dll,./packages/NUnit.2.6.4/lib/nunit.framework.dll"
fi
#Locate the compiler...
GMCS_BIN=`which mcs 2>> /dev/null`
if [ -z "$GMCS_BIN" ]; then
#try locating mcs
GMCS_BIN=`which gmcs 2>> /dev/null`
if [ -z "$GMCS_BIN" ]; then
#try locating gmcs
GMCS_BIN=`which csc 2>> /dev/null`
if [ -z "$GMCS_BIN" ]; then
#no compiler found :(
echo "Unable to find a C# compiler. Install Mono or add it to your path."
exit -1
fi
fi
fi
if [ "$OS" = "$MAC" ]; then
ICON="SwinGame.icns"
else
ICON="SwinGame"
fi
CLEAN="N"
#
# Library versions
#
OPENGL=false
SDL_13=true
SDL_12=false
Usage()
{
echo "Usage: [-c] [-h] [-d] [name]"
echo
echo "Compiles your game into an executable application."
echo "Output is located in $FULL_OUT_DIR."
echo
echo "Options:"
echo " -c Perform a clean rather than a build"
echo " -r Release build"
echo " -h Show this help message "
echo " -i [icon] Change the icon file"
exit 0
}
RELEASE=""
while getopts chri:g:b:s: o
do
case "$o" in
c) CLEAN="Y" ;;
s) if [ "${OPTARG}" = "dl12" ]; then
SDL_12=true
SDL_13=false
OPENGL=false
fi
;;
b) if [ "${OPTARG}" = "adass" ]; then
SDL_12=false
SDL_13=true
OPENGL=false
fi
;;
h) Usage ;;
g) if [ "${OPTARG}" = "odly" ]; then
SDL_12=false
SDL_13=false
OPENGL=true
fi
;;
d) RELEASE="Y" ;;
i) ICON="$OPTARG";;
?) Usage
esac
done
shift $((${OPTIND}-1))
if [ "a$1a" != "aa" ]; then
GAME_NAME=$1
fi
if [ "$OS" = "$MAC" ]; then
if [ ${SDL_13} = true ]; then
TMP_DIR="${TMP_DIR}/badass"
LIB_DIR="${APP_PATH}/lib/sdl13"
elif [ ${OPENGL} = true ]; then
TMP_DIR="${TMP_DIR}/godly"
LIB_DIR="${APP_PATH}/lib/godly"
else
TMP_DIR="${TMP_DIR}/sdl12"
LIB_DIR="${APP_PATH}/lib/mac"
fi
elif [ "$OS" = "$WIN" ]; then
#
# This needs 1.3 versions of SDL for Windows...
# along with function sdl_gfx, sdl_ttf, sdl_image, sdl_mixer
#
# if [ ${SDL_13} = true ]; then
# LIB_DIR="${APP_PATH}/lib/sdl13/win"
# elif [ ${OPENGL} = true ]; then
# LIB_DIR="${APP_PATH}/lib/sdl13/win"
# else
SDL_13=false
OPENGL=false
LIB_DIR="${APP_PATH}/lib/win"
# fi
fi
#
# Change directories based on release or debug builds
#
if [ -n "${RELEASE}" ]; then
CS_FLAGS="-optimize+"
OUT_DIR="${OUT_DIR}/Release"
FULL_OUT_DIR="${FULL_OUT_DIR}/Release"
else
CS_FLAGS="-debug -define:DEBUG"
OUT_DIR="${OUT_DIR}/Debug"
FULL_OUT_DIR="${FULL_OUT_DIR}/Debug"
fi
if [ -f "${LOG_FILE}" ]
then
rm -f "${LOG_FILE}"
fi
doMacPackage()
{
GAMEAPP_PATH="${FULL_OUT_DIR}/${GAME_NAME}.app"
if [ -d "${GAMEAPP_PATH}" ]
then
echo " ... Removing old application"
rm -rf "${GAMEAPP_PATH}"
fi
echo " ... Creating Application Bundle"
macpack -m winforms -n "${GAME_NAME}" -o "${OUT_DIR}" "${OUT_DIR}/${GAME_NAME}.exe"
# mkdir "${GAMEAPP_PATH}/Contents/Frameworks"
# echo " ... Adding Private Frameworks"
# cp -R -p "${LIB_DIR}/"*.framework "${GAMEAPP_PATH}/Contents/Frameworks/"
# cp -R -p "./lib/SwinGame.dll" "${GAMEAPP_PATH}/Contents/Resources/"
# pushd . >> /dev/null
# cd "${GAMEAPP_PATH}/Contents/Resources"
# ln -s ../Frameworks/SGSDK.framework/SGSDK libSGSDK.dylib
# ln -s ../Frameworks ./Frameworks #Silly macpac uses ./bin folder
# popd >> /dev/null
cp "${LIB_DIR}/libSGSDK.dylib" "${GAMEAPP_PATH}/Contents/Resources/libSGSDK.dylib"
cp -R -p "./lib/SwinGame.dll" "${GAMEAPP_PATH}/Contents/Resources/"
rm -f "${OUT_DIR}/${GAME_NAME}.exe"
if [ -f "${EXECUTABLE_NAME}.mdb" ]
then
echo " ... Adding Debug Information"
mv "${EXECUTABLE_NAME}.mdb" "${PRODUCT_NAME}.app/Contents/Resources"
fi
echo " ... Adding Application Information"
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"
}
doCompile()
{
if [ ! -d ${OUT_DIR} ]; then
mkdir -p ${OUT_DIR}
fi
if [ "$OS" = "$WIN" ]; then
"${GMCS_BIN}" ${GMCS_FLAGS} ${CS_FLAGS} -out:"${OUT_DIR}/${GAME_NAME}.exe" `find ${APP_PATH} -mindepth 2 -exec ${APP_PATH}/lib/cygpath -ma {} \; | grep [.]cs$` >> ${LOG_FILE}
else
"${GMCS_BIN}" ${GMCS_FLAGS} ${CS_FLAGS} -out:"${OUT_DIR}/${GAME_NAME}.exe" `find ${APP_PATH} -mindepth 2 | grep [.]cs$` >> ${LOG_FILE}
fi
if [ $? != 0 ]; then echo "Error compiling."; cat ${LOG_FILE}; exit 1; fi
}
doLinuxPackage()
{
echo " ... Copying SwinGame Library"
cp -R -p "./lib/SwinGame.dll" "${OUT_DIR}/"
RESOURCE_DIR="${FULL_OUT_DIR}/Resources"
}
doWindowsPackage()
{
RESOURCE_DIR=${FULL_OUT_DIR}/Resources
echo " ... Copying libraries"
cp -p -f "${LIB_DIR}"/*.dll "${OUT_DIR}"
cp -R -p "./lib/SwinGame.dll" "${OUT_DIR}"
}
copyWithoutSVN()
{
FROM_DIR=$1
TO_DIR=$2
cd "${FROM_DIR}"
# Create directory structure
find . -mindepth 1 -type d ! -path \*.svn\* -exec sh -c "if [ ! -d '${TO_DIR}/{}' ]; then mkdir -p '${TO_DIR}/{}'; fi" \;
# 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 $FULL_APP_PATH"
echo " Saving output to $OUT_DIR"
echo " Compiler flags ${CS_FLAGS}"
echo "--------------------------------------------------"
echo " ... Creating ${GAME_NAME}"
doCompile
if [ "$OS" = "$MAC" ]; then
doMacPackage
elif [ "$OS" = "$LIN" ]; then
doLinuxPackage
else
doWindowsPackage
fi
doCopyResources
else
CleanTmp
rm -rf "${BIN_DIR}"
mkdir -p "${BIN_DIR}"
echo ... Cleaned
fi
#remove temp files on success
rm -f ${LOG_FILE} 2>> /dev/null
echo " Finished"
echo "--------------------------------------------------"