Compare commits

...

12 Commits
trunk ... BMAKE

Author SHA1 Message Date
nia 8c218dc01b Import bmake- 2020-05-24 05:35:51 +00:00
joerg 41f4d684ea Import bmake-20150505 2015-05-19 21:36:43 +00:00
bsiegert 7cb16bb665 Import bmake-20110606. Many changes, among them:
- unit-tests/modts now works on MirBSD
  - meta mode
  - ApplyModifiers: when we parse a variable which is not the entire modifier
    string, or not followed by ':', do not consider it as containing modifiers.
  - when long modifiers fail to match, check sysV style.
  - :hash - cheap 32bit hash of value
  - :localtime, :gmtime - use value as format string for strftime.
  - fix for use after free() in CondDoExists().
  - boot-strap (TOOL_DIFF): aparently at least on linux distro
    formats the output of 'type' differently - so eat any "()"
  - correct sysV substitution handling of empty lhs and variable
  - correct exists() check for dir with trailing /
  - correct handling of modifiers for non-existant variables during evaluation
    of conditionals.
  - fix for incorrect .PARSEDIR when .OBJDIR is re-computed after makefiles
    have been read.
  - fix example of :? modifier in man page.
  - sigcompat.c: convert to ansi so we can use higher warning levels.
  - parse.c: SunOS 5.8 at least does not have MAP_FILE
  - use mmap(2) if available, for reading makefiles
  - to ensure unit-tests results match, need to control LC_ALL as well as LANG.
  - if stale dependency is an IMPSRC, search via .PATH
  - machine.sh: like os.sh, allow for uname -p producing useless drivel
  - boot-strap: document configure knobs for meta and filemon.
2011-06-18 22:17:41 +00:00
joerg 92219014db Import bmake-20100808:
- boot-strap (TOOL_DIFF): set this to ensure tests use the same version
  of diff that configure tested
- in jobs mode, when we discover we cannot make something, call
  PrintOnError before exit.
- formatting fixes for ignored errors
- ensure jobs are cleaned up regardless of where wait() was called.
- os.sh (MACHINE_ARCH): watch out for drivel from uname -p
- call PrintOnError from JobFinish when we detect an error we are not
  ignoring.
- use bmake_signal() which is a wrapper around sigaction() in place of
  signal()
- add .export-env to allow exporting variables to environment without
  tracking (so no re-export when the internal value is changed).
- fix for .info et al being greedy.
- back to using realpath on argv[0] but only if contains '/' and does not
  start with '/'.
2010-09-07 14:11:07 +00:00
joerg 4f45bdd33e Import bmake-20100510:
- use absolute path for bmake when running tests during boot-strap
- revert use of realpath on argv[0]
- print MAKE_PRINT_VAR_ON_ERROR before running .ERROR target
- fix for missing SIGCHLD when compiled with SunPRO
- fflush stdout before writing to stdout
2010-05-13 18:37:38 +00:00
joerg 8019959086 Import bmake-20100423:
- Fixes for vfork(), bogus $TMPDIR, .export and realpath(3)
- boot-strap fixes to allow -m .../mk, no default use of /usr/share/mk
  on !NetBSD, honor --with-default-sys-path
- Other small improvements
2010-04-24 20:33:51 +00:00
joerg 75156626a2 Import bmake-20100414:
- Resolve argv[0] with realpath if needed
- Add :tA to realpath(3)ify variables
- Support for .info, .warning, .error, .ERROR
- Unit tests for .ERROR / .error; never make .ERROR the default target
- Fix for .ALLSRC being populated twice
- Support for .MAKE_MODE, .MAKE.MAKEFILE_PREFERENCE, .MAKE_DEPENDFILE
- Haiku support
- Improved diagnostics for .for with multiple variables
- Rewrite bootstrap to not use make
- Fix for -m .../
- Add support for .unexport
- Catch typoes in .el*if etc
- Fix parsing of :S;...;...; applied to .for loop iterators appearing in
  dependency lines
2010-04-20 13:32:15 +00:00
joerg 1869e77931 Import bmake-20090909:
- .MAKE.LEVEL, -C, SIGINFO support
- fixes for :M and \:
- vfork signal handling fixes e.g. for Solaris
2009-09-18 20:55:21 +00:00
joerg b952f77587 bmake-20081111:
- remove unused compat code for (v)asprintf
- remove unneeded configure checks
- use emalloc and co only if the whole family is provided by libutil
2008-11-11 19:32:16 +00:00
joerg 0c12e37e30 Update to bmake 20081101 snapshot. The more important changes are:
- portability fixes for putenv
- man page updates
- fix processing of .END with -j
- fix some segmentation faults on parse errors
- debug output goes to stderr by default
- first round of fixes for A/UX
- fix crashes on long lines
- faster VarQuote
- fix use of ?= when the LHS contains variable references
2008-11-11 14:28:21 +00:00
joerg 769645f870 Import bmake-20080215 2008-03-09 19:39:31 +00:00
sjg dd9795f0fb Import bmake-20051105 2005-12-02 00:02:59 +00:00
288 changed files with 77814 additions and 0 deletions

2378
devel/bmake/files/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

186
devel/bmake/files/FILES Normal file
View File

@ -0,0 +1,186 @@
ChangeLog
FILES
Makefile
Makefile.config.in
PSD.doc/Makefile
PSD.doc/tutorial.ms
README
VERSION
aclocal.m4
arch.c
bmake.1
bmake.cat1
boot-strap
bsd.after-import.mk
buf.c
buf.h
compat.c
cond.c
config.h.in
configure
configure.in
dir.c
dir.h
dirname.c
filemon/filemon.h
filemon/filemon_dev.c
filemon/filemon_ktrace.c
find_lib.sh
for.c
getopt.c
hash.c
hash.h
install-sh
job.c
job.h
lst.h
lst.lib/Makefile
lst.lib/lstAppend.c
lst.lib/lstAtEnd.c
lst.lib/lstAtFront.c
lst.lib/lstClose.c
lst.lib/lstConcat.c
lst.lib/lstDatum.c
lst.lib/lstDeQueue.c
lst.lib/lstDestroy.c
lst.lib/lstDupl.c
lst.lib/lstEnQueue.c
lst.lib/lstFind.c
lst.lib/lstFindFrom.c
lst.lib/lstFirst.c
lst.lib/lstForEach.c
lst.lib/lstForEachFrom.c
lst.lib/lstInit.c
lst.lib/lstInsert.c
lst.lib/lstInt.h
lst.lib/lstIsAtEnd.c
lst.lib/lstIsEmpty.c
lst.lib/lstLast.c
lst.lib/lstMember.c
lst.lib/lstNext.c
lst.lib/lstOpen.c
lst.lib/lstPrev.c
lst.lib/lstRemove.c
lst.lib/lstReplace.c
lst.lib/lstSucc.c
machine.sh
main.c
make-bootstrap.sh.in
make-conf.h
make.1
make.c
make.h
make_malloc.c
make_malloc.h
makefile.in
meta.c
meta.h
metachar.c
metachar.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
trace.c
trace.h
unit-tests/Makefile
unit-tests/Makefile.config.in
unit-tests/comment.exp
unit-tests/comment.mk
unit-tests/cond1.exp
unit-tests/cond1.mk
unit-tests/cond2.exp
unit-tests/cond2.mk
unit-tests/cond-late.mk
unit-tests/cond-late.exp
unit-tests/dollar.exp
unit-tests/dollar.mk
unit-tests/doterror.exp
unit-tests/doterror.mk
unit-tests/dotwait.exp
unit-tests/dotwait.mk
unit-tests/error.exp
unit-tests/error.mk
unit-tests/escape.exp
unit-tests/escape.mk
unit-tests/export-all.exp
unit-tests/export-all.mk
unit-tests/export-env.exp
unit-tests/export-env.mk
unit-tests/export.exp
unit-tests/export.mk
unit-tests/forloop.exp
unit-tests/forloop.mk
unit-tests/forsubst.exp
unit-tests/forsubst.mk
unit-tests/hash.exp
unit-tests/hash.mk
unit-tests/impsrc.exp
unit-tests/impsrc.mk
unit-tests/include-main.exp
unit-tests/include-main.mk
unit-tests/include-sub.mk
unit-tests/include-subsub.mk
unit-tests/misc.exp
unit-tests/misc.mk
unit-tests/moderrs.exp
unit-tests/moderrs.mk
unit-tests/modmatch.exp
unit-tests/modmatch.mk
unit-tests/modmisc.exp
unit-tests/modmisc.mk
unit-tests/modorder.exp
unit-tests/modorder.mk
unit-tests/modts.exp
unit-tests/modts.mk
unit-tests/modword.exp
unit-tests/modword.mk
unit-tests/order.exp
unit-tests/order.mk
unit-tests/phony-end.exp
unit-tests/phony-end.mk
unit-tests/posix.exp
unit-tests/posix.mk
unit-tests/posix1.exp
unit-tests/posix1.mk
unit-tests/qequals.exp
unit-tests/qequals.mk
unit-tests/suffixes.exp
unit-tests/suffixes.mk
unit-tests/sunshcmd.exp
unit-tests/sunshcmd.mk
unit-tests/sysv.exp
unit-tests/sysv.mk
unit-tests/ternary.exp
unit-tests/ternary.mk
unit-tests/unexport-env.exp
unit-tests/unexport-env.mk
unit-tests/unexport.exp
unit-tests/unexport.mk
unit-tests/varcmd.exp
unit-tests/varcmd.mk
unit-tests/varmisc.exp
unit-tests/varmisc.mk
unit-tests/varmod-edge.exp
unit-tests/varmod-edge.mk
unit-tests/varquote.exp
unit-tests/varquote.mk
unit-tests/varshell.exp
unit-tests/varshell.mk
util.c
var.c
wait.h

241
devel/bmake/files/Makefile Normal file
View File

@ -0,0 +1,241 @@
# $Id: Makefile,v 1.1.1.2 2020/05/24 05:35:51 nia Exp $
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 \
metachar.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
.-include "VERSION"
.-include "Makefile.inc"
# 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?= ${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
# should be set by now
USE_FILEMON ?= no
.if ${USE_FILEMON:tl} != "no"
.PATH: ${.CURDIR}/filemon
SRCS+= filemon_${USE_FILEMON}.c
COPTS.meta.c+= -DUSE_FILEMON -DUSE_FILEMON_${USE_FILEMON:tu}
COPTS.job.c+= ${COPTS.meta.c}
.if ${USE_FILEMON} == "dev"
FILEMON_H ?= /usr/include/dev/filemon/filemon.h
.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
COPTS.filemon_dev.c += -DHAVE_FILEMON_H -I${FILEMON_H:H}
.endif
.endif # USE_FILEMON == dev
.endif # USE_FILEMON
.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 MirBSD Bitrig
# 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=
# suppress with -DWITHOUT_*
OPTIONS_DEFAULT_YES+= \
AUTOCONF_MK \
INSTALL_MK \
PROG_LINK
OPTIONS_DEFAULT_NO+= \
PROG_VERSION
# process options now
.include <own.mk>
.if ${MK_PROG_VERSION} == "yes"
PROG_NAME= ${PROG}-${_MAKE_VERSION}
.if ${MK_PROG_LINK} == "yes"
SYMLINKS+= ${PROG_NAME} ${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 '/^.Dt/s/MAKE/${PROG:tu}/' \
-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 <prog.mk>
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= ${SHAREDIR.bmake:U${prefix}/share}
BINDIR= ${BINDIR.bmake:U${prefix}/bin}
MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
.if !exists(.depend)
${OBJS}: config.h
.endif
# start-delete2 for bsd.after-import.mk
# make sure that MAKE_VERSION gets updated.
main.o: ${SRCS} ${.CURDIR}/VERSION
.if ${MK_AUTOCONF_MK} == "yes"
CONFIGURE_DEPS += ${.CURDIR}/VERSION
# we do not need or want the generated makefile
CONFIGURE_ARGS += --without-makefile
.include <autoconf.mk>
.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}

View File

@ -0,0 +1,22 @@
# things set by configure
_MAKE_VERSION?=@_MAKE_VERSION@
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@
USE_FILEMON?= @use_filemon@
FILEMON_H?= @filemon_h@
BMAKE_PATH_MAX?= @bmake_path_max@
# used if MAXPATHLEN not defined
CPPFLAGS+= -DBMAKE_PATH_MAX=${BMAKE_PATH_MAX}

View File

@ -0,0 +1,171 @@
# $NetBSD: Makefile.in,v 1.1.1.10 2011/06/18 22:17:41 bsiegert Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
# $Id: Makefile.in,v 1.1.1.10 2011/06/18 22:17:41 bsiegert 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= 20110606
MACHINE=@machine@
MACHINE_ARCH=@machine_arch@
DEFAULT_SYS_PATH = @default_sys_path@
CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
CFLAGS+= -I. -I${srcdir} @DEFS@ @CPPFLAGS@ ${XDEFS} -DMAKE_NATIVE
CFLAGS+= ${CFLAGS_${.TARGET:T}}
CFLAGS_main.o= "-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:tl} != "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 empty(isBSD44:M${OS})
# XXX not sure if we still want this given that configure
# lets us force or not the definition of MACHINE.
CFLAGS_main.o+= "-DFORCE_MACHINE=\"${MACHINE}\""
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
# 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")
${MAN}: make.1
@echo making ${PROG}.1
@sed -e '/^.Nm/s/make/${PROG}/' -e '/^.Sh HISTORY/,$$d' ${srcdir}/make.1 > $@
@(echo ".Sh HISTORY"; echo ".Nm"; echo "is derived from NetBSD's"; echo ".Xr make 1 ."; echo It uses autoconf to facilitate portability to other platforms.) >> $@
.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 <bsd.prog.mk>
# 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(SUBDIR) && !target(${SUBDIR:[1]})
.-include <bsd.subdir.mk>
.endif
# 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
CFLAGS_var.o += -Wno-cast-qual
.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 && ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}

View File

@ -0,0 +1,10 @@
# $NetBSD: Makefile,v 1.1.1.4 2015/05/19 21:36:44 joerg Exp $
# @(#)Makefile 8.1 (Berkeley) 8/14/93
SECTION=reference/ref1
ARTICLE=make
SRCS= tutorial.ms
MACROS= -ms
EXTRAHTMLFILES=make1.png make2.png
.include <bsd.doc.mk>

File diff suppressed because it is too large Load Diff

52
devel/bmake/files/README Normal file
View File

@ -0,0 +1,52 @@
bmake
*****
This directory contains a port of the BSD make tool (from NetBSD).
Since 1993 I have run it on AIX, BSDi, Darwin, FreeBSD, HP-UX, IRIX,
Linux, Minix, OSF, Solaris, SunOS and even UTS.
Others have run it on many more systems.
Currently each release is tested on NetBSD, FreeBSD, Solaris and Linux.
Since 2003 bmake switched to a date based version (first was 20030714)
which generally represents the date it was last merged with NetBSD's
make. Since then, NetBSD's make is imported within a week of any
interesting changes, so that bmake tracks it very closely.
Building
========
The preferred way to bootstrap bmake is::
./bmake/boot-strap
there are a number of args - most of which get passed to configure,
eg.
::
./bmake/boot-strap --prefix=/opt
see the boot-strap script for details.
For folk that hate to read anything, since 20121212 you can also use
the GNU standard process of::
./configure; make; make install
To make much use of bmake you will need the bsd.*.mk macros or my
portable *.mk macros which are included with bmake since 20121212
and separately available from
http://www.crufty.net/ftp/pub/sjg/mk.tar.gz
which will be links to the latest versions.
Porting
=======
If you encounter a system that bmake does not build or work on *out of
the box*, I welcome patches.
If you can provide access to a suitable machine - even better.
More info can be found at http://www.crufty.net/help/sjg/bmake.htm
--sjg <sjg@crufty.net>

View File

@ -0,0 +1,2 @@
# keep this compatible with sh and make
_MAKE_VERSION=20200517

82
devel/bmake/files/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,82 @@
dnl RCSid:
dnl $Id: aclocal.m4,v 1.1.1.4 2020/05/24 05:35:51 nia Exp $
dnl
dnl
dnl AC_CHECK_HEADER_HAS(HEADER, PATTERN, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]))
AC_DEFUN(AC_CHECK_HEADER_HAS,
[dnl first check if header exists and if so, see if it contains PATTERN
ac_has_hdr=`echo "ac_cv_header_$1" | sed 'y%./+-%__p_%'`
ac_has_it=`echo "ac_cv_header_$1"_$2 | sed 'y%./+-%__p_%'`
if eval "test \"`echo x'$'$ac_has_hdr`\" = x"; then
AC_CHECK_HEADER($1)
fi
if eval "test \"`echo '$'$ac_has_hdr`\" = yes"; then
ac_x=HAVE_`echo "$1" | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
AC_DEFINE_UNQUOTED($ac_x)
AC_MSG_CHECKING([if $1 has $2])
AC_CACHE_VAL($ac_has_it,
[eval $ac_has_it=no
AC_EGREP_HEADER($2, $1, eval "$ac_has_it=yes")])
if eval "test \"`echo '$'$ac_has_it`\" = yes"; then
AC_MSG_RESULT(yes)
ac_x=HAVE_`echo "$1"_$2 | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
AC_DEFINE_UNQUOTED($ac_x)
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT(no)
ifelse([$4], , , [$4
])dnl
fi
fi
])
dnl AC_EGREP(PATTERN, FILE, ACTION-IF-FOUND [,
dnl ACTION-IF-NOT-FOUND])
AC_DEFUN(AC_EGREP,
[
dnl Prevent m4 from eating character classes:
changequote(, )dnl
if egrep "$1" $2 >/dev/null 2>&1; then
changequote([, ])dnl
ifelse([$3], , :, [$3])
ifelse([$4], , , [else
$4
])dnl
fi
])
dnl
dnl Test for __attribute__
dnl
AC_DEFUN(AC_C___ATTRIBUTE__, [
AC_MSG_CHECKING(for __attribute__)
AC_CACHE_VAL(ac_cv___attribute__, [
AC_LINK_IFELSE([
#include <stdlib.h>
static void foo(void) __attribute__ ((noreturn));
static void
foo(void)
{
exit(1);
}
int
main(int argc, char **argv)
{
foo();
}
],
ac_cv___attribute__=yes,
ac_cv___attribute__=no)])
if test "$ac_cv___attribute__" = "yes"; then
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
fi
AC_MSG_RESULT($ac_cv___attribute__)
])

1416
devel/bmake/files/arch.c Normal file

File diff suppressed because it is too large Load Diff

2419
devel/bmake/files/bmake.1 Normal file

File diff suppressed because it is too large Load Diff

1544
devel/bmake/files/bmake.cat1 Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 78 KiB

File diff suppressed because it is too large Load Diff

475
devel/bmake/files/boot-strap Executable file
View File

@ -0,0 +1,475 @@
:
# NAME:
# boot-strap
#
# SYNOPSIS:
# 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 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 (unless SKIP_RC is set in environment).
#
# --share "share_dir"
# Where to put man pages and mk files.
# If $prefix ends in $HOST_TARGET, and $prefix/../share
# exits, the default will be that rather than $prefix/share.
#
# --mksrc "mksrc"
# Indicate where the mk files can be found.
# 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:
#
# --without-meta
# disable use of meta mode.
#
# --without-filemon
# disable use of filemon(9) which is currently only
# available for NetBSD and FreeBSD.
#
# --with-filemon=ktrace
# on NetBSD or others with fktrace(2), use ktrace
# version of filemon.
#
# --with-filemon="path/to/filemon.h"
# enables use of filemon(9) by meta mode.
#
# --with-machine="machine"
# set "machine" to override that determined by
# machine.sh
#
# --with-force-machine="machine"
# force "machine" even if uname(3) provides a value.
#
# --with-machine_arch="machine_arch"
# set "machine_arch" to override that determined by
# machine.sh
#
# --with-default-sys-path="syspath"
# set an explicit default "syspath" which is where bmake
# will look for sys.mk and friends.
#
# AUTHOR:
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: boot-strap,v 1.1.1.12 2020/05/24 05:35:51 nia Exp $
#
# @(#) Copyright (c) 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
#
Mydir=`dirname $0`
. "$Mydir/os.sh"
case "$Mydir" in
/*) ;;
*) Mydir=`cd "$Mydir" && 'pwd'`;;
esac
Usage() {
[ "$1" ] && echo "ERROR: $@" >&2
echo "Usage:" >&2
echo "$0 [--<configure_arg> ...][<prefix>][--install]" >&2
exit 1
}
Error() {
echo "ERROR: $@" >&2
exit 1
}
source_rc() {
rc="$1"; shift
for d in ${*:-""}
do
r="${d:+$d/}$rc"
[ -f "$r" -a -s "$r" ] || continue
echo "NOTE: reading $r"
. "$r"
break
done
}
cmd_args="$@"
# clear some things from the environment that we care about
unset MAKEOBJDIR MAKEOBJDIRPREFIX
# or that might be incompatible
unset MAKE MAKEFLAGS
# --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:-.}" ] || 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=$Mydir
mksrc=$Mydir/mk
objdir=
quiet=:
${SKIP_RC:+:} source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME"
get_optarg() {
expr "x$1" : "x[^=]*=\\(.*\\)"
}
here=`'pwd'`
if [ $here = $Mydir ]; then
# avoid pollution
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"`;;
--with-mksrc=*|--mksrc=*) mksrc=`get_optarg "$1"`;;
--share=*) share_dir=`get_optarg "$1"`;;
--share) share_dir="$2"; shift;;
--with-default-sys-path=*)
CONFIGURE_ARGS="$1";;
--with-default-sys-path)
CONFIGURE_ARGS="$1 $2";;
--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;;
-q) quiet=;;
-c) source_rc "$2"; shift;;
--*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1";;
*=*) eval "$1"; export `expr "x$1" : "x\\(.[^=]*\\)=.*"`;;
*) break;;
esac
shift
done
AddConfigure() {
case " $CONFIGURE_ARGS " in
*" $1"*) ;;
*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1$2";;
esac
}
GetDir() {
match="$1"
shift
fmatch="$1"
shift
for dir in $*
do
[ -d "$dir" ] || continue
case "/$dir/" in
*$match*) ;;
*) continue;;
esac
case "$fmatch" in
.) ;;
*) [ -s $dir/$fmatch ] || continue;;
esac
case "$dir/" in
*./*) cd "$dir" && 'pwd';;
/*) echo $dir;;
*) cd "$dir" && 'pwd';;
esac
break
done
}
FindHereOrAbove() {
(
_t=-s
while :
do
case "$1" in
-C) cd "$2"; shift; shift;;
-?) _t=$1; shift;;
*) break;;
esac
done
case "$1" in
/*) # we shouldn't be here
[ $_t "$1" ] && echo "$1"
return
;;
.../*) want=`echo "$1" | sed 's,^.../*,,'`;;
*) want="$1";;
esac
here=`'pwd'`
while :
do
if [ $_t "./$want" ]; then
echo "$here/$want"
return
fi
cd ..
here=`'pwd'`
case "$here" in
/) return;;
esac
done
)
}
# is $1 missing from $2 (or PATH) ?
no_path() {
eval "__p=\$${2:-PATH}"
case ":$__p:" in *:"$1":*) return 1;; *) return 0;; esac
}
# if $1 exists and is not in path, append it
add_path () {
case "$1" in
-?) t=$1; shift;;
*) t=-d;;
esac
case "$2,$1" in
MAKESYSPATH,.../*) ;;
*) [ $t ${1:-.} ] || return;;
esac
no_path $* && eval ${2:-PATH}="$__p${__p:+:}$1"
}
srcdir=`GetDir /bmake make-bootstrap.sh.in "$srcdir" "$2" "$Mydir" ./bmake* "$Mydir"/../bmake*`
[ -d "${srcdir:-/dev/null}" ] || Usage
case "$mksrc" in
none|-) # we ignore this now
mksrc=$Mydir/mk
;;
.../*) # find here or above
mksrc=`FindHereOrAbove -C "$Mydir" -s "$mksrc/sys.mk"`
# that found a file
mksrc=`dirname $mksrc`
;;
*) # guess we want mksrc...
mksrc=`GetDir /mk sys.mk "$mksrc" "$3" ./mk* "$srcdir"/mk* "$srcdir"/../mk*`
[ -d "${mksrc:-/dev/null}" ] || Usage "Use '-m none' to build without mksrc"
;;
esac
# Ok, get to work...
objdir="${objdir:-$OBJROOT$HOST_TARGET}"
[ -d "$objdir" ] || mkdir -p "$objdir"
[ -d "$objdir" ] || mkdir "$objdir"
cd "$objdir" || exit 1
# make it absolute
objdir=`'pwd'`
ShareDir() {
case "/$1" in
/) [ -d /share ] || return;;
*/$HOST_TARGET)
if [ -d "$1/../share" ]; then
echo `dirname "$1"`/share
return
fi
;;
esac
echo $1/share
}
# make it easy to force prefix to use $HOST_TARGET
: looking at "$prefix"
case "$prefix" in
*/host?target) prefix=`echo "$prefix" | sed "s,host.target,${HOST_TARGET},"`;;
esac
share_dir="${share_dir:-`ShareDir $prefix`}"
AddConfigure --prefix= "$prefix"
case "$CONFIGURE_ARGS" in
*--with-*-sys-path*) ;; # skip
*) [ "$share_dir" ] && AddConfigure --with-default-sys-path= "$share_dir/mk";;
esac
if [ "$mksrc" ]; then
AddConfigure --with-mksrc= "$mksrc"
# not all cc's support this
CFLAGS_MF= CFLAGS_MD=
export CFLAGS_MF CFLAGS_MD
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 "$@"
)
}
# there is actually a shell where type is not a builtin
# if type is missing, which(1) had better exists!
if (type cat) > /dev/null 2>&1; then
which() {
type "$@" | sed 's,[()],,g;s,^[^/][^/]*,,;q'
}
fi
# make sure test below uses the same diff that configure did
TOOL_DIFF=`which diff`
export TOOL_DIFF
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
}
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 suppress bmake -> bmake-$MAKE_VERSION symlink"
echo "Use -DWITHOUT_INSTALL_MK to skip installing files to $prefix/share/mk"
fi
}
op_$op
exit 0

View File

@ -0,0 +1,111 @@
# $Id: bsd.after-import.mk,v 1.1.1.2 2020/05/24 05:35:51 nia Exp $
# This makefile is for use when integrating bmake into a BSD build
# system. Use this makefile after importing bmake.
# It will bootstrap the new version,
# capture the generated files we need, and add an after-import
# target to allow the process to be easily repeated.
# The goal is to allow the benefits of autoconf without
# the overhead of running configure.
all: _makefile
all: after-import
# we rely on bmake
.if !defined(.PARSEDIR)
.error this makefile requires bmake
.endif
_this := ${MAKEFILE:tA}
BMAKE_SRC := ${.PARSEDIR}
# it helps to know where the top of the tree is.
.if !defined(SRCTOP)
srctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
.if empty(srctop)
# likely locations?
.for d in contrib/bmake external/bsd/bmake/dist
.if ${BMAKE_SRC:M*/$d} != ""
srctop := ${BMAKE_SRC:tA:S,/$d,,}
.endif
.endfor
.endif
.if !empty(srctop)
SRCTOP := ${srctop}
.endif
.endif
# This lets us match what boot-strap does
.if !defined(HOST_OS)
HOST_OS!= uname
.endif
BOOTSTRAP_ARGS = \
--prefix /usr \
--share /usr/share
.if !empty(DEFAULT_SYS_PATH)
BOOTSTRAP_ARGS += --with-default-sys-path='${DEFAULT_SYS_PATH}'
.endif
# run boot-strap with minimal influence
bootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE}
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 '/include.*VERSION/d' \
-e '/^PROG/ { s,=,?=,;s,bmake,$${.CURDIR:T},; }' \
-e 's,^.-include,.sinclude,' \
-e '/^\..*include *</ { s,<,<bsd.,;/autoconf/d; }' \
-e 's,${SRCTOP},$${SRCTOP},g'
# These are the simple files we want to capture
configured_files= config.h Makefile.config unit-tests/Makefile.config
after-import: bootstrap ${MAKEFILE}
.for f in ${configured_files:M*.[ch]}
@echo Capturing $f
@mkdir -p ${${.CURDIR}/$f:L:H}
@(echo '/* $$${HOST_OS}$$ */'; cat ${HOST_OS}/$f) > ${.CURDIR}/$f
.endfor
.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 '# $$${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
# this needs the most work
_makefile: bootstrap ${MAKEFILE}
@echo Generating ${.CURDIR}/Makefile
@(echo '# This is a generated file, do NOT edit!'; \
echo '# See ${_this:S,${SRCTOP}/,,}'; \
echo '#'; echo '# $$${HOST_OS}$$'; \
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; \
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; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo ) > ${.TARGET}
@cmp -s ${.TARGET} ${.CURDIR}/Makefile || \
mv ${.TARGET} ${.CURDIR}/Makefile
.include <bsd.obj.mk>

291
devel/bmake/files/buf.c Normal file
View File

