summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: fffaf1f76bb9a5e51aff4c96c82056a356cd79d0 (plain)
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
# Contributor: carstene1ns <arch carsten-teibes de>
# Contributor: felix <base64 -d <<< ZmVsaXgudm9uLnNAcG9zdGVvLmRlCg==>
# Contributor: janezz55

pkgname=dosbox-gcc
pkgver=9.1.0
_target="i586-pc-msdosdjgpp"
_islver=0.18
_djver=2.05
_pthver=3.14
_zlver=1.2.11
_wattver="2.2-dev.10"
pkgrel=2
pkgdesc="djgpp cross-compiler for the dosbox environment"
arch=('i686' 'x86_64')
url="http://gcc.gnu.org"
license=('GPL' 'LGPL' 'FDL' 'custom')
groups=('djgpp')
depends=('zlib' 'libmpc' 'dosbox-binutils')
makedepends=('unzip')
optdepends=('dosbox-djcrx: headers and utilities')
options=('!strip' 'staticlibs' '!emptydirs')
source=("https://ftp.gnu.org/gnu/gcc/gcc-${pkgver}/gcc-$pkgver.tar.xz"
        "ftp://www.delorie.com/pub/djgpp/current/v2/djcrx${_djver//./}.zip"
        "http://isl.gforge.inria.fr/isl-${_islver}.tar.xz"
        "https://zlib.net/zlib-${_zlver}.tar.gz"
        "http://www.watt-32.net/watt32s-${_wattver}.zip"
        "mkmake.bash"
        "watt32.pc"
	"gcc-djgpp.diff"
        "lto.patch")
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'c03dbd61274e1ce14f84366abf348d75779bbd6e0bc32b9f4fd74f1ce54a5ef0')
noextract=("djcrx${_djver//./}.zip"
           "watt32s-${_wattver}.zip")

