Commit graph

2840 commits

Author SHA1 Message Date
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
Paul Smith
55f06bdc3f * src/main.c (decode_switches): Fix memory leak. 2021-09-05 22:28:10 -04:00
Paul Smith
0d367bbe6e Clean up a few Windows build warnings (not all!)
* build_w32.bat: Quote uses of %VSWHERE% so it can contain spaces
* src/hash.c (hash_init): Avoid use of an undefined struct.
(hash_rehash): Ditto.
* src/vpath.c (construct_vpath_list): Cast explicitly to void*.
2021-09-05 21:09:27 -04:00
Paul Smith
f4b8ddf260 [SV 45211] Parse MAKEFLAGS immediately when it's reset
When MAKEFLAGS is set in a makefile, reparse it immediately rather
than waiting until after all makefiles have been read and parsed.
This change doesn't actually fix the SV bug referenced because, even
though we do reparse MAKEFLAGS, we don't handle the -r or -R options
immediately.  Doing this will require more effort.

* NEWS: Announce the change.
* src/makeint.h: Publish reset_switches() and decode_env_switches()
from main.c
* src/main.c (main): Don't call construct_include_path(); it will be
invoked decode_switches().
Preserve the old values of builtin_rules, builtin_variables, and
job_slots before we read makefiles since they can be changed now.
(reset_switches): Publish (remove static).  Set the initial value of
the stringlist list to NULL.
(decode_switches): Call construct_include_path() after decoding.
(decode_env_switches): Publish (remove static).
(define_makeflags): Set the MAKEFLAGS variable for special handling.
* src/read.c (eval_makefile): Check for empty include_directories.
(construct_include_path): Clear any old value of .INCLUDE_DIRS before
appending new values.  Free the previous include_directories.
* src/variable.c (lookup_special_var): When MAKEFLAGS is set, first
reset the switches then re-parse the variable.
* tests/run_make_tests.pl: Memo-ize some default variable values.
* tests/scripts/options/dash-r: Create tests for setting -r and -R.
* tests/scripts/variables/MAKEFLAGS: Test that resetting -I from
within the makefile takes effect immediately.
2021-09-05 21:08:59 -04:00
Paul Smith
e13fd5c83d * make-gdb.py: Add pretty-printers and clean up.
Create a pretty-printer for next-pointer lists.
Create a pretty-printer for stringlists.
Change showargv from a function to a command (easier to use).

Clean up some Python PEP violations.  Add support for testing null
pointers and caching gdb.Types.
2021-09-05 20:05:02 -04:00
Paul Smith
7c4e6b0299 [SV 60595] Restart whenever any makefile is rebuilt
Previously if an included makefile was rebuilt as a prerequisite of
another included makefile which didn't need to be rebuilt, make would
not realize that it needed to re-exec itself.

Ensure that if any included makefile target is rebuilt we re-exec.
Also ensure that if an included makefile is not readable, and our rule
for rebuilding it doesn't actually change it, we will still fail.

* src/remake.c (update_goal_chain): If a goal's update was successful
then check its status, even if no actual commands were run because it
was already up to date.
(show_goal_error): Remove superfluous cast.
* src/main.c (main): If the makefile remake did nothing, check that we
were able to successfully include all the makefiles we care about; if
not fail.  When generating error messages about included makefiles be
sure to show the filename/linenumber information.
* test/scripts/features/reinvoke: Add tests for this behavior.
* test/scripts/options/dash-k: Update error messages.
2021-09-03 12:08:11 -04:00
Paul Smith
b9c4fc441b [SV 60412] Allow -I- to throw out the current directory path
Accept a "-" directory value to the -I option to clear the set of
directories to be searched up to that point, including the default
directories.

* NEWS: Announce the change.
* doc/make.texi (Summary of Options): Add documentation.
* src/read.c (construct_include_path): Check for '-' and if found,
clear the list of directories to be searched.
* tests/scripts/options/dash-I: Add tests for -I-.
* tests/scripts/variables/INCLUDE_DIRS: Add tests for -I-.
2021-09-03 12:08:11 -04:00
Dmitry Goncharov
65b73ce434 [SV 60699] Avoid calling strlen() repeatedly in a loop
* src/variable.c (lookup_pattern_var): Accept target length parameter.
(initialize_file_variables): Pass computed target length to lookup.
2021-07-25 17:15:38 -04:00
Paul Smith
2d73c9bf25 * NEWS: Add a few missing attributions
* AUTHORS: Add some missing attributions
2021-07-25 17:15:38 -04:00
Dmitry Goncharov
33468b3f31 [SV 60297] Add .NOTINTERMEDIATE special target
Support a new special target, .NOTINTERMEDIATE.  Any file or pattern
prerequisite of this target will never be considered intermediate.
This differs from .SECONDARY in that .SECONDARY files won't be deleted
but they will still not be built if they are missing.

