1 # $NetBSD: Makefile.gnuhost,v 1.42 2013/08/13 20:41:25 drochner 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}/../../gnu/dist/${MODULE}
30 # AL - MINIX /usr/src does not have the sources for the GNU utilities
31 # in-tree (they are much bigger than Minix itself!) So to successfully
32 # use them while cross-compiling, we have to fetch them. The success of
33 # that operation is indicated by the presence of a .gitignore file in
34 # the corresponding ${.CURDIR}, which also conveniently hides from git.
35 .if exists(${GNUHOSTDIST:H}/fetch.sh)
36 ${GNUHOSTDIST:H}/.gitignore: ${GNUHOSTDIST:H}/fetch.sh
37 ${HOST_SH} ${GNUHOSTDIST:H}/fetch.sh
38 @test -e ${GNUHOSTDIST}/configure
39 @echo "${MODULE:U${.CURDIR:T}:C,gcc[0-9]*,gcc,}-*.tar.*z*" >> $@
40 @echo ${GNUHOSTDIST:T} >> $@
41 _gnu_get_src=${GNUHOSTDIST:H}/.gitignore
42 .endif # exists(GNUHOSTDIST:H/fetch.sh) on MINIX
44 # AL - Special target for MINIX, reset the source tree as pristine
45 .if ${CLEANFETCHED:Uno} == "yes" && exists(${GNUHOSTDIST:H}/fetch.sh)
46 cleandir: clean_gnu_src
48 -rm -r -f ${GNUHOSTDIST} ${GNUHOSTDIST:H}/.gitignore
49 # XXX CHECKME: could have used the content of .gitignore as well?
50 .endif # CLEANFETCHED == yes
51 .endif # defined(__MINIX)
53 FIND_ARGS+= \! \( -type d \( \
62 # Do this "find" only if actually building something.
63 # AL - ... and on MINIX, if the source has already being fetched
64 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
65 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
66 !defined(_GNU_CFGSRC) && exists(${GNUHOSTDIST}/configure)
68 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
69 -type f \( -name 'config*' -o -name '*.in' \) -print
70 .MAKEOVERRIDES+= _GNU_CFGSRC
77 CFLAGS=${HOST_CFLAGS:Q} \
78 CONFIG_SHELL=${HOST_SH:Q} \
79 CPPFLAGS=${HOST_CPPFLAGS:Q} \
81 CXXFLAGS=${HOST_CXXFLAGS:Q} \
82 INSTALL=${HOST_INSTALL_FILE:Q} \
83 LDFLAGS=${HOST_LDFLAGS:Q} \
86 MAKE=${MAKE_PROGRAM:Q} \
87 PATH="${TOOLDIR}/bin:$$PATH" \
88 RANLIB=${HOST_RANLIB:Q} \
91 BUILD_ENV+= ${CONFIGURE_ENV}
93 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
95 CONFIGURE_ARGS+=--disable-shared
98 .if ${MAKE_PROGRAM} == ${MAKE}
100 # Some systems have a small ARG_MAX. On such systems, prevent Make
101 # variables set on the command line from being exported in the
102 # environment (they will still be set in MAKEOVERRIDES).
103 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
106 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
108 MAKE_ARGS+= _NOWRAPPER=1
110 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
113 # gmake version of this puts MAKE_ARGS in the environment to be sure that
114 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
115 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
116 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
117 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
121 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
124 INSTALL_TARGET?=install
126 BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
127 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
128 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
130 @mkdir build 2>/dev/null || true
131 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
132 @(cd build && find . -name config.cache | xargs rm -f)
133 configure_cleanup=configure_cleanup
136 # AL For MINIX, fetch the source if not there
137 .configure_done: ${_gnu_get_src} .WAIT ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
138 @mkdir build 2>/dev/null || true
139 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
140 @echo ${BUILD_PLATFORM} > $@
142 # The .build_done timestamp is only updated if a file actually changes
143 # in the build tree during "make all". This way, if nothing has changed,
144 # a "make install MKUPDATE=yes" will do nothing.
146 .build_done: .configure_done
147 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
148 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
151 .install_done! ${BUILD:D.build_done}
152 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
155 # Mapping to standard targets.
157 .if ${USETOOLS} == "yes"
159 realinstall: .install_done
164 -rm -r -f .*_done build
166 .include <bsd.hostprog.mk>