Commit graph

2770 commits

Author SHA1 Message Date
Paul Smith
5f2d114c6d Avoid interleaved $(info ) output
Since $(info ) function output is written using two system calls for
the message and the newline, it's possible for output from another
parallel make job to sneak in between them.

Reported by Paul Eggert <eggert@cs.ucla.edu>, who saw the report from
Lars Ingebrigtsen <https://bugs.gnu.org/53358>.

* src/function.c (func_error): Paul provided a fix but instead I
rewrote the entire function: it's not possible for it to be invoked
with anything other than exactly one argument so don't worry about
re-combining the arguments.
2022-02-06 18:46:32 -05:00
Paul Smith
cbe0d2e47f * tests/scripts/features/implicit_search: [SV 48643] Cleanups. 2022-02-06 18:46:32 -05:00
Paul Smith
f485881d4a * src/implicit.c (pattern_search): Use const ptrs when possible.
Change suggested by Joe Filion <joefilion4@gmail.com>
2022-02-06 18:46:32 -05:00
Paul Smith
15db387f18 * src/job.c (load_too_high): Re-enable Linux /proc/loadavg checks.
Further experimentation shows that my previous thinking that there
was a problem using this was woefully mistaken.  The value generated
by the kernel shows runn*ABLE* processes not runn*ING* processes.
* NEWS: Announce the change.
2022-02-06 18:46:32 -05:00
Paul Smith
aab51f7ef2 * doc/make.texi (Using One Shell): Correct example to use $<. 2022-02-06 18:46:29 -05:00
Jouke Witteveen
2b25eac587 * src/function.c (parse_textint): Handle ints without 0 properly.
* tests/scripts/functions/intcmp: Add tests for values without 0.
2022-01-17 19:11:59 -05:00
Paul Smith
e72c5e021f [SV 61226] Revert changes to detect missing included files
The fix for SV 60595 introduced a backward-incompatibility: rules that
purported to rebuild included files, but didn't actually do so, were
treated as errors whereas before they were ignored.  This breaks a
common idiom in makefiles where an empty recipe is created for an
included makefile so make doesn't complain if it doesn't exist.

Unfortunately this means make cannot diagnose some types of errors.

Extra tests supplied by Dmitry Goncharov <dgoncharov@users.sf.net>.

* doc/make.texi (Including Other Makefiles): Clarify this behavior.
* src/main.c (main): Don't run the new check-for-errors behavior.
* tests/scripts/features/reinvoke: Reset tests of the "old" behavior
and add new tests for this situation.
2022-01-17 18:45:47 -05:00
Paul Smith
b6a779d262 Ensure that loaded functions increment the command count
Since we don't know what a loaded function (via Guile or load) may
do, increment the command count just in case.

* src/function.c (struct file_table_entry): New adds_command bool.
(FT_ENTRY): Initialize it to 0 for built-in functions.
(expand_builtin_function): If adds_command, increment the count.
(define_new_function): Set adds_command for loaded functions.
2022-01-17 18:45:47 -05:00
Paul Smith
26f4bb89bd * src/read.c (tilde_expand): Put back '/' before returning.
Joe Filion <joefilion4@gmail.com> noted that the string is modified,
and Henrik Carlqvist <hc94@poolhem.se> noticed that it wasn't put
back in all cases.
2022-01-17 18:38:32 -05:00
Paul Smith
320714ae85 * tests/scripts/targets/INTERMEDIATE: Rewrite for new test method 2021-12-29 15:27:04 -05:00
Paul Smith
6682fbc2cb Do not force targets to be SECONDARY
In SV 43677 we forced targets to be secondary if we found an
intermediate file that was listed as a prerequisite of another
target.  This overrides .INTERMEDIATE settings, so doesn't work.
Now that we have an is_explicit flag in targets, use that instead.

* src/implicit.c (pattern_search): Remove setting of secondary.
Preserve the value of the is_explicit flag when creating a new
file target, and consider it when setting the intermediate flag.
* tests/scripts/features/patternrules: Add a test w/out INTERMEDIATE
* tests/scripts/targets/INTERMEDIATE: Add a test with INTERMEDIATE
2021-12-29 15:26:56 -05:00
Dmitry Goncharov
f2b130bda8 [SV 48643] Preserve target-specific variables on intermediate files
Target-specific variables used to define the target as "ought to
exist" so they could never be intermediate.  Now they can be, so
merge the target-specific variables from the intermediate target
so they're not lost.