.NOTINTERMEDIATE files are treated the same way as a target which is
explicitly mentioned in the makefile.  This is mostly useful with
patterns; obviously mentioning a target explicitly here is enough in
and of itself to make something not intermediate.

Some adjustments made by psmith@gnu.org

* NEWS: Announce the new feature.
* doc/make.texi (Special Targets): Document .NOTINTERMEDIATE.
(Chained Rules): Describe how to use .NOTINTERMEDIATE.
* src/main.c (main): Add "notintermediate" to the .FEATURES variable.
* src/filedef.h (struct file): Add "notintermediate" flag.
* src/file.c (no_intermediates): Mark global .NOTINTERMEDIATE.
(snap_file): Support .NOTINTERMEDIATE special target.  Throw an error
if the same target is marked both .NOTINTERMEDIATE and .SECONDARY or
.INTERMEDIATE.
(rehash_file): Merge intermediate, notintermediate, secondary flags.
(remove_intermediates): Check notintermediate flag before removing.
(print_file):
* src/implicit.c (pattern_search): Set notintermediate based on the
pattern.
* tests/scripts/targets/NOTINTERMEDIATE: Add a new test suite.
2021-07-25 17:15:38 -04:00
Paul Smith
1cffd0a203 * make.texi (Reading Makefiles): != creates recursive variables.
Reported by Ronald Hoogenboom <RHoogenboom@irdeto.com>.
2021-05-30 15:53:51 -04:00
Dmitry Goncharov
b580949ae0 [SV 60659] Set $$< properly in second expansion
Set the $$< automatic variable as best we can during secondary
expansion of prerequisites.

* src/commands.c (set_file_variables): Don't break without setting
'less' if secondary expansion is enabled.
* tests/scripts/features/se_explicit: Test secondary expansion results.
* tests/scripts/features/se_implicit: Test secondary expansion results.
2021-05-30 15:53:41 -04:00
Paul Smith
f2771aa614 [SV 58341] Add non-trivial options to $(MAKEFLAGS)
Previously only trivial (single-letter) options were available in
$(MAKEFLAGS) when it is examined from inside a makefile (the full
value was set before expanding recipes).

Ensure that all options (but, not command line variable overrides!)
are visible in the $(MAKEFLAGS) variable.  In order to do this
reset the default values of options, particularly options which are
lists, before re-reading MAKEFLAGS after makefiles have been read.
Otherwise we'll get duplicate values for options such as -I.

Unfortunately there are complications here as well: sometimes (for
jobserver options in particular) we modify the values of these
options while running: we must not reset these modifications.

* NEWS: Announce this change
* src/main.c (main): Call new reset_switches() before re-parsing
MAKEFLAGS.
(reset_switches): Reset the value of non-special options to their
defaults.
(define_makeflags): Add non-special options into MAKEFLAGS even
if 'all' is not set.
2021-05-30 15:11:30 -04:00
Dmitry Goncharov
5e829188d3 [SV 60378] Don't add duplicate default search directories
Depending on how make was configured it may add duplicate
directories in the default include search path: avoid this.

(Tweaked by psmith@gnu.org)

* configure.ac: Set AM variable KNOWN_PREFIX if --prefix is known
* Makefile.am: Only set INCLUDEDIR if prefix is not known
* read.c [default_include_directories]: Only add INCLUDEDIR if set
2021-05-30 15:11:30 -04:00
Dmitry Goncharov
297cb5adb7 * tests/scripts/targets/INTERMEDIATE: [SV 60188] Add one more test 2021-05-30 15:11:14 -04:00
Eli Zaretskii
012918bf11 [SV 58656] Fix mtime for large files on MS-Windows
In MSVC builds, 'stat' fails when called on files larger than
2GB.  Call '_stat64' instead to work around this.

* src/remake.c (STAT): Define to '_stat64' for MSVC builds.
(name_mtime) [WINDOWS32]: Use STAT instead of 'stat'.
Suggested by Makoto Kato <m_kato@ga2.so-net.ne.jp>.
2021-05-29 11:37:09 +03:00
Paul Smith
1ae90c030d Fix build and test issues on Windows
* src/dep.h (DEP): Remove extraneous semicolon.
* src/dir.c (find_directory) [W32]: Replace removed variable.
* tests/scripts/features/include: Allow the extra default makefile
searched for on Windows.
* tests/scripts/functions/file: Use $(info ...) to avoid "command
too long" errors on Windows.
2021-03-28 16:25:52 -04:00
Tobias Stoeckmann
0fb6f2d985 * src/remake.c (name_mtime): Reserve space for nul in readlink result
Copyright-paperwork-exempt: yes
2021-03-28 14:45:16 -04:00
Cao jin
97a8d9b45a * doc/make.texi (Call Function): Apply consistent formatting
Copyright-paperwork-exempt: yes
2021-03-25 14:38:58 -04:00
Pete Dietl
c5c02accb7 * src/job.c (child_execute_job): Update gnulib find_in_given_path()
Copyright-paperwork-exempt: yes
2021-03-25 14:25:26 -04:00
Mike Frysinger
76a099997b * doc/make.texi (Automatic Variables): Relocate the $? example
Copyright-paperwork-exempt: yes
2021-03-25 13:10:29 -04:00
Paul Smith
c5319e75f5 [SV 58497] Ensure $(file <) newline removal succeeds
Keep a count of bytes read rather than comparing pointers since the
variable_buffer might get reallocated.

