]> git.ipfire.org Git - thirdparty/make.git/log
thirdparty/make.git
6 months ago[SV 66499] Detect jobserver values that are too large master
Paul Smith [Sun, 8 Dec 2024 21:31:54 +0000 (16:31 -0500)] 
[SV 66499] Detect jobserver values that are too large

Set the jobserver pipe to non-blocking before writing tokens; if a
token write fails the user's jobserver value is too large so fail.

Original implementation: Dmitry Goncharov <dgoncharov@users.sf.net>

* src/posixos.c (set_blocking): Split into force_blocking() which
always enables/disables blocking; set_blocking() may call it.
(jobserver_setup): Set the write side of the pipe to non-blocking
before writing tokens.  If it fails with EAGAIN we know the pipe
is full: create a fatal error.
* tests/scripts/features/jobserver: Test a too-large jobserver.

6 months agojobserver: Ensure the named pipe is deleted on error
Paul Smith [Sun, 8 Dec 2024 21:27:06 +0000 (16:27 -0500)] 
jobserver: Ensure the named pipe is deleted on error

Make sure the jobserver named pipe is deleted even if the
jobserver_setup() function calls fatal() and exits early.

* src/main.c (clean_jobserver): Always reset_jobserver().
* src/posixos.c (jobserver_setup): Set job_root up front.
* tests/test_driver.pl: Print out the logfile pathname on error.
For tests with regex matches this might be the only file available.
Don't print the base filename unless one is created.

6 months ago* doc/make.texi: [SV 66324] Fix a typo
Paul Smith [Sat, 12 Oct 2024 20:15:28 +0000 (16:15 -0400)] 
* doc/make.texi: [SV 66324] Fix a typo

9 months ago[SV 66273] Double-colon targets must not be intermediate
Dmitry Goncharov [Wed, 2 Oct 2024 02:27:25 +0000 (22:27 -0400)] 
[SV 66273] Double-colon targets must not be intermediate

An explicitly mentioned double-colon target cannot be intermediate.

* src/read.c (record_files): Set file->is_explicit in the case of an
explicitly mentioned file built by a double colon rule.
* src/file.c (print_file): Have print_file print whether a file is
explicitly mentioned.
* tests/scripts/features/patternrules: Add tests.

9 months ago[SV 66268] Include newlines in file removal error message
Dmitry Goncharov [Wed, 2 Oct 2024 02:14:31 +0000 (22:14 -0400)] 
[SV 66268] Include newlines in file removal error message

* src/file.c (remove_intermediates): Fix an error message about a
failure to remove an intermediate file.
* tests/scripts/features/patternrules: Add tests.

10 months ago* doc/make.texi: Clarify -j versus -jN behavior
Paul Smith [Mon, 2 Sep 2024 20:23:36 +0000 (16:23 -0400)] 
* doc/make.texi: Clarify -j versus -jN behavior

10 months agoFix biased shuffle by avoiding already "struck" elements
Sergei Trofimovich [Tue, 18 Jun 2024 21:37:54 +0000 (22:37 +0100)] 
Fix biased shuffle by avoiding already "struck" elements

Artem Klimov noticed that current shuffle implementation suffers from
probability bias due to a typical bug in the shuffling implementation.

When we consider already shuffled element we slightly bias their
propability.

https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
suggests shuffling each "struck" element only once.

Before the change probabilities of 4-element array to land from `i`
index to `j` index are:

          0     1     2     3
      _____ _____ _____ _____
  0 | 25.00 29.30 24.60 21.10
  1 | 25.00 22.25 28.13 24.63
  2 | 25.00 23.44 22.26 29.30
  3 | 25.00 25.01 25.01 24.98

Note that `0->1` probability is almost 29% while `0->3` os only 21%.

After the change probabilities are not as biased:

          0     1     2     3
      _____ _____ _____ _____
  0 | 24.99 24.99 25.01 25.01
  1 | 24.99 25.04 24.99 24.99
  2 | 25.01 25.00 25.00 24.99
  3 | 25.01 24.98 25.00 25.01

* src/shuffle.c (random_shuffle_array): Fix biased shuffle by avoiding
already "struck" elements.

10 months ago* doc/make.texi: GNUMAKEFLAGS is only read from the environment
Paul Smith [Mon, 2 Sep 2024 18:53:44 +0000 (14:53 -0400)] 
* doc/make.texi: GNUMAKEFLAGS is only read from the environment

10 months agoCheck for snprintf truncation on W32
Paul Eggert [Mon, 5 Aug 2024 08:39:18 +0000 (01:39 -0700)] 
Check for snprintf truncation on W32

* src/main.c (find_and_set_default_shell) [MK_OS_W32]:
Do not use a buffer that snprintf truncated.

10 months agoFix unlikely pointer overflow in abspath
Paul Eggert [Mon, 5 Aug 2024 08:30:44 +0000 (01:30 -0700)] 
Fix unlikely pointer overflow in abspath

* src/function.c (abspath): len is now ptrdiff_t,
to avoid GCC warning about comparing signed to unsigned.
It really is a pointer difference, after all.
Rejigger comparision to avoid undefined behavior
if dest + len is an invalid pointer.

10 months agoPrefer memcpy to strncpy if either will do
Paul Eggert [Mon, 5 Aug 2024 08:21:09 +0000 (01:21 -0700)] 
Prefer memcpy to strncpy if either will do

strncpy is trickier and a bit slower.
* src/function.c (func_realpath, func_abspath):
* src/misc.c (xstrndup):
Prefer memcpy or mempcpy to strncpy when the source length is known.

10 months agoOmit unused PATH_MAX code
Paul Eggert [Mon, 5 Aug 2024 08:04:13 +0000 (01:04 -0700)] 
Omit unused PATH_MAX code

* src/makeint.h (GET_PATH_MAX, PATH_VAR):
Simplify, since PATH_MAX is always defined here.
(NEED_GET_PATH_MAX): Remove.
* src/misc.c (get_path_max) [NEED_GET_PATH_MAX]: Remove.

