summaryrefslogtreecommitdiffstats
path: root/main/gcc/APKBUILD
blob: e049ac24ec9c3d344bc490563f816f37fc37fc0a (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
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
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gcc
pkgver=4.6.2
_piepatchver=0.4.5
_specs_ver=0.2.0
_specs_gcc_ver=4.4.3

_uclibc_abiver=0.9.32

pkgrel=2
pkgdesc="The GNU Compiler Collection"
url="http://gcc.gnu.org"
arch="all"
license="GPL LGPL"
depends="binutils libgcc libgomp libobjc"
makedepends="bison flex gmp-dev mpfr-dev texinfo libmpc-dev gawk zlib-dev zip
	cloog-dev"
subpackages="$pkgname-doc libstdc++:libcxx g++:gpp libgcc libgomp $pkgname-go
	libgo"
replaces="libstdc++"

if [ -n "$BOOTSTRAP" ]; then
	LANG_OBJC=off
	LANG_JAVA=off
fi

if [ "$LANG_OBJC" != "off" ]; then
	subpackages="$subpackages libobjc"
fi
if [ "$LANG_JAVA" != "off" ]; then
	subpackages="$subpackages $pkgname-java libgcj"
	makedepends="$makedepends paxctl"
fi
if [ "$LANG_GO" != "off" ]; then
	_languages="$_languages,go"
			        fi



source="ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-core-$pkgver.tar.bz2
	ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-g++-$pkgver.tar.bz2
	ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-objc-$pkgver.tar.bz2
	ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-java-$pkgver.tar.bz2
	ftp://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-go-$pkgver.tar.bz2
	http://distfiles.gentoo.org/distfiles/gcc-4.6.1-piepatches-v${_piepatchver}.tar.bz2
	http://distfiles.gentoo.org/distfiles/gcc-$_specs_gcc_ver-specs-$_specs_ver.tar.bz2
	ftp://sourceware.org/pub/java/ecj-latest.jar
	
	08_all_cross-compile.patch
	11_all_default-warn-format-security.patch
	12_all_default-warn-trampolines.patch
	15_all_libgomp-Werror.patch
	34_all_ia64_note.GNU-stack.patch
	51_all_libiberty-pic.patch
	74_all_gcc46_cloog-dl.patch

	gcc-spec-env.patch
	pt_gnu_eh_frame.patch
	uclibc-getipinfo.patch
	gcc-4.6-dynamic-linker.patch
	gcc-4.6-pr32219.patch
	boehem-gc-uclibc.patch
	gcc-pure64.patch
	gcc-go.patch
	gcc-libgcc-x86.get_pc_thunk.bx.patch
	"

# we build out-of-tree
_gccdir="$srcdir"/gcc-$pkgver
_builddir="$srcdir/build"

prepare() {
	cd "$_gccdir"
	# verify we have set CHOST
	if [ -z "$CHOST" ]; then
		error "CHOST not set"
		return 1
	fi

	# PIE patches from gentoo
	# thanks to Zorry for hard work on those patches
	for i in "$srcdir"/piepatch/*.patch; do
		msg "Applying $i"
		patch -p0 -i $i || patch -p1 -i $i || return 1
	done

	# Gentoo and uclibc patches
	_err=
	for i in $source; do
		case "$i" in
		*.patch)
			msg "Applying $i"
			patch -p1 -i "$srcdir"/$i || _err="$_err $i"
			;;
		esac
	done
	
	if [ -n "$_err" ]; then
		error "The following patches failed:"
		for i in $_err; do
			echo "  $i"
		done
		return 1
	fi

	#PR33200
	sed -i 's/use_fixproto=yes/:/' gcc/config.gcc || return 1

	# enable hardened cflags by default
	# building gcc wih PIE seem to hit some strange bug. we probably run
	# out of some resource. so we disable PIE for gcc while enabling it
	# by default for everything else.
	local _hard_cflags="-DEFAULT_PIE_SSP -DEFAULT_RELRO -DEFAULT_BIND_NOW"
	sed -e "/^ALL_CFLAGS/iHARD_CFLAGS = ${_hard_cflags}" \
		-e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) -fno-PIE |' \
		-i gcc/Makefile.in || return 1
	sed -e "/stage1_cflags=/s/-fno-stack-protector/-fno-stack-protector -fno-PIE/" \
		-i configure

	# see http://gcc.gnu.org/ml/java/2008-04/msg00027.html
	mv "$srcdir"/ecj-latest.jar ecj.jar
	
	echo ${pkgver} > gcc/BASE-VER
}

build() {
	local _languages= _dynamic_linker=
	cd "$_gccdir"
	export CFLAGS="-fno-stack-protector"
	[ -z "$CBUILD" ] && CBUILD="$CHOST"
	[ -z "$CTARGET" ] && CTARGET="$CHOST"

	case "$CHOST" in
		x86_64-*-uclibc)
			_dynamic_linker="--with-dynamic-linker=ld64-uClibc.so.$_uclibc_abiver"
			;;
		*-uclibc)
			_dynamic_linker="--with-dynamic-linker=ld-uClibc.so.$_uclibc_abiver"
			;;
		*)	_dynamic_linker=
			;;
	esac

	_languages=c,c++
	# we can disable OBJC with LANG_OBJC=off
	if [ "$LANG_OBJC" != "off" ]; then
		_languages=$_languages,objc
	fi

	# and disable java with LANG_JAVA=off
	if [ "$LANG_JAVA" != "off" ]; then
		_languages="$_languages,java"
	fi

        if [ "$LANG_GO" != "off" ]; then
		_languages="$_languages,go"
	fi

	# --enable-target-optspace is broken on powerpc
	if [ "$CARCH" != "powerpc" ]; then
		_target_optspace="--enable-target-optspace"
	fi

	msg "Building the following:"
	echo ""
	echo "  CBUILD=$CBUILD"
	echo "  CHOST=$CHOST"
	echo "  CTARGET=$CTARGET"
	echo "  languages=$_languages"
	echo "  dynamic_linker=$_dynamic_linker"
	echo "  target_optspace=$_target_optspace"
	echo ""

	mkdir -p "$_builddir"
	cd "$_builddir"
	"$_gccdir"/configure --prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--build=${CBUILD} \
		--host=${CHOST} \
		--target=${CTARGET} \
		--with-pkgversion="Alpine ${pkgver}-r${pkgrel}" \
		--disable-altivec \
		--disable-checking \
		--disable-fixed-point \
		--disable-libssp \
		--disable-libstdcxx-pch \
		--disable-multilib \
		--disable-nls \
		--disable-werror \
		--enable-__cxa_atexit \
		--enable-cld \
		--enable-esp \
		--enable-cloog-backend \
		--enable-languages=$_languages \
		--enable-shared \
		$_target_optspace \
		--enable-tls \
		--enable-threads \
		$_dynamic_linker \
		--with-dynamic-linker-prefix=/lib \
		--with-system-zlib \
		--without-system-libunwind 

	make || return 1
}

package() {
	cd "$_builddir"
	make -j1 DESTDIR="${pkgdir}" install || return 1
	find "$pkgdir" -name '*.la' -delete || return 1

	ln -s gcc "$pkgdir"/usr/bin/cc

	# binutils provides libiberty.a
	rm -f "$pkgdir"/usr/lib/libiberty.a

	# install the specs
	cd "$srcdir"/specs
	install -d "$pkgdir"/usr/share/gcc
	for i in *.specs; do
		install -m644 $i "$pkgdir"/usr/share/gcc/$i || return 1
	done

	# we dont support gcj -static
	# and saving 35MB is not bad.
	find "$pkgdir" -name libgcj.a -o -name libgtkpeer.a \
		-o -name libgjsmalsa.a -o -name libgcj-tools.a \
		-o -name libjvm.a -o -name libgij.a -o -name libgcj_bc.a \
		-o -name libjavamath.a \
		| xargs rm -f \
		|| return 1
	
	[ "$LANG_JAVA" = "on" ] && \
		sed -i -e 's/lib: /&%{static:%eJava programs cannot be linked statically}/' \
		"$pkdir"/usr/lib/libgcj.spec

	# remove ffi
	rm "$pkgdir"/usr/lib/libffi* "$pkgdir"/usr/share/man/man3/ffi* \
		|| return 1
	find "$pkgdir" -name 'ffi*.h' | xargs rm -f

	mkdir -p "$pkgdir"/usr/share/gdb/python/auto-load/usr/lib
	mv "$pkgdir"/usr/lib/*-gdb.py \
		"$pkgdir"/usr/share/gdb/python/auto-load/usr/lib/
}

libcxx() {
	pkgdesc="GNU C++ standard runtime library"
	depends=
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libstdc++.so.* "$subpkgdir"/usr/lib/
}

gpp() {
	pkgdesc="GNU C++ standard library and compiler"
	depends="libstdc++"
	local libexec=usr/libexec/gcc/${CHOST:-$_chost}/$pkgver
	mkdir -p "$subpkgdir/$libexec" \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/include \
		"$subpkgdir"/usr/lib \

	mv "$pkgdir/$libexec/cc1plus" "$subpkgdir/$libexec/"
	mv "$pkgdir"/usr/lib/*++* "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/include/c++ "$subpkgdir"/usr/include/
	mv "$pkgdir"/usr/bin/*++ "$subpkgdir"/usr/bin/
}

libobjc() {
	pkgdesc="GNU ObjectiveC library"
	replaces="objc"
	mkdir -p "$subpkgdir"/usr/lib

	mv "$pkgdir"/usr/lib/*objc* "$subpkgdir"/usr/lib/
}

libgcc() {
	pkgdesc="GNU C compiler runtime libraries"
	depends=
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgcc_s.so.* "$subpkgdir"/usr/lib/
}

libgomp() {
	pkgdesc="GCC shared-memory parallel programming API library"
	depends=
	replaces="gcc"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgomp.so.* "$subpkgdir"/usr/lib/
}

java() {
	pkgdesc="Java support for GCC"
	paxctl -c -p -e -m "$pkgdir"/usr/libexec/gcc/*/*/ecj1 || return 1
	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/lib
	cd "$pkgdir"/usr/bin
	mv gcj gcj-dbtool gjavah gcjh jcf-dump "$subpkgdir"/usr/bin/
	cd "$pkgdir"
	for i in $(find usr/ -name ecj1 -o -name jc1 -o -name jvgenmain); do
		mkdir -p "$subpkgdir"/${i%/*}
		mv "$pkgdir"/$i "$subpkgdir"/$i || return 1
	done
	mv \
		"$pkgdir"/usr/lib/libgcj*.so \
		"$pkgdir"/usr/lib/libgij.so \
		"$pkgdir"/usr/lib/libgcj.spec \
		"$subpkgdir"/usr/lib/
}

libgcj() {
	pkgdesc="Java runtime library for gcc"
	mkdir -p "$subpkgdir"/usr/bin
	cd "$pkgdir"/usr/bin
	paxctl -c -m "$pkgdir"/usr/bin/gij || return 1
	mv aot-compile gappletviewer gc-analyze gij gjar gjarsigner gkeytool\
		gnative2ascii gorbd grmic grmid grmiregistry gserialver \
		gtnameserv i486-alpine-linux-uclibc-gcj jv-convert \
		rebuild-gcj-db \
		"$subpkgdir"/usr/bin/
	cd "$pkgdir"
	for i in $(find usr/lib -name jc1 -o -name jvgenmain); do
		mkdir -p "$subpkgdir"/${i%/*}
		mv "$pkgdir"/$i "$subpkgdir"/$i || return 1
	done
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/gcj-* \
		"$pkgdir"/usr/lib/libgcj*.so.* \
		"$pkgdir"/usr/lib/libgij.so.* \
		"$pkgdir"/usr/lib/logging.properties \
		"$pkgdir"/usr/lib/security \
		"$subpkgdir"/usr/lib/

	mkdir -p "$subpkgdir"/usr/share/
	mv "$pkgdir"/usr/share/java "$subpkgdir"/usr/share/
}

libgo() {
	pkgdesc="Go runtime library for GCC"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgo.so.* "$subpkgdir"/usr/lib/
}

go() {
	pkgdesc="Go support for GCC"
	depends="libgo"
	local libexec=usr/libexec/gcc/${CHOST:-$_chost}/$pkgver
	mkdir -p "$subpkgdir"/$libexec \
		"$subpkgdir"/usr/lib \
		"$subpkgdir"/usr/bin || return 1
	mv "$pkgdir"/usr/lib/go "$subpkgdir"/usr/lib/ || return 1
	mv "$pkgdir"/usr/bin/*gccgo "$subpkgdir"/usr/bin/ || return 1
	mv "$pkgdir"/$libexec/go1 "$subpkgdir"/$libexec/ || return 1
	mv "$pkgdir"/usr/lib/libgo.a \
		"$pkgdir"/usr/lib/libgo.so \
		"$pkgdir"/usr/lib/libgobegin.a \
		"$subpkgdir"/usr/lib/ || return 1
}

md5sums="780f614ab18c7a9066dec6387d7490b2  gcc-core-4.6.2.tar.bz2
87ecd60431e41096419dd8a10f76e46b  gcc-g++-4.6.2.tar.bz2
94043cc0d08394eddebed73f30ecad89  gcc-objc-4.6.2.tar.bz2
52de580642d7092b7b2790d9a81ab7a6  gcc-java-4.6.2.tar.bz2
0b7bdd9bd3096075f035fa9def33c314  gcc-go-4.6.2.tar.bz2
5dc7efd84b526801b94fed21462aea62  gcc-4.6.1-piepatches-v0.4.5.tar.bz2
441c76504e1d97170117c294e65c7a72  gcc-4.4.3-specs-0.2.0.tar.bz2
d7cd6a27c8801e66cbaa964a039ecfdb  ecj-latest.jar
b1b5987e7c53f2c8a0fa929444bd9129  08_all_cross-compile.patch
34e4a0260e9dbd434ac84b9dda381240  11_all_default-warn-format-security.patch
a78022925c0ecb1f13384238b81adbe7  12_all_default-warn-trampolines.patch
6862cb5268fef68a4a1906e0c4ea0d46  15_all_libgomp-Werror.patch
1a8ce6b7a0b9a115e37fdda311704451  34_all_ia64_note.GNU-stack.patch
d8692c56f04b92667096f59d843e95c5  51_all_libiberty-pic.patch
656565d2e2c30ea12a398ef6959a9391  74_all_gcc46_cloog-dl.patch
a695d7648509b4f8e18b389a19e6037c  gcc-spec-env.patch
2db1e3482c5dd59dab70f701afa2ca80  pt_gnu_eh_frame.patch
6cc2385c5bbd6d0da6eaedd53c8bf547  uclibc-getipinfo.patch
3be85df859fa1d5c875bbfcc2dee8288  gcc-4.6-dynamic-linker.patch
32e8e4c0e23ed8f5de95a591cb30f1da  gcc-4.6-pr32219.patch
2c6cb49bb9bfd8b6e690222e66ccc901  boehem-gc-uclibc.patch
d1d3ad2b0c185b5548125a1b81bee154  gcc-pure64.patch
c94014ece84407a36d239417a2bad25d  gcc-go.patch
978e3fac97ad99902a86bafc6f283727  gcc-libgcc-x86.get_pc_thunk.bx.patch"