forked from christianhaitian/bennugd-monolithic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·126 lines (114 loc) · 3.64 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
#!/bin/bash
# This function will try to copy the required dependencies for the
# binaries in the given directory.
function copy_dependencies {
# We require two params:
# * the dir to install the dependencies into
# * the dir where we should be looking for deps
NUMFILES=$(ls ${1}/* | wc -l)
if [ "$OS" = "Msys" ]; then
for i in "${1}/*"; do
for DEP in $(objdump -p $i | grep "DLL Name" | cut -d ":" -f 2); do
# Is the dependency in the given dir? => copy it if not present
if [ -f "${2}/${DEP}" ]; then
if ! [ -f "${1}/${DEP}" ]; then
cp "${2}/${DEP}" "${1}"
fi
fi
done
done
elif [ "$OS" = "Darwin" ]; then
# Here we should be doing pretty much the same thing as in Msys
# but we should also be changing the dependency path to use
# relative paths when looking for the dependencies
echo "Darwin!"
fi
# If the number of files has changed, iterate again
if [ ! "${NUMFILES}" = "$(ls ${1}/* | wc -l)" ]; then
copy_dependencies ${1} ${2}
fi
}
if [[ "$1" == "clean" ]]; then
rm -rf projects/cmake/bgdc_build
rm -rf projects/cmake/bgdi_build
rm -rf projects/cmake/bin
rm bgdc
rm bgdi
exit 0
fi
# Determine the OS
if [ $(uname) = "Darwin" ]; then
OS=Darwin
else
OS=$(uname -o)
fi
# If given an argument, interpret it as the build type
# Valid values are:
# Debug Release RelWithDebInfo MinSizeRel
# Otherwise compile with Debug configuration
BUILD_TYPE="Release"
#if [ $# -eq 1 ]; then
# BUILD_TYPE=$1
#fi
echo "Build type: ${BUILD_TYPE}"
# Set some variables we'll be using
EXTRACMAKEFLAGS=""
if [ "$OS" = "Msys" ]; then
PROJECTTYPE="Ninja"
EXT=".exe"
BINDIR="bin/win32"
BUILDTOOL="ninja"
INSTALLTOOL="ninja install"
elif [ "$OS" = "GNU/Linux" ]; then
PROJECTTYPE="Ninja"
EXT=""
BINDIR="../../"
if ! [ "$(type -p ninja)" = "" ]; then
BUILDTOOL="ninja"
INSTALLTOOL="ninja install"
else
BUILDTOOL="ninja-build"
INSTALLTOOL="ninja-build install"
fi
# Ubuntu? => Manually specify library locations (beats me)
# if [ "$(lsb_release -is)" = "Ubuntu" ]; then
# EXTRACMAKEFLAGS="-DZLIB_LIBRARY=/usr/lib/i386-linux-gnu/libz.so -DPNG_LIBRARY=/usr/lib/i386-linux-gnu/libpng.so -DFREETYPE_LIBRARY=/usr/lib/i386-linux-gnu/libfreetype.so -DOPENAL_LIBRARY=/usr/lib/i386-linux-gnu/libopenal.so"
# elif [ "$(lsb_release -is)" = "Fedora" ]; then
# EXTRACMAKEFLAGS="-DZLIB_LIBRARY=/usr/lib/libz.so"
# fi
elif [ "$OS" = "Darwin" ]; then
PROJECTTYPE="Ninja"
EXT=""
BINDIR="bin/osx32"
BUILDTOOL="ninja"
INSTALLTOOL="ninja install"
fi
# Compile BGDC and BGDI
cd projects/cmake
for PROJECT in bgdc bgdi; do
echo "Making ${PROJECT}"
rm -rf ${PROJECT}_build
mkdir ${PROJECT}_build
cd ${PROJECT}_build
cmake -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${EXTRACMAKEFLAGS} -G "${PROJECTTYPE}" -DCMAKE_INSTALL_PREFIX=$(pwd)/../ ../${PROJECT}
$BUILDTOOL && $INSTALLTOOL
cd ..
done
# Copy binaries to a common "bin" folder
if ! [ -d ${BINDIR} ]; then
mkdir -p ${BINDIR}
fi
strip bgdc_build/bgdc${EXT}
strip bgdi_build/bgdi${EXT}
cp bgdc_build/bgdc${EXT} ${BINDIR}
cp bgdi_build/bgdi${EXT} ${BINDIR}
cd ../../
# Copy dependencies to the bin dir (for Windows/OS X)
# However, we could do better:
# We can download SDL2 & SDL_mixer from their sites, and use their binaries
# which include far less deps
if [ "$OS" = "Msys" ] || [ "$OS" = "Darwin" ]; then
# if ! [ "${BUILD_TYPE}" = "Debug" ]; then
copy_dependencies ${BINDIR} /mingw32/bin/
# fi
fi