* src/implicit.c (pattern_search): Use merge_variable_set_lists
to merge target-specific variables.
* tests/scripts/features/implicit_search: Add tests of target-
specific variable assignments and implicit rules.
2021-12-29 15:26:56 -05:00
Paul Smith
8aba33a8bd * README.template: Clean up patch submission information 2021-12-29 15:26:54 -05:00
Jouke Witteveen
d365bdfdbc * src/read.c (find_percent_cached): [SV 60798] Silence GCC11 warnings 2021-12-19 16:55:50 -05:00
Jouke Witteveen
f440c3ebe2 [SV 60798] Silence bogus GCC10 and GCC11 warnings
* src/main.c (main): Use a separate variable to track final character.
* src/read.c (eval): Track the semicolon position not one beyond it.
* src/variable.c (do_variable_definition): Include a default switch
case to ease the work of the exhaustiveness prover.
2021-12-19 16:55:50 -05:00
Paul Smith
3efba8a145 Update documentation with instructions for patch submission
* README.template: Add notes on how to submit patches.
* README.git: Point to the README.
* doc/make.texi: Ditto.
2021-12-19 16:55:50 -05:00
Paul Smith
e7b2f6818c Change HTTP URLs to use HTTPS instead
Also remove unnecessary tests/COPYING file.

* README.template: Change http: to https:
* README.git: Ditto
* doc/make.texi: Ditto
* doc/make.1: Ditto
* src/main.c: Ditto
* maintMakefile: Remove invalid URL
2021-12-19 16:55:50 -05:00
Paul Smith
c90db9276a * src/makeint.h: Compute INTSTR_LENGTH based on size of intmax_t
Math suggested by Edward Welbourne <edward.welbourne@qt.io>
2021-12-19 16:55:47 -05:00
Paul Eggert
7192d0ec4a Remove arbitrary limits on intcmp integers
We don't need to parse strings into C integer values to compare them.

* src/function.c (parse_textint): Find boundaries of a numeric string.
(func_intcmp): Use parse_textint() to compare integers textually.
* tests/scripts/functions/intcmp: Test with extra-large numbers.
2021-12-19 16:34:19 -05:00
Paul Smith
9230bfb9ae Use a well-known error string for out-of-bound function arguments
* src/function.c (parse_numeric): Check for empty value and error.
If we find ERANGE just print our own error, not strerror.
(func_word): Use a generic "not good" error message.
(func_wordlist): Ditto
(func_intcmp): Ditto
* tests/run_make_tests.pl: Remove code to find strerror(ERANGE)
* tests/scrips/functions/intcmp: Update the error message.
* tests/scrips/functions/word: Ditto.
2021-12-19 16:34:19 -05:00
Paul Smith
55b993ae09 * doc/make.text (Wildcards): Document that glob results are sorted. 2021-12-19 16:34:19 -05:00
Paul Smith
1d20aa7247 [SV 61621] Don't use POSIX_SPAWN_RESETIDS with posix_spawn()
When make is invoked in a environment where the user namespace is
restricted, such as under unshare(1) (on GNU/Linux), it won't be able
to find its real UID so the effective UID can't be set to it and
posix_spawn() will fail with EINVAL.

It's not less safe to run recipe jobs using the same UID values that
make was invoked with, so don't worry about this flag.

* src/job.c (child_execute_job): Don't set POSIX_SPAWN_RESETIDS flag.
2021-12-19 16:34:10 -05:00
Paul Smith
21f7ac8f47 * .gitignore: Ignore patch files. 2021-12-05 14:22:37 -05:00
U2FsdGVkX1
aa376ad638 * src/commands.c (fatal_error_signal) [W32]: Use %lu for DWORD.
* src/function.c (windows32_openpipe) [W32]: Ditto.