10 months agoAvoid strlen calls after sprintf
Paul Eggert [Mon, 5 Aug 2024 07:44:28 +0000 (00:44 -0700)] 
Avoid strlen calls after sprintf

* src/file.c (file_timestamp_sprintf):
* src/function.c (func_words, func_call):
* src/job.c (child_error):
* src/main.c (define_makeflags):
* src/output.c (message, error, fatal):
Use return value from sprintf instead of calling strlen
on the resulting buffer.

10 months ago[SV 65759] Document special handling of "-" command line option
Paul Smith [Mon, 2 Sep 2024 16:35:58 +0000 (12:35 -0400)] 
[SV 65759] Document special handling of "-" command line option

* doc/make.1: Add information on "-" option handling.
* doc/make.texi: Ditto.

10 months ago[SV 65777] Add more const
Dan D [Mon, 2 Sep 2024 13:54:17 +0000 (09:54 -0400)] 
[SV 65777] Add more const

Add more const to static arrays.  On some systems this allows more
data to be placed in RO segments and shared between multiple
instances of the make executable.  Anyway more const is good hygiene.

* src/default.c: Add const to arrays.
* src/function.c: Ditto.
* src/hash.c: Ditto.
* src/hash.h: Ditto.
* src/job.c: Ditto.
* src/read.c: Ditto.
* src/remake.c: Ditto.
* src/rule.c: Ditto.
* src/rule.h: Ditto.

10 months agoRemove obsolete email address for the FSF
Paul Smith [Mon, 2 Sep 2024 01:12:37 +0000 (21:12 -0400)] 
Remove obsolete email address for the FSF

* doc/make.texi: Use the newer email address in the manual.
* gl/lib/fnmatch.c: Use a URL instead of a street address.
* gl/lib/fnmatch.in.h: Ditto.
* gl/lib/glob.c: Ditto.
* gl/lib/glob.in.h: Ditto.

10 months ago* bootstrap.conf: Update to newer prerequisites
Paul Smith [Mon, 2 Sep 2024 01:09:42 +0000 (21:09 -0400)] 
* bootstrap.conf: Update to newer prerequisites

11 months ago[SV 65917] Mark also_make targets as updated in make -n
Paul Smith [Mon, 5 Aug 2024 03:48:51 +0000 (23:48 -0400)] 
[SV 65917] Mark also_make targets as updated in make -n

Suggested patch by Hannes Domani <ssbssa@yahoo.de>

* src/remake.c (notice_finished_file): When run with -n, mark
also_make targets as updated.
* tests/scripts/options/dash-n: Test pattern and grouped targets.

11 months ago* src/job.c (new_job): [SV-66030] Show all also-make targets
Paul Smith [Sun, 4 Aug 2024 21:16:23 +0000 (17:16 -0400)] 
* src/job.c (new_job): [SV-66030] Show all also-make targets

11 months agoDon't add a target to its own also_make list
Paul Smith [Sun, 4 Aug 2024 21:13:07 +0000 (17:13 -0400)] 
Don't add a target to its own also_make list

* src/dep.h (copy_dep): Make a copy of one struct dep.
* src/misc.c (copy_dep): Implement the new function.
(copy_dep_chain): Call copy_dep() for each dep in the chain.
* src/read.c (record_files): Write our own copy loop and omit the
current file from its own also_make list.  Since we don't keep
the function's also_make, free it.

11 months ago* doc/make.texi: [SV-65982] Clarify what --debug=makefile does
Paul Smith [Sun, 4 Aug 2024 20:04:19 +0000 (16:04 -0400)] 
* doc/make.texi: [SV-65982] Clarify what --debug=makefile does

11 months ago* src/remake.c (update_file_1): [SV 65999] Clarify debug output
Paul Smith [Sun, 4 Aug 2024 19:59:58 +0000 (15:59 -0400)] 
* src/remake.c (update_file_1): [SV 65999] Clarify debug output

11 months ago* doc/make.texi: [SV-66018] Mention .ONESHELL in [-+@] docs
Paul Smith [Sun, 4 Aug 2024 19:45:55 +0000 (15:45 -0400)] 
* doc/make.texi: [SV-66018] Mention .ONESHELL in [-+@] docs

11 months ago[SV 66037] Avoid hang/crash from MAKEFLAGS=... on command line
Dmitry Goncharov [Sun, 4 Aug 2024 19:13:44 +0000 (15:13 -0400)] 
[SV 66037] Avoid hang/crash from MAKEFLAGS=... on command line

Make enters an infinite loop when some option and MAKEFLAGS=<value>
are specified on the command line.  For example,
    $ make -r MAKEFLAGS=hello=world

If decode_switches() runs handle_non_switch_argument() from within
the getopt() loop, it would recursively call decode_switches() to
enter a new getopt() loop, corrupting the state of the outer loop.

* src/main.c (decode_switches): Save up non-option arguments and run
handle_non_switch_argument() only after we're done with getopt().
* tests/scripts/variables/MAKEFLAGS: Add tests.

11 months ago* doc/make.texi (Overview): Update reference to POSIX.1-2024
Paul Smith [Wed, 19 Jun 2024 18:03:40 +0000 (14:03 -0400)] 
* doc/make.texi (Overview): Update reference to POSIX.1-2024

11 months ago* src/warning.h: Put warnings into alphabetical order.
Paul Smith [Sun, 19 May 2024 23:10:32 +0000 (19:10 -0400)] 
* src/warning.h: Put warnings into alphabetical order.

* src/warning.c: Ditto.
* tests/scripts/options/warn: Fix tests for the new order.

11 months ago[SV 65739] Add warning circular-dep.
Dmitry Goncharov [Sun, 19 May 2024 22:56:12 +0000 (18:56 -0400)] 
[SV 65739] Add warning circular-dep.

Add a warning to control circular dependency detection.  Use "warn" as
the default action to be backward-compatible.

* src/warning.h (enum warning_type): Add warning type wt_circular_dep.
* src/warning.c (warn_init): Set default wt_circular_dep to w_warn.
* src/remake.c (update_file_1): Consult the circular-dep warning to
handle circular dependencies.
* tests/scripts/options/warn: Test --warn circular-dep flag.
* tests/scripts/variables/WARNINGS: Test .WARNINGS circular-dep flag.
* doc/make.texi: Document circular-dep warning.
* doc/make.1: Ditto.

