Import bmake-20150418

This commit is contained in:
Simon J. Gerraty 2015-04-20 03:45:54 +00:00
parent 769742d3af
commit 023e89e5ef
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/NetBSD/bmake/dist/; revision=281760
svn path=/vendor/NetBSD/bmake/20150418/; revision=281761; tag=vendor/NetBSD/bmake/20150418
116 changed files with 3122 additions and 922 deletions

View File

@ -1,8 +1,76 @@
2015-04-18 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150418
Merge with NetBSD make, pick up
o job.c: use memmove() rather than memcpy()
* unit-tests/varshell.mk: SunOS cannot handle the TERMINATED_BY_SIGNAL
case, so skip it.
2015-04-11 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150411
bump version - only mk/ changes.
2015-04-10 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150410
Merge with NetBSD make, pick up
o document different handling of '-' in jobs mode vs compat
o fix jobs mode so that '-' only applies to whole job
when shell lacks hasErrCtl
o meta.c: use separate vars to track lcwd and latestdir (read)
per process
2015-04-01 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150401
Merge with NetBSD make, pick up
o meta.c: close meta file in child
* Makefile: use BINDIR.bmake if set.
Same for MANDIR and SHAREDIR
Handy for testing release candidates
in various environments.
2015-03-26 Simon J. Gerraty <sjg@bad.crufty.net>
* move initialization of savederr to block where it is used
to avoid spurious warning from gcc5
2014-11-11 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20141111
just a cooler number
2014-11-05 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20141105
Merge with NetBSD make, pick up
o revert major overhaul of suffix handling
and POSIX compliance - too much breakage
and impossible to make backwards compatible.
o we still have the new unit test structure which is ok.
o meta.c ensure "-- filemon" is at start of line.
2014-09-17 Simon J. Gerraty <sjg@bad.crufty.net>
* configure.in: test that result of getconf PATH_MAX is numeric
and discard if not. Apparently needed for Hurd.
2014-08-30 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20140830
Merge with NetBSD make, pick up
o major overhaul of suffix handling
o improved POSIX compliance
o overhauled unit-tests
2014-06-20 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20140620
Merge with NetBSD make, pick up
o var.c return varNoError rather than var_Error for ::= modidiers.
o var.c return varNoError rather than var_Error for ::= modifiers.
2014-05-22 Simon J. Gerraty <sjg@bad.crufty.net>

97
FILES
View File

@ -92,35 +92,74 @@ targ.c
trace.c
trace.h
unit-tests/Makefile.in
unit-tests/comment
unit-tests/cond1
unit-tests/doterror
unit-tests/dotwait
unit-tests/error
unit-tests/export
unit-tests/export-all
unit-tests/export-env
unit-tests/forloop
unit-tests/forsubst
unit-tests/hash
unit-tests/misc
unit-tests/moderrs
unit-tests/modmatch
unit-tests/modmisc
unit-tests/modorder
unit-tests/modts
unit-tests/modword
unit-tests/order
unit-tests/phony-end
unit-tests/posix
unit-tests/qequals
unit-tests/sunshcmd
unit-tests/sysv
unit-tests/ternary
unit-tests/test.exp
unit-tests/unexport
unit-tests/unexport-env
unit-tests/varcmd
unit-tests/comment.exp
unit-tests/comment.mk
unit-tests/cond1.exp
unit-tests/cond1.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/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/varshell.exp
unit-tests/varshell.mk
util.c
var.c
wait.h

View File

@ -1,7 +1,7 @@
# $Id: Makefile,v 1.27 2014/06/20 14:51:54 sjg Exp $
# $Id: Makefile,v 1.36 2015/04/18 19:58:53 sjg Exp $
# Base version on src date
MAKE_VERSION= 20140620
MAKE_VERSION= 20150418
PROG= bmake
@ -180,9 +180,9 @@ COPTS.parse.c += -Wno-format-nonliteral
COPTS.var.c += -Wno-format-nonliteral
# Force these
SHAREDIR= ${prefix}/share
BINDIR= ${prefix}/bin
MANDIR= ${SHAREDIR}/man
SHAREDIR= ${SHAREDIR.bmake:U${prefix}/share}
BINDIR= ${BINDIR.bmake:U${prefix}/bin}
MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
.if !exists(.depend)
${OBJS}: config.h

View File

@ -1,8 +1,10 @@
# $NetBSD: Makefile,v 1.2 1995/06/14 15:20:23 christos Exp $
# $NetBSD: Makefile,v 1.4 2014/07/05 19:22:43 dholland Exp $
# @(#)Makefile 8.1 (Berkeley) 8/14/93
DIR= psd/12.make
SECTION=reference/ref1
ARTICLE=make
SRCS= tutorial.ms
MACROS= -ms
EXTRAHTMLFILES=make1.png make2.png
.include <bsd.doc.mk>

View File

@ -1,4 +1,4 @@
.\" $NetBSD: tutorial.ms,v 1.11 2011/08/18 15:19:30 sjg Exp $
.\" $NetBSD: tutorial.ms,v 1.12 2014/09/30 21:33:14 christos Exp $
.\" Copyright (c) 1988, 1989, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@ -67,6 +67,16 @@
.\"
.EH 'PSD:12-%''PMake \*- A Tutorial'
.OH 'PMake \*- A Tutorial''PSD:12-%'
.\" Ix is an indexing macro similar to .IX but I've disabled it for now
.\" Since that would require 2 passes and I am not in the mood for that.
.de Ix
..
.\" Rd is section (region) define and Rm is region mention? Again disable for
.\" now.
.de Rd
..
.de Rm
..
.\" xH is a macro to provide numbered headers that are automatically stuffed
.\" into a table-of-contents, properly indented, etc. If the first argument
.\" is numeric, it is taken as the depth for numbering (as for .NH), else

222
bmake.1
View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.229 2014/01/19 10:23:29 apb Exp $
.\" $NetBSD: make.1,v 1.247 2015/04/10 08:43:32 wiz Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
.Dd February 14, 2014
.Dd April 9, 2015
.Dt MAKE 1
.Os
.Sh NAME
@ -209,8 +209,6 @@ Force the
option to print raw values of variables.
.It Ar v
Print debugging information about variable assignment.
.It Ar w
Print entering and leaving directory messages, pre and post processing.
.It Ar x
Run shell commands with
.Fl x
@ -352,6 +350,8 @@ contains a
then the value will be expanded before printing.
.It Fl W
Treat any warnings during makefile parsing as errors.
.It Fl w
Print entering and leaving directory messages, pre and post processing.
.It Fl X
Don't export variables passed on the command line to the environment
individually.
@ -441,17 +441,29 @@ The value
need not necessarily be used to describe existing files.
Expansion is in directory order, not alphabetically as done in the shell.
.Sh SHELL COMMANDS
Each target may have associated with it a series of shell commands, normally
Each target may have associated with it one or more lines of shell
commands, normally
used to create the target.
Each of the commands in this script
Each of the lines in this script
.Em must
be preceded by a tab.
While any target may appear on a dependency line, only one of these
dependencies may be followed by a creation script, unless the
(For historical reasons, spaces are not accepted.)
While targets can appear in many dependency lines if desired, by
default only one of these rules may be followed by a creation
script.
If the
.Ql Ic \&::
operator is used.
operator is used, however, all rules may include scripts and the
scripts are executed in the order found.
.Pp
If the first characters of the command line are any combination of
Each line is treated as a separate shell command, unless the end of
line is escaped with a backslash
.Pq Ql \e
in which case that line and the next are combined.
.\" The escaped newline is retained and passed to the shell, which
.\" normally ignores it.
.\" However, the tab at the beginning of the following line is removed.
If the first characters of the command are any combination of
.Ql Ic @ ,
.Ql Ic + ,
or
@ -469,6 +481,7 @@ This is similar to the effect of the .MAKE special source,
except that the effect can be limited to a single line of a script.
A
.Ql Ic \-
in compatibility mode
causes any non-zero exit status of the command line to be ignored.
.Pp
When
@ -477,13 +490,45 @@ is run in jobs mode with
.Fl j Ar max_jobs ,
the entire script for the target is fed to a
single instance of the shell.
.Pp
In compatibility (non-jobs) mode, each command is run in a separate process.
If the command contains any shell meta characters
.Pq Ql #=|^(){};&<>*?[]:$`\e\en
it will be passed to the shell, otherwise
it will be passed to the shell; otherwise
.Nm
will attempt direct execution.
If a line starts with
.Ql Ic \-
and the shell has ErrCtl enabled then failure of the command line
will be ignored as in compatibility mode.
Otherwise
.Ql Ic \-
affects the entire job;
the script will stop at the first command line that fails,
but the target will not be deemed to have failed.
.Pp
Makefiles should be written so that the mode of
.Nm
operation does not change their behavior.
For example, any command which needs to use
.Dq cd
or
.Dq chdir
without potentially changing the directory for subsequent commands
should be put in parentheses so it executes in a subshell.
To force the use of one shell, escape the line breaks so as to make
the whole script one command.
For example:
.Bd -literal -offset indent
avoid-chdir-side-effects:
@echo Building $@ in `pwd`
@(cd ${.CURDIR} && ${MAKE} $@)
@echo Back in `pwd`
ensure-one-shell-regardless-of-mode:
@echo Building $@ in `pwd`; \e
(cd ${.CURDIR} && ${MAKE} $@); \e
echo Back in `pwd`
.Ed
.Pp
Since
.Nm
@ -493,27 +538,6 @@ to
.Ql Va .OBJDIR
before executing any targets, each child process
starts with that as its current working directory.
.Pp
Makefiles should be written so that the mode of
.Nm
operation does not change their behavior.
For example, any command which needs to use
.Dq cd
or
.Dq chdir ,
without side-effect should be put in parenthesis:
.Bd -literal -offset indent
avoid-chdir-side-effects:
@echo Building $@ in `pwd`
@(cd ${.CURDIR} && ${.MAKE} $@)
@echo Back in `pwd`
ensure-one-shell-regardless-of-mode:
@echo Building $@ in `pwd`; \\
(cd ${.CURDIR} && ${.MAKE} $@); \\
echo Back in `pwd`
.Ed
.Sh VARIABLE ASSIGNMENTS
Variables in make are much like variables in the shell, and, by tradition,
consist of all upper-case letters.
@ -624,13 +648,19 @@ Variables defined in the makefile or in included makefiles.
Variables defined as part of the command line.
.It Local variables
Variables that are defined specific to a certain target.
.El
.Pp
Local variables are all built in and their values vary magically from
target to target.
It is not currently possible to define new local variables.
The seven local variables are as follows:
.Bl -tag -width ".ARCHIVE"
.Bl -tag -width ".ARCHIVE" -offset indent
.It Va .ALLSRC
The list of all sources for this target; also known as
.Ql Va \&\*[Gt] .
.It Va .ARCHIVE
The name of the archive file.
The name of the archive file; also known as
.Ql Va \&! .
.It Va .IMPSRC
In suffix-transformation rules, the name/path of the source from which the
target is to be transformed (the
@ -639,7 +669,8 @@ source); also known as
.Ql Va \&\*[Lt] .
It is not defined in explicit rules.
.It Va .MEMBER
The name of the archive member.
The name of the archive member; also known as
.Ql Va % .
.It Va .OODATE
The list of sources for this target that were deemed out-of-date; also
known as
@ -648,31 +679,41 @@ known as
The file prefix of the target, containing only the file portion, no suffix
or preceding directory components; also known as
.Ql Va * .
The suffix must be one of the known suffixes declared with
.Ic .SUFFIXES
or it will not be recognized.
.It Va .TARGET
The name of the target; also known as
.Ql Va @ .
.El
.Pp
The shorter forms
.Ql Va @ ,
.Ql ( Va \*[Gt] ,
.Ql Va \&! ,
.Ql Va \*[Lt] ,
.Ql Va % ,
.Ql Va \&? ,
.Ql Va \&\*[Lt] ,
.Ql Va \&\*[Gt] ,
.Ql Va * ,
and
.Ql Va *
.Ql Va @ )
are permitted for backward
compatibility with historical makefiles and are not recommended.
The six variables
.Ql Va "@F" ,
.Ql Va "@D" ,
.Ql Va "\*[Lt]F" ,
.Ql Va "\*[Lt]D" ,
.Ql Va "*F" ,
compatibility with historical makefiles and legacy POSIX make and are
not recommended.
.Pp
Variants of these variables with the punctuation followed immediately by
.Ql D
or
.Ql F ,
e.g.
.Ql Va $(@D) ,
are legacy forms equivalent to using the
.Ql :H
and
.Ql Va "*D"
are permitted for compatibility with
.Ql :T
modifiers.
These forms are accepted for compatibility with
.At V
makefiles and are not recommended.
makefiles and POSIX but are not recommended.
.Pp
Four of the local variables may be used in sources on dependency lines
because they expand to the proper value for each target on the line.
@ -682,7 +723,6 @@ These variables are
.Ql Va .ARCHIVE ,
and
.Ql Va .MEMBER .
.El
.Ss Additional built-in variables
In addition,
.Nm
@ -2119,19 +2159,87 @@ system makefile
system makefile directory
.El
.Sh COMPATIBILITY
The basic make syntax is compatible between different versions of make,
The basic make syntax is compatible between different versions of make;
however the special variables, variable modifiers and conditionals are not.
.Pp
The way that parallel makes are scheduled changed in
NetBSD 4.0
so that .ORDER and .WAIT apply recursively to the dependent nodes.
The algorithms used may change again in the future.
.Ss Older versions
An incomplete list of changes in older versions of
.Nm :
.Pp
The way that .for loop variables are substituted changed after
NetBSD 5.0
so that they still appear to be variable expansions.
In particular this stops them being treated as syntax, and removes some
obscure problems using them in .if statements.
.Pp
The way that parallel makes are scheduled changed in
NetBSD 4.0
so that .ORDER and .WAIT apply recursively to the dependent nodes.
The algorithms used may change again in the future.
.Ss Other make dialects
Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not
support most of the features of
.Nm
as described in this manual.
Most notably:
.Bl -bullet -offset indent
.It
The
.Ic .WAIT
and
.Ic .ORDER
declarations and most functionality pertaining to parallelization.
(GNU make supports parallelization but lacks these features needed to
control it effectively.)
.It
Directives, including for loops and conditionals and most of the
forms of include files.
(GNU make has its own incompatible and less powerful syntax for
conditionals.)
.It
All built-in variables that begin with a dot.
.It
Most of the special sources and targets that begin with a dot,
with the notable exception of
.Ic .PHONY ,
.Ic .PRECIOUS ,
and
.Ic .SUFFIXES .
.It
Variable modifiers, except for the
.Dl :old=new
string substitution, which does not portably support globbing with
.Ql %
and historically only works on declared suffixes.
.It
The
.Ic $>
variable even in its short form; most makes support this functionality
but its name varies.
.El
.Pp
Some features are somewhat more portable, such as assignment with
.Ic += ,
.Ic ?= ,
and
.Ic != .
The
.Ic .PATH
functionality is based on an older feature
.Ic VPATH
found in GNU make and many versions of SVR4 make; however,
historically its behavior is too ill-defined (and too buggy) to rely
upon.
.Pp
The
.Ic $@
and
.Ic $<
variables are more or less universally portable, as is the
.Ic $(MAKE)
variable.
Basic use of suffix rules (for files only in the current directory,
not trying to chain transformations together, etc.) is also reasonably
portable.
.Sh SEE ALSO
.Xr mkdep 1
.Sh HISTORY

View File