Copyright-paperwork-exempt: yes
2021-11-28 15:51:37 -05:00
Paul Smith
35b51df110 * NEWS: Update with author details 2021-11-28 14:34:05 -05:00
Paul Smith
e62f4cf9a2 Special-case Windows error results
* tests/scripts/features/errors: Match Windows-specific errors.
* tests/scripts/features/targetvars: Match Windows-specific errors.
* tests/scripts/misc/general4: Match Windows-specific errors.
2021-11-28 14:27:10 -05:00
Paul Smith
116767901f Convert word, wordlist, and intcmp functions to use long long
Modify make functions that parse integer values to use long long
values instead of long: on Windows long is the same as int (4 bytes)
and we don't want behavior to differ between different platforms.

* bootstrap.conf: Change strtol module to strtoll module.
* src/function.c (parse_numeric): Use strtoll() and return long long.
(func_word): Use long long.
(func_wordlist): Use long long.  Verify second argument is >= 0.
(func_intcmp): Use long long.
* src/config.ami.template: Don't define HAVE_STRTOLL.
* src/config-vms.template: Define HAVE_STRTOLL.
* src/config.W32.template: Define HAVE_STRTOLL.
* tests/run_make_tests.pl: Set $ERR_out_of_range to the proper string.
* tests/scripts/functions/word: Rework to use the new style and avoid
TAB characters.  Verify trailing whitespace is ignored.  Add a test
for a negative second argument to wordlist.  Add tests for max signed
integer values.  Use $ERR_out_of_range for the error string.
* tests/scripts/functions/intcmp: Add tests for min and max signed
integer values.  Use $ERR_out_of_range for the error string.
2021-11-28 14:27:10 -05:00
Jouke Witteveen
71eb0a8038 Introduce $(intcmp ...) for numerical comparison
Numbers can come from $(words ...), automatic variables such as
$(MAKELEVEL), from environment variables, or from shell output such as
through $(shell expr ...).  The $(intcmp ...) function allows
conditional evaluation controlled by numerical variables.

* NEWS: Announce this feature.
* doc/make.texi (Functions for Conditionals): Document 'intcmp'.
* src/function.c (func_intcmp): Create the 'intcmp' built-in function.
* tests/scripts/functions/intcmp: Test the 'intcmp' built-in function.
2021-11-28 14:27:10 -05:00
Jouke Witteveen
d9291d09b8 Use strtol() instead of atoi()
strtol() is part of C89 and a fallback is provided by gnulib.

* src/function.c (func_word, func_wordlist): Change atoi to strtol.
* test/scripts/functions/word: Add out-of-range verification testing.
2021-11-28 14:26:28 -05:00
Jouke Witteveen
f3ad572099 * src/makeint.h: Removed unused atol declaration 2021-11-27 22:05:29 -05:00
Paul Smith
cefe747e85 * src/implicit.c (pattern_search): Fix text for easier translation. 2021-11-27 22:00:12 -05:00
Paul Smith
3ecf97d3af [SV 48643] Update the implicit rule search docs
* NEWS: Announce the change.
* doc/make.texi (Implicit Rule Search): Update the definition of
"ought to exist" and add the extra step for compatibility mode.
2021-11-27 22:00:12 -05:00
Dmitry Goncharov
21d3865973 [SV 48643] Enhance "ought to exist" definition
The traditional definition of "ought to exist" in the user's manual can
lead to make choosing a poor series of chained implicit rules.  Modify
that rule so that we first attempt to resolve implicit rules by
considering targets which are only (a) targets or (b) explicit
prerequisites of the current target.

For backward-compatibility, if we don't find a solution using that
algorithm use the previous definition where "ought to exist" means
"mentioned as a prerequisite of any target".

* src/implicit.c (pattern_search): An extra argument controls whether
to perform the backward-compatible rule search or not.  If a prereq is
a target, or if it's a prerequisite of THIS target, then choose it.
If we get to the end and haven't found a match, but we have found a
potential compatibility rule, then retry with compat rules enabled.
If we're searching with compat rules enabled and we find a file
mentioned as a prerequisite of ANY target, then use it.
* tests/features/implicit_search: Provide a large suite of tests for
different steps of implicit rule search.
2021-11-27 22:00:05 -05:00
Paul Smith
29d92d4091 tests: Enhance output to contain filename/line number info
* tests/scripts/options/dash-I: Use string comparison operator.
* tests/test_driver.pl (cmd2str): New method to convert a
command line to a string with proper quoting.
* tests/run_make_tests.pl (create_command): Call cmd2str() to format
the command.  Add the filename/line number to the output.
2021-11-27 14:03:44 -05:00
Dmitry Goncharov
f8f9d371ff [SV 61042] Enhance logging of implicit rule search
Logging of implicit rule search gives limited information as to why a
given implicit rule was rejected, and if no implicit rule is found we
get the confusing "No rule to make target" result when the real issue
is that some prerequisite of some implicit rule could not be built.

