Update lang/ghc to version 8.6.3_1
[dports.git] / lang / ghc / Makefile
1 # Created by: Simon Marlow <simonmar@microsoft.com>
2 # $FreeBSD$
3
4 PORTNAME=       ghc
5 PORTVERSION=    ${GHC_VERSION}
6 PORTREVISION=   1
7 CATEGORIES=     lang haskell
8 MASTER_SITES=   https://www.haskell.org/ghc/dist/${PORTVERSION}/:source \
9                 http://leaf.dragonflybsd.org/~marino/dports-src/:dflyboot \
10                 LOCAL/arrowd/:boot \
11                 https://hackage.haskell.org/package/hscolour-${HSCOLOUR_VERSION}/:docs
12 DISTFILES=      ghc-${PORTVERSION}-src${EXTRACT_SUFX}:source \
13                 hscolour-${HSCOLOUR_VERSION}.tar.gz:docs
14 EXTRACT_ONLY=   ${_DISTFILES:C/hscolour.*$//g}
15
16 MAINTAINER=     haskell@FreeBSD.org
17 COMMENT=        Compiler for the functional language Haskell
18
19 LICENSE=        BSD3CLAUSE
20 LICENSE_FILE=   ${WRKSRC}/LICENSE
21
22 # other supported arches are added based on GHC_VERSION below
23 ONLY_FOR_ARCHS= amd64 i386
24
25 USES=                   autoreconf gmake iconv:translit localbase:ldflags ncurses perl5 tar:xz
26 USE_LOCALE=             en_US.UTF-8
27 USE_PERL5=              build
28 GNU_CONFIGURE=          yes
29 CONFIGURE_ARGS=         --with-iconv-includes=${LOCALBASE}/include \
30                         --with-iconv-libraries=${LOCALBASE}/lib
31 CONFIGURE_ENV=          CC=${CC} LD=${LD} PATH=${SLAVES_PREFIX}/bin:${PATH}
32 MAKE_ENV=               PATH=${SLAVES_PREFIX}/bin:${PATH}
33 # Turn off for a while, see PR 228727
34 CONFIGURE_ARGS+=        --enable-dtrace=0
35
36 SUB_FILES=              build.mk
37 SUB_LIST=               GHC_VERSION=${GHC_VERSION} \
38                         NCURSESINC="${NCURSESBASE}/include" NCURSESLIB="${NCURSESLIB}" \
39                         CFLAGS="${CFLAGS}"
40
41 OPTIONS_GROUP=          BOOTSTRAP
42 BOOTSTRAP_DESC=         Bootsrap using installed ghc
43 OPTIONS_GROUP_BOOTSTRAP=BOOT
44 OPTIONS_DEFINE=         DYNAMIC GMP PROFILE DOCS
45 OPTIONS_SUB=            yes
46
47 OPTIONS_DEFAULT=        DYNAMIC PROFILE GMP
48
49 BOOT_DESC=              Use installed GHC for bootstrapping
50 DOCS_DESC=              Install HTML documentation
51 DYNAMIC_DESC=           Add support for dynamic linking
52 GMP_DESC=               Use GNU Multi-precision Library for big integers support
53 PROFILE_DESC=           Add support for performance profiling
54
55 DOCS_BUILD_DEPENDS+=    sphinx-build:textproc/py-sphinx
56 DOCS_SUB_LIST=          WITH_DOCS="YES"
57 DOCS_SUB_LIST_OFF=      WITH_DOCS="NO"
58
59 DYNAMIC_CONFIGURE_WITH= system-libffi \
60                         ffi-includes=${LOCALBASE}/include \
61                         ffi-libraries=${LOCALBASE}/lib
62 # The version number is needed as lang/gcc installs a different version
63 DYNAMIC_LIB_DEPENDS=    libffi.so.6:devel/libffi
64 DYNAMIC_SUB_LIST=       WITH_DYNAMIC="YES"
65 DYNAMIC_SUB_LIST_OFF=   WITH_DYNAMIC="NO"
66
67 GMP_CONFIGURE_WITH=     gmp-includes=${LOCALBASE}/include \
68                         gmp-libraries=${LOCALBASE}/lib
69 GMP_LIB_DEPENDS=        libgmp.so:math/gmp
70 GMP_SUB_LIST=           INTEGER_LIBRARY="integer-gmp"
71 GMP_SUB_LIST_OFF=       INTEGER_LIBRARY="integer-simple"
72
73 # Append substitutions for build.mk
74 BOOT_SUB_LIST=          HSC2HS=${LOCALBASE}/bin/hsc2hs
75 BOOT_SUB_LIST_OFF=      HSC2HS=${BOOT_HSC2HS}
76
77 PROFILE_SUB_LIST=       WITH_PROFILE="YES"
78 PROFILE_SUB_LIST_OFF=   WITH_PROFILE="NO"
79
80 GHC_VERSION?=           ${GHC_VERSION_DEFAULT}
81 GHC_VERSION_DEFAULT=    8.6.3
82 GHC_VERSION_MAJOR=      ${GHC_VERSION:S/./ /g:[1]}
83 GHC_VERSION_MINOR=      ${GHC_VERSION:S/./ /g:[2]}
84
85 HSCOLOUR_VERSION=       1.24.4
86
87 .if ${GHC_VERSION_MAJOR} >= 8 && ${GHC_VERSION_MINOR} >= 6
88 ONLY_FOR_ARCHS+=        aarch64 armv6 armv7 powerpc64
89 .endif
90
91 .include <bsd.port.pre.mk>
92
93 .if ${GHC_VERSION_MAJOR} == 8 && ${GHC_VERSION_MINOR} <= 4
94 LLVM_VERSION=           50
95 .else
96 LLVM_VERSION=           60
97 .endif
98
99 .if ${ARCH} == x86_64 || ${ARCH} == i386
100 BOOT_GHC_VERSION=       8.4.3
101 .else
102 BOOT_GHC_VERSION=       8.6.3
103 .endif
104
105 # LLVM version that bootstrap compiler uses
106 BOOT_LLVM_VERSION=      60
107
108 .if "${GHC_VERSION}" != "${GHC_VERSION_DEFAULT}"
109 PATCHDIR=       ${.CURDIR}/files${GHC_VERSION:S/.//g}/
110 .endif
111
112 NO_CCACHE=      ccache: error: Failed to create directory /nonexistent/.ccache/tmp: Permission denied
113
114 DOCSDIR=                ${PREFIX}/share/doc/${DISTNAME}
115 DATADIR=                ${PREFIX}/share/ghc-${GHC_VERSION}
116 EXAMPLESDIR=            ${PREFIX}/share/examples/ghc-${GHC_VERSION}
117 GHC_ARCH=               ${ARCH:S/amd64/x86_64/:C/armv.*/arm/}
118 GHC_LIBDIR=             ${STAGEDIR}${PREFIX}/lib/ghc-${GHC_VERSION}
119 GHC_LIBDIR_REL=         lib/ghc-${GHC_VERSION}
120
121 _EXECUTABLES=   ${GHC_LIBDIR}/bin/unlit \
122                 ${GHC_LIBDIR}/bin/hpc \
123                 ${GHC_LIBDIR}/bin/ghc-iserv \
124                 ${GHC_LIBDIR}/bin/ghc-pkg \
125                 ${GHC_LIBDIR}/bin/hsc2hs \
126                 ${GHC_LIBDIR}/bin/runghc \
127                 ${GHC_LIBDIR}/bin/ghc \
128                 ${GHC_LIBDIR}/bin/hp2ps \
129                 ${GHC_LIBDIR}/bin/haddock
130
131 .if ${PORT_OPTIONS:MPROFILE}
132 _EXECUTABLES+=  ${GHC_LIBDIR}/bin/ghc-iserv-prof
133 .endif
134 .if ${PORT_OPTIONS:MDYNAMIC}
135 _EXECUTABLES+=  ${GHC_LIBDIR}/bin/ghc-iserv-dyn
136 .endif
137
138 .include <bsd.port.options.mk>
139
140 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "FreeBSD"
141
142 DISTFILES+=             ghc-${BOOT_GHC_VERSION}-boot-${ARCH}-freebsd${EXTRACT_SUFX}:boot
143 .endif # MBOOT
144
145 .if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7
146 # CONFIGURE_TARGET must to be the same as the llvm triple
147 CONFIGURE_TARGET=       ${ARCH}-unknown-freebsd${"${ARCH:Maarch64}" != "":?:-gnueabihf}
148 EXTRA_PATCHES+=         ${PATCHDIR}/extra-patch-aclocal.m4
149 BUILD_DEPENDS+=         ld.gold:devel/binutils \
150                         llc${LLVM_VERSION}:devel/llvm${LLVM_VERSION}
151 RUN_DEPENDS+=           ld.gold:devel/binutils \
152                         llc${LLVM_VERSION}:devel/llvm${LLVM_VERSION}
153 USE_GCC=                yes
154
155 # When GHC being compiled and GHC used for bootstrapping support different
156 # LLVM versions, we have to pull in both. Luckily, this is relatively rare.
157 .  if ${BOOT_LLVM_VERSION} != ${LLVM_VERSION}
158 BUILD_DEPENDS+=         llc${BOOT_LLVM_VERSION}:devel/llvm${BOOT_LLVM_VERSION}
159 RUN_DEPENDS+=           llc${BOOT_LLVM_VERSION}:devel/llvm${BOOT_LLVM_VERSION}
160 .  endif
161
162 .  if ${OSVERSION} < 1200064
163 IGNORE= lang/ghc on ARM requires at least __FreeBSD_version 1200064
164 .  endif
165
166 .  ifdef QEMU_EMULATING
167 IGNORE= qemu-user-static isn't able to build lang/ghc, but it builds fine on a real hardware
168 .  endif
169 .endif
170
171 .if ${ARCH} == powerpc64
172 USE_GCC=        yes
173
174 .  if ${OSVERSION} < 1200086
175 IGNORE= lang/ghc on powerpc64 requires at least __FreeBSD_version 1200086
176 .  endif
177 .endif
178
179 # Use binutils strip if we are using gcc, as it is faster that base one. See PR 234949
180 .if defined(USE_GCC)
181 CONFIGURE_ENV+= STRIP=${LOCALBASE}/bin/strip
182 .endif
183
184 PLIST_SUB+=     GHC_VERSION=${GHC_VERSION} GHC_LIBDIR=${GHC_LIBDIR_REL}
185
186 .if empty(PORT_OPTIONS:MBOOT)
187 BOOT_DIR=       ${WRKDIR}/ghc-${BOOT_GHC_VERSION}-boot
188 BOOT_GHC=       ${BOOT_DIR}/bin/ghc-${BOOT_GHC_VERSION}
189 BOOT_GHC-PKG=   ${BOOT_DIR}/bin/ghc-pkg-${BOOT_GHC_VERSION}
190 BOOT_HSC2HS=    ${BOOT_DIR}/bin/hsc2hs
191
192 SLAVE_ENV=      ${SETENV} PATH=${BOOT_DIR}/bin:${PATH}
193
194 CONFIGURE_ARGS+=        --with-ghc=${BOOT_GHC}
195 .else # MBOOT
196 SLAVE_ENV=              # empty
197 CONFIGURE_ARGS+=        --with-ghc=${LOCALBASE}/bin/ghc
198 .endif # MBOOT
199
200 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "DragonFly"
201 BOOT_GHC_VERSION=       8.4.4
202 DISTFILES+=             ghc-${BOOT_GHC_VERSION}-boot-${ARCH}-dragonfly.tar.xz:dflyboot
203 CONFIGURE_TARGET=       ${ARCH}-portbld-dragonfly
204 CONFIGURE_ENV+=         BOOTDIR=${BOOT_DIR} LBASE=${LOCALBASE}
205
206 # avoid "sed: RE error: Illegal byte sequence" in bootstrap configure script, smth fishy
207 BUILD_DEPENDS+=         gsed:textproc/gsed
208 dfly-patch:
209         ${REINPLACE_CMD} -e 's@sed@gsed@g' \
210                 ${BOOT_DIR}/configure
211 .endif
212
213 # override TMPDIR because /tmp often doesn't have enough space
214 # to build some of the larger libraries.
215 #TMPDIR=                ${WRKSRC}/tmp
216
217 SLAVES_PREFIX=          ${WRKDIR}/slaves_prefix
218 SLAVES_WRKDIRPREFIX=    ${WRKDIR}/slaves_wrkdirprefix
219
220 post-extract:
221 # Use the "wrap" trick on arches that have to use pre-ino64 bootstrap binaries
222 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031 && \
223     (${ARCH} == x86_64 || ${ARCH} == i386)
224         @${REINPLACE_CMD} -e 's|@SettingsCCompilerLinkFlags@|& -Wl,--wrap=readdir_r,--wrap=stat,--wrap=lstat,--wrap=fstat,--wrap=mknod|' ${BOOT_DIR}/settings.in
225 .endif
226
227 # %%PORTDOCS%%%%DOCSDIR%%/html/libraries/doc-index-V.html
228 post-install-script:
229         ${FIND} -ds ${GHC_LIBDIR} -type f -print | ${SED} -E \
230                 -e 's,^${STAGEDIR}${PREFIX}/?,,' \
231                 -e '/^${GHC_LIBDIR:C/\//\\\//g}\/package.conf.d\/package\.cache/s|^|@comment |g' \
232                 >> ${TMPPLIST}
233         ${FIND} -ds ${STAGEDIR}${DOCSDIR} -type f -print | ${SED} -E \
234                 -e 's,^${STAGEDIR}${PREFIX}/?,,' \
235                 -e '/^${STAGEDIR:C/\//\\\//g}${DOCSDIR:C/\//\\\//g}\/html\/libraries\/doc-index-[^.]+\.html/s|^|@comment |g' \
236                 -e '/^${STAGEDIR:C/\//\\\//g}${DOCSDIR:C/\//\\\//g}\/html\/libraries\/index[^\/.]*\.html/s|^|@comment|g' \
237                 -e '/^${STAGEDIR:C/\//\\\//g}${DOCSDIR:C/\//\\\//g}\/html\/libraries\/[^\/]+\.png/s|^|@comment |g' \
238                 >> ${TMPPLIST}
239 .if ${PORT_OPTIONS:MDOCS}
240         # Cleanup the indexen created by gen_contents_index
241         ${ECHO} "@postunexec ${RM} %D/${DOCSDIR_REL}/html/libraries/doc-index-*.html" >> ${TMPPLIST}
242         ${ECHO} "@postunexec ${RM} %D/${DOCSDIR_REL}/html/libraries/index*.html" >> ${TMPPLIST}
243         ${ECHO} "@postunexec ${RM} %D/${DOCSDIR_REL}/html/libraries/*.png" >> ${TMPPLIST}
244 .endif
245         ${ECHO} '@postunexec ${RM} %D/${GHC_LIBDIR_REL}/package.conf.d/package.cache' >>${TMPPLIST}
246
247 post-patch:
248         @${REINPLACE_CMD} -e 's|%%CC%%|${CC}|; \
249                 s|%%AR%%|${AR}|; \
250                 s|%%LD%%|${LD}|' \
251                 ${WRKSRC}/libraries/Cabal/Cabal/Distribution/Simple/Program/Builtin.hs
252 # we must use binutils:ld on arm
253 .if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7
254         @${REINPLACE_CMD} -e 's|LD_NO_GOLD=ld|LD_NO_GOLD=${LOCALBASE}/bin/ld|' \
255                 ${WRKSRC}/aclocal.m4
256 .endif
257
258         @${REINPLACE_CMD} -e 's/@SettingsLlcCommand@/llc${LLVM_VERSION}/' ${WRKSRC}/settings.in
259         @${REINPLACE_CMD} -e 's/@SettingsOptCommand@/opt${LLVM_VERSION}/' ${WRKSRC}/settings.in
260
261 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "FreeBSD"
262         @${REINPLACE_CMD} -e '/^mandir/d' ${BOOT_DIR}/mk/build.mk
263         @${REINPLACE_CMD} -e '/^infodir/d' ${BOOT_DIR}/mk/build.mk
264         @${REINPLACE_CMD} -e '/^docdir/d' ${BOOT_DIR}/mk/build.mk
265         @${REINPLACE_CMD} -e '/^htmldir/d' ${BOOT_DIR}/mk/build.mk
266 .endif
267
268 pre-configure: apply-slist
269         # Copy the subbed build.mk to the proper position
270         ${CP} ${WRKDIR}/build.mk ${WRKSRC}/mk/build.mk
271
272 # Use the "wrap" trick on arches that have to use pre-ino64 bootstrap binaries
273 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == FreeBSD && \
274     ${OSVERSION} >= 1200031 && \
275     (${ARCH} == x86_64 || ${ARCH} == i386)
276         ${CC} ${CFLAGS} -c -o ${BOOT_DIR}/wrap.o ${PATCHDIR}/wrap.c
277         for x in ${BOOT_DIR}/rts/dist/build/libCffi*.a; do \
278             ${AR} q $$x ${BOOT_DIR}/wrap.o; ${RANLIB} $$x; \
279         done
280         ${RM} ${BOOT_DIR}/wrap.o
281 .endif
282 # If we are using bootstrap compiler, configure and install it into ${BOOT_DIR}
283 .if empty(PORT_OPTIONS:MBOOT)
284         cd ${BOOT_DIR} && ${CONFIGURE_ENV} ${CONFIGURE_CMD} --prefix=${BOOT_DIR}
285         cd ${BOOT_DIR} && PACKAGES='' ${MAKE_CMD} install
286 .endif
287 # If DOCS are set, install HsColour in-place
288 .if ${PORT_OPTIONS:MDOCS}
289         ${MKDIR} ${SLAVES_PREFIX}
290         ${MKDIR} ${SLAVES_WRKDIRPREFIX}
291
292         cd ${SLAVES_WRKDIRPREFIX} && \
293                 ${TAR} xvf ${DISTDIR}/hscolour-${HSCOLOUR_VERSION}.tar.gz && \
294                 cd hscolour-${HSCOLOUR_VERSION} && \
295                 ${SLAVE_ENV} ghc --make -o Setup Setup.hs -package Cabal && \
296                 ${SLAVE_ENV} ./Setup configure --ghc --prefix=${SLAVES_PREFIX} --with-gcc=${CC} --with-ld=${LD} && \
297                 ${SLAVE_ENV} ./Setup build && \
298                 ${SLAVE_ENV} ./Setup install
299 .endif
300
301 post-install:
302         (for f in ${_EXECUTABLES} $$(${FIND} ${GHC_LIBDIR} -name '*.so*'); do \
303                 ${STRIP_CMD} $$f; done)
304 .if ${PORT_OPTIONS:MDOCS}
305         ${MV} ${STAGEDIR}${PREFIX}/bin/haddock ${STAGEDIR}${PREFIX}/bin/haddock-ghc-${GHC_VERSION}
306 .endif
307
308 # Create a bootstrap compiler tar ball: run this in an interactive poudriere jail
309 .PHONY: create-bootstrap
310 create-bootstrap:
311         cd ${WRKSRC} \
312                 && ${ECHO} "BIN_DIST_NAME=ghc-${GHC_VERSION}-boot" >> mk/build.mk \
313                 && ${ECHO} "BIN_DIST_TAR=ghc-${GHC_VERSION}-boot.tar" >> mk/build.mk \
314                 && ${GMAKE} binary-dist TAR_COMP=xz \
315                 && ${MV} ${WRKSRC}/ghc-${GHC_VERSION}-boot-${GHC_ARCH}-portbld-freebsd.tar.xz /tmp/ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz
316
317         cd /tmp \
318                 && sha256 ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz \
319                 && ${ECHO} -n "SIZE (ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz) = " \
320                 && ${STAT} -f %z ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz
321
322 # Much like create-bootstrap, just different naming and output format
323 .PHONY: create-stack-bindist
324 create-stack-bindist:
325         ${REINPLACE_CMD} -e '/^mandir/d' \
326                         -e '/^infodir/d' \
327                         -e '/^docdir/d' \
328                         -e '/^htmldir/d' \
329                 ${WRKSRC}/mk/build.mk
330
331         cd ${WRKSRC} \
332                 && ${GMAKE} binary-dist TAR_COMP=xz \
333                 && ${MV} ${WRKSRC}/ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz /tmp/
334
335         cd /tmp \
336                 && ${ECHO} "${GHC_VERSION}:" \
337                 && ${ECHO} "url: \"http://distcache.FreeBSD.org/local-distfiles/arrowd/stack-bindists/ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz\"" \
338                 && ${ECHO} -n "content-length: " \
339                 && ${STAT} -f %z ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz \
340                 && ${ECHO} -n "sha1: " \
341                 && sha1 -q ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz \
342                 && ${ECHO} -n "sha256: " \
343                 && sha256 -q ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz
344
345 .include <bsd.port.post.mk>