@ -0,0 +1,291 @@
/* $NetBSD: buf.c,v 1.1.1.6 2015/05/19 21:36:43 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: buf.c,v 1.1.1.6 2015/05/19 21:36:43 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: buf.c,v 1.1.1.6 2015/05/19 21:36:43 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* buf.c --
* Functions for automatically-expanded buffers.
*/
#include "make.h"
#include "buf.h"
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#define BUF_DEF_SIZE 256 /* Default buffer size */
/*-
*-----------------------------------------------------------------------
* Buf_Expand_1 --
* Extend buffer for single byte add.
*
*-----------------------------------------------------------------------
*/
void
Buf_Expand_1(Buffer *bp)
{
bp->size += max(bp->size, 16);
bp->buffer = bmake_realloc(bp->buffer, bp->size);
}
/*-
*-----------------------------------------------------------------------
* Buf_AddBytes --
* Add a number of bytes to the buffer.
*
* Results:
* None.
*
* Side Effects:
* Guess what?
*
*-----------------------------------------------------------------------
*/
void
Buf_AddBytes(Buffer *bp, int numBytes, const Byte *bytesPtr)
{
int count = bp->count;
Byte *ptr;
if (__predict_false(count + numBytes >= bp->size)) {
bp->size += max(bp->size, numBytes + 16);
bp->buffer = bmake_realloc(bp->buffer, bp->size);
}
ptr = bp->buffer + count;
bp->count = count + numBytes;
ptr[numBytes] = 0;
memcpy(ptr, bytesPtr, numBytes);
}
/*-
*-----------------------------------------------------------------------
* Buf_GetAll --
* Get all the available data at once.
*
* Results:
* A pointer to the data and the number of bytes available.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
Byte *
Buf_GetAll(Buffer *bp, int *numBytesPtr)
{
if (numBytesPtr != NULL)
*numBytesPtr = bp->count;
return (bp->buffer);
}
/*-
*-----------------------------------------------------------------------
* Buf_Empty --
* Throw away bytes in a buffer.
*
* Results:
* None.
*
* Side Effects:
* The bytes are discarded.
*
*-----------------------------------------------------------------------
*/
void
Buf_Empty(Buffer *bp)
{
bp->count = 0;
*bp->buffer = 0;
}
/*-
*-----------------------------------------------------------------------
* Buf_Init --
* Initialize a buffer. If no initial size is given, a reasonable
* default is used.
*
* Input:
* size Initial size for the buffer
*
* Results:
* A buffer to be given to other functions in this library.
*
* Side Effects:
* The buffer is created, the space allocated and pointers
* initialized.
*
*-----------------------------------------------------------------------
*/
void
Buf_Init(Buffer *bp, int size)
{
if (size <= 0) {
size = BUF_DEF_SIZE;
}
bp->size = size;
bp->count = 0;
bp->buffer = bmake_malloc(size);
*bp->buffer = 0;
}
/*-
*-----------------------------------------------------------------------
* Buf_Destroy --
* Nuke a buffer and all its resources.
*
* Input:
* buf Buffer to destroy
* freeData TRUE if the data should be destroyed
*
* Results:
* Data buffer, NULL if freed
*
* Side Effects:
* The buffer is freed.
*
*-----------------------------------------------------------------------
*/
Byte *
Buf_Destroy(Buffer *buf, Boolean freeData)
{
Byte *data;
data = buf->buffer;
if (freeData) {
free(data);
data = NULL;
}
buf->size = 0;
buf->count = 0;
buf->buffer = NULL;
return data;
}
/*-
*-----------------------------------------------------------------------
* Buf_DestroyCompact --
* Nuke a buffer and return its data.
*
* Input:
* buf Buffer to destroy
*
* Results:
* Data buffer
*
* Side Effects:
* If the buffer size is much greater than its content,
* a new buffer will be allocated and the old one freed.
*
*-----------------------------------------------------------------------
*/
#ifndef BUF_COMPACT_LIMIT
# define BUF_COMPACT_LIMIT 128 /* worthwhile saving */
#endif
Byte *
Buf_DestroyCompact(Buffer *buf)
{
#if BUF_COMPACT_LIMIT > 0
Byte *data;
if (buf->size - buf->count >= BUF_COMPACT_LIMIT) {
/* We trust realloc to be smart */
data = bmake_realloc(buf->buffer, buf->count + 1);
if (data) {
data[buf->count] = 0;
Buf_Destroy(buf, FALSE);
return data;
}
}
#endif
return Buf_Destroy(buf, FALSE);
}

119
devel/bmake/files/buf.h Normal file
View File

@ -0,0 +1,119 @@
/* $NetBSD: buf.h,v 1.1.1.6 2020/05/24 05:35:51 nia Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*-
* buf.h --
* Header for users of the buf library.
*/
#ifndef MAKE_BUF_H
#define MAKE_BUF_H
typedef char Byte;
typedef struct Buffer {
int size; /* Current size of the buffer */
int count; /* Number of bytes in buffer */
Byte *buffer; /* The buffer itself (zero terminated) */
} Buffer;
/* If we aren't on netbsd, __predict_false() might not be defined. */
#ifndef __predict_false
#define __predict_false(x) (x)
#endif
/* Buf_AddByte adds a single byte to a buffer. */
#define Buf_AddByte(bp, byte) do { \
int _count = ++(bp)->count; \
char *_ptr; \
if (__predict_false(_count >= (bp)->size)) \
Buf_Expand_1(bp); \
_ptr = (bp)->buffer + _count; \
_ptr[-1] = (byte); \
_ptr[0] = 0; \
} while (0)
#define BUF_ERROR 256
#define Buf_Size(bp) ((bp)->count)
void Buf_Expand_1(Buffer *);
void Buf_AddBytes(Buffer *, int, const Byte *);
Byte *Buf_GetAll(Buffer *, int *);
void Buf_Empty(Buffer *);
void Buf_Init(Buffer *, int);
Byte *Buf_Destroy(Buffer *, Boolean);
Byte *Buf_DestroyCompact(Buffer *);
#endif /* MAKE_BUF_H */

781
devel/bmake/files/compat.c Normal file
View File

@ -0,0 +1,781 @@
/* $NetBSD: compat.c,v 1.1.1.10 2020/05/24 05:35:51 nia Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: compat.c,v 1.1.1.10 2020/05/24 05:35:51 nia Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.1.1.10 2020/05/24 05:35:51 nia Exp $");
#endif
#endif /* not lint */
#endif
/*-
* compat.c --
* The routines in this file implement the full-compatibility
* mode of PMake. Most of the special functionality of PMake
* is available in this mode. Things not supported:
* - different shells.
* - friendly variable substitution.
*
* Interface:
* Compat_Run Initialize things for this module and recreate
* thems as need creatin'
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include "wait.h"
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include "make.h"
#include "hash.h"
#include "dir.h"
#include "job.h"
#include "metachar.h"
#include "pathnames.h"
static GNode *curTarg = NULL;
static GNode *ENDNode;
static void CompatInterrupt(int);
static pid_t compatChild;
static int compatSigno;
/*
* CompatDeleteTarget -- delete a failed, interrupted, or otherwise
* duffed target if not inhibited by .PRECIOUS.
*/
static void
CompatDeleteTarget(GNode *gn)
{
if ((gn != NULL) && !Targ_Precious (gn)) {
char *p1;
char *file = Var_Value(TARGET, gn, &p1);
if (!noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
}
free(p1);
}
}
/*-
*-----------------------------------------------------------------------
* CompatInterrupt --
* Interrupt the creation of the current target and remove it if
* it ain't precious.
*
* Results:
* None.
*
* Side Effects:
* The target is removed and the process exits. If .INTERRUPT exists,
* its commands are run first WITH INTERRUPTS IGNORED..
*
* XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've
* left the logic alone for now. - dholland 20160826
*
*-----------------------------------------------------------------------
*/
static void
CompatInterrupt(int signo)
{
GNode *gn;
CompatDeleteTarget(curTarg);
if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
/*
* Run .INTERRUPT only if hit with interrupt signal
*/
if (signo == SIGINT) {
gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
if (gn != NULL) {
Compat_Make(gn, gn);
}
}
}
if (signo == SIGQUIT)
_exit(signo);
/*
* If there is a child running, pass the signal on
* we will exist after it has exited.
*/
compatSigno = signo;
if (compatChild > 0) {
KILLPG(compatChild, signo);
} else {
bmake_signal(signo, SIG_DFL);
kill(myPid, signo);
}
}
/*-
*-----------------------------------------------------------------------
* CompatRunCommand --
* Execute the next command for a target. If the command returns an
* error, the node's made field is set to ERROR and creation stops.
*
* Input:
* cmdp Command to execute
* gnp Node from which the command came
*
* Results:
* 0 if the command succeeded, 1 if an error occurred.
*
* Side Effects:
* The node's 'made' field may be set to ERROR.
*
*-----------------------------------------------------------------------
*/
int
CompatRunCommand(void *cmdp, void *gnp)
{
char *cmdStart; /* Start of expanded command */
char *cp, *bp;
Boolean silent, /* Don't print command */
doIt; /* Execute even if -n */
volatile Boolean errCheck; /* Check errors */
WAIT_T reason; /* Reason for child's death */
int status; /* Description of child's death */
pid_t cpid; /* Child actually found */
pid_t retstat; /* Result of wait */
LstNode cmdNode; /* Node where current command is located */
const char ** volatile av; /* Argument vector for thing to exec */
char ** volatile mav;/* Copy of the argument vector for freeing */
int argc; /* Number of arguments in av or 0 if not
* dynamically allocated */
Boolean local; /* TRUE if command should be executed
* locally */
Boolean useShell; /* TRUE if command should be executed
* using a shell */
char * volatile cmd = (char *)cmdp;
GNode *gn = (GNode *)gnp;
silent = gn->type & OP_SILENT;
errCheck = !(gn->type & OP_IGNORE);
doIt = FALSE;
cmdNode = Lst_Member(gn->commands, cmd);
cmdStart = Var_Subst(NULL, cmd, gn, VARF_WANTRES);
/*
* brk_string will return an argv with a NULL in av[0], thus causing
* execvp to choke and die horribly. Besides, how can we execute a null
* command? In any case, we warn the user that the command expanded to
* nothing (is this the right thing to do?).
*/
if (*cmdStart == '\0') {
free(cmdStart);
return(0);
}
cmd = cmdStart;
Lst_Replace(cmdNode, cmdStart);
if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
(void)Lst_AtEnd(ENDNode->commands, cmdStart);
return(0);
}
if (strcmp(cmdStart, "...") == 0) {
gn->type |= OP_SAVE_CMDS;
return(0);
}
while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
switch (*cmd) {
case '@':
silent = DEBUG(LOUD) ? FALSE : TRUE;
break;
case '-':
errCheck = FALSE;
break;
case '+':
doIt = TRUE;
if (!shellName) /* we came here from jobs */
Shell_Init();
break;
}
cmd++;
}
while (isspace((unsigned char)*cmd))
cmd++;
/*
* If we did not end up with a command, just skip it.
*/
if (!*cmd)
return (0);
#if !defined(MAKE_NATIVE)
/*
* In a non-native build, the host environment might be weird enough
* that it's necessary to go through a shell to get the correct
* behaviour. Or perhaps the shell has been replaced with something
* that does extra logging, and that should not be bypassed.
*/
useShell = TRUE;
#else
/*
* Search for meta characters in the command. If there are no meta
* characters, there's no need to execute a shell to execute the
* command.
*
* Additionally variable assignments and empty commands
* go to the shell. Therefore treat '=' and ':' like shell
* meta characters as documented in make(1).
*/
useShell = needshell(cmd, FALSE);
#endif
/*
* Print the command before echoing if we're not supposed to be quiet for
* this one. We also print the command if -n given.
*/
if (!silent || NoExecute(gn)) {
printf("%s\n", cmd);
fflush(stdout);
}
/*
* If we're not supposed to execute any commands, this is as far as
* we go...
*/
if (!doIt && NoExecute(gn)) {
return (0);
}
if (DEBUG(JOB))
fprintf(debug_file, "Execute: '%s'\n", cmd);
again:
if (useShell) {
/*
* We need to pass the command off to the shell, typically
* because the command contains a "meta" character.
*/
static const char *shargv[5];
int shargc;
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[shargc++] = "-xc";
else
shargv[shargc++] = "-c";
shargv[shargc++] = cmd;
shargv[shargc++] = NULL;
av = shargv;
argc = 0;
bp = NULL;
mav = NULL;
} else {
/*
* No meta-characters, so no need to exec a shell. Break the command
* into words to form an argument vector we can execute.
*/
mav = brk_string(cmd, &argc, TRUE, &bp);
if (mav == NULL) {
useShell = 1;
goto again;
}
av = (void *)mav;
}
local = TRUE;
#ifdef USE_META
if (useMeta) {
meta_compat_start();
}
#endif
/*
* Fork and execute the single command. If the fork fails, we abort.
*/
compatChild = cpid = vFork();
if (cpid < 0) {
Fatal("Could not fork");
}
if (cpid == 0) {
Var_ExportVars();
#ifdef USE_META
if (useMeta) {
meta_compat_child();
}
#endif
if (local)
(void)execvp(av[0], (char *const *)UNCONST(av));
else
(void)execv(av[0], (char *const *)UNCONST(av));
execError("exec", av[0]);
_exit(1);
}
free(mav);
free(bp);
Lst_Replace(cmdNode, NULL);
#ifdef USE_META
if (useMeta) {
meta_compat_parent(cpid);
}
#endif
/*
* The child is off and running. Now all we can do is wait...
*/
while (1) {
while ((retstat = wait(&reason)) != cpid) {
if (retstat > 0)
JobReapChild(retstat, reason, FALSE); /* not ours? */
if (retstat == -1 && errno != EINTR) {
break;
}
}
if (retstat > -1) {
if (WIFSTOPPED(reason)) {
status = WSTOPSIG(reason); /* stopped */
} else if (WIFEXITED(reason)) {
status = WEXITSTATUS(reason); /* exited */
#if defined(USE_META) && defined(USE_FILEMON_ONCE)
if (useMeta) {
meta_cmd_finish(NULL);
}
#endif
if (status != 0) {
if (DEBUG(ERROR)) {
fprintf(debug_file, "\n*** Failed target: %s\n*** Failed command: ",
gn->name);
for (cp = cmd; *cp; ) {
if (isspace((unsigned char)*cp)) {
fprintf(debug_file, " ");
while (isspace((unsigned char)*cp))
cp++;
} else {
fprintf(debug_file, "%c", *cp);
cp++;
}
}
fprintf(debug_file, "\n");
}
printf("*** Error code %d", status);
}
} else {
status = WTERMSIG(reason); /* signaled */
printf("*** Signal %d", status);
}
if (!WIFEXITED(reason) || (status != 0)) {
if (errCheck) {
#ifdef USE_META
if (useMeta) {
meta_job_error(NULL, gn, 0, status);
}
#endif
gn->made = ERROR;
if (keepgoing) {
/*
* Abort the current target, but let others
* continue.
*/
printf(" (continuing)\n");
} else {
printf("\n");
}
if (deleteOnError) {
CompatDeleteTarget(gn);
}
} else {
/*
* Continue executing commands for this target.
* If we return 0, this will happen...
*/
printf(" (ignored)\n");
status = 0;
}
}
break;
} else {
Fatal("error in wait: %d: %s", retstat, strerror(errno));
/*NOTREACHED*/
}
}
free(cmdStart);
compatChild = 0;
if (compatSigno) {
bmake_signal(compatSigno, SIG_DFL);
kill(myPid, compatSigno);
}
return (status);
}
/*-
*-----------------------------------------------------------------------
* Compat_Make --
* Make a target.
*
* Input:
* gnp The node to make
* pgnp Parent to abort if necessary
*
* Results:
* 0
*
* Side Effects:
* If an error is detected and not being ignored, the process exits.
*
*-----------------------------------------------------------------------
*/
int
Compat_Make(void *gnp, void *pgnp)
{
GNode *gn = (GNode *)gnp;
GNode *pgn = (GNode *)pgnp;
if (!shellName) /* we came here from jobs */
Shell_Init();
if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
/*
* First mark ourselves to be made, then apply whatever transformations
* the suffix module thinks are necessary. Once that's done, we can
* descend and make all our children. If any of them has an error
* but the -k flag was given, our 'make' field will be set FALSE again.
* This is our signal to not attempt to do anything but abort our
* parent as well.
*/
gn->flags |= REMAKE;
gn->made = BEINGMADE;
if ((gn->type & OP_MADE) == 0)
Suff_FindDeps(gn);
Lst_ForEach(gn->children, Compat_Make, gn);
if ((gn->flags & REMAKE) == 0) {
gn->made = ABORTED;
pgn->flags &= ~REMAKE;
goto cohorts;
}
if (Lst_Member(gn->iParents, pgn) != NULL) {
char *p1;
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
free(p1);
}
/*
* All the children were made ok. Now cmgn->mtime contains the
* modification time of the newest child, we need to find out if we
* exist and when we were modified last. The criteria for datedness
* are defined by the Make_OODate function.
*/
if (DEBUG(MAKE)) {
fprintf(debug_file, "Examining %s...", gn->name);
}
if (! Make_OODate(gn)) {
gn->made = UPTODATE;
if (DEBUG(MAKE)) {
fprintf(debug_file, "up-to-date.\n");
}
goto cohorts;
} else if (DEBUG(MAKE)) {
fprintf(debug_file, "out-of-date.\n");
}
/*
* If the user is just seeing if something is out-of-date, exit now
* to tell him/her "yes".
*/
if (queryFlag) {
exit(1);
}
/*
* We need to be re-made. We also have to make sure we've got a $?
* variable. To be nice, we also define the $> variable using
* Make_DoAllVar().
*/
Make_DoAllVar(gn);
/*
* Alter our type to tell if errors should be ignored or things
* should not be printed so CompatRunCommand knows what to do.
*/
if (Targ_Ignore(gn)) {
gn->type |= OP_IGNORE;
}
if (Targ_Silent(gn)) {
gn->type |= OP_SILENT;
}
if (Job_CheckCommands(gn, Fatal)) {
/*
* Our commands are ok, but we still have to worry about the -t
* flag...
*/
if (!touchFlag || (gn->type & OP_MAKE)) {
curTarg = gn;
#ifdef USE_META
if (useMeta && !NoExecute(gn)) {
meta_job_start(NULL, gn);
}
#endif
Lst_ForEach(gn->commands, CompatRunCommand, gn);
curTarg = NULL;
} else {
Job_Touch(gn, gn->type & OP_SILENT);
}
} else {
gn->made = ERROR;
}
#ifdef USE_META
if (useMeta && !NoExecute(gn)) {
if (meta_job_finish(NULL) != 0)
gn->made = ERROR;
}
#endif
if (gn->made != ERROR) {
/*
* If the node was made successfully, mark it so, update
* its modification time and timestamp all its parents. Note
* that for .ZEROTIME targets, the timestamping isn't done.
* This is to keep its state from affecting that of its parent.
*/
gn->made = MADE;
pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
if (!(gn->type & OP_EXEC)) {
pgn->flags |= CHILDMADE;
Make_TimeStamp(pgn, gn);
}
} else if (keepgoing) {
pgn->flags &= ~REMAKE;
} else {
PrintOnError(gn, "\nStop.");
exit(1);
}
} else if (gn->made == ERROR) {
/*
* Already had an error when making this beastie. Tell the parent
* to abort.
*/
pgn->flags &= ~REMAKE;
} else {
if (Lst_Member(gn->iParents, pgn) != NULL) {
char *p1;
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
free(p1);
}
switch(gn->made) {
case BEINGMADE:
Error("Graph cycles through %s", gn->name);
gn->made = ERROR;
pgn->flags &= ~REMAKE;
break;
case MADE:
if ((gn->type & OP_EXEC) == 0) {
pgn->flags |= CHILDMADE;
Make_TimeStamp(pgn, gn);
}
break;
case UPTODATE:
if ((gn->type & OP_EXEC) == 0) {
Make_TimeStamp(pgn, gn);
}
break;
default:
break;
}
}
cohorts:
Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
return (0);
}
/*-
*-----------------------------------------------------------------------
* Compat_Run --
* Initialize this mode and start making.
*
* Input:
* targs List of target nodes to re-create
*
* Results:
* None.
*
* Side Effects:
* Guess what?
*
*-----------------------------------------------------------------------
*/
void
Compat_Run(Lst targs)
{
GNode *gn = NULL;/* Current root target */
int errors; /* Number of targets not remade due to errors */
if (!shellName)
Shell_Init();
if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGINT, CompatInterrupt);
}
if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGTERM, CompatInterrupt);
}
if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGHUP, CompatInterrupt);
}
if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGQUIT, CompatInterrupt);
}
ENDNode = Targ_FindNode(".END", TARG_CREATE);
ENDNode->type = OP_SPECIAL;
/*
* If the user has defined a .BEGIN target, execute the commands attached
* to it.
*/
if (!queryFlag) {
gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
if (gn != NULL) {
Compat_Make(gn, gn);
if (gn->made == ERROR) {
PrintOnError(gn, "\nStop.");
exit(1);
}
}
}
/*
* Expand .USE nodes right now, because they can modify the structure
* of the tree.
*/
Make_ExpandUse(targs);
/*
* For each entry in the list of targets to create, call Compat_Make on
* it to create the thing. Compat_Make will leave the 'made' field of gn
* in one of several states:
* UPTODATE gn was already up-to-date
* MADE gn was recreated successfully
* ERROR An error occurred while gn was being created
* ABORTED gn was not remade because one of its inferiors
* could not be made due to errors.
*/
errors = 0;
while (!Lst_IsEmpty (targs)) {
gn = (GNode *)Lst_DeQueue(targs);
Compat_Make(gn, gn);
if (gn->made == UPTODATE) {
printf("`%s' is up to date.\n", gn->name);
} else if (gn->made == ABORTED) {
printf("`%s' not remade because of errors.\n", gn->name);
errors += 1;
}
}
/*
* If the user has defined a .END target, run its commands.
*/
if (errors == 0) {
Compat_Make(ENDNode, ENDNode);
if (gn->made == ERROR) {
PrintOnError(gn, "\nStop.");
exit(1);
}
}
}

1436
devel/bmake/files/cond.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,344 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* Path of default shell */
#undef DEFSHELL_CUSTOM
/* Shell spec to use by default */
#undef DEFSHELL_INDEX
/* Define to 1 if you have the <ar.h> header file. */
#undef HAVE_AR_H
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
don't. */
#undef HAVE_DECL_SYS_SIGLIST
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the `dirname' function. */
#undef HAVE_DIRNAME
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
/* Define to 1 if you have the `err' function. */
#undef HAVE_ERR
/* Define to 1 if you have the `errx' function. */
#undef HAVE_ERRX
/* Define to 1 if you have the <err.h> header file. */
#undef HAVE_ERR_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
/* Define to 1 if you have the `getcwd' function. */
#undef HAVE_GETCWD
/* Define to 1 if you have the `getenv' function. */
#undef HAVE_GETENV
/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT
/* Define to 1 if you have the `getwd' function. */
#undef HAVE_GETWD
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `killpg' function. */
#undef HAVE_KILLPG
/* Define to 1 if you have the <libgen.h> header file. */
#undef HAVE_LIBGEN_H
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the <paths.h> header file. */
#undef HAVE_PATHS_H
/* Define to 1 if you have the <poll.h> header file. */
#undef HAVE_POLL_H
/* Define to 1 if you have the `putenv' function. */
#undef HAVE_PUTENV
/* Define to 1 if you have the <ranlib.h> header file. */
#undef HAVE_RANLIB_H
/* Define to 1 if you have the `realpath' function. */
#undef HAVE_REALPATH
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `setenv' function. */
#undef HAVE_SETENV
/* Define to 1 if you have the `setpgid' function. */
#undef HAVE_SETPGID
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `sigvec' function. */
#undef HAVE_SIGVEC
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the `stresep' function. */
#undef HAVE_STRESEP
/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP
/* Define to 1 if you have the `strtod' function. */
#undef HAVE_STRTOD
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL
/* Define to 1 if `st_rdev' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_RDEV
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
#undef HAVE_ST_RDEV
/* Define to 1 if you have the `sysctl' function. */
#undef HAVE_SYSCTL
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#undef HAVE_SYS_SYSCTL_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/uio.h> header file. */
#undef HAVE_SYS_UIO_H
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H
/* Define to 1 if you have the `vprintf' function. */
#undef HAVE_VPRINTF
/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
/* Define to 1 if you have the `wait3' function. */
#undef HAVE_WAIT3
/* Define to 1 if you have the `wait4' function. */
#undef HAVE_WAIT4
/* Define to 1 if you have the `waitpid' function. */
#undef HAVE_WAITPID
/* Define to 1 if you have the `warn' function. */
#undef HAVE_WARN
/* Define to 1 if you have the `warnx' function. */
#undef HAVE_WARNX
/* Define to 1 if `fork' works. */
#undef HAVE_WORKING_FORK
/* Define to 1 if `vfork' works. */
#undef HAVE_WORKING_VFORK
/* define if your compiler has __attribute__ */
#undef HAVE___ATTRIBUTE__
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
#undef TM_IN_SYS_TIME
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
# undef WORDS_BIGENDIAN
# endif
#endif
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
#undef _UINT32_T
/* C99 function name */
#undef __func__
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to `int' if <sys/types.h> does not define. */
#undef mode_t
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#undef uint32_t
/* Define as `fork' if `vfork' does not work. */
#undef vfork

