Commit graph

2710 commits

Author SHA1 Message Date
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
Paul Smith
74bd8b3aa5 * file.c (remove_intermediates): Restart "rm ..." on error 2021-03-07 19:04:22 -05:00
Paul Smith
9043b28250 * doc/make.texi (How Patterns Match): [SV 58639] Fix chaining info. 2020-12-07 01:03:11 -05:00
Jouke Witteveen
fcc11d05a6 Create $(let ...) providing lexically scoped variables
Add a new function $(let ...) which allows lexically scoped variables.

* NEWS: Add information on this feature.
* doc/make.texi (Let Function): Document the 'let' function.
* src/function.c (func_let): Create the 'let' built-in function.
* tests/scripts/functions/let: Test the 'let' built-in function.
2020-12-06 18:30:58 -05:00
Paul Smith
a8f4669b23 * doc/make.texi (Phony Targets): [SV 58961] Clarify pattern handling 2020-12-06 15:21:23 -05:00
Paul Smith
bd4829096c * doc/make.texi (Synchronized Terminal Output): [SV 58960] Fix link 2020-12-06 10:14:15 -05:00
Paul Smith
7044e0c93c [SV 59169] Add --debug=why and --debug=print options
Add debug options to print recipes even if they would otherwise be
silent, and to print the reason that a target was considered out of
date.

Modify --trace to simply be a shorthand for --debug=print,why.

* NEWS: Announce changes.
* doc/make.texi (Summary of Options): Document the new options.
* doc/make.1: Ditto.
* src/debug.h: Add new flags DB_PRINT and DB_WHY.
* src/makeint.h: Remove the trace_flag variable.
* src/job.c (start_job_command): Check debug flags not trace_flag.
(new_job): Ditto.
* src/main.c (trace_flag): Make a static variable for switches.
(decode_debug_flags): Set DB_PRINT and DB_WHY if trace_flag is set.
* tests/scripts/variables/GNUMAKEFLAGS: Update known-good messages.
* tests/scripts/variables/MAKEFLAGS: Ditto.
2020-12-05 16:25:12 -05:00
Paul Smith
94d9077691 * configure.ac: [SV 58836] Copy build.sh to the build directory 2020-12-05 15:11:52 -05:00
Paul Smith
c4cc2e9595 [SV 57676] Support included files being built after failing
If a -include file does not exist, then some subsequent operation
creates it, then allow it to be successfully included.

* src/read.c (eval_makefile): If our last mtime was NONEXISTENT then
reset it to 0 so we'll check it again.
* tests/scripts/features/include: Add a test for this behavior.
2020-12-05 15:06:25 -05:00
Paul Smith
5e234e4048 * src/makeint.h (free_alloca): Check for builtin alloca 2020-12-02 17:29:16 -05:00
Paul Smith
950f3d305f * src/main.c (main): [SV 59601] Check for malformed env. variables 2020-12-02 17:27:55 -05:00
Paul Smith
58a37927e6 * maintMakefile: [SV 58794] Check for file existence in the release 2020-11-29 17:59:40 -05:00
Paul Smith
ec272f3a9c * Makefile.am (HAVE_GUILE): Only use Guile options if HAVE_GUILE. 2020-11-29 17:59:40 -05:00
Paul Smith
ef6aca5a38 * tests/scripts/features/vpathgpath: Avoid duplicate function name. 2020-11-29 17:59:40 -05:00
Paul Smith
b262ea5d8f Resolve unused-result warnings for alloca(0)
* src/makeint.h (free_alloca): New macro to defeat warn_unused_result.
* src/read.c (eval_makefile): Call it.
(eval_buffer): Ditto.
* src/remake.c (update_file): Ditto.
2020-11-29 17:59:40 -05:00
Paul Smith
cc20f90507 Avoid some valgrind warnings
Using sscanf() to parse archive header values (struct ar_hdr) can lead
to valgrind warnings which are probably bogus but are annoying.
To be safer, create a local method to convert the ASCII integer
strings into integers.

