Update lang/ghc to version 8.10.4_1
[dports.git] / lang / ghc / Makefile
1 # Created by: Simon Marlow <simonmar@microsoft.com>
2
3 PORTNAME=       ghc
4 PORTVERSION=    ${GHC_VERSION}
5 PORTREVISION=   1
6 CATEGORIES=     lang haskell
7 MASTER_SITES=   https://www.haskell.org/ghc/dist/${PORTVERSION}/:source \
8                 http://leaf.dragonflybsd.org/~marino/dports-src/:dflyboot \
9                 LOCAL/arrowd/:boot \
10                 https://hackage.haskell.org/package/hscolour-${HSCOLOUR_VERSION}/:docs
11 DISTFILES=      ghc-${PORTVERSION}-src${EXTRACT_SUFX}:source \
12                 hscolour-${HSCOLOUR_VERSION}.tar.gz:docs
13 EXTRACT_ONLY=   ${_DISTFILES:C/hscolour.*$//g}
14
15 MAINTAINER=     haskell@FreeBSD.org
16 COMMENT=        Compiler for the functional language Haskell
17
18 LICENSE=        BSD3CLAUSE
19 LICENSE_FILE=   ${WRKSRC}/LICENSE
20
21 ONLY_FOR_ARCHS= amd64 i386 aarch64 armv6 armv7 powerpc64
22
23 USES=                   autoreconf compiler:c11 gmake iconv:translit \
24                         localbase:ldflags ncurses perl5 tar:xz
25 USE_LOCALE=             en_US.UTF-8
26 USE_PERL5=              build
27 GNU_CONFIGURE=          yes
28 CONFIGURE_ARGS=         --with-iconv-includes=${LOCALBASE}/include \
29                         --with-iconv-libraries=${LOCALBASE}/lib
30 CONFIGURE_ENV=          CC=${CC} LD=${LD} PATH=${SLAVES_PREFIX}/bin:${PATH}
31 MAKE_ENV=               PATH=${SLAVES_PREFIX}/bin:${PATH}
32
33 SUB_FILES=              build.mk
34 SUB_LIST=               GHC_VERSION=${GHC_VERSION} \
35                         NCURSESINC="${NCURSESBASE}/include" NCURSESLIB="${NCURSESLIB}" \
36                         CFLAGS="${CFLAGS}"
37
38 OPTIONS_GROUP=          BOOTSTRAP
39 BOOTSTRAP_DESC=         Bootsrap using installed ghc
40 OPTIONS_GROUP_BOOTSTRAP=BOOT
41 OPTIONS_DEFINE=         DYNAMIC GMP PROFILE DOCS
42 OPTIONS_SUB=            yes
43
44 OPTIONS_DEFAULT=        DYNAMIC PROFILE GMP
45
46 BOOT_DESC=              Use installed GHC for bootstrapping
47 DOCS_DESC=              Install HTML documentation
48 DYNAMIC_DESC=           Add support for dynamic linking
49 GMP_DESC=               Use GNU Multi-precision Library for big integers support
50 PROFILE_DESC=           Add support for performance profiling
51
52 DOCS_BUILD_DEPENDS=     sphinx-build:textproc/py-sphinx
53
54 DYNAMIC_CONFIGURE_WITH= system-libffi \
55                         ffi-includes=${LOCALBASE}/include \
56                         ffi-libraries=${LOCALBASE}/lib
57 DYNAMIC_LIB_DEPENDS=    libffi.so:devel/libffi
58 DYNAMIC_SUB_LIST=       WITH_DYNAMIC="YES"
59 DYNAMIC_SUB_LIST_OFF=   WITH_DYNAMIC="NO"
60 DYNAMIC_PLIST_SUB=      NODYNAMIC="@comment "
61 DYNAMIC_PLIST_SUB_OFF=  NODYNAMIC=""
62
63 GMP_CONFIGURE_WITH=     gmp-includes=${LOCALBASE}/include \
64                         gmp-libraries=${LOCALBASE}/lib
65 GMP_LIB_DEPENDS=        libgmp.so:math/gmp
66 GMP_SUB_LIST=           INTEGER_LIBRARY="integer-gmp"
67 GMP_SUB_LIST_OFF=       INTEGER_LIBRARY="integer-simple"
68 GMP_PLIST_SUB=          GMP="" SIMPLE="@comment "
69 GMP_PLIST_SUB_OFF=      GMP="@comment " SIMPLE=""
70
71 # Append substitutions for build.mk
72 BOOT_SUB_LIST=          HSC2HS=${LOCALBASE}/bin/hsc2hs
73 BOOT_SUB_LIST_OFF=      HSC2HS=${BOOT_HSC2HS}
74
75 PROFILE_SUB_LIST=       WITH_PROFILE="YES"
76 PROFILE_SUB_LIST_OFF=   WITH_PROFILE="NO"
77
78 GHC_VERSION=            8.10.4
79 CABAL_VERSION=          3.2.1.0
80 HSCOLOUR_VERSION=       1.24.4
81 LLVM_VERSION=           90
82 # LLVM version that bootstrap compiler uses
83 BOOT_LLVM_VERSION=      90
84
85 PLIST_SUB=              GHC_VERSION=${GHC_VERSION} CABAL_VERSION=${CABAL_VERSION}
86
87 PORTDOCS=               *
88
89 .include <bsd.port.pre.mk>
90
91 # This version of ncurses is needed by bootstrap compiler
92 .if ${OPSYS} == FreeBSD
93 .if ${OSVERSION} > 1300078 && empty(PORT_OPTIONS:MBOOT) && ${ARCH} != powerpc64
94 BUILD_DEPENDS+= ${LOCALBASE}/lib/compat/libncursesw.so.8:misc/compat12x
95 .endif
96 .endif
97
98 .if ${ARCH} == powerpc64
99 CONFIGURE_ARGS+=        --enable-dtrace=0
100 .endif
101
102 .if defined(PPC_ABI) && ${PPC_ABI} == ELFv1
103 BOOT_GHC_VERSION=      8.6.3
104 .elif ${ARCH} == aarch64 || ${ARCH:Marmv*}
105 BOOT_GHC_VERSION=       8.10.4
106 .else
107 BOOT_GHC_VERSION=       8.6.5
108 .endif
109
110 NO_CCACHE=      ccache: error: Failed to create directory /nonexistent/.ccache/tmp: Permission denied
111
112 DOCSDIR=                ${PREFIX}/share/doc/${DISTNAME}
113 DATADIR=                ${PREFIX}/share/ghc-${GHC_VERSION}
114 EXAMPLESDIR=            ${PREFIX}/share/examples/ghc-${GHC_VERSION}
115 GHC_ARCH=               ${ARCH:S/amd64/x86_64/:C/armv.*/arm/}
116 GHC_LIBDIR=             ${STAGEDIR}${PREFIX}/lib/ghc-${GHC_VERSION}
117 GHC_LIBDIR_REL=         lib/ghc-${GHC_VERSION}
118
119 _EXECUTABLES=   ${GHC_LIBDIR}/bin/unlit \
120                 ${GHC_LIBDIR}/bin/hpc \
121                 ${GHC_LIBDIR}/bin/ghc-iserv \
122                 ${GHC_LIBDIR}/bin/ghc-pkg \
123                 ${GHC_LIBDIR}/bin/hsc2hs \
124                 ${GHC_LIBDIR}/bin/runghc \
125                 ${GHC_LIBDIR}/bin/ghc \
126                 ${GHC_LIBDIR}/bin/haddock \
127                 ${GHC_LIBDIR}/bin/hp2ps
128
129 .if ${PORT_OPTIONS:MPROFILE}
130 _EXECUTABLES+=  ${GHC_LIBDIR}/bin/ghc-iserv-prof
131 .endif
132 .if ${PORT_OPTIONS:MDYNAMIC}
133 _EXECUTABLES+=  ${GHC_LIBDIR}/bin/ghc-iserv-dyn
134 .endif
135
136 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "FreeBSD"
137 BOOTSTRAPS_SUFFIX?=             ${BOOTSTRAPS_SUFFIX_${ARCH}}
138 BOOTSTRAPS_SUFFIX_powerpc64?=   -${PPC_ABI:tl}
139 .  if ${OSVERSION} < 1200000 && (${ARCH} == x86_64 || ${ARCH} == i386)
140 ELEVEN_SUFX=            11
141 .  endif
142 DISTFILES+=             ghc-${BOOT_GHC_VERSION}-boot-${ARCH}-freebsd${BOOTSTRAPS_SUFFIX}${ELEVEN_SUFX}${EXTRACT_SUFX}:boot
143 .endif # MBOOT
144
145 .if ${ARCH} == aarch64 || ${ARCH:Marmv*}
146 # ghc-8.10.x on arm requires devel/llvm90
147 # CONFIGURE_TARGET must to be the same as the llvm triple
148 CONFIGURE_TARGET=       ${ARCH}-unknown-freebsd${"${ARCH:Maarch64}" != "":?:-gnueabihf}
149 EXTRA_PATCHES+=         ${PATCHDIR}/extra-patch-aclocal.m4
150 BUILD_DEPENDS+=         llc${LLVM_VERSION}:devel/llvm${LLVM_VERSION}
151 RUN_DEPENDS+=           llc${LLVM_VERSION}:devel/llvm${LLVM_VERSION}
152 CONFIGURE_ENV+=         LLC=llc${LLVM_VERSION} \
153                         OPT=opt${LLVM_VERSION} \
154                         CLANG=clang${LLVM_VERSION} \
155                         CC=clang${LLVM_VERSION}
156
157 # When GHC being compiled and GHC used for bootstrapping support different
158 # LLVM versions, we have to pull in both. Luckily, this is relatively rare.
159 .  if ${BOOT_LLVM_VERSION} != ${LLVM_VERSION}
160 BUILD_DEPENDS+=         llc${BOOT_LLVM_VERSION}:devel/llvm${BOOT_LLVM_VERSION}
161 # Keep in sync with BOOT_LLVM_VERSION
162 BINARY_ALIAS+=          llc-9.0=llc90 \
163                         opt-9.0=opt90
164 .  endif
165 .endif
166
167 .if ${ARCH} == aarch64 || ${ARCH:Marmv*} || ${ARCH} == powerpc64
168 .  if ${OSVERSION} < 1202000
169 IGNORE= lang/ghc requires at least FreeBSD 12.2-RELEASE
170 .  endif
171 .  ifdef QEMU_EMULATING
172 IGNORE= qemu-user-static isn't able to build lang/ghc, but it builds fine on a real hardware
173 .  endif
174 .endif
175
176 .if empty(PORT_OPTIONS:MBOOT)
177 BOOT_DIR=       ${WRKDIR}/ghc-${BOOT_GHC_VERSION}-boot
178 BOOT_GHC=       ${BOOT_DIR}/bin/ghc-${BOOT_GHC_VERSION}
179 BOOT_GHC-PKG=   ${BOOT_DIR}/bin/ghc-pkg-${BOOT_GHC_VERSION}
180 BOOT_HSC2HS=    ${BOOT_DIR}/bin/hsc2hs
181
182 SLAVE_ENV=      ${SETENV} PATH=${BOOT_DIR}/bin:${PATH}
183
184 CONFIGURE_ARGS+=        GHC=${BOOT_GHC}
185 .else # MBOOT
186 SLAVE_ENV=              # empty
187 CONFIGURE_ARGS+=        GHC=${LOCALBASE}/bin/ghc
188 .endif # MBOOT
189
190 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "DragonFly"
191 BUILD_DEPENDS+=         libtinfow-compat>0:misc/libtinfow-compat
192 BOOT_GHC_VERSION=       8.8.4
193 DISTFILES+=             ghc-${BOOT_GHC_VERSION}-boot-${ARCH}-dragonfly.tar.xz:dflyboot
194 CONFIGURE_TARGET=       ${ARCH}-portbld-dragonfly
195 CONFIGURE_ENV+=         BOOTDIR=${BOOT_DIR} LBASE=${LOCALBASE}
196
197 CONFIGURE_ARGS+=        --target=${CONFIGURE_TARGET}
198 LLVM_VERSION:=  ${LLVM_DEFAULT}
199 # for bootstrap only disable all OPTIONS_DEFAULT except for GMP, previous boots used devel/libffi321
200 .if 0
201 CONFIGURE_ARGS+=        --with-intree-gmp
202 DOCS_BUILD_DEPENDS:=
203 PORT_OPTIONS:=
204 .endif
205
206 # avoid "sed: RE error: Illegal byte sequence" in bootstrap configure script, smth fishy
207 # upstream configure does not support target x86_64-unknown-dragonfly5.9, resed solaris2
208 BUILD_DEPENDS+=         gsed:textproc/gsed
209 dfly-patch:
210         ${REINPLACE_CMD} -e 's@solaris2\*@dragonfly*@g' -e 's@"solaris2"@"dragonfly"@g' \
211                 ${WRKSRC}/configure # this is fragile, but avoid patch-configure diffs...
212         ${REINPLACE_CMD} -e 's@solaris2\*@dragonfly*@g' -e 's@"solaris2"@"dragonfly"@g' \
213                 ${BOOT_DIR}/configure
214 #       ${REINPLACE_CMD} -e 's@[[:<:]]sed[[:>:]]@gsed@g' \
215 #               ${BOOT_DIR}/configure
216 .endif
217
218 SLAVES_PREFIX=          ${WRKDIR}/slaves_prefix
219 SLAVES_WRKDIRPREFIX=    ${WRKDIR}/slaves_wrkdirprefix
220
221 post-patch:
222         @${REINPLACE_CMD} -e 's|%%CC%%|${CC}|; \
223                 s|%%AR%%|${AR}|; \
224                 s|%%LD%%|${LD}|' \
225                 ${WRKSRC}/libraries/Cabal/Cabal/Distribution/Simple/Program/Builtin.hs
226
227 .if empty(PORT_OPTIONS:MBOOT) && ${OPSYS} == "FreeBSD"
228         @${REINPLACE_CMD} -e '/^mandir/d' ${BOOT_DIR}/mk/build.mk
229         @${REINPLACE_CMD} -e '/^infodir/d' ${BOOT_DIR}/mk/build.mk
230         @${REINPLACE_CMD} -e '/^docdir/d' ${BOOT_DIR}/mk/build.mk
231         @${REINPLACE_CMD} -e '/^htmldir/d' ${BOOT_DIR}/mk/build.mk
232 .endif
233
234 .if ${ARCH} == powerpc64 && ${PPC_ABI} == ELFv2
235         @${REINPLACE_CMD} -e 's/ELF_V1/ELF_V2/' \
236                 ${WRKSRC}/configure ${WRKSRC}/aclocal.m4
237 .endif
238
239 pre-configure: apply-slist
240         # Copy the subbed build.mk to the proper position
241         ${CP} ${WRKDIR}/build.mk ${WRKSRC}/mk/build.mk
242
243 # If we are using bootstrap compiler, configure and install it into ${BOOT_DIR}
244 .if empty(PORT_OPTIONS:MBOOT)
245         cd ${BOOT_DIR} && ${CONFIGURE_ENV} ${CONFIGURE_CMD} --prefix=${BOOT_DIR}
246         cd ${BOOT_DIR} && PACKAGES='' ${MAKE_CMD} install
247 .else
248 # otherwise, make sure we have "ghc" in PATH
249         if ! ${WHICH} -s ghc ; then \
250                 echo "No 'ghc' executable is found in your PATH! Turn off BOOT option." ; false ; \
251         fi
252 .endif
253 # If DOCS are set, install HsColour in-place
254 .if ${PORT_OPTIONS:MDOCS}
255         ${MKDIR} ${SLAVES_PREFIX}
256         ${MKDIR} ${SLAVES_WRKDIRPREFIX}
257
258         cd ${SLAVES_WRKDIRPREFIX} && \
259                 ${TAR} xvf ${DISTDIR}/hscolour-${HSCOLOUR_VERSION}.tar.gz && \
260                 cd hscolour-${HSCOLOUR_VERSION} && \
261                 ${SLAVE_ENV} ghc --make -o Setup Setup.hs -package Cabal && \
262                 ${SLAVE_ENV} ./Setup configure --ghc --prefix=${SLAVES_PREFIX} --with-gcc=${CC} --with-ld=${LD} && \
263                 ${SLAVE_ENV} ./Setup build && \
264                 ${SLAVE_ENV} ./Setup install
265 .endif
266
267 post-install:
268         (for f in ${_EXECUTABLES} $$(${FIND} ${GHC_LIBDIR} -name '*.so*'); do \
269                 ${STRIP_CMD} $$f; done)
270         ${RM} -r ${STAGEDIR}${DOCSDIR}/html/haddock/.build-html
271         ${RM} ${STAGEDIR}${PREFIX}/bin/haddock
272
273 .PHONY: fixup-plist
274 fixup-plist:
275         ${BOOT_DIR}/bin/runhaskell ${PATCHDIR}/fixup-plist.hs ${.CURDIR}/pkg-plist
276
277 # Create a bootstrap compiler tar ball: run this in an interactive poudriere jail
278 # Set all OPTIONS to OFF when generating bootstraps
279 .PHONY: create-bootstrap
280 create-bootstrap:
281         cd ${WRKSRC} \
282                 && ${ECHO} "BIN_DIST_NAME=ghc-${GHC_VERSION}-boot" >> mk/build.mk \
283                 && ${ECHO} "BIN_DIST_TAR=ghc-${GHC_VERSION}-boot.tar" >> mk/build.mk \
284                 && ${ECHO} "HADDOCK_DOCS=NO" >> mk/build.mk \
285                 && ${GMAKE} binary-dist TAR_COMP=xz \
286                 && ${MV} ${WRKSRC}/ghc-${GHC_VERSION}-boot-${GHC_ARCH}-portbld-freebsd.tar.xz /tmp/ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz
287
288         cd /tmp \
289                 && sha256 ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz \
290                 && ${ECHO} -n "SIZE (ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz) = " \
291                 && ${STAT} -f %z ghc-${GHC_VERSION}-boot-${ARCH}-freebsd.tar.xz
292
293 # Much like create-bootstrap, just different naming and output format
294 # Set DYNAMIC, GMP and PROFILE to ON, and DOCS to OFF when generating Stack bindist
295 .PHONY: create-stack-bindist
296 create-stack-bindist:
297         ${REINPLACE_CMD} -e '/^mandir/d' \
298                         -e '/^infodir/d' \
299                         -e '/^docdir/d' \
300                         -e '/^htmldir/d' \
301                 ${WRKSRC}/mk/build.mk
302
303         cd ${WRKSRC} \
304                 && ${GMAKE} binary-dist TAR_COMP=xz \
305                 && ${MV} ${WRKSRC}/ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz /tmp/
306
307         cd /tmp \
308                 && ${ECHO} "${GHC_VERSION}:" \
309                 && ${ECHO} "url: \"http://distcache.FreeBSD.org/local-distfiles/arrowd/stack-bindists/ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz\"" \
310                 && ${ECHO} -n "content-length: " \
311                 && ${STAT} -f %z ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz \
312                 && ${ECHO} -n "sha1: " \
313                 && sha1 -q ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz \
314                 && ${ECHO} -n "sha256: " \
315                 && sha256 -q ghc-${GHC_VERSION}-${GHC_ARCH}-portbld-freebsd.tar.xz
316
317 .include <bsd.port.post.mk>