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