* src/arscan.c (parse_int): Turn integer strings into integers.
(ar_scan): Initialize struct ar_hdr memory.
Call parse_int() rather than sscanf/atol.
2020-11-29 17:59:40 -05:00
Paul Smith
9e2fa24649 [SV 41273] Allow the directory cache to be invalidated
Each time we invoke a command it's possible that it will change the
filesystem in ways that were not described by the target.  If that
happens but we have cached previous directory contents then we may
make decisions or report results based on obsolete information.

Keep a count of how many commands we've invoked, and remember the
current command count every time we load the contents of a directory.
If we request the directory and the current command count has changed
we know the cache is outdated so reload from scratch.

* NEWS: Announce the change.
* src/makeint.h (command_count): Create a global counter.
* src/main.c (command_count): Ditto.
* src/job.c (reap_children): Increment the counter on job completion.
* src/function.c (func_file): Increment if we write a file.
* src/dir.c (clear_directory_contents): Clear the current contents of
a cached directory.
(struct directory_contents): Remember the counter value.
(struct directory): Remember the counter value for non-existing dirs.
(find_directory): If we have a cached directory and the count hasn't
changed then return it.  Else, clear the previous contents and re-read
from scratch.
* tests/scripts/features/dircache: Add tests of the directory cache.
2020-11-29 17:59:16 -05:00
Paul Smith
2dc0280d82 Support "unexport" in target-specific variables.
Rewrite the environment variable algorithm to correctly inherit
export settings from parent variable sets.  The new algorithm
for computing the table of environment variables is:

- Start with the most local variable set and proceed to global.
- If the variable already exists in the table and we don't know
  its export status, update it with the current variable's status.
- If the variable is not in the table and it's not global, add it
  regardless of its status so if it's unexported we remember that.
- If the variable is not in the table and is global, check its
  export status and don't add it if we won't export it.

Then when generating the environment variables, check the export
status of each variable in case it was a target-specific variable
and we have determined it should not be exported.

Rework SHELL handling to check at the end whether we added it or
not and if we didn't, add the value from the environment.

* NEWS: Announce support for target-specific "unexport"."
* doc/make.texi (Target-specific): Document the support.
* src/variable.h (enum variable_export): Make into a global type.
* src/read.c (struct vmodifiers): Use enum variable_export rather
than individual booleans.
(parse_var_assignment): Parse the "unexport" keyword.
(eval): Remember the vmodifier value in the variable.
(record_target_var): Ditto.
* src/variable.c (should_export): Check if the variable should be
exported.
(target_environment): Implement the above algorithm.
* tests/scripts/features/export: Test export/unexport with variable
assignments on the same line.
* tests/scripts/features/targetvars: Add a comprehensive suite of
tests for different types of target-specific export / unexport.
* tests/scripts/variables/SHELL: Update the comment.
2020-11-29 17:57:33 -05:00
Dmitry Goncharov
90959b8b70 [SV 59230] Preserve export settings for target-specific vars
* src/read.c (record_target_var): Don't overwrite pre-existing export
flag unless we're changing it.
* tests/scripts/features/targetvars: Add a test.
2020-11-29 17:55:32 -05:00
Paul Smith
19ae6fe72a [SV 59230] Ensure environment variables are exportable
When checking for invalid environment variable names we searched the
entire name string instead of just the first LENGTH chars; this could
cause us to incorrectly decide the variable was not exportable.

Dmitry Goncharov <dgoncharov@users.sf.net> found this bug and
provided a test case and sample fix: I used the test but chose a
slightly different fix.

