Commit Graph

25 Commits

Author SHA1 Message Date
Paul Smith
a80670ad41 * (all): Update Copyright year to 2024 2024-01-06 18:06:09 -05:00
Paul Smith
c2792d6129 Adjust output strings to be aligned
Change error and fatal messages to start with lowercase and not
end with a period.  Note a few very common messages were left
as-is, just in case some other tools parse them.

Also modify the test known-good-output to satisfy the messages.
2023-04-02 10:02:18 -04:00
Paul Smith
a0d1e76d60 Add support for .WARNINGS special variable
Create a new special variable, .WARNINGS, to allow per-makefile
control over warnings.  The command line settings will override
this.

Move the handling of warning flags to a new file: src/warning.c.
Allow the decode to work with generic strings, and call it from
decode_switches().

* Makefile.am: Add new file src/warning.c.
* build_w32.bat: Ditto.
* builddos.bat: Ditto.
* po/POTFILES.in: Ditto.
* src/makeint.h: #define for the .WARNINGS variable name.
* src/warning.h: Add declarations for methods moved from main.c.
Rename the enum warning_state to warning_action.
* src/warning.c: New file.  Move all warning encode/decode here
from main.c.
* src/main.c: Move methods into warning.c and call those methods
instead.
(main): Set .WARNINGS as a special variable.
* src/job.c (construct_command_argv): Rename to warning_action.
* src/read.c (tilde_expand): Ditto.
* src/variable.c (set_special_var): Update warnings when the
.WARNINGS special variable is set.
* tests/scripts/options/warn: Check invalid warning options.
* tests/scripts/variables/WARNINGS: Add tests for the .WARNINGS
special variable.
2023-04-02 10:02:18 -04:00
Paul Smith
6128c3e266 Rename WINDOWS32 macro to MK_OS_W32
* configure.ac: Set MK_OS_W32 to 1 if we're on Windows32.
* src/config.h.W32: Ditto.
* mk/Windows32.mk: Ditto.
* src/makeint.h: Convert #if refs to WINDOWS32, to use MK_OS_W32.
* src/*: Ditto.
* src/w32/*: Ditto.
* gl/lib/*: Ditto.
2023-01-15 18:27:13 -05:00
Paul Smith
e7ce3a655e Convert references from "GNU make" to "GNU Make" 2023-01-01 17:05:12 -05:00
Paul Smith
56d2978141 Update the copyright year on all files 2023-01-01 10:06:01 -05:00
Dmitry Goncharov
8f9e7722ff [SV 63537] Fix setting -w in makefiles
* src/makeint.h: Replace print_directory flag with should_print_dir().
* src/main.c (main): Remove print_directory flag and related code.
(should_print_dir): Create.
* src/output.c (output_dump): Use should_print_dir().
(output_start): Ditto.
2022-12-18 20:06:38 -05:00
Dmitry Goncharov
1b51ba1f5d [SV 63333] Be more lenient when failing to create temporary files
If make cannot create a temporary lock file for output sync, continue
without output sync enabled rather than dying.

However, if make cannot store a makefile from stdin to a temporary
file that is still a fatal error.

* misc.c (get_tmppath): Keep running on failure to generate a
temporary file name.
(get_tmpfd): Keep running on failure to get a temporary file.
(get_tmpfile): Keep running on failure to open a temporary file.
Ensure memory is freed if we return an error.
* posixos.c (os_anontmp): Keep running on failure to open an
anonymous temporary file.
* output.c (setup_tmpfile): Print an error on failure to create an
output sync lock file.
* main.c (main): Die on failure to store makefile from stdin to a
temporary file.
* tests/scripts/features/output-sync: Add tests.
* tests/scripts/features/temp_stdin: Ditto.
2022-11-13 16:34:01 -05:00
Paul Smith
d18a87d0a4 [SV 63260] Don't recurse forever if setup_tmpfile() fails
If we fail during setup_tmpfile() we'll try to write an error, which
will invoke setup_tmpfile() again, etc.  Avoid infinite recursion.
Original patch by Dmitry Goncharov <dgoncharov@users.sf.net>

* src/output.c (setup_tmpfile): Remember we're in this function and
return immediately if we enter it during recursion.
(message): Remember the starting location and use that instead of
fmtbuf.buffer.
(error): Ditto.
(fatal): Ditto.
2022-10-24 01:50:12 -04:00
Paul Smith
41c35f2ffe * src/output.c (_outputs): Don't use invalid output sync FDs
Just write to stdout/stderr in this situation.
2022-10-24 01:50:12 -04:00
Paul Smith
d9fc1ac5d2 Update URLs to use https rather than http
* (all): Change http:// to https://
* README.W32: Remove invalid link to mingw.org.
2022-10-18 14:37:47 -04:00
Paul Smith
26e359c71d [SV 62840] Don't change IO buffering before printing version
If users run 'make --version | head -n1' they expect make to exit
with a success (0) code.  This works because the pipe forces the
default buffering on stdout to be fully buffered so all the output
is printed to the pipe in a single write(2) and won't fail.  However
due to output sync we forcibly set stdout to line buffered, which
means if the reader closes the pipe fast enough make will exit with
an error code because the write to stdout failed.

Move the setup done in output_init() back into main() where it can
be done in a proper order.  Rework the order of operations during
startup so that we check for help and version flags before we change
the buffering.  Clean up the behavior of print_usage().

Original changes from Dmitry Goncharov <dgoncharov@users.sf.net>.

* src/main.c (switches): Don't send --version in the environment.
(print_usage): Add a blank line after the version before the usage.
Move the die() into this function since we always die() afterward.
Note the die will flush so no need to do it explicitly.
(print_version): The caller will fflush when appropriate.
(close_stdout): Move from output.c so it is installed early.
(decode_switches): Only call print_usage on error, not for --help.
(main): Install the close_stdout handler immediately after start.
Move the calls to print_usage() due to --help and --version to be
called immediately after we decode the switches.  Move the buffer set
here from output_init(), immediately after we know we'll be running.
* src/output.c (output_init): Move buffer setting to main().
(close_stdout): Move to main().
2022-08-30 21:04:48 -04:00
Paul Smith
4da2055a10 Rework output sync to lock a temp file on POSIX
Some POSIX systems do not allow locks to be taken on non-files, such
as pipes.  This is a problem since very often make is invoked with
its stdout redirected to a pipe.  Also, if stdout is redirected to a
file that already has a lock on it for some other reason (perhaps a
shared file such as /dev/null) it can cause a hang.

This means our previous method of locking stdout, although it had some
nice advantages, is not portable enough.  Instead, use a temporary
file and take the lock on that.  We pass the name of the file to child
make processes.  On Windows we continue to use a shared mutex for
output sync.

Remove POSIX emulation functions like fcntl from Windows; instead
follow the lead of the jobserver and create an interface in os.h for
output sync, and move the OS-specific content to posixos.c and
w32os.c.

* NEWS: Add a note.
* src/makeint.h (ALL_SET): Check that all bits are set.
* src/os.h: Add bits for checking the state of stdin/stdout/stderr.
Add prototypes for OS-specific output sync methods.
* src/posixos.c (check_io_state): Determine the status of stdin,
stdout, stderr an return a suite of bits describing them.
(osync_enabled): If the global variable holding the FD of the lock
file (osync_handle) is valid return true.
(osync_setup): Create a temporary file and remember its name in a
global variable (osync_tmpfile), and set osync_handle.
(osync_get_mutex): If output sync is enabled, return the filename
of the lock file prefixed with "fnm:" to denote a filename.
(osync_parse_mutex): If the provided filename has the wrong format
disable output sync.  Else open the lock file and set osync_handle.
(osync_clear): Close osync_handle.  If we're the parent make, then
also unlink the temporary file.
(osync_acquire): Take a lock on the osync_handle descriptor.
(osync_release): Release the lock on the osync_handle descriptor.
(fd_set_append): Add APPEND mode to a file descriptor.
* src/w32/w32os.c: Perform the same actions as posixos.c, copying
the details from src/w32/compat/posixfcn.c.  Use a mutex rather
than locking a temporary file.
* src/output.h: Remove all the OS-specific content.
* src/output.c: Remove all the OS-specific content.
(set_append_mode): Remove and replace with fd_set_append().
(sync_init): Remove and replace with check_io_state().
(acquire_semaphore): Remove and replace with osync_acquire().
(release_semaphore): Remove and replace with osync_release().
(setup_tmpfile): If the IO state is not obtained, get it.  If stdout
and/or stderr are valid, set up a tempfile to capture them.
(output_init): Set io_state if not set already, and check it when
deciding whether to close stdout on exit.
* src/main.c (main): If we're syncing, set up the mutex using the
new osync_setup() / osync_parse_mutex() methods.
(prepare_mutex_handl_string): Replace with osync_parse_mutex().
(die): Call osync_clear().
* src/w32/compat/posixfcn.c: Remove implementations of fcntl(),
record_sync_mutex(), create_mutex(), and same_stream().
2022-08-30 15:44:43 -04:00
Paul Smith
a2ba5ccbda Add get_tmpfd() and allow anonymous temp files
The output sync feature wants a file descriptor not a FILE*.  We were
using tmpfile() but this returns FILE* which means we needed to dup()
the descriptor then fclose() the original, which is just unnecessary
overhead for every command we run.

Create a get_tmpfd() method that returns a file descriptor directly
by using mkstemp() if available, else do the best we can.

Also allow anonymous temp files if the filename pointer is NULL.
This causes the file to be unlinked.  On Windows this requires a
special open so add an os_anontmp() method to handle this.

* src/makeint.h: Add prototype for get_tmpfd().
* src/misc.c (get_tmpfd): If we have mkstemp() use that, else just
open(2).  If we don't want to keep the filename, unlink the file.
(get_tmpfile): Use get_tmpfd() if we have fdopen(), else use fopen().
* src/output.c (output_tmpfd): Call get_tmpfd() with NULL.
* src/os.h (os_anontmp): On Windows make this a function, else fails.
* src/w32/compat/posixcfn.c (tmpfile): Move to w32os.c:os_anontmp().
* src/w32/w32os.c (os_anontmp): Create a temp file that will be deleted
when the process exits, and return a file descriptor to it.
2022-08-30 15:39:02 -04:00
Paul Smith
5dc7358547 * configure.ac: Remove AC_FUNC_SETVBUF_REVERSED.
This macro is obsolete: no useful system has this problem anymore.
* src/output.c (output_init): Remove reference to SETVBUF_REVERSED.
* src/config.ami.template: Remove undef of SETVBUF_REVERSED.
* src/config.h-vms.template: Ditto.
* src/config.h.W32.template: Ditto.
2022-07-09 10:47:13 -04:00
Paul Smith
ec09ec775a * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
Paul Smith
80b90b7866 [SV 57967] Only set APPEND mode for regular files
APPEND is a permanent mode shared by all users of a file.  If we
set it on a tty, pipe, etc. it will stay in effect even after make
exits, which can cause problems.

Patch provided by 0xef967c36@gmail.com

* src/output.c (set_append_mode): Check for a regular file.

Copyright-paperwork-exempt: yes
2020-03-31 00:19:20 -04:00
Paul Smith
8e024a2532 Obey order of multiple print/no-print directory options
Previously if --no-print-directory was seen anywhere even once
(environment, command line, etc.) it would always take precedence
over any --print-directory option.  Change this so that the last
seen option (which will be the command line, if present there) takes
precedence.

* NEWS: Mark this change in behavior.
* src/makeint.h (print_directory): A new variable to control printing.
* src/output.c (output_dump): Use the new variable.
(output_start): Ditto.
* src/main.c: Add a new variable print_directory.  Use -1 for
print_directory_flag so we know of the option was seen or not.  Add a
new default_print_directory_flag set to -1 to keep options from being
added.
(switches): Use flag_off for --no-print-directory, rather than a
separate inhibit_print_directory_flag.
(main): If print_directory_flag was set by the user, use that for
print_directory.  If not, compute the print_directory value based on
-s, -C, and sub-makes as before.
* tests/scripts/variables/GNUMAKEFLAGS: -w is not added automatically
* tests/scripts/options/print-directory: Add tests for overriding
print-directory options.
2020-03-31 00:17:49 -04:00
Paul Smith
12b14f0484 Update copyright statements for 2020 2020-01-03 02:08:59 -05:00
Eli Zaretskii
715c787dc6 Fix MS-Windows MinGW build
* src/w32/subproc/sub_proc.c (process_wait_for_multiple_objects):
Fix format specifier for GetLastError's value.

* src/job.c (reap_children): Define the 'remote_status_lose' label
only for Posix platforms, to avoid compiler warning.

* build_w32.bat (LNKOUT): New variable, using forward slashes.
Use forward slashes in calls to :Compile, so that linking with GNU
ld works.

* src/makeint.h [!HAVE_UMASK]: Prototype for 'umask'.
(UMASK, MODE_T): Don't define.

* src/misc.c (get_tmpfile): Don't call UMASK, call umask, to
avoid compilation warning on !HAVE_UMASK platforms.
* src/output.c (output_tmpfd): Likewise.

* src/misc.c (umask) [!HAVE_UMASK]: New no-op function.

* src/config.h.W32.template (__USE_MINGW_ANSI_STDIO)
[__MINGW32__]: Define to 1, to force Make use ANSI-compatible
stdio functions, which also support the non-standard 'Id' and 'Ix'
specifiers.
(HAVE_UMASK) [__MINGW32__]: Define to 1.

* src/arscan.c (ar_member_touch): Type-cast argument of strlen to
avoid compiler warnings.
2019-08-28 17:45:49 +03:00
Paul Smith
389dcb608f Update copyright statements for 2019 2019-05-19 15:27:26 -04:00
Paul Smith
5d6508a475 Change output_write() to writebuf(), add readbuf() helper.
* src/misc.c (writebuf, readbuf): Create helper functions that will
reliably write a buffer to a file descriptor in the face of EINTR
causing short writes, and read from a file descriptor into a buffer
in the face of EINTR causing short reads.
* src/makeint.h: Declare these functions.
* src/output.c: Remove output_write() and replace with writebuf().
(_outputs, out_of_memory): Call writebuf(), not output_write().
* src/arscan.c (ar_scan): Call readbuf() instead of read(2).
(ar_member_touch): Remove duplicate header write, call writebuf()
instead of output_write(), and readbuf() instead of read(2).
2018-09-16 01:04:10 -04:00
Paul Smith
0ce880e5ee Resolve most of the Windows Visual Studio warnings.
* Convert integer types to size_t where necessary.
* Align other integral types to avoid casts and type warnings.
2018-07-02 07:54:07 -04:00
Paul Smith
afbecbd9dc * all: Update Copyright statements for 2018 2018-07-01 12:22:04 -04:00
Paul Smith
fb779d2f1e Rework directory structure to use GNU-recommended "src" directory.
Move the source code (other than glob) into the "src" subdirectory.
Update all scripting and recommendations to support this change.

* *.c, *.h, w32/*: Move to src/
* configure.ac, Makefile.am, maintMakefile: Locate new source files.
* Basic.mk.template, mk/*: Update for new source file locations.
* NEWS, README.DOS.template: Update for new locations.
* build.template, build_w32.bat, builddos.bat: Ditto.
* po/POTFILES.in: Ditto
* tests/run_make_tests.pl, tests/scripts/features/load*: Ditto.
* make.1: Move to doc.
* mk/VMS.mk: Add support for building on VMS (hopefully).
* makefile.vms, prepare_w32.bat: Remove.
* SCOPTIONS: Update to define HAVE_CONFIG_H
2017-11-19 14:07:22 -05:00