@ -122,9 +122,6 @@ DDEESSCCRRIIPPTTIIOONN
_v Print debugging information about variable assignment.
_w Print entering and leaving directory messages, pre and
post processing.
_x Run shell commands with --xx so the actual commands are
printed as they are executed.
@ -221,6 +218,9 @@ DDEESSCCRRIIPPTTIIOONN
--WW Treat any warnings during makefile parsing as errors.
--ww Print entering and leaving directory messages, pre and post pro-
cessing.
--XX Don't export variables passed on the command line to the environ-
ment individually. Variables passed on the command line are
still exported via the _M_A_K_E_F_L_A_G_S environment variable. This
@ -273,46 +273,55 @@ FFIILLEE DDEEPPEENNDDEENNCCYY SSPPEECCIIFFIICCAATTIIOO
done in the shell.
SSHHEELLLL CCOOMMMMAANNDDSS
Each target may have associated with it a series of shell commands, nor-
mally used to create the target. Each of the commands in this script
_m_u_s_t be preceded by a tab. While any target may appear on a dependency
line, only one of these dependencies may be followed by a creation
script, unless the `::::' operator is used.
Each target may have associated with it one or more lines of shell com-
mands, normally used to create the target. Each of the lines in this
script _m_u_s_t be preceded by a tab. (For historical reasons, spaces are
not accepted.) While targets can appear in many dependency lines if
desired, by default only one of these rules may be followed by a creation
script. If the `::::' operator is used, however, all rules may include
scripts and the scripts are executed in the order found.
If the first characters of the command line are any combination of `@@',
`++', or `--', the command is treated specially. A `@@' causes the command
not to be echoed before it is executed. A `++' causes the command to be
executed even when --nn is given. This is similar to the effect of the
.MAKE special source, except that the effect can be limited to a single
line of a script. A `--' causes any non-zero exit status of the command
line to be ignored.
Each line is treated as a separate shell command, unless the end of line
is escaped with a backslash (`\') in which case that line and the next
are combined. If the first characters of the command are any combination
of `@@', `++', or `--', the command is treated specially. A `@@' causes the
command not to be echoed before it is executed. A `++' causes the command
to be executed even when --nn is given. This is similar to the effect of
the .MAKE special source, except that the effect can be limited to a sin-
gle line of a script. A `--' in compatibility mode causes any non-zero
exit status of the command line to be ignored.
When bbmmaakkee is run in jobs mode with --jj _m_a_x___j_o_b_s, the entire script for
the target is fed to a single instance of the shell.
In compatibility (non-jobs) mode, each command is run in a separate
process. If the command contains any shell meta characters
(`#=|^(){};&<>*?[]:$`\\n') it will be passed to the shell, otherwise
bbmmaakkee will attempt direct execution.
Since bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' before executing any targets, each
child process starts with that as its current working directory.
the target is fed to a single instance of the shell. In compatibility
(non-jobs) mode, each command is run in a separate process. If the com-
mand contains any shell meta characters (`#=|^(){};&<>*?[]:$`\\n') it
will be passed to the shell; otherwise bbmmaakkee will attempt direct execu-
tion. If a line starts with `--' and the shell has ErrCtl enabled then
failure of the command line will be ignored as in compatibility mode.
Otherwise `--' affects the entire job; the script will stop at the first
command line that fails, but the target will not be deemed to have
failed.
Makefiles should be written so that the mode of bbmmaakkee operation does not
change their behavior. For example, any command which needs to use
``cd'' or ``chdir'', without side-effect should be put in parenthesis:
``cd'' or ``chdir'' without potentially changing the directory for subse-
quent commands should be put in parentheses so it executes in a subshell.
To force the use of one shell, escape the line breaks so as to make the
whole script one command. For example:
avoid-chdir-side-effects:
@echo Building $@ in `pwd`
@(cd ${.CURDIR} && ${.MAKE} $@)
@(cd ${.CURDIR} && ${MAKE} $@)
@echo Back in `pwd`
ensure-one-shell-regardless-of-mode:
@echo Building $@ in `pwd`; \
(cd ${.CURDIR} && ${.MAKE} $@); \
(cd ${.CURDIR} && ${MAKE} $@); \
echo Back in `pwd`
Since bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' before executing any targets, each
child process starts with that as its current working directory.
VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS
Variables in make are much like variables in the shell, and, by tradi-
tion, consist of all upper-case letters.
@ -402,40 +411,47 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS
Variables defined as part of the command line.
Local variables
Variables that are defined specific to a certain target. The
seven local variables are as follows:
Variables that are defined specific to a certain target.
_._A_L_L_S_R_C The list of all sources for this target; also known as
`_>'.
Local variables are all built in and their values vary magically from
target to target. It is not currently possible to define new local vari-
ables. The seven local variables are as follows:
_._A_R_C_H_I_V_E The name of the archive file.
_._A_L_L_S_R_C The list of all sources for this target; also known as
`_>'.
_._I_M_P_S_R_C In suffix-transformation rules, the name/path of the
source from which the target is to be transformed (the
``implied'' source); also known as `_<'. It is not
defined in explicit rules.
_._A_R_C_H_I_V_E The name of the archive file; also known as `_!'.
_._M_E_M_B_E_R The name of the archive member.
_._I_M_P_S_R_C In suffix-transformation rules, the name/path of the
source from which the target is to be transformed (the
``implied'' source); also known as `_<'. It is not
defined in explicit rules.
_._O_O_D_A_T_E The list of sources for this target that were deemed
out-of-date; also known as `_?'.
_._M_E_M_B_E_R The name of the archive member; also known as `_%'.
_._P_R_E_F_I_X The file prefix of the target, containing only the file
portion, no suffix or preceding directory components;
also known as `_*'.
_._O_O_D_A_T_E The list of sources for this target that were deemed out-
of-date; also known as `_?'.
_._T_A_R_G_E_T The name of the target; also known as `_@'.
_._P_R_E_F_I_X The file prefix of the target, containing only the file
portion, no suffix or preceding directory components;
also known as `_*'. The suffix must be one of the known
suffixes declared with ..SSUUFFFFIIXXEESS or it will not be recog-
nized.
The shorter forms `_@', `_?', `_<', `_>', and `_*' are permitted for
backward compatibility with historical makefiles and are not rec-
ommended. The six variables `_@_F', `_@_D', `_<_F', `_<_D', `_*_F', and
`_*_D' are permitted for compatibility with AT&T System V UNIX
makefiles and are not recommended.
_._T_A_R_G_E_T The name of the target; also known as `_@'.
Four of the local variables may be used in sources on dependency
lines because they expand to the proper value for each target on
the line. These variables are `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E',
and `_._M_E_M_B_E_R'.
The shorter forms (`_>', `_!', `_<', `_%', `_?', `_*', and `_@') are permitted
for backward compatibility with historical makefiles and legacy POSIX
make and are not recommended.
Variants of these variables with the punctuation followed immediately by
`D' or `F', e.g. `_$_(_@_D_)', are legacy forms equivalent to using the `:H'
and `:T' modifiers. These forms are accepted for compatibility with AT&T
System V UNIX makefiles and POSIX but are not recommended.
Four of the local variables may be used in sources on dependency lines
because they expand to the proper value for each target on the line.
These variables are `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E', and `_._M_E_M_B_E_R'.
AAddddiittiioonnaall bbuuiilltt--iinn vvaarriiaabblleess
In addition, bbmmaakkee sets or knows about the following variables:
@ -1356,19 +1372,58 @@ FFIILLEESS
/usr/share/mk system makefile directory
CCOOMMPPAATTIIBBIILLIITTYY
The basic make syntax is compatible between different versions of make,
The basic make syntax is compatible between different versions of make;
however the special variables, variable modifiers and conditionals are
not.
The way that parallel makes are scheduled changed in NetBSD 4.0 so that
.ORDER and .WAIT apply recursively to the dependent nodes. The algo-
rithms used may change again in the future.
OOllddeerr vveerrssiioonnss
An incomplete list of changes in older versions of bbmmaakkee:
The way that .for loop variables are substituted changed after NetBSD 5.0
so that they still appear to be variable expansions. In particular this
stops them being treated as syntax, and removes some obscure problems
using them in .if statements.
The way that parallel makes are scheduled changed in NetBSD 4.0 so that
.ORDER and .WAIT apply recursively to the dependent nodes. The algo-
rithms used may change again in the future.
OOtthheerr mmaakkee ddiiaalleeccttss
Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not sup-
port most of the features of bbmmaakkee as described in this manual. Most
notably:
++oo The ..WWAAIITT and ..OORRDDEERR declarations and most functionality per-
taining to parallelization. (GNU make supports parallelization
but lacks these features needed to control it effectively.)
++oo Directives, including for loops and conditionals and most of
the forms of include files. (GNU make has its own incompatible
and less powerful syntax for conditionals.)
++oo All built-in variables that begin with a dot.
++oo Most of the special sources and targets that begin with a dot,
with the notable exception of ..PPHHOONNYY, ..PPRREECCIIOOUUSS, and ..SSUUFFFFIIXXEESS.
++oo Variable modifiers, except for the
:old=new
string substitution, which does not portably support globbing
with `%' and historically only works on declared suffixes.
++oo The $$>> variable even in its short form; most makes support this
functionality but its name varies.
Some features are somewhat more portable, such as assignment with ++==, ??==,
and !!==. The ..PPAATTHH functionality is based on an older feature VVPPAATTHH found
in GNU make and many versions of SVR4 make; however, historically its
behavior is too ill-defined (and too buggy) to rely upon.
The $$@@ and $$<< variables are more or less universally portable, as is the
$$((MMAAKKEE)) variable. Basic use of suffix rules (for files only in the cur-
rent directory, not trying to chain transformations together, etc.) is
also reasonably portable.
SSEEEE AALLSSOO
mkdep(1)
@ -1394,4 +1449,4 @@ BBUUGGSS
There is no way of escaping a space character in a filename.
NetBSD 5.1 February 14, 2014 NetBSD 5.1
NetBSD 5.1 April 9, 2015 NetBSD 5.1

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.94 2014/01/03 00:02:01 sjg Exp $ */
/* $NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: compat.c,v 1.94 2014/01/03 00:02:01 sjg Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg 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.94 2014/01/03 00:02:01 sjg Exp $");
__RCSID("$NetBSD: compat.c,v 1.96 2014/09/07 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif

2
configure vendored
View File

@ -4247,6 +4247,8 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
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

View File

@ -1,6 +1,6 @@
dnl
dnl RCSid:
dnl $Id: configure.in,v 1.52 2014/02/15 22:27:59 sjg Exp $
dnl $Id: configure.in,v 1.53 2014/11/06 01:49:40 sjg Exp $
dnl
dnl Process this file with autoconf to produce a configure script
dnl
@ -82,6 +82,8 @@ 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

26
job.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $ */
/* $NetBSD: job.c,v 1.180 2015/04/16 13:31:03 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.180 2015/04/16 13:31:03 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.176 2013/08/04 16:48:15 sjg Exp $");
__RCSID("$NetBSD: job.c,v 1.180 2015/04/16 13:31:03 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -728,7 +728,6 @@ JobPrintCommand(void *cmdp, void *jobp)
shutUp = DEBUG(LOUD) ? FALSE : TRUE;
break;
case '-':
job->flags |= JOB_IGNERR;
errOff = TRUE;
break;
case '+':
@ -807,6 +806,7 @@ JobPrintCommand(void *cmdp, void *jobp)
* to ignore errors. Set cmdTemplate to use the weirdness
* instead of the simple "%s\n" template.
*/
job->flags |= JOB_IGNERR;
if (!(job->flags & JOB_SILENT) && !shutUp) {
if (commandShell->hasEchoCtl) {
DBPRINTF("%s\n", commandShell->echoOff);
@ -1360,7 +1360,7 @@ JobExec(Job *job, char **argv)
(void)fcntl(0, F_SETFD, 0);
(void)lseek(0, (off_t)0, SEEK_SET);
if (job->node->type & OP_MAKE) {
if (job->node->type & (OP_MAKE | OP_SUBMAKE)) {
/*
* Pass job token pipe to submakes.
*/
@ -1894,16 +1894,16 @@ JobDoOutput(Job *job, Boolean finish)
(void)fflush(stdout);
}
}
if (i < max - 1) {
/* shift the remaining characters down */
(void)memcpy(job->outBuf, &job->outBuf[i + 1], max - (i + 1));
/*
* max is the last offset still in the buffer. Move any remaining
* characters to the start of the buffer and update the end marker
* curPos.
*/
if (i < max) {
(void)memmove(job->outBuf, &job->outBuf[i + 1], max - (i + 1));
job->curPos = max - (i + 1);
} else {
/*
* We have written everything out, so we just start over
* from the start of the buffer. No copying. No nothing.
*/
assert(i == max);
job->curPos = 0;
}
}

2
lst.h
View File

@ -1,4 +1,4 @@
/* $NetBSD: lst.h,v 1.18 2009/01/23 21:58:27 dsl Exp $ */
/* $NetBSD: lst.h,v 1.20 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.

View File

@ -1,4 +1,4 @@
/* $NetBSD: lstInt.h,v 1.20 2009/01/24 14:43:29 dsl Exp $ */
/* $NetBSD: lstInt.h,v 1.22 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993

View File

@ -1,4 +1,4 @@
/* $NetBSD: lstRemove.c,v 1.14 2008/12/13 15:19:29 dsl Exp $ */
/* $NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -33,14 +33,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstRemove.c,v 1.14 2008/12/13 15:19:29 dsl Exp $";
static char rcsid[] = "$NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 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.14 2008/12/13 15:19:29 dsl Exp $");
__RCSID("$NetBSD: lstRemove.c,v 1.16 2014/09/07 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif

22
main.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $ */
/* $NetBSD: main.c,v 1.232 2015/03/26 22:20:42 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.232 2015/03/26 22:20:42 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $");
__RCSID("$NetBSD: main.c,v 1.232 2015/03/26 22:20:42 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -99,14 +99,14 @@ __RCSID("$NetBSD: main.c,v 1.226 2014/02/07 17:23:35 pooka Exp $");
*
* Error Print a tagged error message. The global
* MAKE variable must have been defined. This
* takes a format string and two optional
* arguments for it.
* takes a format string and optional arguments
* for it.
*
* Fatal Print an error message and exit. Also takes
* a format string and two arguments.
* a format string and arguments for it.
*
* Punt Aborts all jobs and exits with a message. Also
* takes a format string and two arguments.
* takes a format string and arguments for it.
*
* Finish Finish things up by printing the number of
* errors which occurred, as passed to it, and
@ -1522,7 +1522,8 @@ Cmd_Exec(const char *cmd, const char **errnum)
WAIT_T status; /* command exit status */
Buffer buf; /* buffer to store the result */
char *cp;
int cc;
int cc; /* bytes read, or -1 */
int savederr; /* saved errno */
*errnum = NULL;
@ -1579,6 +1580,7 @@ Cmd_Exec(const char *cmd, const char **errnum)
*/
(void)close(fds[1]);
savederr = 0;
Buf_Init(&buf, 0);
do {
@ -1588,6 +1590,8 @@ Cmd_Exec(const char *cmd, const char **errnum)
Buf_AddBytes(&buf, cc, result);
}
while (cc > 0 || (cc == -1 && errno == EINTR));
if (cc == -1)
savederr = errno;
/*
* Close the input side of the pipe.
@ -1604,7 +1608,7 @@ Cmd_Exec(const char *cmd, const char **errnum)
cc = Buf_Size(&buf);
res = Buf_Destroy(&buf, FALSE);
if (cc == 0)
if (savederr != 0)
*errnum = "Couldn't read shell's output for \"%s\"";
if (WIFSIGNALED(status))

222
make.1
View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.230 2014/02/15 18:55:30 sjg Exp $
.\" $NetBSD: make.1,v 1.247 2015/04/10 08:43:32 wiz Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
.Dd February 14, 2014
.Dd April 9, 2015
.Dt MAKE 1
.Os
.Sh NAME
@ -209,8 +209,6 @@ Force the
option to print raw values of variables.
.It Ar v
Print debugging information about variable assignment.
.It Ar w
Print entering and leaving directory messages, pre and post processing.
.It Ar x
Run shell commands with
.Fl x
@ -352,6 +350,8 @@ contains a
then the value will be expanded before printing.
.It Fl W
Treat any warnings during makefile parsing as errors.
.It Fl w
Print entering and leaving directory messages, pre and post processing.
.It Fl X
Don't export variables passed on the command line to the environment
individually.
@ -441,17 +441,29 @@ The value
need not necessarily be used to describe existing files.
Expansion is in directory order, not alphabetically as done in the shell.
.Sh SHELL COMMANDS
Each target may have associated with it a series of shell commands, normally
Each target may have associated with it one or more lines of shell
commands, normally
used to create the target.
Each of the commands in this script
Each of the lines in this script
.Em must
be preceded by a tab.
While any target may appear on a dependency line, only one of these
dependencies may be followed by a creation script, unless the
(For historical reasons, spaces are not accepted.)
While targets can appear in many dependency lines if desired, by
default only one of these rules may be followed by a creation
script.
If the
.Ql Ic \&::
operator is used.
operator is used, however, all rules may include scripts and the
scripts are executed in the order found.
.Pp
If the first characters of the command line are any combination of
Each line is treated as a separate shell command, unless the end of
line is escaped with a backslash
.Pq Ql \e
in which case that line and the next are combined.
.\" The escaped newline is retained and passed to the shell, which
.\" normally ignores it.
.\" However, the tab at the beginning of the following line is removed.
If the first characters of the command are any combination of
.Ql Ic @ ,
.Ql Ic + ,
or
@ -469,6 +481,7 @@ This is similar to the effect of the .MAKE special source,
except that the effect can be limited to a single line of a script.
A
.Ql Ic \-
in compatibility mode
causes any non-zero exit status of the command line to be ignored.
.Pp
When
@ -477,13 +490,45 @@ is run in jobs mode with
.Fl j Ar max_jobs ,
the entire script for the target is fed to a
single instance of the shell.
.Pp
In compatibility (non-jobs) mode, each command is run in a separate process.
If the command contains any shell meta characters
.Pq Ql #=|^(){};&<>*?[]:$`\e\en
it will be passed to the shell, otherwise
it will be passed to the shell; otherwise
.Nm
will attempt direct execution.
If a line starts with
.Ql Ic \-
and the shell has ErrCtl enabled then failure of the command line
will be ignored as in compatibility mode.
Otherwise
.Ql Ic \-
affects the entire job;
the script will stop at the first command line that fails,
but the target will not be deemed to have failed.
.Pp
Makefiles should be written so that the mode of
.Nm
operation does not change their behavior.
For example, any command which needs to use
.Dq cd
or
.Dq chdir
without potentially changing the directory for subsequent commands
should be put in parentheses so it executes in a subshell.
To force the use of one shell, escape the line breaks so as to make
the whole script one command.
For example:
.Bd -literal -offset indent
avoid-chdir-side-effects:
@echo Building $@ in `pwd`
@(cd ${.CURDIR} && ${MAKE} $@)
@echo Back in `pwd`
ensure-one-shell-regardless-of-mode:
@echo Building $@ in `pwd`; \e
(cd ${.CURDIR} && ${MAKE} $@); \e
echo Back in `pwd`
.Ed
.Pp
Since
.Nm
@ -493,27 +538,6 @@ to
.Ql Va .OBJDIR
before executing any targets, each child process
starts with that as its current working directory.
.Pp
Makefiles should be written so that the mode of
.Nm
operation does not change their behavior.
For example, any command which needs to use
.Dq cd
or
.Dq chdir ,
without side-effect should be put in parenthesis:
.Bd -literal -offset indent
avoid-chdir-side-effects:
@echo Building $@ in `pwd`
@(cd ${.CURDIR} && ${.MAKE} $@)
@echo Back in `pwd`
ensure-one-shell-regardless-of-mode:
@echo Building $@ in `pwd`; \\
(cd ${.CURDIR} && ${.MAKE} $@); \\
echo Back in `pwd`
.Ed
.Sh VARIABLE ASSIGNMENTS
Variables in make are much like variables in the shell, and, by tradition,
consist of all upper-case letters.
@ -624,13 +648,19 @@ Variables defined in the makefile or in included makefiles.
Variables defined as part of the command line.
.It Local variables
Variables that are defined specific to a certain target.
.El
.Pp
Local variables are all built in and their values vary magically from
target to target.
It is not currently possible to define new local variables.
The seven local variables are as follows:
.Bl -tag -width ".ARCHIVE"
.Bl -tag -width ".ARCHIVE" -offset indent
.It Va .ALLSRC
The list of all sources for this target; also known as
.Ql Va \&\*[Gt] .
.It Va .ARCHIVE
The name of the archive file.
The name of the archive file; also known as
.Ql Va \&! .
.It Va .IMPSRC
In suffix-transformation rules, the name/path of the source from which the
target is to be transformed (the
@ -639,7 +669,8 @@ source); also known as
.Ql Va \&\*[Lt] .
It is not defined in explicit rules.
.It Va .MEMBER
The name of the archive member.
The name of the archive member; also known as
.Ql Va % .
.It Va .OODATE
The list of sources for this target that were deemed out-of-date; also
known as
@ -648,31 +679,41 @@ known as
The file prefix of the target, containing only the file portion, no suffix
or preceding directory components; also known as
.Ql Va * .
The suffix must be one of the known suffixes declared with
.Ic .SUFFIXES
or it will not be recognized.
.It Va .TARGET
The name of the target; also known as
.Ql Va @ .
.El
.Pp
The shorter forms
.Ql Va @ ,
.Ql ( Va \*[Gt] ,
.Ql Va \&! ,
.Ql Va \*[Lt] ,
.Ql Va % ,
.Ql Va \&? ,
.Ql Va \&\*[Lt] ,
.Ql Va \&\*[Gt] ,
.Ql Va * ,
and
.Ql Va *
.Ql Va @ )
are permitted for backward
compatibility with historical makefiles and are not recommended.
The six variables
.Ql Va "@F" ,
.Ql Va "@D" ,
.Ql Va "\*[Lt]F" ,
.Ql Va "\*[Lt]D" ,
.Ql Va "*F" ,
compatibility with historical makefiles and legacy POSIX make and are
not recommended.
.Pp
Variants of these variables with the punctuation followed immediately by
.Ql D
or
.Ql F ,
e.g.
.Ql Va $(@D) ,
are legacy forms equivalent to using the
.Ql :H
and
.Ql Va "*D"
are permitted for compatibility with
.Ql :T
modifiers.
These forms are accepted for compatibility with
.At V
makefiles and are not recommended.
makefiles and POSIX but are not recommended.
.Pp
Four of the local variables may be used in sources on dependency lines
because they expand to the proper value for each target on the line.
@ -682,7 +723,6 @@ These variables are
.Ql Va .ARCHIVE ,
and
.Ql Va .MEMBER .
.El
.Ss Additional built-in variables
In addition,
.Nm
@ -2119,19 +2159,87 @@ system makefile
system makefile directory
.El
.Sh COMPATIBILITY
The basic make syntax is compatible between different versions of make,
The basic make syntax is compatible between different versions of make;
however the special variables, variable modifiers and conditionals are not.
.Pp
The way that parallel makes are scheduled changed in
.Nx 4.0
so that .ORDER and .WAIT apply recursively to the dependent nodes.
The algorithms used may change again in the future.
.Ss Older versions
An incomplete list of changes in older versions of
.Nm :
.Pp
The way that .for loop variables are substituted changed after
.Nx 5.0
so that they still appear to be variable expansions.
In particular this stops them being treated as syntax, and removes some
obscure problems using them in .if statements.
.Pp
The way that parallel makes are scheduled changed in
.Nx 4.0
so that .ORDER and .WAIT apply recursively to the dependent nodes.
The algorithms used may change again in the future.
.Ss Other make dialects
Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not
support most of the features of
.Nm
as described in this manual.
Most notably:
.Bl -bullet -offset indent
.It
The
.Ic .WAIT
and
.Ic .ORDER
declarations and most functionality pertaining to parallelization.
(GNU make supports parallelization but lacks these features needed to
control it effectively.)
.It
Directives, including for loops and conditionals and most of the
forms of include files.
(GNU make has its own incompatible and less powerful syntax for
conditionals.)
.It
All built-in variables that begin with a dot.
.It
Most of the special sources and targets that begin with a dot,
with the notable exception of
.Ic .PHONY ,
.Ic .PRECIOUS ,
and
.Ic .SUFFIXES .
.It
Variable modifiers, except for the
.Dl :old=new
string substitution, which does not portably support globbing with
.Ql %
and historically only works on declared suffixes.
.It
The
.Ic $>
variable even in its short form; most makes support this functionality
but its name varies.
.El
.Pp
Some features are somewhat more portable, such as assignment with
.Ic += ,
.Ic ?= ,
and
.Ic != .
The
.Ic .PATH
functionality is based on an older feature
.Ic VPATH
found in GNU make and many versions of SVR4 make; however,
historically its behavior is too ill-defined (and too buggy) to rely
upon.
.Pp
The
.Ic $@
and
.Ic $<
variables are more or less universally portable, as is the
.Ic $(MAKE)
variable.
Basic use of suffix rules (for files only in the current directory,
not trying to chain transformations together, etc.) is also reasonably
portable.
.Sh SEE ALSO
.Xr mkdep 1
.Sh HISTORY

8
make.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $ */
/* $NetBSD: make.c,v 1.91 2014/10/18 08:33:30 snj Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $";
static char rcsid[] = "$NetBSD: make.c,v 1.91 2014/10/18 08:33:30 snj Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: make.c,v 1.88 2012/11/09 18:53:05 sjg Exp $");
__RCSID("$NetBSD: make.c,v 1.91 2014/10/18 08:33:30 snj Exp $");
#endif
#endif /* not lint */
#endif
@ -563,7 +563,7 @@ MakeHandleUse(void *cgnp, void *pgnp)
* in the comments below.
*
* Results:
* returns 0 if the gnode does not exist, or it's filesystem
* returns 0 if the gnode does not exist, or its filesystem
* time if it does.
*
* Side Effects:

3
make.h
View File

@ -1,4 +1,4 @@
/* $NetBSD: make.h,v 1.92 2013/09/04 15:38:26 sjg Exp $ */
/* $NetBSD: make.h,v 1.95 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -289,6 +289,7 @@ typedef struct GNode {
#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 */

89
meta.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: meta.c,v 1.33 2013/10/01 05:37:17 sjg Exp $ */
/* $NetBSD: meta.c,v 1.38 2015/04/11 05:24:30 sjg Exp $ */
/*
* Implement 'meta' mode.
@ -155,8 +155,8 @@ filemon_open(BuildMon *pbm)
static void
filemon_read(FILE *mfp, int fd)
{
FILE *fp;
char buf[BUFSIZ];
int n;
/* Check if we're not writing to a meta data file.*/
if (mfp == NULL) {
@ -166,17 +166,14 @@ filemon_read(FILE *mfp, int fd)
}
/* rewind */
(void)lseek(fd, (off_t)0, SEEK_SET);
if ((fp = fdopen(fd, "r")) == NULL)
err(1, "Could not read build monitor file '%d'", fd);
fprintf(mfp, "-- filemon acquired metadata --\n");
fprintf(mfp, "\n-- filemon acquired metadata --\n");
while (fgets(buf, sizeof(buf), fp)) {
fprintf(mfp, "%s", buf);
while ((n = read(fd, buf, sizeof(buf))) > 0) {
fwrite(buf, 1, n, mfp);
}
fflush(mfp);
clearerr(fp);
fclose(fp);
close(fd);
}
#endif
@ -662,17 +659,21 @@ meta_job_child(Job *job)
{
#ifdef USE_FILEMON
BuildMon *pbm;
pid_t pid;
if (job != NULL) {
pbm = &job->bm;
} else {
pbm = &Mybm;
}
pid = getpid();
if (pbm->mfp != NULL && useFilemon) {
if (ioctl(pbm->filemon_fd, FILEMON_SET_PID, &pid) < 0) {
err(1, "Could not set filemon pid!");
if (pbm->mfp != NULL) {
close(fileno(pbm->mfp));
if (useFilemon) {
pid_t pid;
pid = getpid();
if (ioctl(pbm->filemon_fd, FILEMON_SET_PID, &pid) < 0) {
err(1, "Could not set filemon pid!");
}
}
}
#endif
@ -844,9 +845,10 @@ string_match(const void *p, const void *q)
/*
* When running with 'meta' functionality, a target can be out-of-date
* if any of the references in it's meta data file is more recent.
* if any of the references in its meta data file is more recent.
* We have to track the latestdir on a per-process basis.
*/
#define LCWD_VNAME_FMT ".meta.%d.lcwd"
#define LDIR_VNAME_FMT ".meta.%d.ldir"
/*
@ -872,11 +874,14 @@ meta_oodate(GNode *gn, Boolean oodate)
{
static char *tmpdir = NULL;
static char cwd[MAXPATHLEN];
char lcwd_vname[64];
char ldir_vname[64];
char lcwd[MAXPATHLEN];
char latestdir[MAXPATHLEN];
char fname[MAXPATHLEN];
char fname1[MAXPATHLEN];
char fname2[MAXPATHLEN];
char fname3[MAXPATHLEN];
char *p;
char *cp;
char *link_src;
@ -928,6 +933,8 @@ meta_oodate(GNode *gn, Boolean oodate)
err(1, "Could not get current working directory");
cwdlen = strlen(cwd);
}
strlcpy(lcwd, cwd, sizeof(lcwd));
strlcpy(latestdir, cwd, sizeof(latestdir));
if (!tmpdir) {
tmpdir = getTmpdir();
@ -1011,9 +1018,11 @@ meta_oodate(GNode *gn, Boolean oodate)
char *tp;
if (lastpid > 0) {
/* We need to remember this. */
/* We need to remember these. */
Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0);
Var_Set(ldir_vname, latestdir, VAR_GLOBAL, 0);
}
snprintf(lcwd_vname, sizeof(lcwd_vname), LCWD_VNAME_FMT, pid);
snprintf(ldir_vname, sizeof(ldir_vname), LDIR_VNAME_FMT, pid);
lastpid = pid;
ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp);
@ -1021,15 +1030,22 @@ meta_oodate(GNode *gn, Boolean oodate)
strlcpy(latestdir, ldir, sizeof(latestdir));
if (tp)
free(tp);
} else
strlcpy(latestdir, cwd, sizeof(latestdir));
}
ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp);
if (ldir) {
strlcpy(lcwd, ldir, sizeof(lcwd));
if (tp)
free(tp);
}
}
/* Skip past the pid. */
if (strsep(&p, " ") == NULL)
continue;
#ifdef DEBUG_META_MODE
if (DEBUG(META))
fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, latestdir);
fprintf(debug_file, "%s: %d: %d: %c: cwd=%s lcwd=%s ldir=%s\n",
fname, lineno,
pid, buf[0], cwd, lcwd, latestdir);
#endif
break;
}
@ -1039,6 +1055,7 @@ meta_oodate(GNode *gn, Boolean oodate)
/* Process according to record type. */
switch (buf[0]) {
case 'X': /* eXit */
Var_Delete(lcwd_vname, VAR_GLOBAL);
Var_Delete(ldir_vname, VAR_GLOBAL);
lastpid = 0; /* no need to save ldir_vname */
break;
@ -1050,15 +1067,30 @@ meta_oodate(GNode *gn, Boolean oodate)
child = atoi(p);
if (child > 0) {
snprintf(cldir, sizeof(cldir), LCWD_VNAME_FMT, child);
Var_Set(cldir, lcwd, VAR_GLOBAL, 0);
snprintf(cldir, sizeof(cldir), LDIR_VNAME_FMT, child);
Var_Set(cldir, latestdir, VAR_GLOBAL, 0);
#ifdef DEBUG_META_MODE
if (DEBUG(META))
fprintf(debug_file, "%s: %d: %d: cwd=%s lcwd=%s ldir=%s\n",
fname, lineno,
child, cwd, lcwd, latestdir);
#endif
}
}
break;
case 'C': /* Chdir */
/* Update the latest directory. */
strlcpy(latestdir, p, sizeof(latestdir));
/* Update lcwd and latest directory. */
strlcpy(latestdir, p, sizeof(latestdir));
strlcpy(lcwd, p, sizeof(lcwd));
Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0);
Var_Set(ldir_vname, lcwd, VAR_GLOBAL, 0);
#ifdef DEBUG_META_MODE
if (DEBUG(META))
fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, lcwd);
#endif
break;
case 'M': /* renaMe */
@ -1207,11 +1239,16 @@ meta_oodate(GNode *gn, Boolean oodate)
snprintf(fname1, sizeof(fname1), "%s/%s", latestdir, p);
sdirs[sdx++] = fname1;
if (strcmp(latestdir, cwd) != 0) {
/* Check vs cwd */
snprintf(fname2, sizeof(fname2), "%s/%s", cwd, p);
if (strcmp(latestdir, lcwd) != 0) {
/* Check vs lcwd */
snprintf(fname2, sizeof(fname2), "%s/%s", lcwd, p);
sdirs[sdx++] = fname2;
}
if (strcmp(lcwd, cwd) != 0) {
/* Check vs cwd */
snprintf(fname3, sizeof(fname3), "%s/%s", cwd, p);
sdirs[sdx++] = fname3;
}
}
sdirs[sdx++] = NULL;
@ -1250,6 +1287,10 @@ meta_oodate(GNode *gn, Boolean oodate)
oodate = TRUE;
}
}
if (buf[0] == 'E') {
/* previous latestdir is no longer relevant */
strlcpy(latestdir, lcwd, sizeof(latestdir));
}
break;
default:
break;

