From 8fe4f8f7a75f3f6d1fc52e31a6d25a112d4644fd Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Thu, 20 Apr 2023 10:05:43 -0700 Subject: [PATCH] Fix building host tools for host Several makefile depend on tools built for host. At least when using DIRDEPS_BUILD we can build these for the pseudo machine "host" to facilitate building on older host versions. Ideally we would build these tools in their own directories to avoid building more than needed. For now, setting an appropriate default for BTOOLSPATH will suffice Reviewed by: stevek Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D39708 --- bin/csh/Makefile | 5 ++++- bin/sh/Makefile | 7 +++++-- lib/ncurses/tinfo/Makefile | 13 +++++++++++++ share/mk/local.meta.sys.mk | 7 +++++++ share/syscons/scrnmaps/Makefile | 10 ++++++---- usr.bin/awk/Makefile | 2 ++ 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/bin/csh/Makefile b/bin/csh/Makefile index d5962670368..2d1edcf53a8 100644 --- a/bin/csh/Makefile +++ b/bin/csh/Makefile @@ -118,15 +118,18 @@ NLSSRCFILES_${catalog:C/.*://}!= cd ${NLSSRCDIR_${catalog:C/.*://}}; echo charse csh.1: tcsh.man cat ${.ALLSRC} > ${.TARGET} +.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no" build-tools: gethost +tc.defs.c: gethost DEPENDOBJS+= gethost gethost: gethost.c sh.err.h tc.const.h sh.h ${BUILD_TOOLS_META} @rm -f ${.TARGET} ${CC:N${CCACHE_BIN}} -o gethost ${LDFLAGS} ${CFLAGS:C/-DHAVE_ICONV//} \ ${TCSHDIR}/gethost.c +.endif -tc.defs.c: gethost ${TCSHDIR}/host.defs +tc.defs.c: ${TCSHDIR}/host.defs @rm -f ${.TARGET} @echo "/* Do not edit this file, make creates it */" > ${.TARGET} ${BTOOLSPATH:U.}/gethost ${TCSHDIR}/host.defs >> ${.TARGET} diff --git a/bin/sh/Makefile b/bin/sh/Makefile index c61094b0672..039da7309ad 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -39,15 +39,18 @@ CFLAGS+=-DSHELL -I. -I${.CURDIR} CLEANFILES+= mknodes mksyntax CLEANFILES+= ${GENSRCS} ${GENHDRS} +.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no" build-tools: mknodes mksyntax +DEPENDOBJS+= mknodes mksyntax +mknodes mksyntax: ${BUILD_TOOLS_META} +.endif + .ORDER: builtins.c builtins.h builtins.h: .NOMETA builtins.c builtins.h: mkbuiltins builtins.def sh ${.CURDIR}/mkbuiltins ${.CURDIR} -DEPENDOBJS+= mknodes mksyntax -mknodes mksyntax: ${BUILD_TOOLS_META} .ORDER: nodes.c nodes.h nodes.h: .NOMETA diff --git a/lib/ncurses/tinfo/Makefile b/lib/ncurses/tinfo/Makefile index fc4e4447562..2d251072acb 100644 --- a/lib/ncurses/tinfo/Makefile +++ b/lib/ncurses/tinfo/Makefile @@ -270,6 +270,11 @@ keys.list: MKkeys_list.sh Caps Caps-ncurses AWK=${AWK} sh ${NCURSES_DIR}/ncurses/tinfo/MKkeys_list.sh \ ${NCURSES_DIR}/include/Caps ${NCURSES_DIR}/include/Caps-ncurses | LC_ALL=C sort > keys.list +.if ${MK_DIRDEPS_BUILD} == "yes" && ${MACHINE} != "host" +# we need to override the default +BTOOLSPATH= ${HOST_OBJTOP}/${RELDIR:S,w$,,} +.endif +.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no" # Build tools DEPENDOBJS+= make_hash make_keys build-tools: make_hash make_keys @@ -280,6 +285,14 @@ make_keys: make_keys.c names.c ncurses_def.h ${HEADERS} ${BUILD_TOOLS_META} make_hash: make_hash.c hashsize.h ncurses_def.h ${HEADERS} ${BUILD_TOOLS_META} ${CC:N${CCACHE_BIN}} -o $@ ${CFLAGS} -DMAIN_PROGRAM \ ${NCURSES_DIR}/ncurses/tinfo/make_hash.c +.endif +.if ${MK_DIRDEPS_BUILD} == "yes" && ${MACHINE} != "host" +make_keys: ${BTOOLSPATH}/make_keys + ${LN:Uln} -sf ${.ALLSRC} ${.TARGET} + +make_hash: ${BTOOLSPATH}/make_hash + ${LN:Uln} -sf ${.ALLSRC} ${.TARGET} +.endif # ./configure generated MKterm.h.awk: MKterm.h.awk.in diff --git a/share/mk/local.meta.sys.mk b/share/mk/local.meta.sys.mk index 6b5ff5e9755..6d54d9c5881 100644 --- a/share/mk/local.meta.sys.mk +++ b/share/mk/local.meta.sys.mk @@ -210,12 +210,19 @@ TOOLSDIR?= ${HOST_OBJTOP}/tools .elif defined(STAGE_HOST_OBJTOP) TOOLSDIR?= ${STAGE_HOST_OBJTOP} .endif +.if ${MK_DIRDEPS_BUILD} == "yes" && ${MACHINE} != "host" +# ideally tools needed by makefiles like sh,csh,tinfo +# would be built in their own directories but for now +# this works well enough. +BTOOLSPATH= ${HOST_OBJTOP}/${RELDIR} +.else # Only define if it exists in case user didn't run bootstrap-tools. Otherwise # the tool will be built during the build. Building it assumes it is # TARGET==MACHINE. .if exists(${HOST_OBJTOP}/tools${.CURDIR}) BTOOLSPATH= ${HOST_OBJTOP}/tools${.CURDIR} .endif +.endif # Don't use the bootstrap tools logic on itself. .if ${.TARGETS:Mbootstrap-tools} == "" && \ diff --git a/share/syscons/scrnmaps/Makefile b/share/syscons/scrnmaps/Makefile index fb6bf59131b..f3b5ed273cd 100644 --- a/share/syscons/scrnmaps/Makefile +++ b/share/syscons/scrnmaps/Makefile @@ -14,16 +14,18 @@ CLEANFILES+= ${SCRMAPS_MK} ${SCRMAPS} FILES= ${SCRMAPS} FILESDIR= ${SHAREDIR}/syscons/scrnmaps +.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no" DEPENDOBJS+= ${SCRMAPS_MK} build-tools: ${SCRMAPS_MK} +${SCRMAPS_MK}: ${.TARGET:R} mkscrfil.c ${BUILD_TOOLS_META} + ${CC:N${CCACHE_BIN}} ${CFLAGS} -I${.CURDIR} -DFIL=\"${.TARGET:R}\" \ + ${LDFLAGS} -o ${.TARGET} ${.CURDIR}/mkscrfil.c +.endif + ${SCRMAPS}: ${.TARGET:R}.mk ${BTOOLSPATH:U.}/${.TARGET:R}.mk ${.TARGET:R}.tmp uuencode ${.TARGET:R}.tmp ${.TARGET:R} > ${.TARGET} rm -f ${.TARGET:R}.tmp -${SCRMAPS_MK}: ${.TARGET:R} mkscrfil.c ${BUILD_TOOLS_META} - ${CC:N${CCACHE_BIN}} ${CFLAGS} -I${.CURDIR} -DFIL=\"${.TARGET:R}\" \ - ${LDFLAGS} -o ${.TARGET} ${.CURDIR}/mkscrfil.c - .include diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile index 28212f75f7d..f604684804f 100644 --- a/usr.bin/awk/Makefile +++ b/usr.bin/awk/Makefile @@ -25,9 +25,11 @@ awkgram.tab.h: awkgram.h proctab.c: maketab awkgram.tab.h ${BTOOLSPATH:U.}/maketab awkgram.tab.h > proctab.c +.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no" DEPENDOBJS+= maketab build-tools: maketab maketab: awkgram.tab.h ${BUILD_TOOLS_META} +.endif HAS_TESTS= SUBDIR.${MK_TESTS}+= tests