aboutsummaryrefslogtreecommitdiffstats
path: root/community/ghc/APKBUILD
blob: 95062358f57559cc23c89f042c92a57f4eeb4a6e (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
# Maintainer: Mitch Tishmack <mitch.tishmack@gmail.com>
pkgname=ghc
pkgver=8.4.3
pkgrel=0
# Normal non rc candidate
_urlprefix="$pkgver"
_pkgprefix="$pkgname-$pkgver"
pkgdesc="The Glasgow Haskell Compiler"
# Next 5 variables only needed for release candidate testing
#pkgrcver=8.2.2
#pkgrc=rc3
#pkgdate=20171108
#urlprefix="$pkgrcver-$pkgrc"
#pkgprefix="ghc-$pkgver.$pkgdate"
url="http://haskell.org"
arch="x86_64"
# Note ghc's license is basically BSD-3. If you'd like to know more visit:
# * https://www.haskell.org/ghc/license
# * https://ghc.haskell.org/trac/ghc/wiki/Licensing
license="BSD-3-Clause"
# Note that ghc is sensitive to the version of llvm used,
# hence the llvm5 dependency.
#
# Ref: https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1
#      https://ghc.haskell.org/trac/ghc/wiki/ImprovedLLVMBackend
depends="gmp-dev perl gcc>=6.2.1 llvm5 libffi-dev"
# ghc is self-hosted, so we need ghc to build ghc. ghc-bootstrap is provided by
# this aport (see below).
makedepends_build="$pkgname-bootstrap
	autoconf cpio binutils binutils-gold paxmark libffi-dev ncurses-dev xz coreutils"
makedepends_host="linux-headers musl-dev zlib-dev gmp-dev binutils-dev libffi-dev ncurses-dev cpio" # need GNU cpio
makedepends="$makedepends_build $makedepends_host"
checkdepends="python3"
# XXX: ghc-bootstrap is a hack to allow this abuild to depend on itself.
# Adding "ghc" to makedepends would not work, because abuild implicitly removes
# $pkgname and $subpackages from the abuild's dependencies.
provides="$pkgname-bootstrap=$pkgver-r$pkgrel"
subpackages="$pkgname-doc $pkgname-dev"
install="$pkgname.post-install"
options="!strip"  # we strip it manually in build()
source="https://downloads.haskell.org/~ghc/$_urlprefix/$_pkgprefix-src.tar.xz
        https://downloads.haskell.org/~ghc/$_urlprefix/$_pkgprefix-testsuite.tar.xz
        0005-buildpath-abi-stability.patch
        "

# We only need the bootstrap patch when bootstrapping a new arches ghc.
if [ "$CBUILD" != "$CTARGET" ]; then
	source="$source 0000-bootstrap.patch"
fi

builddir="$srcdir/$_pkgprefix"

prepare() {
	default_prepare

	cp mk/build.mk.sample mk/build.mk

	cat >> mk/build.mk <<-EOF
		BuildFlavour         = perf-llvm
		INTEGER_LIBRARY      = integer-gmp
		BeConservative       = YES
		GhcStage3HcOpts     += -O3
		SplitSections        = YES
	EOF

	if [ "$CBUILD" != "$CTARGET" ]; then
		# cross-build
		cat >> mk/build.mk <<-EOF
			HADDOCK_DOCS         = NO
			BUILD_SPHINX_HTML    = NO
			BUILD_SPHINX_PS      = NO
			BUILD_SPHINX_PDF     = NO
		EOF
	fi

	# Due to patches to the configure script
	autoreconf
}

build() {
	cd "$builddir"

	local ffi_inc=$(pkg-config libffi --cflags-only-I); ffi_inc="${ffi_inc%% }"
	local ffi_lib=$(pkg-config libffi --libs-only-L); ffi_lib="${ffi_lib%% }"

	GHCLD=${CROSS_COMPILE}ld.gold

	# NOTE: ghc build system requires host == build, and it ends up
	# compiling the cross-compiler (stage1) and cross-compiling with
	# that the native compiler (stage2)
	./configure \
		--build=$CBUILD \
		--host=$CBUILD \
		--target=$CTARGET \
		--prefix=/usr \
		--with-system-libffi \
		${ffi_inc:+--with-ffi-includes="${ffi_inc#-I}"} \
		${ffi_lib:+--with-ffi-libraries="${ffi_lib#-L}"} \
		--with-ar=${CROSS_COMPILE}ar \
		--with-nm=${CROSS_COMPILE}nm \
		--with-ranlib=${CROSS_COMPILE}ranlib \
		--with-objdump=${CROSS_COMPILE}objdump \
		--disable-ld-override \
		CONF_CPP_OPTS_STAGE0=" $ffi_inc $ffi_lib " \
		CONF_CC_OPTS_STAGE0=" $ffi_inc $ffi_lib " \
		LD=$GHCLD

	# Switch llvm-targets from unknown-linux-gnueabihf->alpine-linux
	# so we can match the llvm vendor string alpine uses
	sed -i -e 's/unknown-linux-gnueabihf/alpine-linux/g' llvm-targets
	sed -i -e 's/unknown-linux-gnueabi/alpine-linux/g' llvm-targets
	sed -i -e 's/unknown-linux-gnu/alpine-linux/g' llvm-targets

	make
}

check() {
	cd "$builddir/testsuite"
	make fast THREADS=$JOBS
}

doc() {
	default_doc
	install -Dm644 "$builddir/LICENSE" \
		"$subpkgdir/usr/share/licenses/$subpkgname/LICENSE"
}

package() {
	local ghclib="usr/lib/ghc-$pkgver"
	local newpath path target

	cd "$builddir"
	make -j1 DESTDIR="$pkgdir" install

	cd "$pkgdir"

	# Fixup install tree if needed.
	if [ -d usr/lib/$CTARGET-ghc-$pkgver ]; then
		# different location
		ghclib="usr/lib/$CTARGET-ghc-$pkgver"

		# Rename binaries and fix links.
		local path; for path in usr/bin/"$CTARGET"-*; do
			newpath="${path//$CTARGET-/}"

			if [ -h "$path" ]; then
				target="$(readlink $path)"
				ln -sf "${target//$CTARGET-/}" "$newpath"
				rm "$path"
			else
				mv "$path" "$newpath"
			fi
		done

		# Remove triplet prefix from settings -- the intention is
		# that the native compiler will use native gcc/ld on the target.
		sed -i "s|$CTARGET-||g" usr/lib/$CTARGET-ghc-$pkgver/settings
	fi

	# Can't do a full strip on archives.
	find . -type f \( -name "*.so" -o -name "*.a" \) \
		-exec ${CROSS_COMPILE}strip --strip-unneeded {} \;
	find $ghclib/bin -type f -exec ${CROSS_COMPILE}strip {} \;

	paxmark -m \
		$ghclib/bin/ghc \
		$ghclib/bin/ghc-iserv \
		$ghclib/bin/ghc-iserv-dyn \
		$ghclib/bin/ghc-iserv-prof
}

# Like debian, we split apart the profiled archives/etc...
# This drastically reduces the install size of the ghc pkg.
dev() {
	pkgdesc="$pkgdesc (development files)"
	depends="$pkgname=$pkgver-r$pkgrel"

	cd "$pkgdir"

	install -dm755 "$subpkgdir"

	local pfiles=$(find . \( -type f -o -type l \) \( -name "*.p_*" -o -name "lib*_p.a" \))
	echo "$pfiles" | cpio -pamVd "$subpkgdir"
	echo "$pfiles" | xargs rm -fr
}
sha512sums="c6cea84264f32ae888f9931f834a1d721889242f656d14262e787ec54a1793d1862ce76daacaf1006c12b8af12919501afce1dc02571373e24830e4d51803414  ghc-8.4.3-src.tar.xz
8a6d1016ae7166c0932973a22e8bfa02e4edab2374ea4dbcc7c9315245bc2df72f8faab2e1e15220c0eeeeeee89549deb1b3ae6bb56899b208345ef02f53aa16  ghc-8.4.3-testsuite.tar.xz
e1c2cef06d307eda4b35521204e95eb54ace5dbcd22de659e95356f884b4424d6304365e4ab45c5116192cba4c095e2e91114bc7cb73d7c7173a7035287d0854  0005-buildpath-abi-stability.patch"