Enhance logging around implicit rule search as follows:
1. The messages which refer to a rule print a description (the targets
   and prerequisites) of the rule.
2. A new message tells when a rule is rejected, along with the reason.
3. The 'Looking for an implicit rule...' message is printed for every
   prerequisite, not just the top-level target.
4. "Trying harder" message is printed, when intermediate prerequisites
   are going to be searched.
5. The 'No rule found...' and 'Found implicit rule...' messages are
   printed for every prerequisite, not just the top-level target.
6. "Ought to exist...", "Found..." or "Not found..." message is
   printed for each prerequisite.

* src/rule.h (struct rule): Remember the definition of the rule.
* src/rule.c (get_rule_defn): Compute the definition of a rule.
(install_pattern_rule): Initialize the definition to empty.
(create_pattern_rule): Ditto.
(freerule): Free the definition.
(print_rule): Use the definition when printing rules.
* src/remake.c (update_file_1): Push debug output down into
try_implicit_rule().
* src/implicit.c (try_implicit_rule): Add debugging
(pattern_search): Show the rule definition in various debug output.
Add new debug messages for implicit rule search.

Additional changes by Paul Smith <psmith@gnu.org>:

Since we usually don't need the rule definition, defer computing it
until we do.

* bootstrap.conf: Include the mempcpy Gnulib module.
* src/makeint.h (mempcpy): Declare mempcpy if not available.
* src/misc.c (mempcpy): Define mempcpy if not available.
* src/config.h-vms.template: Don't set HAVE_MEMPCPY.
* src/config.h.W32.template: Ditto.
* src/rule.h (get_rule_defn): Return the definition of a rule.
* src/rule.c (get_rule_defn): If we don't have a definition compute
it; either way return it.
* src/implicit.c (pattern_search): Rework the handling of explicit
prerequisites to pattern rules to be more clear.  There is no change
in behavior.
2021-10-18 23:00:21 -04:00
Dmitry Goncharov
f5af979357 * doc/make.texi (Special Targets): [SV 61122] Add .SECONDARY example 2021-10-17 19:08:16 -04:00
Paul Smith
76cb186732 * README.git: Update C version prerequisite 2021-10-17 19:08:16 -04:00
Paul Smith
6c06c547dc Add support for the POSIX :::= assignment operator.
POSIX Issue 8 will require a new assignment operator, :::=.
This operator behaves similarly to the BSD make := operator: the
right-hand side is expanded immediately, but then the value is
re-escaped (all '$' are converted to '$$') and the resulting variable
is considered a recursive variable: the value is re-expanded on use.

* src/variable.h (enum variable_flavor): Add f_expand flavor.
* src/variable.c (do_variable_definition): When defining f_expand,
post-process the result to re-escape '$' characters.
Remove default: to the compiler warns about un-handled enum values.
Set recursive values for both f_recursive and f_expand.
(parse_variable_definition): Rewrite this method.
The previous version was annoying to extend to ':::='.
(print_variable): Remove default: so the compiler warns us about
un-handled enum values.
* src/function.c (func_origin): Remove default: so the compiler warns
us about un-handled enum values.
* doc/make.texi: Add documentation for :::=.
* tests/scripts/variables/define: Add a test for define :::=.
* tests/scripts/variables/flavors: Add tests for :::=.
* tests/scripts/variables/negative: Add tests for :::=.
2021-09-20 00:29:31 -04:00
Paul Smith
c5d4b7b2f2 Clean up more Windows warnings.
* src/config.h.W32.template: Re-enable warnings that we don't violate.
Add a new disabled warning: 4130 (logical operation on address of
string constant).
* src/w32/compat/posixfcn.c: Make makeint.h the first included header.
* src/w32/subproc/sub_proc.c: Ditto.  It includes config.h already.
2021-09-07 01:14:33 -04:00
Dmitry Goncharov
9e4b3d3f4c [SV 60435] Ensure intermediate grouped files are removed
If multiple intermediate files are built together be sure all of them
are removed after make is finished.  Continue to ensure that targets
that exist before make starts are not removed even if they appear to be
intermediate.

