]> gitweb @ CieloNegro.org - pkgsrc-ghc.git/blob - bootstrap.mk
stage0.mk -> bootstrap.mk
[pkgsrc-ghc.git] / bootstrap.mk
1 # $NetBSD$
2
3 USE_TOOLS+=     autoconf date gtar perl
4
5 # Build an unregisterised bootstrap compiler and install it directly
6 # into the .buildlink directory. But we can't use "make install"
7 # because we don't build it in a standard way (./configure && make).
8 #
9 # To install it, we just copy ghc and ghc-pkg from
10 # "work/bootstrap/ghc-${VERSION}/inplace/bin" to
11 # "${BUILDLINK_DIR}/bin". Note that in-place ghc isn't usable until we
12 # run "ghc-pkg recache".
13
14 .if ${MACHINE_ARCH} == "i386" && ${OPSYS} == "NetBSD"
15 BOOTSTRAP_CAPI_C=       ${PKGDIR}/files/capi-wrappers-netbsd-i386.c
16 BOOTSTRAP_TARBALL=      ${DISTNAME}-boot-i386-unknown-netbsdelf6.99.1.tar.bz2
17 PLATFORM                = i386-unknown-netbsd
18
19 .elif ${MACHINE_ARCH} == "i386" && ${OPSYS} == "FreeBSD"
20 BOOTSTRAP_CAPI_C=       ${PKGDIR}/files/capi-wrappers-freebsd-i386.c
21 BOOTSTRAP_TARBALL=      ${DISTNAME}-boot-i386-unknown-freebsd8.0.tar.bz2
22 PLATFORM=               i386-unknown-freebsd
23
24 .elif ${MACHINE_ARCH} == "powerpc" && ${OPSYS} == "Darwin"
25 BOOTSTRAP_CAPI_C=       ${PKGDIR}/files/capi-wrappers-darwin-powerpc.c
26 BOOTSTRAP_TARBALL=      ${DISTNAME}-boot-powerpc-apple-darwin9.8.0.tar.bz2
27 PLATFORM=               powerpc-apple-darwin
28 # Existence of libelf makes LeadingUnderscore being "NO", which is
29 # incorrect for this platform. See ghc-6.12.1/aclocal.m4
30 # (FP_LEADING_UNDERSCORE)
31 CONFLICTS=              libelf-[0-9]*
32
33 .elif ${MACHINE_ARCH} == "x86_64" && ${OPSYS} == "Linux"
34 BOOTSTRAP_CAPI_C=       ${PKGDIR}/files/capi-wrappers-linux-x86_64.c
35 BOOTSTRAP_TARBALL=      ${DISTNAME}-boot-x86_64-unknown-linux-gnu.tar.bz2
36 PLATFORM=               x86_64-unknown-linux
37
38 .else
39 PKG_FAIL_REASON+=       "internal error: unsupported platform"
40 .endif
41
42 BOOTSTRAP_MAIN_C=       ${PKGDIR}/files/bootstrap-main.c
43
44 pre-configure: ${WRKDIR}/stamp-bootstrap-ghc
45
46 ${WRKDIR}/stamp-autoreconf:
47         ${RUN} cd ${WRKSRC} && \
48                 ${PHASE_MSG} "Regenerating configuration scripts for ${PKGNAME}" && \
49                 ${PERL5} boot && \
50                 ${TOUCH} ${.TARGET}
51
52 ${WRKDIR}/stamp-prepare-bootstrap: ${WRKDIR}/stamp-autoreconf
53         ${RUN} cd ${WRKDIR} && \
54                 ${PHASE_MSG} "Preparing bootstrapping compiler for ${PKGNAME}" && \
55                 ${RM} -rf bootstrap && \
56                 ${MKDIR} bootstrap && \
57                 ${GTAR} -cf - ${DISTNAME} | ${GTAR} -C bootstrap -xf - && \
58                 ${CP} -f ${BOOTSTRAP_MAIN_C} bootstrap/${DISTNAME}/rts/bootstrap-main.c && \
59                 ${CP} -f ${BOOTSTRAP_CAPI_C} bootstrap/${DISTNAME}/rts/capi-wrappers.c  && \
60                 ${TOUCH} ${.TARGET}
61
62 ${WRKDIR}/stamp-configure-hc-boot: ${WRKDIR}/stamp-prepare-bootstrap
63         ${RUN} cd ${WRKDIR}/bootstrap/${DISTNAME} && \
64                 ${PHASE_MSG} "Configuring bootstrapping compiler for ${PKGNAME}" && \
65                 ${SETENV} ${CONFIGURE_ENV} ./configure --enable-hc-boot --with-ghc="" ${CONFIGURE_ARGS} && \
66                 ${TOUCH} ${.TARGET}
67
68 ${WRKDIR}/stamp-extract-hc: ${WRKDIR}/stamp-configure-hc-boot
69         ${RUN} cd ${WRKDIR}/bootstrap && \
70                 ${PHASE_MSG} "Extracting bootstrap HC archive for ${PKGNAME}" && \
71                 if ${TEST} "`${DATE} '+%Y%m%d%H%M'`" -le 200001010000; then \
72                         ${FAIL_MSG} "Adjust your system clock: `${DATE}`"; \
73                 fi && \
74                 ${FIND} ${DISTNAME} -type d -o -type f | ${XARGS} ${TOUCH} -t 200001010000 && \
75                 ${GTAR} -jxf ${DISTDIR}/${BOOTSTRAP_TARBALL} && \
76                 (cd ${DISTNAME} && ${SH} mkfiles) && \
77                 ${TOUCH} ${.TARGET}
78
79 ${WRKDIR}/bootstrap/${DISTNAME}/mk/build.mk: ${WRKDIR}/stamp-extract-hc
80         ${RUN} ${PHASE_MSG} "Creating bootstrapping configuration file for ${PKGNAME}"
81         ${RUN} ${CP} -f ${PKGDIR}/files/build.bootstrap.common.mk ${.TARGET}
82         ${RUN} ${ECHO} "SRC_CC_OPTS += -I${PREFIX}/include" >> ${.TARGET}
83 .if ${OPSYS} == "Darwin"
84         ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv" >> ${.TARGET}
85         ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lncurses" >> ${.TARGET}
86         ${RUN} ${ECHO} "EXTRA_CC_OPTS += -O2" >> ${.TARGET}
87 .elif ${OPSYS} == "FreeBSD" || ${OPSYS} == "NetBSD"
88         ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lutil -lrt" >> ${.TARGET}
89         ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lutil -lrt -lncurses" >> ${.TARGET}
90 #   Unregisterised stage0 compiler gets too large (.text section being
91 # over 64 MiB) without -Os, exceeding NetBSD/i386's kernel default
92 # limitation.
93 #   Note that stage1 currently doesn't bloat that much (about 42.6
94 # MiB), but when it does we have to append CONF_CC_OPTS_STAGE0="-Os"
95 # to CONFIGURE_ARGS as well. I guess that's a matter of time :(
96         ${RUN} ${ECHO} "EXTRA_CC_OPTS += -Os" >> ${.TARGET}
97 .elif ${OPSYS} == "Linux"
98         ${RUN} ${ECHO} "ghc_stage2_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lrt -ldl" >> ${.TARGET}
99         ${RUN} ${ECHO} "utils/ghc-pkg_dist-install_v_EXTRA_CC_OPTS += -L${PREFIX}/lib -lm -liconv -lrt -ldl -lncurses" >> ${.TARGET}
100         ${RUN} ${ECHO} "EXTRA_CC_OPTS += -O2" >> ${.TARGET}
101 .else
102 PKG_FAIL_REASON+=       "internal error: unsupported platform"
103 .endif
104
105 ${WRKDIR}/stamp-rewrite-hc-paths: ${WRKDIR}/stamp-extract-hc ${WRKDIR}/bootstrap/${DISTNAME}/mk/build.mk
106         ${RUN} cd ${WRKDIR}/bootstrap/${DISTNAME} && \
107                 ${PHASE_MSG} "Rewriting source paths in bootstrapping compiler for ${PKGNAME}" && \
108                 for c in libraries/*/configure; do \
109                         (cd `${DIRNAME} $$c` && ${SETENV} ${CONFIGURE_ENV} ${SH} configure ${CONFIGURE_ARGS}); \
110                 done && \
111                 for i in inplace/lib/package.conf.d/*.conf \
112                                  */package.conf.inplace \
113                                  */*/package-data.mk \
114                                  */*/*/package-data.mk \
115                                  */*/*/*/package-data.mk; do \
116                         ${SED} -e "s#\\[\\[PREFIX\\]\\]#${PREFIX}#g" \
117                                    -e "s#\\[\\[GHC_SOURCE_PATH\\]\\]#`${PWD_CMD}`#g" $$i > $$i.tmp; \
118                         ${MV} -f $$i.tmp $$i; \
119                 done && \
120                 ${TOUCH} -r inplace/lib/package.conf.d \
121                                         inplace/lib/package.conf.d/*.conf \
122                                         */package.conf.inplace \
123                                         */*/package-data.mk \
124                                         */*/*/package-data.mk \
125                                         */*/*/*/package-data.mk \
126                                         compiler/stage?/build/Config.hs && \
127                 ${TOUCH} ${.TARGET}
128
129 ${WRKDIR}/stamp-bootstrap-ghc: ${WRKDIR}/stamp-rewrite-hc-paths
130         ${RUN} cd ${WRKDIR}/bootstrap/${DISTNAME} && \
131                 ${PHASE_MSG} "Creating bootstrapping files for ${PKGNAME}" && \
132                 ${BUILD_MAKE_CMD} bootstrapping-files && \
133                 ${PHASE_MSG} "Building bootstrapping compiler for ${PKGNAME}" && \
134                 ${BUILD_MAKE_CMD} all_ghc_stage2 && \
135                 ${PHASE_MSG} "Building bootstrapping toolkit for ${PKGNAME}" && \
136                 ${BUILD_MAKE_CMD} inplace/bin/ghc-pkg && \
137                 ${BUILD_MAKE_CMD} inplace/lib/unlit && \
138                 inplace/bin/ghc-pkg recache && \
139                 ${CP} -f inplace/bin/ghc-stage2 ${BUILDLINK_DIR}/bin/ghc && \
140                 ${CP} -f inplace/bin/ghc-pkg ${BUILDLINK_DIR}/bin/ghc-pkg && \
141                 ${TOUCH} ${.TARGET}