14 months ago* tests/scripts/functions/shell: [SV 65323] Run huge var test in bash
Dmitry Goncharov [Sun, 21 Apr 2024 17:35:33 +0000 (13:35 -0400)] 
* tests/scripts/functions/shell: [SV 65323] Run huge var test in bash

The long variable name causes ksh to crash.  Some systems use ksh as
/bin/sh, so force bash if it's available else skip the test.

14 months ago[SV 65324] disable_builtins: Don't dereference NULL suffix_file
Dmitry Goncharov [Sun, 21 Apr 2024 17:34:12 +0000 (13:34 -0400)] 
[SV 65324] disable_builtins: Don't dereference NULL suffix_file

Make crashes when -r and MAKEFLAGS= are specified on the command line.

On startup make begins to process command line arguments.
During processing of "MAKEFLAGS=" make calls reset_makeflags, which in
turn calls disable_builtins, which dereferences null suffix_file.
Here is the backtrace.

0 disable_builtins main.c:3482
1 reset_makeflags main.c:3104
2 set_special_var variable.c:1325
3 do_variable_definition variable.c:1693
4 try_variable_definition variable.c:1889
5 handle_non_switch_argument main.c:3021
6 decode_switches main.c:3150
7 main main.c:1621

* src/main.c (disable_builtins): Avoid dereferencing null suffix_file.
* tests/scripts/features/suffixrules: Add a test.

14 months ago* make.texi (How to Use Variables): [SV 65536] Rewrite this chapter
Paul Smith [Sun, 21 Apr 2024 16:42:55 +0000 (12:42 -0400)] 
* make.texi (How to Use Variables): [SV 65536] Rewrite this chapter

Re-reading this chapter I decided it was time to introduce a complete
rewrite, of at least parts of this.  Much of the enhancements added
over the years were in the wrong place or not clear.

14 months ago* .dir-locals.el: Correct bug reference regex format
Paul Smith [Sun, 14 Apr 2024 19:51:23 +0000 (15:51 -0400)] 
* .dir-locals.el: Correct bug reference regex format

14 months ago[SV 65537] Update to newer gnulib
Paul Smith [Sun, 14 Apr 2024 19:27:37 +0000 (15:27 -0400)] 
[SV 65537] Update to newer gnulib

* bootstrap.conf: Switch to gnulib stable-202401 branch.
* maintMakefile: Support an EXTRA_CFLAGS variable in maintainer mode.
* README.git: Describe how to use it.

14 months ago* NEWS: Clean up UTF-8 issues
Paul Smith [Sun, 14 Apr 2024 19:27:12 +0000 (15:27 -0400)] 
* NEWS: Clean up UTF-8 issues

15 months ago* doc/make.texi (Pattern Rules): Clarify that rules must have recipes.
Paul Smith [Thu, 28 Mar 2024 23:08:20 +0000 (19:08 -0400)] 
* doc/make.texi (Pattern Rules): Clarify that rules must have recipes.

15 months ago* src/arscan.c (parse_int): Fix integer overflow test
Paul Eggert [Mon, 8 Jan 2024 00:09:49 +0000 (16:09 -0800)] 
* src/arscan.c (parse_int): Fix integer overflow test

Use intprops.h macros rather than trying to detect integer overflow by
hand, and doing it incorrectly.  Example of incorrect behavior:
if val == 3689348814741910323, base == 10, UINTMAX_WIDTH == 64, and
 *ptr == '0' then (val*base)+(*ptr-'0') yields 18446744073709551614
which is greater than val even though overflow has occurred.
Fortunately this bug could not be triggered on GNU/Linux hosts,
although it may be possible on platforms (if any) where struct ar_hdr
has members so large that they can represent integers that do not fit
int uintmax_t.

15 months ago* src/makeint.h (JOBSERVER_USE_FIFO): Do not define on OS/2.
KO Myung-Hun [Sun, 24 Mar 2024 21:10:08 +0000 (17:10 -0400)] 
* src/makeint.h (JOBSERVER_USE_FIFO): Do not define on OS/2.

mkfifo() on OS/2 is a dummy, it even returns a wrong value on error.

15 months ago* src/variable.c (do_variable_definition) [W32]: Fix bad variable.
Paul Smith [Sun, 24 Mar 2024 20:47:19 +0000 (16:47 -0400)] 
* src/variable.c (do_variable_definition) [W32]: Fix bad variable.

15 months ago* src/arscan.c (ar_name_equal): Support GNU ar's -P option.
Marco Sirabella [Sun, 24 Mar 2024 20:41:13 +0000 (16:41 -0400)] 
* src/arscan.c (ar_name_equal): Support GNU ar's -P option.

15 months ago* tests/README: Fix sample run_make_tests command line.
Marco Sirabella [Sun, 24 Mar 2024 20:36:35 +0000 (16:36 -0400)] 
* tests/README: Fix sample run_make_tests command line.

15 months ago* doc/make.texi: GNU Make does set GNUMAKEFLAGS, to empty.
Paul Smith [Sun, 24 Mar 2024 20:29:14 +0000 (16:29 -0400)] 
* doc/make.texi: GNU Make does set GNUMAKEFLAGS, to empty.

15 months ago* doc/make.texi: Document temporary file name prefix
Paul Smith [Sun, 24 Mar 2024 20:23:28 +0000 (16:23 -0400)] 
* doc/make.texi: Document temporary file name prefix

* src/posixos.c (jobserver_setup): Set prefix for FIFO temp file.
Ensure it can't conflict with a "normal" temp file.
* src/w32/w32os.c (os_anontmp): Set prefix for anon temp files.

15 months ago[SV 65268] Un-set append mode for stdout/stderr on exit
Paul Smith [Sun, 24 Mar 2024 19:19:11 +0000 (15:19 -0400)] 
[SV 65268] Un-set append mode for stdout/stderr on exit

