-
Notifications
You must be signed in to change notification settings - Fork 235
/
bootstrap
executable file
·349 lines (268 loc) · 7.17 KB
/
bootstrap
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
336
337
338
339
340
341
342
343
344
345
346
#!/bin/sh
# Alternate bootstrap script for Nu, contributed by Andrew Norrie
# Currently this is for Mac OS systems only.
# INSTALLING NU
# =============
#
# This script builds and installs a single architecture Nu framework
# and nush, the nu shell.
#
# A univeral-binary version can then be built if required by running
#
# % rm -fR build/*
# % nuke
# % nuke install
#
here=`dirname "$0"`
BUILD_PATH_ROOT="${here}/build"
BUILD_PATH="${BUILD_PATH_ROOT}"
FRAMEWORK_DESTINATION="/Library/Frameworks/"
INSTALL_PREFIX="/usr/local"
CFLAGS=
MFLAGS=
LDFLAGS=
FRAMEWORK_NAME="Nu"
FRAMEWORK_EXECUTABLE_NAME="${FRAMEWORK_NAME}"
FRAMEWORK_IDENTIFIER="nu.programming.framework"
FRAMEWORK_ICON="nu.icns"
FRAMEWORK_CREATOR_CODE="????"
FRAMEWORK_COPYRIGHT_STRING="Nu. Copyright (c) 2007 Tim Burks, Radtastical Inc."
FRAMEWORK_REVISION_LETTER="A"
FRAMEWORK_INIT="-Wl,-init -Wl,_NuInit"
#
# DETERMINE CURRENT PLATFORM
# --------------------------
#
# - To determine the current platform we test to see if it is Darwin,
# a.k.a Mac OS X, or anything else. The Darwin major version number
# (8 => 10.4, 9 => 10.5) is passed to the C compiler in the DARWIN
# preprocessor symbol.
#
CFLAGS="${CFLAGS} -Wall -g -std=gnu99 -I ${here}/include -I ${here}/include/Nu -I /usr/local/include"
MFLAGS="${MFLAGS} -fobjc-exceptions"
if test `uname -s` = "Darwin"
then
DARWIN=`uname -r | sed '/\..*/s///'`
else
DARWIN=
fi
if test ${DARWIN}
then
if test ${DARWIN} = "9"
then
LEOPARD="-DLEOPARD_OBJC2 -D__OBJC2__"
SDK="/Developer/SDKs/MacOSX10.5.sdk"
else
if test ${DARWIN} = "8"
then
SDK="/Developer/SDKs/MacOSX10.4u.sdk"
else
echo Error: SDK not found or unknown.
exit 1
fi
fi
if test ! -d "${SDK}"
then
echo Error: "SDK expected at '${SDK}' does not exist."
exit 1
fi
CFLAGS="${CFLAGS} -DMACOSX -DDARWIN=${DARWIN} -isysroot ${SDK} ${LEOPARD}"
else
MFLAGS="${MFLAGS} -fconstant-string-class=NSConstantString";
fi
#
# LOCATION OF PREREQUISITES
# -------------------------
#
# - Nu requires PCRE, the Perl-Compatible Regular Expression Library.
# Before building Nu, download and install pcre, enabling UTF-8.
# Look for it at http://www.pcre.org.
#
# On Mac OS X, to build a universal binary with UTF-8 support,
# use the following command:
#
# % env \
# CXXFLAGS="-arch i386 -arch ppc" \
# CFLAGS="-arch i386 -arch ppc" \
# LDFLAGS="-arch i386 -arch ppc" \
# ./configure \
# --disable-dependency-tracking \
# --enable-utf8
#
# When you install PCRE, it's best to put it in /usr/local (the default).
# If you put it anywhere else, you'll have to modify the Nukefile
# used to build Nu.
#
PCRE_PREFIX="/usr/local"
PCRE_LIBRARY_PATH="${PCRE_PREFIX}/lib"
PCRE_INCLUDE_PATH="${PCRE_PREFIX}/include"
for file in "${PCRE_INCLUDE_PATH}/pcre.h" "${PCRE_LIBRARY_PATH}/libpcre.dylib"
do
if test ! -f "${file}"
then
echo Error: "Perl-Compatible-Regualar-Expressions file '${file}' connot be found"
exit 1
fi
done
# - Nu requires libffi.
FFI_LIBRARY_PATH="/usr/lib"
FFI_INCLUDE_PATH="/usr/include"
for file in "${FFI_INCLUDE_PATH}/ffi/ffi.h" "${FFI_LIBRARY_PATH}/libffi.dylib"
do
if test ! -f "${file}"
then
echo Error: "Foreign-Function-Interface file '${file}' connot be found"
exit 1
fi
done
# CFLAGS="${CFLAGS} -I ${FFI_INCLUDE_PATH}"
#
# BUILD, INSTALL AND TEST NU
# --------------------------
#
# - Make the framework structure
#
FRAMEWORK_STUB="${FRAMEWORK_NAME}.framework"
FRAMEWORK_CONTENTS_STUB="${FRAMEWORK_STUB}/Versions/${FRAMEWORK_REVISION_LETTER}"
FRAMEWORK="${BUILD_PATH}/${FRAMEWORK_STUB}"
FRAMEWORK_CONTENTS="${BUILD_PATH}/${FRAMEWORK_CONTENTS_STUB}"
if test ! -d "${FRAMEWORK}/Headers" -o ! -d "${FRAMEWORK}/Resources"
then
mkdir -p "${FRAMEWORK_CONTENTS}/Headers" "${FRAMEWORK_CONTENTS}/Resources" && \
(cd "${FRAMEWORK}/Versions"; \
ln -sf "${FRAMEWORK_REVISION_LETTER}" Current; \
cd ..; \
ln -sf "Versions/Current/Headers" "Versions/Current/Resources" .)
if test ! -d "${FRAMEWORK}/Headers" -o ! -d "${FRAMEWORK}/Resources"
then
echo Error: "Cannot create the framework folders '${FRAMEWORK}'"
exit
fi
fi
#
# - Add additional external libraries and frameworks
#
if test ${DARWIN}
then
for name in "pcre" "edit" "ffi"
do
LDFLAGS="${LDFLAGS} -l${name}"
done
for name in "Cocoa"
do
LDFLAGS="${LDFLAGS} -framework ${name}"
done
else
for name in "pcre" "readline" "ffi" "m"
do
LDFLAGS="${LDFLAGS} -l${name}"
done
fi
#
# - compilation
#
for file in "${here}/objc/"*.m
do
targ=${BUILD_PATH}/`basename "${file}" | sed -e '/\.m$/s//.o/'`
if test "${targ}" -ot "${file}"
then
rm -f "${FRAMEWORK_CONTENTS}/${FRAMEWORK_EXECUTABLE_NAME}"
if ! gcc ${CFLAGS} ${MFLAGS} -c -o "${targ}" "${file}"
then
exit
fi
fi
done
for file in "${here}/objc/"*.c
do
targ=${BUILD_PATH}/`basename "${file}" | sed -e '/\.c$/s//.o/'`
if test "${targ}" -ot "${file}"
then
rm -f "${FRAMEWORK_CONTENTS}/${FRAMEWORK_EXECUTABLE_NAME}"
if ! gcc ${CFLAGS} -c -o "${targ}" "${file}"
then
exit
fi
fi
done
if test ! -f "${FRAMEWORK_CONTENTS}/${FRAMEWORK_EXECUTABLE_NAME}"
then
if gcc \
${CFLAGS} \
${LDFLAGS} \
${FRAMEWORK_INIT} \
-install_name "${FRAMEWORK_CONTENTS_STUB}/${FRAMEWORK_EXECUTABLE_NAME}" \
-dynamiclib \
-o "${FRAMEWORK_CONTENTS}/${FRAMEWORK_EXECUTABLE_NAME}" \
"${BUILD_PATH}/"*.o
then
(cd "${FRAMEWORK}"; ln -sf "Versions/Current/${FRAMEWORK_EXECUTABLE_NAME}" .)
else
exit
fi
fi
for file in "${here}/include/Nu/"*
do
cp "${file}" "${FRAMEWORK}/Headers"
done
for file in "${here}/nu/"*
do
cp "${file}" "${FRAMEWORK}/Resources"
done
for file in "${here}/share/nu/resources/"*
do
cp -PR "${file}" "${FRAMEWORK}/Resources"
done
cat > "${FRAMEWORK}/Resources/info.plist" <<!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//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>${FRAMEWORK_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${FRAMEWORK_COPYRIGHT_STRING}</string>
<key>CFBundleIdentifier</key>
<string>${FRAMEWORK_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${FRAMEWORK_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleSignature</key>
<string>${FRAMEWORK_CREATOR_CODE}</string>
<key>CFBundleVersion</key>
<string>0.1</string>
<key>NSHumanReadableCopyright</key>
<string>${FRAMEWORK_COPYRIGHT_STRING}</string>
</dict>
</plist>
!
echo Installing Nu framework to ${FRAMEWORK_DESTINATION}
# mv "${FRAMEWORK}" "${FRAMEWORK_DESTINATION}"
if ! gcc \
${CFLAGS} \
${LDFLAGS} \
-framework Nu \
-o "${BUILD_PATH}/nush" \
main/main.m
then
exit
fi
echo Installing Nu tools
for file in "${BUILD_PATH}/nush" "${here}/tools/"*
do
echo `basename ${file}`
sudo cp "${file}" "${INSTALL_PREFIX}/bin"
done
echo Installing Nu shared files and examples
sudo mkdir -p "${INSTALL_PREFIX}/share/nu"
sudo rm -rf "${INSTALL_PREFIX}/share/nu"*
sudo cp -Rp "${here}/share/nu" "${INSTALL_PREFIX}/share/nu"
sudo ditto "${here}/examples" "${INSTALL_PREFIX}/share/nu/examples"
echo Testing Nu
#nutest ${here}/test/test_*.nu
nutest test/test_*.nu