7422
devel/bmake/files/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,430 @@
dnl
dnl RCSid:
dnl $Id: configure.in,v 1.1.1.8 2020/05/24 05:35:51 nia Exp $
dnl
dnl Process this file with autoconf to produce a configure script
dnl
AC_PREREQ(2.50)
AC_INIT([bmake], [20200418], [sjg@NetBSD.org])
AC_CONFIG_HEADERS(config.h)
dnl make srcdir absolute
case "$srcdir" in
/*) ;;
*) srcdir=`cd $srcdir && pwd`;;
esac
dnl get _MAKE_VERSION
. $srcdir/VERSION
OS=`uname -s`
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],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake DEFSHELL) ;;
no) ;;
*) case "$with_defshell" in
sh) DEFSHELL_INDEX=DEFSHELL_INDEX_SH;; # it's the default anyway
ksh) DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
csh) DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;; # kidding right?
*) defshell_path=$with_defshell;; # better be sh compatible!
esac
;;
esac])
dnl
case "$OS" in
CYGWIN*|MINGW*) use_makefile=no;;
*) use_makefile=yes;;
esac
AC_ARG_WITH(makefile,
[ --without-makefile dissable use of generated makefile],
[case "${withval}" in
yes|no) use_makefile=${withval};;
*) AC_MSG_ERROR(bad value ${withval} given for makefile) ;;
esac])
dnl
use_meta=yes
AC_ARG_WITH(meta,
[ --without-meta dissable use of meta-mode],
[case "${withval}" in
yes|no) use_meta=${withval};;
*) AC_MSG_ERROR(bad value ${withval} given for meta) ;;
esac])
dnl
AC_ARG_WITH(filemon,
[ --with-filemon={no,dev,ktrace,path/filemon.h} indicate filemon method for meta-mode. Path to filemon.h implies dev],
[ case "/${withval}" in
/no) use_filemon=no;;
/*trace) filemon_h=no use_filemon="${withval}";;
*/filemon.h) filemon_h="${withval}";;
*/filemon*) filemon_h="${withval}/filemon.h";;
*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;;
esac],
[
case "$OS" in
NetBSD) filemon_h=no use_filemon=ktrace;;
*)
for d in "/usr/include/dev/filemon" "$prefix/include/dev/filemon" "$srcdir/../../sys/dev/filemon"
do
for x in "/$OS" ""
do
filemon_h="$d$x/filemon.h"
test -s "$filemon_h" && break
done
test -s "$filemon_h" && { use_filemon=dev; break; }
done
;;
esac
use_filemon=${use_filemon:-no}
case "$use_filemon" in
dev) ;;
*) filemon_h=no;;
esac
])
dnl echo "Note: use_meta=$use_meta use_filemon=$use_filemon filemon_h=$filemon_h" >&6
case "$use_meta" in
yes)
case "$use_filemon" in
no) ;;
*) echo "Using: filemon_${use_filemon}.c" >&6;;
esac
;;
esac
dnl
dnl Check for OS problems
dnl Solaris's signal.h only privides sigset_t etc if one of
dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined.
dnl The later two seem to cause more problems than they solve so if we
dnl see _EXTENSIONS_ we use it.
AC_USE_SYSTEM_EXTENSIONS
dnl Checks for programs.
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
dnl Executable suffix - normally empty; .exe on os2.
AC_SUBST(ac_exe_suffix)dnl
dnl
dnl Hurd refuses to define PATH_MAX or MAXPATHLEN
if test -x /usr/bin/getconf; then
bmake_path_max=`getconf PATH_MAX / 2> /dev/null`
# only a numeric response is useful
test ${bmake_path_max:-0} -gt 0 2> /dev/null || bmake_path_max=
fi
bmake_path_max=${bmake_path_max:-1024}
if test $bmake_path_max -gt 1024; then
# this is all we expect
bmake_path_max=1024
fi
echo "Using: BMAKE_PATH_MAX=$bmake_path_max" >&6
AC_SUBST(bmake_path_max)dnl
dnl
dnl AC_C_CROSS
dnl
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
dnl Keep this list sorted
AC_CHECK_HEADERS(sys/param.h)
dnl On BSDi at least we really need sys/param.h for sys/sysctl.h
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
[#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
])
AC_CHECK_HEADERS( \
ar.h \
err.h \
fcntl.h \
libgen.h \
limits.h \
paths.h \
poll.h \
ranlib.h \
string.h \
sys/mman.h \
sys/select.h \
sys/socket.h \
sys/time.h \
sys/uio.h \
unistd.h \
utime.h \
)
dnl Both *BSD and Linux have sys/cdefs.h, most do not.
dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
dnl also if sys/cdefs.h does not have __RCSID we need to use ours
dnl but we need to include the host's one too *sigh*
AC_CHECK_HEADER(sys/cdefs.h,
echo $ECHO_N "checking whether sys/cdefs.h is compatible... $ECHO_C" >&6
AC_EGREP_CPP(yes,
[#include <sys/cdefs.h>
#ifdef __RCSID
yes
#endif
],
echo yes >&6,
echo no >&6; CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd` -DNEED_HOST_CDEFS_H"),
CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C___ATTRIBUTE__
AC_C_BIGENDIAN
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_DECL_SYS_SIGLIST
AC_HEADER_TIME
AC_STRUCT_TM
dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
dnl Keep this list sorted
AC_CHECK_FUNCS( \
err \
errx \
getcwd \
getenv \
getopt \
getwd \
killpg \
mmap \
putenv \
select \
setenv \
setpgid \
setsid \
sigaction \
sigvec \
snprintf \
strerror \
strftime \
strsep \
strtod \
strtol \
sysctl \
unsetenv \
vsnprintf \
wait3 \
wait4 \
waitpid \
warn \
warnx \
)
dnl functions which we may need to provide
AC_REPLACE_FUNCS( \
realpath \
dirname \
stresep \
strlcpy \
)
AC_CHECK_LIB([util], [emalloc],
[ AC_CHECK_LIB([util], [erealloc],
[ AC_CHECK_LIB([util], [estrdup],
[ AC_CHECK_LIB([util], [estrndup],
[ LIBS="$LIBS -lutil"
CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])
dnl
dnl Structures
dnl
AC_HEADER_STAT
AC_STRUCT_ST_RDEV
dnl
echo "checking if compiler supports __func__" >&6
AC_LANG(C)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[[const char *func = __func__;]])],,
AC_DEFINE(__func__, __FUNCTION__, C99 function name))
dnl
dnl we want this for unit-tests/Makefile
echo $ECHO_N "checking if diff -u works... $ECHO_C" >&6
if diff -u /dev/null /dev/null > /dev/null 2>&1; then
diff_u=-u
echo yes >&6
else
diff_u=
echo no >&6
fi
dnl
dnl AC_* don't quite cut it.
dnl
echo "checking for MACHINE & MACHINE_ARCH..." >&6
cat > conftest.$ac_ext <<EOF
#include "confdefs.h"
#include <sys/param.h>
#ifdef MACHINE
machine=MACHINE
#endif
#ifdef MACHINE_ARCH
machine_arch=MACHINE_ARCH
#endif
EOF
default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 |
egrep machine= | tr -d ' "'`
rm -rf conftest*
if test "$default_machine"; then
eval "$default_machine"
fi
machine=${machine:-`$srcdir/machine.sh`}
machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl now allow overrides
dnl
AC_ARG_WITH(machine,
[ --with-machine=MACHINE explicitly set MACHINE],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
no) ;;
generic) machine=`$srcdir/machine.sh`;;
*) machine=$with_machine;;
esac])
force_machine=
AC_ARG_WITH(force_machine,
[ --with-force-machine=MACHINE set FORCE_MACHINE],
[case "${withval}" in
yes) force_machine=FORCE_;;
no) ;;
*) force_machine=FORCE_; machine=$with_force_machine;;
esac])
dnl
force_machine_arch=
AC_ARG_WITH(force_machine_arch,
[ --with-force-machine-arch=MACHINE set FORCE_MACHINE_ARCH],
[case "${withval}" in
yes) force_machine_arch=FORCE_;;
no) ;;
*) force_machine_arch=FORCE_; machine_arch=$with_force_machine;;
esac])
dnl
AC_ARG_WITH(machine_arch,
[ --with-machine_arch=MACHINE_ARCH explicitly set MACHINE_ARCH],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
no) ;;
*) machine_arch=$with_machine_arch;;
esac])
dnl
dnl Tell them what we ended up with
dnl
echo "Using: ${force_machine}MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl Allow folk to control _PATH_DEFSYSPATH
dnl
default_sys_path=\${prefix}/share/mk
AC_ARG_WITH(default-sys-path,
[ --with-default-sys-path=PATH:DIR:LIST use an explicit _PATH_DEFSYSPATH
MAKESYSPATH is a ':' separated list of directories
that bmake will search for system .mk files.
_PATH_DEFSYSPATH is its default value.],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
no) ;;
*) default_sys_path="$with_default_sys_path"
;;
esac])
dnl
dnl Some folk don't like this one
dnl
AC_ARG_WITH(path-objdirprefix,
[ --with-path-objdirprefix=PATH override _PATH_OBJDIRPREFIX],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
*) CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
esac])
dnl
dnl And this can be handy to do with out.
dnl
AC_ARG_ENABLE(pwd-override,
[ --disable-pwd-override disable \$PWD overriding getcwd()],
[case "${enableval}" in
yes) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
*) AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
esac])
dnl
dnl Just for grins
dnl
AC_ARG_ENABLE(check-make-chdir,
[ --disable-check-make-chdir disable make trying to guess
when it should automatically cd \${.CURDIR}],
[case "${enableval}" in
yes) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
*) AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
esac])
dnl
dnl On non-BSD systems, bootstrap won't work without mk
dnl
AC_ARG_WITH(mksrc,
[ --with-mksrc=PATH tell makefile.boot where to find mk src],
[case "${withval}" in
""|yes|no) ;;
*) test -s $withval/install-mk && mksrc=$withval ||
AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
;;
esac
])
dnl
dnl Now make sure we have a value
dnl
srcdir=`cd $srcdir && pwd`
for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
do
test -s $mksrc/install-mk || continue
mksrc=`cd $mksrc && pwd`
break
done
mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
echo "Using: MKSRC=$mksrc" 1>&6
dnl On some systems we want a different default shell by default
if test -x /usr/xpg4/bin/sh; then
defshell_path=${defshell_path:-/usr/xpg4/bin/sh}
fi
if test -n "$defshell_path"; then
echo "Using: SHELL=$defshell_path" >&6
AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
fi
if test -n "$DEFSHELL_INDEX"; then
AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
fi
dnl
AC_SUBST(machine)
AC_SUBST(force_machine)
AC_SUBST(machine_arch)
AC_SUBST(mksrc)
AC_SUBST(default_sys_path)
AC_SUBST(INSTALL)
AC_SUBST(GCC)
AC_SUBST(diff_u)
AC_SUBST(use_meta)
AC_SUBST(use_filemon)
AC_SUBST(filemon_h)
AC_SUBST(_MAKE_VERSION)
bm_outfiles="Makefile.config unit-tests/Makefile.config make-bootstrap.sh"
if test $use_makefile = yes; then
bm_outfiles="makefile $bm_outfiles"
fi
AC_OUTPUT($bm_outfiles)
cat <<EOF
You can now run
sh ./make-bootstrap.sh
to produce a fully functional bmake.
EOF

1849
devel/bmake/files/dir.c Normal file

File diff suppressed because it is too large Load Diff

108
devel/bmake/files/dir.h Normal file
View File

@ -0,0 +1,108 @@
/* $NetBSD: dir.h,v 1.1.1.6 2020/05/24 05:35:52 nia Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)dir.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)dir.h 8.1 (Berkeley) 6/6/93
*/
/* dir.h --
*/
#ifndef MAKE_DIR_H
#define MAKE_DIR_H
typedef struct Path {
char *name; /* Name of directory */
int refCount; /* Number of paths with this directory */
int hits; /* the number of times a file in this
* directory has been found */
Hash_Table files; /* Hash table of files in directory */
} Path;
void Dir_Init(const char *);
void Dir_InitCur(const char *);
void Dir_InitDot(void);
void Dir_End(void);
void Dir_SetPATH(void);
Boolean Dir_HasWildcards(char *);
void Dir_Expand(const char *, Lst, Lst);
char *Dir_FindFile(const char *, Lst);
int Dir_FindHereOrAbove(char *, char *, char *, int);
int Dir_MTime(GNode *, Boolean);
Path *Dir_AddDir(Lst, const char *);
char *Dir_MakeFlags(const char *, Lst);
void Dir_ClearPath(Lst);
void Dir_Concat(Lst, Lst);
void Dir_PrintDirectories(void);
void Dir_PrintPath(Lst);
void Dir_Destroy(void *);
void * Dir_CopyDir(void *);
#endif /* MAKE_DIR_H */

126
devel/bmake/files/dirname.c Normal file
View File

@ -0,0 +1,126 @@
/* $NetBSD: dirname.c,v 1.1.1.2 2020/05/24 05:35:52 nia Exp $ */
/*-
* Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Klaus Klein and Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef HAVE_DIRNAME
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: dirname.c,v 1.1.1.2 2020/05/24 05:35:52 nia Exp $");
#endif /* !LIBC_SCCS && !lint */
#include "namespace.h"
#include <sys/param.h>
#ifdef HAVE_LIBGEN_H
#include <libgen.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
#ifndef MIN
# define MIN(a, b) ((a < b) ? a : b)
#endif
static size_t
xdirname_r(const char *path, char *buf, size_t buflen)
{
const char *endp;
size_t len;
/*
* If `path' is a null pointer or points to an empty string,
* return a pointer to the string ".".
*/
if (path == NULL || *path == '\0') {
path = ".";
len = 1;
goto out;
}
/* Strip trailing slashes, if any. */
endp = path + strlen(path) - 1;
while (endp != path && *endp == '/')
endp--;
/* Find the start of the dir */
while (endp > path && *endp != '/')
endp--;
if (endp == path) {
path = *endp == '/' ? "/" : ".";
len = 1;
goto out;
}
do
endp--;
while (endp > path && *endp == '/');
len = endp - path + 1;
out:
if (buf != NULL && buflen != 0) {
buflen = MIN(len, buflen - 1);
if (buf != path)
memcpy(buf, path, buflen);
buf[buflen] = '\0';
}
return len;
}
char *
dirname(char *path)
{
static char result[PATH_MAX];
(void)xdirname_r(path, result, sizeof(result));
return result;
}
#ifdef MAIN
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
printf("%s\n", dirname(argv[1]));
exit(0);
}
#endif
#endif

View File

@ -0,0 +1,53 @@
/* $NetBSD: filemon.h,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Taylor R. Campbell.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef FILEMON_H_
#define FILEMON_H_
#include <sys/types.h>
struct filemon;
const char *
filemon_path(void);
struct filemon *
filemon_open(void);
int filemon_close(struct filemon *);
int filemon_setfd(struct filemon *, int);
void filemon_setpid_parent(struct filemon *, pid_t);
int filemon_setpid_child(const struct filemon *, pid_t);
int filemon_readfd(const struct filemon *);
int filemon_process(struct filemon *);
#endif /* FILEMON_H_ */

View File

@ -0,0 +1,151 @@
/* $NetBSD: filemon_dev.c,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Taylor R. Campbell.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#include "filemon.h"
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_FILEMON_H
# include <filemon.h>
#endif
#ifndef _PATH_FILEMON
#define _PATH_FILEMON "/dev/filemon"
#endif
struct filemon {
int fd;
};
const char *
filemon_path(void)
{
return _PATH_FILEMON;
}
struct filemon *
filemon_open(void)
{
struct filemon *F;
unsigned i;
int error;
/* Allocate and zero a struct filemon object. */
F = calloc(1, sizeof(*F));
if (F == NULL)
return NULL;
/* Try opening /dev/filemon, up to six times (cargo cult!). */
for (i = 0; (F->fd = open(_PATH_FILEMON, O_RDWR)) == -1; i++) {
if (i == 5) {
error = errno;
goto fail0;
}
}
/* Success! */
return F;
fail0: free(F);
errno = error;
return NULL;
}
int
filemon_setfd(struct filemon *F, int fd)
{
/* Point the kernel at this file descriptor. */
if (ioctl(F->fd, FILEMON_SET_FD, &fd) == -1)
return -1;
/* No need for it in userland any more; close it. */
(void)close(fd);
/* Success! */
return 0;
}
void
filemon_setpid_parent(struct filemon *F, pid_t pid)
{
/* Nothing to do! */
}
int
filemon_setpid_child(const struct filemon *F, pid_t pid)
{
/* Just pass it on to the kernel. */
return ioctl(F->fd, FILEMON_SET_PID, &pid);
}
int
filemon_close(struct filemon *F)
{
int error = 0;
/* Close the filemon device fd. */
if (close(F->fd) == -1 && error == 0)
error = errno;
/* Free the filemon descriptor. */
free(F);
/* Set errno and return -1 if anything went wrong. */
if (error) {
errno = error;
return -1;
}
/* Success! */
return 0;
}
int
filemon_readfd(const struct filemon *F)
{
return -1;
}
int
filemon_process(struct filemon *F)
{
return 0;
}

View File

@ -0,0 +1,878 @@
/* $NetBSD: filemon_ktrace.c,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Taylor R. Campbell.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#define _KERNTYPES /* register_t */
#include "filemon.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/rbtree.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <sys/ktrace.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef AT_CWD
#define AT_CWD -1
#endif
struct filemon;
struct filemon_key;
struct filemon_state;
typedef struct filemon_state *filemon_syscall_t(struct filemon *,
const struct filemon_key *, const struct ktr_syscall *);
static filemon_syscall_t filemon_sys_chdir;
static filemon_syscall_t filemon_sys_execve;
static filemon_syscall_t filemon_sys_exit;
static filemon_syscall_t filemon_sys_fork;
static filemon_syscall_t filemon_sys_link;
static filemon_syscall_t filemon_sys_open;
static filemon_syscall_t filemon_sys_openat;
static filemon_syscall_t filemon_sys_symlink;
static filemon_syscall_t filemon_sys_unlink;
static filemon_syscall_t filemon_sys_rename;
static filemon_syscall_t *const filemon_syscalls[] = {
[SYS_chdir] = &filemon_sys_chdir,
[SYS_execve] = &filemon_sys_execve,
[SYS_exit] = &filemon_sys_exit,
[SYS_fork] = &filemon_sys_fork,
[SYS_link] = &filemon_sys_link,
[SYS_open] = &filemon_sys_open,
[SYS_openat] = &filemon_sys_openat,
[SYS_symlink] = &filemon_sys_symlink,
[SYS_unlink] = &filemon_sys_unlink,
[SYS_rename] = &filemon_sys_rename,
};
struct filemon {
int ktrfd; /* kernel writes ktrace events here */
FILE *in; /* we read ktrace events from here */
FILE *out; /* we write filemon events to here */
rb_tree_t active;
pid_t child;
/* I/O state machine. */
enum {
FILEMON_START = 0,
FILEMON_HEADER,
FILEMON_PAYLOAD,
FILEMON_ERROR,
} state;
unsigned char *p;
size_t resid;
/* I/O buffer. */
struct ktr_header hdr;
union {
struct ktr_syscall syscall;
struct ktr_sysret sysret;
char namei[PATH_MAX];
unsigned char buf[4096];
} payload;
};
struct filemon_state {
struct filemon_key {
pid_t pid;
lwpid_t lid;
} key;
struct rb_node node;
int syscode;
void (*show)(struct filemon *, const struct filemon_state *,
const struct ktr_sysret *);
unsigned i;
unsigned npath;
char *path[/*npath*/];
};
static int
compare_filemon_states(void *cookie, const void *na, const void *nb)
{
const struct filemon_state *Sa = na;
const struct filemon_state *Sb = nb;
if (Sa->key.pid < Sb->key.pid)
return -1;
if (Sa->key.pid > Sb->key.pid)
return +1;
if (Sa->key.lid < Sb->key.lid)
return -1;
if (Sa->key.lid > Sb->key.lid)
return +1;
return 0;
}
static int
compare_filemon_key(void *cookie, const void *n, const void *k)
{
const struct filemon_state *S = n;
const struct filemon_key *key = k;
if (S->key.pid < key->pid)
return -1;
if (S->key.pid > key->pid)
return +1;
if (S->key.lid < key->lid)
return -1;
if (S->key.lid > key->lid)
return +1;
return 0;
}
static const rb_tree_ops_t filemon_rb_ops = {
.rbto_compare_nodes = &compare_filemon_states,
.rbto_compare_key = &compare_filemon_key,
.rbto_node_offset = offsetof(struct filemon_state, node),
.rbto_context = NULL,
};
/*
* filemon_path()
*
* Return a pointer to a constant string denoting the `path' of
* the filemon.
*/
const char *
filemon_path(void)
{
return "ktrace";
}
/*
* filemon_open()
*
* Allocate a filemon descriptor. Returns NULL and sets errno on
* failure.
*/
struct filemon *
filemon_open(void)
{
struct filemon *F;
int ktrpipe[2];
int error;
/* Allocate and zero a struct filemon object. */
F = calloc(1, sizeof(*F));
if (F == NULL)
return NULL;
/* Create a pipe for ktrace events. */
if (pipe2(ktrpipe, O_CLOEXEC|O_NONBLOCK) == -1) {
error = errno;
goto fail0;
}
/* Create a file stream for reading the ktrace events. */
if ((F->in = fdopen(ktrpipe[0], "r")) == NULL) {
error = errno;
goto fail1;
}
ktrpipe[0] = -1; /* claimed by fdopen */
/*
* Set the fd for writing ktrace events and initialize the
* rbtree. The rest can be safely initialized to zero.
*/
F->ktrfd = ktrpipe[1];
rb_tree_init(&F->active, &filemon_rb_ops);
/* Success! */
return F;
fail2: __unused
(void)fclose(F->in);
fail1: (void)close(ktrpipe[0]);
(void)close(ktrpipe[1]);
fail0: free(F);
errno = error;
return NULL;
}
/*
* filemon_closefd(F)
*
* Internal subroutine to try to flush and close the output file.
* If F is not open for output, do nothing. Never leaves F open
* for output even on failure. Returns 0 on success; sets errno
* and return -1 on failure.
*/
static int
filemon_closefd(struct filemon *F)
{
int error = 0;
/* If we're not open, nothing to do. */
if (F->out == NULL)
return 0;
/*
* Flush it, close it, and null it unconditionally, but be
* careful to return the earliest error in errno.
*/
if (fflush(F->out) == EOF && error == 0)
error = errno;
if (fclose(F->out) == EOF && error == 0)
error = errno;
F->out = NULL;
/* Set errno and return -1 if anything went wrong. */
if (error) {
errno = error;
return -1;
}
/* Success! */
return 0;
}
/*
* filemon_setfd(F, fd)
*
* Cause filemon activity on F to be sent to fd. Claims ownership
* of fd; caller should not use fd afterward, and any duplicates
* of fd may see their file positions changed.
*/
int
filemon_setfd(struct filemon *F, int fd)
{
/*
* Close an existing output file if done. Fail now if there's
* an error closing.
*/
if ((filemon_closefd(F)) == -1)
return -1;
assert(F->out == NULL);
/* Open a file stream and claim ownership of the fd. */
if ((F->out = fdopen(fd, "a")) == NULL)
return -1;
/*
* Print the opening output. Any failure will be deferred
* until closing. For hysterical raisins, we show the parent
* pid, not the child pid.
*/
fprintf(F->out, "# filemon version 4\n");
fprintf(F->out, "# Target pid %jd\n", (intmax_t)getpid());
fprintf(F->out, "V 4\n");
/* Success! */
return 0;
}
/*
* filemon_setpid_parent(F, pid)
*
* Set the traced pid, from the parent. Never fails.
*/
void
filemon_setpid_parent(struct filemon *F, pid_t pid)
{
F->child = pid;
}
/*
* filemon_setpid_child(F, pid)
*
* Set the traced pid, from the child. Returns 0 on success; sets
* errno and returns -1 on failure.
*/
int
filemon_setpid_child(const struct filemon *F, pid_t pid)
{
int ops, trpoints;
ops = KTROP_SET|KTRFLAG_DESCEND;
trpoints = KTRFACv2;
trpoints |= KTRFAC_SYSCALL|KTRFAC_NAMEI|KTRFAC_SYSRET;
trpoints |= KTRFAC_INHERIT;
if (fktrace(F->ktrfd, ops, trpoints, pid) == -1)
return -1;
return 0;
}
/*
* filemon_close(F)
*
* Close F for output if necessary, and free a filemon descriptor.
* Returns 0 on success; sets errno and returns -1 on failure, but
* frees the filemon descriptor either way;
*/
int
filemon_close(struct filemon *F)
{
struct filemon_state *S;
int error = 0;
/* Close for output. */
if (filemon_closefd(F) == -1 && error == 0)
error = errno;
/* Close the ktrace pipe. */
if (fclose(F->in) == EOF && error == 0)
error = errno;
if (close(F->ktrfd) == -1 && error == 0)
error = errno;
/* Free any active records. */
while ((S = RB_TREE_MIN(&F->active)) != NULL) {
rb_tree_remove_node(&F->active, S);
free(S);
}
/* Free the filemon descriptor. */
free(F);
/* Set errno and return -1 if anything went wrong. */
if (error) {
errno = error;
return -1;
}
/* Success! */
return 0;
}
/*
* filemon_readfd(F)
*
* Returns a file descriptor which will select/poll ready for read
* when there are filemon events to be processed by
* filemon_process, or -1 if anything has gone wrong.
*/
int
filemon_readfd(const struct filemon *F)
{
if (F->state == FILEMON_ERROR)
return -1;
return fileno(F->in);
}
/*
* filemon_dispatch(F)
*
* Internal subroutine to dispatch a filemon ktrace event.
* Silently ignore events that we don't recognize.
*/
static void
filemon_dispatch(struct filemon *F)
{
const struct filemon_key key = {
.pid = F->hdr.ktr_pid,
.lid = F->hdr.ktr_lid,
};
struct filemon_state *S;
switch (F->hdr.ktr_type) {
case KTR_SYSCALL: {
struct ktr_syscall *call = &F->payload.syscall;
struct filemon_state *S1;
/* Validate the syscall code. */
if (call->ktr_code < 0 ||
(size_t)call->ktr_code >= __arraycount(filemon_syscalls) ||
filemon_syscalls[call->ktr_code] == NULL)
break;
/*
* Invoke the syscall-specific logic to create a new
* active state.
*/
S = (*filemon_syscalls[call->ktr_code])(F, &key, call);
if (S == NULL)
break;
/*
* Insert the active state, or ignore it if there
* already is one.
*
* Collisions shouldn't happen because the states are
* keyed by <pid,lid>, in which syscalls should happen
* sequentially in CALL/RET pairs, but let's be
* defensive.
*/
S1 = rb_tree_insert_node(&F->active, S);
if (S1 != S) {
/* XXX Which one to drop? */
free(S);
break;
}
break;
}
case KTR_NAMEI:
/* Find an active syscall state, or drop it. */
S = rb_tree_find_node(&F->active, &key);
if (S == NULL)
break;
/* Find the position of the next path, or drop it. */
if (S->i >= S->npath)
break;
/* Record the path. */
S->path[S->i++] = strndup(F->payload.namei,
sizeof F->payload.namei);
break;
case KTR_SYSRET: {
struct ktr_sysret *ret = &F->payload.sysret;
unsigned i;
/* Find and remove an active syscall state, or drop it. */
S = rb_tree_find_node(&F->active, &key);
if (S == NULL)
break;
rb_tree_remove_node(&F->active, S);
/*
* If the active syscall state matches this return,
* invoke the syscall-specific logic to show a filemon
* event.
*/
/* XXX What to do if syscall code doesn't match? */
if (S->i == S->npath && S->syscode == ret->ktr_code)
(*S->show)(F, S, ret);
/* Free the state now that it is no longer active. */
for (i = 0; i < S->i; i++)
free(S->path[i]);
free(S);
break;
}
default:
/* Ignore all other ktrace events. */
break;
}
}
/*
* filemon_process(F)
*
* Process all pending events after filemon_readfd(F) has
* selected/polled ready for read.
*
* Returns -1 on failure, 0 on end of events, and anything else if
* there may be more events.
*
* XXX What about fairness to other activities in the event loop?
* If we stop while there's events buffered in F->in, then select
* or poll may not return ready even though there's work queued up
* in the buffer of F->in, but if we don't stop then ktrace events
* may overwhelm all other activity in the event loop.
*/
int
filemon_process(struct filemon *F)
{
size_t nread;
top: /* If the child has exited, nothing to do. */
/* XXX What if one thread calls exit while another is running? */
if (F->child == 0)
return 0;
/* If we're waiting for input, read some. */
if (F->resid) {
nread = fread(F->p, 1, F->resid, F->in);
if (nread == 0) {
if (feof(F->in))
return 0;
assert(ferror(F->in));
/*
* If interrupted or would block, there may be
* more events. Otherwise fail.
*/
if (errno == EAGAIN || errno == EINTR)
return 1;
F->state = FILEMON_ERROR;
F->p = NULL;
F->resid = 0;
return -1;
}
assert(nread <= F->resid);
F->p += nread;
F->resid -= nread;
if (F->resid) /* may be more events */
return 1;
}
/* Process a state transition now that we've read a buffer. */
switch (F->state) {
case FILEMON_START: /* just started filemon; read header next */
F->state = FILEMON_HEADER;
F->p = (void *)&F->hdr;
F->resid = sizeof F->hdr;
goto top;
case FILEMON_HEADER: /* read header */
/* Sanity-check ktrace header; then read payload. */
if (F->hdr.ktr_len < 0 ||
(size_t)F->hdr.ktr_len > sizeof F->payload) {
F->state = FILEMON_ERROR;
F->p = NULL;
F->resid = 0;
errno = EIO;
return -1;
}
F->state = FILEMON_PAYLOAD;
F->p = (void *)&F->payload;
F->resid = (size_t)F->hdr.ktr_len;
goto top;
case FILEMON_PAYLOAD: /* read header and payload */
/* Dispatch ktrace event; then read next header. */
filemon_dispatch(F);
F->state = FILEMON_HEADER;
F->p = (void *)&F->hdr;
F->resid = sizeof F->hdr;
goto top;
default: /* paranoia */
F->state = FILEMON_ERROR;
/*FALLTHROUGH*/
case FILEMON_ERROR: /* persistent error indicator */
F->p = NULL;
F->resid = 0;
errno = EIO;
return -1;
}
}
static struct filemon_state *
syscall_enter(struct filemon *F,
const struct filemon_key *key, const struct ktr_syscall *call,
unsigned npath,
void (*show)(struct filemon *, const struct filemon_state *,
const struct ktr_sysret *))
{
struct filemon_state *S;
unsigned i;
S = calloc(1, offsetof(struct filemon_state, path[npath]));
if (S == NULL)
return NULL;
S->key = *key;
S->show = show;
S->syscode = call->ktr_code;
S->i = 0;
S->npath = npath;
for (i = 0; i < npath; i++)
S->path[i] = NULL; /* paranoia */
return S;
}
static void
show_paths(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret, const char *prefix)
{
unsigned i;
/* Caller must ensure all paths have been specified. */
assert(S->i == S->npath);
/*
* Ignore it if it failed or yielded EJUSTRETURN (-2), or if
* we're not producing output.
*/
if (ret->ktr_error && ret->ktr_error != -2)
return;
if (F->out == NULL)
return;
/*
* Print the prefix, pid, and paths -- with the paths quoted if
* there's more than one.
*/
fprintf(F->out, "%s %jd", prefix, (intmax_t)S->key.pid);
for (i = 0; i < S->npath; i++) {
const char *q = S->npath > 1 ? "'" : "";
fprintf(F->out, " %s%s%s", q, S->path[i], q);
}
fprintf(F->out, "\n");
}
static void
show_retval(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret, const char *prefix)
{
/*
* Ignore it if it failed or yielded EJUSTRETURN (-2), or if
* we're not producing output.
*/
if (ret->ktr_error && ret->ktr_error != -2)
return;
if (F->out == NULL)
return;
fprintf(F->out, "%s %jd %jd\n", prefix, (intmax_t)S->key.pid,
(intmax_t)ret->ktr_retval);
}
static void
show_chdir(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "C");
}
static void
show_execve(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
return show_paths(F, S, ret, "E");
}
static void
show_fork(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_retval(F, S, ret, "F");
}
static void
show_link(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "L"); /* XXX same as symlink */
}
static void
show_open_read(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "R");
}
static void
show_open_write(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "W");
}
static void
show_open_readwrite(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "R");
show_paths(F, S, ret, "W");
}
static void
show_openat_read(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
if (S->path[0][0] != '/')
show_paths(F, S, ret, "A");
show_paths(F, S, ret, "R");
}
static void
show_openat_write(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
if (S->path[0][0] != '/')
show_paths(F, S, ret, "A");
show_paths(F, S, ret, "W");
}
static void
show_openat_readwrite(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
if (S->path[0][0] != '/')
show_paths(F, S, ret, "A");
show_paths(F, S, ret, "R");
show_paths(F, S, ret, "W");
}
static void
show_symlink(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "L"); /* XXX same as link */
}
static void
show_unlink(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "D");
}
static void
show_rename(struct filemon *F, const struct filemon_state *S,
const struct ktr_sysret *ret)
{
show_paths(F, S, ret, "M");
}
static struct filemon_state *
filemon_sys_chdir(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 1, &show_chdir);
}
static struct filemon_state *
filemon_sys_execve(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 1, &show_execve);
}
static struct filemon_state *
filemon_sys_exit(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
const register_t *args = (const void *)&call[1];
int status = args[0];
if (F->out) {
fprintf(F->out, "X %jd %d\n", (intmax_t)key->pid, status);
if (key->pid == F->child) {
fprintf(F->out, "# Bye bye\n");
F->child = 0;
}
}
return NULL;
}
static struct filemon_state *
filemon_sys_fork(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 0, &show_fork);
}
static struct filemon_state *
filemon_sys_link(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 2, &show_link);
}
static struct filemon_state *
filemon_sys_open(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
const register_t *args = (const void *)&call[1];
int flags;
if (call->ktr_argsize < 2)
return NULL;
flags = args[1];
if ((flags & O_RDWR) == O_RDWR)
return syscall_enter(F, key, call, 1, &show_open_readwrite);
else if ((flags & O_WRONLY) == O_WRONLY)
return syscall_enter(F, key, call, 1, &show_open_write);
else if ((flags & O_RDONLY) == O_RDONLY)
return syscall_enter(F, key, call, 1, &show_open_read);
else
return NULL; /* XXX Do we care if no read or write? */
}
static struct filemon_state *
filemon_sys_openat(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
const register_t *args = (const void *)&call[1];
int flags, fd;
if (call->ktr_argsize < 3)
return NULL;
fd = args[0];
flags = args[2];
if (fd == AT_CWD) {
if ((flags & O_RDWR) == O_RDWR)
return syscall_enter(F, key, call, 1,
&show_open_readwrite);
else if ((flags & O_WRONLY) == O_WRONLY)
return syscall_enter(F, key, call, 1,
&show_open_write);
else if ((flags & O_RDONLY) == O_RDONLY)
return syscall_enter(F, key, call, 1, &show_open_read);
else
return NULL;
} else {
if ((flags & O_RDWR) == O_RDWR)
return syscall_enter(F, key, call, 1,
&show_openat_readwrite);
else if ((flags & O_WRONLY) == O_WRONLY)
return syscall_enter(F, key, call, 1,
&show_openat_write);
else if ((flags & O_RDONLY) == O_RDONLY)
return syscall_enter(F, key, call, 1,
&show_openat_read);
else
return NULL;
}
}
static struct filemon_state *
filemon_sys_symlink(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 2, &show_symlink);
}
static struct filemon_state *
filemon_sys_unlink(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 1, &show_unlink);
}
static struct filemon_state *
filemon_sys_rename(struct filemon *F, const struct filemon_key *key,
const struct ktr_syscall *call)
{
return syscall_enter(F, key, call, 2, &show_rename);
}

