summaryrefslogtreecommitdiff
path: root/src/makeint.h
Commit message (Collapse)AuthorAgeFilesLines
* [SV 63219] Support an "unload" function for loaded objectsPaul Smith2023-05-141-0/+1
| | | | | | | | | | | | | | | | | | | | 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.
* Remove the "preview" status from the loaded object featurePaul Smith2023-05-071-1/+0
| | | | | | | | | | | | | | | | 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.
* Add support for .WARNINGS special variablePaul Smith2023-04-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Introduce a --warn command line optionPaul Smith2023-04-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace the singleton --warn-undefined-variables with infrastructure to manage multiple warnings: the --warn option can take an action "ignore", "warn", or "error" (which will apply to all warnings), or a specific warning type and an action for that type. Multiple options can be provided and are consolidated. * NEWS: Announce the new option. * doc/make.1: Document in the man page. * doc/make.texi (Warnings): Document in the user's manual. * Makefile.am: Add new header warning.h. * src/warning.h: Define enum for actions and warning types, and macros to test whether they are set. Keep the default settings separate so that we can correctly reconstruct MAKEFLAGS. * src/makeint.h: Remove deprecated warn_undefined_variables_flag. * src/main.c: Create global variables to hold warning settings. (switches): Add a new switch for --warn. (initialize_warnings): Set the default warning actions. (main): Call initialize_warnings(). (encode_warning_state, decode_warning_state): Convert warning states between strings and enums. (encode_warning_name, decode_warning_name): Convert warning names between strings and enums. (decode_warn_flags): Convert a --warn option into enum values. If deprecated warn_undefined_variables_flag is set convert it to --warn. (decode_switches): Don't remove duplicates of --warn since order matters. Call decode_warn_flags() to handle --warn. (define_makeflags): Special-case handling of --warn options written to MAKEFLAGS: write out the current settings. * src/read.c (tilde_expand): Use new warning control macros. * src/variable.c (warn_undefined): Ditto. * src/job.c (construct_command_argv): Ditto. * tests/scripts/options/warn: Rename from warn-undefined-variables and add tests for --warn. * tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
* Clean up expand.cPaul Smith2023-03-261-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Clarify the naming and documentation on functions in src/expand.c: - variable_expand -> expand_string - variable_expand_string -> expand_string_buf - variable_expand_for_file -> expand_string_for_file - allocated_variable_expand -> allocated_expand_string - allocated_variable_expand_for_file -> allocated_expand_string_for_file Change all callers to use the new names. * src/variable.h: Rename the functions and macros. * src/expand.c: Ditto. * src/file.c: Use the new function names. * src/function.c: Ditto. * src/implicit.c: Ditto. * src/job.c: Ditto. * src/loadapi.c: Ditto. * src/main.c: Ditto. * src/read.c: Ditto. * src/remake.c: Ditto. * src/variable.c: Ditto. * src/vpath.c: Ditto. * src/w32/subproc/sub_proc.c: Ditto.
* * src/expand.c (swap_variable_buffer): Swap two variable buffersPaul Smith2023-03-261-0/+4
| | | | | | | | Return the current buffer instead of freeing it. (variable_append): Use install/swap to handle variable buffers. (allocated_variable_expand_for_file): Ditto. * src/variable.c (shell_result): Ditto. * src/variable.h: Declare the new function.
* Clean up some preprocessor operationsPaul Smith2023-01-161-9/+9
|
* Use MK_OS_OS2 macro instead of __EMX__Paul Smith2023-01-161-2/+6
| | | | | * src/makeint.h: Set MK_OS_OS2 to 1 if __EMX__ is set. * src/*: Convert #if refs to __EMX__, to use MK_OS_OS2.
* Rename WINDOWS32 macro to MK_OS_W32Paul Smith2023-01-151-4/+4
| | | | | | | | | | * 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.
* Rename VMS macro to MK_OS_VMSPaul Smith2023-01-151-9/+10
| | | | | | * src/makeint.h: Set MK_OS_VMS to 1 if we're on VMS. * src/*: Convert all #if references to VMS, to use MK_OS_VMS. * gl/lib/*: Ditto.
* * src/makeint.h [CYGWIN]: Use pipe mode for the jobserverPaul Smith2023-02-191-2/+5
|
* * src/makeint.h (WIN32_LEAN_AND_MEAN) [Windows]: Don't redefine.Paul Smith2023-02-191-1/+3
| | | | Suggested for tcc builds by Christian Jullien <eligis@orange.fr>.
* Allow jobserver style to be forced to "pipe"Paul Smith2023-02-191-0/+11
| | | | | | | | | | | | | | Some systems that support mkfifo() don't support the usage that GNU make wants. Provide a way to force using "pipe" jobserver mode even when mkfifo() is available. * src/makeint.h (MK_OS_HURD): Define if we're on Hurd. (JOBSERVER_USE_FIFO): Define if we have mkfifo() and we're NOT on Hurd. * src/main.c (main): Test JOBSERVER_USE_FIFO not HAVE_MKFIFO. * src/posixos.c (jobserver_setup): Ditto. * maintMakefile: Create a config check test for forcing "pipe" mode. * tests/run_make_tests.pl: Show discovered FEATURES in verbose mode.
* [SV 62654] Support GNU Make on z/OSPaul Smith2023-01-081-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Original patches provided by Igor Todorovski <itodorov@ca.ibm.com> Reworked by Paul Smith <psmith@gnu.org>. Thanks to IBM for providing a test system. * NEWS: Announce support. * AUTHORS: Ditto. * README.zOS: Provide details on building GNU Make on z/OS. * build.sh (get_mk_var): z/OS sh has a strange bug which causes it to generate extra lines of output: rework the function to print output as we compute it instead of collecting it into a variable, which works around this bug. * src/makeint.h: Declare MK_OS_ZOS if we're building for z/OS. * src/arscan.c: Don't include <ar.h> on z/OS. * src/job.c: We can't change environ in ASCII mode on z/OS. * src/main.c: Ditto. Also we can't use pselect() on z/OS. * src/posixos.c: pselect() seems to hang on z/OS: don't use it. * tests/run_make_tests.pl: Handle different exit codes on z/OS. * tests/test_driver.pl: Preserve some special z/OS env.vars. Add special checks to output comparisons when on z/OS. * tests/scripts/features/archives: Don't validate names. Don't try to compile empty files as IBM compilers complain. * tests/scripts/features/shell_assignment: Fix octal value of #. * tests/scripts/features/temp_stdin: Don't print "term". * tests/scripts/functions/shell: Handle shell exit codes. * tests/scripts/targets/ONESHELL: Ditto. * tests/scripts/targets/POSIX: sh -x prints differently. * tests/scripts/variables/SHELL: Ditto.
* Create src/mkcustom.h which is included by config.hPaul Smith2023-01-081-39/+0
| | | | | | | | | | | | | | | | Put declarations for missing functions which we create in src/misc.c into a file which is included by config.h via AH_BOTTOM(). This ensures those prototypes are available, even in files added to lib/... from gnulib. * src/mkcustom.h: Add a new file with function declarations. * configure.ac: Include src/mkcustom.h in config.h with AH_BOTTOM() * Makefile.am: Add the header to the SRCS list. * src/makeint.h: Remove content that we added to src/mkcustom.h. * src/config.ami: Add #include "mkcustom.h" to specialized config.h. * src/config.h-vms: Ditto. * src/config.h.W32: Ditto. * src/configh.dos: Ditto.
* Include <strings.h> globallyPaul Smith2023-01-081-2/+4
| | | | | | | | | | Various code uses str{,n}casecmp() so include <strings.h>, if it exists, everywhere. * configure.ac: Check for <strings.h> explicitly. * src/makeint.h: Include it if HAVE_STRINGS_H, for str{,n}casecmp(). * src/job.c: Remove include of <strings.h>. * src/main.c: Ditto.
* Update the copyright year on all filesPaul Smith2023-01-011-1/+1
|
* [SV 63552] Change directories before constructing include pathsPaul Smith2022-12-241-2/+2
| | | | | | | | | | | | | | * src/makeint.h (reset_makeflags): New function to handle changing MAKEFLAGS from within makefiles. Remove decode_env_switches(). * src/variable.c (set_special_var): Call reset_makeflags() instead of various internal methods. * src/main.c (decode_env_switches): Only internal now so make static. (decode_switches): Don't invoke construct_include_path() yet. (reset_makeflags): Decode env switches and construct include paths. (main): Construct include paths after we process -C options. * tests/scripts/options/dash-C: Rewrite to use new test constructs. Add a test using both -C and -I together. Add a test for multiple -C options.
* [SV 63537] Fix setting -w in makefilesDmitry Goncharov2022-12-181-1/+2
| | | | | | | | * 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.
* [SV 63516] [DOS] Support include files with drivespecsPaul Smith2022-12-181-2/+14
| | | | | | | | | * src/makeint.h (HAVE_DRIVESPEC): Create a macro to check. * src/main.c (.FEATURES): Add "dospaths" as a feature. * src/read.c (eval_makefile) [DOS]: If the included makefile name starts with a drivespec, don't search the include directories. * doc/make.texi (Include): Document this behavior. * tests/scripts/features/include: Add a test.
* [SV 63417] Ensure global .NOTINTERMEDIATE disables all intermediatesDmitry Goncharov2022-11-281-0/+2
| | | | | | | | | | | | | | | | | Fix .NOTINTERMEDIATE without prerequisites to disable intermediate status for all targets. * src/makeint.h: Declare extern no_intermediates. * src/main.c: Add global definition of no_intermediates. * src/file.c: Remove static no_intermediates to use global variable. (remove_intermediates): Check no_intermediates. * src/implicit.c (pattern_search): For a file found by implicit search set file->notintermediate if no_intermediates is set. * src/remake.c (update_file_1): Don't set file->secondary for a pre-existing file if no_intermediates is set. The check for no_intermediates here is redundant, but won't hurt: keep it in case things change so that it matters. * tests/scripts/targets/NOTINTERMEDIATE: Fix a test.
* [SV 63347] Always add command line variable assignments to MAKEFLAGSDmitry Goncharov2022-11-281-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit introduces two visible changes: 1. Keep command line variable assignments in MAKEFLAGS at all times, even while parsing makefiles. 2. Define makeflags immediately when a makefile modifies MAKEFLAGS. The new MAKEFLAGS and MAKEOVERRIDES initialization procedure: 1. decode_switches (argc, argv, o_command) is called to parse command line variable assignments. 2. Command line variable assignments go through quote_for_env. Initialize -*-command-variables-*- to the quoted values. 3. MAKEOVERRIDES is initialized to refer to -*-command-variables-*- with origin o_env to keep the definitions in the database intact. 4. define_makeflags() is called which adds MAKEOVERRIDES to MAKEFLAGS. 5. Makefiles are parsed. If a makefile modifies MAKEFLAGS, the new value of MAKEFLAGS is defined right away. 6. Env switches are decoded again as o_env. The definitions set by decode_switches at step 1 stay intact, as o_command beats o_env. We must preserve the original intact definitions in order to detect failure cases; for example: $ cat makefile all:; $(hello) $ make hello='$(world' makefile:1: *** unterminated variable reference. Stop. * src/makeint.h: Declare enum variable_origin, struct variable and define_makeflags(). Add parameter origin to decode_env_switches(). * src/main.c (define_makeflags): Remove "all". If a variable is assigned on the command line then append MAKEOVERRIDES to MAKEFLAGS. (decode_env_switches): Replace parameter env with origin. (decode_switches): Replace parameter env with origin. Treat origin == o_command as env == 0. (handle_non_switch_argument): Replace parameter env with origin. Treat origin == o_command as env == 0. (main): Call decode_switches() with origin==o_command before parsing makefiles. Call decode_switches() with origin==o_env after parsing makefiles. * src/variable.c (set_special_var): Define makeflags at parse time, each time a makefile modifies MAKEFLAGS. (do_variable_definition): Strip command line variable assignments from MAKEFLAGS before appending extra flags. set_special_var() adds them back. * tests/scripts/variables/MAKEFLAGS: Add tests.
* * src/rule.c (get_rule_defn): Don't use STRING_SIZE_TUPLE in mempcpyPaul Smith2022-10-231-0/+2
| | | | If mempcpy() is a macro then STRING_SIZE_TUPLE won't compile.
* Provide a maintainer-only debug methodPaul Smith2022-10-231-0/+4
| | | | | | | | | | | Generating debug logs to stdout or stderr makes it impossible to run tests etc. so create a dumb DBG facility to log to a temp file. This exists only in maintainer mode and the DBG macro gives a compile error if it's used in non-maintainer mode. * src/makeint.h (DBG): Call dbg() in maintainer mode, else error. (dbg): Define it in maintainer mode. * src/misc.c (dbg): Open a log file for append, write, then close.
* Set PATH_MAX on systems without a default valuePaul Smith2022-10-221-4/+5
| | | | | | | | | | | | | | | | Some systems (HURD) use fully-dynamic pathnames, with no limit. We can't support this without significant effort so for now set PATH_MAX to a large value. * src/makeint.h: Set PATH_MAX to 4096 if not set and MAXPATHLEN is also not set. Remove MAXPATHLEN setting: we won't use it. * src/misc.c (get_path_max): If we can't get the path max via pathconf() use the default PATH_MAX. * src/dir.c (find_directory) [W32]: Use MAX_PATH not MAXPATHLEN. (local_stat) [W32]: Ditto. * src/job.c (create_batch_file) [W32]: Ditto. * src/remake.c (name_mtime) [W32]: Ditto. * src/w32/w32os.c (os_anontmp) [W32]: Ditto.
* Update URLs to use https rather than httpPaul Smith2022-10-181-1/+1
| | | | | * (all): Change http:// to https:// * README.W32: Remove invalid link to mingw.org.
* Rework temp file handling to avoid GNU libc warningsPaul Smith2022-10-181-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Original patch provided by Paul Eggert <eggert@cs.ucla.edu>. GNU libc will generate a link-time warning if we use mktemp() even though we are using it safely (we only use it with mkfifo()). Avoid this and clean up some handling. First, check all calls related to temporary files and exit with a fatal error and a useful message if we can't obtain them. In some situations it might be possible to continue with reduced capability but it's not worth the effort. On POSIX systems we can create anonymous temp files using O_TMPFILE if it's supported, else if we're using the default location and we have dup(2), we can use standard tmpfile() and get an FD from it. If we need a named temp file and FILE* and we have mkstemp() we can use that, else if we have fdopen() we can get a temp FD and open it. If none of those are available all we can do is generate a temp name then open it with fopen() which is not secure. * src/makeint.h (get_tmpdir): Declare it for use elsewhere. * src/misc.c (get_tmpdir): Make it public not static. (get_tmptemplate): Simplify the implementation. (get_tmppath): Only define this if we have to have it to avoid warnings from GNU libc. (get_tmpfd): Generate fatal errors on error. (get_tmpfile): Ditto. Open files in "wb+" mode to match tmpfile(). Require a filename pointer (all callers want it). * src/os.h (os_anontmp): Implement for posixos.c as well. * src/posix.c (jobserver_setup): Don't use mktemp to avoid GNU libc errors. Instead construct the FIFO name based on the PID. (osync_setup): get_tmpfd() can't fail so don't check it. (os_anontmp): If the system supports O_TMPFILE use it. If not, and we want to create the temporary file in the default directory, we can use tmpfile() then use dup() to copy the file descriptor. * src/main.c (main): get_tmpfile() can't fail. * src/vmsjobs.c (child_execute_job): get_tmpfile() can't fail.
* Add ISDIRSEP() helper macro and use itPaul Smith2022-10-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Create a ISDIRSEP() macro to check for directory separator chars using the stopchar_map, and replace inline checks and explicit STOP_SET calls with this macro. * src/makeint.h (ISDIRSEP): Create the macro using MAP_DIRSEP. * src/dir.c (find_directory): Replace inline checks with ISDIRSEP. (file_exists_p): Ditto. (file_impossible): Ditto. (file_impossible_p): Ditto. (local_stat): Ditto. * src/file.c (lookup_file): Ditto. * src/function.c (abspath): Ditto. * src/job.c (_is_unixy_shell): Ditto. (is_bourne_compatible_shell): Ditto. (construct_command_argv): Ditto. * src/main.c (find_and_set_default_shell): Ditto. (main): Ditto. * src/read.c (eval): Ditto. (parse_file_seq): Ditto. * src/remake.c (name_mtime): Ditto. * src/vpath.c (construct_vpath_list): Ditto.
* Use (void) rather than () in function declarationsPaul Smith2022-10-151-6/+6
| | | | | | | | | | | In C, a function declaration with () allows any set of arguments. Use (void) to mean "no arguments". * src/dep.h: Switch () to (void) for functions with no arguments. * src/makeint.h: Ditto. * src/os.h: Ditto. * src/shuffle.h: Ditto. * src/variable.h: Ditto.
* [SV 63157] Ensure temporary files are removed when signaledPaul Smith2022-10-151-0/+1
| | | | | | | | | | | | | | | | | | Original patch from Dmitry Goncharov <dgoncharov@users.sf.net>. When handling a fatal signal ensure the temporary files for stdin and the jobserver fifo (if in use) are deleted. * src/makeint.h (temp_stdin_unlink): Declare a new method. * src/main.c (temp_stdin_unlink): Delete the stdin temporary file if it exists. If the unlink fails and we're not handling a signal then show an error. (main): Call temp_stdin_unlink() instead of unlinking by hand. * src/commands.c (fatal_error_signal): Invoke cleanup methods if we're handling a fatal signal. * tests/scripts/features/output-sync: Test signal handling during output sync and jobserver with FIFO. * tests/scripts/features/temp_stdin: Test signal handling when makefiles are read from stdin.
* Set the proper type for variables set in signal handlersPaul Smith2022-10-151-1/+1
| | | | | | | * bootstrap.conf: Get gnulib's sig_atomic_t type checking M4 macro. * configure.ac: Invoke it. * src/makeint.h (handling_fatal_signal): Set the type correctly. * src/commands.c (handling_fatal_signal): Ditto.
* Support systems with 32-bit long and 64-bit time_tPaul Eggert2022-10-031-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | | Don't assume that time_t fits in long, as some hosts (e.g., glibc x86 -D_TIME_BITS=64) have 32-bit long and 64-bit time_t. * bootstrap.conf (gnulib_modules): Add largefile, to support files with timestamps after Y2038 on hosts with 32-bit long. * configure.ac: Do not call AC_SYS_LARGEFILE, as the largefile module does that for us. * src/makeint.h (PRIdMAX, PRIuMAX, SCNdMAX): Define if not already defined (taken from gnulib). * src/ar.c: Include intprops.h, for TYPE_MAXIMUM, as INTEGER_TYPE_MAXIMUM does not work on time_t without issuing a bunch of warnings. (ar_member_date): Check that result is in time_t range. (ar_member_date_1): Use intmax_t to hold the date. (ar_glob_match): Ditto. * src/arscan.c (VMS_function, VMS_function_ret, ar_scan) (parse_int, ar_scan, ar_member_pos, ar_member_touch) (describe_member): Convert long int to intmax_t. * src/file.c (file_timestamp_sprintf): Use intmax_t/uintmax_t instead of long/unsigned long for values that might be time_t. * src/arscan.c (ar_member_touch): Fix buffer overrun if the timestamp is too large.
* Implement a simple xorshift 32bit random number generatorPaul Smith2022-10-011-0/+2
| | | | | | | | | | | | | | | | Avoid relying on the system random number generator for our random shuffle, so that the same seed gives the same results on all systems. This generator doesn't need to be amazing, just pretty good, so don't bother with xorshift* or xorshift+, etc. * src/makeint.h: Declare make_seed() and make_rand(). * src/misc.c (make_seed): Set the seed value for the RNG. (make_rand): Return the next random number. If the seed was not set initialize it first. * src/shuffle.c (shuffle_set_mode): If we don't get a seed from the user just leave it unset (0). (shuffle_deps_recursive): Use make_seed() not srand(). (random_shuffle_array): Use make_rand() not rand().
* Provide new functions to convert long long to stringPaul Smith2022-09-251-8/+2
| | | | | | | | | | | | | | | | | | | | The previous attempt to use PRI* macros to avoid compiler-specific printf format specifiers didn't work because we are using raw long long type, not the uintX_t types. On systems where long and long long are the same size, uint64_t might be type "long" and PRId64 is just "ld". Instead write new functions that convert [unsigned] long long to a string and call those instead. * src/makeint.h: Declare make_lltoa() and make_ulltoa(). * src/misc.c (make_lltoa): New function that writes a long long value into a provided buffer. Return the buffer for ease-of-use. (make_ulltoa): Ditto, for unsigned long long. * src/function.c (func_wordlist): Call these new methods. Also rework the error strings so we share the translated string. * src/dir.c (print_dir_data_base): Call the new methods instead of using MSVC macros.
* * src/misc.c (strncasecmp): Use size_t for length to match std.Paul Smith2022-09-251-1/+1
| | | | * src/misc.h (strncasecmp): Fix the declaration.
* Fix compiler warnings in the MS-Windows build.Eli Zaretskii2022-09-251-0/+8
| | | | | | | | | | | * src/w32/w32os.c (osync_get_mutex, osync_parse_mutex): Cast to DWORD_PTR when converting integers to HANDLEs and vice versa. * src/w32/pathstuff.c (w32ify): Pacify compiler warnings about 'strncpy'. * src/makeint.h (PRId64) [!HAVE_INTTYPES_H]: Define if undefined. * src/function.c (func_wordlist): Use PRId64 instead of %lld.
* [SV 63045] Reload each intact unloaded shared objectDmitry Goncharov2022-09-121-2/+4
| | | | | | | | | | | | | | | | | | | | | | | If makefile rules do not update an unloaded shared object, load it again. Avoid double loading of the same object if the setup function returns -1. * src/filedef.h (struct file): Add "unloaded" flag. * src/makeint.h (load_file): Take struct file *. (unload_file): Return int. * src/main.c (main): Reload unloaded shared objects if they weren't updated. * src/commands.c (execute_file_commands): Set "unloaded" and reset "loaded" when a shared object is unloaded. * src/read.c (eval): Set "loaded" and reset "unloaded" when a shared object is loaded. Add successfully loaded files to the db. * src/load.c (load_file): Check "loaded" to avoid double loading the same object. Fix a memory leak of string loaded. Return -1, rather than 1, if the object is already loaded. This fixes double loading of the same object when the setup routine returns -1. (load_object): Add a log message. (unload_file): Return an error on dlclose failure. Log a message. * tests/scripts/features/loadapi: Add new tests.
* Rework output sync to lock a temp file on POSIXPaul Smith2022-08-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
* Add get_tmpfd() and allow anonymous temp filesPaul Smith2022-08-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Enhance get_tmpfile() and add get_tmppath()Paul Smith2022-08-021-1/+2
| | | | | | | | | | | | | | | | | | Move all the logic on creating temporary files into misc.c, and add a new function get_tmppath() that returns the pathname to a temporary file without creating or opening it. * src/makeint.h: Add a declaration for get_tmppath(). Remove the template argument from get_tmpfile(): it will compute its own. * src/main.c (main): Remove the logic for computing templates. * src/vmsjobs.c (child_execute_job): Ditto. * src/misc.c (get_tmptemplate): New function to return an allocated template string for use with various mktemp-style functions. (get_tmppath): Return an allocated path to a temporary file, but do not create it. Generally this should be avoided due to TOCTOU issues. (get_tmpfile): Use get_tmptemplate() to generate a template rather than using one passed in. If we don't have mkstemp() then use get_tmppath() to compute the path of a temp file.
* Disable the jobserver in non-recursive childrenPaul Smith2022-07-301-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Savannah issues such as SV 57242 and SV 62397 show how passing references to closed file descriptors via the --jobserver-auth option in MAKEFLAGS can lead to problematic outcomes. When computing the child environment for a non-recursive shell, add an extra option to MAKEFLAGS to disable the file descriptors for the jobserver. Unfortunately this doesn't modify the value of the make variable MAKEFLAGS, it only modifies the value of the sub-shell environment variable MAKEFLAGS. This can lead to confusion if the user is not considering the distinction. * src/makeint.h: Publish the jobserver-auth value. Add a global definition of the name of the command line option. * src/os.h (jobserver_get_invalid_auth): New function to return a string invalidating the jobserver-auth option. * src/w32/w32os.c (jobserver_get_invaid_auth): Implement it. On Windows we use a semaphore so there's no need to invalidate. * src/posixos.c (jobserver_parse_auth): If we parse the invalid auth string, don't set up the jobserver. (jobserver_get_invalid_auth): Return an invalid option. * src/variable.h (target_environment): Specify if the target environment is for a recursive shell or non-recursive shell. * src/variable.c (target_environment): Move checking for MAKELEVEL into the loop rather than doing it at the end. Along with this, check for MAKEFLAGS and MFLAGS, and update them based on whether we're invoking a recursive or non-recursive child, and also on whether it's necessary to invalidate the jobserver. * src/function.c (func_shell_base): Shell functions can never be recursive to pass 0 to target_environment(). * src/job.c (start_job_command): Specify whether the child is recursive when calling target_environment(). * src/main.c: Export jobserver_auth. sync_mutex doesn't need to be exported. Use the global definition for the option name. * tests/scripts/variables/MAKEFLAGS: Add tests for $MAKEFLAGS.
* Take advantage of mempcpy() and stpcpy()Paul Smith2022-07-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | * src/makeint.h (stpcpy): Add missing declaration. * src/amiga.c (MyExecute): Avoid extra strlen using stpcpy. * src/function.c (func_shell_base): Ditto. (func_error): Use memcpy() not strcpy() when we know the length. * src/job.c (construct_command_argv_internal): Use stpcpy(). * src/main.c (main): Ditto. (define_makeflags): Ditto. * src/variable.c (print_target_variables): Use memcpy() when we know the length. * src/commands.c (set_file_variables): Use mempcpy(). * src/expand.c (variable_buffer_output): Ditto. * src/file.c (expand_deps): Ditto. * src/function.c (abspath): Ditto. (handle_function): Ditto. * src/implicit.c (pattern_search): Ditto. * src/job.c (construct_command_argv_internal): Use mempcpy() and don't add multiple spaces when there are no shell flags. * src/main.c (decode_env_switches): Use mempcpy() to simplify. (define_makeflags): Ditto. * src/variable.c (selective_vpath_search): Ditto.
* getloadavg: Remove support for privileged invocationPaul Smith2022-07-091-4/+0
| | | | | | | | | | | | | | | | | | | | | | | This was needed when getloadavg required privileged access; in this case GNU make needed to be installed as a setgid program. But this hasn't been supported by gnulib getloadavg() since 2011 and systems are no longer using it, so remove it. * src/makeint.h (user_access): Remove unnecessary function. (make_access): Ditto. (child_access): Ditto. * src/misc.c: Remove implementations of the *_access() functions. * src/main.c (main): Remove unneeded call to user_access(). * src/job.c (load_too_high): Remove calls to {make,user}_access(). (exec_command): Remove call to child_access(). * src/remote-cstms.c: Remove calls to these methods. I suppose it might be possible this is needed and was piggy-backing on the privileged setting but since that's been broken for a while I doubt this is needed. If so we can bring back the implementation into this source file. * src/config.h.W32.template: Remove GETLOADAVG_PRIVILEGED undef. * src/config.h-vms.template: Ditto. * src/config.ami.template: Ditto.
* Run autoupdate and clean up autoconf usagePaul Smith2022-07-091-12/+2
| | | | | | | | | | | | | | | | | | | | | | | | | We can assume that the return type of a signal handler is void. We can assume that, if sys/time.h exists, it can be included with time.h. * bootstrap: Get the latest version * configure.ac: Require a newer version of autoconf. Remove unnecessary AC_PROG_CC_C99 (already have AC_PROC_CC). Remove unnecessary AC_AIX, AC_ISC_POSIX, AC_MINIX. Remove unnecessary AC_HEADER_STDC, AC_HEADER_TIME, AC_TYPE_SIGNAL. Use strerror to search for the cposix library. * src/commands.c (fatal_error_signal): Assume return type is void. * src/commands.h: Ditto. * src/job.c: Ditto. * src/job.h: Ditto. * src/main.c: Ditto. * src/makeint.h: Ditto. Don't bother with TIME_WITH_SYS_TIME. * src/remote-cstms.c: Check HAVE_SYS_TIME_H. * src/config.ami.template: Remove RETSIGTYPE. * src/config.h-vms.template: Ditto. * src/config.h.W32.template: Ditto. Remove TIME_WITH_SYS_TIME.
* [SV 62514] Honor command line interface flagsDmitry Goncharov2022-07-091-1/+0
| | | | | | | | | | | | | | Commit f2771aa614 introduced a bug where some switches were left out of MAKEFLAGS. Instead of resetting switches, get the same results by filtering out duplicates. * src/makeint.h: Remove reset_switches. * src/main.c: (reset_switches): Remove reset_switches. * (main): Remove call to reset_switches. * (decode_switches): Filter out duplicate flags. * src/variable.c: (set_special_var): Remove call to reset_switches. * tests/scripts/variables/MAKEFLAGS: Verify that duplicate flags are properly filtered out.
* * src/misc.c (make_toui): Parse a string into an unsigned intPaul Smith2022-06-041-0/+1
| | | | | | | | | * src/makeint.h: Declare it. * src/arscan.c (ar_scan): Replace atoi() calls with make_toui(). Modify some integral types to be more correct. * src/job.c (load_too_high): Replace atoi() calls with make_toui(). * src/main.c (main): Ditto. (decode_switches): Ditto.
* * src/misc.c (make_pid): A function to return the PIDPaul Smith2022-06-041-0/+1
| | | | | * src/makeint.h: Declare it. * src/commands.c (fatal_error_signal): Call it.
* Ensure buffers are large enough for integer valuesPaul Smith2022-02-211-1/+1
| | | | | | | | | | Issue raised by Sergei Trofimovich <siarheit@google.com> * src/makeint.h (INTSTR_LENGTH): Update for unsigned values. * src/function.c (func_lastword): Use INTSTR_LENGTH as buffer size. (shell_function_completed): Ditto. (func_call): Ditto. * src/remote-cstms.c (start_remote_job): Ditto.
* * <all>: Update copyright notices.Paul Smith2022-02-101-1/+1
|
* * src/makeint.h: Compute INTSTR_LENGTH based on size of intmax_tPaul Smith2021-12-191-3/+10
| | | | Math suggested by Edward Welbourne <edward.welbourne@qt.io>