Makefile.gnuhost revision 1.36
11.36Schristos#	$NetBSD: Makefile.gnuhost,v 1.36 2012/01/20 23:01:05 christos Exp $
21.1Stv#
31.1Stv# Rules used when building a GNU host package.  Expects MODULE to be set.
41.1Stv#
51.1Stv# There's not a lot we can do to build reliably in the face of many
61.1Stv# available configuration options.  To be as low-overhead as possible,
71.1Stv# we follow the following scheme:
81.1Stv#
91.1Stv# * Configuration is only re-run when an autoconf source file (such as
101.1Stv#   "configure" or "config.sub") is changed.
111.1Stv#
121.1Stv# * "config.status" is run to rebuild Makefiles and .h files if an
131.1Stv#   autoconf-parsed file (such as Makefile.in) is changed.
141.1Stv#
151.19Slukem# * If MKUPDATE != "no", "make install" is only run if a build has happened
161.1Stv#   since the last install in the current directory.
171.1Stv
181.1Stv.include <bsd.own.mk>
191.20Sdbj
201.20Sdbj# Disable use of pre-compiled headers on Darwin.
211.36SchristosBUILD_OSTYPE!= uname -s
221.20Sdbj.if ${BUILD_OSTYPE} == "Darwin"
231.21SdbjHOST_CFLAGS+=-O2 -no-cpp-precomp
241.20Sdbj.endif
251.36SchristosMAKE_PROGRAM?=	${MAKE}
261.1Stv
271.17SlukemGNUHOSTDIST?=	${.CURDIR}/../../gnu/dist/${MODULE}
281.1Stv
291.1StvFIND_ARGS+=	\! \( -type d \( \
301.1Stv			-name 'CVS' -o \
311.1Stv			-name 'config' -o \
321.1Stv			-name 'doc' -o \
331.1Stv			-name 'po' -o \
341.8Stv			-name 'nbsd.mt' -o \
351.1Stv			-name 'tests*' \
361.1Stv		\) -prune \)
371.1Stv
381.1Stv# Do this "find" only if actually building something.
391.1Stv.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
401.1Stv    (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
411.1Stv    !defined(_GNU_CFGSRC)
421.1Stv
431.17Slukem_GNU_CFGSRC!=	find ${GNUHOSTDIST} ${FIND_ARGS} \
441.1Stv		-type f \( -name 'config*' -o -name '*.in' \) -print
451.1Stv.MAKEOVERRIDES+= _GNU_CFGSRC
461.1Stv.endif
471.1Stv
481.33SapbCONFIGURE_ENV+= \
491.33Sapb		AR=${HOST_AR:Q} \
501.33Sapb		AWK=${TOOL_AWK:Q} \
511.33Sapb		CC=${HOST_CC:Q} \
521.1Stv		CFLAGS=${HOST_CFLAGS:Q} \
531.1Stv		CPPFLAGS=${HOST_CPPFLAGS:Q} \
541.1Stv		CXX=${HOST_CXX:Q} \
551.1Stv		CXXFLAGS=${HOST_CXXFLAGS:Q} \
561.9Sperry		INSTALL=${HOST_INSTALL_FILE:Q} \
571.1Stv		LDFLAGS=${HOST_LDFLAGS:Q} \
581.14Stv		LEX=${LEX:Q} \
591.35Stsutsui		M4=${TOOL_M4:Q} \
601.36Schristos		MAKE=${MAKE_PROGRAM:Q} \
611.14Stv		PATH="${TOOLDIR}/bin:$$PATH" \
621.33Sapb		RANLIB=${HOST_RANLIB:Q} \
631.14Stv		YACC=${YACC:Q}
641.1Stv
651.31SjmcBUILD_ENV+=	${CONFIGURE_ENV}
661.31Sjmc
671.25SskrllCONFIGURE_ARGS+=--prefix=${TOOLDIR}
681.26Sskrll.if ${MKPIC} == "no"
691.26SskrllCONFIGURE_ARGS+=--disable-shared
701.26Sskrll.endif
711.1Stv
721.36Schristos.if ${MAKE_PROGRAM} == ${MAKE}
731.2Stv.ifndef _NOWRAPPER
741.18Sthorpej# Some systems have a small ARG_MAX.  On such systems, prevent Make
751.18Sthorpej# variables set on the command line from being exported in the
761.18Sthorpej# environment (they will still be set in MAKEOVERRIDES).
771.18Sthorpej.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
781.18Sthorpej__noenvexport=	-X
791.18Sthorpej.endif
801.18SthorpejMAKE_ARGS:=	${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
811.2Stv.else
821.2StvMAKE_ARGS+=	_NOWRAPPER=1
831.2Stv.endif
841.36SchristosBUILD_COMMAND=	${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
851.36Schristos.else
861.36Schristos
871.36Schristos# gmake version of this puts MAKE_ARGS in the environment to be sure that
881.36Schristos# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
891.36Schristos# fails.  it also uses "env -i" to entirely clear out MAKEFLAGS.
901.36SchristosGMAKE_J_ARGS?=	${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W}
911.36SchristosBUILD_COMMAND=	/usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
921.36Schristos
931.36Schristos.endif
941.3Stv
951.15StvMAKE_ARGS+=	BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q}
961.2Stv
971.1StvALL_TARGET?=	all
981.1StvINSTALL_TARGET?=install
991.1Stv
1001.36SchristosBUILD_PLATFORM!= uname -srm | tr ' ' '-'
1011.36SchristosCONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
1021.36Schristos.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
1031.36Schristosconfigure_cleanup:
1041.36Schristos	@mkdir build 2>/dev/null || true
1051.36Schristos	@(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
1061.36Schristos	@(cd build && find . -name config.cache -print0 | xargs -0 rm -f)
1071.36Schristosconfigure_cleanup=configure_cleanup
1081.36Schristos.endif
1091.36Schristos
1101.36SchristosBUILD_PLATFORM!= uname -srm | tr ' ' '-'
1111.36SchristosCONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi
1121.36Schristos.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}"
1131.36Schristosconfigure_cleanup:
1141.36Schristos	@mkdir build 2>/dev/null || true
1151.36Schristos	@(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}")
1161.36Schristos	@(cd build && find . -name config.cache -print0 | xargs -0 rm -f)
1171.36Schristosconfigure_cleanup=configure_cleanup
1181.36Schristos.endif
1191.36Schristos
1201.36Schristos.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup}
1211.1Stv	@mkdir build 2>/dev/null || true
1221.32Sjmc	@(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS})
1231.36Schristos	@echo ${BUILD_PLATFORM} > $@
1241.1Stv
1251.12Stv# The .build_done timestamp is only updated if a file actually changes
1261.12Stv# in the build tree during "make all".  This way, if nothing has changed,
1271.19Slukem# a "make install MKUPDATE=yes" will do nothing.
1281.12Stv
1291.1Stv.build_done: .configure_done
1301.36Schristos	@(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
1311.15Stv	@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
1321.13Stv		then touch $@; fi
1331.1Stv
1341.27Sjmc.install_done! ${BUILD:D.build_done}
1351.36Schristos	@(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET})
1361.1Stv	@touch $@
1371.12Stv
1381.1Stv# Mapping to standard targets.
1391.1Stv
1401.1Stv.if ${USETOOLS} == "yes"
1411.1Stvrealall: .build_done
1421.1Stvrealinstall: .install_done
1431.1Stv.endif
1441.1Stv
1451.1Stvclean: clean.gnu
1461.1Stvclean.gnu:
1471.29Sjmc	-rm -r -f .*_done build
1481.1Stv
1491.1Stv.include <bsd.hostprog.mk>
150