13
devel/bmake/files/find_lib.sh Executable file
View File

@ -0,0 +1,13 @@
:
re=$1; shift
for lib in $*
do
found=`nm $lib | egrep "$re"`
case "$found" in
"") ;;
*) echo "$lib: $found";;
esac
done

496
devel/bmake/files/for.c Normal file
View File

@ -0,0 +1,496 @@
/* $NetBSD: for.c,v 1.1.1.9 2020/05/24 05:35:52 nia Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: for.c,v 1.1.1.9 2020/05/24 05:35:52 nia Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: for.c,v 1.1.1.9 2020/05/24 05:35:52 nia Exp $");
#endif
#endif /* not lint */
#endif
/*-
* for.c --
* Functions to handle loops in a makefile.
*
* Interface:
* For_Eval Evaluate the loop in the passed line.
* For_Run Run accumulated loop
*
*/
#include <assert.h>
#include <ctype.h>
#include "make.h"
#include "hash.h"
#include "dir.h"
#include "buf.h"
#include "strlist.h"
#define FOR_SUB_ESCAPE_CHAR 1
#define FOR_SUB_ESCAPE_BRACE 2
#define FOR_SUB_ESCAPE_PAREN 4
/*
* For statements are of the form:
*
* .for <variable> in <varlist>
* ...
* .endfor
*
* The trick is to look for the matching end inside for for loop
* To do that, we count the current nesting level of the for loops.
* and the .endfor statements, accumulating all the statements between
* the initial .for loop and the matching .endfor;
* then we evaluate the for loop for each variable in the varlist.
*
* Note that any nested fors are just passed through; they get handled
* recursively in For_Eval when we're expanding the enclosing for in
* For_Run.
*/
static int forLevel = 0; /* Nesting level */
/*
* State of a for loop.
*/
typedef struct _For {
Buffer buf; /* Body of loop */
strlist_t vars; /* Iteration variables */
strlist_t items; /* Substitution items */
char *parse_buf;
int short_var;
int sub_next;
} For;
static For *accumFor; /* Loop being accumulated */
static char *
make_str(const char *ptr, int len)
{
char *new_ptr;
new_ptr = bmake_malloc(len + 1);
memcpy(new_ptr, ptr, len);
new_ptr[len] = 0;
return new_ptr;
}
static void
For_Free(For *arg)
{
Buf_Destroy(&arg->buf, TRUE);
strlist_clean(&arg->vars);
strlist_clean(&arg->items);
free(arg->parse_buf);
free(arg);
}
/*-
*-----------------------------------------------------------------------
* For_Eval --
* Evaluate the for loop in the passed line. The line
* looks like this:
* .for <variable> in <varlist>
*
* Input:
* line Line to parse
*
* Results:
* 0: Not a .for statement, parse the line
* 1: We found a for loop
* -1: A .for statement with a bad syntax error, discard.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
int
For_Eval(char *line)
{
For *new_for;
char *ptr = line, *sub;
int len;
int escapes;
unsigned char ch;
char **words, *word_buf;
int n, nwords;
/* Skip the '.' and any following whitespace */
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
/*
* If we are not in a for loop quickly determine if the statement is
* a for.
*/
if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' ||
!isspace((unsigned char) ptr[3])) {
if (ptr[0] == 'e' && strncmp(ptr+1, "ndfor", 5) == 0) {
Parse_Error(PARSE_FATAL, "for-less endfor");
return -1;
}
return 0;
}
ptr += 3;
/*
* we found a for loop, and now we are going to parse it.
*/
new_for = bmake_malloc(sizeof *new_for);
memset(new_for, 0, sizeof *new_for);
/* Grab the variables. Terminate on "in". */
for (;; ptr += len) {
while (*ptr && isspace((unsigned char) *ptr))
ptr++;
if (*ptr == '\0') {
Parse_Error(PARSE_FATAL, "missing `in' in for");
For_Free(new_for);
return -1;
}
for (len = 1; ptr[len] && !isspace((unsigned char)ptr[len]); len++)
continue;
if (len == 2 && ptr[0] == 'i' && ptr[1] == 'n') {
ptr += 2;
break;
}
if (len == 1)
new_for->short_var = 1;
strlist_add_str(&new_for->vars, make_str(ptr, len), len);
}
if (strlist_num(&new_for->vars) == 0) {
Parse_Error(PARSE_FATAL, "no iteration variables in for");
For_Free(new_for);
return -1;
}
while (*ptr && isspace((unsigned char) *ptr))
ptr++;
/*
* Make a list with the remaining words
* The values are substituted as ${:U<value>...} so we must \ escape
* characters that break that syntax.
* Variables are fully expanded - so it is safe for escape $.
* We can't do the escapes here - because we don't know whether
* we are substuting into ${...} or $(...).
*/
sub = Var_Subst(NULL, ptr, VAR_GLOBAL, VARF_WANTRES);
/*
* Split into words allowing for quoted strings.
*/
words = brk_string(sub, &nwords, FALSE, &word_buf);
free(sub);
if (words != NULL) {
for (n = 0; n < nwords; n++) {
ptr = words[n];
if (!*ptr)
continue;
escapes = 0;
while ((ch = *ptr++)) {
switch(ch) {
case ':':
case '$':
case '\\':
escapes |= FOR_SUB_ESCAPE_CHAR;
break;
case ')':
escapes |= FOR_SUB_ESCAPE_PAREN;
break;
case /*{*/ '}':
escapes |= FOR_SUB_ESCAPE_BRACE;
break;
}
}
/*
* We have to dup words[n] to maintain the semantics of
* strlist.
*/
strlist_add_str(&new_for->items, bmake_strdup(words[n]), escapes);
}
free(words);
free(word_buf);
if ((len = strlist_num(&new_for->items)) > 0 &&
len % (n = strlist_num(&new_for->vars))) {
Parse_Error(PARSE_FATAL,
"Wrong number of words (%d) in .for substitution list"
" with %d vars", len, n);
/*
* Return 'success' so that the body of the .for loop is
* accumulated.
* Remove all items so that the loop doesn't iterate.
*/
strlist_clean(&new_for->items);
}
}
Buf_Init(&new_for->buf, 0);
accumFor = new_for;
forLevel = 1;
return 1;
}
/*
* Add another line to a .for loop.
* Returns 0 when the matching .endfor is reached.
*/
int
For_Accum(char *line)
{
char *ptr = line;
if (*ptr == '.') {
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
if (strncmp(ptr, "endfor", 6) == 0 &&
(isspace((unsigned char) ptr[6]) || !ptr[6])) {
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: end for %d\n", forLevel);
if (--forLevel <= 0)
return 0;
} else if (strncmp(ptr, "for", 3) == 0 &&
isspace((unsigned char) ptr[3])) {
forLevel++;
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: new loop %d\n", forLevel);
}
}
Buf_AddBytes(&accumFor->buf, strlen(line), line);
Buf_AddByte(&accumFor->buf, '\n');
return 1;
}
/*-
*-----------------------------------------------------------------------
* For_Run --
* Run the for loop, imitating the actions of an include file
*
* Results:
* None.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
static int
for_var_len(const char *var)
{
char ch, var_start, var_end;
int depth;
int len;
var_start = *var;
if (var_start == 0)
/* just escape the $ */
return 0;
if (var_start == '(')
var_end = ')';
else if (var_start == '{')
var_end = '}';
else
/* Single char variable */
return 1;
depth = 1;
for (len = 1; (ch = var[len++]) != 0;) {
if (ch == var_start)
depth++;
else if (ch == var_end && --depth == 0)
return len;
}
/* Variable end not found, escape the $ */
return 0;
}
static void
for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
{
const char *item = strlist_str(items, item_no);
int len;
char ch;
/* If there were no escapes, or the only escape is the other variable
* terminator, then just substitute the full string */
if (!(strlist_info(items, item_no) &
(ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
Buf_AddBytes(cmds, strlen(item), item);
return;
}
/* Escape ':', '$', '\\' and 'ech' - removed by :U processing */
while ((ch = *item++) != 0) {
if (ch == '$') {
len = for_var_len(item);
if (len != 0) {
Buf_AddBytes(cmds, len + 1, item - 1);
item += len;
continue;
}
Buf_AddByte(cmds, '\\');
} else if (ch == ':' || ch == '\\' || ch == ech)
Buf_AddByte(cmds, '\\');
Buf_AddByte(cmds, ch);
}
}
static char *
For_Iterate(void *v_arg, size_t *ret_len)
{
For *arg = v_arg;
int i, len;
char *var;
char *cp;
char *cmd_cp;
char *body_end;
char ch;
Buffer cmds;
if (arg->sub_next + strlist_num(&arg->vars) > strlist_num(&arg->items)) {
/* No more iterations */
For_Free(arg);
return NULL;
}
free(arg->parse_buf);
arg->parse_buf = NULL;
/*
* Scan the for loop body and replace references to the loop variables
* with variable references that expand to the required text.
* Using variable expansions ensures that the .for loop can't generate
* syntax, and that the later parsing will still see a variable.
* We assume that the null variable will never be defined.
*
* The detection of substitions of the loop control variable is naive.
* Many of the modifiers use \ to escape $ (not $) so it is possible
* to contrive a makefile where an unwanted substitution happens.
*/
cmd_cp = Buf_GetAll(&arg->buf, &len);
body_end = cmd_cp + len;
Buf_Init(&cmds, len + 256);
for (cp = cmd_cp; (cp = strchr(cp, '$')) != NULL;) {
char ech;
ch = *++cp;
if ((ch == '(' && (ech = ')', 1)) || (ch == '{' && (ech = '}', 1))) {
cp++;
/* Check variable name against the .for loop variables */
STRLIST_FOREACH(var, &arg->vars, i) {
len = strlist_info(&arg->vars, i);
if (memcmp(cp, var, len) != 0)
continue;
if (cp[len] != ':' && cp[len] != ech && cp[len] != '\\')
continue;
/* Found a variable match. Replace with :U<value> */
Buf_AddBytes(&cmds, cp - cmd_cp, cmd_cp);
Buf_AddBytes(&cmds, 2, ":U");
cp += len;
cmd_cp = cp;
for_substitute(&cmds, &arg->items, arg->sub_next + i, ech);
break;
}
continue;
}
if (ch == 0)
break;
/* Probably a single character name, ignore $$ and stupid ones. {*/
if (!arg->short_var || strchr("}):$", ch) != NULL) {
cp++;
continue;
}
STRLIST_FOREACH(var, &arg->vars, i) {
if (var[0] != ch || var[1] != 0)
continue;
/* Found a variable match. Replace with ${:U<value>} */
Buf_AddBytes(&cmds, cp - cmd_cp, cmd_cp);
Buf_AddBytes(&cmds, 3, "{:U");
cmd_cp = ++cp;
for_substitute(&cmds, &arg->items, arg->sub_next + i, /*{*/ '}');
Buf_AddBytes(&cmds, 1, "}");
break;
}
}
Buf_AddBytes(&cmds, body_end - cmd_cp, cmd_cp);
cp = Buf_Destroy(&cmds, FALSE);
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: loop body:\n%s", cp);
arg->sub_next += strlist_num(&arg->vars);
arg->parse_buf = cp;
*ret_len = strlen(cp);
return cp;
}
void
For_Run(int lineno)
{
For *arg;
arg = accumFor;
accumFor = NULL;
if (strlist_num(&arg->items) == 0) {
/* Nothing to expand - possibly due to an earlier syntax error. */
For_Free(arg);
return;
}
Parse_SetInput(NULL, lineno, -1, For_Iterate, arg);
}

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 1987 Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_GETENV
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)getenv.c 5.8 (Berkeley) 2/23/91";*/
static char *rcsid = "$Id: getenv.c,v 1.1.1.3 2009/09/18 20:55:25 joerg Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/cdefs.h>
/*
* getenv --
* Returns ptr to value associated with name, if any, else NULL.
*/
char *
getenv(name)
const char *name;
{
int offset;
char *__findenv();
return(__findenv(name, &offset));
}
/*
* __findenv --
* Returns pointer to value associated with name, if any, else NULL.
* Sets offset to be the offset of the name/value combination in the
* environmental array, for use by setenv(3) and unsetenv(3).
* Explicitly removes '=' in argument name.
*
* This routine *should* be a static; don't use it.
*/
char *
__findenv(name, offset)
register char *name;
int *offset;
{
extern char **environ;
register int len;
register char **P, *C;
for (C = name, len = 0; *C && *C != '='; ++C, ++len);
for (P = environ; *P; ++P)
if (!strncmp(*P, name, len))
if (*(C = *P + len) == '=') {
*offset = P - environ;
return(++C);
}
return(NULL);
}
#endif

188
devel/bmake/files/getopt.c Normal file
View File

@ -0,0 +1,188 @@
/* $NetBSD: getopt.c,v 1.1.1.4 2020/05/24 05:35:52 nia Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if !defined(HAVE_GETOPT) || defined(WANT_GETOPT_LONG) || defined(BROKEN_GETOPT)
#include <sys/cdefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt = BADCH, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
/*
* getopt --
* Parse argc/argv argument vector.
*/
int
getopt(int nargc, char * const nargv[], const char *ostr)
{
extern char *__progname;
static const char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
#ifndef BSD4_4
if (!__progname) {
if (__progname = strrchr(nargv[0], '/'))
++__progname;
else
__progname = nargv[0];
}
#endif
if (optreset || *place == 0) { /* update scanning pointer */
optreset = 0;
place = nargv[optind];
if (optind >= nargc || *place++ != '-') {
/* Argument is absent or is not an option */
place = EMSG;
return (-1);
}
optopt = *place++;
if (optopt == '-' && *place == 0) {
/* "--" => end of options */
++optind;
place = EMSG;
return (-1);
}
if (optopt == 0) {
/* Solitary '-', treat as a '-' option
if the program (eg su) is looking for it. */
place = EMSG;
if (strchr(ostr, '-') == NULL)
return -1;
optopt = '-';
}
} else
optopt = *place++;
/* See if option letter is one the caller wanted... */
if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) {
if (*place == 0)
++optind;
if (opterr && *ostr != ':')
(void)fprintf(stderr,
"%s: unknown option -- %c\n", __progname, optopt);
return (BADCH);
}
/* Does this option need an argument? */
if (oli[1] != ':') {
/* don't need argument */
optarg = NULL;
if (*place == 0)
++optind;
} else {
/* Option-argument is either the rest of this argument or the
entire next argument. */
if (*place)
optarg = __UNCONST(place);
else if (oli[2] == ':')
/*
* GNU Extension, for optional arguments if the rest of
* the argument is empty, we return NULL
*/
optarg = NULL;
else if (nargc > ++optind)
optarg = nargv[optind];
else {
/* option-argument absent */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, optopt);
return (BADCH);
}
place = EMSG;
++optind;
}
return (optopt); /* return option letter */
}
#endif
#ifdef MAIN
#ifndef BSD4_4
char *__progname;
#endif
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
char *opts = argv[1];
--argc;
++argv;
while ((c = getopt(argc, argv, opts)) != EOF) {
switch (c) {
case '-':
if (optarg)
printf("--%s ", optarg);
break;
case '?':
exit(1);
break;
default:
if (optarg)
printf("-%c %s ", c, optarg);
else
printf("-%c ", c);
break;
}
}
if (optind < argc) {
printf("-- ");
for (; optind < argc; ++optind) {
printf("%s ", argv[optind]);
}
}
printf("\n");
exit(0);
}
#endif

466
devel/bmake/files/hash.c Normal file
View File

@ -0,0 +1,466 @@
/* $NetBSD: hash.c,v 1.1.1.5 2015/05/19 21:36:44 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: hash.c,v 1.1.1.5 2015/05/19 21:36:44 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: hash.c,v 1.1.1.5 2015/05/19 21:36:44 joerg Exp $");
#endif
#endif /* not lint */
#endif
/* hash.c --
*
* This module contains routines to manipulate a hash table.
* See hash.h for a definition of the structure of the hash
* table. Hash tables grow automatically as the amount of
* information increases.
*/
#include "sprite.h"
#include "make.h"
#include "hash.h"
/*
* Forward references to local procedures that are used before they're
* defined:
*/
static void RebuildTable(Hash_Table *);
/*
* The following defines the ratio of # entries to # buckets
* at which we rebuild the table to make it larger.
*/
#define rebuildLimit 3
/*
*---------------------------------------------------------
*
* Hash_InitTable --
*
* This routine just sets up the hash table.
*
* Input:
* t Structure to to hold table.
* numBuckets How many buckets to create for starters. This
* number is rounded up to a power of two. If
* <= 0, a reasonable default is chosen. The
* table will grow in size later as needed.
*
* Results:
* None.
*
* Side Effects:
* Memory is allocated for the initial bucket area.
*
*---------------------------------------------------------
*/
void
Hash_InitTable(Hash_Table *t, int numBuckets)
{
int i;
struct Hash_Entry **hp;
/*
* Round up the size to a power of two.
*/
if (numBuckets <= 0)
i = 16;
else {
for (i = 2; i < numBuckets; i <<= 1)
continue;
}
t->numEntries = 0;
t->size = i;
t->mask = i - 1;
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
}
/*
*---------------------------------------------------------
*
* Hash_DeleteTable --
*
* This routine removes everything from a hash table
* and frees up the memory space it occupied (except for
* the space in the Hash_Table structure).
*
* Results:
* None.
*
* Side Effects:
* Lots of memory is freed up.
*
*---------------------------------------------------------
*/
void
Hash_DeleteTable(Hash_Table *t)
{
struct Hash_Entry **hp, *h, *nexth = NULL;
int i;
for (hp = t->bucketPtr, i = t->size; --i >= 0;) {
for (h = *hp++; h != NULL; h = nexth) {
nexth = h->next;
free(h);
}
}
free(t->bucketPtr);
/*
* Set up the hash table to cause memory faults on any future access
* attempts until re-initialization.
*/
t->bucketPtr = NULL;
}
/*
*---------------------------------------------------------
*
* Hash_FindEntry --
*
* Searches a hash table for an entry corresponding to key.
*
* Input:
* t Hash table to search.
* key A hash key.
*
* Results:
* The return value is a pointer to the entry for key,
* if key was present in the table. If key was not
* present, NULL is returned.
*
* Side Effects:
* None.
*
*---------------------------------------------------------
*/
Hash_Entry *
Hash_FindEntry(Hash_Table *t, const char *key)
{
Hash_Entry *e;
unsigned h;
const char *p;
if (t == NULL || t->bucketPtr == NULL) {
return NULL;
}
for (h = 0, p = key; *p;)
h = (h << 5) - h + *p++;
p = key;
for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next)
if (e->namehash == h && strcmp(e->name, p) == 0)
return (e);
return NULL;
}
/*
*---------------------------------------------------------
*
* Hash_CreateEntry --
*
* Searches a hash table for an entry corresponding to
* key. If no entry is found, then one is created.
*
* Input:
* t Hash table to search.
* key A hash key.
* newPtr Filled in with TRUE if new entry created,
* FALSE otherwise.
*
* Results:
* The return value is a pointer to the entry. If *newPtr
* isn't NULL, then *newPtr is filled in with TRUE if a
* new entry was created, and FALSE if an entry already existed
* with the given key.
*
* Side Effects:
* Memory may be allocated, and the hash buckets may be modified.
*---------------------------------------------------------
*/
Hash_Entry *
Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr)
{
Hash_Entry *e;
unsigned h;
const char *p;
int keylen;
struct Hash_Entry **hp;
/*
* Hash the key. As a side effect, save the length (strlen) of the
* key in case we need to create the entry.
*/
for (h = 0, p = key; *p;)
h = (h << 5) - h + *p++;
keylen = p - key;
p = key;
for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next) {
if (e->namehash == h && strcmp(e->name, p) == 0) {
if (newPtr != NULL)
*newPtr = FALSE;
return (e);
}
}
/*
* The desired entry isn't there. Before allocating a new entry,
* expand the table if necessary (and this changes the resulting
* bucket chain).
*/
if (t->numEntries >= rebuildLimit * t->size)
RebuildTable(t);
e = bmake_malloc(sizeof(*e) + keylen);
hp = &t->bucketPtr[h & t->mask];
e->next = *hp;
*hp = e;
Hash_SetValue(e, NULL);
e->namehash = h;
(void)strcpy(e->name, p);
t->numEntries++;
if (newPtr != NULL)
*newPtr = TRUE;
return (e);
}
/*
*---------------------------------------------------------
*
* Hash_DeleteEntry --
*
* Delete the given hash table entry and free memory associated with
* it.
*
* Results:
* None.
*
* Side Effects:
* Hash chain that entry lives in is modified and memory is freed.
*
*---------------------------------------------------------
*/
void
Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e)
{
Hash_Entry **hp, *p;
if (e == NULL)
return;
for (hp = &t->bucketPtr[e->namehash & t->mask];
(p = *hp) != NULL; hp = &p->next) {
if (p == e) {
*hp = p->next;
free(p);
t->numEntries--;
return;
}
}
(void)write(2, "bad call to Hash_DeleteEntry\n", 29);
abort();
}
/*
*---------------------------------------------------------
*
* Hash_EnumFirst --
* This procedure sets things up for a complete search
* of all entries recorded in the hash table.
*
* Input:
* t Table to be searched.
* searchPtr Area in which to keep state about search.
*
* Results:
* The return value is the address of the first entry in
* the hash table, or NULL if the table is empty.
*
* Side Effects:
* The information in searchPtr is initialized so that successive
* calls to Hash_Next will return successive HashEntry's
* from the table.
*
*---------------------------------------------------------
*/
Hash_Entry *
Hash_EnumFirst(Hash_Table *t, Hash_Search *searchPtr)
{
searchPtr->tablePtr = t;
searchPtr->nextIndex = 0;
searchPtr->hashEntryPtr = NULL;
return Hash_EnumNext(searchPtr);
}
/*
*---------------------------------------------------------
*
* Hash_EnumNext --
* This procedure returns successive entries in the hash table.
*
* Input:
* searchPtr Area used to keep state about search.
*
* Results:
* The return value is a pointer to the next HashEntry
* in the table, or NULL when the end of the table is
* reached.
*
* Side Effects:
* The information in searchPtr is modified to advance to the
* next entry.
*
*---------------------------------------------------------
*/
Hash_Entry *
Hash_EnumNext(Hash_Search *searchPtr)
{
Hash_Entry *e;
Hash_Table *t = searchPtr->tablePtr;
/*
* The hashEntryPtr field points to the most recently returned
* entry, or is nil if we are starting up. If not nil, we have
* to start at the next one in the chain.
*/
e = searchPtr->hashEntryPtr;
if (e != NULL)
e = e->next;
/*
* If the chain ran out, or if we are starting up, we need to
* find the next nonempty chain.
*/
while (e == NULL) {
if (searchPtr->nextIndex >= t->size)
return NULL;
e = t->bucketPtr[searchPtr->nextIndex++];
}
searchPtr->hashEntryPtr = e;
return (e);
}
/*
*---------------------------------------------------------
*
* RebuildTable --
* This local routine makes a new hash table that
* is larger than the old one.
*
* Results:
* None.
*
* Side Effects:
* The entire hash table is moved, so any bucket numbers
* from the old table are invalid.
*
*---------------------------------------------------------
*/
static void
RebuildTable(Hash_Table *t)
{
Hash_Entry *e, *next = NULL, **hp, **xp;
int i, mask;
Hash_Entry **oldhp;
int oldsize;
oldhp = t->bucketPtr;
oldsize = i = t->size;
i <<= 1;
t->size = i;
t->mask = mask = i - 1;
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
for (hp = oldhp, i = oldsize; --i >= 0;) {
for (e = *hp++; e != NULL; e = next) {
next = e->next;
xp = &t->bucketPtr[e->namehash & mask];
e->next = *xp;
*xp = e;
}
}
free(oldhp);
}

149
devel/bmake/files/hash.h Normal file
View File

@ -0,0 +1,149 @@
/* $NetBSD: hash.h,v 1.1.1.4 2020/05/24 05:35:52 nia Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)hash.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)hash.h 8.1 (Berkeley) 6/6/93
*/
/* hash.h --
*
* This file contains definitions used by the hash module,
* which maintains hash tables.
*/
#ifndef _HASH_H
#define _HASH_H
/*
* The following defines one entry in the hash table.
*/
typedef struct Hash_Entry {
struct Hash_Entry *next; /* Used to link together all the
* entries associated with the same
* bucket. */
void *clientPtr; /* Arbitrary pointer */
unsigned namehash; /* hash value of key */
char name[1]; /* key string */
} Hash_Entry;
typedef struct Hash_Table {
struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one
* for each bucket in the table. */
int size; /* Actual size of array. */
int numEntries; /* Number of entries in the table. */
int mask; /* Used to select bits for hashing. */
} Hash_Table;
/*
* The following structure is used by the searching routines
* to record where we are in the search.
*/
typedef struct Hash_Search {
Hash_Table *tablePtr; /* Table being searched. */
int nextIndex; /* Next bucket to check (after current). */
Hash_Entry *hashEntryPtr; /* Next entry to check in current bucket. */
} Hash_Search;
/*
* Macros.
*/
/*
* void * Hash_GetValue(h)
* Hash_Entry *h;
*/
#define Hash_GetValue(h) ((h)->clientPtr)
/*
* Hash_SetValue(h, val);
* Hash_Entry *h;
* char *val;
*/
#define Hash_SetValue(h, val) ((h)->clientPtr = (val))
/*
* Hash_Size(n) returns the number of words in an object of n bytes
*/
#define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int))
void Hash_InitTable(Hash_Table *, int);
void Hash_DeleteTable(Hash_Table *);
Hash_Entry *Hash_FindEntry(Hash_Table *, const char *);
Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *);
void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
Hash_Entry *Hash_EnumNext(Hash_Search *);
#endif /* _HASH_H */

201
devel/bmake/files/install-sh Executable file
View File

