summaryrefslogtreecommitdiff
path: root/src/file.c
Commit message (Collapse)AuthorAgeFilesLines
* Adjust output strings to be alignedPaul Smith2023-04-021-7/+7
| | | | | | | | 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.
* Clean up memory leak warnings from ASAN and ValgrindPaul Smith2023-04-011-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | * src/main.c (main): Add "sanitize" to .FEATURES if ASAN is enabled. * src/expand.c (expand_variable_output): Remember "recursive" setting in case it's changed by the expansion of the variable. * src/file.c (rehash_file): If we drop a file from the global 'files' hash, remember it in rehashed_files. We can't free it because it's still being referenced (callers will invoke check_renamed()) but it will be a leak since it's no longer referenced by 'files'. * src/remake.c (update_file_1): If we drop a dependency, remember it in dropped_list. We can't free it because it's still being referenced by callers but it will be a leak since it's no longer referenced as a prerequisite. * tests/scripts/functions/guile: Don't run Guile tests when ASAN is enabled. * tests/scripts/functions/wildcard: Enabling ASAN causes glob(3) to break! Don't run this test. * tests/scripts/features/exec: Valgrind's exec() doesn't support scripts with no shbang. * tests/scripts/jobserver: Valgrind fails if TMPDIR is set to an invalid directory: skip those tests. * tests/scripts/features/output-sync: Ditto. * tests/scripts/features/temp_stdin: Ditto.
* Clean up expand.cPaul Smith2023-03-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rename VMS macro to MK_OS_VMSPaul Smith2023-01-151-5/+5
| | | | | | * 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.
* Remove support for AmigaOSPaul Smith2023-01-151-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a lot of specialized code for supporting AmigaOS and it has not been maintained for a number of years. It's highly unlikely that the latest versions even compile properly on AmigaOS anymore. After requesting that someone step forward to own the maintenance of the port in the GNU Make 4.4 release and getting no takers, I removed it. * NEWS: Announce the removal. * README.in: Remove README.Amiga reference. * README.Amiga: Remove unused file. * SCOPTIONS: Ditto. * src/amiga.c: Ditto. * src/amiga.h: Ditto. * src/config.ami: Ditto. * mk/Amiga.mk: Ditto. * Makefile.am: Remove references to deleted files. * Basic.mk.template: Ditto. * maintMakefile: Ditto. * src/commands.c: Remove ifdef'd Amiga code. * src/default.c: Ditto. * src/dir.c: Ditto. * src/file.c: Ditto. * src/function.c: Ditto. * src/job.c: Ditto. * src/job.h: Ditto. * src/main.c: Ditto. * src/os.h: Ditto. * src/read.c: Ditto. * src/remake.c: Ditto.
* Update the copyright year on all filesPaul Smith2023-01-011-1/+1
|
* Apply spelling fixes discovered by CodespellPaul Smith2022-12-311-1/+1
| | | | | | | | | | | | | | | | | | * maintMakefile: Apply spelling fixes. * src/file.c: Ditto. * src/misc.c: Ditto. * src/remake.c: Ditto. * src/vmsjobs.c: Ditto. * src/w32/pathstuff.c: Ditto. * tests/test_driver.pl: Ditto. * tests/run_make_tests.com: Ditto * tests/scripts/features/implicit_search: Ditto * tests/scripts/features/output-sync: Ditto * tests/scripts/features/patternrules: Ditto * tests/scripts/features/se_explicit: Ditto * tests/scripts/features/statipattrules: Ditto * tests/scripts/functions/foreach: Ditto * tests/scripts/variables/MAKEFLAGS: Ditto
* [SV 63417] Ensure global .NOTINTERMEDIATE disables all intermediatesDmitry Goncharov2022-11-281-5/+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.
* 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.
* Add ISDIRSEP() helper macro and use itPaul Smith2022-10-181-12/+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.
* Support systems with 32-bit long and 64-bit time_tPaul Eggert2022-10-031-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* [SV 13862] Implement the .WAIT special targetPaul Smith2022-09-121-7/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The next version of the POSIX standard defines parallel execution and requires the .WAIT special target as is implemented in some other versions of make. This implementation behaves similarly to others in that it does not create a relationship between targets in the dependency graph, so that the same two targets may be run in parallel if they appear as prerequisites elsewhere without .WAIT between them. Now that we support .WAIT it's trivial to also support prerequisites of the .NOTPARALLEL special target, which forces the prerequisites of those targets to be run serially (as if .WAIT was specified between each one). * NEWS: Announce the new .WAIT and .NOTPARALLEL support. * doc/make.texi (Parallel Disable): A new section to discuss ways in which parallel execution can be controlled. Modify cross-refs to refer to this section. * src/dep.h (struct dep): Add a new wait_here boolean. (parse_file_seq): Add PARSEFS_WAIT to check for .WAIT dependencies. * src/file.c (split_prereqs): Use PARSEFS_WAIT. (snap_deps): If .NOTPARALLEL has prerequisites, set .WAIT between each of _their_ prerequisites. (print_prereqs): Add back in .WAIT when printing prerequisites. * src/implicit.c (struct patdeps): Preserve wait_here. (pattern_search): Ditto. Use PARSEFS_WAIT when parsing prereqs for pattern rule expansion. * src/read.c (check_specials): Don't give up early: remembering to update these options is not worth the rare speedup. (check_special_file): If .WAIT is given as a target show an error-- once--if it has prereqs or commands. (record_files): Call check_special_file on each target. (parse_file_seq): If PARSEFS_WAIT is given, look for .WAIT prereqs. If we see one assume that we are building a struct dep chain and set the wait_here option while not putting it into the list. * src/remake.c (update_file_1): If wait_here is set and we are still running, then stop trying to build this target's prerequisites. * src/rule.c (get_rule_defn): Add .WAIT to the prerequisite list. * src/shuffle.c (shuffle_deps): Don't shuffle the prerequisite list if .WAIT appears anywhere in it. * tests/scripts/targets/WAIT: Add a test suite for this feature.
* [SV 63047] Fix shuffle of SECONDEXPANSION prerequisitesSergei Trofimovich2022-09-121-0/+10
| | | | | | | | | | | | | | Commit 07eea3aa4 `make --shuffle` prevented shuffling prerequisites that use .SECONDEXPANSION, since shuffle happens before expansion. This has two problems: 1. No shuffling happens for such prerequisites. 2. Use-after-free when outdated '->shuf' links are used. Add a reshuffle into expansion phase right after dependency changes. * src/file.c (expand_deps): Add reshuffle if dependencies change. * src/shuffle.c (identity_shuffle_array): Fix comment typo. * tests/scripts/options/shuffle: Add new SECONDEXPANSION test.
* [SV 62706] Only second-expand targets that might be builtDmitry Goncharov2022-07-301-38/+10
| | | | | | | | | | | | | | | | | | | | | Second-expand only the prerequisites of the targets being built. Defer second-expanding the prerequisites of targets until we need to decide if they should be built. * NEWS: Mention the change in behavior. * doc/make.texi (Secondary Expansion): Document the new behavior. * src/filedef.h (struct file): Add flag snapped. (expand_deps): Declare a function to second expand the prerequisites of a target. * src/file.c (rehash_file): Merge flag snapped. (expand_deps): Remove qualifier static. Check flag snapped. (snap_deps): Remove the loop which performed second expansion for all targets. * src/remake.c (update_file_1): Second expand the prerequisites of the considered target. * tests/scripts/features/se_explicit: Add tests. * tests/scripts/features/se_implicit: Ditto. * tests/scripts/features/se_statpat: Ditto.
* Take advantage of mempcpy() and stpcpy()Paul Smith2022-07-301-4/+2
| | | | | | | | | | | | | | | | | | | | | | | * 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.
* [SV 62650] Show correct warning when combining targetsDmitry Goncharov2022-07-091-4/+4
| | | | | | | * src/file.c (rehash_file): Fix warning message. (rehash_file): Fix comment to match the behavior. * tests/scripts/features/se_explicit: Fix test. * tests/scripts/features/mult_rules: Add a new test.
* [SV 62324] Simplify set_file_variables by passing in the stemDmitry Goncharov2022-04-241-8/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we always used the file->stem value as our stem in set_file_variables(); when that wasn't correct we had to temporarily set that value while the function was called, then reset it afterward. This led to issues (for example when we assumed the stem was a cached string but it wasn't). Avoid this by passing in the stem as an argument so that different values can be provided. Add tests to verify this. * src/commands.c (set_file_variables): Take second parameter stem to relieve the callers of set_file_variables() from setting/restoring file->stem. * src/commands.h (set_file_variables): Ditto. (execute_file_commands): Pass file->stem to set_file_variables(). * src/file.c (expand_deps): Pass d->stem to set_file_variables() and remove set and restore of file->stem. * src/implicit.c (pattern_search): Pass stem to set_file_variables() and remove set and restore of file->stem. * tests/scripts/features/se_explicit: Add new tests. * tests/scripts/features/se_implicit: Ditto. * tests/scripts/features/se_statpat: Ditto. * tests/scripts/variables/automatic: Ditto.
* [SV 62278] Only expand the first pattern during secondary expansionDmitry Goncharov2022-04-241-14/+57
| | | | | | | | | | | | | | | | During normal pattern rule expansion only the first pattern (%) is expanded; however during secondary expansion all patterns were expanded. Modify secondary expansion to match the behavior of normal expansion. Implementation tweaked by Paul Smith <psmith@gnu.org> * src/file.c (expand_deps): Don't use subst_expand() which replaces all % with $*: instead replace only the first one, by hand. Fix a memory leak where the dep structure was not always freed. * tests/scripts/features/statipattrules: Use .RECIPEPREFIX not TAB. Add a series of tests verifying that static pattern rules with and without secondary expansion both return the same results.
* Remove extraneous characters from fatal() callsPaul Smith2022-02-271-2/+2
| | | | | | | | | | | The fatal() method adds ". Stop.\n" to every message. * src/amiga.c (MyExecute): Remove newline from fatal() message. * src/job.c (<various>): Ditto. * src/file.c (snap_deps): Remove "." from fatal() message. * src/main.c (main): Ditto. * src/load.c: Ditto. * tests/scripts/targets/NOTINTERMEDIATE: Fix expected output.
* * <all>: Update copyright notices.Paul Smith2022-02-101-1/+1
|
* [SV 60435] Ensure intermediate grouped files are removedDmitry Goncharov2021-09-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | If multiple intermediate files are built together be sure all of them are removed after make is finished. Continue to ensure that targets that exist before make starts are not removed even if they appear to be intermediate. Add a number of tests to pattern rules to verify this behavior. * src/filedef.h (struct file): Add a new is_explicit bitfield. * src/file.c (rehash_file): Merge the is_explicit bit. (enter_prereqs): Set is_explicit if the file is explicitly mentioned. * src/implicit.c (pattern_search): Set intermediate on the file if it's not explicit. (record_files): Set is_explicit if a file is mentioned as a target. * src/remake.c (update_file_1): Set secondary on files that already exist so they won't be removed. * tests/scripts/features/double_colon: Add a test for double-colon pattern rules. * tests/scripts/features/patternrules: Update KGO for tests where more files are removed. Add new tests to verify handling removal of intermediate files in the context of grouped pattern targets.
* [SV 60297] Add .NOTINTERMEDIATE special targetDmitry Goncharov2021-07-251-5/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support a new special target, .NOTINTERMEDIATE. Any file or pattern prerequisite of this target will never be considered intermediate. This differs from .SECONDARY in that .SECONDARY files won't be deleted but they will still not be built if they are missing. .NOTINTERMEDIATE files are treated the same way as a target which is explicitly mentioned in the makefile. This is mostly useful with patterns; obviously mentioning a target explicitly here is enough in and of itself to make something not intermediate. Some adjustments made by psmith@gnu.org * NEWS: Announce the new feature. * doc/make.texi (Special Targets): Document .NOTINTERMEDIATE. (Chained Rules): Describe how to use .NOTINTERMEDIATE. * src/main.c (main): Add "notintermediate" to the .FEATURES variable. * src/filedef.h (struct file): Add "notintermediate" flag. * src/file.c (no_intermediates): Mark global .NOTINTERMEDIATE. (snap_file): Support .NOTINTERMEDIATE special target. Throw an error if the same target is marked both .NOTINTERMEDIATE and .SECONDARY or .INTERMEDIATE. (rehash_file): Merge intermediate, notintermediate, secondary flags. (remove_intermediates): Check notintermediate flag before removing. (print_file): * src/implicit.c (pattern_search): Set notintermediate based on the pattern. * tests/scripts/targets/NOTINTERMEDIATE: Add a new test suite.
* Ensure variable_buffer is always set.Paul Smith2021-03-151-7/+7
| | | | | | | | | | | | | | | | | | | Initialize the global variable_buffer in main() so that it is never a null pointer. Then invoking variable_expand("") is never needed: simply use the variable_buffer pointer when we want to restart the variable buffer. The main point of this simplification is not to keep a separate pointer to the beginning of the buffer: this is dangerous because the buffer may be re-allocated. Instead always use the variable_buffer pointer itself. * src/variable.h (initialize_variable_output): Publish. * src/expand.c (initialize_variable_output): Remove static. * src/main.c (main): Initialize variable_buffer. * src/file.c (enter_prereqs): Don't call variable_expand("") and don't save a separate buffer pointer than might be outdated. (expand_deps): Ditto. * src/read.c (record_files): Ditto. * src/remake.c (library_search): Ditto.
* * file.c (remove_intermediates): Restart "rm ..." on errorPaul Smith2021-03-071-1/+5
|
* Enable compilation with C90 compilersPaul Smith2020-01-041-1/+2
| | | | | | | | | | | | | * configure.ac: Try compiling Guile headers: they don't work with C90. * maintMakefile: Simplify config checks via target-specific variables. * src/makeint.h: Use ATTRIBUTE rather than defining __attribute__, as that causes compile issues with system headers. (ENUM_BITFIELD): Don't use enum bitfields in ANSI mode. * src/main.c: Use ATTRIBUTE instead of __attribute__. * src/job.h: Ditto. * src/file.c: Don't define variables inside for loops. * src/rule.c: Ditto. * src/dep.h (SI): Only use static inline in non-ANSI mode.
* Update copyright statements for 2020Paul Smith2020-01-031-1/+1
|
* Support the .EXTRA_PREREQS special variablePaul Smith2020-01-031-20/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initial implementation by Christof Warlich <cwarlich@gmx.de> * NEWS: Announce the new feature. * doc/make.texi (Other Special Variables): Document .EXTRA_PREREQS. * src/dep.h (struct dep): New flag to note extra prereq deps. * src/filedef.h (expand_extra_prereqs): Declare a function to expand the value of .EXTRA_PREREQS. * src/file.c (expand_extra_prereqs): Given a struct variable lookup of .EXTRA_PREREQS, convert it into a list of deps and for each one make sure it has a struct file and has the new flag set. (snap_file): A new function invoked by hash_map that will perform per-file operations: set up second expansion, intermediate, and also .EXTRA_PREREQS. Manage circular dependencies by ignoring them. (snap_deps): Defer per-file operations until the end. Look up the global .EXTRA_PREREQS and pass it along to snap_file for each file. * src/implicit.c (struct patdeps): Remember the extra prereqs flag. (pattern_search): Transfer extra prereqs flag settings into the matched pattern rule. * src/rule.h (snap_implicit_rules): Rename count_implicit_rules to snap_implicit_rules since we now do more than count. * src/rule.c (snap_implicit_rules): As we walk through all the pattern rules, add in any global .EXTRA_PREREQS to the dep list. Ensure we take them into account for the max number of prereqs and name length. * src/main.c (main): Add extra-prereqs to .FEATURES. Call the renamed snap_implicit_rules. * tests/scripts/variables/EXTRA_PREREQS: Add tests.
* [SV 54740] Ensure .SILENT settings do not leak into sub-makesPaul Smith2019-05-191-2/+2
| | | | | | | | | | | | | | Create a new variable run_silent to hold the current instance's global silence setting, allowing silent_flag to represent only whether the -s option was provided on the command line. * src/makeint.h: Change silent_flag variable to run_silent. * src/job.c: Ditto. * src/remake.c: Ditto. * src/file.c: Ditto. * src/main.c: Add a new global variable run_silent. (decode_switches): After switches are decoded, initialize run_silent. * tests/scripts/targets/SILENT: Add a test for recursive behavior.
* Update copyright statements for 2019Paul Smith2019-05-191-1/+1
|
* [SV 54233] Preserve higher command_state values on also_make targets.Paul Smith2018-08-041-2/+5
| | | | | | | | | | | | | | If multiple pattern rules have the same pattern as also-make targets and we attempt to run them at the same time, we might downgrade the command state from 'running' to 'deps_running'; this will prevent that also_make from being considered complete causing make to wait forever for it to finish. Ensure that set_command_state never downgrades the state of a target. * src/file.c (set_command_state): Don't downgrade command_state. * src/filedef.h (struct file): Document the order prerequisite. * test/scripts/features/patternrules: Test the behavior.
* Resolve most of the Windows Visual Studio warnings.Paul Smith2018-07-021-5/+5
| | | | | * Convert integer types to size_t where necessary. * Align other integral types to avoid casts and type warnings.
* * all: Update Copyright statements for 2018Paul Smith2018-07-011-1/+1
|
* Rework directory structure to use GNU-recommended "src" directory.Paul Smith2017-11-191-0/+1148
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