Commit graph

2848 commits

Author SHA1 Message Date
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
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