@ -0,0 +1,201 @@
:
# NAME:
# install.sh - portable version of install(1)
#
# SYNOPSIS:
# install [-CNcs] [-f flags] [-i errs] [-o owner] [-g group] [-m mode] file1 file2 ...
# install -d [-i errs] [-o owner] [-g group] [-m mode] directory ...
#
# DESCRIPTION:
# Compatible with BSD install(1). Except that '-c' is always
# true and we always move an already installed target aside as
# this is important on many systems. Recent BSD install(1)
# versions have a '-b' option for this.
#
#
# OPTIONS:
# -b move previous target file aside (always true).
#
# -B "suffix"
# use "suffix" instead of .old for saving existing target.
#
# -c copy rather than move the file into place (always true).
#
# -C compare. Only install if target is missing or
# different.
#
# -N newer. Only install if target is missing or older.
#
# -s strip target
#
# -o "owner"
# make target owned by "owner"
#
# -g "group"
# make target group owned by "group"
#
# -m "mode"
# set permissions to "mode"
#
# -f "flags"
# Pass "flags" onto chflags(1)
#
# -i "errs"
# Ignore errors from steps indicated by "errs" (``s,o,g,m'').
#
# BUGS:
# The '-i' option is to save your sanity when 'bsd.prog.mk'
# insists on haveing a '-o' "owner" option which is doomed to
# fail on many systems. We ignore '-b', '-B' and '-c' options.
#
# AUTHOR:
# Simon J. Gerraty <sjg@quick.com.au>
#
# RCSid:
# $Id: install-sh,v 1.1.1.3 2009/09/18 20:55:26 joerg Exp $
#
# @(#) Copyright (c) 1993 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@quick.com.au
#
set -- `getopt B:bpxCNcsdo:g:m:i:f: $*`
Mydir=`dirname $0`
[ -s $Mydir/.installrc ] && . $Mydir/.installrc
owner=:
group=:
mode=:
strip=:
mkdirs=
compare=:
newer=:
chflags=:
LS1=
CP_P=
while [ $# -gt 1 ]
do
case $1 in
--) shift; break;;
-p) CP_P=-p;;
-x) set -x;;
-B) OLD_EXT=$2; shift;;
-C) compare=Different;;
-N) newer=Newer;
# check if /bin/ls supports -1
/bin/ls -1 $0 >/dev/null 2>&1 && LS1=1
;;
-o) owner="${CHOWN:-chown} $2 "; shift;;
-g) group="${CHGRP:-chgrp} $2 "; shift;;
-m) mode="${CHMOD:-chmod} $2 "; shift;;
-s) strip=${STRIP:-strip};;
-d) mkdirs="mkdir -p";;
-i) ignore_err="$ignore_err$2"; shift;;
-f) chflags="${CHFLAGS:-chflags} $2 "; shift;;
esac
shift
done
Newer() {
n=`/bin/ls -t$LS1 $* 2>/dev/null | head -1`
[ $1 = $n ]
}
Different() {
cmp -s $*
[ $? != 0 ]
}
Err() {
case "$ignore_err" in
*$1*) ;;
*) exit 1;;
esac
}
Setem() {
# the order is important
if [ ! -d $1 ]; then
$strip $1 || Err s
fi
$group $1 || Err g
$owner $1 || Err o
$mode $1 || Err m
$chflags $1 || Err f
return 0
}
# a bug in HP-UX's /bin/sh, means we need to re-set $*
# after any calls to add_path()
args="$*"
# all this just for chown!
add_path () { [ -d $1 ] && eval ${2:-PATH}="\$${2:-PATH}:$1"; }
add_path /etc
add_path /usr/etc
add_path /sbin
add_path /usr/sbin
# restore saved $*
set -- $args
# make directories if needed
# and ensure mode etc are as desired
if [ "$mkdirs" ]; then
for d in $*
do
[ ! -d $d ] && $mkdirs $d
Setem $d
done
exit 0 # that's all we do
fi
# install files
if [ $# -gt 2 ]; then
dest_dir=yes
elif [ $# -eq 1 ]; then
echo "what should I do with $*?" >&2
exit 1
fi
# get list of files
while [ $# -gt 1 ]
do
files="$files $1"
shift
done
# last one is dest
dest=$1
shift
if [ "$dest_dir" = yes -a ! -d $dest ]; then
echo "no directory $dest" >&2
exit 1
fi
for f in $files
do
b=`basename $f`
if [ -d $dest ]; then
t=$dest/$b
else
t=$dest
fi
$newer $f $t || continue
$compare $f $t || continue
[ -f $t ] && { mv -f $t $t.old || exit 1; }
{ cp $CP_P $f $t && Setem $t; } || exit 1
done
exit 0

3147
devel/bmake/files/job.c Normal file

File diff suppressed because it is too large Load Diff

274
devel/bmake/files/job.h Normal file
View File

@ -0,0 +1,274 @@
/* $NetBSD: job.h,v 1.1.1.6 2015/05/19 21:36:44 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
*/
/*-
* job.h --
* Definitions pertaining to the running of jobs in parallel mode.
*/
#ifndef _JOB_H_
#define _JOB_H_
#define TMPPAT "makeXXXXXX" /* relative to tmpdir */
#ifdef USE_SELECT
/*
* Emulate poll() in terms of select(). This is not a complete
* emulation but it is sufficient for make's purposes.
*/
#define poll emul_poll
#define pollfd emul_pollfd
struct emul_pollfd {
int fd;
short events;
short revents;
};
#define POLLIN 0x0001
#define POLLOUT 0x0004
int
emul_poll(struct pollfd *fd, int nfd, int timeout);
#endif
/*
* The POLL_MSEC constant determines the maximum number of milliseconds spent
* in poll before coming out to see if a child has finished.
*/
#define POLL_MSEC 5000
/*-
* Job Table definitions.
*
* Each job has several things associated with it:
* 1) The process id of the child shell
* 2) The graph node describing the target being made by this job
* 3) A LstNode for the first command to be saved after the job
* completes. This is NULL if there was no "..." in the job's
* commands.
* 4) An FILE* for writing out the commands. This is only
* used before the job is actually started.
* 5) The output is being caught via a pipe and
* the descriptors of our pipe, an array in which output is line
* buffered and the current position in that buffer are all
* maintained for each job.
* 6) A word of flags which determine how the module handles errors,
* echoing, etc. for the job
*
* When a job is finished, the Make_Update function is called on each of the
* parents of the node which was just remade. This takes care of the upward
* traversal of the dependency graph.
*/
struct pollfd;
#ifdef USE_META
# include "meta.h"
#endif
#define JOB_BUFSIZE 1024
typedef struct Job {
int pid; /* The child's process ID */
GNode *node; /* The target the child is making */
LstNode tailCmds; /* The node of the first command to be
* saved when the job has been run */
FILE *cmdFILE; /* When creating the shell script, this is
* where the commands go */
int exit_status; /* from wait4() in signal handler */
char job_state; /* status of the job entry */
#define JOB_ST_FREE 0 /* Job is available */
#define JOB_ST_SETUP 1 /* Job is allocated but otherwise invalid */
#define JOB_ST_RUNNING 3 /* Job is running, pid valid */
#define JOB_ST_FINISHED 4 /* Job is done (ie after SIGCHILD) */
char job_suspended;
short flags; /* Flags to control treatment of job */
#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
#define JOB_SILENT 0x002 /* no output */
#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
* if we can't export it and maxLocal is 0 */
#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
* commands */
#define JOB_TRACED 0x400 /* we've sent 'set -x' */
int jobPipe[2]; /* Pipe for readind output from job */
struct pollfd *inPollfd; /* pollfd associated with inPipe */
char outBuf[JOB_BUFSIZE + 1];
/* Buffer for storing the output of the
* job, line by line */
int curPos; /* Current position in op_outBuf */
#ifdef USE_META
struct BuildMon bm;
#endif
} Job;
#define inPipe jobPipe[0]
#define outPipe jobPipe[1]
/*-
* Shell Specifications:
* Each shell type has associated with it the following information:
* 1) The string which must match the last character of the shell name
* for the shell to be considered of this type. The longest match
* wins.
* 2) A command to issue to turn off echoing of command lines
* 3) A command to issue to turn echoing back on again
* 4) What the shell prints, and its length, when given the echo-off
* command. This line will not be printed when received from the shell
* 5) A boolean to tell if the shell has the ability to control
* error checking for individual commands.
* 6) The string to turn this checking on.
* 7) The string to turn it off.
* 8) The command-flag to give to cause the shell to start echoing
* commands right away.
* 9) The command-flag to cause the shell to Lib_Exit when an error is
* detected in one of the commands.
*
* Some special stuff goes on if a shell doesn't have error control. In such
* a case, errCheck becomes a printf template for echoing the command,
* should echoing be on and ignErr becomes another printf template for
* executing the command while ignoring the return status. Finally errOut
* is a printf template for running the command and causing the shell to
* exit on error. If any of these strings are empty when hasErrCtl is FALSE,
* the command will be executed anyway as is and if it causes an error, so be
* it. Any templates setup to echo the command will escape any '$ ` \ "'i
* characters in the command string to avoid common problems with
* echo "%s\n" as a template.
*/
typedef struct Shell {
const char *name; /* the name of the shell. For Bourne and C
* shells, this is used only to find the
* shell description when used as the single
* source of a .SHELL target. For user-defined
* shells, this is the full path of the shell.
*/
Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
const char *echoOff; /* command to turn off echo */
const char *echoOn; /* command to turn it back on again */
const char *noPrint; /* command to skip when printing output from
* shell. This is usually the command which
* was executed to turn off echoing */
int noPLen; /* length of noPrint command */
Boolean hasErrCtl; /* set if can control error checking for
* individual commands */
const char *errCheck; /* string to turn error checking on */
const char *ignErr; /* string to turn off error checking */
const char *errOut; /* string to use for testing exit code */
const char *newline; /* string literal that results in a newline
* character when it appears outside of any
* 'quote' or "quote" characters */
char commentChar; /* character used by shell for comment lines */
/*
* command-line flags
*/
const char *echo; /* echo commands */
const char *exit; /* exit on error */
} 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 */
void Shell_Init(void);
const char *Shell_GetNewline(void);
void Job_Touch(GNode *, Boolean);
Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
#define CATCH_BLOCK 1
void Job_CatchChildren(void);
void Job_CatchOutput(void);
void Job_Make(GNode *);
void Job_Init(void);
Boolean Job_Full(void);
Boolean Job_Empty(void);
ReturnStatus Job_ParseShell(char *);
int Job_Finish(void);
void Job_End(void);
void Job_Wait(void);
void Job_AbortAll(void);
void JobFlagForMigration(int);
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_ */

189
devel/bmake/files/lst.h Normal file
View File

@ -0,0 +1,189 @@
/* $NetBSD: lst.h,v 1.1.1.5 2015/05/19 21:36:44 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)lst.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)lst.h 8.1 (Berkeley) 6/6/93
*/
/*-
* lst.h --
* Header for using the list library
*/
#ifndef _LST_H_
#define _LST_H_
#include <sys/param.h>
#include <stdlib.h>
#include "sprite.h"
/*
* basic typedef. This is what the Lst_ functions handle
*/
typedef struct List *Lst;
typedef struct ListNode *LstNode;
typedef void *DuplicateProc(void *);
typedef void FreeProc(void *);
#define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */
#define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */
/*
* Creation/destruction functions
*/
/* Create a new list */
Lst Lst_Init(Boolean);
/* Duplicate an existing list */
Lst Lst_Duplicate(Lst, DuplicateProc *);
/* Destroy an old one */
void Lst_Destroy(Lst, FreeProc *);
/* True if list is empty */
Boolean Lst_IsEmpty(Lst);
/*
* Functions to modify a list
*/
/* Insert an element before another */
ReturnStatus Lst_InsertBefore(Lst, LstNode, void *);
/* Insert an element after another */
ReturnStatus Lst_InsertAfter(Lst, LstNode, void *);
/* Place an element at the front of a lst. */
ReturnStatus Lst_AtFront(Lst, void *);
/* Place an element at the end of a lst. */
ReturnStatus Lst_AtEnd(Lst, void *);
/* Remove an element */
ReturnStatus Lst_Remove(Lst, LstNode);
/* Replace a node with a new value */
ReturnStatus Lst_Replace(LstNode, void *);
/* Concatenate two lists */
ReturnStatus Lst_Concat(Lst, Lst, int);
/*
* Node-specific functions
*/
/* Return first element in list */
LstNode Lst_First(Lst);
/* Return last element in list */
LstNode Lst_Last(Lst);
/* Return successor to given element */
LstNode Lst_Succ(LstNode);
/* Return predecessor to given element */
LstNode Lst_Prev(LstNode);
/* Get datum from LstNode */
void *Lst_Datum(LstNode);
/*
* Functions for entire lists
*/
/* Find an element in a list */
LstNode Lst_Find(Lst, const void *, int (*)(const void *, const void *));
/* Find an element starting from somewhere */
LstNode Lst_FindFrom(Lst, LstNode, const void *,
int (*cProc)(const void *, const void *));
/*
* See if the given datum is on the list. Returns the LstNode containing
* the datum
*/
LstNode Lst_Member(Lst, void *);
/* Apply a function to all elements of a lst */
int Lst_ForEach(Lst, int (*)(void *, void *), void *);
/*
* Apply a function to all elements of a lst starting from a certain point.
* If the list is circular, the application will wrap around to the
* beginning of the list again.
*/
int Lst_ForEachFrom(Lst, LstNode, int (*)(void *, void *),
void *);
/*
* these functions are for dealing with a list as a table, of sorts.
* An idea of the "current element" is kept and used by all the functions
* between Lst_Open() and Lst_Close().
*/
/* Open the list */
ReturnStatus Lst_Open(Lst);
/* Next element please */
LstNode Lst_Next(Lst);
/* Done yet? */
Boolean Lst_IsAtEnd(Lst);
/* Finish table access */
void Lst_Close(Lst);
/*
* for using the list as a queue
*/
/* Place an element at tail of queue */
ReturnStatus Lst_EnQueue(Lst, void *);
/* Remove an element from head of queue */
void *Lst_DeQueue(Lst);
#endif /* _LST_H_ */

View File

View File

@ -0,0 +1,122 @@
/* $NetBSD: lstAppend.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAppend.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstAppend.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAppend.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAppend.c --
* Add a new node with a new datum after an existing node
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_InsertAfter --
* Create a new node and add it to the given list after the given node.
*
* Input:
* l affected list
* ln node after which to append the datum
* d said datum
*
* Results:
* SUCCESS if all went well.
*
* Side Effects:
* A new ListNode is created and linked in to the List. The lastPtr
* field of the List will be altered if ln is the last node in the
* list. lastPtr and firstPtr will alter if the list was empty and
* ln was NULL.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_InsertAfter(Lst l, LstNode ln, void *d)
{
List list;
ListNode lNode;
ListNode nLNode;
if (LstValid (l) && (ln == NULL && LstIsEmpty (l))) {
goto ok;
}
if (!LstValid (l) || LstIsEmpty (l) || ! LstNodeValid (ln, l)) {
return (FAILURE);
}
ok:
list = l;
lNode = ln;
PAlloc (nLNode, ListNode);
nLNode->datum = d;
nLNode->useCount = nLNode->flags = 0;
if (lNode == NULL) {
if (list->isCirc) {
nLNode->nextPtr = nLNode->prevPtr = nLNode;
} else {
nLNode->nextPtr = nLNode->prevPtr = NULL;
}
list->firstPtr = list->lastPtr = nLNode;
} else {
nLNode->prevPtr = lNode;
nLNode->nextPtr = lNode->nextPtr;
lNode->nextPtr = nLNode;
if (nLNode->nextPtr != NULL) {
nLNode->nextPtr->prevPtr = nLNode;
}
if (lNode == list->lastPtr) {
list->lastPtr = nLNode;
}
}
return (SUCCESS);
}

View File

@ -0,0 +1,79 @@
/* $NetBSD: lstAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstAtEnd.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAtEnd.c --
* Add a node at the end of the list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_AtEnd --
* Add a node to the end of the given list
*
* Input:
* l List to which to add the datum
* d Datum to add
*
* Results:
* SUCCESS if life is good.
*
* Side Effects:
* A new ListNode is created and added to the list.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_AtEnd(Lst l, void *d)
{
LstNode end;
end = Lst_Last(l);
return (Lst_InsertAfter(l, end, d));
}

View File

@ -0,0 +1,76 @@
/* $NetBSD: lstAtFront.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstAtFront.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAtFront.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAtFront.c --
* Add a node at the front of the list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_AtFront --
* Place a piece of data at the front of a list
*
* Results:
* SUCCESS or FAILURE
*
* Side Effects:
* A new ListNode is created and stuck at the front of the list.
* hence, firstPtr (and possible lastPtr) in the list are altered.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_AtFront(Lst l, void *d)
{
LstNode front;
front = Lst_First(l);
return (Lst_InsertBefore(l, front, d));
}

View File

@ -0,0 +1,86 @@
/* $NetBSD: lstClose.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstClose.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstClose.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstClose.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstClose.c --
* Close a list for sequential access.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Close --
* Close a list which was opened for sequential access.
*
* Input:
* l The list to close
*
* Results:
* None.
*
* Side Effects:
* The list is closed.
*
*-----------------------------------------------------------------------
*/
void
Lst_Close(Lst l)
{
List list = l;
if (LstValid(l) == TRUE) {
list->isOpen = FALSE;
list->atEnd = Unknown;
}
}

View File

@ -0,0 +1,185 @@
/* $NetBSD: lstConcat.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstConcat.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstConcat.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstConcat.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* listConcat.c --
* Function to concatentate two lists.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Concat --
* Concatenate two lists. New elements are created to hold the data
* elements, if specified, but the elements themselves are not copied.
* If the elements should be duplicated to avoid confusion with another
* list, the Lst_Duplicate function should be called first.
* If LST_CONCLINK is specified, the second list is destroyed since
* its pointers have been corrupted and the list is no longer useable.
*
* Input:
* l1 The list to which l2 is to be appended
* l2 The list to append to l1
* flags LST_CONCNEW if LstNode's should be duplicated
* LST_CONCLINK if should just be relinked
*
* Results:
* SUCCESS if all went well. FAILURE otherwise.
*
* Side Effects:
* New elements are created and appended the first list.
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Concat(Lst l1, Lst l2, int flags)
{
ListNode ln; /* original LstNode */
ListNode nln; /* new LstNode */
ListNode last; /* the last element in the list. Keeps
* bookkeeping until the end */
List list1 = l1;
List list2 = l2;
if (!LstValid (l1) || !LstValid (l2)) {
return (FAILURE);
}
if (flags == LST_CONCLINK) {
if (list2->firstPtr != NULL) {
/*
* We set the nextPtr of the
* last element of list two to be NIL to make the loop easier and
* so we don't need an extra case should the first list turn
* out to be non-circular -- the final element will already point
* to NIL space and the first element will be untouched if it
* existed before and will also point to NIL space if it didn't.
*/
list2->lastPtr->nextPtr = NULL;
/*
* So long as the second list isn't empty, we just link the
* first element of the second list to the last element of the
* first list. If the first list isn't empty, we then link the
* last element of the list to the first element of the second list
* The last element of the second list, if it exists, then becomes
* the last element of the first list.
*/
list2->firstPtr->prevPtr = list1->lastPtr;
if (list1->lastPtr != NULL) {
list1->lastPtr->nextPtr = list2->firstPtr;
} else {
list1->firstPtr = list2->firstPtr;
}
list1->lastPtr = list2->lastPtr;
}
if (list1->isCirc && list1->firstPtr != NULL) {
/*
* If the first list is supposed to be circular and it is (now)
* non-empty, we must make sure it's circular by linking the
* first element to the last and vice versa
*/
list1->firstPtr->prevPtr = list1->lastPtr;
list1->lastPtr->nextPtr = list1->firstPtr;
}
free(l2);
} else if (list2->firstPtr != NULL) {
/*
* We set the nextPtr of the last element of list 2 to be nil to make
* the loop less difficult. The loop simply goes through the entire
* second list creating new LstNodes and filling in the nextPtr, and
* prevPtr to fit into l1 and its datum field from the
* datum field of the corresponding element in l2. The 'last' node
* follows the last of the new nodes along until the entire l2 has
* been appended. Only then does the bookkeeping catch up with the
* changes. During the first iteration of the loop, if 'last' is nil,
* the first list must have been empty so the newly-created node is
* made the first node of the list.
*/
list2->lastPtr->nextPtr = NULL;
for (last = list1->lastPtr, ln = list2->firstPtr;
ln != NULL;
ln = ln->nextPtr)
{
PAlloc (nln, ListNode);
nln->datum = ln->datum;
if (last != NULL) {
last->nextPtr = nln;
} else {
list1->firstPtr = nln;
}
nln->prevPtr = last;
nln->flags = nln->useCount = 0;
last = nln;
}
/*
* Finish bookkeeping. The last new element becomes the last element
* of list one.
*/
list1->lastPtr = last;
/*
* The circularity of both list one and list two must be corrected
* for -- list one because of the new nodes added to it; list two
* because of the alteration of list2->lastPtr's nextPtr to ease the
* above for loop.
*/
if (list1->isCirc) {
list1->lastPtr->nextPtr = list1->firstPtr;
list1->firstPtr->prevPtr = list1->lastPtr;
} else {
last->nextPtr = NULL;
}
if (list2->isCirc) {
list2->lastPtr->nextPtr = list2->firstPtr;
}
}
return (SUCCESS);
}

View File

@ -0,0 +1,77 @@
/* $NetBSD: lstDatum.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDatum.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstDatum.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDatum.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDatum.c --
* Return the datum associated with a list node.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Datum --
* Return the datum stored in the given node.
*
* Results:
* The datum or NULL if the node is invalid.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
void *
Lst_Datum(LstNode ln)
{
if (ln != NULL) {
return ((ln)->datum);
} else {
return NULL;
}
}

View File

@ -0,0 +1,87 @@
/* $NetBSD: lstDeQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstDeQueue.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDeQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDeQueue.c --
* Remove the node and return its datum from the head of the list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_DeQueue --
* Remove and return the datum at the head of the given list.
*
* Results:
* The datum in the node at the head or NULL if the list
* is empty.
*
* Side Effects:
* The head node is removed from the list.
*
*-----------------------------------------------------------------------
*/
void *
Lst_DeQueue(Lst l)
{
void *rd;
ListNode tln;
tln = Lst_First(l);
if (tln == NULL) {
return NULL;
}
rd = tln->datum;
if (Lst_Remove(l, tln) == FAILURE) {
return NULL;
} else {
return (rd);
}
}

View File

@ -0,0 +1,101 @@
/* $NetBSD: lstDestroy.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDestroy.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstDestroy.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDestroy.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDestroy.c --
* Nuke a list and all its resources
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Destroy --
* Destroy a list and free all its resources. If the freeProc is
* given, it is called with the datum from each node in turn before
* the node is freed.
*
* Results:
* None.
*
* Side Effects:
* The given list is freed in its entirety.
*
*-----------------------------------------------------------------------
*/
void
Lst_Destroy(Lst list, FreeProc *freeProc)
{
ListNode ln;
ListNode tln = NULL;
if (list == NULL)
return;
/* To ease scanning */
if (list->lastPtr != NULL)
list->lastPtr->nextPtr = NULL;
else {
free(list);
return;
}
if (freeProc) {
for (ln = list->firstPtr; ln != NULL; ln = tln) {
tln = ln->nextPtr;
freeProc(ln->datum);
free(ln);
}
} else {
for (ln = list->firstPtr; ln != NULL; ln = tln) {
tln = ln->nextPtr;
free(ln);
}
}
free(list);
}

View File

@ -0,0 +1,107 @@
/* $NetBSD: lstDupl.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDupl.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstDupl.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDupl.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* listDupl.c --
* Duplicate a list. This includes duplicating the individual
* elements.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Duplicate --
* Duplicate an entire list. If a function to copy a void *is
* given, the individual client elements will be duplicated as well.
*
* Input:
* l the list to duplicate
* copyProc A function to duplicate each void *
*
* Results:
* The new Lst structure or NULL if failure.
*
* Side Effects:
* A new list is created.
*-----------------------------------------------------------------------
*/
Lst
Lst_Duplicate(Lst l, DuplicateProc *copyProc)
{
Lst nl;
ListNode ln;
List list = l;
if (!LstValid (l)) {
return NULL;
}
nl = Lst_Init(list->isCirc);
if (nl == NULL) {
return NULL;
}
ln = list->firstPtr;
while (ln != NULL) {
if (copyProc != NULL) {
if (Lst_AtEnd(nl, copyProc(ln->datum)) == FAILURE) {
return NULL;
}
} else if (Lst_AtEnd(nl, ln->datum) == FAILURE) {
return NULL;
}
if (list->isCirc && ln == list->lastPtr) {
ln = NULL;
} else {
ln = ln->nextPtr;
}
}
return (nl);
}

View File

@ -0,0 +1,78 @@
/* $NetBSD: lstEnQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstEnQueue.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstEnQueue.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstEnQueue.c--
* Treat the list as a queue and place a datum at its end
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_EnQueue --
* Add the datum to the tail of the given list.
*
* Results:
* SUCCESS or FAILURE as returned by Lst_InsertAfter.
*
* Side Effects:
* the lastPtr field is altered all the time and the firstPtr field
* will be altered if the list used to be empty.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_EnQueue(Lst l, void *d)
{
if (LstValid (l) == FALSE) {
return (FAILURE);
}
return (Lst_InsertAfter(l, Lst_Last(l), d));
}

View File

@ -0,0 +1,74 @@
/* $NetBSD: lstFind.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFind.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstFind.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFind.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFind.c --
* Find a node on a list.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Find --
* Find a node on the given list using the given comparison function
* and the given datum.
*
* Results:
* The found node or NULL if none matches.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Find(Lst l, const void *d, int (*cProc)(const void *, const void *))
{
return (Lst_FindFrom(l, Lst_First(l), d, cProc));
}

View File

@ -0,0 +1,90 @@
/* $NetBSD: lstFindFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstFindFrom.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFindFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFindFrom.c --
* Find a node on a list from a given starting point. Used by Lst_Find.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_FindFrom --
* Search for a node starting and ending with the given one on the
* given list using the passed datum and comparison function to
* determine when it has been found.
*
* Results:
* The found node or NULL
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_FindFrom(Lst l, LstNode ln, const void *d,
int (*cProc)(const void *, const void *))
{
ListNode tln;
if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
return NULL;
}
tln = ln;
do {
if ((*cProc)(tln->datum, d) == 0)
return (tln);
tln = tln->nextPtr;
} while (tln != ln && tln != NULL);
return NULL;
}

View File

@ -0,0 +1,77 @@
/* $NetBSD: lstFirst.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFirst.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstFirst.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFirst.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFirst.c --
* Return the first node of a list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_First --
* Return the first node on the given list.
*
* Results:
* The first node or NULL if the list is empty.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_First(Lst l)
{
if (!LstValid (l) || LstIsEmpty (l)) {
return NULL;
} else {
return (l->firstPtr);
}
}

View File

@ -0,0 +1,76 @@
/* $NetBSD: lstForEach.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstForEach.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstForEach.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstForEach.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstForeach.c --
* Perform a given function on all elements of a list.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_ForEach --
* Apply the given function to each element of the given list. The
* function should return 0 if Lst_ForEach should continue and non-
* zero if it should abort.
*
* Results:
* None.
*
* Side Effects:
* Only those created by the passed-in function.
*
*-----------------------------------------------------------------------
*/
/*VARARGS2*/
int
Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d)
{
return Lst_ForEachFrom(l, Lst_First(l), proc, d);
}

View File

@ -0,0 +1,125 @@
/* $NetBSD: lstForEachFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstForEachFrom.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstForEachFrom.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* lstForEachFrom.c --
* Perform a given function on all elements of a list starting from
* a given point.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_ForEachFrom --
* Apply the given function to each element of the given list. The
* function should return 0 if traversal should continue and non-
* zero if it should abort.
*
* Results:
* None.
*
* Side Effects:
* Only those created by the passed-in function.
*
*-----------------------------------------------------------------------
*/
/*VARARGS2*/
int
Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *),
void *d)
{
ListNode tln = ln;
List list = l;
ListNode next;
Boolean done;
int result;
if (!LstValid (list) || LstIsEmpty (list)) {
return 0;
}
do {
/*
* Take care of having the current element deleted out from under
* us.
*/
next = tln->nextPtr;
/*
* We're done with the traversal if
* - the next node to examine is the first in the queue or
* doesn't exist and
* - nothing's been added after the current node (check this
* after proc() has been called).
*/
done = (next == NULL || next == list->firstPtr);
(void) tln->useCount++;
result = (*proc) (tln->datum, d);
(void) tln->useCount--;
/*
* Now check whether a node has been added.
* Note: this doesn't work if this node was deleted before
* the new node was added.
*/
if (next != tln->nextPtr) {
next = tln->nextPtr;
done = 0;
}
if (tln->flags & LN_DELETED) {
free((char *)tln);
}
tln = next;
} while (!result && !LstIsEmpty(list) && !done);
return result;
}

View File

@ -0,0 +1,85 @@
/* $NetBSD: lstInit.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstInit.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstInit.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstInit.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* init.c --
* Initialize a new linked list.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Init --
* Create and initialize a new list.
*
* Input:
* circ TRUE if the list should be made circular
*
* Results:
* The created list.
*
* Side Effects:
* A list is created, what else?
*
*-----------------------------------------------------------------------
*/
Lst
Lst_Init(Boolean circ)
{
List nList;
PAlloc (nList, List);
nList->firstPtr = NULL;
nList->lastPtr = NULL;
nList->isOpen = FALSE;
nList->isCirc = circ;
nList->atEnd = Unknown;
return (nList);
}

View File

@ -0,0 +1,122 @@
/* $NetBSD: lstInsert.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstInsert.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstInsert.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstInsert.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstInsert.c --
* Insert a new datum before an old one
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_InsertBefore --
* Insert a new node with the given piece of data before the given
* node in the given list.
*
* Input:
* l list to manipulate
* ln node before which to insert d
* d datum to be inserted
*
* Results:
* SUCCESS or FAILURE.
*
* Side Effects:
* the firstPtr field will be changed if ln is the first node in the
* list.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_InsertBefore(Lst l, LstNode ln, void *d)
{
ListNode nLNode; /* new lnode for d */
ListNode lNode = ln;
List list = l;
/*
* check validity of arguments
*/
if (LstValid (l) && (LstIsEmpty (l) && ln == NULL))
goto ok;
if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
return (FAILURE);
}
ok:
PAlloc (nLNode, ListNode);
nLNode->datum = d;
nLNode->useCount = nLNode->flags = 0;
if (ln == NULL) {
if (list->isCirc) {
nLNode->prevPtr = nLNode->nextPtr = nLNode;
} else {
nLNode->prevPtr = nLNode->nextPtr = NULL;
}
list->firstPtr = list->lastPtr = nLNode;
} else {
nLNode->prevPtr = lNode->prevPtr;
nLNode->nextPtr = lNode;
if (nLNode->prevPtr != NULL) {
nLNode->prevPtr->nextPtr = nLNode;
}
lNode->prevPtr = nLNode;
if (lNode == list->firstPtr) {
list->firstPtr = nLNode;
}
}
return (SUCCESS);
}

View File

@ -0,0 +1,105 @@
/* $NetBSD: lstInt.h,v 1.1.1.6 2015/05/19 21:36:45 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)lstInt.h 8.1 (Berkeley) 6/6/93
*/
/*-
* lstInt.h --
* Internals for the list library
*/
#ifndef _LSTINT_H_
#define _LSTINT_H_
#include "../lst.h"
#include "../make_malloc.h"
typedef struct ListNode {
struct ListNode *prevPtr; /* previous element in list */
struct ListNode *nextPtr; /* next in list */
unsigned int useCount:8, /* Count of functions using the node.
* node may not be deleted until count
* goes to 0 */
flags:8; /* Node status flags */
void *datum; /* datum associated with this element */
} *ListNode;
/*
* Flags required for synchronization
*/
#define LN_DELETED 0x0001 /* List node should be removed when done */
typedef enum {
Head, Middle, Tail, Unknown
} Where;
typedef struct List {
ListNode firstPtr; /* first node in list */
ListNode lastPtr; /* last node in list */
Boolean isCirc; /* true if the list should be considered
* circular */
/*
* fields for sequential access
*/
Where atEnd; /* Where in the list the last access was */
Boolean isOpen; /* true if list has been Lst_Open'ed */
ListNode curPtr; /* current node, if open. NULL if
* *just* opened */
ListNode prevPtr; /* Previous node, if open. Used by
* Lst_Remove */
} *List;
/*
* PAlloc (var, ptype) --
* Allocate a pointer-typedef structure 'ptype' into the variable 'var'
*/
#define PAlloc(var,ptype) var = (ptype) bmake_malloc(sizeof *(var))
/*
* LstValid (l) --
* Return TRUE if the list l is valid
*/
#define LstValid(l) ((Lst)(l) != NULL)
/*
* LstNodeValid (ln, l) --
* Return TRUE if the LstNode ln is valid with respect to l
*/
#define LstNodeValid(ln, l) ((ln) != NULL)
/*
* LstIsEmpty (l) --
* TRUE if the list l is empty.
*/
#define LstIsEmpty(l) (((List)(l))->firstPtr == NULL)
#endif /* _LSTINT_H_ */

View File