It turns out that options set on stdout/stderr last after exit.
Leaving append-mode enabled can break other facilities, so reset the
flags on stdout/stderr before we exit.

* src/os.h: Add a new fd_reset_append() to reset flags on FDs.
Modify fd_set_append() to return the old flags.
* src/posixos.c (fd_reset_append): Set provided flags on the FD.
(fd_set_append): Return the previous flags set on the FD.
* src/output.c (output_init): Preserve old flags for stdout/stderr.
(output_close): Reset flags for stdout/stderr.
* src/w32/w32os.c: Implement dummy methods.

15 months ago[SV 65273] configure.ac: Remove check for sys/timeb.h
Paul Smith [Sun, 24 Mar 2024 18:19:23 +0000 (14:19 -0400)] 
[SV 65273] configure.ac: Remove check for sys/timeb.h

GNU Make doesn't use ftime(); we only checked for this to work around
an error in the completely obsolete SCO 3.2 system.  Since ftime() is
deprecated, including sys/timeb.h has started throwing warnings on
newer systems so just remove it completely.
Reported by: Collin Funk <collin.funk1@gmail.com>

* configure.ac: Remove the check for sys/timeb.h.
* src/makeint.h: Remove the include of sys/timeb.h.
* src/config.h-vms: Don't define HAVE_SYS_TIMEB_H.
* src/config.h.W32: Ditto.

15 months ago[SV 65448] intcmp: Compare values instead of magnitudes
Jouke Witteveen [Sun, 24 Mar 2024 18:08:59 +0000 (14:08 -0400)] 
[SV 65448] intcmp: Compare values instead of magnitudes

* src/function.c (func_intcmp): Reverse comparison direction when
both arguments are negative.
* tests/scripts/functions/intcmp: Add tests and remove useless ones.

15 months ago[SV 65359] doc/make.texi: Describe invalid export variable names
Paul Smith [Sun, 24 Mar 2024 18:05:45 +0000 (14:05 -0400)] 
[SV 65359] doc/make.texi: Describe invalid export variable names

17 months ago[SV 64085] Handle .POSIX plus .IGNORE correctly
Paul Smith [Mon, 5 Feb 2024 00:41:50 +0000 (19:41 -0500)] 
[SV 64085] Handle .POSIX plus .IGNORE correctly

POSIX requires that a conforming makefile should not use -e if
 1) make is invoked with -i
 2) A .IGNORE target exists with no prerequisites
 3) The current target is a prerequisite of .IGNORE

* src/job.c (start_job_command): Add the target's flags when
constructing argv so it can check (3) above.
(construct_command_argv_internal): Don't set shellflags if it's not
set: this only happens if we're parsing for the slow path and we
don't need them.
(construct_command_argv): Don't allocate buffers if not needed.
When detecting "-ec", check the global ignore_errors_flag and the
current command line flags.
* tests/scripts/targets/IGNORE: Add tests for .IGNORE.
* tests/scripts/targets/POSIX: Add tests for the three cases above.

17 months ago[SV 64822, SV 36486] Fix appending to a pattern specific variable
Dmitry Goncharov [Sun, 4 Feb 2024 18:04:05 +0000 (13:04 -0500)] 
[SV 64822, SV 36486] Fix appending to a pattern specific variable

Appending to a pattern specific variable produces an incorrect value
in the presence of a command line definition or an env override of
the variable.  Also, fix pattern/target-specific appending to a
variable with origin override.

* At parse time record_target_var sets the value of a pattern
  specific variable to the value defined on command line or to the
  value of the env override.
* Later, at build time, recursively_expand_for_file appends this
  value of the variable (set in record_target_var) to the command
  line value again, regardless of the origin of the variable.

This patch modifies recursively_expand_for_file to avoid appending,
unless the origin of the variable beats or equals the origin of one
of the parent definitions of this variable.

Reported by Rob <robw9739@gmail.com>,
Brian Vandenberg <phantall@gmail.com>,
Markus Oberhumer <markus@oberhumer.com>.

* NEWS: Note the change.
* src/variable.c (do_variable_definition): Avoid merging a
pattern-specific variable with the parent definition when a command
line or env override is present.
* src/expand.c (recursively_expand_for_file): Avoid appending to a
pattern-specific variable, unless the origin of this pattern-specific
variable beats or equals the origin of one of the parent definitions
of this variable.
* doc/make.texi (Override Directive): Add missing cross-reference.
* tests/scripts/variables/append: Add tests.

17 months ago* NEWS: Clean up
Paul Smith [Sun, 4 Feb 2024 16:31:19 +0000 (11:31 -0500)] 
* NEWS: Clean up

17 months ago[SV 64803] Set origin for unmodified variables after -e
Dmitry Goncharov [Sun, 4 Feb 2024 16:16:40 +0000 (11:16 -0500)] 
[SV 64803] Set origin for unmodified variables after -e

Ensure the origin of all variables inherited from the environment is
"environment override" if -e is given.  Previously only variables
that were set in the makefile had this origin.

PDS: Most of these changes are from Dmitry but I slightly modified
the algorithm: instead of rearranging the way in which MAKEFLAGS is
parsed we reset the env_override value to the default before we
re-parse MAKEFLAGS, then we set the origin of all env vars to the
correct value based on the new setting.

* NEWS: Mention the change for backward-compatibility.
* src/main.c (main): Ensure MAKEFLAGS is always marked special.
(reset_makeflags): Set env_overrides back to default before parsing
MAKEFLAGS.
(decode_switches): Call reset_env_override() to check for changes.
* src/variable.h (reset_env_override): Declare a new function.
* src/variable.c (reset_env_override): Go through all env variables
and ensure the origin is correct based on env_overrides.
(set_env_override): Helper function for the hash.
* tests/scripts/functions/foreach: Fix tests.
* tests/scripts/functions/let: Ditto.
* tests/scripts/functions/origin: Ditto.
* tests/scripts/options/dash-e: Add tests.

17 months ago* tests/test_driver.pl: Add cd to the .run output file
Paul Smith [Sun, 4 Feb 2024 14:47:36 +0000 (09:47 -0500)] 
* tests/test_driver.pl: Add cd to the .run output file

