Commit graph

3132 commits

Author SHA1 Message Date
Marco Sirabella
0b91f42f58 * src/arscan.c (ar_name_equal): Support GNU ar's -P option. 2024-03-28 19:08:13 -04:00
Marco Sirabella
882d59c672 * tests/README: Fix sample run_make_tests command line. 2024-03-24 16:36:35 -04:00
Paul Smith
5fc62f8295 * doc/make.texi: GNU Make does set GNUMAKEFLAGS, to empty. 2024-03-24 16:29:14 -04:00
Paul Smith
3d4f3e0627 * 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.
2024-03-24 16:23:28 -04:00
Paul Smith
242603fa46 [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.
2024-03-24 15:25:53 -04:00
Paul Smith
b8a2a4424b [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.
2024-03-24 15:25:18 -04:00
Jouke Witteveen
bfbf169b63 [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.
2024-03-24 14:08:59 -04:00
Paul Smith
21a538ce8f [SV 65359] doc/make.texi: Describe invalid export variable names 2024-03-24 14:05:45 -04:00
Paul Smith
3176b60566 [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.
2024-02-04 19:41:50 -05:00
Dmitry Goncharov
07187db947 [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.
2024-02-04 18:26:21 -05:00
Paul Smith
a493d9ab6c * NEWS: Clean up 2024-02-04 11:34:49 -05:00
Dmitry Goncharov
a382ac6cd1 [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.
2024-02-04 11:34:49 -05:00
Paul Smith
63b602e74f * tests/test_driver.pl: Add cd to the .run output file 2024-02-04 11:34:49 -05:00
Dmitry Goncharov
ec348f51d0 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.
2024-02-04 11:32:50 -05:00
Paul Smith
51e56a028e * doc/make.texi: Grammar improvements.
Reported-by: David Apps <davidapps3+gnu@gmail.com>
2024-01-28 14:21:00 -05:00
Paul Smith
1eff20f6f6 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.
2024-01-28 14:20:47 -05:00
Paul Smith
82708b3a3a 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.
2024-01-27 16:40:36 -05:00
Paul Smith
828906b6dc 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.
2024-01-27 16:40:36 -05:00
Paul Smith
b936970956 * src/misc.c (writebuf, readbuf): Return a constant -1 2024-01-27 16:40:36 -05:00
Dmitry Goncharov
1e43a5d104 [SV 65211] Fix load and loadapi tests.
* scripts/features/load: Suppress unused variable compiler warnings.
* scripts/features/loadapi: Ditto.
2024-01-27 16:40:36 -05:00
Paul Smith
25049fef16 [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.
2024-01-27 16:40:36 -05:00
Paul Smith
31036e648f [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.
2024-01-08 23:31:58 -05:00
Paul Smith
1ff728bff4 * 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.
2024-01-07 11:28:23 -05:00
Paul Smith
1161779ef8 * doc/make.texi (Text Functions): [SV 64339] Clarify pattern use. 2024-01-07 10:22:20 -05:00
Paul Smith
a80670ad41 * (all): Update Copyright year to 2024 2024-01-06 18:06:09 -05:00
Paul Smith
d86448fe5f [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.
2024-01-06 17:42:40 -05:00
Dmitry Goncharov
33932663b0 [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>.
2024-01-06 17:39:43 -05:00
Jouke Witteveen
89bea82af3 * src/function.c (func_let): Don't edit nonexistent values
* tests/scripts/functions/let: Test trailing whitespace in value list.
2024-01-01 19:31:37 -05:00
Paul Smith
dd1980426e * doc/make.texi (Text Functions): [SV 64818] Remove redundant text 2024-01-01 19:24:37 -05:00
Paul Smith
2ce7e40822 * .clangd: Add configuration for the clangd LSP server 2024-01-01 19:24:37 -05:00
Paul Smith
b1e240c554 * doc/make.texi: [SV 64924] Add missing parenthesis 2023-11-26 23:21:55 -05:00
Paul Smith
7fa40eb4fc * doc/make.texi: Add a quick reference appendix 2023-11-26 23:21:06 -05:00
Paul Smith
8817efe46a * src/function.c (function_table_entry): Sort 2023-11-26 23:20:22 -05:00
Paul Smith
66adfb7c6f make.texi: Cleanup 2023-09-01 16:57:58 -04:00
Paul Smith
9af3e60f4d make.texi: Add an appendix with troubleshooting tips 2023-08-29 15:39:16 -04:00
Paul Smith
8061929963 doc/make.texi: Clean up references to GNU Make 2023-08-29 15:20:31 -04:00
Paul Smith
cd33c9a1e9 doc/make.texi: Remove unnecessary @node arguments 2023-08-29 14:44:50 -04:00
Paul Smith
c4ecd9d9eb bootstrap.conf: Update to the latest gnulib stable branch 2023-08-25 11:10:14 -04:00
Paul Smith
6b7f35cb0b * AUTHORS: Updates 2023-07-04 14:26:58 -04:00
Torbjörn SVENSSON
1000374759 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.
2023-07-04 14:26:58 -04:00
Torbjörn SVENSSON
8d76fb8778 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.
2023-07-01 12:49:24 -04:00
Torbjörn SVENSSON
ee366afbf1 * src/w32/compat/posixfcn.c (ttyname): Avoid const char* 2023-07-01 12:49:24 -04:00
Torbjörn SVENSSON
b686980c66 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.
2023-07-01 12:49:24 -04:00
Torbjörn SVENSSON
8e5c96c318 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.
2023-07-01 12:49:24 -04:00
Torbjörn SVENSSON
363bdaef8c Fix GCC compile warning declaration-after-statement on Windows
* src/w32/w32os.c (check_io_state): Move the HANDLE declarations.
2023-07-01 12:49:20 -04:00
Costas Argyris
b2bf660abc 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.
2023-06-19 13:29:52 -04:00
Paul Smith
04f4c2b8d9 [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.
2023-06-19 13:27:50 -04:00
Paul Smith
347316fdf6 * po/LINGUAS: Add support for Georgian translation 2023-06-19 10:05:19 -04:00
Paul Smith
1a03888afa * NEWS: Set a prerelease version 2023-06-19 10:05:19 -04:00
Paul Smith
07fcee35f0 [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.
2023-05-22 23:36:13 -04:00