@ -0,0 +1,87 @@
/* $NetBSD: lstIsAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstIsAtEnd.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstIsAtEnd.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstIsAtEnd.c --
* Tell if the current node is at the end of the list.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_IsAtEnd --
* Return true if have reached the end of the given list.
*
* Results:
* TRUE if at the end of the list (this includes the list not being
* open or being invalid) or FALSE if not. We return TRUE if the list
* is invalid or unopend so as to cause the caller to exit its loop
* asap, the assumption being that the loop is of the form
* while (!Lst_IsAtEnd (l)) {
* ...
* }
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
Boolean
Lst_IsAtEnd(Lst l)
{
List list = l;
return (!LstValid (l) || !list->isOpen ||
(list->atEnd == Head) || (list->atEnd == Tail));
}

View File

@ -0,0 +1,75 @@
/* $NetBSD: lstIsEmpty.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstIsEmpty.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstIsEmpty.c,v 1.1.1.3 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstIsEmpty.c --
* A single function to decide if a list is empty
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_IsEmpty --
* Return TRUE if the given list is empty.
*
* Results:
* TRUE if the list is empty, FALSE otherwise.
*
* Side Effects:
* None.
*
* A list is considered empty if its firstPtr == NULL (or if
* the list itself is NULL).
*-----------------------------------------------------------------------
*/
Boolean
Lst_IsEmpty(Lst l)
{
return ( ! LstValid (l) || LstIsEmpty(l));
}

View File

@ -0,0 +1,77 @@
/* $NetBSD: lstLast.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstLast.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstLast.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstLast.c,v 1.1.1.4 2009/09/18 20:55:33 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstLast.c --
* Return the last element of a list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Last --
* Return the last node on the list l.
*
* Results:
* The requested node or NULL if the list is empty.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Last(Lst l)
{
if (!LstValid(l) || LstIsEmpty (l)) {
return NULL;
} else {
return (l->lastPtr);
}
}

View File

@ -0,0 +1,77 @@
/* $NetBSD: lstMember.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstMember.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstMember.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstMember.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* lstMember.c --
* See if a given datum is on a given list.
*/
#include "lstInt.h"
LstNode
Lst_Member(Lst l, void *d)
{
List list = l;
ListNode lNode;
if (list == NULL) {
return NULL;
}
lNode = list->firstPtr;
if (lNode == NULL) {
return NULL;
}
do {
if (lNode->datum == d) {
return lNode;
}
lNode = lNode->nextPtr;
} while (lNode != NULL && lNode != list->firstPtr);
return NULL;
}

View File

@ -0,0 +1,120 @@
/* $NetBSD: lstNext.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstNext.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstNext.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstNext.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstNext.c --
* Return the next node for a list.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Next --
* Return the next node for the given list.
*
* Results:
* The next node or NULL if the list has yet to be opened. Also
* if the list is non-circular and the end has been reached, NULL
* is returned.
*
* Side Effects:
* the curPtr field is updated.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Next(Lst l)
{
ListNode tln;
List list = l;
if ((LstValid (l) == FALSE) ||
(list->isOpen == FALSE)) {
return NULL;
}
list->prevPtr = list->curPtr;
if (list->curPtr == NULL) {
if (list->atEnd == Unknown) {
/*
* If we're just starting out, atEnd will be Unknown.
* Then we want to start this thing off in the right
* direction -- at the start with atEnd being Middle.
*/
list->curPtr = tln = list->firstPtr;
list->atEnd = Middle;
} else {
tln = NULL;
list->atEnd = Tail;
}
} else {
tln = list->curPtr->nextPtr;
list->curPtr = tln;
if (tln == list->firstPtr || tln == NULL) {
/*
* If back at the front, then we've hit the end...
*/
list->atEnd = Tail;
} else {
/*
* Reset to Middle if gone past first.
*/
list->atEnd = Middle;
}
}
return (tln);
}

View File

@ -0,0 +1,87 @@
/* $NetBSD: lstOpen.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstOpen.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstOpen.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstOpen.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstOpen.c --
* Open a list for sequential access. The sequential functions access the
* list in a slightly different way. CurPtr points to their idea of the
* current node in the list and they access the list based on it.
* If the list is circular, Lst_Next and Lst_Prev will go around
* the list forever. Lst_IsAtEnd must be used to determine when to stop.
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Open --
* Open a list for sequential access. A list can still be searched,
* etc., without confusing these functions.
*
* Results:
* SUCCESS or FAILURE.
*
* Side Effects:
* isOpen is set TRUE and curPtr is set to NULL so the
* other sequential functions no it was just opened and can choose
* the first element accessed based on this.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Open(Lst l)
{
if (LstValid (l) == FALSE) {
return (FAILURE);
}
(l)->isOpen = TRUE;
(l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
(l)->curPtr = NULL;
return (SUCCESS);
}

View File

@ -0,0 +1,79 @@
/* $NetBSD: lstPrev.c,v 1.1.1.3 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstPrev.c,v 1.1.1.3 2009/09/18 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstPrev.c,v 1.1.1.3 2009/09/18 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstPrev.c --
* return the predecessor to a given node
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Prev --
* Return the predecessor to the given node on its list.
*
* Results:
* The predecessor of the node, if it exists (note that on a circular
* list, if the node is the only one in the list, it is its own
* predecessor).
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Prev(LstNode ln)
{
if (ln == NULL) {
return NULL;
} else {
return (ln->prevPtr);
}
}

View File

@ -0,0 +1,136 @@
/* $NetBSD: lstRemove.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstRemove.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstRemove.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstRemove.c,v 1.1.1.5 2015/05/19 21:36:45 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstRemove.c --
* Remove an element from a list
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Remove --
* Remove the given node from the given list.
*
* Results:
* SUCCESS or FAILURE.
*
* Side Effects:
* The list's firstPtr will be set to NULL if ln is the last
* node on the list. firsPtr and lastPtr will be altered if ln is
* either the first or last node, respectively, on the list.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Remove(Lst l, LstNode ln)
{
List list = l;
ListNode lNode = ln;
if (!LstValid (l) ||
!LstNodeValid (ln, l)) {
return (FAILURE);
}
/*
* unlink it from the list
*/
if (lNode->nextPtr != NULL) {
lNode->nextPtr->prevPtr = lNode->prevPtr;
}
if (lNode->prevPtr != NULL) {
lNode->prevPtr->nextPtr = lNode->nextPtr;
}
/*
* if either the firstPtr or lastPtr of the list point to this node,
* adjust them accordingly
*/
if (list->firstPtr == lNode) {
list->firstPtr = lNode->nextPtr;
}
if (list->lastPtr == lNode) {
list->lastPtr = lNode->prevPtr;
}
/*
* Sequential access stuff. If the node we're removing is the current
* node in the list, reset the current node to the previous one. If the
* previous one was non-existent (prevPtr == NULL), we set the
* end to be Unknown, since it is.
*/
if (list->isOpen && (list->curPtr == lNode)) {
list->curPtr = list->prevPtr;
if (list->curPtr == NULL) {
list->atEnd = Unknown;
}
}
/*
* the only way firstPtr can still point to ln is if ln is the last
* node on the list (the list is circular, so lNode->nextptr == lNode in
* this case). The list is, therefore, empty and is marked as such
*/
if (list->firstPtr == lNode) {
list->firstPtr = NULL;
}
/*
* note that the datum is unmolested. The caller must free it as
* necessary and as expected.
*/
if (lNode->useCount == 0) {
free(ln);
} else {
lNode->flags |= LN_DELETED;
}
return (SUCCESS);
}

View File

@ -0,0 +1,78 @@
/* $NetBSD: lstReplace.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstReplace.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstReplace.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstReplace.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstReplace.c --
* Replace the datum in a node with a new datum
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Replace --
* Replace the datum in the given node with the new datum
*
* Results:
* SUCCESS or FAILURE.
*
* Side Effects:
* The datum field fo the node is altered.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Replace(LstNode ln, void *d)
{
if (ln == NULL) {
return (FAILURE);
} else {
(ln)->datum = d;
return (SUCCESS);
}
}

View File

@ -0,0 +1,79 @@
/* $NetBSD: lstSucc.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstSucc.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstSucc.c,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstSucc.c --
* return the successor to a given node
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Succ --
* Return the successor to the given node on its list.
*
* Results:
* The successor of the node, if it exists (note that on a circular
* list, if the node is the only one in the list, it is its own
* successor).
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Succ(LstNode ln)
{
if (ln == NULL) {
return NULL;
} else {
return (ln->nextPtr);
}
}

View File

@ -0,0 +1,44 @@
# RCSid:
# $Id: makefile.boot.in,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $
srcdir=@srcdir@
VPATH=.:$(srcdir)
OBJ=lstAppend.o lstDupl.o lstInit.o lstOpen.o lstAtEnd.o lstEnQueue.o \
lstInsert.o lstAtFront.o lstIsAtEnd.o lstClose.o lstFind.o lstIsEmpty.o \
lstRemove.o lstConcat.o lstFindFrom.o lstLast.o lstReplace.o lstFirst.o \
lstDatum.o lstForEach.o lstMember.o lstSucc.o lstDeQueue.o \
lstForEachFrom.o lstDestroy.o lstNext.o lstPrev.o
CFLAGS=@CFLAGS@ -I..
all: ${OBJ}
depend:
VPATH=${VPATH} ${MKDEP} -f makefile.boot ${CFLAGS} ${OBJ:.o=.c}
#lstAppend.o: $(srcdir)/lstAppend.c
#lstDupl.o: $(srcdir)/lstDupl.c
#lstInit.o: $(srcdir)/lstInit.c
#lstOpen.o: $(srcdir)/lstOpen.c
#lstAtEnd.o: $(srcdir)/lstAtEnd.c
#lstEnQueue.o: $(srcdir)/lstEnQueue.c
#lstInsert.o: $(srcdir)/lstInsert.c
#lstAtFront.o: $(srcdir)/lstAtFront.c
#lstIsAtEnd.o: $(srcdir)/lstIsAtEnd.c
#lstClose.o: $(srcdir)/lstClose.c
#lstFind.o: $(srcdir)/lstFind.c
#lstIsEmpty.o: $(srcdir)/lstIsEmpty.c
#lstRemove.o: $(srcdir)/lstRemove.c
#lstConcat.o: $(srcdir)/lstConcat.c
#lstFindFrom.o: $(srcdir)/lstFindFrom.c
#lstLast.o: $(srcdir)/lstLast.c
#lstReplace.o: $(srcdir)/lstReplace.c
#lstFirst.o: $(srcdir)/lstFirst.c
#lstDatum.o: $(srcdir)/lstDatum.c
#lstForEach.o: $(srcdir)/lstForEach.c
#lstMember.o: $(srcdir)/lstMember.c
#lstSucc.o: $(srcdir)/lstSucc.c
#lstDeQueue.o: $(srcdir)/lstDeQueue.c
#lstForEachFrom.o: $(srcdir)/lstForEachFrom.c
#lstDestroy.o: $(srcdir)/lstDestroy.c
#lstNext.o: $(srcdir)/lstNext.c

106
devel/bmake/files/machine.sh Executable file
View File

@ -0,0 +1,106 @@
:
# derrived from /etc/rc_d/os.sh
# RCSid:
# $Id: machine.sh,v 1.1.1.6 2020/05/24 05:35:52 nia Exp $
#
# @(#) Copyright (c) 1994-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
#
OS=`uname`
OSREL=`uname -r`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
machine=`uname -p 2>/dev/null || uname -m`
MACHINE=
# there is at least one case of `uname -p` outputting
# a bunch of usless drivel
case "$machine" in
unknown|*[!A-Za-z0-9_-]*)
machine=`uname -m`
;;
esac
# Great! Solaris keeps moving arch(1)
# we need this here, and it is not always available...
Which() {
# some shells cannot correctly handle `IFS`
# in conjunction with the for loop.
_dirs=`IFS=:; echo ${2:-$PATH}`
for d in $_dirs
do
test -x $d/$1 && { echo $d/$1; break; }
done
}
case $OS in
AIX) # from http://gnats.netbsd.org/29386
OSMAJOR=`uname -v`
OSMINOR=`uname -r`
MACHINE=$OS$OSMAJOR.$OSMINOR
MACHINE_ARCH=`bootinfo -T`
;;
OpenBSD)
MACHINE=$OS$OSMAJOR.$machine
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
MACHINE_ARCH=`$arch -s`;
;;
Bitrig)
MACHINE=$OS$OSMAJOR.$machine
MACHINE_ARCH=`uname -m`;
;;
*BSD)
MACHINE=$OS$OSMAJOR.$machine
;;
SunOS)
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
test "$arch" && machine_arch=`$arch`
case "$OSREL" in
4.0*) MACHINE_ARCH=$machine_arch MACHINE=$machine_arch;;
4*) MACHINE_ARCH=$machine_arch;;
esac
;;
HP-UX)
MACHINE_ARCH=`IFS="/-."; set $machine; echo $1`
;;
Interix)
MACHINE=i386
MACHINE_ARCH=i386
;;
UnixWare)
OSREL=`uname -v`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
MACHINE_ARCH=`uname -m`
;;
Linux)
case "$machine" in
i?86) MACHINE_ARCH=i386;;# does anyone really care about 686 vs 586?
esac
;;
esac
MACHINE=${MACHINE:-$OS$OSMAJOR}
MACHINE_ARCH=${MACHINE_ARCH:-$machine}
(
case "$0" in
arch*) echo $MACHINE_ARCH;;
*)
case "$1" in
"") echo $MACHINE;;
*) echo $MACHINE_ARCH;;
esac
;;
esac
) | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz

2223
devel/bmake/files/main.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
#!/bin/sh
set -e
srcdir=@srcdir@
DEFAULT_SYS_PATH="@default_sys_path@"
case "@use_meta@" in
yes) XDEFS="-DUSE_META ${XDEFS}";;
esac
CC="@CC@"
CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS} -DBMAKE_PATH_MAX=@bmake_path_max@"
MAKE_VERSION=@_MAKE_VERSION@
MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \
-D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \
-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\""
LDFLAGS="@LDFLAGS@"
LIBS="@LIBS@"
toUpper() {
${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}
do_compile2() {
obj="$1"; shift
src="$1"; shift
echo ${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
}
do_compile() {
obj="$1"; shift
case "$1" in
*.c) src=$1; shift;;
*) src=`basename "$obj" .o`.c;;
esac
for d in "$srcdir" "$srcdir/lst.lib"
do
test -s "$d/$src" || continue
do_compile2 "$obj" "$d/$src" "$@" || exit 1
return
done
echo "Unknown object file '$obj'" >&2
exit 1
}
do_link() {
output="$1"; shift
echo ${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
}
BASE_OBJECTS="arch.o buf.o compat.o cond.o dir.o for.o getopt hash.o \
make.o make_malloc.o metachar.o parse.o sigcompat.o str.o strlist.o \
suff.o targ.o trace.o var.o util.o"
LST_OBJECTS="lstAppend.o lstDupl.o lstInit.o lstOpen.o \
lstAtEnd.o lstEnQueue.o lstInsert.o lstAtFront.o lstIsAtEnd.o \
lstClose.o lstFind.o lstIsEmpty.o lstRemove.o lstConcat.o \
lstFindFrom.o lstLast.o lstReplace.o lstFirst.o lstDatum.o \
lstForEach.o lstMember.o lstSucc.o lstDeQueue.o lstForEachFrom.o \
lstDestroy.o lstNext.o lstPrev.o"
LIB_OBJECTS="@LIBOBJS@"
do_compile main.o ${MDEFS}
for o in ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
do
do_compile "$o"
done
case "@use_meta@" in
yes)
case "@use_filemon@" in
no) MDEFS=;;
*)
MDEFS="-DUSE_FILEMON -DUSE_FILEMON_`echo @use_filemon@ | toUpper`"
case "@use_filemon@,@filemon_h@" in
dev,*/filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";;
*) FDEFS=;;
esac
do_compile filemon_@use_filemon@.o filemon/filemon_@use_filemon@.c ${FDEFS}
BASE_OBJECTS="filemon_@use_filemon@.o $BASE_OBJECTS"
;;
esac
do_compile meta.o ${MDEFS}
BASE_OBJECTS="meta.o ${BASE_OBJECTS}"
;;
esac
do_compile job.o ${MDEFS}
do_link bmake main.o job.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}

View File

@ -0,0 +1,162 @@
/* $NetBSD: make-conf.h,v 1.1.1.5 2015/05/19 21:36:44 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
*/
/*
* DEFMAXJOBS
* DEFMAXLOCAL
* These control the default concurrency. On no occasion will more
* than DEFMAXJOBS targets be created at once (locally or remotely)
* DEFMAXLOCAL is the highest number of targets which will be
* created on the local machine at once. Note that if you set this
* to 0, nothing will ever happen...
*/
#define DEFMAXJOBS 4
#define DEFMAXLOCAL 1
/*
* INCLUDES
* LIBRARIES
* These control the handling of the .INCLUDES and .LIBS variables.
* If INCLUDES is defined, the .INCLUDES variable will be filled
* from the search paths of those suffixes which are marked by
* .INCLUDES dependency lines. Similarly for LIBRARIES and .LIBS
* See suff.c for more details.
*/
#define INCLUDES
#define LIBRARIES
/*
* LIBSUFF
* Is the suffix used to denote libraries and is used by the Suff module
* to find the search path on which to seek any -l<xx> targets.
*
* RECHECK
* If defined, Make_Update will check a target for its current
* modification time after it has been re-made, setting it to the
* starting time of the make only if the target still doesn't exist.
* Unfortunately, under NFS the modification time often doesn't
* get updated in time, so a target will appear to not have been
* re-made, causing later targets to appear up-to-date. On systems
* that don't have this problem, you should defined this. Under
* NFS you probably should not, unless you aren't exporting jobs.
*/
#define LIBSUFF ".a"
#define RECHECK
/*
* POSIX
* Adhere to the POSIX 1003.2 draft for the make(1) program.
* - Use MAKEFLAGS instead of MAKE to pick arguments from the
* environment.
* - Allow empty command lines if starting with tab.
*/
#define POSIX
/*
* SYSVINCLUDE
* Recognize system V like include directives [include "filename"]
* SYSVVARSUB
* Recognize system V like ${VAR:x=y} variable substitutions
*/
#define SYSVINCLUDE
#define SYSVVARSUB
/*
* GMAKEEXPORT
* Recognize gmake like variable export directives [export <VAR>=<VALUE>]
*/
#define GMAKEEXPORT
/*
* SUNSHCMD
* Recognize SunOS and Solaris:
* VAR :sh= CMD # Assign VAR to the command substitution of CMD
* ${VAR:sh} # Return the command substitution of the value
* # of ${VAR}
*/
#define SUNSHCMD
/*
* USE_IOVEC
* We have writev(2)
*/
#ifdef HAVE_SYS_UIO_H
# define USE_IOVEC
#endif
#if defined(MAKE_NATIVE) && !defined(__ELF__)
# ifndef RANLIBMAG
# define RANLIBMAG "__.SYMDEF"
# endif
#endif

2437
devel/bmake/files/make.1 Normal file

File diff suppressed because it is too large Load Diff

1555
devel/bmake/files/make.c Normal file

File diff suppressed because it is too large Load Diff

553
devel/bmake/files/make.h Normal file
View File

@ -0,0 +1,553 @@
/* $NetBSD: make.h,v 1.1.1.9 2020/05/24 05:35:52 nia Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)make.h 8.3 (Berkeley) 6/13/95
*/
/*
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: @(#)make.h 8.3 (Berkeley) 6/13/95
*/
/*-
* make.h --
* The global definitions for pmake
*/
#ifndef _MAKE_H_
#define _MAKE_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <unistd.h>
#include <sys/cdefs.h>
#ifndef FD_CLOEXEC
#define FD_CLOEXEC 1
#endif
#if defined(__GNUC__)
#define MAKE_GNUC_PREREQ(x, y) \
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
(__GNUC__ > (x)))
#else /* defined(__GNUC__) */
#define MAKE_GNUC_PREREQ(x, y) 0
#endif /* defined(__GNUC__) */
#if MAKE_GNUC_PREREQ(2, 7)
#define MAKE_ATTR_UNUSED __attribute__((__unused__))
#else
#define MAKE_ATTR_UNUSED /* delete */
#endif
#if MAKE_GNUC_PREREQ(2, 5)
#define MAKE_ATTR_DEAD __attribute__((__noreturn__))
#elif defined(__GNUC__)
#define MAKE_ATTR_DEAD __volatile
#else
#define MAKE_ATTR_DEAD /* delete */
#endif
#if MAKE_GNUC_PREREQ(2, 7)
#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \
__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
#else
#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */
#endif
#include "sprite.h"
#include "lst.h"
#include "hash.h"
#include "make-conf.h"
#include "buf.h"
#include "make_malloc.h"
/*
* some vendors don't have this --sjg
*/
#if defined(S_IFDIR) && !defined(S_ISDIR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#if defined(sun) && (defined(__svr4__) || defined(__SVR4))
#define POSIX_SIGNALS
#endif
/*-
* The structure for an individual graph node. Each node has several
* pieces of data associated with it.
* 1) the name of the target it describes
* 2) the location of the target file in the file system.
* 3) the type of operator used to define its sources (qv. parse.c)
* 4) whether it is involved in this invocation of make
* 5) whether the target has been remade
* 6) whether any of its children has been remade
* 7) the number of its children that are, as yet, unmade
* 8) its modification time
* 9) the modification time of its youngest child (qv. make.c)
* 10) a list of nodes for which this is a source (parents)
* 11) a list of nodes on which this depends (children)
* 12) a list of nodes that depend on this, as gleaned from the
* transformation rules (iParents)
* 13) a list of ancestor nodes, which includes parents, iParents,
* and recursive parents of parents
* 14) a list of nodes of the same name created by the :: operator
* 15) a list of nodes that must be made (if they're made) before
* this node can be, but that do not enter into the datedness of
* this node.
* 16) a list of nodes that must be made (if they're made) before
* this node or any child of this node can be, but that do not
* enter into the datedness of this node.
* 17) a list of nodes that must be made (if they're made) after
* this node is, but that do not depend on this node, in the
* normal sense.
* 18) a Lst of ``local'' variables that are specific to this target
* and this target only (qv. var.c [$@ $< $?, etc.])
* 19) a Lst of strings that are commands to be given to a shell
* to create this target.
*/
typedef struct GNode {
char *name; /* The target's name */
char *uname; /* The unexpanded name of a .USE node */
char *path; /* The full pathname of the file */
int type; /* Its type (see the OP flags, below) */
int flags;
#define REMAKE 0x1 /* this target needs to be (re)made */
#define CHILDMADE 0x2 /* children of this target were made */
#define FORCE 0x4 /* children don't exist, and we pretend made */
#define DONE_WAIT 0x8 /* Set by Make_ProcessWait() */
#define DONE_ORDER 0x10 /* Build requested by .ORDER processing */
#define FROM_DEPEND 0x20 /* Node created from .depend */
#define DONE_ALLSRC 0x40 /* We do it once only */
#define CYCLE 0x1000 /* Used by MakePrintStatus */
#define DONECYCLE 0x2000 /* Used by MakePrintStatus */
#define INTERNAL 0x4000 /* Internal use only */
enum enum_made {
UNMADE, DEFERRED, REQUESTED, BEINGMADE,
MADE, UPTODATE, ERROR, ABORTED
} made; /* Set to reflect the state of processing
* on this node:
* UNMADE - Not examined yet
* DEFERRED - Examined once (building child)
* REQUESTED - on toBeMade list
* BEINGMADE - Target is already being made.
* Indicates a cycle in the graph.
* MADE - Was out-of-date and has been made
* UPTODATE - Was already up-to-date
* ERROR - An error occurred while it was being
* made (used only in compat mode)
* ABORTED - The target was aborted due to
* an error making an inferior (compat).
*/
int unmade; /* The number of unmade children */
time_t mtime; /* Its modification time */
struct GNode *cmgn; /* The youngest child */
Lst iParents; /* Links to parents for which this is an
* implied source, if any */
Lst cohorts; /* Other nodes for the :: operator */
Lst parents; /* Nodes that depend on this one */
Lst children; /* Nodes on which this one depends */
Lst order_pred; /* .ORDER nodes we need made */
Lst order_succ; /* .ORDER nodes who need us */
char cohort_num[8]; /* #n for this cohort */
int unmade_cohorts;/* # of unmade instances on the
cohorts list */
struct GNode *centurion; /* Pointer to the first instance of a ::
node; only set when on a cohorts list */
unsigned int checked; /* Last time we tried to makle this node */
Hash_Table context; /* The local variables */
Lst commands; /* Creation commands */
struct _Suff *suffix; /* Suffix for the node (determined by
* Suff_FindDeps and opaque to everyone
* but the Suff module) */
const char *fname; /* filename where the GNode got defined */
int lineno; /* line number where the GNode got defined */
} GNode;
/*
* The OP_ constants are used when parsing a dependency line as a way of
* communicating to other parts of the program the way in which a target
* should be made. These constants are bitwise-OR'ed together and
* placed in the 'type' field of each node. Any node that has
* a 'type' field which satisfies the OP_NOP function was never never on
* the lefthand side of an operator, though it may have been on the
* righthand side...
*/
#define OP_DEPENDS 0x00000001 /* Execution of commands depends on
* kids (:) */
#define OP_FORCE 0x00000002 /* Always execute commands (!) */
#define OP_DOUBLEDEP 0x00000004 /* Execution of commands depends on kids
* per line (::) */
#define OP_OPMASK (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
#define OP_OPTIONAL 0x00000008 /* Don't care if the target doesn't
* exist and can't be created */
#define OP_USE 0x00000010 /* Use associated commands for parents */
#define OP_EXEC 0x00000020 /* Target is never out of date, but always
* execute commands anyway. Its time
* doesn't matter, so it has none...sort
* of */
#define OP_IGNORE 0x00000040 /* Ignore errors when creating the node */
#define OP_PRECIOUS 0x00000080 /* Don't remove the target when
* interrupted */
#define OP_SILENT 0x00000100 /* Don't echo commands when executed */
#define OP_MAKE 0x00000200 /* Target is a recursive make so its
* commands should always be executed when
* it is out of date, regardless of the
* state of the -n or -t flags */
#define OP_JOIN 0x00000400 /* Target is out-of-date only if any of its
* children was out-of-date */
#define OP_MADE 0x00000800 /* Assume the children of the node have
* been already made */
#define OP_SPECIAL 0x00001000 /* Special .BEGIN, .END, .INTERRUPT */
#define OP_USEBEFORE 0x00002000 /* Like .USE, only prepend commands */
#define OP_INVISIBLE 0x00004000 /* The node is invisible to its parents.
* I.e. it doesn't show up in the parents's
* local variables. */
#define OP_NOTMAIN 0x00008000 /* The node is exempt from normal 'main
* target' processing in parse.c */
#define OP_PHONY 0x00010000 /* Not a file target; run always */
#define OP_NOPATH 0x00020000 /* Don't search for file in the path */
#define OP_WAIT 0x00040000 /* .WAIT phony node */
#define OP_NOMETA 0x00080000 /* .NOMETA do not create a .meta file */
#define OP_META 0x00100000 /* .META we _do_ want a .meta file */
#define OP_NOMETA_CMP 0x00200000 /* Do not compare commands in .meta file */
#define OP_SUBMAKE 0x00400000 /* Possibly a submake node */
/* Attributes applied by PMake */
#define OP_TRANSFORM 0x80000000 /* The node is a transformation rule */
#define OP_MEMBER 0x40000000 /* Target is a member of an archive */
#define OP_LIB 0x20000000 /* Target is a library */
#define OP_ARCHV 0x10000000 /* Target is an archive construct */
#define OP_HAS_COMMANDS 0x08000000 /* Target has all the commands it should.
* Used when parsing to catch multiple
* commands for a target */
#define OP_SAVE_CMDS 0x04000000 /* Saving commands on .END (Compat) */
#define OP_DEPS_FOUND 0x02000000 /* Already processed by Suff_FindDeps */
#define OP_MARK 0x01000000 /* Node found while expanding .ALLSRC */
#define NoExecute(gn) ((gn->type & OP_MAKE) ? noRecursiveExecute : noExecute)
/*
* OP_NOP will return TRUE if the node with the given type was not the
* object of a dependency operator
*/
#define OP_NOP(t) (((t) & OP_OPMASK) == 0x00000000)
#define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
/*
* The TARG_ constants are used when calling the Targ_FindNode and
* Targ_FindList functions in targ.c. They simply tell the functions what to
* do if the desired node(s) is (are) not found. If the TARG_CREATE constant
* is given, a new, empty node will be created for the target, placed in the
* table of all targets and its address returned. If TARG_NOCREATE is given,
* a NULL pointer will be returned.
*/
#define TARG_NOCREATE 0x00 /* don't create it */
#define TARG_CREATE 0x01 /* create node if not found */
#define TARG_NOHASH 0x02 /* don't look in/add to hash table */
/*
* These constants are all used by the Str_Concat function to decide how the
* final string should look. If STR_ADDSPACE is given, a space will be
* placed between the two strings. If STR_ADDSLASH is given, a '/' will
* be used instead of a space. If neither is given, no intervening characters
* will be placed between the two strings in the final output. If the
* STR_DOFREE bit is set, the two input strings will be freed before
* Str_Concat returns.
*/
#define STR_ADDSPACE 0x01 /* add a space when Str_Concat'ing */
#define STR_ADDSLASH 0x02 /* add a slash when Str_Concat'ing */
/*
* Error levels for parsing. PARSE_FATAL means the process cannot continue
* once the makefile has been parsed. PARSE_WARNING means it can. Passed
* as the first argument to Parse_Error.
*/
#define PARSE_INFO 3
#define PARSE_WARNING 2
#define PARSE_FATAL 1
/*
* Values returned by Cond_Eval.
*/
#define COND_PARSE 0 /* Parse the next lines */
#define COND_SKIP 1 /* Skip the next lines */
#define COND_INVALID 2 /* Not a conditional statement */
/*
* Definitions for the "local" variables. Used only for clarity.
*/
#define TARGET "@" /* Target of dependency */
#define OODATE "?" /* All out-of-date sources */
#define ALLSRC ">" /* All sources */
#define IMPSRC "<" /* Source implied by transformation */
#define PREFIX "*" /* Common prefix */
#define ARCHIVE "!" /* Archive in "archive(member)" syntax */
#define MEMBER "%" /* Member in "archive(member)" syntax */
#define FTARGET "@F" /* file part of TARGET */
#define DTARGET "@D" /* directory part of TARGET */
#define FIMPSRC "<F" /* file part of IMPSRC */
#define DIMPSRC "<D" /* directory part of IMPSRC */
#define FPREFIX "*F" /* file part of PREFIX */
#define DPREFIX "*D" /* directory part of PREFIX */
/*
* Global Variables
*/
extern Lst create; /* The list of target names specified on the
* command line. used to resolve #if
* make(...) statements */
extern Lst dirSearchPath; /* The list of directories to search when
* looking for targets */
extern Boolean compatMake; /* True if we are make compatible */
extern Boolean ignoreErrors; /* True if should ignore all errors */
extern Boolean beSilent; /* True if should print no commands */
extern Boolean noExecute; /* True if should execute nothing */
extern Boolean noRecursiveExecute; /* True if should execute nothing */
extern Boolean allPrecious; /* True if every target is precious */
extern Boolean deleteOnError; /* True if failed targets should be deleted */
extern Boolean keepgoing; /* True if should continue on unaffected
* portions of the graph when have an error
* in one portion */
extern Boolean touchFlag; /* TRUE if targets should just be 'touched'
* if out of date. Set by the -t flag */
extern Boolean queryFlag; /* TRUE if we aren't supposed to really make
* anything, just see if the targets are out-
* of-date */
extern Boolean doing_depend; /* TRUE if processing .depend */
extern Boolean checkEnvFirst; /* TRUE if environment should be searched for
* variables before the global context */
extern Boolean jobServer; /* a jobServer already exists */
extern Boolean parseWarnFatal; /* TRUE if makefile parsing warnings are
* treated as errors */
extern Boolean varNoExportEnv; /* TRUE if we should not export variables
* set on the command line to the env. */
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 */
extern GNode *VAR_FOR; /* Iteration variables */
extern char var_Error[]; /* Value returned by Var_Parse when an error
* is encountered. It actually points to
* an empty string, so naive callers needn't
* worry about it. */
extern time_t now; /* The time at the start of this whole
* process */
extern Boolean oldVars; /* Do old-style variable substitution */
extern Lst sysIncPath; /* The system include path. */
extern Lst defIncPath; /* The default include path. */
extern char curdir[]; /* Startup directory */
extern char *progname; /* The program name */
extern char *makeDependfile; /* .depend */
extern char **savedEnv; /* if we replaced environ this will be non-NULL */
/*
* We cannot vfork() in a child of vfork().
* Most systems do not enforce this but some do.
*/
#define vFork() ((getpid() == myPid) ? vfork() : fork())
extern pid_t myPid;
#define MAKEFLAGS ".MAKEFLAGS"
#define MAKEOVERRIDES ".MAKEOVERRIDES"
#define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */
#define MAKE_EXPORTED ".MAKE.EXPORTED" /* variables we export */
#define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all the makefiles we read */
#define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
#define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
#define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
#define MAKE_MODE ".MAKE.MODE"
#ifndef MAKE_LEVEL_ENV
# define MAKE_LEVEL_ENV "MAKELEVEL"
#endif
/*
* debug control:
* There is one bit per module. It is up to the module what debug
* information to print.
*/
extern FILE *debug_file; /* Output written here - default stdout */
extern int debug;
#define DEBUG_ARCH 0x00001
#define DEBUG_COND 0x00002
#define DEBUG_DIR 0x00004
#define DEBUG_GRAPH1 0x00008
#define DEBUG_GRAPH2 0x00010
#define DEBUG_JOB 0x00020
#define DEBUG_MAKE 0x00040
#define DEBUG_SUFF 0x00080
#define DEBUG_TARG 0x00100
#define DEBUG_VAR 0x00200
#define DEBUG_FOR 0x00400
#define DEBUG_SHELL 0x00800
#define DEBUG_ERROR 0x01000
#define DEBUG_LOUD 0x02000
#define DEBUG_META 0x04000
#define DEBUG_GRAPH3 0x10000
#define DEBUG_SCRIPT 0x20000
#define DEBUG_PARSE 0x40000
#define DEBUG_CWD 0x80000
#define CONCAT(a,b) a##b
#define DEBUG(module) (debug & CONCAT(DEBUG_,module))
#include "nonints.h"
int Make_TimeStamp(GNode *, GNode *);
Boolean Make_OODate(GNode *);
void Make_ExpandUse(Lst);
time_t Make_Recheck(GNode *);
void Make_HandleUse(GNode *, GNode *);
void Make_Update(GNode *);
void Make_DoAllVar(GNode *);
Boolean Make_Run(Lst);
char * Check_Cwd_Cmd(const char *);
void Check_Cwd(const char **);
void PrintOnError(GNode *, const char *);
void Main_ExportMAKEFLAGS(Boolean);
Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
int mkTempFile(const char *, char **);
int str2Lst_Append(Lst, char *, const char *);
int cached_lstat(const char *, void *);
int cached_stat(const char *, void *);
#define VARF_UNDEFERR 1
#define VARF_WANTRES 2
#define VARF_ASSIGN 4
#ifdef __GNUC__
#define UNCONST(ptr) ({ \
union __unconst { \
const void *__cp; \
void *__p; \
} __d; \
__d.__cp = ptr, __d.__p; })
#else
#define UNCONST(ptr) (void *)(ptr)
#endif
#ifndef MIN
#define MIN(a, b) ((a < b) ? a : b)
#endif
#ifndef MAX
#define MAX(a, b) ((a > b) ? a : b)
#endif
/* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN BMAKE_PATH_MAX
#endif
#ifndef PATH_MAX
#define PATH_MAX MAXPATHLEN
#endif
#if defined(SYSV)
#define KILLPG(pid, sig) kill(-(pid), (sig))
#else
#define KILLPG(pid, sig) killpg((pid), (sig))
#endif
#endif /* _MAKE_H_ */