* src/variable.c (define_variable_in_set): check the variable name
not the input string.
* tests/scripts/features/targetvars: Ensure environment variable
values are exported.
2020-11-29 17:55:32 -05:00
Paul Smith
0e020bbc24 * src/default.c (default_variables) [AIX]: [SV 59096] Fix ARFLAGS
Reported by Dmitry Goncharov <dgoncharov@users.sf.net>, with a patch
changing the pattern rule for building archives.  I decided to
change the default value of ARFLAGS on AIX instead.
2020-11-29 17:55:32 -05:00
Paul Smith
c01222c018 [SV 35711] Check for special targets earlier
GNU make must recognize some special targets as they are defined.
Because of the way targets are defined, we were not recognizing these
special targets until we were handling the NEXT statement.  However
that's too late for some special targets such as .POSIX etc. which can
change the behavior of make during parsing.

Check for special targets earlier, as soon as we've finished parsing
the target introduction line (before we've even parsed the recipe).

* NEWS: Mention the change.
* src/read.c (check_specials): New function to look for special
targets.  Move checks from eval() and record_files() to this new
function.
(eval): Call check_specials() after we've completed parsing the target
introduction line.  Move default goal detection to check_specials().
(record_files): Move handling of .POSIX, .SECONDEXPANSION, and
.ONESHELL to check_specials().
* tests/scripts/misc/bs-nl: Remove workaround for late .POSIX issue.
* tests/scripts/targets/POSIX: Add a comment.
2020-11-29 17:55:02 -05:00
Paul Smith
957aa450a0 * .ccls: Disable clang compare against static string warning 2020-11-29 10:02:45 -05:00
Paul Smith
e49e11e069 [SV 59093] Rewrite filter/filter-out to avoid large stack usage
* src/function.c (func_filter_filterout): Allocate arrays to hold
pattern and word information rather than creating linked lists on
the stack.
* tests/scripts/functions/filter-out: Test large filters.
2020-11-13 00:44:24 -05:00
Paul Smith
f4f353bb54 * doc/make.texi (Include): Update behavior for missing included files 2020-10-28 11:10:52 -04:00
Paul Smith
a80b0096f5 * NEWS: [SV 58435] Document minimum C compiler version requirement
* configure.ac: Require c99 via AC_PROG_CC_C99
2020-07-19 18:59:06 -04:00
Paul Smith
62e8f029e9 [SV 58735] Define the order that makefiles are rebuilt.
Ensure that makefiles are rebuilt in the order in which make first
considered them, and document this behavior in the manual.

* NEWS: Add a note about the new behavior
* doc/make.text (How make Processes a Makefile): Document it.
* main.c (main): Inverse the list of makefile goals.
* read.c (read_all_makefiles): Add default makefiles to the list at
the front in reverse order, the same way other makefiles are added.
* tests/scripts/features/include: Add tests to verify rebuild order.
2020-07-19 13:56:23 -04:00
Paul Smith
db7658e042 * src/makeint.h: [ARM] [SV 58347] Don't assume ARM is not POSIX 2020-07-10 11:59:40 -04:00
Paul Smith
fa7f95c66c * src/job.c (unblock_sigs): [!POSIX] [SV 58743] Fix syntax errors 2020-07-10 11:59:38 -04:00
Paul Smith
df5f30a76a * NEWS: Fix some tortured grammar. 2020-05-14 01:00:28 -04:00
Paul Smith
1770540217 [SV 57930] Cast char to unsigned char to call ctype functions
This cast was already done almost everywhere: fix some stragglers.

* src/load.c (load_file): Cast char to unsigned char.
* src/misc.c (strcasecmp, strncasecmp): [!POSIX] Ditto.
* src/dir.c (vms_hash): [VMS] Ditto.
* src/vms_progname.c (set_program_name): [VMS] Ditto.
* src/vms_jobs.c (posix_parse_dq): [VMS] Ditto.
(posix_parse_dollar): [VMS] Ditto.
(build_vms_cmd): [VMS] Ditto.
(child_execute_job): [VMS] Ditto.
2020-05-03 14:54:56 -04:00