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}/../../gnu/dist/${MODULE}
29 # AL - MINIX /usr/src does not have the sources for the GNU utilities
30 # in-tree (they are much bigger than Minix itself!) So to successfully
31 # use them while cross-compiling, we have to fetch them. The success of
32 # that operation is indicated by the presence of a .gitignore file in
33 # the corresponding ${.CURDIR}, which also conveniently hides from git.
34 .if exists(${GNUHOSTDIST:H}/fetch.sh)
35 ${GNUHOSTDIST:H}/.gitignore: ${GNUHOSTDIST:H}/fetch.sh
36 ${HOST_SH} ${GNUHOSTDIST:H}/fetch.sh
37 @test -e ${GNUHOSTDIST}/configure
38 @echo "${MODULE:U${.CURDIR:T:C,^gcc[0-9]*$,gcc,}}-*.tar.*z*" > $@
39 @echo ${GNUHOSTDIST:T} >> $@
40 _gnu_get_src=${GNUHOSTDIST:H}/.gitignore
41 .endif # exists(GNUHOSTDIST:H/fetch.sh) on MINIX
43 FIND_ARGS+= \! \( -type d \( \
52 # Do this "find" only if actually building something.
53 # AL - ... and on MINIX, if the source has already being fetched
54 .if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
55 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
56 !defined(_GNU_CFGSRC) && exists(${GNUHOSTDIST}/configure)
58 _GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \
59 -type f \( -name 'config*' -o -name '*.in' \) -print
60 .MAKEOVERRIDES+= _GNU_CFGSRC
67 CFLAGS=${HOST_CFLAGS:Q} \
68 CPPFLAGS=${HOST_CPPFLAGS:Q} \
70 CXXFLAGS=${HOST_CXXFLAGS:Q} \
71 INSTALL=${HOST_INSTALL_FILE:Q} \
72 LDFLAGS=${HOST_LDFLAGS:Q} \
75 MAKE=${MAKE_PROGRAM:Q} \
76 PATH="${TOOLDIR}/bin:$$PATH" \
77 RANLIB=${HOST_RANLIB:Q} \
80 BUILD_ENV+= ${CONFIGURE_ENV}
82 CONFIGURE_ARGS+=--prefix=${TOOLDIR}
84 CONFIGURE_ARGS+=--disable-shared
87 .if ${MAKE_PROGRAM} == ${MAKE}
89 # Some systems have a small ARG_MAX. On such systems, prevent Make
90 # variables set on the command line from being exported in the
91 # environment (they will still be set in MAKEOVERRIDES).
92 .if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
95 MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
97 MAKE_ARGS+= _NOWRAPPER=1
99 BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
102 # gmake version of this puts MAKE_ARGS in the environment to be sure that
103 # sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
104 # fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
105 GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
106 BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
110 MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
113 INSTALL_TARGET?=install
115 BUILD_PLATFORM!= uname -srm | tr ' ()' '-'
116 CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
117 .if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
119 @mkdir build 2>/dev/null || true
120 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
121 @(cd build && find . -name config.cache | xargs rm -f)
122 configure_cleanup=configure_cleanup
125 # AL For MINIX, fetch the source if not there
126 .configure_done: ${_gnu_get_src} .WAIT ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
127 @mkdir build 2>/dev/null || true
128 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
129 @echo ${BUILD_PLATFORM} > $@
131 # The .build_done timestamp is only updated if a file actually changes
132 # in the build tree during "make all". This way, if nothing has changed,
133 # a "make install MKUPDATE=yes" will do nothing.
135 .build_done: .configure_done
136 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
137 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
140 .install_done! ${BUILD:D.build_done}
141 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
144 # Mapping to standard targets.
146 .if ${USETOOLS} == "yes"
148 realinstall: .install_done
153 -rm -r -f .*_done build
155 # AL - Special target for MINIX, reset the source tree as pristine
156 .if ${CLEANFETCHED:Uno} == "yes" && exists(${GNUHOSTDIST:H}/fetch.sh)
157 cleandir: clean_gnu_src
159 -rm -r -f ${GNUHOSTDIST} ${GNUHOSTDIST:H}/.gitignore
160 # XXX CHECKME: could have used the content of .gitignore as well?
161 .endif # CLEANFETCHED == yes
163 .include <bsd.hostprog.mk>