View File

@ -0,0 +1,119 @@
/* $NetBSD: make_malloc.c,v 1.1.1.4 2020/05/24 05:35:52 nia Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifdef MAKE_NATIVE
#include <sys/cdefs.h>
__RCSID("$NetBSD: make_malloc.c,v 1.1.1.4 2020/05/24 05:35:52 nia Exp $");
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "make.h"
#ifndef USE_EMALLOC
static MAKE_ATTR_DEAD void enomem(void);
/*
* enomem --
* die when out of memory.
*/
static MAKE_ATTR_DEAD void
enomem(void)
{
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(ENOMEM));
exit(2);
}
/*
* bmake_malloc --
* malloc, but die on error.
*/
void *
bmake_malloc(size_t len)
{
void *p;
if ((p = malloc(len)) == NULL)
enomem();
return(p);
}
/*
* bmake_strdup --
* strdup, but die on error.
*/
char *
bmake_strdup(const char *str)
{
size_t len;
char *p;
len = strlen(str) + 1;
if ((p = malloc(len)) == NULL)
enomem();
return memcpy(p, str, len);
}
/*
* bmake_strndup --
* strndup, but die on error.
*/
char *
bmake_strndup(const char *str, size_t max_len)
{
size_t len;
char *p;
if (str == NULL)
return NULL;
len = strlen(str);
if (len > max_len)
len = max_len;
p = bmake_malloc(len + 1);
memcpy(p, str, len);
p[len] = '\0';
return(p);
}
/*
* bmake_realloc --
* realloc, but die on error.
*/
void *
bmake_realloc(void *ptr, size_t size)
{
if ((ptr = realloc(ptr, size)) == NULL)
enomem();
return(ptr);
}
#endif

View File

@ -0,0 +1,41 @@
/* $NetBSD: make_malloc.h,v 1.1.1.1 2009/09/18 20:55:23 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef USE_EMALLOC
void *bmake_malloc(size_t);
void *bmake_realloc(void *, size_t);
char *bmake_strdup(const char *);
char *bmake_strndup(const char *, size_t);
#else
#include <util.h>
#define bmake_malloc(x) emalloc(x)
#define bmake_realloc(x,y) erealloc(x,y)
#define bmake_strdup(x) estrdup(x)
#define bmake_strndup(x,y) estrndup(x,y)
#endif

View File

@ -0,0 +1,84 @@
# RCSid:
# $Id: makefile.boot.in,v 1.1.1.4 2009/09/18 20:55:30 joerg Exp $
#
# modify MACHINE and MACHINE_ARCH as appropriate for your target architecture
#
prefix=@prefix@
srcdir=@srcdir@
VPATH=.:$(srcdir)
CC=@CC@
INSTALL=$(srcdir)/install-sh
MKDEP=$(srcdir)/mkdeps.sh -n -i/usr/include
MKDEP_OPTS=-A
MK=${prefix}/share/mk
MKSRC=@mksrc@
# this is what we build into bmake
DEFAULT_SYS_PATH = @default_sys_path@
# this is what we might use during bootstrap
BOOTSTRAP_SYS_PATH= `pwd`/mk:${MK}:${MKSRC}:${DEFAULT_SYS_PATH}:/usr/share/mk:/usr/local/share/mk:/opt/share/mk
CFLAGS= @CFLAGS@ -I. -I$(srcdir) @DEFS@ @CPPFLAGS@ ${XDEFS} \
-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
MDEFS="-D@force_machine@MACHINE=\"@machine@\"" "-DMACHINE_ARCH=\"@machine_arch@\""
OBJ=arch.o buf.o compat.o cond.o dir.o for.o hash.o job.o main.o make.o \
parse.o str.o suff.o targ.o trace.o var.o util.o getopt.o sigcompat.o \
strlist.o make_malloc.o \
@LIBOBJS@
BMAKE_ENV= CC="$(CC)" LIBC= MAKEFLAGS= MAKESYSPATH=${BOOTSTRAP_SYS_PATH}
bootstrap: bmake.boot .mk.done
${BMAKE_ENV} ./bmake.boot -f Makefile
${BMAKE_ENV} ./bmake.boot -f Makefile bmake.1
${BMAKE_ENV} `pwd`/bmake -f Makefile test
bmake: bmake.boot
@echo you might want to try:
@echo ${MAKE} -f makefile.boot bootstrap
cp bmake.boot $@
bmake.boot: ${OBJ}
(cd lst.lib; $(MAKE) -f makefile.boot CC="$(CC)" CFLAGS="-I.. -I../${srcdir} -I${srcdir} ${CFLAGS}" )
${CC} *.o lst.lib/*.o -o $@ @LDFLAGS@ @LIBS@
rm -f *.[ado] */*.[ado]
.mk.done:
@if test -s ${MKSRC}/install-mk; then \
sh ${MKSRC}/install-mk -v -m 644 `pwd`/mk ${USE_OS}; \
elif test ! -s /usr/share/mk/sys.mk -a ! -s ${MK}/sys.mk; then \
echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC or MK; false; \
fi
@touch $@
install: install-bin install-man install-mk
install-bin:
test -d ${prefix}/bin || ${INSTALL} -m 755 -d ${prefix}/bin
${INSTALL} -m 755 bmake ${prefix}/bin
install-man:
test -d ${prefix}/man/cat1 || ${INSTALL} -m 755 -d ${prefix}/man/cat1
${INSTALL} -m 444 ${srcdir}/bmake.cat1 ${prefix}/man/cat1/bmake.1
install-mk:
@if test -s ${MKSRC}/install-mk; then \
test -d ${DESTDIR}${MK} || ${INSTALL} -m 775 -d ${DESTDIR}${MK}; \
sh ${MKSRC}/install-mk -v -m 644 ${DESTDIR}${MK} ${USE_OS}; \
else \
echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false; \
fi
depend:
VPATH=${VPATH} ${MKDEP} $(MKDEP_OPTS) -f makefile.boot ${CFLAGS} ${OBJ:.o=.c}
(cd lst.lib; $(MAKE) -f makefile.boot depend MKDEP="$(MKDEP) $(MKDEP_OPTS)" CC="$(CC)" CFLAGS="-I.. ${CFLAGS}" )
main.o: $(srcdir)/main.c
${CC} ${CFLAGS} ${MDEFS} -o $@ -c $(srcdir)/main.c
${OBJ}: config.h
clean:
rm -f bmake *.[ado] */*.[ado] .*.done .depend

View File

@ -0,0 +1,14 @@
# $Id: makefile.in,v 1.1.1.1 2015/05/19 21:36:44 joerg 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=$@

1743
devel/bmake/files/meta.c Normal file

File diff suppressed because it is too large Load Diff

59
devel/bmake/files/meta.h Normal file
View File

@ -0,0 +1,59 @@
/* $NetBSD: meta.h,v 1.1.1.3 2020/05/24 05:35:52 nia Exp $ */
/*
* Things needed for 'meta' mode.
*/
/*
* Copyright (c) 2009-2010, Juniper Networks, Inc.
*
* 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.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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.
*/
typedef struct BuildMon {
char meta_fname[MAXPATHLEN];
struct filemon *filemon;
int mon_fd;
FILE *mfp;
} BuildMon;
extern Boolean useMeta;
struct Job; /* not defined yet */
void meta_init(void);
void meta_finish(void);
void meta_mode_init(const char *);
void meta_job_start(struct Job *, GNode *);
void meta_job_child(struct Job *);
void meta_job_parent(struct Job *, pid_t);
int meta_job_fd(struct Job *);
int meta_job_event(struct Job *);
void meta_job_error(struct Job *, GNode *, int, int);
void meta_job_output(struct Job *, char *, const char *);
int meta_cmd_finish(void *);
int meta_job_finish(struct Job *);
Boolean meta_oodate(GNode *, Boolean);
void meta_compat_start(void);
void meta_compat_child(void);
void meta_compat_parent(pid_t);

View File

@ -0,0 +1,88 @@
/* $NetBSD: metachar.c,v 1.1.1.1 2020/05/24 05:35:52 nia Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#if defined(MAKE_NATIVE) || defined(HAVE_NBTOOL_CONFIG_H)
#include <sys/cdefs.h>
#endif
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: metachar.c,v 1.1.1.1 2020/05/24 05:35:52 nia Exp $");
#endif
#include "metachar.h"
/*
* The following array is used to make a fast determination of which
* characters are interpreted specially by the shell. If a command
* contains any of these characters, it is executed by the shell, not
* directly by us.
*
* perhaps move it to ctype?
*/
unsigned char _metachar[128] = {
// nul soh stx etx eot enq ack bel
1, 0, 0, 0, 0, 0, 0, 0,
// bs ht nl vt np cr so si
0, 0, 1, 0, 0, 0, 0, 0,
// dle dc1 dc2 dc3 dc4 nak syn etb
0, 0, 0, 0, 0, 0, 0, 0,
// can em sub esc fs gs rs us
0, 0, 0, 0, 0, 0, 0, 0,
// sp ! " # $ % & '
0, 1, 1, 1, 1, 0, 1, 1,
// ( ) * + , - . /
1, 1, 1, 0, 0, 0, 0, 0,
// 0 1 2 3 4 5 6 7
0, 0, 0, 0, 0, 0, 0, 0,
// 8 9 : ; < = > ?
0, 0, 0, 1, 1, 0, 1, 1,
// @ A B C D E F G
0, 0, 0, 0, 0, 0, 0, 0,
// H I J K L M N O
0, 0, 0, 0, 0, 0, 0, 0,
// P Q R S T U V W
0, 0, 0, 0, 0, 0, 0, 0,
// X Y Z [ \ ] ^ _
0, 0, 0, 1, 1, 1, 1, 0,
// ` a b c d e f g
1, 0, 0, 0, 0, 0, 0, 0,
// h i j k l m n o
0, 0, 0, 0, 0, 0, 0, 0,
// p q r s t u v w
0, 0, 0, 0, 0, 0, 0, 0,
// x y z { | } ~ del
0, 0, 0, 1, 1, 1, 1, 0,
};

View File

@ -0,0 +1,61 @@
/* $NetBSD: metachar.h,v 1.1.1.1 2020/05/24 05:35:52 nia Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _METACHAR_H
#define _METACHAR_H
#include <ctype.h>
extern unsigned char _metachar[];
#define ismeta(c) _metachar[(c) & 0x7f]
static inline int
hasmeta(const char *cmd)
{
while (!ismeta(*cmd))
cmd++;
return *cmd != '\0';
}
static inline int
needshell(const char *cmd, int white)
{
while (!ismeta(*cmd) && *cmd != ':' && *cmd != '=') {
if (white && isspace((unsigned char)*cmd))
break;
cmd++;
}
return *cmd != '\0';
}
#endif /* _METACHAR_H */

View File

@ -0,0 +1,186 @@
/* $NetBSD: cdefs.h,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Berkeley Software Design, Inc.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#)cdefs.h 8.7 (Berkeley) 1/21/94
*/
#ifndef _SYS_CDEFS_H_
#if defined(NEED_HOST_CDEFS_H)
/*
* make sure we don't come past here again.
*/
#undef NEED_HOST_CDEFS_H
/*
* Some systems - notably linux, have sys/cdefs.h
* which is not really compatible with our's.
*/
#ifdef __GNUC__
# include_next <sys/cdefs.h>
#else
/*
* It sucks that we have to hard code a path like this.
* But systems that have a sys/cdefs.h that don't use gcc
* should be few.
*/
# include "/usr/include/sys/cdefs.h"
#endif
/*
* We are about to [re]define these
*/
#undef __P
#undef _SYS_CDEFS_H_
#endif
#define _SYS_CDEFS_H_
#ifdef NetBSD
#include <machine/cdefs.h>
#endif
#if defined(__cplusplus)
# ifndef __BEGIN_DECLS
# define __BEGIN_DECLS extern "C" {
# endif
# ifndef __END_DECLS
# define __END_DECLS };
# endif
#else
# ifndef __BEGIN_DECLS
# define __BEGIN_DECLS
# endif
# ifndef __END_DECLS
# define __END_DECLS
# endif
#endif
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
* The __CONCAT macro is a bit tricky -- make sure you don't put spaces
* in between its arguments. __CONCAT can also concatenate double-quoted
* strings produced by the __STRING macro, but this only works with ANSI C.
*/
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos /* full-blown ANSI C */
#ifndef __CONCAT
#define __CONCAT(x,y) x ## y
#endif
#define __STRING(x) #x
#define __const const /* define reserved names to standard */
#define __signed signed
#define __volatile volatile
#if defined(__cplusplus)
#define __inline inline /* convert to C++ keyword */
#else
#ifndef __GNUC__
#define __inline /* delete GCC keyword */
#endif /* !__GNUC__ */
#endif /* !__cplusplus */
#else /* !(__STDC__ || __cplusplus) */
#define __P(protos) () /* traditional C preprocessor */
#define __CONCAT(x,y) x/**/y
#define __STRING(x) "x"
#ifndef __GNUC__
#define __const /* delete pseudo-ANSI C keywords */
#define __inline
#define __signed
#define __volatile
#endif /* !__GNUC__ */
/*
* In non-ANSI C environments, new programs will want ANSI-only C keywords
* deleted from the program and old programs will want them left alone.
* Programs using the ANSI C keywords const, inline etc. as normal
* identifiers should define -DNO_ANSI_KEYWORDS.
*/
#ifndef NO_ANSI_KEYWORDS
#define const __const /* convert ANSI C keywords */
#define inline __inline
#define signed __signed
#define volatile __volatile
#endif /* !NO_ANSI_KEYWORDS */
#endif /* !(__STDC__ || __cplusplus) */
/*
* GCC1 and some versions of GCC2 declare dead (non-returning) and
* pure (no side effects) functions using "volatile" and "const";
* unfortunately, these then cause warnings under "-ansi -pedantic".
* GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
* these work for GNU C++ (modulo a slight glitch in the C++ grammar
* in the distribution version of 2.5.5).
*/
#if !defined(__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 5)
#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __dead __volatile
#define __pure __const
#endif
#endif
#ifdef sun386
# define __attribute__(x)
#endif
#ifdef __KPRINTF_ATTRIBUTE__
#define __kprintf_attribute__(a) __attribute__(a)
#else
#define __kprintf_attribute__(a)
#endif
/* Delete pseudo-keywords wherever they are not available or needed. */
#ifndef __dead
#define __dead
#define __pure
#endif
#define __IDSTRING(name,string) \
static const char name[] __attribute__((__unused__)) = string
#ifndef __RCSID
#define __RCSID(s) __IDSTRING(rcsid,s)
#endif
#ifndef __COPYRIGHT
#define __COPYRIGHT(s) __IDSTRING(copyright,s)
#endif
#endif /* !_SYS_CDEFS_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
ChangeLog
FILES
README
auto.obj.mk
autoconf.mk
autodep.mk
auto.dep.mk
compiler.mk
cython.mk
dep.mk
doc.mk
dpadd.mk
files.mk
final.mk
host-target.mk
host.libnames.mk
inc.mk
init.mk
install-mk
java.mk
ldorder.mk
lib.mk
libnames.mk
libs.mk
links.mk
man.mk
manifest.mk
mk-files.txt
mkopt.sh
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.debug.mk
sys.dependfile.mk
sys.vars.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
whats.mk
yacc.mk
dirdeps.mk
dirdeps-options.mk
dirdeps-targets.mk
gendirdeps.mk
install-new.mk
meta2deps.py
meta2deps.sh
meta.sys.mk
meta.autodep.mk
meta.stage.mk
meta.subdir.mk

401
devel/bmake/files/mk/README Normal file
View File

@ -0,0 +1,401 @@
# $Id: README,v 1.1.1.1 2020/05/24 05:35:53 nia 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: README,v 1.1.1.1 2020/05/24 05:35:53 nia 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 <bsd.prog.mk>".
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 <sys.mk> 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 <bsd.man.mk> 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 <bsd.man.mk> includes a file named "../Makefile.inc" if
it exists.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The include file <bsd.own.mk> 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 <bsd.prog.mk> 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 <bsd.prog.mk> includes the file named "../Makefile.inc"
if it exists, as well as the include file <bsd.man.mk>.
Some simple examples:
To build foo from foo.c with a manual page foo.1, use:
PROG= foo
.include <bsd.prog.mk>
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 <bsd.subdir.mk> contains the default targets for building
subdirectories. It has the same eight targets as <bsd.prog.mk>: 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 <bsd.sys.mk> is used by <bsd.prog.mk> and
<bsd.lib.mk>. 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 <bsd.lib.mk> has support for building libraries. It has
the same eight targets as <bsd.prog.mk>: 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 <bsd.lib.mk> includes the file named "../Makefile.inc"
if it exists, as well as the include file <bsd.man.mk>.
It has rules for building profiled objects; profiled libraries are
built by default.
Libraries are ranlib'd when made.

View File

@ -0,0 +1,74 @@
#
# RCSid:
# $Id: auto.dep.mk,v 1.1.1.1 2020/05/24 05:35:53 nia 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_MK=auto.dep.mk 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
.if ${MAKE_VERSION} < 20160218
# 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 > $@
.else
# we have .dinclude
.if empty(_SKIP_BUILD)
_all_objs = ${OBJS} ${POBJS} ${SOBJS}
.for d in ${_all_objs:M*o:T:O:u:%=%.d}
.dinclude <$d>
.endfor
.endif
.endif
.endif

View File

