1*cf4db277Slukem# $NetBSD: Makefile.gnuhost,v 1.56 2023/05/19 10:42:34 lukem Exp $ 2b5cd2489Stv# 3b5cd2489Stv# Rules used when building a GNU host package. Expects MODULE to be set. 4b5cd2489Stv# 5b5cd2489Stv# There's not a lot we can do to build reliably in the face of many 6b5cd2489Stv# available configuration options. To be as low-overhead as possible, 7b5cd2489Stv# we follow the following scheme: 8b5cd2489Stv# 9b5cd2489Stv# * Configuration is only re-run when an autoconf source file (such as 10b5cd2489Stv# "configure" or "config.sub") is changed. 11b5cd2489Stv# 12b5cd2489Stv# * "config.status" is run to rebuild Makefiles and .h files if an 13b5cd2489Stv# autoconf-parsed file (such as Makefile.in) is changed. 14b5cd2489Stv# 15f134f3dcSlukem# * If MKUPDATE != "no", "make install" is only run if a build has happened 16b5cd2489Stv# since the last install in the current directory. 17b5cd2489Stv 18b5cd2489Stv.include <bsd.own.mk> 19b5cd2489Stv 202fe0adbeSdbj# Disable use of pre-compiled headers on Darwin. 212fe0adbeSdbjBUILD_OSTYPE!= uname -s 222d7f932bSchristosHOST_COMPILER_CLANG!= if ${HOST_CC} --version | grep -q -s clang; then echo yes; else echo no; fi 232d7f932bSchristos.if ${HOST_COMPILER_CLANG} == "yes" 243c72899fSdbjHOST_CFLAGS+=-O2 -no-cpp-precomp 251c811476Schristos.endif 261c811476Schristos 27c300185bSchristosMAKE_PROGRAM?= ${MAKE} 282fe0adbeSdbj 29ee45ee4bSchristos.for i in 3 2 30ee45ee4bSchristos.if exists(${.CURDIR}/../../external/gpl${i}/${MODULE}/dist) 31ee45ee4bSchristosGNUHOSTDIST?= ${.CURDIR}/../../external/gpl${i}/${MODULE}/dist 328c986671Schristos.endif 33ee45ee4bSchristos.endfor 34b5cd2489Stv 35b5cd2489StvFIND_ARGS+= \! \( -type d \( \ 36b5cd2489Stv -name 'CVS' -o \ 37b5cd2489Stv -name 'config' -o \ 38b5cd2489Stv -name 'doc' -o \ 39b5cd2489Stv -name 'po' -o \ 40f39f0b51Stv -name 'nbsd.mt' -o \ 41b5cd2489Stv -name 'tests*' \ 42b5cd2489Stv \) -prune \) 43b5cd2489Stv 44b5cd2489Stv# Do this "find" only if actually building something. 45b5cd2489Stv.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \ 46b5cd2489Stv (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \ 47b5cd2489Stv !defined(_GNU_CFGSRC) 48b5cd2489Stv 4927c21a91Slukem_GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \ 50b5cd2489Stv -type f \( -name 'config*' -o -name '*.in' \) -print 51b5cd2489Stv.MAKEOVERRIDES+= _GNU_CFGSRC 52b5cd2489Stv.endif 53b5cd2489Stv 5496230fabSapbCONFIGURE_ENV+= \ 5596230fabSapb AR=${HOST_AR:Q} \ 5696230fabSapb AWK=${TOOL_AWK:Q} \ 5796230fabSapb CC=${HOST_CC:Q} \ 58b5cd2489Stv CFLAGS=${HOST_CFLAGS:Q} \ 5986d6df49Sdrochner CONFIG_SHELL=${HOST_SH:Q} \ 60b5cd2489Stv CPPFLAGS=${HOST_CPPFLAGS:Q} \ 61b5cd2489Stv CXX=${HOST_CXX:Q} \ 62b5cd2489Stv CXXFLAGS=${HOST_CXXFLAGS:Q} \ 63184d8eecSperry INSTALL=${HOST_INSTALL_FILE:Q} \ 64b5cd2489Stv LDFLAGS=${HOST_LDFLAGS:Q} \ 65c10af7beStv LEX=${LEX:Q} \ 66bbde9f9dSmartin FLEX=${LEX:Q} \ 67b042dd28Sapb M4=${TOOL_M4:Q} \ 68c300185bSchristos MAKE=${MAKE_PROGRAM:Q} \ 69c10af7beStv PATH="${TOOLDIR}/bin:$$PATH" \ 7096230fabSapb RANLIB=${HOST_RANLIB:Q} \ 71c10af7beStv YACC=${YACC:Q} 72b5cd2489Stv 7307aeec53SjmcBUILD_ENV+= ${CONFIGURE_ENV} 7407aeec53Sjmc 75b263dbddSskrllCONFIGURE_ARGS+=--prefix=${TOOLDIR} 760aae5402Sskrll.if ${MKPIC} == "no" 770aae5402SskrllCONFIGURE_ARGS+=--disable-shared 780aae5402Sskrll.endif 79b5cd2489Stv 8049c251ebSlukem.if ${MAKEVERBOSE} == 0 8149c251ebSlukemCONFIGURE_ARGS+=--silent 8249c251ebSlukem.endif 8349c251ebSlukem 8449c251ebSlukem 85c300185bSchristos.if ${MAKE_PROGRAM} == ${MAKE} 868753b7b6Stv.ifndef _NOWRAPPER 87d2809fcfSthorpej# Some systems have a small ARG_MAX. On such systems, prevent Make 88d2809fcfSthorpej# variables set on the command line from being exported in the 89d2809fcfSthorpej# environment (they will still be set in MAKEOVERRIDES). 90d2809fcfSthorpej.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD" 91d2809fcfSthorpej__noenvexport= -X 92d2809fcfSthorpej.endif 93d2809fcfSthorpejMAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS} 948753b7b6Stv.else 958753b7b6StvMAKE_ARGS+= _NOWRAPPER=1 968753b7b6Stv.endif 97c300185bSchristosBUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS} 98c300185bSchristos.else 99c300185bSchristos 100c300185bSchristos# gmake version of this puts MAKE_ARGS in the environment to be sure that 101c300185bSchristos# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and 102c300185bSchristos# fails. it also uses "env -i" to entirely clear out MAKEFLAGS. 103*cf4db277SlukemGMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/(^|.* )(-j ?[0-9][0-9]*).*/\2/W} 1044c66371fSrilligBUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS:N-*} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS} 105c300185bSchristos 106c300185bSchristos.endif 1078753b7b6Stv 1089fbd8888StvMAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q} 10971abcbf8Stv 110ccc4feafSlukem.if ${MAKEVERBOSE} < 2 1114c66371fSrilligMAKE_ARGS+= -s V=0 112c2a5a723Slukem.else 113c2a5a723SlukemMAKE_ARGS+= V=1 114ccc4feafSlukem.endif 115ccc4feafSlukem 116b5cd2489StvALL_TARGET?= all 117b5cd2489StvINSTALL_TARGET?=install 118b5cd2489Stv 11907a6a7e7StsutsuiBUILD_PLATFORM!= uname -srm | tr ' ()' '-' 120c300185bSchristosCONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi 121c300185bSchristos.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}" 122c300185bSchristosconfigure_cleanup: 123c300185bSchristos @mkdir build 2>/dev/null || true 124c300185bSchristos @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}") 125f70d5ee4Shans @(cd build && find . -name config.cache | xargs rm -f) 126c300185bSchristosconfigure_cleanup=configure_cleanup 127c300185bSchristos.endif 128c300185bSchristos 129c300185bSchristos.configure_done: ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup} 130b5cd2489Stv @mkdir build 2>/dev/null || true 1312fbd40c4Sjmc @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS}) 132c300185bSchristos @echo ${BUILD_PLATFORM} > $@ 133b5cd2489Stv 134b6ed0d75Stv# The .build_done timestamp is only updated if a file actually changes 135b6ed0d75Stv# in the build tree during "make all". This way, if nothing has changed, 136f134f3dcSlukem# a "make install MKUPDATE=yes" will do nothing. 137b6ed0d75Stv 138b5cd2489Stv.build_done: .configure_done 139c300185bSchristos @(cd build && ${BUILD_COMMAND} ${ALL_TARGET}) 1409fbd8888Stv @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \ 141fe9dd95fStv then touch $@; fi 142b5cd2489Stv 143c1f07893Sjmc.install_done! ${BUILD:D.build_done} 144c300185bSchristos @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET}) 145b5cd2489Stv @touch $@ 146b5cd2489Stv 147b5cd2489Stv# Mapping to standard targets. 148b5cd2489Stv 149b5cd2489Stv.if ${USETOOLS} == "yes" 150b5cd2489Stvrealall: .build_done 151b5cd2489Stvrealinstall: .install_done 152b5cd2489Stv.endif 153b5cd2489Stv 154b5cd2489Stvclean: clean.gnu 155b5cd2489Stvclean.gnu: 15684fafa3dSjmc -rm -r -f .*_done build 157b5cd2489Stv 158b5cd2489Stv.include <bsd.hostprog.mk> 159