summaryrefslogtreecommitdiff
path: root/src/read.c
Commit message (Collapse)AuthorAgeFilesLines
* * src/read.c (eval): [SV 40942] Allow targets named "load"Paul Smith2023-05-071-2/+5
| | | | | | | Previously "load:" worked but "load :" failed. Allow the latter as well. This doesn't fix all issues; "load foo :" is still treated as a load operation for "foo" and ":". Avoids SV 50413 as well. * tests/scripts/features/load: Write tests.
* Move local headers after system headersPaul Smith2023-04-031-9/+9
| | | | | | | | | Avoid compiler warnings on Windows by moving local headers after system headers. * src/job.c: Move all headers other than makeint.h. * src/main.c: Ditto. * src/read.c: Ditto.
* Adjust output strings to be alignedPaul Smith2023-04-021-1/+1
| | | | | | | | 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.
* Add support for .WARNINGS special variablePaul Smith2023-04-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Add new warnings invalid-var and invalid-refPaul Smith2023-04-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | The "invalid-var" warning triggers if the makefile attempts to assign a value to an invalid variable name (a name containing whitespace). The "invalid-ref" warning triggers if the makefile attempts to reference an invalid variable name. Both new warnings have a default action of "warn". * NEWS: Add these new warnings. * doc/make.1: Document them in the man page. * doc/make.texi (Warnings): Document them in the user's manual. * src/warning.h: Add enum values for the new warning types. * src/main.c (initialize_warnings): Initialize the new warnings. * src/variable.h (undefine_variable_in_set, undefine_variable_global): Ask callers to provide a struct floc specifying where the variable is undefined. * src/read.c (do_undefine): Pass floc when undefining. * src/variable.c (check_valid_name): If invalid-var is enabled, check the variable name. (define_variable_in_set): Call it. (undefine_variable_in_set): Ditto. (check_variable_reference): If invalid-ref is enabled, check the variable reference. (lookup_variable): Call it. (lookup_variable_in_set): Ditto. * tests/scripts/options/warn: Add tests for the new warning types.
* Introduce a --warn command line optionPaul Smith2023-04-011-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 memory leak warnings from ASAN and ValgrindPaul Smith2023-04-011-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Add functions to directly expand variables by namePaul Smith2023-04-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Replace all locally-created "$("+varname+")" and similar constructs with calls to these new functions. * src/expand.c (expand_variable_output): Call expand_string_output() on the expansion of a variable value. Replaces reference_variable(). (expand_variable_buf): Like expand_variable_output() but return the starting location of the result. (allocated_expand_variable): Like expand_variable_buf() but return an allocated string. (expand_string_buf): Call expand_variable_output(). * src/variable.h: Declare the new functions. * src/function.c (func_call): Call expand_variable_output() instead of expand_string_buf(). * src/main.c (decode_env_switches): Call expand_variable() instead of expand_string(). * src/remake.c (library_search): Call allocated_expand_variable() instead of expand_string() plus xstrdup(). * src/vpath.c (build_vpath_lists): Expand VPATH and GPATH using expand_variable() instead of expand_string(). * src/w32/subproc/sub_proc.c (process_begin): Use expand_variable() to expand SHELL. Also use alloc() in case the result is larger than PATH_MAX.
* Clean up expand.cPaul Smith2023-03-261-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Use MK_OS_OS2 macro instead of __EMX__Paul Smith2023-01-161-2/+2
| | | | | * src/makeint.h: Set MK_OS_OS2 to 1 if __EMX__ is set. * src/*: Convert #if refs to __EMX__, to use MK_OS_OS2.
* Use MK_OS_DOS macro instead of __MSDOS__Paul Smith2023-01-161-4/+4
| | | | | | * src/configh.dos: Set MK_OS_DOS to 1 * src/*: Convert #if refs to __MSDOS__, to use MK_OS_DOS. * gl/lib/*: Ditto.
* Rename WINDOWS32 macro to MK_OS_W32Paul Smith2023-01-151-10/+10
| | | | | | | | | | * 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-10/+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.
* Remove support for AmigaOSPaul Smith2023-01-151-49/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
|
* [SV 63439, SV 63452] Don't warn on undefined internal variablesPaul Smith2022-12-241-9/+1
| | | | | | | | | | | | | | | | | Don't generate undefined variable warnings for variables that are internal / special to make and where the empty string is valid. Rather than defining them to empty, which could introduce unwanted behavior, keep a list of variable names which we should never warn about. * src/variable.h (warn_undefined): Convert the macro to a function. * src/variable.c (defined_vars): Always "defined" variable names. (warn_undefined): Implement as a function and check against the defined_vars before generating a warning. * src/read.c (read_all_makefiles): No need to reset warning flag. * src/vpath.c (build_vpath_lists): Ditto. * tests/scripts/options/warn-undefined-variables: Expand all the pre-defined variables to ensure warnings are not generated.
* [SV 63484] Force included makefiles to be explicitDmitry Goncharov2022-12-181-0/+1
| | | | | | | | | Ensure included makefiles are not treated as intermediate, even if they are created by an implicit rule. Reported by Patrick Oppenlander <patrick.oppenlander@gmail.com>. * src/read.c (eval_makefile): Mark makefiles as explicit. * tests/scripts/features/include: Add a test.
* [SV 63516] [DOS] Support include files with drivespecsPaul Smith2022-12-181-2/+3
| | | | | | | | | * 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.
* Add specific hints for errors due to invalid conditionalsPaul Smith2022-11-151-7/+16
| | | | | | | | * src/read.c (eval): If "missing separator" appears to be due to missing space after ifeq/ifneq, give a hint about the error. * tests/scripts/misc/failure: Check for these types of failures. * tests/scripts/variables/special: Move error checking unrelated to special variables, to misc/failure.
* Avoid C99 constructsPaul Smith2022-10-291-16/+19
| | | | | | | | | | Although gnulib requires C99, most of the code does compile with a C90 compiler (perhaps with a lot of warnings). Reinstate our C90 configuration test, and clean up a few C99 things that crept in. * src/job.c (construct_command_argv_internal): Don't use loop-local variables or C++ comments. * src/read.c (eval_makefile): Don't use loop-local variables.
* 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-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Clean up some warnings on Windows buildsPaul Smith2022-10-031-1/+1
| | | | | | | | | | | | | | * src/arscan.c (parse_int): Avoid conversion from int to char and check for overflow given a max value. (ar_scan): Check intmax sizes then cast to the proper type. (ar_member_touch): Get proper return type from ar_scan and cast it to off_t. * src/function.c (a_word_hash_cmp): Don't cast from size_t to int. (func_filter_filterout): Count using unsigned long to avoid casts. (construct_include_path): Explicitly cast to void*. * src/shuffle.c (reverse_shuffle_array): Use size_t index. * src/w32/subproc/sub_proc.c (process_wait_for_multiple_objects): Initialize the return value in case the count is 0.
* [SV 63100] Set the floc of every created goal dep structDmitry Goncharov2022-09-251-0/+1
| | | | | | * src/read.c (eval): Initialize the goaldep floc pointer. * tests/scripts/features/loadapi: Verify that the floc is set after unloading and reloading dynamic objects.
* [SV 13862] Implement the .WAIT special targetPaul Smith2022-09-121-13/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 63045] Reload each intact unloaded shared objectDmitry Goncharov2022-09-121-10/+19
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Replace strcmp() with memcmp() where possibleNoah Goldstein2022-04-241-3/+2
| | | | | | | | | | | | | memcmp() is always faster than strcmp(). In places where we already know that both buffers have sufficient size, replace strcmp() with memcmp(). * src/main.c (main): Replace strncmp() with memcmp()==0. * src/read.c (word1eq): Ditto. * src/commands.c (set_file_variables): Ditto. * src/function.c (func_filter_filterout): Ditto. (a_word_hash_cmp): Use STRING_N_COMPARE since we know the length. (func_sort): Replace strcmp() with memcmp().
* * src/read.c (check_specials): [SV 62171] Reset ARFLAGS under .POSIXDmitry Goncharov2022-04-241-0/+1
|
* * <all>: Update copyright notices.Paul Smith2022-02-101-1/+1
|
* * src/read.c (tilde_expand): Put back '/' before returning.Paul Smith2022-01-171-3/+4
| | | | | | Joe Filion <joefilion4@gmail.com> noted that the string is modified, and Henrik Carlqvist <hc94@poolhem.se> noticed that it wasn't put back in all cases.
* * src/read.c (find_percent_cached): [SV 60798] Silence GCC11 warningsJouke Witteveen2021-12-191-59/+40
|
* [SV 60798] Silence bogus GCC10 and GCC11 warningsJouke Witteveen2021-12-191-5/+7
| | | | | | | * src/main.c (main): Use a separate variable to track final character. * src/read.c (eval): Track the semicolon position not one beyond it. * src/variable.c (do_variable_definition): Include a default switch case to ease the work of the exhaustiveness prover.
* [SV 60435] Ensure intermediate grouped files are removedDmitry Goncharov2021-09-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | 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 57778] Don't ignore included makefiles that can't be readDmitry Goncharov2021-09-061-6/+13
| | | | | | | | | | If we find an included makefile but it's not readable, stop immediately with an error rather than continuing to look in other directories. * src/read.c (eval_makefile): Only keep searching if the fopen error is ENOENT, else stop and fail. * tests/scripts/features/include: Add tests to verify this behavior.
* [SV 60795] Don't remake phony included makefiles and show errorsPaul Smith2021-09-061-3/+1
| | | | | | | | | | | | | | | | | | | | | | | Change the handling of included makefiles which are phony targets to be similar to double-colon rules with no prerequisites: simply don't build them at all during the remake a makefile phase. Ensure that any included makefile which is needed but not built results in an error. Update the documentation to make this clear. Add tests to verify this behavior. * doc/make.texi (Remaking Makefiles): Clarify double-colon exception. Document that phony targets are handled the same way. (Phony Targets): Ditto. * src/main.c (main): Check for phony targets when skipping goals. Rather than throwing out skipped but failed goals keep them separately then report them as errors. * src/read.c (eval): Set the file location on included makefiles even when there's no error. * tests/scripts/features/include: Add tests for handling included makefiles with both phony and double-colon rules to rebuild them.
* Remove UBSAN issues discovered via fuzzing tests.Paul Smith2021-09-061-6/+18
| | | | | | | | | | | | | | | | The arithmetic conversions in C say that if a binary operator has an unsigned and signed type as operands and the unsigned type has a greater rank then the signed value is converted to unsigned. This is bad if the signed value is negative. There are a few places in the code which have this situation; convert the signed value to positive and add instead of subtracting. Reported by He Jingxuan <jingxuan.he@inf.ethz.ch> * src/read.c (find_map_unquote): Use a positive int in memmove(). (find_char_unquote): Ditto. (find_percent_cached): Ditto.
* [SV 45211] Parse MAKEFLAGS immediately when it's resetPaul Smith2021-09-051-15/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When MAKEFLAGS is set in a makefile, reparse it immediately rather than waiting until after all makefiles have been read and parsed. This change doesn't actually fix the SV bug referenced because, even though we do reparse MAKEFLAGS, we don't handle the -r or -R options immediately. Doing this will require more effort. * NEWS: Announce the change. * src/makeint.h: Publish reset_switches() and decode_env_switches() from main.c * src/main.c (main): Don't call construct_include_path(); it will be invoked decode_switches(). Preserve the old values of builtin_rules, builtin_variables, and job_slots before we read makefiles since they can be changed now. (reset_switches): Publish (remove static). Set the initial value of the stringlist list to NULL. (decode_switches): Call construct_include_path() after decoding. (decode_env_switches): Publish (remove static). (define_makeflags): Set the MAKEFLAGS variable for special handling. * src/read.c (eval_makefile): Check for empty include_directories. (construct_include_path): Clear any old value of .INCLUDE_DIRS before appending new values. Free the previous include_directories. * src/variable.c (lookup_special_var): When MAKEFLAGS is set, first reset the switches then re-parse the variable. * tests/run_make_tests.pl: Memo-ize some default variable values. * tests/scripts/options/dash-r: Create tests for setting -r and -R. * tests/scripts/variables/MAKEFLAGS: Test that resetting -I from within the makefile takes effect immediately.
* [SV 60412] Allow -I- to throw out the current directory pathPaul Smith2021-09-031-30/+39
| | | | | | | | | | | | | Accept a "-" directory value to the -I option to clear the set of directories to be searched up to that point, including the default directories. * NEWS: Announce the change. * doc/make.texi (Summary of Options): Add documentation. * src/read.c (construct_include_path): Check for '-' and if found, clear the list of directories to be searched. * tests/scripts/options/dash-I: Add tests for -I-. * tests/scripts/variables/INCLUDE_DIRS: Add tests for -I-.
* [SV 60378] Don't add duplicate default search directoriesDmitry Goncharov2021-05-301-0/+2
| | | | | | | | | | | Depending on how make was configured it may add duplicate directories in the default include search path: avoid this. (Tweaked by psmith@gnu.org) * configure.ac: Set AM variable KNOWN_PREFIX if --prefix is known * Makefile.am: Only set INCLUDEDIR if prefix is not known * read.c [default_include_directories]: Only add INCLUDEDIR if set
* Ensure variable_buffer is always set.Paul Smith2021-03-151-4/+3
| | | | | | | | | | | | | | | | | | | 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.
* [SV 59881] Handle vertical TAB consistentlyPaul Smith2021-03-151-4/+4
| | | | | | | | | | | | | | While parsing makefiles get_next_mword() was treating VTAB as a word character rather than a word separator. However, when using find_next_token(), for example in patsubst_expand_pat(), we treated VTAB as a word separator causing multiple words to appear where we didn't expect them. * src/makeint.h (END_OF_TOKEN): Change from a loop to a boolean check. * src/misc.c (end_of_token): Move the loop here. * src/read.c (get_next_mword): Skip whitespace, not just blank, to find the start of the word and use END_OF_TOKEN() to decide when the current word is finished.
* [SV 59870] define/undefine prerequisites are not target-specific varsPaul Smith2021-03-141-5/+5
| | | | | | | * src/read.c (parse_var_assignment): If called in a target-specific variable context don't allow define/undefine as variable assignments. * test/scripts/variables/define: Add a test. * test/scripts/variables/undefine: Add a test.
* [SV 57676] Support included files being built after failingPaul Smith2020-12-051-0/+5
| | | | | | | | | If a -include file does not exist, then some subsequent operation creates it, then allow it to be successfully included. * src/read.c (eval_makefile): If our last mtime was NONEXISTENT then reset it to 0 so we'll check it again. * tests/scripts/features/include: Add a test for this behavior.
* Resolve unused-result warnings for alloca(0)Paul Smith2020-11-291-2/+2
| | | | | | | * src/makeint.h (free_alloca): New macro to defeat warn_unused_result. * src/read.c (eval_makefile): Call it. (eval_buffer): Ditto. * src/remake.c (update_file): Ditto.
* Support "unexport" in target-specific variables.Paul Smith2020-11-291-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewrite the environment variable algorithm to correctly inherit export settings from parent variable sets. The new algorithm for computing the table of environment variables is: - Start with the most local variable set and proceed to global. - If the variable already exists in the table and we don't know its export status, update it with the current variable's status. - If the variable is not in the table and it's not global, add it regardless of its status so if it's unexported we remember that. - If the variable is not in the table and is global, check its export status and don't add it if we won't export it. Then when generating the environment variables, check the export status of each variable in case it was a target-specific variable and we have determined it should not be exported. Rework SHELL handling to check at the end whether we added it or not and if we didn't, add the value from the environment. * NEWS: Announce support for target-specific "unexport"." * doc/make.texi (Target-specific): Document the support. * src/variable.h (enum variable_export): Make into a global type. * src/read.c (struct vmodifiers): Use enum variable_export rather than individual booleans. (parse_var_assignment): Parse the "unexport" keyword. (eval): Remember the vmodifier value in the variable. (record_target_var): Ditto. * src/variable.c (should_export): Check if the variable should be exported. (target_environment): Implement the above algorithm. * tests/scripts/features/export: Test export/unexport with variable assignments on the same line. * tests/scripts/features/targetvars: Add a comprehensive suite of tests for different types of target-specific export / unexport. * tests/scripts/variables/SHELL: Update the comment.
* [SV 59230] Preserve export settings for target-specific varsDmitry Goncharov2020-11-291-1/+2
| | | | | | * src/read.c (record_target_var): Don't overwrite pre-existing export flag unless we're changing it. * tests/scripts/features/targetvars: Add a test.
* * src/default.c (default_variables) [AIX]: [SV 59096] Fix ARFLAGSPaul Smith2020-11-291-1/+0
| | | | | | Reported by Dmitry Goncharov <dgoncharov@users.sf.net>, with a patch changing the pattern rule for building archives. I decided to change the default value of ARFLAGS on AIX instead.
* [SV 35711] Check for special targets earlierPaul Smith2020-11-291-96/+103
| | | | | | | | | | | | | | | | | | | | | | GNU make must recognize some special targets as they are defined. Because of the way targets are defined, we were not recognizing these special targets until we were handling the NEXT statement. However that's too late for some special targets such as .POSIX etc. which can change the behavior of make during parsing. Check for special targets earlier, as soon as we've finished parsing the target introduction line (before we've even parsed the recipe). * NEWS: Mention the change. * src/read.c (check_specials): New function to look for special targets. Move checks from eval() and record_files() to this new function. (eval): Call check_specials() after we've completed parsing the target introduction line. Move default goal detection to check_specials(). (record_files): Move handling of .POSIX, .SECONDEXPANSION, and .ONESHELL to check_specials(). * tests/scripts/misc/bs-nl: Remove workaround for late .POSIX issue. * tests/scripts/targets/POSIX: Add a comment.
* [SV 58735] Define the order that makefiles are rebuilt.Paul Smith2020-07-191-11/+2
| | | | | | | | | | | | Ensure that makefiles are rebuilt in the order in which make first considered them, and document this behavior in the manual. * NEWS: Add a note about the new behavior * doc/make.text (How make Processes a Makefile): Document it. * main.c (main): Inverse the list of makefile goals. * read.c (read_all_makefiles): Add default makefiles to the list at the front in reverse order, the same way other makefiles are added. * tests/scripts/features/include: Add tests to verify rebuild order.
* Apply spelling corrections from Fossies spellcheckPaul Smith2020-01-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | See https://fossies.org/features.html#codespell Spelling issues in Git commit messages or lib/* source are not applied. * README.OS2.template: Apply spelling corrections. * README.VMS: Ditto. * src/commands.c: Ditto. * src/config.ami.template: Ditto. * src/configh.dos.template: Ditto. * src/job.c: Ditto. * src/job.h: Ditto. * src/read.c: Ditto. * src/variable.c: Ditto. * src/vms_exit.c: Ditto. * src/vms_export_symbol.c: Ditto. * src/vms_progname.c: Ditto. * src/vmsfunctions.c: Ditto. * src/vmsjobs.c: Ditto. * src/w32/pathstuff.c: Ditto. * tests/scripts/variables/automatic: Ditto. * tests/test_driver.pl: Ditto.