@ -0,0 +1,76 @@
# $Id: auto.obj.mk,v 1.1.1.1 2020/05/24 05:35:53 nia 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 ${MK_AUTO_OBJ:Uno} == "yes"
MKOBJDIRS= auto
.endif
.if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto
# Use __objdir here so it is easier to tweak without impacting
# the logic.
.if !empty(MAKEOBJDIRPREFIX)
.if ${.CURDIR:M${MAKEOBJDIRPREFIX}/*} != ""
# we are already in obj tree!
__objdir?= ${.CURDIR}
.endif
__objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR}
.endif
__objdir?= ${MAKEOBJDIR:Uobj}
__objdir:= ${__objdir}
.if ${.OBJDIR:tA} != ${__objdir:tA}
# 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:tA} != ${__objdir:tA}
# we did not get what we want - do we care?
.if ${__objdir_made:Uno:M${__objdir}/*} != ""
# watch out for __objdir being relative path
.if !(${__objdir:M/*} == "" && ${.OBJDIR:tA} == ${${.CURDIR}/${__objdir}:L:tA})
.error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
.endif
.endif
# apparently we can live with it
# make sure we know what we have
.OBJDIR: ${.CURDIR}
.endif
.endif
.endif

View File

@ -0,0 +1,80 @@
# $Id: autoconf.mk,v 1.1.1.1 2020/05/24 05:35:53 nia 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
CONFIGURE_DEPS += ${.CURDIR}/config.h.in ${.CURDIR}/configure
.if !target(config.h)
config.h: ${CONFIGURE_DEPS} 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: ${CONFIGURE_DEPS}
./config.status --recheck
@touch $@
config.gen: ${CONFIGURE_DEPS}
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

View File

@ -0,0 +1,219 @@
#
# RCSid:
# $Id: autodep.mk,v 1.1.1.1 2020/05/24 05:35:53 nia 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 compatibility,
# dependencies are normally updated as part of compilation.
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
DEPENDFILE?= .depend
.for d in ${DEPENDFILE:N.depend}
# bmake only groks .depend
.if ${MAKE_VERSION} < 20160218
.-include <$d>
.else
.dinclude <$d>
.endif
.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
MAKE_SHELL?= sh
# 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}
# should have been set by sys.mk
CXX_SUFFIXES?= .cc .cpp .cxx .C
# 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} $<
@${MAKE_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} $<
@${MAKE_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 $<
@${MAKE_SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
.s.d .S.d:
@echo updating dependencies for $<
@${MAKE_SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} ${AINC} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
${CXX_SUFFIXES:%=%.d}:
@echo updating dependencies for $<
@${MAKE_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; }
${CXX_SUFFIXES:%=%.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

View File

@ -0,0 +1,43 @@
# $Id: compiler.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
#
# @(#) Copyright (c) 2019, 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 ${MACHINE} == "common"
COMPILER_TYPE = none
COMPILER_VERSION = 0
.endif
.if empty(COMPILER_TYPE) || empty(COMPILER_VERSION)
# gcc does not always say gcc
_v != ${CC} --version 2> /dev/null | \
egrep -i 'clang|cc|[1-9]\.[0-9]|Free Software Foundation'
.if empty(COMPILER_TYPE)
.if ${_v:Mclang} != ""
COMPILER_TYPE = clang
.elif ${_v:M[Gg][Cc][Cc]} != "" || ${_v:MFoundation*} != ""
COMPILER_TYPE = gcc
.endif
.endif
.if empty(COMPILER_VERSION)
COMPILER_VERSION != echo "${_v:M[1-9].[0-9]*}:[1]" | \
awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
.endif
.undef _v
.endif
# just in case we don't recognize compiler
COMPILER_TYPE ?= unknown
COMPILER_VERSION ?= 0
.endif

View File

@ -0,0 +1,101 @@
# RCSid:
# $Id: cython.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
#
# @(#) Copyright (c) 2014, 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
#
# pyprefix is where python bits are
# which may not be where we want to put ours (prefix)
.if exists(/usr/pkg/include)
pyprefix?= /usr/pkg
.endif
pyprefix?= /usr/local
PYTHON_VERSION?= 2.7
PYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h
PYVERSION:= ${PYTHON_VERSION:C,\..*,,}
CFLAGS+= -I${PYTHON_H:H}
# conf.host_target() is limited to uname -m rather than uname -p
_HOST_MACHINE!= uname -m
.if ${HOST_TARGET:M*${_HOST_MACHINE}} == ""
PY_HOST_TARGET:= ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},}
.endif
COMPILE.c?= ${CC} -c ${CFLAGS}
PICO?= .pico
.SUFFIXES: ${PICO} .c
.c${PICO}:
${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
# this is what we build
.if !empty(CYTHON_MODULE_NAME)
CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
# this is where we save generated src
CYTHON_SAVEGENDIR?= ${.CURDIR}/gen
# set this empty if you don't want to handle multiple versions
.if !defined(CYTHON_PYVERSION)
CYTHON_PYVERSION:= ${PYVERSION}
.endif
CYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,}
SRCS+= ${CYTHON_GENSRCS}
.SUFFIXES: .pyx .c .So
CYTHON?= ${pyprefix}/bin/cython
# if we don't have cython we can use pre-generated srcs
.if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == ""
.PATH: ${CYTHON_SAVEGENDIR}
.else
.if !empty(CYTHON_PYVERSION)
.for c in ${CYTHON_SRCS}
${c:R}${CYTHON_PYVERSION}.${c:E}: $c
ln -sf ${.ALLSRC:M*pyx} ${.TARGET}
.endfor
.endif
.pyx.c:
${CYTHON} ${CYTHON_FLAGS} -${PYVERSION} -o ${.TARGET} ${.IMPSRC}
save-gen: ${CYTHON_GENSRCS}
mkdir -p ${CYTHON_SAVEGENDIR}
cp -p ${.ALLSRC} ${CYTHON_SAVEGENDIR}
.endif
${CYTHON_MODULE}: ${SRCS:S,.c,${PICO},}
${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*${PICO}} ${LDADD}
MODULE_BINDIR?= ${.CURDIR:H}/${PY_HOST_TARGET:U${HOST_TARGET}}
build-cython-module: ${CYTHON_MODULE}
install-cython-module: ${CYTHON_MODULE}
test -d ${DESTDIR}${MODULE_BINDIR} || \
${INSTALL} -d ${DESTDIR}${MODULE_BINDIR}
${INSTALL} -m 755 ${.ALLSRC} ${DESTDIR}${MODULE_BINDIR}
CLEANFILES+= *${PICO} ${CYTHON_MODULE}
.endif

127
devel/bmake/files/mk/dep.mk Normal file
View File

@ -0,0 +1,127 @@
# $Id: dep.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
# handle Proc*C as well...
.if defined(SRCS)
.if !empty(SRCS:M*.pc)
.include <proc.mk>
.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_MK:Uno} == "auto.dep.mk" && make(depend)
# auto.dep.mk does not "do" depend
MK_AUTODEP= no
.endif
.if ${MK_AUTODEP} == yes
MKDEP_MK ?= autodep.mk
.include <${MKDEP_MK}>
.else
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

View File

@ -0,0 +1,73 @@
# $Id: dirdeps-options.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
#
# @(#) Copyright (c) 2018, 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 is used to deal with optional DIRDEPS.
#
# It is to be included by Makefile.depend.options in a
# directory which has DIRDEPS affected by optional features.
# Makefile.depend.options should set DIRDEPS_OPTIONS and
# may also set specific DIRDEPS.* for those options.
#
# If a Makefile.depend.options file exists, it will be included by
# dirdeps.mk and meta.autodep.mk
#
# We include local.dirdeps-options.mk which may also define DIRDEPS.*
# for options.
#
# Thus a directory, that is affected by an option FOO would have
# a Makefile.depend.options that sets
# DIRDEPS_OPTIONS= FOO
# It can also set either/both of
# DIRDEPS.FOO.yes
# DIRDEPS.FOO.no
# to whatever applies for that dir, or it can rely on globals
# set in local.dirdeps-options.mk
# Either way, we will .undef DIRDEPS.* when done.
# This should have been set by Makefile.depend.options
# before including us
DIRDEPS_OPTIONS ?=
# pickup any DIRDEPS.* we need
.-include <local.dirdeps-options.mk>
.if ${.MAKE.LEVEL} == 0
# :U below avoids potential errors when we :=
.for o in ${DIRDEPS_OPTIONS:tu}
DIRDEPS += ${DIRDEPS.$o.${MK_$o:U}:U}
.endfor
DIRDEPS := ${DIRDEPS:O:u}
# avoid cross contamination
.for o in ${DIRDEPS_OPTIONS:tu}
.undef DIRDEPS.$o.yes
.undef DIRDEPS.$o.no
.endfor
.else
# whether options are enabled or not,
# we want to filter out the relevant DIRDEPS.*
# we should only be included by meta.autodep.mk
# if dependencies are to be updated
.for o in ${DIRDEPS_OPTIONS:tu}
.for d in ${DIRDEPS.$o.yes} ${DIRDEPS.$o.no}
.if exists(${SRCTOP}/$d)
GENDIRDEPS_FILTER += N$d*
.elif exists(${SRCTOP}/${d:R})
GENDIRDEPS_FILTER += N${d:R}*
.endif
.endfor
.endfor
.endif

View File

@ -0,0 +1,133 @@
# RCSid:
# $Id: dirdeps-targets.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
#
# @(#) Copyright (c) 2019 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 is used to set initial DIRDEPS for top-level build
# targets.
#
# The basic idea is that we have a list of directories in
# DIRDEPS_TARGETS_DIRS which are relative to SRCTOP.
# When asked to make 'foo' we look for any directory named 'foo'
# under DIRDEPS_TARGETS_DIRS.
# We then search those dirs for any Makefile.depend*
# Finally we select any that match conditions like REQUESTED_MACHINE
# or TARGET_SPEC and initialize DIRDEPS accordingly.
#
.if ${.MAKE.LEVEL} == 0
# pickup customizations
.-include <local.dirdeps-targets.mk>
# for DIRDEPS_BUILD this is how we prime the pump
DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo
# these prefixes can modify how we behave
# they need to be stripped when looking for target dirs
DIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build-
# matching target dirs if any
tdirs := ${.TARGETS:Nall:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}
.if !empty(DEBUG_DIRDEPS_TARGETS)
.info tdirs=${tdirs}
.endif
.if !empty(tdirs)
# some things we know we want to ignore
DIRDEPS_TARGETS_SKIP_LIST += \
*~ \
*.bak \
*.inc \
*.old \
*.options \
*.orig \
*.rej \
# the list of MACHINEs we consider
DIRDEPS_TARGETS_MACHINE_LIST += \
${ALL_MACHINE_LIST:U} \
${PSEUDO_MACHINE_LIST:Ucommon host host32} \
${TARGET_MACHINE_LIST}
DIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u}
# raw Makefile.depend* list
tdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@} 2> /dev/null; echo
.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
.info tdeps=${tdeps}
.endif
# remove things we know we don't want
tdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}}
.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
.info tdeps=${tdeps}
.endif
# plain entries (no qualifiers) these apply to any TARGET_SPEC
ptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,}
# MACHINE qualified entries
mqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
tqtdeps =
.if ${TARGET_SPEC_VARS:[#]} > 1
# TARGET_SPEC qualified entries
.if !empty(TARGET_SPEC_LIST)
# we have a list of valid TARGET_SPECS; use it
tqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
.else
# do we have a list of valid tuple members for at least
# the last tupple element? if so match on that
TARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST}
.if !empty(TARGET_SPEC_LAST_LIST)
tqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
.else
# this is sub-optimal match MACHINE,
tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
.endif
.endif
.endif
# now work out what we want in DIRDEPS
.if empty(REQUESTED_MACHINE)
# we want them all just as found
DIRDEPS = ${ptdeps} ${mqtdeps} ${tqtdeps}
.else
# we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC
# or REQUESTED_TARGET_SPEC (TARGET_SPEC)
DIRDEPS = \
${ptdeps:@d@$d.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC:U${REQUESTED_MACHINE}}}@} \
${mqtdeps:M*.${REQUESTED_MACHINE}} \
${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}}
.endif
# clean up
DIRDEPS := ${DIRDEPS:O:u}
.if !empty(DEBUG_DIRDEPS_TARGETS)
.for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS
.info $x=${$x}
.endfor
.endif
.endif
# if we got DIRDEPS get to work
.if !empty(DIRDEPS)
.include <dirdeps.mk>
DIRDEPS_TARGETS_SKIP += all clean* destroy*
.for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}}
$t: dirdeps
.endfor
.endif
.endif

View File

@ -0,0 +1,834 @@
# $Id: dirdeps.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
# Copyright (c) 2010-2020, Simon J. Gerraty
# Copyright (c) 2010-2018, 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 .<machine>
# or .<target_spec> 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 .<target_spec>.
# The _DIRDEP_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.
#
# Before each Makefile.depend file is read, we set
# DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for
# its directory, and DEP_MACHINE etc according to the .<target_spec>
# represented by the suffix of the corresponding target.
#
# 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 _DIRDEP_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,}
#
# The following variables can influence the initial DIRDEPS
# computation with regard to the TARGET_SPECs that will be
# built.
# Most should also be considered by init.mk
#
# ONLY_TARGET_SPEC_LIST
# Defines a list of TARGET_SPECs for which the current
# directory can be built.
# If ALL_MACHINES is defined, we build for all the
# TARGET_SPECs listed.
#
# ONLY_MACHINE_LIST
# As for ONLY_TARGET_SPEC_LIST but only specifies
# MACHINEs.
#
# NOT_TARGET_SPEC_LIST
# A list of TARGET_SPECs for which the current
# directory should not be built.
#
# NOT_MACHINE_LIST
# A list of MACHINEs the current directory should not be
# built for.
#
.if !target(bootstrap) && (make(bootstrap) || \
make(bootstrap-this) || \
make(bootstrap-recurse) || \
make(bootstrap-empty))
# disable most of below
.MAKE.LEVEL = 1
.endif
# touch this at your peril
_DIRDEP_USE_LEVEL?= 0
.if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
# only the first instance is interested in all this
.if !target(_DIRDEP_USE)
# do some setup we only need once
_CURDIR ?= ${.CURDIR}
_OBJDIR ?= ${.OBJDIR}
now_utc = ${%s:L:gmtime}
.if !defined(start_utc)
start_utc := ${now_utc}
.endif
.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != ""
# This little trick let's us do
#
# mk -f dirdeps.mk some/dir.${TARGET_SPEC}
#
all:
${.TARGETS:Nall}: all
DIRDEPS := ${.TARGETS:M*[/.]*}
# so that -DNO_DIRDEPS works
DEP_RELDIR := ${DIRDEPS:[1]:R}
# this will become DEP_MACHINE below
TARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//}
.if ${TARGET_MACHINE:N*/*} == ""
TARGET_MACHINE := ${MACHINE}
.endif
# disable DIRDEPS_CACHE as it does not like this trick
MK_DIRDEPS_CACHE = no
.endif
# make sure we get the behavior we expect
.MAKE.SAVE_DOLLARS = no
# make sure these are empty to start with
_DEP_TARGET_SPEC =
# 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.
.if ${MAKE_VERSION} >= 20170130
_tspec_x := ${TARGET_SPEC_VARS:range}
.elif ${TARGET_SPEC_VARS:[#]} > 10
# seriously? better have jot(1) or equivalent to produce suitable sequence
_tspec_x := ${${JOT:Ujot} ${TARGET_SPEC_VARS:[#]}:L:sh}
.else
# we can provide the sequence ourselves
_tspec_x := ${1 2 3 4 5 6 7 8 9 10:L:[1..${TARGET_SPEC_VARS:[#]}]}
.endif
# 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)
# 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 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
.if defined(.INCLUDEDFROMFILE)
_last_dependfile := ${.INCLUDEDFROMFILE:M${.MAKE.DEPENDFILE_PREFIX}*}
.else
_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]}
.endif
.if ${_debug_reldir:U0}
.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
_dirdeps_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
# reset each time through
_build_all_dirs =
# 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: beforedirdeps .WAIT
beforedirdeps:
# 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}
.endif
# DIRDEPS_CACHE can be very handy for debugging.
# Also if repeatedly building the same target,
# we can avoid the overhead of re-computing the tree dependencies.
MK_DIRDEPS_CACHE ?= no
BUILD_DIRDEPS_CACHE ?= no
BUILD_DIRDEPS ?= yes
.if ${MK_DIRDEPS_CACHE} == "yes"
# this is where we will cache all our work
DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
.endif
.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
_debug_reldir = 1
.else
_debug_reldir = 0
.endif
.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@} != ""
_debug_search = 1
.else
_debug_search = 0
.endif
# pickup customizations
# as below you can use !target(_DIRDEP_USE) to protect things
# which should only be done once.
.-include <local.dirdeps.mk>
.if !target(_DIRDEP_USE)
# things we skip for host tools
SKIP_HOSTDIR ?=
NSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${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} \
${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \
${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \
${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@}
NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}}
.if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
NO_DIRDEPS =
.elif defined(WITHOUT_DIRDEPS_BELOW)
NO_DIRDEPS_BELOW =
.endif
.if defined(NO_DIRDEPS)
# confine ourselves to the original dir and below.
DIRDEPS_FILTER += M${_DEP_RELDIR}*
.elif defined(NO_DIRDEPS_BELOW)
DIRDEPS_FILTER += M${_DEP_RELDIR}
.endif
# this is what we run below
DIRDEP_MAKE ?= ${.MAKE}
DIRDEP_DIR ?= ${.TARGET:R}
# we suppress 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} ..."; \
${DIRDEP_USE_PRELUDE} \
MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \
TARGET_SPEC=${.TARGET:E} \
MACHINE=${.TARGET:E} \
${DIRDEP_MAKE} -C ${DIRDEP_DIR} || 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_TARGET_SPEC_LIST) && 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_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U}
.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_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that.
# Note that ONLY_TARGET_SPEC_LIST should be fully qualified.
# 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_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*}
.if empty(_only_machines)
_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
.endif
.endif
.if !empty(NOT_MACHINE_LIST)
_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
.endif
.if !empty(NOT_TARGET_SPEC_LIST)
# we must first qualify
_dm := ${DEP_MACHINE}
_only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
DEP_MACHINE := ${_dm}
_only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}}
.endif
# clean up
_only_machines := ${_only_machines:O:u}
# make sure we have a starting place?
DIRDEPS ?= ${RELDIR}
.endif # target
.if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW)
.if ${MK_DIRDEPS_CACHE} == "yes"
# just ensure this exists
build-dirdeps:
M_oneperline = @x@\\${.newline} $$x@
.if ${BUILD_DIRDEPS_CACHE} == "no"
.if !target(dirdeps-cached)
# we do this via sub-make
BUILD_DIRDEPS = no
# ignore anything but these
.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*
dirdeps: dirdeps-cached
dirdeps-cached: ${DIRDEPS_CACHE} .MAKE
@echo "${TRACER}Using ${DIRDEPS_CACHE}"
@MAKELEVEL=${.MAKE.LEVEL} ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \
dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no
# these should generally do
BUILD_DIRDEPS_MAKEFILE ?= ${MAKEFILE}
BUILD_DIRDEPS_TARGETS ?= ${.TARGETS}
# we need the .meta file to ensure we update if
# any of the Makefile.depend* changed.
# We do not want to compare the command line though.
${DIRDEPS_CACHE}: .META .NOMETA_CMP
+@{ echo '# Autogenerated - do NOT edit!'; echo; \
echo 'BUILD_DIRDEPS=no'; echo; \
echo '.include <dirdeps.mk>'; echo; \
} > ${.TARGET}.new
+@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \
DIRDEPS="${DIRDEPS}" \
TARGET_SPEC=${TARGET_SPEC} \
MAKEFLAGS= ${.MAKE} -C ${_CURDIR} -f ${BUILD_DIRDEPS_MAKEFILE} \
${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \
.MAKE.DEPENDFILE=.none \
${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \
${.MAKEFLAGS:tW:S,-d ,-d,g:tw:M-d*} \
3>&1 1>&2 | sed 's,${SRCTOP},$${SRCTOP},g' >> ${.TARGET}.new && \
mv ${.TARGET}.new ${.TARGET}
.endif
.elif !target(_count_dirdeps)
# we want to capture the dirdeps count in the cache
.END: _count_dirdeps
_count_dirdeps: .NOMETA
@echo '.info $${.newline}$${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]}' >&3
.endif
.elif !make(dirdeps) && !target(_count_dirdeps)
beforedirdeps: _count_dirdeps
_count_dirdeps: .NOMETA
@echo "${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} seconds=`expr ${now_utc} - ${start_utc}`"
.endif
.endif
.if ${BUILD_DIRDEPS} == "yes"
# 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}>
.-include <${_dep_hack:R}.options>
.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:Nhost*} == ""
# we need to build this guy's dependencies for host as well.
.if ${DEP_MACHINE:Nhost*} == ""
_machines += ${DEP_MACHINE}
.else
_machines += host
.endif
.endif
_machines := ${_machines:O:u}
.endif
.if ${TARGET_SPEC_VARS:[#]} > 1
# we need to tweak _machines
_dm := ${DEP_MACHINE}
# apply the same filtering that we do when qualifying DIRDEPS.
# M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
# Again we expect that any already qualified machines are fully qualified.
_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
DEP_MACHINE := ${_dm}
_machines := ${_machines:O:u}
.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
.if ${MAKE_VERSION} < 20160220
.-include <.depend>
.else
.dinclude <.depend>
.endif
.endif
.endif
.endif
.if ${_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} \
${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}: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:}:C,//+,/,g:O:u:@d@${SRCTOP}/$d@}
# some entries may be qualified with .<machine>
# 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@} \
${DPADD:U.:M${HOST_OBJTOP32:Uno}/*:S,${HOST_OBJTOP32:Uno}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host32,:N.*:@d@${SRCTOP}/$d@}
__qual_depdirs += ${__hostdpadd}
.endif
.if ${_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:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \
${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@}
# qualify everything now
_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u}
.endif # empty DIRDEPS
_build_all_dirs += ${_build_dirs}
_build_all_dirs := ${_build_all_dirs:O:u}
# 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_all_dirs)
.if ${BUILD_DIRDEPS_CACHE} == "yes"
# guard against _build_all_dirs being too big for a single command line
# first get list of dirs that need _DIRDEP_USE
# then export that and _build_all_dirs
_new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@}
.export _new_dirdeps _build_all_dirs
x!= echo; { echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; \
echo "dirdeps: \\"; \
for x in $$_build_all_dirs; do echo " $$x \\"; done; echo; \
for x in $$_new_dirdeps; do echo "$$x: _DIRDEP_USE"; done; echo; } >&3
.if !empty(DEP_EXPORT_VARS)
# Discouraged, but there are always exceptions.
# Handle it here rather than explain how.
x!= { echo; ${DEP_EXPORT_VARS:@v@echo '$v=${$v}';@} echo '.export ${DEP_EXPORT_VARS}'; echo; } >&3; echo
.endif
.else
# this makes it all happen
dirdeps: ${_build_all_dirs}
.endif
${_build_all_dirs}: _DIRDEP_USE
.if ${_debug_reldir}
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs}
.endif
.if !empty(DEP_EXPORT_VARS)
.export ${DEP_EXPORT_VARS}
DEP_EXPORT_VARS=
.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 ${_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
.if ${BUILD_DIRDEPS_CACHE} == "yes"
_cache_deps := ${_build_dirs:M*.$q}
.export _cache_deps
x!= echo; { echo "${_this_dir}.$m: \\"; \
for x in $$_cache_deps; do echo " $$x \\"; done; echo; } >&3
.else
${_this_dir}.$m: ${_build_dirs:M*.$q}
.endif
.endfor
.endif
.if ${_debug_reldir}
.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m}
.endif
.if ${BUILD_DIRDEPS_CACHE} == "yes"
_cache_deps := ${_build_dirs:M*.$m:N${_this_dir}.$m}
.export _cache_deps
x!= echo; { echo "${_this_dir}.$m: \\"; \
for x in $$_cache_deps; do echo " $$x \\"; done; echo; } >&3
.else
${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
.endif
.endfor
.endif
# Now find more dependencies - and recurse.
.for d in ${_build_all_dirs}
.if !target(_dirdeps_checked.$d)
# once only
_dirdeps_checked.$d:
.if ${_debug_search}
.info checking $d
.endif
# Note: _build_all_dirs is fully qualifed so d:R is always the directory
.if exists(${d:R})
# 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/,.*//}
# set these too in case Makefile.depend* uses them
.if ${TARGET_SPEC_VARS:[#]} > 1
_dtspec := ${_DEP_TARGET_SPEC:S/,/ /g}
.for i in ${_tspec_x}
DEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]}
.endfor
.else
DEP_MACHINE := ${_DEP_MACHINE}
.endif
# 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)
# M_dep_qual_fixes isn't geared to Makefile.depend
_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}}
.if ${_debug_search}
.info Looking for ${_qm}
.endif
# set this "just in case"
# we can skip :tA since we computed the path above
DEP_RELDIR := ${_m:H:S,${SRCTOP}/,,}
# and reset this
DIRDEPS =
.if ${_debug_reldir} && ${_qm} != ${_m}
.info loading ${_m} for ${d:E}
.endif
.include <${_m}>
.else
.-include <local.dirdeps-missing.mk>
.endif
.endif
.endif
.endfor
.endif # -V
.endif # BUILD_DIRDEPS
.elif ${.MAKE.LEVEL} > 42
.error You should have stopped recursing by now.
.else
# we are building something
DEP_RELDIR := ${RELDIR}
_DEP_RELDIR := ${RELDIR}
# Since we are/should be included by .MAKE.DEPENDFILE
# This is a final opportunity to add/hook global rules.
.-include <local.dirdeps-build.mk>
# pickup local dependencies
.if ${MAKE_VERSION} < 20160220
.-include <.depend>
.else
.dinclude <.depend>
.endif
.endif
# bootstrapping new dependencies made easy?
.if !target(bootstrap) && (make(bootstrap) || \
make(bootstrap-this) || \
make(bootstrap-recurse) || \
make(bootstrap-empty))
# if we are bootstrapping create the default
_want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T}
.if exists(${_want})
# stop here
${.TARGETS:Mboot*}:
.elif !make(bootstrap-empty)
# find a Makefile.depend to use as _src
_src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo
.if empty(_src)
.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty
.endif
_src?= ${.MAKE.DEPENDFILE}
.MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g'
# just create Makefile.depend* for this dir
bootstrap-this: .NOTMAIN
@echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \
echo You need to build ${RELDIR} to correctly populate it.
.if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T}
(cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T})
.else
cp ${.CURDIR}/${_src:T} ${_want}
.endif
# create Makefile.depend* for this dir and its dependencies
bootstrap: bootstrap-recurse
bootstrap-recurse: bootstrap-this
_mf := ${.PARSEFILE}
bootstrap-recurse: .NOTMAIN .MAKE
@cd ${SRCTOP} && \
for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \
test -d $$d || d=$${d%.*}; \
test -d $$d || continue; \
echo "Checking $$d for bootstrap ..."; \
(cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \
done
.endif
# create an empty Makefile.depend* to get the ball rolling.
bootstrap-empty: .NOTMAIN .NOMETA
@echo Creating empty ${RELDIR}/${_want:T}; \
echo You need to build ${RELDIR} to correctly populate it.
@{ echo DIRDEPS=; echo ".include <dirdeps.mk>"; } > ${_want}
.endif

View File

@ -0,0 +1,64 @@
# $Id: doc.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
.include <init.mk>
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 !defined(_SKIP_BUILD)
realbuild: 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:
test -d ${DESTDIR}${DOCDIR}/${DIR} || \
${INSTALL} -d ${DOC_INSTALL_OWN} -m ${DIRMODE} ${DESTDIR}${DOCDIR}/${DIR}
${INSTALL} ${COPY} ${DOC_INSTALL_OWN} -m ${DOCMODE} \
Makefile ${FILES} ${EXTRA} ${DESTDIR}${DOCDIR}/${DIR}
.endif
spell: ${SRCS}
spell ${SRCS} | sort | comm -23 - spell.ok > paper.spell
.if !empty(DOCOWN)
DOC_INSTALL_OWN?= -o ${DOCOWN} -g ${DOCGRP}
.endif
.endif

View File

@ -0,0 +1,339 @@
# $Id: dpadd.mk,v 1.1.1.1 2020/05/24 05:35:53 nia 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
#
##
# DESCRIPTION:
# This makefile manages a number of variables that simplify
# dealing with libs in a build.
#
# Primary inputs are DPLIBS, DPADD and SRC_LIBS:
#
# DPLIBS
# List of LIB* that we will actually link with
# should be in correct link order.
# DPLIBS is a short-cut to ensure that DPADD and LDADD are
# kept in sync.
#
# DPADD List of LIB* that should already be built.
#
# SRC_LIBS
# List of LIB* that we want headers from, we do *not*
# require that such libs have been built.
#
# The above all get added to DPMAGIC_LIBS which is what we
# process.
#
# We expect LIB* to be set to absolute path of a library -
# suitable for putting in DPADD.
# eg.
#
# LIBC ?= ${OBJTOP}/lib/libc/libc.a
#
# From such a path we can derrive a number of other variables
# for which we can supply sensible default values.
# We name all these variables for the basename of the library
# (libc in our example above -- ${__lib:T:R} in below):
#
# LDADD_${__lib:T:R}:
# What should be added to LDADD (eg -lc)
#
# OBJ_${__lib:T:R}:
# This is trivial - just the dirname of the built library.
#
# SRC_${__lib:T:R}:
# Where the src for ${__lib} is, if LIB* is set as above
# we can simply substitute ${SRCTOP} for ${OBJTOP} in
# the dirname.
#
# INCLUDES_${__lib:T:R}:
# What should be added to CFLAGS
#
# If the directory ${SRC_${__lib:T:R}}/h exists we will
# only add -I${SRC_${__lib:T:R}}/h on the basis that
# this is where the public api is kept.
#
# Otherwise default will be -I${OBJ_${__lib:T:R}}
# -I${SRC_${__lib:T:R}}
#
# Note much of the above is skipped for staged libs
# eg.
# LIBC ?= ${STAGE_OBJTOP}/usr/lib/libc.a
#
# Since we can safely assume that -I${STAGE_OBJTOP}/usr/include
# and -L${STAGE_OBJTOP}/usr/lib are sufficient, and we should
# have no need of anything else.
#
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
# sometimes we play games with .CURDIR etc
# _* hold the original values of .*
_OBJDIR?= ${.OBJDIR}
_CURDIR?= ${.CURDIR}
.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}
# we get included just about everywhere so this is handy...
# C*DEBUG_XTRA are for defining on cmd line etc
# so do not use in makefiles.
.ifdef CFLAGS_DEBUG_XTRA
CFLAGS_LAST += ${CFLAGS_DEBUG_XTRA}
.endif
.ifdef CXXFLAGS_DEBUG_XTRA
CXXFLAGS_LAST += ${CXXFLAGS_DEBUG_XTRA}
.endif
.-include <local.dpadd.mk>
# DPLIBS helps us ensure we keep DPADD and LDADD in sync
DPLIBS+= ${DPLIBS_LAST}
DPADD+= ${DPLIBS:N-*}
.for __lib in ${DPLIBS}
.if "${__lib:M-*}" != ""
LDADD += ${__lib}
.else
LDADD += ${LDADD_${__lib:T:R}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
.endif
.endfor
# DPADD can contain things other than libs
__dpadd_libs := ${DPADD:M*/lib*}
.if defined(PROG) && ${MK_PROG_LDORDER_MK:Uno} != "no"
# some libs have dependencies...
# DPLIBS_* allows bsd.libnames.mk to flag libs which must be included
# in DPADD for a given library.
# Gather all such dependencies into __ldadd_all_xtras
# dups will be dealt with later.
# Note: libfoo_pic uses DPLIBS_libfoo
__ldadd_all_xtras=
.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R:S,_pic,,}}@}
__ldadd_all_xtras+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
.if "${DPADD:M${__lib}}" == ""
DPADD+= ${__lib}
.endif
.endfor
.endif
# Last of all... for libc and libgcc
DPADD+= ${DPADD_LAST}
# de-dupuplicate __ldadd_all_xtras into __ldadd_xtras
# in reverse order so that libs end up listed after all that needed them.
__ldadd_xtras=
.for __lib in ${__ldadd_all_xtras:[-1..1]}
.if "${__ldadd_xtras:M${__lib}}" == "" || ${NEED_IMPLICIT_LDADD:tl:Uno} != "no"
__ldadd_xtras+= ${__lib}
.endif
.endfor
.if !empty(__ldadd_xtras)
# now back to the original order
__ldadd_xtras:= ${__ldadd_xtras:[-1..1]}
LDADD+= ${__ldadd_xtras}
.endif
# 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.
# update this
__dpadd_libs := ${DPADD:M*/lib*}
# Order -L's to search 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}/*:N-L${HOST_LIBDIR:U/usr/lib}}
.if defined(HOST_LIBDIR) && ${HOST_LIBDIR} != "/usr/lib"
LDADD+= -L${HOST_LIBDIR}
.endif
.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 library 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 library name available, so stick to that.
#
SRC_LIBS?=
# magic_libs includes those we want to link with
# as well as those we might look at
__dpadd_magic_libs += ${__dpadd_libs} ${SRC_LIBS}
DPMAGIC_LIBS += ${__dpadd_magic_libs} \
${__dpadd_magic_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@}
# we skip this for staged libs
.for __lib in ${DPMAGIC_LIBS:O:u:N${STAGE_OBJTOP:Unot}*/lib/*}
#
# 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
# even for staged libs we sometimes
# need to allow direct -I to avoid cicular dependencies
.for __lib in ${DPMAGIC_LIBS:O:u:T:R}
.if !empty(SRC_${__lib}) && empty(INCLUDES_${__lib})
# must be a staged lib
.if exists(${SRC_${__lib}}/h)
INCLUDES_${__lib} = -I${SRC_${__lib}}/h
.else
INCLUDES_${__lib} = -I${SRC_${__lib}}
.endif
.endif
.endfor
# when linking a shared lib, avoid non pic libs
SHLDADD+= ${LDADD:N-[lL]*}
.for __lib in ${__dpadd_libs:u}
.if defined(SHLIB_NAME) && ${LDADD:M-l${__lib:T:R:S,lib,,}} != ""
.if ${__lib:T:N*_pic.a:N*.so} == "" || exists(${__lib:R}.so)
SHLDADD+= -l${__lib:T:R:S,lib,,}
.elif exists(${__lib:R}_pic.a)
SHLDADD+= -l${__lib:T:R:S,lib,,}_pic
.else
.warning ${RELDIR}.${TARGET_SPEC} needs ${__lib:T:R}_pic.a
SHLDADD+= -l${__lib:T:R:S,lib,,}
.endif
SHLDADD+= -L${__lib:H}
.endif
.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
.endfor
#
# We take care of duplicate suppression later.
# don't apply :T:R too early
__dpadd_incs += ${__dpadd_magic_libs:u:@x@${INCLUDES_${x:T:R}}@}
__dpadd_incs += ${__dpadd_magic_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_${x:T:R}}@}
__dpadd_last_incs += ${__dpadd_magic_libs:u:@x@${INCLUDES_LAST_${x:T:R}}@}
__dpadd_last_incs += ${__dpadd_magic_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_LAST_${x:T:R}}@}
.if defined(HOSTPROG) || ${MACHINE:Nhost*} == ""
# we want any -I/usr/* last
__dpadd_last_incs := \
${__dpadd_last_incs:N-I/usr/*} \
${__dpadd_incs:M-I/usr/*} \
${__dpadd_last_incs:M-I/usr/*}
__dpadd_incs := ${__dpadd_incs:N-I/usr/*}
.endif
#
# 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
.for t in CFLAGS_LAST CXXFLAGS_LAST
# avoid duplicates
__$t_incs:=${$t:M-I*:u}
.for i in ${__dpadd_last_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*)
.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
# after all that, if doing -n we don't care
.if ${.MAKEFLAGS:Ux:M-n} != ""
DPADD =
.elif ${.MAKE.MODE:Mmeta*} != "" && exists(${.MAKE.DEPENDFILE})
DPADD_CLEAR_DPADD ?= yes
.if ${DPADD_CLEAR_DPADD} == "yes"
# save this
__dpadd_libs := ${__dpadd_libs}
# we have made what use of it we can of DPADD
DPADD =
.endif
.endif
.endif

Some files were not shown because too many files have changed in this diff Show More