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