1# $NetBSD: Makefile.gnuhost,v 1.42 2013/08/13 20:41:25 drochner 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 27GNUHOSTDIST?= ${.CURDIR}/../../gnu/dist/${MODULE} 28 29.if defined(__MINIX) 30# AL - MINIX /usr/src does not have the sources for the GNU utilities 31# in-tree (they are much bigger than Minix itself!) So to successfully 32# use them while cross-compiling, we have to fetch them. The success of 33# that operation is indicated by the presence of a .gitignore file in 34# the corresponding ${.CURDIR}, which also conveniently hides from git. 35.if exists(${GNUHOSTDIST:H}/fetch.sh) 36${GNUHOSTDIST:H}/.gitignore: ${GNUHOSTDIST:H}/fetch.sh 37 SED=${TOOL_SED} ${HOST_SH} ${GNUHOSTDIST:H}/fetch.sh 38 @test -e ${GNUHOSTDIST}/configure 39 @echo "${MODULE:U${.CURDIR:T}:C,gcc[0-9]*,gcc,:C,gmake*,make,}-*.tar.*z*" >> $@ 40 @echo ${GNUHOSTDIST:T} >> $@ 41_gnu_get_src=${GNUHOSTDIST:H}/.gitignore 42.endif # exists(GNUHOSTDIST:H/fetch.sh) on MINIX 43 44# AL - Special target for MINIX, reset the source tree as pristine 45.if ${CLEANFETCHED:Uno} == "yes" && exists(${GNUHOSTDIST:H}/fetch.sh) 46cleandir: clean_gnu_src 47clean_gnu_src: 48 -rm -r -f ${GNUHOSTDIST} ${GNUHOSTDIST:H}/.gitignore 49# XXX CHECKME: could have used the content of .gitignore as well? 50.endif # CLEANFETCHED == yes 51.endif # defined(__MINIX) 52 53FIND_ARGS+= \! \( -type d \( \ 54 -name 'CVS' -o \ 55 -name 'config' -o \ 56 -name 'doc' -o \ 57 -name 'po' -o \ 58 -name 'nbsd.mt' -o \ 59 -name 'tests*' \ 60 \) -prune \) 61 62# Do this "find" only if actually building something. 63# AL - ... and on MINIX, if the source has already being fetched 64.if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \ 65 (make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \ 66 !defined(_GNU_CFGSRC) && exists(${GNUHOSTDIST}/configure) 67 68_GNU_CFGSRC!= find ${GNUHOSTDIST} ${FIND_ARGS} \ 69 -type f \( -name 'config*' -o -name '*.in' \) -print 70.MAKEOVERRIDES+= _GNU_CFGSRC 71.endif 72 73CONFIGURE_ENV+= \ 74 AR=${HOST_AR:Q} \ 75 AWK=${TOOL_AWK:Q} \ 76 CC=${HOST_CC:Q} \ 77 CFLAGS=${HOST_CFLAGS:Q} \ 78 CONFIG_SHELL=${HOST_SH:Q} \ 79 CPPFLAGS=${HOST_CPPFLAGS:Q} \ 80 CXX=${HOST_CXX:Q} \ 81 CXXFLAGS=${HOST_CXXFLAGS:Q} \ 82 INSTALL=${HOST_INSTALL_FILE:Q} \ 83 LDFLAGS=${HOST_LDFLAGS:Q} \ 84 LEX=${LEX:Q} \ 85 M4=${TOOL_M4:Q} \ 86 MAKE=${MAKE_PROGRAM:Q} \ 87 PATH="${TOOLDIR}/bin:$$PATH" \ 88 RANLIB=${HOST_RANLIB:Q} \ 89 YACC=${YACC:Q} 90 91BUILD_ENV+= ${CONFIGURE_ENV} 92 93CONFIGURE_ARGS+=--prefix=${TOOLDIR} 94.if ${MKPIC} == "no" 95CONFIGURE_ARGS+=--disable-shared 96.endif 97 98.if ${MAKE_PROGRAM} == ${MAKE} 99.ifndef _NOWRAPPER 100# Some systems have a small ARG_MAX. On such systems, prevent Make 101# variables set on the command line from being exported in the 102# environment (they will still be set in MAKEOVERRIDES). 103.if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD" 104__noenvexport= -X 105.endif 106MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS} 107.else 108MAKE_ARGS+= _NOWRAPPER=1 109.endif 110BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS} 111.else 112 113# gmake version of this puts MAKE_ARGS in the environment to be sure that 114# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and 115# fails. it also uses "env -i" to entirely clear out MAKEFLAGS. 116GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/.*(-j ?[0-9]*).*/\1/W} 117BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS} 118 119.endif 120 121MAKE_ARGS+= BISON=true DESTDIR= INSTALL=${HOST_INSTALL_FILE:Q} 122 123ALL_TARGET?= all 124INSTALL_TARGET?=install 125 126BUILD_PLATFORM!= uname -srm | tr ' ()' '-' 127CONFIGURE_PLATFORM!= if [ -s .configure_done ]; then cat .configure_done; else echo none; fi 128.if "${BUILD_PLATFORM}" != "${CONFIGURE_PLATFORM}" 129configure_cleanup: 130 @mkdir build 2>/dev/null || true 131 @(echo "Cleaning stale cache files ${BUILD_PLATFORM} != ${CONFIGURE_PLATFORM}") 132 @(cd build && find . -name config.cache | xargs rm -f) 133configure_cleanup=configure_cleanup 134.endif 135 136# AL For MINIX, fetch the source if not there 137.configure_done: ${_gnu_get_src} .WAIT ${_GNU_CFGSRC} ${.CURDIR}/Makefile ${configure_cleanup} 138 @mkdir build 2>/dev/null || true 139 @(cd build && ${CONFIGURE_ENV} ${HOST_SH} ${GNUHOSTDIST}/configure ${CONFIGURE_ARGS}) 140 @echo ${BUILD_PLATFORM} > $@ 141 142# The .build_done timestamp is only updated if a file actually changes 143# in the build tree during "make all". This way, if nothing has changed, 144# a "make install MKUPDATE=yes" will do nothing. 145 146.build_done: .configure_done 147 @(cd build && ${BUILD_COMMAND} ${ALL_TARGET}) 148 @if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \ 149 then touch $@; fi 150 151.install_done! ${BUILD:D.build_done} 152 @(cd ${.OBJDIR}/build && ${BUILD_COMMAND} ${INSTALL_TARGET}) 153 @touch $@ 154 155# Mapping to standard targets. 156 157.if ${USETOOLS} == "yes" 158realall: .build_done 159realinstall: .install_done 160.endif 161 162clean: clean.gnu 163clean.gnu: 164 -rm -r -f .*_done build 165 166.include <bsd.hostprog.mk> 167