17 months agoReplace target_var boolean with enum variable_scope
Dmitry Goncharov [Sun, 28 Jan 2024 19:46:55 +0000 (14:46 -0500)] 
Replace target_var boolean with enum variable_scope

Replace the target_var boolean with an enum to distinguish between
global, target-specific, and pattern-specific variables when defining.

* src/variable.h (enum variable_scope): Introduce enum variable_scope.
Replace parameter target_var of type int with enum variable_scope.
* src/load.c (load_file): Ditto.
* src/main.c (handle_non_switch_argument): Ditto.
* src/read.c (eval_makefile): Ditto.
(eval): Ditto.
(do_define): Ditto.
(record_target_var): Ditto.
(construct_include_path): Ditto.
* src/variable.c (initialize_file_variables): Ditto.
(shell_result): Ditto.
(try_variable_definition): Ditto.
(do_variable_definition): Ditto.

17 months ago* doc/make.texi: Grammar improvements.
Paul Smith [Sat, 27 Jan 2024 22:14:53 +0000 (17:14 -0500)] 
* doc/make.texi: Grammar improvements.

Reported-by: David Apps <davidapps3+gnu@gmail.com>
17 months agoSupport conditional modifiers on all assignment operators
Paul Smith [Thu, 11 Jan 2024 15:05:27 +0000 (10:05 -0500)] 
Support conditional modifiers on all assignment operators

Rework the single "?=" operator to instead allow a "?" modifier to be
prepended to ANY assignment operator.  If "?" is given then the
variable is assigned (using whatever operator comes next) if and only
if the variable is not already defined.  If it is defined then no
action is taken (the right-hand side is not expanded, etc.)

* NEWS: Announce this new feature.
* doc/make.texi: Modify the documentation around assignment operators.
* src/variable.h: Remove the f_conditional variable flavor.
(do_variable_definition): Add an argument specifying conditional.
* src/variable.c (parse_variable_definition): Use the existing flag
"conditional" to remember if we saw "?" rather than the flavor.
When we see "?" skip it and continue trying to parse an assignment.
(try_variable_definition): Pass condition to do_variable_definition().
(initialize_file_variables): Ditto.
(do_variable_definition): Check for conditional up-front: quit if set.
Remove handling of obsolete f_conditional flavor.
* src/read.c (eval_makefile): MAKEFILE_LIST is not conditional.
(do_define): Unset conditional for define with no operator.  Pass the
conditional flag to do_variable_definition().
(construct_include_path): .INCLUDE_DIRS is not conditional.
* src/load.c (load_file): .LOADED is not conditional.
* tests/scripts/variables/conditional: Add new tests.

17 months agoRemove unnecessary parsing during makefile read
Paul Smith [Thu, 11 Jan 2024 04:53:05 +0000 (23:53 -0500)] 
Remove unnecessary parsing during makefile read

* src/read.c (make_word_type): Remove w_varassign from the enum.
(get_next_mword): This function is never called on a string in a place
where we might find a variable assignment.  Any variable assignments
have already been handled via try_variable_definition(), so we don't
need to check for them here.
* tests/scripts/variables/flavors: Check triple-colon assignment in
target-specific variables.

17 months agoCreate a common method for skipping variable references
Paul Smith [Wed, 10 Jan 2024 05:01:33 +0000 (00:01 -0500)] 
Create a common method for skipping variable references

* README.git: Add some notes about using ASAN.
* src/makeint.h: Declare skip_references().
* src/misc.c (skip_reference): A new function that will skip over a
variable reference, counting matching open paren/brace characters.
* src/implicit.c (get_next_word): Replace code with skip_reference().
* src/read.c (conditional_line): Ditto.
(find_map_unquote): Ditto.
(get_next_mword): Ditto.
(parse_variable_definition): Ditto.
* src/function.c (handle_function): Make clear that the passed in
pointers are not modified if the function returns false.
* src/expand.c (expand_string_buf): Don't create local variables to
call handle_function() since it doesn't modify its arguments.
* src/job.c (new_job): Small simplifications.

17 months ago* src/misc.c (writebuf, readbuf): Return a constant -1
Paul Smith [Sat, 27 Jan 2024 20:35:45 +0000 (15:35 -0500)] 
* src/misc.c (writebuf, readbuf): Return a constant -1

17 months ago[SV 65211] Fix load and loadapi tests.
Dmitry Goncharov [Sat, 27 Jan 2024 21:37:59 +0000 (16:37 -0500)] 
[SV 65211] Fix load and loadapi tests.

* scripts/features/load: Suppress unused variable compiler warnings.
* scripts/features/loadapi: Ditto.

17 months ago[SV 65172] Avoid buffer overruns when expanding for $(shell ...)
Paul Smith [Thu, 18 Jan 2024 22:54:59 +0000 (17:54 -0500)] 
[SV 65172] Avoid buffer overruns when expanding for $(shell ...)

Reported-by: MIAOW Miao <guoyr_2013@hotmail.com>
Patch from: Henrik Carlqvist <hc981@poolhem.se>
Test from: Dmitry Goncharov <dgoncharov@users.sf.net>

* src/expand.c (recursively_expand_for_file): Check the variable name
before checking for equality so we don't overrun the buffer.
* tests/scripts/functions/shell: Add a test with a very long variable.

17 months ago[SV 64571] Add --print-targets option
Paul Smith [Tue, 9 Jan 2024 04:14:57 +0000 (23:14 -0500)] 
[SV 64571] Add --print-targets option

Add an option to print a list of targets defined in the makefiles.
Don't print targets of implicit rules, or special targets.  To
support this remember which files are deemed suffix rule targets.

Add a missing warning for single-suffix targets with prerequisites.

Suggested by many.  Sample implementation by Tim <tdhutt@gmail.com>.

