1 # $NetBSD: Makefile.gnuhost,v 1.37 2012/01/21 22:31:15 christos 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 _GNU_GET_SRC!= ${HOST_SH} ${.CURDIR}/../../external/gpl3/gcc/fetch.sh && \
40 ${HOST_SH} ${.CURDIR}/../../external/gpl3/binutils/fetch.sh && \
41 ${HOST_SH} ${.CURDIR}/../../gnu/dist/fetch.sh && \
42 ${HOST_SH} ${.CURDIR}/../../external/lgpl2/mpc/fetch.sh && \
43 ${HOST_SH} ${.CURDIR}/../../external/lgpl3/gmp/fetch.sh && \
44 ${HOST_SH} ${.CURDIR}/../../external/lgpl3/mpfr/fetch.sh
46 # Do this "find" only if actually building something.
47 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
48 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
51 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
52 -type f \( -name 'config*' -o -name '*.in' \) -print
53 .MAKEOVERRIDES+= _GNU_CFGSRC
60 CFLAGS=${HOST_CFLAGS:Q} \
61 CPPFLAGS=${HOST_CPPFLAGS:Q} \
63 CXXFLAGS=${HOST_CXXFLAGS:Q} \
64 INSTALL=${HOST_INSTALL_FILE:Q} \
65 LDFLAGS=${HOST_LDFLAGS:Q} \
68 MAKE=${MAKE_PROGRAM:Q} \
69 PATH="${TOOLDIR}/bin:$$PATH" \
70 RANLIB=${HOST_RANLIB:Q} \
73 BUILD_ENV+= ${CONFIGURE_ENV}
75 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
77 CONFIGURE_ARGS+=--disable-shared
80 .if ${MAKE_PROGRAM} == ${MAKE}
82 # Some systems have a small ARG_MAX. On such systems, prevent Make
83 # variables set on the command line from being exported in the
84 # environment (they will still be set in MAKEOVERRIDES).
85 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
88 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
90 MAKE_ARGS+= _NOWRAPPER=1
92 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
95 # gmake version of this puts MAKE_ARGS in the environment to be sure that
96 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
97 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
98 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
99 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
103 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
106 INSTALL_TARGET?=install
108 BUILD_PLATFORM!= uname -srm | tr ' ' '-'
109 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
110 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
112 @mkdir build 2>/dev/null || true
113 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
114 @(cd build && find . -name config.cache -print0 | xargs -0 rm -f)
115 configure_cleanup=configure_cleanup
118 .configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
119 @mkdir build 2>/dev/null || true
120 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
121 @echo ${BUILD_PLATFORM} > $@
123 # The .build_done timestamp is only updated if a file actually changes
124 # in the build tree during "make all". This way, if nothing has changed,
125 # a "make install MKUPDATE=yes" will do nothing.
127 .build_done: .configure_done
128 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
129 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
132 .install_done! ${BUILD:D.build_done}
133 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
136 # Mapping to standard targets.
138 .if ${USETOOLS} == "yes"
140 realinstall: .install_done
145 -rm -r -f .*_done build
147 .include <bsd.hostprog.mk>