-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-commit
executable file
·451 lines (378 loc) · 15 KB
/
build-commit
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/bin/bash
##HOST_CC=i686-w64-mingw32
HOST_CC=${2-"x86_64-w64-mingw32"}
COMMIT=$1
GUILE_AUTOMATIC_BASE_DIR="$PWD"
PREFIX="${GUILE_AUTOMATIC_BASE_DIR}/binaries/guile-${HOST_CC}-${COMMIT}"
WIN_CFLAGS="-I${PREFIX}/include"
LIBICONV_CFLAGS="${WIN_CFLAGS} --std=gnu89"
WIN_CXXFLAGS="-I${PREFIX}/include"
WIN_LDFLAGS="-L${PREFIX}/lib"
ZIPDIR="${GUILE_AUTOMATIC_BASE_DIR}/zips"
ZIPNAME="guile-${HOST_CC}-${COMMIT}.zip"
BUILDDIR="${GUILE_AUTOMATIC_BASE_DIR}/builds/guile-${COMMIT}"
DEPSDIR="${GUILE_AUTOMATIC_BASE_DIR}/deps"
GIT_REPO_WORKDIR="${GUILE_AUTOMATIC_BASE_DIR}/guile-git"
GIT_REPO_DIR="${GIT_REPO_WORKDIR}/.git"
if [ -e "${GIT_REPO_DIR}" ]; then
printf "%s exists\n" ${GIT_REPO_DIR}
else
printf "\n%s does not exist. Downloading git repo..\n\n" "${GIT_REPO_DIR}";
sleep 2 ;
#if guile-git exists but not its .git directory,
#delete guile-git, or else git complains about the destination existing
if [ -e "${GIT_REPO_WORKDIR}" ]; then
rm -rf "${GIT_REPO_WORKDIR}" ;
fi
git clone git://git.sv.gnu.org/guile.git "${GIT_REPO_WORKDIR}"
fi
#Test if we have specified a valid git tag
#Contribution from Kai-Martin Knaak june 12 2016
#Use git cat-file -e $sha^{commit} to test if a commit hash exists
TAGS=`git -C ${GIT_REPO_WORKDIR} tag -l`
git -C "${GIT_REPO_WORKDIR}" cat-file -e "${COMMIT}"
GITCATFILE_RESULT=$?
if [ "${TAGS}" != *"${COMMIT}"* ] && [ "${GITCATFILE_RESULT}" -ne 0 ] ; then
printf "Error: ${COMMIT} is not a valid commit tag or git hash.\n" ;
printf "Run ./list-tags to get a list of valid tags.\n" ;
printf "Exiting.\n" ;
exit 1 ;
fi
#Help the user by ensuring that we have the host MINGW toolchain available on the PATH.
printf "Testing whether ${HOST_CC}-gcc exists..\n"
if [ -z `which ${HOST_CC}-gcc` ]; then
printf "Could not find %s!\n" "${HOST_CC}-gcc" ;
exit 1 ;
else
printf "Found %s\n" "${HOST_CC}-gcc" ;
fi
printf "Testing whether ${HOST_CC}-g++ exists..\n"
if [ -z `which ${HOST_CC}-g++` ]; then
printf "Could not find %s!\n" "${HOST_CC}-g++" ;
exit 1 ;
else
printf "Found %s\n" "${HOST_CC}-g++" ;
fi
printf "Testing whether ${HOST_CC}-cpp exists..\n"
if [ -z `which ${HOST_CC}-cpp` ]; then
printf "Could not find %s!\n" "${HOST_CC}-cpp" ;
exit 1 ;
else
printf "Found %s\n" "${HOST_CC}-cpp" ;
fi
printf "Testing whether ${HOST_CC}-as exists..\n"
if [ -z `which ${HOST_CC}-as` ]; then
printf "Could not find %s!\n" "${HOST_CC}-as" ;
exit 1 ;
else
printf "Found %s\n" "${HOST_CC}-as" ;
fi
printf "Testing whether ${HOST_CC}-ld exists..\n"
if [ -z `which ${HOST_CC}-ld` ]; then
printf "Could not find %s!\n" "${HOST_CC}-ld" ;
exit 1 ;
else
printf "Found %s\n" "${HOST_CC}-ld" ;
fi
printf "OK!\n"
sleep 1
printf "COMMIT: %s\n" "${COMMIT}"
printf "HOST_CC Host Compiler: %s\n" "${HOST_CC}"
printf "GUILE_AUTOMATIC_BASE_DIR: %s\n" "${GUILE_AUTOMATIC_BASE_DIR}"
printf "PREFIX: %s\n" "${PREFIX}"
printf "WIN_CFLAGS: %s\n" "${WIN_CFLAGS}"
printf "WIN_CXXFLAGS: %s\n" "${WIN_CXXFLAGS}"
printf "WIN_LDFLAGS: %s\n" "${WIN_LDFLAGS}"
printf "ZIPDIR: %s\n" "${ZIPDIR}"
printf "ZIPNAME: %s\n" "${ZIPNAME}"
printf "BUILDDIR: %s\n" "${BUILDDIR}"
printf "Going to building commit %s.\n" "${COMMIT}"
#printf "Press return to continue\n"
read -n 1 -p "Press return to continue"
#clean working directory so we are sure we can pull
git -C "${GIT_REPO_WORKDIR}" reset --hard
#do a git pull in case the commit or tag is new
git -C "${GIT_REPO_WORKDIR}" pull origin master
#check out our commit via git archive
if [ -e "${BUILDDIR}" ]; then
printf "\nBuild directory %s already exists.\n" "${BUILDDIR}" ;
else
printf "\nBuild directory %s does not exist.\nChecking out commit %s..\n" "${BUILDDIR}" "${COMMIT}" ;
sleep 2 ;
git -C "${GIT_REPO_WORKDIR}" archive -o "${ZIPDIR}/${ZIPNAME}" "${COMMIT}" ;
unzip "${ZIPDIR}/${ZIPNAME}" -d "${BUILDDIR}" ;
#create build directory for native build (for build system)
mkdir -p "${BUILDDIR}/build-linux" ;
#create build directory for windows cross-build
mkdir -p "${BUILDDIR}/build-win" ;
fi
#decompress texinfo dependency (used for old builds like 2.0.0)
if [ ! -e "${BUILDDIR}/deps-shared" ]; then
mkdir -p "${BUILDDIR}/deps-shared" ;
fi
if [ ! -e "${BUILDDIR}/deps-shared/texinfo-4.13" ]; then
tar -zxvf "${DEPSDIR}/texinfo-4.13.tar.gz" -C "${BUILDDIR}/deps-shared/" ;
fi
#decompress library dependencies
if [ ! -e "${BUILDDIR}/deps-win" ]; then
mkdir -p "${BUILDDIR}/deps-win" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/gc-7.2" ]; then
tar -zxvf "${DEPSDIR}/gc-7.2e.tar.gz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/gettext-0.19.7" ]; then
tar -zxvf "${DEPSDIR}/gettext-latest.tar.gz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/gmp-6.1.0" ]; then
tar -xvf "${DEPSDIR}/gmp-6.1.0.tar.lz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/libffi-3.2.1" ]; then
tar -zxvf "${DEPSDIR}/libffi-3.2.1.tar.gz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/libiconv-1.14" ]; then
tar -zxvf "${DEPSDIR}/libiconv-1.14.tar.gz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/libtool-2.4.6" ]; then
tar -zxvf "${DEPSDIR}/libtool-2.4.6.tar.gz" -C "${BUILDDIR}/deps-win/" ;
fi
if [ ! -e "${BUILDDIR}/deps-win/libunistring-0.9.5" ]; then
tar -xvf "${DEPSDIR}/libunistring-0.9.5.tar.xz" -C "${BUILDDIR}/deps-win/" ;
fi
#create install directory
mkdir -p "${PREFIX}"
#####################################################
## Start of dependency build ##
#####################################################
#build texinfo 4.13, which is required for old guile versions
#used by both the native build and the Windows build of Guile
#so it is put in ${BUILDDIR}/deps-shared
cd "${BUILDDIR}/deps-shared/texinfo-4.13"
if [ ! -e "Makefile" ]; then
./configure --without-libiconv-prefix --prefix "${BUILDDIR}/deps-shared/bins" ;
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building texinfo. Aborting.\n" ;
exit 1 ;
fi
#Now we can set ${MAKEINFO} and ${TEXI2DVI} to point
#to the texinfo binaries in ${BUILDDIR}/deps-shared/bins/bin/
MAKEINFO="${BUILDDIR}/deps-shared/bins/bin/makeinfo"
TEXI2DVI="${BUILDDIR}/deps-shared/bins/bin/texi2dvi"
TEXI2PDF="${TEXI2DVI} --pdf --batch"
#build libiconv (no deps)
cd "${BUILDDIR}/deps-win/libiconv-1.14"
if [ ! -e "Makefile" ]; then
./configure --host=${HOST_CC} --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${LIBICONV_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libiconv. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building libiconv. Aborting.\n" ;
exit 1 ;
fi
#build libgmp (no deps)
cd "${BUILDDIR}/deps-win/gmp-6.1.0"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libgmp. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building libgmp. Aborting.\n" ;
exit 1 ;
fi
#build libffi (no deps)
cd "${BUILDDIR}/deps-win/libffi-3.2.1"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libffi. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "Error while building libffi. Aborting.\n" ;
exit 1 ;
fi
#libffi puts its include in a weird place, needs a fix
cp -R "${PREFIX}/lib/libffi-3.2.1/include/*" "${PREFIX}/include/"
#build libtool / libltdl (no deps)
cd "${BUILDDIR}/deps-win/libtool-2.4.6"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libtool. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building libtool / libltdl. Aborting.\n" ;
exit 1 ;
fi
#build libunistring (depends on libiconv)
cd "${BUILDDIR}/deps-win/libunistring-0.9.5"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libunistring. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building libunistring. Aborting.\n" ;
exit 1 ;
fi
#build gettext / libintl / libasprintf (depends on libiconv, libunistring)
cd "${BUILDDIR}/deps-win/gettext-0.19.7"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --disable-threads --enable-static --disable-rpath --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS} -O2" LDFLAGS="${WIN_LDFLAGS}" CXXFLAGS="${WIN_CXXFLAGS} -O2" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring gettext / libintl. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building gettext / libintl. Aborting.\n" ;
exit 1 ;
fi
#build libatomic_ops
cd "${BUILDDIR}/deps-win/gc-7.2/libatomic_ops"
if [ ! -e "Makefile" ]; then
./configure --host="${HOST_CC}" --prefix "${PREFIX}" CFLAGS="${WIN_CFLAGS}" LDFLAGS="${WIN_LDFLAGS}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring libatomic_ops. Aborting.\n" ;
exit 1 ;
fi
fi
make && make install
if [ $? -ne 0 ] ; then
printf "\nError while building libatomic_ops. Aborting.\n" ;
exit 1 ;
fi
#build libgc (depends on libatomic_ops)
cd "${BUILDDIR}/deps-win/gc-7.2"
make -f Makefile.direct CC="${HOST_CC}-gcc" CXX="${HOST_CC}-g++" AS="${HOST_CC}-as" RANLIB="${HOST_CC}-ranlib" HOSTCC=gcc AO_INSTALL_DIR="${PREFIX}" gc.a
if [ $? -ne 0 ] ; then
printf "\nError while building libgc. Aborting.\n" ;
exit 1 ;
fi
#Not sure how to set PREFIX for Makefile.direct, so install manually instead
cp gc.a "${PREFIX}/lib/libgc.a"
cp -r include "${PREFIX}/include/gc"
#####################################################
## Start of guile build ##
#####################################################
cd "${BUILDDIR}"
#create ./configure script if needed
if [ -e "configure" ]; then
printf "\n./configure exist. Skipping ./autogen.sh.\n" ;
sleep 2 ;
else
sh ./autogen.sh ;
#Patch libguile/Makefile.in to link statically against all libraries
printf "\n\nPatching ./libguile/Makefile.in..\n" ;
sleep 2 ;
sed -i -e "s/^guile_LDFLAGS = .*$/guile_LDFLAGS = -all-static/g" "${BUILDDIR}/libguile/Makefile.in" ;
fi
#Fixing a bug in libguile/stime.c (known to exist in 2.0.9 and 2.0.11)
#A conditional enabling of HAVE_POSIX_CPUTIME meant for FreeBSD incorrectly triggers for MinGW
#which tricks guile into thinking that MinGW implements clock_getcpuclockid
#MinGW has limited pthread/pthread time support via winpthreads
sed -i -e "s/#if defined _POSIX_CPUTIME \&\& defined CLOCK_PROCESS_CPUTIME_ID[ ]*$/#if defined _POSIX_CPUTIME \&\& defined CLOCK_PROCESS_CPUTIME_ID \&\& !defined WIN_PTHREADS_TIME_H/g" libguile/stime.c
#Fixing a bug in lib/msvc-inval.c (fixed in 2.0.11, exists in 2.0.8)
#Calling convention is incorrectly written as "cdecl" while the compiler expects "__cdecl"
sed -i -e "s/ cdecl/ __cdecl/g" lib/msvc-inval.c
#Fixing a bug in lib/stdio.h (Fixed in 2.0.9 (?))
#Old gnulib incompatible with new compilers
sed -i -e "s/_GL_WARN_ON_USE (gets, \"gets is a security hole - use fgets instead\");//g" lib/stdio.in.h
#Build guile natively. Required for bootstrapping the Windows build
cd "${BUILDDIR}/build-linux"
if [ -e "GNUmakefile" ]; then
printf "\n./configure already run. Skipping.\n" ;
sleep 2 ;
else
../configure --without-libiconv-prefix --with-threads --disable-deprecated --prefix=/usr/local \
MAKEINFO="${MAKEINFO}" TEXI2DVI="${TEXI2DVI}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring linux guile. Aborting.\n" ;
exit 1 ;
fi
fi
make
if [ $? -ne 0 ] ; then
printf "\nError while building linux guile. Aborting.\n" ;
exit 1 ;
fi
#Build for Windows.
cd "${BUILDDIR}/build-win"
if [ -e "GNUmakefile" ]; then
printf "\n./configure already run. Skipping.\n" ;
sleep 2 ;
else
../configure --host="${HOST_CC}" --prefix="${PREFIX}/guile" --enable-static=yes --enable-shared=no --disable-rpath --enable-debug-malloc --enable-guile-debug \
--disable-deprecated --with-sysroot="${PREFIX}" --without-threads PKG_CONFIG=true BDW_GC_CFLAGS="-I${PREFIX}/include" BDW_GC_LIBS="-L${PREFIX}/lib -lgc" \
LIBFFI_CFLAGS="-I${PREFIX}/include" LIBFFI_LIBS="-L${PREFIX}/lib -lffi" CC_FOR_BUILD=gcc \
GUILE_FOR_BUILD="$BUILDDIR/build-linux/meta/guile" \
CFLAGS="${WIN_CFLAGS} -DGC_NO_DLL" LDFLAGS="${WIN_LDFLAGS} -lwinpthread" \
CXXFLAGS="${WIN_CXXFLAGS}" MAKEINFO="${MAKEINFO}" TEXI2DVI="${TEXI2DVI}" ;
if [ $? -ne 0 ] ; then
printf "\nError while configuring windows guile. Aborting.\n" ;
exit 1 ;
fi
fi
make V=1
if [ $? -ne 0 ] ; then
printf "\nError while building windows guile. Aborting.\n" ;
exit 1 ;
fi
make install
if [ $? -ne 0 ] ; then
printf "\nError while deploying windows guile. Aborting.\n" ;
exit 1 ;
fi
#Erase unnecessary shared libraries that was installed.
#We build statically anyway
printf "\nErasing shared libraries we don't need..\n"
sleep 2
rm "${PREFIX}/bin/*.dll"
#Copy over unit tests
printf "\nCopying over the test suite..\n"
sleep 2
cp -r "${BUILDDIR}/test-suite/" "${PREFIX}/guile/bin"
#Copy over additional files
printf "\nCopying over scripts..\n"
sleep 2
cp -r "${GUILE_AUTOMATIC_BASE_DIR}/base/*" "${PREFIX}"
#Finallly, archive the build
######zip -r ${PREFIX}.zip ${PREFIX}
cd "${GUILE_AUTOMATIC_BASE_DIR}/binaries"
tar -zcvf "guile-${COMMIT}.tar.gz" "guile-${COMMIT}"
cd ${GUILE_AUTOMATIC_BASE_DIR}
printf "\nDone creating archive!\n"
printf "The redistributable archive is located at ${GUILE_AUTOMATIC_BASE_DIR}/binaries/guile-${COMMIT}.tar.gz\n"
exit 0
##########################################################
## Guile Bugs ##
##########################################################
# Guile 2.0.11 ./libguile/stime.c incorrectly thinks that MinGW has support for clock_getcpuclockid()
# Fix by making the conditional macro HAVE_POSIX_CPUTIME on line 132 to not trigger on MinGW builds with libwinpthread. Add a check for WIN_PTHREADS_TIME_H, for example.
# Guile 2.0.8 ./lib/msvc-inval.c incorrectly used "cdecl" where they mean "__cdecl"
# Fix by replacing all instances of "cdecl" with "__cdecl"
# Guile 2.0.0 and some other versions have a too old gnulib (compared to the compiler) which makes ./libs/stdio.h bail on line 477 with "gets: no such function".
# The solution is to remove the _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
# Guile 2.0.0 and some other versions have syntax error in the documentation texi file, which texinfo 5 aborts on.
# Some possible fixes:
# Use texinfo 4.13a or earlier
# Fix the errors manually
# Bypass the texi generation by specifying --enable-maintainer-mode to ./configure