View File

@ -1,3 +1,111 @@
2015-04-16 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20150411
bump version
* own.mk: put AUTO_OBJ in OPTIONS_DEFAULT_NO rather than YES.
it is here mainly for documentation purposes, since
if using auto.obj.mk it is better done via sys.mk
2015-04-01 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20150401
* meta2deps.sh: support @list
* meta2deps.py: updates from Juniper
o add EXCLUDES
o skip bogus input files.
o treat 'M' and 'L' as both an 'R' and a 'W'
2015-03-03 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20150303
* dirdeps.mk: if MK_DIRDEPS_CACHE is yes, use dirdeps-cache
which is built via sub-make so we have a .meta file to tell if
it is out-of-date.
The dirdeps-cache contains the same dependency rules that we
normaly construct on the fly.
This adds a few seconds overhead when the cache is out of date,
but for a large target, the savings can be significant (10-20min).
2014-11-18 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20141118
* meta.stage.mk: add stale_staged
* dirdeps.mk (_DIRDEP_USE_LEVEL): allow this to be tweaked
only useful under very rare conditions such as
FreeBSD's make universe.
* auto.obj.mk: Allow MK_AUTO_OBJ to set MKOBJDIRS=auto
2014-11-11 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20141111
* mkopt.sh: use consistent semantics for _mk_opt and _mk_opts
2014-11-09 Simon J. Gerraty <sjg@bad.crufty.net>
* FILES: include mkopt.sh which allows handling options in shell
scripts in a manner compatible with options.mk
2014-10-12 Simon J. Gerraty <sjg@bad.crufty.net>
* meta.stage.mk: ensure only _STAGED_DIRS under objroot are used
for GENDIRDEPS_FILTER to avoid surprises.
2014-10-10 Simon J. Gerraty <sjg@bad.crufty.net>
* dirdeps.mk (NSkipHostDir): this needs SRCTOP prepended since by
the time it is applied to __depdirs they have.
* dirdeps.mk fix filtering of _machines since M_dep_qual_fixes
expects patterns like *.${MACHINE}
* cython.mk (pyprefix?): use pyprefix to find python bits
since prefix might be something else (where we install our
stuff)
2014-09-11 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20140911
* dirdeps.mk: add bootstrap target to simplify adding support for
new MACHINE.
2014-09-01 Simon J. Gerraty <sjg@bad.crufty.net>
* gendirdeps.mk: Add handling of GENDIRDEPS_FILTER_DIR_VARS and
GENDIRDEPS_FILTER_VARS to make it easier to produce sharable
Makefile.depend files.
2014-08-28 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20140828
* cython.mk: capture logic for building python extension modules
with Cython.
2014-08-08 Simon J. Gerraty <sjg@bad.crufty.net>
* meta.stage.mk (_STAGE_AS_BASENAME_USE): Add StageAs variant
2014-08-02 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20140801
* dep.mk: use explicit MKDEP_MK rather than overload MKDEP to
identify the autodep.mk variant.
* sys.dependfile.mk: delete .MAKE.DEPENDFILE if its
initial value does not match .MAKE.DEPENDFILE_PREFIX
* meta.autodep.mk: if _bootstrap_dirdeps add RELDIR to DIRDEPS
2014-05-22 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20140522

View File

@ -5,6 +5,7 @@ auto.obj.mk
autoconf.mk
autodep.mk
auto.dep.mk
cython.mk
dep.mk
doc.mk
dpadd.mk
@ -20,7 +21,9 @@ libnames.mk
libs.mk
links.mk
man.mk
manifest.mk
mk-files.txt
mkopt.sh
nls.mk
obj.mk
options.mk
@ -49,6 +52,7 @@ sys/SunOS.mk
sys/UnixWare.mk
target-flags.mk
warnings.mk
whats.mk
yacc.mk
dirdeps.mk
gendirdeps.mk

View File

@ -1,6 +1,6 @@
#
# RCSid:
# $Id: auto.dep.mk,v 1.2 2010/04/19 17:37:19 sjg Exp $
# $Id: auto.dep.mk,v 1.3 2014/08/04 05:19:10 sjg Exp $
#
# @(#) Copyright (c) 2010, Simon J. Gerraty
#
@ -18,7 +18,7 @@
# This module provides automagic dependency generation along the
# lines suggested in the GNU make.info
# set MKDEP=auto.dep and dep.mk will include us
# 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

View File

