-
Notifications
You must be signed in to change notification settings - Fork 4
/
buildmacOS.sh
executable file
·154 lines (126 loc) · 4.35 KB
/
buildmacOS.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
#!/bin/bash
ORIGROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRCROOT=$ORIGROOT/src
# check for spaces in path
ESCAPEDORIGROOT=$(printf %q "$ORIGROOT")
if [[ "$ORIGROOT" != "$ESCAPEDORIGROOT" ]] ; then
echo "This script has detected that the path to its parent directory contains spaces"
echo "or other special characters. The build systems of some of our dependencies do"
echo "not support escaped paths, so building is likely to fail. Please move the"
echo "parent directory of this script to a location without spaces or other special"
echo "characters in its path, then try building again."
echo
echo "Press enter to continue anyway, or Ctrl-C to cancel."
read -rs
echo
fi
function printHeading {
if [[ "$#" -gt 0 ]] ; then
NUM_CHARS="$(echo -n "$1" | wc -c)"
while [[ "$NUM_CHARS" -gt 0 ]] ; do printf "=" ; NUM_CHARS="$(($NUM_CHARS - 1))" ; done ; echo
echo $1
NUM_CHARS="$(echo -n "$1" | wc -c)"
while [[ "$NUM_CHARS" -gt 0 ]] ; do printf "=" ; NUM_CHARS="$(($NUM_CHARS - 1))" ; done ; echo
fi
}
function buildDeps {
ARCH=$1
CONF=$2
OUTPUTROOT=$ORIGROOT/dependencies/output-macOS-$CONF-$ARCH
mkdir -p $OUTPUTROOT
mkdir -p $OUTPUTROOT/bin
mkdir -p $OUTPUTROOT/lib
mkdir -p $OUTPUTROOT/include
mkdir -p $ORIGROOT/dependencies/licenses
export MACOSX_DEPLOYMENT_TARGET=10.13
export CPPFLAGS="-I$OUTPUTROOT/include"
export CFLAGS="-arch $ARCH"
export CXXFLAGS="-arch $ARCH"
export LDFLAGS="-L$OUTPUTROOT/lib -arch $ARCH"
if [[ "$ARCH" == x86_64 ]] ; then
BUILD_HOST=x86_64-apple-darwin$(uname -r)
elif [[ "$ARCH" == arm64 ]] ; then
BUILD_HOST=arm-apple-darwin$(uname -r)
else
echo Unknown architecture type $ARCH. Exiting.
exit
fi
############################################
printHeading "Building c-ares ($ARCH $CONF)"
############################################
cd $SRCROOT/c-ares
cp include/ares_build.h include/ares_build.h.bak &&
if [[ $CONF == "Debug" ]] ; then
./configure --prefix=$OUTPUTROOT --host=$BUILD_HOST --disable-shared --disable-tests --enable-debug
else
./configure --prefix=$OUTPUTROOT --host=$BUILD_HOST --disable-shared --disable-tests
fi &&
make -j`sysctl -n hw.ncpu` &&
make install &&
mv include/ares_build.h.bak include/ares_build.h &&
cp LICENSE.md $ORIGROOT/dependencies/licenses/c-ares.txt &&
make clean
THIS_RESULT=$?
if [[ -z $CARES_RESULT || $CARES_RESULT == 0 ]] ; then CARES_RESULT=$THIS_RESULT ; fi
unset THIS_RESULT
echo
##########################################
printHeading "Building GLEW ($ARCH $CONF)"
##########################################
cd $SRCROOT/glew
if [[ $CONF == "Debug" ]] ; then
make glew.lib.static GLEW_DEST=$OUTPUTROOT SYSTEM=darwin CFLAGS.EXTRA="$CFLAGS" STRIP= &&
make install GLEW_DEST=$OUTPUTROOT STRIP=
else
make glew.lib.static GLEW_DEST=$OUTPUTROOT SYSTEM=darwin CFLAGS.EXTRA="$CFLAGS" &&
make install GLEW_DEST=$OUTPUTROOT
fi &&
rm $OUTPUTROOT/lib/libGLEW*.dylib && # the makefile doesn't seem to respect the static-only build configuration
cp LICENSE.txt $ORIGROOT/dependencies/licenses/GLEW.txt &&
make clean
THIS_RESULT=$?
if [[ -z $GLEW_RESULT || $GLEW_RESULT == 0 ]] ; then GLEW_RESULT=$THIS_RESULT ; fi
unset THIS_RESULT
echo
##########################################
printHeading "Building SDL2 ($ARCH $CONF)"
##########################################
cd $SRCROOT/SDL2
cp include/SDL_config.h include/SDL_config.h.bak &&
# SDL2 appears to have no debug configuration
./configure --prefix=$OUTPUTROOT --host=$BUILD_HOST --disable-shared &&
make -j`sysctl -n hw.ncpu` &&
make install &&
mv include/SDL_config.h.bak include/SDL_config.h &&
cp LICENSE.txt $ORIGROOT/dependencies/licenses/SDL2.txt &&
make distclean
THIS_RESULT=$?
if [[ -z $SDL2_RESULT || $SDL2_RESULT == 0 ]] ; then SDL2_RESULT=$THIS_RESULT ; fi
unset THIS_RESULT
echo
cd $ORIGROOT
}
# build these configurations
buildDeps x86_64 Release
buildDeps x86_64 Debug
buildDeps arm64 Release
buildDeps arm64 Debug
echo "#######################"
echo "# Final build results #"
echo "#######################"
if [[ $CARES_RESULT == 0 ]] ; then
echo c-ares ................. SUCCESS!
else
echo c-ares ................. FAILED!
fi
if [[ $GLEW_RESULT == 0 ]] ; then
echo GLEW ................... SUCCESS!
else
echo GLEW ................... FAILED!
fi
if [[ $SDL2_RESULT == 0 ]] ; then
echo SDL2 ................... SUCCESS!
else
echo SDL2 ................... FAILED!
fi
exit