184d9c625SLionel Sambuc# $NetBSD: Makefile.gnuhost,v 1.42 2013/08/13 20:41:25 drochner Exp $ 2c8a0e2f4SThomas Veerman# 3c8a0e2f4SThomas Veerman# Rules used when building a GNU host package. Expects MODULE to be set. 4c8a0e2f4SThomas Veerman# 5c8a0e2f4SThomas Veerman# There's not a lot we can do to build reliably in the face of many 6c8a0e2f4SThomas Veerman# available configuration options. To be as low-overhead as possible, 7c8a0e2f4SThomas Veerman# we follow the following scheme: 8c8a0e2f4SThomas Veerman# 9c8a0e2f4SThomas Veerman# * Configuration is only re-run when an autoconf source file (such as 10c8a0e2f4SThomas Veerman# "configure" or "config.sub") is changed. 11c8a0e2f4SThomas Veerman# 12c8a0e2f4SThomas Veerman# * "config.status" is run to rebuild Makefiles and .h files if an 13c8a0e2f4SThomas Veerman# autoconf-parsed file (such as Makefile.in) is changed. 14c8a0e2f4SThomas Veerman# 15c8a0e2f4SThomas Veerman# * If MKUPDATE != "no", "make install" is only run if a build has happened 16c8a0e2f4SThomas Veerman# since the last install in the current directory. 17c8a0e2f4SThomas Veerman 18c8a0e2f4SThomas Veerman.include <bsd.own.mk> 19c8a0e2f4SThomas Veerman 20c8a0e2f4SThomas Veerman# Disable use of pre-compiled headers on Darwin. 21c8a0e2f4SThomas VeermanBUILD_OSTYPE!= uname -s 22c8a0e2f4SThomas Veerman.if ${BUILD_OSTYPE} == "Darwin" 23c8a0e2f4SThomas VeermanHOST_CFLAGS+=-O2 -no-cpp-precomp 24c8a0e2f4SThomas Veerman.endif 25c8a0e2f4SThomas VeermanMAKE_PROGRAM?= ${MAKE} 26c8a0e2f4SThomas Veerman 27866355d9SAntoine LecaGNUHOSTDIST?= ${.CURDIR}/../../gnu/dist/${MODULE} 28866355d9SAntoine Leca 2984d9c625SLionel Sambuc.if defined(__MINIX) 30*a150b26eSAntoine Leca.include "../minix/Makefile.fetchgnu" 3184d9c625SLionel Sambuc.endif # defined(__MINIX) 3284d9c625SLionel Sambuc 33c8a0e2f4SThomas VeermanFIND_ARGS+= \! \( -type d \( \ 34c8a0e2f4SThomas Veerman -name 'CVS' -o \ 35c8a0e2f4SThomas Veerman -name 'config' -o \ 36c8a0e2f4SThomas Veerman -name 'doc' -o \ 37c8a0e2f4SThomas Veerman -name 'po' -o \ 38c8a0e2f4SThomas Veerman -name 'nbsd.mt' -o \ 39c8a0e2f4SThomas Veerman -name 'tests*' \ 40c8a0e2f4SThomas Veerman \) -prune \) 41d19d7d58SLionel Sambuc 42c8a0e2f4SThomas Veerman# Do this "find" only if actually building something. 43866355d9SAntoine Leca# AL - ... and on MINIX, if the source has already being fetched 44c8a0e2f4SThomas Veerman.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \ 45c8a0e2f4SThomas Veerman (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \ 46866355d9SAntoine Leca !defined(_GNU_CFGSRC) && exists(${GNUHOSTDIST}/configure) 47c8a0e2f4SThomas Veerman 48c8a0e2f4SThomas Veerman_GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \ 49c8a0e2f4SThomas Veerman -type f \( -name 'config*' -o -name '*.in' \) -print 50c8a0e2f4SThomas Veerman.MAKEOVERRIDES+= _GNU_CFGSRC 51c8a0e2f4SThomas Veerman.endif 52c8a0e2f4SThomas Veerman 53c8a0e2f4SThomas VeermanCONFIGURE_ENV+= \ 54c8a0e2f4SThomas Veerman AR=${HOST_AR:Q} \ 55c8a0e2f4SThomas Veerman AWK=${TOOL_AWK:Q} \ 56c8a0e2f4SThomas Veerman CC=${HOST_CC:Q} \ 57c8a0e2f4SThomas Veerman CFLAGS=${HOST_CFLAGS:Q} \ 5884d9c625SLionel Sambuc CONFIG_SHELL=${HOST_SH:Q} \ 59c8a0e2f4SThomas Veerman CPPFLAGS=${HOST_CPPFLAGS:Q} \ 60c8a0e2f4SThomas Veerman CXX=${HOST_CXX:Q} \ 61c8a0e2f4SThomas Veerman CXXFLAGS=${HOST_CXXFLAGS:Q} \ 62c8a0e2f4SThomas Veerman INSTALL=${HOST_INSTALL_FILE:Q} \ 63c8a0e2f4SThomas Veerman LDFLAGS=${HOST_LDFLAGS:Q} \ 64c8a0e2f4SThomas Veerman LEX=${LEX:Q} \ 65c8a0e2f4SThomas Veerman M4=${TOOL_M4:Q} \ 66c8a0e2f4SThomas Veerman MAKE=${MAKE_PROGRAM:Q} \ 67c8a0e2f4SThomas Veerman PATH="${TOOLDIR}/bin:$$PATH" \ 68c8a0e2f4SThomas Veerman RANLIB=${HOST_RANLIB:Q} \ 69c8a0e2f4SThomas Veerman YACC=${YACC:Q} 70c8a0e2f4SThomas Veerman 71c8a0e2f4SThomas VeermanBUILD_ENV+= ${CONFIGURE_ENV} 72c8a0e2f4SThomas Veerman 73c8a0e2f4SThomas VeermanCONFIGURE_ARGS+=--prefix=${TOOLDIR} 74c8a0e2f4SThomas Veerman.if ${MKPIC} == "no" 75c8a0e2f4SThomas VeermanCONFIGURE_ARGS+=--disable-shared 76c8a0e2f4SThomas Veerman.endif 77c8a0e2f4SThomas Veerman 78c8a0e2f4SThomas Veerman.if ${MAKE_PROGRAM} == ${MAKE} 79c8a0e2f4SThomas Veerman.ifndef _NOWRAPPER 80c8a0e2f4SThomas Veerman# Some systems have a small ARG_MAX. On such systems, prevent Make 81c8a0e2f4SThomas Veerman# variables set on the command line from being exported in the 82c8a0e2f4SThomas Veerman# environment (they will still be set in MAKEOVERRIDES). 83c8a0e2f4SThomas Veerman.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD" 84c8a0e2f4SThomas Veerman__noenvexport= -X 85c8a0e2f4SThomas Veerman.endif 86c8a0e2f4SThomas VeermanMAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS} 87c8a0e2f4SThomas Veerman.else 88c8a0e2f4SThomas VeermanMAKE_ARGS+= _NOWRAPPER=1 89c8a0e2f4SThomas Veerman.endif 90c8a0e2f4SThomas VeermanBUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS} 91c8a0e2f4SThomas Veerman.else 92c8a0e2f4SThomas Veerman 93c8a0e2f4SThomas Veerman# gmake version of this puts MAKE_ARGS in the environment to be sure that 94c8a0e2f4SThomas Veerman# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and 95c8a0e2f4SThomas Veerman# fails. it also uses "env -i" to entirely clear out MAKEFLAGS. 96c8a0e2f4SThomas VeermanGMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W} 97c8a0e2f4SThomas VeermanBUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS} 98c8a0e2f4SThomas Veerman 99c8a0e2f4SThomas Veerman.endif 100c8a0e2f4SThomas Veerman 101c8a0e2f4SThomas VeermanMAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q} 102c8a0e2f4SThomas Veerman 103c8a0e2f4SThomas VeermanALL_TARGET?= all 104c8a0e2f4SThomas VeermanINSTALL_TARGET?=install 105c8a0e2f4SThomas Veerman 1069152e1c5SLionel SambucBUILD_PLATFORM!= uname -srm | tr ' ()' '-' 107c8a0e2f4SThomas VeermanCONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi 108c8a0e2f4SThomas Veerman.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}" 109c8a0e2f4SThomas Veermanconfigure_cleanup: 110c8a0e2f4SThomas Veerman @mkdir build 2>/dev/null || true 111c8a0e2f4SThomas Veerman @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}") 1129152e1c5SLionel Sambuc @(cd build && find . -name config.cache | xargs rm -f) 113c8a0e2f4SThomas Veermanconfigure_cleanup=configure_cleanup 114c8a0e2f4SThomas Veerman.endif 115c8a0e2f4SThomas Veerman 116866355d9SAntoine Leca# AL For MINIX, fetch the source if not there 117*a150b26eSAntoine Leca.configure_done: ${fetch_done} ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup} 118c8a0e2f4SThomas Veerman @mkdir build 2>/dev/null || true 119c8a0e2f4SThomas Veerman @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS}) 120c8a0e2f4SThomas Veerman @echo ${BUILD_PLATFORM} > $@ 121c8a0e2f4SThomas Veerman 122c8a0e2f4SThomas Veerman# The .build_done timestamp is only updated if a file actually changes 123c8a0e2f4SThomas Veerman# in the build tree during "make all". This way, if nothing has changed, 124c8a0e2f4SThomas Veerman# a "make install MKUPDATE=yes" will do nothing. 125c8a0e2f4SThomas Veerman 126c8a0e2f4SThomas Veerman.build_done: .configure_done 127c8a0e2f4SThomas Veerman @(cd build && ${BUILD_COMMAND} ${ALL_TARGET}) 128c8a0e2f4SThomas Veerman @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \ 129c8a0e2f4SThomas Veerman then touch $@; fi 130c8a0e2f4SThomas Veerman 131c8a0e2f4SThomas Veerman.install_done! ${BUILD:D.build_done} 132c8a0e2f4SThomas Veerman @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET}) 133c8a0e2f4SThomas Veerman @touch $@ 134c8a0e2f4SThomas Veerman 135c8a0e2f4SThomas Veerman# Mapping to standard targets. 136c8a0e2f4SThomas Veerman 137c8a0e2f4SThomas Veerman.if ${USETOOLS} == "yes" 138c8a0e2f4SThomas Veermanrealall: .build_done 139c8a0e2f4SThomas Veermanrealinstall: .install_done 140c8a0e2f4SThomas Veerman.endif 141c8a0e2f4SThomas Veerman 142c8a0e2f4SThomas Veermanclean: clean.gnu 143c8a0e2f4SThomas Veermanclean.gnu: 144c8a0e2f4SThomas Veerman -rm -r -f .*_done build 145c8a0e2f4SThomas Veerman 146c8a0e2f4SThomas Veerman.include <bsd.hostprog.mk> 147