# $NetBSD: Makefile.gnuhost,v 1.57 2025/05/25 06:06:57 rillig Exp $
#
# Rules used when building a GNU host package. Expects MODULE to be set.
#
# There's not a lot we can do to build reliably in the face of many
# available configuration options. To be as low-overhead as possible,
# we follow the following scheme:
#
# * Configuration is only re-run when an autoconf source file (such as
# "configure" or "config.sub") is changed.
#
# * "config.status" is run to rebuild Makefiles and .h files if an
# autoconf-parsed file (such as Makefile.in) is changed.
#
# * If MKUPDATE != "no", "make install" is only run if a build has happened
# since the last install in the current directory.
include <bsd.own.mk>
# Disable use of pre-compiled headers on Darwin.
BUILD_OSTYPE!= uname -s
HOST_COMPILER_CLANG!= if ${HOST_CC} --version | grep -q -s clang; then echo yes; else echo no; fi
if ${HOST_COMPILER_CLANG} == "yes"
HOST_CFLAGS+=-O2 -no-cpp-precomp
endif
MAKE_PROGRAM?= ${MAKE}
for i in 3 2
if exists(${.CURDIR}/../../external/gpl${i}/${MODULE}/dist)
GNUHOSTDIST?= ${.CURDIR}/../../external/gpl${i}/${MODULE}/dist
endif
endfor
# Do this "find" only if actually building something.
if (${USETOOLS} == "yes") && empty(.MAKEFLAGS:M-V*) && \
(make(all) || make(realall) || (!make(clean) && !make(cleandir) && !make(obj))) && \
!defined(_GNU_CFGSRC)
CONFIGURE_ARGS+=--prefix=${TOOLDIR}
if ${MKPIC} == "no"
CONFIGURE_ARGS+=--disable-shared
endif
if ${MAKEVERBOSE} == 0
CONFIGURE_ARGS+=--silent
endif
if ${MAKE_PROGRAM} == ${MAKE}
ifndef _NOWRAPPER
# Some systems have a small ARG_MAX. On such systems, prevent Make
# variables set on the command line from being exported in the
# environment (they will still be set in MAKEOVERRIDES).
if ${BUILD_OSTYPE} == "Darwin" || ${BUILD_OSTYPE} == "FreeBSD"
__noenvexport= -X
endif
MAKE_ARGS:= ${__noenvexport} -f ${.PARSEDIR}/Makefile.gnuwrap ${MAKE_ARGS}
else
MAKE_ARGS+= _NOWRAPPER=1
endif
BUILD_COMMAND= ${BUILD_ENV} ${MAKE} ${MAKE_ARGS}
else
# gmake version of this puts MAKE_ARGS in the environment to be sure that
# sub-gmake's get them, otherwise tools/gcc tries to build libgcc and
# fails. it also uses "env -i" to entirely clear out MAKEFLAGS.
GMAKE_J_ARGS?= ${MAKEFLAGS:[*]:M*-j*:C/(^|.* )(-j ?[0-9][0-9]*).*/\2/W}
BUILD_COMMAND= /usr/bin/env -i ${BUILD_ENV} ${MAKE_ARGS:N-*} ${TOOL_GMAKE} ${GMAKE_J_ARGS} -e ${MAKE_ARGS}
# The .build_done timestamp is only updated if a file actually changes
# in the build tree during "make all". This way, if nothing has changed,
# a "make install MKUPDATE=yes" will do nothing.
build_done: .configure_done
@${:D make}(cd build && ${BUILD_COMMAND} ${ALL_TARGET})
@if [ ! -f $@ ] || [ -n "$$(find build -type f -newer .build_done -print)" ]; \
then touch $@; fi