1 # $NetBSD: Makefile.gnuhost,v 1.39 2012/06/19 21:48:33 hans Exp $
3 # Rules used when building a GNU host package. Expects MODULE to be set.
5 # There's not a lot we can do to build reliably in the face of many
6 # available configuration options. To be as low-overhead as possible,
7 # we follow the following scheme:
9 # * Configuration is only re-run when an autoconf source file (such as
10 # "configure" or "config.sub") is changed.
12 # * "config.status" is run to rebuild Makefiles and .h files if an
13 # autoconf-parsed file (such as Makefile.in) is changed.
15 # * If MKUPDATE != "no", "make install" is only run if a build has happened
16 # since the last install in the current directory.
20 # Disable use of pre-compiled headers on Darwin.
21 BUILD_OSTYPE!= uname -s
22 .if ${BUILD_OSTYPE} == "Darwin"
23 HOST_CFLAGS+=-O2 -no-cpp-precomp
25 MAKE_PROGRAM?= ${MAKE}
27 GNUHOSTDIST?= ${.CURDIR}/../../external/gpl3/gcc/dist/
29 FIND_ARGS+= \! \( -type d \( \
39 external/gpl3/gcc/fetch.sh \
40 external/gpl3/binutils/fetch.sh \
42 external/lgpl2/mpc/fetch.sh \
43 external/lgpl3/gmp/fetch.sh \
44 external/lgpl3/mpfr/fetch.sh
46 _gnu_get_src: ${_GNU_GET_SCRIPTS}
47 .for name in ${_GNU_GET_SCRIPTS}
49 @${HOST_SH} ${.CURDIR}/../../${name}
52 # Do this "find" only if actually building something.
53 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
54 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
57 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
58 -type f \( -name 'config*' -o -name '*.in' \) -print
59 .MAKEOVERRIDES+= _GNU_CFGSRC
66 CFLAGS=${HOST_CFLAGS:Q} \
67 CPPFLAGS=${HOST_CPPFLAGS:Q} \
69 CXXFLAGS=${HOST_CXXFLAGS:Q} \
70 INSTALL=${HOST_INSTALL_FILE:Q} \
71 LDFLAGS=${HOST_LDFLAGS:Q} \
74 MAKE=${MAKE_PROGRAM:Q} \
75 PATH="${TOOLDIR}/bin:$$PATH" \
76 RANLIB=${HOST_RANLIB:Q} \
79 BUILD_ENV+= ${CONFIGURE_ENV}
81 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
83 CONFIGURE_ARGS+=--disable-shared
86 .if ${MAKE_PROGRAM} == ${MAKE}
88 # Some systems have a small ARG_MAX. On such systems, prevent Make
89 # variables set on the command line from being exported in the
90 # environment (they will still be set in MAKEOVERRIDES).
91 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
94 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
96 MAKE_ARGS+= _NOWRAPPER=1
98 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
101 # gmake version of this puts MAKE_ARGS in the environment to be sure that
102 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
103 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
104 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
105 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
109 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
112 INSTALL_TARGET?=install
114 BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
115 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
116 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
118 @mkdir build 2>/dev/null || true
119 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
120 @(cd build && find . -name config.cache | xargs rm -f)
121 configure_cleanup=configure_cleanup
124 .configure_done: _gnu_get_src .WAIT ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
125 @mkdir build 2>/dev/null || true
126 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
127 @echo ${BUILD_PLATFORM} > $@
129 # The .build_done timestamp is only updated if a file actually changes
130 # in the build tree during "make all". This way, if nothing has changed,
131 # a "make install MKUPDATE=yes" will do nothing.
133 .build_done: .configure_done
134 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
135 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
138 .install_done! ${BUILD:D.build_done}
139 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
142 # Mapping to standard targets.
144 .if ${USETOOLS} == "yes"
146 realinstall: .install_done
151 -rm -r -f .*_done build
153 .include <bsd.hostprog.mk>