From 0815243c3937b61db8b5a10cc652900d4df4acb0 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 6 Oct 2012 20:01:05 +0000 Subject: [PATCH] Add support for bmake. This includes: 1. Don't do upgrade_checks when using bmake. As long as we have WITH_BMAKE, there's a bootstrap complication in ths respect. Avoid it. Make the necessary changes to have upgrade_checks work wth bmake anyway. 2. Remove the use of -E. It's not needed in our build because we use ?= for the respective variables, which means that we'll take the environment value (if any) anyway. 3. Properly declare phony targets as phony as bmake is a lot smarter (and thus agressive) about build avoidance. 4. Make sure CLEANFILES is complete and use it on .NOPATH. bmake is a lot smarter about build avoidance and should not find files we generate in the source tree. We should not have files in the repository we want to generate, but this is an easier way to cross this hurdle. 5. Have behavior under bmake the same as it is under make with respect to halting when sub-commands fail. Add "set -e" to compound commands so that bmake is informed when sub-commands fail. 6. Make sure crunchgen uses the same make as the rest of the build. This is important when the make utility isn't called make (but bmake for example). 7. While here, add support for using MAKEOBJDIR to set the object tree location. It's the second alternative bmake looks for when determining the actual object directory (= .OBJDIR). Submitted by: Simon Gerraty Submitted by: John Van Horne --- Makefile | 2 ++ Makefile.inc1 | 2 +- gnu/usr.bin/cc/cc_int/Makefile | 3 +++ gnu/usr.bin/cc/include/Makefile | 4 +--- kerberos5/Makefile | 2 +- kerberos5/tools/asn1_compile/Makefile | 2 +- kerberos5/tools/slc/Makefile | 2 +- lib/clang/include/Makefile | 4 +--- share/mk/bsd.crunchgen.mk | 2 ++ share/mk/bsd.dep.mk | 7 +++++-- share/mk/bsd.obj.mk | 7 +++++++ share/mk/bsd.subdir.mk | 4 ++-- share/mk/bsd.sys.mk | 15 +++++++++++++++ share/mk/sys.mk | 15 +++++++++++++++ tools/build/make_check/Makefile | 23 +++++++++++++++++++++-- usr.sbin/crunch/examples/Makefile | 6 +++--- 16 files changed, 81 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 1303e0ea18bd..6d070ee8417b 100644 --- a/Makefile +++ b/Makefile @@ -280,12 +280,14 @@ kernel: buildkernel installkernel # for building the world. # upgrade_checks: +.if !defined(.PARSEDIR) @if ! (cd ${.CURDIR}/tools/build/make_check && \ PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \ PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \ then \ (cd ${.CURDIR} && ${MAKE} make); \ fi +.endif # # Upgrade make(1) to the current version using the installed diff --git a/Makefile.inc1 b/Makefile.inc1 index 821416d1c649..a9b60886eb12 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -330,7 +330,7 @@ LIB32WMAKEENV+= MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \ LIB32WMAKE= ${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \ -DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \ - -DWITHOUT_HTML -DNO_CTF -DNO_LINT -ECC -ECXX -EAS -ELD \ + -DWITHOUT_HTML -DNO_CTF -DNO_LINT \ DESTDIR=${LIB32TMP} LIB32IMAKE= ${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS .endif diff --git a/gnu/usr.bin/cc/cc_int/Makefile b/gnu/usr.bin/cc/cc_int/Makefile index 7082c3ea4238..e6051e14e401 100644 --- a/gnu/usr.bin/cc/cc_int/Makefile +++ b/gnu/usr.bin/cc/cc_int/Makefile @@ -98,4 +98,7 @@ SRCS+= ${OBJS-all:R:S/$/.c/g} toplev.o: toplev.c ${CC} ${CFLAGS} -DTARGET_NAME=\"${GCC_TARGET}\" -c ${.IMPSRC} +# make sure we don't find .o's in ../cc_tools/ +CLEANFILES+= ${OBJS-all} + .include diff --git a/gnu/usr.bin/cc/include/Makefile b/gnu/usr.bin/cc/include/Makefile index 1807a4836b32..169826246bb0 100644 --- a/gnu/usr.bin/cc/include/Makefile +++ b/gnu/usr.bin/cc/include/Makefile @@ -21,6 +21,4 @@ mm_malloc.h: pmm_malloc.h @cp ${.ALLSRC} ${.TARGET} CLEANFILES+= mm_malloc.h -.include -.include -.include +.include diff --git a/kerberos5/Makefile b/kerberos5/Makefile index d87fa1682cb4..401957b32f25 100644 --- a/kerberos5/Makefile +++ b/kerberos5/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ -SUBDIR= doc lib libexec usr.bin usr.sbin +SUBDIR= doc lib libexec tools usr.bin usr.sbin # These are the programs which depend on Kerberos. KPROGS= lib/libpam \ diff --git a/kerberos5/tools/asn1_compile/Makefile b/kerberos5/tools/asn1_compile/Makefile index 94174c4e637b..194642136a0d 100644 --- a/kerberos5/tools/asn1_compile/Makefile +++ b/kerberos5/tools/asn1_compile/Makefile @@ -25,7 +25,7 @@ SRCS= \ CFLAGS+=-I${KRB5DIR}/lib/roken -I${KRB5DIR}/lib/asn1 -I. -CLEANFILES= roken.h +CLEANFILES= roken.h lex.c parse.c roken.h: make-roken > ${.TARGET} diff --git a/kerberos5/tools/slc/Makefile b/kerberos5/tools/slc/Makefile index 6e909d97761f..d1b752f46405 100644 --- a/kerberos5/tools/slc/Makefile +++ b/kerberos5/tools/slc/Makefile @@ -12,7 +12,7 @@ SRCS= roken.h \ CFLAGS+=-I${KRB5DIR}/lib/roken -I${KRB5DIR}/lib/sl -I${KRB5DIR}/lib/vers -I. -CLEANFILES= roken.h +CLEANFILES= roken.h slc-gram.c slc-lex.c roken.h: ${MAKE_ROKEN} > ${.TARGET} diff --git a/lib/clang/include/Makefile b/lib/clang/include/Makefile index 9b2670a2f35d..93d91c7dba80 100644 --- a/lib/clang/include/Makefile +++ b/lib/clang/include/Makefile @@ -30,6 +30,4 @@ INCS= altivec.h \ xmmintrin.h \ xopintrin.h -.include -.include -.include +.include diff --git a/share/mk/bsd.crunchgen.mk b/share/mk/bsd.crunchgen.mk index 80d337f8b160..95f1aa3be03d 100644 --- a/share/mk/bsd.crunchgen.mk +++ b/share/mk/bsd.crunchgen.mk @@ -38,6 +38,8 @@ OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache CRUNCHOBJS= ${.OBJDIR} .if defined(MAKEOBJDIRPREFIX) CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} +.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != "" +CANONICALOBJDIR:=${MAKEOBJDIR} .else CANONICALOBJDIR:= /usr/obj${.CURDIR} .endif diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk index 5e4ec0b3086e..deac736c2d37 100644 --- a/share/mk/bsd.dep.mk +++ b/share/mk/bsd.dep.mk @@ -102,8 +102,8 @@ ${_YC} y.tab.h: ${_YSRC} CLEANFILES+= y.tab.c y.tab.h .elif !empty(YFLAGS:M-d) .for _YH in ${_YC:R}.h -.ORDER: ${_YC} ${_YH} -${_YC} ${_YH}: ${_YSRC} +${_YH}: ${_YC} +${_YC}: ${_YSRC} ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} SRCS+= ${_YH} CLEANFILES+= ${_YH} @@ -123,6 +123,9 @@ ${_YC:R}.o: ${_YC} .if defined(SRCS) depend: beforedepend ${DEPENDFILE} afterdepend +# Tell bmake not to look for generated files via .PATH +.NOPATH: ${DEPENDFILE} + # Different types of sources are compiled with slightly different flags. # Split up the sources, and filter out headers and non-applicable flags. MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \ diff --git a/share/mk/bsd.obj.mk b/share/mk/bsd.obj.mk index bd8f2aabc218..634261eba594 100644 --- a/share/mk/bsd.obj.mk +++ b/share/mk/bsd.obj.mk @@ -44,6 +44,8 @@ ____: .if defined(MAKEOBJDIRPREFIX) CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} +.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != "" +CANONICALOBJDIR:=${MAKEOBJDIR} .else CANONICALOBJDIR:=/usr/obj${.CURDIR} .endif @@ -116,6 +118,11 @@ cleanobj: clean cleandepend .endif @if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi +# Tell bmake not to look for generated files via .PATH +.if !empty(CLEANFILES) +.NOPATH: ${CLEANFILES} +.endif + .if !target(clean) clean: .if defined(CLEANFILES) && !empty(CLEANFILES) diff --git a/share/mk/bsd.subdir.mk b/share/mk/bsd.subdir.mk index dc5af72ff175..a66ab9bf9fce 100644 --- a/share/mk/bsd.subdir.mk +++ b/share/mk/bsd.subdir.mk @@ -42,7 +42,7 @@ distribute: _SUBDIR: .USE .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) - @${_+_}for entry in ${SUBDIR}; do \ + @${_+_}set -e; for entry in ${SUBDIR}; do \ if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:realinstall=install})"; \ edir=$${entry}.${MACHINE_ARCH}; \ @@ -79,7 +79,7 @@ ${__stage}${__target}: _SUBDIR .endif .endfor ${__target}: - ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target} + ${_+_}set -e; cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target} .endfor .if !target(install) diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index cc752a26804a..847e571e0d17 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -126,3 +126,18 @@ CFLAGS+= ${SSP_CFLAGS} # Allow user-specified additional warning flags CFLAGS+= ${CWARNFLAGS} + + +# Tell bmake not to mistake standard targets for things to be searched for +# or expect to ever be up-to-date. +PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ + beforelinking build build-tools buildfiles buildincludes \ + checkdpadd clean cleandepend cleandir cleanobj configure \ + depend dependall distclean distribute exe extract fetch \ + html includes install installfiles installincludes lint \ + obj objlink objs objwarn patch realall realdepend \ + realinstall regress subdir-all subdir-depend subdir-install \ + tags whereobj + +.PHONY: ${PHONY_NOTMAIN} +.NOTMAIN: ${PHONY_NOTMAIN} diff --git a/share/mk/sys.mk b/share/mk/sys.mk index 3c43ff4c21a2..0e8dc95acb90 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -16,6 +16,10 @@ unix ?= We run FreeBSD, not UNIX. MACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/} .endif +# Set any local definitions first. Place this early, but it needs +# MACHINE_CPUARCH to be defined. +.sinclude + # If the special target .POSIX appears (without prerequisites or # commands) before the first noncomment line in the makefile, make shall # process the makefile as specified by the Posix 1003.2 specification. @@ -324,8 +328,19 @@ SHELL= ${__MAKE_SHELL} # XXX hint for bsd.port.mk OBJFORMAT?= elf +# Tell bmake to expand -V VAR by default +.MAKE.EXPAND_VARIABLES= yes + +.if !defined(.PARSEDIR) +# We are not bmake, which is more aggressive about searching .PATH +# It is sometime necessary to curb its enthusiasm with .NOPATH +# The following allows us to quietly ignore .NOPATH when not using bmake. +.NOTMAIN: .NOPATH +.NOPATH: + # Toggle on warnings .WARN: dirsyntax +.endif .endif diff --git a/tools/build/make_check/Makefile b/tools/build/make_check/Makefile index 346b4bb06856..3a0f6ad2a956 100644 --- a/tools/build/make_check/Makefile +++ b/tools/build/make_check/Makefile @@ -56,8 +56,10 @@ all: @echo "ok 14 shell # Test shell detected no regression." @${SMAKE} shell_1 || ${SMAKE} failure @echo "ok 15 shell_1 # Test shell_1 detected no regression." +.if !defined(.PARSEDIR) @${SMAKE} shell_2 || ${SMAKE} failure @echo "ok 16 shell_2 # Test shell_2 detected no regression." +.endif .if make(C_check) C_check: @@ -92,17 +94,34 @@ lhs_expn: # to determine its value; that was not always the case. .undef notdef notdef: -.if defined(notdef) && ${notdef:U} +.if defined(notdef) && ${notdef:M/} .endif .endif .if make(modifiers) -# See if make(1) supports the C modifier. +.if defined(.PARSEDIR) +# check if bmake can expand plain variables +.MAKE.EXPAND_VARIABLES= yes +x!= ${SMAKE} -V .CURDIR:H modifiers: +.if ${.CURDIR:H} != "$x" + @false +.endif +.else +# See if make(1) supports the C modifier. +modifiers: dollarV @if ${SMAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \ grep -q "Unknown modifier 'C'"; then \ false; \ fi + +# check that make -V '${VAR}' works +V_expn != V_OK=ok ${SMAKE} -r -f /dev/null -V '$${V_OK}' +dollarV: +.if ${V_expn} == "" + @false +.endif +.endif .endif .if make(arith_expr) diff --git a/usr.sbin/crunch/examples/Makefile b/usr.sbin/crunch/examples/Makefile index 6dd49acc1a15..120830196c66 100644 --- a/usr.sbin/crunch/examples/Makefile +++ b/usr.sbin/crunch/examples/Makefile @@ -19,14 +19,14 @@ all: $(CRUNCHED) exe: $(CRUNCHED) $(OUTPUTS): $(CONF) - crunchgen ${.CURDIR}/$(CONF) + MAKE=${MAKE} crunchgen ${.CURDIR}/$(CONF) $(CRUNCHED): $(OUTPUTS) submake submake: - make -f $(OUTMK) + ${MAKE} -f $(OUTMK) objs: - make -f $(OUTMK) objs + ${MAKE} -f $(OUTMK) objs cleandir: rm -f $(CLEANDIRFILES)