* NEWS: Announce the new option and single-suffix warning.
* doc/make.1: Add --print-targets to the man page.
* doc/make.texi: Add --print-targets to the documentation.  Clean up
the text around the definition of suffix rules.
* src/main.c (print_targets_flag): New variable for --print-targets.
(switches): Add a new long option --print-targets.
(main): If the option was provided call print_targets() and exit.
* src/filedef.h (struct file): Add a "suffix" boolean value.  Remove
print_prereqs() since it's static.  Add new print_targets().
* src/file.c (rehash_file): Merge the new suffix value.
(print_prereqs): Used only locally: change to static.
(print_target): Print targets which are not suffix rule targets and
are not special targets.
(print_targets): Call print_target() on each file.
* src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't
need to be static.  Emit ignoring prerequisites for single-suffix
rules as well as double-suffix rules.  Remember which files are
actually suffix rules.
* tests/scripts/features/suffixrules: Test single-suffix behavior.
* tests/scripts/options/print-targets: Add tests for --print-targets.

17 months ago* src/makeint.h: Add an ARRAYLEN macro to compute array sizes
Paul Smith [Sun, 7 Jan 2024 16:28:23 +0000 (11:28 -0500)] 
* src/makeint.h: Add an ARRAYLEN macro to compute array sizes

* src/main.c: Replace inline array length computation with ARRAYLEN.
* src/function.c: Ditto.
* src/read.h: Ditto.

17 months ago* doc/make.texi (Text Functions): [SV 64339] Clarify pattern use.
Paul Smith [Sun, 7 Jan 2024 15:22:20 +0000 (10:22 -0500)] 
* doc/make.texi (Text Functions): [SV 64339] Clarify pattern use.

18 months ago* (all): Update Copyright year to 2024
Paul Smith [Sat, 6 Jan 2024 22:55:04 +0000 (17:55 -0500)] 
* (all): Update Copyright year to 2024

18 months ago[SV 64402] Correct locating "," in ifeq/ifneq conditionals
Paul Smith [Sat, 6 Jan 2024 22:42:40 +0000 (17:42 -0500)] 
[SV 64402] Correct locating "," in ifeq/ifneq conditionals

Ensure that we correctly skip the entirety of a macro or function
reference when searching for the "," separator in an ifeq/ifneq
conditional, including using "$," and also "${foo,bar}".  Note that
this change means that parenthesis OTHER than those used for variable
expansion are not considered special, any longer.

* NEWS: Announce the change.
* src/read.c (conditional_line): Skip variable references when looking
  for "," and ensure that we match closing parens/braces properly.
* tests/scripts/features/conditionals: Add tests for this behavior.

18 months ago[SV 65006] Allow secondary expansion of .EXTRA_PREREQS
Dmitry Goncharov [Sat, 6 Jan 2024 22:39:43 +0000 (17:39 -0500)] 
[SV 65006] Allow secondary expansion of .EXTRA_PREREQS

* src/rule.c (snap_implicit_rules): Set need_2nd_expansion of each
  prerequisite of global .EXTRA_PREREQS.
* src/file.c (snap_file):  Set need_2nd_expansion of each prerequisite
  of target-specific .EXTRA_PREREQS.
* tests/scripts/variables/EXTRA_PREREQS: Add tests.

Reported by Daniel Gerber <dg@atufi.org>.

18 months ago* src/function.c (func_let): Don't edit nonexistent values
Jouke Witteveen [Tue, 2 Jan 2024 00:27:44 +0000 (19:27 -0500)] 
* src/function.c (func_let): Don't edit nonexistent values

* tests/scripts/functions/let: Test trailing whitespace in value list.

18 months ago* doc/make.texi (Text Functions): [SV 64818] Remove redundant text
Paul Smith [Sun, 3 Dec 2023 23:28:25 +0000 (18:28 -0500)] 
* doc/make.texi (Text Functions): [SV 64818] Remove redundant text

18 months ago* .clangd: Add configuration for the clangd LSP server
Paul Smith [Sun, 3 Dec 2023 23:00:01 +0000 (18:00 -0500)] 
* .clangd: Add configuration for the clangd LSP server

19 months ago* doc/make.texi: [SV 64924] Add missing parenthesis
Paul Smith [Mon, 27 Nov 2023 04:21:55 +0000 (23:21 -0500)] 
* doc/make.texi: [SV 64924] Add missing parenthesis

19 months ago* doc/make.texi: Add a quick reference appendix
Paul Smith [Mon, 27 Nov 2023 04:21:06 +0000 (23:21 -0500)] 
* doc/make.texi: Add a quick reference appendix

19 months ago* src/function.c (function_table_entry): Sort
Paul Smith [Mon, 27 Nov 2023 04:20:22 +0000 (23:20 -0500)] 
* src/function.c (function_table_entry): Sort

22 months agomake.texi: Cleanup
Paul Smith [Tue, 29 Aug 2023 18:24:33 +0000 (14:24 -0400)] 
make.texi: Cleanup

22 months agomake.texi: Add an appendix with troubleshooting tips
Paul Smith [Fri, 25 Aug 2023 15:10:34 +0000 (11:10 -0400)] 
make.texi: Add an appendix with troubleshooting tips

22 months agodoc/make.texi: Clean up references to GNU Make
Paul Smith [Tue, 29 Aug 2023 19:20:31 +0000 (15:20 -0400)] 
doc/make.texi: Clean up references to GNU Make

22 months agodoc/make.texi: Remove unnecessary @node arguments
Paul Smith [Tue, 29 Aug 2023 18:44:50 +0000 (14:44 -0400)] 
doc/make.texi: Remove unnecessary @node arguments

22 months agobootstrap.conf: Update to the latest gnulib stable branch
Paul Smith [Fri, 25 Aug 2023 15:10:14 +0000 (11:10 -0400)] 
bootstrap.conf: Update to the latest gnulib stable branch

2 years ago* AUTHORS: Updates
Paul Smith [Tue, 4 Jul 2023 18:19:37 +0000 (14:19 -0400)] 
* AUTHORS: Updates

2 years agoFix GCC compile warning for "bad-function-cast" on Windows
Torbjörn SVENSSON [Fri, 9 Jun 2023 19:00:32 +0000 (21:00 +0200)] 
Fix GCC compile warning for "bad-function-cast" on Windows

