From 46fe92eefd7311e899ade7e20bf4962a4d37a6aa Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Thu, 21 Nov 2013 13:34:06 +0100 Subject: [PATCH 1/4] update to bmake-20131001. --- contrib/bmake/ChangeLog | 193 +++++ contrib/bmake/FILES | 55 +- contrib/bmake/Makefile | 221 ++++++ contrib/bmake/Makefile.config.in | 16 + contrib/bmake/Makefile.in | 190 ----- contrib/bmake/bmake.1 | 124 +++- contrib/bmake/bmake.cat1 | 1414 ++---------------------------------- contrib/bmake/boot-strap | 270 ++++--- contrib/bmake/bsd.after-import.mk | 30 +- contrib/bmake/compat.c | 24 +- contrib/bmake/cond.c | 37 +- contrib/bmake/configure | 35 +- contrib/bmake/configure.in | 21 +- contrib/bmake/dir.c | 15 +- contrib/bmake/job.c | 176 +++-- contrib/bmake/job.h | 4 +- contrib/bmake/main.c | 373 ++++------ contrib/bmake/make-bootstrap.sh.in | 2 +- contrib/bmake/make.1 | 141 +++- contrib/bmake/make.c | 10 +- contrib/bmake/make.h | 13 +- contrib/bmake/makefile.in | 14 + contrib/bmake/meta.c | 177 +++-- contrib/bmake/meta.h | 5 +- contrib/bmake/mk/ChangeLog | 758 +++++++++++++++++++ contrib/bmake/mk/FILES | 61 ++ contrib/bmake/mk/README | 401 ++++++++++ contrib/bmake/mk/auto.dep.mk | 64 ++ contrib/bmake/mk/auto.obj.mk | 56 ++ contrib/bmake/mk/autoconf.mk | 78 ++ contrib/bmake/mk/autodep.mk | 216 ++++++ contrib/bmake/mk/dep.mk | 133 ++++ contrib/bmake/mk/dirdeps.mk | 500 +++++++++++++ contrib/bmake/mk/doc.mk | 63 ++ contrib/bmake/mk/dpadd.mk | 196 +++++ contrib/bmake/mk/final.mk | 14 + contrib/bmake/mk/gendirdeps.mk | 337 +++++++++ contrib/bmake/mk/host-target.mk | 31 + contrib/bmake/mk/host.libnames.mk | 29 + contrib/bmake/mk/inc.mk | 35 + contrib/bmake/mk/init.mk | 50 ++ contrib/bmake/mk/install-mk | 185 +++++ contrib/bmake/mk/install-new.mk | 53 ++ contrib/bmake/mk/java.mk | 97 +++ contrib/bmake/mk/lib.mk | 602 +++++++++++++++ contrib/bmake/mk/libnames.mk | 22 + contrib/bmake/mk/libs.mk | 93 +++ contrib/bmake/mk/links.mk | 75 ++ contrib/bmake/mk/man.mk | 137 ++++ contrib/bmake/mk/meta.autodep.mk | 262 +++++++ contrib/bmake/mk/meta.stage.mk | 244 +++++++ contrib/bmake/mk/meta.subdir.mk | 79 ++ contrib/bmake/mk/meta.sys.mk | 139 ++++ contrib/bmake/mk/meta2deps.py | 677 +++++++++++++++++ contrib/bmake/mk/meta2deps.sh | 379 ++++++++++ contrib/bmake/mk/mk-files.txt | 467 ++++++++++++ contrib/bmake/mk/nls.mk | 48 ++ contrib/bmake/mk/obj.mk | 113 +++ contrib/bmake/mk/options.mk | 59 ++ contrib/bmake/mk/own.mk | 245 +++++++ contrib/bmake/mk/prlist.mk | 36 + contrib/bmake/mk/prog.mk | 228 ++++++ contrib/bmake/mk/progs.mk | 102 +++ contrib/bmake/mk/rst2htm.mk | 43 ++ contrib/bmake/mk/scripts.mk | 52 ++ contrib/bmake/mk/srctop.mk | 66 ++ contrib/bmake/mk/stage-install.sh | 98 +++ contrib/bmake/mk/subdir.mk | 99 +++ contrib/bmake/mk/sys.clean-env.mk | 119 +++ contrib/bmake/mk/sys.dependfile.mk | 51 ++ contrib/bmake/mk/sys.mk | 199 +++++ contrib/bmake/mk/sys/AIX.mk | 197 +++++ contrib/bmake/mk/sys/Darwin.mk | 220 ++++++ contrib/bmake/mk/sys/Generic.mk | 208 ++++++ contrib/bmake/mk/sys/HP-UX.mk | 237 ++++++ contrib/bmake/mk/sys/IRIX.mk | 199 +++++ contrib/bmake/mk/sys/Linux.mk | 200 +++++ contrib/bmake/mk/sys/NetBSD.mk | 234 ++++++ contrib/bmake/mk/sys/OSF1.mk | 211 ++++++ contrib/bmake/mk/sys/OpenBSD.mk | 209 ++++++ contrib/bmake/mk/sys/SunOS.mk | 232 ++++++ contrib/bmake/mk/sys/UnixWare.mk | 254 +++++++ contrib/bmake/mk/target-flags.mk | 62 ++ contrib/bmake/mk/warnings.mk | 148 ++++ contrib/bmake/mk/yacc.mk | 57 ++ contrib/bmake/parse.c | 118 +-- contrib/bmake/realpath.c | 77 +- contrib/bmake/suff.c | 191 ++--- contrib/bmake/var.c | 132 ++-- 89 files changed, 12429 insertions(+), 2408 deletions(-) create mode 100644 contrib/bmake/Makefile create mode 100644 contrib/bmake/Makefile.config.in delete mode 100644 contrib/bmake/Makefile.in create mode 100644 contrib/bmake/makefile.in create mode 100644 contrib/bmake/mk/ChangeLog create mode 100644 contrib/bmake/mk/FILES create mode 100644 contrib/bmake/mk/README create mode 100644 contrib/bmake/mk/auto.dep.mk create mode 100644 contrib/bmake/mk/auto.obj.mk create mode 100644 contrib/bmake/mk/autoconf.mk create mode 100644 contrib/bmake/mk/autodep.mk create mode 100644 contrib/bmake/mk/dep.mk create mode 100644 contrib/bmake/mk/dirdeps.mk create mode 100644 contrib/bmake/mk/doc.mk create mode 100644 contrib/bmake/mk/dpadd.mk create mode 100644 contrib/bmake/mk/final.mk create mode 100644 contrib/bmake/mk/gendirdeps.mk create mode 100644 contrib/bmake/mk/host-target.mk create mode 100644 contrib/bmake/mk/host.libnames.mk create mode 100644 contrib/bmake/mk/inc.mk create mode 100644 contrib/bmake/mk/init.mk create mode 100644 contrib/bmake/mk/install-mk create mode 100644 contrib/bmake/mk/install-new.mk create mode 100644 contrib/bmake/mk/java.mk create mode 100644 contrib/bmake/mk/lib.mk create mode 100644 contrib/bmake/mk/libnames.mk create mode 100644 contrib/bmake/mk/libs.mk create mode 100644 contrib/bmake/mk/links.mk create mode 100644 contrib/bmake/mk/man.mk create mode 100644 contrib/bmake/mk/meta.autodep.mk create mode 100644 contrib/bmake/mk/meta.stage.mk create mode 100644 contrib/bmake/mk/meta.subdir.mk create mode 100644 contrib/bmake/mk/meta.sys.mk create mode 100755 contrib/bmake/mk/meta2deps.py create mode 100755 contrib/bmake/mk/meta2deps.sh create mode 100644 contrib/bmake/mk/mk-files.txt create mode 100644 contrib/bmake/mk/nls.mk create mode 100644 contrib/bmake/mk/obj.mk create mode 100644 contrib/bmake/mk/options.mk create mode 100644 contrib/bmake/mk/own.mk create mode 100644 contrib/bmake/mk/prlist.mk create mode 100644 contrib/bmake/mk/prog.mk create mode 100644 contrib/bmake/mk/progs.mk create mode 100644 contrib/bmake/mk/rst2htm.mk create mode 100644 contrib/bmake/mk/scripts.mk create mode 100644 contrib/bmake/mk/srctop.mk create mode 100755 contrib/bmake/mk/stage-install.sh create mode 100644 contrib/bmake/mk/subdir.mk create mode 100644 contrib/bmake/mk/sys.clean-env.mk create mode 100644 contrib/bmake/mk/sys.dependfile.mk create mode 100644 contrib/bmake/mk/sys.mk create mode 100644 contrib/bmake/mk/sys/AIX.mk create mode 100644 contrib/bmake/mk/sys/Darwin.mk create mode 100644 contrib/bmake/mk/sys/Generic.mk create mode 100644 contrib/bmake/mk/sys/HP-UX.mk create mode 100644 contrib/bmake/mk/sys/IRIX.mk create mode 100644 contrib/bmake/mk/sys/Linux.mk create mode 100644 contrib/bmake/mk/sys/NetBSD.mk create mode 100644 contrib/bmake/mk/sys/OSF1.mk create mode 100644 contrib/bmake/mk/sys/OpenBSD.mk create mode 100644 contrib/bmake/mk/sys/SunOS.mk create mode 100644 contrib/bmake/mk/sys/UnixWare.mk create mode 100644 contrib/bmake/mk/target-flags.mk create mode 100644 contrib/bmake/mk/warnings.mk create mode 100644 contrib/bmake/mk/yacc.mk diff --git a/contrib/bmake/ChangeLog b/contrib/bmake/ChangeLog index 933e435..b68a6e9 100644 --- a/contrib/bmake/ChangeLog +++ b/contrib/bmake/ChangeLog @@ -1,3 +1,196 @@ +2013-10-01 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20131001 + Merge with NetBSD make, pick up + o main.c: for NATIVE build sysctl to get MACHINE_ARCH from + hw.machine_arch if necessary. + o meta.c: meta_oodate - need to look at src of Link and target + of Move as well. + * main.c: check that CTL_HW and HW_MACHINE_ARCH exist. + provide __arraycount() if needed. + +2013-09-04 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130904 + Merge with NetBSD make, pick up + o Add VAR_INTERNAL context, so that internal setting of + MAKEFILE does not override value set by makefiles. + +2013-09-02 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130902 + Merge with NetBSD make, pick up + o CompatRunCommand: only apply shellErrFlag when errCheck is true + +2013-08-28 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130828 + Merge with NetBSD make, pick up + o Fix VAR :sh = syntax from Will Andrews at freebsd.org + o Call Job_SetPrefix() from Job_Init() so makefiles have + opportunity to set .MAKE.JOB.PREFIX + +2013-07-30 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130730 + Merge with NetBSD make, pick up + o Allow suppression of --- job -- tokens by setting + .MAKE.JOB.PREFIX empty. + +2013-07-16 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130716 + Merge with NetBSD make, pick up + o number of gmake compatability tweaks + -w for gmake style entering/leaving messages + if .MAKE.LEVEL > 0 indicate it in progname "make[1]" etc. + handle MAKEFLAGS containing only letters. + o when overriding a GLOBAL variable on the command line, + delete it from GLOBAL context so -V doesn't show the wrong + value. + +2013-07-06 Simon J. Gerraty + + * configure.in: We don't need MAKE_LEVEL_SAFE anymore. + + * Makefile (MAKE_VERSION): 20130706 + Merge with NetBSD make, pick up + o Shell_Init(): export shellErrFlag if commandShell hasErrCtl is + true so that CompatRunCommand() can use it, to ensure + consistent behavior with jobs mode. + o use MAKE_LEVEL_ENV to define the variable to propagate + .MAKE.LEVEL - currently set to MAKELEVEL (same as gmake). + o meta.c: use .MAKE.META.IGNORE_PATHS to allow customization of + paths to ignore. + +2013-06-04 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130604 + Merge with NetBSD make, pick up + o job.c: JobCreatePipe: do fcntl() after any tweaking of fd's + to avoid leaking descriptors. + +2013-05-28 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130528 + Merge with NetBSD make, pick up + o var.c: cleanup some left-overs in VarHash() + +2013-05-20 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130520 + generate manifest from component FILES rather than have to + update FILES when mk/FILES changes. + +2013-05-18 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130518 + Merge with NetBSD make, pick up + o suff.c: don't skip all processsing for .PHONY targets + else wildcard srcs do not get expanded. + o var.c: expand name of variable to delete if necessary. + +2013-03-30 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130330 + Merge with NetBSD make, pick up + o meta.c: refine the handling of .OODATE in commands. + Rather than suppress command comparison for the entire script + as though .NOMETA_CMP had been used, only suppress it for the + one command line. + This allows something like ${.OODATE:M.NOMETA_CMP} to be used to + suppress comparison of a command without otherwise affecting it. + o make.1: document that + +2013-03-22 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130321 + yes, not quite right but its a cooler number. + Merge with NetBSD make, pick up + o parse.c: fix ParseGmakeExport to be portable + and add a unit-test. + * meta.c: call meta_init() before makefiles are read and if built + with filemon support set .MAKE.PATH_FILEMON to _PATH_FILEMON + this let's makefiles test for support. + Call meta_mode_init() to process .MAKE.MODE. + +2013-03-13 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130305 + Merge with NetBSD make, pick up + o run .STALE: target when a dependency from .depend is missing. + o job.c: add Job_RunTarget() for the above and .BEGIN + +2013-03-03 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130303 + Merge with NetBSD make, pick up + o main.c: set .MAKE.OS to utsname.sysname + o job.c: more checks for read and poll errors + o var.c: lose VarChangeCase() saves 4% time + +2013-03-02 Simon J. Gerraty + + * boot-strap: remove MAKEOBJDIRPREFIX from environment since we + want to use MAKEOBJDIR + +2013-01-27 Simon J. Gerraty + + * Merge with NetBSD make, pick up + o make.1: more info on how shell commands are handled. + o job.c,main.c: detect write errors to job pipes. + +2013-01-25 Simon J. Gerraty + + * Makefile (MAKE_VERSION): 20130123 + Merge with NetBSD make, pick up + o meta.c: if script uses .OODATE and meta_oodate() decides + rebuild is needed, .OODATE will be empty - set it to .ALLSRC. + o var.c: in debug output indicate which variabale modifiers + apply to. + o remove Check_Cwd logic the makefiles have been fixed. + +2012-12-12 Simon J. Gerraty + + * makefile.in: add a simple makefile for folk who insist on + ./configure; make; make install + it just runs boot-strap + * include mk/* to accommodate the above + * boot-strap: re-work to accommodate the above + mksrc defaults to $Mydir/mk + allow op={configure,build,install,clean,all} + add options to facilitate install + * Makefile.config.in: just the bits set by configure + * Makefile: bump version to 20121212 + abandon Makefile.in (NetBSD Makefile) + leverage mk/* instead + * configure.in: ensure srcdir is absolute + +2012-11-11 Simon J. Gerraty + + * Makefile.in (MAKE_VERSION): 20121111 + fix generation of bmake.cat1 + +2012-11-09 Simon J. Gerraty + + * Makefile.in (MAKE_VERSION): 20121109 + Merge with NetBSD make, pick up + o make.c: MakeBuildChild: return 0 so search continues if a + .ORDER dependency is detected. + o unit-tests/order: test the above + +2012-11-02 Simon J. Gerraty + + * Makefile.in (MAKE_VERSION): 20121102 + Merge with NetBSD make, pick up + o cond.c: allow cond_state[] to grow. + In meta mode with a very large tree, we can hit the limit + while processing dirdeps. + +2012-10-25 Simon J. Gerraty + + * Makefile.in: we need to use ${srcdir} not ${.CURDIR} + 2012-10-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121010 diff --git a/contrib/bmake/FILES b/contrib/bmake/FILES index 397d3a2..d4b5dca 100644 --- a/contrib/bmake/FILES +++ b/contrib/bmake/FILES @@ -1,27 +1,26 @@ -FILES ChangeLog -bmake.cat1 -boot-strap -bsd.after-import.mk -os.sh -Makefile.in +FILES +Makefile +Makefile.config.in PSD.doc/Makefile PSD.doc/tutorial.ms README +aclocal.m4 arch.c +bmake.1 +bmake.cat1 +boot-strap +bsd.after-import.mk buf.c buf.h compat.c cond.c -make-conf.h -make_malloc.c -make_malloc.h config.h.in configure -aclocal.m4 configure.in dir.c dir.h +dirname.c find_lib.sh for.c getopt.c @@ -30,16 +29,6 @@ hash.h install-sh job.c job.h -meta.c -meta.h -dirname.c -realpath.c -strlcpy.c -strlist.c -strlist.h -stresep.c -trace.c -trace.h lst.h lst.lib/Makefile lst.lib/lstAppend.c @@ -72,26 +61,36 @@ lst.lib/lstReplace.c lst.lib/lstSucc.c machine.sh main.c +make-bootstrap.sh.in +make-conf.h make.1 -bmake.1 make.c make.h -make-bootstrap.sh.in +make_malloc.c +make_malloc.h +makefile.in +meta.c +meta.h missing/sys/cdefs.h mkdeps.sh nonints.h +os.sh parse.c pathnames.h ranlib.h +realpath.c setenv.c sigcompat.c sprite.h str.c +stresep.c +strlcpy.c +strlist.c +strlist.h suff.c targ.c -util.c -var.c -wait.h +trace.c +trace.h unit-tests/Makefile.in unit-tests/comment unit-tests/cond1 @@ -100,6 +99,7 @@ unit-tests/dotwait unit-tests/error unit-tests/export unit-tests/export-all +unit-tests/export-env unit-tests/forloop unit-tests/forsubst unit-tests/hash @@ -110,12 +110,17 @@ unit-tests/modmisc unit-tests/modorder unit-tests/modts unit-tests/modword +unit-tests/order unit-tests/phony-end unit-tests/posix unit-tests/qequals +unit-tests/sunshcmd unit-tests/sysv unit-tests/ternary unit-tests/test.exp unit-tests/unexport unit-tests/unexport-env unit-tests/varcmd +util.c +var.c +wait.h diff --git a/contrib/bmake/Makefile b/contrib/bmake/Makefile new file mode 100644 index 0000000..2ee2bf6 --- /dev/null +++ b/contrib/bmake/Makefile @@ -0,0 +1,221 @@ +# $Id: Makefile,v 1.21 2013/10/01 15:44:05 sjg Exp $ + +# Base version on src date +MAKE_VERSION= 20131001 + +PROG= bmake + +SRCS= \ + arch.c \ + buf.c \ + compat.c \ + cond.c \ + dir.c \ + for.c \ + hash.c \ + job.c \ + main.c \ + make.c \ + make_malloc.c \ + meta.c \ + parse.c \ + str.c \ + strlist.c \ + suff.c \ + targ.c \ + trace.c \ + util.c \ + var.c + +# from lst.lib/ +SRCS+= \ + lstAppend.c \ + lstAtEnd.c \ + lstAtFront.c \ + lstClose.c \ + lstConcat.c \ + lstDatum.c \ + lstDeQueue.c \ + lstDestroy.c \ + lstDupl.c \ + lstEnQueue.c \ + lstFind.c \ + lstFindFrom.c \ + lstFirst.c \ + lstForEach.c \ + lstForEachFrom.c \ + lstInit.c \ + lstInsert.c \ + lstIsAtEnd.c \ + lstIsEmpty.c \ + lstLast.c \ + lstMember.c \ + lstNext.c \ + lstOpen.c \ + lstPrev.c \ + lstRemove.c \ + lstReplace.c \ + lstSucc.c + +# this file gets generated by configure +.-include "Makefile.config" + +.if !empty(LIBOBJS) +SRCS+= ${LIBOBJS:T:.o=.c} +.endif + +# just in case +prefix?= /usr +srcdir?= ${.CURDIR} + +DEFAULT_SYS_PATH?= .../share/mk:${prefix}/share/mk + +CPPFLAGS+= -DUSE_META +CFLAGS+= ${CPPFLAGS} +CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\" +CFLAGS+= -I. -I${srcdir} ${XDEFS} -DMAKE_NATIVE +CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}} +COPTS.main.c+= "-DMAKE_VERSION=\"${MAKE_VERSION}\"" + +# meta mode can be useful even without filemon +FILEMON_H ?= /usr/include/dev/filemon/filemon.h +.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" +COPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H} +.endif + +.PATH: ${srcdir} +.PATH: ${srcdir}/lst.lib + +.if make(obj) || make(clean) +SUBDIR+= unit-tests +.endif + +# start-delete1 for bsd.after-import.mk +# we skip a lot of this when building as part of FreeBSD etc. + +# list of OS's which are derrived from BSD4.4 +BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly +# we are... +OS!= uname -s +# are we 4.4BSD ? +isBSD44:=${BSD44_LIST:M${OS}} + +.if ${isBSD44} == "" +MANTARGET= cat +INSTALL?=${srcdir}/install-sh +.if (${MACHINE} == "sun386") +# even I don't have one of these anymore :-) +CFLAGS+= -DPORTAR +.elif (${MACHINE} != "sunos") +SRCS+= sigcompat.c +CFLAGS+= -DSIGNAL_FLAGS=SA_RESTART +.endif +.else +MANTARGET?= man +.endif + +# turn this on by default - ignored if we are root +WITH_INSTALL_AS_USER= + +# supress with -DWITHOUT_* +OPTIONS_DEFAULT_YES+= \ + AUTOCONF_MK \ + INSTALL_MK \ + PROG_LINK + +OPTIONS_DEFAULT_NO+= \ + PROG_VERSION + +# process options now +.include + +.if ${MK_PROG_VERSION} == "yes" +PROG_NAME= ${PROG}-${MAKE_VERSION} +.if ${MK_PROG_LINK} == "yes" +SYMLINKS+= ${PROG}-${MAKE_VERSION} ${BINDIR}/${PROG} +.endif +.endif + +EXTRACT_MAN=no +# end-delete1 + +MAN= ${PROG}.1 +MAN1= ${MAN} + +.if (${PROG} != "make") +CLEANFILES+= my.history +.if make(${MAN}) || !exists(${srcdir}/${MAN}) +my.history: ${MAKEFILE} + @(echo ".Nm"; \ + echo "is derived from NetBSD"; \ + echo ".Xr make 1 ."; \ + echo "It uses autoconf to facilitate portability to other platforms."; \ + echo ".Pp") > $@ + +.NOPATH: ${MAN} +${MAN}: make.1 my.history + @echo making $@ + @sed -e 's/^.Nx/NetBSD/' -e '/^.Nm/s/make/${PROG}/' \ + -e '/^.Sh HISTORY/rmy.history' \ + -e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@ + +all beforeinstall: ${MAN} +_mfromdir=. +.endif +.endif + +MANTARGET?= cat +MANDEST?= ${MANDIR}/${MANTARGET}1 + +.if ${MANTARGET} == "cat" +_mfromdir=${srcdir} +.endif + +.include + +CPPFLAGS+= -DMAKE_NATIVE -DHAVE_CONFIG_H +COPTS.var.c += -Wno-cast-qual +COPTS.job.c += -Wno-format-nonliteral +COPTS.parse.c += -Wno-format-nonliteral +COPTS.var.c += -Wno-format-nonliteral + +# Force these +SHAREDIR= ${prefix}/share +BINDIR= ${prefix}/bin +MANDIR= ${SHAREDIR}/man + +.if !exists(.depend) +${OBJS}: config.h +.endif + +# make sure that MAKE_VERSION gets updated. +main.o: ${SRCS} ${MAKEFILE} + +# start-delete2 for bsd.after-import.mk +.if ${MK_AUTOCONF_MK} == "yes" +.include +.endif +SHARE_MK?=${SHAREDIR}/mk +MKSRC=${srcdir}/mk +INSTALL?=${srcdir}/install-sh + +.if ${MK_INSTALL_MK} == "yes" +install: install-mk +.endif + +beforeinstall: + test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m 775 -d ${DESTDIR}${BINDIR} + test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m 775 -d ${DESTDIR}${MANDEST} + +install-mk: +.if exists(${MKSRC}/install-mk) + test -d ${DESTDIR}${SHARE_MK} || ${INSTALL} -m 775 -d ${DESTDIR}${SHARE_MK} + sh ${MKSRC}/install-mk -v -m 644 ${DESTDIR}${SHARE_MK} +.else + @echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false +.endif +# end-delete2 + +# A simple unit-test driver to help catch regressions +accept test: + cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET} diff --git a/contrib/bmake/Makefile.config.in b/contrib/bmake/Makefile.config.in new file mode 100644 index 0000000..16ea66e --- /dev/null +++ b/contrib/bmake/Makefile.config.in @@ -0,0 +1,16 @@ +# things set by configure + +prefix= @prefix@ +srcdir= @srcdir@ +CC?= @CC@ +MACHINE= @machine@ +MACHINE_ARCH= @machine_arch@ +DEFAULT_SYS_PATH= @default_sys_path@ + +CPPFLAGS+= @CPPFLAGS@ +CFLAGS+= ${CPPFLAGS} @DEFS@ +LDFLAGS= @LDFLAGS@ +LIBOBJS= @LIBOBJS@ +LDADD= @LIBS@ +USE_META= @use_meta@ +FILEMON_H= @filemon_h@ diff --git a/contrib/bmake/Makefile.in b/contrib/bmake/Makefile.in deleted file mode 100644 index 4cb55dd..0000000 --- a/contrib/bmake/Makefile.in +++ /dev/null @@ -1,190 +0,0 @@ -# $NetBSD: Makefile,v 1.56 2012/05/30 21:54:23 sjg Exp $ -# @(#)Makefile 5.2 (Berkeley) 12/28/90 - -# $Id: Makefile.in,v 1.174 2012/10/10 18:46:24 sjg Exp $ - -PROG= bmake -SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \ - make.c parse.c str.c suff.c targ.c trace.c var.c util.c -SRCS+= strlist.c -SRCS+= make_malloc.c -SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ - lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \ - lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \ - lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \ - lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c -SRCS += lstPrev.c - -# you can use this Makefile if you have an earlier version of bmake. -prefix= @prefix@ -srcdir= @srcdir@ -CC?= @CC@ - -# Base version on src date -MAKE_VERSION= 20121010 -MACHINE=@machine@ -MACHINE_ARCH=@machine_arch@ -DEFAULT_SYS_PATH = @default_sys_path@ - -CPPFLAGS+= @CPPFLAGS@ -CFLAGS+= ${CPPFLAGS} -CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\" -CFLAGS+= -I. -I${srcdir} @DEFS@ ${XDEFS} -DMAKE_NATIVE -CFLAGS+= ${CFLAGS_${.TARGET:T}} -CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}} -COPTS.main.c+= "-DMAKE_VERSION=\"${MAKE_VERSION}\"" -LDFLAGS= @LDFLAGS@ -LIBOBJS= @LIBOBJS@ -LDADD= @LIBS@ - -.if !empty(LIBOBJS) -SRCS+= ${LIBOBJS:T:.o=.c} -.endif - -USE_META = @use_meta@ -.if ${USE_META} != "no" -SRCS+= meta.c -CPPFLAGS+= -DUSE_META -FILEMON_H ?= @filemon_h@ -.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" -COPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H} -.endif -.endif - -.PATH: ${srcdir} -.PATH: ${srcdir}/lst.lib - -OS!= uname -s -ARCH!= uname -p 2>/dev/null || uname -m - -# list of OS's which are derrived from BSD4.4 -isBSD44= NetBSD FreeBSD OpenBSD DragonFly - -.if ${OS} == "NetBSD" -# Don't set these for anyone else since we don't know what the effect may be. -# On FreeBSD WARNS=2 sets a bunch of -W flags that make does not handle. -WFORMAT= 1 -WARNS=4 -.NOPATH: bmake.cat1 -.if make(install) && exists(${DESTDIR}/usr/share/doc) -SUBDIR= PSD.doc -.endif -.endif - -.if defined(.PARSEDIR) -# we cannot rely on anything but bmake to parse this correctly. -.if empty(isBSD44:M${OS}) -MANTARGET=cat -INSTALL?=${srcdir}/install-sh -.if (${MACHINE} == "sun386") -# even I don't have one of these anymore :-) -CFLAGS+= -DPORTAR -.elif (${MACHINE} != "sunos") -SRCS+= sigcompat.c -CFLAGS+= -DSIGNAL_FLAGS=SA_RESTART -.endif -.endif - -.if make(obj) || make(clean) -SUBDIR+= unit-tests -.endif -.endif - -# many systems use gcc these days -CC_IS_GCC=@GCC@ -.if ${CC_IS_GCC} == "yes" -# problem with gcc3 -CFLAGS_var.o+= -Wno-cast-qual -.endif - -CFLAGS_main.o+= "-D@force_machine@MACHINE=\"${MACHINE}\"" "-DMACHINE_ARCH=\"${MACHINE_ARCH}\"" - -EXTRACT_MAN=no - -MAN=${PROG}.1 -.if (${PROG} != "make") -my.history: ${MAKEFILE} - @(echo ".Nm"; \ - echo "is derived from NetBSD"; \ - echo ".Xr make 1 ."; \ - echo "It uses autoconf to facilitate portability to other platforms."; \ - echo ".Pp") > $@ - -${MAN}: make.1 my.history - @echo making ${PROG}.1 - @sed -e 's/^.Nx/NetBSD/' -e '/^.Nm/s/make/${PROG}/' \ - -e '/^.Sh HISTORY/rmy.history' \ - -e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${.CURDIR}/make.1 > $@ - -.endif - -.if !empty(isBSD44:M${OS}) -.if "${OS}" != "NetBSD" -MAN1=${MAN} -.endif -MANTARGET?=man -.endif - -MANTARGET?= cat -MANDEST?= ${MANDIR}/${MANTARGET}1 - -.if ${MANTARGET} == "cat" -_mfromdir=${srcdir} -.endif - -.if exists(${srcdir}/../Makefile.inc) -.include "${srcdir}/../Makefile.inc" -.endif -.-include -# sigh, FreeBSD at least includes bsd.subdir.mk via bsd.obj.mk -# so the inclusion below, results in complaints about re-defined -# targets. For NetBSD though we need to explicitly include it. -.if defined(.PARSEDIR) -.if defined(SUBDIR) && !target(${SUBDIR:[1]}) -.-include -.endif -.endif - -CPPFLAGS+= -DMAKE_NATIVE -COPTS.var.c += -Wno-cast-qual -COPTS.job.c += -Wno-format-nonliteral -COPTS.parse.c += -Wno-format-nonliteral -COPTS.var.c += -Wno-format-nonliteral - -# Force these -BINDIR= ${prefix}/bin -MANDIR= ${prefix}/man - -arch.o: config.h -# make sure that MAKE_VERSION gets updated. -main.o: ${SRCS} ${MAKEFILE} - -MK?=${prefix}/share/mk -MKSRC?=@mksrc@ -INSTALL?=${srcdir}/install-sh - -beforeinstall: - test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m 775 -d ${DESTDIR}${BINDIR} - test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m 775 -d ${DESTDIR}${MANDEST} - -# latest version of *.mk includes an installer. -# you should not need to set USE_OS -install-mk: -.if exists(${MKSRC}/install-mk) - test -d ${DESTDIR}${MK} || ${INSTALL} -m 775 -d ${DESTDIR}${MK} - ${MKSRC}/install-mk -v -m 644 ${DESTDIR}${MK} ${USE_OS} -.else - @echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false -.endif - -.ifdef TOOLDIR -# this is a native netbsd build, -# use libutil rather than the local emalloc etc. -CPPFLAGS+= -DUSE_EMALLOC -LDADD+=-lutil -DPADD+=${LIBUTIL} -.endif - -# A simple unit-test driver to help catch regressions -accept test: - cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET} diff --git a/contrib/bmake/bmake.1 b/contrib/bmake/bmake.1 index d7ed08a..df604e7 100644 --- a/contrib/bmake/bmake.1 +++ b/contrib/bmake/bmake.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.209 2012/10/08 15:09:48 christos Exp $ +.\" $NetBSD: make.1,v 1.222 2013/08/11 09:53:49 apb Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd October 8, 2012 +.Dd August 11, 2013 .Dt MAKE 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd maintain program dependencies .Sh SYNOPSIS .Nm -.Op Fl BeikNnqrstWX +.Op Fl BeikNnqrstWwX .Op Fl C Ar directory .Op Fl D Ar variable .Op Fl d Ar flags @@ -209,6 +209,8 @@ Force the option to print raw values of variables. .It Ar v Print debugging information about variable assignment. +.It Ar w +Print entering and leaving directory messages, pre and post processing. .It Ar x Run shell commands with .Fl x @@ -468,6 +470,50 @@ except that the effect can be limited to a single line of a script. A .Ql Ic \- causes any non-zero exit status of the command line to be ignored. +.Pp +When +.Nm +is run in jobs mode with +.Fl j Ar max_jobs , +the entire script for the target is fed to a +single instance of the shell. +.Pp +In compatibility (non-jobs) mode, each command is run in a separate process. +If the command contains any shell meta characters +.Pq Ql #=|^(){};&<>*?[]:$`\e\en +it will be passed to the shell, otherwise +.Nm +will attempt direct execution. +.Pp +Since +.Nm +will +.Xr chdir 2 +to +.Ql Va .OBJDIR +before executing any targets, each child process +starts with that as its current working directory. +.Pp +Makefiles should be written so that the mode of +.Nm +operation does not change their behavior. +For example, any command which needs to use +.Dq cd +or +.Dq chdir , +without side-effect should be put in parenthesis: +.Bd -literal -offset indent + +avoid-chdir-side-effects: + @echo Building $@ in `pwd` + @(cd ${.CURDIR} && ${.MAKE} $@) + @echo Back in `pwd` + +ensure-one-shell-regardless-of-mode: + @echo Building $@ in `pwd`; \\ + (cd ${.CURDIR} && ${.MAKE} $@); \\ + echo Back in `pwd` +.Ed .Sh VARIABLE ASSIGNMENTS Variables in make are much like variables in the shell, and, by tradition, consist of all upper-case letters. @@ -699,6 +745,9 @@ then output for each target is prefixed with a token .Ql --- target --- the first part of which can be controlled via .Va .MAKE.JOB.PREFIX . +If +.Va .MAKE.JOB.PREFIX +is empty, no token is printed. .br For example: .Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] @@ -812,6 +861,11 @@ In "meta" mode, this variable contains a list of all the meta files used (updated or not). This list can be used to process the meta files to extract dependency information. +.It Va .MAKE.META.IGNORE_PATHS +Provides a list of path prefixes that should be ignored; +because the contents are expected to change over time. +The default list includes: +.Ql Pa /dev /etc /proc /tmp /var/run /var/tmp .It Va .MAKE.META.PREFIX Defines the message printed for each meta file updated in "meta verbose" mode. The default value is: @@ -830,6 +884,13 @@ by appending their names to is re-exported whenever .Ql Va .MAKEOVERRIDES is modified. +.It Va .MAKE.PATH_FILEMON +If +.Nm +was built with +.Xr filemon 4 +support, this is set to the path of the device node. +This allows makefiles to test for this support. .It Va .MAKE.PID The process-id of .Nm . @@ -1247,7 +1308,7 @@ should start and end with a period. For example. .Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} .Pp -However a single character varaiable is often more readable: +However a single character variable is often more readable: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Cm \&:U Ns Ar newval If the variable is undefined @@ -1270,7 +1331,7 @@ The path of the node which has the same name as the variable is the value. If no such node exists or its path is null, then the name of the variable is used. -In order for this modifier to work, the name (node) must at least have +In order for this modifier to work, the name (node) must at least have appeared on the rhs of a dependency. .Sm off .It Cm \&:\&! Ar cmd Cm \&! @@ -1713,6 +1774,20 @@ targets. Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the target will still be out of date. +The same effect applies to any command line that uses the variable +.Va .OODATE , +which can be used for that purpose even when not otherwise needed or desired: +.Bd -literal -offset indent + +skip-compare-for-some: + @echo this will be compared + @echo this will not ${.OODATE:M.NOMETA_CMP} + @echo this will also be compared + +.Ed +The +.Cm \&:M +pattern suppresses any expansion of the unwanted variable. .It Ic .NOPATH Do not search for the target in the directories specified by .Ic .PATH . @@ -1896,6 +1971,12 @@ If the source is the special .Ic .DOTLAST target, then the current working directory is searched last. +.It Ic .PATH. Ns Va suffix +Like +.Ic .PATH +but applies only to files with a particular suffix. +The suffix must have been previously declared with +.Ic .SUFFIXES . .It Ic .PHONY Apply the .Ic .PHONY @@ -1964,6 +2045,10 @@ If no sources are specified, the .Ic .SILENT attribute is applied to every command in the file. +.It Ic .STALE +This target gets run when a dependency file contains stale entries, having +.Va .ALLSRC +set to the name of that dependency file. .It Ic .SUFFIXES Each source specifies a suffix to .Nm . @@ -2027,28 +2112,6 @@ NetBSD 5.0 so that they still appear to be variable expansions. In particular this stops them being treated as syntax, and removes some obscure problems using them in .if statements. -.Pp -Unlike other -.Nm -programs, this implementation by default executes all commands for a given -target using a single shell invocation. -This is done for both efficiency and to simplify error handling in remote -command invocations. -Typically this is transparent to the user, unless the target commands change -the current working directory using -.Dq cd -or -.Dq chdir . -To be compatible with Makefiles that do this, one can use -.Fl B -to disable this behavior. -.Pp -In compatibility mode, each command is run in a separate process. -If the command contains any shell meta characters -.Pq Ql #=|^(){};&<>*?[]:$`\e\en -it will be passed to the shell, otherwise -.Nm -will attempt direct execution. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY @@ -2068,6 +2131,13 @@ for Sprite at Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called .Dq customs . +.Pp +Historically the target/dependency +.Dq FRC +has been used to FoRCe rebuilding (since the target/dependency +does not exist... unless someone creates an +.Dq FRC +file). .Sh BUGS The make diff --git a/contrib/bmake/bmake.cat1 b/contrib/bmake/bmake.cat1 index f693b07..ca49bb6 100644 --- a/contrib/bmake/bmake.cat1 +++ b/contrib/bmake/bmake.cat1 @@ -4,7 +4,7 @@ NNAAMMEE bbmmaakkee -- maintain program dependencies SSYYNNOOPPSSIISS - bbmmaakkee [--BBeeiikkNNnnqqrrssttWWXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] + bbmmaakkee [--BBeeiikkNNnnqqrrssttWWwwXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] [--ff _m_a_k_e_f_i_l_e] [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s] [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_l_e] [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] [_t_a_r_g_e_t _._._.] @@ -122,1334 +122,8 @@ DDEESSCCRRIIPPTTIIOONN _v Print debugging information about variable assignment. - _x Run shell commands with --xx so the actual commands are - printed as they are executed. - - --ee Specify that environment variables override macro assignments - within makefiles. - - --ff _m_a_k_e_f_i_l_e - Specify a makefile to read instead of the default `_m_a_k_e_f_i_l_e'. If - _m_a_k_e_f_i_l_e is `--', standard input is read. Multiple makefiles may - be specified, and are read in the order specified. - - --II _d_i_r_e_c_t_o_r_y - Specify a directory in which to search for makefiles and included - makefiles. The system makefile directory (or directories, see - the --mm option) is automatically included as part of this list. - - --ii Ignore non-zero exit of shell commands in the makefile. Equiva- - lent to specifying `--' before each command line in the makefile. - - --JJ _p_r_i_v_a_t_e - This option should _n_o_t be specified by the user. - - When the _j option is in use in a recursive build, this option is - passed by a make to child makes to allow all the make processes - in the build to cooperate to avoid overloading the system. - - --jj _m_a_x___j_o_b_s - Specify the maximum number of jobs that bbmmaakkee may have running at - any one time. The value is saved in _._M_A_K_E_._J_O_B_S. Turns compati- - bility mode off, unless the _B flag is also specified. When com- - patibility mode is off, all commands associated with a target are - executed in a single shell invocation as opposed to the tradi- - tional one shell invocation per line. This can break traditional - scripts which change directories on each command invocation and - then expect to start with a fresh environment on the next line. - It is more efficient to correct the scripts rather than turn - backwards compatibility on. - - --kk Continue processing after errors are encountered, but only on - those targets that do not depend on the target whose creation - caused the error. - - --mm _d_i_r_e_c_t_o_r_y - Specify a directory in which to search for sys.mk and makefiles - included via the <_f_i_l_e>-style include statement. The --mm option - can be used multiple times to form a search path. This path will - override the default system include path: /usr/share/mk. Fur- - thermore the system include path will be appended to the search - path used for "_f_i_l_e"-style include statements (see the --II - option). - - If a file or directory name in the --mm argument (or the - MAKESYSPATH environment variable) starts with the string ".../" - then bbmmaakkee will search for the specified file or directory named - in the remaining part of the argument string. The search starts - with the current directory of the Makefile and then works upward - towards the root of the filesystem. If the search is successful, - then the resulting directory replaces the ".../" specification in - the --mm argument. If used, this feature allows bbmmaakkee to easily - search in the current source tree for customized sys.mk files - (e.g., by using ".../mk/sys.mk" as an argument). - - --nn Display the commands that would have been executed, but do not - actually execute them unless the target depends on the .MAKE spe- - cial source (see below). - - --NN Display the commands which would have been executed, but do not - actually execute any of them; useful for debugging top-level - makefiles without descending into subdirectories. - - --qq Do not execute any commands, but exit 0 if the specified targets - are up-to-date and 1, otherwise. - - --rr Do not use the built-in rules specified in the system makefile. - - --ss Do not echo any commands as they are executed. Equivalent to - specifying `@@' before each command line in the makefile. - - --TT _t_r_a_c_e_f_i_l_e - When used with the --jj flag, append a trace record to _t_r_a_c_e_f_i_l_e - for each job started and completed. - - --tt Rather than re-building a target as specified in the makefile, - create it or update its modification time to make it appear up- - to-date. - - --VV _v_a_r_i_a_b_l_e - Print bbmmaakkee's idea of the value of _v_a_r_i_a_b_l_e, in the global con- - text. Do not build any targets. Multiple instances of this - option may be specified; the variables will be printed one per - line, with a blank line for each null or undefined variable. If - _v_a_r_i_a_b_l_e contains a `$' then the value will be expanded before - printing. - - --WW Treat any warnings during makefile parsing as errors. - - --XX Don't export variables passed on the command line to the environ- - ment individually. Variables passed on the command line are - still exported via the _M_A_K_E_F_L_A_G_S environment variable. This - option may be useful on systems which have a small limit on the - size of command arguments. - - _v_a_r_i_a_b_l_e_=_v_a_l_u_e - Set the value of the variable _v_a_r_i_a_b_l_e to _v_a_l_u_e. Normally, all - values passed on the command line are also exported to sub-makes - in the environment. The --XX flag disables this behavior. Vari- - able assignments should follow options for POSIX compatibility - but no ordering is enforced. - - There are seven different types of lines in a makefile: file dependency - specifications, shell commands, variable assignments, include statements, - conditional directives, for loops, and comments. - - In general, lines may be continued from one line to the next by ending - them with a backslash (`\'). The trailing newline character and initial - whitespace on the following line are compressed into a single space. - -FFIILLEE DDEEPPEENNDDEENNCCYY SSPPEECCIIFFIICCAATTIIOONNSS - Dependency lines consist of one or more targets, an operator, and zero or - more sources. This creates a relationship where the targets ``depend'' - on the sources and are usually created from them. The exact relationship - between the target and the source is determined by the operator that sep- - arates them. The three operators are as follows: - - :: A target is considered out-of-date if its modification time is less - than those of any of its sources. Sources for a target accumulate - over dependency lines when this operator is used. The target is - removed if bbmmaakkee is interrupted. - - !! Targets are always re-created, but not until all sources have been - examined and re-created as necessary. Sources for a target accumu- - late over dependency lines when this operator is used. The target - is removed if bbmmaakkee is interrupted. - - :::: If no sources are specified, the target is always re-created. Oth- - erwise, a target is considered out-of-date if any of its sources - has been modified more recently than the target. Sources for a - target do not accumulate over dependency lines when this operator - is used. The target will not be removed if bbmmaakkee is interrupted. - - Targets and sources may contain the shell wildcard values `?', `*', `[]', - and `{}'. The values `?', `*', and `[]' may only be used as part of the - final component of the target or source, and must be used to describe - existing files. The value `{}' need not necessarily be used to describe - existing files. Expansion is in directory order, not alphabetically as - done in the shell. - -SSHHEELLLL CCOOMMMMAANNDDSS - Each target may have associated with it a series of shell commands, nor- - mally used to create the target. Each of the commands in this script - _m_u_s_t be preceded by a tab. While any target may appear on a dependency - line, only one of these dependencies may be followed by a creation - script, unless the `::::' operator is used. - - If the first characters of the command line are any combination of `@@', - `++', or `--', the command is treated specially. A `@@' causes the command - not to be echoed before it is executed. A `++' causes the command to be - executed even when --nn is given. This is similar to the effect of the - .MAKE special source, except that the effect can be limited to a single - line of a script. A `--' causes any non-zero exit status of the command - line to be ignored. - -VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS - Variables in make are much like variables in the shell, and, by tradi- - tion, consist of all upper-case letters. - - VVaarriiaabbllee aassssiiggnnmmeenntt mmooddiiffiieerrss - The five operators that can be used to assign values to variables are as - follows: - - == Assign the value to the variable. Any previous value is overrid- - den. - - ++== Append the value to the current value of the variable. - - ??== Assign the value to the variable if it is not already defined. - - ::== Assign with expansion, i.e. expand the value before assigning it - to the variable. Normally, expansion is not done until the vari- - able is referenced. _N_O_T_E: References to undefined variables are - _n_o_t expanded. This can cause problems when variable modifiers - are used. - - !!== Expand the value and pass it to the shell for execution and - assign the result to the variable. Any newlines in the result - are replaced with spaces. - - Any white-space before the assigned _v_a_l_u_e is removed; if the value is - being appended, a single space is inserted between the previous contents - of the variable and the appended value. - - Variables are expanded by surrounding the variable name with either curly - braces (`{}') or parentheses (`()') and preceding it with a dollar sign - (`$'). If the variable name contains only a single letter, the surround- - ing braces or parentheses are not required. This shorter form is not - recommended. - - If the variable name contains a dollar, then the name itself is expanded - first. This allows almost arbitrary variable names, however names con- - taining dollar, braces, parenthesis, or whitespace are really best - avoided! - - If the result of expanding a variable contains a dollar sign (`$') the - string is expanded again. - - Variable substitution occurs at three distinct times, depending on where - the variable is being used. - - 1. Variables in dependency lines are expanded as the line is read. - - 2. Variables in shell commands are expanded when the shell command is - executed. - - 3. ``.for'' loop index variables are expanded on each loop iteration. - Note that other variables are not expanded inside loops so the fol- - lowing example code: - - - .for i in 1 2 3 - a+= ${i} - j= ${i} - b+= ${j} - .endfor - - all: - @echo ${a} - @echo ${b} - - will print: - - 1 2 3 - 3 3 3 - - Because while ${a} contains ``1 2 3'' after the loop is executed, - ${b} contains ``${j} ${j} ${j}'' which expands to ``3 3 3'' since - after the loop completes ${j} contains ``3''. - - VVaarriiaabbllee ccllaasssseess - The four different classes of variables (in order of increasing prece- - dence) are: - - Environment variables - Variables defined as part of bbmmaakkee's environment. - - Global variables - Variables defined in the makefile or in included makefiles. - - Command line variables - Variables defined as part of the command line. - - Local variables - Variables that are defined specific to a certain target. The - seven local variables are as follows: - - _._A_L_L_S_R_C The list of all sources for this target; also known as - `_>'. - - _._A_R_C_H_I_V_E The name of the archive file. - - _._I_M_P_S_R_C In suffix-transformation rules, the name/path of the - source from which the target is to be transformed (the - ``implied'' source); also known as `_<'. It is not - defined in explicit rules. - - _._M_E_M_B_E_R The name of the archive member. - - _._O_O_D_A_T_E The list of sources for this target that were deemed - out-of-date; also known as `_?'. - - _._P_R_E_F_I_X The file prefix of the target, containing only the file - portion, no suffix or preceding directory components; - also known as `_*'. - - _._T_A_R_G_E_T The name of the target; also known as `_@'. - - The shorter forms `_@', `_?', `_<', `_>', and `_*' are permitted for - backward compatibility with historical makefiles and are not rec- - ommended. The six variables `_@_F', `_@_D', `_<_F', `_<_D', `_*_F', and - `_*_D' are permitted for compatibility with AT&T System V UNIX - makefiles and are not recommended. - - Four of the local variables may be used in sources on dependency - lines because they expand to the proper value for each target on - the line. These variables are `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E', - and `_._M_E_M_B_E_R'. - - AAddddiittiioonnaall bbuuiilltt--iinn vvaarriiaabblleess - In addition, bbmmaakkee sets or knows about the following variables: - - _$ A single dollar sign `$', i.e. `$$' expands to a single - dollar sign. - - _._A_L_L_T_A_R_G_E_T_S The list of all targets encountered in the Makefile. If - evaluated during Makefile parsing, lists only those tar- - gets encountered thus far. - - _._C_U_R_D_I_R A path to the directory where bbmmaakkee was executed. Refer - to the description of `PWD' for more details. - - MAKE The name that bbmmaakkee was executed with (_a_r_g_v_[_0_]). For - compatibility bbmmaakkee also sets _._M_A_K_E with the same value. - The preferred variable to use is the environment variable - MAKE because it is more compatible with other versions of - bbmmaakkee and cannot be confused with the special target with - the same name. - - _._M_A_K_E_._D_E_P_E_N_D_F_I_L_E - Names the makefile (default `_._d_e_p_e_n_d') from which gener- - ated dependencies are read. - - _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S - A boolean that controls the default behavior of the --VV - option. - - _._M_A_K_E_._E_X_P_O_R_T_E_D The list of variables exported by bbmmaakkee. - - _._M_A_K_E_._J_O_B_S The argument to the --jj option. - - _._M_A_K_E_._J_O_B_._P_R_E_F_I_X - If bbmmaakkee is run with _j then output for each target is - prefixed with a token `--- target ---' the first part of - which can be controlled via _._M_A_K_E_._J_O_B_._P_R_E_F_I_X. - For example: - .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] - would produce tokens like `---make[1234] target ---' mak- - ing it easier to track the degree of parallelism being - achieved. - - MAKEFLAGS The environment variable `MAKEFLAGS' may contain anything - that may be specified on bbmmaakkee's command line. Anything - specified on bbmmaakkee's command line is appended to the - `MAKEFLAGS' variable which is then entered into the envi- - ronment for all programs which bbmmaakkee executes. - - _._M_A_K_E_._L_E_V_E_L The recursion depth of bbmmaakkee. The initial instance of - bbmmaakkee will be 0, and an incremented value is put into the - environment to be seen by the next generation. This - allows tests like: .if ${.MAKE.LEVEL} == 0 to protect - things which should only be evaluated in the initial - instance of bbmmaakkee. - - _._M_A_K_E_._M_A_K_E_F_I_L_E___P_R_E_F_E_R_E_N_C_E - The ordered list of makefile names (default `_m_a_k_e_f_i_l_e', - `_M_a_k_e_f_i_l_e') that bbmmaakkee will look for. - - _._M_A_K_E_._M_A_K_E_F_I_L_E_S - The list of makefiles read by bbmmaakkee, which is useful for - tracking dependencies. Each makefile is recorded only - once, regardless of the number of times read. - - _._M_A_K_E_._M_O_D_E Processed after reading all makefiles. Can affect the - mode that bbmmaakkee runs in. It can contain a number of key- - words: - - _c_o_m_p_a_t Like --BB, puts bbmmaakkee into "compat" mode. - - _m_e_t_a Puts bbmmaakkee into "meta" mode, where meta files - are created for each target to capture the - command run, the output generated and if - filemon(4) is available, the system calls - which are of interest to bbmmaakkee. The captured - output can be very useful when diagnosing - errors. - - _c_u_r_d_i_r_O_k_= _b_f Normally bbmmaakkee will not create .meta files - in `_._C_U_R_D_I_R'. This can be overridden by set- - ting _b_f to a value which represents True. - - _e_n_v For debugging, it can be useful to inlcude - the environment in the .meta file. - - _v_e_r_b_o_s_e If in "meta" mode, print a clue about the - target being built. This is useful if the - build is otherwise running silently. The - message printed the value of: - _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X. - - _i_g_n_o_r_e_-_c_m_d Some makefiles have commands which are simply - not stable. This keyword causes them to be - ignored for determining whether a target is - out of date in "meta" mode. See also - ..NNOOMMEETTAA__CCMMPP. - - _s_i_l_e_n_t_= _b_f If _b_f is True, when a .meta file is created, - mark the target ..SSIILLEENNTT. - - _._M_A_K_E_._M_E_T_A_._B_A_I_L_I_W_I_C_K - In "meta" mode, provides a list of prefixes which match - the directories controlled by bbmmaakkee. If a file that was - generated outside of _._O_B_J_D_I_R but within said bailiwick is - missing, the current target is considered out-of-date. - - _._M_A_K_E_._M_E_T_A_._C_R_E_A_T_E_D - In "meta" mode, this variable contains a list of all the - meta files updated. If not empty, it can be used to - trigger processing of _._M_A_K_E_._M_E_T_A_._F_I_L_E_S. - - _._M_A_K_E_._M_E_T_A_._F_I_L_E_S - In "meta" mode, this variable contains a list of all the - meta files used (updated or not). This list can be used - to process the meta files to extract dependency informa- - tion. - - _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X - Defines the message printed for each meta file updated in - "meta verbose" mode. The default value is: - Building ${.TARGET:H:tA}/${.TARGET:T} - - _._M_A_K_E_O_V_E_R_R_I_D_E_S This variable is used to record the names of variables - assigned to on the command line, so that they may be - exported as part of `MAKEFLAGS'. This behaviour can be - disabled by assigning an empty value to `_._M_A_K_E_O_V_E_R_R_I_D_E_S' - within a makefile. Extra variables can be exported from - a makefile by appending their names to `_._M_A_K_E_O_V_E_R_R_I_D_E_S'. - `MAKEFLAGS' is re-exported whenever `_._M_A_K_E_O_V_E_R_R_I_D_E_S' is - modified. - - _._M_A_K_E_._P_I_D The process-id of bbmmaakkee. - - _._M_A_K_E_._P_P_I_D The parent process-id of bbmmaakkee. - - _M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R - When bbmmaakkee stops due to an error, it prints its name and - the value of `_._C_U_R_D_I_R' as well as the value of any vari- - ables named in `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R'. - - _._n_e_w_l_i_n_e This variable is simply assigned a newline character as - its value. This allows expansions using the ::@@ modifier - to put a newline between iterations of the loop rather - than a space. For example, the printing of - `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R' could be done as - ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}. - - _._O_B_J_D_I_R A path to the directory where the targets are built. Its - value is determined by trying to chdir(2) to the follow- - ing directories in order and using the first match: - - 1. ${MAKEOBJDIRPREFIX}${.CURDIR} - - (Only if `MAKEOBJDIRPREFIX' is set in the environ- - ment or on the command line.) - - 2. ${MAKEOBJDIR} - - (Only if `MAKEOBJDIR' is set in the environment or - on the command line.) - - 3. ${.CURDIR}_/_o_b_j_.${MACHINE} - - 4. ${.CURDIR}_/_o_b_j - - 5. _/_u_s_r_/_o_b_j_/${.CURDIR} - - 6. ${.CURDIR} - - Variable expansion is performed on the value before it's - used, so expressions such as - ${.CURDIR:S,^/usr/src,/var/obj,} - may be used. This is especially useful with - `MAKEOBJDIR'. - - `_._O_B_J_D_I_R' may be modified in the makefile as a global - variable. In all cases, bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' - and set `PWD' to that directory before executing any tar- - gets. - - _._P_A_R_S_E_D_I_R A path to the directory of the current `_M_a_k_e_f_i_l_e' being - parsed. - - _._P_A_R_S_E_F_I_L_E The basename of the current `_M_a_k_e_f_i_l_e' being parsed. - This variable and `_._P_A_R_S_E_D_I_R' are both set only while the - `_M_a_k_e_f_i_l_e_s' are being parsed. If you want to retain - their current values, assign them to a variable using - assignment with expansion: (`::=='). - - _._P_A_T_H A variable that represents the list of directories that - bbmmaakkee will search for files. The search list should be - updated using the target `_._P_A_T_H' rather than the vari- - able. - - PWD Alternate path to the current directory. bbmmaakkee normally - sets `_._C_U_R_D_I_R' to the canonical path given by getcwd(3). - However, if the environment variable `PWD' is set and - gives a path to the current directory, then bbmmaakkee sets - `_._C_U_R_D_I_R' to the value of `PWD' instead. This behaviour - is disabled if `MAKEOBJDIRPREFIX' is set or `MAKEOBJDIR' - contains a variable transform. `PWD' is set to the value - of `_._O_B_J_D_I_R' for all programs which bbmmaakkee executes. - - .TARGETS The list of targets explicitly specified on the command - line, if any. - - VPATH Colon-separated (``:'') lists of directories that bbmmaakkee - will search for files. The variable is supported for - compatibility with old make programs only, use `_._P_A_T_H' - instead. - - VVaarriiaabbllee mmooddiiffiieerrss - Variable expansion may be modified to select or modify each word of the - variable (where a ``word'' is white-space delimited sequence of charac- - ters). The general format of a variable expansion is as follows: - - ${variable[:modifier[:...]]} - - Each modifier begins with a colon, which may be escaped with a backslash - (`\'). - - A set of modifiers can be specified via a variable, as follows: - - modifier_variable=modifier[:...] - ${variable:${modifier_variable}[:...]} - - In this case the first modifier in the modifier_variable does not start - with a colon, since that must appear in the referencing variable. If any - of the modifiers in the modifier_variable contain a dollar sign (`$'), - these must be doubled to avoid early expansion. - - The supported modifiers are: - - ::EE Replaces each word in the variable with its suffix. - - ::HH Replaces each word in the variable with everything but the last com- - ponent. - - ::MM_p_a_t_t_e_r_n - Select only those words that match _p_a_t_t_e_r_n. The standard shell - wildcard characters (`*', `?', and `[]') may be used. The wildcard - characters may be escaped with a backslash (`\'). - - ::NN_p_a_t_t_e_r_n - This is identical to `::MM', but selects all words which do not match - _p_a_t_t_e_r_n. - - ::OO Order every word in variable alphabetically. To sort words in - reverse order use the `::OO::[[--11....11]]' combination of modifiers. - - ::OOxx Randomize words in variable. The results will be different each - time you are referring to the modified variable; use the assignment - with expansion (`::==') to prevent such behaviour. For example, - - LIST= uno due tre quattro - RANDOM_LIST= ${LIST:Ox} - STATIC_RANDOM_LIST:= ${LIST:Ox} - - all: - @echo "${RANDOM_LIST}" - @echo "${RANDOM_LIST}" - @echo "${STATIC_RANDOM_LIST}" - @echo "${STATIC_RANDOM_LIST}" - may produce output similar to: - - quattro due tre uno - tre due quattro uno - due uno quattro tre - due uno quattro tre - - ::QQ Quotes every shell meta-character in the variable, so that it can be - passed safely through recursive invocations of bbmmaakkee. - - ::RR Replaces each word in the variable with everything but its suffix. - - ::ggmmttiimmee - The value is a format string for strftime(3), using the current - gmtime(3). - - ::hhaasshh - Compute a 32bit hash of the value and encode it as hex digits. - - ::llooccaallttiimmee - The value is a format string for strftime(3), using the current - localtime(3). - - ::ttAA Attempt to convert variable to an absolute path using realpath(3), - if that fails, the value is unchanged. - - ::ttll Converts variable to lower-case letters. - - ::ttss_c - Words in the variable are normally separated by a space on expan- - sion. This modifier sets the separator to the character _c. If _c is - omitted, then no separator is used. The common escapes (including - octal numeric codes), work as expected. - - ::ttuu Converts variable to upper-case letters. - - ::ttWW Causes the value to be treated as a single word (possibly containing - embedded white space). See also `::[[**]]'. - - ::ttww Causes the value to be treated as a sequence of words delimited by - white space. See also `::[[@@]]'. - - ::SS/_o_l_d___s_t_r_i_n_g/_n_e_w___s_t_r_i_n_g/[11ggWW] - Modify the first occurrence of _o_l_d___s_t_r_i_n_g in the variable's value, - replacing it with _n_e_w___s_t_r_i_n_g. If a `g' is appended to the last - slash of the pattern, all occurrences in each word are replaced. If - a `1' is appended to the last slash of the pattern, only the first - word is affected. If a `W' is appended to the last slash of the - pattern, then the value is treated as a single word (possibly con- - taining embedded white space). If _o_l_d___s_t_r_i_n_g begins with a caret - (`^'), _o_l_d___s_t_r_i_n_g is anchored at the beginning of each word. If - _o_l_d___s_t_r_i_n_g ends with a dollar sign (`$'), it is anchored at the end - of each word. Inside _n_e_w___s_t_r_i_n_g, an ampersand (`&') is replaced by - _o_l_d___s_t_r_i_n_g (without any `^' or `$'). Any character may be used as a - delimiter for the parts of the modifier string. The anchoring, - ampersand and delimiter characters may be escaped with a backslash - (`\'). - - Variable expansion occurs in the normal fashion inside both - _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash - is used to prevent the expansion of a dollar sign (`$'), not a pre- - ceding dollar sign as is usual. - - ::CC/_p_a_t_t_e_r_n/_r_e_p_l_a_c_e_m_e_n_t/[11ggWW] - The ::CC modifier is just like the ::SS modifier except that the old and - new strings, instead of being simple strings, are a regular expres- - sion (see regex(3)) string _p_a_t_t_e_r_n and an ed(1)-style string - _r_e_p_l_a_c_e_m_e_n_t. Normally, the first occurrence of the pattern _p_a_t_t_e_r_n - in each word of the value is substituted with _r_e_p_l_a_c_e_m_e_n_t. The `1' - modifier causes the substitution to apply to at most one word; the - `g' modifier causes the substitution to apply to as many instances - of the search pattern _p_a_t_t_e_r_n as occur in the word or words it is - found in; the `W' modifier causes the value to be treated as a sin- - gle word (possibly containing embedded white space). Note that `1' - and `g' are orthogonal; the former specifies whether multiple words - are potentially affected, the latter whether multiple substitutions - can potentially occur within each affected word. - - ::TT Replaces each word in the variable with its last component. - - ::uu Remove adjacent duplicate words (like uniq(1)). - - ::??_t_r_u_e___s_t_r_i_n_g::_f_a_l_s_e___s_t_r_i_n_g - If the variable name (not its value), when parsed as a .if condi- - tional expression, evaluates to true, return as its value the - _t_r_u_e___s_t_r_i_n_g, otherwise return the _f_a_l_s_e___s_t_r_i_n_g. Since the variable - name is used as the expression, :? must be the first modifier after - the variable name itself - which will, of course, usually contain - variable expansions. A common error is trying to use expressions - like - ${NUMBERS:M42:?match:no} - which actually tests defined(NUMBERS), to determine is any words - match "42" you need to use something like: - ${"${NUMBERS:M42}" != "":?match:no}. - - _:_o_l_d___s_t_r_i_n_g_=_n_e_w___s_t_r_i_n_g - This is the AT&T System V UNIX style variable substitution. It must - be the last modifier specified. If _o_l_d___s_t_r_i_n_g or _n_e_w___s_t_r_i_n_g do not - contain the pattern matching character _% then it is assumed that - they are anchored at the end of each word, so only suffixes or - entire words may be replaced. Otherwise _% is the substring of - _o_l_d___s_t_r_i_n_g to be replaced in _n_e_w___s_t_r_i_n_g. - - Variable expansion occurs in the normal fashion inside both - _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash - is used to prevent the expansion of a dollar sign (`$'), not a pre- - ceding dollar sign as is usual. - - ::@@_t_e_m_p@@_s_t_r_i_n_g@@ - This is the loop expansion mechanism from the OSF Development Envi- - ronment (ODE) make. Unlike ..ffoorr loops expansion occurs at the time - of reference. Assign _t_e_m_p to each word in the variable and evaluate - _s_t_r_i_n_g. The ODE convention is that _t_e_m_p should start and end with a - period. For example. - ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} - - However a single character varaiable is often more readable: - ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} - - ::UU_n_e_w_v_a_l - If the variable is undefined _n_e_w_v_a_l is the value. If the variable - is defined, the existing value is returned. This is another ODE - make feature. It is handy for setting per-target CFLAGS for - instance: - ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} - If a value is only required if the variable is undefined, use: - ${VAR:D:Unewval} - - ::DD_n_e_w_v_a_l - If the variable is defined _n_e_w_v_a_l is the value. - - ::LL The name of the variable is the value. - - ::PP The path of the node which has the same name as the variable is the - value. If no such node exists or its path is null, then the name of - the variable is used. In order for this modifier to work, the name - (node) must at least have appeared on the rhs of a dependency. - - ::!!_c_m_d!! - The output of running _c_m_d is the value. - - ::sshh If the variable is non-empty it is run as a command and the output - becomes the new value. - - ::::==_s_t_r - The variable is assigned the value _s_t_r after substitution. This - modifier and its variations are useful in obscure situations such as - wanting to set a variable when shell commands are being parsed. - These assignment modifiers always expand to nothing, so if appearing - in a rule line by themselves should be preceded with something to - keep bbmmaakkee happy. - - The `::::' helps avoid false matches with the AT&T System V UNIX style - ::== modifier and since substitution always occurs the ::::== form is - vaguely appropriate. - - ::::??==_s_t_r - As for ::::== but only if the variable does not already have a value. - - ::::++==_s_t_r - Append _s_t_r to the variable. - - ::::!!==_c_m_d - Assign the output of _c_m_d to the variable. - - ::[[_r_a_n_g_e]] - Selects one or more words from the value, or performs other opera- - tions related to the way in which the value is divided into words. - - Ordinarily, a value is treated as a sequence of words delimited by - white space. Some modifiers suppress this behaviour, causing a - value to be treated as a single word (possibly containing embedded - white space). An empty value, or a value that consists entirely of - white-space, is treated as a single word. For the purposes of the - `::[[]]' modifier, the words are indexed both forwards using positive - integers (where index 1 represents the first word), and backwards - using negative integers (where index -1 represents the last word). - - The _r_a_n_g_e is subjected to variable expansion, and the expanded - result is then interpreted as follows: - - _i_n_d_e_x Selects a single word from the value. - - _s_t_a_r_t...._e_n_d - Selects all words from _s_t_a_r_t to _e_n_d, inclusive. For example, - `::[[22....--11]]' selects all words from the second word to the last - word. If _s_t_a_r_t is greater than _e_n_d, then the words are out- - put in reverse order. For example, `::[[--11....11]]' selects all - the words from last to first. - - ** Causes subsequent modifiers to treat the value as a single - word (possibly containing embedded white space). Analogous - to the effect of "$*" in Bourne shell. - - 0 Means the same as `::[[**]]'. - - @@ Causes subsequent modifiers to treat the value as a sequence - of words delimited by white space. Analogous to the effect - of "$@" in Bourne shell. - - ## Returns the number of words in the value. - -IINNCCLLUUDDEE SSTTAATTEEMMEENNTTSS,, CCOONNDDIITTIIOONNAALLSS AANNDD FFOORR LLOOOOPPSS - Makefile inclusion, conditional structures and for loops reminiscent of - the C programming language are provided in bbmmaakkee. All such structures - are identified by a line beginning with a single dot (`.') character. - Files are included with either ..iinncclluuddee <_f_i_l_e> or ..iinncclluuddee "_f_i_l_e". Vari- - ables between the angle brackets or double quotes are expanded to form - the file name. If angle brackets are used, the included makefile is - expected to be in the system makefile directory. If double quotes are - used, the including makefile's directory and any directories specified - using the --II option are searched before the system makefile directory. - For compatibility with other versions of bbmmaakkee `include file ...' is also - accepted. If the include statement is written as ..--iinncclluuddee or as - ..ssiinncclluuddee then errors locating and/or opening include files are ignored. - - Conditional expressions are also preceded by a single dot as the first - character of a line. The possible conditionals are as follows: - - ..eerrrroorr _m_e_s_s_a_g_e - The message is printed along with the name of the makefile and - line number, then bbmmaakkee will exit. - - ..eexxppoorrtt _v_a_r_i_a_b_l_e _._._. - Export the specified global variable. If no variable list is - provided, all globals are exported except for internal variables - (those that start with `.'). This is not affected by the --XX - flag, so should be used with caution. For compatibility with - other bbmmaakkee programs `export variable=value' is also accepted. - - Appending a variable name to _._M_A_K_E_._E_X_P_O_R_T_E_D is equivalent to - exporting a variable. - - ..eexxppoorrtt--eennvv _v_a_r_i_a_b_l_e _._._. - The same as `.export', except that the variable is not appended - to _._M_A_K_E_._E_X_P_O_R_T_E_D. This allows exporting a value to the environ- - ment which is different from that used by bbmmaakkee internally. - - ..iinnffoo _m_e_s_s_a_g_e - The message is printed along with the name of the makefile and - line number. - - ..uunnddeeff _v_a_r_i_a_b_l_e - Un-define the specified global variable. Only global variables - may be un-defined. - - ..uunneexxppoorrtt _v_a_r_i_a_b_l_e _._._. - The opposite of `.export'. The specified global _v_a_r_i_a_b_l_e will be - removed from _._M_A_K_E_._E_X_P_O_R_T_E_D. If no variable list is provided, - all globals are unexported, and _._M_A_K_E_._E_X_P_O_R_T_E_D deleted. - - ..uunneexxppoorrtt--eennvv - Unexport all globals previously exported and clear the environ- - ment inherited from the parent. This operation will cause a mem- - ory leak of the original environment, so should be used spar- - ingly. Testing for _._M_A_K_E_._L_E_V_E_L being 0, would make sense. Also - note that any variables which originated in the parent environ- - ment should be explicitly preserved if desired. For example: - - .if ${.MAKE.LEVEL} == 0 - PATH := ${PATH} - .unexport-env - .export PATH - .endif - - Would result in an environment containing only `PATH', which is - the minimal useful environment. Actually `.MAKE.LEVEL' will also - be pushed into the new environment. - - ..wwaarrnniinngg _m_e_s_s_a_g_e - The message prefixed by `_w_a_r_n_i_n_g_:' is printed along with the name - of the makefile and line number. - - ..iiff [!]_e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.] - Test the value of an expression. - - ..iiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] - Test the value of a variable. - - ..iiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] - Test the value of a variable. - - ..iiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] - Test the target being built. - - ..iiffnnmmaakkee [!] _t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] - Test the target being built. - - ..eellssee Reverse the sense of the last conditional. - - ..eelliiff [!] _e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.] - A combination of `..eellssee' followed by `..iiff'. - - ..eelliiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] - A combination of `..eellssee' followed by `..iiffddeeff'. - - ..eelliiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] - A combination of `..eellssee' followed by `..iiffnnddeeff'. - - ..eelliiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] - A combination of `..eellssee' followed by `..iiffmmaakkee'. - - ..eelliiffnnmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] - A combination of `..eellssee' followed by `..iiffnnmmaakkee'. - - ..eennddiiff End the body of the conditional. - - The _o_p_e_r_a_t_o_r may be any one of the following: - - |||| Logical OR. - - &&&& Logical AND; of higher precedence than ``||''. - - As in C, bbmmaakkee will only evaluate a conditional as far as is necessary to - determine its value. Parentheses may be used to change the order of - evaluation. The boolean operator `!!' may be used to logically negate an - entire conditional. It is of higher precedence than `&&&&'. - - The value of _e_x_p_r_e_s_s_i_o_n may be any of the following: - - ddeeffiinneedd Takes a variable name as an argument and evaluates to true if - the variable has been defined. - - mmaakkee Takes a target name as an argument and evaluates to true if the - target was specified as part of bbmmaakkee's command line or was - declared the default target (either implicitly or explicitly, - see _._M_A_I_N) before the line containing the conditional. - - eemmppttyy Takes a variable, with possible modifiers, and evaluates to true - if the expansion of the variable would result in an empty - string. - - eexxiissttss Takes a file name as an argument and evaluates to true if the - file exists. The file is searched for on the system search path - (see _._P_A_T_H). - - ttaarrggeett Takes a target name as an argument and evaluates to true if the - target has been defined. - - ccoommmmaannddss - Takes a target name as an argument and evaluates to true if the - target has been defined and has commands associated with it. - - _E_x_p_r_e_s_s_i_o_n may also be an arithmetic or string comparison. Variable - expansion is performed on both sides of the comparison, after which the - integral values are compared. A value is interpreted as hexadecimal if - it is preceded by 0x, otherwise it is decimal; octal numbers are not sup- - ported. The standard C relational operators are all supported. If after - variable expansion, either the left or right hand side of a `====' or `!!==' - operator is not an integral value, then string comparison is performed - between the expanded variables. If no relational operator is given, it - is assumed that the expanded variable is being compared against 0 or an - empty string in the case of a string comparison. - - When bbmmaakkee is evaluating one of these conditional expressions, and it - encounters a (white-space separated) word it doesn't recognize, either - the ``make'' or ``defined'' expression is applied to it, depending on the - form of the conditional. If the form is `..iiffddeeff', `..iiffnnddeeff', or `..iiff' - the ``defined'' expression is applied. Similarly, if the form is - `..iiffmmaakkee' or `..iiffnnmmaakkee, tthhee' ``make'' expression is applied. - - If the conditional evaluates to true the parsing of the makefile contin- - ues as before. If it evaluates to false, the following lines are - skipped. In both cases this continues until a `..eellssee' or `..eennddiiff' is - found. - - For loops are typically used to apply a set of rules to a list of files. - The syntax of a for loop is: - - ..ffoorr _v_a_r_i_a_b_l_e [_v_a_r_i_a_b_l_e _._._.] iinn _e_x_p_r_e_s_s_i_o_n - - ..eennddffoorr - - After the for eexxpprreessssiioonn is evaluated, it is split into words. On each - iteration of the loop, one word is taken and assigned to each vvaarriiaabbllee, - in order, and these vvaarriiaabblleess are substituted into the mmaakkee--rruulleess inside - the body of the for loop. The number of words must come out even; that - is, if there are three iteration variables, the number of words provided - must be a multiple of three. - -CCOOMMMMEENNTTSS - Comments begin with a hash (`#') character, anywhere but in a shell com- - mand line, and continue to the end of an unescaped new line. - -SSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS)) - ..EEXXEECC Target is never out of date, but always execute commands any- - way. - - ..IIGGNNOORREE Ignore any errors from the commands associated with this tar- - get, exactly as if they all were preceded by a dash (`-'). - - ..MMAADDEE Mark all sources of this target as being up-to-date. - - ..MMAAKKEE Execute the commands associated with this target even if the --nn - or --tt options were specified. Normally used to mark recursive - bbmmaakkee's. - - ..MMEETTAA Create a meta file for the target, even if it is flagged as - ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL. Usage in conjunction with ..MMAAKKEE is - the most likely case. In "meta" mode, the target is out-of- - date if the meta file is missing. - - ..NNOOMMEETTAA Do not create a meta file for the target. Meta files are also - not created for ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL targets. - - ..NNOOMMEETTAA__CCMMPP - Ignore differences in commands when deciding if target is out - of date. This is useful if the command contains a value which - always changes. If the number of commands change, though, the - target will still be out of date. - - ..NNOOPPAATTHH Do not search for the target in the directories specified by - ..PPAATTHH. - - ..NNOOTTMMAAIINN Normally bbmmaakkee selects the first target it encounters as the - default target to be built if no target was specified. This - source prevents this target from being selected. - - ..OOPPTTIIOONNAALL - If a target is marked with this attribute and bbmmaakkee can't fig- - ure out how to create it, it will ignore this fact and assume - the file isn't needed or already exists. - - ..PPHHOONNYY The target does not correspond to an actual file; it is always - considered to be out of date, and will not be created with the - --tt option. Suffix-transformation rules are not applied to - ..PPHHOONNYY targets. - - ..PPRREECCIIOOUUSS - When bbmmaakkee is interrupted, it normally removes any partially - made targets. This source prevents the target from being - removed. - - ..RREECCUURRSSIIVVEE - Synonym for ..MMAAKKEE. - - ..SSIILLEENNTT Do not echo any of the commands associated with this target, - exactly as if they all were preceded by an at sign (`@'). - - ..UUSSEE Turn the target into bbmmaakkee's version of a macro. When the tar- - get is used as a source for another target, the other target - acquires the commands, sources, and attributes (except for - ..UUSSEE) of the source. If the target already has commands, the - ..UUSSEE target's commands are appended to them. - - ..UUSSEEBBEEFFOORREE - Exactly like ..UUSSEE, but prepend the ..UUSSEEBBEEFFOORREE target commands - to the target. - - ..WWAAIITT If ..WWAAIITT appears in a dependency line, the sources that precede - it are made before the sources that succeed it in the line. - Since the dependents of files are not made until the file - itself could be made, this also stops the dependents being - built unless they are needed for another branch of the depen- - dency tree. So given: - - x: a .WAIT b - echo x - a: - echo a - b: b1 - echo b - b1: - echo b1 - - the output is always `a', `b1', `b', `x'. - The ordering imposed by ..WWAAIITT is only relevant for parallel - makes. - -SSPPEECCIIAALL TTAARRGGEETTSS - Special targets may not be included with other targets, i.e. they must be - the only target specified. - - ..BBEEGGIINN Any command lines attached to this target are executed before - anything else is done. - - ..DDEEFFAAUULLTT - This is sort of a ..UUSSEE rule for any target (that was used only - as a source) that bbmmaakkee can't figure out any other way to cre- - ate. Only the shell script is used. The ..IIMMPPSSRRCC variable of a - target that inherits ..DDEEFFAAUULLTT's commands is set to the target's - own name. - - ..EENNDD Any command lines attached to this target are executed after - everything else is done. - - ..EERRRROORR Any command lines attached to this target are executed when - another target fails. The ..EERRRROORR__TTAARRGGEETT variable is set to the - target that failed. See also MMAAKKEE__PPRRIINNTT__VVAARR__OONN__EERRRROORR. - - ..IIGGNNOORREE Mark each of the sources with the ..IIGGNNOORREE attribute. If no - sources are specified, this is the equivalent of specifying the - --ii option. - - ..IINNTTEERRRRUUPPTT - If bbmmaakkee is interrupted, the commands for this target will be - executed. - - ..MMAAIINN If no target is specified when bbmmaakkee is invoked, this target - will be built. - - ..MMAAKKEEFFLLAAGGSS - This target provides a way to specify flags for bbmmaakkee when the - makefile is used. The flags are as if typed to the shell, - though the --ff option will have no effect. - - ..NNOOPPAATTHH Apply the ..NNOOPPAATTHH attribute to any specified sources. - - ..NNOOTTPPAARRAALLLLEELL - Disable parallel mode. - - ..NNOO__PPAARRAALLLLEELL - Synonym for ..NNOOTTPPAARRAALLLLEELL, for compatibility with other pmake - variants. - - ..OORRDDEERR The named targets are made in sequence. This ordering does not - add targets to the list of targets to be made. Since the depen- - dents of a target do not get built until the target itself could - be built, unless `a' is built by another part of the dependency - graph, the following is a dependency loop: - - .ORDER: b a - b: a - - The ordering imposed by ..OORRDDEERR is only relevant for parallel - makes. - - ..PPAATTHH The sources are directories which are to be searched for files - not found in the current directory. If no sources are speci- - fied, any previously specified directories are deleted. If the - source is the special ..DDOOTTLLAASSTT target, then the current working - directory is searched last. - - ..PPHHOONNYY Apply the ..PPHHOONNYY attribute to any specified sources. - - ..PPRREECCIIOOUUSS - Apply the ..PPRREECCIIOOUUSS attribute to any specified sources. If no - sources are specified, the ..PPRREECCIIOOUUSS attribute is applied to - every target in the file. - - ..SSHHEELLLL Sets the shell that bbmmaakkee will use to execute commands. The - sources are a set of _f_i_e_l_d_=_v_a_l_u_e pairs. - - _n_a_m_e This is the minimal specification, used to select - one of the builtin shell specs; _s_h, _k_s_h, and _c_s_h. - - _p_a_t_h Specifies the path to the shell. - - _h_a_s_E_r_r_C_t_l Indicates whether the shell supports exit on error. - - _c_h_e_c_k The command to turn on error checking. - - _i_g_n_o_r_e The command to disable error checking. - - _e_c_h_o The command to turn on echoing of commands executed. - - _q_u_i_e_t The command to turn off echoing of commands exe- - cuted. - - _f_i_l_t_e_r The output to filter after issuing the _q_u_i_e_t com- - mand. It is typically identical to _q_u_i_e_t. - - _e_r_r_F_l_a_g The flag to pass the shell to enable error checking. - - _e_c_h_o_F_l_a_g The flag to pass the shell to enable command echo- - ing. - - _n_e_w_l_i_n_e The string literal to pass the shell that results in - a single newline character when used outside of any - quoting characters. - Example: - - .SHELL: name=ksh path=/bin/ksh hasErrCtl=true \ - check="set -e" ignore="set +e" \ - echo="set -v" quiet="set +v" filter="set +v" \ - echoFlag=v errFlag=e newline="'\n'" - - ..SSIILLEENNTT Apply the ..SSIILLEENNTT attribute to any specified sources. If no - sources are specified, the ..SSIILLEENNTT attribute is applied to every - command in the file. - - ..SSUUFFFFIIXXEESS - Each source specifies a suffix to bbmmaakkee. If no sources are - specified, any previously specified suffixes are deleted. It - allows the creation of suffix-transformation rules. - - Example: - - .SUFFIXES: .o - .c.o: - cc -o ${.TARGET} -c ${.IMPSRC} - -EENNVVIIRROONNMMEENNTT - bbmmaakkee uses the following environment variables, if they exist: MACHINE, - MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH, - PWD, and TMPDIR. - - MAKEOBJDIRPREFIX and MAKEOBJDIR may only be set in the environment or on - the command line to bbmmaakkee and not as makefile variables; see the descrip- - tion of `_._O_B_J_D_I_R' for more details. - -FFIILLEESS - .depend list of dependencies - Makefile list of dependencies - makefile list of dependencies - sys.mk system makefile - /usr/share/mk system makefile directory - -CCOOMMPPAATTIIBBIILLIITTYY - The basic make syntax is compatible between different versions of make, - however the special variables, variable modifiers and conditionals are - not. - - The way that parallel makes are scheduled changed in NetBSD 4.0 so that - .ORDER and .WAIT apply recursively to the dependent nodes. The algo- - rithms used may change again in the future. - - The way that .for loop variables are substituted changed after NetBSD 5.0 - so that they still appear to be variable expansions. In particular this - stops them being treated as syntax, and removes some obscure problems - using them in .if statements. - - Unlike other bbmmaakkee programs, this implementation by default executes all - commands for a given target using a single shell invocation. This is - done for both efficiency and to simplify error handling in remote command - invocations. Typically this is transparent to the user, unless the tar- - get commands change the current working directory using ``cd'' or - ``chdir''. To be compatible with Makefiles that do this, one can use --BB - to disable this behavior. - - In compatibility mode, each command is run in a separate process. If the - command contains any shell meta characters (`#=|^(){};&<>*?[]:$`\\n') it - will be passed to the shell, otherwise bbmmaakkee will attempt direct execu- - tion. - -SSEEEE AALLSSOO - mkdep(1) - -HHIISSTTOORRYY - bbmmaakkee is derived from NetBSD make(1). It uses autoconf to facilitate - portability to other platforms. - - A make command appeared in Version 7 AT&T UNIX. This make implementation - is based on Adam De Boor's pmake program which was written for Sprite at - Berkeley. It was designed to be a parallel distributed make running jobs - on different machines using a daemon called ``customs''. - -BBUUGGSS - The make syntax is difficult to parse without actually acting of the - data. For instance finding the end of a variable use should involve - scanning each the modifiers using the correct terminator for each field. - In many places make just counts {} and () in order to find the end of a - variable expansion. - -MAKE(1) NetBSD General Commands Manual MAKE(1) - - There is no way of escaping a space character in a filename. - -NNAAMMEE - bbmmaakkee -- maintain program dependencies - -SSYYNNOOPPSSIISS - bbmmaakkee [--BBeeiikkNNnnqqrrssttWWXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] - [--ff _m_a_k_e_f_i_l_e] [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s] - [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_l_e] [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] - [_t_a_r_g_e_t _._._.] - -DDEESSCCRRIIPPTTIIOONN - bbmmaakkee is a program designed to simplify the maintenance of other pro- - grams. Its input is a list of specifications as to the files upon which - programs and other files depend. If no --ff _m_a_k_e_f_i_l_e makefile option is - given, bbmmaakkee will try to open `_m_a_k_e_f_i_l_e' then `_M_a_k_e_f_i_l_e' in order to find - the specifications. If the file `_._d_e_p_e_n_d' exists, it is read (see - mkdep(1)). - - This manual page is intended as a reference document only. For a more - thorough description of bbmmaakkee and makefiles, please refer to _P_M_a_k_e _- _A - _T_u_t_o_r_i_a_l. - - bbmmaakkee will prepend the contents of the _M_A_K_E_F_L_A_G_S environment variable to - the command line arguments before parsing them. - - The options are as follows: - - --BB Try to be backwards compatible by executing a single shell per - command and by executing the commands to make the sources of a - dependency line in sequence. - - --CC _d_i_r_e_c_t_o_r_y - Change to _d_i_r_e_c_t_o_r_y before reading the makefiles or doing any- - thing else. If multiple --CC options are specified, each is inter- - preted relative to the previous one: --CC _/ --CC _e_t_c is equivalent to - --CC _/_e_t_c. - - --DD _v_a_r_i_a_b_l_e - Define _v_a_r_i_a_b_l_e to be 1, in the global context. - - --dd _[_-_]_f_l_a_g_s - Turn on debugging, and specify which portions of bbmmaakkee are to - print debugging information. Unless the flags are preceded by - `-' they are added to the _M_A_K_E_F_L_A_G_S environment variable and will - be processed by any child make processes. By default, debugging - information is printed to standard error, but this can be changed - using the _F debugging flag. The debugging output is always - unbuffered; in addition, if debugging is enabled but debugging - output is not directed to standard output, then the standard out- - put is line buffered. _F_l_a_g_s is one or more of the following: - - _A Print all possible debugging information; equivalent to - specifying all of the debugging flags. - - _a Print debugging information about archive searching and - caching. - - _C Print debugging information about current working direc- - tory. - - _c Print debugging information about conditional evaluation. - - _d Print debugging information about directory searching and - caching. - - _e Print debugging information about failed commands and - targets. - - _F[++]_f_i_l_e_n_a_m_e - Specify where debugging output is written. This must be - the last flag, because it consumes the remainder of the - argument. If the character immediately after the `F' - flag is `+', then the file will be opened in append mode; - otherwise the file will be overwritten. If the file name - is `stdout' or `stderr' then debugging output will be - written to the standard output or standard error output - file descriptors respectively (and the `+' option has no - effect). Otherwise, the output will be written to the - named file. If the file name ends `.%d' then the `%d' is - replaced by the pid. - - _f Print debugging information about loop evaluation. - - _g_1 Print the input graph before making anything. - - _g_2 Print the input graph after making everything, or before - exiting on error. - - _g_3 Print the input graph before exiting on error. - - _j Print debugging information about running multiple - shells. - - _l Print commands in Makefiles regardless of whether or not - they are prefixed by `@' or other "quiet" flags. Also - known as "loud" behavior. - - _M Print debugging information about "meta" mode decisions - about targets. - - _m Print debugging information about making targets, includ- - ing modification dates. - - _n Don't delete the temporary command scripts created when - running commands. These temporary scripts are created in - the directory referred to by the TMPDIR environment vari- - able, or in _/_t_m_p if TMPDIR is unset or set to the empty - string. The temporary scripts are created by mkstemp(3), - and have names of the form _m_a_k_e_X_X_X_X_X_X. _N_O_T_E: This can - create many files in TMPDIR or _/_t_m_p, so use with care. - - _p Print debugging information about makefile parsing. - - _s Print debugging information about suffix-transformation - rules. - - _t Print debugging information about target list mainte- - nance. - - _V Force the --VV option to print raw values of variables. - - _v Print debugging information about variable assignment. + _w Print entering and leaving directory messages, pre and + post processing. _x Run shell commands with --xx so the actual commands are printed as they are executed. @@ -1613,6 +287,32 @@ SSHHEELLLL CCOOMMMMAANNDDSS line of a script. A `--' causes any non-zero exit status of the command line to be ignored. + When bbmmaakkee is run in jobs mode with --jj _m_a_x___j_o_b_s, the entire script for + the target is fed to a single instance of the shell. + + In compatibility (non-jobs) mode, each command is run in a separate + process. If the command contains any shell meta characters + (`#=|^(){};&<>*?[]:$`\\n') it will be passed to the shell, otherwise + bbmmaakkee will attempt direct execution. + + Since bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' before executing any targets, each + child process starts with that as its current working directory. + + Makefiles should be written so that the mode of bbmmaakkee operation does not + change their behavior. For example, any command which needs to use + ``cd'' or ``chdir'', without side-effect should be put in parenthesis: + + + avoid-chdir-side-effects: + @echo Building $@ in `pwd` + @(cd ${.CURDIR} && ${.MAKE} $@) + @echo Back in `pwd` + + ensure-one-shell-regardless-of-mode: + @echo Building $@ in `pwd`; \ + (cd ${.CURDIR} && ${.MAKE} $@); \ + echo Back in `pwd` + VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS Variables in make are much like variables in the shell, and, by tradi- tion, consist of all upper-case letters. @@ -1772,7 +472,8 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS _._M_A_K_E_._J_O_B_._P_R_E_F_I_X If bbmmaakkee is run with _j then output for each target is prefixed with a token `--- target ---' the first part of - which can be controlled via _._M_A_K_E_._J_O_B_._P_R_E_F_I_X. + which can be controlled via _._M_A_K_E_._J_O_B_._P_R_E_F_I_X. If + _._M_A_K_E_._J_O_B_._P_R_E_F_I_X is empty, no token is printed. For example: .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] would produce tokens like `---make[1234] target ---' mak- @@ -1854,6 +555,12 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS to process the meta files to extract dependency informa- tion. + _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___P_A_T_H_S + Provides a list of path prefixes that should be ignored; + because the contents are expected to change over time. + The default list includes: `_/_d_e_v _/_e_t_c _/_p_r_o_c _/_t_m_p _/_v_a_r_/_r_u_n + _/_v_a_r_/_t_m_p' + _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X Defines the message printed for each meta file updated in "meta verbose" mode. The default value is: @@ -1868,6 +575,11 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS `MAKEFLAGS' is re-exported whenever `_._M_A_K_E_O_V_E_R_R_I_D_E_S' is modified. + _._M_A_K_E_._P_A_T_H___F_I_L_E_M_O_N + If bbmmaakkee was built with filemon(4) support, this is set + to the path of the device node. This allows makefiles to + test for this support. + _._M_A_K_E_._P_I_D The process-id of bbmmaakkee. _._M_A_K_E_._P_P_I_D The parent process-id of bbmmaakkee. @@ -2116,7 +828,7 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS period. For example. ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} - However a single character varaiable is often more readable: + However a single character variable is often more readable: ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} ::UU_n_e_w_v_a_l @@ -2409,7 +1121,19 @@ SSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS)) Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the - target will still be out of date. + target will still be out of date. The same effect applies to + any command line that uses the variable _._O_O_D_A_T_E, which can be + used for that purpose even when not otherwise needed or + desired: + + + skip-compare-for-some: + @echo this will be compared + @echo this will not ${.OODATE:M.NOMETA_CMP} + @echo this will also be compared + + The ::MM pattern suppresses any expansion of the unwanted vari- + able. ..NNOOPPAATTHH Do not search for the target in the directories specified by ..PPAATTHH. @@ -2533,6 +1257,10 @@ SSPPEECCIIAALL TTAARRGGEETTSS source is the special ..DDOOTTLLAASSTT target, then the current working directory is searched last. + ..PPAATTHH.._s_u_f_f_i_x + Like ..PPAATTHH but applies only to files with a particular suffix. + The suffix must have been previously declared with ..SSUUFFFFIIXXEESS. + ..PPHHOONNYY Apply the ..PPHHOONNYY attribute to any specified sources. ..PPRREECCIIOOUUSS @@ -2581,6 +1309,9 @@ SSPPEECCIIAALL TTAARRGGEETTSS sources are specified, the ..SSIILLEENNTT attribute is applied to every command in the file. + ..SSTTAALLEE This target gets run when a dependency file contains stale + entries, having _._A_L_L_S_R_C set to the name of that dependency file. + ..SSUUFFFFIIXXEESS Each source specifies a suffix to bbmmaakkee. If no sources are specified, any previously specified suffixes are deleted. It @@ -2622,19 +1353,6 @@ CCOOMMPPAATTIIBBIILLIITTYY stops them being treated as syntax, and removes some obscure problems using them in .if statements. - Unlike other bbmmaakkee programs, this implementation by default executes all - commands for a given target using a single shell invocation. This is - done for both efficiency and to simplify error handling in remote command - invocations. Typically this is transparent to the user, unless the tar- - get commands change the current working directory using ``cd'' or - ``chdir''. To be compatible with Makefiles that do this, one can use --BB - to disable this behavior. - - In compatibility mode, each command is run in a separate process. If the - command contains any shell meta characters (`#=|^(){};&<>*?[]:$`\\n') it - will be passed to the shell, otherwise bbmmaakkee will attempt direct execu- - tion. - SSEEEE AALLSSOO mkdep(1) @@ -2647,6 +1365,10 @@ HHIISSTTOORRYY Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called ``customs''. + Historically the target/dependency ``FRC'' has been used to FoRCe + rebuilding (since the target/dependency does not exist... unless someone + creates an ``FRC'' file). + BBUUGGSS The make syntax is difficult to parse without actually acting of the data. For instance finding the end of a variable use should involve @@ -2656,4 +1378,4 @@ BBUUGGSS There is no way of escaping a space character in a filename. -NetBSD 5.1 October 8, 2012 NetBSD 5.1 +NetBSD 5.1 August 11, 2013 NetBSD 5.1 diff --git a/contrib/bmake/boot-strap b/contrib/bmake/boot-strap index 660b766..2193926 100755 --- a/contrib/bmake/boot-strap +++ b/contrib/bmake/boot-strap @@ -3,23 +3,52 @@ # boot-strap # # SYNOPSIS: -# boot-strap [--"configure_arg" ... ][-s "srcdir"][-m "mksrc"]\\ -# ["prefix" ["bmakesrc" ["mksrc"]]] +# boot-strap ["options"] +# boot-strap --prefix=/opt --install +# boot-strap --prefix=$HOME --install-host-target -DWITH_PROG_VERSION +# boot-strap ["options"] op=build +# boot-strap ["options"] op=install # # DESCRIPTION: # This script is used to configure/build bmake it builds for -# each OS in a subdir to keep the src clean. -# On successful completion it echos commands to put the new -# bmake binary into the /configs tree (if it exists) -# (http://www.crufty.net/FreeWare/configs.html), $prefix/bin -# and a suitable ~/*bin directory. +# each host-target in a different subdir to keep the src clean. +# There is no requirement for an existing make(1). # +# On successful completion if no '--install' flag is given, +# it echos a command to do installation. +# +# The variable "op" defaults to 'all', and is affected by +# '--install' flag as above. +# Other values include: +# +# configure +# Just run 'configure' +# +# build +# If 'configure' has not been done, do it, then +# run the build script, and finally 'test'. +# +# install +# If 'build' has not been done, do it, 'test' then +# install. +# +# clean +# attempt to clean up +# +# test +# run the unit-tests. Done automatically after 'build' +# and before 'install'. +# +# The above are leveraged by a trivial makefile for the benefit +# of those that have './configure; make; make install' baked +# into them. +# # Options: # # -c "rc" # Pick up settings from "rc". # We look for '.bmake-boot-strap.rc' before processing -# options. +# options (unless SKIP_RC is set in environment). # # --share "share_dir" # Where to put man pages and mk files. @@ -28,9 +57,28 @@ # # --mksrc "mksrc" # Indicate where the mk files can be found. -# Default is ./mk or ../mk, set to 'none' to force -# building without "mksrc" but in that case a sys.mk -# needs to exist in the default syspath ($share_dir/mk) +# Default is $Mydir/mk +# +# --install +# If build and test work, run bmake install. +# BINDIR=$prefix/bin +# SHAREDIR=$prefix/share +# +# --install-host-target +# As for '--install' but BINDIR=$prefix/$HOST_TARGET/bin +# This is useful when $prefix/ is shared by multiple +# machines. +# +# Flags relevant when installing: +# +# -DWITHOUT_INSTALL_MK +# Skip installing mk files. +# By default they will be installed to $prefix/share/mk +# +# -DWITH_PROG_VERSION +# Install 'bmake' as 'bmake-$MAKE_VERSION' +# A symlink will be made as 'bmake' unless +# -DWITHOUT_PROG_LINK is set. # # Possibly useful configure_args: # @@ -63,7 +111,7 @@ # Simon J. Gerraty # RCSid: -# $Id: boot-strap,v 1.39 2012/03/26 17:08:22 sjg Exp $ +# $Id: boot-strap,v 1.43 2013/03/02 18:55:23 sjg Exp $ # # @(#) Copyright (c) 2001 Simon J. Gerraty # @@ -85,11 +133,10 @@ case "$Mydir" in *) Mydir=`cd "$Mydir" && 'pwd'`;; esac - Usage() { [ "$1" ] && echo "ERROR: $@" >&2 echo "Usage:" >&2 - echo "$0 [-- ...][-s ][-m ][ [[] []]]" >&2 + echo "$0 [-- ...][][--install]" >&2 exit 1 } @@ -110,28 +157,58 @@ source_rc() { done } +cmd_args="$@" + +# clear some things from the environment that we care about +unset MAKEOBJDIR MAKEOBJDIRPREFIX + +# --install[-host-target] will set this +INSTALL_PREFIX= +# other things we pass to install step +INSTALL_ARGS= CONFIGURE_ARGS= MAKESYSPATH= # pick a useful default prefix (for me at least ;-) for prefix in /opt/$HOST_TARGET "$HOME/$HOST_TARGET" /usr/pkg /usr/local "" do - [ -d "${prefix:-.}" ] && break + [ -d "${prefix:-.}" ] || continue + case "$prefix" in + */$HOST_TARGET) + p=`dirname $prefix` + if [ -d $p/share ]; then + INSTALL_BIN=$HOST_TARGET/bin + prefix=$p + fi + ;; + esac + echo "NOTE: default prefix=$prefix ${INSTALL_BIN:+INSTALL_BIN=$INSTALL_BIN}" + break done -srcdir= -mksrc= +srcdir=$Mydir +mksrc=$Mydir/mk objdir= quiet=: -source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME" +${SKIP_RC:+:} source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME" get_optarg() { expr "x$1" : "x[^=]*=\\(.*\\)" } +here=`'pwd'` +if [ $here = $Mydir ]; then + # avoid polution + OBJROOT=../ +fi + +op=all +BMAKE= + while : do case "$1" in --) shift; break;; + --help) sed -n -e "1d;/RCSid/,\$d" -e '/^#\.[a-z]/d' -e '/^#/s,^# *,,p' $0; exit 0;; --prefix) prefix="$2"; shift;; --prefix=*) prefix=`get_optarg "$1"`;; --src=*) srcdir=`get_optarg "$1"`;; @@ -144,6 +221,13 @@ do --with-default-sys-path) CONFIGURE_ARGS="$1 $2" MAKESYSPATH="$2"; shift;; + --install) INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix};; + --install-host-target) + INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix} + INSTALL_BIN=$HOST_TARGET/bin;; + --install-destdir=*) INSTALL_DESTDIR=`get_optarg "$1"`;; + --install-prefix=*) INSTALL_PREFIX=`get_optarg "$1"`;; + -DWITH*) INSTALL_ARGS="$INSTALL_ARGS $1";; -s|--src) srcdir="$2"; shift;; -m|--mksrc) mksrc="$2"; shift;; -o|--objdir) objdir="$2"; shift;; @@ -261,7 +345,7 @@ none|-) # we don't want it esac # Ok, get to work... -objdir="${objdir:-$OS}" +objdir="${objdir:-$OBJROOT$HOST_TARGET}" [ -d "$objdir" ] || mkdir -p "$objdir" [ -d "$objdir" ] || mkdir "$objdir" cd "$objdir" || exit 1 @@ -301,88 +385,80 @@ if [ "$mksrc" ]; then export CFLAGS_MF CFLAGS_MD fi -$srcdir/configure $CONFIGURE_ARGS || exit 1 -chmod 755 make-bootstrap.sh || exit 1 -./make-bootstrap.sh || exit 1 -if [ -z "$MAKESYSPATH" ]; then - add_path "${share_dir:-...}/mk" MAKESYSPATH - case "$HOST_TARGET" in - netbsd*) add_path /usr/share/mk MAKESYSPATH;; - esac -fi -if [ -s "${mksrc:-/dev/null}/install-mk" ]; then - sh "${mksrc}/install-mk" "$objdir/mk" - case "$MAKESYSPATH" in - .../mk*) ;; - *) MAKESYSPATH=".../mk:${MAKESYSPATH}";; - esac -fi +# this makes it easy to run the bmake we just built +# the :tA dance is needed because 'pwd' and even /bin/pwd +# may not give the same result as realpath(). +Bmake() { + ( + cd $Mydir && + MAKESYSPATH=$mksrc SRCTOP=$Mydir OBJTOP=$objdir \ + MAKEOBJDIR='${.CURDIR:S,${SRCTOP:tA},${OBJTOP:tA},}' \ + ${BMAKE:-$objdir/bmake} -f $Mydir/Makefile "$@" + ) +} + # make sure test below uses the same diff that configure did TOOL_DIFF=`type diff | sed 's,[()],,g;s,^[^/][^/]*,,;q'` -export MAKESYSPATH TOOL_DIFF -if [ "$mksrc" ]; then - $objdir/bmake test || exit 1 -else - # assume nothing - $objdir/bmake -r -m / test || exit 1 -fi -# If -q given, we don't want all the install instructions -$quiet exit 0 - -make_version=`./bmake -r -m / -f ./Makefile -V MAKE_VERSION | ( read one two; echo $one )` -bmake_version=bmake-$make_version - -if [ -s /usr/share/tmac/andoc.tmac ]; then - # this should be ok - man_subdir=man1 - man_src=$srcdir/bmake.1 -else - # guess not - man_subdir=cat1 - man_src=$srcdir/bmake.cat1 -fi +export TOOL_DIFF -install_prefix() { - ( - bin_dir= - share_dir= - man_dir= - mk_dir= - while : - do - case "$1" in - *=*) eval "$1"; shift;; - *) break;; - esac - done - bin_dir=${bin_dir:-$1/bin} - share_dir=${share_dir:-`ShareDir "$1"`} - man_dir=${man_dir:-$share_dir/man} - mk_dir=${mk_dir:-$share_dir/mk} - echo - echo Commands to install into $1/ - echo - echo mkdir -p $bin_dir - echo cp $objdir/bmake $bin_dir/$bmake_version - echo rm -f $bin_dir/bmake - echo ln -s $bmake_version $bin_dir/bmake - echo mkdir -p $man_dir/$man_subdir - echo cp $man_src $man_dir/$man_subdir/bmake.1 - if [ "$mksrc" ]; then - ev=`env | grep '_MK='` - echo $ev sh $mksrc/install-mk $mk_dir +op_configure() { + $srcdir/configure $CONFIGURE_ARGS || exit 1 +} + +op_build() { + [ -s make-bootstrap.sh ] || op_configure + chmod 755 make-bootstrap.sh || exit 1 + ./make-bootstrap.sh || exit 1 + case "$op" in + build) op_test;; + esac +} + +op_test() { + [ -x bmake ] || op_build + Bmake test || exit 1 +} + +op_clean() { + if [ -x bmake ]; then + ln bmake bmake$$ + BMAKE=$objdir/bmake$$ Bmake clean + rm -f bmake$$ + elif [ $objdir != $srcdir ]; then + rm -rf * fi - ) } -case "$prefix/" in -"$HOME"/*) ;; -*) CONFIGS=${CONFIGS:-/configs} - [ -d $CONFIGS ] && - install_prefix mksrc= "$CONFIGS/$OS/$OSMAJOR.X/$MACHINE_ARCH$prefix" - # I like to keep a copy here... - install_prefix share_dir="$HOME/share" "$HOME/$HOST_TARGET" - ;; -esac +op_install() { + op_test + case "$INSTALL_PREFIX,$INSTALL_BIN,$prefix" in + ,$HOST_TARGET/bin,*/$HOST_TARGET) + INSTALL_PREFIX=`dirname $prefix` + ;; + esac + INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix} + Bmake install prefix=$INSTALL_PREFIX BINDIR=$INSTALL_PREFIX/${INSTALL_BIN:-bin} ${INSTALL_DESTDIR:+DESTDIR=$INSTALL_DESTDIR} $INSTALL_ARGS || exit 1 +} + +op_all() { + rm -f make-bootstrap.sh bmake *.o + if [ -n "$INSTALL_PREFIX" ]; then + op_install + else + op_test + MAKE_VERSION=`sed -n '/^MAKE_VERSION/ { s,.*= *,,;p; }' $srcdir/Makefile` + echo You can install by running: + echo + echo $0 $cmd_args op=install + echo + echo "Use --install-prefix=/something to install somewhere other than $prefix" + echo "Use --install-destdir=/somewhere to set DESTDIR during install" + echo "Use --install-host-target to use INSTALL_BIN=$HOST_TARGET/bin" + echo "Use -DWITH_PROG_VERSION to install as bmake-$MAKE_VERSION" + echo "Use -DWITHOUT_PROG_LINK to supress bmake -> bmake-$MAKE_VERSION symlink" + echo "Use -DWITHOUT_INSTALL_MK to skip installing files to $prefix/share/mk" + fi +} -install_prefix "$prefix" +op_$op +exit 0 diff --git a/contrib/bmake/bsd.after-import.mk b/contrib/bmake/bsd.after-import.mk index 6cd442a..85bd2c1 100644 --- a/contrib/bmake/bsd.after-import.mk +++ b/contrib/bmake/bsd.after-import.mk @@ -1,4 +1,4 @@ -# $Id: bsd.after-import.mk,v 1.9 2012/09/20 00:30:15 sjg Exp $ +# $Id: bsd.after-import.mk,v 1.11 2012/12/29 19:32:25 sjg Exp $ # This makefile is for use when integrating bmake into a BSD build # system. Use this makefile after importing bmake. @@ -48,36 +48,36 @@ DEFAULT_SYS_PATH= .../share/mk:/usr/share/mk BOOTSTRAP_ARGS = \ --with-default-sys-path='${DEFAULT_SYS_PATH}' \ --prefix /usr \ - --share /usr/share \ - --mksrc none + --share /usr/share + # run boot-strap with minimal influence bootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE} - HOME=/ ${BMAKE_SRC}/boot-strap ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS} + HOME=/ ${BMAKE_SRC}/boot-strap -o ${HOST_OS} ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS} touch ${.TARGET} # Makefiles need a little more tweaking than say config.h MAKEFILE_SED = sed -e '/^MACHINE/d' \ -e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \ -e 's,^.-include,.sinclude,' \ + -e '/^\..*include * ${.CURDIR}/$f .endfor -.for f in ${configured_files:M*Makefile} +.for f in ${configured_files:M*Makefile*} @echo Capturing $f @mkdir -p ${${.CURDIR}/$f:L:H} @(echo '# This is a generated file, do NOT edit!'; \ echo '# See ${_this:S,${SRCTOP}/,,}'; \ - echo '#'; echo '# $$${OS}$$'; echo; \ + echo '#'; echo '# $$${HOST_OS}$$'; echo; \ echo 'SRCTOP?= $${.CURDIR:${${.CURDIR}/$f:L:H:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; echo; \ ${MAKEFILE_SED} ${HOST_OS}/$f ) > ${.CURDIR}/$f .endfor @@ -87,18 +87,22 @@ _makefile: bootstrap ${MAKEFILE} @echo Generating ${.CURDIR}/Makefile @(echo '# This is a generated file, do NOT edit!'; \ echo '# See ${_this:S,${SRCTOP}/,,}'; \ - echo '#'; echo '# $$${OS}$$'; \ + echo '#'; echo '# $$${HOST_OS}$$'; \ echo; echo '.sinclude "Makefile.inc"'; \ echo; echo 'SRCTOP?= $${.CURDIR:${.CURDIR:S,${SRCTOP}/,,:C,[^/]+,H,g:S,/,:,g}}'; \ echo; echo '# look here first for config.h'; \ echo 'CFLAGS+= -I$${.CURDIR}'; echo; \ - ${MAKEFILE_SED} ${HOST_OS}/Makefile; \ + echo '# for after-import'; \ + echo 'CLEANDIRS+= ${HOST_OS}'; \ + echo 'CLEANFILES+= bootstrap'; echo; \ + ${MAKEFILE_SED} \ + ${1 2:L:@n@-e '/start-delete$n/,/end-delete$n/d'@} \ + ${BMAKE_SRC}/Makefile; \ echo; echo '# override some simple things'; \ echo 'BINDIR= /usr/bin'; \ echo 'MANDIR= ${MANDIR:U/usr/share/man}'; \ echo; echo '# make sure we get this'; \ echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \ - echo 'CLEANFILES+= bootstrap'; \ echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \ echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \ echo ) > ${.TARGET} diff --git a/contrib/bmake/compat.c b/contrib/bmake/compat.c index 4cc699e..b0bbc93 100644 --- a/contrib/bmake/compat.c +++ b/contrib/bmake/compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.90 2012/10/07 19:17:31 sjg Exp $ */ +/* $NetBSD: compat.c,v 1.93 2013/09/02 19:26:42 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: compat.c,v 1.90 2012/10/07 19:17:31 sjg Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.93 2013/09/02 19:26:42 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: compat.c,v 1.90 2012/10/07 19:17:31 sjg Exp $"); +__RCSID("$NetBSD: compat.c,v 1.93 2013/09/02 19:26:42 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -332,18 +332,23 @@ again: * We need to pass the command off to the shell, typically * because the command contains a "meta" character. */ - static const char *shargv[4]; + static const char *shargv[5]; + int shargc; - shargv[0] = shellPath; + shargc = 0; + shargv[shargc++] = shellPath; /* * The following work for any of the builtin shell specs. */ + if (errCheck && shellErrFlag) { + shargv[shargc++] = shellErrFlag; + } if (DEBUG(SHELL)) - shargv[1] = "-xc"; + shargv[shargc++] = "-xc"; else - shargv[1] = "-c"; - shargv[2] = cmd; - shargv[3] = NULL; + shargv[shargc++] = "-c"; + shargv[shargc++] = cmd; + shargv[shargc++] = NULL; av = shargv; argc = 0; bp = NULL; @@ -377,7 +382,6 @@ again: Fatal("Could not fork"); } if (cpid == 0) { - Check_Cwd(av); Var_ExportVars(); #ifdef USE_META if (useMeta) { diff --git a/contrib/bmake/cond.c b/contrib/bmake/cond.c index 6d0b965..a1c6705 100644 --- a/contrib/bmake/cond.c +++ b/contrib/bmake/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $ */ +/* $NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $"; +static char rcsid[] = "$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $"); +__RCSID("$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $"); #endif #endif /* not lint */ #endif @@ -1227,7 +1227,8 @@ do_Cond_EvalExpression(Boolean *value) int Cond_Eval(char *line) { - #define MAXIF 128 /* maximum depth of .if'ing */ +#define MAXIF 128 /* maximum depth of .if'ing */ +#define MAXIF_BUMP 32 /* how much to grow by */ enum if_states { IF_ACTIVE, /* .if or .elif part active */ ELSE_ACTIVE, /* .else part active */ @@ -1235,7 +1236,8 @@ Cond_Eval(char *line) SKIP_TO_ELSE, /* has been true, but not seen '.else' */ SKIP_TO_ENDIF /* nothing else to execute */ }; - static enum if_states cond_state[MAXIF + 1] = { IF_ACTIVE }; + static enum if_states *cond_state = NULL; + static unsigned int max_if_depth = MAXIF; const struct If *ifp; Boolean isElif; @@ -1244,7 +1246,10 @@ Cond_Eval(char *line) enum if_states state; level = PARSE_FATAL; - + if (!cond_state) { + cond_state = bmake_malloc(max_if_depth * sizeof(*cond_state)); + cond_state[0] = IF_ACTIVE; + } /* skip leading character (the '.') and any whitespace */ for (line++; *line == ' ' || *line == '\t'; line++) continue; @@ -1261,8 +1266,6 @@ Cond_Eval(char *line) } /* Return state for previous conditional */ cond_depth--; - if (cond_depth > MAXIF) - return COND_SKIP; return cond_state[cond_depth] <= ELSE_ACTIVE ? COND_PARSE : COND_SKIP; } @@ -1275,8 +1278,6 @@ Cond_Eval(char *line) return COND_PARSE; } - if (cond_depth > MAXIF) - return COND_SKIP; state = cond_state[cond_depth]; switch (state) { case SEARCH_FOR_ELIF: @@ -1325,9 +1326,6 @@ Cond_Eval(char *line) Parse_Error(level, "if-less elif"); return COND_PARSE; } - if (cond_depth > MAXIF) - /* Error reported when we saw the .if ... */ - return COND_SKIP; state = cond_state[cond_depth]; if (state == SKIP_TO_ENDIF || state == ELSE_ACTIVE) { Parse_Error(PARSE_WARNING, "extra elif"); @@ -1341,10 +1339,15 @@ Cond_Eval(char *line) } } else { /* Normal .if */ - if (cond_depth >= MAXIF) { - cond_depth++; - Parse_Error(PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); - return COND_SKIP; + if (cond_depth + 1 >= max_if_depth) { + /* + * This is rare, but not impossible. + * In meta mode, dirdeps.mk (only runs at level 0) + * can need more than the default. + */ + max_if_depth += MAXIF_BUMP; + cond_state = bmake_realloc(cond_state, max_if_depth * + sizeof(*cond_state)); } state = cond_state[cond_depth]; cond_depth++; diff --git a/contrib/bmake/configure b/contrib/bmake/configure index ee479f1..7accf1a 100755 --- a/contrib/bmake/configure +++ b/contrib/bmake/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.64 for bmake 20120620. +# Generated by GNU Autoconf 2.64 for bmake 20130706. # # Report bugs to . # @@ -549,8 +549,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='bmake' PACKAGE_TARNAME='bmake' -PACKAGE_VERSION='20120620' -PACKAGE_STRING='bmake 20120620' +PACKAGE_VERSION='20130706' +PACKAGE_STRING='bmake 20130706' PACKAGE_BUGREPORT='sjg@NetBSD.org' PACKAGE_URL='' @@ -1220,7 +1220,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures bmake 20120620 to adapt to many kinds of systems. +\`configure' configures bmake 20130706 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1281,7 +1281,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of bmake 20120620:";; + short | recursive ) echo "Configuration of bmake 20130706:";; esac cat <<\_ACEOF @@ -1386,7 +1386,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -bmake configure 20120620 +bmake configure 20130706 generated by GNU Autoconf 2.64 Copyright (C) 2009 Free Software Foundation, Inc. @@ -1907,7 +1907,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by bmake $as_me 20120620, which was +It was created by bmake $as_me 20130706, which was generated by GNU Autoconf 2.64. Invocation command line was $ $0 $@ @@ -2257,6 +2257,11 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers config.h" +case "$srcdir" in +/*) ;; +*) srcdir=`cd $srcdir && pwd`;; +esac + # Check whether --with-defshell was given. if test "${with_defshell+set}" = set; then : @@ -4240,13 +4245,6 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' -echo $ECHO_N "checking if sh will pass .MAKE. variables... $ECHO_C" >&6 -ok=`env .MAKE.LEVEL=1 /bin/sh -c env | grep LEVEL=` -case "$ok" in -"") echo no >&6; CPPFLAGS="${CPPFLAGS} -DNEED_MAKE_LEVEL_SAFE";; -*) echo yes >&6;; -esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } @@ -5861,7 +5859,7 @@ fi -ac_config_files="$ac_config_files Makefile make-bootstrap.sh unit-tests/Makefile" +ac_config_files="$ac_config_files makefile Makefile.config make-bootstrap.sh unit-tests/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -6369,7 +6367,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by bmake $as_me 20120620, which was +This file was extended by bmake $as_me 20130706, which was generated by GNU Autoconf 2.64. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6429,7 +6427,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -bmake config.status 20120620 +bmake config.status 20130706 configured by $0, generated by GNU Autoconf 2.64, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" @@ -6544,7 +6542,8 @@ for ac_config_target in $ac_config_targets do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "makefile") CONFIG_FILES="$CONFIG_FILES makefile" ;; + "Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;; "make-bootstrap.sh") CONFIG_FILES="$CONFIG_FILES make-bootstrap.sh" ;; "unit-tests/Makefile") CONFIG_FILES="$CONFIG_FILES unit-tests/Makefile" ;; diff --git a/contrib/bmake/configure.in b/contrib/bmake/configure.in index 156034b..ac2cc2e 100644 --- a/contrib/bmake/configure.in +++ b/contrib/bmake/configure.in @@ -1,12 +1,18 @@ dnl dnl RCSid: -dnl $Id: configure.in,v 1.45 2012/06/20 22:43:41 sjg Exp $ +dnl $Id: configure.in,v 1.49 2013/07/06 18:25:19 sjg Exp $ dnl dnl Process this file with autoconf to produce a configure script dnl -AC_INIT([bmake], [20120620], [sjg@NetBSD.org]) +AC_INIT([bmake], [20130706], [sjg@NetBSD.org]) AC_CONFIG_HEADER(config.h) +dnl make srcdir absolute +case "$srcdir" in +/*) ;; +*) srcdir=`cd $srcdir && pwd`;; +esac + dnl AC_ARG_WITH(defshell, [ --with-defshell=SHELL use SHELL by default - must be sh compatible, use sh or ksh to pick the internal definitions], @@ -73,15 +79,6 @@ dnl Executable suffix - normally empty; .exe on os2. AC_SUBST(ac_exe_suffix)dnl dnl -dnl Check if /bin/sh will pass .MAKE.LEVEL -echo $ECHO_N "checking if sh will pass .MAKE. variables... $ECHO_C" >&6 -ok=`env .MAKE.LEVEL=1 /bin/sh -c env | grep LEVEL=` -case "$ok" in -"") echo no >&6; CPPFLAGS="${CPPFLAGS} -DNEED_MAKE_LEVEL_SAFE";; -*) echo yes >&6;; -esac - -dnl dnl AC_C_CROSS dnl @@ -357,7 +354,7 @@ AC_SUBST(GCC) AC_SUBST(diff_u) AC_SUBST(use_meta) AC_SUBST(filemon_h) -AC_OUTPUT(Makefile make-bootstrap.sh unit-tests/Makefile) +AC_OUTPUT(makefile Makefile.config make-bootstrap.sh unit-tests/Makefile) cat < #ifndef lint #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: dir.c,v 1.65 2012/06/12 19:21:50 joerg Exp $"); +__RCSID("$NetBSD: dir.c,v 1.67 2013/03/05 22:01:43 christos Exp $"); #endif #endif /* not lint */ #endif @@ -145,6 +145,7 @@ __RCSID("$NetBSD: dir.c,v 1.65 2012/06/12 19:21:50 joerg Exp $"); #include "make.h" #include "hash.h" #include "dir.h" +#include "job.h" /* * A search path consists of a Lst of Path structures. A Path structure @@ -1463,9 +1464,11 @@ Dir_MTime(GNode *gn, Boolean recheck) * so that we give that to the compiler. */ gn->path = bmake_strdup(fullName); - fprintf(stdout, - "%s: ignoring stale %s for %s, found %s\n", - progname, makeDependfile, gn->name, fullName); + if (!Job_RunTarget(".STALE", gn->fname)) + fprintf(stdout, + "%s: %s, %d: ignoring stale %s for %s, " + "found %s\n", progname, gn->fname, gn->lineno, + makeDependfile, gn->name, fullName); } } } diff --git a/contrib/bmake/job.c b/contrib/bmake/job.c index 99e05d5..b5dbf4c 100644 --- a/contrib/bmake/job.c +++ b/contrib/bmake/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.163 2012/07/03 21:03:40 sjg Exp $ */ +/* $NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.163 2012/07/03 21:03:40 sjg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.163 2012/07/03 21:03:40 sjg Exp $"); +__RCSID("$NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -142,6 +142,7 @@ __RCSID("$NetBSD: job.c,v 1.163 2012/07/03 21:03:40 sjg Exp $"); #include #include "wait.h" +#include #include #include #if !defined(USE_SELECT) && defined(HAVE_POLL_H) @@ -312,6 +313,7 @@ static Shell *commandShell = &shells[DEFSHELL_INDEX]; /* this is the shell to const char *shellPath = NULL, /* full pathname of * executable image */ *shellName = NULL; /* last component of shell */ +char *shellErrFlag = NULL; static const char *shellArgv = NULL; /* Custom shell args */ @@ -343,7 +345,7 @@ static Job childExitJob; /* child exit pseudo-job */ #define TARG_FMT "%s %s ---\n" /* Default format */ #define MESSAGE(fp, gn) \ - if (maxJobs != 1) \ + if (maxJobs != 1 && targPrefix && *targPrefix) \ (void)fprintf(fp, TARG_FMT, targPrefix, gn->name) static sigset_t caught_signals; /* Set of signals we handle */ @@ -413,6 +415,15 @@ JobCreatePipe(Job *job, int minfd) if (pipe(job->jobPipe) == -1) Punt("Cannot create pipe: %s", strerror(errno)); + for (i = 0; i < 2; i++) { + /* Avoid using low numbered fds */ + fd = fcntl(job->jobPipe[i], F_DUPFD, minfd); + if (fd != -1) { + close(job->jobPipe[i]); + job->jobPipe[i] = fd; + } + } + /* Set close-on-exec flag for both */ (void)fcntl(job->jobPipe[0], F_SETFD, 1); (void)fcntl(job->jobPipe[1], F_SETFD, 1); @@ -425,15 +436,6 @@ JobCreatePipe(Job *job, int minfd) */ fcntl(job->jobPipe[0], F_SETFL, fcntl(job->jobPipe[0], F_GETFL, 0) | O_NONBLOCK); - - for (i = 0; i < 2; i++) { - /* Avoid using low numbered fds */ - fd = fcntl(job->jobPipe[i], F_DUPFD, minfd); - if (fd != -1) { - close(job->jobPipe[i]); - job->jobPipe[i] = fd; - } - } } /*- @@ -490,7 +492,8 @@ JobCondPassSig(int signo) static void JobChildSig(int signo MAKE_ATTR_UNUSED) { - write(childExitJob.outPipe, CHILD_EXIT, 1); + while (write(childExitJob.outPipe, CHILD_EXIT, 1) == -1 && errno == EAGAIN) + continue; } @@ -517,7 +520,9 @@ JobContinueSig(int signo MAKE_ATTR_UNUSED) * Defer sending to SIGCONT to our stopped children until we return * from the signal handler. */ - write(childExitJob.outPipe, DO_JOB_RESUME, 1); + while (write(childExitJob.outPipe, DO_JOB_RESUME, 1) == -1 && + errno == EAGAIN) + continue; } /*- @@ -688,7 +693,6 @@ JobPrintCommand(void *cmdp, void *jobp) char *escCmd = NULL; /* Command with quotes/backticks escaped */ char *cmd = (char *)cmdp; Job *job = (Job *)jobp; - char *cp, *tmp; int i, j; noSpecials = NoExecute(job->node); @@ -860,11 +864,6 @@ JobPrintCommand(void *cmdp, void *jobp) job->flags |= JOB_TRACED; } - if ((cp = Check_Cwd_Cmd(cmd)) != NULL) { - DBPRINTF("test -d %s && ", cp); - DBPRINTF("cd %s\n", cp); - } - DBPRINTF(cmdTemplate, cmd); free(cmdStart); if (escCmd) @@ -884,10 +883,6 @@ JobPrintCommand(void *cmdp, void *jobp) if (shutUp && commandShell->hasEchoCtl) { DBPRINTF("%s\n", commandShell->echoOn); } - if (cp != NULL) { - DBPRINTF("test -d %s && ", cp); - DBPRINTF("cd %s\n", Var_Value(".OBJDIR", VAR_GLOBAL, &tmp)); - } return 0; } @@ -1185,7 +1180,8 @@ Job_Touch(GNode *gn, Boolean silent) */ if (read(streamID, &c, 1) == 1) { (void)lseek(streamID, (off_t)0, SEEK_SET); - (void)write(streamID, &c, 1); + while (write(streamID, &c, 1) == -1 && errno == EAGAIN) + continue; } (void)close(streamID); @@ -1251,8 +1247,10 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) static const char msg[] = ": don't know how to make"; if (gn->flags & FROM_DEPEND) { - fprintf(stdout, "%s: ignoring stale %s for %s\n", - progname, makeDependfile, gn->name); + if (!Job_RunTarget(".STALE", gn->fname)) + fprintf(stdout, "%s: %s, %d: ignoring stale %s for %s\n", + progname, gn->fname, gn->lineno, makeDependfile, + gn->name); return TRUE; } @@ -2069,31 +2067,45 @@ Job_CatchOutput(void) (void)fflush(stdout); /* The first fd in the list is the job token pipe */ - nready = poll(fds + 1 - wantToken, nfds - 1 + wantToken, POLL_MSEC); + do { + nready = poll(fds + 1 - wantToken, nfds - 1 + wantToken, POLL_MSEC); + } while (nready < 0 && errno == EINTR); + + if (nready < 0) + Punt("poll: %s", strerror(errno)); - if (nready < 0 || readyfd(&childExitJob)) { + if (nready > 0 && readyfd(&childExitJob)) { char token = 0; - nready -= 1; - (void)read(childExitJob.inPipe, &token, 1); - if (token == DO_JOB_RESUME[0]) - /* Complete relay requested from our SIGCONT handler */ - JobRestartJobs(); - Job_CatchChildren(); + ssize_t count; + count = read(childExitJob.inPipe, &token, 1); + switch (count) { + case 0: + Punt("unexpected eof on token pipe"); + case -1: + Punt("token pipe read: %s", strerror(errno)); + case 1: + if (token == DO_JOB_RESUME[0]) + /* Complete relay requested from our SIGCONT handler */ + JobRestartJobs(); + break; + default: + abort(); + } + --nready; } - if (nready <= 0) - return; - - if (wantToken && readyfd(&tokenWaitJob)) - nready--; + Job_CatchChildren(); + if (nready == 0) + return; for (i = 2; i < nfds; i++) { if (!fds[i].revents) continue; job = jobfds[i]; - if (job->job_state != JOB_ST_RUNNING) - continue; - JobDoOutput(job, FALSE); + if (job->job_state == JOB_ST_RUNNING) + JobDoOutput(job, FALSE); + if (--nready == 0) + return; } } @@ -2141,6 +2153,24 @@ Shell_Init(void) if (commandShell->echo == NULL) { commandShell->echo = ""; } + if (commandShell->hasErrCtl && *commandShell->exit) { + if (shellErrFlag && + strcmp(commandShell->exit, &shellErrFlag[1]) != 0) { + free(shellErrFlag); + shellErrFlag = NULL; + } + if (!shellErrFlag) { + int n = strlen(commandShell->exit) + 2; + + shellErrFlag = bmake_malloc(n); + if (shellErrFlag) { + snprintf(shellErrFlag, n, "-%s", commandShell->exit); + } + } + } else if (shellErrFlag) { + free(shellErrFlag); + shellErrFlag = NULL; + } } /*- @@ -2184,8 +2214,7 @@ Job_SetPrefix(void) void Job_Init(void) { - GNode *begin; /* node for commands to do at the very start */ - + Job_SetPrefix(); /* Allocate space for all the job info */ job_table = bmake_malloc(maxJobs * sizeof *job_table); memset(job_table, 0, maxJobs * sizeof *job_table); @@ -2261,15 +2290,7 @@ Job_Init(void) ADDSIG(SIGCONT, JobContinueSig) #undef ADDSIG - begin = Targ_FindNode(".BEGIN", TARG_NOCREATE); - - if (begin != NULL) { - JobRun(begin); - if (begin->made == ERROR) { - PrintOnError(begin, "\n\nStop."); - exit(1); - } - } + (void)Job_RunTarget(".BEGIN", NULL); postCommands = Targ_FindNode(".END", TARG_CREATE); } @@ -2495,6 +2516,8 @@ Job_ParseShell(char *line) commandShell = bmake_malloc(sizeof(Shell)); *commandShell = newShell; } + /* this will take care of shellErrFlag */ + Shell_Init(); } if (commandShell->echoOn && commandShell->echoOff) { @@ -2805,7 +2828,8 @@ JobTokenAdd(void) if (DEBUG(JOB)) fprintf(debug_file, "(%d) aborting %d, deposit token %c\n", getpid(), aborting, JOB_TOKENS[aborting]); - write(tokenWaitJob.outPipe, &tok, 1); + while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN) + continue; } /*- @@ -2826,6 +2850,8 @@ Job_ServerStart(int max_tokens, int jp_0, int jp_1) /* Pipe passed in from parent */ tokenWaitJob.inPipe = jp_0; tokenWaitJob.outPipe = jp_1; + (void)fcntl(jp_0, F_SETFD, 1); + (void)fcntl(jp_1, F_SETFD, 1); return; } @@ -2918,13 +2944,15 @@ Job_TokenWithdraw(void) while (read(tokenWaitJob.inPipe, &tok1, 1) == 1) continue; /* And put the stopper back */ - write(tokenWaitJob.outPipe, &tok, 1); + while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN) + continue; Fatal("A failure has been detected in another branch of the parallel make"); } if (count == 1 && jobTokensRunning == 0) /* We didn't want the token really */ - write(tokenWaitJob.outPipe, &tok, 1); + while (write(tokenWaitJob.outPipe, &tok, 1) == -1 && errno == EAGAIN) + continue; jobTokensRunning++; if (DEBUG(JOB)) @@ -2932,6 +2960,38 @@ Job_TokenWithdraw(void) return TRUE; } +/*- + *----------------------------------------------------------------------- + * Job_RunTarget -- + * Run the named target if found. If a filename is specified, then + * set that to the sources. + * + * Results: + * None + * + * Side Effects: + * exits if the target fails. + * + *----------------------------------------------------------------------- + */ +Boolean +Job_RunTarget(const char *target, const char *fname) { + GNode *gn = Targ_FindNode(target, TARG_NOCREATE); + + if (gn == NULL) + return FALSE; + + if (fname) + Var_Set(ALLSRC, fname, gn, 0); + + JobRun(gn); + if (gn->made == ERROR) { + PrintOnError(gn, "\n\nStop."); + exit(1); + } + return TRUE; +} + #ifdef USE_SELECT int emul_poll(struct pollfd *fd, int nfd, int timeout) diff --git a/contrib/bmake/job.h b/contrib/bmake/job.h index 560b70b..91e2c87 100644 --- a/contrib/bmake/job.h +++ b/contrib/bmake/job.h @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.40 2010/09/13 15:36:57 sjg Exp $ */ +/* $NetBSD: job.h,v 1.42 2013/07/05 22:14:56 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -243,6 +243,7 @@ typedef struct Shell { extern const char *shellPath; extern const char *shellName; +extern char *shellErrFlag; extern int jobTokensRunning; /* tokens currently "out" */ extern int maxJobs; /* Max jobs we can run */ @@ -268,5 +269,6 @@ void Job_TokenReturn(void); Boolean Job_TokenWithdraw(void); void Job_ServerStart(int, int, int); void Job_SetPrefix(void); +Boolean Job_RunTarget(const char *, const char *); #endif /* _JOB_H_ */ diff --git a/contrib/bmake/main.c b/contrib/bmake/main.c index 0b177bb..7c1e64d 100644 --- a/contrib/bmake/main.c +++ b/contrib/bmake/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $ */ +/* $NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $"; #else #include #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $"); +__RCSID("$NetBSD: main.c,v 1.225 2013/09/14 15:09:34 matt Exp $"); #endif #endif /* not lint */ #endif @@ -117,19 +117,21 @@ __RCSID("$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $"); #include #include #include -#include #include #ifdef MAKE_NATIVE -#include +#include #endif +#include #include "wait.h" #include #include +#include #include #include #include #include +#include #include "make.h" #include "hash.h" @@ -146,6 +148,10 @@ __RCSID("$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $"); #define DEFMAXLOCAL DEFMAXJOBS #endif /* DEFMAXLOCAL */ +#ifndef __arraycount +# define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) +#endif + Lst create; /* Targets to be made */ time_t now; /* Time at start of make */ GNode *DEFAULT; /* .DEFAULT node */ @@ -165,6 +171,7 @@ Boolean noRecursiveExecute; /* -N flag */ Boolean keepgoing; /* -k flag */ Boolean queryFlag; /* -q flag */ Boolean touchFlag; /* -t flag */ +Boolean enterFlag; /* -w flag */ Boolean ignoreErrors; /* -i flag */ Boolean beSilent; /* -s flag */ Boolean oldVars; /* variable substitution style */ @@ -176,9 +183,6 @@ Boolean varNoExportEnv; /* -X flag */ Boolean doing_depend; /* Set while reading .depend */ static Boolean jobsRunning; /* TRUE if the jobs might be running */ static const char * tracefile; -#ifndef NO_CHECK_MAKE_CHDIR -static char * Check_Cwd_av(int, char **, int); -#endif static void MainParseArgs(int, char **); static int ReadMakefile(const void *, const void *); static void usage(void) MAKE_ATTR_DEAD; @@ -189,6 +193,7 @@ char curdir[MAXPATHLEN + 1]; /* Startup directory */ char *progname; /* the program name */ char *makeDependfile; pid_t myPid; +int makelevel; Boolean forceJobs = FALSE; @@ -203,6 +208,38 @@ Boolean forceJobs = FALSE; extern Lst parseIncPath; +/* + * For compatibility with the POSIX version of MAKEFLAGS that includes + * all the options with out -, convert flags to -f -l -a -g -s. + */ +static char * +explode(const char *flags) +{ + size_t len; + char *nf, *st; + const char *f; + + if (flags == NULL) + return NULL; + + for (f = flags; *f; f++) + if (!isalpha((unsigned char)*f)) + break; + + if (*f) + return bmake_strdup(flags); + + len = strlen(flags); + st = nf = bmake_malloc(len * 3 + 1); + while (*flags) { + *nf++ = '-'; + *nf++ = *flags++; + *nf++ = ' '; + } + *nf = '\0'; + return st; +} + static void parse_debug_options(const char *argvalue) { @@ -355,7 +392,7 @@ MainParseArgs(int argc, char **argv) Boolean inOption, dashDash = FALSE; char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */ -#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrst" +#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw" /* Can't actually use getopt(3) because rescanning is not portable */ getopt_def = OPTFLAGS; @@ -563,6 +600,10 @@ rearg: touchFlag = TRUE; Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL); break; + case 'w': + enterFlag = TRUE; + Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL); + break; case '-': dashDash = TRUE; break; @@ -771,7 +812,7 @@ MakeMode(const char *mode) } #if USE_META if (strstr(mode, "meta")) - meta_init(mode); + meta_mode_init(mode); #endif } if (mp) @@ -801,7 +842,7 @@ main(int argc, char **argv) Lst targs; /* target nodes to create -- passed to Make_Init */ Boolean outOfDate = FALSE; /* FALSE if all targets up to date */ struct stat sb, sa; - char *p1, *path, *pwd; + char *p1, *path; char mdpath[MAXPATHLEN]; #ifdef FORCE_MACHINE const char *machine = FORCE_MACHINE; @@ -816,9 +857,7 @@ main(int argc, char **argv) static char defsyspath[] = _PATH_DEFSYSPATH; char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */ struct timeval rightnow; /* to initialize random seed */ -#ifdef MAKE_NATIVE struct utsname utsname; -#endif /* default to writing debug to stderr */ debug_file = stderr; @@ -837,7 +876,7 @@ main(int argc, char **argv) progname++; else progname = argv[0]; -#ifdef RLIMIT_NOFILE +#if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)) /* * get rid of resource limit on file descriptors */ @@ -851,6 +890,12 @@ main(int argc, char **argv) } #endif + if (uname(&utsname) == -1) { + (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, + strerror(errno)); + exit(2); + } + /* * Get the name of this type of MACHINE from utsname * so we can share an executable for similar machines. @@ -861,11 +906,6 @@ main(int argc, char **argv) */ if (!machine) { #ifdef MAKE_NATIVE - if (uname(&utsname) == -1) { - (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, - strerror(errno)); - exit(2); - } machine = utsname.machine; #else #ifdef MAKE_MACHINE @@ -877,6 +917,20 @@ main(int argc, char **argv) } if (!machine_arch) { +#if defined(MAKE_NATIVE) && defined(CTL_HW) && defined(HW_MACHINE_ARCH) + static char machine_arch_buf[sizeof(utsname.machine)]; + const int mib[2] = { CTL_HW, HW_MACHINE_ARCH }; + size_t len = sizeof(machine_arch_buf); + + if (sysctl(mib, __arraycount(mib), machine_arch_buf, + &len, NULL, 0) < 0) { + (void)fprintf(stderr, "%s: sysctl failed (%s).\n", progname, + strerror(errno)); + exit(2); + } + + machine_arch = machine_arch_buf; +#else #ifndef MACHINE_ARCH #ifdef MAKE_MACHINE_ARCH machine_arch = MAKE_MACHINE_ARCH; @@ -886,6 +940,7 @@ main(int argc, char **argv) #else machine_arch = MACHINE_ARCH; #endif +#endif } myPid = getpid(); /* remember this for vFork() */ @@ -895,6 +950,7 @@ main(int argc, char **argv) */ Var_Init(); /* Initialize the lists of variables for * parsing arguments */ + Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL, 0); Var_Set("MACHINE", machine, VAR_GLOBAL, 0); Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0); #ifdef MAKE_VERSION @@ -968,35 +1024,43 @@ main(int argc, char **argv) Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0); Var_Set("MFLAGS", "", VAR_GLOBAL, 0); Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0); + /* some makefiles need to know this */ + Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0); /* * Set some other useful macros */ { - char tmp[64]; - const char *ep; + char tmp[64], *ep; - if (!(ep = getenv(MAKE_LEVEL))) { -#ifdef MAKE_LEVEL_SAFE - if (!(ep = getenv(MAKE_LEVEL_SAFE))) -#endif - ep = "0"; - } - Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0); + makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0; + if (makelevel < 0) + makelevel = 0; + snprintf(tmp, sizeof(tmp), "%d", makelevel); + Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0); snprintf(tmp, sizeof(tmp), "%u", myPid); Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0); snprintf(tmp, sizeof(tmp), "%u", getppid()); Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0); } - Job_SetPrefix(); + if (makelevel > 0) { + char pn[1024]; + snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel); + progname = bmake_strdup(pn); + } +#ifdef USE_META + meta_init(); +#endif /* * First snag any flags out of the MAKE environment variable. * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's * in a different format). */ #ifdef POSIX - Main_ParseArgLine(getenv("MAKEFLAGS")); + p1 = explode(getenv("MAKEFLAGS")); + Main_ParseArgLine(p1); + free(p1); #else Main_ParseArgLine(getenv("MAKE")); #endif @@ -1013,6 +1077,9 @@ main(int argc, char **argv) MainParseArgs(argc, argv); + if (enterFlag) + printf("%s: Entering directory `%s'\n", progname, curdir); + /* * Verify that cwd is sane. */ @@ -1034,15 +1101,19 @@ main(int argc, char **argv) * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform. */ #ifndef NO_PWD_OVERRIDE - if (!ignorePWD && - (pwd = getenv("PWD")) != NULL && - getenv("MAKEOBJDIRPREFIX") == NULL) { - const char *makeobjdir = getenv("MAKEOBJDIR"); - - if (makeobjdir == NULL || !strchr(makeobjdir, '$')) { - if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && - sa.st_dev == sb.st_dev) - (void)strncpy(curdir, pwd, MAXPATHLEN); + if (!ignorePWD) { + char *pwd; + + if ((pwd = getenv("PWD")) != NULL && + getenv("MAKEOBJDIRPREFIX") == NULL) { + const char *makeobjdir = getenv("MAKEOBJDIR"); + + if (makeobjdir == NULL || !strchr(makeobjdir, '$')) { + if (stat(pwd, &sb) == 0 && + sa.st_ino == sb.st_ino && + sa.st_dev == sb.st_dev) + (void)strncpy(curdir, pwd, MAXPATHLEN); + } } } #endif @@ -1204,10 +1275,6 @@ main(int argc, char **argv) Main_ExportMAKEFLAGS(TRUE); /* initial export */ -#ifndef NO_CHECK_MAKE_CHDIR - Check_Cwd_av(0, NULL, 0); /* initialize it */ -#endif - /* * For compatibility, look at the directories in the VPATH variable * and add them to the search path, if the variable is defined. The @@ -1334,6 +1401,9 @@ main(int argc, char **argv) Trace_Log(MAKEEND, 0); + if (enterFlag) + printf("%s: Leaving directory `%s'\n", progname, curdir); + Suff_End(); Targ_End(); Arch_End(); @@ -1366,7 +1436,7 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) if (!strcmp(fname, "-")) { Parse_File(NULL /*stdin*/, -1); - Var_Set("MAKEFILE", "", VAR_GLOBAL, 0); + Var_Set("MAKEFILE", "", VAR_INTERNAL, 0); } else { /* if we've chdir'd, rebuild the path name */ if (strcmp(curdir, objdir) && *fname != '/') { @@ -1415,7 +1485,7 @@ ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) */ found: if (!doing_depend) - Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0); + Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0); Parse_File(fname, fd); } free(path); @@ -1423,208 +1493,6 @@ found: } -/* - * If MAKEOBJDIRPREFIX is in use, make ends up not in .CURDIR - * in situations that would not arrise with ./obj (links or not). - * This tends to break things like: - * - * build: - * ${MAKE} includes - * - * This function spots when ${.MAKE:T} or ${.MAKE} is a command (as - * opposed to an argument) in a command line and if so returns - * ${.CURDIR} so caller can chdir() so that the assumptions made by - * the Makefile hold true. - * - * If ${.MAKE} does not contain any '/', then ${.MAKE:T} is skipped. - * - * The chdir() only happens in the child process, and does nothing if - * MAKEOBJDIRPREFIX and MAKEOBJDIR are not in the environment so it - * should not break anything. Also if NOCHECKMAKECHDIR is set we - * do nothing - to ensure historic semantics can be retained. - */ -#ifdef NO_CHECK_MAKE_CHDIR -char * -Check_Cwd_Cmd(cmd) - char *cmd; -{ - return 0; -} - -void -Check_Cwd(argv) - char **argv; -{ - return; -} - -#else - -static int Check_Cwd_Off = 0; - -static char * -Check_Cwd_av(int ac, char **av, int copy) -{ - static char *make[4]; - static char *cur_dir = NULL; - char **mp; - char *cp; - int is_cmd, next_cmd; - int i; - int n; - - if (Check_Cwd_Off) { - if (DEBUG(CWD)) - fprintf(debug_file, "check_cwd: check is off.\n"); - return NULL; - } - - if (make[0] == NULL) { - if (Var_Exists("NOCHECKMAKECHDIR", VAR_GLOBAL)) { - Check_Cwd_Off = 1; - if (DEBUG(CWD)) - fprintf(debug_file, "check_cwd: turning check off.\n"); - return NULL; - } - - make[1] = Var_Value(".MAKE", VAR_GLOBAL, &cp); - if ((make[0] = strrchr(make[1], '/')) == NULL) { - make[0] = make[1]; - make[1] = NULL; - } else - ++make[0]; - make[2] = NULL; - cur_dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp); - } - if (ac == 0 || av == NULL) { - if (DEBUG(CWD)) - fprintf(debug_file, "check_cwd: empty command.\n"); - return NULL; /* initialization only */ - } - - if (getenv("MAKEOBJDIR") == NULL && - getenv("MAKEOBJDIRPREFIX") == NULL) { - if (DEBUG(CWD)) - fprintf(debug_file, "check_cwd: no obj dirs.\n"); - return NULL; - } - - - next_cmd = 1; - for (i = 0; i < ac; ++i) { - is_cmd = next_cmd; - - n = strlen(av[i]); - cp = &(av[i])[n - 1]; - if (strspn(av[i], "|&;") == (size_t)n) { - next_cmd = 1; - continue; - } else if (*cp == ';' || *cp == '&' || *cp == '|' || *cp == ')') { - next_cmd = 1; - if (copy) { - do { - *cp-- = '\0'; - } while (*cp == ';' || *cp == '&' || *cp == '|' || - *cp == ')' || *cp == '}') ; - } else { - /* - * XXX this should not happen. - */ - fprintf(stderr, "%s: WARNING: raw arg ends in shell meta '%s'\n", - progname, av[i]); - } - } else - next_cmd = 0; - - cp = av[i]; - if (*cp == ';' || *cp == '&' || *cp == '|') - is_cmd = 1; - - if (DEBUG(CWD)) - fprintf(debug_file, "av[%d] == %s '%s'", - i, (is_cmd) ? "cmd" : "arg", av[i]); - if (is_cmd != 0) { - if (*cp == '(' || *cp == '{' || - *cp == ';' || *cp == '&' || *cp == '|') { - do { - ++cp; - } while (*cp == '(' || *cp == '{' || - *cp == ';' || *cp == '&' || *cp == '|'); - if (*cp == '\0') { - next_cmd = 1; - continue; - } - } - if (strcmp(cp, "cd") == 0 || strcmp(cp, "chdir") == 0) { - if (DEBUG(CWD)) - fprintf(debug_file, " == cd, done.\n"); - return NULL; - } - for (mp = make; *mp != NULL; ++mp) { - n = strlen(*mp); - if (strcmp(cp, *mp) == 0) { - if (DEBUG(CWD)) - fprintf(debug_file, " %s == '%s', chdir(%s)\n", - cp, *mp, cur_dir); - return cur_dir; - } - } - } - if (DEBUG(CWD)) - fprintf(debug_file, "\n"); - } - return NULL; -} - -char * -Check_Cwd_Cmd(const char *cmd) -{ - char *cp, *bp; - char **av; - int ac; - - if (Check_Cwd_Off) - return NULL; - - if (cmd) { - av = brk_string(cmd, &ac, TRUE, &bp); - if (DEBUG(CWD)) - fprintf(debug_file, "splitting: '%s' -> %d words\n", - cmd, ac); - } else { - ac = 0; - av = NULL; - bp = NULL; - } - cp = Check_Cwd_av(ac, av, 1); - if (bp) - free(bp); - if (av) - free(av); - return cp; -} - -void -Check_Cwd(const char **argv) -{ - char *cp; - int ac; - - if (Check_Cwd_Off) - return; - - for (ac = 0; argv[ac] != NULL; ++ac) - /* NOTHING */; - if (ac == 3 && *argv[1] == '-') { - cp = Check_Cwd_Cmd(argv[2]); - } else { - cp = Check_Cwd_av(ac, UNCONST(argv), 0); - } - if (cp) { - chdir(cp); - } -} -#endif /* NO_CHECK_MAKE_CHDIR */ /*- * Cmd_Exec -- @@ -1906,7 +1774,7 @@ Finish(int errors) } /* - * enunlink -- + * eunlink -- * Remove a file carefully, avoiding directories. */ int @@ -1952,7 +1820,8 @@ execError(const char *af, const char *av) IOADD(")\n"); #ifdef USE_IOVEC - (void)writev(2, iov, 8); + while (writev(2, iov, 8) == -1 && errno == EAGAIN) + continue; #endif } @@ -1963,8 +1832,12 @@ execError(const char *af, const char *av) static void usage(void) { + char *p; + if ((p = strchr(progname, '[')) != NULL) + *p = '\0'; + (void)fprintf(stderr, -"usage: %s [-BeikNnqrstWX] \n\ +"usage: %s [-BeikNnqrstWwX] \n\ [-C directory] [-D variable] [-d flags] [-f makefile]\n\ [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\ [-V variable] [variable=value] [target ...]\n", progname); diff --git a/contrib/bmake/make-bootstrap.sh.in b/contrib/bmake/make-bootstrap.sh.in index d9ff9ff..70d7e2b 100755 --- a/contrib/bmake/make-bootstrap.sh.in +++ b/contrib/bmake/make-bootstrap.sh.in @@ -13,7 +13,7 @@ esac CC="@CC@" CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS}" -MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' Makefile` +MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' $srcdir/Makefile` MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \ -D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \ diff --git a/contrib/bmake/make.1 b/contrib/bmake/make.1 index 25fe488..142e989 100644 --- a/contrib/bmake/make.1 +++ b/contrib/bmake/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.209 2012/10/08 15:09:48 christos Exp $ +.\" $NetBSD: make.1,v 1.222 2013/08/11 09:53:49 apb Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd October 8, 2012 +.Dd August 11, 2013 .Dt MAKE 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd maintain program dependencies .Sh SYNOPSIS .Nm -.Op Fl BeikNnqrstWX +.Op Fl BeikNnqrstWwX .Op Fl C Ar directory .Op Fl D Ar variable .Op Fl d Ar flags @@ -209,6 +209,8 @@ Force the option to print raw values of variables. .It Ar v Print debugging information about variable assignment. +.It Ar w +Print entering and leaving directory messages, pre and post processing. .It Ar x Run shell commands with .Fl x @@ -468,6 +470,50 @@ except that the effect can be limited to a single line of a script. A .Ql Ic \- causes any non-zero exit status of the command line to be ignored. +.Pp +When +.Nm +is run in jobs mode with +.Fl j Ar max_jobs , +the entire script for the target is fed to a +single instance of the shell. +.Pp +In compatibility (non-jobs) mode, each command is run in a separate process. +If the command contains any shell meta characters +.Pq Ql #=|^(){};&<>*?[]:$`\e\en +it will be passed to the shell, otherwise +.Nm +will attempt direct execution. +.Pp +Since +.Nm +will +.Xr chdir 2 +to +.Ql Va .OBJDIR +before executing any targets, each child process +starts with that as its current working directory. +.Pp +Makefiles should be written so that the mode of +.Nm +operation does not change their behavior. +For example, any command which needs to use +.Dq cd +or +.Dq chdir , +without side-effect should be put in parenthesis: +.Bd -literal -offset indent + +avoid-chdir-side-effects: + @echo Building $@ in `pwd` + @(cd ${.CURDIR} && ${.MAKE} $@) + @echo Back in `pwd` + +ensure-one-shell-regardless-of-mode: + @echo Building $@ in `pwd`; \\ + (cd ${.CURDIR} && ${.MAKE} $@); \\ + echo Back in `pwd` +.Ed .Sh VARIABLE ASSIGNMENTS Variables in make are much like variables in the shell, and, by tradition, consist of all upper-case letters. @@ -699,6 +745,9 @@ then output for each target is prefixed with a token .Ql --- target --- the first part of which can be controlled via .Va .MAKE.JOB.PREFIX . +If +.Va .MAKE.JOB.PREFIX +is empty, no token is printed. .br For example: .Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] @@ -812,6 +861,11 @@ In "meta" mode, this variable contains a list of all the meta files used (updated or not). This list can be used to process the meta files to extract dependency information. +.It Va .MAKE.META.IGNORE_PATHS +Provides a list of path prefixes that should be ignored; +because the contents are expected to change over time. +The default list includes: +.Ql Pa /dev /etc /proc /tmp /var/run /var/tmp .It Va .MAKE.META.PREFIX Defines the message printed for each meta file updated in "meta verbose" mode. The default value is: @@ -830,6 +884,13 @@ by appending their names to is re-exported whenever .Ql Va .MAKEOVERRIDES is modified. +.It Va .MAKE.PATH_FILEMON +If +.Nm +was built with +.Xr filemon 4 +support, this is set to the path of the device node. +This allows makefiles to test for this support. .It Va .MAKE.PID The process-id of .Nm . @@ -1247,7 +1308,7 @@ should start and end with a period. For example. .Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} .Pp -However a single character varaiable is often more readable: +However a single character variable is often more readable: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Cm \&:U Ns Ar newval If the variable is undefined @@ -1270,7 +1331,7 @@ The path of the node which has the same name as the variable is the value. If no such node exists or its path is null, then the name of the variable is used. -In order for this modifier to work, the name (node) must at least have +In order for this modifier to work, the name (node) must at least have appeared on the rhs of a dependency. .Sm off .It Cm \&:\&! Ar cmd Cm \&! @@ -1713,6 +1774,20 @@ targets. Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the target will still be out of date. +The same effect applies to any command line that uses the variable +.Va .OODATE , +which can be used for that purpose even when not otherwise needed or desired: +.Bd -literal -offset indent + +skip-compare-for-some: + @echo this will be compared + @echo this will not ${.OODATE:M.NOMETA_CMP} + @echo this will also be compared + +.Ed +The +.Cm \&:M +pattern suppresses any expansion of the unwanted variable. .It Ic .NOPATH Do not search for the target in the directories specified by .Ic .PATH . @@ -1896,6 +1971,12 @@ If the source is the special .Ic .DOTLAST target, then the current working directory is searched last. +.It Ic .PATH. Ns Va suffix +Like +.Ic .PATH +but applies only to files with a particular suffix. +The suffix must have been previously declared with +.Ic .SUFFIXES . .It Ic .PHONY Apply the .Ic .PHONY @@ -1964,6 +2045,10 @@ If no sources are specified, the .Ic .SILENT attribute is applied to every command in the file. +.It Ic .STALE +This target gets run when a dependency file contains stale entries, having +.Va .ALLSRC +set to the name of that dependency file. .It Ic .SUFFIXES Each source specifies a suffix to .Nm . @@ -2018,64 +2103,44 @@ The basic make syntax is compatible between different versions of make, however the special variables, variable modifiers and conditionals are not. .Pp The way that parallel makes are scheduled changed in -NetBSD 4.0 +.Nx 4.0 so that .ORDER and .WAIT apply recursively to the dependent nodes. The algorithms used may change again in the future. .Pp The way that .for loop variables are substituted changed after -NetBSD 5.0 +.Nx 5.0 so that they still appear to be variable expansions. In particular this stops them being treated as syntax, and removes some obscure problems using them in .if statements. -.Pp -Unlike other -.Nm -programs, this implementation by default executes all commands for a given -target using a single shell invocation. -This is done for both efficiency and to simplify error handling in remote -command invocations. -Typically this is transparent to the user, unless the target commands change -the current working directory using -.Dq cd -or -.Dq chdir . -To be compatible with Makefiles that do this, one can use -.Fl B -to disable this behavior. -.Pp -In compatibility mode, each command is run in a separate process. -If the command contains any shell meta characters -.Pq Ql #=|^(){};&<>*?[]:$`\e\en -it will be passed to the shell, otherwise -.Nm -will attempt direct execution. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY -make -is derived from NetBSD -.Xr make 1 . -It uses autoconf to facilitate portability to other platforms. -.Pp A -make +.Nm command appeared in .At v7 . This -make +.Nm implementation is based on Adam De Boor's pmake program which was written for Sprite at Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called .Dq customs . +.Pp +Historically the target/dependency +.Dq FRC +has been used to FoRCe rebuilding (since the target/dependency +does not exist... unless someone creates an +.Dq FRC +file). .Sh BUGS The -make +.Nm syntax is difficult to parse without actually acting of the data. For instance finding the end of a variable use should involve scanning each the modifiers using the correct terminator for each field. In many places -make +.Nm just counts {} and () in order to find the end of a variable expansion. .Pp There is no way of escaping a space character in a filename. diff --git a/contrib/bmake/make.c b/contrib/bmake/make.c index 4fa4ff9..7905f8c 100644 --- a/contrib/bmake/make.c +++ b/contrib/bmake/make.c @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.87 2012/06/12 19:21:51 joerg Exp $ */ +/* $NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: make.c,v 1.87 2012/06/12 19:21:51 joerg Exp $"; +static char rcsid[] = "$NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: make.c,v 1.87 2012/06/12 19:21:51 joerg Exp $"); +__RCSID("$NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -1032,7 +1032,7 @@ MakeBuildChild(void *v_cn, void *toBeMade_next) if (cn->order_pred && Lst_ForEach(cn->order_pred, MakeCheckOrder, 0)) { /* Can't build this (or anything else in this child list) yet */ cn->made = DEFERRED; - return 1; + return 0; /* but keep looking */ } if (DEBUG(MAKE)) @@ -1055,7 +1055,7 @@ MakeBuildChild(void *v_cn, void *toBeMade_next) return cn->type & OP_WAIT && cn->unmade > 0; } -/* When a .ORDER RHS node completes we do this on each LHS */ +/* When a .ORDER LHS node completes we do this on each RHS */ static int MakeBuildParent(void *v_pn, void *toBeMade_next) { diff --git a/contrib/bmake/make.h b/contrib/bmake/make.h index 384d109..b13716f 100644 --- a/contrib/bmake/make.h +++ b/contrib/bmake/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.89 2012/06/12 19:21:51 joerg Exp $ */ +/* $NetBSD: make.h,v 1.92 2013/09/04 15:38:26 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -103,7 +103,7 @@ ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ (__GNUC__ > (x))) #else /* defined(__GNUC__) */ -#define MAKE_GNUC_PREREQx, y) 0 +#define MAKE_GNUC_PREREQ(x, y) 0 #endif /* defined(__GNUC__) */ #if MAKE_GNUC_PREREQ(2, 7) @@ -404,6 +404,10 @@ extern Boolean varNoExportEnv; /* TRUE if we should not export variables extern GNode *DEFAULT; /* .DEFAULT rule */ +extern GNode *VAR_INTERNAL; /* Variables defined internally by make + * which should not override those set by + * makefiles. + */ extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g * in the Makefile itself */ extern GNode *VAR_CMD; /* Variables defined on the command line */ @@ -442,9 +446,8 @@ extern pid_t myPid; #define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE" #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */ #define MAKE_MODE ".MAKE.MODE" - -#ifdef NEED_MAKE_LEVEL_SAFE -# define MAKE_LEVEL_SAFE "_MAKE_LEVEL" /* some shells will not pass .MAKE. */ +#ifndef MAKE_LEVEL_ENV +# define MAKE_LEVEL_ENV "MAKELEVEL" #endif /* diff --git a/contrib/bmake/makefile.in b/contrib/bmake/makefile.in new file mode 100644 index 0000000..03b980a --- /dev/null +++ b/contrib/bmake/makefile.in @@ -0,0 +1,14 @@ +# $Id: makefile.in,v 1.1 2012/12/28 21:28:19 sjg Exp $ + +# a simple makefile for those who don't like anything beyond: +# ./configure; make; make install + +prefix= @prefix@ +srcdir= @srcdir@ + +all: build + +build clean install test: + ${srcdir}/boot-strap --prefix=${prefix} -o . op=$@ + + diff --git a/contrib/bmake/meta.c b/contrib/bmake/meta.c index 77af4e8..3ec0bdc 100644 --- a/contrib/bmake/meta.c +++ b/contrib/bmake/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.25 2012/06/27 17:22:58 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.33 2013/10/01 05:37:17 sjg Exp $ */ /* * Implement 'meta' mode. @@ -55,7 +55,12 @@ #endif static BuildMon Mybm; /* for compat */ -static Lst metaBailiwick; /* our scope of control */ +static Lst metaBailiwick; /* our scope of control */ +static Lst metaIgnorePaths; /* paths we deliberately ignore */ + +#ifndef MAKE_META_IGNORE_PATHS +#define MAKE_META_IGNORE_PATHS ".MAKE.META.IGNORE_PATHS" +#endif Boolean useMeta = FALSE; static Boolean useFilemon = FALSE; @@ -539,8 +544,24 @@ boolValue(char *s) return TRUE; } +/* + * Initialization we need before reading makefiles. + */ +void +meta_init(void) +{ +#ifdef USE_FILEMON + /* this allows makefiles to test if we have filemon support */ + Var_Set(".MAKE.PATH_FILEMON", _PATH_FILEMON, VAR_GLOBAL, 0); +#endif +} + + +/* + * Initialization we need after reading makefiles. + */ void -meta_init(const char *make_mode) +meta_mode_init(const char *make_mode) { static int once = 0; char *cp; @@ -591,6 +612,17 @@ meta_init(const char *make_mode) if (cp) { str2Lst_Append(metaBailiwick, cp, NULL); } + /* + * We ignore any paths that start with ${.MAKE.META.IGNORE_PATHS} + */ + metaIgnorePaths = Lst_Init(FALSE); + Var_Append(MAKE_META_IGNORE_PATHS, + "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}", VAR_GLOBAL); + cp = Var_Subst(NULL, + "${" MAKE_META_IGNORE_PATHS ":O:u:tA}", VAR_GLOBAL, 0); + if (cp) { + str2Lst_Append(metaIgnorePaths, cp, NULL); + } } /* @@ -828,6 +860,13 @@ string_match(const void *p, const void *q) continue; \ } +#define DEQUOTE(p) if (*p == '\'') { \ + char *ep; \ + p++; \ + if ((ep = strchr(p, '\''))) \ + *ep = '\0'; \ + } + Boolean meta_oodate(GNode *gn, Boolean oodate) { @@ -840,10 +879,12 @@ meta_oodate(GNode *gn, Boolean oodate) char fname2[MAXPATHLEN]; char *p; char *cp; + char *link_src; + char *move_target; static size_t cwdlen = 0; static size_t tmplen = 0; FILE *fp; - Boolean ignoreOODATE = FALSE; + Boolean needOODATE = FALSE; Lst missingFiles; if (oodate) @@ -906,6 +947,8 @@ meta_oodate(GNode *gn, Boolean oodate) oodate = TRUE; break; } + link_src = NULL; + move_target = NULL; /* Find the start of the build monitor section. */ if (!f) { if (strncmp(buf, "-- filemon", 10) == 0) { @@ -1019,16 +1062,21 @@ meta_oodate(GNode *gn, Boolean oodate) break; case 'M': /* renaMe */ - if (Lst_IsEmpty(missingFiles)) - break; + /* + * For 'M'oves we want to check + * the src as for 'R'ead + * and the target as for 'W'rite. + */ + cp = p; /* save this for a second */ + /* now get target */ + if (strsep(&p, " ") == NULL) + continue; + CHECK_VALID_META(p); + move_target = p; + p = cp; /* 'L' and 'M' put single quotes around the args */ - if (*p == '\'') { - char *ep; - - p++; - if ((ep = strchr(p, '\''))) - *ep = '\0'; - } + DEQUOTE(p); + DEQUOTE(move_target); /* FALLTHROUGH */ case 'D': /* unlink */ if (*p == '/' && !Lst_IsEmpty(missingFiles)) { @@ -1037,24 +1085,42 @@ meta_oodate(GNode *gn, Boolean oodate) char *tp = Lst_Datum(ln); Lst_Remove(missingFiles, ln); free(tp); + ln = NULL; /* we're done with it */ } } + if (buf[0] == 'M') { + /* the target of the mv is a file 'W'ritten */ +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_oodate: M %s -> %s\n", + p, move_target); +#endif + p = move_target; + goto check_write; + } break; case 'L': /* Link */ - /* we want the target */ + /* + * For 'L'inks check + * the src as for 'R'ead + * and the target as for 'W'rite. + */ + link_src = p; + /* now get target */ if (strsep(&p, " ") == NULL) continue; CHECK_VALID_META(p); /* 'L' and 'M' put single quotes around the args */ - if (*p == '\'') { - char *ep; - - p++; - if ((ep = strchr(p, '\''))) - *ep = '\0'; - } + DEQUOTE(p); + DEQUOTE(link_src); +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_oodate: L %s -> %s\n", + link_src, p); +#endif /* FALLTHROUGH */ case 'W': /* Write */ + check_write: /* * If a file we generated within our bailiwick * but outside of .OBJDIR is missing, @@ -1086,6 +1152,14 @@ meta_oodate(GNode *gn, Boolean oodate) Lst_AtEnd(missingFiles, bmake_strdup(p)); } break; + check_link_src: + p = link_src; + link_src = NULL; +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_oodate: L src %s\n", p); +#endif + /* FALLTHROUGH */ case 'R': /* Read */ case 'E': /* Exec */ /* @@ -1093,20 +1167,15 @@ meta_oodate(GNode *gn, Boolean oodate) * be part of the dependencies because * they are _expected_ to change. */ - if (strncmp(p, "/tmp/", 5) == 0 || - (tmplen > 0 && strncmp(p, tmpdir, tmplen) == 0)) - break; - - if (strncmp(p, "/var/", 5) == 0) - break; - - /* Ignore device files. */ - if (strncmp(p, "/dev/", 5) == 0) - break; - - /* Ignore /etc/ files. */ - if (strncmp(p, "/etc/", 5) == 0) + if (*p == '/' && + Lst_ForEach(metaIgnorePaths, prefix_match, p)) { +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_oodate: ignoring: %s\n", + p); +#endif break; + } if ((cp = strrchr(p, '/'))) { cp++; @@ -1185,6 +1254,8 @@ meta_oodate(GNode *gn, Boolean oodate) default: break; } + if (!oodate && buf[0] == 'L' && link_src != NULL) + goto check_link_src; } else if (strcmp(buf, "CMD") == 0) { /* * Compare the current command with the one in the @@ -1196,17 +1267,19 @@ meta_oodate(GNode *gn, Boolean oodate) oodate = TRUE; } else { char *cmd = (char *)Lst_Datum(ln); - - if (!ignoreOODATE) { - if (strstr(cmd, "$?")) - ignoreOODATE = TRUE; - else if ((cp = strstr(cmd, ".OODATE"))) { - /* check for $[{(].OODATE[)}] */ - if (cp > cmd + 2 && cp[-2] == '$') - ignoreOODATE = TRUE; - } - if (ignoreOODATE && DEBUG(META)) - fprintf(debug_file, "%s: %d: cannot compare commands using .OODATE\n", fname, lineno); + Boolean hasOODATE = FALSE; + + if (strstr(cmd, "$?")) + hasOODATE = TRUE; + else if ((cp = strstr(cmd, ".OODATE"))) { + /* check for $[{(].OODATE[:)}] */ + if (cp > cmd + 2 && cp[-2] == '$') + hasOODATE = TRUE; + } + if (hasOODATE) { + needOODATE = TRUE; + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: cannot compare command using .OODATE\n", fname, lineno); } cmd = Var_Subst(NULL, cmd, gn, TRUE); @@ -1235,7 +1308,7 @@ meta_oodate(GNode *gn, Boolean oodate) if (buf[x - 1] == '\n') buf[x - 1] = '\0'; } - if (!ignoreOODATE && + if (!hasOODATE && !(gn->type & OP_NOMETA_CMP) && strcmp(p, cmd) != 0) { if (DEBUG(META)) @@ -1279,14 +1352,16 @@ meta_oodate(GNode *gn, Boolean oodate) oodate = TRUE; } } - if (oodate && ignoreOODATE) { + if (oodate && needOODATE) { /* - * Target uses .OODATE, so we need to re-compute it. - * We need to clean up what Make_DoAllVar() did. + * Target uses .OODATE which is empty; or we wouldn't be here. + * We have decided it is oodate, so .OODATE needs to be set. + * All we can sanely do is set it to .ALLSRC. */ - Var_Delete(ALLSRC, gn); Var_Delete(OODATE, gn); - gn->flags &= ~DONE_ALLSRC; + Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0); + if (cp) + free(cp); } return oodate; } diff --git a/contrib/bmake/meta.h b/contrib/bmake/meta.h index 1ce01ca..57c73ca 100644 --- a/contrib/bmake/meta.h +++ b/contrib/bmake/meta.h @@ -1,4 +1,4 @@ -/* $NetBSD: meta.h,v 1.2 2011/03/30 22:03:49 sjg Exp $ */ +/* $NetBSD: meta.h,v 1.3 2013/03/23 05:31:29 sjg Exp $ */ /* * Things needed for 'meta' mode. @@ -41,7 +41,8 @@ typedef struct BuildMon { extern Boolean useMeta; struct Job; /* not defined yet */ -void meta_init(const char *); +void meta_init(void); +void meta_mode_init(const char *); void meta_job_start(struct Job *, GNode *); void meta_job_child(struct Job *); void meta_job_error(struct Job *, GNode *, int, int); diff --git a/contrib/bmake/mk/ChangeLog b/contrib/bmake/mk/ChangeLog new file mode 100644 index 0000000..b547197 --- /dev/null +++ b/contrib/bmake/mk/ChangeLog @@ -0,0 +1,758 @@ +2013-09-04 Simon J. Gerraty + + * gendirdeps.mk (_objtops): fix typo also + while processing M2D_OBJROOTS to gather qualdir_list + qualify $ql with loop iterator to ensure correct results. + +2013-08-01 Simon J. Gerraty + + * install-mk (MK_VERSION): 20130801 + * libs.mk: update to match progs.mk + +2013-07-26 Simon J. Gerraty + + * install-mk (MK_VERSION): 20130726 + some updates from Juniper and FreeBSD + o meta2deps.py: indicate file and line number when we hit parse + errors + also allow @file to provide huge list of .meta files. + * meta2deps.py: add try_parse() to cleanup the above. + +2013-07-16 Simon J. Gerraty + + * install-mk (MK_VERSION): 20130716 + * own.mk: add GPROG as an option + * prog.mk: honor MK_GPROF==yes + +2013-05-10 Simon J. Gerraty + + * install-mk (MK_VERSION): 20130505 + * gendirdeps.mk, meta2deps.py, meta2deps.sh: handle $TARGET_SPEC + for when $MACHINE isn't enough for objdir distinction. + Bring meta2deps.sh closer to par with meta2deps.py. + +2013-04-18 Simon J. Gerraty + + * meta.stage.mk: set INSTALL to STAGE_INSTALL when making 'all' + also if the target 'beforeinstall' exists, make it depend on + .dirdep (incase it uses STAGE_INSTALL). + +2013-04-17 Simon J. Gerraty + + * install-mk (MK_VERSION): 20130401 ;-) + * meta.stage.mk (STAGE_INSTALL_SH): add stage-install.sh as + wrapper around install(1). + * options.mk (OPTION_PREFIX): Allow a prefix other than MK_ + +2013-03-30 Simon J. Gerraty + + * meta2deps.py (MetaFile.__init__): ensure self.cwd is initialized. + * install-mk (MK_VERSION): bump version + +2013-03-21 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * gendirdeps.mk: do not apply :tA to DPADD entries, since we lose + any trailing /., rather apply :tA only when needed. + * gendirdeps.mk: better mimic meta2deps handling of .dirdep files. + * meta.stage.mk (LN_CP_SCRIPT): Add LnCp to do the ln||cp dance + consistently. + * dirdeps.mk: better describe the dance in sys.mk for TARGET_SPEC. + +2013-03-18 Simon J. Gerraty + + * gendirdeps.mk: revert the dance around .MAKE.DEPENDFILE_DEFAULT + it is simpler to just not update when say building for "host" + (where we know we apply filters to DIRDEPS), and using a + non-machine qualified dependfile. + +2013-03-16 Simon J. Gerraty + + * dirdeps.mk: improve DIRDEPS filtering by allowing DEP_SKIP_DIR + and DEP_DIRDEPS_FILTER to vary by DEP_MACHINE and DEP_TARGET_SPEC + * gendirdeps.mk: ensure _objroot has trailing / if it needs it. + * meta2deps.py: if machine is "host", then also trim + self.host_target from any OBJROOTS. + + +2013-03-11 Simon J. Gerraty + + * gendirdeps.mk: if .MAKE.DEPENDFILE_DEFAULT is not machine + qualified but _DEPENDFILE is, and .MAKE.DEPENDFILE_DEFAULT exists + but _DEPENDFILE does not, compare the new _DEPENDFILE against + .MAKE.DEPENDFILE_DEFAULT and discard if the same. + +2013-03-08 Simon J. Gerraty + + * meta.stage.mk: use STAGE_TARGETS to control .ORDER + and hook to all: via staging: + +2013-03-07 Simon J. Gerraty + + * sys.dependfile.mk (.MAKE.DEPENDFILE_DEFAULT): + use a separate variable for the default .MAKE.DEPENDFILE value + so that it can be controlled independently of + .MAKE.DEPENDFILE_PREFERENCE + + * meta.stage.mk: throw error if cp fails etc. + Stage*() return early if passed no args. + .ORDER stage_* + +2013-03-03 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * gendirdeps.mk: handle multiple M2D_OBJROOTS better. + +2013-02-10 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20130210 + * import latest dirdeps.mk, gendirdeps.mk and meta2deps.py + from Juniper. + o dirdeps.mk now fully supports TARGET_SPEC consisting of more + than just MACHINE. + o no longer use DEP_MACHINE from Makefile.depend* so remove it. + +2013-01-23 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20130123 + * meta.stage.mk: add stage_links (hard links). + if doing hard links, we add dest to link as well. + Default the stage dir for [sym]links to STAGE_OBJTOP since + these are typically specified as absolute paths. + Add -m "mode" flag to StageFiles and StageAs. + +2012-11-11 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20121111 + * autoconf.mk: avoid meta mode seeing changed commands for config.status + * meta.autodep.mk: pass resolved MAKESYSPATH to gendirdeps + in case we were found via .../mk + * sys.clean-env.mk: move it from examples, we and others use it + "as is". + * FILES: add srctop.mk and options.mk + * own.mk: convert to using options.mk + which is modeled after FreeBSD's handling of MK_* + but more flexible. + This allows MK_* for boolean knobs to not be confused + with MK* which can be commands. + + * examples/sys.clean-env.mk: add WITH[OUT]_ to + MAKE_ENV_SAVE_PREFIX_LIST. + Mention that HOME=/var/empty might be a good idea. + +2012-11-08 Simon J. Gerraty + + * sys.dependfile.mk: if not depend file exists, $MACHINE + specific ones are supported but not the default, + check if any exist and follow suit. + +2012-11-06 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20121106 + +2012-11-05 Simon J. Gerraty + + * import latest dirdeps.mk and meta2deps.py from Juniper. + * progs.mk: add MAN and CXXFLAGS to PROG_VARS + also add PROGS_TARGETS and pass on PROG_CXX if it seems + appropriate. + +2012-11-04 Simon J. Gerraty + + * meta.stage.mk: update CLEANFILES + remove redundant cp of .dirdep from STAGE_AS_SCRIPT. + * progs.mk: Add LDADD to PROG_VARS + +2012-10-12 Simon J. Gerraty + + * meta.stage.mk (STAGE_DIR_FILTER): track dirs we stage to in + _STAGED_DIRS so that these can be turned into filters for + GENDIRDEPS_FILTER. + +2012-10-10 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20121010 + * meta.stage.mk (STAGE_DIRDEP_SCRIPT): check that an existing + target.dirdep matches .dirdep + +2012-08-08 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120808 + * import latest meta2deps.py from Juniper. + +2012-07-11 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120711 + * dep.mk: add explicit dependencies on SRCS after applying + SRCS_DEP_FILTER + * meta.autodep.mk: add explicit dependencies on SRCS after + applying SRCS_DEP_FILTER + * meta.autodep.mk: ensure GENDIRDEPS_FILTER is exported if needed. + +2012-06-26 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120626 + * meta.sys.mk: ignore PYTHON if it does not exist + compare ${.MAKE.DEPENDFILE:E} against ${MACHINE} is more reliable. + * meta.stage.mk: examine .MAKE.DEPENDFILE_PREFERENCE for any + entries ending in .${MACHINE} to decide if qualified _dirdep is + needed. + * gendirdeps.mk: only produce unqualified deps if no + .MAKE.DEPENDFILE_PREFERENCE ends in .${MACHINE} + * meta.subdir.mk: apply SUBDIREPS_FILTER + +2012-04-20 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120420 + * add sys.dependfile.mk so we can experiment with + .MAKE.DEPENDFILE_PREFERENCE + * meta.autodep.mk: _DEPENDFILE is precious! + +2012-03-15 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120315 + * install-new.mk: avoid being interrupted + +2012-02-26 Simon J. Gerraty + + * man.mk: MAN might have multiple values so be careful with exists(). + +2012-01-19 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20120112 + * fix examples/sys.clean-env.mk so that MAKEOBJDIR is handled + as: MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}' + +2011-12-03 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111201 + * import dirdeps.mk from Juniper sjg@ + o more consistent handling of DEP_MACHINE, especially when + dealing with an odd Makefile.depend, when normally using + Makefile.depend.${MACHINE} + +2011-11-22 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111122 + * meta.autodep.mk: add some debug output, be more crisp about + updating. Use ${.ALLTARGETS:M*.o} as a clue for .depend + +2011-11-13 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111111 + it's too cool to miss + * import meta* updates from Juniper sjg@ + o dirdeps.mk set DEP_MACHINE for Makefile.depend (when we are + normally using Makefile.depend.${MACHINE}), handy for + read-only manually maintained dependencies. + o meta2deps.py add a clear 'ERROR:' token if an exception is raised. + o gendirdeps.mk if ERROR: from meta2deps.py do not update + anything. + +2011-10-30 Simon J. Gerraty + + * install-new.mk separate the cmp and copy logic to its own function. + +2011-10-28 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111028 + * sys.mk: include auto.obj.mk if MKOBJDIRS is set to auto + * subdir.mk: ensure _SUBDIRUSE is provided + * meta.autodep.mk: remove dependency of gendirdeps.mk on auto.obj.mk + * meta.subdir.mk: always allow for Makefile.depend + +2011-10-10 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111010 + o minor tweak to *dirdeps.mk from Juniper sjg@ + +2011-10-01 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20111001 + o add meta2deps.py from Juniper sjg@ + o tweak gendirdeps.mk to work with meta2deps.py when not + cross-building + * autoconf.mk: add autoconf-input as a hook for regenerating + AUTOCONF_INPUTS (configure). + +2011-08-24 Simon J. Gerraty + + * meta.autodep.mk: if we do not have OBJS, .depend isn't a useful + trigger for updating Makefile.depend* + +2011-08-08 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110808 + * obj.mk: minor cleanup + * auto.obj.mk: improve description of Mkdirs and honor NO_OBJ too. + +2011-08-01 Simon J. Gerraty + + * auto.obj.mk (.OBJDIR): throw an error if we cannot use the + specified dir. + +2011-06-28 Simon J. Gerraty + + * meta.autodep.mk: if XMAKE_META_FILE is set + the makefile uses a foreign make, and so dependencies + can only be gathered from a clean tree build. + +2011-06-24 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110622 + * meta.autodep.mk: improve bootstraping + +2011-06-10 Simon J. Gerraty + + * yacc.mk: handle the corner case of .c being removed + while .h remains. + +2011-06-08 Simon J. Gerraty + + * yacc.mk: do .y.h and .y.c separately + +2011-06-04 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110606 + * don't store SRC_DIRDEPS in Makefile.depend* by default + not everyone needs it. + +2011-05-04 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110505 + first release including meta mode makefiles + +2011-05-02 Simon J. Gerraty + + * meta.stage.mk: add STAGE_AS_SETS and stage_as + for things that need to be staged with different names. + +2011-05-01 Simon J. Gerraty + + * meta.stage.mk: add notion of STAGE_SETS + so a makefile can stage to multiple dirs + +2011-04-03 Simon J. Gerraty + + * rst2htm.mk: convert rst to s5 (slides) or plain html depending + on target name. + +2011-03-30 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110330 + +2011-03-29 Simon J. Gerraty + + * sys.mk (_DEBUG_MAKE_FLAGS): use indirection so that DEBUG_MAKE_FLAGS0 + can be used to debug level 0 only and DEBUG_MAKE_FLAGS for the rest. + * sys.mk: re-define M_whence in terms of M_type. + M_type is useful for checking if something is a builtin. + +2011-03-16 Simon J. Gerraty + + * meta.stage.mk: add stage_symlinks and leverage StageLinks for + stage_libs + +2011-03-10 Simon J. Gerraty + + * dirdeps.mk: correct value for _depdir_files depends on + .MAKE.DEPENDFILE + Add our copyright - just to make it clear we have frobbed this + quite a bit. + DEP_MACHINE needs to be set to MACHINE each time, if using only + Makefile.depend (cf. Makefile.depend.${MACHINE}) + + * meta.stage.mk: meta mode version of staging + + * init.mk, final.mk: include local.*.mk to simplify customization + +2011-03-03 Simon J. Gerraty + + * auto.obj.mk: just because we are doing mk destroy, we should + still set .OBJDIR correctly if it exists. + + * install-mk (mksrc): do not exclude meta.sys.mk + +2011-03-01 Simon J. Gerraty + + * host-target.mk: set/export _HOST_ARCH etc separately, + catch junk resulting from uname -p, so we can find sys/Linux.mk + correctly. + +2011-02-18 Simon J. Gerraty + + * meta.sys.mk: throw an error if /dev/filemon is missing and we + expected to be updating Makefile.depend* + +2011-02-14 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20110214 + * meta.subdir.mk: add support for -DBOOTSTRAP_DEPENDFILES + +2010-09-25 Simon J. Gerraty + + * meta.sys.mk: not valid for older bmake + +2010-09-24 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100919 + include dirdeps.mk et al from Juniper Networks, + for meta mode - requires filemon(9). + * sys.mk, subdir.mk: Add hooks for meta mode. + we do this as meta.sys.mk, meta.autodep.mk and meta.subdir.mk + to make turning it on/off simple. + +2010-06-16 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100616 + * fix typo in sys.mk + +2010-06-12 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100612 + * lib.mk: remove duplicate addition to SOBJS + +2010-06-10 Simon J. Gerraty + + * sys.mk: Add a means of selectively turning on debug flags. + Eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_DIRS="*lib/sjg" + will act as if we did make -dv if .CURDIR ends in lib/sjg + DEBUG_MAKE_SYS_DIRS does the same thing, but we set the flags at + the start of sys.mk rather than the end. + This only makes sense for leaf dirs, so we check that + .MAKE.LEVEL > 0 + +2010-06-09 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100608 + * sys.mk: include sys.env.mk later so it can use M_ListToSkip et al. + * examples/sys.clean-env.mk: require MAKE_VERIONS >= 20100606 + also make it easier for folk to tweak + +2010-06-08 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100606 + do not install examples/* + * FILES: add examples/sys.clean-env.mk + * examples/sys.clean-env.mk: use .export-env to handle MAKEOBJDIR + this requires bmake-20100606 or later to work. + +2010-05-13 Simon J. Gerraty + + * sys.mk (M_tA): better simulate the result of :tA if not available. + +2010-05-04 Simon J. Gerraty + + * sys.mk: canonicalize MAKE_VERSION + old versions reported bmake- build- + whereas we only care about + +2010-04-25 Simon J. Gerraty + + * install-mk: just warn about FORCE_{BSD,SYS}_MK being ignored + * lib.mk: we only build the shared lib if SHLIB_FULLVERSION + is !empty + +2010-04-22 Simon J. Gerraty + + * dpadd.mk: use LDADD_* if defined. + +2010-04-21 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100420 + * sys/NetBSD.mk: add MACHINE_CPU to keep netbsd makefiles happy + * autoconf.mk allow AUTO_AUTOCONF + +2010-04-19 Simon J. Gerraty + + * obj.mk: add objwarn to keep freebsd makefiles happy + * auto.obj.mk: ensure Mkdirs is available. + * FILES: add auto.dep.mk - a simpler version of autodep.mk + * dep.mk: auto.dep.mk does not do 'make depend' so ignore it if + asked to do that. + fix/simplify the tests for when to run mkdep. + * auto.dep.mk: add some explaination of how/what we do. + * autodep.mk: skip the .OPTIONAL frobbing of .depend + bmake's FROM_DEPEND flag makes it redundant. + +2010-04-13 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100404 + * subdir.mk: protect from multiple inclusion using _SUBDIRUSE. + * obj.mk: protect from multiple inclusion even as bsd.obj.mk + Also create a target _SUBDIRUSE so that we can be used without + subdir.mk + +2010-04-12 Simon J. Gerraty + + * dep.mk: use <> when .including so can override. + +2010-01-11 Simon J. Gerraty + + * lib.mk (SHLIB_LINKS): ensure a string comparison. + +2010-01-04 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20100102 + * own.mk: ensure PRINTOBJDIR works + * autoconf.mk: pass on CONFIGURE_ARGS + * init.mk: handle COPTS.${.IMPSRC:T} etc. + * lib.mk: allow sys.mk to control SHLIB_FULLVERSION + fix handling of symlinks for darwin + * libnames.mk: add DSHLIBEXT for libs which only exist as shared. + * man.mk: suppress chown when not root. + * rst2htm.mk: allow srcs from multiple locations. + * sys.mk: M_whence, stop after 1st line of output. + * sys/Darwin.mk: Use .dylib for DSHLIBEXT and HOST_LIBEXT + * sys/SunOS.mk: we need to export PATH + +2009-12-23 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + include rst2htm.mk + +2009-12-17 Simon J. Gerraty + + * sys.mk,libnames.mk add .-include + this allows local customization without the need to edit the + distributed files. + +2009-12-14 Simon J. Gerraty + + * dpadd.mk (__dpadd_libdirs): order -L's to avoid picking up + older versions already installed. + +2009-12-13 Simon J. Gerraty + + * stage.mk (.stage-install): generalize lib.mk's .libinstall + * rules.mk rules for generic Makefile. + * inc.mk install for includes. + +2009-12-11 Simon J. Gerraty + + * sys/NetBSD.mk (MAKE_VERSION): some of our *.mk want to check + this, so provide it if using native make. + +2009-12-10 Simon J. Gerraty + + * FILES: move all the platform *.sys.mk files to sys/*.mk + * Rename Generic.sys.mk to sys.mk - we always want it. + +2009-11-17 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * host-target.mk: only export the expensive stuff + * Generic.sys.mk (sys_mk): for SunOS we need to look for + ${HOST_OS}.${HOST_OSMAJOR} too! + +2009-11-07 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * lib.mk: if sys.mk doesn't give us an lorder, don't use it. + based on patch from Greg Olszewski. + * Generic.sys.mk: if we have nothing to work with + set LORDER etc only if we can find it. + +2009-09-08 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * man.mk: cleanman: remove CLEANMAN if defined. + +2009-09-04 Simon J. Gerraty + + * SunOS.5.sys.mk (CC): Use ?= like the other *sys.mk + +2009-07-17 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + include auto.obj.mk + + +2009-03-26 Simon J. Gerraty + + * prog.mk,lib.mk: ensure test of USE_DPADD_MK doesn't fail. + +2008-11-11 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + man.mk: ensure we generate *.cat1 etc in . + +2008-07-16 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + add prlist.mk + +2007-11-25 Simon J. Gerraty + + * Generic.sys.mk: Allow os specific sys.mk to be in a + subdir of ${.PARSEDIR} + +2007-11-22 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * general cleanup + * dpadd.mk introduce DPMAGIC_LIBS_* + +2007-04-30 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + + * libs.mk, progs.mk, autodep.mk: allow for per lib/prog + depend files and ensure clean is called for each lib/prog. + +2007-03-27 Simon J. Gerraty + + * autodep.mk (.depend): delete lines that do not start with + space and do not contain ':' + +2007-02-16 Simon J. Gerraty + + * autodep.mk (.depend): gcc may wrap lines if pathnames are long + so make sure the transform for .OPTIONAL copes. + +2007-02-03 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + + * own.mk: make sure RM and LN are defined. + + * obj.mk: fix a typo, and objlink target. + +2006-12-30 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version + * added libs.mk - analagous to progs.mk + make both of them always inlcude {lib,prog}.mk + +2006-12-28 Simon J. Gerraty + + * progs.mk: add a means of building multiple apps in one dir. + +2006-11-26 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20061126 + + * warnings.mk: detect invalid WARNINGS_SET + + * warnings.mk: use ${.TARGET:T:R}.o when looking for target + specific warnings. + + * For .cc sources, turn off warnings that g++ vomits on. + +2006-11-08 Simon J. Gerraty + + * own.mk: if __initialized__ target doesn't exist and we are + FreeBSD we got here directly from sys.mk + +2006-11-06 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20061106 + add scripts.mk + +2006-03-18 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20060318 + + * autodep.mk: avoid := when modifying OBJS into __dependsrcs + +2006-03-02 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20060302 + * autodep.mk: use -MF et al to help gcc+ccache DTRT. + +2006-03-01 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20060301 + * autodep.mk (.depend): + if MAKE_VERSION is newer than 20050530 we can make .END depend on + .depend and make .depend depend on __depsrcs that exist. + * dpadd.mk: add SRC_PATHADD + +2005-11-04 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20051104 + * prog.mk: remove all the LIBC?= junk, use + .-include libnames.mk instead (none by default). + also if USE_DPADD_MK is set, include that. + +2005-10-09 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20051001 + Add UnixWare.sys.mk from Klaus Heinz. + +2005-04-05 Simon J. Gerraty + + * install-mk: always install *.sys.mk and if need be symlink one + to sys.mk + +2005-03-22 Simon J. Gerraty + + * subdir.mk, own.mk: use .MAKE rather than MAKE + +2004-02-15 Simon J. Gerraty + + * own.mk: don't use NetBSD's _SRC_TOP_ it can + cause confusion. Also don't take just 'mk' as a + srctop indicator. + +2004-02-14 Simon J. Gerraty + + * warnings.mk: overhauled, now very powerful. + +2004-02-03 Simon J. Gerraty + + * Generic.sys.mk: need to use ${.PARSEDIR} with exists(). + +2004-02-01 Simon J. Gerraty + + * install-mk (MK_VERSION): bump version to 20040201 + * extract HOST_TARGET stuff to host-target.mk so own.mk and + Generic.sys.mk can share. + * fix typo in autodep.mk _SUBDIRUSE not _SUBDIR. + +2003-09-30 Simon J. Gerraty + + * install-mk (MK_VERSION): 20030930 + * rename generic.sys.mk to Generic.sys.mk + so that it does not get installed (unless being used as sys.mk) + * set OS and ROOT_GROUP for those that we know the value. + for others (eg. Generic.sys.mk) wrap the != in an .ifndef so + we don't do it again for each sub-make. + +2003-09-28 Simon J. Gerraty + + * install-mk (MK_VERSION): 20030928 + Add some extra *.sys.mk from bootstrap-pkgsrc + some of these likely still need work. + Make everything default to root:wheel ownership, + sys.mk can set ROOT_GROUP accordingly. + +2003-08-07 Simon J. Gerraty + + * install-mk: if FORCE_BSD_MK={cp,ln} use the ones in SYS_MK_DIR + not the portable ones. + +2003-07-31 Simon J. Gerraty + + * install-mk: add ability to use cp -f when updating + destination .mk files. Also now possible to play games with + FORCE_SYS_MK=ln etc on *BSD machines to link /usr/share/mk/sys.mk + into dest - not recommended unless you seriously want to. + +2003-07-28 Simon J. Gerraty + + * own.mk (IMPFLAGS): add support for COPTS.${IMPSRC:T} etc + for semi-compatability with NetBSD. + +2003-07-23 Simon J. Gerraty + + * install-mk: add a version indicator + +2003-07-22 Simon J. Gerraty + + * prog.mk: don't try and use ${LIBCRT0} if its /dev/null + + * install-mk: Allow FORCE_SYS_MK to come from env + + + diff --git a/contrib/bmake/mk/FILES b/contrib/bmake/mk/FILES new file mode 100644 index 0000000..443aa2e --- /dev/null +++ b/contrib/bmake/mk/FILES @@ -0,0 +1,61 @@ +ChangeLog +FILES +README +auto.obj.mk +autoconf.mk +autodep.mk +auto.dep.mk +dep.mk +doc.mk +dpadd.mk +final.mk +host-target.mk +host.libnames.mk +inc.mk +init.mk +install-mk +java.mk +lib.mk +libnames.mk +libs.mk +links.mk +man.mk +mk-files.txt +nls.mk +obj.mk +options.mk +own.mk +prlist.mk +prog.mk +progs.mk +rst2htm.mk +scripts.mk +srctop.mk +stage-install.sh +subdir.mk +sys.mk +sys.clean-env.mk +sys.dependfile.mk +sys/AIX.mk +sys/Darwin.mk +sys/Generic.mk +sys/HP-UX.mk +sys/IRIX.mk +sys/Linux.mk +sys/NetBSD.mk +sys/OSF1.mk +sys/OpenBSD.mk +sys/SunOS.mk +sys/UnixWare.mk +target-flags.mk +warnings.mk +yacc.mk +dirdeps.mk +gendirdeps.mk +install-new.mk +meta2deps.py +meta2deps.sh +meta.sys.mk +meta.autodep.mk +meta.stage.mk +meta.subdir.mk diff --git a/contrib/bmake/mk/README b/contrib/bmake/mk/README new file mode 100644 index 0000000..3d79b6a --- /dev/null +++ b/contrib/bmake/mk/README @@ -0,0 +1,401 @@ +# $Id: README,v 1.1 1997/03/11 07:27:15 sjg Exp $ + +This directory contains some macro's derrived from the NetBSD bsd.*.mk +macros. They have the same names but without the bsd., separate macro +files are needed to ensure we can make them do what we want for +builing things outside of /usr/src. Nearly all the comments below +apply. + +# $NetBSD: bsd.README,v 1.18 1997/01/13 00:54:23 mark Exp $ +# @(#)bsd.README 5.1 (Berkeley) 5/11/90 + +This is the README file for the new make "include" files for the BSD +source tree. The files are installed in /usr/share/mk, and are, by +convention, named with the suffix ".mk". + +Note, this file is not intended to replace reading through the .mk +files for anything tricky. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +RANDOM THINGS WORTH KNOWING: + +The files are simply C-style #include files, and pretty much behave like +you'd expect. The syntax is slightly different in that a single '.' is +used instead of the hash mark, i.e. ".include ". + +One difference that will save you lots of debugging time is that inclusion +of the file is normally done at the *end* of the Makefile. The reason for +this is because .mk files often modify variables and behavior based on the +values of variables set in the Makefile. To make this work, remember that +the FIRST target found is the target that is used, i.e. if the Makefile has: + + a: + echo a + a: + echo a number two + +the command "make a" will echo "a". To make things confusing, the SECOND +variable assignment is the overriding one, i.e. if the Makefile has: + + a= foo + a= bar + + b: + echo ${a} + +the command "make b" will echo "bar". This is for compatibility with the +way the V7 make behaved. + +It's fairly difficult to make the BSD .mk files work when you're building +multiple programs in a single directory. It's a lot easier split up the +programs than to deal with the problem. Most of the agony comes from making +the "obj" directory stuff work right, not because we switch to a new version +of make. So, don't get mad at us, figure out a better way to handle multiple +architectures so we can quit using the symbolic link stuff. (Imake doesn't +count.) + +The file .depend in the source directory is expected to contain dependencies +for the source files. This file is read automatically by make after reading +the Makefile. + +The variable DESTDIR works as before. It's not set anywhere but will change +the tree where the file gets installed. + +The profiled libraries are no longer built in a different directory than +the regular libraries. A new suffix, ".po", is used to denote a profiled +object. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file has the default rules for all makes, in the BSD +environment or otherwise. You probably don't want to touch this file. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file handles installing manual pages and their +links. + +It has a single target: + + maninstall: + Install the manual pages and their links. + +It sets/uses the following variables: + +MANDIR Base path for manual installation. + +MANGRP Manual group. + +MANOWN Manual owner. + +MANMODE Manual mode. + +MANSUBDIR Subdirectory under the manual page section, i.e. "/vax" + or "/tahoe" for machine specific manual pages. + +MAN The manual pages to be installed (use a .1 - .9 suffix). + +MLINKS List of manual page links (using a .1 - .9 suffix). The + linked-to file must come first, the linked file second, + and there may be multiple pairs. The files are soft-linked. + +The include file includes a file named "../Makefile.inc" if +it exists. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file contains source tree configuration parameters, +such as the owners, groups, etc. for both manual pages and binaries, and +a few global "feature configuration" parameters. + +It has no targets. + +To get system-specific configuration parameters, bsd.own.mk will try to +include the file specified by the "MAKECONF" variable. If MAKECONF is not +set, or no such file exists, the system make configuration file, /etc/mk.conf +is included. These files may define any of the variables described below. + +bsd.own.mk sets the following variables, if they are not already defined +(defaults are in brackets): + +BSDSRCDIR The real path to the system sources, so that 'make obj' + will work correctly. [/usr/src] + +BSDOBJDIR The real path to the system 'obj' tree, so that 'make obj' + will work correctly. [/usr/obj] + +BINGRP Binary group. [bin] + +BINOWN Binary owner. [bin] + +BINMODE Binary mode. [555] + +NONBINMODE Mode for non-executable files. [444] + +MANDIR Base path for manual installation. [/usr/share/man/cat] + +MANGRP Manual group. [bin] + +MANOWN Manual owner. [bin] + +MANMODE Manual mode. [${NONBINMODE}] + +LIBDIR Base path for library installation. [/usr/lib] + +LINTLIBDIR Base path for lint(1) library installation. [/usr/libdata/lint] + +LIBGRP Library group. [${BINGRP}] + +LIBOWN Library owner. [${BINOWN}] + +LIBMODE Library mode. [${NONBINMODE}] + +DOCDIR Base path for system documentation (e.g. PSD, USD, etc.) + installation. [/usr/share/doc] + +DOCGRP Documentation group. [bin] + +DOCOWN Documentation owner. [bin] + +DOCMODE Documentation mode. [${NONBINMODE}] + +NLSDIR Base path for National Language Support files installation. + [/usr/share/nls] + +NLSGRP National Language Support files group. [bin] + +NLSOWN National Language Support files owner. [bin] + +NLSMODE National Language Support files mode. [${NONBINMODE}] + +STRIP The flag passed to the install program to cause the binary + to be stripped. This is to be used when building your + own install script so that the entire system can be made + stripped/not-stripped using a single knob. [-s] + +COPY The flag passed to the install program to cause the binary + to be copied rather than moved. This is to be used when + building our own install script so that the entire system + can either be installed with copies, or with moves using + a single knob. [-c] + +Additionally, the following variables may be set by bsd.own.mk or in a +make configuration file to modify the behaviour of the system build +process (default values are in brackets along with comments, if set by +bsd.own.mk): + +EXPORTABLE_SYSTEM + Do not build /usr/src/domestic, even if it is present. + +SKEY Compile in support for S/key authentication. [yes, set + unconditionally] + +KERBEROS Compile in support for Kerberos 4 authentication. + +KERBEROS5 Compile in support for Kerberos 5 authentication. + +MANZ Compress manual pages at installation time. + +SYS_INCLUDE Copy or symlink kernel include files into /usr/include. + Possible values are "symlinks" or "copies" (which is + the same as the variable being unset). + +NOPROFILE Do not build profiled versions of system libraries + +NOPIC Do not build PIC versions of system libraries, and + do not build shared libraries. [set if ${MACHINE_ARCH} + is "mips", "vax", "alpha" or "arm32", unset otherwise.] + +NOLINT Do not build lint libraries. [set, set unconditionally] + +bsd.own.mk is generally useful when building your own Makefiles so that +they use the same default owners etc. as the rest of the tree. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file handles building programs from one or +more source files, along with their manual pages. It has a limited number +of suffixes, consistent with the current needs of the BSD tree. + +It has eight targets: + + all: + build the program and its manual page + clean: + remove the program, any object files and the files a.out, + Errs, errs, mklog, and core. + cleandir: + remove all of the files removed by the target clean, as + well as .depend, tags, and any manual pages. + depend: + make the dependencies for the source files, and store + them in the file .depend. + includes: + install any header files. + install: + install the program and its manual pages; if the Makefile + does not itself define the target install, the targets + beforeinstall and afterinstall may also be used to cause + actions immediately before and after the install target + is executed. + lint: + run lint on the source files + tags: + create a tags file for the source files. + +It sets/uses the following variables: + +BINGRP Binary group. + +BINOWN Binary owner. + +BINMODE Binary mode. + +CLEANFILES Additional files to remove for the clean and cleandir targets. + +COPTS Additional flags to the compiler when creating C objects. + +HIDEGAME If HIDEGAME is defined, the binary is installed in + /usr/games/hide, and a symbolic link is created to + /usr/games/dm. + +LDADD Additional loader objects. Usually used for libraries. + For example, to load with the compatibility and utility + libraries, use: + + LDADD+=-lutil -lcompat + +LDFLAGS Additional loader flags. + +LINKS The list of binary links; should be full pathnames, the + linked-to file coming first, followed by the linked + file. The files are hard-linked. For example, to link + /bin/test and /bin/[, use: + + LINKS= ${DESTDIR}/bin/test ${DESTDIR}/bin/[ + +MAN Manual pages (should end in .1 - .9). If no MAN variable is + defined, "MAN=${PROG}.1" is assumed. + +PROG The name of the program to build. If not supplied, nothing + is built. + +SRCS List of source files to build the program. If PROG is not + defined, it's assumed to be ${PROG}.c. + +DPADD Additional dependencies for the program. Usually used for + libraries. For example, to depend on the compatibility and + utility libraries use: + + DPADD+=${LIBCOMPAT} ${LIBUTIL} + + The following libraries are predefined for DPADD: + + LIBC /lib/libc.a + LIBCOMPAT /usr/lib/libcompat.a + LIBCRYPT /usr/lib/libcrypt.a + LIBCURSES /usr/lib/libcurses.a + LIBDBM /usr/lib/libdbm.a + LIBDES /usr/lib/libdes.a + LIBL /usr/lib/libl.a + LIBKDB /usr/lib/libkdb.a + LIBKRB /usr/lib/libkrb.a + LIBKVM /usr/lib/libkvm.a + LIBM /usr/lib/libm.a + LIBMP /usr/lib/libmp.a + LIBPC /usr/lib/libpc.a + LIBPLOT /usr/lib/libplot.a + LIBRPC /usr/lib/sunrpc.a + LIBTERM /usr/lib/libterm.a + LIBUTIL /usr/lib/libutil.a + +SHAREDSTRINGS If defined, a new .c.o rule is used that results in shared + strings, using xstr(1). Note that this will not work with + parallel makes. + +STRIP The flag passed to the install program to cause the binary + to be stripped. + +SUBDIR A list of subdirectories that should be built as well. + Each of the targets will execute the same target in the + subdirectories. + +The include file includes the file named "../Makefile.inc" +if it exists, as well as the include file . + +Some simple examples: + +To build foo from foo.c with a manual page foo.1, use: + + PROG= foo + + .include + +To build foo from foo.c with a manual page foo.2, add the line: + + MAN= foo.2 + +If foo does not have a manual page at all, add the line: + + NOMAN= noman + +If foo has multiple source files, add the line: + + SRCS= a.c b.c c.c d.c + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file contains the default targets for building +subdirectories. It has the same eight targets as : all, +clean, cleandir, depend, includes, install, lint, and tags. For all of +the directories listed in the variable SUBDIRS, the specified directory +will be visited and the target made. There is also a default target which +allows the command "make subdir" where subdir is any directory listed in +the variable SUBDIRS. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file is used by and +. It contains overrides that are used when building +the NetBSD source tree. For instance, if "PARALLEL" is defined by +the program/library Makefile, it includes a set of rules for lex and +yacc that allow multiple lex and yacc targets to be built in parallel. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +The include file has support for building libraries. It has +the same eight targets as : all, clean, cleandir, depend, +includes, install, lint, and tags. It has a limited number of suffixes, +consistent with the current needs of the BSD tree. + +It sets/uses the following variables: + +LIB The name of the library to build. + +LIBDIR Target directory for libraries. + +LINTLIBDIR Target directory for lint libraries. + +LIBGRP Library group. + +LIBOWN Library owner. + +LIBMODE Library mode. + +LDADD Additional loader objects. + +MAN The manual pages to be installed (use a .1 - .9 suffix). + +SRCS List of source files to build the library. Suffix types + .s, .c, and .f are supported. Note, .s files are preferred + to .c files of the same name. (This is not the default for + versions of make.) + +The include file includes the file named "../Makefile.inc" +if it exists, as well as the include file . + +It has rules for building profiled objects; profiled libraries are +built by default. + +Libraries are ranlib'd when made. diff --git a/contrib/bmake/mk/auto.dep.mk b/contrib/bmake/mk/auto.dep.mk new file mode 100644 index 0000000..bb2d4c1 --- /dev/null +++ b/contrib/bmake/mk/auto.dep.mk @@ -0,0 +1,64 @@ +# +# RCSid: +# $Id: auto.dep.mk,v 1.2 2010/04/19 17:37:19 sjg Exp $ +# +# @(#) Copyright (c) 2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# This module provides automagic dependency generation along the +# lines suggested in the GNU make.info + +# set MKDEP=auto.dep and dep.mk will include us + +# This version differs from autodep.mk, in that +# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d +# this makes it simpler to get the args to -MF and -MT right +# and ensure we can simply include all the .d files. +# +# However suffix rules do not work with something like .o.d so we +# don't even try to handle 'make depend' gracefully. +# dep.mk will handle that itself. +# +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# this what bmake > 20100401 will look for +.MAKE.DEPENDFILE ?= .depend + +# set this to -MMD to ignore /usr/include +# actually it ignores <> so may not be a great idea +CFLAGS_MD ?= -MD +# -MF etc not available on all gcc versions. +CFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T} +CFLAGS += ${CFLAGS_MD} ${CFLAGS_MF} +CXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF} + +CLEANFILES += .depend ${.MAKE.DEPENDFILE} *.d + +# skip generating dependfile for misc targets +.if ${.TARGETS:Uall:M*all} != "" +.END: ${.MAKE.DEPENDFILE} +.endif + +# doing 'make depend' isn't a big win with this model +.if !target(depend) +depend: ${.MAKE.DEPENDFILE} +.endif + +# this is trivial +${.MAKE.DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS} + -@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \ + echo ".-include \"$$f\""; \ + done > $@ + +.endif diff --git a/contrib/bmake/mk/auto.obj.mk b/contrib/bmake/mk/auto.obj.mk new file mode 100644 index 0000000..adccd4b --- /dev/null +++ b/contrib/bmake/mk/auto.obj.mk @@ -0,0 +1,56 @@ +# $Id: auto.obj.mk,v 1.8 2011/08/08 17:35:20 sjg Exp $ +# +# @(#) Copyright (c) 2004, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +ECHO_TRACE ?= echo + +.ifndef Mkdirs +# A race condition in some versions of mkdir, means that it can bail +# if another process made a dir that mkdir expected to. +# We repeat the mkdir -p a number of times to try and work around this. +# We stop looping as soon as the dir exists. +# If we get to the end of the loop, a plain mkdir will issue an error. +Mkdirs= Mkdirs() { \ + for d in $$*; do \ + for i in 1 2 3 4 5 6; do \ + mkdir -p $$d; \ + test -d $$d && return 0; \ + done > /dev/null 2>&1; \ + mkdir $$d || exit $$?; \ + done; } +.endif + +# if MKOBJDIRS is set to auto (and NOOBJ isn't defined) do some magic... +# This will automatically create objdirs as needed. +# Skip it if we are just doing 'clean'. +.if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto +# Use __objdir here so it is easier to tweak without impacting +# the logic. +__objdir?= ${MAKEOBJDIR} +.if ${.OBJDIR} != ${__objdir} +# We need to chdir, make the directory if needed +.if !exists(${__objdir}/) && \ + (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "") +# This will actually make it... +__objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \ + ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \ + ${Mkdirs}; Mkdirs ${__objdir} +.endif +# This causes make to use the specified directory as .OBJDIR +.OBJDIR: ${__objdir} +.if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != "" +.error could not use ${__objdir} +.endif +.endif +.endif diff --git a/contrib/bmake/mk/autoconf.mk b/contrib/bmake/mk/autoconf.mk new file mode 100644 index 0000000..573a715 --- /dev/null +++ b/contrib/bmake/mk/autoconf.mk @@ -0,0 +1,78 @@ +# $Id: autoconf.mk,v 1.8 2012/11/19 05:37:48 sjg Exp $ +# +# @(#) Copyright (c) 1996-2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.NOPATH: config.h config.status + +.if !target(config.h) +config.h: ${.CURDIR}/config.h.in config.status + ./config.status +.endif + +.if !target(config.status) +# avoid the targets behaving differently +.if exists(${.OBJDIR}/config.status) +config.status: config.recheck +.else +config.status: config.gen +.endif + +config.recheck: config.h.in ${.CURDIR}/configure + ./config.status --recheck + @touch $@ + +config.gen: config.h.in ${.CURDIR}/configure + CC="${CC} ${CCMODE}" ${.CURDIR}/configure --no-create ${CONFIGURE_ARGS} + @touch $@ config.recheck + +CLEANFILES+= config.recheck config.gen config.status *.meta +.endif + +# avoid things blowing up if these are not here... +# this is not quite per the autoconf manual, +# and is extremely convoluted - but all utterly necessary! + +.if make(autoconf-in) || make(configure) || make(config.h.in) || ${AUTO_AUTOCONF:Uno:tl} == "yes" +AUTOCONF ?= autoconf +AUTOHEADER ?= autoheader + +# expand it to a full path +AUTOCONF := ${AUTOCONF:${M_whence}} + +.if exists(${AUTOCONF}) + +.PRECIOUS: configure config.h.in config.status + +ACLOCAL = +ACCONFIG = + +.if exists(${.CURDIR}/aclocal.m4) +ACLOCAL += aclocal.m4 +.endif +# use of acconfig.h is deprecated! +.if exists(${.CURDIR}/acconfig.h) +ACCONFIG += acconfig.h +.endif + +config.h.in: ${.CURDIR}/configure.in ${ACCONFIG} + (cd ${.CURDIR} && ${AUTOHEADER}) + +configure: ${.CURDIR}/configure.in ${ACLOCAL} + (cd ${.CURDIR} && ${AUTOCONF}) + +AUTOCONF_INPUTS += configure +autoconf-input: ${AUTOCONF_INPUTS} + +.endif +.endif diff --git a/contrib/bmake/mk/autodep.mk b/contrib/bmake/mk/autodep.mk new file mode 100644 index 0000000..744770f --- /dev/null +++ b/contrib/bmake/mk/autodep.mk @@ -0,0 +1,216 @@ +# +# RCSid: +# $Id: autodep.mk,v 1.32 2010/04/19 17:37:56 sjg Exp $ +# +# @(#) Copyright (c) 1999-2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net + +# This module provides automagic dependency generation along the +# lines suggested in the GNU make.info +# The depend target is mainly for backwards compatability, +# dependencies are normally updated as part of compilation. + +# set MKDEP=autodep and dep.mk will include us +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# different versions of bsd.dep.mk use these +MKDEP=autodep +MKDEPCMD=autodep + +DEPENDFILE?= .depend +.for d in ${DEPENDFILE:N.depend} +# bmake only groks .depend +.-include "$d" +.endfor + +# it does nothing if SRCS is not defined or is empty +.if defined(SRCS) && !empty(SRCS) +DEPSRCS?=${SRCS} +__depsrcs=${DEPSRCS:M*.c} +__depsrcs+=${DEPSRCS:M*.y} +__depsrcs+=${DEPSRCS:M*.l} +__depsrcs+=${DEPSRCS:M*.s} +__depsrcs+=${DEPSRCS:M*.S} +__depsrcs+=${DEPSRCS:M*.cc} +__depsrcs+=${DEPSRCS:M*.cpp} +__depsrcs+=${DEPSRCS:M*.C} +__depsrcs+=${DEPSRCS:M*.cxx} +__depsrcs+=${DEPSRCS:M*.pc} + +.for s in ${__depsrcs} +${s:T:R}.d: $s +.endfor + +__depsrcs:=${__depsrcs:T:R:S/$/.d/g} +# we also need to handle makefiles where the .d's from __depsrcs +# don't match those from OBJS +# we avoid using := here, since the modifier applied to OBJS +# can cause trouble if there are any undefined vars in OBJS. +__dependsrcsx?= ${__depsrcs} ${OBJS:S/.o/.d/} +__dependsrcs= ${__dependsrcsx:O:u} + +# clean up any .c files we may have generated +#__gensrcs:= ${DEPSRCS:M*.y} ${DEPSRCS:M*.l} +#CLEANFILES+= ${__gensrcs:T:R:S/$/.c/g} + +# set this to -MMD to ignore /usr/include +# actually it ignores <> so may not be a great idea +CFLAGS_MD?=-MD +# -MF etc not available on all gcc versions. +# we "fix" the .o later +CFLAGS_MF?=-MF ${.TARGET:T:R}.d -MT ${.TARGET:T:R}.o +CFLAGS+= ${CFLAGS_MD} ${CFLAGS_MF} +RM?= rm + +# watch out for people who don't use CPPFLAGS +CPPFLAGS_MD=${CFLAGS:M-[IUD]*} ${CPPFLAGS} +CXXFLAGS_MD=${CXXFLAGS:M-[IUD]*} ${CPPFLAGS} + +# just in case these need to be different +CC_MD?=${CC} +CXX_MD?=${CXX} + +# so we can do an explicit make depend, but not otherwise +.if make(depend) +.SUFFIXES: .d + +.if empty(CFLAGS_MD) +.y.d: + @echo updating dependencies for $< + @${YACC} ${YFLAGS} $< + @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} y.tab.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f y.tab.c $@; false; } + @${RM} -f y.tab.c + +.l.d: + @echo updating dependencies for $< + ${LEX} ${LFLAGS} $< + @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} lex.yy.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f lex.yy.c $@; false; } + @${RM} -f lex.yy.c + +.c.d: + @echo updating dependencies for $< + @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; } + +.s.d .S.d: + @echo updating dependencies for $< + @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} ${AINC} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; } + +.cc.d .cpp.d .C.d .cxx.d: + @echo updating dependencies for $< + @${SHELL} -ec "${CXX_MD} -M ${CXXFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; } +.else +.y.d: + ${YACC} ${YFLAGS} $< + ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} y.tab.c > $@ || { ${RM} -f y.tab.c $@; false; } + ${RM} -f y.tab.c + +.l.d: + ${LEX} ${LFLAGS} $< + ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} lex.yy.c > $@ || { ${RM} -f lex.yy.c $@; false; } + ${RM} -f lex.yy.c + +.c.d: + ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} $< > $@ || { ${RM} -f $@; false; } + +.s.d .S.d: + ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} ${AINC} $< > $@ || { ${RM} -f $@; false; } + +.cc.d .cpp.d .C.d .cxx.d: + ${CXX_MD} ${CFLAGS_MD:S/D//} ${CXXFLAGS_MD} $< > $@ || { ${RM} -f $@; false; } +.endif + +.if !target(depend) +depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIRUSE + +${DEPENDFILE}: ${DEPSRCS} ${__dependsrcs} +.NOPATH: ${__dependsrcs} +.OPTIONAL: ${__dependsrcs} +.endif +.endif # make(depend) + +.if empty(CFLAGS_MD) +# make sure the .d's are generated/updated +${PROG} ${_LIBS}: ${DEPENDFILE} +.endif + +.ORDER: beforedepend ${DEPENDFILE} afterdepend + +.if ${.OBJDIR} != ${.CURDIR} +__depfiles= *.d +.else +__depfiles= ${__dependsrcs} +.endif + +DEPCLEANFILES= ${DEPENDFILE} ${__depfiles} y.tab.d *.tmp.d + +cleandir: cleanautodepend +cleanautodepend: + ${RM} -f ${DEPCLEANFILES} + +CLEANFILES+= ${DEPCLEANFILES} + +.if defined(__dependsrcs) && !empty(__dependsrcs) +.if make(depend) || !(make(clean*) || make(destroy*) || make(obj) || make(*install) || make(install-*)) +# this ensures we do the right thing if only building a shared or +# profiled lib +OBJ_EXTENSIONS?=.o .po .so .So +MDLIB_SED= -e '/:/s,^\([^\.:]*\)\.[psS]*o,${OBJ_EXTENSIONS:S,^,\1,},' +.ifdef NOMD_SED +.ifdef LIB +MD_SED=sed ${MDLIB_SED} +.else +MD_SED=cat +.endif +.else +# arrange to put some variable names into ${DEPENDFILE} +.ifdef LIB +MD_SED=sed ${MDLIB_SED} +.else +MD_SED=sed +.endif +SUBST_DEPVARS+= SB TOP BACKING SRC SRCDIR BASE BASEDIR +.for v in ${SUBST_DEPVARS} +.if defined(${v}) && !empty(${v}) +MD_SED+= -e 's,${$v},$${$v},' +.endif +.endfor +.endif +.if (${MD_SED} == "sed") +MD_SED=cat +.endif + +# this will be done whenever make finishes successfully +.if ${MAKE_VERSION:U0:[1]:C/.*-//} < 20050530 +.END: +.else +.END: ${DEPENDFILE} +# we do not want to trigger building .d's just use them if they exist +${DEPENDFILE}: ${__dependsrcs:@d@${exists($d):?$d:}@} +.endif + -@${MD_SED} ${__depfiles} > ${DEPENDFILE}.new 2> /dev/null && \ + test -s ${DEPENDFILE}.new && mv ${DEPENDFILE}.new ${DEPENDFILE}; \ + ${RM} -f ${DEPENDFILE}.new +.endif +.endif +.else +depend: beforedepend afterdepend _SUBDIRUSE +.endif + +.if !target(beforedepend) +beforedepend: +.endif +.if !target(afterdepend) +afterdepend: +.endif + +.endif diff --git a/contrib/bmake/mk/dep.mk b/contrib/bmake/mk/dep.mk new file mode 100644 index 0000000..b754500 --- /dev/null +++ b/contrib/bmake/mk/dep.mk @@ -0,0 +1,133 @@ +# $Id: dep.mk,v 1.16 2012/11/11 22:37:02 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# handle Proc*C as well... +.if defined(SRCS) +.if !empty(SRCS:M*.pc) +.include +.endif + +# it would be nice to be able to query .SUFFIXES +OBJ_EXTENSIONS+= .o .po .lo .So + +# explicit dependencies help short-circuit .SUFFIX searches +SRCS_DEP_FILTER+= N*.[hly] +.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} +.for e in ${OBJ_EXTENSIONS:O:u} +.if !target(${s:T:R}$e) +${s:T:R}$e: $s +.endif +.endfor +.endfor +.endif + +.if exists(/usr/bin/mkdep) +MKDEP_CMD?= mkdep +.elif exists(/usr/local/share/bin/mkdeps.sh) +MKDEP_CMD?= /usr/local/share/bin/mkdeps.sh -N +.endif +MKDEP_CMD?= mkdep + +MKDEP ?= ${MKDEP_CMD} + +.NOPATH: .depend + +.if ${MKDEP} == "auto.dep" && make(depend) +# auto.dep.mk does not "do" depend +MK_AUTODEP= no +.endif + +.if ${MK_AUTODEP} == yes +.if ${MKDEP:T:S,auto,,} != ${MKDEP:T} +.include <${MKDEP}.mk> +.else +.include +.endif +.else +.if ${MKDEP:T:S,auto,,} != ${MKDEP:T} +MKDEP = ${MKDEP_CMD} +.endif +MKDEP_ENV_VARS += CC CXX +.for v in ${MKDEP_ENV_VARS:O:u} +.if !empty($v) +MKDEP_ENV += $v='${$v}' +.endif +.endfor + +_MKDEP = ${MKDEP_ENV} ${MKDEP} + +# some of the rules involve .h sources, so remove them from mkdep line +.if !target(depend) +depend: beforedepend .depend _SUBDIRUSE afterdepend + +.if defined(SRCS) +# libs can have too many SRCS for a single command line +# so do them one at a time. +.depend: ${SRCS} ${.PARSEDIR}/${.PASEFILE} + @rm -f .depend +.ifdef LIB + @files="${.ALLSRC:M*.[sS]}"; \ + set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$f; done + @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \ + set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done + @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \ + set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done +.else + @files="${.ALLSRC:M*.[Ss]}"; \ + case "$$files" in *.[Ss]*) \ + echo ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files; \ + ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files;; \ + esac + @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \ + case "$$files" in *.c*) \ + echo ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ + ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \ + esac + @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \ + case "$$files" in *.[Cc]*) \ + echo ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ + ${_MKDEP} -a ${MKDEPFLAGS} \ + ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \ + esac +.endif +.else +.depend: +.endif +.if !target(beforedepend) +beforedepend: +.endif +.if !target(afterdepend) +afterdepend: +.endif +.endif +.endif + +.if !target(tags) +.if defined(SRCS) +tags: ${SRCS} _SUBDIRUSE + -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \ + sed "s;\${.CURDIR}/;;" > tags +.else +tags: +.endif +.endif + +.if defined(SRCS) +cleandir: cleandepend +.if !target(cleandepend) +cleandepend: + rm -f .depend ${.CURDIR}/tags +.endif +.endif + +.endif diff --git a/contrib/bmake/mk/dirdeps.mk b/contrib/bmake/mk/dirdeps.mk new file mode 100644 index 0000000..e812416 --- /dev/null +++ b/contrib/bmake/mk/dirdeps.mk @@ -0,0 +1,500 @@ +# $Id: dirdeps.mk,v 1.28 2013/03/25 21:11:43 sjg Exp $ + +# Copyright (c) 2010-2013, Juniper Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Much of the complexity here is for supporting cross-building. +# If a tree does not support that, simply using plain Makefile.depend +# should provide sufficient clue. +# Otherwise the recommendation is to use Makefile.depend.${MACHINE} +# as expected below. + +# Note: this file gets multiply included. +# This is what we do with DIRDEPS + +# DIRDEPS: +# This is a list of directories - relative to SRCTOP, it is +# normally only of interest to .MAKE.LEVEL 0. +# In some cases the entry may be qualified with a . +# or . suffix (see TARGET_SPEC_VARS below), +# for example to force building something for the pseudo +# machines "host" or "common" regardless of current ${MACHINE}. +# +# All unqualified entries end up being qualified with .${TARGET_SPEC} +# and partially qualified (if TARGET_SPEC_VARS has multiple +# entries) are also expanded to a full .. +# The _DIRDEPS_USE target uses the suffix to set TARGET_SPEC +# correctly when visiting each entry. +# +# The fully qualified directory entries are used to construct a +# dependency graph that will drive the build later. +# +# Also, for each fully qualified directory target, we will search +# using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional +# dependencies. We use Makefile.depend (default value for +# .MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to +# distinguish them from others. +# +# Each Makefile.depend file sets DEP_RELDIR to be the +# the RELDIR (path relative to SRCTOP) for its directory, and +# since each Makefile.depend file includes dirdeps.mk, this +# processing is recursive and results in .MAKE.LEVEL 0 learning the +# dependencies of the tree wrt the initial directory (_DEP_RELDIR). +# +# BUILD_AT_LEVEL0 +# Indicates whether .MAKE.LEVEL 0 builds anything: +# if "no" sub-makes are used to build everything, +# if "yes" sub-makes are only used to build for other machines. +# It is best to use "no", but this can require fixing some +# makefiles to not do anything at .MAKE.LEVEL 0. +# +# TARGET_SPEC_VARS +# The default value is just MACHINE, and for most environments +# this is sufficient. The _DIRDEPS_USE target actually sets +# both MACHINE and TARGET_SPEC to the suffix of the current +# target so that in the general case TARGET_SPEC can be ignored. +# +# If more than MACHINE is needed then sys.mk needs to decompose +# TARGET_SPEC and set the relevant variables accordingly. +# It is important that MACHINE be included in and actually be +# the first member of TARGET_SPEC_VARS. This allows other +# variables to be considered optional, and some of the treatment +# below relies on MACHINE being the first entry. +# Note: TARGET_SPEC cannot contain any '.'s so the target +# triple used by compiler folk won't work (directly anyway). +# +# For example: +# +# # Always list MACHINE first, +# # other variables might be optional. +# TARGET_SPEC_VARS = MACHINE TARGET_OS +# .if ${TARGET_SPEC:Uno:M*,*} != "" +# _tspec := ${TARGET_SPEC:S/,/ /g} +# MACHINE := ${_tspec:[1]} +# TARGET_OS := ${_tspec:[2]} +# # etc. +# # We need to stop that TARGET_SPEC affecting any submakes +# # and deal with MACHINE=${TARGET_SPEC} in the environment. +# TARGET_SPEC = +# # export but do not track +# .export-env TARGET_SPEC +# .export ${TARGET_SPEC_VARS} +# .for v in ${TARGET_SPEC_VARS:O:u} +# .if empty($v) +# .undef $v +# .endif +# .endfor +# .endif +# # make sure we know what TARGET_SPEC is +# # as we may need it to find Makefile.depend* +# TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} +# + +.if ${.MAKE.LEVEL} == 0 +# only the first instance is interested in all this + +# First off, we want to know what ${MACHINE} to build for. +# This can be complicated if we are using a mixture of ${MACHINE} specific +# and non-specific Makefile.depend* + +.if !target(_DIRDEP_USE) +# do some setup we only need once +_CURDIR ?= ${.CURDIR} + +# make sure these are empty to start with +_DEP_TARGET_SPEC = +_DIRDEP_CHECKED = + +# If TARGET_SPEC_VARS is other than just MACHINE +# it should be set by sys.mk or similar by now. +# TARGET_SPEC must not contain any '.'s. +TARGET_SPEC_VARS ?= MACHINE +# this is what we started with +TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} +# this is what we mostly use below +DEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} +# make sure we have defaults +.for v in ${TARGET_SPEC_VARS} +DEP_$v ?= ${$v} +.endfor + +.if ${TARGET_SPEC_VARS:[#]} > 1 +# Ok, this gets more complex (putting it mildly). +# In order to stay sane, we need to ensure that all the build_dirs +# we compute below are fully qualified wrt DEP_TARGET_SPEC. +# The makefiles may only partially specify (eg. MACHINE only), +# so we need to construct a set of modifiers to fill in the gaps. +# jot 10 should output 1 2 3 .. 10 +JOT ?= jot +_tspec_x := ${${JOT} ${TARGET_SPEC_VARS:[#]}:L:sh} +# this handles unqualified entries +M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.${DEP_TARGET_SPEC}; +# there needs to be at least one item missing for these to make sense +.for i in ${_tspec_x:[2..-1]} +_tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,} +_tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$${DEP_$v}@:ts,} +M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i}; +.endfor +.else +# A harmless? default. +M_dep_qual_fixes = U +.endif + +.if !defined(.MAKE.DEPENDFILE_PREFERENCE) +# .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater? +# you really want this set by sys.mk or similar +.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T} +.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}" +.if ${TARGET_SPEC} != ${MACHINE} +.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE} +.endif +.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R} +.endif +.endif + +_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T} +_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*} + +# for machine specific dependfiles we require ${MACHINE} to be at the end +# also for the sake of sanity we require a common prefix +.if !defined(.MAKE.DEPENDFILE_PREFIX) +# knowing .MAKE.DEPENDFILE_PREFIX helps +.if !empty(_machine_dependfiles) +.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R} +.else +.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T} +.endif +.endif + + +# this is how we identify non-machine specific dependfiles +N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} + +.endif # !target(_DIRDEP_USE) + +# if we were included recursively _DEP_TARGET_SPEC should be valid. +.if empty(_DEP_TARGET_SPEC) +# we may or may not have included a dependfile yet +_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]} +.if !empty(_debug_reldir) +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _last_dependfile='${_last_dependfile}' +.endif + +.if empty(_last_dependfile) || ${_last_dependfile:E:${N_notmachine}} == "" +# this is all we have to work with +DEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}} +_DEP_TARGET_SPEC := ${DEP_TARGET_SPEC} +.else +_DEP_TARGET_SPEC = ${_last_dependfile:${M_dep_qual_fixes:ts:}:E} +.endif +.if !empty(_last_dependfile) +# record that we've read dependfile for this +_DIRDEP_CHECKED += ${_CURDIR}.${TARGET_SPEC} +.endif +.endif + +# by now _DEP_TARGET_SPEC should be set, parse it. +.if ${TARGET_SPEC_VARS:[#]} > 1 +# we need to parse DEP_MACHINE may or may not contain more info +_tspec := ${_DEP_TARGET_SPEC:S/,/ /g} +.for i in ${_tspec_x} +DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} +.endfor +.for v in ${TARGET_SPEC_VARS:O:u} +.if empty(DEP_$v) +.undef DEP_$v +.endif +.endfor +.else +DEP_MACHINE := ${_DEP_TARGET_SPEC} +.endif + +# pickup customizations +# as below you can use !target(_DIRDEP_USE) to protect things +# which should only be done once. +.-include "local.dirdeps.mk" + +# the first time we are included the _DIRDEP_USE target will not be defined +# we can use this as a clue to do initialization and other one time things. +.if !target(_DIRDEP_USE) +# make sure this target exists +dirdeps: + +# We normally expect to be included by Makefile.depend.* +# which sets the DEP_* macros below. +DEP_RELDIR ?= ${RELDIR} + +# this can cause lots of output! +# set to a set of glob expressions that might match RELDIR +DEBUG_DIRDEPS ?= no + +# remember the initial value of DEP_RELDIR - we test for it below. +_DEP_RELDIR := ${DEP_RELDIR} + +# things we skip for host tools +SKIP_HOSTDIR ?= + +NSkipHostDir = ${SKIP_HOSTDIR:N*.host:S,$,.host,:N.host:${M_ListToSkip}} + +# things we always skip +# SKIP_DIRDEPS allows for adding entries on command line. +SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS} +SKIP_DIR.host += ${SKIP_HOSTDIR} + +DEP_SKIP_DIR = ${SKIP_DIR} \ + ${SKIP_DIR.${DEP_TARGET_SPEC}:U} \ + ${SKIP_DIR.${DEP_MACHINE}:U} \ + ${SKIP_DIRDEPS.${DEP_MACHINE}:U} + +NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}} + +.if defined(NO_DIRDEPS) || defined(NODIRDEPS) +# confine ourselves to the original dir +DIRDEPS_FILTER += M${_DEP_RELDIR}* +.endif + +# we supress SUBDIR when visiting the leaves +# we assume sys.mk will set MACHINE_ARCH +# you can add extras to DIRDEP_USE_ENV +# if there is no makefile in the target directory, we skip it. +_DIRDEP_USE: .USE .MAKE + @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \ + test -s ${.TARGET:R}/$$m || continue; \ + echo "${TRACER}Checking ${.TARGET:R} for ${.TARGET:E} ..."; \ + MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \ + TARGET_SPEC=${.TARGET:E} \ + MACHINE=${.TARGET:E} \ + ${.MAKE} -C ${.TARGET:R} || exit 1; \ + break; \ + done + +.ifdef ALL_MACHINES +# this is how you limit it to only the machines we have been built for +# previously. +.if empty(ONLY_MACHINE_LIST) +.if !empty(ALL_MACHINE_LIST) +# ALL_MACHINE_LIST is the list of all legal machines - ignore anything else +_machine_list != cd ${_CURDIR} && 'ls' -1 ${ALL_MACHINE_LIST:O:u:@m@${.MAKE.DEPENDFILE:T:R}.$m@} 2> /dev/null; echo +.else +_machine_list != 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.* 2> /dev/null; echo +.endif +_only_machines := ${_machine_list:${NIgnoreFiles:UN*.bak}:E:O:u} +.else +_only_machines := ${ONLY_MACHINE_LIST} +.endif + +.if empty(_only_machines) +# we must be boot-strapping +_only_machines := ${TARGET_MACHINE:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}} +.endif + +.else # ! ALL_MACHINES +# if ONLY_MACHINE_LIST is set, we are limited to that +# if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST +# otherwise DEP_MACHINE is it - so DEP_MACHINE will match. +_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}} +.endif + +.if !empty(NOT_MACHINE_LIST) +_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}} +.endif + +# make sure we have a starting place? +DIRDEPS ?= ${RELDIR} +.endif # target + +_debug_reldir := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} +_debug_search := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@} + +# the rest is done repeatedly for every Makefile.depend we read. +# if we are anything but the original dir we care only about the +# machine type we were included for.. + +.if ${DEP_RELDIR} == "." +_this_dir := ${SRCTOP} +.else +_this_dir := ${SRCTOP}/${DEP_RELDIR} +.endif + +# on rare occasions, there can be a need for extra help +_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc +.-include "${_dep_hack}" + +.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC} +# this should be all +_machines := ${DEP_MACHINE} +.else +# this is the machine list we actually use below +_machines := ${_only_machines} + +.if defined(HOSTPROG) || ${DEP_MACHINE} == "host" +# we need to build this guy's dependencies for host as well. +_machines += host +.endif + +_machines := ${_machines:O:u} +.endif + +.if ${TARGET_SPEC_VARS:[#]} > 1 +# we need to tweak _machines +_dm := ${DEP_MACHINE} +_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@} +DEP_MACHINE := ${_dm} +.endif + +# reset each time through +_build_dirs = + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# pickup other machines for this dir if necessary +.if ${BUILD_AT_LEVEL0:Uyes} == "no" +_build_dirs += ${_machines:@m@${_CURDIR}.$m@} +.else +_build_dirs += ${_machines:N${DEP_TARGET_SPEC}:@m@${_CURDIR}.$m@} +.if ${DEP_TARGET_SPEC} == ${TARGET_SPEC} +# pickup local dependencies now +.-include <.depend> +.endif +.endif +.endif + +.if !empty(_debug_reldir) +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}' +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}' +.endif + +.if !empty(DIRDEPS) +# these we reset each time through as they can depend on DEP_MACHINE +DEP_DIRDEPS_FILTER = \ + ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \ + ${DIRDEPS_FILTER.${DEP_MACHINE}:U} \ + ${DIRDEPS_FILTER:U} +.if empty(DEP_DIRDEPS_FILTER) +# something harmless +DEP_DIRDEPS_FILTER = U +.endif + +# this is what we start with +__depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:O:u:@d@${SRCTOP}/$d@} + +# some entries may be qualified with . +# the :M*/*/*.* just tries to limit the dirs we check to likely ones. +# the ${d:E:M*/*} ensures we don't consider junos/usr.sbin/mgd +__qual_depdirs := ${__depdirs:M*/*/*.*:@d@${exists($d):?:${"${d:E:M*/*}":?:${exists(${d:R}):?$d:}}}@} +__unqual_depdirs := ${__depdirs:${__qual_depdirs:Uno:${M_ListToSkip}}} + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# if it was called out - we likely need it. +__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} +__qual_depdirs += ${__hostdpadd} +.endif + +.if !empty(_debug_reldir) +.info depdirs=${__depdirs} +.info qualified=${__qual_depdirs} +.info unqualified=${__unqual_depdirs} +.endif + +# _build_dirs is what we will feed to _DIRDEP_USE +_build_dirs += \ + ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \ + ${__qual_depdirs:N*.host} \ + ${_machines:@m@${__unqual_depdirs:@d@$d.$m@}@} + +# qualify everything now +_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u} + +.endif # empty DIRDEPS + +# Normally if doing make -V something, +# we do not want to waste time chasing DIRDEPS +# but if we want to count the number of Makefile.depend* read, we do. +.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS}} == "" +.if !empty(_build_dirs) +# this makes it all happen +dirdeps: ${_build_dirs} +${_build_dirs}: _DIRDEP_USE + +.if !empty(_debug_reldir) +.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs} +.endif + +# this builds the dependency graph +.for m in ${_machines} +# it would be nice to do :N${.TARGET} +.if !empty(__qual_depdirs) +.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m} +.if !empty(_debug_reldir) || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != "" +.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q} +.endif +${_this_dir}.$m: ${_build_dirs:M*.$q} +.endfor +.endif +.if !empty(_debug_reldir) +.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m} +.endif +${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} +.endfor + +.endif + +# Now find more dependencies - and recurse. +.for d in ${_build_dirs} +.if ${_DIRDEP_CHECKED:M$d} == "" +# once only +_DIRDEP_CHECKED += $d +# Note: _build_dirs is fully qualifed so d:R is always the directory +.if exists(${d:R}) +# Warning: there is an assumption here that MACHINE is always +# the first entry in TARGET_SPEC_VARS. +# If TARGET_SPEC and MACHINE are insufficient, you have a problem. +_m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:S;${MACHINE};${d:E:C/,.*//};:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]} +.if !empty(_m) +_qm := ${_m:${M_dep_qual_fixes:ts:}} +.if !empty(_debug_search) +.info Looking for ${_qm} +.endif +# we pass _DEP_TARGET_SPEC to tell the next step what we want +_DEP_TARGET_SPEC := ${d:E} +# some makefiles may still look at this +_DEP_MACHINE := ${d:E:C/,.*//} +.if !empty(_debug_reldir) && ${_qm} != ${_m} +.info loading ${_m} for ${d:E} +.endif +.include <${_m}> +.endif +.endif +.endif +.endfor + +.endif # -V + +.elif ${.MAKE.LEVEL} > 42 +.error You should have stopped recursing by now. +.else +_DEP_RELDIR := ${DEP_RELDIR} +# pickup local dependencies +.-include <.depend> +.endif + diff --git a/contrib/bmake/mk/doc.mk b/contrib/bmake/mk/doc.mk new file mode 100644 index 0000000..d496c42 --- /dev/null +++ b/contrib/bmake/mk/doc.mk @@ -0,0 +1,63 @@ +# $Id: doc.mk,v 1.4 2012/11/11 22:37:02 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +BIB?= bib +EQN?= eqn +GREMLIN?= grn +GRIND?= vgrind -f +INDXBIB?= indxbib +PIC?= pic +REFER?= refer +ROFF?= groff -M/usr/share/tmac ${MACROS} ${PAGES} +SOELIM?= soelim +TBL?= tbl + +.PATH: ${.CURDIR} + +.if !target(all) +.MAIN: all +all: paper.ps +.endif + +.if !target(paper.ps) +paper.ps: ${SRCS} + ${ROFF} ${SRCS} > ${.TARGET} +.endif + +.if !target(print) +print: paper.ps + lpr -P${PRINTER} paper.ps +.endif + +.if !target(manpages) +manpages: +.endif + +.if !target(obj) +obj: +.endif + +clean cleandir: + rm -f paper.* [eE]rrs mklog ${CLEANFILES} + +.if ${MK_DOC} == "no" +install: +.else +FILES?= ${SRCS} +install: + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \ + Makefile ${FILES} ${EXTRA} ${DESTDIR}${BINDIR}/${DIR} +.endif + +spell: ${SRCS} + spell ${SRCS} | sort | comm -23 - spell.ok > paper.spell + +BINDIR?= /usr/share/doc +BINGRP?= bin +BINOWN?= bin +BINMODE?= 444 + +.include +.endif diff --git a/contrib/bmake/mk/dpadd.mk b/contrib/bmake/mk/dpadd.mk new file mode 100644 index 0000000..a940b61 --- /dev/null +++ b/contrib/bmake/mk/dpadd.mk @@ -0,0 +1,196 @@ +# $Id: dpadd.mk,v 1.18 2011/11/10 05:13:37 sjg Exp $ +# +# @(#) Copyright (c) 2004, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# sometimes we play games with .CURDIR etc +# _* hold the original values of .* +_OBJDIR?= ${.OBJDIR} +_CURDIR?= ${.CURDIR} + +# DPLIBS helps us ensure we keep DPADD and LDADD in sync +DPLIBS+= ${DPLIBS_LAST} +DPADD+= ${DPLIBS} +.for __lib in ${DPLIBS:T:R} +LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}} +.endfor + +# DPADD can contain things other than libs +__dpadd_libs = ${DPADD:M*/lib*} + +# some libs have dependencies... +# DPLIBS_* allows bsd.libnames.mk to flag libs which must be included +# in DPADD for a given library. +.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R}}@} +.if "${DPADD:M${__lib}}" == "" +DPADD+= ${__lib} +LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}} +.endif +.endfor +# Last of all... for libc and libgcc +DPADD+= ${DPADD_LAST} + +# Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD +# For the -I's convert the path to a relative one. For separate objdirs +# the DPADD paths will be to the obj tree so we need to subst anyway. + +# If USE_PROFILE is yes, then check for profiled versions of libs +# and use them. + +USE_PROFILE?=no +.if defined(LIBDL) && exists(${LIBDL}) +.if defined(PROG) && (make(${PROG}_p) || ${USE_PROFILE} == yes) && \ + defined(LDFLAGS) && ${LDFLAGS:M-export-dynamic} +# building profiled version of a prog that needs dlopen to work +DPLIBS+= ${LIBDL} +.endif +.endif + +.if defined(LIBDMALLOC) && exists(${LIBDMALLOC}) +.if defined(USE_DMALLOC) && ${USE_DMALLOC} != no +.if !defined(NO_DMALLOC) +CPPFLAGS+= -DUSE_DMALLOC +.endif +DPLIBS+= ${LIBDMALLOC} +.endif +.endif + +# Order -L's to seach ours first. +# Avoids picking up old versions already installed. +__dpadd_libdirs := ${__dpadd_libs:R:H:S/^/-L/g:O:u:N-L} +LDADD += ${__dpadd_libdirs:M-L${OBJTOP}/*} +LDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*} + +.if ${.CURDIR} == ${SRCTOP} +RELDIR=. +RELTOP=. +.else +RELDIR?= ${.CURDIR:S,${SRCTOP}/,,} +.if ${RELDIR} == ${.CURDIR} +RELDIR?= ${.OBJDIR:S,${OBJTOP}/,,} +.endif +RELTOP?= ${RELDIR:C,[^/]+,..,g} +.endif +RELOBJTOP?= ${OBJTOP} +RELSRCTOP?= ${SRCTOP} + +.if !make(dpadd) +.ifdef LIB +# Each lib is its own src_lib, we want to include it in SRC_LIBS +# so that the correct INCLUDES_* will be picked up automatically. +SRC_LIBS+= ${_OBJDIR}/lib${LIB}.a +.endif +.endif + +# +# This little bit of magic, assumes that SRC_libfoo will be +# set if it cannot be correctly derrived from ${LIBFOO} +# Note that SRC_libfoo and INCLUDES_libfoo should be named for the +# actual libary name not the variable name that might refer to it. +# 99% of the time the two are the same, but the DPADD logic +# only has the libary name available, so stick to that. +# + +SRC_LIBS?= +__dpadd_libs += ${SRC_LIBS} +DPMAGIC_LIBS += ${__dpadd_libs} \ + ${__dpadd_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@} + +.for __lib in ${DPMAGIC_LIBS:O:u} +# +# if SRC_libfoo is not set, then we assume that the srcdir corresponding +# to where we found the library is correct. +# +SRC_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELSRCTOP},} +# +# This is a no-brainer but just to be complete... +# +OBJ_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELOBJTOP},} +# +# If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists, +# else just ${SRC_libfoo}. +# +INCLUDES_${__lib:T:R}?= -I${exists(${SRC_${__lib:T:R}}/h):?${SRC_${__lib:T:R}}/h:${SRC_${__lib:T:R}}} + +.endfor + +# Now for the bits we actually need +__dpadd_incs= +.for __lib in ${__dpadd_libs:u} +.if (make(${PROG}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a) +__ldadd=-l${__lib:T:R:S,lib,,} +LDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g} +.endif + +# +# Some libs generate headers, so we potentially need both +# the src dir and the obj dir. +# If ${INCLUDES_libfoo} contains a word ending in /h, we assume that either +# 1. it does not generate headers or +# 2. INCLUDES_libfoo will have been set correctly +# XXX it gets ugly avoiding duplicates... +# use :? to ensure .for does not prevent correct evaluation +# +# We take care of duplicate suppression later. +__dpadd_incs += ${"${INCLUDES_${__lib:T:R}:M*/h}":? :-I${OBJ_${__lib:T:R}}} +__dpadd_incs += ${INCLUDES_${__lib:T:R}} +.endfor + +# +# eliminate any duplicates - but don't mess with the order +# force evaluation now - to avoid giving make a headache +# +.for t in CFLAGS CXXFLAGS +# avoid duplicates +__$t_incs:=${$t:M-I*:O:u} +.for i in ${__dpadd_incs} +.if "${__$t_incs:M$i}" == "" +$t+= $i +__$t_incs+= $i +.endif +.endfor +.endfor + +# This target is used to gather a list of +# dir: ${DPADD} +# entries +.if make(*dpadd*) +# allow overrides +.-include "dpadd++.mk" + +.if !target(dpadd) +dpadd: .NOTMAIN +.if defined(DPADD) && ${DPADD} != "" + @echo "${RELDIR}: ${DPADD:S,${OBJTOP}/,,}" +.endif +.endif +.endif + +.ifdef SRC_PATHADD +# We don't want to assume that we need to .PATH every element of +# SRC_LIBS, but the Makefile cannot do +# .PATH: ${SRC_libfoo} +# since the value of SRC_libfoo must be available at the time .PATH: +# is read - and we only just worked it out. +# Further, they can't wait until after include of {lib,prog}.mk as +# the .PATH is needed before then. +# So we let the Makefile do +# SRC_PATHADD+= ${SRC_libfoo} +# and we defer the .PATH: until now so that SRC_libfoo will be available. +.PATH: ${SRC_PATHADD} +.endif + +.endif diff --git a/contrib/bmake/mk/final.mk b/contrib/bmake/mk/final.mk new file mode 100644 index 0000000..5f41189 --- /dev/null +++ b/contrib/bmake/mk/final.mk @@ -0,0 +1,14 @@ +# $Id: final.mk,v 1.5 2011/03/11 05:22:38 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# provide a hook for folk who want to do scary stuff +.-include "${.CURDIR}/../Makefile-final.inc" + +.if !empty(STAGE) +.-include +.endif + +.-include +.endif diff --git a/contrib/bmake/mk/gendirdeps.mk b/contrib/bmake/mk/gendirdeps.mk new file mode 100644 index 0000000..20e2b15 --- /dev/null +++ b/contrib/bmake/mk/gendirdeps.mk @@ -0,0 +1,337 @@ +# $Id: gendirdeps.mk,v 1.23 2013/09/04 17:49:20 sjg Exp $ + +# Copyright (c) 2010-2013, Juniper Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# +# This makefile [re]generates ${.MAKE.DEPENDFILE} +# + +.include + +# Assumptions: +# RELDIR is the relative path from ${SRCTOP} to ${_CURDIR} +# (SRCTOP is ${SB}/src) +# _CURDIR is the absolute version of ${.CURDIR} +# _OBJDIR is the absolute version of ${.OBJDIR} +# _objroot is realpath of ${_OBJTOP} without ${MACHINE} +# this may be different from _OBJROOT if $SB/obj is a +# symlink to another filesystem. +# _objroot must be a prefix match for _objtop + +.MAIN: all + +# keep this simple +.MAKE.MODE = compat + +all: + +_CURDIR ?= ${.CURDIR} +_OBJDIR ?= ${.OBJDIR} +_OBJTOP ?= ${OBJTOP} +_OBJROOT ?= ${OBJROOT:U${_OBJTOP}} +.if ${_OBJROOT:M*/} +_slash=/ +.else +_slash= +.endif +_objroot ?= ${_OBJROOT:tA}${_slash} + +_this = ${.PARSEDIR}/${.PARSEFILE} + +# remember what to make +_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} + +# We do _not_ want to read our own output! +.MAKE.DEPENDFILE = /dev/null + +# caller should have set this +META_FILES ?= ${.MAKE.META.FILES} + +.if !empty(META_FILES) + +.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) +# so we can compare below +.-include <${_DEPENDFILE}> +# yes, I mean :U with no value +_DIRDEPS := ${DIRDEPS:U:O:u} +.endif + +META_FILES := ${META_FILES:T:O:u} +.export META_FILES + +# pickup customizations +.-include "local.gendirdeps.mk" + +# these are actually prefixes that we'll skip +# they should all be absolute paths +SKIP_GENDIRDEPS ?= +.if !empty(SKIP_GENDIRDEPS) +_skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | +.else +_skip_gendirdeps = +.endif + +# this (*should* be set in meta.sys.mk) +# is the script that extracts what we want. +META2DEPS ?= ${.PARSEDIR}/meta2deps.sh +META2DEPS := ${META2DEPS} + +.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != "" +_time = time +_sh_x = sh -x +_py_d = -ddd +.else +_time = +_sh_x = +_py_d = +.endif + +.if ${META2DEPS:E} == "py" +# we can afford to do this all the time. +DPDEPS ?= no +META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} +.if ${DPDEPS:tl} != "no" +META2DEPS_CMD += -D ${DPDEPS} +.endif +META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' | +.elif ${META2DEPS:E} == "sh" +META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP} +.else +META2DEPS_CMD ?= ${META2DEPS} +.endif + +.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE} +META2DEPS_CMD += -T ${TARGET_OBJ_SPEC} +.endif +META2DEPS_CMD += \ + -R ${RELDIR} -H ${HOST_TARGET} \ + ${M2D_OBJROOTS:O:u:@o@-O $o@} + + +M2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot} +.if defined(SB_OBJROOT) +M2D_OBJROOTS += ${SB_OBJROOT} +.endif +.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == "" +# meta2deps.py only groks objroot +# so we need to give it what it expects +# and tell it not to add machine qualifiers +META2DEPS_ARGS += MACHINE=none +.endif +.if defined(SB_BACKING_SB) +META2DEPS_CMD += -S ${SB_BACKING_SB}/src +M2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX} +.endif + +# we are only interested in the dirs +# sepecifically those we read something from. +# we canonicalize them to keep things simple +# if we are using a split-fs sandbox, it gets a little messier. +_objtop := ${_OBJTOP:tA} +dir_list != cd ${_OBJDIR} && \ + ${META2DEPS_CMD} MACHINE=${MACHINE} \ + SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \ + ${META2DEPS_ARGS} \ + ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ + sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,' + +.if ${dir_list:M*ERROR\:*} != "" +.warning ${dir_list:tW:C,.*(ERROR),\1,} +.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} +# we are not going to update anything +.else +dpadd_dir_list= +.if !empty(DPADD) +_nonlibs := ${DPADD:T:Nlib*:N*include} +.if !empty(_nonlibs) +ddep_list = +.for f in ${_nonlibs:@x@${DPADD:M*/$x}@} +.if exists($f.dirdep) +ddep_list += $f.dirdep +.elif exists(${f:H}.dirdep) +ddep_list += ${f:H}.dirdep +.else +dir_list += ${f:H:tA} +dpadd_dir_list += ${f:H:tA} +.endif +.endfor +.if !empty(ddep_list) +ddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ + sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,' + +.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.info ${RELDIR}: raw_dir_list='${dir_list}' +.info ${RELDIR}: ddeps='${ddeps}' +.endif +dir_list += ${ddeps} +.endif +.endif +.endif + +# DIRDEPS represent things that had to have been built first +# so they should all be undir OBJTOP. +# Note that ${_OBJTOP}/bsd/include/machine will get reported +# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we +# will want to visit bsd/include +# so we add +# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:} +# to GENDIRDEPS_DIR_LIST_XTRAS +_objtops = ${OBJTOP} ${_OBJTOP} ${_objtop} +_objtops := ${_objtops:O:u} +dirdep_list = \ + ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \ + ${GENDIRDEPS_DIR_LIST_XTRAS} + +# sort longest first +M2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]} + +# anything we use from an object dir other than ours +# needs to be qualified with its . suffix +# (we used the pseudo machine "host" for the HOST_TARGET). +skip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} +.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}} +# we need := so only skip_ql to this point applies +ql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,} +qualdir_list += ${ql.$o} +.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@} +.endif +skip_ql+= $o* +.endfor + +dirdep_list := ${dirdep_list:O:u} +qualdir_list := ${qualdir_list:N*.${MACHINE}:O:u} + +DIRDEPS = \ + ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \ + ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*} + +# We only consider things below $RELDIR/ if they have a makefile. +# This is the same test that _DIRDEPS_USE applies. +# We have do a double test with dirdep_list as it _may_ contain +# qualified dirs - if we got anything from a stage dir. +# qualdir_list we know are all qualified. +# It would be nice do peform this check for all of DIRDEPS, +# but we cannot assume that all of the tree is present, +# in fact we can only assume that RELDIR is. +DIRDEPS += \ + ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \ + ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@} + +DIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:O:u} + +.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" +.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS} +.info ${RELDIR}: dir_list='${dir_list}' +.info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}' +.info ${RELDIR}: dirdep_list='${dirdep_list}' +.info ${RELDIR}: qualdir_list='${qualdir_list}' +.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}' +.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}' +.info ${RELDIR}: FORCE_DPADD='${DPADD}' +.info ${RELDIR}: DIRDEPS='${DIRDEPS}' +.endif + +# SRC_DIRDEPS is for checkout logic +src_dirdep_list = \ + ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,} + +SRC_DIRDEPS = \ + ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,} + +SRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:O:u} + +# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put +# SRC_DIRDEPS_FILE = ${_DEPENDFILE} +# in local.gendirdeps.mk +.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no" +ECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo; + +.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T} +_include_src_dirdeps = ${ECHO_SRC_DIRDEPS} +.else +all: ${SRC_DIRDEPS_FILE} +.if !target(${SRC_DIRDEPS_FILE}) +${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS} + @(${ECHO_SRC_DIRDEPS}) > $@ +.endif +.endif +.endif +_include_src_dirdeps ?= + +all: ${_DEPENDFILE} + +# if this is going to exist it would be there by now +.if !exists(.depend) +CAT_DEPEND = /dev/null +.endif +CAT_DEPEND ?= .depend + +.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS} +# we may have changed a filter +.PHONY: ${_DEPENDFILE} +.endif + +# 'cat .depend' should suffice, but if we are mixing build modes +# .depend may contain things we don't want. +# The sed command at the end of the stream, allows for the filters +# to output _{VAR} tokens which we will turn into proper ${VAR} references. +${_DEPENDFILE}: ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS} + @(echo '# Autogenerated - do NOT edit!'; echo; \ + echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \ + echo 'DIRDEPS = \'; \ + echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ + ${_include_src_dirdeps} \ + echo '.include '; \ + echo; \ + echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \ + echo '# local dependencies - needed for -jN in clean tree'; \ + [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ + echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} + @${InstallNew}; InstallNew -s $@.new${.MAKE.PID} + +.endif # meta2deps failed +.elif !empty(SUBDIR) + +DIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u} + +all: ${_DEPENDFILE} + +${_DEPENDFILE}: ${MAKEFILE} ${_this} + @(echo '# Autogenerated - do NOT edit!'; echo; \ + echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \ + echo 'DIRDEPS = \'; \ + echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ + echo '.include '; \ + echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new + @${InstallNew}; InstallNew $@.new + +.else + +# nothing to do +all ${_DEPENDFILE}: + +.endif +${_DEPENDFILE}: .PRECIOUS diff --git a/contrib/bmake/mk/host-target.mk b/contrib/bmake/mk/host-target.mk new file mode 100644 index 0000000..c6d4562 --- /dev/null +++ b/contrib/bmake/mk/host-target.mk @@ -0,0 +1,31 @@ +# RCSid: +# $Id: host-target.mk,v 1.6 2011/03/02 05:05:21 sjg Exp $ + +# Host platform information; may be overridden +.if !defined(_HOST_OSNAME) +_HOST_OSNAME != uname -s +.export _HOST_OSNAME +.endif +.if !defined(_HOST_OSREL) +_HOST_OSREL != uname -r +.export _HOST_OSREL +.endif +.if !defined(_HOST_ARCH) +_HOST_ARCH != uname -p 2>/dev/null || uname -m +# uname -p may produce garbage on linux +.if ${_HOST_ARCH:[\#]} > 1 +_HOST_ARCH != uname -m +.endif +.export _HOST_ARCH +.endif + +HOST_OSMAJOR := ${_HOST_OSREL:C/[^0-9].*//} +HOST_OSTYPE := ${_HOST_OSNAME}-${_HOST_OSREL:C/\([^\)]*\)//}-${_HOST_ARCH} +HOST_OS := ${_HOST_OSNAME} +host_os := ${_HOST_OSNAME:tl} +HOST_TARGET := ${host_os}${HOST_OSMAJOR}-${_HOST_ARCH} + +# tr is insanely non-portable, accommodate the lowest common denominator +TR ?= tr +toLower = ${TR} 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' +toUpper = ${TR} 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' diff --git a/contrib/bmake/mk/host.libnames.mk b/contrib/bmake/mk/host.libnames.mk new file mode 100644 index 0000000..c0a13d7 --- /dev/null +++ b/contrib/bmake/mk/host.libnames.mk @@ -0,0 +1,29 @@ +# $Id: host.libnames.mk,v 1.4 2010/01/11 23:01:31 sjg Exp $ +# +# @(#) Copyright (c) 2007-2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + + +DLIBEXT ?= .a +DSHLIBEXT ?= ${DLIBEXT} +HOST_LIBEXT ?= ${DSHLIBEXT} +HOST_LIBDIRS ?= /usr/lib /lib +HOST_LIBS ?= + +.for x in ${HOST_LIBS:O:u} +.for d in ${HOST_LIBDIRS} +.if exists($d/lib$x${HOST_LIBEXT}) +LIB${x:tu} ?= $d/lib$x${HOST_LIBEXT} +.endif +.endfor +.endfor diff --git a/contrib/bmake/mk/inc.mk b/contrib/bmake/mk/inc.mk new file mode 100644 index 0000000..5d57f52 --- /dev/null +++ b/contrib/bmake/mk/inc.mk @@ -0,0 +1,35 @@ +# $Id: inc.mk,v 1.3 2011/03/11 05:23:05 sjg Exp $ +# +# @(#) Copyright (c) 2008, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.include + +includes: ${INCS} + +.if !empty(LIBOWN) +INC_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP} +.endif +INCMODE ?= 444 +INC_COPY ?= -C +INCSDIR ?= ${INCDIR} + +realinstall: incinstall +.if !target(incinstall) +incinstall: +.if !empty(INCS) + [ -d ${DESTDIR}${INCSDIR} ] || \ + ${INSTALL} -d ${INC_INSTALL_OWN} -m 775 ${DESTDIR}${INCSDIR} + ${INSTALL} ${INC_COPY} ${INC_INSTALL_OWN} -m ${INCMODE} ${INCS} ${DESTDIR}${INCSDIR} +.endif +.endif diff --git a/contrib/bmake/mk/init.mk b/contrib/bmake/mk/init.mk new file mode 100644 index 0000000..e700370 --- /dev/null +++ b/contrib/bmake/mk/init.mk @@ -0,0 +1,50 @@ +# $Id: init.mk,v 1.9 2013/07/18 05:46:24 sjg Exp $ +# +# @(#) Copyright (c) 2002, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.if ${MAKE_VERSION:U0} > 20100408 +_this_mk_dir := ${.PARSEDIR:tA} +.else +_this_mk_dir := ${.PARSEDIR} +.endif + +.-include +.-include "${.CURDIR:H}/Makefile.inc" +.include + +.MAIN: all + +.if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH}) +.include +.endif + +COPTS += ${COPTS.${.IMPSRC:T}} +CPPFLAGS += ${CPPFLAGS.${.IMPSRC:T}} +CPUFLAGS += ${CPUFLAGS.${.IMPSRC:T}} + +CC_PG?= -pg +CXX_PG?= ${CC_PG} +CC_PIC?= -DPIC +CXX_PIC?= ${CC_PIC} +PROFFLAGS?= -DGPROF -DPROF + +.if ${.MAKE.LEVEL:U1} == 0 && ${BUILD_AT_LEVEL0:Uyes:tl} == "no" +# this tells lib.mk and prog.mk to not actually build anything +_SKIP_BUILD = not building at level 0 +.endif + +.endif diff --git a/contrib/bmake/mk/install-mk b/contrib/bmake/mk/install-mk new file mode 100644 index 0000000..0640906 --- /dev/null +++ b/contrib/bmake/mk/install-mk @@ -0,0 +1,185 @@ +: +# NAME: +# install-mk - install mk files +# +# SYNOPSIS: +# install-mk [options] [var=val] [dest] +# +# DESCRIPTION: +# This tool installs mk files in a semi-intelligent manner into +# "dest". +# +# Options: +# +# -n just say what we want to do, but don't touch anything. +# +# -f use -f when copying sys,mk. +# +# -v be verbose +# +# -q be quiet +# +# -m "mode" +# Use "mode" for installed files (444). +# +# -o "owner" +# Use "owner" for installed files. +# +# -g "group" +# Use "group" for installed files. +# +# var=val +# Set "var" to "val". See below. +# +# All our *.mk files are copied to "dest" with appropriate +# ownership and permissions. +# +# By default if a sys.mk can be found in a standard location +# (that bmake will find) then no sys.mk will be put in "dest". +# +# SKIP_SYS_MK: +# If set, we will avoid installing our 'sys.mk' +# This is probably a bad idea. +# +# SKIP_BSD_MK: +# If set, we will skip making bsd.*.mk links to *.mk +# +# sys.mk: +# +# By default (and provided we are not installing to the system +# mk dir - '/usr/share/mk') we install our own 'sys.mk' which +# includes a sys specific file, or a generic one. +# +# +# AUTHOR: +# Simon J. Gerraty + +# RCSid: +# $Id: install-mk,v 1.93 2013/08/02 18:28:47 sjg Exp $ +# +# @(#) Copyright (c) 1994 Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +MK_VERSION=20130801 +OWNER= +GROUP= +MODE=444 +BINMODE=555 +ECHO=: +SKIP= +cp_f=-f + +while : +do + case "$1" in + *=*) eval "$1"; shift;; + +f) cp_f=; shift;; + -f) cp_f=-f; shift;; + -m) MODE=$2; shift 2;; + -o) OWNER=$2; shift 2;; + -g) GROUP=$2; shift 2;; + -v) ECHO=echo; shift;; + -q) ECHO=:; shift;; + -n) ECHO=echo SKIP=:; shift;; + --) shift; break;; + *) break;; + esac +done + +case $# in +0) echo "$0 [options] []" + echo "eg." + echo "$0 -o bin -g bin -m 444 /usr/local/share/mk" + exit 1 + ;; +esac +dest=$1 +os=${2:-`uname`} +osrel=${3:-`uname -r`} + +Do() { + $ECHO "$@" + $SKIP "$@" +} + +Error() { + echo "ERROR: $@" >&2 + exit 1 +} + +Warning() { + echo "WARNING: $@" >&2 +} + +[ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)" + +SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk} +SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk} + +realpath() { + [ -d $1 ] && cd $1 && 'pwd' && return + echo $1 +} + +if [ -s $SYS_MK -a -d $dest ]; then + # if this is a BSD system we don't want to touch $SYS_MK + dest=`realpath $dest` + sys_mk_dir=`realpath $SYS_MK_DIR` + if [ $dest = $sys_mk_dir ]; then + case "$os" in + *BSD*) SKIP_SYS_MK=: + SKIP_BSD_MK=: + ;; + *) # could be fake? + if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then + SKIP_SYS_MK=: # play safe + SKIP_BSD_MK=: + fi + ;; + esac + fi +fi + +[ -d $dest/sys ] || Do mkdir -p $dest/sys +[ -d $dest/sys ] || Do mkdir $dest/sys || exit 1 +[ -z "$SKIP" ] && dest=`realpath $dest` + +cd `dirname $0` +mksrc=`'pwd'` +if [ $mksrc = $dest ]; then + SKIP_MKFILES=: +else + # we do not install the examples + mk_files=`grep '^[a-z].*\.mk' FILES | egrep -v '(examples/|^sys\.mk|sys/)'` + mk_scripts=`egrep '^[a-z].*\.(sh|py)' FILES | egrep -v '/'` + sys_mk_files=`grep 'sys/.*\.mk' FILES` + SKIP_MKFILES= + [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" +fi +$SKIP_MKFILES Do cp $cp_f $mk_files $dest +$SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys +$SKIP_MKFILES Do cp $cp_f $mk_scripts $dest +$SKIP cd $dest +$SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files +$SKIP_MKFILES Do chmod $BINMODE $mk_scripts +[ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files +[ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files +# if this is a BSD system the bsd.*.mk should exist and be used. +if [ -z "$SKIP_BSD_MK" ]; then + for f in dep doc init lib links man nls obj own prog subdir + do + b=bsd.$f.mk + [ -s $b ] || Do ln -s $f.mk $b + done +fi +exit 0 diff --git a/contrib/bmake/mk/install-new.mk b/contrib/bmake/mk/install-new.mk new file mode 100644 index 0000000..ddfff20 --- /dev/null +++ b/contrib/bmake/mk/install-new.mk @@ -0,0 +1,53 @@ +# $Id: install-new.mk,v 1.3 2012/03/24 18:25:49 sjg Exp $ +# +# @(#) Copyright (c) 2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !defined(InstallNew) + +# copy if src and target are different making a backup if desired +CmpCp= CmpCp() { \ + src=$$1 target=$$2 _bak=$$3; \ + if ! test -s $$target || ! cmp -s $$target $$src; then \ + trap "" 1 2 3 15; \ + if test -s $$target; then \ + if test "x$$_bak" != x; then \ + rm -f $$target$$_bak; \ + mv $$target $$target$$_bak; \ + else \ + rm -f $$target; \ + fi; \ + fi; \ + cp $$src $$target; \ + fi; } + +# If the .new file is different, we want it. +# Note: this function will work as is for *.new$RANDOM" +InstallNew= ${CmpCp}; InstallNew() { \ + _t=-e; _bak=; \ + while :; do \ + case "$$1" in \ + -?) _t=$$1; shift;; \ + --bak) _bak=$$2; shift 2;; \ + *) break;; \ + esac; \ + done; \ + for new in "$$@"; do \ + if test $$_t $$new; then \ + target=`expr $$new : '\(.*\).new'`; \ + CmpCp $$new $$target $$_bak; \ + fi; \ + rm -f $$new; \ + done; :; } + +.endif diff --git a/contrib/bmake/mk/java.mk b/contrib/bmake/mk/java.mk new file mode 100644 index 0000000..ef4a5ea --- /dev/null +++ b/contrib/bmake/mk/java.mk @@ -0,0 +1,97 @@ +# +# RCSid: +# $Id: java.mk,v 1.14 2007/11/22 08:16:25 sjg Exp $ + +# @(#) Copyright (c) 1998-2001, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.include + +CLASSPATH?=. + +.if defined(PROG) +SRCS?= ${PROG:.class=.java} +.endif +.if !defined(SRCS) || empty(SRCS) +SRCS!=cd ${.CURDIR} && echo *.java +.endif +.SUFFIXES: .class .java + +CLEANFILES+= *.class + +JAVAC?= javac +JAVADOC?= javadoc + +.if !target(docs) +docs: + ${JAVADOC} ${JAVADOC_FLAGS} ${SRCS} +.endif + +.if defined(JAVADESTDIR) && !empty(JAVADESTDIR) +JAVASRCDIR?=${JAVADESTDIR:H}/src +__classdest:=${JAVADESTDIR}${.CURDIR:S,${JAVASRCDIR},,}/ +CLASSPATH:=${CLASSPATH}:${JAVADESTDIR} +JAVAC_FLAGS+= -d ${JAVADESTDIR} +.else +__classdest= +.endif + +JAVAC_FLAGS+= ${JAVAC_DBG} + +.if defined(MAKE_VERSION) && !defined(NO_CLASSES_COOKIE) +# java works best by compiling a bunch of classes at once. +# this lot does that but needs a recent netbsd make or +# or its portable cousin bmake. +.for __s in ${SRCS} +__c:= ${__classdest}${__s:.java=.class} +.if !target(${__c}) +# We need to do something to force __c's parent to be made. +${__c}: ${__s} + @rm -f ${.TARGET} +.endif +SRCS_${__c}=${__s} +__classes:= ${__classes} ${__c} +.endfor +__classes_cookie=${__classdest}.classes.done +CLEANFILES+= ${__classes} ${__classes_cookie} + +${__classes_cookie}: ${__classes} + CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE:@c@${SRCS_$c}@} + @touch ${.TARGET} + +all: ${__classes_cookie} + +.else +# this will work with other BSD make's +.for __s in ${SRCS} +__c:= ${__classdest}${__s:.java=.class} +${__c}: ${__s} + CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE} +.endfor + +all: ${SRCS:%.java=${__classdest}%.class} + +.endif + +.if !target(cleanjava) +cleanjava: + rm -f [Ee]rrs mklog core *.core ${PROG} ${CLEANFILES} + +clean: cleanjava +cleandir: cleanjava +.endif + +.endif diff --git a/contrib/bmake/mk/lib.mk b/contrib/bmake/mk/lib.mk new file mode 100644 index 0000000..f219115 --- /dev/null +++ b/contrib/bmake/mk/lib.mk @@ -0,0 +1,602 @@ +# $Id: lib.mk,v 1.49 2013/07/18 05:46:24 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.include + +.if ${OBJECT_FMT} == "ELF" +NEED_SOLINKS?= yes +.endif + +.if exists(${.CURDIR}/shlib_version) +SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major +SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor +.endif + +print-shlib-major: +.if defined(SHLIB_MAJOR) && ${MK_PIC} != "no" + @echo ${SHLIB_MAJOR} +.else + @false +.endif + +print-shlib-minor: +.if defined(SHLIB_MINOR) && ${MK_PIC} != "no" + @echo ${SHLIB_MINOR} +.else + @false +.endif + +print-shlib-teeny: +.if defined(SHLIB_TEENY) && ${MK_PIC} != "no" + @echo ${SHLIB_TEENY} +.else + @false +.endif + +SHLIB_FULLVERSION ?= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L:ts.} +SHLIB_FULLVERSION := ${SHLIB_FULLVERSION} + +# add additional suffixes not exported. +# .po is used for profiling object files. +# .so is used for PIC object files. +.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 .m + +CFLAGS+= ${COPTS} + +# Derrived from NetBSD-1.6 + +# Set PICFLAGS to cc flags for producing position-independent code, +# if not already set. Includes -DPIC, if required. + +# Data-driven table using make variables to control how shared libraries +# are built for different platforms and object formats. +# OBJECT_FMT: currently either "ELF" or "a.out", from +# SHLIB_SOVERSION: version number to be compiled into a shared library +# via -soname. Usualy ${SHLIB_MAJOR} on ELF. +# NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR} +# [.${SHLIB_TEENY}]] +# SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library. +# with ELF, also set shared-lib version for ld.so. +# SHLIB_LDSTARTFILE: support .o file, call C++ file-level constructors +# SHLIB_LDENDFILE: support .o file, call C++ file-level destructors +# FPICFLAGS: flags for ${FC} to compile .[fF] files to .so objects. +# CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS} +# CPICFLAGS: flags for ${CC} to compile .[cC] files to .so objects. +# CAPICFLAGS flags for {$CC} to compiling .[Ss] files +# (usually just ${CPPPICFLAGS} ${CPICFLAGS}) +# APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects. + +.if ${TARGET_OSNAME} == "NetBSD" +.if ${MACHINE_ARCH} == "alpha" + # Alpha-specific shared library flags +FPICFLAGS ?= -fPIC +CPICFLAGS ?= -fPIC -DPIC +CPPPICFLAGS?= -DPIC +CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS} +APICFLAGS ?= +.elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb" + # mips-specific shared library flags + +# On mips, all libs are compiled with ABIcalls, not just sharedlibs. +MKPICLIB= no + +# so turn shlib PIC flags on for ${AS}. +AINC+=-DABICALLS +AFLAGS+= -fPIC +AS+= -KPIC + +.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF" +# On the VAX, all object are PIC by default, not just sharedlibs. +MKPICLIB= no + +.elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \ + ${OBJECT_FMT} == "ELF" +# If you use -fPIC you need to define BIGPIC to turn on 32-bit +# relocations in asm code +FPICFLAGS ?= -fPIC +CPICFLAGS ?= -fPIC -DPIC +CPPPICFLAGS?= -DPIC -DBIGPIC +CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS} +APICFLAGS ?= -KPIC + +.else + +# Platform-independent flags for NetBSD a.out shared libraries +SHLIB_SOVERSION=${SHLIB_FULLVERSION} +SHLIB_SHFLAGS= +FPICFLAGS ?= -fPIC +CPICFLAGS?= -fPIC -DPIC +CPPPICFLAGS?= -DPIC +CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS} +APICFLAGS?= -k + +.endif + +# Platform-independent linker flags for ELF shared libraries +.if ${OBJECT_FMT} == "ELF" +SHLIB_SOVERSION= ${SHLIB_MAJOR} +SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION} +SHLIB_LDSTARTFILE?= /usr/lib/crtbeginS.o +SHLIB_LDENDFILE?= /usr/lib/crtendS.o +.endif + +# for compatability with the following +CC_PIC?= ${CPICFLAGS} +LD_shared=${SHLIB_SHFLAGS} + +.endif # NetBSD + +.if ${TARGET_OSNAME} == "FreeBSD" +.if ${OBJECT_FMT} == "ELF" +SHLIB_SOVERSION= ${SHLIB_MAJOR} +SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION} +.else +SHLIB_SHFLAGS= -assert pure-text +.endif +SHLIB_LDSTARTFILE= +SHLIB_LDENDFILE= +CC_PIC?= -fpic +LD_shared=${SHLIB_SHFLAGS} + +.endif # FreeBSD + +MKPICLIB?= yes + +# sys.mk can override these +LD_X?=-X +LD_x?=-x +LD_r?=-r + +# Non BSD machines will be using bmake. +.if ${TARGET_OSNAME} == "SunOS" +LD_shared=-assert pure-text +.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris" +# Solaris +LD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G +.endif +.elif ${TARGET_OSNAME} == "HP-UX" +LD_shared=-b +LD_so=sl +DLLIB= +# HPsUX lorder does not grok anything but .o +LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'` +LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'` +.elif ${TARGET_OSNAME} == "OSF1" +LD_shared= -msym -shared -expect_unresolved '*' +LD_solib= -all lib${LIB}_pic.a +DLLIB= +# lorder does not grok anything but .o +LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'` +LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'` +AR_cq= -cqs +.elif ${TARGET_OSNAME} == "FreeBSD" +LD_solib= lib${LIB}_pic.a +.elif ${TARGET_OSNAME} == "Linux" +# this is ambiguous of course +LD_shared=-shared -h lib${LIB}.so.${SHLIB_MAJOR} +LD_solib= --whole-archive lib${LIB}_pic.a +# Linux uses GNU ld, which is a multi-pass linker +# so we don't need to use lorder or tsort +LD_objs = ${OBJS} +LD_pobjs = ${POBJS} +LD_sobjs = ${SOBJS} +.elif ${TARGET_OSNAME} == "Darwin" +SHLIB_LD = ${CC} +SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR} +SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0} +SHLIB_COMPATABILITY ?= \ + -compatibility_version ${SHLIB_COMPATABILITY_VERSION} \ + -current_version ${SHLIB_FULLVERSION} +LD_shared = -dynamiclib \ + -flat_namespace -undefined suppress \ + -install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \ + ${SHLIB_COMPATABILITY} +SHLIB_LINKS = +.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION} +.if "$v" != "${SHLIB_FULLVERSION}" +SHLIB_LINKS += lib${LIB}.$v.${LD_solink} +.endif +.endfor +.if ${MK_LINKLIB} != "no" +SHLIB_LINKS += lib${LIB}.${LD_solink} +.endif + +LD_so = ${SHLIB_FULLVERSION}.dylib +LD_sobjs = ${SOBJS:O:u} +LD_solib = ${LD_sobjs} +SOLIB = ${LD_sobjs} +LD_solink = dylib +.if ${MACHINE_ARCH} == "i386" +PICFLAG ?= -fPIC +.else +PICFLAG ?= -fPIC -fno-common +.endif +RANLIB = : +.endif + +SHLIB_LD ?= ${LD} + +.if !empty(SHLIB_MAJOR) +.if ${NEED_SOLINKS} && empty(SHLIB_LINKS) +.if ${MK_LINKLIB} != "no" +SHLIB_LINKS = lib${LIB}.${LD_solink} +.endif +.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}" +SHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR} +.endif +.endif +.endif + +LIBTOOL?=libtool +LD_shared ?= -Bshareable -Bforcearchive +LD_so ?= so.${SHLIB_FULLVERSION} +LD_solink ?= so +.if empty(LORDER) +LD_objs ?= ${OBJS} +LD_pobjs ?= ${POBJS} +LD_sobjs ?= ${SOBJS} +.else +LD_objs ?= `${LORDER} ${OBJS} | ${TSORT}` +LD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}` +LD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}` +.endif +LD_solib ?= ${LD_sobjs} +AR_cq ?= cq +.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so) +DLLIB ?= -ldl +.endif + +# some libs have lots of objects, and scanning all .o, .po and .So meta files +# is a waste of time, this tells meta.autodep.mk to just pick one +# (typically .So) +# yes, 42 is a random number. +.if ${MK_META_MODE} == "yes" && ${SRCS:Uno:[\#]} > 42 +OPTIMIZE_OBJECT_META_FILES ?= yes +.endif + + +.if ${MK_LIBTOOL} == "yes" +# because libtool is so facist about naming the object files, +# we cannot (yet) build profiled libs +MK_PROFILE=no +_LIBS=lib${LIB}.a +.if exists(${.CURDIR}/shlib_version) +SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age +.endif +.else +# for the normal .a we do not want to strip symbols +.c.o: + ${COMPILE.c} ${.IMPSRC} + +# for the normal .a we do not want to strip symbols +.cc.o .C.o: + ${COMPILE.cc} ${.IMPSRC} + +.S.o .s.o: + @echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} + @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} + +.if (${LD_X} == "") +.c.po: + ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET} + +.cc.po .C.po: + ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET} + +.S.so .s.so: + ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} +.else +.c.po: + @echo ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +.cc.po .C.po: + @echo ${COMPILE.cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +.S.so .s.so: + @echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o +.endif + +.if (${LD_x} == "") +.c.so: + ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET} + +.cc.so .C.so: + ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET} + +.S.po .s.po: + ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} +.else + +.c.so: + @echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +.cc.so .C.so: + @echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +.S.po .s.po: + @echo ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET} + @${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o + @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +.endif +.endif + +.c.ln: + ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC} + +.if ${MK_LIBTOOL} != "yes" + +.if !defined(PICFLAG) +PICFLAG=-fpic +.endif + +_LIBS= + +.if ${MK_ARCHIVE} != "no" +_LIBS += lib${LIB}.a +.endif + +.if ${MK_PROFILE} != "no" +_LIBS+=lib${LIB}_p.a +POBJS+=${OBJS:.o=.po} +.endif + +.if ${MK_PIC} != "no" +.if ${MK_PICLIB} == "no" +SOLIB ?= lib${LIB}.a +.else +SOLIB=lib${LIB}_pic.a +_LIBS+=${SOLIB} +.endif +.if !empty(SHLIB_FULLVERSION) +_LIBS+=lib${LIB}.${LD_so} +.endif +.endif + +.if ${MK_LINT} != "no" +_LIBS+=llib-l${LIB}.ln +.endif + +# here is where you can define what LIB* are +.-include +.if ${MK_DPADD_MK} == "yes" +# lots of cool magic, but might not suit everyone. +.include +.endif + +.if !defined(_SKIP_BUILD) +all: prebuild .WAIT ${_LIBS} +# a hook for things that must be done early +prebuild: +.if !defined(.PARSEDIR) +# no-op is the best we can do if not bmake. +.WAIT: +.endif +.endif +all: _SUBDIRUSE + +.for s in ${SRCS:N*.h:M*/*} +${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s +.endfor + +OBJS+= ${SRCS:T:N*.h:R:S/$/.o/g} +.NOPATH: ${OBJS} + +.if ${MK_LIBTOOL} == "yes" +.if ${MK_PIC} == "no" +LT_STATIC=-static +.else +LT_STATIC= +.endif +SHLIB_AGE?=0 + +# .lo's are created as a side effect +.s.o .S.o .c.o: + ${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC} + +# can't really do profiled libs with libtool - its too facist about +# naming the output... +lib${LIB}.a:: ${OBJS} + @rm -f ${.TARGET} + ${LIBTOOL} --mode=link ${CC} ${LT_STATIC} -o ${.TARGET:.a=.la} ${OBJS:.o=.lo} -rpath ${SHLIBDIR}:/usr/lib -version-info ${SHLIB_MAJOR}:${SHLIB_MINOR}:${SHLIB_AGE} + @ln .libs/${.TARGET} . + +lib${LIB}.${LD_so}:: lib${LIB}.a + @[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : } + @[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET} + +.else # MK_LIBTOOL=yes + +lib${LIB}.a:: ${OBJS} + @echo building standard ${LIB} library + @rm -f ${.TARGET} + @${AR} ${AR_cq} ${.TARGET} ${LD_objs} + ${RANLIB} ${.TARGET} + +POBJS+= ${OBJS:.o=.po} +.NOPATH: ${POBJS} +lib${LIB}_p.a:: ${POBJS} + @echo building profiled ${LIB} library + @rm -f ${.TARGET} + @${AR} ${AR_cq} ${.TARGET} ${LD_pobjs} + ${RANLIB} ${.TARGET} + +SOBJS+= ${OBJS:.o=.so} +.NOPATH: ${SOBJS} +lib${LIB}_pic.a:: ${SOBJS} + @echo building shared object ${LIB} library + @rm -f ${.TARGET} + @${AR} ${AR_cq} ${.TARGET} ${LD_sobjs} + ${RANLIB} ${.TARGET} + +#SHLIB_LDADD?= ${LDADD} + +# bound to be non-portable... +# this is known to work for NetBSD 1.6 and FreeBSD 4.2 +lib${LIB}.${LD_so}: ${SOLIB} ${DPADD} + @echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\) + @rm -f ${.TARGET} +.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" +.if ${OBJECT_FMT} == "ELF" + ${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \ + ${SHLIB_LDSTARTFILE} \ + --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \ + ${SHLIB_LDENDFILE} +.else + ${SHLIB_LD} ${LD_x} ${LD_shared} \ + -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD} +.endif +.else + ${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD} +.endif +.endif +.if !empty(SHLIB_LINKS) + rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@} +.endif + +LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} +.NOPATH: ${LOBJS} +LLIBS?= -lc +llib-l${LIB}.ln: ${LOBJS} + @echo building llib-l${LIB}.ln + @rm -f llib-l${LIB}.ln + @${LINT} -C${LIB} ${LOBJS} ${LLIBS} + +.if !target(clean) +cleanlib: .PHONY + rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES} + rm -f lib${LIB}.a ${OBJS} + rm -f lib${LIB}_p.a ${POBJS} + rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS} + rm -f llib-l${LIB}.ln ${LOBJS} +.if !empty(SHLIB_LINKS) + rm -f ${SHLIB_LINKS} +.endif + +clean: _SUBDIRUSE cleanlib +cleandir: _SUBDIRUSE cleanlib +.else +cleandir: _SUBDIRUSE clean +.endif + +.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) +.endif + +.if !target(install) +.if !target(beforeinstall) +beforeinstall: +.endif + +.if !empty(LIBOWN) +LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP} +.endif + +.include + +.if !target(realinstall) +realinstall: libinstall +.endif +.if !target(libinstall) +libinstall: + [ -d ${DESTDIR}/${LIBDIR} ] || \ + ${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR} +.if ${MK_ARCHIVE} != "no" + ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \ + ${DESTDIR}${LIBDIR} + ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a + chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a +.endif +.if ${MK_PROFILE} != "no" + ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \ + lib${LIB}_p.a ${DESTDIR}${LIBDIR} + ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a + chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a +.endif +.if ${MK_PIC} != "no" +.if ${MK_PICLIB} != "no" + ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \ + lib${LIB}_pic.a ${DESTDIR}${LIBDIR} + ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a + chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a +.endif +.if !empty(SHLIB_MAJOR) + ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \ + lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR} +.if !empty(SHLIB_LINKS) + (cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} }) +.endif +.endif +.endif +.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS) + ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \ + llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR} +.endif +.if defined(LINKS) && !empty(LINKS) + @set ${LINKS}; ${_LINKS_SCRIPT} +.endif +.endif + +install: maninstall _SUBDIRUSE +maninstall: afterinstall +afterinstall: realinstall +realinstall: beforeinstall +.endif + +.if ${MK_MAN} != "no" +.include +.endif + +.if ${MK_NLS} != "no" +.include +.endif + +.include +.include +.include +.include +.endif + +# during building we usually need/want to install libs somewhere central +# note that we do NOT ch{own,grp} as that would likely fail at this point. +# otherwise it is the same as realinstall +# Note that we don't need this when using dpadd.mk +.libinstall: ${_LIBS} + test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR} +.for _lib in ${_LIBS:M*.a} + ${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR} + ${RANLIB} ${DESTDIR}${LIBDIR}/${_lib} +.endfor +.for _lib in ${_LIBS:M*.${LD_solink}*:O:u} + ${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR} +.if !empty(SHLIB_LINKS) + (cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; }) +.endif +.endfor + @touch ${.TARGET} + +.include +.endif diff --git a/contrib/bmake/mk/libnames.mk b/contrib/bmake/mk/libnames.mk new file mode 100644 index 0000000..60e12eb --- /dev/null +++ b/contrib/bmake/mk/libnames.mk @@ -0,0 +1,22 @@ +# $Id: libnames.mk,v 1.7 2009/12/25 07:34:03 sjg Exp $ +# +# @(#) Copyright (c) 2007-2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +DLIBEXT ?= .a +DSHLIBEXT ?= .so + +.-include "local.libnames.mk" +.-include "sjg.libnames.mk" +.-include "fwall.libnames.mk" +.-include "host.libnames.mk" diff --git a/contrib/bmake/mk/libs.mk b/contrib/bmake/mk/libs.mk new file mode 100644 index 0000000..7f974bfa --- /dev/null +++ b/contrib/bmake/mk/libs.mk @@ -0,0 +1,93 @@ +# $Id: libs.mk,v 1.3 2013/08/02 18:28:48 sjg Exp $ +# +# @(#) Copyright (c) 2006, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.MAIN: all + +.if defined(LIBS) + +# In meta mode, we can capture dependenices for _one_ of the progs. +# if makefile doesn't nominate one, we use the first. +.ifndef UPDATE_DEPENDFILE_LIB +UPDATE_DEPENDFILE_LIB = ${LIBS:[1]} +.export UPDATE_DEPENDFILE_LIB +.endif + +.ifndef LIB +# They may have asked us to build just one +.for t in ${LIBS:R:T:S,^lib,,} +.if make(lib$t) +LIB?= $t +lib$t: all +.endif +.endfor +.endif + +.if defined(LIB) +# just one of many +LIB_VARS += \ + LIBDIR \ + CFLAGS \ + COPTS \ + CPPFLAGS \ + CXXFLAGS \ + DPADD \ + DPLIBS \ + LDADD \ + LDFLAGS \ + MAN \ + SRCS + +.for v in ${LIB_VARS:O:u} +.if defined(${v}.${LIB}) || defined(${v}_${LIB}) +$v += ${${v}_${LIB}:U${${v}.${LIB}}} +.endif +.endfor + +# for meta mode, there can be only one! +.if ${LIB} == ${UPDATE_DEPENDFILE_LIB:Uno} +UPDATE_DEPENDFILE ?= yes +.endif +UPDATE_DEPENDFILE ?= NO + +# ensure that we don't clobber each other's dependencies +DEPENDFILE?= .depend.${LIB} +# lib.mk will do the rest +.else +all: ${LIBS:S,^lib,,:@t@lib$t.a@} .MAKE + +# We cannot capture dependencies for meta mode here +UPDATE_DEPENDFILE = NO +# nor can we safely run in parallel. +.NOTPARALLEL: +.endif +.endif + +# handle being called [bsd.]libs.mk +.include <${.PARSEFILE:S,libs,lib,}> + +.ifndef LIB +# tell libs.mk we might want to install things +LIBS_TARGETS+= cleandepend cleandir cleanobj depend install + +.for b in ${LIBS:R:T:S,^lib,,} +lib$b.a: ${SRCS} ${DPADD} ${SRCS_lib$b} ${DPADD_lib$b} + (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b) + +.for t in ${LIBS_TARGETS:O:u} +$b.$t: .PHONY .MAKE + (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$b ${@:E}) +.endfor +.endfor +.endif diff --git a/contrib/bmake/mk/links.mk b/contrib/bmake/mk/links.mk new file mode 100644 index 0000000..4ec8a01 --- /dev/null +++ b/contrib/bmake/mk/links.mk @@ -0,0 +1,75 @@ +# $Id: links.mk,v 1.5 2005/07/11 18:01:05 sjg Exp $ +# +# @(#) Copyright (c) 2005, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# some platforms need something special +LN?= ln +ECHO?= echo + +LINKS?= +SYMLINKS?= + +__SYMLINK_SCRIPT= \ + ${ECHO} "$$t -> $$l"; \ + mkdir -p `dirname $$t`; \ + rm -f $$t; \ + ${LN} -s $$l $$t + +__LINK_SCRIPT= \ + ${ECHO} "$$t -> $$l"; \ + mkdir -p `dirname $$t`; \ + rm -f $$t; \ + ${LN} $$l $$t + +_SYMLINKS_SCRIPT= \ + while test $$\# -ge 2; do \ + l=$$1; shift; \ + t=${DESTDIR}$$1; shift; \ + ${__SYMLINK_SCRIPT}; \ + done; :; + +_LINKS_SCRIPT= \ + while test $$\# -ge 2; do \ + l=${DESTDIR}$$1; shift; \ + t=${DESTDIR}$$1; shift; \ + ${__LINK_SCRIPT}; \ + done; :; + +_SYMLINKS_USE: .USE + @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_SYMLINKS_SCRIPT} + +_LINKS_USE: .USE + @set ${$@_LINKS:U${LINKS}}; ${_LINKS_SCRIPT} + + +# sometimes we want to ensure DESTDIR is ignored +_BUILD_SYMLINKS_SCRIPT= \ + while test $$\# -ge 2; do \ + l=$$1; shift; \ + t=$$1; shift; \ + ${__SYMLINK_SCRIPT}; \ + done; :; + +_BUILD_LINKS_SCRIPT= \ + while test $$\# -ge 2; do \ + l=$$1; shift; \ + t=$$1; shift; \ + ${__LINK_SCRIPT}; \ + done; :; + +_BUILD_SYMLINKS_USE: .USE + @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_BUILD_SYMLINKS_SCRIPT} + +_BUILD_LINKS_USE: .USE + @set ${$@_LINKS:U${LINKS}}; ${_BUILD_LINKS_SCRIPT} diff --git a/contrib/bmake/mk/man.mk b/contrib/bmake/mk/man.mk new file mode 100644 index 0000000..391b08a --- /dev/null +++ b/contrib/bmake/mk/man.mk @@ -0,0 +1,137 @@ +# $Id: man.mk,v 1.20 2012/12/13 01:51:01 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.include + +# unlike bsd.man.mk we handle 3 approaches +# 1. install unformated nroff (default) +# 2. install formatted pages +# 3. install formatted pages but with extension of .0 +# sadly we cannot rely on a shell that supports ${foo#...} and ${foo%...} +# so we have to use sed(1). + +# set MANTARGET=cat for formatted pages +MANTARGET?= man +# set this to .0 for same behavior as bsd.man.mk +MCATEXT?= + +NROFF?= nroff +MANDIR?= /usr/share/man +MANDOC?= man + +.SUFFIXES: .1 .2 .3 .4 .5 .6 .7 .8 .9 .cat1 .cat2 .cat3 .cat4 .cat5 .cat6 \ + .cat7 .cat8 .cat9 + +.9.cat9 .8.cat8 .7.cat7 .6.cat6 .5.cat5 .4.cat4 .3.cat3 .2.cat2 .1.cat1: + @echo "${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}" + @${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false ) + +.if defined(MAN) && !empty(MAN) + +# we use cmt2doc.pl to extract manpages from source +# this is triggered by the setting of EXTRACT_MAN or MAN being set but +# not existsing. + +.if !exists(${MAN:[1]}) && !target(${MAN:[1]}) +.if defined(EXTRACT_MAN) && ${EXTRACT_MAN} == "no" +MAN= +.else +.if exists(/usr/local/share/bin/cmt2doc.pl) +CMT2DOC?= cmt2doc.pl +CMT2DOC_OPTS?= ${CMT2DOC_ORGOPT} -pmS${.TARGET:E} +.endif +.ifdef CMT2DOC +.c.8 .c.5 .c.3 .c.4 .c.1 \ + .cc.8 .cc.5 .cc.3 .cc.4 .cc.1 \ + .h.8 .h.5 .h.3 .h.4 .h.1 \ + .sh.8 .sh.5 .sh.3 .sh.4 .sh.1 \ + .pl.8 .pl.5 .pl.3 .pl.4 .pl.1: + @echo "${CMT2DOC} ${.IMPSRC} > ${.TARGET:T}" + @${CMT2DOC} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false ) +.else +MAN= +.endif +.endif +.endif + +_mandir=${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'` +.if ${MANTARGET} == "cat" +_mfromdir?=. +MANALL= ${MAN:S/.1$/.cat1/g:S/.2$/.cat2/g:S/.3$/.cat3/g:S/.4$/.cat4/g:S/.5$/.cat5/g:S/.6$/.cat6/g:S/.7$/.cat7/g:S/.8$/.cat8/g:S/.9$/.cat9/g} +.if ${MCATEXT} == "" +_minstpage=`echo $$page | sed 's/\.cat/./'` +.else +_minstpage=`echo $$page | sed 's/\.cat.*//'`${MCATEXT} +.endif +.endif +.if target(${MAN:[1]}) +_mfromdir?=. +.endif +_mfromdir?=${.CURDIR} +MANALL?= ${MAN} +_minstpage?=$${page} +.endif + +.if !empty(MANOWN) +MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP} +MAN_CHOWN ?= chown +.else +MAN_CHOWN = : +.endif + +MINSTALL= ${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE} +.if defined(MANZ) +# chown and chmod are done afterward automatically +MCOMPRESS= gzip -cf +MCOMPRESSSUFFIX= .gz +.endif + +maninstall: +.if defined(MANALL) && !empty(MANALL) + @for page in ${MANALL:T}; do \ + test -s ${_mfromdir}/$$page || continue; \ + dir=${_mandir}; \ + test -d $$dir || ${INSTALL} -d ${MAN_INSTALL_OWN} -m 775 $$dir; \ + instpage=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \ + if [ X"${MCOMPRESS}" = X ]; then \ + echo ${MINSTALL} ${_mfromdir}/$$page $$instpage; \ + ${MINSTALL} ${_mfromdir}/$$page $$instpage; \ + else \ + rm -f $$instpage; \ + echo ${MCOMPRESS} ${_mfromdir}/$$page \> $$instpage; \ + ${MCOMPRESS} ${_mfromdir}/$$page > $$instpage; \ + ${MAN_CHOWN} ${MANOWN}:${MANGRP} $$instpage; \ + chmod ${MANMODE} $$instpage; \ + fi \ + done +.if defined(MLINKS) && !empty(MLINKS) + @set ${MLINKS}; \ + while test $$# -ge 2; do \ + page=$$1; \ + shift; \ + dir=${_mandir}; \ + l=${_minstpage}${MCOMPRESSSUFFIX}; \ + page=$$1; \ + shift; \ + dir=${_mandir}; \ + t=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \ + echo $$t -\> $$l; \ + rm -f $$t; \ + ln -s $$l $$t; \ + done +.endif +.endif + +.if defined(MANALL) && !empty(MANALL) +manall: ${MANALL} +all: manall +.endif + +.if defined(CLEANMAN) && !empty(CLEANMAN) +cleandir: cleanman +cleanman: + rm -f ${CLEANMAN} +.endif +.endif diff --git a/contrib/bmake/mk/meta.autodep.mk b/contrib/bmake/mk/meta.autodep.mk new file mode 100644 index 0000000..c29c26e --- /dev/null +++ b/contrib/bmake/mk/meta.autodep.mk @@ -0,0 +1,262 @@ +# $Id: meta.autodep.mk,v 1.32 2012/11/13 00:44:26 sjg Exp $ + +# +# @(#) Copyright (c) 2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +_this ?= ${.PARSEFILE} +.if !target(__${_this}__) +__${_this}__: .NOTMAIN + +.-include "local.autodep.mk" + +.if defined(SRCS) +# it would be nice to be able to query .SUFFIXES +OBJ_EXTENSIONS+= .o .po .lo .So + +# explicit dependencies help short-circuit .SUFFIX searches +SRCS_DEP_FILTER+= N*.[hly] +.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} +.for e in ${OBJ_EXTENSIONS:O:u} +.if !target(${s:T:R}$e) +${s:T:R}$e: $s +.endif +.endfor +.endfor +.endif + +.if make(gendirdeps) +# you are supposed to know what you are doing! +UPDATE_DEPENDFILE = yes +.elif !empty(.TARGETS) && !make(all) +# do not update the *depend* files +# unless we are building the entire directory or the default target. +# NO means don't update .depend - or Makefile.depend* +# no means update .depend but not Makefile.depend* +UPDATE_DEPENDFILE = NO +.elif ${.MAKEFLAGS:M-k} != "" +# it is a bad idea to update anything +UPDATE_DEPENDFILE = NO +.endif + +_CURDIR ?= ${.CURDIR} +_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} + +.if ${.MAKE.LEVEL} == 0 +.if ${BUILD_AT_LEVEL0:Uyes:tl} == "no" +UPDATE_DEPENDFILE = NO +.endif +.endif +.if !exists(${_DEPENDFILE}) +_bootstrap_dirdeps = yes +.endif +_bootstrap_dirdeps ?= no +UPDATE_DEPENDFILE ?= yes + +.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} +.endif + +.if !empty(XMAKE_META_FILE) +.if exists(${.OBJDIR}/${XMAKE_META_FILE}) +# we cannot get accurate dependencies from an update build +UPDATE_DEPENDFILE = NO +.else +META_XTRAS += ${XMAKE_META_FILE} +.endif +.endif + +.if ${_bootstrap_dirdeps} == "yes" || exists(${_DEPENDFILE}) +# if it isn't supposed to be touched by us the Makefile should have +# UPDATE_DEPENDFILE = no +WANT_UPDATE_DEPENDFILE ?= yes +.endif + +.if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no" +.if ${.MAKE.MODE:Mmeta*} == "" || ${.MAKE.MODE:M*read*} != "" +UPDATE_DEPENDFILE = no +.endif + +.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} +.endif + +.if ${UPDATE_DEPENDFILE:tl} == "yes" +# sometimes we want .meta files generated to aid debugging/error detection +# but do not want to consider them for dependencies +# for example the result of running configure +# just make sure this is not empty +META_FILE_FILTER ?= N.meta + +.if !empty(DPADD) +# if we have any non-libs in DPADD, +# they probably need to be paid attention to +.if !empty(DPLIBS) +FORCE_DPADD = ${DPADD:${DPLIBS:${M_ListToSkip}}:${DPADD_LAST:${M_ListToSkip}}} +.else +_nonlibs := ${DPADD:T:Nlib*:N*include} +.if !empty(_nonlibs) +FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@} +.endif +.endif +.endif + +.if !make(gendirdeps) +.END: gendirdeps +.endif + +# if we don't have OBJS, then .depend isn't useful +.if !target(.depend) && (!empty(OBJS) || ${.ALLTARGETS:M*.o} != "") +# some makefiles and/or targets contain +# circular dependencies if you dig too deep +# (as meta mode is apt to do) +# so we provide a means of supressing them. +# the input to the loop below is target: dependency +# with just one dependency per line. +# Also some targets are not really local, or use random names. +# Use local.autodep.mk to provide local additions! +SUPPRESS_DEPEND += \ + ${SB:S,/,_,g}* \ + *:y.tab.c \ + *.c:*.c \ + *.h:*.h + +.NOPATH: .depend +# we use ${.MAKE.META.CREATED} to trigger an update but +# we process using ${.MAKE.META.FILES} +# the double $$ defers initial evaluation +# if necessary, we fake .po dependencies, just so the result +# in Makefile.depend* is stable +# The current objdir may be refered to in various ways +OBJDIR_REFS += ${.OBJDIR} ${.OBJDIR:tA} ${_OBJDIR} ${RELOBJTOP}/${RELDIR} +_depend = .depend +# it would be nice to be able to get .SUFFIXES as ${.SUFFIXES} +# we actually only care about the .SUFFIXES of files that might be +# generated by tools like yacc. +DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh +.depend: .NOMETA $${.MAKE.META.CREATED} ${_this} + @echo "Updating $@: ${.OODATE:T:[1..8]}" + @egrep -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \ + sed -e 's, \./, ,${OBJDIR_REFS:O:u:@d@;s, $d/, ,@};/\//d' \ + -e 's,^\([^/][^/]*\).meta...[0-9]* ,\1: ,' | \ + sort -u | \ + while read t d; do \ + case "$$d:" in $$t) continue;; esac; \ + case "$$t$$d" in ${SUPPRESS_DEPEND:U.:O:u:ts|}) continue;; esac; \ + echo $$t $$d; \ + done > $@.${.MAKE.PID} + @case "${.MAKE.META.FILES:T:M*.po.*}" in \ + *.po.*) mv $@.${.MAKE.PID} $@;; \ + *) { cat $@.${.MAKE.PID}; \ + sed 's,\.So:,.o:,;s,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \ + rm -f $@.${.MAKE.PID};; \ + esac +.else +# make sure this exists +.depend: +# do _not_ assume that .depend is in any fit state for us to use +CAT_DEPEND = /dev/null +.if ${.MAKE.LEVEL} > 0 +.export CAT_DEPEND +.endif +_depend = +.endif + +.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.info ${_DEPENDFILE:S,${SRCTOP}/,,} _depend=${_depend} +.endif + +gendirdeps: ${_DEPENDFILE} + +.if !target(${_DEPENDFILE}) +.if ${_bootstrap_dirdeps} == "yes" +# We are boot-strapping a new directory +# Use DPADD to seed DIRDEPS +.if !empty(DPADD) +# anything which matches ${_OBJROOT}* but not ${_OBJTOP}* +# needs to be qualified in DIRDEPS +# The pseudo machine "host" is used for HOST_TARGET +DIRDEPS = \ + ${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \ + ${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u} + +.endif +.endif + +_gendirdeps_mutex = +.if defined(NEED_GENDIRDEPS_MUTEX) +# If a src dir gets built with multiple object dirs, +# we need a mutex. Obviously, this is best avoided. +# Note if .MAKE.DEPENDFILE is common for all ${MACHINE} +# you either need to mutex, or ensure only one machine builds at a time! +# lockf is an example of a suitable tool +LOCKF ?= /usr/bin/lockf +.if exists(${LOCKF}) +GENDIRDEPS_MUTEXER ?= ${LOCKF} -k +.endif +.if empty(GENDIRDEPS_MUTEXER) +.error NEED_GENDIRDEPS_MUTEX defined, but GENDIRDEPS_MUTEXER not set +.else +_gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefile} +.endif +.endif + +# If we have META_XTRAS we most likely did not create them +# but we need to behave as if we did. +# Avoid adding glob patterns to .MAKE.META.CREATED though. +.MAKE.META.CREATED += ${META_XTRAS:N*\**:O:u} + +.if make(gendirdeps) +META_FILES = *.meta +.elif ${OPTIMIZE_OBJECT_META_FILES:Uno:tl} == "no" +META_FILES = ${.MAKE.META.FILES:T:N.depend*:O:u} +.else +# if we have 1000's of .o.meta, .So.meta etc we need only look at one set +# it is left as an exercise for the reader to work out what this does +META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \ + ${.MAKE.META.FILES:T:M*.${.MAKE.META.FILES:M*o.meta:R:E:O:u:[1]}.meta:O:u} +.endif + +.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" +.info ${_DEPENDFILE:S,${SRCTOP}/,,}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} xtras=${META_XTRAS} +.endif + +.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) +.export GENDIRDEPS_FILTER +.endif + +# we might have .../ in MAKESYSPATH +_makesyspath:= ${_PARSEDIR} +${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.META.CREATED} + @echo Checking $@: ${.OODATE:T:[1..8]} + @(cd . && \ + SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS:O:u}' \ + DPADD='${FORCE_DPADD:O:u}' ${_gendirdeps_mutex} \ + MAKESYSPATH=${_makesyspath} \ + ${.MAKE} -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE} \ + META_FILES='${META_XTRAS:T:O:u} ${META_FILES:T:O:u:${META_FILE_FILTER:ts:}}') + @test -s $@ && touch $@; : +.endif + +.endif +.endif + +.if ${_bootstrap_dirdeps} == "yes" +# make sure this is included at least once +.include +.else +${_DEPENDFILE}: .PRECIOUS +.endif + +CLEANFILES += *.meta filemon.* *.db +.endif diff --git a/contrib/bmake/mk/meta.stage.mk b/contrib/bmake/mk/meta.stage.mk new file mode 100644 index 0000000..2f02700 --- /dev/null +++ b/contrib/bmake/mk/meta.stage.mk @@ -0,0 +1,244 @@ +# $Id: meta.stage.mk,v 1.30 2013/04/19 16:32:57 sjg Exp $ +# +# @(#) Copyright (c) 2011, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != "" +# this is generally safer anyway +_dirdep = ${RELDIR}.${MACHINE} +.else +_dirdep = ${RELDIR} +.endif + +# this allows us to trace dependencies back to their src dir +.dirdep: + @echo '${_dirdep}' > $@ + +.if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == "" +_stage_file_basename = `basename $$f` +_stage_target_dirname = `dirname $$t` +.else +_stage_file_basename = $${f\#\#*/} +_stage_target_dirname = $${t%/*} +.endif + +_objroot ?= ${_OBJROOT:tA} +# make sure this is global +_STAGED_DIRS ?= +.export _STAGED_DIRS +# add each dir we stage to to _STAGED_DIRS +# and make sure we have absolute paths so that bmake +# will match against .MAKE.META.BAILIWICK +STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@ +# convert _STAGED_DIRS into suitable filters +GENDIRDEPS_FILTER += Nnot-empty-is-important \ + ${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \ + ${_STAGED_DIRS:O:u:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,} + +LN_CP_SCRIPT = LnCp() { \ + rm -f $$2 2> /dev/null; \ + ln $$1 $$2 2> /dev/null || \ + cp -p $$1 $$2; } + +# it is an error for more than one src dir to try and stage +# the same file +STAGE_DIRDEP_SCRIPT = ${LN_CP_SCRIPT}; StageDirdep() { \ + t=$$1; \ + if [ -s $$t.dirdep ]; then \ + cmp -s .dirdep $$t.dirdep && return; \ + echo "ERROR: $$t installed by `cat $$t.dirdep` not ${_dirdep}" >&2; \ + exit 1; \ + fi; \ + LnCp .dirdep $$t.dirdep || exit 1; } + +# common logic for staging files +# this all relies on RELDIR being set to a subdir of SRCTOP +# we use ln(1) if we can, else cp(1) +STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \ + case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ + dest=$$1; shift; \ + mkdir -p $$dest; \ + [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ + for f in "$$@"; do \ + case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \ + StageDirdep $$t; \ + LnCp $$f $$t || exit 1; \ + [ -z "$$mode" ] || chmod $$mode $$t; \ + done; :; } + +STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \ + case "$$1" in "") return;; --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \ + dest=$$1; shift; \ + mkdir -p $$dest; \ + [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ + while test $$\# -ge 2; do \ + l=$$ldest$$1; shift; \ + t=$$dest/$$1; \ + case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ + shift; \ + StageDirdep $$t; \ + rm -f $$t 2>/dev/null; \ + ln $$lnf $$l $$t || exit 1; \ + done; :; } + +STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \ + case "$$1" in "") return;; -m) mode=$$2; shift 2;; *) mode=;; esac; \ + dest=$$1; shift; \ + mkdir -p $$dest; \ + [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \ + while test $$\# -ge 2; do \ + s=$$1; shift; \ + t=$$dest/$$1; \ + case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \ + shift; \ + StageDirdep $$t; \ + LnCp $$s $$t || exit 1; \ + [ -z "$$mode" ] || chmod $$mode $$t; \ + done; :; } + +# this is simple, a list of the "staged" files depends on this, +_STAGE_BASENAME_USE: .USE ${.TARGET:T} + @${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} + +.if !empty(STAGE_INCSDIR) +STAGE_TARGETS += stage_incs +STAGE_INCS ?= ${.ALLSRC:N.dirdep} + +stage_incs: .dirdep + @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS} + @touch $@ +.endif + +.if !empty(STAGE_LIBDIR) +STAGE_TARGETS += stage_libs + +STAGE_LIBS ?= ${.ALLSRC:N.dirdep} + +stage_libs: .dirdep + @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS} +.if !empty(SHLIB_LINKS) + @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \ + ${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*} $t@} +.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME) + @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK} ${SYMLINKS:T} +.endif + @touch $@ +.endif + +.if !empty(STAGE_DIR) +STAGE_SETS += _default +STAGE_DIR._default = ${STAGE_DIR} +STAGE_LINKS_DIR._default = ${STAGE_LINKS_DIR:U${STAGE_OBJTOP}} +STAGE_SYMLINKS_DIR._default = ${STAGE_SYMLINKS_DIR:U${STAGE_OBJTOP}} +STAGE_FILES._default = ${STAGE_FILES} +STAGE_LINKS._default = ${STAGE_LINKS} +STAGE_SYMLINKS._default = ${STAGE_SYMLINKS} +STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*} +STAGE_SYMLINKS ?= ${.ALLSRC:T:N.dirdep:Nstage_*} +.endif + +.if !empty(STAGE_SETS) +CLEANFILES += ${STAGE_SETS:@s@stage*$s@} + +# some makefiles need to populate multiple directories +.for s in ${STAGE_SETS:O:u} +STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep} +STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep} +STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP} +STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP} + +STAGE_TARGETS += stage_files +.if $s != "_default" +stage_files: stage_files.$s +stage_files.$s: .dirdep +.else +stage_files: .dirdep +.endif + @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s} + @touch $@ + +STAGE_TARGETS += stage_links +.if $s != "_default" +stage_links: stage_links.$s +stage_links.$s: .dirdep +.else +stage_links: .dirdep +.endif + @${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s} + @touch $@ + +STAGE_TARGETS += stage_symlinks +.if $s != "_default" +stage_symlinks: stage_symlinks.$s +stage_symlinks.$s: .dirdep +.else +stage_symlinks: .dirdep +.endif + @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s} + @touch $@ + +.endfor +.endif + +.if !empty(STAGE_AS_SETS) +CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@} + +STAGE_TARGETS += stage_as + +# sometimes things need to be renamed as they are staged +# each ${file} will be staged as ${STAGE_AS_${file:T}} +# one could achieve the same with SYMLINKS +.for s in ${STAGE_AS_SETS:O:u} +STAGE_AS.$s ?= ${.ALLSRC:N.dirdep} + +stage_as: stage_as.$s +stage_as.$s: .dirdep + @${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:@f@$f ${STAGE_AS_${f:T}:U${f:T}}@} + @touch $@ + +.endfor +.endif + +CLEANFILES += ${STAGE_TARGETS} + +# stage_*links usually needs to follow any others. +.for t in ${STAGE_TARGETS:N*links:O:u} +.ORDER: $t stage_links +.ORDER: $t stage_symlinks +.endfor + +# make sure this exists +staging: + +# generally we want staging to wait until everything else is done +STAGING_WAIT ?= .WAIT + +all: ${STAGING_WAIT} staging + +.if exists(${.PARSEDIR}/stage-install.sh) && !defined(STAGE_INSTALL) +# this will run install(1) and then followup with .dirdep files. +STAGE_INSTALL := sh ${.PARSEDIR:tA}/stage-install.sh INSTALL="${INSTALL}" OBJDIR=${.OBJDIR:tA} +.endif + +# if ${INSTALL} gets run during 'all' assume it is for staging? +.if ${.TARGETS:Nall} == "" && defined(STAGE_INSTALL) +INSTALL := ${STAGE_INSTALL} +.if target(beforeinstall) +beforeinstall: .dirdep +.endif +.endif + +.endif diff --git a/contrib/bmake/mk/meta.subdir.mk b/contrib/bmake/mk/meta.subdir.mk new file mode 100644 index 0000000..2b739ee --- /dev/null +++ b/contrib/bmake/mk/meta.subdir.mk @@ -0,0 +1,79 @@ +# $Id: meta.subdir.mk,v 1.10 2012/07/03 05:26:46 sjg Exp $ + +# +# @(#) Copyright (c) 2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !defined(NO_SUBDIR) && !empty(SUBDIR) +.if make(destroy*) || make(clean*) +.MAKE.MODE = compat +.if !commands(destroy) +.-include +.endif +.elif ${.MAKE.LEVEL} == 0 + +.MAIN: all + +.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps) +# start with this +DIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@} + +.if make(gendirdeps) +.include +.else +# this is the cunning bit +# actually it is probably a bit risky +# since we may pickup subdirs which are not relevant +# the alternative is a walk through the tree though +# which is difficult without a sub-make. + +.if defined(BOOTSTRAP_DEPENDFILES) +_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1} +DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@} +.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES) +# we want to find Makefile.depend.* ie for all machines +# and turn the dirs into dir. +_find_name = -name '${.MAKE.DEPENDFILE:T:R}*' +DIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,} +.else +# much simpler +_find_name = -name ${.MAKE.DEPENDFILE:T} +.if ${.MAKE.DEPENDFILE:E} == ${MACHINE} +_find_name += -o -name ${.MAKE.DEPENDFILE:T:R} +.endif +DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@} +.endif + +_subdeps != cd ${.CURDIR} && \ + find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \ + -name .svn -prune 2> /dev/null; echo + +.if empty(_subdeps) +DIRDEPS = +.else +# clean up if needed +DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIREPS_FILTER:Uu}} +.endif +# we just dealt with it, if we leave it defined, +# dirdeps.mk will compute some interesting combinations. +.undef ALL_MACHINES + +DEP_RELDIR = ${RELDIR} +.include +.endif +.endif +.else +all: .PHONY +.endif + +.endif diff --git a/contrib/bmake/mk/meta.sys.mk b/contrib/bmake/mk/meta.sys.mk new file mode 100644 index 0000000..1707a66 --- /dev/null +++ b/contrib/bmake/mk/meta.sys.mk @@ -0,0 +1,139 @@ +# $Id: meta.sys.mk,v 1.16 2012/07/03 05:26:00 sjg Exp $ + +# +# @(#) Copyright (c) 2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# include this if you want to enable meta mode +# for maximum benefit, requires filemon(4) driver. + +.if ${MAKE_VERSION:U0} > 20100901 +.if !target(.ERROR) + + +META_MODE += meta verbose +.MAKE.MODE ?= ${META_MODE} + +.if ${.MAKE.LEVEL} == 0 +_make_mode := ${.MAKE.MODE} ${META_MODE} +.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != "" +# tell everyone we are not updating Makefile.depend* +UPDATE_DEPENDFILE = NO +.export UPDATE_DEPENDFILE +.endif +.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon) +# we should not get upset +META_MODE += nofilemon +.export META_MODE +.endif +.endif + +.if !defined(NO_SILENT) +.if ${MAKE_VERSION} > 20110818 +# only be silent when we have a .meta file +META_MODE += silent=yes +.else +.SILENT: +.endif +.endif + +# make defaults .MAKE.DEPENDFILE to .depend +# that won't work for us. +.if ${.MAKE.DEPENDFILE} == ".depend" +.undef .MAKE.DEPENDFILE +.endif + +# if you don't cross build for multiple MACHINEs concurrently, then +# .MAKE.DEPENDFILE = Makefile.depend +# probably makes sense - you can set that in local.sys.mk +.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE} + +# we use the pseudo machine "host" for the build host. +# this should be taken care of before we get here +.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} +MACHINE = host +.endif + +.if ${.MAKE.LEVEL} == 0 +# it can be handy to know which MACHINE kicked off the build +# for example, if using Makefild.depend for multiple machines, +# allowing only MACHINE0 to update can keep things simple. +MACHINE0 := ${MACHINE} + +.if defined(PYTHON) && exists(${PYTHON}) +# we prefer the python version of this - it is much faster +META2DEPS ?= ${.PARSEDIR}/meta2deps.py +.else +META2DEPS ?= ${.PARSEDIR}/meta2deps.sh +.endif +META2DEPS := ${META2DEPS} +.export META2DEPS +.endif + +MAKE_PRINT_VAR_ON_ERROR += \ + .ERROR_TARGET \ + .ERROR_META_FILE \ + .MAKE.LEVEL \ + MAKEFILE \ + .MAKE.MODE + +.if !defined(SB) && defined(SRCTOP) +SB = ${SRCTOP:H} +.endif +ERROR_LOGDIR ?= ${SB}/error +meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log + +# we are not interested in make telling us a failure happened elsewhere +.ERROR: _metaError +_metaError: .NOMETA .NOTMAIN + -@[ "${.ERROR_META_FILE}" ] && { \ + grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \ + mkdir -p ${meta_error_log:H}; \ + cp ${.ERROR_META_FILE} ${meta_error_log}; \ + echo "ERROR: log ${meta_error_log}" >&2; }; : + +.endif + +# Are we, after all, in meta mode? +.if ${.MAKE.MODE:Mmeta*} != "" +MKDEP = meta.autodep + +.if ${.MAKE.LEVEL} == 0 +# make sure dirdeps target exists and do it first +all: dirdeps .WAIT +dirdeps: +.NOPATH: dirdeps + +.if defined(ALL_MACHINES) +# the first .MAIN: is what counts +# by default dirdeps is all we want at level0 +.MAIN: dirdeps +# tell dirdeps.mk what we want +BUILD_AT_LEVEL0 = no +.endif + +.if ${.MAKE.DEPENDFILE:E} == ${MACHINE} +# it works best if we do everything via sub-makes +BUILD_AT_LEVEL0 ?= no +.endif +BUILD_AT_LEVEL0 ?= yes +.endif + +# if we think we are updating dependencies, +# then filemon had better be present +.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon) +.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded. +.endif + +.endif +.endif diff --git a/contrib/bmake/mk/meta2deps.py b/contrib/bmake/mk/meta2deps.py new file mode 100755 index 0000000..254f230 --- /dev/null +++ b/contrib/bmake/mk/meta2deps.py @@ -0,0 +1,677 @@ +#!/usr/bin/env python + +""" +This script parses each "meta" file and extracts the +information needed to deduce build and src dependencies. + +It works much the same as the original shell script, but is +*much* more efficient. + +The parsing work is handled by the class MetaFile. +We only pay attention to a subset of the information in the +"meta" files. Specifically: + +'CWD' to initialize our notion. + +'C' to track chdir(2) on a per process basis + +'R' files read are what we really care about. + directories read, provide a clue to resolving + subsequent relative paths. That is if we cannot find + them relative to 'cwd', we check relative to the last + dir read. + +'W' files opened for write or read-write, + for filemon V3 and earlier. + +'E' files executed. + +'L' files linked + +'V' the filemon version, this record is used as a clue + that we have reached the interesting bit. + +""" + +""" +RCSid: + $Id: meta2deps.py,v 1.15 2013/07/29 20:41:23 sjg Exp $ + + Copyright (c) 2011-2013, Juniper Networks, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" + +import os, re, sys + +def getv(dict, key, d=None): + """Lookup key in dict and return value or the supplied default.""" + if key in dict: + return dict[key] + return d + +def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): + """ + Return an absolute path, resolving via cwd or last_dir if needed. + """ + if path.endswith('/.'): + path = path[0:-2] + if len(path) > 0 and path[0] == '/': + return path + if path == '.': + return cwd + if path.startswith('./'): + return cwd + path[1:] + if last_dir == cwd: + last_dir = None + for d in [last_dir, cwd]: + if not d: + continue + p = '/'.join([d,path]) + if debug > 2: + print >> debug_out, "looking for:", p, + if not os.path.exists(p): + if debug > 2: + print >> debug_out, "nope" + p = None + continue + if debug > 2: + print >> debug_out, "found:", p + return p + return None + +def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr): + """ + Return an absolute path, resolving via cwd or last_dir if needed. + this gets called a lot, so we try to avoid calling realpath + until we know we have something. + """ + rpath = resolve(path, cwd, last_dir, debug, debug_out) + if rpath: + path = rpath + if (path.find('./') > 0 or + path.endswith('/..') or + os.path.islink(path)): + return os.path.realpath(path) + return path + +def sort_unique(list, cmp=None, key=None, reverse=False): + list.sort(cmp, key, reverse) + nl = [] + le = None + for e in list: + if e == le: + continue + nl.append(e) + return nl + +def add_trims(x): + return ['/' + x + '/', + '/' + x, + x + '/', + x] + +class MetaFile: + """class to parse meta files generated by bmake.""" + + conf = None + dirdep_re = None + host_target = None + srctops = [] + objroots = [] + + seen = {} + obj_deps = [] + src_deps = [] + file_deps = [] + + def __init__(self, name, conf={}): + """if name is set we will parse it now. + conf can have the follwing keys: + + SRCTOPS list of tops of the src tree(s). + + CURDIR the src directory 'bmake' was run from. + + RELDIR the relative path from SRCTOP to CURDIR + + MACHINE the machine we built for. + set to 'none' if we are not cross-building. + More specifically if machine cannot be deduced from objdirs. + + TARGET_SPEC + Sometimes MACHINE isn't enough. + + HOST_TARGET + when we build for the psuedo machine 'host' + the object tree uses HOST_TARGET rather than MACHINE. + + OBJROOTS a list of the common prefix for all obj dirs it might + end in '/' or '-'. + + DPDEPS names an optional file to which per file dependencies + will be appended. + For example if 'some/path/foo.h' is read from SRCTOP + then 'DPDEPS_some/path/foo.h +=' "RELDIR" is output. + This can allow 'bmake' to learn all the dirs within + the tree that depend on 'foo.h' + + debug desired debug level + + debug_out open file to send debug output to (sys.stderr) + + """ + + self.name = name + self.debug = getv(conf, 'debug', 0) + self.debug_out = getv(conf, 'debug_out', sys.stderr) + + self.machine = getv(conf, 'MACHINE', '') + self.machine_arch = getv(conf, 'MACHINE_ARCH', '') + self.target_spec = getv(conf, 'TARGET_SPEC', '') + self.curdir = getv(conf, 'CURDIR') + self.reldir = getv(conf, 'RELDIR') + self.dpdeps = getv(conf, 'DPDEPS') + self.line = 0 + + if not self.conf: + # some of the steps below we want to do only once + self.conf = conf + self.host_target = getv(conf, 'HOST_TARGET') + for srctop in getv(conf, 'SRCTOPS', []): + if srctop[-1] != '/': + srctop += '/' + if not srctop in self.srctops: + self.srctops.append(srctop) + _srctop = os.path.realpath(srctop) + if _srctop[-1] != '/': + _srctop += '/' + if not _srctop in self.srctops: + self.srctops.append(_srctop) + + trim_list = add_trims(self.machine) + if self.machine == 'host': + trim_list += add_trims(self.host_target) + if self.target_spec: + trim_list += add_trims(self.target_spec) + + for objroot in getv(conf, 'OBJROOTS', []): + for e in trim_list: + if objroot.endswith(e): + # this is not what we want - fix it + objroot = objroot[0:-len(e)] + if e.endswith('/'): + objroot += '/' + if not objroot in self.objroots: + self.objroots.append(objroot) + _objroot = os.path.realpath(objroot) + if objroot[-1] == '/': + _objroot += '/' + if not _objroot in self.objroots: + self.objroots.append(_objroot) + + # we want the longest match + self.srctops.sort(reverse=True) + self.objroots.sort(reverse=True) + + if self.debug: + print >> self.debug_out, "host_target=", self.host_target + print >> self.debug_out, "srctops=", self.srctops + print >> self.debug_out, "objroots=", self.objroots + + self.dirdep_re = re.compile(r'([^/]+)/(.+)') + + if self.dpdeps and not self.reldir: + if self.debug: + print >> self.debug_out, "need reldir:", + if self.curdir: + srctop = self.find_top(self.curdir, self.srctops) + if srctop: + self.reldir = self.curdir.replace(srctop,'') + if self.debug: + print >> self.debug_out, self.reldir + if not self.reldir: + self.dpdeps = None # we cannot do it? + + self.cwd = os.getcwd() # make sure this is initialized + + if name: + self.try_parse() + + def reset(self): + """reset state if we are being passed meta files from multiple directories.""" + self.seen = {} + self.obj_deps = [] + self.src_deps = [] + self.file_deps = [] + + def dirdeps(self, sep='\n'): + """return DIRDEPS""" + return sep.strip() + sep.join(self.obj_deps) + + def src_dirdeps(self, sep='\n'): + """return SRC_DIRDEPS""" + return sep.strip() + sep.join(self.src_deps) + + def file_depends(self, out=None): + """Append DPDEPS_${file} += ${RELDIR} + for each file we saw, to the output file.""" + if not self.reldir: + return None + for f in sort_unique(self.file_deps): + print >> out, 'DPDEPS_%s += %s' % (f, self.reldir) + + def seenit(self, dir): + """rememer that we have seen dir.""" + self.seen[dir] = 1 + + def add(self, list, data, clue=''): + """add data to list if it isn't already there.""" + if data not in list: + list.append(data) + if self.debug: + print >> self.debug_out, "%s: %sAdd: %s" % (self.name, clue, data) + + def find_top(self, path, list): + """the logical tree may be split accross multiple trees""" + for top in list: + if path.startswith(top): + if self.debug > 2: + print >> self.debug_out, "found in", top + return top + return None + + def find_obj(self, objroot, dir, path, input): + """return path within objroot, taking care of .dirdep files""" + ddep = None + for ddepf in [path + '.dirdep', dir + '/.dirdep']: + if not ddep and os.path.exists(ddepf): + ddep = open(ddepf, 'rb').readline().strip('# \n') + if self.debug > 1: + print >> self.debug_out, "found %s: %s\n" % (ddepf, ddep) + if ddep.endswith(self.machine): + ddep = ddep[0:-(1+len(self.machine))] + elif self.target_spec and ddep.endswith(self.target_spec): + ddep = ddep[0:-(1+len(self.target_spec))] + + if not ddep: + # no .dirdeps, so remember that we've seen the raw input + self.seenit(input) + self.seenit(dir) + if self.machine == 'none': + if dir.startswith(objroot): + return dir.replace(objroot,'') + return None + m = self.dirdep_re.match(dir.replace(objroot,'')) + if m: + ddep = m.group(2) + dmachine = m.group(1) + if dmachine != self.machine: + if not (self.machine == 'host' and + dmachine == self.host_target): + if self.debug > 2: + print >> self.debug_out, "adding .%s to %s" % (dmachine, ddep) + ddep += '.' + dmachine + + return ddep + + def try_parse(self, name=None, file=None): + """give file and line number causing exception""" + try: + self.parse(name, file) + except: + # give a useful clue + print >> sys.stderr, '{}:{}: '.format(self.name, self.line), + raise + + def parse(self, name=None, file=None): + """A meta file looks like: + + # Meta data file "path" + CMD "command-line" + CWD "cwd" + TARGET "target" + -- command output -- + -- filemon acquired metadata -- + # buildmon version 3 + V 3 + C "pid" "cwd" + E "pid" "path" + F "pid" "child" + R "pid" "path" + W "pid" "path" + X "pid" "status" + D "pid" "path" + L "pid" "src" "target" + M "pid" "old" "new" + S "pid" "path" + # Bye bye + + We go to some effort to avoid processing a dependency more than once. + Of the above record types only C,E,F,L,R,V and W are of interest. + """ + + version = 0 # unknown + if name: + self.name = name; + if file: + f = file + cwd = last_dir = self.cwd + else: + f = open(self.name, 'rb') + skip = True + pid_cwd = {} + pid_last_dir = {} + last_pid = 0 + + self.line = 0 + if self.curdir: + self.seenit(self.curdir) # we ignore this + + interesting = 'CEFLRV' + for line in f: + self.line += 1 + # ignore anything we don't care about + if not line[0] in interesting: + continue + if self.debug > 2: + print >> self.debug_out, "input:", line, + w = line.split() + + if skip: + if w[0] == 'V': + skip = False + version = int(w[1]) + """ + if version < 4: + # we cannot ignore 'W' records + # as they may be 'rw' + interesting += 'W' + """ + elif w[0] == 'CWD': + self.cwd = cwd = last_dir = w[1] + self.seenit(cwd) # ignore this + if self.debug: + print >> self.debug_out, "%s: CWD=%s" % (self.name, cwd) + continue + + pid = int(w[1]) + if pid != last_pid: + if last_pid: + pid_cwd[last_pid] = cwd + pid_last_dir[last_pid] = last_dir + cwd = getv(pid_cwd, pid, self.cwd) + last_dir = getv(pid_last_dir, pid, self.cwd) + last_pid = pid + + # process operations + if w[0] == 'F': + npid = int(w[2]) + pid_cwd[npid] = cwd + pid_last_dir[npid] = cwd + last_pid = npid + continue + elif w[0] == 'C': + cwd = abspath(w[2], cwd, None, self.debug, self.debug_out) + if cwd.endswith('/.'): + cwd = cwd[0:-2] + last_dir = cwd + if self.debug > 1: + print >> self.debug_out, "cwd=", cwd + continue + + if w[2] in self.seen: + if self.debug > 2: + print >> self.debug_out, "seen:", w[2] + continue + # file operations + if w[0] in 'ML': + path = w[2].strip("'") + else: + path = w[2] + # we are never interested in .dirdep files as dependencies + if path.endswith('.dirdep'): + continue + # we don't want to resolve the last component if it is + # a symlink + path = resolve(path, cwd, last_dir, self.debug, self.debug_out) + if not path: + continue + dir,base = os.path.split(path) + if dir in self.seen: + if self.debug > 2: + print >> self.debug_out, "seen:", dir + continue + # we can have a path in an objdir which is a link + # to the src dir, we may need to add dependencies for each + rdir = dir + dir = abspath(dir, cwd, last_dir, self.debug, self.debug_out) + if rdir == dir or rdir.find('./') > 0: + rdir = None + # now put path back together + path = '/'.join([dir,base]) + if self.debug > 1: + print >> self.debug_out, "raw=%s rdir=%s dir=%s path=%s" % (w[2], rdir, dir, path) + if w[0] in 'SRWL': + if w[0] == 'W' and path.endswith('.dirdep'): + continue + if path in [last_dir, cwd, self.cwd, self.curdir]: + if self.debug > 1: + print >> self.debug_out, "skipping:", path + continue + if os.path.isdir(path): + if w[0] in 'RW': + last_dir = path; + if self.debug > 1: + print >> self.debug_out, "ldir=", last_dir + continue + + if w[0] in 'REWML': + # finally, we get down to it + if dir == self.cwd or dir == self.curdir: + continue + srctop = self.find_top(path, self.srctops) + if srctop: + if self.dpdeps: + self.add(self.file_deps, path.replace(srctop,''), 'file') + self.add(self.src_deps, dir.replace(srctop,''), 'src') + self.seenit(w[2]) + self.seenit(dir) + if rdir and not rdir.startswith(srctop): + dir = rdir # for below + rdir = None + else: + continue + + objroot = None + for dir in [dir,rdir]: + if not dir: + continue + objroot = self.find_top(dir, self.objroots) + if objroot: + break + if objroot: + ddep = self.find_obj(objroot, dir, path, w[2]) + if ddep: + self.add(self.obj_deps, ddep, 'obj') + else: + # don't waste time looking again + self.seenit(w[2]) + self.seenit(dir) + if not file: + f.close() + + +def main(argv, klass=MetaFile, xopts='', xoptf=None): + """Simple driver for class MetaFile. + + Usage: + script [options] [key=value ...] "meta" ... + + Options and key=value pairs contribute to the + dictionary passed to MetaFile. + + -S "SRCTOP" + add "SRCTOP" to the "SRCTOPS" list. + + -C "CURDIR" + + -O "OBJROOT" + add "OBJROOT" to the "OBJROOTS" list. + + -m "MACHINE" + + -a "MACHINE_ARCH" + + -H "HOST_TARGET" + + -D "DPDEPS" + + -d bumps debug level + + """ + import getopt + + # import Psyco if we can + # it can speed things up quite a bit + have_psyco = 0 + try: + import psyco + psyco.full() + have_psyco = 1 + except: + pass + + conf = { + 'SRCTOPS': [], + 'OBJROOTS': [], + } + + try: + machine = os.environ['MACHINE'] + if machine: + conf['MACHINE'] = machine + machine_arch = os.environ['MACHINE_ARCH'] + if machine_arch: + conf['MACHINE_ARCH'] = machine_arch + srctop = os.environ['SB_SRC'] + if srctop: + conf['SRCTOPS'].append(srctop) + objroot = os.environ['SB_OBJROOT'] + if objroot: + conf['OBJROOTS'].append(objroot) + except: + pass + + debug = 0 + output = True + + opts, args = getopt.getopt(argv[1:], 'a:dS:C:O:R:m:D:H:qT:' + xopts) + for o, a in opts: + if o == '-a': + conf['MACHINE_ARCH'] = a + elif o == '-d': + debug += 1 + elif o == '-q': + output = False + elif o == '-H': + conf['HOST_TARGET'] = a + elif o == '-S': + if a not in conf['SRCTOPS']: + conf['SRCTOPS'].append(a) + elif o == '-C': + conf['CURDIR'] = a + elif o == '-O': + if a not in conf['OBJROOTS']: + conf['OBJROOTS'].append(a) + elif o == '-R': + conf['RELDIR'] = a + elif o == '-D': + conf['DPDEPS'] = a + elif o == '-m': + conf['MACHINE'] = a + elif o == '-T': + conf['TARGET_SPEC'] = a + elif xoptf: + xoptf(o, a, conf) + + conf['debug'] = debug + + # get any var=val assignments + eaten = [] + for a in args: + if a.find('=') > 0: + k,v = a.split('=') + if k in ['SRCTOP','OBJROOT','SRCTOPS','OBJROOTS']: + if k == 'SRCTOP': + k = 'SRCTOPS' + elif k == 'OBJROOT': + k = 'OBJROOTS' + if v not in conf[k]: + conf[k].append(v) + else: + conf[k] = v + eaten.append(a) + continue + break + + for a in eaten: + args.remove(a) + + debug_out = getv(conf, 'debug_out', sys.stderr) + + if debug: + print >> debug_out, "config:" + print >> debug_out, "psyco=", have_psyco + for k,v in conf.items(): + print >> debug_out, "%s=%s" % (k,v) + + for a in args: + if a.endswith('.meta'): + m = klass(a, conf) + elif a.startswith('@'): + # there can actually multiple files per line + for line in open(a[1:]): + for f in line.strip().split(): + m = klass(f, conf) + + if output: + print m.dirdeps() + + print m.src_dirdeps('\nsrc:') + + dpdeps = getv(conf, 'DPDEPS') + if dpdeps: + m.file_depends(open(dpdeps, 'wb')) + + return m + +if __name__ == '__main__': + try: + main(sys.argv) + except: + # yes, this goes to stdout + print "ERROR: ", sys.exc_info()[1] + raise + diff --git a/contrib/bmake/mk/meta2deps.sh b/contrib/bmake/mk/meta2deps.sh new file mode 100755 index 0000000..f63aee3 --- /dev/null +++ b/contrib/bmake/mk/meta2deps.sh @@ -0,0 +1,379 @@ +#!/bin/sh + +# NAME: +# meta2deps.sh - extract useful info from .meta files +# +# SYNOPSIS: +# meta2deps.sh SB="SB" "meta" ... +# +# DESCRIPTION: +# This script looks each "meta" file and extracts the +# information needed to deduce build and src dependencies. +# +# To do this, we extract the 'CWD' record as well as all the +# syscall traces which describe 'R'ead, 'C'hdir and 'E'xec +# syscalls. +# +# The typical meta file looks like:: +#.nf +# +# # Meta data file "path" +# CMD "command-line" +# CWD "cwd" +# TARGET "target" +# -- command output -- +# -- filemon acquired metadata -- +# # buildmon version 2 +# V 2 +# E "pid" "path" +# R "pid" "path" +# C "pid" "cwd" +# R "pid" "path" +# X "pid" "status" +#.fi +# +# The fact that all the syscall entry lines start with a single +# character make these files quite easy to process using sed(1). +# +# To simplify the logic the 'CWD' line is made to look like a +# normal 'C'hdir entry, and "cwd" is remembered so that it can +# be prefixed to any "path" which is not absolute. +# +# If the "path" being read ends in '.srcrel' it is the content +# of (actually the first line of) that file that we are +# interested in. +# +# Any "path" which lies outside of the sandbox "SB" is generally +# not of interest and is ignored. +# +# The output, is a set of absolute paths with "SB" like: +#.nf +# +# $SB/obj-i386/bsd/gnu/lib/csu +# $SB/obj-i386/bsd/gnu/lib/libgcc +# $SB/obj-i386/bsd/include +# $SB/obj-i386/bsd/lib/csu/i386-elf +# $SB/obj-i386/bsd/lib/libc +# $SB/src/bsd/include +# $SB/src/bsd/sys/i386/include +# $SB/src/bsd/sys/sys +# $SB/src/pan-release/rtsock +# $SB/src/pfe-shared/include/jnx +#.fi +# +# Which can then be further processed by 'gendirdeps.mk' +# +# If we are passed 'DPDEPS='"dpdeps", then for each src file +# outside of "CURDIR" we read, we output a line like: +#.nf +# +# DPDEPS_$path += $RELDIR +#.fi +# +# with "$path" geting turned into reldir's, so that we can end +# up with a list of all the directories which depend on each src +# file in another directory. This can allow for efficient yet +# complete testing of changes. + + +# RCSid: +# $Id: meta2deps.sh,v 1.6 2013/05/11 05:16:26 sjg Exp $ + +# Copyright (c) 2010-2013, Juniper Networks, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +meta2src() { + cat /dev/null "$@" | + sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' | + sort -u +} + +meta2dirs() { + cat /dev/null "$@" | + sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' | + sort -u +} + +add_list() { + sep=' ' + suffix= + while : + do + case "$1" in + "|") sep="$1"; shift;; + -s) suffix="$2"; shift 2;; + *) break;; + esac + done + name=$1 + shift + eval list="\$$name" + for top in "$@" + do + case "$sep$list$sep" in + *"$sep$top$suffix$sep"*) continue;; + esac + list="${list:+$list$sep}$top$suffix" + done + eval "$name=\"$list\"" +} + +meta2deps() { + DPDEPS= + SRCTOPS=$SRCTOP + OBJROOTS= + while : + do + case "$1" in + *=*) eval export "$1"; shift;; + -a) MACHINE_ARCH=$2; shift 2;; + -m) MACHINE=$2; shift 2;; + -C) CURDIR=$2; shift 2;; + -H) HOST_TARGET=$2; shift 2;; + -S) add_list SRCTOPS $2; shift 2;; + -O) add_list OBJROOTS $2; shift 2;; + -R) RELDIR=$2; shift 2;; + -T) TARGET_SPEC=$2; shift 2;; + *) break;; + esac + done + + _th= _o= + case "$MACHINE" in + host) _ht=$HOST_TARGET;; + esac + + for o in $OBJROOTS + do + case "$MACHINE,/$o/" in + host,*$HOST_TARGET*) ;; + *$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;; + *) add_list _o $o; continue;; + esac + for x in $_ht $TARGET_SPEC $MACHINE + do + case "$o" in + "") continue;; + */$x/) add_list _o ${o%$x/}; o=;; + */$x) add_list _o ${o%$x}; o=;; + *$x/) add_list _o ${o%$x/}; o=;; + *$x) add_list _o ${o%$x}; o=;; + esac + done + done + OBJROOTS="$_o" + + case "$OBJTOP" in + "") + for o in $OBJROOTS + do + OBJTOP=$o${TARGET_SPEC:-$MACHINE} + break + done + ;; + esac + src_re= + obj_re= + add_list '|' -s '/*' src_re $SRCTOPS + add_list '|' -s '*' obj_re $OBJROOTS + + [ -z "$RELDIR" ] && unset DPDEPS + tf=/tmp/m2d$$-$USER + rm -f $tf.* + trap 'rm -f $tf.*; trap 0' 0 + + > $tf.dirdep + > $tf.qual + > $tf.srcdep + > $tf.srcrel + > $tf.dpdeps + + seenit= + seensrc= + lpid= + cat /dev/null "$@" | + sed -e 's,^CWD,C C,;/^[CREFL] /!d' -e "s,',,g" | + while read op pid path junk + do + : op=$op pid=$pid path=$path + # we track cwd and ldir (of interest) per pid + # CWD is bmake's cwd + case "$lpid,$pid" in + ,C) CWD=$path cwd=$path ldir=$path + if [ -z "$SB" ]; then + SB=`echo $CWD | sed 's,/obj.*,,'` + fi + SRCTOP=${SRCTOP:-$SB/src} + continue + ;; + $pid,$pid) ;; + *) + case "$lpid" in + "") ;; + *) eval ldir_$lpid=$ldir cwd_$lpid=$cwd;; + esac + eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD} + lpid=$pid + ;; + esac + + case "$op,$path" in + W,*srcrel|*.dirdep) continue;; + C,*) + case "$path" in + /*) cwd=$path;; + *) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;; + esac + # watch out for temp dirs that no longer exist + test -d ${cwd:-/dev/null/no/such} || cwd=$CWD + continue + ;; + F,*) eval cwd_$path=$cwd ldir_$path=$ldir + continue + ;; + *) dir=${path%/*} + case "$path" in + $src_re|$obj_re) ;; + /*/stage/*) ;; + /*) continue;; + *) for path in $ldir/$path $cwd/$path + do + test -e $path && break + done + dir=${path%/*} + ;; + esac + ;; + esac + # avoid repeating ourselves... + case "$DPDEPS,$seensrc," in + ,*) + case ",$seenit," in + *,$dir,*) continue;; + esac + ;; + *,$path,*) continue;; + esac + # canonicalize if needed + case "/$dir/" in + */../*|*/./*) + rdir=$dir + dir=`cd $dir 2> /dev/null && /bin/pwd` + seen="$rdir,$dir" + ;; + *) seen=$dir;; + esac + case "$dir" in + ${CURDIR:-.}|${CURDIR:-.}/*|"") continue;; + $src_re) + # avoid repeating ourselves... + case "$DPDEPS,$seensrc," in + ,*) + case ",$seenit," in + *,$dir,*) continue;; + esac + ;; + esac + ;; + *) + case ",$seenit," in + *,$dir,*) continue;; + esac + ;; + esac + if [ -d $path ]; then + case "$path" in + */..) ldir=${dir%/*};; + *) ldir=$path;; + esac + continue + fi + [ -f $path ] || continue + case "$dir" in + $CWD) continue;; # ignore + $src_re) + seenit="$seenit,$seen" + echo $dir >> $tf.srcdep + case "$DPDEPS,$reldir,$seensrc," in + ,*) ;; + *) seensrc="$seensrc,$path" + echo "DPDEPS_$dir/${path##*/} += $RELDIR" >> $tf.dpdeps + ;; + esac + continue + ;; + esac + # if there is a .dirdep we cannot skip + # just because we've seen the dir before. + if [ -s $path.dirdep ]; then + # this file contains: + # '# ${RELDIR}.' + echo $path.dirdep >> $tf.qual + continue + elif [ -s $dir.dirdep ]; then + echo $dir.dirdep >> $tf.qual + seenit="$seenit,$seen" + continue + fi + seenit="$seenit,$seen" + case "$dir" in + $obj_re) + echo $dir;; + esac + done > $tf.dirdep + _nl=echo + for f in $tf.dirdep $tf.qual $tf.srcdep + do + [ -s $f ] || continue + case $f in + *qual) # a list of .dirdep files + # we can prefix everthing with $OBJTOP to + # tell gendirdeps.mk that these are + # DIRDEP entries, since they are already + # qualified with . as needed. + # We strip .$MACHINE though + xargs cat < $f | sort -u | + sed "s,^# ,,;s,^,$OBJTOP/,;s,\.${TARGET_SPEC:-$MACHINE}\$,,;s,\.$MACHINE\$,," + ;; + *) sort -u $f;; + esac + _nl=: + done + if [ -s $tf.dpdeps ]; then + case "$DPDEPS" in + */*) ;; + *) echo > $DPDEPS;; # the echo is needed! + esac + sort -u $tf.dpdeps | + sed "s,${SRCTOP}/,,;s,${SB_BACKING_SB:-$SB}/src/,," >> $DPDEPS + fi + # ensure we produce _something_ else egrep -v gets upset + $_nl +} + +case /$0 in +*/meta2dep*) meta2deps "$@";; +*/meta2dirs*) meta2dirs "$@";; +*/meta2src*) meta2src "$@";; +esac diff --git a/contrib/bmake/mk/mk-files.txt b/contrib/bmake/mk/mk-files.txt new file mode 100644 index 0000000..7882641 --- /dev/null +++ b/contrib/bmake/mk/mk-files.txt @@ -0,0 +1,467 @@ +mk-files +******** + +The term ``mk-files`` refers to a collection of ``*.mk`` files. + +You need bmake_ or a *recent* NetBSD_ make. +If in doubt use bmake_. + +Introduction +============ + +Many years ago, when building large software projects, I used GNU make +(or my own patched version of it), and had developed a set of macros +to simplify developing complex build trees. + +Since the early 90's my main development machines, run BSD +(NetBSD_ to be precise), and the BSD source tree is good example of a +large software project. It quickly became clear that +``/usr/share/mk/*.mk`` were a great model, but were quite tightly +linked to building the BSD tree. + +Much as I liked using NetBSD, my customers were more likely to be +using SunOS, HP-UX etc, so I started on bmake_ and a portable collection +of mk-files (mk.tar.gz_). NetBSD provided much of the original structure. + +Since then I've added a lot of features to NetBSD's make and hence to +bmake which is kept closely in sync. The mk-files however have +diverged quite a bit, though ideas are still picked up from NetBSD. + +Basics +------ + +The BSD build model is very simple. A directory produces one +component, which is generally either a library or a program. +Library makefiles include ``lib.mk`` and programs include ``prog.mk`` +and they *do the right thing*. + +A simple library makefile might look like:: + + LIB = sig + + SRCS = \ + sigaction.c \ + sigcompat.c \ + sighdl.c + + .include + +a simple program makefile:: + + PROG = cat + + SRCS = cat.c + + .include + +in such cases even the ``SRCS`` line is unnecessary as ``prog.mk`` +will default it to ``${PROG}.c``. + +It is the sensible use of defaults and the plethora of macro modifiers +provided by bmake_ that allow simple makefiles such as the above +*just work* on many different systems. + + +mk-files +======== + +This section provides a brief description of some of the ``*.mk`` +files. + +sys.mk +------ + +When bmake starts, it looks for ``sys.mk`` and reads it before doing +anything else. Thus, this is the place to setup the environment for +everyone else. + +In this distribution, sys.mk avoids doing anything platform dependent. +It is quite short, and includes a number of other files (which may or +may not exists) + +sys.env.mk + If it exists, is expected to do things like conditioning the + environment. Since it will only be included by the initial + instance of bmake, it should ``.export`` anything that + sub-makes might need. + +examples/sys.clean-env.mk + An example of how to clean the environment. + See the file for all the details:: + + .if ${MAKE_VERSION} >= 20100606 && ${.MAKE.LEVEL} == 0 + # we save any env var that starts with these + MAKE_SAVE_ENV_PREFIX += SB MK MAKE MACHINE NEED_ CCACHE DISTCC USE_ SSH + MAKE_SAVE_ENV_VARS += \ + PATH HOME USER LOGNAME \ + SRCTOP OBJTOP OBJROOT \ + ${_env_vars} + + _env_vars != env | egrep '^(${MAKE_SAVE_ENV_PREFIX:ts|})' | sed 's,=.*,,'; echo + _export_list = + .for v in ${MAKE_SAVE_ENV_VARS:O:u} + .if !empty($v) + _export_list += $v + $v := ${$v} + .endif + .endfor + # now clobber the environment + .unexport-env + + # list of vars that we handle specially below + _tricky_env_vars = MAKEOBJDIR + # export our selection - sans tricky ones + .export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}} + + # this next bit may need tweaking + .if defined(MAKEOBJDIR) + srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}} + objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}} + # we'll take care of MACHINE below + objtop := ${OBJTOP:U${objroot}${MACHINE}} + .if !empty(objtop) + # we would normally want something like (/bin/sh): + # MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJROOT}\${MACHINE},}" + # the $$ below is how we achieve the same result here. + # since everything saved from the environment above + # has run through := we need to compensate for ${MACHINE} + MAKEOBJDIR = $${.CURDIR:S,${srctop},${objtop:S,${MACHINE},\${MACHINE},},} + + # export these as-is, and do not track... + .export-env ${_tricky_env_vars} + # now evaluate for ourselves + .for v in ${_tricky_env_vars} + $v := ${$v} + .endfor + + .endif + .endif + .endif + + +host-target.mk + Is used to set macros like ``HOST_TARGET``, ``HOST_OS`` and + ``host_os`` which are used to find the next step. + +sys/\*.mk + Platform specific additions, such as ``Darwin.mk`` or ``SunOS.mk`` + set things like ``HOST_LIBEXT = .dylib`` for Darwin or + ``SHLIB_FULLVERSION = ${SHLIB_MAJOR}`` for SunOS 5. + If there is no OS specific file, ``sys/Generic.mk`` is used. + +local.sys.mk + Any ``local.*.mk`` file is not part of the distribution. + This provides a hook for sites to do extra setup without + having to edit the distributed files. + + +The above arrangement makes it easy for the mk files to be part of a +src tree on an NFS volume and to allow building on multiple platforms. + +lib.mk +------ + +This file is used to build a number of different libraries from the +same SRCS. + +lib${LIB}.a + An archive lib of ``.o`` files, this is the default + +lib${LIB}_p.a + A profiled lib of ``.po`` files. + Still an archive lib, but all the objects are built with + profiling in mind - hence the different extension. + It is skipped if ``MKPROFILE`` is "no". + +lib${LIB}_pic.a + An archive of ``.so`` objects compiled for relocation. + On NetBSD this is the input to ``lib${LIB}.${LD_so}``, it is + skipped if ``MKPICLIB`` is "no". + +lib${LIB}.${LD_so} + A shared library. The value of ``LD_so`` is very platform + specific. For example:: + + # SunOS 5 and most other ELF systems + libsslfd.so.1 + + # Darwin + libsslfd.1.dylib + + This library will only be built if ``SHLIB_MAJOR`` has + a value, and ``MKPIC`` is not set to "no". + +There is a lot of platform specific tweaking in ``lib.mk``, largely the +result of the original distributions trying to avoid interfering with +the system's ``sys.mk``. + +libnames.mk +----------- + +This is included by both ``prog.mk`` and ``lib.mk`` and tries to +include ``*.libnames.mk`` of which: + +local.libnames.mk + does not exist unless you create it. It is a handy way for you + to customize without touching the distributed files. + For example, on a test machine I needed to build openssl but + not install it, so put the following in ``local.libnames.mk``:: + + .if ${host_os} == "sunos" + LIBCRYPTO = ${OBJTOP}/openssl/lib/crypto/libcrypto${DLIBEXT} + LIBSSL = ${OBJTOP}/openssl/lib/ssl/libssl${DLIBEXT} + INCLUDES_libcrypto = -I${OBJ_libcrypto} + .endif + + The makefile created an openssl dir in ``${OBJ_libcrypto}`` to + gather all the headers. dpadd.mk_ did the rest. + +sjg.libnames.mk + not part of the mk-files distribution. + +host.libnames.mk + contains logic to find any libs named in ``HOST_LIBS`` in + ``HOST_LIBDIRS``. + +Each file above gets an opportunity to define things like:: + + LIBSSLFD ?= ${OBJTOP}/ssl/lib/sslfd/libsslfd${DLIBEXT} + INCLUDES_libsslfd = -I${SRC_libsslfd}/h -I${OBJ_libslfd} + +these are used by dpadd.mk_ and will be explained below. + +dpadd.mk +-------- + +This file looks like line noise, and is best considered read-only. +However it provides some very useful functionality, which simplifies the build. + +Makefiles can use the LIB* macros defined via libnames.mk_ or anywhere +else in various ways:: + + # indicate that we need to include headers from LIBCRYPTO + # this would result in ${INCLUDES_libcrypto} being added to CFLAGS. + SRC_LIBS += ${LIBCRYPTO} + + # indicate that libsslfd must be built already. + # it also has the same effect as SRC_LIBS + DPADD += ${LIBSSLFD} + + # indicate that not only must libsslfd be built, + # but that we need to link with it. + # this is almost exactly equivalent to + # DPADD += ${LIBSSLFD} + # LDADD += -L${LIBSSLFD:H} -lsslfd + # and mostly serves to ensure that DPADD and LDADD are in sync. + DPLIBS += ${LIBSSLFD} + +Any library (referenced by its full path) in any of the above, is +added to ``DPMAGIC_LIBS`` with the following results, for each lib *foo*. + +SRC_libfoo + Is set to indicate where the src for libfoo is. + By default it is derived from ``LIBFOO`` by replacing + ``${OBJTOP}`` with ``${SRCTOP}``. + +OBJ_libfoo + Not very exciting, is just the dir where libfoo lives. + +INCLUDES_libfoo + What to add to ``CFLAGS`` to find the public headers. + The default varies. If ``${SRC_libfoo}/h`` exists, it is assumed + to be the home of all public headers and thus the default is + ``-I${SRC_libfoo}/h`` + + Otherwise we make no assumptions and the default is + ``-I${SRC_libfoo} -I${OBJ_libfoo}`` + +LDADD_libfoo + This only applies to libs reference via ``DPLIBS``. + The default is ``-lfoo``, ``LDADD_*`` provides a hook to + instantiate other linker flags at the appropriate point + without losing the benfits of ``DPLIBS``. + +prog.mk +------- + +Compiles the specified SRCS and links them and the nominated libraries +into a program. Prog makefiles usually need to list the libraries +that need to be linked. We prefer use of ``DPLIBS`` but the more +traditional ``DPADD`` and ``LDADD`` work just as well. +That is:: + + DPLIBS += ${LIBCRYPTO} + +is equivalent to:: + + DPADD += ${LIBCRYPTO} + LDADD += -lcrypto + +obj.mk +------ + +One of the cool aspects of BSD make, is its support for separating +object files from the src tree. This is also the source of much +confusion to some. + +Traditionally one had to do a separate ``make obj`` pass through the +tree. If ``MKOBJDIRS`` is "auto", we include auto.obj.mk_. + +auto.obj.mk +----------- + +This leverages the ``.OBJDIR`` target introduced some years ago to +NetBSD make, to automatically create the desired object dir. + +subdir.mk +--------- + +This is the traditional means of walking the tree. A makefile sets +``SUBDIR`` to the list of sub-dirs to visit. + +If ``SUBDIR_MUST_EXIST`` is set, missing directories cause an error, +otherwise a warning is issued. If you don't even want the warning, +set ``MISSING_DIR=continue``. + +Traditionally, ``subdir.mk`` prints clue as it visits each subdir:: + + ===> ssl + ===> ssl/lib + ===> ssl/lib/sslfd + +you can suppress that - or enhance it by setting ``ECHO_DIR``:: + + # suppress subdir noise + ECHO_DIR=: + # print time stamps + ECHO_DIR=echo @ `date "+%s [%Y-%m-%d %T] "` + +links.mk +-------- + +Provides rules for processing lists of ``LINKS`` and ``SYMLINKS``. +Each is expected to be a list of ``link`` and ``target`` pairs +(``link`` -> ``target``). + +The logic is generally in a ``_*_SCRIPT`` which is referenced in a +``_*_USE`` (``.USE``) target. + +The ``_BUILD_*`` forms are identical, but do not use ``${DESTDIR}`` +and so are useful for creating symlinks during the build phase. +For example:: + + SYMLINKS += ${.CURDIR}/${MACHINE_ARCH}/include machine + header_links: _BUILD_SYMLINKS_USE + + md.o: header_links + +would create a symlink called ``machine`` in ``${.OBJDIR}`` pointing to +``${.CURDIR}/${MACHINE_ARCH}/include`` before compiling ``md.o`` + + +autoconf.mk +----------- + +Deals with running (or generating) GNU autoconf ``configure`` scripts. + +dep.mk +------ + +Deals with collecting dependencies. Another useful feature of BSD +make is the separation of this sort of information into a ``.depend`` +file. ``MKDEP`` needs to point to a suitable tool (like mkdeps.sh_) + +If ``USE_AUTODEP_MK`` is "yes" includes autodep.mk_ + +autodep.mk +---------- + +Leverages the ``-MD`` feature of recent GCC to collect dependency +information as a side effect of compilation. With this GCC puts +dependency info into a ``.d`` file. + +Unfortunately GCC bases the name of the ``.d`` file on the name of the +input rather than the output file, which causes problems when the same +source is compiled different ways. The latest GCC supports ``-MF`` to +name the ``.d`` file and ``-MT`` to control the name to put as the +dependent. + +Recent bmake allows dependencies for the ``.END`` target (run at the +end if everything was successful), and ``autodep.mk`` uses this to +post process the ``.d`` files into ``.depend``. + +auto.dep.mk +----------- + +A much simpler implementation than autodep.mk_ it uses +``-MF ${.TARGET:T}.d`` +to avoid possible conflicts during parallel builds. +This precludes the use of suffix rules to drive ``make depend``, so +dep.mk_ handles that if specifically requested. + +own.mk +------ + +Normally included by ``init.mk`` (included by ``lib.mk`` and +``prog.mk`` etc), sets macros for default ownership etc. + +It includes ``${MAKECONF}`` if it is defined and exists. + +man.mk +------ + +Deals with man pages. + +warnings.mk +----------- + +This provides a means of fine grained control over warnings on a per +``${MACHINE}`` or even file basis. + +A makefile sets ``WARNINGS_SET`` to name a list of warnings +and individual ``W_*`` macros can be used to tweak them. +For example:: + + WARNINGS_SET = HIGH + W_unused_sparc = -Wno-unused + +would add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but +on sparc, ``-Wno-unused`` would replace ``-Wunused``. + +You should never need to edit ``warnings.mk``, it will include +``warnings-sets.mk`` if it exists and you use that to make any local +customizations. + +Meta mode +========= + +The 20110505 and later versions of ``mk-files`` include a number of +makefile contributed by Juniper Networks, Inc. +These allow the latest version of bmake_ to run in `meta mode`_. + +.. _`meta mode`: bmake-meta-mode.htm + +Install +======= + +You can use the content of mk.tar.gz_ without installing at all. + +The script ``install-mk`` takes care of copying ``*.mk`` into a +destination directory, and unless told not to, create ``bsd.*.mk`` links +for ``lib.mk`` etc. + +If you just want to create the ``bsd.*.mk`` links in the directory +where you unpacked the tar file, you can:: + + ./mk/install-mk ./mk + +------ + +.. _bmake: bmake.htm +.. _NetBSD: http://www.netbsd.org/ +.. _mkdeps.sh: http://www.crufty.net/ftp/pub/sjg/mkdeps.sh +.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz + +:Author: sjg@crufty.net +:Revision: $Id: mk-files.txt,v 1.15 2011/06/08 07:06:18 sjg Exp $ +:Copyright: Crufty.NET diff --git a/contrib/bmake/mk/nls.mk b/contrib/bmake/mk/nls.mk new file mode 100644 index 0000000..e302c8d --- /dev/null +++ b/contrib/bmake/mk/nls.mk @@ -0,0 +1,48 @@ +# $NetBSD: bsd.nls.mk,v 1.3 1996/10/18 02:34:45 thorpej Exp $ + +.if !target(.MAIN) +.if exists(${.CURDIR}/../Makefile.inc) +.include "${.CURDIR}/../Makefile.inc" +.endif + +.MAIN: all +.endif + +.SUFFIXES: .cat .msg + +.msg.cat: + @rm -f ${.TARGET} + gencat ${.TARGET} ${.IMPSRC} + +.if defined(NLS) && !empty(NLS) +NLSALL= ${NLS:.msg=.cat} +.NOPATH: ${NLSALL} +.endif + +.if !defined(NLSNAME) +.if defined(PROG) +NLSNAME=${PROG} +.else +NLSNAME=lib${LIB} +.endif +.endif + +nlsinstall: +.if defined(NLSALL) + @for msg in ${NLSALL}; do \ + NLSLANG=`basename $$msg .cat`; \ + dir=${DESTDIR}${NLSDIR}/$${NLSLANG}; \ + ${INSTALL} -d $$dir; \ + ${INSTALL} ${COPY} -o ${NLSOWN} -g ${NLSGRP} -m ${NLSMODE} $$msg $$dir/${NLSNAME}.cat; \ + done +.endif + +.if defined(NLSALL) +all: ${NLSALL} + +install: nlsinstall + +cleandir: cleannls +cleannls: + rm -f ${NLSALL} +.endif diff --git a/contrib/bmake/mk/obj.mk b/contrib/bmake/mk/obj.mk new file mode 100644 index 0000000..b936379 --- /dev/null +++ b/contrib/bmake/mk/obj.mk @@ -0,0 +1,113 @@ +# $Id: obj.mk,v 1.15 2012/11/11 22:37:02 sjg Exp $ +# +# @(#) Copyright (c) 1999-2010, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE:S,bsd.,,}__) +__${.PARSEFILE:S,bsd.,,}__: + +.include + +ECHO_TRACE ?= echo + +.if ${MK_OBJDIRS} == "no" +obj: +objlink: +objwarn: +.else + +# this has to match how make behaves +.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR) +.if defined(MAKEOBJDIRPREFIX) +__objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR} +.else +__objdir:= ${MAKEOBJDIR} +.endif +.else +__objdir= ${__objlink} +.endif + +.if defined(OBJMACHINE) +__objlink= obj.${MACHINE} +.else +__objlink= obj +.endif + +.if ${MK_AUTO_OBJ} == "yes" +.-include "auto.obj.mk" +.endif + +.NOPATH: ${__objdir} +.PHONY: obj + +obj: _SUBDIRUSE + @if test ! -d ${__objdir}/.; then \ + mkdir -p ${__objdir}; \ + if test ! -d ${__objdir}; then \ + mkdir ${__objdir}; exit 1; \ + fi; \ + ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \ + fi + +.if !target(_SUBDIRUSE) +# this just allows us to be included by ourselves +_SUBDIRUSE: +.endif + +# so we can interact with freebsd makefiles +.if !target(objwarn) +objwarn: +.if ${.OBJDIR} == ${.CURDIR} + @echo "Warning Object directory is ${.CURDIR}" +.elif ${.OBJDIR} != ${__objdir} + @echo "Warning Object directory is ${.OBJDIR} vs. ${__objdir}" +.endif +.endif + +.if !target(objlink) +objlink: +.if ${__objdir:T} != ${__objlink} + @if test -d ${__objdir}/.; then \ + ${RM} -f ${.CURDIR}/${__objlink}; \ + ${LN} -s ${__objdir} ${.CURDIR}/${__objlink}; \ + echo "${__objlink} -> ${__objdir}"; \ + else \ + echo "No ${__objdir} to link to - do a 'make obj'"; \ + fi +.endif +.endif +.endif + +_CURDIR?= ${.CURDIR} +_OBJDIR?= ${.OBJDIR} + +.if !target(print-objdir) +print-objdir: + @echo ${_OBJDIR} +.endif + +.if !target(whereobj) +whereobj: + @echo ${_OBJDIR} +.endif + +.if !target(destroy) +.if ${.CURDIR} != ${.OBJDIR} +destroy: + (cd ${_CURDIR} && rm -rf ${_OBJDIR}) +.else +destroy: clean +.endif +.endif + +.endif diff --git a/contrib/bmake/mk/options.mk b/contrib/bmake/mk/options.mk new file mode 100644 index 0000000..aa54754 --- /dev/null +++ b/contrib/bmake/mk/options.mk @@ -0,0 +1,59 @@ +# $Id: options.mk,v 1.7 2013/04/17 20:32:38 sjg Exp $ +# +# @(#) Copyright (c) 2012, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# Inspired by FreeBSD bsd.own.mk, but intentionally simpler and more flexible. + +# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO} +# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES. +# We add the OPTIONS_DEFAULT_NO first so they take precedence. +# This allows override of an OPTIONS_DEFAULT_YES by adding it to +# OPTIONS_DEFAULT_NO or adding ${OPTION}/no to OPTIONS_DEFAULT_VALUES. +# An OPTIONS_DEFAULT_NO option can only be overridden by putting +# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES. +# A makefile may set NO_* (or NO*) to indicate it cannot do something. +# User sets WITH_* and WITHOUT_* to indicate what they want. +# We set ${OPTION_PREFIX:UMK_}* which is then all we need care about. +OPTIONS_DEFAULT_VALUES += \ + ${OPTIONS_DEFAULT_NO:O:u:S,$,/no,} \ + ${OPTIONS_DEFAULT_YES:O:u:S,$,/yes,} + +OPTION_PREFIX ?= MK_ +.for o in ${OPTIONS_DEFAULT_VALUES:M*/*} +.if ${o:T:tl} == "no" +.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H}) +${OPTION_PREFIX}${o:H} ?= yes +.else +${OPTION_PREFIX}${o:H} ?= no +.endif +.else +.if defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H}) +${OPTION_PREFIX}${o:H} ?= no +.else +${OPTION_PREFIX}${o:H} ?= yes +.endif +.endif +.endfor + +# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO +# if neither WITH[OUT]_FOO_UTILS is set, use value of ${OPTION_PREFIX}FOO +.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u} +.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H}) +${OPTION_PREFIX}${o:H} ?= yes +.elif defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H}) +${OPTION_PREFIX}${o:H} ?= no +.else +${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}} +.endif +.endfor diff --git a/contrib/bmake/mk/own.mk b/contrib/bmake/mk/own.mk new file mode 100644 index 0000000..e29ff9e --- /dev/null +++ b/contrib/bmake/mk/own.mk @@ -0,0 +1,245 @@ +# $Id: own.mk,v 1.27 2013/07/18 05:46:24 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.if !target(__init.mk__) +.include "init.mk" +.endif + +.ifndef NOMAKECONF +MAKECONF?= /etc/mk.conf +.-include "${MAKECONF}" +.endif + +.include + +TARGET_OSNAME?= ${_HOST_OSNAME} +TARGET_OSREL?= ${_HOST_OSREL} +TARGET_OSTYPE?= ${HOST_OSTYPE} +TARGET_HOST?= ${HOST_TARGET} + +# these may or may not exist +.-include "${TARGET_HOST}.mk" +.-include "config.mk" + +RM?= rm +LN?= ln +INSTALL?= install + +prefix?= /usr +.if exists(${prefix}/lib) +libprefix?= ${prefix} +.else +libprefix?= /usr +.endif + +# FreeBSD at least does not set this +MACHINE_ARCH?=${MACHINE} +# we need to make sure these are defined too in case sys.mk fails to. +COMPILE.s?= ${CC} ${AFLAGS} -c +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} +LEX.l?= ${LEX} ${LFLAGS} +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} +YACC.y?= ${YACC} ${YFLAGS} + +# for suffix rules +IMPFLAGS?= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} +.for s in .c .cc +COMPILE.$s += ${IMPFLAGS} +LINK.$s += ${IMPFLAGS} +.endfor + +PRINT.VAR.MAKE = MAKESYSPATH=${MAKESYSPATH:U${.PARSEDIR}} ${.MAKE} +.if empty(.MAKEFLAGS:M-V*) +.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR) +PRINTOBJDIR= ${PRINT.VAR.MAKE} -r -V .OBJDIR -f /dev/null xxx +.else +PRINTOBJDIR= ${PRINT.VAR.MAKE} -V .OBJDIR +.endif +.else +PRINTOBJDIR= echo # prevent infinite recursion +.endif + +# we really like to have SRCTOP and OBJTOP defined... +.if !defined(SRCTOP) || !defined(OBJTOP) +.-include "srctop.mk" +.endif + +.if !defined(SRCTOP) || !defined(OBJTOP) +# dpadd.mk is rather pointless without these +OPTIONS_DEFAULT_NO+= DPADD_MK +.endif + +# process options +OPTIONS_DEFAULT_NO+= \ + INSTALL_AS_USER \ + GPROF \ + LIBTOOL \ + LINT \ + META_MODE \ + +OPTIONS_DEFAULT_YES+= \ + ARCHIVE \ + AUTODEP \ + AUTO_OBJ \ + CRYPTO \ + DOC \ + DPADD_MK \ + GDB \ + KERBEROS \ + LINKLIB \ + MAN \ + NLS \ + OBJ \ + PIC \ + SHARE \ + SKEY \ + YP \ + +OPTIONS_DEFAULT_DEPENDENT+= \ + CATPAGES/MAN \ + OBJDIRS/OBJ \ + PICINSTALL/LINKLIB \ + PICLIB/PIC \ + PROFILE/LINKLIB \ + +.include + +.if ${MK_INSTALL_AS_USER} == "yes" +# We ignore this if user is root. +_uid!= id -u +.if ${_uid} != 0 +.if !defined(USERGRP) +USERGRP!= id -g +.export USERGRP +.endif +.for x in BIN CONF DOC INFO KMOD LIB MAN NLS SHARE +$xOWN= ${USER} +$xGRP= ${USERGRP} +.endfor +.endif +.endif + +# override this in sys.mk +ROOT_GROUP?= wheel +BINGRP?= ${ROOT_GROUP} +BINOWN?= root +BINMODE?= 555 +NONBINMODE?= 444 + +# Define MANZ to have the man pages compressed (gzip) +#MANZ= 1 + +MANTARGET?= cat +MANDIR?= ${prefix}/share/man/${MANTARGET} +MANGRP?= ${BINGRP} +MANOWN?= ${BINOWN} +MANMODE?= ${NONBINMODE} + +LIBDIR?= ${libprefix}/lib +SHLIBDIR?= ${libprefix}/lib +.if ${USE_SHLIBDIR:Uno} == "yes" +_LIBSODIR?= ${SHLIBDIR} +.else +_LIBSODIR?= ${LIBDIR} +.endif +# this is where ld.*so lives +SHLINKDIR?= /usr/libexec +LINTLIBDIR?= ${libprefix}/libdata/lint +LIBGRP?= ${BINGRP} +LIBOWN?= ${BINOWN} +LIBMODE?= ${NONBINMODE} + +DOCDIR?= ${prefix}/share/doc +DOCGRP?= ${BINGRP} +DOCOWN?= ${BINOWN} +DOCMODE?= ${NONBINMODE} + +NLSDIR?= ${prefix}/share/nls +NLSGRP?= ${BINGRP} +NLSOWN?= ${BINOWN} +NLSMODE?= ${NONBINMODE} + +KMODDIR?= ${prefix}/lkm +KMODGRP?= ${BINGRP} +KMODOWN?= ${BINOWN} +KMODMODE?= ${NONBINMODE} + +COPY?= -c +STRIP_FLAG?= -s + +.if ${TARGET_OSNAME} == "NetBSD" +.if exists(/usr/libexec/ld.elf_so) +OBJECT_FMT=ELF +.endif +OBJECT_FMT?=a.out +.endif +# sys.mk should set something appropriate if need be. +OBJECT_FMT?=ELF + +.if (${_HOST_OSNAME} == "FreeBSD") +CFLAGS+= ${CPPFLAGS} +.endif + +# allow for per target flags +# apply the :T:R first, so the more specific :T can override if needed +CPPFLAGS += ${CPPFLAGS_${.TARGET:T:R}} ${CPPFLAGS_${.TARGET:T}} +CFLAGS += ${CFLAGS_${.TARGET:T:R}} ${CFLAGS_${.TARGET:T}} + +# Define SYS_INCLUDE to indicate whether you want symbolic links to the system +# source (``symlinks''), or a separate copy (``copies''); (latter useful +# in environments where it's not possible to keep /sys publicly readable) +#SYS_INCLUDE= symlinks + +# don't try to generate PIC versions of libraries on machines +# which don't support PIC. +.if (${MACHINE_ARCH} == "vax") || \ + ((${MACHINE_ARCH} == "mips") && defined(STATIC_TOOLCHAIN)) || \ + ((${MACHINE_ARCH} == "alpha") && defined(ECOFF_TOOLCHAIN)) +MK_PIC=no +.endif + +# No lint, for now. +NOLINT= + + +.if ${MK_LINKLIB} == "no" +MK_PICINSTALL= no +MK_PROFILE= no +.endif + +.if ${MK_MAN} == "no" +MK_CATPAGES= no +.endif + +.if ${MK_OBJ} == "no" +MK_OBJDIRS= no +MK_AUTO_OBJ= no +.endif + +.if ${MK_SHARE} == "no" +MK_CATPAGES= no +MK_DOC= no +MK_INFO= no +MK_MAN= no +MK_NLS= no +.endif + +.endif diff --git a/contrib/bmake/mk/prlist.mk b/contrib/bmake/mk/prlist.mk new file mode 100644 index 0000000..09d7dfd --- /dev/null +++ b/contrib/bmake/mk/prlist.mk @@ -0,0 +1,36 @@ +# $Id: prlist.mk,v 1.3 2008/07/17 16:24:57 sjg Exp $ +# +# @(#) Copyright (c) 2006, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +# this needs to be included after all the lists it will process +# are defined - which is why it is a separate file. +# Usage looks like: +# MAKEFLAGS= ${.MAKE} -f ${MAKEFILE} prlist.SOMETHING_HUGE | xargs whatever +# +.if make(prlist.*) +.for t in ${.TARGETS:Mprlist.*:E} +.if empty($t) +prlist.$t: +.else +prlist.$t: ${$t:O:u:S,^,prlist-,} +${$t:O:u:S,^,prlist-,}: .PHONY + @echo "${.TARGET:S,prlist-,,}" +.endif +.endfor +.endif + +.endif diff --git a/contrib/bmake/mk/prog.mk b/contrib/bmake/mk/prog.mk new file mode 100644 index 0000000..3a7a07e --- /dev/null +++ b/contrib/bmake/mk/prog.mk @@ -0,0 +1,228 @@ +# $Id: prog.mk,v 1.25 2013/07/18 05:46:24 sjg Exp $ + +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: + +.include + +# FreeBSD at least expects MAN8 etc. +.if defined(MAN) && !empty(MAN) +_sect:=${MAN:E} +MAN${_sect}=${MAN} +.endif + +.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0 + +CFLAGS+= ${COPTS} + +.if ${TARGET_OSNAME} == "NetBSD" +.if ${MACHINE_ARCH} == "sparc64" +CFLAGS+= -mcmodel=medlow +.endif + +# ELF platforms depend on crtbegin.o and crtend.o +.if ${OBJECT_FMT} == "ELF" +.ifndef LIBCRTBEGIN +LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o +.MADE: ${LIBCRTBEGIN} +.endif +.ifndef LIBCRTEND +LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o +.MADE: ${LIBCRTEND} +.endif +_SHLINKER= ${SHLINKDIR}/ld.elf_so +.else +LIBCRTBEGIN?= +LIBCRTEND?= +_SHLINKER= ${SHLINKDIR}/ld.so +.endif + +.ifndef LIBCRT0 +LIBCRT0= ${DESTDIR}/usr/lib/crt0.o +.MADE: ${LIBCRT0} +.endif +.endif # NetBSD + +# here is where you can define what LIB* are +.-include +.if ${MK_DPADD_MK} == "yes" +# lots of cool magic, but might not suit everyone. +.include +.endif + +.if ${MK_GPROF} == "yes" +CFLAGS+= ${CC_PG} ${PROFFLAGS} +LDADD+= ${CC_PG} +.if ${MK_DPADD_MK} == "no" +LDADD_LIBC_P?= -lc_p +LDADD_LAST+= ${LDADD_LIBC_P} +.endif +.endif + +.if defined(SHAREDSTRINGS) +CLEANFILES+=strings +.c.o: + ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c - + @${CC} ${CFLAGS} -c x.c -o ${.TARGET} + @rm -f x.c + +.cc.o: + ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - + @mv -f x.c x.cc + @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET} + @rm -f x.cc + +.C.o: + ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - + @mv -f x.c x.C + @${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET} + @rm -f x.C +.endif + + +.if defined(PROG) +SRCS?= ${PROG}.c +.for s in ${SRCS:N*.h:N*.sh:M*/*} +${.o .po .lo:L:@o@${s:T:R}$o@}: $s +.endfor +.if !empty(SRCS:N*.h:N*.sh) +OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} +LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} +.endif + +.if defined(OBJS) && !empty(OBJS) +.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} + +# this is known to work for NetBSD 1.6 and FreeBSD 4.2 +.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" +_PROGLDOPTS= +.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves +_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} +.endif +.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} +_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ + -L${DESTDIR}${SHLIBDIR} +.endif +_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib + +.if defined(PROG_CXX) +_CCLINK= ${CXX} +_SUPCXX= -lstdc++ -lm +.endif +.endif # NetBSD + +_CCLINK?= ${CC} + +.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" + +${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} + ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND} + +.else + +${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} + ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD} + +.endif # defined(DESTDIR) +.endif # defined(OBJS) && !empty(OBJS) + +.if !defined(MAN) +MAN= ${PROG}.1 +.endif # !defined(MAN) +.endif # defined(PROG) + +.if !defined(_SKIP_BUILD) +all: ${PROG} +.endif +all: _SUBDIRUSE + +.if !target(clean) +cleanprog: + rm -f a.out [Ee]rrs mklog core *.core \ + ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} + +clean: _SUBDIRUSE cleanprog +cleandir: _SUBDIRUSE cleanprog +.else +cleandir: _SUBDIRUSE clean +.endif + +.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) +.endif + +.if !target(install) +.if !target(beforeinstall) +beforeinstall: +.endif +.if !target(afterinstall) +afterinstall: +.endif + +.if !empty(BINOWN) +PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} +.endif + +.if !target(realinstall) +realinstall: proginstall +.endif +.if !target(proginstall) +proginstall: +.if defined(PROG) + [ -d ${DESTDIR}${BINDIR} ] || \ + ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} + ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ + ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} +.endif +.if defined(HIDEGAME) + (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) +.endif +.endif + +.include + +install: maninstall install_links _SUBDIRUSE + +install_links: +.if !empty(SYMLINKS) + @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} +.endif +.if !empty(LINKS) + @set ${LINKS}; ${_LINKS_SCRIPT} +.endif + +maninstall: afterinstall +afterinstall: realinstall +realinstall: beforeinstall +.endif + +.if !target(lint) +lint: ${LOBJS} +.if defined(LOBJS) && !empty(LOBJS) + @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} +.endif +.endif + +.NOPATH: ${PROG} +.if defined(OBJS) && !empty(OBJS) +.NOPATH: ${OBJS} +.endif + +.if ${MK_MAN} != "no" +.include +.endif + +.if ${MK_NLS} != "no" +.include +.endif + +.include +.include +.include +.include + +.endif diff --git a/contrib/bmake/mk/progs.mk b/contrib/bmake/mk/progs.mk new file mode 100644 index 0000000..7ccebbf --- /dev/null +++ b/contrib/bmake/mk/progs.mk @@ -0,0 +1,102 @@ +# $Id: progs.mk,v 1.13 2013/08/02 18:28:48 sjg Exp $ +# +# @(#) Copyright (c) 2006, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.MAIN: all + +.if defined(PROGS) + +# In meta mode, we can capture dependenices for _one_ of the progs. +# if makefile doesn't nominate one, we use the first. +.ifndef UPDATE_DEPENDFILE_PROG +UPDATE_DEPENDFILE_PROG = ${PROGS:[1]} +.export UPDATE_DEPENDFILE_PROG +.endif + +.ifndef PROG +# They may have asked us to build just one +.for t in ${PROGS} +.if make($t) +PROG ?= $t +.endif +.endfor +.endif + +.if defined(PROG) +# just one of many +PROG_VARS += \ + BINDIR \ + CFLAGS \ + COPTS \ + CPPFLAGS \ + CXXFLAGS \ + DPADD \ + DPLIBS \ + LDADD \ + LDFLAGS \ + MAN \ + SRCS + +.for v in ${PROG_VARS:O:u} +.if defined(${v}.${PROG}) || defined(${v}_${PROG}) +$v += ${${v}_${PROG}:U${${v}.${PROG}}} +.endif +.endfor + +# for meta mode, there can be only one! +.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno} +UPDATE_DEPENDFILE ?= yes +.endif +UPDATE_DEPENDFILE ?= NO + +# ensure that we don't clobber each other's dependencies +DEPENDFILE?= .depend.${PROG} +# prog.mk will do the rest +.else +all: ${PROGS} + +# We cannot capture dependencies for meta mode here +UPDATE_DEPENDFILE = NO +# nor can we safely run in parallel. +.NOTPARALLEL: +.endif +.endif + +# handle being called [bsd.]progs.mk +.include <${.PARSEFILE:S,progs,prog,}> + +.ifndef PROG +# tell progs.mk we might want to install things +PROGS_TARGETS+= cleandepend cleandir cleanobj depend install + +.for p in ${PROGS} +.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) +# bsd.prog.mk may need to know this +x.$p= PROG_CXX=$p +.endif + +$p ${p}_p: .PHONY .MAKE + (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p}) + +.for t in ${PROGS_TARGETS:O:u} +$p.$t: .PHONY .MAKE + (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E}) +.endfor +.endfor + +.for t in ${PROGS_TARGETS:O:u} +$t: ${PROGS:%=%.$t} +.endfor + +.endif diff --git a/contrib/bmake/mk/rst2htm.mk b/contrib/bmake/mk/rst2htm.mk new file mode 100644 index 0000000..8bd66da --- /dev/null +++ b/contrib/bmake/mk/rst2htm.mk @@ -0,0 +1,43 @@ +# $Id: rst2htm.mk,v 1.8 2011/04/03 21:39:25 sjg Exp $ +# +# @(#) Copyright (c) 2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# convert reStructuredText to HTML, using rst2html.py from +# docutils - http://docutils.sourceforge.net/ + +.if empty(TXTSRCS) +TXTSRCS != 'ls' -1t ${.CURDIR}/*.txt ${.CURDIR}/*.rst 2>/dev/null; echo +.endif +RSTSRCS ?= ${TXTSRCS} +HTMFILES ?= ${RSTSRCS:R:T:O:u:%=%.htm} +RST2HTML ?= rst2html.py +RST2S5 ?= rst2s5.py +# the following will run RST2S5 if the target name contains the word 'slides' +# otherwise it uses RST2HTML +RST2HTM = ${"${.TARGET:T:M*slides*}":?${RST2S5} ${RST2S5_FLAGS}:${RST2HTML} ${RST2HTML_FLAGS}} + +RST_SUFFIXES ?= .rst .txt + +CLEANFILES += ${HTMFILES} + +html: ${HTMFILES} + +.SUFFIXES: ${RST_SUFFIXES} .htm + +${RST_SUFFIXES:@s@$s.htm@}: + ${RST2HTM} ${.IMPSRC} ${.TARGET} + +.for s in ${RSTSRCS:O:u} +${s:R:T}.htm: $s +.endfor diff --git a/contrib/bmake/mk/scripts.mk b/contrib/bmake/mk/scripts.mk new file mode 100644 index 0000000..efd65f9 --- /dev/null +++ b/contrib/bmake/mk/scripts.mk @@ -0,0 +1,52 @@ +# $Id: scripts.mk,v 1.2 2006/11/09 01:55:18 sjg Exp $ + +.include + +.if defined(SCRIPTS) + +all: ${SCRIPTS} + +.PHONY: scriptsinstall +install: scriptsinstall + +.if !target(scriptsinstall) +SCRIPTSDIR?= ${BINDIR} +SCRIPTSOWN?= ${BINOWN} +SCRIPTSGRP?= ${BINGRP} +SCRIPTSMODE?= ${BINMODE} + +# how we get script name from src +SCRIPTSNAME_MOD?=T:R + +script_targets= ${SCRIPTS:@s@${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}@} + +scriptsinstall:: ${script_targets} + +.PRECIOUS: ${script_targets} +.if !defined(UPDATE) +.PHONY: ${script_targets} +.endif + +INSTALL_FLAGS?= ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} \ + -o ${OWN_${.TARGET:T}:U${SCRIPTSOWN}} \ + -g ${GRP_${.TARGET:T}:U${SCRIPTSGRP}} \ + -m ${MODE_${.TARGET:T}:U${SCRIPTSMODE}} + +__SCRIPTINSTALL_USE: .USE + ${INSTALL} ${INSTALL_FLAGS_${.TARGET:T}:U${INSTALL_FLAGS}} \ + ${.ALLSRC} ${.TARGET} + +.for s in ${SCRIPTS} +.if !defined(BUILD) && !make(all) && !make(${s}) +${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}: .MADE +.endif +${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}: ${s} __SCRIPTINSTALL_USE +.endfor +.endif + +.endif + +.if !target(scriptsinstall) +scriptsinstall:: +.endif + diff --git a/contrib/bmake/mk/srctop.mk b/contrib/bmake/mk/srctop.mk new file mode 100644 index 0000000..fab090c --- /dev/null +++ b/contrib/bmake/mk/srctop.mk @@ -0,0 +1,66 @@ +# $Id: srctop.mk,v 1.3 2012/11/11 23:20:18 sjg Exp $ +# +# @(#) Copyright (c) 2012, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.if !defined(SRCTOP) +# if using mk(1) SB will be set. +.ifdef SB +.if ${.CURDIR:S,${SB},,} != ${.CURDIR} +# we are actually within SB +.ifdef SB_SRC +SRCTOP:= ${SB_SRC} +.elif exists(${SB}/src) +SRCTOP:= ${SB}/src +.else +SRCTOP:= ${SB} +.endif +.endif +.endif + +.if !defined(SRCTOP) +.for rd in share/mk build/mk mk +.if ${_this_mk_dir:M*${rd}} != "" +.if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR} +SRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}} +.endif +.endif +.endfor +.endif + +.if !defined(SRCTOP) +_SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ] +# Linux at least has a bug where attempting to check an automounter +# directory will hang. So avoid looking above /a/b +SRCTOP!= cd ${.CURDIR}; while :; do \ + here=`pwd`; \ + ${_SRCTOP_TEST_} && { echo $$here; break; }; \ + case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \ + done +.endif +.if defined(SRCTOP) && exists(${SRCTOP}/.) +.export SRCTOP +.endif +.endif + +.if !defined(OBJTOP) && !empty(SRCTOP) +.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP}) +OBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP} +.elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile)) +OBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR} +.endif +.if empty(OBJTOP) +OBJTOP= ${SRCTOP} +.endif +.export OBJTOP +.endif diff --git a/contrib/bmake/mk/stage-install.sh b/contrib/bmake/mk/stage-install.sh new file mode 100755 index 0000000..64d044f --- /dev/null +++ b/contrib/bmake/mk/stage-install.sh @@ -0,0 +1,98 @@ +#!/bin/sh + +# NAME: +# stage-install.sh - wrapper around install +# +# SYNOPSIS: +# stage-install.sh [variable="value"] "args" "dest" +# +# DESCRIPTION: +# This script is a wrapper around the normal install(1). +# Its role is to add '.dirdep' files to the destination. +# The variables we might use are: +# +# INSTALL +# Path to actual install(1), default is +# $REAL_INSTALL +# +# OBJDIR +# Path to the dir where '.dirdep' was generated, +# default is '.' +# +# _DIRDEP +# Path to actual '.dirdep' file, default is +# $OBJDIR/.dirdep +# +# The "args" and "dest" are passed as is to install(1), and if a +# '.dirdep' file exists it will be linked or copied to each +# "file".dirdep placed in "dest" or "dest".dirdep if it happed +# to be a file rather than a directory. +# +# SEE ALSO: +# meta.stage.mk +# + +# RCSid: +# $Id: stage-install.sh,v 1.5 2013/04/19 16:32:24 sjg Exp $ +# +# @(#) Copyright (c) 2013, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +INSTALL=${REAL_INSTALL:-install} +OBJDIR=. + +while : +do + case "$1" in + *=*) eval "$1"; shift;; + *) break;; + esac +done + +# if .dirdep doesn't exist, just run install and be done +_DIRDEP=${_DIRDEP:-$OBJDIR/.dirdep} +[ -s $_DIRDEP ] && EXEC= || EXEC=exec +$EXEC $INSTALL "$@" || exit 1 + +# from meta.stage.mk +LnCp() { + rm -f $2 2> /dev/null + ln $1 $2 2> /dev/null || cp -p $1 $2 +} + +StageDirdep() { + t=$1 + if [ -s $t.dirdep ]; then + cmp -s $_DIRDEP $t.dirdep && return + echo "ERROR: $t installed by `cat $t.dirdep` not `cat $_DIRDEP`" >&2 + exit 1 + fi + LnCp $_DIRDEP $t.dirdep || exit 1 +} + +args="$@" +while [ $# -gt 8 ] +do + shift 8 +done +eval dest=\$$# +if [ -f $dest ]; then + # a file, there can be only one .dirdep needed + StageDirdep $dest +elif [ -d $dest ]; then + for f in $args + do + test -f $f || continue + StageDirdep $dest/${f##*/} + done +fi diff --git a/contrib/bmake/mk/subdir.mk b/contrib/bmake/mk/subdir.mk new file mode 100644 index 0000000..313b7d7 --- /dev/null +++ b/contrib/bmake/mk/subdir.mk @@ -0,0 +1,99 @@ +# $Id: subdir.mk,v 1.14 2012/11/12 04:34:33 sjg Exp $ +# skip missing directories... + +# $NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $ +# @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91 + +.if ${.MAKE.LEVEL} == 0 && ${.MAKE.MODE:Uno:Mmeta*} != "" +.include +# keep everyone happy +_SUBDIRUSE: +.elif !commands(_SUBDIRUSE) && !defined(NO_SUBDIR) && !defined(NOSUBDIR) +.if exists(${.CURDIR}/Makefile.inc) +.include "Makefile.inc" +.endif +.if !target(.MAIN) +.MAIN: all +.endif + +ECHO_DIR ?= echo +.ifdef SUBDIR_MUST_EXIST +MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1 +.else +MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue +.endif + +_SUBDIRUSE: .USE +.if defined(SUBDIR) + @Exists() { test -f $$1; }; \ + for entry in ${SUBDIR}; do \ + (set -e; \ + if Exists ${.CURDIR}/$${entry}.${MACHINE}/[mM]akefile; then \ + _newdir_="$${entry}.${MACHINE}"; \ + elif Exists ${.CURDIR}/$${entry}/[mM]akefile; then \ + _newdir_="$${entry}"; \ + else \ + ${MISSING_DIR}; \ + fi; \ + if test X"${_THISDIR_}" = X""; then \ + _nextdir_="$${_newdir_}"; \ + else \ + _nextdir_="$${_THISDIR_}/$${_newdir_}"; \ + fi; \ + ${ECHO_DIR} "===> $${_nextdir_}"; \ + cd ${.CURDIR}/$${_newdir_}; \ + ${.MAKE} _THISDIR_="$${_nextdir_}" \ + ${.TARGET:S/realinstall/install/:S/.depend/depend/}) || exit 1; \ + done + +${SUBDIR}:: + @set -e; if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \ + _newdir_=${.TARGET}.${MACHINE}; \ + else \ + _newdir_=${.TARGET}; \ + fi; \ + ${ECHO_DIR} "===> $${_newdir_}"; \ + cd ${.CURDIR}/$${_newdir_}; \ + ${.MAKE} _THISDIR_="$${_newdir_}" all +.endif + +.if !target(install) +.if !target(beforeinstall) +beforeinstall: +.endif +.if !target(afterinstall) +afterinstall: +.endif +install: maninstall +maninstall: afterinstall +afterinstall: realinstall +realinstall: beforeinstall _SUBDIRUSE +.endif + +.if defined(SRCS) +etags: ${SRCS} + -cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'` +.endif + +SUBDIR_TARGETS += \ + all \ + clean \ + cleandir \ + includes \ + depend \ + lint \ + obj \ + tags \ + etags + +.for t in ${SUBDIR_TARGETS:O:u} +$t: _SUBDIRUSE +.endfor + +.include +.if make(destroy*) +.include +.endif +.endif +# make sure this exists +all: diff --git a/contrib/bmake/mk/sys.clean-env.mk b/contrib/bmake/mk/sys.clean-env.mk new file mode 100644 index 0000000..b1867c3 --- /dev/null +++ b/contrib/bmake/mk/sys.clean-env.mk @@ -0,0 +1,119 @@ +# $Id: sys.clean-env.mk,v 1.20 2012/11/12 06:56:04 sjg Exp $ +# +# @(#) Copyright (c) 2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# This makefile would normally be included by sys.env.mk + +# The variables used by this makefile include: +# +# MAKE_ENV_SAVE_VAR_LIST +# The actuall list of variables from the environment that will be +# preserved. +# MAKE_ENV_SAVE_PREFIX_LIST +# A list of prefixes to match against the environment - the results +# are added to MAKE_ENV_SAVE_VAR_LIST after being filtered by... +# MAKE_ENV_SAVE_EXCLUDE_LIST +# A list of words or patterns which is turned into a list of :N +# modifiers. + +.if ${.MAKE.LEVEL} == 0 && ${MAKE_VERSION} >= 20100606 +# We save any env var that starts with the words in MAKE_ENV_SAVE_PREFIX_LIST. +# This gets expanded to an egrep expression like '^(A|B|C...)' +# and added to MAKE_ENV_SAVE_VAR_LIST below. +# If any of these end up being too greedy, MAKE_ENV_SAVE_EXCLUDE_LIST +# can be used to filter. +MAKE_ENV_SAVE_PREFIX_LIST += \ + CCACHE \ + CVS \ + DEBUG \ + DISTCC \ + HOST \ + MACHINE \ + MAKE \ + MK \ + NEED_ \ + SB_ \ + SSH \ + SVN \ + USE_ \ + WITH_ \ + WITHOUT_ \ + + +# This could be a list of vars or patterns to explicitly exclude. +MAKE_ENV_SAVE_EXCLUDE_LIST ?= _ + +# This is the actual list that we will save +# HOME is probably something worth clobbering eg. +# HOME=/var/empty +MAKE_ENV_SAVE_VAR_LIST += \ + HOME \ + LOGNAME \ + OBJROOT \ + OBJTOP \ + PATH \ + SB \ + SRCTOP \ + USER \ + ${_env_vars:${MAKE_ENV_SAVE_EXCLUDE_LIST:${M_ListToSkip}}} + +_env_vars != env | egrep '^(${MAKE_ENV_SAVE_PREFIX_LIST:ts|})' | sed 's,=.*,,'; echo + +_export_list = +.for v in ${MAKE_ENV_SAVE_VAR_LIST:O:u} +.if defined($v) +_export_list += $v +# Save current value +$v := ${$v} +.endif +.endfor + +# Now, clobber the environment +.unexport-env + +# This is a list of vars that we handle specially below +_tricky_env_vars = MAKEOBJDIR OBJTOP +# Export our selection - sans tricky ones +.export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}} + +# This next bit may need tweaking +# if you don't happen to like the way I set it. +.if defined(MAKEOBJDIR) +# We are going to set this to the equivalent of the shell's +# MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}' +_srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}} +_objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}} +_objtop := ${OBJTOP:U${_objroot}${MACHINE}} +# Take care of ${MACHINE} +.if ${MACHINE} == "host" || ${OBJTOP} == ${HOST_OBJTOP:Uno} +OBJTOP = ${_objtop:S,${HOST_TARGET}$,\${MACHINE},} +.else +OBJTOP = ${_objtop:S,${MACHINE}$,\${MACHINE},} +.endif +# Export like this +MAKEOBJDIR = $${.CURDIR:S,${_srctop},$${OBJTOP},} +#.info ${MAKE_SAVE_ENV_VARS _srctop _objroot _objtop OBJTOP MAKEOBJDIR:L:@v@${.newline}$v=${$v}@} + +# Export these as-is, and do not track... +# otherwise the environment will be ruined when we evaluate them below. +.export-env ${_tricky_env_vars} + +# Now evaluate for ourselves +.for v in ${_tricky_env_vars} +$v := ${$v} +.endfor +#.info ${_tricky_env_vars:@v@${.newline}$v=${$v}@} + +.endif # MAKEOBJDIR +.endif # level 0 diff --git a/contrib/bmake/mk/sys.dependfile.mk b/contrib/bmake/mk/sys.dependfile.mk new file mode 100644 index 0000000..42cec61 --- /dev/null +++ b/contrib/bmake/mk/sys.dependfile.mk @@ -0,0 +1,51 @@ +# $Id: sys.dependfile.mk,v 1.5 2013/03/08 00:59:21 sjg Exp $ +# +# @(#) Copyright (c) 2012, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# This only makes sense in meta mode. +# This allows a mixture of auto generated as well as manually edited +# dependency files, which can be differentiated by their names. +# As per dirdeps.mk we only require: +# 1. a common prefix +# 2. that machine specific files end in .${MACHINE} +# +# The .MAKE.DEPENDFILE_PREFERENCE below is an example. + +# All depend file names should start with this +.MAKE.DEPENDFILE_PREFIX ?= Makefile.depend + +# The order of preference: we will use the first one of these we find. +# It usually makes sense to order from most specific to least. +.MAKE.DEPENDFILE_PREFERENCE ?= \ + ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \ + ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX} + +# Normally the 1st entry is our default choice +# Another useful default is ${.MAKE.DEPENDFILE_PREFIX} +.MAKE.DEPENDFILE_DEFAULT ?= ${.MAKE.DEPENDFILE_PREFERENCE:[1]} + +_e := ${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@} +.if !empty(_e) +.MAKE.DEPENDFILE := ${_e:[1]} +.elif ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}} != "" && ${.MAKE.DEPENDFILE_DEFAULT:E} != ${MACHINE} +# MACHINE specific depend files are supported, but *not* default. +# If any already exist, we should follow suit. +_aml = ${ALL_MACHINE_LIST:Uarm amd64 i386 powerpc:N${MACHINE}} ${MACHINE} +# MACHINE must be the last entry in _aml ;-) +_e := ${_aml:@MACHINE@${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}@} +.if !empty(_e) +.MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}:[1]} +.endif +.endif +.MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_DEFAULT} diff --git a/contrib/bmake/mk/sys.mk b/contrib/bmake/mk/sys.mk new file mode 100644 index 0000000..30eca9b --- /dev/null +++ b/contrib/bmake/mk/sys.mk @@ -0,0 +1,199 @@ +# $Id: sys.mk,v 1.35 2012/11/12 06:27:51 sjg Exp $ +# +# @(#) Copyright (c) 2003-2009, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# Avoid putting anything platform specific in here. + +# We use the following paradigm for preventing multiple inclusion. +# It relies on the fact that conditionals and dependencies are resolved +# at the time they are read. +# +# _this ?= ${.PARSEFILE} +# .if !target(__${_this}__) +# __${_this}__: +# +.if ${MAKE_VERSION:U0} > 20100408 +_this = ${.PARSEDIR:tA}/${.PARSEFILE} +.else +_this = ${.PARSEDIR}/${.PARSEFILE} +.endif + +# Sometimes we want to turn on debugging in just one or two places +# if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we +# will apply DEBUG_MAKE_FLAGS now. +# if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk +# eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg" +# use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0 +# +.if ${.MAKE.LEVEL:U1} == 0 +# we use indirection, to simplify the tests below, and incase +# DEBUG_* were given on our command line. +_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0} +_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}} +_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}} +.else +_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS} +_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS} +_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS} +.endif + +.if !empty(_DEBUG_MAKE_FLAGS) +.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" +.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} +.endif +.endif + +# if this is an ancient version of bmake +MAKE_VERSION ?= 0 +.if ${MAKE_VERSION:M*make-*} +# turn it into what we want - just the date +MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} +.endif + +# some useful modifiers + +# A useful trick for testing multiple :M's against something +# :L says to use the variable's name as its value - ie. literal +# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} +M_ListToMatch = L:@m@$${V:M$$m}@ +# match against our initial targets (see above) +M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} + +# turn a list into a set of :N modifiers +# NskipFoo = ${Foo:${M_ListToSkip}} +M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N, + +# type should be a builtin in any sh since about 1980, +# AUTOCONF := ${autoconf:L:${M_whence}} +M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g +M_whence = ${M_type}:M/* + +# convert a path to a valid shell variable +M_P2V = tu:C,[./-],_,g + +# convert path to absolute +.if ${MAKE_VERSION:U0} > 20100408 +M_tA = tA +.else +M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh +.endif + +# absoulte path to what we are reading. +_PARSEDIR = ${.PARSEDIR:${M_tA}} + +# we expect a recent bmake +.if !defined(_TARGETS) +# some things we do only once +_TARGETS := ${.TARGETS} +.-include +.endif + +# we need HOST_TARGET etc below. +.include + +# find the OS specifics +.if defined(SYS_OS_MK) +.include <${SYS_OS_MK}> +.else +_sys_mk = +.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic +.if empty(_sys_mk) +.-include +_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} +.if !empty(_sys_mk) +_sys_mk := sys/${_sys_mk:T} +.endif +.endif +.if empty(_sys_mk) +# might be an old style +.-include <$x.sys.mk> +_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} +.endif +.endfor + +SYS_OS_MK := ${_sys_mk} +.export SYS_OS_MK +.endif + +# allow customization without editing. +.-include + +# if you want objdirs make them automatic +.if ${MKOBJDIRS:Uno} == "auto" +.include +.endif + +.if !empty(SRCTOP) +.if ${.CURDIR} == ${SRCTOP} +RELDIR = . +.elif ${.CURDIR:M${SRCTOP}/*} +RELDIR := ${.CURDIR:S,${SRCTOP}/,,} +.endif +.endif + +MACHINE_ARCH.host ?= ${_HOST_ARCH} +MACHINE_ARCH.${MACHINE} ?= ${MACHINE} +.if empty(MACHINE_ARCH) +MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +.endif + +.ifndef ROOT_GROUP +ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group +.export ROOT_GROUP +.endif + +unix ?= We run ${_HOST_OSNAME}. + +# A race condition in mkdir, means that it can bail if another +# process made a dir that mkdir expected to. +# We repeat the mkdir -p a number of times to try and work around this. +# We stop looping as soon as the dir exists. +# If we get to the end of the loop, a plain mkdir will issue an error. +Mkdirs= Mkdirs() { \ + for d in $$*; do \ + for i in 1 2 3 4 5 6; do \ + mkdir -p $$d; \ + test -d $$d && return 0; \ + done; \ + mkdir $$d || exit $$?; \ + done; } + +# this often helps with debugging +.SUFFIXES: .cpp-out + +.c.cpp-out: + @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' + +.cc.cpp-out: + @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' + +# we don't include own.mk but user can expect -DWITH_META_MODE to work +.if defined(WITHOUT_META_MODE) +USE_META= no +.elif defined(WITH_META_MODE) +USE_META= yes +.endif +.if ${USE_META:Uno} == "yes" +.-include +.endif +# make sure we have a harmless value +.MAKE.MODE ?= normal + +# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we +# will apply DEBUG_MAKE_FLAGS, now. +.if !empty(_DEBUG_MAKE_FLAGS) +.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" +.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} +.endif +.endif diff --git a/contrib/bmake/mk/sys/AIX.mk b/contrib/bmake/mk/sys/AIX.mk new file mode 100644 index 0000000..18adfa6 --- /dev/null +++ b/contrib/bmake/mk/sys/AIX.mk @@ -0,0 +1,197 @@ +# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ +# @(#)sys.mk 5.11 (Berkeley) 3/13/91 + +OS= AIX +unix= We run ${OS}. +ROOT_GROUP= system + +# This needs a lot of work yet... + +NOPIC=no # no shared libs? + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +.LIBS: .a + +AR= ar +ARFLAGS= rl +RANLIB= ranlib + +AS= as +AFLAGS= +COMPILE.s= ${AS} ${AFLAGS} +LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +.if exists(/usr/local/bin/gcc) +CC= gcc +DBG= -O -g +STATIC?= -static +.else +CC= cc +DBG= -g +STATIC= +.endif +CFLAGS= ${DBG} +COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX= g++ +CXXFLAGS= ${CFLAGS} +COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP= cpp +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif + +MK_DEP= mkdeps.sh -N +FC= f77 +FFLAGS= -O +RFLAGS= +COMPILE.f= ${FC} ${FFLAGS} -c +LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +LEX= lex +LFLAGS= +LEX.l= ${LEX} ${LFLAGS} + +LD= ld +LDFLAGS= + +LINT= lint +LINTFLAGS= -chapbx + +MAKE= bmake + +PC= pc +PFLAGS= +COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL= sh + +YACC= yacc +YFLAGS= -d +YACC.y= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} -o ${.TARGET} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/Darwin.mk b/contrib/bmake/mk/sys/Darwin.mk new file mode 100644 index 0000000..d05e32a --- /dev/null +++ b/contrib/bmake/mk/sys/Darwin.mk @@ -0,0 +1,220 @@ +# $NetBSD: Darwin.sys.mk,v 1.3 2003/02/16 09:44:41 grant Exp $ +# @(#)sys.mk 8.2 (Berkeley) 3/21/94 + +OS= Darwin +unix?= We run ${OS}. + +.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 .dylib + +.LIBS: .a .dylib + +SHLIBEXT = .dylib +HOST_LIBEXT = .dylib +DSHLIBEXT = .dylib + +AR?= ar +ARFLAGS?= rl +RANLIB = + +AS?= as +AFLAGS?= +COMPILE.s?= ${AS} ${AFLAGS} +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +.if exists(/usr/bin/gcc) +CC?= gcc -pipe +.else +CC?= cc -pipe +.endif +DBG?= -O2 +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +.if exists(/usr/bin/g++) +CXX?= g++ +.else +CXX?= c++ +.endif +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +OBJC?= ${CC} +OBJCFLAGS?= ${CFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= cpp +NOLINT= 1 +CPPFLAGS?= + +MK_DEP?= mkdeps.sh -N + +FC?= f77 +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= install + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +SHLIB_TEENY = 0 +SHLIB_MINOR = 0 + +MKPICLIB = no +LIBEXT = .dylib + +LINT?= lint +LINTFLAGS?= -chapbx + +LORDER?= lorder + +MAKE?= bmake + +NM?= nm + +PC?= pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +TSORT?= tsort -q + +YACC?= bison -y +YFLAGS?= -d +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} -o ${.TARGET} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/Generic.mk b/contrib/bmake/mk/sys/Generic.mk new file mode 100644 index 0000000..179da97 --- /dev/null +++ b/contrib/bmake/mk/sys/Generic.mk @@ -0,0 +1,208 @@ +# $Id: Generic.mk,v 1.11 2010/09/24 05:59:53 sjg Exp $ +# + +# some reasonable defaults +.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 + +.LIBS: .a + +tools = \ + ar \ + lorder \ + ranlib \ + tsort + +.for t in ${tools} +${t:tu} := ${t:${M_whence}} +.endfor + +# need to make sure this is set +MACHINE_ARCH.${MACHINE} ?= ${MACHINE} +.if empty(MACHINE_ARCH) +MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +.endif + +.if !empty(TSORT) +TSORT += -q +.endif + +ARFLAGS?= rl + +AS?= as +AFLAGS?= +.if ${MACHINE_ARCH} == "sparc64" +AFLAGS+= -Wa,-Av9a +.endif +COMPILE.s?= ${CC} ${AFLAGS} -c +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CC?= cc +DBG?= -O2 +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX?= c++ +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +OBJC?= ${CC} +OBJCFLAGS?= ${CFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= cpp +CPPFLAGS?= + +FC?= f77 +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= install + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +LINT?= lint +LINTFLAGS?= -chapbxzF + +MAKE?= ${.MAKE} + +NM?= nm + +PC?= pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +YACC?= yacc +YFLAGS?= +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.c.ln: + ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} + +# C++ +.cc .cpp .cxx .C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o .cpp.o .cxx.o .C.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a .cpp.a .cxx.a .C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} + diff --git a/contrib/bmake/mk/sys/HP-UX.mk b/contrib/bmake/mk/sys/HP-UX.mk new file mode 100644 index 0000000..f6e3e2c --- /dev/null +++ b/contrib/bmake/mk/sys/HP-UX.mk @@ -0,0 +1,237 @@ +# $Id: HP-UX.mk,v 1.9 2003/09/30 16:42:23 sjg Exp $ +# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ +# @(#)sys.mk 5.11 (Berkeley) 3/13/91 + +OS= HP-UX +ROOT_GROUP= root +unix?= We run ${OS}. + +# HP-UX's cc does not provide any clues as to wether this is 9.x or 10.x +# nor does sys/param.h, so we'll use the existence of /hp-ux +.if exists("/hp-ux") +OSMAJOR?=9 +.endif +OSMAJOR?=10 +__HPUX_VERSION?=${OSMAJOR} + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +LIBMODE= 755 +LIBCRT0= /lib/crt0.o + +.LIBS: .a + +# +b is needed to stop the binaries from insisting on having +# the build tree available :-) +# +s tells the dynamic loader to use SHLIB_PATH if set +LD_bpath?=-Wl,+b/lib:/usr/lib:/usr/local/lib +LD_spath?=-Wl,+s +LDADD+= ${LD_bpath} ${LD_spath} + +.if exists(/usr/lib/end.o) +LDADD+= /usr/lib/end.o +.endif + +AR= ar +ARFLAGS= rl +RANLIB= : + +AFLAGS= +COMPILE.s= ${AS} ${AFLAGS} +LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +.if exists(/usr/local/bin/gcc) +PIPE?= -pipe +CC?= gcc ${PIPE} +AS= gas +DBG?= -O -g +STATIC?= -static +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif +.else +# HP's bundled compiler knows not -g or -O +AS= as +CC= cc +.if exists(/opt/ansic/bin/cc) +CCMODE?=-Ae +ESlit +PICFLAG?= +z +LD_x= +DBG?=-g -O +.endif +DBG?= +STATIC?= -Wl,-a,archive +.endif +.if (${__HPUX_VERSION} == "10") +CCSOURCE_FLAGS?= -D_HPUX_SOURCE +.else +CCSOURCE_FLAGS?= -D_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED +.endif +CFLAGS= ${DBG} +CFLAGS+= ${CCMODE} -D__hpux__ -D__HPUX_VERSION=${__HPUX_VERSION} ${CCSOURCE_FLAGS} +COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX= g++ +CXXFLAGS= ${CFLAGS} +COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP= cpp + +MK_DEP= mkdeps.sh -N +FC= f77 +FFLAGS= -O +RFLAGS= +COMPILE.f= ${FC} ${FFLAGS} -c +LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +LEX= lex +LFLAGS= +LEX.l= ${LEX} ${LFLAGS} + +LD= ld +LDFLAGS= + +LINT= lint +LINTFLAGS= -chapbx + +MAKE= bmake + +PC= pc +PFLAGS= +COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +# HP's sh sucks +ENV= +SHELL= /bin/ksh + +.if exists(/usr/local/bin/bison) +YACC= bison -y +.else +YACC= yacc +.endif +YFLAGS= -d +YACC.y= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} -o ${.TARGET} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/IRIX.mk b/contrib/bmake/mk/sys/IRIX.mk new file mode 100644 index 0000000..783e405 --- /dev/null +++ b/contrib/bmake/mk/sys/IRIX.mk @@ -0,0 +1,199 @@ +# $NetBSD: IRIX.sys.mk,v 1.2 2002/12/24 23:03:27 jschauma Exp $ +# @(#)sys.mk 8.2 (Berkeley) 3/21/94 + +.if ${.PARSEFILE} == "sys.mk" +.ifndef ROOT_GROUP +OS!= uname -s +ROOT_GROUP!= sed -n /:0:/s/:.*//p /etc/group +.MAKEOVERRIDES+= OS ROOT_GROUP +.endif +unix?= We run ${OS}. +.endif + +.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 + +.LIBS: .a + +AR?= ar +ARFLAGS?= rl +RANLIB?= ranlib + +AS?= as +AFLAGS?= +COMPILE.s?= ${CC} ${AFLAGS} -c +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CC?= cc +NOGCCERROR?= # defined +DBG?= -O2 +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX?= CC +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +OBJC?= ${CC} +OBJCFLAGS?= ${CFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= CC +CPPFLAGS?= + +FC?= f77 +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= ${PREFIX}/bin/install-sh + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +LINT?= lint +LINTFLAGS?= -chapbxzF + +LORDER?= lorder + +MAKE?= make + +NM?= nm + +PC?= pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +TSORT?= tsort -q + +YACC?= yacc +YFLAGS?= +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.c.ln: + ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} + +# C++ +.cc .cpp .cxx .C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o .cpp.o .cxx.o .C.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a .cpp.a .cxx.a .C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/Linux.mk b/contrib/bmake/mk/sys/Linux.mk new file mode 100644 index 0000000..862cde6 --- /dev/null +++ b/contrib/bmake/mk/sys/Linux.mk @@ -0,0 +1,200 @@ +# $Id: Linux.mk,v 1.7 2011/03/02 05:05:21 sjg Exp $ +# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ +# @(#)sys.mk 5.11 (Berkeley) 3/13/91 + +OS?= Linux +unix?= We run ${OS}. + +ROOT_GROUP= root + +# would be better to work out where it is... +LIBCRT0= /dev/null + +NEED_SOLINKS=yes + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +.LIBS: .a + +AR= ar +ARFLAGS= rl +RANLIB= ranlib + +AS= as +AFLAGS= +COMPILE.s= ${AS} ${AFLAGS} +LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +.if exists(/usr/local/bin/gcc) +CC= gcc -pipe +DBG= -O -g +STATIC?= -static +.else +CC= cc -pipe +DBG= -g +STATIC= -Bstatic +.endif +CFLAGS= ${DBG} +COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX= g++ +CXXFLAGS= ${CFLAGS} +COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP= cpp +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif + +MK_DEP= mkdeps.sh -N +FC= f77 +FFLAGS= -O +RFLAGS= +COMPILE.f= ${FC} ${FFLAGS} -c +LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +LEX= lex +LFLAGS= +LEX.l= ${LEX} ${LFLAGS} + +LD= ld +LDFLAGS= + +LINT= lint +LINTFLAGS= -chapbx + +MAKE= bmake + +PC= pc +PFLAGS= +COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL= sh + +YACC= yacc +YFLAGS= -d +YACC.y= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} -o ${.TARGET} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/NetBSD.mk b/contrib/bmake/mk/sys/NetBSD.mk new file mode 100644 index 0000000..4bc7da1 --- /dev/null +++ b/contrib/bmake/mk/sys/NetBSD.mk @@ -0,0 +1,234 @@ +# $NetBSD: sys.mk,v 1.66.2.1 2002/06/05 03:31:01 lukem Exp $ +# @(#)sys.mk 8.2 (Berkeley) 3/21/94 + +OS= NetBSD +unix?= We run ${OS}. + +.if !defined(MAKE_VERSION) +# we are running native make +# which defined MAKE_VERSION between 20010609 and 20090324 +# so we can make a rough guess +.if defined(.MAKE.LEVEL) +MAKE_VERSION = 20090908 +.elif defined(.MAKE.MAKEFILES) +# introduced 20071008 +MAKE_VERSION = 20090324 +.else +# this just before when MAKE_VERSION was introduced +MAKE_VERSION = 20010606 +.endif +.endif + +.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 + +.LIBS: .a + +AR?= ar +ARFLAGS?= rl +RANLIB?= ranlib + +AS?= as +AFLAGS?= +COMPILE.s?= ${CC} ${AFLAGS} -c +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CC?= cc + +# need to make sure this is set +MACHINE_ARCH.${MACHINE} ?= ${MACHINE} +.if empty(MACHINE_ARCH) +MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +.endif + +# +# CPU model, derived from MACHINE_ARCH +# +MACHINE_CPU= ${MACHINE_ARCH:C/mipse[bl]/mips/:C/mips64e[bl]/mips/:C/sh3e[bl]/sh3/:S/m68000/m68k/:S/armeb/arm/} + +.if ${MACHINE_CPU} == "alpha" || \ + ${MACHINE_CPU} == "arm" || \ + ${MACHINE_CPU} == "i386" || \ + ${MACHINE_CPU} == "m68k" || \ + ${MACHINE_CPU} == "mips" || \ + ${MACHINE_CPU} == "powerpc" || \ + ${MACHINE_CPU} == "sparc" || \ + ${MACHINE_CPU} == "vax" +DBG?= -O2 +.elif ${MACHINE_ARCH} == "x86_64" +DBG?= +.elif ${MACHINE_ARCH} == "sparc64" +DBG?= -O -ffixed-g4 #Hack for embedany memory model compatibility +.else +DBG?= -O +.endif +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX?= c++ +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +OBJC?= ${CC} +OBJCFLAGS?= ${CFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= cpp +CPPFLAGS?= + +FC?= f77 +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= install + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +LINT?= lint +LINTFLAGS?= -chapbxzF + +LORDER?= lorder + +MAKE?= make + +NM?= nm + +PC?= pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +TSORT?= tsort -q + +YACC?= yacc +YFLAGS?= +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.c.ln: + ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} + +# C++ +.cc .cpp .cxx .C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o .cpp.o .cxx.o .C.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a .cpp.a .cxx.a .C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/OSF1.mk b/contrib/bmake/mk/sys/OSF1.mk new file mode 100644 index 0000000..a8d729a --- /dev/null +++ b/contrib/bmake/mk/sys/OSF1.mk @@ -0,0 +1,211 @@ +# $Id: OSF1.mk,v 1.6 2003/09/30 16:42:23 sjg Exp $ +# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ +# @(#)sys.mk 5.11 (Berkeley) 3/13/91 + +OS?= OSF1 +unix?= We run ${OS}. +ROOT_GROUP= system + +# can't fine one anywhere, so just stop the dependency +LIBCRT0= /dev/null + +PATH=/usr/sbin:/usr/bin:/usr/ucb:/opt/gnu/bin:/usr/ccs/bin + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +.LIBS: .a + +# no -X +LD_X= +LD_x= -x +LD_r= -r +AR= ar +ARFLAGS= rl +RANLIB= ranlib + +AS= as +AS_STDIN= - +AFLAGS= +COMPILE.s= ${AS} ${AFLAGS} +LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +.if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc) +CC?= gcc +.else +CC?= cc -std +.endif +.if (${CC:T} == "gcc") +DBG= -O -g +STATIC= -static +DBG= -g +STATIC= -non_shared +.endif + +CFLAGS= ${DBG} +COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX= g++ +CXXFLAGS= ${CFLAGS} +COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP= /usr/ccs/lib/cpp +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif + +MK_DEP= mkdeps.sh -N +FC= f77 +FFLAGS= -O +RFLAGS= +COMPILE.f= ${FC} ${FFLAGS} -c +LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +LEX= lex +LFLAGS= +LEX.l= ${LEX} ${LFLAGS} + +LD= ld +LDFLAGS= + +LINT= lint +LINTFLAGS= -chapbx + +MAKE= bmake + +PC= pc +PFLAGS= +COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL= sh + +.if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison) +YACC= bison -y +.else +YACC= yacc +.endif +YFLAGS= -d +YACC.y= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/OpenBSD.mk b/contrib/bmake/mk/sys/OpenBSD.mk new file mode 100644 index 0000000..ed496f1 --- /dev/null +++ b/contrib/bmake/mk/sys/OpenBSD.mk @@ -0,0 +1,209 @@ +# $NetBSD: OpenBSD.sys.mk,v 1.1 2002/11/17 09:18:00 cjep Exp $ +# @(#)sys.mk 8.2 (Berkeley) 3/21/94 + +OS= OpenBSD +unix?= We run ${OS}. + +.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h +.SUFFIXES: .sh .m4 + +.LIBS: .a + +# need to make sure this is set +MACHINE_ARCH.${MACHINE} ?= ${MACHINE} +.if empty(MACHINE_ARCH) +MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} +.endif + +AR?= ar +ARFLAGS?= rl +RANLIB?= ranlib + +AS?= as +AFLAGS?= +.if ${MACHINE_ARCH} == "sparc64" +AFLAGS+= -Wa,-Av9a +.endif +COMPILE.s?= ${CC} ${AFLAGS} -c +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CC?= cc +.if ${MACHINE_ARCH} == "alpha" || \ + ${MACHINE_ARCH} == "i386" || \ + ${MACHINE_ARCH} == "m68k" || \ + ${MACHINE_ARCH} == "sparc" || \ + ${MACHINE_ARCH} == "vax" +DBG?= -O2 +.else +DBG?= -O +.endif +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX?= c++ +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +OBJC?= ${CC} +OBJCFLAGS?= ${CFLAGS} +COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c +LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= cpp +CPPFLAGS?= + +FC?= f77 +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= install + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +LINT?= lint +LINTFLAGS?= -chapbxzF + +LORDER?= lorder + +MAKE?= make + +NM?= nm + +PC?= pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +TSORT?= tsort -q + +YACC?= yacc +YFLAGS?= +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.c.ln: + ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC} + +# C++ +.cc .cpp .cxx .C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o .cpp.o .cxx.o .C.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a .cpp.a .cxx.a .C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/SunOS.mk b/contrib/bmake/mk/sys/SunOS.mk new file mode 100644 index 0000000..f164aa2 --- /dev/null +++ b/contrib/bmake/mk/sys/SunOS.mk @@ -0,0 +1,232 @@ +# $Id: SunOS.mk,v 1.5 2010/01/11 23:02:05 sjg Exp $ + +.if ${.PARSEFILE} == "sys.mk" +.include + +OS?= SunOS.${HOST_OSMAJOR} +unix?= We run ${OS}. +.endif + +.if ${HOST_OSMAJOR} > 4 +ROOT_GROUP= root + +SHLIB_FULLVERSION = ${SHLIB_MAJOR} + +# supress the dependency +LIBCRT0= /dev/null + +.ifndef CC +# the PATH below may find an ancient gcc +CC := ${gcc:L:${M_whence}} +.export CC +.endif + +# the stuff in /usr/xpg4/bin is usually more sane. +PATH=/usr/xpg4/bin:/usr/sbin:/usr/bin:/usr/ucb:/usr/sfw/bin:/opt/gnu/bin:/usr/ccs/bin:/usr/local/bin +.export PATH + +DSHLIBEXT = .so +HOST_LIBDIRS = /usr/lib /lib /usr/sfw/lib + +# no -X +LD_X= +LD_x= +RANLIB= : +CPP= /usr/ccs/lib/cpp +.else +ROOT_GROUP= wheel +RANLIB= ranlib +CPP= cpp +.endif + +# the rest is common + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +.LIBS: .a + +AR= ar +ARFLAGS= rl + +AS= as +AS_STDIN= - +AFLAGS= +COMPILE.s= ${AS} ${AFLAGS} +LINK.s= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} +.if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc) +CC ?= gcc -pipe +DBG= -O -g +STATIC= -static +.else +CC ?= cc +DBG= -g +STATIC= -Bstatic +.endif +CFLAGS= ${DBG} +COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CXX= g++ +CXXFLAGS= ${CFLAGS} +COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif + +MK_DEP= mkdeps.sh -N +FC= f77 +FFLAGS= -O +RFLAGS= +COMPILE.f= ${FC} ${FFLAGS} -c +LINK.f= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +LEX= lex +LFLAGS= +LEX.l= ${LEX} ${LFLAGS} + +LD= ld +LDFLAGS= + +LINT= lint +LINTFLAGS= -chapbx + +MAKE= bmake + +PC= pc +PFLAGS= +COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL= sh + +.if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison) +YACC= bison -y +.else +YACC= yacc +.endif +YFLAGS= -d +YACC.y= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/sys/UnixWare.mk b/contrib/bmake/mk/sys/UnixWare.mk new file mode 100644 index 0000000..f21895b --- /dev/null +++ b/contrib/bmake/mk/sys/UnixWare.mk @@ -0,0 +1,254 @@ +# $Id: UnixWare.mk,v 1.1 2005/10/09 22:56:40 sjg Exp $ +# based on "Id: SunOS.5.sys.mk,v 1.6 2003/09/30 16:42:23 sjg Exp " +# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $ +# @(#)sys.mk 5.11 (Berkeley) 3/13/91 + +OS?= UnixWare +unix?= We run ${OS}. +ROOT_GROUP= root + +# can't fine one anywhere, so just stop the dependency +LIBCRT0= /dev/null + +PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ccs/lib:/usr/ucb:/usr/local/bin + +.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4 + +.LIBS: .a + +# no -X +LD_X= +LD_x= +AR?= ar +ARFLAGS?= rl +RANLIB?= : + +AS?= as +AS_STDIN?= - +AFLAGS?= +COMPILE.s?= ${AS} ${AFLAGS} +LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS} +COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c +LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS} + +# at least gcc 2.95 on UnixWare has no internal macro to identify the system +.if exists(/usr/local/bin/gcc) +CC?= gcc -pipe -DUNIXWARE +DBG?= -O -g +STATIC?= -static +.else +CC?= cc +DBG?= -g +STATIC?= -Bstatic # XXX: don't know about UDK compilers +.endif +CFLAGS?= ${DBG} +COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c +LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} + +.if exists(/usr/local/bin/g++) +CXX?= g++ -DUNIXWARE +.else +CXX?= c++ # XXX: don't know about UDK compilers +.endif +CXXFLAGS?= ${CFLAGS} +COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c +LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS} + +CPP?= /usr/ccs/lib/cpp +.if defined(DESTDIR) +CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include +.endif + +MK_DEP?= mkdeps.sh -N +.if exists(/usr/local/bin/g77) +FC?= g77 +.else +FC?= f77 # XXX: don't know about UDK compilers +.endif +FFLAGS?= -O +RFLAGS?= +COMPILE.f?= ${FC} ${FFLAGS} -c +LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS} +COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c +LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS} +COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c +LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS} + +INSTALL?= /usr/ucb/install # BSD install + +LEX?= lex +LFLAGS?= +LEX.l?= ${LEX} ${LFLAGS} + +LD?= ld +LDFLAGS?= + +LIBC?= ${DESTDIR}/usr/ccs/lib/libc.a +LIBCOMPAT?= +LIBCRYPT?= ${DESTDIR}/usr/lib/libcrypt.a +LIBCURSES?= ${DESTDIR}/usr/ccs/lib/libcurses.a +LIBDBM?= +LIBDES?= +LIBEDIT?= +LIBGCC?= +LIBKDB?= +LIBKRB?= +LIBKVM?= +LIBL?= ${DESTDIR}/usr/ccs/lib/libl.a +LIBM?= ${DESTDIR}/usr/ccs/lib/libm.a +LIBMP?= +LIBPC?= +LIBPCAP?= +LIBPLOT?= +LIBRESOLV?= +LIBRPCSVC?= ${DESTDIR}/usr/lib/librpcsvc.a +LIBSKEY?= ${DESTDIR}/usr/lib/libskey.a +LIBTERMCAP?= ${DESTDIR}/usr/ccs/lib/libtermcap.a +LIBUTIL?= +LIBWRAP?= +LIBY?= ${DESTDIR}/usr/ccs/lib/liby.a +LIBZ?= + +LINT?= lint +LINTFLAGS?= -pF + +LORDER?= lorder + +MAKE?= bmake + +NM?= nm + +PC?= pc # XXX: UDK probably does not have pc +PFLAGS?= +COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c +LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS} + +SHELL?= sh + +SIZE?= size + +TSORT?= tsort + +.if exists(/usr/local/bin/bison) +YACC?= bison -y +.else +YACC?= yacc +.endif +YFLAGS?= -d +YACC.y?= ${YACC} ${YFLAGS} + +# C +.c: + ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.c.o: + ${COMPILE.c} ${.IMPSRC} +.c.a: + ${COMPILE.c} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# C++ +.cc: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.cc.o: + ${COMPILE.cc} ${.IMPSRC} +.cc.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.C: + ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.C.o: + ${COMPILE.cc} ${.IMPSRC} +.C.a: + ${COMPILE.cc} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Fortran/Ratfor +.f: + ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.f.o: + ${COMPILE.f} ${.IMPSRC} +.f.a: + ${COMPILE.f} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.F: + ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.F.o: + ${COMPILE.F} ${.IMPSRC} +.F.a: + ${COMPILE.F} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +.r: + ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.r.o: + ${COMPILE.r} ${.IMPSRC} +.r.a: + ${COMPILE.r} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Pascal +.p: + ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.p.o: + ${COMPILE.p} ${.IMPSRC} +.p.a: + ${COMPILE.p} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Assembly +.s: + ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.s.o: + ${COMPILE.s} ${.IMPSRC} +.s.a: + ${COMPILE.s} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o +.S: + ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS} +.S.o: + ${COMPILE.S} ${.IMPSRC} +.S.a: + ${COMPILE.S} ${.IMPSRC} + ${AR} ${ARFLAGS} $@ $*.o + rm -f $*.o + +# Lex +.l: + ${LEX.l} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll + rm -f lex.yy.c +.l.c: + ${LEX.l} ${.IMPSRC} + mv lex.yy.c ${.TARGET} +.l.o: + ${LEX.l} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} lex.yy.c + rm -f lex.yy.c + +# Yacc +.y: + ${YACC.y} ${.IMPSRC} + ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS} + rm -f y.tab.c +.y.c: + ${YACC.y} ${.IMPSRC} + mv y.tab.c ${.TARGET} +.y.o: + ${YACC.y} ${.IMPSRC} + ${COMPILE.c} -o ${.TARGET} y.tab.c + rm -f y.tab.c + +# Shell +.sh: + rm -f ${.TARGET} + cp ${.IMPSRC} ${.TARGET} diff --git a/contrib/bmake/mk/target-flags.mk b/contrib/bmake/mk/target-flags.mk new file mode 100644 index 0000000..f8932b2 --- /dev/null +++ b/contrib/bmake/mk/target-flags.mk @@ -0,0 +1,62 @@ +# NAME: +# target-flags.mk - target specific flags +# +# DESCRIPTION: +# Include this macro file after all others in a makefile and +# follow it with any target specfic flag settings. +# For each such variable v in TARGET_FLAG_VARS we set: +#.nf +# +# _$v := ${$v} +# $v = ${${v}_${.TARGET:T}:U${_$v}} +#.fi +# +# This allows one to do things like: +#.nf +# +# TARGET_FLAG_VARS= CFLAGS +# .include +# CFLAGS_fu.o = ${_CFLAGS:N-Wall} +#.fi +# +# To turn off -Wall for just the target fu.o +# Actually CFLAGS is the default value for TARGET_FLAG_VARS. +# +# BUGS: +# One must be careful to avoid creating circular references in +# variables. The original version of this macro file did +# elaborate things with CFLAGS. The current, simpler +# implementation is ultimately more flexible. +# +# It is important that target-flags.mk is included after other +# macro files and that target specific flags that may reference +# _$v are set after that. +# +# Only works with a make(1) that does nested evaluation correctly. + + + +# RCSid: +# $Id: target-flags.mk,v 1.8 2002/05/08 06:01:00 sjg Exp $ +# +# @(#) Copyright (c) 1998-2002, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +TARGET_FLAG_VARS?= CFLAGS +.for v in ${TARGET_FLAG_VARS} +.ifndef _$v +_$v := ${$v} +$v = ${${v}_${.TARGET:T}:U${_$v}} +.endif +.endfor + diff --git a/contrib/bmake/mk/warnings.mk b/contrib/bmake/mk/warnings.mk new file mode 100644 index 0000000..9143e42 --- /dev/null +++ b/contrib/bmake/mk/warnings.mk @@ -0,0 +1,148 @@ +# RCSid: +# $Id: warnings.mk,v 1.7 2009/12/11 17:06:03 sjg Exp $ +# +# @(#) Copyright (c) 2002, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +.ifndef _w_cflags + +# Any number of warnings sets can be added. +.-include "warnings-sets.mk" + +# Modest defaults - put more elaborate sets in warnings-sets.mk +# -Wunused etc are here so you can set +# W_unused=-Wno-unused etc. +MIN_WARNINGS?= -Wall \ + -Wformat \ + -Wimplicit \ + -Wunused \ + -Wuninitialized + +LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes + +MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror + +HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \ + -Wcast-align \ + -Wcast-qual \ + -Wparentheses \ + -Wpointer-arith \ + -Wmissing-declarations \ + -Wreturn-type \ + -Wswitch \ + -Wwrite-strings + +# The two step default makes it easier to test build with different defaults. +DEFAULT_WARNINGS_SET?= MIN +WARNINGS_SET?= ${DEFAULT_WARNINGS_SET} + +# If you add sets, besure to list them (you don't have to touch this list). +ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH + +.if empty(${WARNINGS_SET}_WARNINGS) +.if ${MAKE_VERSION:U0:[1]:C/.*-//} >= 20050530 +.BEGIN: _empty_warnings +_empty_warnings: .PHONY +.else +.BEGIN: +.endif + @echo "ERROR: Invalid: WARNINGS_SET=${WARNINGS_SET}" + @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1 + +.endif + +# Without -O or if we've set -O0 somewhere - to make debugging more effective, +# we need to turn off -Wuninitialized as otherwise we get a warning that +# -Werror turns into an error. To be safe, set W_uninitialized blank. +_w_cflags:= ${CFLAGS} ${CPPFLAGS} +.if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != "" +W_uninitialized= +.endif + +.if ${MAKE_VERSION:U0:[1]:C/.*-//} <= 20040118 +# This version uses .for loops to avoid a double free bug in old bmake's +# but the .for loops are sensitive to when this file is read. + +# first, make a list of all the warning flags - doesn't matter if +# its redundant - we'll sort -u +_all_sets= ${WARNINGS_SET_${MACHINE_ARCH}} ${WARNINGS_SET} ${ALL_WARNINGS_SETS} +_all_warnings= ${WARNINGS} ${_all_sets:O:u:@s@${$s_WARNINGS}@} + +# we want to set W_* for each warning so they are easy to turn off. +# :O:u does a sort -u +# using :C allows us to handle -f* -w* etc as well as -W* +.for w in ${_all_warnings:O:u} +${w:C/-(.)/\1_/} ?= $w +.endfor + +# Allow for per-target warnings +# Warning: the WARNINGS+= line below, +# may make your brain hurt - trust me; it works --sjg +# the idea is that you can set WARNINGS_SET[_${MACHINE_ARCH}]=HIGH +# and use one of +# W_format_mips_foo.o= +# W_format_foo.o= +# to turn off -Wformat for foo.o (on mips only in the first case), or +# W_format_foo.o=-Wformat=2 +# for stricter checking. +# +# NOTE: that we force the target extension to be .o +# +.for w in ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:@s@${$s_WARNINGS}@:O:u} +WARNINGS+= ${${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U${${w:C/-(.)/\1_/}}}}} +.endfor + +.else + +# .for loops have the [dis]advantage of being evaluated when read, +# so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is +# read has no effect. +# Replacing the above .for loops with the WARNINGS+= below solves that +# but tiggers a double free bug in bmake-20040118 and earlier. +# Don't try and read this too fast! +# +# The first :@ "loop" handles multiple sets in WARNINGS_SET +# +# In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc +# which makes it easy to turn off override individual flags +# (see W_uninitialized above). +# +# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}} +# which is the bit we ultimately want. It allows W_* to be set on a +# per target basis. +# +# NOTE: that we force the target extension to be .o +# +WARNINGS+= ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:@s@${$s_WARNINGS}@:O:u:@w@${${w:C/-(.)/\1_/}::?=$w} ${${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U${${w:C/-(.)/\1_/}}}}}@} + +.endif + +.ifndef NO_CFLAGS_WARNINGS +# Just ${WARNINGS} should do, but this is more flexible? +CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}} +.endif + +# it is rather silly that g++ blows up on some warning flags +NO_CXX_WARNINGS+= \ + missing-declarations \ + missing-prototypes \ + nested-externs \ + strict-prototypes + +.for s in ${SRCS:M*.cc} +.for w in ${NO_CXX_WARNINGS} +W_$w_${s:T:R}.o= +.endfor +.endfor + +.endif # _w_cflags diff --git a/contrib/bmake/mk/yacc.mk b/contrib/bmake/mk/yacc.mk new file mode 100644 index 0000000..910b004 --- /dev/null +++ b/contrib/bmake/mk/yacc.mk @@ -0,0 +1,57 @@ +# $Id: yacc.mk,v 1.6 2011/06/10 22:45:46 sjg Exp $ + +# +# @(#) Copyright (c) 1999-2011, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# this file contains rules to DTRT when SRCS contains foo.y or foo.c +# when only a foo.y exists. + +YACC?= yacc +YFLAGS?= -v -t +RM?= rm + +YACC.y?= ${YACC} ${YFLAGS} + +.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) + +.y.c: + ${YACC.y} ${.IMPSRC} + [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} + ${RM} -f y.tab.[!h] + +.else + +# the touch of the .c is to ensure it is newer than .h (paranoia) +.y.h: + ${YACC.y} ${.IMPSRC} + [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c + [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ + || mv y.tab.h ${.TARGET:T:R}.h + touch ${.TARGET:T:R}.c + ${RM} -f y.tab.* + +# Normally the .y.h rule does the work - to avoid races. +# If for any reason the .c is lost but the .h remains, +# regenerate the .c +.y.c: ${.TARGET:T:R}.h + [ -s ${.TARGET} ] || { \ + ${YACC.y} ${.IMPSRC} && \ + { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \ + ${RM} y.tab.*; }; } +.endif + +beforedepend: ${SRCS:T:M*.y:S/.y/.c/g} + +CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g} +CLEANFILES+= y.tab.[ch] diff --git a/contrib/bmake/parse.c b/contrib/bmake/parse.c index 0b18f5d..41323b5 100644 --- a/contrib/bmake/parse.c +++ b/contrib/bmake/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $ */ +/* $NetBSD: parse.c,v 1.191 2013/08/28 21:56:49 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.191 2013/08/28 21:56:49 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $"); +__RCSID("$NetBSD: parse.c,v 1.191 2013/08/28 21:56:49 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -157,7 +157,7 @@ __RCSID("$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $"); * Structure for a file being read ("included file") */ typedef struct IFile { - const char *fname; /* name of file */ + char *fname; /* name of file */ int lineno; /* current line number in file */ int first_lineno; /* line number of start of text */ int cond_depth; /* 'if' nesting when file opened */ @@ -213,6 +213,7 @@ typedef enum { ExShell, /* .SHELL */ Silent, /* .SILENT */ SingleShell, /* .SINGLESHELL */ + Stale, /* .STALE */ Suffixes, /* .SUFFIXES */ Wait, /* .WAIT */ Attribute /* Generic attribute */ @@ -336,6 +337,7 @@ static const struct { { ".SHELL", ExShell, 0 }, { ".SILENT", Silent, OP_SILENT }, { ".SINGLESHELL", SingleShell, 0 }, +{ ".STALE", Stale, 0 }, { ".SUFFIXES", Suffixes, 0 }, { ".USE", Attribute, OP_USE }, { ".USEBEFORE", Attribute, OP_USEBEFORE }, @@ -915,6 +917,8 @@ ParseDoOp(void *gnp, void *opp) gn->type |= op & ~OP_OPMASK; cohort = Targ_FindNode(gn->name, TARG_NOHASH); + if (doing_depend) + ParseMark(cohort); /* * Make the cohort invisible as well to avoid duplicating it into * other variables. True, parents of this target won't tend to do @@ -987,6 +991,8 @@ ParseDoSrc(int tOp, const char *src) */ snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number); gn = Targ_FindNode(wait_src, TARG_NOHASH); + if (doing_depend) + ParseMark(gn); gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN; Lst_ForEach(targets, ParseLinkSrc, gn); return; @@ -1018,6 +1024,8 @@ ParseDoSrc(int tOp, const char *src) * source and the current one. */ gn = Targ_FindNode(src, TARG_CREATE); + if (doing_depend) + ParseMark(gn); if (predecessor != NULL) { (void)Lst_AtEnd(predecessor->order_succ, gn); (void)Lst_AtEnd(gn->order_pred, predecessor); @@ -1049,6 +1057,8 @@ ParseDoSrc(int tOp, const char *src) /* Find/create the 'src' node and attach to all targets */ gn = Targ_FindNode(src, TARG_CREATE); + if (doing_depend) + ParseMark(gn); if (tOp) { gn->type |= tOp; } else { @@ -1294,6 +1304,7 @@ ParseDoDependency(char *line) * apply the .DEFAULT commands. * .PHONY The list of targets * .NOPATH Don't search for file in the path + * .STALE * .BEGIN * .END * .ERROR @@ -1304,42 +1315,45 @@ ParseDoDependency(char *line) * .ORDER Must set initial predecessor to NULL */ switch (specType) { - case ExPath: - if (paths == NULL) { - paths = Lst_Init(FALSE); - } - (void)Lst_AtEnd(paths, dirSearchPath); - break; - case Main: - if (!Lst_IsEmpty(create)) { - specType = Not; - } - break; - case Begin: - case End: - case dotError: - case Interrupt: - gn = Targ_FindNode(line, TARG_CREATE); - gn->type |= OP_NOTMAIN|OP_SPECIAL; - (void)Lst_AtEnd(targets, gn); - break; - case Default: - gn = Targ_NewGN(".DEFAULT"); - gn->type |= (OP_NOTMAIN|OP_TRANSFORM); - (void)Lst_AtEnd(targets, gn); - DEFAULT = gn; - break; - case NotParallel: - maxJobs = 1; - break; - case SingleShell: - compatMake = TRUE; - break; - case Order: - predecessor = NULL; - break; - default: - break; + case ExPath: + if (paths == NULL) { + paths = Lst_Init(FALSE); + } + (void)Lst_AtEnd(paths, dirSearchPath); + break; + case Main: + if (!Lst_IsEmpty(create)) { + specType = Not; + } + break; + case Begin: + case End: + case Stale: + case dotError: + case Interrupt: + gn = Targ_FindNode(line, TARG_CREATE); + if (doing_depend) + ParseMark(gn); + gn->type |= OP_NOTMAIN|OP_SPECIAL; + (void)Lst_AtEnd(targets, gn); + break; + case Default: + gn = Targ_NewGN(".DEFAULT"); + gn->type |= (OP_NOTMAIN|OP_TRANSFORM); + (void)Lst_AtEnd(targets, gn); + DEFAULT = gn; + break; + case NotParallel: + maxJobs = 1; + break; + case SingleShell: + compatMake = TRUE; + break; + case Order: + predecessor = NULL; + break; + default: + break; } } else if (strncmp(line, ".PATH", 5) == 0) { /* @@ -1398,6 +1412,8 @@ ParseDoDependency(char *line) } else { gn = Suff_AddTransform(targName); } + if (doing_depend) + ParseMark(gn); (void)Lst_AtEnd(targets, gn); } @@ -1445,6 +1461,7 @@ ParseDoDependency(char *line) Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); break; case Default: + case Stale: case Begin: case End: case dotError: @@ -1734,6 +1751,12 @@ Parse_IsVar(char *line) ch = *line++; wasSpace = TRUE; } +#ifdef SUNSHCMD + if (ch == ':' && strncmp(line, "sh", 2) == 0) { + line += 2; + continue; + } +#endif if (ch == '=') return TRUE; if (*line == '=' && ISEQOPERATOR(ch)) @@ -2327,7 +2350,7 @@ Parse_SetInput(const char *name, int line, int fd, * name of the include file so error messages refer to the right * place. */ - curFile->fname = name; + curFile->fname = bmake_strdup(name); curFile->lineno = line; curFile->first_lineno = line; curFile->nextbuf = nextbuf; @@ -2340,6 +2363,8 @@ Parse_SetInput(const char *name, int line, int fd, buf = curFile->nextbuf(curFile->nextbuf_arg, &len); if (buf == NULL) { /* Was all a waste of time ... */ + if (curFile->fname) + free(curFile->fname); free(curFile); return; } @@ -2454,6 +2479,7 @@ ParseGmakeExport(char *line) "Variable/Value missing from \"export\""); return; } + *value++ = '\0'; /* terminate variable */ /* * Expand the value before putting it in the environment. @@ -2562,6 +2588,16 @@ ParseGetLine(int flags, int *length) if (cf->P_end == NULL) /* End of string (aka for loop) data */ break; + /* see if there is more we can parse */ + while (ptr++ < cf->P_end) { + if ((ch = *ptr) == '\n') { + if (ptr > line && ptr[-1] == '\\') + continue; + Parse_Error(PARSE_WARNING, + "Zero byte read from file, skipping rest of line."); + break; + } + } if (cf->nextbuf != NULL) { /* * End of this buffer; return EOF and outer logic diff --git a/contrib/bmake/realpath.c b/contrib/bmake/realpath.c index 1ef2cd8..fbf0335 100644 --- a/contrib/bmake/realpath.c +++ b/contrib/bmake/realpath.c @@ -1,5 +1,5 @@ -/* $Id: realpath.c,v 1.2 2010/04/21 17:47:49 sjg Exp $ */ -/* from: $NetBSD: getcwd.c,v 1.45 2007/10/26 19:48:14 christos Exp $ */ +/* $Id: realpath.c,v 1.3 2013/01/25 17:06:09 sjg Exp $ */ +/* from: $NetBSD: getcwd.c,v 1.53 2012/06/21 23:29:23 enami Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -52,24 +52,40 @@ # include #endif +#ifndef __restrict +# define __restrict /* restrict */ +#endif + /* - * char *realpath(const char *path, char resolved[MAXPATHLEN]); + * char *realpath(const char *path, char *resolved); * * Find the real name of path, by removing all ".", ".." and symlink * components. Returns (resolved) on success, or (NULL) on failure, * in which case the path which caused trouble is left in (resolved). */ char * -realpath(const char *path, char *resolved) +realpath(const char * __restrict path, char * __restrict resolved) { struct stat sb; - int idx = 0, n, nlnk = 0; + int idx = 0, nlnk = 0; const char *q; - char *p, wbuf[2][MAXPATHLEN]; + char *p, wbuf[2][MAXPATHLEN], *fres; size_t len; + ssize_t n; + + /* POSIX sez we must test for this */ + if (path == NULL) { + errno = EINVAL; + return NULL; + } + + if (resolved == NULL) { + fres = resolved = malloc(MAXPATHLEN); + if (resolved == NULL) + return NULL; + } else + fres = NULL; - if (!path || !resolved || path == resolved) - return (NULL); /* * Build real path one by one with paying an attention to ., @@ -82,10 +98,10 @@ realpath(const char *path, char *resolved) */ p = resolved; - if (*path == 0) { - *p = 0; + if (*path == '\0') { + *p = '\0'; errno = ENOENT; - return (NULL); + goto out; } /* If relative path, start from current working directory. */ @@ -93,8 +109,8 @@ realpath(const char *path, char *resolved) /* check for resolved pointer to appease coverity */ if (resolved && getcwd(resolved, MAXPATHLEN) == NULL) { p[0] = '.'; - p[1] = 0; - return (NULL); + p[1] = '\0'; + goto out; } len = strlen(resolved); if (len > 1) @@ -106,18 +122,18 @@ loop: while (*path == '/') path++; - if (*path == 0) { + if (*path == '\0') { if (p == resolved) *p++ = '/'; - *p = 0; - return (resolved); + *p = '\0'; + return resolved; } /* Find the end of this component. */ q = path; do q++; - while (*q != '/' && *q != 0); + while (*q != '/' && *q != '\0'); /* Test . or .. */ if (path[0] == '.') { @@ -129,7 +145,7 @@ loop: /* Trim the last component. */ if (p != resolved) while (*--p != '/') - ; + continue; path = q; goto loop; } @@ -140,39 +156,39 @@ loop: errno = ENAMETOOLONG; if (p == resolved) *p++ = '/'; - *p = 0; - return (NULL); + *p = '\0'; + goto out; } p[0] = '/'; memcpy(&p[1], path, /* LINTED We know q > path. */ q - path); - p[1 + q - path] = 0; + p[1 + q - path] = '\0'; /* * If this component is a symlink, toss it and prepend link * target to unresolved path. */ - if (lstat(resolved, &sb) == -1) { - return (NULL); - } + if (lstat(resolved, &sb) == -1) + goto out; + if (S_ISLNK(sb.st_mode)) { if (nlnk++ >= MAXSYMLINKS) { errno = ELOOP; - return (NULL); + goto out; } n = readlink(resolved, wbuf[idx], sizeof(wbuf[0]) - 1); if (n < 0) - return (NULL); + goto out; if (n == 0) { errno = ENOENT; - return (NULL); + goto out; } /* Append unresolved path to link target and switch to it. */ if (n + (len = strlen(q)) + 1 > sizeof(wbuf[0])) { errno = ENAMETOOLONG; - return (NULL); + goto out; } memcpy(&wbuf[idx][n], q, len + 1); path = wbuf[idx]; @@ -185,12 +201,15 @@ loop: } if (*q == '/' && !S_ISDIR(sb.st_mode)) { errno = ENOTDIR; - return (NULL); + goto out; } /* Advance both resolved and unresolved path. */ p += 1 + q - path; path = q; goto loop; +out: + free(fres); + return NULL; } #endif diff --git a/contrib/bmake/suff.c b/contrib/bmake/suff.c index 6abdeb0..d4f0eb1 100644 --- a/contrib/bmake/suff.c +++ b/contrib/bmake/suff.c @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $ */ +/* $NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $"; +static char rcsid[] = "$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; #else -__RCSID("$NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $"); +__RCSID("$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -2058,118 +2058,124 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * children, then look for any overriding transformations they imply. * Should we find one, we discard the one we found before. */ + bottom = NULL; + targ = NULL; - while (ln != NULL) { - /* - * Look for next possible suffix... - */ - ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP); - - if (ln != NULL) { - int prefLen; /* Length of the prefix */ + if (!(gn->type & OP_PHONY)) { + while (ln != NULL) { /* - * Allocate a Src structure to which things can be transformed + * Look for next possible suffix... */ + ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP); + + if (ln != NULL) { + int prefLen; /* Length of the prefix */ + + /* + * Allocate a Src structure to which things can be transformed + */ + targ = bmake_malloc(sizeof(Src)); + targ->file = bmake_strdup(gn->name); + targ->suff = (Suff *)Lst_Datum(ln); + targ->suff->refCount++; + targ->node = gn; + targ->parent = NULL; + targ->children = 0; +#ifdef DEBUG_SRC + targ->cp = Lst_Init(FALSE); +#endif + + /* + * Allocate room for the prefix, whose end is found by + * subtracting the length of the suffix from + * the end of the name. + */ + prefLen = (eoname - targ->suff->nameLen) - sopref; + targ->pref = bmake_malloc(prefLen + 1); + memcpy(targ->pref, sopref, prefLen); + targ->pref[prefLen] = '\0'; + + /* + * Add nodes from which the target can be made + */ + SuffAddLevel(srcs, targ); + + /* + * Record the target so we can nuke it + */ + (void)Lst_AtEnd(targs, targ); + + /* + * Search from this suffix's successor... + */ + ln = Lst_Succ(ln); + } + } + + /* + * Handle target of unknown suffix... + */ + if (Lst_IsEmpty(targs) && suffNull != NULL) { + if (DEBUG(SUFF)) { + fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name); + } + targ = bmake_malloc(sizeof(Src)); targ->file = bmake_strdup(gn->name); - targ->suff = (Suff *)Lst_Datum(ln); + targ->suff = suffNull; targ->suff->refCount++; targ->node = gn; targ->parent = NULL; targ->children = 0; + targ->pref = bmake_strdup(sopref); #ifdef DEBUG_SRC targ->cp = Lst_Init(FALSE); #endif /* - * Allocate room for the prefix, whose end is found by subtracting - * the length of the suffix from the end of the name. + * Only use the default suffix rules if we don't have commands + * defined for this gnode; traditional make programs used to + * not define suffix rules if the gnode had children but we + * don't do this anymore. */ - prefLen = (eoname - targ->suff->nameLen) - sopref; - targ->pref = bmake_malloc(prefLen + 1); - memcpy(targ->pref, sopref, prefLen); - targ->pref[prefLen] = '\0'; + if (Lst_IsEmpty(gn->commands)) + SuffAddLevel(srcs, targ); + else { + if (DEBUG(SUFF)) + fprintf(debug_file, "not "); + } - /* - * Add nodes from which the target can be made - */ - SuffAddLevel(srcs, targ); + if (DEBUG(SUFF)) + fprintf(debug_file, "adding suffix rules\n"); - /* - * Record the target so we can nuke it - */ (void)Lst_AtEnd(targs, targ); - - /* - * Search from this suffix's successor... - */ - ln = Lst_Succ(ln); - } - } - - /* - * Handle target of unknown suffix... - */ - if (Lst_IsEmpty(targs) && suffNull != NULL) { - if (DEBUG(SUFF)) { - fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name); } - targ = bmake_malloc(sizeof(Src)); - targ->file = bmake_strdup(gn->name); - targ->suff = suffNull; - targ->suff->refCount++; - targ->node = gn; - targ->parent = NULL; - targ->children = 0; - targ->pref = bmake_strdup(sopref); -#ifdef DEBUG_SRC - targ->cp = Lst_Init(FALSE); -#endif - /* - * Only use the default suffix rules if we don't have commands - * defined for this gnode; traditional make programs used to - * not define suffix rules if the gnode had children but we - * don't do this anymore. + * Using the list of possible sources built up from the target + * suffix(es), try and find an existing file/target that matches. */ - if (Lst_IsEmpty(gn->commands)) - SuffAddLevel(srcs, targ); - else { - if (DEBUG(SUFF)) - fprintf(debug_file, "not "); - } - - if (DEBUG(SUFF)) - fprintf(debug_file, "adding suffix rules\n"); - - (void)Lst_AtEnd(targs, targ); - } - - /* - * Using the list of possible sources built up from the target suffix(es), - * try and find an existing file/target that matches. - */ - bottom = SuffFindThem(srcs, slst); + bottom = SuffFindThem(srcs, slst); - if (bottom == NULL) { - /* - * No known transformations -- use the first suffix found for setting - * the local variables. - */ - if (!Lst_IsEmpty(targs)) { - targ = (Src *)Lst_Datum(Lst_First(targs)); + if (bottom == NULL) { + /* + * No known transformations -- use the first suffix found + * for setting the local variables. + */ + if (!Lst_IsEmpty(targs)) { + targ = (Src *)Lst_Datum(Lst_First(targs)); + } else { + targ = NULL; + } } else { - targ = NULL; + /* + * Work up the transformation path to find the suffix of the + * target to which the transformation was made. + */ + for (targ = bottom; targ->parent != NULL; targ = targ->parent) + continue; } - } else { - /* - * Work up the transformation path to find the suffix of the - * target to which the transformation was made. - */ - for (targ = bottom; targ->parent != NULL; targ = targ->parent) - continue; } Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); @@ -2419,12 +2425,7 @@ SuffFindDeps(GNode *gn, Lst slst) */ Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); Var_Set(PREFIX, gn->name, gn, 0); - if (gn->type & OP_PHONY) { - /* - * If this is a .PHONY target, we do not apply suffix rules. - */ - return; - } + if (DEBUG(SUFF)) { fprintf(debug_file, "SuffFindDeps (%s)\n", gn->name); } diff --git a/contrib/bmake/var.c b/contrib/bmake/var.c index e958a36..290ad3a 100644 --- a/contrib/bmake/var.c +++ b/contrib/bmake/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.171 2012/06/12 19:21:51 joerg Exp $ */ +/* $NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.171 2012/06/12 19:21:51 joerg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $"; #else #include #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.171 2012/06/12 19:21:51 joerg Exp $"); +__RCSID("$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -139,6 +139,7 @@ __RCSID("$NetBSD: var.c,v 1.171 2012/06/12 19:21:51 joerg Exp $"); #include "dir.h" #include "job.h" +extern int makelevel; /* * This lets us tell if we have replaced the original environ * (which we cannot free). @@ -175,6 +176,7 @@ static char varNoError[] = ""; * The four contexts are searched in the reverse order from which they are * listed. */ +GNode *VAR_INTERNAL; /* variables from make itself */ GNode *VAR_GLOBAL; /* variables from the makefile */ GNode *VAR_CMD; /* variables defined on the command-line */ @@ -309,7 +311,6 @@ static char *VarGetPattern(GNode *, Var_Parse_State *, int, const char **, int, int *, int *, VarPattern *); static char *VarQuote(char *); -static char *VarChangeCase(char *, int); static char *VarHash(char *); static char *VarModify(GNode *, Var_Parse_State *, const char *, @@ -408,6 +409,10 @@ VarFind(const char *name, GNode *ctxt, int flags) (ctxt != VAR_GLOBAL)) { var = Hash_FindEntry(&VAR_GLOBAL->context, name); + if ((var == NULL) && (ctxt != VAR_INTERNAL)) { + /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ + var = Hash_FindEntry(&VAR_INTERNAL->context, name); + } } if ((var == NULL) && (flags & FIND_ENV)) { char *env; @@ -429,6 +434,9 @@ VarFind(const char *name, GNode *ctxt, int flags) (ctxt != VAR_GLOBAL)) { var = Hash_FindEntry(&VAR_GLOBAL->context, name); + if ((var == NULL) && (ctxt != VAR_INTERNAL)) { + var = Hash_FindEntry(&VAR_INTERNAL->context, name); + } if (var == NULL) { return NULL; } else { @@ -530,11 +538,20 @@ void Var_Delete(const char *name, GNode *ctxt) { Hash_Entry *ln; - - ln = Hash_FindEntry(&ctxt->context, name); + char *cp; + + if (strchr(name, '$')) { + cp = Var_Subst(NULL, name, VAR_GLOBAL, 0); + } else { + cp = (char *)name; + } + ln = Hash_FindEntry(&ctxt->context, cp); if (DEBUG(VAR)) { fprintf(debug_file, "%s:delete %s%s\n", - ctxt->name, name, ln ? "" : " (not found)"); + ctxt->name, cp, ln ? "" : " (not found)"); + } + if (cp != name) { + free(cp); } if (ln != NULL) { Var *v; @@ -649,6 +666,15 @@ Var_ExportVars(void) char *val; int n; + /* + * Several make's support this sort of mechanism for tracking + * recursion - but each uses a different name. + * We allow the makefiles to update MAKELEVEL and ensure + * children see a correctly incremented value. + */ + snprintf(tmp, sizeof(tmp), "%d", makelevel + 1); + setenv(MAKE_LEVEL_ENV, tmp, 1); + if (VAR_EXPORTED_NONE == var_exportedVars) return; @@ -770,7 +796,7 @@ Var_UnExport(char *str) if (unexport_env) { char **newenv; - cp = getenv(MAKE_LEVEL); /* we should preserve this */ + cp = getenv(MAKE_LEVEL_ENV); /* we should preserve this */ if (environ == savedEnv) { /* we have been here before! */ newenv = bmake_realloc(environ, 2 * sizeof(char *)); @@ -787,10 +813,7 @@ Var_UnExport(char *str) environ = savedEnv = newenv; newenv[0] = NULL; newenv[1] = NULL; - setenv(MAKE_LEVEL, cp, 1); -#ifdef MAKE_LEVEL_SAFE - setenv(MAKE_LEVEL_SAFE, cp, 1); -#endif + setenv(MAKE_LEVEL_ENV, cp, 1); } else { for (; *str != '\n' && isspace((unsigned char) *str); str++) continue; @@ -914,6 +937,14 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) } v = VarFind(name, ctxt, 0); if (v == NULL) { + if (ctxt == VAR_CMD && (flags & VAR_NO_EXPORT) == 0) { + /* + * This var would normally prevent the same name being added + * to VAR_GLOBAL, so delete it from there if needed. + * Otherwise -V name may show the wrong value. + */ + Var_Delete(name, VAR_GLOBAL); + } VarAdd(name, val, ctxt); } else { Buf_Empty(&v->val); @@ -948,25 +979,6 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL); } - /* - * Another special case. - * Several make's support this sort of mechanism for tracking - * recursion - but each uses a different name. - * We allow the makefiles to update .MAKE.LEVEL and ensure - * children see a correctly incremented value. - */ - if (ctxt == VAR_GLOBAL && strcmp(MAKE_LEVEL, name) == 0) { - char tmp[64]; - int level; - - level = atoi(val); - snprintf(tmp, sizeof(tmp), "%u", level + 1); - setenv(MAKE_LEVEL, tmp, 1); -#ifdef MAKE_LEVEL_SAFE - setenv(MAKE_LEVEL_SAFE, tmp, 1); -#endif - } - out: if (expanded_name != NULL) @@ -2302,9 +2314,7 @@ VarHash(char *str) size_t len, len2; unsigned char *ustr = (unsigned char *)str; uint32_t h, k, c1, c2; - int done; - done = 1; h = 0x971e137bU; c1 = 0x95543787U; c2 = 0x2ad7eb25U; @@ -2334,7 +2344,7 @@ VarHash(char *str) h = (h << 13) ^ (h >> 19); h = h * 5 + 0x52dce729U; h ^= k; - } while (!done); + } h ^= len2; h *= 0x85ebca6b; h ^= h >> 13; @@ -2350,37 +2360,6 @@ VarHash(char *str) return Buf_Destroy(&buf, FALSE); } -/*- - *----------------------------------------------------------------------- - * VarChangeCase -- - * Change the string to all uppercase or all lowercase - * - * Input: - * str String to modify - * upper TRUE -> uppercase, else lowercase - * - * Results: - * The string with case changed - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ -static char * -VarChangeCase(char *str, int upper) -{ - Buffer buf; - int (*modProc)(int); - - modProc = (upper ? toupper : tolower); - Buf_Init(&buf, 0); - for (; *str ; str++) { - Buf_AddByte(&buf, modProc(*str)); - } - return Buf_Destroy(&buf, FALSE); -} - static char * VarStrftime(const char *fmt, int zulu) { @@ -2567,7 +2546,8 @@ ApplyModifiers(char *nstr, const char *tstr, } apply_mods: if (DEBUG(VAR)) { - fprintf(debug_file, "Applying :%c to \"%s\"\n", *tstr, nstr); + fprintf(debug_file, "Applying[%s] :%c to \"%s\"\n", v->name, + *tstr, nstr); } newStr = var_Error; switch ((modifier = *tstr)) { @@ -3056,8 +3036,16 @@ ApplyModifiers(char *nstr, const char *tstr, VarRealpath, NULL); cp = tstr + 2; termc = *cp; - } else if (tstr[1] == 'u' || tstr[1] == 'l') { - newStr = VarChangeCase(nstr, (tstr[1] == 'u')); + } else if (tstr[1] == 'u') { + char *dp = bmake_strdup(nstr); + for (newStr = dp; *dp; dp++) + *dp = toupper((unsigned char)*dp); + cp = tstr + 2; + termc = *cp; + } else if (tstr[1] == 'l') { + char *dp = bmake_strdup(nstr); + for (newStr = dp; *dp; dp++) + *dp = tolower((unsigned char)*dp); cp = tstr + 2; termc = *cp; } else if (tstr[1] == 'W' || tstr[1] == 'w') { @@ -3167,8 +3155,8 @@ ApplyModifiers(char *nstr, const char *tstr, free(cp2); } if (DEBUG(VAR)) - fprintf(debug_file, "Pattern for [%s] is [%s]\n", nstr, - pattern); + fprintf(debug_file, "Pattern[%s] for [%s] is [%s]\n", + v->name, nstr, pattern); if (*tstr == 'M') { newStr = VarModify(ctxt, &parsestate, nstr, VarMatch, pattern); @@ -3523,7 +3511,8 @@ ApplyModifiers(char *nstr, const char *tstr, } } if (DEBUG(VAR)) { - fprintf(debug_file, "Result of :%c is \"%s\"\n", modifier, newStr); + fprintf(debug_file, "Result[%s] of :%c is \"%s\"\n", + v->name, modifier, newStr); } if (newStr != nstr) { @@ -4156,6 +4145,7 @@ Var_GetHead(char *file) void Var_Init(void) { + VAR_INTERNAL = Targ_NewGN("Internal"); VAR_GLOBAL = Targ_NewGN("Global"); VAR_CMD = Targ_NewGN("Command"); -- 1.8.4.1