Add a number of tests to pattern rules to verify this behavior.

* src/filedef.h (struct file): Add a new is_explicit bitfield.
* src/file.c (rehash_file): Merge the is_explicit bit.
(enter_prereqs): Set is_explicit if the file is explicitly mentioned.
* src/implicit.c (pattern_search): Set intermediate on the file if it's
not explicit.
(record_files): Set is_explicit if a file is mentioned as a target.
* src/remake.c (update_file_1): Set secondary on files that already
exist so they won't be removed.
* tests/scripts/features/double_colon: Add a test for double-colon
pattern rules.
* tests/scripts/features/patternrules: Update KGO for tests where more
files are removed.
Add new tests to verify handling removal of intermediate files in the
context of grouped pattern targets.
2021-09-07 01:14:20 -04:00
Paul Smith
5a96d5a066 * src/default.c (default_variables): Use CPP in PREPROCESS.S. 2021-09-06 20:42:34 -04:00
Dmitry Goncharov
4488592dda * src/main.c (decode_debug_flags): [SV 607777] Preserve -d options
* tests/scripts/options/dash-d: Test that -d --trace keeps -d.
2021-09-06 20:36:15 -04:00
Dmitry Goncharov
e7eb8b5962 [SV 57778] Don't ignore included makefiles that can't be read
If we find an included makefile but it's not readable, stop
immediately with an error rather than continuing to look in other
directories.

* src/read.c (eval_makefile): Only keep searching if the fopen error
is ENOENT, else stop and fail.
* tests/scripts/features/include: Add tests to verify this behavior.
2021-09-06 20:20:28 -04:00
Paul Smith
0c2fc00544 [SV 60795] Don't remake phony included makefiles and show errors
Change the handling of included makefiles which are phony targets to
be similar to double-colon rules with no prerequisites: simply don't
build them at all during the remake a makefile phase.

Ensure that any included makefile which is needed but not built
results in an error.

Update the documentation to make this clear.
Add tests to verify this behavior.

* doc/make.texi (Remaking Makefiles): Clarify double-colon exception.
Document that phony targets are handled the same way.
(Phony Targets): Ditto.
* src/main.c (main): Check for phony targets when skipping goals.
Rather than throwing out skipped but failed goals keep them
separately then report them as errors.
* src/read.c (eval): Set the file location on included makefiles even
when there's no error.
* tests/scripts/features/include: Add tests for handling included
makefiles with both phony and double-colon rules to rebuild them.
2021-09-06 18:49:08 -04:00
Paul Smith
214df0e92a * doc/make.texi (Environment): [SV 60841] Clarify variable exporting. 2021-09-06 10:57:43 -04:00
Paul Smith
b2e898d0bf * doc/make.texi (Chained Rules): [SV 60904] Clarify intermediate files. 2021-09-06 10:46:52 -04:00
Paul Smith
abb1e8d10b Remove UBSAN issues discovered via fuzzing tests.
The arithmetic conversions in C say that if a binary operator has an
unsigned and signed type as operands and the unsigned type has a greater
rank then the signed value is converted to unsigned.  This is bad if the
signed value is negative.

There are a few places in the code which have this situation; convert
the signed value to positive and add instead of subtracting.

Reported by He Jingxuan <jingxuan.he@inf.ethz.ch>

* src/read.c (find_map_unquote): Use a positive int in memmove().
(find_char_unquote): Ditto.
(find_percent_cached): Ditto.
2021-09-06 00:14:57 -04:00
Paul Smith
cc6dc70b16 * doc/make.texi (Prerequisite Types): [SV 61069] Mention PHONY prereqs 2021-09-05 23:29:33 -04:00
Paul Smith
2638552859 * doc/make.1: Clean up man page text. 2021-09-05 23:17:26 -04:00
Paul Smith
de48d6a4f7 * README.git: Add a section on ways to test. 2021-09-05 22:28:36 -04:00