forked from andrewwutw/build-djgpp
-
Notifications
You must be signed in to change notification settings - Fork 9
/
build-djgpp.sh
executable file
·362 lines (298 loc) · 11.2 KB
/
build-djgpp.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
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
#!/usr/bin/env bash
DJCROSS_METHOD=djcross
DJGPP_DOWNLOAD_BASE="http://www.mirrorservice.org/sites/ftp.delorie.com/pub"
PACKAGE_SOURCES="djgpp binutils common"
source script/init.sh
case $TARGET in
*-msdosdjgpp) ;;
*) TARGET="i386-pc-msdosdjgpp" ;;
esac
prepend BINUTILS_CONFIGURE_OPTIONS "--disable-werror
--disable-nls"
prepend GCC_CONFIGURE_OPTIONS "--disable-nls
--enable-libquadmath-support
--enable-version-specific-runtime-libs
--enable-fat
--enable-libstdcxx-filesystem-ts"
prepend GDB_CONFIGURE_OPTIONS "--disable-werror
--disable-nls"
DEPS=""
[ ! -z ${WATT32_VERSION} ] && DEPS+=" gcc djgpp binutils"
[ ! -z ${GCC_VERSION} ] && DEPS+=" djgpp binutils"
[ ! -z ${DJGPP_VERSION} ] && DEPS+=" binutils gcc"
source ${BASE}/script/check-deps-and-confirm.sh
source ${BASE}/script/download.sh
source ${BASE}/script/build-tools.sh
cd ${BASE}/build/ || exit 1
if [ ! -z ${BINUTILS_VERSION} ]; then
if echo ${BINUTILS_VERSION} | grep -q '\.'; then
source ${BASE}/script/unpack-build-binutils.sh
else
mkdir -p bnu${BINUTILS_VERSION}s
cd bnu${BINUTILS_VERSION}s
if [ ! -e binutils-unpacked ]; then
echo "Unpacking binutils..."
unzip -oq ../../download/bnu${BINUTILS_VERSION}s.zip || exit 1
pushd gnu/binutils-* || exit 1
cat ${BASE}/patch/djgpp-binutils-${BINUTILS_VERSION}/* | patch -p1 -u || exit 1
popd
touch binutils-unpacked
fi
cd gnu/binutils-* || exit 1
# exec permission of some files are not set, fix it.
for EXEC_FILE in install-sh missing configure; do
echo "chmod a+x $EXEC_FILE"
chmod a+x $EXEC_FILE || exit 1
done
source ${BASE}/script/build-binutils.sh
fi
fi
cd ${BASE}/build/ || exit 1
if [ ! -z ${WATT32_VERSION} ]; then
export WATT_ROOT=${BASE}/build/Watt-32
cd ${WATT_ROOT} || exit 1
patch -p1 -u < ../../patch/watt32.patch || exit 1
cd util/ || exit 1
case $(uname) in
MINGW*|MSYS*) WATT_UTILS=win32 ;;
Linux) WATT_UTILS=linux ;;
*) WATT_UTILS=linux
rm -f linux/* ;;
esac
case $(uname -m) in
x86_64) ;;
*) rm -f linux/* ;;
esac
${MAKE_J} ${WATT_UTILS}
for i in mkmake mkdep bin2c; do
if ! [ -x ${WATT_UTILS}/$i ]; then
echo "Unable to build Watt-32 tool '$i'. Make sure you have S-Lang installed."
exit 1
fi
done
cd ../src/ || exit 1
if [ ! "`cat configure-options 2> /dev/null`" == "${CFLAGS_FOR_TARGET}" ]; then
${MAKE_J} -f djgpp.mak clean
fi
./configur.sh clean || exit 1
fi
cd ${BASE}/build/ || exit 1
if [ ! -z ${DJGPP_VERSION} ]; then
if [ "${DJGPP_VERSION}" == "cvs" ]; then
cd djgpp-cvs || exit 1
else
echo "Unpacking djgpp..."
rm -rf djgpp-${DJGPP_VERSION}/
mkdir -p djgpp-${DJGPP_VERSION}/
cd djgpp-${DJGPP_VERSION}/ || exit 1
unzip -uoq ../../download/djdev${DJGPP_VERSION}.zip || exit 1
unzip -uoq ../../download/djlsr${DJGPP_VERSION}.zip || exit 1
unzip -uoq ../../download/djcrx${DJGPP_VERSION}.zip || exit 1
patch -p1 -u < ../../patch/patch-djcrx${DJGPP_VERSION}.txt || exit 1
cat ../../patch/djlsr${DJGPP_VERSION}/* | patch -p1 -u || exit 1
fi
cd src
unset COMSPEC
sed -i "50cCROSS_PREFIX = ${TARGET}-" makefile.def
sed -i "61cGCC = ${CC} -g -O2 ${CFLAGS}" makefile.def
if [ ! -z ${GCC_VERSION} ] || [ ! "`cat configure-options 2> /dev/null`" == "${TARGET}:${DST}:${CFLAGS_FOR_TARGET}" ]; then
${MAKE_J} clean
rm -f ../lib/*.{a,o}
fi
${MAKE} misc.exe makemake.exe || exit 1
mkdir -p ../hostbin
${MAKE} -C djasm native || exit 1
${MAKE} -C stub native || exit 1
cd ..
case `uname` in
MINGW*) EXE=.exe ;;
MSYS*) EXE=.exe ;;
*) EXE= ;;
esac
echo "Installing djgpp headers and utilities"
${SUDO} mkdir -p ${DST}/${TARGET}/sys-include || exit 1
install_files include/* ${DST}/${TARGET}/sys-include/ || exit 1
${SUDO} mkdir -p ${DST}/bin || exit 1
install_files hostbin/stubify.exe ${DST}/bin/${TARGET}-stubify${EXE} || exit 1
install_files hostbin/stubedit.exe ${DST}/bin/${TARGET}-stubedit${EXE} || exit 1
fi
cd ${BASE}/build/
if [ ! -z ${GCC_VERSION} ]; then
if [ ! -e ${TMPINST}/autoconf-version ] || [ "$(cat ${TMPINST}/autoconf-version)" != "${AUTOCONF_VERSION}" ]; then
echo "Building autoconf"
cd ${BASE}/build/ || exit 1
untar ${AUTOCONF_ARCHIVE} || exit 1
cd autoconf-${AUTOCONF_VERSION}/
./configure --prefix=${TMPINST} || exit 1
${MAKE_J} DESTDIR= all install || exit 1
echo ${AUTOCONF_VERSION} > ${TMPINST}/autoconf-version
else
echo "autoconf already built, skipping."
fi
if [ ! -e ${TMPINST}/automake-version ] || [ "$(cat ${TMPINST}/automake-version)" != "${AUTOMAKE_VERSION}" ]; then
echo "Building automake"
cd ${BASE}/build/ || exit 1
untar ${AUTOMAKE_ARCHIVE} || exit 1
cd automake-${AUTOMAKE_VERSION}/
./configure --prefix=${TMPINST} || exit 1
${MAKE} DESTDIR= all install || exit 1
echo ${AUTOMAKE_VERSION} > ${TMPINST}/automake-version
else
echo "automake already built, skipping."
fi
cd ${BASE}/build/
# build gcc
BUILDDIR="${BASE}/build/djcross-gcc-${GCC_VERSION}"
mkdir -p ${BUILDDIR}
if [ ! -e ${BUILDDIR}/gcc-unpacked ]; then
rm -rf ${BUILDDIR}/gnu/
echo "Unpacking gcc..."
mkdir -p ${BUILDDIR}/gnu/
cd ${BUILDDIR}/gnu/ || exit 1
untar ${GCC_ARCHIVE}
cd ..
if [ "${DJCROSS_METHOD}" = 'djcross' ]; then
( cd ${BASE}/build/ && untar ${DJCROSS_GCC_ARCHIVE} ) || exit 1
if [ `uname` = "FreeBSD" ]; then
# The --verbose option is not recognized by BSD patch
sed -i 's/patch --verbose/patch/' unpack-gcc.sh || exit 1
fi
case ${GCC_VERSION} in
4.7.3) UNPACK_PATCH=patch-unpack-gcc-4.7.3.txt ;;
4.8.0) ;&
4.8.1) ;&
4.8.2) UNPACK_PATCH=patch-unpack-gcc-4.8.0.txt ;;
*) UNPACK_PATCH=patch-unpack-gcc.txt ;;
esac
patch -p1 -u < ${BASE}/patch/${UNPACK_PATCH} || exit 1
echo "Running unpack-gcc.sh"
sh unpack-gcc.sh --no-djgpp-source || exit 1
fi
# patch gnu/gcc-X.XX/gcc/doc/gcc.texi
echo "Patch gcc/doc/gcc.texi"
cd gnu/gcc-*/gcc/doc || exit 1
sed -i "s/[^^]@\(\(tex\)\|\(end\)\)/\n@\1/g" gcc.texi || exit 1
cd ${BUILDDIR}/gnu/gcc-${GCC_VERSION} || exit 1
# apply extra patches if necessary
cat ${BASE}/patch/djgpp-gcc-${GCC_VERSION}/* | patch -p1 -u || exit 1
touch ${BUILDDIR}/gcc-unpacked
else
echo "gcc already unpacked, skipping."
fi
echo "Building gcc (stage 1)"
mkdir -p ${BUILDDIR}/djcross
cd ${BUILDDIR}/djcross || exit 1
TEMP_CFLAGS="$CFLAGS"
TEMP_CXXFLAGS="$CXXFLAGS"
export CFLAGS="$CFLAGS $GCC_EXTRA_CFLAGS"
export CXXFLAGS="$CXXFLAGS $GCC_EXTRA_CXXFLAGS"
GCC_CONFIGURE_OPTIONS+=" --target=${TARGET} --prefix=${PREFIX}
--enable-languages=${ENABLE_LANGUAGES}
${HOST_FLAG} ${BUILD_FLAG} ${WITH_LIBS}
--with-native-system-header-dir=${PREFIX}/${TARGET}/sys-include"
if [ ! -z "${DESTDIR}" ]; then
GCC_CONFIGURE_OPTIONS+=" --with-build-sysroot=${DESTDIR}"
fi
strip_whitespace GCC_CONFIGURE_OPTIONS
if [ ! -e configure-prefix ] || [ ! "`cat configure-prefix`" == "${GCC_CONFIGURE_OPTIONS}" ]; then
rm -rf *
eval "../gnu/gcc-${GCC_VERSION}/configure ${GCC_CONFIGURE_OPTIONS}" || exit 1
echo ${GCC_CONFIGURE_OPTIONS} > configure-prefix
else
echo "Note: gcc already configured. To force a rebuild, use: rm -rf $(pwd)"
sleep 5
fi
cp ${DST}/bin/${TARGET}-stubify ${TMPINST}/bin/stubify || exit 1
${MAKE_J} all-gcc || exit 1
echo "Installing gcc (stage 1)"
${SUDO} ${MAKE_J} install-gcc || exit 1
CFLAGS="$TEMP_CFLAGS"
CXXFLAGS="$TEMP_CXXFLAGS"
fi
if [ ! -z ${DJGPP_VERSION} ]; then
echo "Building djgpp libc"
cd ${BASE}/build/djgpp-${DJGPP_VERSION}/src
TEMP_CFLAGS="$CFLAGS"
TEMP_LDFLAGS="$LDFLAGS"
export CFLAGS="$CFLAGS_FOR_TARGET"
export LDFLAGS="$LDFLAGS_FOR_TARGET"
sed -i 's/Werror/Wno-error/' makefile.cfg
${MAKE} config || exit 1
echo "${TARGET}:${DST}:${CFLAGS_FOR_TARGET}" > configure-options
${MAKE_J} -C mkdoc || exit 1
${MAKE_J} -C libc || exit 1
echo "Installing djgpp libc"
${SUDO} mkdir -p ${DST}/${TARGET}/lib
install_files ../lib/* ${DST}/${TARGET}/lib || exit 1
LDFLAGS="$TEMP_LDFLAGS"
CFLAGS="$TEMP_CFLAGS"
fi
cd ${BASE}/build/ || exit 1
if [ ! -z ${WATT32_VERSION} ]; then
echo "Building Watt-32"
cd ${WATT_ROOT}/src || exit 1
DJGPP_PREFIX=${TARGET} ./configur.sh djgpp || exit 1
cp ${BASE}/patch/watt32-djgpp-$(get_version djgpp)/djgpp.err ../inc/sys/djgpp.err || exit 1
cp ${BASE}/patch/watt32-djgpp-$(get_version djgpp)/syserr.c build/djgpp/syserr.c || exit 1
echo "${CFLAGS_FOR_TARGET}" > configure-options
export TARGET CFLAGS_FOR_TARGET
${MAKE_J} -f djgpp.mak || exit 1
echo "Installing Watt-32"
${SUDO} mkdir -p ${DST}/${TARGET}/watt/inc || exit 1
${SUDO} mkdir -p ${DST}/${TARGET}/watt/lib || exit 1
install_files ../lib/libwatt.a ${DST}/${TARGET}/watt/lib/ || exit 1
${SUDO} ln -fs ../watt/lib/libwatt.a ${DST}/${TARGET}/lib/libwatt.a || exit 1
${SUDO} ln -fs libwatt.a ${DST}/${TARGET}/lib/libsocket.a || exit 1
install_files ../inc/* ${DST}/${TARGET}/watt/inc/ || exit 1
set_version watt32
fi
if [ ! -z ${GCC_VERSION} ]; then
echo "Building gcc (stage 2)"
cd $BUILDDIR/djcross || exit 1
TEMP_CFLAGS="$CFLAGS"
TEMP_CXXFLAGS="$CXXFLAGS"
export CFLAGS="$CFLAGS $GCC_EXTRA_CFLAGS"
export CXXFLAGS="$CXXFLAGS $GCC_EXTRA_CXXFLAGS"
export STAGE_CC_WRAPPER="${BASE}/script/destdir-hack.sh ${DST}/${TARGET}"
${MAKE_J} || exit 1
[ ! -z $MAKE_CHECK_GCC ] && ${MAKE_J} -s check-gcc | tee ${BASE}/tests/gcc.log
echo "Installing gcc (stage 2)"
${SUDO} ${MAKE_J} install-strip || \
${SUDO} ${MAKE_J} install-strip || exit 1
CFLAGS="$TEMP_CFLAGS"
CXXFLAGS="$TEMP_CXXFLAGS"
set_version gcc
fi
if [ ! -z ${DJGPP_VERSION} ]; then
echo "Building djgpp libraries"
cd ${BASE}/build/djgpp-${DJGPP_VERSION}/src
TEMP_CFLAGS="$CFLAGS"
TEMP_LDFLAGS="$LDFLAGS"
export CFLAGS="$CFLAGS_FOR_TARGET"
export LDFLAGS="$LDFLAGS_FOR_TARGET"
${MAKE_J} -C utils native || exit 1
${MAKE_J} -C dxe native || exit 1
${MAKE_J} -C debug || exit 1
# Disabled for now. See issue #46.
#${MAKE_J} -C libemu || exit 1
${MAKE_J} -C libm || exit 1
${MAKE_J} -C docs || exit 1
${MAKE_J} -C ../zoneinfo/src
${MAKE_J} -f makempty || exit 1
LDFLAGS="$TEMP_LDFLAGS"
CFLAGS="$TEMP_CFLAGS"
cd ..
echo "Installing djgpp libraries and utilities"
install_files lib/* ${DST}/${TARGET}/lib || exit 1
${SUDO} mkdir -p ${DST}/${TARGET}/share/info
install_files info/* ${DST}/${TARGET}/share/info
install_files hostbin/exe2coff.exe ${DST}/bin/${TARGET}-exe2coff${EXE} || exit 1
install_files hostbin/djasm.exe ${DST}/bin/${TARGET}-djasm${EXE} || exit 1
install_files hostbin/dxegen.exe ${DST}/bin/${TARGET}-dxegen${EXE} || exit 1
install_files hostbin/dxegen.exe ${DST}/bin/${TARGET}-dxe3gen${EXE} || exit 1
install_files hostbin/dxe3res.exe ${DST}/bin/${TARGET}-dxe3res${EXE} || exit 1
set_version djgpp
fi
cd ${BASE}/build
source ${BASE}/script/build-gdb.sh
source ${BASE}/script/finalize.sh