@ -1,4 +1,4 @@
# $Id: auto.obj.mk,v 1.8 2011/08/08 17:35:20 sjg Exp $
# $Id: auto.obj.mk,v 1.10 2015/04/16 16:59:00 sjg Exp $
#
# @(#) Copyright (c) 2004, Simon J. Gerraty
#
@ -34,10 +34,14 @@ Mkdirs= Mkdirs() { \
# 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.
__objdir?= ${MAKEOBJDIR}
__objdir:= ${__objdir:tA}
.if ${.OBJDIR} != ${__objdir}
# We need to chdir, make the directory if needed
.if !exists(${__objdir}/) && \
@ -46,11 +50,12 @@ __objdir?= ${MAKEOBJDIR}
__objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \
${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
${Mkdirs}; Mkdirs ${__objdir}
__objdir:= ${__objdir:tA}
.endif
# This causes make to use the specified directory as .OBJDIR
.OBJDIR: ${__objdir}
.if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != ""
.error could not use ${__objdir}
.error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
.endif
.endif
.endif

View File

@ -1,6 +1,6 @@
#
# RCSid:
# $Id: autodep.mk,v 1.33 2014/04/05 22:56:54 sjg Exp $
# $Id: autodep.mk,v 1.34 2014/08/04 05:12:27 sjg Exp $
#
# @(#) Copyright (c) 1999-2010, Simon J. Gerraty
#
@ -19,14 +19,9 @@
# The depend target is mainly for backwards compatibility,
# dependencies are normally updated as part of compilation.
# set MKDEP=autodep and dep.mk will include us
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
# different versions of bsd.dep.mk use these
MKDEP=autodep
MKDEPCMD=autodep
DEPENDFILE?= .depend
.for d in ${DEPENDFILE:N.depend}
# bmake only groks .depend

96
mk/cython.mk Normal file
View File

@ -0,0 +1,96 @@
# RCSid:
# $Id: cython.mk,v 1.6 2014/10/15 06:23:51 sjg 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
#
# this is what we build
CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
CYTHON_MODULE_NAME?= it
CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
# this is where we save generated src
CYTHON_SAVEGENDIR?= ${.CURDIR}/gen
# 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,\..*,,}
# set this empty if you don't want to handle multiple versions
.if !defined(CYTHON_PYVERSION)
CYTHON_PYVERSION:= ${PYVERSION}
.endif
CFLAGS+= -I${PYTHON_H:H}
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
COMPILE.c?= ${CC} -c ${CFLAGS}
.c.So:
${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
${CYTHON_MODULE}: ${SRCS:S,.c,.So,}
${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*.So} ${LDADD}
# 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
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+= *.So ${CYTHON_MODULE}

View File

@ -1,4 +1,4 @@
# $Id: dep.mk,v 1.16 2012/11/11 22:37:02 sjg Exp $
# $Id: dep.mk,v 1.17 2014/08/04 05:12:27 sjg Exp $
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
@ -34,21 +34,15 @@ MKDEP ?= ${MKDEP_CMD}
.NOPATH: .depend
.if ${MKDEP} == "auto.dep" && make(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
.if ${MKDEP:T:S,auto,,} != ${MKDEP:T}
.include <${MKDEP}.mk>
MKDEP_MK ?= autodep.mk
.include <${MKDEP_MK}>
.else
.include <autodep.mk>
.endif
.else
.if ${MKDEP:T:S,auto,,} != ${MKDEP:T}
MKDEP = ${MKDEP_CMD}
.endif
MKDEP_ENV_VARS += CC CXX
.for v in ${MKDEP_ENV_VARS:O:u}
.if !empty($v)

View File

@ -1,4 +1,4 @@
# $Id: dirdeps.mk,v 1.35 2014/05/03 06:27:56 sjg Exp $
# $Id: dirdeps.mk,v 1.49 2015/03/11 21:39:28 sjg Exp $
# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
@ -111,7 +111,9 @@
# TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
#
.if ${.MAKE.LEVEL} == 0
# touch this at your peril
_DIRDEP_USE_LEVEL?= 0
.if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
# only the first instance is interested in all this
# First off, we want to know what ${MACHINE} to build for.
@ -121,6 +123,12 @@
.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
# make sure these are empty to start with
_DEP_TARGET_SPEC =
@ -201,7 +209,7 @@ _last_dependfile := ${.INCLUDEDFROMFILE:M${.MAKE.DEPENDFILE_PREFIX}*}
.else
_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]}
.endif
.if !empty(_debug_reldir)
.if ${_debug_reldir:U0}
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _last_dependfile='${_last_dependfile}'
.endif
@ -260,7 +268,7 @@ _DEP_RELDIR := ${DEP_RELDIR}
# things we skip for host tools
SKIP_HOSTDIR ?=
NSkipHostDir = ${SKIP_HOSTDIR:N*.host:S,$,.host,:N.host:${M_ListToSkip}}
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.
@ -332,8 +340,78 @@ _only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
DIRDEPS ?= ${RELDIR}
.endif # target
_debug_reldir := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@}
_debug_search := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@}
# 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 !defined(NO_DIRDEPS)
.if ${MK_DIRDEPS_CACHE} == "yes"
# this is where we will cache all our work
DIRDEPS_CACHE?= ${_OBJDIR}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,^,.,:N.}
# 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
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>'; \
} > ${.TARGET}.new
+@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \
DIRDEPS="${DIRDEPS}" \
MAKEFLAGS= ${.MAKE} -C ${_CURDIR} -f ${BUILD_DIRDEPS_MAKEFILE} \
${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \
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
.endif
.elif !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
.if ${BUILD_DIRDEPS} == "yes"
.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
# the rest is done repeatedly for every Makefile.depend we read.
# if we are anything but the original dir we care only about the
@ -368,7 +446,8 @@ _machines := ${_machines:O:u}
# we need to tweak _machines
_dm := ${DEP_MACHINE}
# apply the same filtering that we do when qualifying DIRDEPS.
_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@:${M_dep_qual_fixes:ts:}:O:u}
# M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
DEP_MACHINE := ${_dm}
.endif
@ -388,7 +467,7 @@ _build_dirs += ${_machines:N${DEP_TARGET_SPEC}:@m@${_CURDIR}.$m@}
.endif
.endif
.if !empty(_debug_reldir)
.if ${_debug_reldir}
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}'
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}'
.endif
@ -419,7 +498,7 @@ __hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${
__qual_depdirs += ${__hostdpadd}
.endif
.if !empty(_debug_reldir)
.if ${_debug_reldir}
.info depdirs=${__depdirs}
.info qualified=${__qual_depdirs}
.info unqualified=${__unqual_depdirs}
@ -429,7 +508,8 @@ __qual_depdirs += ${__hostdpadd}
_build_dirs += \
${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \
${__qual_depdirs:N*.host} \
${_machines:@m@${__unqual_depdirs:@d@$d.$m@}@}
${_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}
@ -441,11 +521,17 @@ _build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u}
# but if we want to count the number of Makefile.depend* read, we do.
.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS}} == ""
.if !empty(_build_dirs)
.if ${BUILD_DIRDEPS_CACHE} == "yes"
x!= { echo; echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; \
echo 'dirdeps: ${_build_dirs:${M_oneperline}}'; echo; } >&3; echo
x!= { ${_build_dirs:@x@${target($x):?:echo '$x: _DIRDEP_USE';}@} echo; } >&3; echo
.else
# this makes it all happen
dirdeps: ${_build_dirs}
.endif
${_build_dirs}: _DIRDEP_USE
.if !empty(_debug_reldir)
.if ${_debug_reldir}
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs}
.endif
@ -454,16 +540,24 @@ ${_build_dirs}: _DIRDEP_USE
# it would be nice to do :N${.TARGET}
.if !empty(__qual_depdirs)
.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m}
.if !empty(_debug_reldir) || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != ""
.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"
x!= { echo; echo '${_this_dir}.$m: ${_build_dirs:M*.$q:${M_oneperline}}'; echo; } >&3; echo
.else
${_this_dir}.$m: ${_build_dirs:M*.$q}
.endif
.endfor
.endif
.if !empty(_debug_reldir)
.if ${_debug_reldir}
.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m}
.endif
.if ${BUILD_DIRDEPS_CACHE} == "yes"
x!= { echo; echo '${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m:${M_oneperline}}'; echo; } >&3; echo
.else
${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
.endif
.endfor
.endif
@ -473,7 +567,7 @@ ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
.if ${_DIRDEP_CHECKED:M$d} == ""
# once only
_DIRDEP_CHECKED += $d
.if !empty(_debug_search)
.if ${_debug_search}
.info checking $d
.endif
# Note: _build_dirs is fully qualifed so d:R is always the directory
@ -485,14 +579,14 @@ _m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:S;${MACHINE};${d
.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 !empty(_debug_search)
.if ${_debug_search}
.info Looking for ${_qm}
.endif
# we pass _DEP_TARGET_SPEC to tell the next step what we want
_DEP_TARGET_SPEC := ${d:E}
# some makefiles may still look at this
_DEP_MACHINE := ${d:E:C/,.*//}
.if !empty(_debug_reldir) && ${_qm} != ${_m}
.if ${_debug_reldir} && ${_qm} != ${_m}
.info loading ${_m} for ${d:E}
.endif
.include <${_m}>
@ -502,6 +596,7 @@ _DEP_MACHINE := ${d:E:C/,.*//}
.endfor
.endif # -V
.endif # BUILD_DIRDEPS
.elif ${.MAKE.LEVEL} > 42
.error You should have stopped recursing by now.
@ -511,3 +606,37 @@ _DEP_RELDIR := ${DEP_RELDIR}
.-include <.depend>
.endif
# bootstrapping new dependencies made easy?
.if make(bootstrap*) && !target(bootstrap)
.if exists(${.CURDIR}/${.MAKE.DEPENDFILE:T})
# stop here
${.TARGETS:Mboot*}:
.else
# 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}
.endif
_src?= ${.MAKE.DEPENDFILE:T}
bootstrap-this: .NOTMAIN
@echo Bootstrapping ${RELDIR}/${.MAKE.DEPENDFILE:T} from ${_src:T}
(cd ${.CURDIR} && sed 's,${_src:E},${MACHINE},g' ${_src} > ${.MAKE.DEPENDFILE:T})
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
.endif

View File

@ -1,4 +1,4 @@
# $Id: gendirdeps.mk,v 1.25 2014/03/14 21:28:37 sjg Exp $
# $Id: gendirdeps.mk,v 1.26 2014/09/05 04:40:52 sjg Exp $
# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
@ -93,6 +93,17 @@ _skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
_skip_gendirdeps =
.endif
# Below we will turn _{VAR} into ${VAR} which keeps this simple
# GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for.
# GENDIRDEPS_FILTER_VARS is more general.
# In each case order matters.
.if !empty(GENDIRDEPS_FILTER_DIR_VARS)
GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@}
.endif
.if !empty(GENDIRDEPS_FILTER_VARS)
GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u}
.endif
# this (*should* be set in meta.sys.mk)
# is the script that extracts what we want.
META2DEPS ?= ${.PARSEDIR}/meta2deps.sh

View File

@ -55,7 +55,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: install-mk,v 1.100 2014/05/23 01:30:36 sjg Exp $
# $Id: install-mk,v 1.109 2015/04/16 16:59:00 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@ -70,7 +70,7 @@
# sjg@crufty.net
#
MK_VERSION=20140522
MK_VERSION=20150411
OWNER=
GROUP=
MODE=444

View File

@ -1,4 +1,4 @@
# $Id: links.mk,v 1.5 2005/07/11 18:01:05 sjg Exp $
# $Id: links.mk,v 1.6 2014/09/29 17:14:40 sjg Exp $
#
# @(#) Copyright (c) 2005, Simon J. Gerraty
#
@ -22,9 +22,14 @@ SYMLINKS?=
__SYMLINK_SCRIPT= \
${ECHO} "$$t -> $$l"; \
mkdir -p `dirname $$t`; \
rm -f $$t; \
${LN} -s $$l $$t
case `'ls' -l $$t 2> /dev/null` in \
*"> $$l") ;; \
*) \
mkdir -p `dirname $$t`; \
rm -f $$t; \
${LN} -s $$l $$t;; \
esac
__LINK_SCRIPT= \
${ECHO} "$$t -> $$l"; \

66
mk/manifest.mk Normal file
View File

@ -0,0 +1,66 @@
# $Id: manifest.mk,v 1.2 2014/10/31 18:06:17 sjg 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
#
# generate mtree style manifest supported by makefs in FreeBSD
# input looks like
# MANIFEST= my.mtree
# for each MANIFEST we have a list of dirs
# ${MANIFEST}.DIRS += bin sbin usr/bin ...
# for each dir we have a ${MANIFEST}.SRCS.$dir
# that provides the absolute path to the contents
# ${MANIFEST}.SRCS.bin += ${OBJTOP}/bin/sh/sh
# ${MANIFEST}.SYMLINKS is a list of src target pairs
# for each file/dir there are a number of attributes
# UID GID MODE FLAGS
# which can be set per dir, per file or we use defaults
# eg.
# MODE.sbin = 550
# MODE.usr/sbin = 550
# MODE.dirs = 555
# means that sbin and usr/sbin get 550 all other dirs get 555
# MODE.usr/bin/passwd = 4555
# MODE.usr/bin.files = 555
# MODE.usr/sbin.files = 500
# means passwd gets 4555 other files in usr/bin get 555 and
# files in usr/sbin get 500
# STORE defaults to basename of src and target directory
# but we can use
# ${MANIFEST}.SRCS.sbin += ${OBJTOP}/bin/sh-static/sh-static
# STORE.sbin/sh-static = sbin/sh
#
# the above is a little overkill but means we can easily adapt to
# different formats
UID.dirs ?= 0
GID.dirs ?= 0
MODE.dirs ?= 775
FLAGS.dirs ?=
UID.files ?= 0
GID.files ?= 0
MODE.files ?= 555
# a is attribute name d is dirname
M_DIR_ATTR = L:@a@$${$$a.$$d:U$${$$a.dirs}}@
# as above and s is set to the name we store f as
M_FILE_ATTR = L:@a@$${$$a.$$s:U$${$$a.$$d.files:U$${$$a.files}}}@
# this produces the body of the manifest
# there should typically be a header prefixed
_GEN_MTREE_MANIFEST_USE: .USE
@(${${.TARGET}.DIRS:O:u:@d@echo '$d type=dir uid=${UID:${M_DIR_ATTR}} gid=${GID:${M_DIR_ATTR}} mode=${MODE:${M_DIR_ATTR}} ${FLAGS:${M_DIR_ATTR}}';@} \
${${.TARGET}.DIRS:O:u:@d@${${.TARGET}.SRCS.$d:O:u:@f@echo '${s::=${STORE.$d/${f:T}:U$d/${f:T}}}$s contents="$f" type=file uid=${UID:${M_FILE_ATTR}} gid=${GID:${M_FILE_ATTR}} mode=${MODE:${M_FILE_ATTR}} ${FLAGS:${M_FILE_ATTR}}';@}@} \
set ${${.TARGET}.SYMLINKS}; while test $$# -ge 2; do echo "$$2 type=link link=$$1"; shift 2; done) > ${.TARGET}

View File

@ -1,4 +1,4 @@
# $Id: meta.autodep.mk,v 1.35 2014/05/09 00:05:46 sjg Exp $
# $Id: meta.autodep.mk,v 1.36 2014/08/02 23:10:29 sjg Exp $
#
# @(#) Copyright (c) 2010, Simon J. Gerraty
@ -254,6 +254,9 @@ ${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.MET
.endif
.if ${_bootstrap_dirdeps} == "yes"
.if ${BUILD_AT_LEVEL0:Uno} == "no"
DIRDEPS+= ${RELDIR}.${TARGET_SPEC:U${MACHINE}}
.endif
# make sure this is included at least once
.include <dirdeps.mk>
.else

View File

@ -1,4 +1,4 @@
# $Id: meta.stage.mk,v 1.30 2013/04/19 16:32:57 sjg Exp $
# $Id: meta.stage.mk,v 1.34 2014/11/20 22:40:08 sjg Exp $
#
# @(#) Copyright (c) 2011, Simon J. Gerraty
#
@ -35,7 +35,13 @@ _stage_file_basename = $${f\#\#*/}
_stage_target_dirname = $${t%/*}
.endif
_OBJROOT ?= ${OBJROOT:U${OBJTOP:H}}
.if ${_OBJROOT:M*/} != ""
_objroot ?= ${_OBJROOT:tA}/
.else
_objroot ?= ${_OBJROOT:tA}
.endif
# make sure this is global
_STAGED_DIRS ?=
.export _STAGED_DIRS
@ -46,7 +52,7 @@ STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@
# convert _STAGED_DIRS into suitable filters
GENDIRDEPS_FILTER += Nnot-empty-is-important \
${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \
${_STAGED_DIRS:O:u:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,}
${_STAGED_DIRS:O:u:M${_objroot}*:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,}
LN_CP_SCRIPT = LnCp() { \
rm -f $$2 2> /dev/null; \
@ -113,10 +119,14 @@ STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \
_STAGE_BASENAME_USE: .USE ${.TARGET:T}
@${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T}
_STAGE_AS_BASENAME_USE: .USE ${.TARGET:T}
@${STAGE_AS_SCRIPT}; StageAs ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} ${STAGE_AS_${.TARGET:T}:U${.TARGET:T}}
.if !empty(STAGE_INCSDIR)
STAGE_TARGETS += stage_incs
STAGE_INCS ?= ${.ALLSRC:N.dirdep}
stage_includes: stage_incs
stage_incs: .dirdep
@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS}
@touch $@
@ -129,11 +139,13 @@ STAGE_LIBS ?= ${.ALLSRC:N.dirdep}
stage_libs: .dirdep
@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS}
.if !defined(NO_SHLIB_LINKS)
.if !empty(SHLIB_LINKS)
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \
${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*} $t@}
.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME)
@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK} ${SYMLINKS:T}
.endif
.endif
@touch $@
.endif
@ -212,7 +224,7 @@ stage_as.$s: .dirdep
.endfor
.endif
CLEANFILES += ${STAGE_TARGETS}
CLEANFILES += ${STAGE_TARGETS} stage_incs stage_includes
# stage_*links usually needs to follow any others.
.for t in ${STAGE_TARGETS:N*links:O:u}
@ -240,5 +252,26 @@ INSTALL := ${STAGE_INSTALL}
beforeinstall: .dirdep
.endif
.endif
.NOPATH: ${STAGE_FILES}
.if !empty(STAGE_TARGETS)
MK_STALE_STAGED?= no
.if ${MK_STALE_STAGED} == "yes"
all: stale_staged
# get a list of paths that we have just staged
# get a list of paths that we have previously staged to those same dirs
# anything in the 2nd list but not the first is stale - remove it.
stale_staged: staging .NOMETA
@egrep '^[WL] .*${STAGE_OBJTOP}' /dev/null ${.MAKE.META.FILES:M*stage_*} | \
sed "/\.dirdep/d;s,.* '*\(${STAGE_OBJTOP}/[^ '][^ ']*\).*,\1," | \
sort > ${.TARGET}.staged1
@grep -l '${_dirdep}' /dev/null ${_STAGED_DIRS:M${STAGE_OBJTOP}*:O:u:@d@$d/*.dirdep@} | \
sed 's,\.dirdep,,' | sort > ${.TARGET}.staged2
@comm -13 ${.TARGET}.staged1 ${.TARGET}.staged2 > ${.TARGET}.stale
@test ! -s ${.TARGET}.stale || { \
echo "Removing stale staged files..."; \
sed 's,.*,& &.dirdep,' ${.TARGET}.stale | xargs rm -f; }
.endif
.endif
.endif

View File

@ -1,4 +1,4 @@
# $Id: meta.sys.mk,v 1.16 2012/07/03 05:26:00 sjg Exp $
# $Id: meta.sys.mk,v 1.20 2014/08/04 05:12:27 sjg Exp $
#
# @(#) Copyright (c) 2010, Simon J. Gerraty
@ -106,7 +106,13 @@ _metaError: .NOMETA .NOTMAIN
# Are we, after all, in meta mode?
.if ${.MAKE.MODE:Mmeta*} != ""
MKDEP = meta.autodep
MKDEP_MK = meta.autodep.mk
# if we think we are updating dependencies,
# then filemon had better be present
.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
.endif
.if ${.MAKE.LEVEL} == 0
# make sure dirdeps target exists and do it first
@ -121,19 +127,11 @@ dirdeps:
# tell dirdeps.mk what we want
BUILD_AT_LEVEL0 = no
.endif
.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
.if ${.TARGETS:Nall} == ""
# it works best if we do everything via sub-makes
BUILD_AT_LEVEL0 ?= no
.endif
BUILD_AT_LEVEL0 ?= yes
.endif
# if we think we are updating dependencies,
# then filemon had better be present
.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
.endif
.endif
.endif
.endif

View File

@ -37,7 +37,7 @@
"""
RCSid:
$Id: meta2deps.py,v 1.17 2014/04/05 22:56:54 sjg Exp $
$Id: meta2deps.py,v 1.18 2015/04/03 18:23:25 sjg Exp $
Copyright (c) 2011-2013, Juniper Networks, Inc.
All rights reserved.
@ -112,7 +112,8 @@ def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
rpath = resolve(path, cwd, last_dir, debug, debug_out)
if rpath:
path = rpath
if (path.find('./') > 0 or
if (path.find('/') < 0 or
path.find('./') > 0 or
path.endswith('/..') or
os.path.islink(path)):
return os.path.realpath(path)
@ -142,7 +143,7 @@ class MetaFile:
host_target = None
srctops = []
objroots = []
excludes = []
seen = {}
obj_deps = []
src_deps = []
@ -179,6 +180,10 @@ def __init__(self, name, conf={}):
This can allow 'bmake' to learn all the dirs within
the tree that depend on 'foo.h'
EXCLUDES
A list of paths to ignore.
ccache(1) can otherwise be trouble.
debug desired debug level
debug_out open file to send debug output to (sys.stderr)
@ -236,11 +241,14 @@ def __init__(self, name, conf={}):
# we want the longest match
self.srctops.sort(reverse=True)
self.objroots.sort(reverse=True)
self.excludes = getv(conf, 'EXCLUDES', [])
if self.debug:
print("host_target=", self.host_target, file=self.debug_out)
print("srctops=", self.srctops, file=self.debug_out)
print("objroots=", self.objroots, file=self.debug_out)
print("excludes=", self.excludes, file=self.debug_out)
self.dirdep_re = re.compile(r'([^/]+)/(.+)')
@ -257,6 +265,7 @@ def __init__(self, name, conf={}):
self.dpdeps = None # we cannot do it?
self.cwd = os.getcwd() # make sure this is initialized
self.last_dir = self.cwd
if name:
self.try_parse()
@ -360,18 +369,18 @@ def parse(self, name=None, file=None):
V 3
C "pid" "cwd"
E "pid" "path"
F "pid" "child"
F "pid" "child"
R "pid" "path"
W "pid" "path"
X "pid" "status"
D "pid" "path"
L "pid" "src" "target"
M "pid" "old" "new"
S "pid" "path"
# Bye bye
D "pid" "path"
L "pid" "src" "target"
M "pid" "old" "new"
S "pid" "path"
# Bye bye
We go to some effort to avoid processing a dependency more than once.
Of the above record types only C,E,F,L,R,V and W are of interest.
We go to some effort to avoid processing a dependency more than once.
Of the above record types only C,E,F,L,R,V and W are of interest.
"""
version = 0 # unknown
@ -379,7 +388,7 @@ def parse(self, name=None, file=None):
self.name = name;
if file:
f = file
cwd = last_dir = self.cwd
cwd = self.last_dir = self.cwd
else:
f = open(self.name, 'r')
skip = True
@ -412,7 +421,7 @@ def parse(self, name=None, file=None):
interesting += 'W'
"""
elif w[0] == 'CWD':
self.cwd = cwd = last_dir = w[1]
self.cwd = cwd = self.last_dir = w[1]
self.seenit(cwd) # ignore this
if self.debug:
print("%s: CWD=%s" % (self.name, cwd), file=self.debug_out)
@ -422,9 +431,9 @@ def parse(self, name=None, file=None):
if pid != last_pid:
if last_pid:
pid_cwd[last_pid] = cwd
pid_last_dir[last_pid] = last_dir
pid_last_dir[last_pid] = self.last_dir
cwd = getv(pid_cwd, pid, self.cwd)
last_dir = getv(pid_last_dir, pid, self.cwd)
self.last_dir = getv(pid_last_dir, pid, self.cwd)
last_pid = pid
# process operations
@ -438,7 +447,7 @@ def parse(self, name=None, file=None):
cwd = abspath(w[2], cwd, None, self.debug, self.debug_out)
if cwd.endswith('/.'):
cwd = cwd[0:-2]
last_dir = cwd
self.last_dir = cwd
if self.debug > 1:
print("cwd=", cwd, file=self.debug_out)
continue
@ -449,98 +458,114 @@ def parse(self, name=None, file=None):
continue
# file operations
if w[0] in 'ML':
path = w[2].strip("'")
else:
# these are special, tread src as read and
# target as write
self.parse_path(w[1].strip("'"), cwd, 'R', w)
self.parse_path(w[2].strip("'"), cwd, 'W', w)
continue
elif w[0] in 'ERWS':
path = w[2]
# we are never interested in .dirdep files as dependencies
if path.endswith('.dirdep'):
continue
# we don't want to resolve the last component if it is
# a symlink
path = resolve(path, cwd, last_dir, self.debug, self.debug_out)
if not path:
continue
dir,base = os.path.split(path)
if dir in self.seen:
if self.debug > 2:
print("seen:", dir, file=self.debug_out)
continue
# we can have a path in an objdir which is a link
# to the src dir, we may need to add dependencies for each
rdir = dir
dir = abspath(dir, cwd, last_dir, self.debug, self.debug_out)
if rdir == dir or rdir.find('./') > 0:
rdir = None
# now put path back together
path = '/'.join([dir,base])
if self.debug > 1:
print("raw=%s rdir=%s dir=%s path=%s" % (w[2], rdir, dir, path), file=self.debug_out)
if w[0] in 'SRWL':
if w[0] == 'W' and path.endswith('.dirdep'):
continue
if path in [last_dir, cwd, self.cwd, self.curdir]:
if self.debug > 1:
print("skipping:", path, file=self.debug_out)
continue
if os.path.isdir(path):
if w[0] in 'RW':
last_dir = path;
if self.debug > 1:
print("ldir=", last_dir, file=self.debug_out)
continue
self.parse_path(path, cwd, w[0], w)
if w[0] in 'REWML':
# finally, we get down to it
if dir == self.cwd or dir == self.curdir:
continue
srctop = self.find_top(path, self.srctops)
if srctop:
if self.dpdeps:
self.add(self.file_deps, path.replace(srctop,''), 'file')
self.add(self.src_deps, dir.replace(srctop,''), 'src')
self.seenit(w[2])
self.seenit(dir)
if rdir and not rdir.startswith(srctop):
dir = rdir # for below
rdir = None
else:
continue
objroot = None
for dir in [dir,rdir]:
if not dir:
continue
objroot = self.find_top(dir, self.objroots)
if objroot:
break
if objroot:
ddep = self.find_obj(objroot, dir, path, w[2])
if ddep:
self.add(self.obj_deps, ddep, 'obj')
else:
# don't waste time looking again
self.seenit(w[2])
self.seenit(dir)
if not file:
f.close()
def parse_path(self, path, cwd, op=None, w=[]):
"""look at a path for the op specified"""
if not op:
op = w[0]
# we are never interested in .dirdep files as dependencies
if path.endswith('.dirdep'):
return
for p in self.excludes:
if p and path.startswith(p):
if self.debug > 2:
print >> self.debug_out, "exclude:", p, path
return
# we don't want to resolve the last component if it is
# a symlink
path = resolve(path, cwd, self.last_dir, self.debug, self.debug_out)
if not path:
return
dir,base = os.path.split(path)
if dir in self.seen:
if self.debug > 2:
print("seen:", dir, file=self.debug_out)
return
# we can have a path in an objdir which is a link
# to the src dir, we may need to add dependencies for each
rdir = dir
dir = abspath(dir, cwd, self.last_dir, self.debug, self.debug_out)
if rdir == dir or rdir.find('./') > 0:
rdir = None
# now put path back together
path = '/'.join([dir,base])
if self.debug > 1:
print("raw=%s rdir=%s dir=%s path=%s" % (w[2], rdir, dir, path), file=self.debug_out)
if op in 'RWS':
if path in [self.last_dir, cwd, self.cwd, self.curdir]:
if self.debug > 1:
print("skipping:", path, file=self.debug_out)
return
if os.path.isdir(path):
if op in 'RW':
self.last_dir = path;
if self.debug > 1:
print("ldir=", self.last_dir, file=self.debug_out)
return
if op in 'ERW':
# finally, we get down to it
if dir == self.cwd or dir == self.curdir:
return
srctop = self.find_top(path, self.srctops)
if srctop:
if self.dpdeps:
self.add(self.file_deps, path.replace(srctop,''), 'file')
self.add(self.src_deps, dir.replace(srctop,''), 'src')
self.seenit(w[2])
self.seenit(dir)
if rdir and not rdir.startswith(srctop):
dir = rdir # for below
rdir = None
else:
return
objroot = None
for dir in [dir,rdir]:
if not dir:
continue
objroot = self.find_top(dir, self.objroots)
if objroot:
break
if objroot:
ddep = self.find_obj(objroot, dir, path, w[2])
if ddep:
self.add(self.obj_deps, ddep, 'obj')
else:
# don't waste time looking again
self.seenit(w[2])
self.seenit(dir)
def main(argv, klass=MetaFile, xopts='', xoptf=None):
"""Simple driver for class MetaFile.
Usage:
script [options] [key=value ...] "meta" ...
script [options] [key=value ...] "meta" ...
Options and key=value pairs contribute to the
dictionary passed to MetaFile.
-S "SRCTOP"
add "SRCTOP" to the "SRCTOPS" list.
add "SRCTOP" to the "SRCTOPS" list.
-C "CURDIR"
-O "OBJROOT"
add "OBJROOT" to the "OBJROOTS" list.
add "OBJROOT" to the "OBJROOTS" list.
-m "MACHINE"
@ -550,7 +575,7 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
-D "DPDEPS"
-d bumps debug level
-d bumps debug level
"""
import getopt
@ -568,6 +593,7 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
conf = {
'SRCTOPS': [],
'OBJROOTS': [],
'EXCLUDES': [],
}
try:
@ -589,7 +615,7 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
debug = 0
output = True
opts, args = getopt.getopt(argv[1:], 'a:dS:C:O:R:m:D:H:qT:' + xopts)
opts, args = getopt.getopt(argv[1:], 'a:dS:C:O:R:m:D:H:qT:X:' + xopts)
for o, a in opts:
if o == '-a':
conf['MACHINE_ARCH'] = a
@ -615,6 +641,9 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
conf['MACHINE'] = a
elif o == '-T':
conf['TARGET_SPEC'] = a
elif o == '-X':
if a not in conf['EXCLUDES']:
conf['EXCLUDES'].append(a)
elif xoptf:
xoptf(o, a, conf)
@ -649,16 +678,21 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
for k,v in list(conf.items()):
print("%s=%s" % (k,v), file=debug_out)
m = None
for a in args:
if a.endswith('.meta'):
if not os.path.exists(a):
continue
m = klass(a, conf)
elif a.startswith('@'):
# there can actually multiple files per line
for line in open(a[1:]):
for f in line.strip().split():
if not os.path.exists(f):
continue
m = klass(f, conf)
if output:
if output and m:
print(m.dirdeps())
print(m.src_dirdeps('\nsrc:'))

View File

@ -77,7 +77,7 @@
# RCSid:
# $Id: meta2deps.sh,v 1.7 2014/04/05 22:56:54 sjg Exp $
# $Id: meta2deps.sh,v 1.9 2015/04/03 18:23:25 sjg Exp $
# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
@ -139,10 +139,15 @@ add_list() {
eval "$name=\"$list\""
}
_excludes_f() {
egrep -v "$EXCLUDES"
}
meta2deps() {
DPDEPS=
SRCTOPS=$SRCTOP
OBJROOTS=
EXCLUDES=
while :
do
case "$1" in
@ -153,6 +158,7 @@ meta2deps() {
-H) HOST_TARGET=$2; shift 2;;
-S) add_list SRCTOPS $2; shift 2;;
-O) add_list OBJROOTS $2; shift 2;;
-X) add_list EXCLUDES '|' $2; shift 2;;
-R) RELDIR=$2; shift 2;;
-T) TARGET_SPEC=$2; shift 2;;
*) break;;
@ -212,8 +218,26 @@ meta2deps() {
seenit=
seensrc=
lpid=
cat /dev/null "$@" |
sed -e 's,^CWD,C C,;/^[CREFL] /!d' -e "s,',,g" |
case "$EXCLUDES" in
"") _excludes=cat;;
*) _excludes=_excludes_f;;
esac
# handle @list files
case "$@" in
*@[!.]*)
for f in "$@"
do
case "$f" in
*.meta) cat $f;;
@*) xargs cat < ${f#@};;
*) cat $f;;
esac
done
;;
*) cat /dev/null "$@";;
esac 2> /dev/null |
sed -e 's,^CWD,C C,;/^[CREFLM] /!d' -e "s,',,g" |
$_excludes |
while read op pid path junk
do
: op=$op pid=$pid path=$path

View File

@ -432,13 +432,27 @@ You should never need to edit ``warnings.mk``, it will include
``warnings-sets.mk`` if it exists and you use that to make any local
customizations.
rst2htm.mk
----------
Logic to simplify generating HTML (and PDF) documents from ReStructuredText.
cython.mk
---------
Logic to build Python C interface modules using Cython_
.. _Cython: http://www.cython.org/
Meta mode
=========
The 20110505 and later versions of ``mk-files`` include a number of
makefile contributed by Juniper Networks, Inc.
These allow the latest version of bmake_ to run in `meta mode`_.
makefiles contributed by Juniper Networks, Inc.
These allow the latest version of bmake_ to run in `meta mode`_
see `dirdeps.mk`_
.. _`dirdeps.mk`: /help/sjg/dirdeps.htm
.. _`meta mode`: bmake-meta-mode.htm
Install
@ -463,5 +477,5 @@ where you unpacked the tar file, you can::
.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz
:Author: sjg@crufty.net
:Revision: $Id: mk-files.txt,v 1.15 2011/06/08 07:06:18 sjg Exp $
:Revision: $Id: mk-files.txt,v 1.16 2014/09/05 04:41:16 sjg Exp $
:Copyright: Crufty.NET

94
mk/mkopt.sh Executable file
View File

@ -0,0 +1,94 @@
:
# $Id: mkopt.sh,v 1.8 2014/11/15 07:07:18 sjg 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
#
# handle WITH[OUT]_* options in a manner compatible with
# options.mk and bsd.mkopt.mk in recent FreeBSD
# no need to be included more than once
_MKOPT_SH=:
#
# _mk_opt OPT default
#
# Set MK_$OPT
#
# The semantics are simple, if MK_$OPT has no value
# WITHOUT_$OPT results in MK_$OPT=no
# otherwise WITH_$OPT results in MK_$OPT=yes.
# Note WITHOUT_$OPT overrides WITH_$OPT.
#
# For backwards compatability reasons we treat WITH_$OPT=no
# the same as WITHOUT_$OPT.
#
_mk_opt() {
_d=$1
_mo=MK_$2 _wo=WITHOUT_$2 _wi=WITH_$2
eval "_mov=\$$_mo _wov=\$$_wo _wiv=\$$_wi"
case "$_wiv" in
no) _wov=no;;
esac
_v=${_mov:-${_wov:+no}}
_v=${_v:-${_wiv:+yes}}
_v=${_v:-$_d}
_opt_list="$_opt_list $_mo"
case "$_v" in
yes|no) ;; # sane
0|[NnFf]*) _v=no;; # they mean no
1|[YyTt]*) _v=yes;; # they mean yes
*) _v=$_d;; # ignore bogus value
esac
eval "$_mo=$_v"
}
#
# _mk_opts default opt ... [default [opt] ...]
#
# see _mk_opts_defaults for example
#
_mk_opts() {
_d=no
for _o in "$@"
do
case "$_o" in
yes|no) _d=$_o; continue;;
esac
_mk_opt $_d $_o
done
}
_mk_opts_defaults() {
_mk_opts no $__DEFAULT_NO_OPTIONS yes $__DEFAULT_YES_OPTIONS
}
case "/$0" in
*/mkopt*)
_list=no
while :
do
case "$1" in
*=*) eval "$1"; shift;;
--no|no) _list="$_list no"; shift;;
--yes|yes) _list="$_list yes"; shift;;
-DWITH*) eval "${1#-D}=1"; shift;;
[A-Z]*) _list="$_list $1"; shift;;
*) break;;
esac
done
_mk_opts $_list
;;
esac