Trick the compiler by hiding the cast in a function call.

* src/os.h: Declare the new function.
* src/w32/w32os.c (get_handle_for_fd): Convert and cast a file
descriptor into a Windows HANDLE.
(check_io_state): Call the new function rather than casting.
(osync_release): Ditto.
(fd_inherit): Ditto.
(fd_noinherit): Ditto.
* src/function.c (windows32_openpipe): Ditto.
* src/w32/compat/posixfcn.c (isatty): Ditto.
* src/w32/subproc/sub_proc.c (process_easy): Ditto.

2 years agoFix GCC compile warning for "format-signedness" in Windows
Torbjörn SVENSSON [Fri, 9 Jun 2023 19:00:31 +0000 (21:00 +0200)] 
Fix GCC compile warning for "format-signedness" in Windows

* src/job.c (reap_children): Use unsigned int for DWORD.
* src/w32/subproc/sub_proc.c (process_easy): Ditto.
* src/w32/w32os.c (jobserver_setup): Ditto.
(jobserver_release): Ditto.
(jobserver_acquire): Ditto.

2 years ago* src/w32/compat/posixfcn.c (ttyname): Avoid const char*
Torbjörn SVENSSON [Fri, 9 Jun 2023 14:09:54 +0000 (16:09 +0200)] 
* src/w32/compat/posixfcn.c (ttyname): Avoid const char*

2 years agoFix GCC compile warning for "unused-parameter" on Windows
Torbjörn SVENSSON [Fri, 9 Jun 2023 14:09:55 +0000 (16:09 +0200)] 
Fix GCC compile warning for "unused-parameter" on Windows

* src/w32/compat/posixfcn.c (isatty): Avoid unused-parameter warnings.
(jobserver_pre_child): Ditto.
(jobserver_post_child): Ditto.
(jobserver_acquire): Ditto.
(fd_set_append): Ditto.

2 years agoFix GCC compile warning format-security on Windows
Torbjörn SVENSSON [Fri, 9 Jun 2023 14:09:53 +0000 (16:09 +0200)] 
Fix GCC compile warning format-security on Windows

* src/job.c (create_batch_file): Avoid non-static format strings.
* src/main.c (handle_runtime_exceptions): Ditto.
* src/w32/subproc/w32err.c (map_windows32_error_to_string): Ditto.

2 years agoFix GCC compile warning declaration-after-statement on Windows
Torbjörn SVENSSON [Fri, 9 Jun 2023 14:09:52 +0000 (16:09 +0200)] 
Fix GCC compile warning declaration-after-statement on Windows

* src/w32/w32os.c (check_io_state): Move the HANDLE declarations.

2 years agoAdd a UTF-8 resource when building for Windows
Costas Argyris [Mon, 19 Jun 2023 13:51:13 +0000 (09:51 -0400)] 
Add a UTF-8 resource when building for Windows

If a resource compiler is available, use it to add a UTF-8 resource
to the GNU Make executable on Windows.  As a result, GNU Make will
use UTF-8 as its ANSI code page, enabling it to work with UTF-8
encoded Makefiles, understand UTF-8 paths passed to it, etc.

These build process changes apply to all 3 ways that GNU Make can
be built for Windows:

1) configure
2) Basic.mk
3) build_w32.bat

When building with Visual Studio the resource compiler should always
be available.

When building with GCC or TCC, it depends on the availability of
'windres'.

If a resource compiler is not available, don't fail the build but
just proceed without the UTF-8 resource, effectively ignoring this
feature.

The UTF-8 resource only has an effect when GNU Make is running on a
minimum target version of Windows Version 1903 (May 2019 Update).
When the built GNU Make is running on an earlier version of Windows,
the embedded UTF-8 resource has no effect.

Code page information is added to --version output to tell users what
code pages are being used by any combination of GNU Make build (with
or without the UTF-8 resource) and Windows version that GNU Make is
running on (earlier than 1903 or not).

* README.git: Fix a typo.
* configure.ac: Search for windres and set WINDRES / HAVE_WINDRES.
* Makefile.am: Add manifest and resource files to EXTRA_DIST and
add a windres invocation to build them.
* build_w32.bat: Add support to build resource files.
* src/main.c (print_version): Add codepage info to Windows output.
* src/w32/utf8.manifest: Add a windres manifest file.
* src/w32/utf8.rc: Add a windres resource file.
* Basic.mk.template: Add support for building resource files.
* mk/Windows32.mk: Support windres resource files.
* .gitignore: Ignore TCC output directories.

2 years ago[SV 64124] Avoid stack overflows for large command lines
Paul Smith [Mon, 19 Jun 2023 14:00:11 +0000 (10:00 -0400)] 
[SV 64124] Avoid stack overflows for large command lines

Modify areas dealing with large command lines to use the heap rather
than relying on alloca / stack space.

* src/main.c (main): Allocate potentially large buffers with xmalloc.
(decode_env_switches): Ditto.
* src/function.c (func_error): Replace alloca with xmalloc/free.
* tests/scripts/features/expand: Add a newline for readable diffs.

2 years ago* po/LINGUAS: Add support for Georgian translation
Paul Smith [Mon, 19 Jun 2023 14:04:25 +0000 (10:04 -0400)] 
* po/LINGUAS: Add support for Georgian translation

2 years ago* NEWS: Set a prerelease version
Paul Smith [Mon, 19 Jun 2023 14:04:47 +0000 (10:04 -0400)] 
* NEWS: Set a prerelease version

2 years ago[SV 64815] Recipe lines cannot contain conditional statements
Paul Smith [Tue, 23 May 2023 03:36:13 +0000 (23:36 -0400)] 
[SV 64815] Recipe lines cannot contain conditional statements

* NEWS: Mention this change.
* src/read.c (eval): Check for ignoring for any line even if not
in a rule context.
* tests/scripts/features/conditionals: Write new tests.

2 years agomake -p now uses consistent timestamp format
Paul Eggert [Wed, 10 May 2023 19:10:16 +0000 (12:10 -0700)] 
make -p now uses consistent timestamp format