Bug and patch by Ken Tossell <ken@tossell.net>
Regression tests by Dmitry Goncharov <dgoncharov@users.sf.net>
Tweaked by Paul Smith <psmith@gnu.org>

* src/function.c (func_file): Use bytes read rather than a pointer.
* tests/scripts/functions/file: Provide various tests for reading
empty files, files with/without newlines, and large files.
2021-03-15 03:28:11 -04:00
Dmitry Goncharov
510e5ce801 [SV 60188] Explicit prereqs cannot be intermediate files
If a prereq of a pattern is an explicit target, it should not be
considered an intermediate file.

(Minor tweaks by Paul Smith <psmith@gnu.org>)

* src/dep.h (struct nameseq): Add is_explicit flag.
* src/implicit.c (struct patdeps): Ditto.
(pattern_search): Set the is_explicit flag appropriately for each
prerequisite, based on whether it contained a pattern or not.
Update the help output to note implicit vs. explicit prereqs.
* tests/scripts/features/double_colon: Add tests.
* tests/scripts/features/grouped_targets: Ditto.
* tests/scripts/features/patternrules: Ditto.
* tests/scripts/features/se_implicit: Ditto.
* tests/scripts/features/statipattrules: Ditto.
2021-03-15 02:10:49 -04:00
Paul Smith
144f436c4b * tests/scripts/features/exec: Small cleanup 2021-03-15 01:17:06 -04:00
Paul Smith
52056d7b2c Ensure variable_buffer is always set.
Initialize the global variable_buffer in main() so that it is never
a null pointer.  Then invoking variable_expand("") is never needed:
simply use the variable_buffer pointer when we want to restart the
variable buffer.  The main point of this simplification is not to
keep a separate pointer to the beginning of the buffer: this is
dangerous because the buffer may be re-allocated.  Instead always
use the variable_buffer pointer itself.

* src/variable.h (initialize_variable_output): Publish.
* src/expand.c (initialize_variable_output): Remove static.
* src/main.c (main): Initialize variable_buffer.
* src/file.c (enter_prereqs): Don't call variable_expand("") and
don't save a separate buffer pointer than might be outdated.
(expand_deps): Ditto.
* src/read.c (record_files): Ditto.
* src/remake.c (library_search): Ditto.
2021-03-15 01:17:06 -04:00
Paul Smith
c66ec5fa20 [SV 59881] Handle vertical TAB consistently
While parsing makefiles get_next_mword() was treating VTAB as a word
character rather than a word separator.  However, when using
find_next_token(), for example in patsubst_expand_pat(), we treated
VTAB as a word separator causing multiple words to appear where we
didn't expect them.

* src/makeint.h (END_OF_TOKEN): Change from a loop to a boolean check.
* src/misc.c (end_of_token): Move the loop here.
* src/read.c (get_next_mword): Skip whitespace, not just blank, to
find the start of the word and use END_OF_TOKEN() to decide when the
current word is finished.
2021-03-15 01:16:32 -04:00
Paul Smith
da6fc6aae2 [SV 59870] define/undefine prerequisites are not target-specific vars
* src/read.c (parse_var_assignment): If called in a target-specific
variable context don't allow define/undefine as variable assignments.
* test/scripts/variables/define: Add a test.
* test/scripts/variables/undefine: Add a test.
2021-03-14 16:35:38 -04:00
Paul Smith
d9aff6b817 * maintMakefile: Don't make .check-git-HEAD .PHONY 2021-03-14 15:53:45 -04:00
Jouke Witteveen
e5f6dc54b9 More correctly describe the scope of variables
* NEWS: Use "local" instead of the incorrect "lexically-scoped".
* doc/make.texi: Refer to let/foreach variables as local variables.
2021-03-07 19:06:59 -05:00
Paul Smith
88732a29f2 * doc/make.text: Clarify that patsubst doesn't touch unmatched words 2021-03-07 19:05:20 -05:00
Paul Smith
7b0a741857 * .dir-locals.el: Update for newer LSP config 2021-03-07 19:04:48 -05:00