View File

@ -1,4 +1,4 @@
# $Id: own.mk,v 1.27 2013/07/18 05:46:24 sjg Exp $
# $Id: own.mk,v 1.28 2015/04/16 16:59:00 sjg Exp $
.if !target(__${.PARSEFILE}__)
__${.PARSEFILE}__:
@ -89,6 +89,7 @@ OPTIONS_DEFAULT_NO+= DPADD_MK
# process options
OPTIONS_DEFAULT_NO+= \
AUTO_OBJ \
INSTALL_AS_USER \
GPROF \
LIBTOOL \
@ -98,7 +99,6 @@ OPTIONS_DEFAULT_NO+= \
OPTIONS_DEFAULT_YES+= \
ARCHIVE \
AUTODEP \
AUTO_OBJ \
CRYPTO \
DOC \
DPADD_MK \

View File

@ -1,4 +1,4 @@
# $Id: sys.dependfile.mk,v 1.5 2013/03/08 00:59:21 sjg Exp $
# $Id: sys.dependfile.mk,v 1.6 2014/08/02 18:02:06 sjg Exp $
#
# @(#) Copyright (c) 2012, Simon J. Gerraty
#
@ -25,6 +25,12 @@
# All depend file names should start with this
.MAKE.DEPENDFILE_PREFIX ?= Makefile.depend
.if !empty(.MAKE.DEPENDFILE) && \
${.MAKE.DEPENDFILE:M${.MAKE.DEPENDFILE_PREFIX}*} == ""
# let us do our thing below...
.undef .MAKE.DEPENDFILE
.endif
# The order of preference: we will use the first one of these we find.
# It usually makes sense to order from most specific to least.
.MAKE.DEPENDFILE_PREFERENCE ?= \

63
mk/whats.mk Normal file
View File