prepare() {
  # extract bootstrap wattcp
  mkdir -p watt
  cd watt
  unzip -qo "../watt32s-${_wattver}.zip"

  # apply felix's patches
	sed -i -e '
		s,#include "/dev/env/DJDIR/include/\(.*\)",#include_next <\1>,
	' inc/sys/cdefs.h

 	cd src
	ln -fs chksum0.s  chksum0.S
	ln -fs cpumodel.s cpumodel.S

  mkdir -p djgpp

	# use standard zlib
	sed -i -e 's,"zlib/zlib\.h",<zlib.h>,' pcdbug.c
	sed -i -e '/define Z_PREFIX/ d' config.h

	sed -i -e '
		s,\tar,\t$(AR),
		s,\.\./util/nasm32,\t$(NASM),
		s,\.\./util/bin2c,\t$(BIN2C),
    s,-O2,-Ofast,
	' makefile.all zlib/makefile.all
  sed -i -e "
		/CFLAGS/ s,=,= -fno-strict-aliasing -fgnu89-inline -march=i586 -I${srcdir}/zlib-${_zlver},
  " makefile.all zlib/makefile.all
	bash "$srcdir/mkmake.bash" DJGPP RELEASE <makefile.all >djgpp.mak

  cd ../util
	sed -n -e '
		$ {
			i #include "errnos0.i"
			x
			w errnos0.c
			q
		};
		/_ERRNO(/ H
		/<io\.h>/ d
		/\(VendorName\|VendorVersion\|process\|prologue\|epilogue\) (void)\r$/,/^\}\r$/ ! { p; b };
		H
	' errnos.c > errnos1.c

  # gcc hacks
  cd $srcdir/gcc-$pkgver

  # link isl for in-tree build
  ln -fs "../isl-${_islver}" isl

  # hack! - some configure tests for header files break with FORTIFY_SOURCE
  sed -i "/ac_cpp=/ s/\$CPPFLAGS/\$CPPFLAGS -O2/" {libiberty,gcc}/configure

  # build the lto plugin
  patch -Np0 < ../lto.patch

  # Other DJGPP related changes
  patch -Np1 < ../gcc-djgpp.diff

  # extract bootstrap djcrx
  mkdir -p ../gcc-build-$_target/lib/gcc/$_target/$pkgver
  cd ../gcc-build-${_target}/lib/gcc/$_target/$pkgver
  unzip -qoW "$srcdir/djcrx${_djver//./}.zip" 'include/**' 'lib/*.[oa]'
  mv lib/* .
}

build() {
  OLD_PATH=$PATH

  cd gcc-build-$_target
  ../gcc-$pkgver/configure \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --datarootdir=/usr/$_target/share \
    --target="$_target" \
    --disable-ld \
    --disable-nls \
    --disable-libssp \
    --disable-libquadmath \
    --disable-libquadmath-support \
    --disable-libgomp \
    --disable-install-libiberty \
    --enable-decimal-float \
    --enable-gold \
    --enable-languages=c,c++ \
    --enable-shared \
    --enable-static \
    --with-system-zlib \
    --with-arch=i586 \
    --with-cpu=i586 \
    --enable-threads \
    --enable-libstdcxx-threads \
    --enable-lto \
    --enable-libstdcxx-filesystem-ts \
    --enable-libstdcxx-time \
    --disable-multilib --enable-checking=release
  make all-gcc

  export PATH=$srcdir/gcc-build-$_target/gcc:$PATH

  # build zlib
  echo ...building zlib
  cd $srcdir/zlib-${_zlver}
  CC=$srcdir/gcc-build-$_target/gcc/xgcc \
  CHOST=${_target} \
  CFLAGS="-march=i586 -Ofast -DHAVE_VSNPRINTF -I$srcdir/gcc-build-${_target}/lib/gcc/$_target/$pkgver/include -pipe" \
  ../zlib-${_zlver}/configure --const --prefix=/usr/$_target --static
  sed -i 's/-DNO_STRERROR -DNO_vsnprintf//' Makefile
  make libz.a

  # build wattcp
  echo ...building wattcp
  cd $srcdir/watt/util
	$srcdir/gcc-build-$_target/gcc/xgcc -P -E errnos0.c \
		-include $srcdir/gcc-build-${_target}/lib/gcc/$_target/$pkgver/include/errno.h \
		-include $srcdir/gcc-build-${_target}/lib/gcc/$_target/$pkgver/include/sys/version.h \
		| sed -e '/^extern/ d' > errnos0.i

	# TCC would also do
  export PATH=$OLD_PATH
	gcc errnos1.c -o errnos1
	./errnos1 -e > "../inc/sys/djgpp.err"
	./errnos1 -s > "../src/djgpp/syserr.c"
  export PATH=$srcdir/gcc-build-$_target/gcc:$PATH

  cd $srcdir/watt/src
	make -f djgpp.mak \
		CC=$srcdir/gcc-build-$_target/gcc/xgcc -I$srcdir/gcc-build-${_target}/lib/gcc/$_target/$pkgver/include \
		AS=$_target-as \
		AR=$_target-ar \
		NASM=/usr/bin/nasm \
		BIN2C='hexdump -ve "1/1 \"0x%02X\,\" \"\n\""' \
		DJDIR=/usr/$_target ZLIB_OBJS=

  # start building gcc again, with pthreads
  echo ...back to building gcc
  export PATH=$OLD_PATH

  cd $srcdir/gcc-build-$_target
  make all
}

package_dosbox-gcc() {
  echo ...installing
  make -C gcc-build-$_target DESTDIR="$pkgdir/" install
  make -C zlib-${_zlver} DESTDIR="$pkgdir/" install

  # strip manually, djgpp libs spew errors otherwise
  strip -s "$pkgdir"/usr/bin/$_target-*
  strip -s "$pkgdir"/usr/lib/gcc/$_target/$pkgver/{cc1*,collect2,lto*}

  # for compatibility
  ln -sf $_target-gcc "$pkgdir"/usr/bin/$_target-cc

  # remove unnecessary files
  rm -rf "$pkgdir"/usr/$_target/share/{man,info,locale}
  rm -rf "$pkgdir"/usr/share/{man,info,locale}
  rm -rf "$pkgdir"/usr/lib/gcc/$_target/$pkgver/include-fixed
  rm -f "$pkgdir"/usr/lib/libcc1.*

  # install wattcp
	cd "$srcdir/watt/inc"

	install -dm0755 "$pkgdir/usr/$_target/include/watt32"
	install -m0644 *.h "$pkgdir/usr/$_target/include/watt32"
	for _d in netinet6 protocol netinet net rpc rpcsvc sys arpa; do
		install -dm0755 "$pkgdir/usr/$_target/include/watt32/$_d"
		install -m0644 "$_d"/*.h "$pkgdir/usr/$_target/include/watt32/$_d"
	done
	install -dm0755 "$pkgdir/usr/$_target/include/sys"
	install -m0644 sys/djgpp.err "$pkgdir/usr/$_target/include/sys/djgpp.err"

	cd "$srcdir/watt/lib"
	install -Dm0644 libwatt.a "$pkgdir/usr/$_target/lib/libwatt.a"
	install -Dm0644 $srcdir/watt32.pc "$pkgdir/usr/$_target/lib/pkgconfig/watt32.pc"
}