* NEWS: mention this.
* src/main.c (safer_ctime, time_now): Remove.
(print_data_base): Use file_timestamp_sprintf to format timestamps.

2 years agomake -p buffer overrun fix with outlandish current time
Paul Eggert [Wed, 10 May 2023 19:10:14 +0000 (12:10 -0700)] 
make -p buffer overrun fix with outlandish current time

* src/main.c (safer_ctime): New function.
(print_data_base): Use it.

2 years agomake -p uses same clock as rest of 'make'
Paul Eggert [Wed, 10 May 2023 19:10:15 +0000 (12:10 -0700)] 
make -p uses same clock as rest of 'make'

Without this patch, the output of 'make -p' would generate output that
sometimes incorrectly implied that the clock jumped backwards.
* src/main.c (time_now): New function.
(print_data_base): Use it.

2 years ago[SV 63219] Support an "unload" function for loaded objects
Paul Smith [Sun, 7 May 2023 20:51:12 +0000 (16:51 -0400)] 
[SV 63219] Support an "unload" function for loaded objects

If a loaded object defines a symbol <object>_gmk_unload, assume it's
a function and invoke it whenever the loaded object is unloaded.
Original implementation by Dmitry Goncharov <dgoncharov@users.sf.net>

* NEWS: Announce the change.
* doc/make.texi: Describe the behavior.
* src/gnumake.h: Add information to the comments.
* src/makeint.h (unload_all): Declare a new function.
* src/main.c (die): Invoke unload_all().
* src/load.c (unload_func_t): Declare a new type for unload.
(struct load_list): Remember the unload symbol if it exists.
(load_object): Move the parsing of the object name from load_file.
Check for the _gmk_unload symbol and if found, remember it.
(load_file): Allow load_object to do object filename parsing.
(unload_file): Remove the load_list entry when unloading the object.
(unload_all): Unload all the loaded objects.
* tests/scripts/features/loadapi: Test the unload function.

2 years agoRemove the "preview" status from the loaded object feature
Paul Smith [Sat, 6 May 2023 20:21:39 +0000 (16:21 -0400)] 
Remove the "preview" status from the loaded object feature

Add an ABI version both to the header file and passed to the setup
function.  Unfortunately this itself is an ABI break and I couldn't
find a good way to avoid it.

* NEWS: Announce the ABI is not a preview and the incompatibility.
* doc/make.texi: Remove the preview warnings for object loading.
Document the new ABI version argument.
* src/gnumake.h (GMK_ABI_VERSION): Set the ABI version to 1.
Add comments documenting the format of the setup function.
* src/load.c (setup_func_t): Rename from load_func_t.
(load_file): Pass the ABI version to the setup function.
* tests/scripts/features/load: Rework the setup function.
* tests/scripts/features/loadapi: Ditto.

2 years ago* src/read.c (eval): [SV 40942] Allow targets named "load"
Paul Smith [Sat, 6 May 2023 20:12:11 +0000 (16:12 -0400)] 
* src/read.c (eval): [SV 40942] Allow targets named "load"

Previously "load:" worked but "load :" failed.  Allow the latter as
well.  This doesn't fix all issues; "load foo :" is still treated
as a load operation for "foo" and ":".  Avoids SV 50413 as well.
* tests/scripts/features/load: Write tests.

2 years ago* tests/test_driver.pl: Show info about failed tests
Paul Smith [Sat, 6 May 2023 18:45:56 +0000 (14:45 -0400)] 
* tests/test_driver.pl: Show info about failed tests

Remove working directories for skipped tests.
We use different directories per test so don't keep rmfiles.

2 years ago* tests/scripts/features/comments: Add missing "1;"
Paul Smith [Sat, 6 May 2023 18:45:09 +0000 (14:45 -0400)] 
* tests/scripts/features/comments: Add missing "1;"

2 years ago[SV 64124] Avoid use-after-free in expand_variable_buf()
Dmitry Goncharov [Sun, 30 Apr 2023 13:39:04 +0000 (09:39 -0400)] 
[SV 64124] Avoid use-after-free in expand_variable_buf()

When the expanded value of the variable in buf occupies more space
than available in variable_buffer, function variable_buffer_output
reallocates variable_buffer: return a pointer into the new memory,
not the old memory.

* src/expand.c (expand_variable_buf): Preserve the offset of buf and
return that offset into the (potentially reallocated) buffer.
* tests/scripts/features/expand: Add tests.

2 years ago[SV 64115] Suppress warnings about undefined GNUMAKEFLAGS
Dmitry Goncharov [Sun, 30 Apr 2023 13:30:19 +0000 (09:30 -0400)] 
[SV 64115] Suppress warnings about undefined GNUMAKEFLAGS

* src/variable.c (defined_vars): Add GNUMAKEFLAGS to defined variables.
* tests/scripts/options/warn: Add a test.

2 years ago[SV 64107] Disable builtins immediately on -R or -r
Dmitry Goncharov [Sun, 30 Apr 2023 13:26:29 +0000 (09:26 -0400)] 
[SV 64107] Disable builtins immediately on -R or -r

Disable builtin variables and rules immediately, when -R or -r is
added to MAKEFLAGS inside the makefile.

* src/main.c (disable_builtins): Add new function disable_builtins().
(main): Call disable_builtins().
(reset_makeflags): Call disable_builtins().
* tests/scripts/options/dash-r: Add tests.
* tests/scripts/variables/MAKEFLAGS: Update tests.

2 years ago* tests/scripts/features/double_colon: Test parallel double-colon rules
Paul Smith [Sun, 30 Apr 2023 13:19:06 +0000 (09:19 -0400)] 
* tests/scripts/features/double_colon: Test parallel double-colon rules

Original test proposed by Dmitry Goncharov <dgoncharov@users.sf.net>

2 years ago* src/remake.c (update_goal_chain): [SV 64016] Avoid double negation
Dmitry Goncharov [Sun, 30 Apr 2023 13:07:17 +0000 (09:07 -0400)] 
* src/remake.c (update_goal_chain): [SV 64016] Avoid double negation