@ -0,0 +1,63 @@
# $Id: whats.mk,v 1.1 2014/08/30 22:40:47 sjg 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
#
.if ${MK_WHATSTRING:Uno} != "no"
what_build_exts?= o
# it can be useful to embed a what(1) string in binaries
# so that the build location can be seen from a core file.
.if defined(PROG) && ${.MAKE.MAKEFILES:M*prog.mk} != ""
what_thing?= ${PROGNAME:U${PROG}}
what_build_thing?= ${PROG}
.elif defined(LIB) && ${.MAKE.MAKEFILES:M*lib.mk} != ""
# probably only makes sense for shared libs
# and the plumbing needed varies depending on *lib.mk
what_thing?= lib${LIB}
.if !empty(SOBJS)
_soe:= ${SOBJS:E:[1]}
what_build_exts= ${_soe}
SOBJS+= ${what_uuid}.${_soe}
.endif
.elif defined(KMOD) && ${.MAKE.MAKEFILES:M*kmod.mk} != ""
what_thing?= ${KMOD}
what_build_thing?= ${KMOD}.ko
.endif
.if !empty(what_thing)
# a unique name that won't conflict with anything
what_uuid = what_${.CURDIR:T:hash}
.if !empty(what_build_thing)
${what_build_thing}: ${what_build_exts:@e@${what_uuid}.$e@}
.endif
OBJS+= ${what_uuid}.o
CLEANFILES+= ${what_uuid}.c
# we do not need to capture this
SUPPRESS_DEPEND+= *${what_uuid}.c
SB?= ${SRCTOP:H}
SB_LOCATION?= ${HOST}:${SB}
what_location:= ${.OBJDIR:S,${SB},${SB_LOCATION},}
# this works with clang and gcc
_what_t= const char __attribute__ ((section(".data")))
_what1:= @(\#)${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
_what2:= @(\#)${what_location}
${what_uuid}.c:
echo '${_what_t} ${what_uuid}1[] = "${_what1}";' > $@ ${.OODATE:MNO_META_CMP}
echo '${_what_t} ${what_uuid}2[] = "${_what2}";' >> $@
.endif
.endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.65 2012/08/30 21:17:05 sjg Exp $ */
/* $NetBSD: nonints.h,v 1.67 2014/09/07 20:55:34 joerg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993

87
parse.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.194 2014/02/15 00:17:17 christos Exp $ */
/* $NetBSD: parse.c,v 1.204 2014/09/18 08:06:13 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: parse.c,v 1.194 2014/02/15 00:17:17 christos Exp $";
static char rcsid[] = "$NetBSD: parse.c,v 1.204 2014/09/18 08:06:13 dholland Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: parse.c,v 1.194 2014/02/15 00:17:17 christos Exp $");
__RCSID("$NetBSD: parse.c,v 1.204 2014/09/18 08:06:13 dholland Exp $");
#endif
#endif /* not lint */
#endif
@ -1203,7 +1203,17 @@ ParseDoDependency(char *line)
curTargs = Lst_Init(FALSE);
/*
* First, grind through the targets.
*/
do {
/*
* Here LINE points to the beginning of the next word, and
* LSTART points to the actual beginning of the line.
*/
/* Find the end of the next word. */
for (cp = line; *cp && (ParseIsEscaped(lstart, cp) ||
!(isspace((unsigned char)*cp) ||
*cp == '!' || *cp == ':' || *cp == LPAREN));
@ -1226,6 +1236,10 @@ ParseDoDependency(char *line)
}
}
/*
* If the word is followed by a left parenthesis, it's the
* name of an object file inside an archive (ar file).
*/
if (!ParseIsEscaped(lstart, cp) && *cp == LPAREN) {
/*
* Archives must be handled specially to make sure the OP_ARCHV
@ -1242,13 +1256,16 @@ ParseDoDependency(char *line)
"Error in archive specification: \"%s\"", line);
goto out;
} else {
/* Done with this word; on to the next. */
continue;
}
}
savec = *cp;
if (!*cp) {
/*
* We got to the end of the line while we were still
* looking at targets.
*
* Ending a dependency line without an operator is a Bozo
* no-no. As a heuristic, this is also often triggered by
* undetected conflicts from cvs/rcs merges.
@ -1263,10 +1280,13 @@ ParseDoDependency(char *line)
: "Need an operator");
goto out;
}
/* Insert a null terminator. */
savec = *cp;
*cp = '\0';
/*
* Have a word in line. See if it's a special target and set
* Got the word. See if it's a special target and if so set
* specType to match it.
*/
if (*line == '.' && isupper ((unsigned char)line[1])) {
@ -1405,6 +1425,8 @@ ParseDoDependency(char *line)
(void)Lst_AtEnd(curTargs, line);
}
/* Apply the targets. */
while(!Lst_IsEmpty(curTargs)) {
char *targName = (char *)Lst_DeQueue(curTargs);
@ -1422,7 +1444,9 @@ ParseDoDependency(char *line)
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
}
/* Don't need the inserted null terminator any more. */
*cp = savec;
/*
* If it is a special type and not .PATH, it's the only target we
* allow on this line...
@ -1498,12 +1522,21 @@ ParseDoDependency(char *line)
goto out;
}
cp++; /* Advance beyond operator */
/* Advance beyond the operator */
cp++;
/*
* Apply the operator to the target. This is how we remember which
* operator a target was defined with. It fails if the operator
* used isn't consistent across all references.
*/
Lst_ForEach(targets, ParseDoOp, &op);
/*
* Get to the first source
* Onward to the sources.
*
* LINE will now point to the first source word, if any, or the
* end of the string if not.
*/
while (*cp && isspace ((unsigned char)*cp)) {
cp++;
@ -1962,6 +1995,40 @@ Parse_DoVar(char *line, GNode *ctxt)
}
/*
* ParseMaybeSubMake --
* Scan the command string to see if it a possible submake node
* Input:
* cmd the command to scan
* Results:
* TRUE if the command is possibly a submake, FALSE if not.
*/
static Boolean
ParseMaybeSubMake(const char *cmd)
{
size_t i;
static struct {
const char *name;
size_t len;
} vals[] = {
#define MKV(A) { A, sizeof(A) - 1 }
MKV("${MAKE}"),
MKV("${.MAKE}"),
MKV("$(MAKE)"),
MKV("$(.MAKE)"),
MKV("make"),
};
for (i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) {
char *ptr;
if ((ptr = strstr(cmd, vals[i].name)) == NULL)
continue;
if ((ptr == cmd || !isalnum((unsigned char)ptr[-1]))
&& !isalnum((unsigned char)ptr[vals[i].len]))
return TRUE;
}
return FALSE;
}
/*-
* ParseAddCmd --
* Lst_ForEach function to add a command line to all targets
@ -1974,7 +2041,9 @@ Parse_DoVar(char *line, GNode *ctxt)
* Always 0
*
* Side Effects:
* A new element is added to the commands list of the node.
* A new element is added to the commands list of the node,
* and the node can be marked as a submake node if the command is
* determined to be that.
*/
static int
ParseAddCmd(void *gnp, void *cmd)
@ -1988,6 +2057,8 @@ ParseAddCmd(void *gnp, void *cmd)
/* if target already supplied, ignore commands */
if (!(gn->type & OP_HAS_COMMANDS)) {
(void)Lst_AtEnd(gn->commands, cmd);
if (ParseMaybeSubMake(cmd))
gn->type |= OP_SUBMAKE;
ParseMark(gn);
} else {
#ifdef notyet

6
suff.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $ */
/* $NetBSD: suff.c,v 1.73 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $";
static char rcsid[] = "$NetBSD: suff.c,v 1.73 2014/09/07 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
__RCSID("$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $");
__RCSID("$NetBSD: suff.c,v 1.73 2014/09/07 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif

6
targ.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.57 2012/06/12 19:21:51 joerg Exp $ */
/* $NetBSD: targ.c,v 1.59 2014/09/07 20:55:34 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: targ.c,v 1.57 2012/06/12 19:21:51 joerg Exp $";
static char rcsid[] = "$NetBSD: targ.c,v 1.59 2014/09/07 20:55:34 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: targ.c,v 1.57 2012/06/12 19:21:51 joerg Exp $");
__RCSID("$NetBSD: targ.c,v 1.59 2014/09/07 20:55:34 joerg Exp $");
#endif
#endif /* not lint */
#endif

View File

@ -1,17 +1,18 @@
# $Id: Makefile.in,v 1.44 2013/08/28 22:09:29 sjg Exp $
# $Id: Makefile.in,v 1.46 2014/11/06 01:47:57 sjg Exp $
#
# $NetBSD: Makefile,v 1.38 2013/08/28 21:56:50 sjg Exp $
# $NetBSD: Makefile,v 1.51 2014/10/20 23:21:11 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
#
# all: run all the tests
# test: run 'all', capture output and compare to expected results
# test: run 'all', and compare to expected results
# accept: move generated output to expected results
#
# Adding a test case.
# Each feature should get its own set of tests in its own suitably
# named makefile which should be added to SUBFILES to hook it in.
# named makefile (*.mk), with its own set of expected results (*.exp),
# and it should be added to the TESTNAMES list.
#
srcdir= @srcdir@
@ -19,10 +20,11 @@ srcdir= @srcdir@
.MAIN: all
UNIT_TESTS:= ${srcdir}
.PATH: ${UNIT_TESTS}
# Simple sub-makefiles - we run them as a black box
# keep the list sorted.
SUBFILES= \
# Each test is in a sub-makefile.
# Keep the list sorted.
TESTNAMES= \
comment \
cond1 \
error \
@ -42,7 +44,6 @@ SUBFILES= \
modts \
modword \
order \
phony-end \
posix \
qequals \
sunshcmd \
@ -50,23 +51,36 @@ SUBFILES= \
ternary \
unexport \
unexport-env \
varcmd
varcmd \
varmisc \
varshell
all: ${SUBFILES}
# these tests were broken by referting POSIX chanegs
STRICT_POSIX_TESTS = \
escape \
impsrc \
phony-end \
posix1 \
suffixes
# Override make flags for certain tests
flags.doterror=
flags.order=-j1
# the tests are actually done with sub-makes.
.PHONY: ${SUBFILES}
.PRECIOUS: ${SUBFILES}
${SUBFILES}:
-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
OUTFILES= ${TESTNAMES:S/$/.out/}
all: ${OUTFILES}
CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
CLEANFILES += obj*.[och] lib*.a # posix1.mk
CLEANFILES += issue* .[ab]* # suffixes.mk
CLEANRECURSIVE += dir dummy # posix1.mk
clean:
rm -f *.out *.fail *.core
.-include <obj.mk>
rm -f ${CLEANFILES}
.if !empty(CLEANRECURSIVE)
rm -rf ${CLEANRECURSIVE}
.endif
TEST_MAKE?= ${.MAKE}
TOOL_SED?= sed
@ -81,22 +95,56 @@ LANG= C
.export LANG LC_ALL
.endif
# The driver.
# some tests need extra post-processing
SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \
-e '/command/s,No such.*,not found,'
# the tests are actually done with sub-makes.
.SUFFIXES: .mk .rawout .out
.mk.rawout:
@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
-@cd ${.OBJDIR} && \
{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
@mv ${.TARGET}.tmp ${.TARGET}
# We always pretend .MAKE was called 'make'
# and strip ${.CURDIR}/ from the output
# and replace anything after 'stopped in' with unit-tests
# so the results can be compared.
test:
@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
${TOOL_TR} -d '\015' | \
${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[^:]*:,make:,' \
-e '/stopped/s, /.*, unit-tests,' \
-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
.rawout.out:
@echo postprocess ${.TARGET}
@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
-e 's,${TEST_MAKE:C/\./\\\./g},make,' \
-e '/stopped/s, /.*, unit-tests,' \
-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \
< ${.IMPSRC} > ${.TARGET}.tmp
@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
@mv ${.TARGET}.tmp ${.TARGET}
# Compare all output files
test: ${OUTFILES} .PHONY
@failed= ; \
for test in ${TESTNAMES}; do \
${TOOL_DIFF} -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
|| failed="$${failed}$${failed:+ }$${test}" ; \
done ; \
if [ -n "$${failed}" ]; then \
echo "Failed tests: $${failed}" ; false ; \
else \
echo "All tests passed" ; \
fi
accept:
mv test.out ${srcdir}/test.exp
@for test in ${TESTNAMES}; do \
cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
|| { echo "Replacing $${test}.exp" ; \
cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
done
.if exists(${TEST_MAKE})
${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
.endif
.-include <obj.mk>

5
unit-tests/comment.exp Normal file
View File

@ -0,0 +1,5 @@
comment testing start
this is foo
This is how a comment looks: # comment
comment testing done
exit status 0

23
unit-tests/cond1.exp Normal file
View File

@ -0,0 +1,23 @@
make: "cond1.mk" line 75: warning: extra else
make: "cond1.mk" line 85: warning: extra else
2 is prime
A='other' B='unknown' C='clever' o='no,no'
Passed:
var
("var")
(var != var)
var != var
!((var != var) && defined(name))
var == quoted
1 is not prime
2 is prime
3 is prime
4 is not prime
5 is prime
make: warning: String comparison operator should be either == or !=
make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
OK
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: cond1,v 1.1.1.3 2011/03/06 00:04:58 sjg Exp $
# $Id: cond1.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
# hard code these!
TEST_UNAME_S= NetBSD

9
unit-tests/doterror.exp Normal file
View File

@ -0,0 +1,9 @@
At first, I am
happy
and now: sad
.ERROR: Looks like 'sad' is upset.
*** Error code 1
Stop.
make: stopped in unit-tests
exit status 1

View File

@ -1,4 +1,4 @@
# $Id: doterror,v 1.1.1.1 2010/04/08 17:43:00 sjg Exp $
# $Id: doterror.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
.BEGIN:

30
unit-tests/dotwait.exp Normal file
View File

@ -0,0 +1,30 @@
simple.1
simple.1
simple.2
simple.2
recursive.1.1.*
recursive.1.1.*
recursive.1.1.*
recursive.1.1.*
recursive.1.99
recursive.1.99
recursive.2.1.*
recursive.2.1.*
recursive.2.1.*
recursive.2.1.*
recursive.2.99
recursive.2.99
shared.0
shared.0
shared.1.99
shared.1.99
shared.2.1
shared.2.1
shared.2.99
shared.2.99
make: Graph cycles through `cycle.2.99'
make: Graph cycles through `cycle.2.98'
make: Graph cycles through `cycle.2.97'
cycle.1.99
cycle.1.99
exit status 0

View File

@ -1,4 +1,4 @@
# $NetBSD: dotwait,v 1.1 2006/02/26 22:45:46 apb Exp $
# $NetBSD: dotwait.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
THISMAKEFILE:= ${.PARSEDIR}/${.PARSEFILE}

4
unit-tests/error.exp Normal file
View File

@ -0,0 +1,4 @@
make: "error.mk" line 3: just FYI
make: "error.mk" line 4: warning: this could be serious
make: "error.mk" line 5: this is fatal
exit status 1

View File

@ -1,4 +1,4 @@
# $Id: error,v 1.1.1.2 2010/05/24 23:36:03 sjg Exp $
# $Id: error.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
.info just FYI
.warning this could be serious

104
unit-tests/escape.exp Normal file
View File

@ -0,0 +1,104 @@
var-1bs
printf "%s=:%s:\n" VAR1BS 111\\111; printf "%s=:%s:\n" VAR1BSa 111\\aaa; printf "%s=:%s:\n" VAR1BSA 111\\aaa; printf "%s=:%s:\n" VAR1BSda 111\\\$\{a\}; printf "%s=:%s:\n" VAR1BSdA 111\\\$\{A\}; printf "%s=:%s:\n" VAR1BSc 111\#\ backslash\ escapes\ comment\ char,\ so\ this\ is\ part\ of\ the\ value; printf "%s=:%s:\n" VAR1BSsc 111\\\ ;
VAR1BS=:111\111:
VAR1BSa=:111\aaa:
VAR1BSA=:111\aaa:
VAR1BSda=:111\${a}:
VAR1BSdA=:111\${A}:
VAR1BSc=:111# backslash escapes comment char, so this is part of the value:
VAR1BSsc=:111\ :
var-2bs
printf "%s=:%s:\n" VAR2BS 222\\\\222; printf "%s=:%s:\n" VAR2BSa 222\\\\aaa; printf "%s=:%s:\n" VAR2BSA 222\\\\aaa; printf "%s=:%s:\n" VAR2BSda 222\\\\\$\{a\}; printf "%s=:%s:\n" VAR2BSdA 222\\\\\$\{A\}; printf "%s=:%s:\n" VAR2BSc 222\\\\; printf "%s=:%s:\n" VAR2BSsc 222\\\\;
VAR2BS=:222\\222:
VAR2BSa=:222\\aaa:
VAR2BSA=:222\\aaa:
VAR2BSda=:222\\${a}:
VAR2BSdA=:222\\${A}:
VAR2BSc=:222\\:
VAR2BSsc=:222\\:
var-1bsnl
printf "%s=:%s:\n" VAR1BSNL 111\ 111; printf "%s=:%s:\n" VAR1BSNLa 111\ aaa; printf "%s=:%s:\n" VAR1BSNLA 111\ aaa; printf "%s=:%s:\n" VAR1BSNLda 111\ \$\{a\}; printf "%s=:%s:\n" VAR1BSNLdA 111\ \$\{A\}; printf "%s=:%s:\n" VAR1BSNLc 111; printf "%s=:%s:\n" VAR1BSNLsc 111;
VAR1BSNL=:111 111:
VAR1BSNLa=:111 aaa:
VAR1BSNLA=:111 aaa:
VAR1BSNLda=:111 ${a}:
VAR1BSNLdA=:111 ${A}:
VAR1BSNLc=:111:
VAR1BSNLsc=:111:
var-2bsnl
printf "%s=:%s:\n" VAR2BSNL 222\\\\; printf "%s=:%s:\n" VAR2BSNLa 222\\\\; printf "%s=:%s:\n" VAR2BSNLA 222\\\\; printf "%s=:%s:\n" VAR2BSNLda 222\\\\; printf "%s=:%s:\n" VAR2BSNLdA 222\\\\; printf "%s=:%s:\n" VAR2BSNLc 222\\\\; printf "%s=:%s:\n" VAR2BSNLsc 222\\\\;
VAR2BSNL=:222\\:
VAR2BSNLa=:222\\:
VAR2BSNLA=:222\\:
VAR2BSNLda=:222\\:
VAR2BSNLdA=:222\\:
VAR2BSNLc=:222\\:
VAR2BSNLsc=:222\\:
var-3bsnl
printf "%s=:%s:\n" VAR3BSNL 333\\\\\ 333=; printf "%s=:%s:\n" VAR3BSNLa 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLA 333\\\\\ aaa=; printf "%s=:%s:\n" VAR3BSNLda 333\\\\\ \$\{a\}=; printf "%s=:%s:\n" VAR3BSNLdA 333\\\\\ \$\{A\}=; printf "%s=:%s:\n" VAR3BSNLc 333\\\\; printf "%s=:%s:\n" VAR3BSNLsc 333\\\\;
VAR3BSNL=:333\\ 333=:
VAR3BSNLa=:333\\ aaa=:
VAR3BSNLA=:333\\ aaa=:
VAR3BSNLda=:333\\ ${a}=:
VAR3BSNLdA=:333\\ ${A}=:
VAR3BSNLc=:333\\:
VAR3BSNLsc=:333\\:
var-1bsnl-space
printf "%s=:%s:\n" VAR1BSNL00 first\ line; printf "%s=:%s:\n" VAR1BSNL0 first\ line\ no\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLs first\ line\ one\ space\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLss first\ line\ two\ spaces\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLt first\ line\ one\ tab\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLtt first\ line\ two\ tabs\ on\ second\ line; printf "%s=:%s:\n" VAR1BSNLxx first\ line\ many\ spaces\ and\ tabs\ \[\ \ \ \ \]\ on\ second\ line;
VAR1BSNL00=:first line:
VAR1BSNL0=:first line no space on second line:
VAR1BSNLs=:first line one space on second line:
VAR1BSNLss=:first line two spaces on second line:
VAR1BSNLt=:first line one tab on second line:
VAR1BSNLtt=:first line two tabs on second line:
VAR1BSNLxx=:first line many spaces and tabs [ ] on second line:
cmd-1bsnl
echo :'first line\
#second line without space\
third line':
:first line\
#second line without space\
third line:
echo :'first line\
second line spaces should be retained':
:first line\
second line spaces should be retained:
echo :'first line\
second line tab should be elided':
:first line\
second line tab should be elided:
echo :'first line\
only one tab should be elided, second tab remains'
:first line\
only one tab should be elided, second tab remains
cmd-1bsnl-eof
echo :'command ending with backslash-newline'; \
:command ending with backslash-newline
cmd-2bsnl
echo take one\\
take one\
echo take two\\
take two\
echo take three\\
take three\
cmd-3bsnl
echo :'first line\\\
#second line without space\\\
third line':
:first line\\\
#second line without space\\\
third line:
echo :'first line\\\
second line spaces should be retained':
:first line\\\
second line spaces should be retained:
echo :'first line\\\
second line tab should be elided':
:first line\\\
second line tab should be elided:
echo :'first line\\\
only one tab should be elided, second tab remains'
:first line\\\
only one tab should be elided, second tab remains
exit status 0

246
unit-tests/escape.mk Normal file
View File

@ -0,0 +1,246 @@
# $Id: escape.mk,v 1.1.1.2 2014/11/06 01:40:37 sjg Exp $
#
# Test backslash escaping.
# Extracts from the POSIX 2008 specification
# <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html>:
#
# Comments start with a <number-sign> ( '#' ) and continue until an
# unescaped <newline> is reached.
#
# When an escaped <newline> (one preceded by a <backslash>) is found
# anywhere in the makefile except in a command line, an include
# line, or a line immediately preceding an include line, it shall
# be replaced, along with any leading white space on the following
# line, with a single <space>.
#
# When an escaped <newline> is found in a command line in a
# makefile, the command line shall contain the <backslash>, the
# <newline>, and the next line, except that the first character of
# the next line shall not be included if it is a <tab>.
#
# When an escaped <newline> is found in an include line or in a
# line immediately preceding an include line, the behavior is
# unspecified.
#
# Notice that the behaviour of <backslash><backslash> or
# <backslash><anything other than newline> is not mentioned. I think
# this implies that <backslash> should be taken literally everywhere
# except before <newline>.
#
# Our practice, despite what POSIX might say, is that "\#"
# in a variable assignment stores "#" as part of the value.
# The "\" is not taken literally, and the "#" does not begin a comment.
#
# Also, our practice is that an even number of backslashes before a
# newline in a variable assignment simply stores the backslashes as part
# of the value, and treats the newline as though it was not escaped.
# Similarly, ann even number of backslashes before a newline in a
# command simply uses the backslashes as part of the command test, but
# does not escape the newline. This is compatible with GNU make.
all: .PHONY
# We will add dependencies like "all: yet-another-test" later.
# Some variables to be expanded in tests
#
a = aaa
A = ${a}
# Backslash at end of line in a comment\
should continue the comment. \
# This is also tested in comment.mk.
__printvars: .USE .MADE
@echo ${.TARGET}
${.ALLSRC:@v@ printf "%s=:%s:\n" ${v:Q} ${${v}:Q}; @}
# Embedded backslash in variable should be taken literally.
#
VAR1BS = 111\111
VAR1BSa = 111\${a}
VAR1BSA = 111\${A}
VAR1BSda = 111\$${a}
VAR1BSdA = 111\$${A}
VAR1BSc = 111\# backslash escapes comment char, so this is part of the value
VAR1BSsc = 111\ # This is a comment. Value ends with <backslash><space>
all: var-1bs
var-1bs: .PHONY __printvars VAR1BS VAR1BSa VAR1BSA VAR1BSda VAR1BSdA \
VAR1BSc VAR1BSsc
# Double backslash in variable should be taken as two literal backslashes.
#
VAR2BS = 222\\222
VAR2BSa = 222\\${a}
VAR2BSA = 222\\${A}
VAR2BSda = 222\\$${a}
VAR2BSdA = 222\\$${A}
VAR2BSc = 222\\# backslash does not escape comment char, so this is a comment
VAR2BSsc = 222\\ # This is a comment. Value ends with <backslash><backslash>
all: var-2bs
var-2bs: .PHONY __printvars VAR2BS VAR2BSa VAR2BSA VAR2BSda VAR2BSdA \
VAR2BSc VAR2BSsc
# Backslash-newline in a variable setting is replaced by a single space.
#
VAR1BSNL = 111\
111
VAR1BSNLa = 111\
${a}
VAR1BSNLA = 111\
${A}
VAR1BSNLda = 111\
$${a}
VAR1BSNLdA = 111\
$${A}
VAR1BSNLc = 111\
# this should be processed as a comment
VAR1BSNLsc = 111\
# this should be processed as a comment
all: var-1bsnl
var-1bsnl: .PHONY
var-1bsnl: .PHONY __printvars \
VAR1BSNL VAR1BSNLa VAR1BSNLA VAR1BSNLda VAR1BSNLdA \
VAR1BSNLc VAR1BSNLsc
# Double-backslash-newline in a variable setting.
# Both backslashes should be taken literally, and the newline is NOT escaped.
#
# The second lines below each end with '=' so that they will not
# generate syntax errors regardless of whether or not they are
# treated as part of the value.
#
VAR2BSNL = 222\\
222=
VAR2BSNLa = 222\\
${a}=
VAR2BSNLA = 222\\
${A}=
VAR2BSNLda = 222\\
$${a}=
VAR2BSNLdA = 222\\
$${A}=
VAR2BSNLc = 222\\
# this should be processed as a comment
VAR2BSNLsc = 222\\
# this should be processed as a comment
all: var-2bsnl
var-2bsnl: .PHONY __printvars \
VAR2BSNL VAR2BSNLa VAR2BSNLA VAR2BSNLda VAR2BSNLdA \
VAR2BSNLc VAR2BSNLsc
# Triple-backslash-newline in a variable setting.
# First two should be taken literally, and last should escape the newline.
#
# The second lines below each end with '=' so that they will not
# generate syntax errors regardless of whether or not they are
# treated as part of the value.
#
VAR3BSNL = 333\\\
333=
VAR3BSNLa = 333\\\
${a}=
VAR3BSNLA = 333\\\
${A}=
VAR3BSNLda = 333\\\
$${a}=
VAR3BSNLdA = 333\\\
$${A}=
VAR3BSNLc = 333\\\
# this should be processed as a comment
VAR3BSNLsc = 333\\\
# this should be processed as a comment
all: var-3bsnl
var-3bsnl: .PHONY __printvars \
VAR3BSNL VAR3BSNLa VAR3BSNLA VAR3BSNLda VAR3BSNLdA \
VAR3BSNLc VAR3BSNLsc
# Backslash-newline in a variable setting, plus any amount of white space
# on the next line, is replaced by a single space.
#
VAR1BSNL00= first line\
# above line is entirely empty, and this is a comment
VAR1BSNL0= first line\
no space on second line
VAR1BSNLs= first line\
one space on second line
VAR1BSNLss= first line\
two spaces on second line
VAR1BSNLt= first line\
one tab on second line
VAR1BSNLtt= first line\
two tabs on second line
VAR1BSNLxx= first line\
many spaces and tabs [ ] on second line
all: var-1bsnl-space
var-1bsnl-space: .PHONY __printvars \
VAR1BSNL00 VAR1BSNL0 VAR1BSNLs VAR1BSNLss VAR1BSNLt VAR1BSNLtt \
VAR1BSNLxx
# Backslash-newline in a command is retained.
#
# The "#" in "# second line without space" makes it a comment instead
# of a syntax error if the preceding line is parsed incorretly.
# The ":" in "third line':" makes it look like the start of a
# target instead of a syntax error if the first line is parsed incorrectly.
#
all: cmd-1bsnl
cmd-1bsnl: .PHONY
@echo ${.TARGET}
echo :'first line\
#second line without space\
third line':
echo :'first line\
second line spaces should be retained':
echo :'first line\
second line tab should be elided':
echo :'first line\
only one tab should be elided, second tab remains'
# When backslash-newline appears at the end of a command script,
# both the backslash and the newline should be passed to the shell.
# The shell should elide the backslash-newline.
#
all: cmd-1bsnl-eof
cmd-1bsnl-eof:
@echo ${.TARGET}
echo :'command ending with backslash-newline'; \
# above line must be blank
# Double-backslash-newline in a command.
# Both backslashes are retained, but the newline is not escaped.
# XXX: This may differ from POSIX, but matches gmake.
#
# When make passes two backslashes to the shell, the shell will pass one
# backslash to the echo commant.
#
all: cmd-2bsnl
cmd-2bsnl: .PHONY
@echo ${.TARGET}
echo take one\\
# this should be a comment
echo take two\\
echo take three\\
# Triple-backslash-newline in a command is retained.
#
all: cmd-3bsnl
cmd-3bsnl: .PHONY
@echo ${.TARGET}
echo :'first line\\\
#second line without space\\\
third line':
echo :'first line\\\
second line spaces should be retained':
echo :'first line\\\
second line tab should be elided':
echo :'first line\\\
only one tab should be elided, second tab remains'

12
unit-tests/export-all.exp Normal file
View File

@ -0,0 +1,12 @@
UT_ALL=even this gets exported
UT_BADDIR=unit-tests
UT_DOLLAR=This is $UT_FU
UT_F=fine
UT_FOO=foobar is fubar
UT_FU=fubar
UT_NO=all
UT_OK=good
UT_OKDIR=unit-tests
UT_TEST=export-all
UT_ZOO=hoopie
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: export-all,v 1.1.1.2 2010/04/21 04:26:14 sjg Exp $
# $Id: export-all.mk,v 1.1.1.2 2015/04/10 20:43:38 sjg Exp $
UT_OK=good
UT_F=fine
@ -17,7 +17,7 @@ UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T}
.export
.include "export"
.include "export.mk"
UT_TEST=export-all
UT_ALL=even this gets exported

View File

@ -0,0 +1,9 @@
make:
UT_TEST=export-env.mk
UT_ENV=not-exported
UT_EXP=not-exported
env:
UT_TEST=export-env.mk
UT_ENV=exported
UT_EXP=exported
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: export-env,v 1.1.1.1 2013/03/23 02:26:59 sjg Exp $
# $Id: export-env.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
# our normal .export, subsequent changes affect the environment
UT_TEST=this

6
unit-tests/export.exp Normal file
View File

@ -0,0 +1,6 @@
UT_DOLLAR=This is $UT_FU
UT_FOO=foobar is fubar
UT_FU=fubar
UT_TEST=export
UT_ZOO=hoopie
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: export,v 1.1.1.1 2007/10/08 20:30:12 sjg Exp $
# $Id: export.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
UT_TEST=export
UT_FOO=foo${BAR}

19
unit-tests/forloop.exp Normal file
View File

@ -0,0 +1,19 @@
x=one
x="two and three"
x=four
x="five"
x=-I/this
x=-I"This or that"
x=-Ithat
x="-DTHIS=\"this and that\""
cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
a=one b="two and three"
a=four b="five"
a=ONE b="TWO AND THREE"
a=FOUR b="FIVE"
We expect an error next:
make: "forloop.mk" line 38: Wrong number of words (9) in .for substitution list with 2 vars
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
OK
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: forloop,v 1.1.1.1 2012/06/19 23:30:49 sjg Exp $
# $Id: forloop.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
all: for-loop

2
unit-tests/forsubst.exp Normal file
View File

@ -0,0 +1,2 @@
.for with :S;... OK
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: forsubst,v 1.1.1.1 2009/10/07 18:53:35 sjg Exp $
# $Id: forsubst.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
all: for-subst

9
unit-tests/hash.exp Normal file
View File

@ -0,0 +1,9 @@
b2af338b
3360ac65
7747f046
9ca87054
880fe816
208fcbd3
d5d376eb
de41416c
exit status 0

13
unit-tests/impsrc.exp Normal file
View File

@ -0,0 +1,13 @@
expected: source4
actual: source4
expected: target1.x
actual: target1.x
expected: target1.y
actual: target1.y
expected: source1
actual: source1
expected: source2
actual: source2
expected: source1
actual: source1
exit status 0

43
unit-tests/impsrc.mk Normal file
View File

@ -0,0 +1,43 @@
# $NetBSD: impsrc.mk,v 1.2 2014/08/30 22:21:07 sjg Exp $
# Does ${.IMPSRC} work properly?
# It should be set, in order of precedence, to ${.TARGET} of:
# 1) the implied source of a transformation rule,
# 2) the first prerequisite from the dependency line of an explicit rule, or
# 3) the first prerequisite of an explicit rule.
#
all: target1.z target2 target3 target4
.SUFFIXES: .x .y .z
.x.y: source1
@echo 'expected: target1.x'
@echo 'actual: $<'
.y.z: source2
@echo 'expected: target1.y'
@echo 'actual: $<'
target1.y: source3
target1.x: source4
@echo 'expected: source4'
@echo 'actual: $<'
target2: source1 source2
@echo 'expected: source1'
@echo 'actual: $<'
target3: source1
target3: source2 source3
@echo 'expected: source2'
@echo 'actual: $<'
target4: source1
target4:
@echo 'expected: source1'
@echo 'actual: $<'
source1 source2 source3 source4:

1
unit-tests/misc.exp Normal file
View File

@ -0,0 +1 @@
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: misc,v 1.1.1.1 2011/03/06 00:04:58 sjg Exp $
# $Id: misc.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
.if !exists(${.CURDIR}/)
.warning ${.CURDIR}/ doesn't exist ?

16
unit-tests/moderrs.exp Normal file
View File

@ -0,0 +1,16 @@
Expect: Unknown modifier 'Z'
make: Unknown modifier 'Z'
VAR:Z=
Expect: Unknown modifier 'Z'
make: Unknown modifier 'Z'
VAR:Z=
Expect: Unclosed variable specification for VAR
make: Unclosed variable specification (expecting '}') for "VAR" (value "Thevariable") modifier S
VAR:S,V,v,=Thevariable
Expect: Unclosed variable specification for VAR
make: Unclosed variable specification after complex modifier (expecting '}') for VAR
VAR:S,V,v,=Thevariable
Expect: Unclosed substitution for VAR (, missing)
make: Unclosed substitution for VAR (, missing)
VAR:S,V,v=
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: moderrs,v 1.2 2006/05/11 18:53:39 sjg Exp $
# $Id: moderrs.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
#
# various modifier error tests

17
unit-tests/modmatch.exp Normal file
View File

@ -0,0 +1,17 @@
LIB=a X_LIBS:M${LIB${LIB:tu}} is "/tmp/liba.a"
LIB=a X_LIBS:M*/lib${LIB}.a is "/tmp/liba.a"
LIB=a X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBA.A"
LIB=b X_LIBS:M${LIB${LIB:tu}} is ""
LIB=b X_LIBS:M*/lib${LIB}.a is ""
LIB=b X_LIBS:M*/lib${LIB}.a:tu is ""
LIB=c X_LIBS:M${LIB${LIB:tu}} is ""
LIB=c X_LIBS:M*/lib${LIB}.a is ""
LIB=c X_LIBS:M*/lib${LIB}.a:tu is ""
LIB=d X_LIBS:M${LIB${LIB:tu}} is "/tmp/libd.a"
LIB=d X_LIBS:M*/lib${LIB}.a is "/tmp/libd.a"
LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A"
LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a"
LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a"
LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A"
Mscanner=OK
exit status 0

10
unit-tests/modmisc.exp Normal file
View File

@ -0,0 +1,10 @@
path=':/bin:/tmp::/:.:/no/such/dir:.'
path='/bin:/tmp:/:/no/such/dir'
path='/bin:/tmp:/:/no/such/dir'
path='/bin':'/tmp':'/':'/no/such/dir'
path='/bin':'/tmp':'/':'/no/such/dir'
path_/usr/xbin=/opt/xbin/
paths=/bin /tmp / /no/such/dir /opt/xbin
PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN
The answer is 42
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: modmisc,v 1.1.1.5 2011/04/11 15:10:32 sjg Exp $
# $Id: modmisc.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
#
# miscellaneous modifier tests

11
unit-tests/modorder.exp Normal file
View File

@ -0,0 +1,11 @@
LIST = one two three four five six seven eight nine ten
LIST:O = eight five four nine one seven six ten three two
LIST:Ox = Ok
LIST:O:Ox = Ok
LISTX = Ok
LISTSX = Ok
make: Bad modifier `:OX' for LIST
BADMOD 1 = }
make: Bad modifier `:OxXX' for LIST
BADMOD 2 = XX}
exit status 0

View File

@ -1,4 +1,4 @@
# $NetBSD: modorder,v 1.2 2007/10/05 15:27:46 sjg Exp $
# $NetBSD: modorder.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
LIST= one two three four five six seven eight nine ten
LISTX= ${LIST:Ox}

33
unit-tests/modts.exp Normal file
View File

@ -0,0 +1,33 @@
LIST="one two three four five six"
LIST:ts,="one,two,three,four,five,six"
LIST:ts/:tu="ONE/TWO/THREE/FOUR/FIVE/SIX"
LIST:ts::tu="ONE:TWO:THREE:FOUR:FIVE:SIX"
LIST:ts:tu="ONETWOTHREEFOURFIVESIX"
LIST:tu:ts/="ONE/TWO/THREE/FOUR/FIVE/SIX"
LIST:ts:="one:two:three:four:five:six"
LIST:ts="onetwothreefourfivesix"
LIST:ts:S/two/2/="one2threefourfivesix"
LIST:S/two/2/:ts="one2threefourfivesix"
LIST:ts/:S/two/2/="one/2/three/four/five/six"
Pretend the '/' in '/n' etc. below are back-slashes.
LIST:ts/n="one
two
three
four
five
six"
LIST:ts/t="one two three four five six"
LIST:ts/012:tu="ONE
TWO
THREE
FOUR
FIVE
SIX"
make: Bad modifier `:tx' for LIST
LIST:tx="}"
make: Bad modifier `:ts\x' for LIST
LIST:ts/x:tu="\x:tu}"
FU_mod-ts="a/b/cool"
FU_mod-ts:ts:T="cool" == cool?
B.${AAA:ts}="Baaa" == Baaa?
exit status 0

122
unit-tests/modword.exp Normal file
View File

@ -0,0 +1,122 @@
make: Bad modifier `:[]' for LIST
LIST:[]="" is an error
LIST:[0]="one two three four five six"
LIST:[0x0]="one two three four five six"
LIST:[000]="one two three four five six"
LIST:[*]="one two three four five six"
LIST:[@]="one two three four five six"
LIST:[0]:C/ /,/="one,two three four five six"
LIST:[0]:C/ /,/g="one,two,three,four,five,six"
LIST:[0]:C/ /,/1g="one,two,three,four,five,six"
LIST:[*]:C/ /,/="one,two three four five six"
LIST:[*]:C/ /,/g="one,two,three,four,five,six"
LIST:[*]:C/ /,/1g="one,two,three,four,five,six"
LIST:[@]:C/ /,/="one two three four five six"
LIST:[@]:C/ /,/g="one two three four five six"
LIST:[@]:C/ /,/1g="one two three four five six"
LIST:[@]:[0]:C/ /,/="one,two three four five six"
LIST:[0]:[@]:C/ /,/="one two three four five six"
LIST:[@]:[*]:C/ /,/="one,two three four five six"
LIST:[*]:[@]:C/ /,/="one two three four five six"
EMPTY=""
EMPTY:[#]="1" == 1 ?
ESCAPEDSPACE="\ "
ESCAPEDSPACE:[#]="1" == 1 ?
REALLYSPACE=" "
REALLYSPACE:[#]="1" == 1 ?
LIST:[#]="6"
LIST:[0]:[#]="1" == 1 ?
LIST:[*]:[#]="1" == 1 ?
LIST:[@]:[#]="6"
LIST:[1]:[#]="1"
LIST:[1..3]:[#]="3"
EMPTY:[1]=""
ESCAPEDSPACE="\ "
ESCAPEDSPACE:[1]="\ "
REALLYSPACE=" "
REALLYSPACE:[1]="" == "" ?
REALLYSPACE:[*]:[1]=" " == " " ?
LIST:[1]="one"
make: Bad modifier `:[1.]' for LIST
LIST:[1.]="" is an error
make: Bad modifier `:[1].' for LIST
LIST:[1].="}" is an error
LIST:[2]="two"
LIST:[6]="six"
LIST:[7]=""
LIST:[999]=""
make: Bad modifier `:[-]' for LIST
LIST:[-]="" is an error
make: Bad modifier `:[--]' for LIST
LIST:[--]="" is an error
LIST:[-1]="six"
LIST:[-2]="five"
LIST:[-6]="one"
LIST:[-7]=""
LIST:[-999]=""
LONGLIST:[17]="17"
LONGLIST:[0x11]="17"
LONGLIST:[021]="17"
LIST:[0]:[1]="one two three four five six"
LIST:[*]:[1]="one two three four five six"
LIST:[@]:[1]="one"
LIST:[0]:[2]=""
LIST:[*]:[2]=""
LIST:[@]:[2]="two"
LIST:[*]:C/ /,/:[2]=""
LIST:[*]:C/ /,/:[*]:[2]=""
LIST:[*]:C/ /,/:[@]:[2]="three"
make: Bad modifier `:[1.]' for LIST
LIST:[1.]="" is an error
make: Bad modifier `:[1..]' for LIST
LIST:[1..]="" is an error
LIST:[1..1]="one"
make: Bad modifier `:[1..1.]' for LIST
LIST:[1..1.]="" is an error
LIST:[1..2]="one two"
LIST:[2..1]="two one"
LIST:[3..-2]="three four five"
LIST:[-4..4]="three four"
make: Bad modifier `:[0..1]' for LIST
LIST:[0..1]="" is an error
make: Bad modifier `:[-1..0]' for LIST
LIST:[-1..0]="" is an error
LIST:[-1..1]="six five four three two one"
LIST:[0..0]="one two three four five six"
LIST:[3..99]="three four five six"
LIST:[-3..-99]="four three two one"
LIST:[-99..-3]="one two three four"
HASH="#" == "#" ?
LIST:[${HASH}]="6"
LIST:[${ZERO}]="one two three four five six"
LIST:[${ZERO}x${ONE}]="one"
LIST:[${ONE}]="one"
LIST:[${MINUSONE}]="six"
LIST:[${STAR}]="one two three four five six"
LIST:[${AT}]="one two three four five six"
make: Bad modifier `:[${EMPTY' for LIST
LIST:[${EMPTY}]="" is an error
LIST:[${LONGLIST:[21]:S/2//}]="one"
LIST:[${LIST:[#]}]="six"
LIST:[${LIST:[${HASH}]}]="six"
LIST:S/ /,/="one two three four five six"
LIST:S/ /,/W="one,two three four five six"
LIST:S/ /,/gW="one,two,three,four,five,six"
EMPTY:S/^/,/=","
EMPTY:S/^/,/W=","
LIST:C/ /,/="one two three four five six"
LIST:C/ /,/W="one,two three four five six"
LIST:C/ /,/gW="one,two,three,four,five,six"
EMPTY:C/^/,/=","
EMPTY:C/^/,/W=","
LIST:tW="one two three four five six"
LIST:tw="one two three four five six"
LIST:tW:C/ /,/="one,two three four five six"
LIST:tW:C/ /,/g="one,two,three,four,five,six"
LIST:tW:C/ /,/1g="one,two,three,four,five,six"
LIST:tw:C/ /,/="one two three four five six"
LIST:tw:C/ /,/g="one two three four five six"
LIST:tw:C/ /,/1g="one two three four five six"
LIST:tw:tW:C/ /,/="one,two three four five six"
LIST:tW:tw:C/ /,/="one two three four five six"
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: modword,v 1.1.1.1 2003/09/28 17:01:48 sjg Exp $
# $Id: modword.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
#
# Test behaviour of new :[] modifier

4
unit-tests/order.exp Normal file
View File

@ -0,0 +1,4 @@
Making the.c
Making the.h
Making the.o from the.h the.c
exit status 0

View File

@ -1,4 +1,4 @@
# $NetBSD: order,v 1.1 2012/11/09 19:08:28 sjg Exp $
# $NetBSD: order.mk,v 1.1 2014/08/21 13:44:51 apb Exp $
# Test that .ORDER is handled correctly.
# The explicit dependency the.o: the.h will make us examine the.h

6
unit-tests/phony-end.exp Normal file
View File

@ -0,0 +1,6 @@
.TARGET="phony" .PREFIX="phony" .IMPSRC=""
.TARGET="all" .PREFIX="all" .IMPSRC="phony"
.TARGET="ok" .PREFIX="ok" .IMPSRC=""
.TARGET="also.ok" .PREFIX="also.ok" .IMPSRC=""
.TARGET="bug" .PREFIX="bug" .IMPSRC=""
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: phony-end,v 1.1.1.1 2011/10/01 17:19:39 sjg Exp $
# $Id: phony-end.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
all ok also.ok bug phony:
@echo '${.TARGET .PREFIX .IMPSRC:L:@v@$v="${$v}"@}'

23
unit-tests/posix.exp Normal file
View File

@ -0,0 +1,23 @@
Posix says we should execute the command as if run by system(3)
Expect 'Hello,' and 'World!'
Hello,
World!
a command
a command prefixed by '+' executes even with -n
another command
make -n
echo a command
echo "a command prefixed by '+' executes even with -n"
a command prefixed by '+' executes even with -n
echo another command
make -n -j1
{ echo a command
} || exit $?
echo "a command prefixed by '+' executes even with -n"
a command prefixed by '+' executes even with -n
{ echo another command
} || exit $?
Now we expect an error...
*** Error code 1 (continuing)
`all' not remade because of errors.
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: posix,v 1.1.1.1 2004/05/08 16:45:39 sjg Exp $
# $Id: posix.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
all: x plus subs err

185
unit-tests/posix1.exp Normal file
View File

@ -0,0 +1,185 @@
${VAR} = "foo bar baz"
a
b
c
foo baR baz, bar baz, foo bar baz, fooadd baradd bazadd
mkdir -p 'dir'
touch 'dir/obj_1.h'
mkdir -p 'dir'
printf '#include "obj_1.h"\nconst char* obj_1 = "dir/obj_1.c";\n' \
>'dir/obj_1.c'
Local variables
${@}="dir/obj_1.o" ${<}="dir/obj_1.c"
${*}="dir/obj_1" ${?}="dir/obj_1.h dir/obj_1.c"
${%}=""
Directory and filename parts of local variables
${@D}="dir" ${@F}="obj_1.o"
${<D}="dir" ${<F}="obj_1.c"
${*D}="dir" ${*F}="obj_1"
${?D}="dir dir" ${?F}="obj_1.h obj_1.c"
${%D}="" ${%F}=""
Local variable substitutions
${@:.o=}="dir/obj_1" ${<:.c=.C}="dir/obj_1.C"
${*:=.h}="dir/obj_1.h" ${?:.h=.H}="dir/obj_1.H dir/obj_1.c"
${%:=}=""
Target with suffix transformations
${@D:=append}="dirappend"
${@F:.o=.O}="obj_1.O"
Implied source with suffix transformations
${<D:r=rr}="dirr"
${<F:.c=.C}="obj_1.C"
Suffixless target with suffix transformations
${*D:.=dot}="dir"
${*F:.a=}="obj_1"
Out-of-date dependencies with suffix transformations
${?D:ir=}="d d"
${?F:.h=.H}="obj_1.H obj_1.c"
Member with suffix transformations
${%D:.=}=""
${%F:${VAR2}=${VAR}}=""
cc -c -o 'dir/obj_1.o' 'dir/obj_1.c'
mkdir -p '.'
touch 'dummy'
Local variables
${@}="lib.a" ${<}="dir/obj_1.o"
${*}="obj1" ${?}="dir/obj_1.o dummy"
${%}="obj1.o"
Directory and filename parts of local variables
${@D}="." ${@F}="lib.a"
${<D}="dir" ${<F}="obj_1.o"
${*D}="." ${*F}="obj1"
${?D}="dir ." ${?F}="obj_1.o dummy"
${%D}="." ${%F}="obj1.o"
Local variable substitutions
${@:.o=}="lib.a" ${<:.c=.C}="dir/obj_1.o"
${*:=.h}="obj1.h" ${?:.h=.H}="dir/obj_1.o dummy"
${%:=}="obj1.o"
Target with suffix transformations
${@D:=append}=".append"
${@F:.o=.O}="lib.a"
Implied source with suffix transformations
${<D:r=rr}="dirr"
${<F:.c=.C}="obj_1.o"
Suffixless target with suffix transformations
${*D:.=dot}="dot"
${*F:.a=}="obj1"
Out-of-date dependencies with suffix transformations
${?D:ir=}="d ."
${?F:.h=.H}="obj_1.o dummy"
Member with suffix transformations
${%D:.=}=""
${%F:${VAR2}=${VAR}}="obj1foo bar baz"
cp 'dir/obj_1.o' 'obj1.o'
ar -rcv 'lib.a' 'obj1.o'
a - obj1.o
rm -f 'obj1.o'
mkdir -p '.'
printf '#include "obj_2.h"\nconst char* obj_2 = "obj_2.c";\n' \
>'obj_2.c'
mkdir -p '.'
touch 'obj_2.h'
Local variables
${@}="obj2.o" ${<}="obj_2.c"
${*}="obj2" ${?}="obj_2.c obj_2.h dir/obj_1.h"
${%}=""
Directory and filename parts of local variables
${@D}="." ${@F}="obj2.o"
${<D}="." ${<F}="obj_2.c"
${*D}="." ${*F}="obj2"
${?D}=". . dir" ${?F}="obj_2.c obj_2.h obj_1.h"
${%D}="" ${%F}=""
Local variable substitutions
${@:.o=}="obj2" ${<:.c=.C}="obj_2.C"
${*:=.h}="obj2.h" ${?:.h=.H}="obj_2.c obj_2.H dir/obj_1.H"
${%:=}=""
Target with suffix transformations
${@D:=append}=".append"
${@F:.o=.O}="obj2.O"
Implied source with suffix transformations
${<D:r=rr}="."
${<F:.c=.C}="obj_2.C"
Suffixless target with suffix transformations
${*D:.=dot}="dot"
${*F:.a=}="obj2"
Out-of-date dependencies with suffix transformations
${?D:ir=}=". . d"
${?F:.h=.H}="obj_2.c obj_2.H obj_1.H"
Member with suffix transformations
${%D:.=}=""
${%F:${VAR2}=${VAR}}=""
cc -c -o 'obj2.o' 'obj_2.c'
ar -rcv 'lib.a' 'obj2.o'
a - obj2.o
mkdir -p '.'
touch 'obj3.h'
mkdir -p 'dir'
touch 'dir/dummy'
mkdir -p '.'
printf '#include "obj3.h"\nconst char* obj3 = "obj3.c";\n' \
>'obj3.c'
Local variables
${@}="lib.a" ${<}="obj3.c"
${*}="obj3" ${?}="obj3.h dir/dummy obj3.c"
${%}="obj3.o"
Directory and filename parts of local variables
${@D}="." ${@F}="lib.a"
${<D}="." ${<F}="obj3.c"
${*D}="." ${*F}="obj3"
${?D}=". dir ." ${?F}="obj3.h dummy obj3.c"
${%D}="." ${%F}="obj3.o"
Local variable substitutions
${@:.o=}="lib.a" ${<:.c=.C}="obj3.C"
${*:=.h}="obj3.h" ${?:.h=.H}="obj3.H dir/dummy obj3.c"
${%:=}="obj3.o"
Target with suffix transformations
${@D:=append}=".append"
${@F:.o=.O}="lib.a"
Implied source with suffix transformations
${<D:r=rr}="."
${<F:.c=.C}="obj3.C"
Suffixless target with suffix transformations
${*D:.=dot}="dot"
${*F:.a=}="obj3"
Out-of-date dependencies with suffix transformations
${?D:ir=}=". d ."
${?F:.h=.H}="obj3.H dummy obj3.c"
Member with suffix transformations
${%D:.=}=""
${%F:${VAR2}=${VAR}}="obj3foo bar baz"
cc -c -o 'obj3.o' 'obj3.c'
ar -rcv 'lib.a' 'obj3.o'
a - obj3.o
rm -f 'obj3.o'
exit status 0

184
unit-tests/posix1.mk Normal file
View File

@ -0,0 +1,184 @@
# $NetBSD: posix1.mk,v 1.3 2014/08/30 22:21:08 sjg Exp $
# Keep the default suffixes from interfering, just in case.
.SUFFIXES:
all: line-continuations suffix-substitution localvars
# we need to clean for repeatable results
.BEGIN: clean
clean:
@rm -f lib.a dir/* dummy obj*
#
# Line continuations
#
# Escaped newlines and leading whitespace from the next line are replaced
# with single space, except in commands, where the escape and the newline
# are retained, but a single leading tab (if any) from the next line is
# removed. (PR 49085)
# Expect:
# ${VAR} = "foo bar baz"
# a
# b
# c
VAR = foo\
\
bar\
baz
line-continuations:
@echo '$${VAR} = "${VAR}"'
@echo 'aXbXc' | sed -e 's/X/\
/g'
#
# Suffix substitution
#
# The only variable modifier accepted by POSIX.
# ${VAR:s1=s2}: replace s1, if found, with s2 at end of each word in
# ${VAR}. s1 and s2 may contain macro expansions.
# Expect: foo baR baz, bar baz, foo bar baz, fooadd baradd bazadd
suffix-substitution:
@echo '${VAR:r=R}, ${VAR:foo=}, ${VAR:not_there=wrong}, ${VAR:=add}'
#
# Local variables: regular forms, D/F forms and suffix substitution.
#
# In the past substitutions did not work with the D/F forms and those
# forms were not available for $?. (PR 49085)
ARFLAGS = -rcv
localvars: lib.a
# $@ = target or archive name $< = implied source
# $* = target without suffix $? = sources newer than target
# $% = archive member name
LOCALS = \
"Local variables\n\
\$${@}=\"${@}\" \$${<}=\"${<}\"\n\
\$${*}=\"${*}\" \$${?}=\"${?}\"\n\
\$${%%}=\"${%}\"\n\n"
# $XD = directory part of X $XF = file part of X
# X is one of the local variables.
LOCAL_ALTERNATIVES = \
"Directory and filename parts of local variables\n\
\$${@D}=\"${@D}\" \$${@F}=\"${@F}\"\n\
\$${<D}=\"${<D}\" \$${<F}=\"${<F}\"\n\
\$${*D}=\"${*D}\" \$${*F}=\"${*F}\"\n\
\$${?D}=\"${?D}\" \$${?F}=\"${?F}\"\n\
\$${%%D}=\"${%D}\" \$${%%F}=\"${%F}\"\n\n"
# Do all kinds of meaningless substitutions on local variables to see
# if they work. Add, remove and replace things.
VAR2 = .o
VAR3 = foo
LOCAL_SUBSTITUTIONS = \
"Local variable substitutions\n\
\$${@:.o=}=\"${@:.o=}\" \$${<:.c=.C}=\"${<:.c=.C}\"\n\
\$${*:=.h}=\"${*:=.h}\" \$${?:.h=.H}=\"${?:.h=.H}\"\n\
\$${%%:=}=\"${%:=}\"\n\n"
LOCAL_ALTERNATIVE_SUBSTITUTIONS = \
"Target with suffix transformations\n\
\$${@D:=append}=\"${@D:=append}\"\n\
\$${@F:.o=.O}=\"${@F:.o=.O}\"\n\
\n\
Implied source with suffix transformations\n\
\$${<D:r=rr}=\"${<D:r=rr}\"\n\
\$${<F:.c=.C}=\"${<F:.c=.C}\"\n\
\n\
Suffixless target with suffix transformations\n\
\$${*D:.=dot}=\"${*D:.=dot}\"\n\
\$${*F:.a=}=\"${*F:.a=}\"\n\
\n\
Out-of-date dependencies with suffix transformations\n\
\$${?D:ir=}=\"${?D:ir=}\"\n\
\$${?F:.h=.H}=\"${?F:.h=.H}\"\n\
\n\
Member with suffix transformations\n\
\$${%%D:.=}=\"${%D:.=}\"\n\
\$${%%F:\$${VAR2}=\$${VAR}}=\"${%F:${VAR2}=${VAR}}\"\n\n"
.SUFFIXES: .c .o .a
# The system makefiles make the .c.a rule .PRECIOUS with a special source,
# but such a thing is not POSIX compatible. It's also somewhat useless
# in a test makefile.
.c.a:
@printf ${LOCALS}
@printf ${LOCAL_ALTERNATIVES}
@printf ${LOCAL_SUBSTITUTIONS}
@printf ${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
cc -c -o '${%}' '${<}'
ar ${ARFLAGS} '${@}' '${%}'
rm -f '${%}'
.c.o:
@printf ${LOCALS}
@printf ${LOCAL_ALTERNATIVES}
@printf ${LOCAL_SUBSTITUTIONS}
@printf ${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
cc -c -o '${@}' '${<}'
# Some of these rules are padded with useless extra dependencies just so
# that ${?} has more than one file.
lib.a: lib.a(obj1.o) lib.a(obj2.o) lib.a(obj3.o)
@ar -s '${@}'
# Explicit rule where the dependency is an inferred file. The dependency
# object's name differs from the member's because there was a bug which
# forced a dependency on member even when no such dependency was specified
# (PR 49086).
lib.a(obj1.o): dir/obj_1.o dummy
@printf ${LOCALS}
@printf ${LOCAL_ALTERNATIVES}
@printf ${LOCAL_SUBSTITUTIONS}
@printf ${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
cp 'dir/obj_1.o' '$%'
ar ${ARFLAGS} '${@}' '$%'
rm -f '$%'
# Excplicit rule where the dependency also has an explicit rule.
lib.a(obj2.o): obj2.o
ar ${ARFLAGS} '${@}' '${%}'
# Use .c.a inference with an extra dependency.
lib.a(obj3.o): obj3.h dir/dummy
# Use .c.o inference with an extra dependency.
dir/obj_1.o: dir/obj_1.h
# According to POSIX, $* is only required for inference rules and $<'s
# value is unspecified outside of inference rules. Strictly speaking
# we shouldn't be expanding them here but who cares. At least we get
# to check that the program does nothing stupid (like crash) with them.
# The C file is named differently from the object file because there
# was a bug which forced dependencies based on inference rules on all
# applicable targets (PR 49086).
obj2.o: obj_2.c obj_2.h dir/obj_1.h
@printf ${LOCALS}
@printf ${LOCAL_ALTERNATIVES}
@printf ${LOCAL_SUBSTITUTIONS}
@printf ${LOCAL_ALTERNATIVE_SUBSTITUTIONS}
cc -c -o '${@}' 'obj_2.c'
# Hey, this is make, we can make our own test data setup! obj1.c
# and obj2.c are not used, so they should not get created. They're here
# as a bait for a regression into the forced dependencies discussed earlier.
obj1.c dir/obj_1.c obj2.c obj_2.c obj3.c:
mkdir -p '${@D}'
printf '#include "${@F:.c=.h}"\nconst char* ${@F:.c=} = "${@}";\n' \
>'${@}'
dir/obj_1.h obj_2.h obj3.h dummy dir/dummy:
mkdir -p '${@D}'
touch '${@}'

2
unit-tests/qequals.exp Normal file
View File

@ -0,0 +1,2 @@
V.i386 ?= OK
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: qequals,v 1.1.1.1 2008/03/31 00:13:05 sjg Exp $
# $Id: qequals.mk,v 1.1.1.1 2014/08/30 18:57:18 sjg Exp $
M= i386
V.i386= OK

35
unit-tests/suffixes.exp Normal file
View File

@ -0,0 +1,35 @@
make: don't know how to make issue3 (continuing)
There should be no text after the colon:
touch .a
There should be no text after the colon:
touch .a.b
There should be no text after the colon:
touch .b.a
touch issue5a.c
first set
cp issue5a.c issue5a.d
touch issue5b.d
first set
cp issue5b.d issue5b.c
touch issue5c.d
first set
cp issue5c.d issue5c
touch issue5d.d
first set
cp issue5d.d issue5d.e
touch issue5e.e
first set
cp issue5e.e issue5e.d
make: don't know how to make issue6.f (continuing)
touch issue10.d
first set
cp issue10.d issue10.e
touch issue11.h
touch issue11.first
.ALLSRC: issue11.h issue11.first
cp issue11.h issue11.i
touch issue11.second
.ALLSRC: issue11.i issue11.second
cp issue11.i issue11.j
`all' not remade because of errors.
exit status 0

89
unit-tests/suffixes.mk Normal file
View File

@ -0,0 +1,89 @@
# $NetBSD: suffixes.mk,v 1.3 2014/08/30 22:21:08 sjg Exp $
# Issues from PR 49086
# Issue 3: single suffix rules remain active after .SUFFIXES is cleared
#
# There's a rule for issue3.a, but .a is no longer a known suffix when
# targets are being made, so issue3 should not get made.
all: issue3
# Issue 4: suffix rules do not become regular rules when .SUFFIXES is cleared
#
# When the rules were encountered, .a and .b were known suffices, but later
# on they were forgotten. These should get created as regular targets.
all: .a .a.b .b.a
# Issue 5: adding more suffixes does not make existing rules into suffix rules
#
# When the targets .c.d, .d.c, .d, .d.e, and .e.d were encountered, only .a,
# .b and .c were known suffixes, so all of them were regular rules. Later
# rest of the suffixes were made known, so they should all be suffix
# transformation rules.
all: issue5a.d issue5b.c issue5c issue5d.e issue5e.d
# Issue 6: transformation search can end up in an infinite loop
#
# There is no file or target from which issue6.f could be made from so
# this should fail. The bug was that because rules .e.f, .d.e and .e.d
# exist, make would try to make .f from .e and then infinitely try
# to do .e from .d and vice versa.
all: issue6.f
# Issue 10: explicit dependencies affect transformation rule selection
#
# If issue10.e is wanted and both issue10.d and issue10.f are available,
# make should choose the .d.e rule, because .d is before .f in .SUFFIXES.
# The bug was that if issue10.d had an explicit dependency on issue10.f,
# it would choose .f.e instead.
all: issue10.e
# Issue 11: sources from transformation rules are expanded incorrectly
#
# issue11.j should depend on issue11.i and issue11.second and issue11.i
# should depend on issue11.h and issue11.first. The bug was that
# the dynamic sources were expanded before ${.PREFIX} and ${.TARGET} were
# available, so they would have expanded to a null string.
all: issue11.j
# we need to clean for repeatable results
.BEGIN: clean
clean:
@rm -f issue* .[ab]*
.SUFFIXES: .a .b .c
.a .a.b .b.a:
@echo 'There should be no text after the colon: ${.IMPSRC}'
touch ${.TARGET}
.c.d .d.c .d .d.e .e.d:
@echo 'first set'
cp ${.IMPSRC} ${.TARGET}
.SUFFIXES:
.SUFFIXES: .c .d .e .f .g
.e .e.f .f.e:
@echo 'second set'
cp ${.IMPSRC} ${.TARGET}
issue3.a:
@echo 'There is a bug if you see this.'
touch ${.TARGET}
issue5a.c issue5b.d issue5c.d issue5d.d issue5e.e issue10.d issue10.f:
touch ${.TARGET}
.SUFFIXES: .h .i .j
.h.i: ${.PREFIX}.first
@echo '.ALLSRC: ${.ALLSRC}'
cp ${.IMPSRC} ${.TARGET}
.i.j: ${.PREFIX}.second
@echo '.ALLSRC: ${.ALLSRC}'
cp ${.IMPSRC} ${.TARGET}
issue11.h issue11.first issue11.second:
touch ${.TARGET}

4
unit-tests/sunshcmd.exp Normal file
View File

@ -0,0 +1,4 @@
TEST1=hello
TEST2=bye
TEST3=later
exit status 0

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