Repository: mirror/make Branch: master Commit: c63a5bc6a288 Files: 295 Total size: 3.4 MB Directory structure: gitextract_jw1du2k5/ ├── .ccls ├── .clangd ├── .dir-locals.el ├── .gitignore ├── AUTHORS ├── Basic.mk.template ├── COPYING ├── ChangeLog.1 ├── ChangeLog.2 ├── ChangeLog.3 ├── Makefile.am ├── NEWS ├── README.DOS ├── README.OS2 ├── README.VMS ├── README.W32 ├── README.customs ├── README.git ├── README.in ├── README.zOS ├── TODO.private ├── autogen.sh ├── autopull.sh ├── bootstrap ├── bootstrap-funclib.sh ├── bootstrap.bat ├── bootstrap.conf ├── build.cfg.in ├── build.sh ├── build_w32.bat ├── builddos.bat ├── configure.ac ├── doc/ │ ├── .gitignore │ ├── Makefile.am │ ├── make.1 │ └── make.texi ├── gl/ │ ├── .gitignore │ ├── lib/ │ │ ├── fnmatch.c │ │ ├── fnmatch.in.h │ │ ├── glob.c │ │ └── glob.in.h │ ├── m4/ │ │ ├── acinclude.m4 │ │ ├── dospaths.m4 │ │ └── getloadavg.m4 │ └── modules/ │ ├── concat-filename │ ├── findprog-in │ ├── getloadavg │ ├── make-glob │ └── make-macros ├── maintMakefile ├── make-gdb.py ├── makefile.com ├── mk/ │ ├── Posix.mk.in │ ├── VMS.mk │ ├── Windows32.mk │ └── msdosdjgpp.mk ├── po/ │ ├── .gitignore │ ├── LINGUAS │ └── POTFILES.in ├── prepare_vms.com ├── scripts/ │ └── copyright-update ├── src/ │ ├── ar.c │ ├── arscan.c │ ├── commands.c │ ├── commands.h │ ├── config.h-vms │ ├── config.h.W32 │ ├── configh.dos │ ├── debug.h │ ├── default.c │ ├── dep.h │ ├── dir.c │ ├── expand.c │ ├── file.c │ ├── filedef.h │ ├── function.c │ ├── getopt.c │ ├── getopt.h │ ├── getopt1.c │ ├── gettext.h │ ├── gmk-default.scm │ ├── gnumake.h │ ├── guile.c │ ├── hash.c │ ├── hash.h │ ├── implicit.c │ ├── job.c │ ├── job.h │ ├── load.c │ ├── loadapi.c │ ├── main.c │ ├── makeint.h │ ├── misc.c │ ├── mkconfig.h.in │ ├── mkcustom.h │ ├── os.h │ ├── output.c │ ├── output.h │ ├── posixos.c │ ├── read.c │ ├── remake.c │ ├── remote-cstms.c │ ├── remote-stub.c │ ├── rule.c │ ├── rule.h │ ├── shuffle.c │ ├── shuffle.h │ ├── signame.c │ ├── strcache.c │ ├── variable.c │ ├── variable.h │ ├── version.c │ ├── vms_exit.c │ ├── vms_export_symbol.c │ ├── vms_progname.c │ ├── vmsdir.h │ ├── vmsfunctions.c │ ├── vmsify.c │ ├── vmsjobs.c │ ├── vpath.c │ ├── w32/ │ │ ├── compat/ │ │ │ ├── dirent.c │ │ │ └── posixfcn.c │ │ ├── include/ │ │ │ ├── dirent.h │ │ │ ├── dlfcn.h │ │ │ ├── pathstuff.h │ │ │ ├── sub_proc.h │ │ │ └── w32err.h │ │ ├── pathstuff.c │ │ ├── subproc/ │ │ │ ├── misc.c │ │ │ ├── proc.h │ │ │ ├── sub_proc.c │ │ │ └── w32err.c │ │ ├── utf8.manifest │ │ ├── utf8.rc │ │ └── w32os.c │ ├── warning.c │ └── warning.h ├── tests/ │ ├── .gitignore │ ├── ChangeLog.1 │ ├── NEWS │ ├── config-flags.pm.W32 │ ├── config-flags.pm.in │ ├── config_flags_pm.com │ ├── guile.supp │ ├── mkshadow │ ├── run_make_tests │ ├── run_make_tests.bat │ ├── run_make_tests.com │ ├── run_make_tests.pl │ ├── scripts/ │ │ ├── features/ │ │ │ ├── archives │ │ │ ├── comments │ │ │ ├── conditionals │ │ │ ├── default_names │ │ │ ├── dircache │ │ │ ├── double_colon │ │ │ ├── echoing │ │ │ ├── errors │ │ │ ├── escape │ │ │ ├── exec │ │ │ ├── expand │ │ │ ├── export │ │ │ ├── grouped_targets │ │ │ ├── implicit_search │ │ │ ├── include │ │ │ ├── jobserver │ │ │ ├── load │ │ │ ├── loadapi │ │ │ ├── mult_rules │ │ │ ├── mult_targets │ │ │ ├── order_only │ │ │ ├── output-sync │ │ │ ├── override │ │ │ ├── parallelism │ │ │ ├── patspecific_vars │ │ │ ├── patternrules │ │ │ ├── quoting │ │ │ ├── recursion │ │ │ ├── reinvoke │ │ │ ├── rule_glob │ │ │ ├── se_explicit │ │ │ ├── se_implicit │ │ │ ├── se_statpat │ │ │ ├── shell_assignment │ │ │ ├── statipattrules │ │ │ ├── suffixrules │ │ │ ├── targetvars │ │ │ ├── temp_stdin │ │ │ ├── utf8 │ │ │ ├── varnesting │ │ │ ├── vpath │ │ │ ├── vpathgpath │ │ │ └── vpathplus │ │ ├── functions/ │ │ │ ├── abspath │ │ │ ├── addprefix │ │ │ ├── addsuffix │ │ │ ├── andor │ │ │ ├── basename │ │ │ ├── call │ │ │ ├── dir │ │ │ ├── error │ │ │ ├── eval │ │ │ ├── file │ │ │ ├── filter-out │ │ │ ├── findstring │ │ │ ├── flavor │ │ │ ├── foreach │ │ │ ├── guile │ │ │ ├── if │ │ │ ├── intcmp │ │ │ ├── join │ │ │ ├── let │ │ │ ├── notdir │ │ │ ├── origin │ │ │ ├── realpath │ │ │ ├── shell │ │ │ ├── sort │ │ │ ├── strip │ │ │ ├── substitution │ │ │ ├── suffix │ │ │ ├── value │ │ │ ├── warning │ │ │ ├── wildcard │ │ │ └── word │ │ ├── misc/ │ │ │ ├── bs-nl │ │ │ ├── close_stdout │ │ │ ├── failure │ │ │ ├── fopen-fail │ │ │ ├── general1 │ │ │ ├── general2 │ │ │ ├── general3 │ │ │ ├── general4 │ │ │ └── utf8 │ │ ├── options/ │ │ │ ├── dash-B │ │ │ ├── dash-C │ │ │ ├── dash-I │ │ │ ├── dash-W │ │ │ ├── dash-d │ │ │ ├── dash-e │ │ │ ├── dash-f │ │ │ ├── dash-k │ │ │ ├── dash-l │ │ │ ├── dash-n │ │ │ ├── dash-q │ │ │ ├── dash-r │ │ │ ├── dash-s │ │ │ ├── dash-t │ │ │ ├── eval │ │ │ ├── general │ │ │ ├── print-directory │ │ │ ├── print-targets │ │ │ ├── shuffle │ │ │ ├── symlinks │ │ │ └── warn │ │ ├── targets/ │ │ │ ├── DEFAULT │ │ │ ├── DELETE_ON_ERROR │ │ │ ├── FORCE │ │ │ ├── IGNORE │ │ │ ├── INTERMEDIATE │ │ │ ├── NOTINTERMEDIATE │ │ │ ├── ONESHELL │ │ │ ├── PHONY │ │ │ ├── POSIX │ │ │ ├── SECONDARY │ │ │ ├── SILENT │ │ │ ├── WAIT │ │ │ └── clean │ │ ├── test_template │ │ ├── variables/ │ │ │ ├── CURDIR │ │ │ ├── DEFAULT_GOAL │ │ │ ├── EXTRA_PREREQS │ │ │ ├── GNUMAKEFLAGS │ │ │ ├── INCLUDE_DIRS │ │ │ ├── LIBPATTERNS │ │ │ ├── MAKE │ │ │ ├── MAKECMDGOALS │ │ │ ├── MAKEFILES │ │ │ ├── MAKEFLAGS │ │ │ ├── MAKELEVEL │ │ │ ├── MAKE_RESTARTS │ │ │ ├── MFILE_LIST │ │ │ ├── SHELL │ │ │ ├── WARNINGS │ │ │ ├── append │ │ │ ├── automatic │ │ │ ├── conditional │ │ │ ├── define │ │ │ ├── flavors │ │ │ ├── negative │ │ │ ├── private │ │ │ ├── special │ │ │ └── undefine │ │ └── vms/ │ │ └── library │ ├── test_driver.pl │ └── thelp.pl └── vms_export_symbol_test.com ================================================ FILE CONTENTS ================================================ ================================================ FILE: .ccls ================================================ clang %h --include=makeint.h -DHAVE_CONFIG_H -Isrc -Ilib -DLIBDIR="/usr/local/lib" -DLOCALEDIR="/usr/local/share/locale" -DMAKE_MAINTAINER_MODE -pthread -isystem /usr/include/guile/2.0 -Wall -Wextra -Werror -Wwrite-strings -Wshadow -Wdeclaration-after-statement -Wbad-function-cast -Wformat-security -Wtype-limits -Wunused-but-set-parameter -Wlogical-op -Wpointer-arith -Wignored-qualifiers -Wformat-signedness -Wduplicated-cond -Wno-address -Wno-string-compare ================================================ FILE: .clangd ================================================ CompileFlags: Add: [-xc, -DHAVE_CONFIG_H, -DMAKE_MAINTAINER_MODE, -DLIBDIR="/usr/local/lib", -DLOCALEDIR="/usr/local/share/locale", -I../src, -Isrc, -I../lib, -Ilib, -Wall, -Wextra, -Wwrite-strings, -Wshadow, -Wdeclaration-after-statement, -Wbad-function-cast, -Wformat-security, -Wtype-limits, -Wunused-but-set-parameter, -Wlogical-op, -Wpointer-arith, -Wignored-qualifiers, -Wformat-signedness, -Wduplicated-cond, -Wno-string-compare, -Wno-unused-includes] --- If: PathMatch: .*\.h CompileFlags: Add: [-xc-header, --include=makeint.h] --- If: PathMatch: .*/makeint\.h Diagnostics: UnusedIncludes: None ================================================ FILE: .dir-locals.el ================================================ ( (nil . ((bug-reference-bug-regexp . "\\(\\bSV[- ]\\([0-9]+\\)\\)") (bug-reference-url-format . "https://savannah.gnu.org/bugs/?%s") (ccls-initialization-options . (:index (:threads 6 :initialBlacklist ["/make-[0-9]" "tests/work/" "/\\.deps" "/\\..*cache" "/\\.git"]))) (lsp-file-watch-ignored-directories . ("[/\\\\]\\.git$" "[/\\\\]\\..*cache$" ;; autotools content "[/\\\\]\\.deps$" "[/\\\\]autom4te\\.cache$" "[/\\\\]build-aux$" ;; make-specific content "[/\\\\]doc[/\\\\]manual$" "[/\\\\]tests[/\\\\]work$" "[/\\\\]make-[0-9]")) )) (c-mode . ((c-file-style . "gnu"))) ) ================================================ FILE: .gitignore ================================================ # Development artifacts ID TAGS GPATH GRTAGS GTAGS .*cache .*gdbinit .gdb_history .vscode *~ #* .#* *.diff *.patch *.orig *.rej # Configure artifacts /lib/ /m4/ ABOUT-NLS INSTALL Makefile Makefile.in Basic.mk aclocal.m4 autom4te.cache/ build-aux/ config.cache config.h config.h.in config.log config.status configure /mk/Posix.mk stamp-* .dirstamp gnulib *.sed # Build artifacts .deps/ gmk-default.h loadavg make *.i *.o *.a *.exe *.dll.a *.obj *.lib *.pdb *.sbr # Windows build artifacts WinDebug/ WinRel/ GccDebug/ GccRel/ TccDebug/ TccRel/ # Test artifacts makeerror-* test-suite.log # Distribution artifacts .dep_segment .check-git-HEAD ChangeLog README build.cfg mkconfig.h make-[0-9]*/ make-[0-9]*.tar.* checkcfg.*.log ================================================ FILE: AUTHORS ================================================ ----------------------------------- GNU Make development starting with GNU Make 3.76 by: Paul D. Smith Additional development starting with GNU Make 4.3 by: Dmitry Goncharov Additional development starting with GNU Make 3.81 by: Boris Kolpackov GNU Make development up to version 3.75 by: Roland McGrath GNU Make User's Manual Written by: Richard M. Stallman Edited by: Roland McGrath Bob Chassell Melissa Weisshaus Paul D. Smith ----------------------------------- GNU Make porting efforts: Port to VMS by: Klaus Kaempf Hartmut Becker Archive support/Bug fixes by: John W. Eaton Martin Zinser Port to MS-Windows (native/MinGW) maintained by: Eli Zaretskii Port to MS-DOS (DJGPP), OS/2, and MS-Windows (native/MinGW) by: DJ Delorie Rob Tulloh Eli Zaretskii Jonathan Grant Andreas Beuning Earnie Boyd Troy Runkel Juan M. Guerrero KO Myung-Hun Port to z/OS by: Igor Todorovski ----------------------------------- Other contributors: Luke Allardyce Costas Argyris Aron Barath David Boyce Kevin Buettner Janet Carson Howard Chu Ludovic Courtès Joe Crayne Jeremy Devenport Pete Dietl Aaron Digulla Hannes Domani Martin Dorey Christian Eggers Paul Eggert Mike Frysinger Ramon Garcia Fernandez Noah Goldstein Mike Haboustak Frank Heckenbach Klaus Heinz Ben Hutchings Cao jin Michael Joosten Christian Jullien Jim Kelton Kaz Kylheku David Lubbren Tim Magill Markus Mauhart Greg McGary Thien-Thi Nguyen Han-Wen Nienhuys Enrique Olaizola Ola Olsson Jens Rehsack Thomas Riedl Jaak Ristioja Christoph Schulz Andreas Schwab spagoveanu Carl Staelin (Princeton University) Ian Stewartson (Data Logic Limited) Tobias Stoeckmann Torbjörn Svensson Sergei Trofimovich Justine Tunney Marc Ullman Christof Warlich Florian Weimer David A. Wheeler Bernhard M. Wiedemann Ben Wijen Jouke Witteveen With suggestions/comments/bug reports from a cast of ... well ... hundreds, anyway :) ------------------------------------------------------------------------------- Copyright (C) 1997-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: Basic.mk.template ================================================ # Basic GNU -*-Makefile-*- to build GNU Make # # NOTE: # If you have no 'make' program at all to process this makefile: # * On Windows, run ".\build_w32.bat" to bootstrap one. # * On MS-DOS, run ".\builddos.bat" to bootstrap one. # # Once you have a GNU Make program created, you can use it with this makefile # to keep it up to date if you make changes, as: # # make.exe -f Basic.mk # # Copyright (C) 2017-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . all: src = src/ lib = lib/ make_SOURCES = %make_SOURCES% glob_SOURCES = %glob_SOURCES% loadavg_SOURCES = %loadavg_SOURCES% alloca_SOURCES = %alloca_SOURCES% w32_SOURCES = %w32_SOURCES% vms_SOURCES = %vms_SOURCES% remote_SOURCES = $(src)remote-stub.c OUTDIR = SRCDIR = . OBJEXT = o EXEEXT = PREFIX = /usr/local INCLUDEDIR = $(PREFIX)/include LIBDIR = $(PREFIX)/lib LOCALEDIR = $(PREFIX)/share PROG = $(OUTDIR)make$(EXEEXT) prog_SOURCES = $(make_SOURCES) $(remote_SOURCES) BUILT_SOURCES = OBJECTS = $(patsubst %.c,$(OUTDIR)%.$(OBJEXT),$(prog_SOURCES)) RESOURCE_OBJECTS = OBJDIRS = $(addsuffix .,$(sort $(dir $(OBJECTS)))) # Use the default value of CC LD = $(CC) # Reserved for command-line override CPPFLAGS = CFLAGS = -g -O2 LDFLAGS = extra_CPPFLAGS = -DHAVE_CONFIG_H -I$(OUTDIR)src -I$(SRCDIR)/src -I$(OUTDIR)lib -I$(SRCDIR)/lib \ -DLIBDIR=\"$(LIBDIR)\" -DINCLUDEDIR=\"$(INCLUDEDIR)\" -DLOCALEDIR=\"$(LOCALDIR)\" extra_CFLAGS = extra_LDFLAGS = $(extra_CFLAGS) $(CFLAGS) C_SOURCE = -c OUTPUT_OPTION = -o $@ LINK_OUTPUT = -o $@ # Command lines # $(call COMPILE.cmd,,) COMPILE.cmd = $(CC) $(extra_CFLAGS) $(CFLAGS) $(extra_CPPFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) $(C_SOURCE) $1 # $(call LINK.cmd,) LINK.cmd = $(LD) $(extra_LDFLAGS) $(LDFLAGS) $(TARGET_ARCH) $1 $(LDLIBS) $(LINK_OUTPUT) # $(CHECK.cmd) $(CHECK.args) CHECK.cmd = cd $(SRCDIR)/tests && ./run_make_tests -make $(shell cd $() MKDIR.cmd = mkdir -p $1 # $(call RM.cmd,) RM.cmd = rm -f $1 # $(call CP.cmd,,) CP.cmd = cp $1 $2 CLEANSPACE = $(call RM.cmd,$(OBJECTS) $(RESOURCE_OBJECTS) $(PROG) $(BUILT_SOURCES)) # Load overrides for the above variables. include $(firstword $(wildcard $(SRCDIR)/mk/$(lastword $(subst -, ,$(MAKE_HOST)).mk))) VPATH = $(SRCDIR) all: $(PROG) $(PROG): $(OBJECTS) $(RESOURCE_OBJECTS) $(call LINK.cmd,$^) $(OBJECTS): $(OUTDIR)%.$(OBJEXT): %.c $(call COMPILE.cmd,$<) $(OBJECTS): | $(OBJDIRS) $(BUILT_SOURCES) $(OBJDIRS): $(call MKDIR.cmd,$@) check: $(CHECK.cmd) $(CHECK.args) clean: $(CLEANSPACE) $(filter %.h,$(BUILT_SOURCES)): %.h : %.in.h $(call RM.cmd,$@) $(call CP.cmd,$<,$@) .PHONY: all check clean ================================================ FILE: COPYING ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: ChangeLog.1 ================================================ Tue Oct 29 20:57:36 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62. * remake.c (update_file_1): Check for deps still running before giving up if any dep has failed. Sat Oct 26 16:20:00 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h [uts]: #undef S_ISREG and S_ISDIR if defined. Fri Oct 25 19:50:39 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.17. Thu Oct 24 16:58:36 1991 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * job.c (start_job): Don't check for empty cmds before tweaking the command_ptr. Just let construct_command_argv do it. Tue Oct 22 20:21:03 1991 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * remake.c, arscan.c [POSIX]: instead of . * make.h [POSIX]: Declare vfork as pid_t. Mon Oct 21 15:37:30 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.16. * job.c (construct_command_argv, construct_command_argv_internal): Take new 2nd arg RESTP. If non-NULL, stop parsing at newline, and store addr of the NL in *RESTP. (start_job): Don't chop expanded cmd lines up; use above code to do it. * function.c (expand_function: `shell'): Pass RESTP==NULL. Sat Oct 19 15:36:34 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.15. Fri Oct 18 15:26:55 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (start_job): If on the same cmds->command_lines elt, look at cmds->lines_recurse[CHILD->command_line - 1] instead of [CHILD->command_line]. * dir.c [sgi]: , not ndir or anything else. Thu Oct 17 16:28:55 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * file.c (print_file_data_base): Remove unused var. * make.h [NeXT]: No #define ANSI_STRING. Tue Oct 15 20:08:41 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.60.14. Fri Oct 11 16:23:52 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * make.h: Use PATH_MAX for getwd defn. * make.h: Move getcwd/getwd outside of #ifndef POSIX, and make it #if USG||POSIX. Thu Oct 10 11:53:31 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.60.13. * read.c (read_all_makefiles): When processing MAKEFILES, save the malloc'd ptr to be freed, instead of freeing part-way thru it. * remake.c (update_file_1): Don't tweak FILE->also_make. (update_file): Do it here. After calling update_file_1, set the command_state, update_status, and updated members of each also_make elt to FILE's values. Tue Oct 8 14:56:04 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.60.12. * remake.c (notice_finished_file): Set command_state of FILE and its also_make chain to cs_finished here. * commands.c (execute_file_commands), job.c (child_handler), remake.c (remake_file): Don't set it before calling notice_finished_file. * file.h (struct file): Changed `also_make' to struct dep *. * job.c (delete_child_targets), file.c (print_file_data_base), remake.c (notice_finished_file), implicit.c (pattern_search): Use dep chain instead of array of file names. Mon Oct 7 17:04:33 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.60.11. * arscan.c: Declare open. * misc.c: Declare {get,set}{re,}[ug]id. * variable.c (target_environment): Declare getenv. Sat Oct 5 15:13:03 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * make.h [NeXT]: instead of . Fri Oct 4 16:05:41 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * default.c (default_suffixes, defualt_suffix_rules): Add .texi just like .texinfo. * Version 3.60.10. * job.c: Move vfork decl into make.h. Fri Sep 27 18:45:30 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * compatMakefile (glob/libglob.a): Pass CC value to submake. Thu Sep 26 00:08:15 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * load.c (load_average): Made not static. * load.c [ultrix && vax]: Define LDAV_TYPE and LDAV_CVT for Ultrix 4.2. Tue Sep 24 00:17:20 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.9. * read.c (record_files): Warn about extra cmds even if the target's name begins with a dot. I think the lusers can handle this. Mon Sep 23 22:33:26 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h, arscan.c: Don't declare bcmp, bzero, or bcopy if they're #define'd. * make.h: Declare write and open. * default.c (default_suffixes, default_suffix_rules, default_variables): Add .C just like .cc. * make.texinfo (Catalogue of Rules): Document .C. * make.man (-w): Fix gramo. Fri Sep 20 17:18:16 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h: No text after #endif. Sun Sep 15 16:20:46 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.60.8. * implicit.c (pattern_search): In the second pass, recurse on rule deps that don't have a %. Why did I make it not do this? Fri Sep 14 18:29:39 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * read.c (record_files): For extra cmds, use the last ones given. If the target's name doesn't begin with a dot (bletch!!), emit a two-line warning, one line giving the old cmds' location and the other the new cmds' location. * misc.c (makefile_error, makefile_fatal): New fns. * make.h: Declare them. * Use them instead of error/fatal for all msgs including a file name and line number. Thu Sep 13 16:35:54 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * make.h: Declare define_default_variables. Declare ar_parse_name, instead of ar_name_parse (M-t). Mon Sep 10 18:35:40 1991 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * Version 3.60.7. * make.texinfo (Variables: Setting): Say whitespace is removed if "immediately after =", rather than simply "after =". * job.c: Don't declare wait #ifdef POSIX. * make.h [__GNUC__]: #undef alloca and then #define it. * main.c (main): When pruning makefiles which might loop from the read_makefiles chain, look at all `prev' entries of double-colon rules. Fri Sep 7 00:41:53 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * main.c (main): Only remove makefiles with cmds but no deps from the list of makefiles to be rebuilt if they are :: targets. : targets with cmds and no deps are not dangerous. Wed Sep 5 17:35:51 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (defines): Add comment that some compilers take ENUM_BITFIELDS but produce bogus code. (LOAD_AVG): Fix examples to \ "s. (LOADLIBES): Add comment that SGI Irix needs -lmld for nlist. Tue Sep 4 20:26:26 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.6. Fri Aug 30 19:34:04 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (update_file_1): When checking the command_state of deps, check through the prev chain. (update_goal_chain): When a target is finished, start checking its prev (if it has one) instead. Wed Aug 7 17:32:03 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * rule.c (convert_to_pattern): Allow files with deps to define suffix rules (really this time). Mon Aug 5 17:09:21 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * misc.c (user_access, make_access): Do saved-IDs (USG) flavor #ifdef POSIX. * file.c (enter_file): Strip ./s here. * read.c (parse_file_seq): Not here. Tue Jul 23 23:34:30 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile: Added comment that -lPW alloca is broken on HPUX. Thu Jul 18 03:10:41 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.5. * read.c (read_makefile): Ignore lines containing chars that are all isspace, not just all isblank. * make.texinfo (Copying): @include gpl.texinfo, rather than copying the text. * gpl.texinfo: New file (symlink to /gd/gnu/doc/gpl.texinfo). * GNUmakefile: Put gpl.texinfo in distribution. Tue Jul 16 12:50:35 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * make.h: #define _GNU_SOURCE before including headers. Include and define isblank if doesn't. * commands.c: Don't include here. * *.c: Use isblank instead of explicit ' ' || '\t'. Mon Jul 15 17:43:38 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * function.c (expand_function: `filter'/`filter-out'): Fixed to not loop infinitely. Fri Jul 12 12:18:12 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * function.c (expand_function: `filter'/`filter-out'): Rewritten to handle filter-out of multiple patterns properly. Also no longer mallocs and reallocs for temp array; uses alloca and a linked-list instead. Wed Jul 10 22:34:54 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.4. * make.texinfo: Moved some @groups that were outside @examples to be inside them. * load.c [apollo] (load_average): Define using special syscall for Apollo DOMAIN/OS SR10.n. Thu Jul 4 12:32:53 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * make.texinfo (Missing): Added Unix excessive implicit rule search; mention that POSIX.2 doesn't require any of the missing features. (Top): Updated printed manual price to $15. Wed Jul 3 18:17:50 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * file.c (rename_file): Carry over last_mtime when merging files. * remake.c (f_mtime): Tail-recurse after renaming VPATH file, to check for saved date in existing renamed-to file. * remote-cstms.c (start_remote_job): Use PATH_VAR. * commands.c [POSIX || __GNU_LIBRARY__]: Don't declare getpid. * compatMakefile (glob-{clean,realclean}): Run clean/realclean in glob. (clean, realclean): Require those. * make.h: Always declare environ. Don't declare old glob functions. * GNUmakefile: Make no-lib deps for load.c and remote.c. Tue Jul 2 18:35:20 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.60.3. Mon Jul 1 16:58:30 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (multi_glob): Don't pass GLOB_QUOTE flag to glob. * make.h [POSIX]: Include , and don't declare things that should be there. * main.c (main) [USG && sgi]: malloc a buffer for broken sgi stdio. Sat Jun 29 11:22:21 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * function.c (expand_function: `shell'): Use alloca for the error msg buffer, instead of assuming an arbitrary max size. Fri Jun 28 18:15:08 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c [POSIX] (search_path): Do real 1003.1 goop to get NGROUPS_MAX. Wed Jun 26 11:04:44 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * default.c (define_default_variables): New fn. (install_default_implicit_rules): Code for above fn moved there. * main.c (main): Do define_default_variables before reading the makefile. Tue Jun 25 17:30:46 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * main.c (main): Quote ; in MAKEOVERRIDES. Tue Jun 18 13:56:30 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * compatMakefile: Fixed typo in comment. Tue Jun 11 00:14:59 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.60.2. Mon Jun 10 14:46:37 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h: Always include . [POSIX]: Include and #define MAXPATHLEN to be PATH_MAX. * default.c (default_suffix_rules: .texinfo.dvi): Use $(TEXI2DVI). (default_variables): Define TEXI2DVI. Thu Jun 6 16:49:19 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.60.1. * make.h (SIGNAL): Cast handler arg to SIGHANDLER type. Wed Jun 5 06:00:43 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * read.c (multi_glob): Use POSIX.2 `glob' function. If a glob pattern matches nothing, leave it as is (a la sh, bash). Also, if can't find USER for ~USER, leave it as is (a la bash). Mon Jun 3 16:36:00 1991 Roland McGrath (roland@albert.gnu.ai.mit.edu) * compatMakefile: Rewrote comments about -Ds to be easier to use. * make.h, arscan.c, remake.c, main.c, dir.c, job.c: Changed tests of _POSIX_SOURCE to POSIX. * job.c: Take getdtablesize out of #ifdef __GNU_LIBRARY__. Put separately #ifdef USG. * COPYING: Replaced with version 2. * Changed copyright notices to refer to GPL v2. Thu May 30 00:31:11 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h: Don't declare sigblock for POSIX. * main.c (main, log_working_directory) [USG]: Get getcwd failure mode from errno, not passed buffer like BSD getwd. * misc.c (child_access): New fn to set access for a child process; like user_access, but you can't change back. * make.h: Declare it. * job.c (exec_command): Use it in place of user_access. Wed May 29 23:28:48 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (default_variables) [pyr]: PC = pascal. Tue May 28 20:24:56 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (print_variable): Put a newline before `endef'. Sat May 25 02:39:52 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.60. Wed May 22 19:41:37 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.59.5. Thu May 16 13:59:24 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (main): Do USGr3 setvbuf behavior #ifdef APOLLO. Don't handle SIGCHLD #ifdef USG (Apollo is USG but defines SIGCHLD). Fri May 10 14:59:33 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * remake.c [sgi]: Don't include . Wed May 8 01:54:08 1991 Roland McGrath (roland@geech.gnu.ai.mit.edu) * make.h (SIGHANDLER): #define as (void *) #if __STDC__, else (int (*)()). (SIGNAL): Use it to cast return value. * main.c (main): Cast SIG_IGN to SIGHANDLER when comparing. * job.c (block_signals, unblock_signals): Use SIGNAL instead of signal. * main.c: Declare mktemp to return char*, not int. * job.c (new_job): Don't increment files_remade. * remake.c (notice_finished_file): Do it here. * read.c (do_define): Don't clobber DEFINITION[-1] on empty defns. Free storage that is no longer needed. Wed Apr 24 20:49:48 1991 Roland McGrath (roland at churchy.gnu.ai.mit.edu) * misc.c (message): New fn to print informational msgs with leading "make: " or "make[N]: ". * make.h: Declare it. * remake.c (update_file): Use it instead of printf. Fri Apr 19 05:52:45 1991 Roland McGrath (roland at churchy.gnu.ai.mit.edu) * main.c (main): When there are no targets, if there were no makefiles, print a different error message, which mentions makefiles. Tue Apr 16 03:22:45 1991 Roland McGrath (roland at geech.gnu.ai.mit.edu) * remake.c (update_file): Print "nothing to be done" instead of "is up to date" if FILE->cmds == 0. * job.c [!WIFEXITED]: Define if not already defined. Thu Apr 11 18:00:50 1991 Roland McGrath (roland at wookumz.gnu.ai.mit.edu) * arscan.c (ar_name_equal): Fixed truncation comparison. Tue Apr 2 16:17:35 1991 Roland McGrath (roland at churchy.gnu.ai.mit.edu) * glob.c: Use common version from djm. * dir.c: Snarfed #ifdef mess for or whatever from glob.c. (dir_file_exists_p): Ignore directory entries with d_ino==0. Mon Apr 1 20:49:45 1991 Roland McGrath (roland at albert.gnu.ai.mit.edu) * Version 3.59.4. Fri Mar 29 19:16:18 1991 Roland McGrath (roland at albert.gnu.ai.mit.edu) * job.c (free_child): Free CHILD->environment and its elts. Sat Mar 23 14:08:09 1991 Roland McGrath (roland at albert.gnu.ai.mit.edu) * read.c (read_makefile): Don't ignore lines containing only comments if they start with a tab. Such lines should be passed to the shell for it to decide about the comments. * job.c (free_child): Free CHILD->command_lines and its elts, not CHILD->commands (which is obsolete). * job.h, job.c: Remove obsolete `commands' member of `struct child'. Sun Mar 17 18:40:53 1991 Roland McGrath (roland at albert.ai.mit.edu) * remake.c (update_file): Print a msg for a top-level up-to-date phony target (a different one than for a real file). * read.c (conditional_line): Boundary check so we don't check the value of the -1th elt of the stack (which is bogus). Sat Mar 16 16:58:47 1991 Roland McGrath (roland at albert.ai.mit.edu) * read.c (conditional_line): Don't evaluate an if* when we're already ignoring. Instead, just push a new level, with a value of 1, to keep ignoring. Tue Mar 12 00:16:52 1991 Roland McGrath (roland at geech.ai.mit.edu) * Version 3.59.3. Mon Mar 11 23:56:57 1991 Roland McGrath (roland at geech.ai.mit.edu) * job.c (construct_command_argv_internal): Quote backslashes when building the shell -c line. Fri Mar 8 01:40:18 1991 Roland McGrath (roland at geech.ai.mit.edu) * job.c (exec_command): Call user_access rather than setgid(getgid()). * misc.c (remove_comments): Renamed from collapse_line; took out collapse_continuations call. * make.h: Change decl. * read.c (read_makefile): Collapse continuations on the line buffer immediately after reading it. Call remove_comments rather than collapse_line (which is now defunct). Thu Feb 21 18:06:51 1991 Roland McGrath (mcgrath at cygint.cygnus.com) * misc.c (user_access, make_access): New fns to toggle btwn permissions for user data (files and spawning children), and permissions for make (for taking the load average, mostly). * make.h: Declare them. * job.c (start_job): Call make_access before wait_to_start_job, and user_access after. * main.c (main): Call user_access before doing much. Mon Feb 3 15:02:03 1991 Roland McGrath (roland at albert.ai.mit.edu) * Version 3.59.2. Tue Jan 29 20:30:50 1991 Roland McGrath (roland at cygint.cygnus.com) * read.c (read_all_makefiles): Use allocated_variable_expand to expand `$(MAKEFILES)', since the results are used across calls to read_makefile, which could clobber them. Wed Jan 23 00:24:10 1991 Roland McGrath (roland at cygint.cygnus.com) * main.c (main): Call install_default_implicit_rules after reading makefiles, not before. * default.c (install_default_implicit_rules): If a suffix-rule file entry has cmds, don't give it any from default_suffix_rules. Fri Jan 17 17:39:49 1991 Roland McGrath (roland at albert.ai.mit.edu) * arscan.c: Added support for AIX archives. * remake.c: Don't include ar.h. * main.c: Removed unused atol decl. * arscan.c (ar_scan): Declare arg FUNCTION to return long int. * ar.c (ar_touch): Don't perror for an invalid archive. * make.h: Declare lseek as long int. * job.c [hpux]: Define getdtablesize a la USG. Sun Jan 12 21:08:34 1991 Roland McGrath (roland at albert.ai.mit.edu) * Version 3.59.1. Fri Jan 10 03:48:08 1991 Roland McGrath (roland at albert.ai.mit.edu) * job.c (search_path): Take new arg, place to put full pathname (rather than mallocing it). (exec_command): Pass it, using auto storage. * main.c (print_version): Updated copyright years. Wed Jan 8 19:46:19 1991 Roland McGrath (roland at albert.ai.mit.edu) * job.c [_POSIX_SOURCE]: Just #include , and define macro WAIT_NOHANG in terms of waitpid. [!_POSIX_SOURCE && (HAVE_SYS_WAIT || !USG)]: Don't #include (make.h does). Define macro WAIT_NOHANG in terms of wait3. (child_handler): #ifdef on WAIT_NOHANG, not HAVE_SYS_WAIT || !USG. Use WAIT_NOHANG macro instead of wait3. * file.h (struct file.command_state): Remove unused elt. Wed Dec 26 18:10:26 1990 Roland McGrath (roland at albert.ai.mit.edu) * commands.c (set_file_variables): If FILE got its commands from .DEFAULT, make $< == $@ (4.3 BSD/POSIX.2d11 compat). Mon Dec 24 17:36:27 1990 Roland McGrath (roland at albert.ai.mit.edu) * default.c (default_variables): Rename 2nd LINK.s defn to LINK.S. Fri Dec 14 15:05:25 1990 Roland McGrath (roland at albert.ai.mit.edu) * vpath.c (selective_vpath_search): Check for makefile-mentioned before checking for actual existence. The old order loses if the containing directory doesn't exist (but a rule might make it). * make.h [__GNUC__]: Don't #define alloca if already #define'd. * rule.c (convert_to_pattern): Don't look at the target constructed for the empty rule when making the null-suffix rule. Construct it over again, since the former may have been freed already. Thu Dec 13 17:21:03 1990 Roland McGrath (roland at churchy.ai.mit.edu) * make.h [__GNU_LIBRARY__]: Include to get random fn decls. Wed Dec 12 17:12:59 1990 Roland McGrath (roland at churchy.ai.mit.edu) * make.h, arscan.c, glob.c: Only include #ifdef USG. * variable.c (define_variable_in_set): Replace env_overrides check that wasn't really redundant (undoing Sep 28 change). Add comment saying why this check is necessary. * job.c, main.c [DGUX]: Needs siglist like USG. Mon Dec 11 01:19:29 1990 Roland McGrath (roland at albert.ai.mit.edu) * default.c [M_XENIX]: For rules that are different for Xenix, use the generic Unix version #ifdef __GNUC__. * main.c [M_XENIX]: Use USGr3-style setvbuf call. * read.c (find_percent): Do backslash folding correctly, not leaving extra crud on the end of the string. Sun Dec 10 21:48:36 1990 Roland McGrath (roland at albert.ai.mit.edu) * job.c: Don't declare wait3 if it's #defined. * GNUmakefile, compatMakefile, make.texinfo: Change make-info to make.info. Thu Dec 7 21:20:01 1990 Roland McGrath (roland at churchy.ai.mit.edu) * make.h [STDC_HEADERS || __GNU_LIBRARY__ || _POSIX_SOURCE]: Use ANSI and names for str/mem functions. Use to declare misc fns rather than explicit decls. [_POSIX_SOURCE]: Don't declare kill ( will). Include before because some braindead nonconformant 1003.1 implementation needs it. * misc.c: Don't declare malloc, realloc. Do it in make.h. * arscan.c, glob.c: Use sequence for string fns from make.h verbatim. * make.h (S_ISDIR, S_ISREG): Declare if necessary. * commands.c (delete_child_targets), job.c (search_path), read.c (construct_include_path): Use S_ISfoo(m) instead of (m & S_IFMT) == S_IFfoo. * dir.c, glob.c [_POSIX_SOURCE]: Use dirent. Wed Nov 29 22:53:32 1990 Roland McGrath (roland at geech.ai.mit.edu) * Version 3.59. Tue Nov 28 16:00:04 1990 Roland McGrath (roland at churchy.ai.mit.edu) * arscan.c (ar_name_equal) [APOLLO]: Don't do `.o' hacking. On Apollos the full file name is elsewhere, and there is no length restriction (or so I'm told). Thu Nov 23 17:33:11 1990 Roland McGrath (roland at albert.ai.mit.edu) * load.c [hp300 && BSD] (LDAV_CVT): Define for this system. Tue Nov 21 07:58:40 1990 Roland McGrath (roland at albert.ai.mit.edu) * read.c (record_files): Fix trivial bug with deciding to free storage for a file name. Thu Nov 16 06:21:38 1990 Roland McGrath (roland at geech.ai.mit.edu) * compatMakefile ($(bindir)/make): Install it setgid kmem. Thu Nov 1 16:12:55 1990 Roland McGrath (roland at churchy.ai.mit.edu) * GNUmakefile (make-*.tar.Z): Use `h' option to tar (dereference symlinks), to grab texinfo.tex from wherever it lives. Tue Oct 30 16:15:20 1990 Roland McGrath (roland at churchy.ai.mit.edu) * Version 3.58.13. Fri Oct 26 14:33:34 1990 Roland McGrath (roland at churchy.ai.mit.edu) * GNUmakefile: make-*.tar.Z: Include texinfo.tex. Tue Oct 23 19:34:33 1990 Roland McGrath (roland at churchy.ai.mit.edu) * main.c (define_makeflags): When there are no flags to write, make sure the array has two leading nulls, since `MAKEFLAGS' is defined from &flags[1]. * main.c (default_keep_going_flag): New variable (constant one). (command_switches: -k, -S): Use above for default value. (define_makeflags): Only write flag/flag_off switches if they are on, and either there is no default value, or they are not the default. Mon Oct 22 16:14:44 1990 Roland McGrath (roland at churchy.ai.mit.edu) * main.c (struct command_switch): New member `no_makefile'. (command_switches: -n, -q, -t): Set no_makefile == 1. (define_makeflags): Take new arg MAKEFILE: if nonzero, don't use options whose `no_makefile' flags are set. (main): Call define_makeflags with MAKEFILE==1 before remaking makefiles, and again with MAKEFILE==0 before remaking goals. Tue Oct 2 17:16:45 1990 Roland McGrath (roland at geech.ai.mit.edu) * Version 3.58.12. Mon Oct 1 15:43:23 1990 Roland McGrath (roland at churchy.ai.mit.edu) * arscan.c [HPUX]: Use PORTAR==1 format. Sat Sep 29 16:38:05 1990 Roland McGrath (roland at churchy.ai.mit.edu) * make.h, remake.c, arscan.c: Don't declare `open'. Fri Sep 28 04:46:23 1990 Roland McGrath (roland at churchy.ai.mit.edu) * variable.c (define_variable_in_set): Remove redundant -e check. Wed Sep 26 00:28:59 1990 Roland McGrath (roland at geech.ai.mit.edu) * job.c (start_job): Set RECURSIVE from the right elt of CHILD->file->cmds->lines_recurse. * commands.c (chop_commands): Don't botch the line count for allocating CMDS->lines_recurse. * Version 3.58.11. * job.c (start_job): Don't always increment CHILD->command_line! Only do it when CHILD->command_ptr has run out! (Dumb bug. Sigh.) Thu Sep 20 02:18:51 1990 Roland McGrath (roland at geech.ai.mit.edu) * GNUmakefile [ARCH]: Give explicit rule for remote.{c,dep} to use variable `REMOTE' for more flags. ($(prog)): Link in $(LOADLIBES). Wed Sep 19 02:30:36 1990 Roland McGrath (roland at churchy.ai.mit.edu) * commands.h (struct commands): New member `ncommand_lines', the number of elts in `command_lines' et al. * commands.c (chop_commands): Set `ncommand_lines' elt of CMDS, and don't put a nil pointer at the end of `command_lines'. * job.h (struct child): New member `command_lines' to hold variable-expanded command lines. * job.c (new_job): Store expanded command lines in `command_lines' member of new child. Don't clobber FILE->cmds. (start_job): Use CHILD->command_lines in place of CHILD->file->cmds->command_lines. * variable.h, variable.c, job.c, expand.c: Undo yesterday's change, which is no longer necessary since we have cleverly avoided the issue. * job.c (start_job): Don't variable-expand each command line. (new_job): Do them all here, storing the expansions in the array. Tue Sep 18 01:23:13 1990 Roland McGrath (roland at churchy.ai.mit.edu) * variable.h (struct variable): Remove `expanding' member. * variable.c (define_variable_in_set): Don't initialize it. * expand.c (struct variable_expanding): New type, a linked list containing `struct variable' pointers. (variables_expanding): New variable, the chain of variables currently being expanded. (recursively_expand): Don't test and set `expanding' member. Instead, run through the `variables_expanding' chain looking for a link referring to V to find self-reference. Add a new link to the chain, describing V, before recursive expansion, and pop it off afterward. * job.c (child_handler): Save `variables_expanding' and clear it before calling start_job, and restore it afterward. This avoids major lossage when the SIGCHLD comes in the middle of variable expansion. Mon Sep 17 14:46:26 1990 Roland McGrath (roland at geech.ai.mit.edu) * job.c, commands.c: Don't define sigmask. * make.h: Put it here instead. * variable.c (target_environment): If `.NOEXPORT' was specified as a target, only export command-line and environment variables, and file-origin variables that were in the original environment. * make.man: Add missing ?roff control for `-I' option description. Thu Sep 13 14:10:02 1990 Roland McGrath (roland at churchy.ai.mit.edu) * load.c [UMAX]: Move #include to [not UMAX_43]. Wed Sep 12 15:10:15 1990 Roland McGrath (roland at churchy.ai.mit.edu) * expand.c (recursively_expand): Don't use `reading_filename' and `reading_lineno_ptr' if they're nil. Thu Aug 30 17:32:50 1990 Roland McGrath (roland at geech) * Version 3.58.10. Tue Aug 28 04:06:29 1990 Roland McGrath (roland at churchy.ai.mit.edu) * job.c [USG] (unknown_children_possible): New variable, set nonzero when it's possible for children not in the `children' chain to die. (block_signals) [USG]: Set it. (unblock_signals) [USG]: Clear it. (child_handler) [USG]: Don't complain about unknown children if `unknown_children_possible' is set. * read.c (do_define): Make sure there's enough space for the newline, so we don't write off the end of allocated space. * arscan.c (ar_name_equal): Fixed to work when MEM is AR_NAMELEN-1 but NAME is not the same length. Sat Aug 25 16:17:14 1990 Roland McGrath (roland at geech) * job.c (construct_command_argv_internal): Use a static char array for a constant, since old C has no auto aggregate initializers. Thu Aug 23 16:11:03 1990 Roland McGrath (roland at churchy.ai.mit.edu) * job.c (search_path): If PATH is nil or "" use a default path. Wed Aug 22 01:05:32 1990 Roland McGrath (roland at churchy.ai.mit.edu) * Version 3.58.9. * job.c (exec_command): Don't take PATH and SHELL args. Get them from ENVP. (child_execute_job): Don't take FILE arg, and don't pass path and shell to exec_command. (start_job): Don't pass FILE arg to child_execute_job. * function.c (expand_function: `shell'): Ditto. * main.c (main): Don't pass path and shell to exec_command. Fri Aug 17 23:17:27 1990 Roland McGrath (roland at geech) * job.c (construct_command_argv_internal): New fn broken out of construct_command_argv. Takes strings SHELL and IFS instead of doing variable expansion for them. Recurse to make an argv for SHELL, passing SHELL==0. When SHELL==0, don't recurse for shell argv; make a simple one using /bin/sh. (construct_command_argv): Do the variable expansions and call above. Thu Aug 16 19:03:14 1990 Roland McGrath (roland at geech) * read.c (multi_glob): For ~USER/FILE, if USER isn't found, don't change the file name at all. Tue Aug 7 18:33:28 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * function.c (expand_function: `suffix'/`notdir'): Don't kill the last space if we never wrote one. * function.c (expand_function: `suffix'): Retain the dot, like the documentation says. Mon Aug 6 14:35:06 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.58.8. * main.c (decode_switches): For positive_int and floating cases, move SW past the arg (and don't set it to ""), so another switch can follow. Fri Aug 3 00:43:15 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * job.c (child_execute_job): Use unblock_signals instead of push_signals_blocked_p (0). * main.c (fatal_signal_mask): New variable, mask of signals caught with fatal_error_signal. (main): Set it. * job.c ({block,unblock}_children): Renamed to {block,unblock}_signals. Block/unblock both child signal and signals in fatal_signal_mask. (children_blocked_p_{stack,max,depth}, {push,pop}_children_blocked_p): Renamed from children to signals. Use {block,unblock}_signals instead of {block,unblock}_children. * commands.c (fatal_error_signal), job.c (wait_for_children, new_job, child_execute_job, main, log_working_directory), function.c (expand_function: `shell'), job.h: Rename {push,pop}_children_blocked_p to {push,pop}_signals_blocked_p. * job.c (child_handler): Call {block,unblock}_signals instead of just {block,unblock}_remote_children. We need to block the fatal signals. Thu Aug 2 22:41:06 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * main.c, function.c: Fixed typos in comments. * file.c (print_file_data_base): Fix computation of avg files/bucket. Tue Jul 31 22:11:14 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.58.7. Wed Jul 25 16:32:38 1990 Roland McGrath (mcgrath at tully.Berkeley.EDU) * arscan.c (ar_name_equal): Fixed to really do it right. (ar_member_pos): Fixed order of args. * ar.c (ar_member_date_1): Ditto. Fri Jul 20 15:30:26 1990 Roland McGrath (mcgrath at tully.Berkeley.EDU) * arscan.c (ar_name_equal): Rewritten. Accounts for a possible trailing slash in MEM. * remake.c (f_mtime): Keep track of whether ARNAME is used and free it if not. Also free MEMNAME. * ar.c (ar_member_date, ar_touch): Ditto. * arscan.c (arscan) [HPUX or hpux]: Treat same as USGr3 PORTAR==1. * make.h: If NSIG is not defined, but _NSIG is, #define NSIG _NSIG. * compatMakefile: Don't use $* in explicit rules. * default.c (default_variables: "PREPROCESS.S"): Include $(CPPFLAGS). * remake.c (f_mtime): If FILE is an ar ref, get the member modtime. * function.c (string_glob): Terminate the string properly when it's empty. Wed Jul 18 11:26:56 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.58.6. * commands.c (set_file_variables): Fixed computation for ^F/?F elt len. Sat Jul 14 13:41:24 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * job.c (construct_command_argv): Always use allocated_variable_expand_for_file instead of variable_expand_for_file because we might be called from inside a variable expansion (for the `shell' function). * function.c (expand_function: `shell'): Free the arglist's storage correctly. construct_command_argv only allocates ARGV and ARGV[0]. * job.c (children_blocked_p_idx): Renamed to children_blocked_p_depth. (push_children_blocked_p, pop_children_blocked_p): Use ..._depth instead of ..._idx, and do it right! Wed Jul 11 15:35:43 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.h (SIGNAL): New macro to replace `signal' calls. Does arg and ret value casts to (void *) #ifdef __STDC__ to avoid conflicts btwn ANSI and BSD `signal' and handler types. * main.c (main), job.c (child_handler): Use it. Fri Jul 6 00:00:38 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * ar.c (ar_member_date, ar_touch): Pass 2nd arg to f_mtime. * read.c (read_makefile): Search the include path for MAKEFILES variable makefiles (TYPE == 1), like it says in the manual. * file.h (struct file), main.c (struct command_switch): Remove trailing commas from enums. * commands.c (execute_file_commands): Remove unused variables. * commands.h: Declare chop_commands. * make.h: Declare uniquize_deps. * main.c (main): Remove unused variable. (decode_switches): Remove unused label. * remake.c: Include "ar.h" for ar_parse_name decl. * implicit.c (try_implicit_rule): Remove unused variable. * function.c (expand_function: `shell'): Declare fork, pipe. * ar.c: Declare ar_name_equal. * GNUmakefile: If using gcc, add warning flags to CFLAGS. * remake.c: Remove decl of ar_member_date, since it's done in make.h. * remake.c (f_mtime): For ar refs, allow the archive to be found via VPATH search if we're searching, and change the ar ref accordingly. * ar.c (ar_parse_name): New global fn to parse archive-member references into the archive and member names. (ar_member_date, ar_touch): Use it. * make.h: Declare it. * remake.c (f_mtime): After doing rename_file, do check_renamed instead of assuming rename_file will always set FILE->renamed (which it won't). * vpath.c (selective_vpath_search): Only accept prospective files that don't actually exist yet are mentioned in a makefile if the file we are searching for isn't a target. Wed Jul 4 04:11:55 1990 Roland McGrath (mcgrath at helen.Berkeley.EDU) * remake.c (update_goal_chain): Do check_renamed after calling file_mtime. (check_dep): Ditto after update_file. * file.c (rename_file): Prettied up long message for merging cmds. * remake.c (update_file_1): Get each dep file's modtime, and allow for it being renamed, before checking for a circular dep, since a renaming may have introduced one. Tue Jul 3 18:15:01 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * ar.c (ar_touch): Don't free ARNAME since enter_file holds onto the storage. * function.c (string_glob): Don't leave a trailing space. * read.c (do_define): Allow leading whitespace before `endef'. Mon Jul 2 14:10:16 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * implicit.c (pattern_search): No longer take NAME arg. Instead take ARCHIVE flag. If ARCHIVE is nonzero, FILE->name is of the form "LIB(MEMBER)"; rule for "(MEMBER)" is searched for, and LASTSLASH is set to nil. Since NAME was only non-nil when it was the archive member name passed by try_implicit_rule, this change easily allows turning off LASTSLASH checking for archive members without excessive kludgery. (try_implicit_rule): Pass ARCHIVE flag instead of file name. * Version 3.58.5. * commands./c (set_file_variables): Don't kill last char of $(^D) elts. Sat Jun 30 00:53:38 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * ar.c (ar_member_date): Don't free ARNAME since enter_file holds onto the storage. * arscan.c (ar_scan) [sun386 && PORTAR == 1]: Treat like USGr3. Wed Jun 27 14:38:49 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * main.c (main): Put a newline on the debugging message when deciding not to remake a makefile to avoid a possible loop. Only decide not to remake makefiles that have commands (as well as being targets and having no deps). Fri Jun 22 12:35:37 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * default.c (default_variables): Define `LINK.s' and `LINK.S'. (default_suffix_rules): Define .S.o rule. * job.c (construct_command_argv): If we decide to go the slow route, free all storage for the chopped args. (start_job): Free the argument list's storage correctly. construct_command_argv only allocates ARGV and ARGV[0]. Tue Jun 19 18:27:43 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.58.4. Fri Jun 15 21:12:10 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * glob.c: New version from ai-lab which doesn't do [^abc]. Thu Jun 7 00:30:46 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * dir.c: Copied dirent vs direct et al mess from glob.c. * glob.c: Replaced with updated version from djm. * glob.c: Check macro DIRENT instead of _POSIX_SOURCE for . __GNU_LIBRARY__ implies DIRENT and STDC_HEADERS. Thu May 31 22:19:49 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * vpath.c (vpath_search): Don't stop the loop if a pattern matches but the search fails. All matching patterns have their paths searched (like it says in the manual). * make.texinfo (Rules: Directory Search: Selective Search): Say that multiple `vpath' directives with the same pattern DO accumulate, not supersede earlier ones. * vpath.c (print_vpath_data_base): Increment the count of vpaths on each loop iteration, rather than letting it stay zero. * Version 3.58.3. * job.c (block_children, unblock_children): Made static. (push_children_blocked_p, pop_children_blocked_p): New functions to push and pop whether children are blocked or not. * job.h: Declare push_children_blocked_p, pop_children_blocked_p and not block_children, unblock_children. * commands.c (fatal_error_signal), job.c (wait_for_children, new_job, child_execute_job), main.c (main, log_working_directory): Use sequences of push_children_blocked_p (1) and pop_children_blocked_p () instead of explicitly blocking and unblocking children. * function.c (expand_function: `shell'): Don't unblock children. The push-pop sequence in wait_for_children makes it unnecessary. Tue May 29 21:30:00 1990 Roland McGrath (mcgrath at helen.Berkeley.EDU) * read.c (do_define): Don't include the last newline in the definition. * function.c (expand_function: `shell'): Call construct_command_argv before forking and don't fork if it returns nil. Free the argument list's storage before finishing. * job.c (start_job): Free the storage for the child's argument list in the parent side of the fork after the child has been spawned. * job.c (start_job): If construct_command_argv returns nil, go to the next command line. * job.c (construct_command_argv): Use the shell if the command contains an unterminated quote. Wed May 23 19:54:10 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.58.2. * read.c (read_makefile): Parse "override define" correctly. Thu May 17 15:25:58 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * arscan.c [USG]: Don't declare memcpy and memcmp. should do this anyway (and lack of declarations is harmless). * remote-customs.c: Renamed to remote-cstms.c for System V. * remote.c [CUSTOMS]: Changed accordingly. Sun May 13 14:38:39 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * GNUmakefile: Use same cmds for doc tar.Z as for dist tar.Z (so the contents go in make-N.NN). Thu Apr 26 19:33:25 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.58.1. Wed Apr 25 20:27:52 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * job.c (init_siglist): Don't do SIGUSR1 and SIGUSR2 if they are the same as SIGIO and SIGURG (true on Cray). Tue Apr 24 20:26:41 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * arscan.c (ar_scan): Do behavior for PORTAR == 1 and USGr3 also #ifdef APOLLO. Wed Apr 11 10:00:39 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * job.c (exec_command): Set the effective GID to the real GID. Somehow this code got lost. * implicit.c (pattern_search): Use the right index variable when seeing if we need to expand FILE->also_make. Sun Mar 4 09:18:58 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.58.0. * remake.c (remake_file): Treat non-targets without commands under -t the same as anything else without commands. Sat Feb 24 17:46:04 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * default.c (default_variables: PREPROCESS.S): Removed $< from defn. * main.c (main): Ignore arguments that are the empty string, rather than feeding them to enter_file and barfing therein. Wed Feb 14 16:28:37 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * main.c (main): Call construct_include_path after doing chdirs. Thu Feb 8 13:43:44 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.58. Sat Feb 3 22:06:55 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.57.7. * make.texinfo (Implicit: Catalogue of Rules): For RCS, noted that working files are never overwritten by the default rule. Thu Feb 1 17:27:54 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * rule.c (count_implicit_rule_limits): Redid loop control to not run twice on freed rules. * GNUmakefile: Made `.dep' files be architecture-specific too. * main.c (main, log_working_directory) [USG]: Block children around calls to `getwd' (actually `getcwd' on USG), because that function sometimes spawns a child running /bin/pwd on USG. Tue Jan 30 14:02:50 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * function.c (subst_expand): Pay attention to SUFFIX_ONLY, putz. Wed Jan 24 21:03:29 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * make.man: Fixed repeated word. * make.texinfo (Missing): Reworded a buggy sentence. Mon Jan 22 12:39:22 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * main.c (print_version): Added 1990 to copyright notice. * Version 3.57.6. Sat Jan 20 11:52:01 1990 Roland McGrath (mcgrath at homer.Berkeley.EDU) * file.c (rename_file): Don't free the storage for the old name, since it might not have been malloc'd. * job.c (construct_command_argv): Call allocated_variable_expand_for_file instead of variable_expand_for_file to expand `$(SHELL)'. * make.texinfo (Bugs): Change address from roland@wheaties.ai.mit.edu to roland@prep.ai.mit.edu. Tue Jan 16 19:22:33 1990 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.57.5. Sun Jan 14 16:48:01 1990 Roland McGrath (mcgrath at helen.Berkeley.EDU) * job.c (start_job): Only call wait_to_start_job for the first command line in each sequence. Thu Jan 4 14:27:20 1990 Roland McGrath (mcgrath at helen.Berkeley.EDU) * load.c [LDAV_BASED] (wait_to_start_job): Loop while job_slots_used > 0, not > 1. * job.c (search_path): Don't return a pointer to local storage. Allocate data space for the pathname instead. * function.c (expand_function: `shell'): Don't write garbage if the child wrote no output. Wed Jan 3 15:28:30 1990 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.57.4. * file.h (struct file): New member `renamed', a `struct file *' that is the place this file has been renamed to (or nil). (check_renamed): Macro to check for a file having been renamed. Dereferences the renaming and sets the given variable. * file.c (rename_file): Completely rewritten. Renames in place if possible, or moves FILE to a different hash bucket if there is no existing file with the new name. If there is an existing file with the new name, FILE is merged into it and FILE->renamed is set to point to it. * variable.c (merge_variable_sets): New fn to merge two variable sets. (merge_variable_set_lists): New fn to merge two variable set lists. * variable.h: Declare merge_variable_set_lists. * remake.c (update_file_1, check_dep): Run `check_renamed' after calling file_mtime, check_dep. (update_file): Same after update_file_1. (update_goal_chain, update_file_1, check_dep): Same after update_file. * read.c (uniquize_deps): New fn, broken out of record_files, to remove duplicate deps from a chain. (record_files): Use it. * implicit.c (pattern_search): Use uniquize_deps. * file.h (file_mtime_1): New macro, like file_mtime, but take second arg, passed to f_mtime. (file_mtime): Implement as file_mtime_1 (file, 1). (file_mtime_no_search): New macro: file_mtime (file, 0). * remake.c (f_mtime): Take new arg SEARCH. Only do VPATH and `-lNAME' searching if it is nonzero. * main.c (main): Use file_mtime_no_search for makefiles. * remake.c (update_goal_chain): Use file_mtime_no_search if MAKEFILES. * main.c (printed_version): New variable, init'd to zero. (print_version): Set it to nonzero before returning. (die): If -v and !printed_version, call print_version before clean up and death. * main.c (log_working_directory): Keep track of whether or not the "Entering" message has been printed, and return without printing the "Leaving" message if not. * main.c (decode_switches): Don't complain about missing args before checking for a noarg_value elt in the command_switch structure. Tue Jan 2 15:41:08 1990 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.texinfo (Commands: Recursion: Options/Recursion): Document special case of -j. * make.texinfo, main.c, job.c: Changed copyright notices to include 1990. * make.texinfo (Top): Fixed introductory paragraph, which said that `make' itself (instead of the manual) has various chapters. (Variables: Advanced: Substitution Refs): When pxref'ing about `patsubst', use node `Text Functions', not `Functions'. Add an xref about `patsubst' after description of $(var:a%b=c%d). (Functions: Syntax of Functions): Explain why mixing delimiters in function/var refs is unwise. Clarify fn arg evaluation order. (Options): Reworded sentence about `-e'. (Implicit: Implicit Variables): Don't say `RM' is unused. Say the dflt values for the flag vars is empty unless otherwise noted, since some have defaults. (Implicit: Pattern Rules: Pattern Examples): Clarified use of $< and $@ in first example. (Implicit: Last Resort): Don't say the .DEFAULT example creates files "silently". It's automatic, but not silent. (Implicit: Search Algorithm): Fixed confusing ungrammatical sentence for item 5.1. (Archives: Archive Update): Added missing `next' pointer. (Archives: Archive Symbols): Note that GNU `ar' deals with this automatically. * job.c (search_path): New fn, to search for an executable file in a search path (broken out of exec_command). (exec_command): Take fourth arg, the shell program to use (if necessary). Use search_path for the program, and the shell program. Pass args "file args ..." to shell program (with no -c), where FILE is the full pathname of the program (script) to be run. (child_execute_job): Pass shell program to exec_command. * main.c (main): Ditto. * main.c (main): Don't write a message if exec_command returns, because it will never return. Fri Dec 22 16:19:58 1989 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * default.c (default_variables: "LINK.cc"): Use $(C++FLAGS) instead of $(CFLAGS). Wed Dec 20 09:58:48 1989 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * job.c (new_job): If start_job set the child's `command_state' to `cs_finished', call notice_finished_file. Sun Dec 17 19:45:41 1989 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * Version 3.57.3. Wed Dec 13 17:57:12 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * rule.c (convert_to_pattern): Accept files with dependencies as suffix rules. Thu Nov 30 15:47:13 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.57.2. * function.c (expand_function: `shell'): Don't clobber BUFFER and then try to free it. * remake.c (update_file_1): Took code to force remake of nonexistent deps out of #if 0, and changed the test to nonexistent non-intermediate deps. In version 4, I think removing this test completely will implement the new feature that if a: b and b: c and c is newer than a, b need not be remade. Sun Nov 26 16:12:41 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * compatMakefile (load.o, remote.o): Use $*.c instead of explicit file names so that using VPATH works. Tue Nov 21 14:57:18 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.57.1. Fri Nov 10 03:28:40 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remake.c (check_dep): Set *MUST_MAKE_PTR if FILE does not exist after being updated. (The exact opposite test was here before; why???) (update_file_1): Set a dep's `changed' member after updating it if it is phony and has commands (because they will then always be executed). Thu Nov 9 13:47:12 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * load.c [UMAX]: #ifdef UMAX_43 include different headers for the `inq_stats' call. * compatMakefile (LOAD_AVG): Document UMAX_43. * Version 3.57.0. * commands.c (chop_commands): New function to chop commands into lines. * job.c (new_job): Break that code out, and call chop_commands. * remake.c (remake_file): Call chop_commands before looking at FILE->cmds->any_recurse. * make.texinfo (Running: Goals): Don't say that the default target won't be taken from an included makefile. * remake.c (update_file_1): #if 0 out setting MUST_MAKE if a dep doesn't exist. Fri Nov 3 15:53:03 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.57. * variable.c (try_variable_definition): Don't calculate useless value. * main.c (define_makeflags): Fixed -j propagation. * commands.c (execute_file_commands): Removed unused variable. Sun Oct 29 11:11:15 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (execute_file_commands): If the commands are empty, call notice_finished_file before returning. Sat Oct 28 23:06:32 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remake.c (update_file_1): Don't always update a target that has no deps. Only do this for double-colon targets. Wed Oct 25 16:36:16 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * main.c (main) [hpux]: hpux == HPUX. * compatMakefile (defines): Document that HPUX should be defined. Tue Oct 24 19:19:48 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.8. * job.c (exec_command): Fixed what mode bits are checked. * remake.c (update_file_1): "No cmds and no deps actually changed" loses if ! FILE->is_target. * make.texinfo (Variables: Setting): Don't say that spaces after a variable definition are ignored (since they aren't). Mon Oct 23 14:34:23 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.7. * remake.c (update_file_1): If, after being updated, any dependency does not exist, remake the target. * remake.c (update_file_1): Always update if FILE has commands but no deps. * commands.c (execute_file_commands): If we return early because there are no commands, set FILE->updated. Thu Oct 19 18:47:37 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * arscan.c (ar_scan) [M_XENIX]: Don't run atoi or atol on the `struct ar_hdr' members that are int or long int on Xenix. Sat Oct 14 10:43:03 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * arscan.c (ar_scan): Cosmetic clean ups. (ar_name_equal): New function to compare names, handling truncated member names and special `.o' truncation. (ar_member_pos): Use ar_name_equal. * ar.c (ar_member_date_1): Use ar_name_equal. * Version 3.56.6. * file.h (struct file): Made `update_status' a `short int', and moved it before `command_state' so the bitfields can be packed better. * remake.c (files_remade): Made global. (notice_finished_file): Don't increment files_remade. * job.c (new_job): Do. * job.c (start_job): Don't return a value. Always set CHILD->file->command_state to either cs_running or cs_finished. (new_job, child_handler): Don't expect start_job to return a value. Instead, look at the file's command_state. * commands.c (chop_commands): Merged into job.c (new_job). * commands.h: Don't declare chop_commands. * job.c (start_job): Made static. (new_job): New function to create a `struct child' and call start_job. (free_child): New function to free a `struct child'. (child_handler, new_job): Call it. * job.h: Don't declare start_job. Do declare new_job. * commands.c (execute_file_commands): Call new_job. * commands.c (execute_file_commands): Don't set FILE->update_status if start_job fails. * function.c (expand_function): Don't use `reading_filename' and `reading_lineno_ptr' if they're nil. Fri Oct 13 18:16:00 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * read.c (find_semicolon): New function to look for an unquoted ; not preceded by an unquoted # in a string. (read_makefile): Call it before expanding the line. If it finds a ;, cut the line short there before expanding it. If not, call it again after expanding. * commands.c (execute_file_commands): Don't check FILE->command_state. We won't get called unless it's cs_not_started. * read.c (read_makefile): Call collapse_line on the variable-expanded rule line after checking for ; and #. * job.c (start_job): When there are no more commands, always return 0. * commands.c (execute_file_commands): Don't put the new child in the `children' chain unless FILE->command_state is cs_running. * read.c (read_makefile): Rewrote ;-handling to only do it once (why did I do it twice??) and to check for a # before the ;. * job.c (start_job): Set CHILD->file->update_status to 0 when we run out of commands. Set it to 1 before returning failure. (child_handler): Don't set C->file->update_status to 0 when start_job returns success and commands are not running. * read.c (read_makefile): If there is a # before the ; for commands, forget the ; and commands. Thu Oct 12 15:48:16 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * job.c (child_execute_job): Pass -c to the shell. Wed Oct 11 18:41:10 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.5. * main.c (define_makeflags): Cleaned up to keep better track of dashes written, etc. * function.c (expand_function: `shell'): When converting newlines to spaces in output, search with `index' calls rather than a simple loop. * main.c (main): Make sure stdout is line-buffered. * main.c (decode_switches): Always check for missing switch arg. Mon Oct 9 17:17:23 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.4. Sat Oct 7 00:32:25 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (set_file_variables): #ifdef NO_ARCHIVES, still set $@ and $%. * commands.c (set_file_variables): Include a trailing slash in the directory variables (@D, etc.). * job.c (child_handler): Call notice_finished_file after changing a child's state to `cs_finished'. * remake.c (update_file_1): Don't call notice_finished_file if FILE->command_state == cs_finished. Wed Oct 4 16:09:33 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.3. Tue Oct 3 21:09:51 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * read.c (read_all_makefiles): When setting elements of MAKEFILES from the contents of read_makefiles, make sure we're using the right element. * dir.c, glob.c [USGr3 || DIRENT]: Don't define d_ino as d_fileno. * Version 3.56.2. * remake.c (update_file_1): Return zero after calling remake_file if FILE->command_state != cs_finished. Test update_status thoroughly. * commands.c (execute_file_commands): Don't call notice_finished_file. * remake.c (remake_file): Return immediately after calling execute_file_commands. Sat Sep 30 14:57:05 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56.1 (alpha). * file.h (struct file): Made `update_status' not be a bitfield, since some broken compilers don't handle it right. * function.c (expand_function: `join'): Don't clobber the pointers and then try to free them. * job.c (exec_command): Fixed & vs = precedence problem. Thu Sep 28 17:29:56 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remake.c (update_file_1): Fixed typo in debugging output. * remake.c (library_file_mtime): Search for /usr/local/lib/libLIB.a after /usr/lib/libLIB.a. Tue Sep 26 16:07:58 1989 Roland McGrath (mcgrath at helen.Berkeley.EDU) * read.c (conditional_line): For `ifeq (a, b)', swallow space after the comma. Sun Sep 24 13:25:32 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * function.c (patsubst_function): If BY_WORD and the match is not a full word, update the text pointer correctly. * function.c (expand_function: `word'): Don't lose track of the second arg's expansion and free something else instead. Fri Sep 22 16:15:29 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.56. Thu Sep 21 14:28:42 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * main.c (main): Make an array of the mtimes of the makefiles before updating them, and compare their file_mtimes against this later. Don't re-exec if a makefile was successfully updated but didn't change. If a makefile failed to be remade and no longer exists, die. If a makefile failed to be remade, but changed anyway, re-exec. If a makefile failed to be remade, but is unchanged, continue on. Wed Sep 20 18:02:07 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.55.6. * implicit.c (pattern_search): Maintain an array CHECK_LASTSLASH of the CHECK_LASTSLASH flag values used to match each member of TRYRULES. When making FILE->stem, if CHECKED_LASTSLASH[FOUNDRULE], prepend the part of FILENAME before LASTSLASH. Tue Sep 19 17:44:08 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * dir.c (dir_file_exists_p): Check for FILENAME being nil before checking for it being "". * main.c (define_makeflags): Fixed test for whether a flag/flag_off option was non-default. Also changed to generate a string that Unix Make will grok (except for FP/int values and new flags). * job.c (child_execute_job): Don't use the shell's -c option. Also fixed an off-by-one bug in the ARGV -> shell arg list copying. Mon Sep 18 15:17:31 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.55.5. * read.c (parse_file_seq): Check the beginning of the file name for a `./', not the two chars after the end of the name (Q rather than P). * job.c (child_execute_job): Include all of ARGV in the arg list for the shell. * main.c (define_makeflags): Don't include floating and positive_int options in !PF. * job.c (exec_command): Set the effective gid to the real gid before execing. * job.c (child_execute_job): Don't clobber the arg list when execing the shell. Sun Sep 17 15:27:19 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * main.c (define_makeflags): Moved all the checking inside the switch. * load.c [LDAV_BASED] (load_average): When we can't get the load average, return zero instead of running off the end. * file.c: Include variables.h. * job.c: Declare dup2 and {block,unblock}_remote_children. * file.h: Declare f_mtime. * job.c: Don't declare construct_command_argv, since job.h does. * function.c, main.c, load.c, remake.c: Include job.h. * load.c [LDAV_BASED] (load_average): Declare nlist. * variable.h: Declare print_file_variables. * job.c [!USG]: Don't declare sigsetmask. [!USG]: Declare getdtablesize. Don't declare load_average. Do declare wait_to_start_job. Declare vfork, gete[gu]id, execve. * commands.c: Declare remote_kill, getpid. * make.h: Declare kill, exit, sigblock, pipe, close, ctime, open, lseek, read. * make.h [not USG]: Declare sigsetmask. * job.h: Declare wait_for_children and {block,unblock}_children. * dir.c (dir_file_exists_p): If FILENAME is nil, read in the whole directory. (find_directory): When we want to read in the whole directory, call dir_file_exists_p with nil instead of "". * file.h (struct file), job.h (struct child), variable.h (struct variable): Use bitfields for flags. * make.h (ENUM_BITFIELD): If GCC or #ifdef ENUM_BITFIELDS, define as :BITS, else empty. * compatMakefile (defines): Document ENUM_BITFIELDS. Sat Sep 16 12:38:58 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.55.4 (alpha). * GNUmakefile (dist): Depend on default and doc. * load.c [LDAV_BASED]: Include rather than ; #ifdef NLIST_NAME_UNION, use n_un.n_name instead of n_name. * compatMakefile (LOAD_AVG): Document NLIST_NAME_UNION. * job.c [USG-ish]: Don't redefine WIF{SIGNALED,EXITED} if they're already defined. Fri Sep 15 13:59:42 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * glob.c, dir.c [USGr3 or DIRENT]: If neither d_ino, nor d_fileno is defined, define d_ino as d_fileno. Thu Sep 14 18:29:38 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * job.c: Don't declare exec_command static. * make.texinfo (Name Index): Changed title to include directives. * Version 3.55.3 (alpha). * make.texinfo (Running: Options): Document -e. * main.c (main): Always give imported environment variables origin `o_env'. * variable.c (define_variable_in_set): Under -e, if ORIGIN, or an existing variable's origin, is `o_env', make it `o_env_override'. * load.c: Use the symbol KERNEL_FILE_NAME instead of KERNEL_FILE. * compatMakefile: Changed the comment for `LOAD_AVG' accordingly. Thu Sep 7 16:46:26 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.55.2 (alpha). * variable.c (print_variable_set), rule.c (print_rule_data_base), file.c (print_file_data_base): If NO_FLOAT is defined, don't use floating-point for printing statistics. * compatMakefile (defines): Document NO_FLOAT. * make.h (HASH): New macro to add the hashing value of one char to a variable.c. * file.c (lookup_file, enter_file, rename_file): Use it. * dir.c (find_directory, dir_file_exists_p, file_impossible_p): Ditto. * variable.c (define_variable_in_set, lookup_variable): Same here. * variable.c, file.c, dir.c: Don't define *_BUCKETS if they are already defined. * compatMakefile (defines): Added comment about defining NO_ARCHIVES. (ARCHIVES, ARCHIVES_SRC): New variables for {ar,arscan}.[oc]. (objs, srcs): Use $(ARCHIVES) and $(ARCHIVES_SRC). * commands.c (set_file_variables), dir.c (file_exists_p), remake.c (touch_file, name_mtime), implicit.c (try_implicit_rule, pattern_search), make.h: If NO_ARCHIVES is #defined, don't do any archive stuff. * commands.c (set_file_variables): Don't kill the last char of directory names in $([@*<%?^]D). Wed Sep 6 15:23:11 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * default.c (default_terminal_rules {%:: %,v}, {%:: RCS/%,v}): Don't run co if the target exists. * glob.c (glob_match): [!xyz], rather than [^xyz], means none of [xyz]. * glob.c: Misc minor cosmetic changes. Tue Sep 5 14:49:56 1989 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * load.c [LDAV_BASED] (load_average): Check for == -1, rather than < 0 to see if lseek fails. On some systems, `avenrun' is at an offset > (2**31)-1, and lseek succeeds, returning a negative value. Mon Sep 4 11:07:58 1989 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * rule.c (new_pattern_rule): Return `int' instead of `void': nonzero if the passed rule was used, zero if not. (install_pattern_rule): Pay attention to the return from new_pattern_rule, and don't set the rule's `terminal' flag or give it commands unless it's used. (create_pattern_rule): Same idea. * dir.c (find_directory): Removed unused variable. * commands.c (execute_file_commands): Removed unused variable. * read.c (record_files): Don't use NAME after freeing it. Sat Sep 2 00:33:19 1989 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * Version 3.55.1 (alpha). * function.c (string_glob): Don't add spaces after file names that aren't added. (Also means don't add spaces without checking the size of the buffer.) * remake.c (update_goal_chain): Don't remove makefiles with cmds and no deps from the chain. * main.c (main): Do it here, before calling update_goal_chain. * remake.c (update_goal_chain): When updating fails, change STATUS even if MAKEFILES is set. Also stop remaking when updating fails if not under -k and MAKEFILES is not set. * remake.c (remake_file, update_file_1, notice_finished_file), commands.c (execute_file_commands), make.h, commands.h: The functions remake_file, notice_finished_file, and execute_file_commands no longer return values, and their callers no longer expect values returned. * remake.c (notice_finished_file): Don't set FILE's modtime to now if it is a non-target with no commands. Fri Sep 1 00:04:39 1989 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * read.c (read_all_makefiles): After freeing each element on MAKEFILES, replace it with the name stored in read_makefiles by read_makefile. * remake.c (update_file_1): Don't decide not to remake if FILE has no cmds and no deps actually changed if FILE doesn't have any deps. * file.c (remove_intermediate): Remove precious files that also have the `dontcare' flag set. * remake.c (update_file_1): Don't always remake if FILE has cmds but no deps; only if FILE is double-colon. (I don't know why this should be done for double-colon targets, but that's what Unix make does.) * load.c [LDAV_BASED] (load_average): Write error messages if the various system calls fail. Keep track of if we've failed before. The first time we fail, write a message saying -l won't be enforced. The first time we succeed after having failed, write a message saying -l will be enforced again. * remake.c [USG]: Don't #include * load.c [generic Unix LDAV_BASED]: #include #ifdef USG, else instead. * job.c [USG && !USGr3 && !HAVE_DUP2]: Remove redundant #include and declaration of `errno'. [...] (dup2): Fixed so it won't always lose. * default.c (default_suffix_rules: .texinfo.dvi): Copy, rather than move, the aux and index files, so the TeX run can use them. * compatMakefile: Remove redundant comment. * load.c [generic Unix LDAV_BASED]: Include instead of , since the `struct nlist' declaration in varies more than the one in . (load_average): Use the `n_un.n_name' field of the `struct nlist', since the declaration uses the union. * main.c (main): For the temporary files made for stdin makefiles, set the `intermediate' and `dontcare' flags. * file.c (remove_intermediates): Don't print any messages for files whose `dontcare' flag is set. (The only files that will be intermediate and `dontcare' will be the temporary files made for stdin makefiles.) * job.c (exec_command): Made global. * job.h: Declare it. * main.c (main): Use exec_command when re-execing. * make.h: Declare environ. * make.c: Don't. * job.c (child_execute_job): New function to perform everything done in the child side of a fork (for a job or `shell' function). (start_job): Call it. * job.h: Declare construct_command_argv and child_execute_job. * function.c (expand_function: `shell'): Use child_execute_job. Thu Aug 31 18:42:51 1989 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * function.c (expand_function: `shell'): Remove a trailing newline instead of turning it into a space. * main.c (main): Do init_siglist #ifdef HAVE_SIGLIST. * job.c [WTERMSIG || (USG && !HAVE_SYS_WAIT)]: Test each W* macro separately and define all those that aren't defined. Sat Aug 26 15:13:21 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * ar.c (ar_name): Return zero for `(foo)'. * Version 3.55. * make.texinfo (Rules: Multiple Targets): Make this node's `next' pointer point to `Static Pattern'. * make.texinfo (Makefiles: MAKEFILES Variable): Make this node's `prev' pointer point to `Makefile Names'. * make.1: Renamed to make.man. * compatMakefile: Define `mandir' and `manext'. (install): Depend on $(mandir)/make.$(manext). ($(mandir)/make.$(manext)): Depend on make.man and copy it to $@. ($(bindir)/make): Use `make' rather than $<; so Unix make can grok it. Thu Aug 24 03:35:48 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * variable.c (target_environment): Allow variables that start with underscores. Wed Aug 23 22:50:32 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * variable.c (target_environment): Reject variables that don't start with letters. Tue Aug 22 04:14:29 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * GNUmakefile (make-$(version).tar.Z): Put make.1 (the Unix manual page) in the tar file. * variable.c (target_environment): Don't write variables with origin o_default (i.e., ones from default.c). * make.texinfo (Commands: Recursion: Variables/Recursion): Document that default variables are not put in the environment. * remake.c (update_file_1): Remake all targets with commands but no deps. Sat Aug 19 06:03:16 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (update_file_1): In the final loop, set the deps' `changed' members if they are newer than FILE. * remake.c (update_goal_chain): Under -d, print a message if we decide not to remake a makefile so as to avoid a possible infinite loop. Fri Aug 18 20:30:14 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (remake_file): Cleaned up. * commands.c (execute_file_commands): If the commands are empty, set FILE->update_status to zero before returning. * remake.c (notice_finished_file): Set `last_mtime' fields to zero instead of calling name_mtime; file_mtime will do that later if anybody cares. Thu Aug 17 10:01:11 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * make.texinfo (Rules: Wildcards: Wildcard Examples): Give this node a `prev' pointer. * Version 3.54.9 (alpha). * make.texinfo: Fixed some @nodes. * remake.c (check_dep): Don't set *MUST_MAKE_PTR if FILE doesn't exist after running update_file. * remake.c (notice_finished_file): If FILE has no commands, pretend its modtime is now. * remake.c (update_file_1): In the loops that call update_file on the deps, compare modtimes before and after (unless deps are still being made) and set the deps' `changed' members. Do not set the `changed' members in the loop that prints the newer/older debugging messages. * remake.c (update_file_1): If no deps changed and FILE has no commands, decide it doesn't need remaking. * remake.c (update_file_1): Print a debugging message if we take commands from default_file. * make.texinfo (Rules: Directory Search: Selective Search): Removed note about warning for `vpath' with a constant pathname, since it isn't warned about anymore. * remake.c (update_goal_chain): If MAKEFILES, remove makefiles which are targets and have no deps. * make.texinfo (Makefiles: Remaking Makefiles): Document that makefiles will not be remade if they are targets but have no dependencies. Tue Aug 15 00:00:08 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) * remake.c (notice_finished_file): Increment files_remade for non-phony files if they didn't exist before (even if they still don't). * job.c: Include and declare errno. * job.c (exec_command): If the execve fails with ENOEXEC (Exec format error), return instead of exiting the child process. * job.c (start_job): In the child side, if exec_command fails, try using the shell. * job.c (start_job): In the child side, call unblock_children instead of sigsetmask. * remake.c (notice_finished_file): Under -n or -q, always increment files_remade for non-phony files. * rule.c (intall_pattern_rule): Use find_percent. * vpath.c (vpath_search): Pass the `percent' members to pattern_matches. Mon Aug 14 23:30:24 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) * vpath.c (struct vpath): New member `percent', to hold a pointer into the pattern where the % is. (construct_vpath_list): Call find_percent on the pattern and set the new `percent' member. * read.c (read_makefile): Don't run find_percent on `vpath' directive patterns. * function.c (pattern_matches): Take new arg PERCENT, a pointer into PATTERN where the % is. If PERCENT is nil, copy PATTERN into local space and run find_percent on it. (expand_function: `filter', `filter-out'): Pass new arg to pattern_matches. * read.c (record_files): Pass PATTERN_PERCENT to pattern_matches for static pattern rules. Save the percent pointer into implicit rule targets, and pass them to create_pattern_rule. * rule.c (convert_to_pattern): Pass new arg to create_pattern_rule. (create_pattern_rule): Take new arg TARGET_PERCENTS, nil or an array of pointers into the corresponding elements of TARGETS, where the %s are. Sun Aug 13 00:29:19 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54.8. * README.templatate, README-doc.template: New files, turned into README and README-doc to go into the two distribution tar files. * GNUmakefile: Added a rule to edit the version number in README.template and README-doc.template, producing README and README-doc. * remake.c (update_goal_chain): If -n or -q is in effect for a makefile, and it got updated, don't change STATUS, so we can still return -1 (meaning nothing was done). This avoids an infinite loop on "make -n Makefile". Sat Aug 12 23:14:24 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (notice_finished_file): Treat -q the same as -n. * remake.c (update_goal_chain): Fixed handling of return from update_file. If -n or -q is in effect, ignore it. * job.c (start_job): Don't test for -t. We should never get called in that case. Fri Aug 11 04:09:14 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * function.c (expand_function): Removed unused variables. (handle_function): Removed unused variable. * main.c (main): Removed unused variable. Wed Aug 9 09:37:10 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54.7. * remake.c (notice_finished_file): If FILE's modtime actually changed, increment files_remade. (remake_file): Don't increment files_remade. * remake.c (update_file): Don't print "up to date" messages for phony files. * job.c (child_handler): Don't set C->file->update_status to 1 if start_job returns nonzero under -n or -t. * expand.c (variable_expand): Count parens in $(foo:a=b) refs. * main.c: Removed old declaration of `glob_tilde' (which hasn't existed for a few months). Tue Aug 8 23:53:43 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * job.c (exec_command): Fixed to not ignore the last path component and to do the right thing with an empty path. Fri Aug 4 15:58:19 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (library_file_mtime): Look for libLIB.a, not /libLIB.a. Do VPATH search on libLIB.a, not /usr/lib/libLIB.a Thu Aug 3 20:42:00 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * job.c [HAVE_SYS_WAIT or not USG]: If WIFSIGNALED is not defined by , define it as (WTERMSIG != 0). Tue Aug 1 19:25:34 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (remake_file): If FILE has no commands and is a target, don't set its time to now. The time gets reset by notice_finished_file anyway, and it isn't needed since check_dep checks for nonexistence. * Version 3.54.6. * read.c (read_makefile): Don't read off the end of the string after an `include'. * job.c (exec_command): New function to search the path for a file and execute it. (start_job): Use exec_command rather than execvp. * read.c (read_makefile): Expand `include' directive args before parsing them. Allow trailing whitespace after filename. * variable.c (target_environment): Put makelevel + 1, rather than makelevel, in the `MAKELEVEL' envariable. Sat Jul 29 10:27:04 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * remake.c (notice_finished_file): Don't get the new modtime of phony files. * remake.c (remake_file): Run commands instead of touching under -t if FILE->cmds->any_recurse is set. * commands.h (struct commands): Add new member `any_recurse', to be set nonzero if any `lines_recurse' element is nonzero. * commands.c (chop_commands): Set the `any_recurse' member. * commands.c (execute_file_commands): Split chopping of commands into lines into new function chop_commands. * commands.h: Declare chop_commands. * read.c (read_makefile): Test for a line beginning with a tab after checking for conditional lines, but before all other checks. Fri Jul 28 18:10:29 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * read.c (read_makefile): Match directives against collapsed line and use that for their args. * read.c (read_makefile): Warn about extra text after `include'. Tue Jul 25 14:34:25 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * make.texinfo (Rules: Directory Search: Selective Search): Fixed example to use correct `vpath' syntax. Mon Jul 24 12:10:58 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54.5. * job.c (start_job): In the child side, unblock SIGCHLD. Fri Jul 21 18:25:59 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * make.h: Don't include #ifdef sun. Mon Jul 17 14:29:10 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * implicit.c (pattern_search): If ar_name (FILENAME), don't check for directory names. * job.c (wait_for_children): Changed "waiting for children" message to "waiting for unfinished jobs". Fri Jul 14 13:17:13 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * load.c (load_average): Use an unsigned offset into kmem. Thu Jul 13 18:44:49 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * variable.c (pop_variable_scope): Don't free the head of the chain of variables in each bucket twice. Tue Jul 11 06:45:24 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * GNUmakefile: Include COPYING in the doc tar file. * variable.c, read.c, misc.c, job.c, function.c: Replace some identical "for" loops with next_token or end_of_token calls. Mon Jul 10 16:55:08 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54.4. * compatMakefile: Documented new conditionals. * job.c: Don't define sys_siglist if HAVE_SIGLIST is defined. Don't define dup2 if HAVE_DUP2 is defined. * job.c (child_handler): Interpret the return from start_job correctly. * remake.c (update_file_1): Don't write "target not remade because of errors" message under -n or -q. * read.c: Declare getpwnam. * glob.c: Use if DIRENT is defined. [USG]: Don't declare memcpy, since does. Fri Jul 7 20:53:13 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * misc.c (collapse_line): Copy the line over in the right place. Fri Jul 7 18:33:24 1989 Roland McGrath (fsf at void.ai.mit.edu) * remake.c: Conditionalize inclusion of on not USG, since HP-UX defines a `struct file' there. Fri Jul 7 12:11:30 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * job.c: If WTERMSIG is defined by , define WAIT_T as int, and don't define other macros; this covers HP-UX. If WTERMSIG is not defined, use int or union wait based on USG and HAVE_SYS_WAIT; this covers BSD and SysV. * Version 3.54.3 (alpha). * job.c [USG and not USGr3]: Include and declare errno. * job.c (unblock_children [USG]): Declare child_handler. * job.c: Renamed WRETCODE to WEXITSTATUS. [HAVE_SYS_WAIT or not USG]: Undefine WTERMSIG, WCOREDUMP, and WEXITSTATUS before defining them. The HP-UX defines them. * main.c (main): If there are no goals, fatal AFTER printing the data base under -p. Thu Jul 6 22:43:33 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) * glob.c [USG]: #define rindex as strrchr. * job.c [USG]: Include and #define getdtablesize() as NOFILE. Wed Jul 5 09:36:00 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54.2 (alpha). * expand.c (variable_expand): When expanding recursive variable references (${${a}}), use the correct delimiters in the constructed variable reference. Mon Jul 3 18:29:26 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) * compatMakefile: Clear out and redefine the .SUFFIXES list because silly Sun 4 make defines .cps.h. * compatMakefile: Fix comment about -DNO_MINUS_C_MINUS_O. * remake.c: Include for O_* on 4.2. * commands.c: Define sigmask if it's not defined. Fri Jun 30 07:33:08 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) * remake.c (remake_file): Don't always increment files_remade. * variable.c (push_new_variable_scope): Zero the new variable hash table. Thu Jun 29 17:14:32 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * expand.c (variable_expand): When terminating the variable expansion buffer, use variable_buffer_output instead of a simply zero store, because the buffer may need to be enlarged. Wed Jun 28 16:53:47 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.54. * default.c (default_suffixes): Added `.ln'. (default_suffix_rules): Changed lint rules to use -C. Thu Jun 22 20:49:35 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * job.c (start_job): Set `environ' to CHILD->environment before execing in the child process! Tue Jun 20 17:23:13 1989 Roland McGrath (roland at spiff.ai.mit.edu) * compatMakefile: Put job.h and rule.h in `srcs'. * Version 3.53. Mon Jun 19 16:25:18 1989 Roland McGrath (roland at spiff.ai.mit.edu) * job.c (start_job): If there are no more commands, return nonzero under -n or -t. * compatMakefile (make): Pass `-f' to mv. * GNUmakefile: If `ARCH' or `machine' is defined, make $(ARCH)/*.o and $(ARCH)/make instead of *.o and make. * function.c (string_glob): Don't try to use freed storage! * read.c (readline): If there is only one byte of space in the buffer, enlarge the buffer before reading more. * arscan.c [M_XENIX]: Miscellaneous minor changes for Xenix. Sun Jun 18 13:07:45 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * GNUmakefile (depend): Split commands into two lines so they won't be so long when variable-expanded. * compatMakefile: Documented MINUS_C_MINUS_O meaning. The line describing it got removed when the USG/wait stuff was documented. Sat Jun 17 22:56:54 1989 Roland McGrath (roland at hobbes.ai.mit.edu) * Version 3.52. Mon Jun 12 17:45:11 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remake.c (check_dep): Drop circular dependencies instead of fataling. (update_file_1 already does this.) * default.c (default_suffix_rules): For .s -> .o, put the -o flag to the assembler before the source file name. Sun Jun 11 12:00:52 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.51. * make.texinfo (Features): Noted 1003.2 requirement of `+' meaning. * file.c (remove_intermediates): If !SIG, write a single "rm" command line, listing all files. * read.c (read_makefile): Don't free the storage for the passed filename, since it might not be malloc'd. When doing an included makefile, free the name's storage. (read_all_makefiles): Use variable_expand to find the value of `MAKEFILES'. Free the storage for the names of -f makefiles. (read_makefile): Allocate storage for the makefile name in the `struct file' in read_makefiles. * make.texinfo (Running: Instead of Execution): Document the effect of + and $(MAKE)/${MAKE}. * make.texinfo (Functions: Foreach Function): Document that if the iteration variable was undefined before the `foreach' call, it will be undefined after the call. * commands.c: Split into commands.c, job.h, and job.c. * rule.c (try_implicit_rule, pattern_search): Moved to new file implicit.c. * rule.c: Split into rule.h, rule.c, and default.c. * default.c (install_default_pattern_rules): Renamed to install_default_implicit_rules. * make.h, main.c (main): Renamed uses. * make.c: Renamed to misc.c. * make.c (main, log_working_directory, decode_switches, decode_env_switches, define_makeflags, die, print_version, print_data_base): Moved to new file main.c. * commands.c (execute_file_commands): Don't collapse backslash-newlines here. When chopping the commands up into lines, don't chop at backslash-newlines. (start_job): Collapse backslash-newlines after printing the line. * commands.c (start_job): Don't collapse backslash-newlines here. (execute_file_commands): Collapse backslash-newlines before chopping the commands up into lines. * commands.c (set_file_variables): Initialize the length counters for $^ and $? to zero! * commands.c (start_job): Use vfork instead of fork. Someone else says the child and parent DO have separate file descriptors. * variable.c: Split internals into variable.c, function expansion into function.c, and variable expansion into expand.c. * function.c (handle_function): New function to check for a function invocation and expand it. * expand.c (variable_expand): Use handle_function. * variable.c (push_new_variable_scope): New function to push a new empty variable set onto the current setlist. (pop_variable_scope): New function to pop the topmost set from the current setlist and free its storage. * function.c (expand_function: `foreach'): Push a new variable scope for the iteration variable and pop the scope when finished. * variable.h: Declare new functions. * variable.c (initialize_variable_output): New function to return a pointer to the beginning of the output buffer. (save_variable_output): New function to save the variable output state. (restore_variable_output): New function to restore it. * expand.c (variable_expand): Use initialize_variable_output. (allocated_variable_expand): Use {save,restore}_variable_output. * variable.c (current_setlist): Renamed to current_variable_set_list and made global. Sat Jun 10 00:11:25 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remake.c (library_file_mtime): Check for libNAME.a in the current directory before doing VPATH search. * variable.c (print_variable_set): Don't write "# Variables", and write fewer blank lines. (print_variable_data_base): Precede the variables with "# Variables". * make.c (main): Print the data base under -p after doing everything else, just before exitting. This way it gets info determined in updating the goal targets. * variable.c (print_variable_data_base): Split into print_variable, which prints one variable, and print_variable_set, which prints a set. Replaced with a call to print_variable_set for the global set. (print_file_variables): New function to print a given file's local variables. * file.c (print_file_data_base): Call print_file_variables to print each file's local variables. * commands.c (set_file_variables): Actually define the values for the $^ and $? variables!!! * make.texinfo (Implicit: Pattern Rules: Automatic): Document new D and F versions of $^ and $?. * commands.c (start_job): In the child fork, use getdtablesize and a loop to close all file descriptors other than 0, 1, and 2. We need to do this since not only the bad stdin pipe, but also some directories, may be open. * commands.c (start_job): Use fork instead of vfork, because a vfork parent and child share file descriptors, and our child needs to diddle with stdin. * variable.c (initialize_file_variables): When created a new variable set, zero out the hash table. * variable.c (target_environment): Don't use variables whose names are not made up of alphanumerics and underscores. * remake.c (update_file_1): Set the `parent' member of each dependency to FILE before updating it. * file.h (struct file): Add `parent' member. * variable.c (initialize_file_variables): Don't take second arg PARENT. Use FILE->parent instead. If FILE->parent->variables is nil, recurse to initialize it. * variable.h: Declare {allocated_}variable_expand_for_file. * variable.c (allocated_variable_expand): Now allocated_variable_expand_for_file, calling variable_expand_for_file, and taking second arg FILE. (allocated_variable_expand): New function, a wrapper around allocated_variable_expand_for_file, passing a nil second arg. Fri Jun 9 12:11:45 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (start_job): On the child side of the fork, always close the bad stdin file descriptor. * commands.c (struct child): New member `environment', to hold the environment for the child. (execute_file_commands): Set the new childs `environment' member to nil before calling start_job. (start_job): Set up CHILD->environment before running the commands if it is nil. * make.c (main): Don't call new_environ. `shell' functions will now be run with the environment make was called with. * commands.c (child_handler): Don't check C->command_ptr before calling start_job since we now have to check C->file->cmds->command_lines and it's easier to let start_job handle all that. * commands.c (struct child): New member `command_line', to hold an index into file->cmds->command_lines. (execute_file_commands): Set the new child's `command_line' to 0 and its `commands' and `commands_ptr' to nil. (start_job): When CHILD->command_ptr runs out, increment CHILD->command_line and run the corresponding line from CHILD->file->cmds->command_lines. Run it even under -t, -q, or -n if the CHILD->file->cmds->lines_recurse element for that line is set. * commands.c (execute_file_commands): Chop CMDS up into lines, setting its `command_lines' and `lines_recurse' members, if it wasn't already chopped. * commands.h (struct commands): New members `command_lines' and `lines_recurse'. The first is an array of chopped-up lines; the second is an array of flags, each nonzero if the corresponding line is recursive. * variable.c (variable_expand_for_file): If FILE is nil, just do a vanilla variable_expand. (expand_function: `shell'): Pass second arg (as nil) to construct_command_argv. * commands.c (construct_command_argv): Use variable_expand_for_file on `$(SHELL)' and `$(IFS)' instead of lookup_variable to check those variables. This handles file-local and recursive values correctly. To support this, take an additional argument FILE. * variable.c (initialize_file_variables): New function to initialize FILE's variable set list from PARENT's setlist. PARENT is the immediate dependent that caused FILE to be remade, or nil if FILE is a goal. (When user-level per-file variables are implemented, PARENT should be passed as nil when defining per-file variables.) * variable.c (variable_expand_for_file): New function to expand a line using the variable set of a given file, and reporting error messages for the file and line number of that file's commands. * variable.h: Don't declare lookup_variable_for_file. * variable.c (lookup_variable_*): Turned back into lookup_variable. It now uses current_setlist. (global_setlist): New static `struct variable_set_list', a setlist containing global_variable_set. (current_setlist): New static `struct variable_set_list *', a pointer to the current variable set list. (define_variable): Define in the current top-level set, not the global set. * commands.c (set_file_variables): New function to set up the automatic variables for a file in its own variable set. (execute_file_commands): Use set_file_variables. * variable.c (new_environ): Replaced with target_environment, taking an argument FILE, and returning an environment for FILE's commands. * variable.c, variable.h: Remove all global special variable pointers. * variable.c (define_variable_for_file): New function like define_variable, but takes additional arg FILE, and defines the variable in the variable set at the top of FILE's chain. (lookup_variable_for_file): New function like lookup_variable, but takes additional arg FILE, and looks the variable up in all of FILE's variable sets. * file.h (struct file): New member `variables', a `struct variable_set_list' containing the list of variable sets used in the expansion of the file's commands. * variable.c (variables): Replaced with static `struct variable_set' global_variable_set. (define_variable): Now define_variable_in_set, taking additional argument SET, the `struct variable_set' to define it in. (define_variable): Use define_variable_in_set with global_variable_set. (lookup_variable): Now lookup_variable_in_set, taking additional argument SET, the `struct variable_set' to look it up in. (lookup_variable): Use lookup_variable_in_set with global_variable_set. (lookup_variable_in_setlist): New function to look up a variable in a `struct variable_set_list' using lookup_variable_in_set. * variable.h (struct variable_set): New structure, containing a hash table and the number of hash buckets. (struct variable_set_list): New structure, containing a link for a linked-list, and a `struct variable_set'. * commands.c (start_job): Under -n, return what the recursive start_job call returns, since it might actually start a child. * make.texinfo (Rules: Wildcards): Document ~ and ~USER expansion. * commands.c (execute_file_commands): If start_job returns failure, but -t is set, set FILE->update_status to success. (start_job): If -t is set, and the commands are not recursive, return failure (is is done for -q). * remake.c (touch_file): New function to touch FILE. (remake_file): Use touch_file. When touching a file, still do execute_file_commands. * remake.c (remake_file): Don't check question_flag (-q), since we can't know here if the commands are recursive. * commands.c (start_job): Don't use the `recursive' member of CHILD->file->cmds. Instead, check for leading +s and $(MAKE) or ${MAKE} in the command line here. * commands.h (struct commands): Remove `recursive' member. * rule.c (install_default_pattern_rules): Remove use of `recursive' member. * read.c (record_files): Don't check commands from $(MAKE) and set their `recursive' member. * commands.c (fatal_error_signal): Treat SIGQUIT like SIGINT, SIGHUP, and SIGTERM, but don't send it to ourselves because it will cause a core dump. Thu Jun 8 20:30:04 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.50. * variable.c (variable_expand): Use allocated_variable_expand instead of expand_argument in a few places. * variable.c (allocated_variable_expand): Do static variable shuffling here instead of using expand_argument. (expand_argument): Use allocated_variable_expand. * variable.c (recursively_expand): New function to recursively expand its argument (a `struct variable'), returning the malloc'd value. (variable_expand): Use recursively_expand. Sun May 28 12:49:27 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (main): Fixed buggy fix in deciding to increase space for command-line variable definitions. (First it never did it, then it always did it; now it does it when necessary.) Sat May 27 14:01:54 1989 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * make.c (main): Fixed bug in deciding to increase space for command-line variable definitions. Fri May 26 15:48:01 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * read.c (multi_glob): Use allocated_expand_variable for checking `HOME' variable for ~ expansion, since this may be called from inside a `wildcard' function expansion. * variable.h: Declare allocated_expand_variable. * variable.c (allocated_expand_variable): New function to do variable expansion in an allocated buffer, rather than the static one. * make.c (main): Don't set glob_tilde (it no longer exists). * variable.c (string_glob): Use multi_glob and parse_file_seq. * read.c (multi_glob): Do ~ expansion here. * glob.c (glob_tilde, glob_filename): Removed ~ expansion. * variable.c (define_variable, lookup_variable): Use a smarter hashing algorithm (the same one used for files and directories). (VARIABLE_BUCKETS): Increased to 523. * file.c (enter_file, lookup_file, rename_file): Use a smarter hashing algorithm, spreading the bits about somewhat. * make.c (log_working_directory): Under `-p', precede the directory message with a `#'. * make.c (print_version): Under `-p', precede each line with a `#'. (print_data_base): Precede the header line with a `#' and include the date and time on it. * vpath.c (print_vpath_data_base): Precede non-directive lines with `#'s. * commands.c (print_commands): Precede the non-command line with a `#'. * rule.c (print_rule_data_base), file.c (print_file_data_base): Precede non-rule lines with `#'s. * dir.c (print_dir_data_base): Precede all lines with `#'s. * variable.c (print_variable_data_base): Changed format so that it can be makefile input. Lines that are not variable definitions are preceded with `#'. Nonrecursive variable definitions are made with all dollar signs doubled to reproduce the initial value. Recursive variable definitions containing newlines are done with `define' directives. Nonrecursive variable definitions containing newlines, and variable names containing :, =, or newlines, will come out garbled. Wed May 24 00:20:04 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.49. Tue May 23 19:18:00 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * variable.c (expand_function: `filter'/`filter-out'): Use find_percent instead of pattern_p. * variable.c (expand_function: `patsubst'): Pass new args (both nil) to patsubst_expand. (variable_expand): For $(var:pat%=rep%) references, pass new args to patsubst_expand so as to avoid find_percent and thus disallow quoting the %s. * read.c (record_files): Pass new args to patsubst_expand. * variable.c (patsubst_expand): Take two new args: PATTERN_PERCENT and REPLACE_PERCENT. Each of these, if non-nil, means that PATTERN (or REPLACE) has already been run through find_percent, and PATTERN_PERCENT (or REPLACE_PERCENT) is the result. * make.h: Declare find_percent instead of pattern_p. * read.c (pattern_p): Changed to find_percent, returning a pointer to the %, or nil if there is none. (record_files): Take another arg, PATTERN_PERCENT, a pointer to the % in PATTERN. (read_makefile): Pass PATTERN_PERCENT to record_files. * make.texinfo (Rules: Static Pattern: Static Usage, Rules: Directory Search: Selective Search, Functions: Text Functions): Documented that `%' can be quoted. * variable.c (expand_function: `filter'/`filter-out'): Use pattern_p to allow quoted %s in patterns. * variable.c (patsubst_expand): Use pattern_p on PATTERN and REPLACE to allow quoted %s. Quoting backslashes are removed from REPLACE even if PATTERN contains no unquoted %. * read.c (pattern_p): Made global. * make.h: Declare pattern_p. * read.c (pattern_p): New function to search for an unquoted % in a string. Backslashes quote %s and backslashes. Quoting backslashes are removed from the string by compacting it into itself. Returns nonzero if an unquoted % was found, zero if not. (record_files): Use pattern_p to check for implicit rules. (read_makefile): Use pattern_p to check for static pattern rules. Also use it to allow quoted %s in `vpath' patterns; warn about `vpath' patterns with no %s. Mon May 22 16:31:52 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * glob.c (glob_filename): Replace a `1' with the `l' that should have been there. This incidentally stops it from dumping core. * glob.c (glob_filename): If the path is just a directory, with no file name pattern, return the directory alone. * glob.c (glob_tilde): New global variable (int), defaults to zero. (glob_filename): If glob_tilde is nonzero, expand ~ or ~USER. * variable.c (string_glob): Keep a static allocated buffer for file names taken from the list, instead of allocating and freeing one every time. Fri May 19 18:06:26 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.c (decode_switches): Get floating numbers from the right string. Sun May 14 13:48:04 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * commands.c (delete_child_targets): When deleting `also_make' files, include the target's name in the message: make: *** [foo] Deleting file `bar' Sat May 13 17:34:26 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (max_load_average, default_load_average): Default to -1. * load.c (wait_to_start_job): Return if max_load_average is < 0.0, not equal. Fri May 12 16:08:05 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * variable.c (variable_buffer_output): Don't try to do pointer arithmetic between objects not in the same array. Wed May 10 15:55:29 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * rule.c [M_XENIX] (default_suffix_rules, default_variables): Minor changes to allow for strange compiler syntax. * rule.c (default_variables): Don't include "> $@" in $(PREPROCESS.S), since it's already in the .S.s rule. * file.c (enter_file): Make a new double-colon file the `prev' member of the bottom `prev' file (the one whose `prev' is nil). * read.c (do_define): Append newlines after copying the lines into the value buffer, so we end up with a trailing newline. * make.c (print_version): If the global variable `remote_description' is not nil or "", append "-%s" (its value) to the version number. * remote-*.c: Define remote_description appropriately. Sun May 7 15:15:53 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (error_status): Converted to new function child_error, taking new arguments TARGET_NAME and IGNORED, and writing an error message: "*** [target] Error 1" (or signal #, etc.), appending " (ignored)" if IGNORED is nonzero. (child_handler): Use child_error instead of error_status. * compatMakefile (all): Don't depend on `doc'. * compatMakefile (clean): Don't remove make-info*. (realclean): New rule, depends on `clean', removes tags, TAGS, and all Info and TeX files. Thu May 4 17:00:46 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * variable.c (print_variable_data_base), file.c (print_file_data_base), rule.c (print_rule_data_base), Use floating-point for averages and percentages. * make.c (print_data_base): Print messages before and after the data base information. * commands.c (print_commands): Changed output format to separate lines in commands and prefix them with tabs. * dir.c (print_dir_data_base): Changed output format slightly. * vpath.c (struct vpath, construct_vpath_list, selective_vpath_search): Remove the `exists' member and its uses. * vpath.c (print_vpath_data_base): New function to print all selective and general VPATH search paths (for -p). * make.c (print_data_base): Call print_vpath_data_base. * file.c (print_file_data_base): Changed format to look more like a makefile rule. Now reports all information in the `struct file'. * rule.c (print_rule_data_base): Changed format of display from: %: (terminal) depends on: RCS/%,v to: %: RCS/%,v is terminal. references nonexistent subdirectory. Also include number and percent that refer to nonexistent subdirectories. Thu Apr 27 15:45:40 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.c (main): Figure out the level of recursion before writing the `Entering directory' message. * variable.c (define_automatic_variables): Don't figure out the level of recursion from `MAKELEVEL'. It's now done in main. * Version 3.48. Wed Apr 26 16:39:17 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (child_handler): Set `update_status' to zero when there are no more commands. * make.c (log_working_directory): If MAKELEVEL > 0, indicate the recurson in the message (make[1]: ...). * commands.c (child_handler): Change status to `cs_finished' when commands fail. * commands.c (start_job): Return 0 (success) if there were no more commands for the child. (child_handler): Change the status to `cs_finished' when start_job fails to start the commands. * make.c (main): Don't handle SIGEMT if it's not defined. Do handle SIGDANGER if it is defined. * commands.c (child_handler): Reorganized inner loop so that it doesn't try to inspect the child before finding it. Tue Apr 25 16:28:24 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.c (end_of_token): Fixed bug wherein backslashes caused immediate return. * Version 3.47. * make.texinfo (Implicit: Pattern Rules: Automatic): Document setting of `$*' for explicit rules. Add note clarifying that automatic variables, though referred to in the documentation as `$<', etc. are no different than `$(<)', etc. Fri Apr 21 18:00:12 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * file.c (enter_file): Don't strip leading `./'s. * read.c (parse_file_seq): Strip leading `./'s. Thu Apr 13 17:26:41 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.texinfo (Commands: Parallel, Running: Options): Document that -l with no argument removes a previous load limit. * make.c (struct command_switch): New member `default_value'. (default_job_slots): Default value (of 1) for -j. (default_load_average): Default value (of 0, unlimited) for -l. (command_switches): Use default values for -j and -l. Also, -l without an arg now means no load limit. (define_makeflags): Don't write positive_int or floating options whose values are their defaults. * make.c (main): Under -w, write a `Leaving directory' message before re-execing. Tue Apr 11 16:46:29 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.46. * Makefile: Provide an easy place for system-specific definitions (-DUSG, etc.) and extra object files (for whatever). * make.texinfo: Miscellaneous fixes from RMS. Mon Apr 10 19:31:34 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * rule.c (pattern_search): Put rules with `subdir' flags set in TRYRULES, since these might be valid with VPATHs. In the TRYRULES loop, don't do lookup_file or file_exists_p calls for dependencies of rules with `subdir' flags set, but still do vpath_search calls and intermediate-file searches. Thu Apr 6 16:33:00 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.texinfo (Implicit: Pattern Rules: Automatic): Document the new definition of $* for explicit rules. * commands.c (execute_file_commands): If FILE->stem is nil, figure out if FILE->name ends in a suffix in the .SUFFIXES list; if so, store the name sans suffix in FILE->stem (and $*). Wed Apr 5 15:24:48 1989 Roland McGrath (mcgrath at helen.Berkeley.EDU) * file.c (remove_intermediates): Don't use `file_exists_p' to check for the existence of intermediate files, because the hashed directories will probably be out of date. * commands.c (child_handler): Free the good stdin before running the next command line. * commands.c [USG] (init_siglist): Don't case SIGEMT if it's not defined. Do case SIGDANGER (for IBM RT) if it is defined. * commands.c: Changed `SYS_WAIT' to `HAVE_SYS_WAIT'. (child_handler): Use `wait3' if HAVE_SYS_WAIT is #defined. * file.c (enter_file): If any `./'s are stripped off, allocate a new copy of the shortened name. * rule.c (pattern_search): Allocate the right length strings for `also_make' members. Sat Apr 1 13:28:38 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.45. * GNUmakefile: Make a separate tarfile of the DVI and info files. * make.c (define_makeflags): If a switch that takes an argument has its default value, put the switch in MAKEFLAGS with no arguments. * make.c (command_switches): Pass `-l' in MAKEFLAGS. Wed Mar 29 17:50:05 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * GNUmakefile: Don't include the DVI and info files in the dist. * commands.c (child_handler): Don't call check_changed_{directories,vpaths}. * make.h: Don't declare check_changed_{directories,vpaths}. * vpath.c (check_changed_vpaths): Removed this function. * dir.c (struct directory): Remove `modtime' member. (find_directory): Don't set `modtime' member. (check_changed_directories): Removed this function. * remake.c (update_file_1): Set FILE->command_state to cs_finished if it didn't need to be remade. * remake.c (update_file): Only write the "up to date" message if the target went from `not_started' state to `finished' state without incrementing the count of files remade. * commands.c [USG] (init_siglist): If both SIGCHLD and SIGCLD are defined, don't put them both in the `switch'. Tue Mar 28 15:37:02 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * file.c (rename_file): Change FILE's name!!! * rule.c (create_pattern_rule): Set the `terminal' member of the new rule after calling new_pattern_rule, which zeros it. * rule.c (default_variables): Use $(C++) in $(COMPILE.cc)! Sun Mar 26 15:52:30 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Makefile: Added a `clean' target. Fri Mar 24 15:08:46 1989 Roland McGrath (mcgrath at helen.Berkeley.EDU) * Version 3.44. * file.c (rename_file): If a `struct file' for the renamed-to name exists, and it is a target or has deps or commands, barf. If not just remove the old one for put in the new one. * remake.c (update_file_1, check_dep): Changed it back so that equal modtimes to NOT make dependencies be considered newer. RCS checks out files with equal modtimes as the RCS files, so this screws it. * make.h, glob.c: If __GNUC__ is defined, use __builtin_alloca. * Makefile: Use variables `ALLOCA' and `ALLOCASRC' so systems without a good standard alloca can get it from the Emacs distribution (or somewhere). * dir.c: Don't include , since make.h does. * make.c: Removed debugging version of getwd. Thu Mar 23 16:16:27 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.43. * remake.c (update_file_1): If a dependency loop is found, don't fatal. Emit an error message and remove the dependency. * remake.c (library_file_mtime): Fixed to use the right names. (update_file_1, check_dep): Consider a dependency "newer" than its dependent if they have the same modification time. Wed Mar 22 19:31:35 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * file.c (remove_intermediates): Don't try to remove nonexistent files. Mon Mar 20 10:21:22 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.42. * rule.c (default_variables): Set F77 to $(FC) and F77FLAGS to $(FFLAGS) so explicit rules expecting these (which are in System V) will work. However, there is no way to make setting these affect the implicit rules, unless we trash FC and FFLAGS (which BSD uses). [USG]: Set GET to `get' rather than `/usr/sccs/get'. Sun Mar 19 20:00:27 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * vpath.c (construct_vpath_list): Don't replace VPATH[ELEM] with dir_name (V), because the latter may get freed. Sat Mar 18 15:01:39 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.41. * make.texinfo: Cleaned-up edition 0.1 Beta from RMS and Bob Chassell. * file.c (rename_file): If a file with the new name already existed, use the same storage space, after freeing the old file's name, deps, and `also_make' member, preserving the link in the chain. Also write an error message telling the user to report the incident; I don't think this should be able to happen, but I'm not sure. * file.c (rename_file): Don't add the hash values of the old and new names together! Reset HASHVAL before computing the second value. * dir.c (check_changed_directories): Zero the new file hash table after allocating it. * dir.c (dir_file_exists_p): If FILENAME is "", return 1 if the directory exists. * vpath.c (check_changed_vpaths): New function to run through the search paths of all VPATHs, making the `exists' members correspond to reality. * commands.c (child_handler): Call check_changed_vpaths. * make.h: Declare check_changed_vpaths. * vpath.c (struct vpath): New element `exists', an array of char flags; exists[N] is nonzero if searchpath[N] exists. (construct_vpath_list): Set the `exists' member. (selective_vpath_search): Don't search directories whose `exists' elements are zero. * read.c (read_makefile): Set the `dontcare' flag of makefiles from the MAKEFILES variable if they were not mentioned anywhere but in the MAKEFILES variable. * read.c (read_makefile): Don't write an error message if fopen fails for a makefile from the MAKEFILES variable. * dir.c (struct directory): Add `modtime' member to record the modification time of the directory when it was opened. (check_changed_directories): New function to check all known directories; if their modtimes have changed since they were opened, their file tables are cleared and they are reset to be read in. * commands.c (child_handler): Call check_changed_directories before returning. make.h: Declare check_changed_directories. Tue Mar 14 20:07:13 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.40. * make.c (print_version): Made the copyright say 1988, 1989. * read.c (read_all_makefiles): Don't set *MAKEFILES to the name of the end of the read_makefiles chain, since the latter may be from an included makefile. (Why did I do this before?) * make.c (main): Set argv[0] to "" if it was nil. Don't put the command-line variable definitions into argv[0], only into the MAKE variable! Sun Mar 5 20:44:08 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * ar.c (ar_member_date, ar_touch): Remove the trailing ) from the member name. Fri Mar 3 18:15:15 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (construct_command_argv): Initialize NEW_ARGV to 0. At `slow' label, if NEW_ARGV is not 0, free it; then allocate 4 strings. Tue Feb 28 14:29:39 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.39. * COPYING, make.texinfo: New GNU General Public License, version 1. * *.c, *.h, Makefile: New copyright notices for the new GNU General Public License, version 1. * commands.c [USG]: Define WRETCODE correctly (again). * variable.c (expand_function: `shell'): Don't capture the standard error output of the shell command. * ar.c (ar_touch, ar_member_date): Allocate MEMNAME with the right length. * load.c [not UMAX] (load_average): Don't clobber the first nlist member when trying to set the second! Thu Feb 23 13:13:53 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * commands.c (child_handler): Really ignore errors under -i and for - lines, don't just print a different message. * make.c (decode_switches): Fixed handling of arguments (or lack thereof) to switches. Wed Feb 22 16:25:39 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * commands.c (construct_command_argv): Don't clobber LINE when checking the IFS variable. Sun Feb 19 11:17:07 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * load.c [UMAX, not NO_LDAV] (load_average): Return 0.0 rather than randomness when calls fail. * Version 3.38. * commands.c (fatal_error_signal): If handling a user kill signal (TERM, INT, HUP), wait for the children without printing the "Waiting for children" message, since they will die quickly. * Version 3.37. * remote-stub.c (remote_status): Take another arg, BLOCK. If this is nonzero block waiting for remote children. If not, return 0 if we would have to block. * commands.c (child_handler) [not USG]: If called as a signal handler, use wait3 and don't block. [USG]: If called as a signal handler, return after handling one child. Sat Feb 18 13:37:04 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * file.c (snap_deps): Process all double-colon entries of each file, not just the first one. * Version 3.36. * remote-stub.c: remote.c renamed. remote.c: Just include remote-stub.c * commands.c (child_handler): If we were called as a signal handler, return after handling one child. * commands.c [not USG]: Include and define `sigmask' if doesn't. (block_children, unblock_children): Use sigmask rather than bitshifting explicitly (and incorrectly). * remote.c (remote_kill): New function to send a signal to a remote child. * commands.c (fatal_error_signal): If we get a SIGTERM, send one to each living child. If we get a SIGTERM, SIGINT, or SIGHUP, delete all pending targets before waiting for children. (struct child): Add new member `deleted'. (start_job): Initialize `deleted' member to 0. (delete_child_targets): New function to delete a given child's targets, unless the `deleted' flag in the `struct child' says they have already been deleted. Sets this flag before returning. Thu Feb 16 18:32:07 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c [USG]: Define `WRETCODE' correctly (X & 0xff00). Tue Feb 14 16:05:00 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (construct_command_argv): Don't make the 0th element of the argument list be "sh" when executing /bin/sh, because start_job uses the 0th element as the program name. Sun Feb 12 17:42:05 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.35. * read.c (readline): Put a null in the beginning of the buffer before starting the reading loop. * read.c (read_makefile): Made main reading loop while !feof (infile), and removed EOF check after calling readline. Sun Feb 5 19:52:38 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * remote.c (block_remote_children, unblock_remote_children): New (stub) functions to block and restore asynchronous notification of remote child death. * commands.c (block_children): Call block_remote_children. (unblock_children): Call unblock_remote_children. (child_handler): If called as a signal handler, block remote children on entry and unblock them before returning. * commands.c (child_handler): For unknown children, if they are remote, give their remote ID; if local, give their PID and make's. * commands.c (execute_file_command): Don't put a new child in the chain unless start_job succeeds. Block children before calling start_job, and unblock them after putting the child in the chain and incrementing `job_slots_used' (if start_job succeeded). * commands.c (block_children, unblock_children): Make these globally visible (not `static'). commands.h: Declare block_children and unblock_children. * variable.c (expand_function: `shell'): Use `shell_function_completed'. Block children before forking and unblock after `shell_function_pid' is set properly and `shell_function_completed' is reset to 0. * commands.c (child_handler): When the child of the `shell' function completes, set `shell_function_completed' to 1 if it actually ran, or -1 if it didn't (due to fork or exec failure). * commands.c (block_children, unblock_children): New functions to block and unblock the child termination signal. (wait_for_children): Use block_children and unblock_children. (execute_file_commands): Block children around the critical section wherein a new child is put on the chain. * make.c (main): Change the environment to contain the correct MAKELEVEL before re-execing. Sat Feb 4 18:28:48 1989 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.34. Fri Feb 3 16:36:49 1989 Roland McGrath (mcgrath at helen.Berkeley.EDU) * rule.c (default_variables): Fixed $(LINK.c). Wed Feb 1 18:05:07 1989 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Version 3.33. * version.c: Removed copyright notice, since this is a one-line file. * commands.c (error_status): Made it return BUF, rather than running off the end (this apparently worked on Sun 3s for some reason). * ar.c, commands.c, dep.h, load.c, make.c, make.h, read.c, remake.c, rule.c, variable.c, Makefile: Changed copyrght notices to cover 1989. Mon Jan 30 15:51:28 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.32. Fri Jan 27 20:09:24 1989 Roland McGrath (mcgrath at tully.Berkeley.EDU) * remake.c (remake_file): Don't touch phony targets. * rule.c (convert_to_pattern): Fixed an incorrect length passed to savestring. * variable.c (expand_function: `shell'): Close the read side of the pipe on the parent side of the fork. * commands.c (start_job): On the child of the fork, close the BAD_STDIN fd if we're not using it. * read.c (record_files): A file beginning with a dot can be a default target if it also contains a slash (as in `../foo'). * commands.c (wait_for_children): For BSD, block SIGCHLD rather than ignoring it to avoid a race condition when child_handler is returning. * commands.c (child_handler): Do blocking waits. (error_status): Return a string describing exit status. (Split out of child_handler). * read.c (multi_glob): Change VECTOR to VEC for Alliant. Thu Jan 5 00:06:51 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.31. * make.texinfo (Features): Noted $(foo:PAT=SUB) from SunOS 4.0. * make.texinfo (Options/Recursion): -d and -p go in the environment. * load.c: Include "commands.h". Wed Jan 4 17:49:25 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * make.c (switches): -d and -p can come from the environment and are put into it. * read.c (record_files): Fixed the checking for duplicate deps so it doesn't clobber the first one. * make.texinfo: Documented default implicit rule changes. * rule.c: Revamped default suffix rules. They now use Sun's style of using variables `COMPILE.c', `LINK.c', etc. for each suffix, and use `TARGET_ARCH' and `TARGET_MACH' variable where appropriate. Also support Modula-2 compilation (suffixes .sym, .def, and .mod). Ratfor Yacc support is gone, since nobody has yacc -r. All EFL support is gone, since nobody uses EFL. * ar.c, arscan.c: Don't assume `long int' and `int' are the same. * commands.c [USG]: Fixed wait status bit encoding. [USG and not USGr3] (dup2): Define this for SysVr2. * make.h, dep.h, make.c [iAPX286]: Make allowances for this brain-damaged compiler. * make.texinfo (Variables: Flavors): Fixed a typo. Tue Jan 3 18:09:31 1989 Roland McGrath (mcgrath at homer.Berkeley.EDU) * ar.c (ar_member_date, ar_touch): Truncate member names to 15 chars. * Version 3.30. * commands.c [SYS_WAIT]: If this is defined, use BSD and wait3 even if USG. * read.c (record_files): Defining .DEFAULT with no deps or commands clears its commands. * rule.c (default_suffixes): Added `.sh'. (default_suffix_rules): Added single-suffix .sh rule, copies source to target and makes target executable. make.texinfo (Catalogue of Rules): Documented .sh rule and its use in conjunction with SCCS. * rule.c (set_default_suffixes): Define variable `SUFFIXES' to the default list ("" under -r). make.texinfo (Suffix Rules): Document `SUFFIXES' variable. * rule.c (default_variables), make.texinfo (Implicit Variables): Variable AR defaults to `ar', ARFLAGS to `rv', and RM to `rm -f'. * rule.c (install_default_pattern_rules): Default variables are made recursive. (default_variables): Added "CPP", defined to "$(CC) -E". (default_suffixes): Added `.S', before `.s'. (default_suffix_rules): New rule for .S to .s, runs CPP. All rules that use CPP now include "$(CPPFLAGS)". make.texinfo (Catalogue of Implicit Rules, Implicit Variables): Documented above changes. * commands.c [USG] (sys_siglist): Don't define. [USG] (init_siglist): New function to initialize sys_siglist. * make.texinfo (Variables: Reference): Documented `$(foo:PAT=SUB)' references. * variable.c (variable_expand): A reference `$(foo:PAT=SUB)' is equivalent to `$(patsubst PAT,SUB,$(foo))'. * variable.c (variable_expand): Free the storage for the expansion of a recursive variable when it is nod longer needed. * variable.c (variable_expand): When checking for `$($(foo))', use lindex so as not to search for the second `$' outside the parens. * make.c (struct stringlist, main, decode_switches): Changed `index' member to `idx'. Sat Dec 24 16:02:32 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (wait_for_children [USG]): Handle SIGCLD with SIG_DFL, rather than SIG_IGN. Ignoring SIGCLD reportedly makes wait return -1. * arscan.c [USGr3]: Define PORTAR to 1 (as with sun386). (ar_scan [USGr3]): Remove trailing slashes from member names. Thu Dec 22 17:54:05 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * make.texinfo (Makefiles: Overriding Makefiles): New node documenting use of .DEFAULT to have one makefile defer unmakeable targets to another. * make.texinfo (Implicit: Using Implicit, Implicit: Last Resort): Mention empty commands and xref node `Empty Commands'. Wed Dec 21 20:12:40 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.29. * make.c (struct command_switch, command_switches, et al): New member `noarg_value', if not nil, ptr to value to use if no arg is given to a switch that would otherwise require one. The -j option can now be given w/o an arg, to mean infinite jobs. * commands.c: If job_slots is zero, infinite jobs. * read.c (read_all_makefiles, read_makefile): Make makefiles precious. * make.c (decode_switches): For a positive_int or floating option, if we moved to the next argument word, but found no argument for the option, move back to the correct word. * make.c (decode_switches): If we got any unknown options, die after processing all arguments. * GNUmakefile: Moved `include depend' to the end, so the default goal will be set before then. * load.c (wait_to_start_job [Unix, UMAX]): Merged into one version under #ifdef LDAV_BASED. Only loop while we have jobs running. Sleep for increasing amounts (increase one second per iteration) before checking the load average (after the first check). Get the load average from function load_average. (wait_to_start_job [not LDAV_BASED]): Always return. (load_average [UMAX]): Fetch load average for Encore UMAX. (load_average [not NO_LDAV]): Fetch load average from /dev/kmem. [not NO_LDAV]: Define LDAV_BASED. Tue Dec 20 18:54:50 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.28. * commands.c (wait_for_children): Take second arg, ERROR. If nonzero, and there are children, print a message on stderr. (execute_file_commands, fatal_error_signal): Pass second arg. * make.c (die), remake.c (update_goal_chain), variable.c (expand_function: `shell'): Ditto. Sat Dec 17 01:05:38 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * commands.c (start_job): Call wait_to_start_job before forking. * load.c (load_average): Converted to wait_to_start_job. * remote.c: New file for remote execution functions. (start_remote_job_p): Return nonzero if the next job should be run remotely. (start_remote_job): Start a remote job and return an ID for it. (remote_status): Get status of dead remote children. Fri Dec 16 16:51:07 1988 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * commands.c (start_job): If start_remote_job_p () returns nonzero, call start_remote_job to start the job rather than fork and exec. (child_handler): * commands.c (execute_file_commands): Moved load average checking to start_job. * commands.c (child_handler: USG): Record the pid wait returns. * load.c (UMAX): Added some #include's needed for UMAX. * read.c (multi_glob), variable.c (string_glob): Ignore a (char **) -1 return from glob_filename. * variable.c (variable_expand): Make sure we don't increment past the end of the string we were passed. * variable.c (variable_expand): Terminate the expansion. * file.c (rename_file): If there is already a file under the new name, set its contents equal to FILE's (ick). * variable.c (define_automatic_variables): Pass all the args to define_variable when defining MAKELEVEL! * commands.c (execute_file_commands): If max_load_average > 0, and we have children running, don't start up another child until the load average goes below max_load_average. * make.c: New variable `max_load_average'. (struct command_switch, decode_switches, decode_env_switches): Handle floating-point (double) args. (command_switches): Added `-l' switch to set `max_load_average'. * load.c (load_average): New file and function to return a double that is the current load average (1.00 scale). * GNUmakefile, oldMakefile: Pass flags in $(LOAD_AVG) for load.c. Thu Dec 15 15:22:08 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Makefile: Renamed to oldMakefile. * GNUmakefile: Make Makefile from oldMakefile and depend. * read.c (read_all_makefiles): When putting the default makefiles in the read_makefiles chain so they will be remade, put them in the right order. * remake.c (update_goal_chain): If MAKEFILES is nonzero, always make in serial, and return as soon as one goal whose `changed' member is nonzero is successfully remade. * commands.c: Don't include . * commands.c (construct_command_argv): Added ` to sh_chars. * make.h: Don't declare construct_makeflags. * make.c (main): Set up MAKEFLAGS and MFLAGS and make an environment both before and after reading the makefiles, so the makefiles can use them and possible change them, and later children will get the right information. (construct_makeflags): Replaced with define_makeflags (static void), which defines the two variables. * variable.c (define_automatic_variables): Don't define MAKEFLAGS and MFLAGS. Mon Dec 12 14:40:31 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * Version 3.27. * commands.c (child_handler): Reset the handler to ourselves when called for USG, since it has no safe signals. * commands.c: For USG, use an int rather than a `union wait' for wait calls, and dissect it with bitmasks. (child_handler): No wait3 system call in USG. Since we can't protect from hanging, always return immediately if we have no children we know about and we're not running a `shell' function. (There is still the danger of hanging waiting for a child that died without our being notified.) * remake.c: Include instead of . What we need is really in , and while BSD includes , USG doesn't. * make.c (main): Figure out the program name before doing anything which might need it (in a call to error or fatal). * dir.c, glob.c: Use `struct dirent' and for USGr3. * arscan.c (ar_scan): Added missing & before buf (which is an int) if SARMAG is not defined (SysV). Fri Dec 9 18:44:13 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Version 3.26. * dir.c (find_directory, dir_file_exists_p): Keep track of how many directories we have open and don't let it be more than MAX_OPEN_DIRECTORIES (currently 10). * variable.c (expand_function: `foreach'): Use expand_argument rather than variable_expand so each repetition doesn't clobber the last!!! Mon Dec 5 15:58:46 1988 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * Version 3.25. * Makefile: Define `install' target. * GNUmakefile: Don't include GNUmakefile or depend in the distribution file. Wed Nov 30 15:53:42 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * commands.c (execute_file_commands): Don't clobber a null into random storage if there were no $^ and/or $? words. * remake.c (check_dep): Set *MUST_MAKE_PTR nonzero if a dependency doesn't exist. * ar.c (ar_member_date, ar_touch): Make sure the modtime of the archive file itself is known before we fetch or change the modtime of one of its members. * read.c (read_makefile): Expand variable and function references before parsing rules so variable can contain special characters (colons and semicolons). Sat Nov 26 11:36:31 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * variable.c (expand_function: `filter', `filter-out'): Fixed so that filter-out works right. * variable.c (expand_function: `filter', `filter-out'): Made these functions use each word of their first argument as a pattern. Fri Nov 25 10:51:47 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.24. * read.c (record_files): If a target is listed more than once in a single rule (that defines commands), give a warning message rather than the counter-intuitive message saying commands were already defined (in the same place). * make.c (fatal, error): Made them both take 6 args since there is at least one error message that need that many. Too bad vfprintf is not universal! * Version 3.23. * read.c (read_makefile): Moved the construction of the `struct commands' into record_files. Call record_files before recursing for an included makefile so the higher-up will determine the default goal. (record_files): Take arguments COMMANDS, COMMANDS_IDX and COMMANDS_STARTED and construct a `struct commands. Thu Nov 24 14:36:33 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.22. * make.c (main): Made it a fatal error if we can't move back to the directory we started in before re-execing. * make.c (main): Get the current directory before doing anything else, so we know it even if we don't need it for the value of `MAKE', since we might want it when re-execing. Wed Nov 23 13:34:44 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.21. * read.c (record_files): Eliminate duplicate deps in a chain. * variable.c (expand_function: `sort'): Pass the right number to qsort, not one less. * remake.c (remake_file): Always call notice_finished_file if FILE->command_state == cs_finished. * commands.c (execute_file_commands): Call notice_finished_file to set FILE's status correctly when start_job fails (because it's out of commands or running under -n). Fri Nov 18 15:31:12 1988 Roland McGrath (mcgrath at saffron.Berkeley.EDU) * Version 3.20. * remake.c (update_file_1): Set the `update_status' of FILE to nonzero and set FILE's `updated' bit if we have decided to give up on remaking FILE because of errors in the dependencies. * rule.c (pattern_search): Debugging messages use `dependency' (vs. `dependent') properly. * make.texinfo (Conditionals: Conditional Syntax): Function index entries for `ifndef' and `ifneq'. * variable.c (define_automatic_variables): Define `MAKELEVEL' to the decimal number of the makelevel, since it may be malformed or blank. * remake.c (remake_file): Call notice_finished_file after touching. Sat Nov 12 19:29:34 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.19. * GNUmakefile (dist): Pass the `-f' flag to compress. * vpath.c (build_vpath_lists): Check for VPATHS being nil after constructing the general VPATH list from the `VPATH' variable. Fri Nov 11 08:02:26 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (fatal, error): Made error messages for recursive runs be shorter. Thu Nov 10 16:51:36 1988 Roland McGrath (mcgrath at basil.Berkeley.EDU) * Version 3.18. * read.c (read_makefile): Made it eat leading spaces and formfeeds (but not tabs), like it's documented to. * read.c (read_makefile): Let included makefiles determine the default goal, as is done by System V Make. Tue Nov 1 19:03:08 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * variable.c (new_environ): Don't increment VCNT when a variable is rejected. Fri Oct 28 16:54:15 1988 Roland McGrath (mcgrath at basil.Berkeley.EDU) * Version 3.17. * rule.c (convert_to_pattern): Don't use the same storage for a name in two rules since new_pattern_rule may free this storage when a rule is discarded. * rule.c (new_pattern_rule): Undid useless change I made Oct 25. Thu Oct 27 19:17:53 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.16. * GNUmakefile, Makefile: Fixed a typo in a comment. * Makefile: Removed malloc.o from object file list. * variable.c: Removed old debugging #define's for xmalloc and xrealloc so non-ANSI cpp's won't barf. * make.c (main): Made local array for temp file name static so compilers that don't do auto aggregate initialization won't barf. * read.c: Removed static declaration of copy_dep_chain since it is no longer static. Tue Oct 25 16:59:30 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * rule.c (new_pattern_rule): If we threw out the new rule because it matched an old one and OVERRIDE was zero, don't put the freed pointer in the chain! Wed Oct 19 15:07:43 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Version 3.15. * variable.c (expand_function: `sort'): Don't do the sorting and writing out if there were no words in the first place. * remake.c (remake_file): Only fail with a "no way to make" message for a dependency (non-target) file. If we don't know how to remake a target file, pretend it was successfully remade and is very new. * remake.c (remake_file): Don't increment `files_remade' for a non-target file we don't know how to remake. * read.c (record_files): Don't die with "both : and :: entries" for a file whose `is_target' flag is not set. Tue Oct 18 17:24:11 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * variable.c (expand_function: `patsubst', `subst'): Free the right things! * variable.c (expand_function: `subst'): Don't clobber the pointer to the end of the second arg and then try to use it!!! Mon Oct 17 16:44:45 1988 Roland McGrath (mcgrath at catnip.Berkeley.EDU) * variable.c (expand_function: `patsubst'): Don't clobber the pointer to the end of the second arg and then try to use it!!! * variable.c (expand_function: `word' function): Made it parse its second argument correctly. * ar.c (ar_touch): Return 1 rather than -1 for on errors. Sat Oct 15 15:12:16 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.14. * GNUmakefile: Removed explicit rule for make.dvi since the built-in implicit rule now works. * rule.c (default_suffix_rules): Fixed .texinfo.dvi rule yet again so that it really works, now that parens are counted. * remake.c (update_file_1): Set FILE's `updated' flag after calling remake_file if it failed or finished immediately. * remake.c (update_file): Use the `updated' flag rather than the command state to decide if a file was fully considered, and therefore might give an "up to date" message. * variable.c (expand_function): Made all functions that take more than one argument count parens of the appropriate flavor in their args and ignore commands nested in parens. Fri Oct 14 18:35:00 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * read.c (read_all_makefiles): Pass second arg to read_makefile for default makefiles. Thu Oct 13 16:40:08 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.13. * GNUmakefile: Added an explicit rule for make.dvi since the built-in .texinfo.dvi implicit rule is screwed up. * rule.c (default_suffix_rules): Added a comment that the .texinfo.dvi rule does not work because of an ahem, feature of Make that at some point will be fixed--er, enhanced to alleviate this difficulty. * rule.c (default_suffix_rules): Fixed Texinfo -> DVI rule (again). * make.texinfo (Commands: Execution): Documented new competing for standard input among children. * commands.c (struct child): Added `good_stdin' flag to tell if this child has the stdin that doesn't point into nirvana. (good_stdin_used): New variable to tell if any child has the good standard input. (child_handler): Reset `good_stdin_used' if a dead child's `good_stdin' flag is set. (start_job): Give the new child the good standard input if `good_stdin_used' is no set, and set the child's `good_stdin' flag appropriately. * rule.c (default_suffix_rules): Changed Texinfo -> DVI rule to work better (I hope). * read.c (read_all_makefiles): Stop reading default makefiles after one is found. * read.c (read_makefile): Reset `reading_filename' and `reading_lineno_ptr' after recursing for an included makefile. * GNUmakefile: New GNU Make-specific makefile that does everything Makefile does plus distribution stuff, and doesn't contain any hacks to try to work with Unix make. * Makefile: Removed distribution stuff. * make.c (main): Use mktemp to construct the names of temporary files used for standard input makefiles. * make.c (main): Don't turn standard input into a broken pipe. * commands.c (start_job): Keep two extra file descriptors around: a good standard input, and a bad one that reads from a broken pipe. On the child side of the fork, if there are other children, give this one the broken pipe so they won't compete; if this is the only one, give it the good standard input. * make.h: Declare notice_finished_file. * commands.c (execute_file_commands): Use noticed_finished_file after waiting for the child when there is only one job slot. * remake.c (notice_finished_file): New function to re-check mtime's and such things to be done when commands finish. (update_file_1): Use notice_finished_file. * commands.c (child_handler, execute_file_commands): Use new variable `job_slots_used' to record the number of jobs currently running, rather than diddling with `job_slots'. (execute_file_commands): Increment `job_slots_used' before calling start_job and decrement it on failure to avoid race condition. If there is only one job slot, wait for the child to finish and return its status so commands are run in linear order, as if there were no parallelism. Wed Oct 12 15:59:03 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * remake.c (remake_file): Don't print a "No way to make" message for targets whose `dontcare' flags are set. * read.c (read_all_makefiles): Set the `dontcare' flag of the `struct file' each default makefile added to the chain. * file.h (struct file): Add `dontcare' member. * read.c (read_all_makefiles): When no default makefiles are found, put the names of all those tried in the `read_makefiles' chain so they will be updated if possible, giving their `struct dep's' `changed' members the value of 0 so we won't care if they cannot be found or remade. * make.texinfo (Makefiles: Remaking Makefiles): Documented that default makefiles will be remade if not found. * read.c (read_all_makefiles): If no default makefiles can be found, go through the list of default names, trying to make one, stopping if one is made. * remake.c (remake_file): Set STATUS to 0 after successfully touching. * dir.c (file_impossible, file_impossible_p): Don't clobber FILENAME to "" and then try to to a strcmp on it!!! Mon Oct 10 16:09:18 1988 Roland McGrath (mcgrath at cinnamon.Berkeley.EDU) * make.c (main): Don't do `dir_load (".")'. * rule.c (count_implicit_rule_limits), vpath.c (construct_vpath_list): Test the existence of a given directory by `dir_file_exists_p (DIR, ".")' and assume that if this returns zero, it means the directory really does not exist. * dir.c (struct dirdata): Replaced with `struct directory' for directories, each containing a chain of `struct dirfiles', one for each file (real or impossible). (dir_load): Removed. (find_directory): New function to find the `struct directory' for a named directory and return it (possibly creating a new one). (dir_file_exists_p): Read the directory on the fly if its stream is still valid (and ever was) if the file we're looking for is not already in the hash tables. (file_impossible, file_impossible_p, dir_name, print_dir_data_base): Use the new directory/file scheme. * make.texinfo: Miscellaneous editorial changes and clarifiactions. * commands.c (struct child): Remove `environ' member. (child_handler, start_job, execute_file_commands): Remove use of `environ' member and new_environ. * make.c (main): Call new_environ after reading makefiles. * variable.h: Declare `new_environ' to return void. * variable.c (new_environ): Put the environment in `environ' and return void. Fri Oct 7 15:48:39 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Version 3.12. * Makefile: Don't make the uncompressed tar file. * variable.c (expand_function: `shell' function): Made it not expect read to null-terminate the buffer. * Makefile: Made it use a temporary symlink to . rather than a temporary directory to make the distribution tar file. Thu Oct 6 17:52:35 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.11. * make.texinfo: Fixed a line that got garbaged somehow. Mon Oct 3 16:14:39 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * make.c (main): Try to move back to the directory we started in before re-exec ourself. * remake.c (update_file_1): A double-colon target with no deps always needs to be remade. * remake.c (remake_file): Changed "No way to make" message to say `target' rather than `file'. Sun Oct 2 12:50:47 1988 Roland McGrath (mcgrath at catnip.Berkeley.EDU) * remake.c (update_file_1): Set FILE->update_status to the return value of remake_file. * rule.c (convert_to_pattern): Fixed swapped lengths passed to xmalloc for source/target suffixes. * make.texinfo: Documented that MAKEFLAGS and MFLAGS are read in from makefiles. Updated the `Features' section a bit. * make.c (main): Read switches from MAKEFLAGS and MFLAGS variables after reading in makefiles. * make.c (main): Put a line "/tmp/foo:;" rather than ".PHONY: /tmp/foo" in front of temp files made for stdin makefiles. * remake.c (update_file): Test the state of the right `struct file' for double-colon files. * make.c (main): Put a ".PHONY: /tmp/foo" line in front of temp files made for stdin makefiles so they won't be remade when we re-exec. Kludge-o-matic!! * remake.c (update_goal_chain): Judge files as being finished based on their `updated' flag, not their state. * read.c (read_makefile): Don't check for FILENAME being "-". (read_all_makefiles): Set each element of MAKEFILES to the name put in READ_MAKEFILES by read_makefile, since read_makefile may free the storage for the name it is passed, and someone might want to look at the elements of MAKEFILES again. * make.c (main): For each `-f' flag with arg `-' (standard input), read standard input into a temp file and pass the temp file's name to read_all_makefiles, after making sure it will not be remade. * make.c (construct_makeflags): Always put out `-j1'. Sat Oct 1 00:19:59 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * commands.c (execute_file_commands): If commands are nothing but whitespace, set the state to `cs_finished' before returning 0. * make.c (decode_switches): Allocate space for args in stringlists so they can be freed later. * make.h: Declare `makelevel'. * variable.c (makelevel): Moved to make.c (and made global). * make.c (fatal, error): Print the makelevel if it's > 0. (perror_with_name): Use error rather than calling fprintf directly. (pfatal_with_name): Use fatal rather than fprintf and die. * variable.c (new_environ): Don't put default variables (origin `o_default') into the environment; they just take up space. * read.c (read_makefile): Don't add FILENAME to the chain of read makefiles if it's "-" (standard input). * remake.c (update_goal_chain): Set STATUS correctly when nothing happens (as well as in all other situations). * make.c (construct_makeflags): Put a `-' before each switch and spaces between them. * Version 3.10. * commands.c (wait_for_children): Don't check if `children' is nil. This is the case when waiting for the child of a `shell' function. * dir.c (dir_load): Don't add a hash-table entry for directory DIRNAME and filename "" if DIRNAME doesn't exist. * commands.c (execute_file_commands): Return 0 after start_job returns 1 (failure) under the -n flag. * remake.c (remake_file): Set the state to `cs_finished' when not calling execute_file_commands. * remake.c (update_goal_chain): Second arg is now MAKEFILES, nonzero meaning to disable -t, -q, and -n for each target unless the target was also given on the command-line. * read.c (read_makefile): Enter the `struct file's for the makefiles added to the `read_makefiles' `struct dep' chain. * remake.c (update_goal_chain): Made it not enter the files for the goals in the chain. It will already have been done. * rule.c (convert_to_pattern): Null-terminate the names of targets and deps of the pattern rules properly. Fri Sep 30 18:56:20 1988 Roland McGrath (mcgrath at nutmeg.Berkeley.EDU) * make.c (main): Call install_default_pattern_rules. * make.h: Declare copy_dep_chain. * read.c (copy_dep_chain): Moved to make.c (and made global). * make.c (main): Call update_goal_chain to update goals. Update read makefiles and re-exec self if they change. * remake.c (update_file): Make this function static. (update_goal_chain): New function to update a `struct dep' chain of goals, waiting until they are all finished before returning. * make.h: Don't declare update_file. Declare update_goal_chain. * make.c (main): Call snap_deps, etc. that were in read_all_makefiles. * read.c (find_makefile): Removed this function. (read_all_makefiles): Don't update makefiles, don't diddle with pattern rules, don't call snap_deps, etc. Return a `struct dep' chain of all makefiles read. (read_makefile): Now takes two args: FILENAME and TYPE, which is 0 for a normal makefile, 1 for MAKEFILES variable or 2 for an included makefile. Add a `struct dep' containing the name of the makefile (as it was found in the search path for type 2s), and TYPE in the `changed' member to the global `read_makefiles' chain. * make.h, rule.c (displace_pattern_rules, add_displaced_pattern_rules): Removed these functions. * read.c (read_makefile): Variable-expand the name of an `include'd makefile before calling find_makefile on it. * file.c (snap_deps): If the `struct file' for a `struct dep' already exists, free the `struct dep's `name' member before setting it to nil (since this info is in the `struct file'). * read.c (copy_dep_chain): Made it copy each name rather than leaving multiple `struct dep's with the same pointers. Thu Sep 29 19:08:13 1988 Roland McGrath (mcgrath at catnip.Berkeley.EDU) * make.c (decode_switches): Fixed second decode_env_switches call to use correct length of "MFLAGS" (6, not 5). * read.c (read_makefile): Don't stop reading when readline returns zero lines read. Only stop when the stream reaches EOF. This makes it recognize the last line of a makefile without a newline. * remake.c (remake_file): If we don't know how to make FILE, set its command state to `cs_finished'. * remake.c (update_file): Don't write the "up to date" message if update_file_1 returned a nonzero status. Wed Sep 28 16:30:07 1988 Roland McGrath (mcgrath at catnip.Berkeley.EDU) * commands.c (child_handler): Set the `update_status' member properly for ignored errors. * rule.c (convert_to_pattern): Made it not care about if the target suffix comes before the source suffix in the .SUFFIXES list. * make.texinfo: Misc editorial changes. * commands.c (wait_for_children): Return immediately if `children' is nil (there are no children). Tue Sep 27 15:33:14 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Version 3.09. * commands.c (struct child): New member `command_ptr' to hold the current position in the commands. The `commands' member is never changed. (start_job, child_handler, execute_file_commands): Use new method for `commands' and `command_ptr' members. * make.c (decode_env_switches): Skip past an invalid letter (instead of looping forever). * commands.c (struct child): Add `environ' member to hold the environment for this child. (execute_file_commands): Get a new environment from new_environ and put in the the new `struct child's `environ' member. (child_handler): When freeing a child, free its `commands' member, the elements of its `environ' array and its `environ' member itself. (start_job): Set `environ' to the child's `environ' member before exec'ing the command. * variable.h, variable.c (new_environ): Made it return the new environment, not putting it in `environ'. * remake.c (update_file): Don't give a "is up to date" message unless no files were remade and the state went from `cs_not_started' to `cs_finished', so repeat calls to finish jobs won't get the message. Mon Sep 26 16:26:08 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * Version 3.08. * make.texinfo (Commands: Execution): Documented that children will be waited for rather than killed. * commands.c (fatal_error_signal): Wait for children. (kill_children): Removed this function. * make.c (main, die): Wait for children to die, don't kill them. * variable.c (expand_function): Use wait_for_children. * make.c (main): Use wait_for_children rather than child_handler. * commands.c (wait_for_children): New function to block waiting for children, insuring that child_handler is not called recursively. (execute_file_commands, kill_children): Use wait_for_children. * commands.c (child_handler): Start up additional commands in a sequence after an ignored error. * remake.c (update_file): Don't print "`foo' is up to date" messages when update_file_1 returns while commands are executing. * remake.c (update_file_1): Pass the file name to name_mtime, not the bloody `struct file', dammit!! * commands.c (child_handler): Print out the "*** ..." error message when not under -i. (I somehow forgot this.) * remake.c (update_file_1): Use name_mtime rather than file_mtime to re-get the mtime of a file whose commands have finished. * make.c (command_switches, decode_switches, decode_env_switches): Make all switches that take string args allow them right after the switch letter. * commands.c (child_handler): Check for a child being the `shell' function's command returning and set the global variable for expand_function to check. * variable.c (expand_function): For the `shell' function, instead of waiting for the child shell ourselves, let child_handler do it and loop around waiting for something to happen. * make.c (print_version): Made the copyright year static, not dynamic. * make.h, make.c: Remove construct_argv function. * make.c (main): Say "no goal target" instead of "no target". * make.texinfo (Commands: Parallel): Don't send SIGKILL. * commands.c (kill_children): Don't send SIGKILL to children that aren't killed by the first signal. * make.c (main), commands.c (kill_children): Decide between SIGCHLD and SIGCLD based on whether or not SIGCHLD is defined, not on USG. * Makefile: Link make with $(LOADLIBES). * read.c (construct_include_path): Fixed another bad xrealloc call. * make.c (decode_switches): Fixed an xrealloc call with no first arg. Sat Sep 24 01:16:21 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * Version 3.07. * remake.c (update_file_1): If deps are running, set state to `cs_deps_running' and return 0. If deps are done, run commands. * commands.c (child_handler): Made it delete non-precious targets killed by fatal signals. * make.texinfo: Documented parallelism. Fri Sep 23 16:52:27 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * remake.c (update_file_1): Don't return if FILE's state is `cs_deps_running'. In that case, we need to run through and check the states of all our dependencies. * commands.c (execute_file_commands): Decrement `job_slots' after starting a new job to run file commands. * commands.c (start_job): Made it set the state to `cs_running'. * make.c (main): Fixed usage of `g', `lastgoal', and `goals' in the goal-making loop. * commands.c (child_handler): When commands finish, set the corresponding file's `update_status' and `updated' flags as appropriate, and reset the modtimes of the file and any `also_make' files it has. * remake.c (remake_file): Don't re-set `last_mtime' and set `updated'. * commands.c (fatal_error_signal): Don't swallow all the children with a loop around `wait ((union wait *) 0)'!!! * make.c (struct command_switch): Added `positive_int' type. (switches): Added -j (job_slots). (construct_makeflags, decode_switches, decode_env_switches): Handle`positive_int'-type switches. * glob.c (glob_vector): Rename local variable `vector' to `VeCtOr'. This is said to avoid a conflict with some system's global `vector' variable. * variable.c (expand_function): Made the `shell' function use construct_command_argv and do its own child control and piping. * make.c (main): Turn standard input into a broken pipe after reading in all makefiles (the last time it will be needed). * commands.c (struct child): Remove `pipe_fd' member. We don't use pipes any more. (start_job): Return 0 for success, 1 or failure (rather than void). Don't use pipes. Don't turn the child's stdin into a broken pipe. (child_handler): Print "*** Error" messages when necessary. Die on failed commands when -k was not given. (execute_file_commands): Check the return of start_job and remove the child from the chain and return failure if it is nonzero. * make.c (die): New function to clean up and exit. (fatal, pfatal_with_name): Use die. Thu Sep 22 14:27:11 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * commands.c (struct child): Added `commands', `pipe_fd', and `noerror' members to keep track of info about a command thread. (start_job): New function to start a job and update the argument `struct child' to reflect its status. (execute_file_commands): Merged run_file_commands back in. Made it use new start_job function. * rule.c (freerule): Don't free the `struct commands' of the discarded rule. It may be used in more than one place. * commands.c (execute_command_line): Made it not try to delete the possibly partly-made file. The child_handler function will do this. (fatal_error_signal): Ditto + call kill_children. * make.h: Declare job_slots. * make.c (main): Collect goals in a dep chain and run through this chain waiting for a child, eliminating finished goals, updating all remaining goals, and quitting if they fail and not -k. * commands.c (child_handler): If called with SIG < 0, - SIG is the max number of children to bury. * commands.c (child_handler): If called with SIG as zero, block waiting for running children. (kill_children): Call child_handler with zero rather than SIGCHLD. * remake.c (update_file_1): Use the `command_state' member of FILE and its dependencies to determine what commands are running, what to do, etc. If commands or dep commands are running when we are called, return success (0). If commands finished since the last time we were called, return their status. * commands.h: Declare kill_children. * commands.c: Define `struct child' to keep track of child processes, with the chain in `children'. (child_handler): New function to catch child-termination signals (SIGCHLD, or SIGCLD for USG), store the returned status in the appropriate structure, take the now-obsolete `struct child' out of the chain, and free its storage. (execute_file_commands): Put all of the stuff invloving running the commands into new function run_file_commands. Execute_file_commands now does process management for the commands, while run_file_commands (which is run in a subprocess) runs the commands. (kill_children): New function to kill all running children by sending them signal SIG. If there are any children still living after they are all sent SIG, they are all sent SIGKILL. * make.c (main): Catch SIGCHLD (SIGCLD for USG) with child_handler. * commands.h: Declare child_handler function. * commands.c (execute_file_commands): Check the `command_state' member of FILE and return 0 if it is `cs_running' or `cs_deps_running' and return the stored status if it is `cs_finished'. * file.h (struct file): Added `command_state' member. * commands.c (execute_command_line): Add `$' to the list of characters special to the shell. Wed Sep 21 15:57:41 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * read.c (read_all_makefiles): Call convert_to_pattern before recomputing the limits after adding the displaced rules. * make.c (main): Move calls to snap_deps, convert_to_pattern, and build_vpath_lists to read_all_makefiles. * read.c (read_all_makefiles): Install the default pattern rules before checking to remake the makefiles, displace these rules before reading in the makefiles, and then add the displaced rules to the chain after reading in all the makefiles. * make.c (main): Don't call install_default_pattern_rules or count_implicit_rule_limits. * make.h: Declare displace_pattern_rules and add_displaced_pattern_rules. * rule.c (displace_pattern_rules, add_displaced_pattern_rules): New functions to stow the chain and add the stowed chain on the end of the current chain. * make.texinfo (Implicit: Search Algorithm): Fixed PREV reference. * make.c (main): Call construct_include_path right after decoding the switches. * read.c (find_makefile): Use rename_file. * file.h: Declare rename_file. * file.c (rename_file): New function to rename a `struct file' and put it in the correct hash bucket. * read.c (find_makefile): New function to find and update a makefile. (read_all_makefilese): Use find_makefile. (read_makefile): Don't do updating. Removed UPDATEIT arg. * remake.c (update_file_1): Took out setting the `updated' member to -1 rather than 1 sometimes. * make.c (main): Made it print version info before doing anything else. * remake.c (library_file_mtime, f_mtime): Removed use of last two arguments to vpath_search. * rule.c (pattern_search): Removed use of last two arguments to vpath_search. * vpath.c (vpath_search, selective_vpath_search): Removed unused DIRPREFIX and DPLEN args. * read.c (read_makefile): Also turn off -n when updating makefiles. Tue Sep 20 17:01:10 1988 Roland McGrath (mcgrath at pepper.Berkeley.EDU) * Makefile: Put tags files in the tarfile. * read.c (read_makefile): Get the modtime of the makefile via a stat call so that a later file_mtime call won't do VPATH search for it. * read.c (read_makefile): Don't turn off -t and -q if the makefile was a command-line target. * make.c (main): Enter command-line targets as files and set their `cmd_target' members. * file.h (struct file): Added `cmd_target' member. * read.c (read_makefile): Temporarily turn off -t and -q while updating makefiles. * make.c (main): Don't use arg 0 from other_args (which is now argv[0]; i.e., the program's name). * read.c (read_makefile): Only return nonzero if commands were actually run to remake the makefile. * remake.c (update_file_1): Set FILE->updated to -1 if no commands were actually run (because no update was done or -t was given). * make.c (decode_switches): Fixed bug wherein xrealloc was passed bad args if it tried to expand other_args->list. * read.c (read_all_makefiles): Made it not look at the `MAKE' variable, just use argv[0]. Sun Sep 18 17:34:11 1988 Roland McGrath (mcgrath at paris.Berkeley.EDU) * read.c (rerun_make): New function to re-exec make. * make.c (construct_makeflags, construct_argv): New functions to construct the `MAKEFLAGS' variable and to construct an arg list from parsed info. * read.c (read_makefile): New arg UPDATEIT, if nonzero, says to update the makefile as a target before reading it in. When reading included makefiles, pass this as zero. Now returns nonzero if the makefile was updated, zero if not. (read_all_makefiles): Pass a nonzero UPDATEIT arg to read_makefile for all default and -f makefiles and all makefiles from the `MAKEFILES' variable. If any of the makefiles has changed, re-exec self to re-read them. * remake.c (update_file): Print a "File `foo' up to date'" message under -p. * commands.c (execute_file_commands): Allocate one byte for each of $^ and $< rather than zero if they are to be empty. Fri Sep 16 13:59:59 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Version 3.06. * make.c (command_switches): Fixed entry for `-o' switch. * make.texinfo: Renamed -c switch to -C. * make.c: Renamed -c switch to -C. * Miscellaneous de-linting. * read.c (record_files): Made it not free the storage for the name if it started with `./' and was therefore not quite the same as in the `struct file'. * read.c (record_files): If commands were specified twice, the error message specifies in what files and at what line numbers. * make.c (main): If any of the signals we usually fatal on were ignored by the parent (probably a shell), ignore them. * make.c (main): Print version info for -v, -p, or -d. (print_data_base): Don't print version info. It will be done in main. * variable.c: Increased number of hash buckets to 257. * file.c: Increased number of hash buckets to 1007. * rule.c (count_implicit_rule_limits): Moved comptation of `maxsuffix' to convert_to_pattern, since that function uses `maxsuffix', and must be called before count_implicit_rule_limits. * rule.c (pattern_search): If an existent (non-intermediate) dependency was found via a terminal rule, set its `tried_implicit' flag, so it will never have implicit rule search done. * glob.c: Bug fix to avoid alloca(0). * arscan.c: USG and Sun386i fixes. Thu Sep 15 19:40:26 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * make.texinfo: Fixed some typos and spelling errors. Wed Sep 7 14:20:39 1988 Roland McGrath (mcgrath at helen.Berkeley.EDU) * make.c (decode_switches): Fixed bug wherein a bad option would give a useless error message and loop forever. Tue Sep 6 14:36:02 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.texinfo: Documented `shell' function. * variable.c (expand_function): New function `shell', does backquote-style command expansion of its arg. * commands.c (execute_command_line): Second arg OUTBUF, if not nil, gets filled in with a malloc'd buffer containing the piped stdout of the command. (execute_file_commands): Use above (pass nil). Mon Sep 5 17:03:49 1988 Roland McGrath (mcgrath at hecuba.Berkeley.EDU) * Makefile: Added copyright notice. Added a comment about defining `NO_MINUS_C_MINUS_O' if necessary. * Version 3.05. * rule.c (default_suffix_rules): Don't pass `-o' switches with `-c' switches if `NO_MINUS_C_MINUS_O' is #define'd. * make.texinfo: Documented `GNUmakefile'. * read.c (read_all_makefiles): Made it try default makefile `GNUmakefile' before others. * make.texinfo: Added new-style Texinfo header thingies. Sat Sep 3 18:09:39 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * Version 3.04. * make.texinfo (Chained Rules): Added a @cindex about using .PRECIOUS to preserve intermediate files. * remake.c (update_file_1): Made it not just return before executing commands under -p. * rule.c (default_pattern_rules, default_variables): Made it use `$(AR)' for `ar r' (to put files in archives). * vpath.c (build_vpath_lists): Made it recursively expand the `VPATH' variable (by using variable_expand instead of lookup_variable). * read.c (conditional_line): Made it not swallow whitespace after the comma in an `ifeq' using the `(a,b)' syntax. * rule.c (count_implicit_rule_limits): Made it not crash if a pattern rule dep begins with `/'. Sun Aug 28 15:51:12 1988 Roland McGrath (mcgrath at homer.Berkeley.EDU) * make.texinfo: Clarified that the arg to the `origin' function is a variable *name*, not a reference. * make.texinfo: Clarified that both -Idir and -I dir are allowed. Sat Aug 27 13:49:28 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * remake.c (remake_file): Made touching phonies work right. Wed Aug 24 20:40:48 1988 Roland McGrath (mcgrath at nutmeg.Berkeley.EDU) * make.texinfo: Removed reference to `RANLIB' variable. * Version 3.03. * variables.c (expand_function): Added `origin' function. * make.texinfo: Documented same. * read.c (record_files): Made double-colon entries work. Sat Aug 20 21:09:39 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (collapse_continuations): Bug fix from RMS. * rule.c (install_default_pattern_rules): Made it set the `in_use' flag of the created rules to zero, rather than letting it be random garbage. * rule.c (pattern_search): Fixed putting `also make' targets into file strucutres. * read.c (record_files): Fixed bug which made double-colon entries make it read off into space. * make.c (decode_switches): Made it understand `ignored' switches rather than dumping core. Sun Aug 14 16:49:00 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * read.c (read_makefile): Made `include' filenames be variable-expanded. * read.c (read_makefile): Fixed an error message. * read.c (read_makefile): Made it accept ^L's as whitespace. * make.c (next_token, end_of_token): Ditto. * vpath.c (vpath_search): Fixed it so that the general VPATH (from the variable) is always checked, even if a selective VPATH (from a directive) matched the filename. Sat Aug 13 14:20:46 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (decode_switches, main): Made the command switches be processed from a table of switches, variables, and types. No functions are passed argc and argv any more. They are passed arrays of strings they need to process. * read.c (read_all_makefiles): Made it take an array rather than argc and argv. (construct_include_path): Ditto. * make.c (collapse_continuations): Made it work right (I hope). * make.texinfo: Minor editorial changes. * read.c (read_makefile): Minor speed improvement by freeing and then mallocing something rather than reallocing it to avoid the unnecessary bcopy. Thu Aug 11 00:10:43 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.texinfo: Fixed some unquoted @'s. * make.texinfo: Documented multiple-target pattern rules. Miscellaneous minor editorial changes and corrections. * make.texinfo (Implicit: Catalogue of Rules): Removed the list of variables. That's what the next section is for. (Implicit: Implicit Variables): Made it agree with reality. Wed Aug 10 00:55:39 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * variable.c (print_variable_data_base): Fixed bug which made -p dump core. (This was a really idiotic bug.) * rule.c (pattern_search): Fixed a bug which made it make the `also_make' member of the file in question nil if the first of the successful rule's targets was the matching one. Made it use only as much storage as necessary in the `also_make' member. (create_pattern): Made it use only as much storage as necessary in the `lens' and `suffixes' members of the created rule. * remake.c (library_file_mtime): Made it `static'. * file.c: Added a declaration for `errno', which is declared in some 's, but not all. * file.h (struct file): Added `also_make' member for multiple-target implicit rules. * rule.c (pattern_search): Made it put the names of files updated by the given file's commands in its `also_make' member. * remake.c (update_file_1): Made it mark the files in a file's `also_make' member as updated when the file is updated. * variable.c (try_variable_definition): Fixed a bug which made it define a variable with the name of the whole definition when there was no space before the = or :=. * make.texinfo (Features): Made the changes which were made in RCS revision 2.7 but somehow lost since then. Added -W. Tue Aug 9 10:04:50 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * variable.h: Added `o_default' to `enum variable_origin'. * variable.c (print_variable_data_base): Made it print the origins of the variables. * rule.c (install_default_pattern_rules): Made it define the default variables with origin `o_default'. * make.texinfo: Documented -W. * make.c (decode_switches, main): Added the -W flag to give files a time-stamp of now, for a `what if' effect when used with -n. * commands.c (print_commands): Made it say `(built-in)' for commands that are built into the default ruleset. * read.c (record_file): Made .SUFFIXES get its deps frontwards (again). * rule.c (set_default_suffixes, convert_to_pattern): Made it read .SUFFIXES's deps frontwards, so the converted rules will not be in reverse order. * rule.c (new_pattern_rule): Fixed a bug wherein it would keep searching after it had removed a matching rule and ended up diddling with freed storage. * rule.c (freerule): Made it take the given rule off the chain. (new_pattern_rule, count_implicit_rule_limits): Use freerule to remove rules from the chain. * vpath.c (construct_vpath_list): Made it return after cleaning out all previous searchpaths when given a nil DIRPATH arg, so it won't go into the construction code and dump core dereferencing a nil pointer. * variable.c (patsubst_expand): Fixed a bug which made it not match correctly and sometimes dump core. Mon Aug 8 16:35:48 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * rule.c (default_suffix_rules): Made the .texinfo.dvi rule remove the files used in the comparison to determine whether or not a second TeX run is necessary. * make.texinfo: Fixed some overfull TeX hboxes. * make.texinfo (Implicit: Catalogue of Rules): Fixed a Texinfo error. * rule.c (create_pattern_rule): Fixed bug wherein index was not being passed its second arg. * read.c (getline): Merged back into readline. * rule.c (default_suffixes, default_suffix_rules, default_variables): Added .texinfo.info rule. * make.texinfo (Implicit: Catalogue of Rules): Documented .texinfo.dvi and .texinfo.info rules. * make.texinfo (Top): Changed `last updated' date to be correct (for the last time it was updated, not today). Changed `for version 3.00' since it's not going to be called that. Sat Aug 6 19:51:10 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * commands.c (print_commands): Added this function to print the contents of a `struct commands' for -p. * rule.c (print_rule_data_base): Use above. * file.c (print_file_data_base): Ditto. * rule.c (count_implicit_rule_limits, new_pattern_rule, install_pattern_rule, print_rule_data_base): Made it understand the changed `struct rule' and act accordingly. (freerule): Added this function to free all the storage used by a rule. * rule.c (pattern_search): Made it grok multiple targets of pattern rules. The matching is done properly, but at present, only the matching pattern's target is used to give deps and commands. Fri Aug 5 18:00:29 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * rule.c (struct rule): Changed name, namelen, and patsuffix members to targets, lens, and suffixes, which are arrays, for multiple targets. (create_pattern_rule): Now takes first arg TARGETS, a nil-terminated array of targets, rather than a single target and patsuffix pointer. * read.c (record_files): If it finds an implicit pattern rule, it collects all the targets into an array and passes the whole thing to create_pattern_rule. If there are non-pattern targets, it is a fatal error. Tue Aug 2 15:06:38 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (readline): Split backslash-newline checking from reading and buffer-expanding. (getline): Created to do the reading and buffer-expanding formerly done in readline. * rule.c (pattern_search): Made it reject nonterminal match-anything rules when a specific rule has matched, rather than rejecting terminal match-anything rules in this case. * rule.c (convert_to_pattern): Fixed a bug caused when the change to make it only recognize two-suffix rules whose target suffixes precede their dependency suffixes which made it work in the opposite direction (even worse than it started out). * rule.c (pattern_search): Made it reject nonterminal match-anything rules as intermediate targets when searching for both real and intermediate dependencies, rather than only when searching for intermediate ones. Sun Jul 31 00:33:56 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * rule.c (convert_to_pattern): Made it only recognize two-suffix rules whose target suffix comes before the dependency suffix in the .SUFFIXES list. * variable.c (define_automatic_variables): Made all automatic variables be defined with origin `o_automatic'. * variable.h: Added `o_automatic' to `enum variable_origin' * file.c (remove_intermediates): Made it not print an error message if the error was that the file does not exist. * rule.c: Removed `recursive' member from `struct rule'. * remake.c (library_file_mtime): Made it not use the directory hash functions, as reading in and hashing /usr/lib and /lib is slow and most likely unnecessary. * remake.c (remake_file): Changed message from ``No specification for making'' to ``No way to make'' so it will be short enough that most filenames will fit on a line. Made it look at the `recursive' member of the `struct commands', rather than of the `struct file' (which no longer has one). * commands.c (execute_file_commands): Made it look at the `recursive' member of the `struct commands', rather than of the `struct file' (which no longer has one). * file.h: Removed `recursive' member from `struct file'. * commands.h: Added `recursive' member to `struct commands'. * dep.h: Removed unused `quotedparen' member from `struct nameseq' and `struct dep'. * read.c (dequote): Removed this function. (multi_glob): Removed reference to `quotedparen' member of a `struct nameseq' and calls to dequote. * read.c (record_files): Made it set the stem for $* for all static pattern rules, not just those with commands given at that time. Removed check for recursive commands. Made it check for pairs of .SUFFIXES dependencies to reject as default goals as well as single ones (that don't start with dots). (read_makefile): Added checks for recursive commands to set the `recursive' flag in the `struct commands'. Sat Jul 30 15:47:23 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (find_next_token): Made the LENGTHPTR arg optionally nil. * make.c: Removed `files_made' variable which is defined static in remake.c and used only there. (main): Cleaned up somewhat. (decode_switches): Cleaned up a bit. Made an unknown option be a non-fatal error. (decode_env_switches): Made LEN arg unsigned. Cleaned up. (print_version): Made it say ``see the source'' rather than ``see the source file'', since there is more than one. * file.h: Made `num_intermediates' declared unsigned. * file.c: Made `num_intermediates' variable unsigned. (remove_intermediates): Removed unused FORMAT arg. (enter_file): Made it handle double-colon files properly, adding the new entry as the old entry's prev pointer. * dir.c: Re-indented the `struct dir' definition to be right. (dir_load): Cleaned up slightly. (file_exists_p): Removed comment saying we could use `access', since that is a bad idea (except for setuid programs). Cleaned up slightly. * commands.c: Changed some comments slightly. (execute_file_commands): Cleaned up a bit. Changed some comments, added others. Moved freeing of storage for $^ and $? to the same place as for the other automatic variables. (execute_command_line): Made `#' trigger a shell. Added some comments. Cleaned up a bit. Put all the special chars that trigger shells into an array easily changeable at the top. * ar.c: Added comments explaining each function. (ar_scan_1): Merged into ar_member_date. (ar_member_date): Changed call to ar_scan_1 to the body of that function. (ar_member_date_1): Simplified to a ?: expression rather than an if-else statement. (ar_member_touch): Changed error handling around a bit. None of these errors are fatal now. * variable.c (subst_expand): Added a new arg BY_WORD, to do substs only on full words. (patsubst_expand): Fixed bug which made calls whose patterns contained no `%' to not work correctly, by using above. (variable_expand): Pass extra arg to `subst_expand'. * variable.c (expand_function): Fixed bug which made `foreach' calls with one-word lists run off into never-never land. Fri Jul 29 20:12:36 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * variable.c (expand_function): Made a very minor speed improvement by avoiding an unnecessary strlen call. Wed Jul 27 16:01:47 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * rule.c (default_suffixes): Rearranged the list somewhat; added `.el' and `.elc' to speed things up (especially when building Emacs), for the same reason `.h' is there. * read.c (record_files): Changed `lineno' from `long' to `unsigned int'. Sun Jul 24 02:15:30 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * variable.c (expand_function): Eliminated use of `wstok' because it is non-reentrant and unreliable. Fixed a minor bug which would cause something not to be freed. * make.c (wstok): Removed `wstok' because it is no longer used. * variable.c (expand_function): Made `foreach' function put spaces between output texts like it's supposed to. Sat Jul 23 17:32:55 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * rule.c (default_suffixes, default_suffix_rules): Added rule to make %.dvi from %.texinfo. * dir.c (print_dir_data_base): Made it say a bit more. Fri Jul 22 23:13:16 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * make.c (print_data_base): Split this function up into one for each thing. * variable.c (print_variable_data_base): One of the above. * rule.c (print_rule_data_base): Ditto. * file.c (print_file_data_base): Ditto. * dir.c (print_dir_data_base): Ditto. * rule.c (install_pattern_rule): Fixed a bug which caused the terminal and recursive flags to always be zero for rules entered by this function. * make.texinfo (Rules: Double-colon): Added a paragraph explaining the purpose of double-colon rules. * make.texinfo (Implicit: Catalogue of Rules): Updated to reflect new C++, TeX, Web, and Texinfo rules. Other slight editorial changes. * commands.c (execute_file_commands): Fixed a bug wherein random memory could get written for files with no deps. Wed Jul 20 19:30:31 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * read.c (readline): Fix bug wherein it would not recognize a backslash-newline if the buffer filled up and was enlarged right before reading the newline. Tue Jul 19 19:55:02 1988 Roland McGrath (mcgrath at chilli.Berkeley.EDU) * read.c: Added default suffix rules for .cc (using $(C++), which defaults to `g++', and $(C++FLAGS)), .tex, .dvi, .web and .cweb (using $(TEX), $(WEAVE), $(TANGLE), $(CWEAVE) and $(CTANGLE)). Sat Jul 16 21:24:28 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Made error formats use %u rather than %ld for line numbers, which are now unsigned int's rather than long's. * read.c (conditional_line): Fixed some bugs caused by use of unsigned int rather than int in one place. * read.c (conditional_line): Put the info about active conditionals in a struct. (read_makefile): Make a new struct of info about conditionals for included makefiles and restore the old one after the included makefile has been read. * read.c (read_makefile): Don't try to read a makefile with name "" after giving an error message because an `include' directive gave no filename. * read.c (read_makefile): Give an error message for non-whitespace text after the filename in an `include' directive. * make.c (error): Take five args, like `fatal'. It managed to lose with only two. Is there a better way to do this without vfprintf? * read.c (read_makefile): Commands consisting of only whitespace are not the same as no commands. I thought I'd fixed this bug months ago; it seems to have come back. * make.c (collapse_continuations): All whitespace around a backslash-newline combination is turned into a single space. * Added COPYING file and copyright notices to all files. * make.texinfo (Running: Goals): Fix a typo. * read.c (do_define): Take an arg for the origin of the variable being defined. (read_makefile): Grok `override define'. * make.texinfo (Variables: Override Directive, Defining): Document the `override define' combination directive. * ar.c (ar_member_date): Make a 0 return from `ar_scan' return (time_t) -1 (nonexistent file), rather than (time_t) 0, which, when put in the `struct file', makes `file_mtime' try to get the mtime over and over again. * variable.c (pattern_matches): Fix a bug that made patterns not beginning with `%' never match. Fri Jul 15 21:01:44 1988 Roland McGrath (mcgrath at tully.Berkeley.EDU) * Took Make out of RCS. * Split the monolithic `make.c' into several smaller files. Copyright (C) 1988-2009 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: ChangeLog.2 ================================================ 2000-06-22 Paul D. Smith * job.c (start_job_command): Increment commands_started before the special check for ":" (empty command) to avoid spurious "is up to date" messages. Also move the test for question_flag after we expand arguments, and only stop if the expansion provided an actual command to run, not just whitespace. This fixes PR/1780. 2000-06-21 Paul D. Smith * read.c (read_makefile): If we find a semicolon in the target definition, remember where it was. If the line turns out to be a target-specific variable, add back the semicolon and everything after it. Fixes PR/1709. 2000-06-19 Paul D. Smith * config.h-vms.template: #define uintmax_t for this system. * config.ami.template: Ditto. * config.h.W32.template: Ditto. * configure.in: We don't use select(2) anymore, so don't bother checking for it. * acconfig.h: Ditto. * acinclude.m4: Ditto. * file.c (all_secondary): New static global; if 1 it means .SECONDARY with no prerequisites was seen in the makefile. (snap_deps): Set it appropriately. (remove_intermediates): Check it. (num_intermediates): Remove this global, it's not used anywhere. (considered): Move this to remake.c and make it static. * NEWS: Document the change to .SECONDARY. * make.texinfo (Special Targets): Document the change to .SECONDARY. * implicit.c (pattern_search): Remove the increment of num_intermediates; it's not used. * filedef.h: Remove num_intermediates and considered. * function.c (handle_function): If the last argument was empty, we were pretending it didn't exist rather than providing an empty value. Keep looking until we're past the end, not just at the end. * implicit.c (pattern_search): Multi-target implicit rules weren't expanding the "also made" targets correctly if the pattern didn't contain a slash but the target did; in that case the directory part wasn't being added back to the stem on the "also made" targets. Reported by Seth M LaForge , with a patch. 2000-06-17 Eli Zaretskii * Makefile.DOS.template (DESTDIR, bindir, datadir, libdir) (infodir, mandir, includedir): Support installation under a non-default DESTDIR. * remake.c (f_mtime): Fix the spelling of __MSDOS__. * configh.DOS.template (HAVE_FDOPEN, HAVE_MKSTEMP): Define. 2000-06-14 Paul D. Smith * acinclude.m4 (pds_WITH_GETTEXT): rewrite fp_WITH_GETTEXT and rename it to avoid confusion. This version is very specific: it won't accept any gettext that isn't GNU. If the user doesn't explicitly ask for the included gettext, we look to see if the system gettext is GNU (testing both the actual libintl library, and the libintl.h header file). Only if the system gettext is really GNU gettext will we allow it to be used. (pds_CHECK_SYSTEM_GETTEXT): A helper function. 2000-06-13 Paul D. Smith * gettext.h: If we have libintl.h, use that instead of any of the contents of gettext.h. We won't check for libintl.h unless we're using the system gettext. * function.c (func_word): Clarify error message. 2000-06-10 Paul Eggert Support nanosecond resolution on hosts with 64-bit time_t and uintmax_t (e.g. 64-bit Sparc Solaris), by splitting FILE_TIMESTAMP into a 30-bit part for nanoseconds, with the rest for seconds, if FILE_TIMESTAMP is at least 64 bits wide. * make.h: Always define FILE_TIMESTAMP to be uintmax_t, for simplicity. * filedef.h (FILE_TIMESTAMP_HI_RES, FILE_TIMESTAMP_LO_BITS) (UNKNOWN_MTIME, NONEXISTENT_MTIME, OLD_MTIME) (ORDINARY_MTIME_MIN, ORDINARY_MTIME_MAX): New macros. (FILE_TIMESTAMP_STAT_MODTIME): Now takes fname arg. All uses changed. (FILE_TIMESTAMP_DIV, FILE_TIMESTAMP_MOD) (FILE_TIMESTAMP_FROM_S_AND_NS): Remove. (FILE_TIMESTAMP_S, FILE_TIMESTAMP_NS): Use shifts instead of multiplication and division. Offset the timestamps by ORDINARY_MTIME_MIN. (file_timestamp_cons): New decl. (NEW_MTIME): Now just the maximal timestamp value, as we no longer use -1 to refer to nonexistent files. * file.c (snap_deps, print_file): Use NONEXISTENT_MTIME, UNKNOWN_MTIME, and OLD_MTIME instead of magic constants. * filedef.h (file_mtime_1): Likewise. * main.c (main): Likewise. * remake.c (update_file_1, notice_finished_file, check_dep) (f_mtime, name_mtime, library_search): Likewise. * vpath.c (selective_vpath_search): Likewise. * remake.c (f_mtime): Do not assume that (time_t) -1 equals NONEXISTENT_MTIME. When futzing with time stamps, adjust by multiples of 2**30, not 10**9. Do not calculate timestamp adjustments on DOS unless they are needed. * commands.c (delete_target): Do not assume that FILE_TIMESTAMP_S yields -1 for a nonexistent file, as that is no longer true with the new representation. * file.c (file_timestamp_cons): New function, replacing FILE_TIMESTAMP_FROM_S_AND_NS. All uses changed. (file_timestamp_now): Use FILE_TIMESTAMP_HI_RES instead of 1 < FILE_TIMESTAMPS_PER_S to determine whether we're using hi-res timestamps. (print_file): Print OLD_MTIME values as "very old" instead of as a timestamp. 2000-05-31 Paul Eggert * remake.c (name_mtime): Check for stat failures. Retry if EINTR. 2000-05-24 Paul D. Smith * main.c (decode_switches): The "positive_int" switch uses atoi() which succeeds for any input, and doesn't notice if extra, non-digit text is after the number. This causes make to mis-parse command lines like "make -j 5foo" as "make -j5" (ignoring "foo" completely) instead of "make -j0 5foo" (where "5foo" is a target). Fix this by checking the value by hand. We could use strtol() if we were sure of having it; this is the only questionable use of atoi() I found so we'll just stick with that. Fixes PR/1716. * i18n/ja.po, i18n/nl.po, i18n/pt_BR.po: New translation files. * configure.in (ALL_LINGUAS): Added pt_BR. 2000-05-22 Paul Eggert * remake.c (f_mtime): Fix bug when handling future odd timestamps in the WINDOWS32 case. Do not bother initializing static var to zero. Simplify code that works around WINDOWS32 and __MSDOS__ time skew brain damage. 2000-05-22 Paul Eggert * job.c: Don't include time.h, as make.h already does this. 2000-05-22 Paul Eggert * configure.in (AC_CHECK_HEADERS): Add sys/time.h. (AC_HEADER_TIME): Add. (clock_gettime): Prefer -lrt to -lposix4, for Solaris 7. (gettimeofday): Add check for standard version of gettimeofday. This merges changes written by Paul D. Smith. * file.c (file_timestamp_now): Use gettimeofday if available and if clock_gettime does not work. Don't bother with high-resolution clocks if file timestamps have only one-second resolution. * make.h : Include, conditionally on the usual TIME_WITH_SYS_TIME and HAVE_SYS_TIME_H macros. This is needed for gettimeofday. 2000-05-20 Paul D. Smith * read.c (read_makefile): We weren't keeping makefile names around unless there was a rule defined in them; but now we need to keep them for variables as well. Forget trying to be fancy: just keep every makefile name we successfully open. * remote-cstms.c (start_remote_job_p): Change DB_EXTRA (?) to DB_JOBS. 2000-05-17 Paul Eggert * commands.c (chop_commands): Ensure ctype macro args are nonnegative. * expand.c (variable_expand_string): Likewise. * function.c (subst_expand, lookup_function, msdos_openpipe): Likewise. * job.c (vms_redirect, start_job_command, new_job, child_execute_job, construct_command_argv_internal, construct_command_argv): Likewise. * main.c (decode_env_switches, quote_for_env): Likewise. * misc.c (collapse_continuations, end_of_token, end_of_token_w32, next_token): Likewise. * read.c (read_makefile, do_define, conditional_line, find_char_unquote,get_next_mword): Likewise. * variable.c (try_variable_definition): Likewise. * vpath.c (construct_vpath_list): Likewise. * w32/pathstuff.c (convert_vpath_to_windows32): Likewise. 2000-05-10 Eli Zaretskii * main.c (main) [__MSDOS__]: Add SIGFPE to signals we block when running child programs, to prevent Make from dying on Windows 9X when the child triggers an FP exception. 2000-05-08 Paul D. Smith * dir.c (find_directory) [WINDOWS32]: If we strip a trailing "\" from the directory name, remember to add it back. The argument might really be inside a longer string (e.g. %Path%) and if you don't restore the "\" it'll be truncated permanently. Fixes PR/1722. Reported by 2000-05-02 Paul D. Smith * job.c (construct_command_argv_internal) [WINDOWS32]: Added "rd" and "rmdir" to the list of command.com commands. Reported by Elod Horvath 2000-04-24 Paul D. Smith * i18n/ja.po: New translation file from the Japanese language team. 2000-04-18 Paul D. Smith * remake.c (f_mtime): If ar_member_date() returns -1 (the member doesn't exist), then return (FILE_TIMESTAMP)-1 rather than returning the timestamp calculated from the value -1. Fixes PR/1696. Reported by Gilles Bourhis . 2000-04-17 Paul D. Smith * config.h.W32.template: Add LOCALEDIR macro resolving to "". * w32/subproc/sub_proc.c (process_begin): Remove reference to debug_flag; change it to a DB() call. Fixes PR/1700. Reported by Jim Smith 2000-04-17 Bruno Haible * arscan.c [BeOS]: Add replacement for nonexistent from GNU binutils. 2000-04-11 Paul D. Smith * function.c (expand_builtin_function): If no arguments were provided, just quit early rather than changing each function to test for this. (function_table[]): Change the min # of arguments to 0 for all those functions for which it makes sense (currently everything that used to take a minimum of 1 argument, except $(call ...)). Fixes PR/1689. 2000-04-09 Eli Zaretskii * README.DOS: Add instructions to install a binary distro. Mention latest versions of Windows. 2000-04-07 Eli Zaretskii * main.c (main): Rename TMP_TEMPLATE into DEFAULT_TMPDIR, and use it for the directory of the temporary file. If P_tmpdir is defined, use it in preference to "/tmp/". Try $TMPDIR, $TEMP, and $TMP in the environment before defaulting to DEFAULT_TMPDIR. (print_version): Add year 2000 to the Copyright line. 2000-04-04 Paul D. Smith * Version 3.79 released. * make.texinfo: Update documentation with new features for 3.79. * function.c (func_wordlist): Don't re-order arguments to wordlist. 2000-04-03 Paul D. Smith * remake.c (f_mtime): Archive member timestamps are stored as time_t, without nanoseconds. But, f_mtime() wants to return nanosecond info on those systems that support it. So, convert the return value of ar_member_date() into a FILE_TIMESTAMP, using 0 as the nanoseconds. 2000-03-28 Paul D. Smith * Version 3.78.92 released. * build.template: Updates for gettext support; some bugs fixed. 2000-03-27 Paul D. Smith * config.guess, config.sub: Updated from config CVS archive at :pserver:anoncvs@subversions.gnu.org:/home/cvs as of today. * read.c (record_files): Check if expanding a static pattern rule's prerequisite pattern leaves an empty string as the prerequisite, and issue an error if so. Fixes PR/1670. (read_makefile): Store the starting linenumber for a rule in TGTS_STARTED. (record_waiting_files): Use the TGTS_STARTED value for the file location passed to record_file() instead of the current linenumber, so error messages list the line where the target was defined instead of the line after the end of the rule definition. * remake.c (start_updating, finish_updating, is_updating): Fix PR/1671; circular dependencies in double-colon rules are not diagnosed. These macros set the updating flag in the root double-colon file instead of the current one, if it's part of a double-colon list. This solution provided by Tim Magill ; I just changed the macro names :). (update_file_1): Call them. (check_dep): Call them. The change to not automatically evaluate the $(call ...) function's arguments breaks recursive use of call. Although using $(if ...) and $(foreach ...) in $(call ...) macros is important, the error conditions generated are simply to obscure for me to feel comfortable with. If a method is devised to get both working, we'll revisit. For now, remove this change. * function.c (function_table): Turn on the expand bit for func_call. (func_call): Don't expand arguments for builtin functions; that will have already been done. 2000-03-26 Paul D. Smith * file.c (remove_intermediates): Never remove targets explicitly requested on the command-line by checking the cmd_target flag. Fixed PR/1669. 2000-03-23 Paul Eggert * filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Use st_mtime instead of st_mtim.tv_sec; the latter doesn't work on Unixware. 2000-03-18 Paul D. Smith * file.c (file_hash_enter): If we're trying to change a file into itself, just return. We used to assert this wasn't true, but someone came up with a weird case involving archives. After playing with it for a while I decided it was OK to ignore it. * default.c: Define COFLAGS to empty to avoid spurious warnings. * filedef.h: Change #if ST_MTIM_NSEC to #ifdef; this is a macro containing the name of the nsec field, not true/false. * make.h: Ditto. Reported by Marco Franzen . 2000-03-08 Tim Magill * remake.c (update_file): Return the exit status of the pruned file when pruning, not just 0. Fixes PR/1634. 2000-02-24 Paul D. Smith * configure.in: Close a minor potential security hole; if you're reading makefiles from stdin (who does that?) you could run into a race condition with the temp file using mktemp() or tmpnam(). Add a check for mkstemp() and fdopen(). * main.c (open_tmpfile): New function to open a temporary file. If we have mkstemp() (and fdopen()), use that. If not use mktemp() or tmpnam(). If we have fdopen(), use open() to open the file O_CREAT|O_EXCL. If not, fall back to normal fopen() (insecure). (main): Call it. * job.c (child_execute_job) [VMS]: Call it. * variable.c (lookup_variable): If we find a variable which is being expanded, then note it but keep looking through the rest of the set list to see if we can find one that isn't. If we do, return that. If we don't, return the original. Fix for PR/1610. While implementing this I realized that it also solves PR/1380 in a much more elegant way. I don't know what I was smoking before. So, remove the hackage surrounding the original fix for that (see below). Change this function back to lookup_variable and remove the extra setlist argument. * variable.h (recursively_expand_setlist): Remove the macro, rename the prototype, and remove the extra setlist argument. (lookup_variable): Ditto. * expand.c (recursively_expand): Rename and remove the extra setlist argument. (reference_variable): Use lookup_variable() again. (allocated_variable_append): Remove the extra setlist argument. 2000-02-21 Paul D. Smith * README.template: A few updates. * i18n/de.po: New version from the German translation team. 2000-02-09 Paul D. Smith * Version 3.78.91 released. 2000-02-07 Paul D. Smith * read.c (read_makefile): Reset *p2 to ':', not *colonp. If any filenames contained backslashes the resulting output (without backslashes) will be shorter, so setting *colonp doesn't change the right character. Fix for PR/1586. For += target-specific variables we need to remember which variable set we found the variable in, so we can start looking from there in the next iteration (otherwise we might see it again in recursively_expand and fail!). This is turning into a hack; if it gets any worse we'll have to rethink this entire algorithm... implementing expansion of these references separately from the "normal" expansion, say, instead of using the same codepath. Actually, it's already "worse enough" :-/. Fix for PR/1380. * variable.h (recursively_expand_setlist): Rename recursively_expand to add a struct variable_set_list argument, and make a macro for recursively_expand. (lookup_variable_setlist): Rename lookup_variable to add a struct variable_set_list argument, and make a macro for lookup_variable. * expand.c (recursively_expand_setlist): Take an extra struct variable_set_list argument and pass it to allocated_variable_append(). (reference_variable): Use lookup_variable_setlist() and pass the returned variable_set_list to recursively_expand_setlist. (allocated_variable_append): Take an extra setlist argument and use this as the starting place when searching for the appended expansion. If it's null, use current_variable_set_list as before. * variable.c (lookup_variable_setlist): If the LISTP argument is not nil, set it to the list containing the variable we found. 2000-02-04 Paul D. Smith * variable.c (print_variable): Write out filename/linenumber information for the variable definition if present. (define_variable_in_set): Store filename information if provided. (define_variable, define_variable_for_file): Removed. (try_variable_definition): Use define_variable_loc() to keep variable definition location information. * read.c (read_makefile): Keep variable definition location info. (do_define): Ditto. (record_target_var): Ditto. * variable.h (define_variable_in_set): New fileinfo argument. (define_variable, define_variable_loc, define_variable_for_file): Declare new macros. Fix PR/1407: * filedef.h (struct file): Rename patvar to pat_variables and make it just a variable_set_list; we need our own copy of the pattern variable's variable set list here to avoid overwriting the global one. * variable.c (initialize_file_variables): Move the instantiation of the pat_variables pointer here. Only do the search after we're done reading the makefiles so we don't search too early. If there's a pat_variables value, set up the variables next ptr. * expand.c (variable_expand_for_file): Remove the setup of the pat_variables info; it's done earlier now to ensure the parent's pattern variables are set up correctly as well. 2000-02-03 Paul D. Smith * job.c (sh_chars_dos) [WINDOWS32]: Add "&" as a shell metacharacter for the W32 DOS shell. Reported by Warren Jones . 2000-02-02 Paul D. Smith Fixes for the OpenVMS port from Hartmut Becker * config.h-vms [VMS]: Define LOCALEDIR to something; needed for the expansion of bindtextdomain() even though it's a no-op. * vmsfunctions.c (strcmpi): Remove duplicate definition of strcmpi(). (readdir): Use DB() instead of testing debug_flag. * dir.c (file_impossible) [VMS]: Search "p" not "name". * job.c [VMS]: Switch from debug_flag to the new DB macro. Add some i18n _() macros (even though VMS doesn't yet support it). * function.c (patsubst_expand): Change "len" to not be unsigned to avoid type mismatches. * main.c (main): Declare signame_init() if we're going to call it. 2000-01-29 Eli Zaretskii * Makefile.DOS.template: Track changes in Makefile.in (install-recursive, uninstall-recursive): Add missing targets. (DESTDIR): Define. (install-binPROGRAMS, uninstall-binPROGRAMS): Use $(DESTDIR). * default.c (default_variables) [__MSDOS__]: Define CXX to gpp. 2000-01-27 Paul D. Smith * gettext.c: Some warning cleanups, and a fix for systems which don't define HAVE_ALLOCA (the workaround code was included twice). 2000-01-26 Paul D. Smith * Version 3.78.90 released. 2000-01-25 Paul D. Smith Change gettext support to use the simplified version in libit 0.7. * getopt.c, make.h: Use gettext.h instead of libintl.h. * ABOUT-NLS, gettext.h, gettext.c: New files from libit 0.7. Modified to remove some static declarations which aren't defined. * acconfig.h: Use new gettext #defines. * acinclude.m4: Add fp_WITH_GETTEXT; remove AM_GNU_GETTEXT. * configure.in: Call fp_WITH_GETTEXT instead. * Makefile.am: New gettext stuff. Also force inclusion of glob files for systems which have LIBC glob. * i18n/Makefile.am, i18n/.cvsignore: New dir for translation files. * i18n/de.po, i18n/es.po, i18n/fr.po, i18n/ko.po, i18n/nl.po: * i18n/pl.po, i18n/ru.po: Import translations already done for earlier versions of GNU make. Thanks for that work!! * po/Makefile.in.in, po/POTFILES.in: Removed. 2000-01-23 Paul D. Smith * main.c (decode_debug_flags): If debug_flag is set, enable all debugging levels. (debug_flag): Resurrect this flag variable. (switches): Make -d give the old behavior of turning on all debugging. Change --debug alone to emit basic debugging and take optional arguments to expand debugging. * NEWS: Document the new debugging options. * remake.c (no_rule_error): Remove this function. This tries to fix a real problem--see the description with the introduction of this function below. However, the cure is worse than the disease and this approach won't work. (remake_file): Put the code from no_rule_error back here. (update_file_1): Remove call to no_rule_error. * filedef.h (struct file): Remove mfile_status field. 2000-01-22 Paul D. Smith Integrate GNU gettext support. * configure.in: Add AM_GNU_GETTEXT. * Makefile.am: Add options for setting LOCALEDIR, -Iintl, etc. * acinclude.m4: Add gettext autoconf macros. * acconfig.h: Add new gettext #defines. * make.h: Include libintl.h. Make sure _() and N_() macros are declared. Make gettext() an empty macro is NLS is disabled. * main.c (struct command_switch switches[]): Can't initialize static data with _() (gettext calls), so use N_() there then use gettext() directly when printing the strings. * remake.c (no_rule_error): The string constants can't be static when initializing _() macros. * file.c (print_file): Reformat a few strings to work better for translation. * po/POTFILES.in, po/Makefile.in.in: New files. Take Makefile.in.in from the latest GNU tar distribution, as that version works better than the one that comes with gettext. * NEWS: Mention i18n ability. 2000-01-21 Paul D. Smith Installed patches for the VMS port. Patches provided by: Hartmut Becker * readme.vms, arscan.c, config.h-vms, default.c, dir.c, file.c: * implicit.c, job.c, make.h, makefile.com, makefile.vms, rule.c: * variable.c, vmsdir.h, vmsfunctions.c, vmsify.c, glob/glob.c: * glob/glob.h: Installed patches. See readme.vms for details. 2000-01-14 Andreas Schwab * dir.c (read_dirstream): Initialize d_type if it exists. 2000-01-11 Paul D. Smith Resolve PR/xxxx: don't automatically evaluate the $(call ...) function's arguments. While we're here, clean up argument passing protocol to always use simple nul-terminated strings, instead of sometimes using offset pointers to mark the end of arguments. This change also fixes PR/1517. Reported by Damien GIBOU . * function.c (struct function_table_entry): Remove the negative required_args hack; put in explicit min and max # of arguments. (function_table): Add in the max value. Turn off the expand bit for func_call. (expand_builtin_function): Test against minimum_args instead of the obsolete required_args. (handle_function): Rewrite this. We don't try to be fancy and pass one style of arguments to expanded functions and another style to non-expanded functions: pass pointers to nul-terminated strings to all functions. (func_call): Rewrite this. If we are invoking a builtin function and it's supposed to have its arguments expanded, do that (since it's not done by handle_function for $(call ...) anymore). For non-builtins, just add the variables as before but mark them as recursive so they'll be expanded later, as needed. (func_if): All arguments are vanilla nul-terminated strings: remove trickery with "argv[1]-1". (func_foreach): Ditto. * expand.c (expand_argument): If the second arg is NULL, expand the entire first argument. * job.c (new_job): Zero the child struct. This change was just made to keep some heap checking software happy, not because there was an actual bug (the important memory was being cleared properly). 1999-12-15 Paul D. Smith * variable.c (print_variable): Print the variable with += if the append flag is set. * implicit.c (pattern_search): Remove the extra check of the implicit flag added on 8/24/1998. This causes problems and the reason for the change was better resolved by the change made to check_deps() on 1998-08-26. This fixes PR/1423. 1999-12-08 Paul D. Smith * dir.c (dir_setup_glob): On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a macro for stat64(). Assignment doesn't work in that case. So, stat is a macro, make a local wrapper function to invoke it. (local_stat): Wrapper function, if needed. Reported by Andrej Borsenkow . 1999-12-02 Paul D. Smith * remake.c (update_file): Move the considered test outside the double-colon loop, _but_ make sure we test the double_colon target not the "current" target. If we stop early because one double-colon target is running, mark all the rest considered and try to start their prerequisites (so they're marked considered). Fix for PR/1476 suggested by Tim Magill . 1999-11-22 Rob Tulloh * function.c (windows32_openpipe, func_shell): Correct Windows32 problem where $(shell nosuchfile) would incorrectly exit make. The fix is to print the error and let make continue. Reported by David Masterson . * w32/subproc/misc.c (arr2envblk): Memory leak fix. 1999-11-21 Paul D. Smith Rework GNU make debugging to provide different levels of output. * NEWS: mention it. * debug.h: New file. Define various debugging levels and macros. * function.c, implicit.c, job.c, main.c, misc.c, read.c, remake.c * remote-cstms.c, vmsfunctions.c: Replace all code depending on debug_flag with invocations of debugging macros. * make.h: Remove debug_flag and DEBUGPR, add db_level. 1999-11-18 Paul Eggert * acinclude.m4 (AC_SYS_LARGEFILE_FLAGS): Work around a problem with the QNX 4.25 shell, which doesn't propagate exit status of failed commands inside shell assignments. 1999-11-17 Paul D. Smith * function.c (func_if): Find the end of the arg list by testing the next item for NULL; any other test is not correct. Reported by Graham Reed (PR/1429). Fix += when used in a target-specific variable context. * variable.h: New bitfield APPEND set if we have a += target-specific variable. * variable.c (try_variable_definition): Add an argument to specify if we're trying a target-specific variable. If we are and it's an append style, don't append it, record it as normal recursive, but set the APPEND flag so it'll be expanded later. * main.c (handle_non_switch_argument): Use new try_variable_definition() signature. * read.c (read_makefile,record_target_var): Ditto. * expand.c (allocated_variable_append): New function: like allocated_variable_expand(), but we expand the same variable name in the context of the ``next'' variable set, then we append this expanded value. (recursively_expand): Invoke it, if the APPEND bit is set. 1999-11-10 Paul D. Smith * file.c (snap_deps): If the .NOTPARALLEL target is defined, turn off parallel builds for this make only (still allow submakes to be run in parallel). * main.c: New variable, ``not_parallel''. * make.h: Add an extern for it. * job.c (new_job): Test NOT_PARALLEL as well as JOB_SLOTS. * NEWS: Add info on .NOTPARALLEL. * make.texinfo (Special Targets): Document it. * configure.in (GLOBDIR): Set to "glob" if we need to build the glob library. * Makefile.am (SUBDIRS): Use the GLOBDIR variable instead of "glob" so we don't try to build glob if we don't need to (if we have GLIBC glob). Reported by Lars Hecking . * main.c (main): Don't put "***" in the clock skew warning message. Reported by karl@gnu.org. * make.h: Remove unneeded signal setup. * signame.c: Remove extraneous #includes; some versions of Ultrix don't protect against multiple inclusions and it causes compile errors. Reported by Simon Burge . 1999-10-15 Paul D. Smith * main.c (quote_for_env): Rename from quote_as_word(). * make.h, *.c: Prefer strchr() and strrchr() in the code rather than index() and rindex(). Define strchr/strrchr in terms of index/rindex if the former aren't supported. * default.c (CHECKOUT,v): Replace the fancy, complicated patsubst/filter expression with a simple $(if ...) expression. * main.c (print_usage): Add the bug reporting mailing address to the --help output, as per the GNU coding standards. Reported by Paul Eggert . * README.customs: Installed information on running Customs-ized GNU make and setuid root, collected by Ted Stern . * read.c (read_all_makefiles): PR/1394: Mark the end of the next token in the MAKEFILES value string _before_ we dup it. 1999-10-13 Paul D. Smith * configure.in (make_cv_sys_gnu_glob): We used to add the -Iglob flag to CPPFLAGS, but that loses if the user specifies his own CPPFLAGS; this one gets added _after_ his and if he happens to have an old or broken glob.h--boom. Instead, put it in GLOBINC and SUBST it. * Makefile.am (INCLUDES): Add @GLOBINC@ to the INCLUDES macro; these things get on the compile line well before the user's CPPFLAGS. 1999-10-12 Paul D. Smith * remake.c (notice_finished_file): If we get here and -n is set, see if all the command lines are marked recursive. If so, then we ran every command there is, so check the mtime on this file just like we would normally. If not, we assume the command we didn't run would updates the target and set mtime of the target to "very new". * job.c (start_job_command): Update lines_flags in the file's cmds structure with any per-line tokens we found (`@', `-', `+'). 1999-10-08 Paul D. Smith * variable.c (initialize_file_variables): Always recurse to initialize the parent's file variables: the parent might not have any rules to run so it might not have been initialized before this--we need this to set up the chain properly for target-specific variables. 1999-09-29 Paul Eggert * main.c (quote_as_word): Always quote for decode_env_switches instead of for the shell, so that arguments with strange characters are are passed to submakes correctly. Remove double_dollars arg; we always double dollars now. All callers changed. (decode_env_switches): Don't run off the end of an environment variable whose contents ends in a unescaped backslash. 1999-09-23 Paul D. Smith * commands.c, function.c, job.c, read.c: Cast arguments to ctype.h functions/macros to _unsigned_ char for portability. * remake.c, function.c: Compiler warning fixes: the second argument to find_next_token() should be an _unsigned_ int*. Reported by Han-Wen Nienhuys . 1999-09-23 Paul D. Smith * Version 3.78.1 released. * make.texinfo: Update version/date stamp. * main.c (main): Argh. For some reason we were closing _all_ the jobserver pipes before we re-exec'd due to changed makefiles. This means that any re-exec got a "jobserver unavailable" error :-/. I can't believe we didn't notice this before. 1999-09-22 Paul D. Smith * Version 3.78 released. * main.c (main): Only fail on multiple --jobserver-fds options if they aren't all the same. Some makefiles use things like $(MAKE) $(MFLAGS) which will cause multiple, identical copies of --jobserver-fds to show up. 1999-09-16 Paul D. Smith * main.c (define_makeflags): Zero out FLAGSTRING to avoid uninitialized memory reads when checking *p != '-' in the loop. 1999-09-15 Paul D. Smith * Version 3.77.97 released. * configure.in (MAKE_HOST): AC_SUBST this so it will go into the makefile. * Makefile.am (check-local): Print a success banner if the check succeeds. (check-regression): A bit of fine-tuning. 1999-09-15 Eli Zaretskii * README.DOS.template: Document requirements for the test suite. * Makefile.DOS.template: Updates to allow the test suite to run from "make check". * main.c (main): Handle it if argv[0] isn't an absolute path. 1999-09-13 Paul D. Smith * Version 3.77.96 released. * Makefile.am (loadavg): Use CPPFLAGS, etc. to make sure we get all the right #defines to compile. (check-regression): Look for the regression test suite in the make package itself. If we're building remotely, use symlinks to make a local copy. (dist-hook): Put the test suite into the tar file. * configure.in: Look for perl for the test suite. 1999-09-10 Paul Eggert * acinclude.m4 (AC_SYS_LARGEFILE_FLAGS): If on HP-UX 10.20 or later, and using GCC, define __STDC_EXT__; this works around a bug in GCC 2.95.1. 1999-09-08 Paul D. Smith * main.c (print_version): Ugh. GLIBC's configure tries to check make version strings and is too aggressive with their matching expressions. I've struck a deal with them to leave the version output as-is for 3.78, and they'll change their configure checks so that I can change this back in the future. 1999-09-07 Eli Zaretskii * job.c (construct_command_argv_internal) [__MSDOS__]: Add "echo" and "unset" to the list of builtin shell commands. * configh.DOS.template (MAKE_HOST): Define to "i386-pc-msdosdjgpp" which is the canonical name of the DJGPP host. 1999-09-05 Paul D. Smith * Version 3.77.95 released. * make.texinfo (Make Errors): Document some new jobserver error messages. 1999-09-04 Eli Zaretskii * make.texinfo (Make Errors): Document the hint about 8 spaces instead of a TAB. (Call Function, Quick Reference): Use @code{$(1)}, not @var. * main.c (main) [__MSDOS__]: Say "on this platform" instead of "on MS-DOS", since the MSDOS version could run on Windows. 1999-09-03 Paul D. Smith * remake.c (notice_finished_file): Always set mtime_before_update if it's not been set, not just if we ran some rules. Otherwise we may have a situation where a target's prerequisite was rebuilt but not changed, so this target's rules weren't run, then update_goal_chain() sees mtime_before_update != last_mtime and thinks that the top-level target changed when it really didn't. This can cause an infinite loop when remaking makefiles. (update_goal_chain): If we get back to the top and we don't know what the goal's last_mtime was, find it now. We need to know so we can compare it to mtime_before_update later (this is only crucial when remaking makefiles--should we only do it then?) 1999-09-02 Paul D. Smith * read.c (read_makefile): If "override" appears as the first prerequisite, look further to ensure this is really a target-specific variable definition, and not just some prerequisite named "override". 1999-09-01 Paul D. Smith * function.c (IS_PATHSEP) [WINDOWS32]: Allow backslash separators for W32 platforms. * read.c (record_files) [WINDOWS32]: Allow backslash separators for W32 platforms. * implicit.c (pattern_search) [WINDOWS32]: Allow backslash separators for W32 platforms. * configure.in (MAKE_HOST): Define it to be the canonical build host info, now that we need AC_CANONICAL_HOST anyway (for large file support). * version.c (make_host): Define a variable to MAKE_HOST so we're sure to get it from the local config.h. * main.c (print_version): Use it in the version information. * config.ami.template: Add MAKE_HOST. * configh.dos.template: Ditto. * config.h.W32.template: Ditto. * config.h-vms.template: Ditto. * main.c (main): Close the jobserver file descriptors if we need to re-exec ourselves. Also print more reasonable error if users force -jN for submakes. This may be common for a while until people use the jobserver feature. If it happens, we ignore the existing jobserver stuff and use whatever they specified on the commandline. (define_makeflags): Fixed a long-standing bug: if a long name only option comes immediately after a single letter option with no argument, then the option string is constructed incorrectly. For example, with -w and --jobserver-fds you get "-w-jobserver-fds..." instead of "-w --jobserver-fds..."; add in an extra " -". * make.texinfo (Phony Targets): Add another example of using .PHONY with subdirectories/recursive make. 1999-08-30 Paul D. Smith * README.W32.template: Renamed from README.W32 so it's autogenerated during the dist. A few minor modifications. * configure.in: Check for kstat_open before AC_FUNC_GETLOADAVG since the latter needs to know whether the former exists to give an accurate result. 1999-08-26 Rob Tulloh * NMakefile [WINDOWS32]: Now more robust. If you change a file under w32/subproc, the make.exe will be relinked. Also added some tests to make sure erase commands won't fail when executed in a pristine build environment. * w32/subproc/sub_proc.c [WINDOWS32]: Added support for HAVE_CYGWIN_SHELL. If you are using the Cygwin B20.1 release, it is now possible to have have native support for this shell without having to rely on klutzy BATCH_MODE_ONLY_SHELL. * config.h.W32 [WINDOWS32]: Added HAVE_CYGWIN_SHELL macro which users can define if they want to build make to use this shell. * README.W32 [WINDOWS32]: Added informaton about HAVE_CYGWIN_SHELL. Cleaned up text a bit to make it more current. 1999-08-26 Paul Eggert Support large files in AIX, HP-UX, and IRIX. * acinclude.m4 (AC_LFS): Remove. Superseded by AC_SYS_LARGEFILE. (AC_SYS_LARGEFILE_FLAGS, AC_SYS_LARGEFILE_SPACE_APPEND, AC_SYS_LARGEFILE_MACRO_VALUE, AC_SYS_LARGEFILE): New macros. (jm_AC_TYPE_UINTMAX_T): Check for busted compilers that can't shift or divide unsigned long long. (AM_PROG_CC_STDC): New macro; a temporary workaround of a bug in automake 1.4. * configure.in (AC_CANONICAL_HOST): Add; required by new AC_SYS_LARGEFILE. (AC_SYS_LARGEFILE): Renamed from AC_LFS. (AM_PROG_CC_STDC): Add. * config.guess, config.sub: New files, needed for AC_CANONICAL_HOST. 1999-08-25 Paul Eggert * make.h (CHAR_MAX): New macro. * main.c (struct command_switch): c is now int, so that it can store values greater than CHAR_MAX. (switches): Replace small numbers N with CHAR_MAX+N-1, to avoid problems with non-ASCII character sets. (short_option): New macro. (init_switches, print_usage, define_makeflags): Use it instead of isalnum. 1999-08-25 Paul D. Smith * Version 3.77.94 released. * main.c (main) [__MSDOS__]: If the user uses -j, warn that it's not supported and reset it. * make.h (ISDIGIT): Obtained this from the textutils distribution. * main.c (decode_switches): Use it. * function.c (is_numeric): Use it. * main.c (struct command_switch): Store the switch char in an unsigned char to shut up GCC about using it with ctype.h macros. Besides, it _is_ always unsigned. 1999-08-24 Paul D. Smith * make.texinfo: Change "dependency" to "prerequisite" and "dependencies" to "prerequisites". Various other cleanups related to the terminology change. * file.c: Change debugging and error messages to use "prerequisite" instead of "dependency". * implicit.c: Ditto. * remake.c: Ditto. * NEWS: Document it. 1999-08-23 Paul D. Smith * remake.c (update_file): Move the considered check into the double-colon rule loop, so we consider double-colon rules individually (otherwise after the first is pruned, the rest won't get run). * README.template: Minor changes. Remove the debugging features of the jobserver, so it no longer writes distinct tokens to the pipe. Thus, we don't need to store the token we get. A side effect of this is to remove a potential "unavailable token" situation: make-1 invokes make-2 with its special token and make-3 with a normal token; make-2 completes. Now we're waiting for make-3 but using 2 tokens; our special token is idle. In the new version we don't have special tokens per se, we merely decide if we already have a child or not. If we don't, we don't need a token. If we do, we have to get one to run the next child. Similar for putting tokens back: if we're cleaning up the last child, we don't put a token back. Otherwise, we do. * main.c: Add a new, internal flag --jobserver-fds instead of overloading the meaning of -j. Remove job_slots_str and add the stringlist jobserver_fds. (struct command_switch): We don't need the int_string type. (switches[]): Add a new option for --jobserver-fds and remove conditions around -j. Make the description for the former 0 so it doesn't print during "make --help". (main): Rework jobserver parsing. If we got --jobserver-fds make sure it's valid. We only get one and job_slots must be 0. If we're the toplevel make (-jN without --jobserver-fds) create the pipe and write generic tokens. Create the stringlist struct for the submakes. Clean up the stringlist where necessary. (init_switches): Remove int_string handling. (print_usage): Don't print internal flags (description ptr is 0). (decode_switches): Remove int_string handling. (define_makeflags): Remove int_string handling. * job.c: Remove my_job_token flag and all references to the child->job_token field. (free_job_token): Remove this and merge it into free_child(). (reap_children): Rework the "reaped a child" logic slightly. Don't call defunct free_job_token anymore. Always call free_child, even if we're dying. (free_child): If we're not freeing the only child, put a token back in the pipe. Then, if we're dying, don't bother to free. (new_job): If we are using the jobserver, loop checking to see if a) there are no children or b) we get a token from the pipe. * job.h (struct child): Remove the job_token field. 1999-08-20 Paul D. Smith * variable.c (try_variable_definition): Allocate for variable expansion in f_append with a simple variable: if we're looking at target-specific variables we don't want to trash the buffer. Noticed by Reiner Beninga . 1999-08-16 Eli Zaretskii * main.c (main) [__MSDOS__]: Mirror any backslashes in argv[0], to avoid problems in shell commands that use backslashes as escape characters. 1999-08-16 Paul D. Smith * Version 3.77.93 released. 1999-08-13 Paul D. Smith Another jobserver algorithm change. We conveniently forgot that the blocking bit is shared by all users of the pipe, it's not a per-process setting. Since we have many make processes all sharing the pipe we can't use the blocking bit as a signal handler flag. Instead, we'll dup the pipe's read FD and have the SIGCHLD handler close the dup'd FD. This will cause the read() to fail with EBADF the next time we invoke it, so we know we need to reap children. We then re-dup and reap. * main.c (main): Define the job_rfd variable to hold the dup'd FD. Actually dup the read side of the pipe. Don't bother setting the blocking bit on the file descriptor. * make.h: Declare the job_rfd variable. * job.c (child_handler): If the dup'd jobserver pipe is open, close it and assign -1 to job_rfd to notify the main program that we got a SIGCHLD. (start_job_command): Close the dup'd FD before exec'ing children. Since we open and close this thing so often it doesn't seem worth it to use the close-on-exec bit. (new_job): Remove code for testing/setting the blocking bit. Instead of EAGAIN, test for EBADF. If the dup'd FD has been closed, re-dup it before we reap children. * function.c (func_shell): Be a little more accurate about the length of the error string to allocate. * expand.c (variable_expand_for_file): If there's no filenm info (say, from a builtin command) then reset reading_file to 0. 1999-08-09 Paul D. Smith * maintMakefile: Use g in sed (s///g) to replace >1 variable per line. * Makefile.DOS.template [__MSDOS__]: Fix mostlyclean-aminfo to remove the right files. 1999-08-01 Eli Zaretskii * function.c (msdos_openpipe) [__MSDOS__]: *Really* return a FILE ptr. 1999-08-01 Paul D. Smith New jobserver algorithm to avoid a possible hole where we could miss SIGCHLDs and get into a deadlock. The original algorithm was suggested by Roland McGrath with a nice refinement by Paul Eggert. Many thanks as well to Tim Magill and Howard Chu, who also provided many viable ideas and critiques. We all had a fun week dreaming up interesting ways to use and abuse UNIX syscalls :). Previously we could miss a SIGCHLD if it happened after we reaped the children but before we re-entered the blocking read. If this happened to all makes and/or all children, make would never wake up. We avoid this by having the SIGCHLD handler reset the blocking bit on the jobserver pipe read FD (normally read does block in this algorithm). Now if the handler is called between the time we reap and the time we read(), and there are no tokens available, the read will merely return with EAGAIN instead of blocking. * main.c (main): Set the blocking bit explicitly here. * job.c (child_handler): If we have a jobserver pipe, set the non-blocking bit for it. (start_waiting_job): Move the token stuff back to new_job; if we do it here then we're not controlling the number of remote jobs started! (new_job): Move the check for job slots to _after_ we've created a child structure. If the read returns without getting a token, set the blocking bit then try to reap_children. * make.h (EINTR_SET): Define to test errno if EINTR is available, or 0 otherwise. Just some code cleanup. * arscan.c (ar_member_touch): Use it. * function.c (func_shell): Use it. * job.c (reap_children): Use it. * remake.c (touch_file): Use it. 1999-07-28 Paul D. Smith * make.h: Define _() and N_() macros as passthrough to initiate NLS support. * : Add _()/N_() around translatable strings. 1999-07-27 Paul D. Smith * read.c: Make sure make.h comes before other headers. 1999-07-26 Paul D. Smith * make.texinfo (Quick Reference): Update with the new features. 1999-07-25 Eli Zaretskii * remake.c [__MSDOS__]: Don't include variables.h, it's already included. * function.c (msdos_openpipe) [__MSDOS__]: Return FILE ptr. (func_shell) [__MSDOS__]: Fix the argument list. * Makefile.DOS.template: Update from Makefile.in. * README.DOS.template: Configure command fixed. * configh.dos.template: Update to provide definitions for uintmax_t, fd_set_size_t, and HAVE_SELECT. 1999-07-24 Paul D. Smith * Version 3.77.91 released. * configure.in: Changes to the boostrapping code: if build.sh.in doesn't exist configure spits an error and generates an empty build.sh file which causes make to be confused. * maintMakefile: Don't build README early. 1999-07-23 Paul D. Smith * job.c (my_job_token): This variable controls whether we've handed our personal token to a subprocess or not. Note we could probably infer this from the value of job_slots_used, but it's clearer to just keep it separately. Job_slots_used isn't really relevant when running the job server. (free_job_token): New function: free a job token. If we don't have one, no-op. If we have the personal token, reclaim it. If we have another token, write it back to the pipe. (reap_children): Call free_job_token. (free_child): Call free_job_token. (start_job_command): Remove duplicate test for '+' in the command. If we don't appear to be running a recursive make, close the jobserver filedescriptors. (start_waiting_job): If our personal token is available, use that instead of going to the server pipe. (*): Add the token value to many debugging statements, and print the child target name in addition to the ptr hex value. Change the default "no token" value from '\0' to '-' so it looks better in the output. * main.c (main): Install the child_handler with sigaction() instead of signal() if we have it. On SysV systems, signal() uses SysV semantics which are a pain. But sigaction() always does what we want. (main): If we got job server FDs from the environment, test them to see if they're open. If not, the parent make closed them because it didn't think we were a submake. Print a warning and suggestion to use "+" on the submake invocation, and hard-set to -j1 for this instance of make. (main): Change the algorithm for assigning slots to be more robust. Previously make checked to see if it thought a subprocess was a submake and if so, didn't give it a token. Since make's don't consume tokens we could spawn many of makes fighting for a small number of tokens. Plus this is unreliable because submakes might not be recognized by the parent (see above) then all the tokens could be used up by unrecognized makes, and no one could run. Now every make consumes a token from its parent. However, the make can also use this token to spawn a child. If the make wants more than one, it goes to the jobserver pipe. Thus there will never be more than N makes running for -jN, and N*2 processes (N makes and their N children). Every make can always run at least one job, and we'll never deadlock. (Note the closing of the pipe for non-submakes also solves this, but this is still a better algorithm.) So! Only put N-1 tokens into the pipe, since the topmost make keeps one for itself. * configure.in: Find sigaction. Disable job server support unless the system provides it, in addition to either waitpid() or wait3(). 1999-07-22 Rob Tulloh * arscan.c (ar_member_touch) [WINDOWS32]: The ar_date field is a string on Windows, not a timestamp. 1999-07-21 Paul D. Smith * Version 3.77.90 released. * Makefile.am (AUTOMAKE_OPTIONS): Require automake 1.4. * function.c: Rearrange so we don't need to predeclare the function_table array; K&R C compilers don't like that. * acinclude.m4 (AC_FUNC_SELECT): Ouch; this requires an ANSI C compiler! Change to work with K&R compilers as well. * configure.in (AC_OUTPUT): Put build.sh back. I don't know how I thought it would work this way :-/. We'll have to think of something else. * Makefile.am: Remove rule to create build.sh. * default.c (default_suffix_rules): Rearrange the default command lines to conform to POSIX rules (put the filename argument $< _after_ the OUTPUT_OPTION, not before it). * various: Changed !strncmp() calls to strneq() macros. * misc.c (sindex): Make slightly more efficient. * dir.c (file_impossible): Change savestring(X,strlen(X)) to xstrdup(). * implicit.c (pattern_search): Ditto. * main.c (enter_command_line_file): Ditto. (main): Ditto. * misc.c (copy_dep_chain): Ditto. * read.c (read_makefile): Ditto. (parse_file_seq): Ditto. (tilde_expand): Ditto. (multi_glob): Ditto. * rule.c (install_pattern_rule): Ditto. * variable.c (define_variable_in_set): Ditto. (define_automatic_variables): Ditto. * vpath.c (construct_vpath_list): Ditto. * misc.c (xrealloc): Some reallocs are non-standard: work around them in xrealloc by calling malloc if PTR is NULL. * main.c (main): Call xrealloc() directly instead of testing for NULL. * function.c (func_sort): Don't try to free NULL; some older, non-standard versions of free() don't like it. * configure.in (--enable-dmalloc): Install some support for using dmalloc (https://www.dmalloc.com/) with make. Use --enable-dmalloc with configure to enable it. * function.c (function_table_entry): Whoops! The function.c rewrite breaks backward compatibility: all text to a function is broken into arguments, and extras are ignored. So $(sort a,b,c) returns "a"! Etc. Ouch. Fix it by making a positive value in the REQUIRED_ARGS field mean exactly that many arguments to the function; any "extras" are considered part of the last argument as before. A negative value means at least that many, but may be more: in this case all text is broken on commas. (handle_function): Stop when we've seen REQUIRED_ARGS args, if >0. (expand_builtin_function): Compare number of args to the absolute value of REQUIRED_ARGS. 1999-07-20 Paul D. Smith * job.c (start_job_command): Ensure that the state of the target is cs_running. It might not be if we skipped all the lines due to -n (for example). * commands.c (execute_file_commands): If we discover that the command script is empty and succeed early, set cs_running so the modtime of the target is still rechecked. * rule.c (freerule): Free the dependency list for the rule. * implicit.c (pattern_search): When turning an intermediate file into a real target, keep the also_make list. Free the dep->name if we didn't use it during enter_file(). 1999-07-16 Paul D. Smith * read.c (read_makefile): Don't allocate the commands buffer until we're sure we found a makefile and won't return early (mem leak). * job.c (start_job_command): Broken #ifdef test: look for F_SETFD, not FD_SETFD. Close-on-exec isn't getting set on the bad_stdin file descriptor and it's leaking :-/. * getloadavg.c (getloadavg): Ditto. 1999-07-15 Paul D. Smith * read.c (read_makefile): Fix some potential memory stomps parsing `define' directives where no variable name is given. * function.c (func_call): Rename from func_apply. Various code cleanup and tightening. (function_table): Add "call" as a valid builtin function. * make.texinfo (Call Function): Document it. * NEWS: Announce it. 1999-07-09 Eli Zaretskii * variable.c (try_variable_definition) [__MSDOS__, WINDOWS32]: Treat "override SHELL=" the same as just "SHELL=". 1999-07-09 Paul D. Smith * job.c (start_waiting_job): Don't get a second job token if we already have one; if we're waiting on the load to go down start_waiting_job() might get called twice on the same file. * filedef.h (struct file): Add new field, mtime_before_update. When notice_finished_file runs it assigns the cached last_mtime to this field. * remake.c (update_goal_chain): Notice that a file wasn't updated by asking if it changed (g->changed) and comparing the current cached time (last_mtime) with the previous one, stored in mtime_before_update. The previous check ("did last_mtime changed during the run of update_file?") fails for parallel builds because last_mtime is set during reap_children, before update_file is run. This causes update_goal_chain to always return -1 (nothing rebuilt) when running parallel (-jN). This is OK during "normal" builds since our caller (main) treats these cases identically in that case, but if when rebuilding makefiles the difference is very important, as it controls whether we re-exec or not. * file.c (file_hash_enter): Copy the mtime_before_update field. (snap_deps): Initialize mtime_before_update to -1. * main.c (main): Initialize mtime_before_update on old (-o) and new (-W) files. 1999-07-08 Paul D. Smith * main.c (switches): Define a new switch -R (or --no-builtin-variables). This option disables the defining of all the GNU make builtin variables. (main): If -R was given, force -r as well. * default.c (define_default_variables): Test the new flag. * make.h: Declare global flag. * make.texinfo (Options Summary): Document the new option. (Implicit Variables): Ditto. 1999-07-06 Paul D. Smith * make.texinfo (Options Summary): Correct examples in --print-data-base option summary (problem reported by David Morse ). * arscan.c: Add support for archives in Windows (VC++). Frank Libbrecht provided info on how to do this. * NMakefile.template (CFLAGS_any): Remove NO_ARCHIVES from the compile line. * build_w32.bat: Ditto. * remake.c (no_rule_error): Fix -include/sinclude so it doesn't give errors if you try to -include the same file twice. (updating_makefiles): New variable: we need to know this info in no_rule_error() so we know whether to print an error or not. (update_file_1): Unconditionally call no_rule_error(), don't try to play games with the dontcare flag. 1999-06-14 Paul D. Smith * make.texinfo (Remaking Makefiles): Add a description of how to prevent implicit rule searches for makefiles. * make.1: Remove statement that make continues processing when -v is given. 1999-06-14 Paul D. Smith * read.c (read_makefile): Cast -1 arguments to variable_expand_string() to long. Alexandre Sauve reports that without casts, this breaks on a NEC SUPER-UX SX-4 system (and it's wrong without a cast anyway). Of course, (a) I'd really love to start using function prototypes, and (b) there's a whole slew of issues related to int vs. long and signed vs. unsigned in the length handling of variable buffers, etc. Gross. Needs a complete mucking-out. * expand.c (variable_expand): Ditto. * acinclude.m4 (AC_FUNC_SELECT): Slight enhancement for AIX 3.2 by Lars Hecking . * read.c (get_next_mword): Allow colons to be escaped in target names: fix for regression failure. 1999-04-26 Paul D. Smith * main.c (main): Reset read_makefiles to empty after processing so we get the right error message. 1999-04-25 Paul D. Smith * make.texinfo: Updates to @dircategory and @direntry suggested by Karl Berry . 1999-04-23 Eli Zaretskii * job.c (start_job_command) [__MSDOS__]: Call unblock_sigs before turning off dos_command_running, so child's signals produce the right effect. * commands.c (fatal_error_signal) [__MSDOS__]: Use EXIT_FAILURE instead of 1. 1999-04-18 Eli Zaretskii * configh.dos.template: Update to recognize that version 2.02 of DJGPP contains sys_siglist stuff. 1999-04-14 Paul D. Smith * make.texinfo (Options/Recursion): Document the job server. (Parallel): Tweaks. 1999-04-13 Paul D. Smith Implement a new "job server" feature; the implementation was suggested by Howard Chu . * configure.in (job-server): New disable option for job server support--it's enabled by default. If it works well this will go away. * NEWS: Summarize the new feature. * acconfig.h: New definition MAKE_JOBSERVER if job server support is enabled. * config.h-vms.template: Undef MAKE_JOBSERVER for this port. * config.h.W32.template: Ditto. * config.ami.template: Ditto. * main.c (struct command_switch): Add a new type: int_string. (switches[]) Use int_string for -j if MAKE_JOBSERVER. (init_switches): Initialize the new int_string switch type. (print_usage): New function, extracted from decode_switches(). (decode_switches): Call it. Decode the new int_string switch type. (define_makeflags): Add new int_string switch data to MAKEFLAGS. (job_fds[]) Array to contain the pipe file descriptors. (main): Parse the job_slots_str option results. If necessary, create the pipe and seed it with tokens. Set the non-blocking bit for the read fd. Enable the signal handler for SIGCHLD even if we have a non-hanging wait; it's needed to interrupt the select() in job.c:start_waiting_job(). * make.h: Declare job_fds[]. * job.h (struct child): Add job_token field to store the token for this job (if any). * job.c (reap_children): When a child is fully reaped, release the token back into the pipe. (free_child): If the child to be freed still has a token, put it back. (new_job): Initialize the job_token member. (start_waiting_job): For local jobs, if we're using the pipe, get a token before we check the load, etc. We do this by performing a non-blocking read in a loop. If the read fails, no token is available. Do a select on the fd to wait for a token. We need to re-enable the signal handler for SIGCHLD even if we have a non-hanging waitpid() or wait3(), so that the signal will interrupt the select() and we can wake up to reap children. (child_handler): Re-enable the signal handler. The count is still kept although it's not needed or used unless you don't have waitpid() or wait3(). 1999-04-10 Paul D. Smith * main.c (main): Reset the considered bit on all the makefiles if something failed to update; we need to examine them again if they appear as normal targets in order to get the proper error message. 1999-04-09 Paul D. Smith Performance enhancement from Tim Magill . * remake.c (update_file): If you have large numbers of dependencies and you run in parallel, make can spend considerable time each pass through the graph looking at branches it has already seen. Since we only reap_children() when starting a pass, not in the middle, if a branch has been seen already in that pass nothing interesting can happen until the next pass. So, we toggle a bit saying whether we've seen this target in this pass or not. (update_goal_chain): Initially set the global considered toggle to 1, since all targets initialize their boolean to 0. At the end of each pass, toggle the global considered variable. * filedef.h (struct file): Per-file considered toggle bit. * file.c: New global toggle variable considered. 1999-04-05 Paul D. Smith * arscan.c (ar_scan): Added support for ARFZMAG (compressed archives?) for Digital UNIX C++. Information provided by Patrick E. Krogel . (ar_member_touch): Ditto. 1999-04-03 Paul D. Smith * remake.c (f_mtime): If: a) we found a file and b) we didn't create it and c) it's not marked as an implicit target and d) it is marked as an intermediate target, then it was so marked due to an .INTERMEDIATE special target, but it already existed in the directory. In this case, unset the intermediate flag so we won't delete it when make is done. It feels like it would be cleaner to put this check in update_file_1() but I worry it'll get missed... 1999-04-01 Paul D. Smith * job.c (construct_command_argv_internal): Use bcopy() to copy overlapping strings, rather than strcpy(). ISO C says the latter is undefined. Found this in a bug report from 1996! Ouch! 1999-03-31 Paul D. Smith * read.c (readline): Ignore carriage returns at the end of the line, to allow Windows-y CRLF line terminators. 1999-03-30 Paul D. Smith * configure.in: Don't put build.sh here, since build.sh.in doesn't exist initially. This cause autoreconf and automake to fail when run on a clean CVS checkout. Instead, we create build.sh in the Makefile (see below). * Makefile.am: Remove BUILT_SOURCES; this is no longer relevant. Put those files directly into EXTRA_DIST so they're distributed. Create a local build rule to create build.sh. Create a local maintainer-clean rule to delete all the funky maintainers files. * maintMakefile: Makefile.in depends on README, since automake fails if it doesn't exist. Also don't remove glob/Makefile.in here, as it causes problems. 1999-03-26 Paul D. Smith * configure.in: Substitute GLOBLIB if we need the link the glob/libglob.a library. * Makefile.am (make_LDADD): Use the subst variable GLOBLIB so we don't link the local libglob.a at all if we don't need it. * build.template: Don't compile glob/*.o unless we want globlib. * maintMakefile (build.sh.in): Substitute the glob/*.o files separately. 1999-03-25 Paul D. Smith * make.texinfo: Various typos and additions, pointed out by James G. Sack . 1999-03-22 Paul D. Smith * make.texinfo (Functions): Add a new section documenting the new $(error ...) and $(warning ...) functions. Also updated copyright dates. * NEWS: Updated for the new functions. * function.c (func_error): Implement the new $(error ...) and $(warning ...) functions. (function_table): Insert new functions into the table. (func_firstword): Don't call find_next_token() with argv[0] itself, since that function modifies the pointer. * function.c: Cleanups and slight changes to the new method of calling functions. 1999-03-20 Han-Wen Nienhuys * function.c: Rewrite to use one C function per make function, instead of a huge switch statement. Also allows some cleanup of multi-architecture issues, and a cleaner API which makes things like func_apply() simple. * function.c (func_apply): Initial implementation. Expand either a builtin function or a make variable in the context of some arguments, provided as $1, $2, ... $N. 1999-03-19 Eli Zaretskii 1999-03-19 Rob Tulloh * job.c (construct_command_argv_internal): Don't treat _all_ backslashes as escapes, only those which really escape a special character. This allows most normal "\" directory separators to be treated normally. 1999-03-05 Paul D. Smith * configure.in: Check for a system strdup(). * misc.c (xstrdup): Created. Suggestion by Han-Wen Nienhuys . * make.h: Prototype xstrdup(). * remake.c (library_search): Use it. * main.c (main): Use it. (find_and_set_default_shell): Use it. * job.c (construct_command_argv_internal): Use it. * dir.c (find_directory): Use it. * Makefile.am, configure.in: Use AC_SUBST_FILE to insert the maintMakefile instead of "include", to avoid automake 1.4 incompatibility. 1999-03-04 Paul D. Smith * amiga.c, amiga.h, ar.c, arscan.c, commands.c, commands.h, * default.c, dep.h, dir.c, expand.c, file.c, filedef.h, function.c, * implicit.c, job.c, job.h, main.c, make.h, misc.c, read.c, remake.c * remote-cstms.c, remote-stub.c, rule.h, variable.c, variable.h, * vpath.c, Makefile.ami, NMakefile.template, build.template, * makefile.vms: Updated FSF address in the copyright notice. * variable.c (try_variable_definition): If we see a conditional variable and we decide to set it, re-type it as recursive so it will be expanded properly later. 1999-02-22 Paul D. Smith * NEWS: Mention new .LIBPATTERNS feature. * make.texinfo (Libraries/Search): Describe the use and ramifications of the new .LIBPATTERNS variable. * remake.c (library_search): Instead of searching only for the hardcoded expansion "libX.a" for a library reference "-lX", we obtain a list of patterns from the .LIBPATTERNS variable and search those in order. * default.c: Added a new default variable .LIBPATTERNS. The default for UNIX is "lib%.so lib%.a". Amiga and DOS values are also provided. * read.c: Remove bogus HAVE_GLOB_H references; always include vanilla glob.h. 1999-02-21 Paul D. Smith * function.c (expand_function): Set value to 0 to avoid freeing it. * variable.c (pop_variable_scope): Free the value of the variable. (try_variable_definition): For simple variables, use allocated_variable_expand() to avoid stomping on the variable buffer when we still need it for other things. * arscan.c: Modified to support AIX 4.3 big archives. The changes are based on information provided by Phil Adams . 1999-02-19 Paul D. Smith * configure.in: Check to see if the GNU glob library is already installed on the system. If so, _don't_ add -I./glob to the compile line. Using the system glob code with the local headers is very bad mojo! Rewrite SCCS macros to use more autoconf facilities. * Makefile.am: Move -Iglob out of INCLUDES; it'll get added to CPPFLAGS by configure now. Automake 1.4 introduced its own "include" feature which conflicts with the maintMakefile stuff. A hack that seems to work is add a space before the include :-/. * build.template: Move -Iglob out of the compile line; it'll get added to CPPFLAGS by configure now. 1999-02-16 Glenn D. Wolf * arscan.c (ar_scan) [VMS]: Initialized VMS_member_date before calling lbr$get_index since if the archive is empty, VMS_get_member_info won't get called at all, and any leftover date will be used. This bug shows up if any member of any archive is made, followed by a dependency check on a different, empty archive. 1998-12-13 Martin Zinser * config.h-vms [VMS]: Set _POSIX_C_SOURCE. Redefine the getopt functions so we don't use the broken VMS versions. * makefile.com [VMS]: Allow debugging. * dir.c (dir_setup_glob) [VMS]: Don't extern stat() on VMS. 1998-11-30 Paul D. Smith * signame.c (init_sig): Check the sizes of signals being set up to avoid array overwrites (if the system headers have problems). 1998-11-17 Paul D. Smith * read.c (record_files): Clean up some indentation. 1998-11-08 Han-Wen Nienhuys * rule.c (print_rule_data_base): Fix arguments to fatal() call. 1998-10-13 Paul D. Smith * job.c (start_job_command): If the command list resolves to no chars at all (e.g.: "foo:;$(empty)") then command_ptr is NULL; quit early. 1998-10-12 Andreas Schwab * rule.c (print_rule_data_base): Ignore num_pattern_rules if it is zero. 1998-10-09 Paul D. Smith * read.c (read_makefile): Allow non-empty lines to expand to the empty string after variable, etc., expansion, and be ignored. 1998-09-21 Paul D. Smith * job.c (construct_command_argv_internal): Only add COMMAND.COM "@echo off" line for non-UNIXy shells. 1998-09-09 Paul D. Smith * w32/subproc/sub_proc.c: Add in missing HAVE_MKS_SHELL tests. 1998-09-04 Paul D. Smith * read.c (read_makefile): If we hit the "missing separator" error, check for the common case of 8 spaces instead of a TAB and give an extra comment to help people out. 1998-08-29 Paul Eggert * configure.in (AC_STRUCT_ST_MTIM_NSEC): Renamed from AC_STRUCT_ST_MTIM. * acinclude.m4 (AC_STRUCT_ST_MTIM_NSEC): Likewise. Port to UnixWare 2.1.2 and pedantic Solaris 2.6. * acconfig.h (ST_MTIM_NSEC): Renamed from HAVE_ST_MTIM, with a new meaning. * filedef.h (FILE_TIMESTAMP_FROM_S_AND_NS): Use new ST_MTIM_NSEC macro. 1998-08-26 Paul D. Smith * remake.c (check_dep): For any intermediate file, not just secondary ones, try implicit and default rules if no explicit rules are given. I'm not sure why this was restricted to secondary rules in the first place. 1998-08-24 Paul D. Smith * make.texinfo (Special Targets): Update documentation for .INTERMEDIATE: if used with no dependencies, then it does nothing; old docs said it marked all targets as intermediate, which it didn't... and which would be silly :). * implicit.c (pattern_search): If we find a dependency in our internal tables, make sure it's not marked intermediate before accepting it as a found_file[]. 1998-08-20 Paul D. Smith * ar.c (ar_glob): Use existing alpha_compare() with qsort. (ar_glob_alphacompare): Remove it. Modify Paul Eggert's patch so we don't abandon older systems: * configure.in: Warn the user if neither waitpid() nor wait3() is available. * job.c (WAIT_NOHANG): Don't syntax error on ancient hosts. (child_handler, dead_children): Define these if WAIT_NOHANG is not available. (reap_children): Only track the dead_children count if no WAIT_NOHANG. Otherwise, it's a boolean. * main.c (main): Add back signal handler if no WAIT_NOHANG is available; only use default signal handler if it is. 1998-08-20 Paul Eggert Install a more robust signal handling mechanism for systems which support it. * job.c (WAIT_NOHANG): Define to a syntax error if our host is truly ancient; this should never happen. (child_handler, dead_children): Remove. (reap_children): Don't try to keep separate track of how many dead children we have, as this is too bug-prone. Just ask the OS instead. (vmsHandleChildTerm): Fix typo in error message; don't mention child_handler. * main.c (main): Make sure we're not ignoring SIGCHLD/SIGCLD; do this early, before we could possibly create a subprocess. Just use the default behavior; don't have our own handler. 1998-08-18 Eli Zaretskii * read.c (read_makefile) [__MSDOS__, WINDOWS32]: Add code to recognize library archive members when dealing with drive spec mess. Discovery and initial fix by George Racz . 1998-08-18 Paul D. Smith * configure.in: Check for stdlib.h explicitly (some hosts have it but don't have STDC_HEADERS). * make.h: Use HAVE_STDLIB_H. Clean up some #defines. * config.ami: Re-compute based on new config.h.in contents. * config.h-vms: Ditto. * config.h.W32: Ditto. * configh.dos: Ditto. * dir.c (find_directory) [WINDOWS32]: Windows stat() fails if directory names end with `\' so strip it. 1998-08-17 Paul D. Smith * make.texinfo: Added copyright year to the printed copy. Removed the price from the manual. Change the top-level reference to running make to be "Invoking make" instead of "make Invocation", to comply with GNU doc standards. * make.h (__format__, __printf__): Added support for these in __attribute__ macro. (message, error, fatal): Use ... prototype form under __STDC__. Add __format__ attributes for printf-style functions. * configure.in (AC_FUNC_VPRINTF): Check for vprintf()/_doprnt(). * misc.c (message, error, fatal): Add preprocessor stuff to enable creation of variable-argument functions with appropriate prototypes, that works with ANSI, pre-ANSI, varargs.h, stdarg.h, v*printf(), _doprnt(), or none of the above. Culled from GNU fileutils and slightly modified. (makefile_error, makefile_error): Removed (merged into error() and fatal(), respectively). * amiga.c: Use them. * ar.c: Use them. * arscan.c: Use them. * commands.c: Use them. * expand.c: Use them. * file.c: Use them. * function.c: Use them. * job.c: Use them. * main.c: Use them. * misc.c: Use them. * read.c: Use them. * remake.c: Use them. * remote-cstms.c: Use them. * rule.c: Use them. * variable.c: Use them. * make.h (struct floc): New structure to store file location information. * commands.h (struct commands): Use it. * variable.c (try_variable_definition): Use it. * commands.c: Use it. * default.c: Use it. * file.c: Use it. * function.c: Use it. * misc.c: Use it. * read.c: Use it. * rule.c: Use it. 1998-08-16 Paul Eggert * filedef.h (FILE_TIMESTAMP_PRINT_LEN_BOUND): Add 10, for nanoseconds. 1998-08-16 Paul Eggert * filedef.h (FLOOR_LOG2_SECONDS_PER_YEAR): New macro. (FILE_TIMESTAMP_PRINT_LEN_BOUND): Tighten bound, and try to make it easier to understand. 1998-08-14 Paul D. Smith * read.c (read_makefile): We've already unquoted any colon chars by the time we're done reading the targets, so arrange for parse_file_seq() on the target list to not do so again. 1998-08-05 Paul D. Smith * configure.in: Added glob/configure.in data. We'll have the glob code include the regular make config.h, rather than creating its own. * getloadavg.c (main): Change return type to int. 1998-08-01 Paul Eggert * job.c (reap_children): Ignore unknown children. 1998-07-31 Paul D. Smith * make.h, filedef.h, dep.h, rule.h, commands.h, remake.c: Add prototypes for functions. Some prototypes needed to be moved in order to get #include order reasonable. 1998-07-30 Paul D. Smith * make.h: Added MIN/MAX. * filedef.h: Use them; remove FILE_TIMESTAMP_MIN. 1998-07-30 Paul Eggert Add support for sub-second timestamp resolution on hosts that support it (just Solaris 2.6, so far). * acconfig.h (HAVE_ST_MTIM, uintmax_t): New undefs. * acinclude.m4 (jm_AC_HEADER_INTTYPES_H, AC_STRUCT_ST_MTIM, jm_AC_TYPE_UINTMAX_T): New defuns. * commands.c (delete_target): Convert file timestamp to seconds before comparing to archive timestamp. Extract mod time from struct stat using FILE_TIMESTAMP_STAT_MODTIME. * configure.in (C_STRUCT_ST_MTIM, jm_AC_TYPE_UINTMAX_T): Add. (AC_CHECK_LIB, AC_CHECK_FUNCS): Add clock_gettime. * file.c (snap_deps): Use FILE_TIMESTAMP, not time_t. (file_timestamp_now, file_timestamp_sprintf): New functions. (print_file): Print file timestamps as FILE_TIMESTAMP, not time_t. * filedef.h: Include if available and if HAVE_ST_MTIM. (FILE_TIMESTAMP, FILE_TIMESTAMP_STAT_MODTIME, FILE_TIMESTAMP_MIN, FILE_TIMESTAMPS_PER_S, FILE_TIMESTAMP_FROM_S_AND_NS, FILE_TIMESTAMP_DIV, FILE_TIMESTAMP_MOD, FILE_TIMESTAMP_S, FILE_TIMESTAMP_NS, FILE_TIMESTAMP_PRINT_LEN_BOUND): New macros. (file_timestamp_now, file_timestamp_sprintf): New decls. (struct file.last_mtime, f_mtime, file_mtime_1, NEW_MTIME): time_t -> FILE_TIMESTAMP. * implicit.c (pattern_search): Likewise. * vpath.c (vpath_search, selective_vpath_search): Likewise. * main.c (main): Likewise. * remake.c (check_dep, name_mtime, library_search, f_mtime): Likewise. (f_mtime): Use file_timestamp_now instead of `time'. Print file timestamp with file_timestamp_sprintf. * vpath.c (selective_vpath_search): Extract file time stamp from struct stat with FILE_TIMESTAMP_STAT_MODTIME. 1998-07-28 Paul D. Smith * Version 3.77 released. * dosbuild.bat: Change to DOS CRLF line terminators. * make-stds.texi: Update from latest version. * make.texinfo (Options Summary): Clarify that the -r option affects only rules, not builtin variables. 1998-07-27 Paul D. Smith * make.h: Make __attribute__ resolve to empty for non-GCC _and_ for GCC pre-2.5.x. * misc.c (log_access): Print UID/GID's as unsigned long int for maximum portability. * job.c (reap_children): Print PIDs as long int for maximum portability. 1998-07-24 Eli Zaretskii * Makefile.DOS (*_INSTALL, *_UNINSTALL): Replace `true' with `:'. 1998-07-25 Paul D. Smith * Version 3.76.94 released. 1998-07-23 Paul D. Smith * config.h.W32.template: Make sure all the #defines of macros here have a value (e.g., use ``#define HAVE_STRING_H 1'' instead of just ``#define HAVE_STRING_H''. Keeps the preprocessor happy in some contexts. * make.h: Remove __attribute__((format...)) stuff; using it with un-prototyped functions causes older GCC's to fail. * Version 3.76.93 released. 1998-07-22 Paul D. Smith * file.c (print_file_data_base): Fix average calculation. 1998-07-20 Paul D. Smith * main.c (die): Postpone the chdir() until after remove_intermediates() so that intermediate targets with relative pathnames are removed properly. 1998-07-17 Paul D. Smith * filedef.h (struct file): New flag: did we print an error or not? * remake.c (no_rule_error): New function to print error messages, extraced from remake_file(). * remake.c (remake_file): Invoke the new error print function. (update_file_1): Invoke the error print function if we see that we already tried this target and it failed, but that an error wasn't printed for it. This can happen if a file is included with -include or sinclude and couldn't be built, then later is also the dependency of another target. Without this change, make just silently stops :-/. 1998-07-16 Paul D. Smith * make.texinfo: Removed "beta" version designator. Updated ISBN for the next printing. 1998-07-13 Paul Eggert * acinclude.m4: New AC_LFS macro to determine if special compiler flags are needed to allow access to large files (e.g., Solaris 2.6). * configure.in: Invoke it. 1998-07-08 Eli Zaretskii * Makefile.DOS: track changes in Makefile.in. 1998-07-07 Paul D. Smith * remote-cstms.c (start_remote_job): Move gethostbyaddr() to the top so host is initialized early enough. * acinclude.m4: New file. Need some special autoconf macros to check for network libraries (-lsocket, -lnsl, etc.) when configuring Customs. * configure.in (make_try_customs): Invoke new network libs macro. 1998-07-06 Paul D. Smith * Version 3.76.92 released. * README.customs: Added to the distribution. * configure.in (make_try_customs): Rewrite to require an installed Customs library, rather than looking at the build directory. * Makefile.am (man_MANS): Install make.1. * make.1: Renamed from make.man. * make.texinfo (Bugs): New mailing list address for GNU make bug reports. 1998-07-02 Paul D. Smith * Version 3.76.91 released. * default.c: Added default rule for new-style RCS master file storage; ``% :: RCS/%''. Added default rules for DOS-style C++ files with suffix ".cpp". They use the new LINK.cpp and COMPILE.cpp macros, which are set by default to be equal to LINK.cc and COMPILE.cc. 1998-06-19 Eli Zaretskii * job.c (start_job_command): Reset execute_by_shell after an empty command was skipped. 1998-06-09 Paul D. Smith * main.c (main): Keep track of the temporary filename created when reading a makefile from stdin (-f-) and attempt to remove it as soon as we know we're not going to re-exec. If we are, add it to the exec'd make's cmd line with "-o" so the exec'd make doesn't try to rebuild it. We still have a hole: if make re-execs then the temporary file will never be removed. To fix this we'd need a brand new option that meant "really delete this". * AUTHORS, getopt.c, getopt1.c, getopt.h, main.c (print_version): Updated mailing addresses. 1998-06-08 Paul D. Smith * main.c (main): Andreas Luik points out that the check for makefile :: rules with commands but no dependencies causing a loop terminates incorrectly. * maintMakefile: Make a template for README.DOS to update version numbers. 1998-05-30 Andreas Schwab * remake.c (update_file_1): Don't free the memory for the dependency structure when dropping a circular dependency. 1998-05-30 Eli Zaretskii * dir.c (file_exists_p, file_impossible_p, file_impossible) [__MSDOS__, WINDOWS32]: Retain trailing slash in "d:/", and make dirname of "d:foo" be "d:". 1998-05-26 Andreas Schwab * read.c (read_makefile): Avoid running past EOS when scanning file name after `include'. 1998-05-26 Andreas Schwab * make.texinfo (Flavors): Correct description of conditional assignment, which is not equivalent to ifndef. (Setting): Likewise. 1998-05-24 Paul D. Smith * arscan.c (ar_name_equal): strncmp() might be implemented as a macro, so don't put preprocessor conditions inside the arguments list. 1998-05-23 Eli Zaretskii * read.c (read_makefile) [__MSDOS__, WINDOWS32]: Skip colons in drive specs when parsing targets, target-specific variables and static pattern rules. A colon can only be part of drive spec if it is after the first letter in a token. 1998-05-22 Eli Zaretskii * remake.c (f_mtime) [__MSDOS__]: Allow up to 3 sec of skew before yelling bloody murder. * dosbuild.bat: Use -DINCLUDEDIR= and -DLIBDIR= where appropriate. * read.c (parse_file_seq): Combine the special file-handling code for WINDOWS32 and __MSDOS__ into a single snippet. (get_next_mword) [__MSDOS__, WINDOWS32]: Allow a word to include a colon as part of a drive spec. * job.c (batch_mode_shell) [__MSDOS__]: Declare. 1998-05-20 Paul D. Smith * Version 3.76.90 released. 1998-05-19 Paul D. Smith * make.texinfo (Make Errors): Added a new appendix describing common errors make might generate and how to resolve them (or at least more information on what they mean). * maintMakefile (NMAKEFILES): Use the new automake 1.3 feature to create a dependency file to construct Makefile.DOS, SMakefile, and NMakefile. (.dep_segment): Generate the dependency fragment file. 1998-05-14 Paul D. Smith * make.man: Minor changes. 1998-05-13 Paul D. Smith * function.c (pattern_matches,expand_function): Change variables and types named "word" to something else, to avoid compilation problems on Cray C90 Unicos. * variable.h: Modify the function prototype. 1998-05-11 Rob Tulloh * job.c (construct_command_argv_internal) [WINDOWS32]: Turn off echo when using a batch file, and make sure the command ends in a newline. 1998-05-03 Paul D. Smith * configure.in (make_try_customs): Add some customs flags if the user configures custom support. * job.c, remote-cstms.c: Merge in changes for custom library. * remote-stub.c: Add option to stub start_remote_job_p(). 1998-05-01 Paul D. Smith * remake.c (f_mtime): Install VPATH+ handling for archives; use the hname field instead of the name field, and rehash when appropriate. 1998-04-30 Paul D. Smith * rule.c (print_rule_data_base): Print out any pattern-specific variable values into the rules database. * variable.c (print_variable_set): Make this variable extern, to be called by print_rule_data_base() for pattern-specific variables. * make.texinfo (Pattern-specific): Document pattern-specific variables. 1998-04-29 Paul D. Smith * expand.c (variable_expand_for_file): Make static; its only called internally. Look up this target in the list of pattern-specific variables and insert the variable set into the queue to be searched. * filedef.h (struct file): Add a new field to hold the previously-found pattern-specific variable reference. Add a new flag to remember whether we already searched for this file. * rule.h (struct pattern_var): New structure for storing pattern-specific variable values. Define new function prototypes. * rule.c: New variables pattern_vars and last_pattern_var for storage and handling of pattern-specific variable values. (create_pattern_var): Create a new pattern-specific variable value structure. (lookup_pattern_var): Try to match a target to one of the pattern-specific variable values. 1998-04-22 Paul D. Smith * make.texinfo (Target-specific): Document target-specific variables. 1998-04-21 Paul D. Smith * variable.c (define_variable_in_set): Made globally visible. (lookup_variable_in_set): New function: like lookup_variable but look only in a specific variable set. (target_environment): Use lookup_variable_in_set() to get the correct export rules for a target-specific variable. (create_new_variable_set): Create a new variable set, and just return it without installing it anywhere. (push_new_variable_scope): Reimplement in terms of create_new_variable_set. * read.c (record_target_var): Like record_files, but instead of files create a target-specific variable value for each of the listed targets. Invoked from read_makefile() when the target line turns out to be a target-specific variable assignment. 1998-04-19 Paul D. Smith * read.c (read_makefile): Rewrite the entire target parsing section to implement target-specific variables. In particular, we cannot expand the entire line as soon as it's read in, since we may want to evaluate parts of it with different variable contexts active. Instead, start expanding from the beginning until we find the `:' (or `::'), then determine what kind of line this is and continue appropriately. * read.c (get_next_mword): New function to parse a makefile line by "words", considering an entire variable or function as one word. Return the type read in, along with its starting position and length. (enum make_word_type): The types of words that are recognized by get_next_mword(). * variable.h (struct variable): Add a flag to specify a per-target variable. * expand.c: Make variable_buffer global. We need this during the new parsing of the makefile. (variable_expand_string): New function. Like variable_expand(), but start at a specific point in the buffer, not the beginning. (variable_expand): Rewrite to simply call variable_expand_string(). 1998-04-13 Paul D. Smith * remake.c (update_goal_chain): Allow the rebuilding makefiles step to use parallel jobs. Not sure why this was disabled: hopefully we won't find out :-/. 1998-04-11 Paul D. Smith * main.c (main): Set the CURDIR makefile variable. * make.texinfo (Recursion): Document it. 1998-03-17 Paul D. Smith * misc.c (makefile_fatal): If FILE is nil, invoke plain fatal(). * variable.c (try_variable_definition): Use new feature. 1998-03-10 Paul D. Smith * main.c (main): Don't pass included, rebuilt makefiles to re-exec'd makes with -o. Reopens a possible loop, but it caused too many problems. 1998-03-02 Paul D. Smith * variable.c (try_variable_definition): Implement ?=. * make.texinfo (Setting): Document it. 1998-02-28 Eli Zaretskii * job.c (start_job_command): Reset execute_by_shell after an empty command, like ":", has been seen. Tue Oct 07 15:00:00 1997 Phil Brooks * make.h [WINDOWS32]: make case sensitivity configurable * dir.c [WINDOWS32]: make case sensitivity configurable * README.W32: Document case sensitivity * config.ami: Share case warping code with Windows Mon Oct 6 18:48:45 CDT 1997 Rob Tulloh * w32/subproc/sub_proc.c: Added support for MKS toolkit shell (turn on HAVE_MKS_SHELL). * read.c [WINDOWS32]: Fixed a problem with multiple target rules reported by Gilbert Catipon (gcatipon@tibco.com). If multiple path tokens in a rule did not have drive letters, make would incorrectly concatenate the 2 tokens together. * main.c/variable.c [WINDOWS32]: changed SHELL detection code to follow what MSDOS did. In addition to watching for SHELL variable updates, make's main will attempt to default the value of SHELL before and after makefiles are parsed. * job.c/job.h [WINDOWS32]: The latest changes made to enable use of the GNUWIN32 shell from make could cause make to fail due to a concurrency condition between parent and child processes. Make now creates a batch file per job instead of trying to reuse the same singleton batch file. * job.c/job.h/function.c/config.h.W32 [WINDOWS32]: Renamed macro from HAVE_CYGNUS_GNUWIN32_TOOLS to BATCH_MODE_ONLY_SHELL. Reworked logic to reduce complexity. WINDOWS32 now uses the unixy_shell variable to detect Bourne-shell compatible environments. There is also a batch_mode_shell variable that determines whether not command lines should be executed via script files. A WINDOWS32 system with no sh.exe installed would have unixy_shell set to FALSE and batch_mode_shell set to TRUE. If you have a unixy shell that does not behave well when invoking things via 'sh -c xxx', you may want to turn on BATCH_MODE_ONLY_SHELL and see if things improve. * NMakefile: Added /D DEBUG to debug build flags so that unhandled exceptions could be debugged. Mon Oct 6 00:04:25 1997 Rob Tulloh * main.c [WINDOWS32]: The function define_variable() does not handle NULL. Test before calling it to set Path. * main.c [WINDOWS32]: Search Path again after makefiles have been parsed to detect sh.exe. * job.c [WINDOWS32]: Added support for Cygnus GNU WIN32 tools. To use, turn on HAVE_CYGNUS_GNUWIN32_TOOLS in config.h.W32. * config.h.W32: Added HAVE_CYGNUS_GNUWIN32_TOOLS macro. Sun Oct 5 22:43:59 1997 John W. Eaton * glob/glob.c (glob_in_dir) [VMS]: Globbing shouldn't be case-sensitive. * job.c (child_execute_job) [VMS]: Use a VMS .com file if the command contains a newline (e.g. from a define/enddef block). * vmsify.c (vmsify): Return relative pathnames wherever possible. * vmsify.c (vmsify): An input string like "../.." returns "[--]". Wed Oct 1 15:45:09 1997 Rob Tulloh * NMakefile: Changed nmake to $(MAKE). * subproc.bat: Take the make command name from the command line. If no command name was given, default to nmake. * job.c [MSDOS, WINDOWS32]: Fix memory stomp: temporary file names are now always created in heap memory. * w32/subproc/sub_proc.c: New implementation of make_command_line() which is more compatible with different Bourne shell implementations. Deleted the now obsolete fix_command_line() function. * main.c [WINDOWS32]: Any arbitrary spelling of Path can be detected. Make will ensure that the special spelling `Path' is inserted into the environment when the path variable is propagated within itself and to make's children. * main.c [WINDOWS32]: Detection of sh.exe was occurring too soon. The 2nd check for the existence of sh.exe must come after the call to read_all_makefiles(). Fri Sep 26 01:14:18 1997 * makefile.com [VMS]: Fixed definition of sys. * readme.vms: Comments on what's changed lately. Fri Sep 26 01:14:18 1997 John W. Eaton * read.c (read_all_makefiles): Allow make to find files named "MAKEFILE" with no extension on VMS. * file.c (lookup_file): Lowercase filenames on VMS. 1997-09-29 Paul D. Smith * read.c (read_makefile): Reworked target detection again; the old version had an obscure quirk. Fri Sep 19 09:20:49 1997 Paul D. Smith * Version 3.76.1 released. * Makefile.am: Add loadavg files to clean rules. * configure.in (AC_OUTPUT): Remove stamp-config; no longer needed. * Makefile.ami (distclean): Ditto. * SMakefile (distclean): Ditto. * main.c (main): Arg count should be int, not char! Major braino. Tue Sep 16 10:18:22 1997 Paul D. Smith * Version 3.76 released. Tue Sep 2 10:07:39 1997 Paul D. Smith * function.c (expand_function): When processing $(shell...) translate a CRLF (\r\n) sequence as well as a newline (\n) to a space. Also remove an ending \r\n sequence. * make.texinfo (Shell Function): Document it. Fri Aug 29 12:59:06 1997 Rob Tulloh * w32/pathstuff.c (convert_Path_to_windows32): Fix problem where paths which contain single character entries like `.' are not handled correctly. * README.W32: Document path handling issues on Windows systems. Fri Aug 29 02:01:27 1997 Paul D. Smith * Version 3.75.93. Thu Aug 28 19:39:06 1997 Rob Tulloh * job.c (exec_command) [WINDOWS32]: If exec_command() is invoked from main() to re-exec make, the call to execvp() would incorrectly return control to parent shell before the exec'ed command could run to completion. I believe this is a feature of the way that execvp() is implemented on top of WINDOWS32 APIs. To alleviate the problem, use the supplied process launch function in the sub_proc library and suspend the parent process until the child process has run. When the child exits, exit the parent make with the exit code of the child make. Thu Aug 28 17:04:47 1997 Paul D. Smith * Makefile.DOS.template (distdir): Fix a line that got wrapped in email. * Makefile.am (loadavg): Give the necessary cmdline options when linking loadavg. * configure.in: Check for pstat_getdynamic for getloadvg on HP. * job.c (start_job_command) [VMS, _AMIGA]: Don't perform empty command optimization on these systems; it doesn't make sense. Wed Aug 27 17:09:32 1997 Paul D. Smith * Version 3.75.92 Tue Aug 26 11:59:15 1997 Paul D. Smith * main.c (print_version): Add '97 to copyright years. * read.c (do_define): Check the length of the array before looking at a particular offset. * job.c (construct_command_argv_internal): Examine the last byte of the previous arg, not the byte after that. Sat Aug 23 1997 Eli Zaretskii * Makefile.DOS.template: New file (converted to Makefile.DOS in the distribution). * configure.bat: Rewrite to use Makefile.DOS instead of editing Makefile.in. Add support for building from outside of the source directory. Fail if the environment block is too small. * configh.dos: Use . * README.DOS: Update instructions. Fri Aug 22 1997 Eli Zaretskii * job.c (start_job_command) [__MSDOS__]: Don't test for "/bin/sh" literally, use value of unixy_shell instead. * filedef.h (NEW_MTIME): Use 1 less than maximum possible value if time_t is unsigned. Sat Aug 16 00:56:15 1997 John W. Eaton * vmsify.c (vmsify, case 11): After translating `..' elements, set nstate to N_OPEN if there are still more elements to process. (vmsify, case 2): After translating `foo/bar' up to the slash, set nstate to N_OPEN, not N_DOT. Fri Aug 8 15:18:09 1997 John W. Eaton * dir.c (vmsstat_dir): Leave name unmodified on exit. * make.h (PATH_SEPARATOR_CHAR): Set to comma for VMS. * vpath.c: Fix comments to refer to path separator, not colon. (selective_vpath_search): Avoid Unixy slash handling for VMS. Thu Aug 7 22:24:03 1997 John W. Eaton * ar.c [VMS]: Don't declare ar_member_touch. Delete VMS version of ar_member_date. Enable non-VMS versions of ar_member_date and ar_member_date_1 for VMS too. * arscan.c (VMS_get_member_info): New function. (ar_scan): Provide version for VMS systems. (ar_name_equal): Simply compare name and mem on VMS systems. Don't define ar_member_pos or ar_member_touch on VMS systems. * config.h-vms (pid_t, uid_t): Don't define. * remake.c: Delete declaration of vms_stat. (name_mtime): Don't call vms_stat. (f_mtime) [VMS]: Funky time value manipulation no longer necessary. * file.c (print_file): [VMS] Use ctime, not cvt_time. * make.h [VMS]: Don't define POSIX. * makefile.com (filelist): Include ar and arscan. Also include them in the link commands. Don't define NO_ARCHIVES in cc command. * makefile.vms (ARCHIVES, ARCHIVES_SRC): Uncomment. (defines): Delete NO_ARCHIVES from list. * remake.c (f_mtime): Only check to see if intermediate file is out of date if it also exists (i.e., mtime != (time_t) -1). * vmsdir.h (u_long, u_short): Skip typedefs if using DEC C. Fri Jun 20 23:02:07 1997 Rob Tulloh * w32/subproc/sub_proc.c: Get W32 sub_proc to handle shebang (#!/bin/sh) in script files correctly. Fixed a couple of memory leaks. Fixed search order in find_file() (w32/subproc/sub_proc.c) so that files with extensions are preferred over files without extensions. Added search for files with .cmd extension too. * w32/subproc/misc.c (arr2envblk): Fixed memory leak. Mon Aug 18 09:41:08 1997 Paul D. Smith * Version 3.75.91 Fri Aug 15 13:50:54 1997 Paul D. Smith * read.c (do_define): Remember to count the newline after the endef. Thu Aug 14 23:14:37 1997 Paul D. Smith * many: Rewrote builds to use Automake 1.2. * AUTHORS: New file. * maintMakefile: Contains maintainer-only make snippets. * GNUmakefile: This now only runs the initial auto* tools. * COPYING,texinfo.tex,mkinstalldirs,install-sh: Removed (obtained automatically by automake). * compatMakefile: Removed (not needed anymore). * README,build.sh.in: Removed (built from templates). * config.h.in,Makefile.in: Removed (built by tools). Wed Aug 13 02:22:08 1997 Paul D. Smith * make.texinfo: Updates for DOS/Windows information (Eli Zaretskii) * README,README.DOS: Ditto. * remake.c (update_file_1,f_mtime): Fix GPATH handling. * vpath.c (gpath_search): Ditto. * file.c (rename_file): New function: rehash, but also rename to the hashname. * filedef.h: Declare it. * variable.c (merge_variable_set_lists): Remove free() of variable set; since various files can share variable sets we don't want to free them here. Tue Aug 12 10:51:54 1997 Paul D. Smith * configure.in: Require autoconf 2.12 * make.texinfo: Replace all "cd subdir; $(MAKE)" examples with a more stylistically correct "cd subdir && $(MAKE)". * main.c: Global variable `clock_skew_detected' defined. (main): Print final warning if it's set. * make.h: Declare it. * remake.c (f_mtime): Test and set it. * job.c (start_job_command): Add special optimizations for "do-nothing" rules, containing just the shell no-op ":". This is useful for timestamp files and can make a real difference if you have a lot of them (requested by Fergus Henderson ). * configure.in,Makefile.in: Rewrote to use the new autoconf program_transform_name macro. * function.c (function_strip): Strip newlines as well as spaces and TABs. Fri Jun 6 23:41:04 1997 Rob Tulloh * remake.c (f_mtime): Datestamps on FAT-based files are rounded to even seconds when stored, so if the date check fails on WINDOWS32 systems, see if this "off-by-one" error is the problem. * General: If your TZ environment variable is not set correctly then all your timestamps will be off by hours. So, set it! Mon Apr 7 02:06:22 1997 Paul D. Smith * Version 3.75.1 * compatMakefile (objs): Define & use the $(GLOB) variable so that it's removed correctly from build.sh.in when it's built. * configure.in: On Solaris we can use the kstat_*() functions to get load averages without needing special permissions. Add a check for -lkstat to see if we have it. * getloadavg.c (getloadavg): Use HAVE_LIBKSTAT instead of SUN5 as the test to enable kstat_open(), etc. processing. Fri Apr 4 20:21:18 1997 Eli Zaretskii * : Fixes to work in the DJGPP DOS environment. Mon Mar 31 02:42:52 1997 Paul D. Smith * function.c (expand_function): Added new function $(wordlist). * make.texinfo (Filename Functions): Document $(wordlist) function. * vpath.c (build_vpath_lists): Construct the GPATH variable information in the same manner we used to construct VPATH. (gpath_search): New function to search GPATH. * make.h: Declare the new function. * remake.c (update_file_1): Call it, and keep VPATH if it's found. * make.texinfo (Search Algorithm): Document GPATH variable. Sun Mar 30 20:57:16 1997 Paul D. Smith * main.c (handle_non_switch_argument): Defined the MAKECMDGOALS variable to contain the user options passed in on the cmd line. * make.texinfo (Goals): Document MAKECMDGOALS variable. * remake.c (f_mtime): Print a warning if we detect a clock skew error, rather than failing. * main.c (main): If we rebuild any makefiles and need to re-exec, add "-o" options for each makefile rebuilt to avoid infinite looping. Fri Mar 28 15:26:05 1997 Paul D. Smith * job.c (construct_command_argv_internal): Track whether the last arg in the cmd string was empty or not (Roland). (construct_command_argv_internal): If the shell line is empty, don't do anything (Roland). * glob/glob.h,glob/glob.c,glob/fnmatch.c,glob/fnmatch.h: Install the latest changes from the GLIBC version of glob (Ulrich Drepper). * getloadavg.c,make-stds.texi: New version (Roland). * (ALL): Changed WIN32 to W32 or WINDOWS32 (RMS). Mon Mar 24 15:33:34 1997 Rob Tulloh * README.W32: Describe preliminary FAT support. * build_w32.bat: Use a variable for the final exe name. * dir.c (find_directory): W32: Find the filesystem type. (dir_contents_file_exists_p): W32: for FAT filesystems, always rehash since FAT doesn't change directory mtime on change. * main.c (handle_runtime_exceptions): W32: Add an UnhandledExceptionFilter so that when make bombs due to ^C or a bug, it won't cause a GUI requestor to pop up unless debug is turned on. (main): Call it. Mon Mar 24 00:57:34 1997 Paul D. Smith * configure.in, config.h.in, config.ami, config.h-vms, config.h.w32: Check for memmove() function. * make.h (bcopy): If memmove() available, define bcopy() to use it. Otherwise just use bcopy(). Don't use memcpy(); it's not guaranteed to handle overlapping moves. * read.c (read_makefile): Fix some uninitialized memory reads (reported by Purify). * job.c (construct_command_argv_internal): Use bcopy() not strcpy(); strcpy() isn't guaranteed to handle overlapping moves. * Makefile.in: Change install-info option ``--infodir'' to ``--info-dir'' for use with new texinfo. * function.c (expand_function): $(basename) and $(suffix) should only search for suffixes as far back as the last directory (e.g., only the final filename in the path). Sun Mar 23 00:13:05 1997 Paul D. Smith * make.texinfo: Add @dircategory/@direntry information. (Top): Remove previous reference to (dir) (from RMS). (Static Usage): Add "all:" rule to example. (Automatic Dependencies): fix .d file creation example. * Install VPATH+ patch: * filedef.h (struct file): Add in hname field to store the hashed filename, and a flag to remember if we're using the vpath filename or not. Renamed a few functions for more clarity. * file.c (lookup_file,enter_file,file_hash_enter): Store filenames in the hash table based on their "hash name". We can change this while keeping the original target in "name". (rehash_file): Renamed from "rename_file" to be more accurate. Changes the hash name, but not the target name. * remake.c (update_file_1): Modify -d output for more detailed VPATH info. If we don't need to rebuild, use the VPATH name. (f_mtime): Don't search for vpath if we're ignoring it. Call renamed function rehash_file. Call name_mtime instead of file_mtime, to avoid infinite recursion since the file wasn't actually renamed. * implicit.c (pattern_search): if we find an implicit file in VPATH, save the original name not the VPATH name. * make.texinfo (Directory Search): Add a section on the new VPATH functionality. Sun Dec 1 18:36:04 1996 Andreas Schwab * dir.c (file_exists_p, file_impossible, file_impossible_p): If dirname is empty replace it by the name of the root directory. Note that this doesn't work (yet) for W32, Amiga, or VMS. Tue Oct 08 13:57:03 1996 Rob Tulloh * main.c (main): W32 bug fix for PATH vars. Tue Sep 17 1996 Paul Eggert * filedef.h (NEW_MTIME): Don't assume that time_t is a signed 32-bit quantity. * make.h: (CHAR_BIT, INTEGER_TYPE_SIGNED, INTEGER_TYPE_MAXIMUM, INTEGER_TYPE_MINIMUM): New macros. Tue Aug 27 01:06:34 1996 Roland McGrath * Version 3.75 released. * main.c (print_version): Print out bug-reporting address. Mon Aug 26 19:55:47 1996 Roland McGrath * main.c (print_data_base): Don't declare ctime; headers do it for us already. Sun Jul 28 15:37:09 1996 Rob Tulloh (tulloh@tivoli.com) * w32/pathstuff.c: Turned convert_vpath_to_w32() into a real function. This was done so that VPATH could contain white space separated pathnames. Please note that directory paths (in VPATH/vpath context) containing white space are not supported (just as they are not under Unix). See README.W32 for suggestions. * w32/include/pathstuff.h: Added prototype for the new function convert_vpath_to_w32. Deleted macro for same. * README.W32: Added some notes about why I chose not to try and support pathnames which contain white space and some workaround suggestions. Thu Jul 25 19:53:31 1996 Roland McGrath * GNUmakefile (mkdep-nolib): Use -MM option unconditionally. * Version 3.74.7. * main.c (define_makeflags): Back up P to point at null terminator when killing final space and dash before setting MFLAGS. From Robert Hoehne : * dir.c [__MSDOS__ && DJGPP > 1]: Include and defin `__opendir_flags' initialized to 0. (dosify) [__MSDOS__ && DJGPP > 1]: Return name unchanged if _USE_LFN. (find_directory) [__MSDOS__ && DJGPP > 1]: If _USE_LGN, set __opendir_flags to __OPENDIR_PRESERVE_CASE. * vmsfunctions.c (vms_stat): `sys$dassgn (DevChan);' added by kkaempf. * GNUmakefile (w32files): Add NMakefile. * NMakefile (LDFLAGS_debug): Value fixed by tulloh. Sat Jul 20 12:32:10 1996 Klaus Kmpf (kkaempf@progis.de) * remake.c (f_mtime) [VMS]: Add missing `if' conditional for future modtime check. * config.h-vms, makefile.vms, readme.vms, vmsify.c: Update address. Sat Jul 20 05:29:43 1996 Roland McGrath * configure.in: Require autoconf 2.10 or later. Fri Jul 19 16:57:27 1996 Roland McGrath * Version 3.74.6. * GNUmakefile (w32files): New variable. (distfiles): Add it. * w32: Updated by Rob Tulloh. * makefile.vms (LOADLIBES): Fix typo. Sun Jul 14 12:59:27 1996 Roland McGrath * job.c (construct_command_argv_internal): Fix up #else, #endifs. * configh.dos: Define HAVE_DIRENT_H instead of DIRENT. * remake.c (f_mtime): Don't compare MTIME to NOW if MTIME == -1. * Version 3.74.5. * main.c (main): Exit with status 2 when update_goal_chain returns 2. Sat Jun 22 14:56:05 1996 Roland McGrath * configure.in: Don't check for _sys_siglist. * make.h [HAVE__SYS_SIGLIST]: Don't test this; just punt if there is no strsignal or sys_siglist. * read.c (conditional_line): Strip ws in `ifeq (a , b)' so it is the same as `ifeq (a, b)'. * job.c (reap_children): Don't call die if handling_fatal_signal. * file.c (file_hash_enter): Allow renaming :: to : when latter is non-target, or : to :: when former is non-target. * job.c (start_job_command): Call block_sigs. (block_sigs): New function, broken out of start_job_command. (reap_children): Block fatal signals around removing dead child from chain and adjusting job_slots_used. * job.h: Declare block_sigs. * remote-stub.c (remote_setup, remote_cleanup): New (empty) functions. * main.c (main): Call remote_setup. (die): Call remote_cleanup. * job.c (reap_children): Quiescent value of shell_function_pid is zero, not -1. * main.c (print_version): Add 96 to copyright years. Sat Jun 15 20:30:01 1996 Andreas Schwab * read.c (find_char_unquote): Avoid calling strlen on every call just to throw away the value most of the time. Sun Jun 2 12:24:01 1996 Roland McGrath * main.c (decode_env_switches): Prepend '-' to ARGV[1] if it contains no '=', regardless of ARGC. (define_makeflags): Elide leading '-' from MAKEFLAGS value if first word is short option, regardless of WORDS. Wed May 22 17:24:51 1996 Roland McGrath * makefile.vms: Set LOADLIBES. * makefile.com (link_using_library): Fix typo. Wed May 15 17:37:26 1996 Roland McGrath * dir.c (print_dir_data_base): Use %ld dev and ino and cast them to long. Wed May 15 10:14:14 CDT 1996 Rob Tulloh * dir.c: W32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on W32 right now so it is lumped under port #ifdef WINDOWS32. * function.c: W32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: W32: Added the code to do fork/exec/waitpid style processing on W32 systems via calls to subproc library. * main.c: W32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: W32: A few macros and header files for W32 support. * misc.c: W32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: W32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: W32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on W32. * variable.c: W32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: W32: Added detection for filenames containing forward or backward slashes. * NMakefile: W32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.W32: W32: Contains some helpful notes. * build_w32.bat: W32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.W32: W32 version of config.h * subproc.bat: W32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: W32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: W32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: W32: prototypes for subproc.lib functions. * w32/include/w32err.h: W32: prototypes for w32err.c. * w32/pathstuff.c: W32: File and Path/Path conversion functions. * w32/subproc/build.bat: W32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: W32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: W32: subproc library support code * w32/subproc/proc.h: W32: subproc library support code * w32/subproc/sub_proc.c: W32: subproc library source code * w32/subproc/w32err.c: W32: subproc library support code Mon May 13 14:37:42 1996 Roland McGrath * Version 3.74.4. * GNUmakefile (vmsfiles): Fix typo. * GNUmakefile (amigafiles): Add amiga.h. Sun May 12 19:19:43 1996 Aaron Digulla * dir.c: New function: amigafy() to fold filenames Changes HASH() to HASHI() to fold filenames on Amiga. Stringcompares use strieq() instead of streq() The current directory on Amiga is "" instead of "." * file.c: Likewise. * amiga.c: New function wildcard_expansion(). Allows to use Amiga wildcards with $(wildcard ) * amiga.h: New file. Prototypes for amiga.c * function.c: Use special function wildcard_expansion() for $(wildcard ) to allow Amiga wildcards The current directory on Amiga is "" instead of "." * job.c: No Pipes on Amiga, too (load_too_high) Neither on Amiga ENV variable on Amiga are in a special directory and are not passed as third argument to main(). * job.h: No envp on Amiga * make.h: Added HASHI(). This is the same as HASH() but converts it's second parameter to lowercase on Amiga to fold filenames. * main.c: (main), variable.c Changed handling of ENV-vars. Make stores now the names of the variables only and reads their contents when they are accessed to reflect that these variables are really global (i.e., they CAN change WHILE make runs !) This handling is made in lookup_variable() * Makefile.ami: renamed file.h to filedep.h Updated dependencies * read.c: "find_semicolon" is declared as static but never defined. No difference between Makefile and makefile on Amiga; added SMakefile to *default_makefiles[]. (read_makefile) SAS/C want's two_colon and pattern_percent be set before use. The current directory on Amiga is "" instead of "." Strange #endif moved. * README.Amiga: updated feature list * SMakefile: Updated dependencies * variable.c: Handling of ENV variable happens inside lookup_variable() Sat May 11 17:58:32 1996 Roland McGrath * variable.c (try_variable_definition): Count parens in lhs variable refs to avoid seeing =/:=/+= inside a ref. Thu May 9 13:54:49 1996 Roland McGrath * commands.c (fatal_error_signal) [SIGQUIT]: Make SIGQUIT check conditional. * main.c (main): Use unsigned for fread return. * read.c (parse_file_seq): Use `int' for char arg to avoid widening conflict issues. * dep.h: Fix prototype. * function.c (expand_function) [_AMIGA]: Fix some typos. (patsubst_expand): Make len vars unsigned. * GNUmakefile (globfiles): Add AmigaDOS support files. (distfiles): Add $(amigafiles). (amigafiles): New variable. Thu Nov 7 10:18:16 1995 Aaron Digulla * Added Amiga support in commands.c, dir.c, function.c, job.c, main.c, make.h, read.c, remake.c * commands.c: Amiga has neither SIGHUP nor SIGQUIT * dir.c: Amiga has filenames with Upper- and Lowercase, but "FileName" is the same as "filename". Added strieq() which is use to compare filenames. This is like streq() on all other systems. Also there is no such thing as "." under AmigaDOS. * function.c: On Amiga, the environment is not passed as envp, there are no pipes and Amiga can't fork. Use my own function to create a new child. * job.c: default_shell is "" (The system automatically chooses a shell for me). Have to use the same workaround as MSDOS for running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't known on Amiga. Cloned code to run children from MSDOS. Own version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga. * main.c: Force stack to 20000 bytes. Read environment from ENV: device. On Amiga, exec_command() does return, so I exit() afterwards. * make.h: Added strieq() to compare filenames. * read.c: Amiga needs special extension to have passwd. Only one include-dir. "Makefile" and "makefile" are the same. Added "SMakefile". Added special code to handle device names (xxx:) and "./" in rules. * remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib" instead of "lib%s.a". * main.c, rule.c, variable.c: Avoid floats at all costs. * vpath.c: Get rid of as many alloca()s as possible. Thu May 9 13:20:43 1996 Roland McGrath * read.c (read_makefile): Grok `sinclude' as alias for `-include'. Wed Mar 20 09:52:27 1996 Roland McGrath * GNUmakefile (vmsfiles): New variable. (distfiles): Include $(vmsfiles). Tue Mar 19 20:21:34 1996 Roland McGrath Merged VMS port from Klaus Kaempf . * make.h (PARAMS): New macro. * config.h-vms: New file. * makefile.com: New file. * makefile.vms: New file. * readme.vms: New file. * vmsdir.h: New file. * vmsfunctions.c: New file. * vmsify.c: New file. * file.h: Renamed to filedef.h to avoid conflict with VMS system hdr. * ar.c: Added prototypes and changes for VMS. * commands.c: Likewise. * commands.h: Likewise. * default.c: Likewise. * dep.h: Likewise. * dir.c: Likewise. * expand.c: Likewise. * file.c: Likewise. * function.c: Likewise. * implicit.c: Likewise. * job.c: Likewise. * job.h: Likewise. * main.c: Likewise. * make.h: Likewise. * misc.c: Likewise. * read.c: Likewise. * remake.c: Likewise. * remote-stub.c: Likewise. * rule.c: Likewise. * rule.h: Likewise. * variable.c: Likewise. * variable.h: Likewise. * vpath.c: Likewise. * compatMakefile (srcs): Rename file.h to filedef.h. Sat Aug 19 23:11:00 1995 Richard Stallman * remake.c (check_dep): For a secondary file, try implicit and default rules if appropriate. Wed Aug 2 04:29:42 1995 Richard Stallman * remake.c (check_dep): If an intermediate file exists, do consider its actual date. Sun Jul 30 00:49:53 1995 Richard Stallman * file.h (struct file): New field `secondary'. * file.c (snap_deps): Check for .INTERMEDIATE and .SECONDARY. (remove_intermediates): Don't delete .SECONDARY files. Sat Mar 2 16:26:52 1996 Roland McGrath * compatMakefile (srcs): Add getopt.h; prepend $(srcdir)/ to getopt*. Fri Mar 1 12:04:47 1996 Roland McGrath * Version 3.74.3. * remake.c (f_mtime): Move future modtime check before FILE is clobbered by :: loop. * dir.c: Use canonical code from autoconf manual for dirent include. [_D_NAMLEN]: Redefine NAMLEN using this. (dir_contents_file_exists_p): Use NAMLEN macro. (read_dirstream) [_DIRENT_HAVE_D_NAMLEN]: Only set d_namlen #if this. * compatMakefile (objs): Add missing backslash. Wed Feb 28 03:56:20 1996 Roland McGrath * default.c (default_terminal_rules): Remove + prefix from RCS cmds. (default_variables): Put + prefix in $(CHECKOUT,v) value instead. * remake.c (f_mtime): Check for future timestamps; give error and mark file as "failed to update". Fri Jan 12 18:09:36 1996 Roland McGrath * job.c: Don't declare unblock_sigs; job.h already does. Sat Jan 6 16:24:44 1996 Roland McGrath * acconfig.h (HAVE_SYSCONF_OPEN_MAX): #undef removed. * job.c (NGROUPS_MAX): Don't try to define this macro. Fri Dec 22 18:44:44 1995 Roland McGrath * compatMakefile (GETOPT, GETOPT_SRC, GLOB): Variables removed. (objs, srcs): Include their values here instead of references. Thu Dec 14 06:21:29 1995 Roland McGrath * Version 3.74.2. * job.c (reap_children): Call unblock_sigs after start_job_command. Thu Dec 14 07:22:03 1995 Roland McGrath * dir.c (dir_setup_glob): Don't use lstat; glob never calls it anyway. Avoid & before function names to silence bogus sunos4 compiler. * configure.in: Remove check for `sysconf (_SC_OPEN_MAX)'. Tue Dec 12 00:48:42 1995 Roland McGrath * Version 3.74.1. * dir.c (read_dirstream): Fix braino: fill in the buffer when not reallocating it! Mon Dec 11 22:26:15 1995 Roland McGrath * misc.c (collapse_continuations): Fix skipping of trailing \s so it can never dereference before the beginning of the array. * read.c (find_semicolon): Function removed. (read_makefile): Don't use find_semicolon or remove_comments for rule lines. Use find_char_unquote directly and handle quoted comments properly. * default.c: Remove all [M_XENIX] code. * dir.c [HAVE_D_NAMLEN]: Define this for __GNU_LIBRARY__ > 1. (D_NAMLEN): Macro removed. (FAKE_DIR_ENTRY): New macro. (dir_contents_file_exists_p): Test HAVE_D_NAMLEN instead of using D_NAMLEN. (read_dirstream): Return a struct dirent * for new glob interface. (init_dir): Function removed. (dir_setup_glob): New function. * main.c (main): Don't call init_dir. * read.c (multi_glob): Call dir_setup_glob on our glob_t and use GLOB_ALTDIRFUNC flag. * misc.c (safe_stat): Function removed. * read.c, commands.c, remake.c, vpath.c: Use plain stat instead of safe_stat. Sat Nov 25 20:35:18 1995 Roland McGrath * job.c [HAVE_UNION_WAIT]: Include sys/wait.h. * main.c (log_working_directory): Made global. Print entering msg only once. * make.h (log_working_directory): Declare it. * misc.c (message): Take new arg PREFIX. Print "make: " only if nonzero. Call log_working_directory. * remake.c: Pass new arg in `message' calls. * job.c (start_job_command): Pass new arg to `message'; fix inverted test in that call. Tue Nov 21 19:01:12 1995 Roland McGrath * job.c (start_job_command): Use `message' to print the command, and call it with null if the command is silent. * remake.c (touch_file): Use message instead of printf. Tue Oct 10 14:59:30 1995 Roland McGrath * main.c (enter_command_line_file): Barf if NAME is "". Sat Sep 9 06:33:20 1995 Roland McGrath * commands.c (delete_target): Ignore unlink failure if it is ENOENT. Thu Aug 17 15:08:57 1995 Roland McGrath * configure.in: Don't check for getdtablesize. * job.c (getdtablesize): Remove decls and macros. Thu Aug 10 19:10:03 1995 Roland McGrath * main.c (define_makeflags): Omit command line variable definitions from MFLAGS value. * arscan.c (ar_scan) [AIAMAG]: Check for zero MEMBER_OFFSET, indicating a valid, but empty, archive. Mon Aug 7 15:40:03 1995 Roland McGrath * dir.c (file_impossible_p): Correctly reset FILENAME to name within directory before hash search. * job.c (child_error): Do nothing if IGNORED under -s. * job.c (exec_command): Correctly use ARGV[0] for script name when running shell directly. Tue Aug 1 14:39:14 1995 Roland McGrath * job.c (child_execute_job): Close STDIN_FD and STDOUT_FD after dup'ing from them. Don't try to close all excess descriptors; getdtablesize might return a huge value. Any open descriptors in the parent should have FD_CLOEXEC set. (start_job_command): Set FD_CLOEXEC flag on BAD_STDIN descriptor. Tue Jun 20 03:47:15 1995 Roland McGrath * read.c (read_all_makefiles): Properly append default makefiles to the end of the `read_makefiles' chain. Fri May 19 16:36:32 1995 Roland McGrath * Version 3.74 released. Wed May 10 17:43:34 1995 Roland McGrath * Version 3.73.3. Tue May 9 17:15:23 1995 Roland McGrath * compatMakefile ($(infodir)/make.info): Make sure $$dir is set in install-info cmd. Wed May 3 15:56:06 1995 Roland McGrath * file.c (print_file): Grok update_status of 1 for -q. Thu Apr 27 12:39:35 1995 Roland McGrath * Version 3.73.2. Wed Apr 26 17:15:57 1995 Roland McGrath * file.c (remove_intermediates): Fix inverted test to bail under -n for signal case. Bail under -q or -t. Skip files with update_status==-1. * job.c (job_next_command): Skip empty lines. (new_job): Don't test the return of job_next_command. Just let start_waiting_job handle the case of empty commands. Wed Apr 19 03:25:54 1995 Roland McGrath * function.c [__MSDOS__]: Include . From DJ Delorie. * Version 3.73.1. Sat Apr 8 14:53:24 1995 Roland McGrath * remake.c (notice_finished_file): Set FILE->update_status to zero if it's -1. Wed Apr 5 00:20:24 1995 Roland McGrath * Version 3.73 released. Tue Mar 28 13:25:46 1995 Roland McGrath * main.c (main): Fixed braino in assert. * Version 3.72.13. Mon Mar 27 05:29:12 1995 Roland McGrath * main.c: Avoid string in assert expression. Some systems are broken. Fri Mar 24 00:32:32 1995 Roland McGrath * main.c (main): Handle 1 and 2 returns from update_goal_chain makefile run properly. * Version 3.72.12. * main.c (handle_non_switch_argument): New function, broken out of decode_switches. (decode_switches): Set optind to 0 to reinitialize getopt, not to 1. When getopt_long returns EOF, break the loop and handle remaining args with a simple second loop. * remake.c (remake_file): Set update_status to 2 instead of 1 for no rule to make. Mention parent (dependent) in error message. (update_file_1): Handle FILE->update_status == 2 in -d printout. * job.c (start_job_command, reap_children): Set update_status to 2 instead of 1 for failed commands. Tue Mar 21 16:23:38 1995 Roland McGrath * job.c (search_path): Function removed (was already #if 0'd out). * configure.in: Remove AC_TYPE_GETGROUPS; nothing needs it any more. Fri Mar 17 15:57:40 1995 Roland McGrath * configure.bat: Write @CPPFLAGS@ translation. Mon Mar 13 00:45:59 1995 Roland McGrath * read.c (parse_file_seq): Rearranged `l(a b)' -> `l(a) l(b)' loop to not skip the elt immediately preceding `l(...'. Fri Mar 10 13:56:49 1995 Roland McGrath * Version 3.72.11. * read.c (find_char_unquote): Make second arg a string of stop chars instead of a single stop char. Stop when any char in the string is hit. All callers changed. (find_semicolon): Pass stop chars "#;" to one find_char_unquote call, instead of using two calls. If the match is not a ; but a #, return zero. * misc.c: Changed find_char_unquote callers here too. * Version 3.72.10. * read.c (read_makefile, parse_file_seq): Fix typo __MS_DOS__ -> __MSDOS__. * GNUmakefile (globfiles): Add glob/configure.bat. (distfiles): Add configh.dos, configure.bat. Wed Mar 8 13:10:57 1995 Roland McGrath Fixes for MS-DOS from DJ Delorie. * read.c (read_makefile, parse_file_seq) [__MS_DOS__]: Don't see : as separator in "C:\...". * configh.dos (STDC_HEADERS): Define only if undefined. (HAVE_SYS_PARAM_H): Don't define this. (HAVE_STRERROR): Define this. * job.c (construct_command_argv_internal) [__MSDOS__]: Fix typos. * Version 3.72.9. * main.c (decode_switches): Reset optind to 1 instead of 0. Tue Mar 7 17:31:06 1995 Roland McGrath * main.c (decode_switches): If non-option arg is "-", ignore it. Mon Mar 6 23:57:38 1995 Roland McGrath * Version 3.72.8. Wed Feb 22 21:26:36 1995 Roland McGrath * Version 3.72.7. Tue Feb 21 22:10:43 1995 Roland McGrath * main.c (main): Pass missing arg to tmpnam. * configure.in: Check for strsignal. * job.c (child_error): Use strsignal. * main.c (main): Don't call signame_init #ifdef HAVE_STRSIGNAL. * misc.c (strerror): Fix swapped args in sprintf. Mon Feb 13 11:50:08 1995 Roland McGrath * configure.in (CFLAGS, LDFLAGS): Don't set these variables. Fri Feb 10 18:44:12 1995 Roland McGrath * main.c (print_version): Add 95 to copyright years. * Version 3.72.6. * job.c (start_job_command): Remember to call notice_finished_file under -n when not recursing. To do this, consolidate that code under the empty command case and goto there for the -n case. Tue Feb 7 13:36:03 1995 Roland McGrath * make.h [! STDC_HEADERS]: Don't declare qsort. Sun headers declare it int. Mon Feb 6 17:37:01 1995 Roland McGrath * read.c (read_makefile): For bogus line starting with tab, ignore it if blank after removing comments. * main.c: Cast results of `alloca' to `char *'. * expand.c: Likewise. Sun Feb 5 18:35:46 1995 Roland McGrath * Version 3.72.5. * configure.in: Check for mktemp. * main.c (main) [! HAVE_MKTEMP]: Use tmpnam instead of mktemp. * configure.in (make_cv_sysconf_open_max): New check for `sysconf (_SC_OPEN_MAX)'. * acconfig.h: Added #undef HAVE_SYSCONF_OPEN_MAX. * job.c [HAVE_SYSCONF_OPEN_MAX] (getdtablesize): Define as macro using sysconf. Fri Jan 27 04:42:09 1995 Roland McGrath * remake.c (update_file_1): When !MUST_MAKE, don't set FILE->update_status to zero before calling notice_finished_file. (notice_finished_file): Touch only when FILE->update_status is zero. (remake_file): Set FILE->update_status to zero after not calling execute_file_command and deciding to touch instead. Thu Jan 26 01:29:32 1995 Roland McGrath * main.c (debug_signal_handler): New function; toggles debug_flag. (main): Handle SIGUSR1 with that. Mon Jan 16 15:46:56 1995 Roland McGrath * compatMakefile (realclean): Remove Info files. Sun Jan 15 08:23:09 1995 Roland McGrath * Version 3.72.4. * job.c (start_job_command): Save and restore environ around vfork call. (search_path): Function #if 0'd out. (exec_command): Use execvp instead of search_path. * expand.c (variable_expand): Rewrote computed variable name and substitution reference handling to be simpler. First expand the entire text between the parens if it contains any $s, then examine the result of that for subtitution references and do no further expansion while parsing them. * job.c (construct_command_argv_internal): Handle " quoting too, when no backslash, $ or ` characters appear inside the quotes. * configure.in (union wait check): If WEXITSTATUS and WTERMSIG are defined, just use int. Tue Jan 10 06:27:27 1995 Roland McGrath * default.c (default_variables) [__hpux]: Remove special definition of ARFLAGS. Existence of the `f' flag is not consistent across HPUX versions; and one might be using GNU ar anyway. * compatMakefile (clean): Don't remove Info files. * compatMakefile (check): Remove gratuitous target declaration. Sat Jan 7 11:38:23 1995 Roland McGrath * compatMakefile (ETAGS, CTAGS): Don't use -t. * arscan.c (ar_name_equal) [cray]: Subtract 1 like [__hpux]. * main.c (decode_switches): For --help, print usage to stdout. Mon Dec 5 12:42:18 1994 Roland McGrath * Version 3.72.3. * remake.c (update_file_1): Do set_command_state (FILE, cs_not_started) only if old state was deps_running. Mon Nov 28 14:24:03 1994 Roland McGrath * job.c (start_waiting_job): Use set_command_state. * build.template (CPPFLAGS): New variable. (prefix, exec_prefix): Set from @...@. (compilation loop): Pass $CPPFLAGS to compiler. * GNUmakefile (build.sh.in): Make it executable. * GNUmakefile (globfiles): Add configure.in, configure. * Version 3.72.2. * configure.in (AC_OUTPUT): Don't write glob/Makefile. * configure.in (AC_CHECK_SYMBOL): Use AC_DEFINE_UNQUOTED. * configure.in: Don't check for ranlib. Tue Nov 22 22:42:40 1994 Roland McGrath * remake.c (notice_finished_file): Only mark also_make's as updated if really ran cmds. Tue Nov 15 06:32:46 1994 Roland McGrath * configure.in: Put dnls before random whitespace. Sun Nov 13 05:02:25 1994 Roland McGrath * compatMakefile (CPPFLAGS): New variable, set from @CPPFLAGS@. (RANLIB): Variable removed. (prefix, exec_prefix): Set these from @...@. (.c.o): Use $(CPPFLAGS). (glob/libglob.a): Don't pass down variables to sub-make. glob/Makefile should be configured properly by configure. (distclean): Remove config.log and config.cache (autoconf stuff). Mon Nov 7 13:58:06 1994 Roland McGrath * acconfig.h: Add #undef HAVE_UNION_WAIT. * configure.in: Converted to Autoconf v2. * dir.c: Test HAVE_DIRENT_H, HAVE_SYS_DIR_H, HAVE_NDIR_H instead of DIRENT, SYSDIR, NDIR. * build.sh.in (prefix, exec_prefix): Set these from @...@. (CPPFLAGS): New variable, set from @CPPFLAGS@. (compiling loop): Pass $CPPFLAGS before $CFLAGS. * install.sh: File renamed to install-sh. * main.c (define_makeflags): When no flags, set WORDS to zero. Sun Nov 6 18:34:01 1994 Roland McGrath * Version 3.72.1. * main.c (define_makeflags): Terminate properly when FLAGSTRING is empty. Fri Nov 4 16:02:51 1994 Roland McGrath * Version 3.72. Tue Nov 1 01:18:10 1994 Roland McGrath * Version 3.71.5. * job.c (start_job_command): When ARGV is nil, only set update_state and call notice_finished_file if job_next_command returns zero. * job.c (start_job_command): Call notice_finished_file for empty command line. Thu Oct 27 02:02:45 1994 Roland McGrath * file.c (snap_deps): Set COMMANDS_SILENT for .SILENT, not COMMANDS_NOERROR. Wed Oct 26 02:14:10 1994 Roland McGrath * Version 3.71.4. Tue Oct 25 22:49:24 1994 Roland McGrath * file.c (snap_deps): Set command_flags bits in all :: entries. Mon Oct 24 18:47:50 1994 Roland McGrath * make.h (posix_pedantic): Declare it. * main.c (main): Move checks .IGNORE, .SILENT, .POSIX to snap_deps. * file.c (snap_deps): Check .IGNORE, .SILENT, .POSIX here instead of in main. If .IGNORE has deps, OR COMMANDS_NOERROR into their command_flags and don't set -i. Likewise .SILENT. * job.c (start_job_command): In FLAGS initialization, OR in CHILD->file->command_flags. * file.h (struct file): New member `command_flags'. Sun Oct 16 01:01:51 1994 Roland McGrath * main.c (switches): Bump flag values for --no-print-directory and --warn-undefined-variables, so neither is 1 (which indicates a nonoption argument). Sat Oct 15 23:39:48 1994 Roland McGrath * main.c (main): Add missing code in .IGNORE test. Mon Oct 10 04:09:03 1994 Roland McGrath * variable.c (define_automatic_variables): Define +D and +F. Sat Oct 1 04:07:48 1994 Roland McGrath * main.c (main): Define hidden automatic variable with command vars, and MAKEOVERRIDES to a reference to that. (define_makeflags): If posix_pedantic, write a reference to that instead. Thu Sep 29 00:14:26 1994 Roland McGrath * main.c (posix_pedantic): New variable. (main): Set posix_pedantic if .POSIX is a target. Fix .IGNORE and .SILENT checks to require is_target. * commands.c (set_file_variables): Define new automatic variable $+, like $^ but before calling uniquize_deps. * job.c (reap_children): Call delete_child_targets for non-signal error if .DELETE_ON_ERROR is a target. Tue Sep 27 01:57:14 1994 Roland McGrath * Version 3.71.3. Mon Sep 26 18:16:55 1994 Roland McGrath * job.c (reap_children): Don't change C->file->command_state when dying. Test it only after calling start_job_command for a new command line. When no more cmds, just set C->file->update_status. (start_job_command): When the last line is empty or under -n, set C->file->update_status. (start_waiting_job): Grok cs_not_started after start_job_command as success. (new_job): Set C->file->update_status when there are no cmds. (job_next_command): When out of lines, don't set CHILD->file->update_status or CHILD->file->command_state. * main.c (quote_as_word): Renamed from shell_quote. Take new arg; if nonzero, also double $s. (main): Define MAKEOVERRIDES from command_variables here. (define_makeflags): Don't use command_variables here; instead write a reference $(MAKEOVERRIDES) in MAKEFLAGS. Make vars recursive. * dir.c [__MSDOS__]: Fixed typo. * vpath.c (selective_vpath_search): Reset EXISTS when stat fails. Sat Sep 10 03:01:35 1994 Roland McGrath * remake.c: Include and use assert instead of printfs and abort. * main.c (decode_switches): Loop until optind hits ARGC, not just until getopt_long returns EOF. Initialize C to zero before loop; in loop if C is EOF, set optarg from ARGV[optind++], else call getopt_long. (decode_env_switches): Use variable_expand instead of allocated_variable_expand. Allocate a fresh buffer to copy split words into; scan characters by hand to break words and debackslashify. (shell_quote): New function. (define_makeflags): Allocate doubled space for switch args, and command variable names and values; use shell_quote to quote those things. Fri Sep 9 01:37:47 1994 Roland McGrath * Version 3.71.2. * acconfig.h: Add HAVE_SYS_SIGLIST and HAVE__SYS_SIGLIST. * main.c (decode_switches): The non-option return from getopt is 1, not 0. (command_variables): New type and variable. (decode_switches, decode_env_switches): After making a variable definition, record the struct variable pointer in the command_variables chain. (define_makeflags): If ALL, write variable definitions for command_variables. * main.c (other_args): Variable removed. (goals, lastgoal): New static variables (moved from auto in main). (main): Don't process OTHER_ARGS at all. Don't set variable MAKEOVERRIDES at all; define MAKE to just $(MAKE_COMMAND). (init_switches): Prepend a - {return in order} instead of a + {require order}. (decode_switches): Don't set OTHER_ARGS at all. Grok '\0' return from getopt_long as non-option argument; try variable definition and (if !ENV) enter goal targets here. (decode_env_switches): Use allocated_variable_expand to store value. Use find_next_token to simplify word-splitting loop. Don't prepend a dash to uninterpreted value. Instead, if split into only one word, try variable definition and failing that prepend a dash to the word and pass it to decode_switches as a single arg. Wed Sep 7 03:02:46 1994 Roland McGrath * remake.c (notice_finished_file): Only recheck modtimes if FILE->command_state was cs_running on entry (meaning the commands actually just ran). (update_file_1): Whenever we set FILE->update_status, call notice_finished_file instead of just set_command_state. * job.c (start_job_command): Whenever we set CHILD->file->update_status, call notice_finished_file instead of just set_command_state. Tue Sep 6 19:13:54 1994 Roland McGrath * default.c: Add missing ". * job.c: Changed all assignments of command_state members to calls to set_command_state. * remake.c: Likewise. * file.c (set_command_state): New function. * file.h: Declare set_command_state. * main.c (init_switches): Put a + first in options. Mon Jul 25 18:07:46 1994 Roland McGrath Merge MSDOS/GO32 port from DJ Delorie . * vpath.c: Changed all uses of ':' to PATH_SEPARATOR_CHAR. * main.c (directory_before_chdir): New variable, moved out of main (was local). (main) [__MSDOS__]: Look for \ or : to delimit last component of PROGRAM. Don't frob ARGV[0] before setting MAKE_COMMAND variable. (die): Change back to `directory_before_chdir' before dying. * make.h (PATH_SEPARATOR_CHAR): New macro; differing defns for [__MSDOS__] and not. * job.c [__MSDOS__]: Include . [__MSDOS__] (dos_pid, dos_status, dos_bname, dos_bename, dos_batch_file): New variables. (reap_children) [__MSDOS__]: Don't call wait; just examine those vars. (unblock_sigs) [__MSDOS__]: Do nothing. (start_job_command) [__MSDOS__]: Use spawnvpe instead of vfork & exec. (load_too_high) [__MSDOS__]: Always return true. (search_path) [__MSDOS__]: Check for : or / in FILE to punt. Use PATH_SEPARATOR_CHAR instead of ':'. (construct_command_argv_internal) [__MSDOS__]: Wholly different values for sh_chars and sh_cmds. Wholly new code to handle shell scripts. * function.c (expand_function: `shell') [__MSDOS__]: Wholly new implementation. * dir.c [__MSDOS__] (dosify): New function. (dir_contents_file_exists_p) [__MSDOS__]: Call it on FILENAME and process the result instead of FILENAME itself. (file_impossible_p) [__MSDOS__]: Likewise. * default.c [__MSDOS__]: Define GCC_IS_NATIVE. (default_suffix_rules) [__MSDOS__]: Use `y_tab.c' instead of `y.tab.c'. (default_variables) [GCC_IS_NATIVE]: Set CC and CXX to `gcc', YACC to `bison -y', and LEX to `flex'. * configure.bat, configh.dos: New files. * commands.c (fatal_error_signal) [__MSDOS__]: Just remove intermediates and exit. * commands.c (set_file_variables): Add parens in length computation in .SUFFIXES dep loop to quiet compiler warning. From Jim Meyering. * read.c (read_makefile): Free FILENAME if we allocated it. From Jim Meyering. Mon Jul 4 17:47:08 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * misc.c (safe_stat): New function, EINTR-safe wrapper around stat. * vpath.c (selective_vpath_search): Use safe_stat in place of stat. * read.c (construct_include_path): Use safe_stat in place of stat. * job.c (search_path): Use safe_stat in place of stat. * dir.c (find_directory): Use safe_stat in place of stat. * commands.c (delete_target): Use safe_stat in place of stat. * arscan.c (ar_member_touch) [EINTR]: Do EINTR looping around fstat. * remake.c (name_mtime): Use safe_stat in place of stat. (touch_file) [EINTR]: Do EINTR looping around fstat. Fri Jun 24 05:40:24 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Check for a shell command first, and then strip leading tabs before further checking if it's not a shell command line. * make.h [__arm]: Undefine POSIX. [!__GNU_LIBRARY__ && !POSIX && !_POSIX_VERSION]: Don't declare system functions that return int. * job.c (construct_command_argv_internal): After swallowing a backslash-newline combination, if INSTRING is set goto string_char (new label) for normal INSTRING handling code. Sat Jun 4 01:11:20 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) * configure.in: Don't check for sys_siglist and _sys_siglist with AC_HAVE_FUNCS. Instead use two AC_COMPILE_CHECKs. Mon May 23 18:20:38 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.71.1 released. * make.h [!__GNU_LIBRARY__ && !POSIX]: Also test #ifndef _POSIX_VERSION for these declarations. * misc.c [GETLOADAVG_PRIVILEGED] [POSIX]: Remove bogus #ifndefs around #undefs of HAVE_SETREUID and HAVE_SETREGID. Sat May 21 16:26:38 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.71 released. * misc.c [GETLOADAVG_PRIVILEGED] [POSIX]: Don't test [HAVE_SETUID] and [HAVE_SETGID]. Every system has those, and configure doesn't check for them. * make.h [_POSIX_VERSION]: Don't #define POSIX #ifdef ultrix. * compatMakefile (loadavg): Depend on and use loadavg.c instead of getloadavg.c. (loadavg.c): Link or copy it from getloadavg.c. (distclean): Remove loadavg.c. Mon May 16 22:59:04 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.70.4. * misc.c [GETLOADAVG_PRIVILEGED] [! POSIX]: Undefine HAVE_SETEUID and HAVE_SETEGID. * default.c (default_terminal_rules): In SCCS rules, put $(SCCS_OUTPUT_OPTION) before $<. On some systems -G is grokked only before the file name. * configure.in (SCCS_GET_MINUS_G check): Put -G flag before file name. Tue May 10 16:27:38 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Swallow backslash-newline combinations inside '' strings too. Thu May 5 04:15:10 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (do_define): Call collapse_continuations on each line before all else. Mon Apr 25 19:32:02 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Notice newline inside '' string when RESTP is non-null. Fri Apr 22 17:33:30 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.70.3. * remake.c (update_goal_chain): Reset FILE to G->file after the double-colon loop so it is never null for following code. * read.c (read_makefile): Fix `override define' parsing to skip whitespace after `define' properly. * compatMakefile (srcdir): Define as @srcdir@; don't reference $(VPATH). (glob/Makefile): New target. Thu Apr 21 16:16:55 1994 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.70.2. * misc.c (remove_comments): Use find_char_unquote. * make.h (find_char_unquote): Declare it. * read.c (find_char_unquote): New function, generalized from find_percent. (find_percent, find_semicolon, parse_file_seq): Use that. Wed Apr 20 18:42:39 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * implicit.c (pattern_search): Always allocate new storage for FILE->stem. It is not safe to store STEM's address because it might be auto storage. * configure.in: Check for seteuid and setegid. * misc.c [HAVE_SETEUID]: Declare seteuid. [HAVE_SETEGID]: Declare setegid. (make_access, user_access) [HAVE_SETEUID]: Use seteuid. [HAVE_SETEGID]: Use setegid. * remake.c (update_goal_chain): Set STATUS to FILE->update_status, to preserve whether it's 2 for error or 1 for -q trigger. When STATUS gets nonzero and -q is set, always stop immediately. * main.c (main, decode_switches): Die with 2 for errors. (main): Accept 2 return from update_goal_chain and die with that. * misc.c (fatal, makefile_fatal): Die with 2; 1 is reserved for -q answer. * job.c (reap_children): Die with 2 for error. (start_job_command): Set update_status to 2 for error. Set it to 1 when we would run a command and question_flag is set. * read.c (read_makefile): Don't mark makefiles as precious. Just like other targets, they can be left inconsistent and in need of remaking by aborted commands. * read.c (read_makefile): Write no error msg for -include file. Tue Apr 5 05:22:19 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * commands.c (fatal_error_signal): Don't unblock signals. * file.h (struct file): Change member `double_colon' from flag to `struct file *'. * read.c (record_files): Set double_colon pointer instead of flag. * main.c (main): When disqualifying makefiles for updating, use double_colon pointer to find all entries for a file. * file.c (enter_file): If there is already a double-colon entry for the file, set NEW->double_colon to that pointer. (file_hash_enter): Use FILE->double_colon to find all entries to set name. * remake.c (update_goal_chain): Do inner loop on double-colon entries. (update_file): Use FILE->double_colon pointer to find all entries. (f_mtime): Likewise. (notice_finished_file): Propagate mtime change to all entries. * variable.c (try_variable_definition): Return after abort. Fri Apr 1 18:44:15 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Remove unused variable. (parse_file_seq): When removing an elt that is just `)', properly fix up the previous elt's next pointer. Mon Mar 28 18:31:49 1994 Roland McGrath (roland@mole.gnu.ai.mit.edu) * configure.in: Do AC_SET_MAKE. * GNUmakefile (Makefile.in): Edit MAKE assignment into @SET_MAKE@. Fri Mar 4 00:02:32 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * function.c (subst_expand): If BY_WORD or SUFFIX_ONLY is set and the search string is the empty string, find a match at the end of each word (using end_of_token in place of sindex). * misc.c (end_of_token): Don't treat backslashes specially; you can no longer escape blanks with backslashes in export, unexport, and vpath. This was never documented anyway. Thu Mar 3 23:53:46 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Variable name for `define' is not just first token; use whole rest of line and strip trailing blanks. Wed Feb 16 16:03:45 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.70.1. * read.c (read_makefile): Add -d msg stating args. * read.c (read_makefile): Use isspace to skip over leading whitespace, and explicitly avoid skipping over tabs. Don't want to skip just spaces though; formfeeds et al should be skipped. * default.c (default_variables) [__hpux]: Add f in ARFLAGS. * arscan.c (ar_name_equal) [__hpux]: Subtract 2 instead of 1 from sizeof ar_name for max length to compare. * misc.c [GETLOADAVG_PRIVILEGED] [POSIX]: Undefine HAVE_SETREUID #ifdef HAVE_SETUID; likewise HAVE_SETREGID and HAVE_SETGID. * main.c (main): Call user_access after setting `program', in case it needs to use it in an error message. * read.c (read_makefile): Ignore an empty line starting with a tab. Thu Feb 10 21:45:31 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in (AC_SYS_SIGLIST_DECLARED): Use this instead of AC_COMPILE_CHECK that is now its contents. Fri Feb 4 16:28:54 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h: #undef strerror after #include . [! ANSI_STRING]: Declare strerror. Thu Feb 3 02:21:22 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * misc.c (strerror): #undef any macro before function definition. Mon Jan 31 19:07:23 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (try_variable_definition): Calculate BEG before loop to strip blanks by decrementing END. Don't decr END to before BEG. * read.c (read_makefile): Skip over leading space characters, but not tabs, after removing continuations and comments (it used to use isspace). Tue Jan 25 16:45:05 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (define_automatic_variables): In $(@D) et al, use patsubst to remove trailing slash. * commands.c (delete_target): New function, broken out of delete_child_targets. Check for archive members and give special msg. (delete_child_targets): Use delete_target. Mon Jan 17 17:03:22 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (default_suffix_rules): Use $(TEXI2DVI_FLAGS) in texi2dvi rules. Use $(MAKEINFO_FLAGS) in makeinfo rules. Tue Jan 11 19:29:55 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * GNUmakefile (tarfiles): Omit make-doc. (make-$(version).tar): Include make.info*. Fri Jan 7 16:27:00 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (configure, config.h.in): Comment out rules. Thu Jan 6 18:08:08 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (binprefix, manprefix): New variables. (instname): Variable removed. (install): Use $({bin,man}prefix)make in place of $(instname). File targets likewised renamed. Mon Jan 3 17:50:25 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.70 released. Thu Dec 23 14:46:54 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.69.3. * read.c (parse_file_seq): Inside multi-word archive ref translation loop, check NEW1==0 at end and break out of the loop. * GNUmakefile (make-$(version).tar): Distribute install.sh. * install.sh: New file. * configure.in (SCCS_GET_MINUS_G check): Put redirection for admin cmds outside subshell parens, to avoid "command not found" msgs from the shell. Wed Dec 22 17:00:43 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in (SCCS_GET_MINUS_G check): Put -G flag last in get cmd. Redirect output & error from get to /dev/null. Fix reversed sense of test. Fri Dec 17 15:31:36 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in (SCCS_GET_MINUS_G check): Use parens instead of braces inside if condition command; some shells lose. Thu Dec 16 15:10:23 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.69.2. * arscan.c [M_UNIX]: Move #undef M_XENIX for PORTAR stuff. (PORTAR) [M_XENIX]: Define to 0 instead of 1. * main.c (define_makeflags): Only export MAKEFLAGS if !ALL. Wed Dec 15 17:47:48 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (main): Cast result of pointer arith to unsigned int before passing to define_variable for envars. Matters when sizeof(unsigned)!=sizeof(ptrdiff_t). Tue Dec 14 14:21:16 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in: Add new check for SCCS_GET_MINUS_G. * config.h.in: Add #undef SCCS_GET_MINUS_G. * default.c (default_terminal_rules): Use `$(SCCS_OUTPUT_OPTION)' in place of `-G $@' in SCCS commands. (default_variables) [SCCS_GET_MINUS_G]: Define SCCS_OUTPUT_OPTION to "-G$@". * configure.in (AC_OUTPUT): Put touch stamp-config in second arg (so it goes in config.status), rather than afterward. * ar.c (ar_member_date): Don't call enter_file on the archive file if it doesn't exist (by file_exists_p). * compatMakefile ($(infodir)/make.info): Replace `$$d/foo.info' with `$$dir/make.info' in install-info invocation (oops). * vpath.c (construct_vpath_list): Only set LASTPATH set PATH when we do not unlink and free PATH. * file.c (print_file_data_base): Fix inverted calculation for average files per hash bucket. * read.c (readline): When we see a NUL, give only a warning and synthesize a newline to terminate the building line (used to fatal). Move fgets call into the loop condition, and after the loop test ferror (used to test !feof in the loop). Fri Dec 3 16:40:31 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in: Check for strerror in AC_HAVE_FUNCS. Thu Dec 2 15:37:50 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) Differentiate different flavors of missing makefile error msgs, removing gratuitous `fopen: ' and giving caller for included makefiles. * misc.c [! HAVE_STRERROR]: Define our own strerror here. (perror_with_name, pfatal_with_name): Use strerror instead of replicating its functionality. * read.c (read_makefile): Return int instead of void. (read_all_makefiles, read_makefile): Change callers to notice zero return and give error msg. Thu Nov 11 11:47:36 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.69.1. * default.c: Put `-G $@' before $< in SCCS cmds. Wed Nov 10 06:06:14 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): After trying a variable defn, notice if the line begins with a tab, and diagnose an error. Sun Nov 7 08:07:37 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.69. Wed Nov 3 06:54:33 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.10. * implicit.c (try_implicit_rule): Look for a normal rule before an archive rule. Fri Oct 29 16:45:28 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * function.c (expand_function: `sort'): Double NWORDS when it overflows, instead of adding five. * compatMakefile (clean): Remove loadavg. Wed Oct 27 17:58:33 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.9. * file.h (NEW_MTIME): Define new macro. * main.c (main): Set time of NEW_FILES to NEW_MTIME, not to current time returned from system. Removed variable NOW. * remake.c (notice_finished_file): Use NEW_MTIME in place of current time here too. Tue Oct 26 19:45:35 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.8. * remake.c (update_file_1): Don't clear MUST_MAKE when FILE has no cmds and !DEPS_CHANGED unless also !NOEXIST. Mon Oct 25 15:25:21 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (parse_file_seq): When converting multi-word archive refs, ignore a word beginning with a '('. Fri Oct 22 02:53:38 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in: Check for sys/timeb.h. * make.h [HAVE_SYS_TIMEB_H]: Test this before including it. Thu Oct 21 16:48:17 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.7. * rule.c (convert_suffix_rule): New local TARGPERCENT. Set it to TARGNAME+1 for "(%.o)", to TARGNAME for "%.?". Use it in place of TARGNAME to initialize PERCENTS[0]. Mon Oct 18 06:49:35 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in: Use AC_HAVE_HEADERS(unistd.h) instead of AC_UNISTD_H. Remove AC_USG; it is no longer used. * file.c (print_file): New function, broken out of print_file_data_base. (print_file_data_base): Call it. * rule.c (print_rule): New function, broken out of print_rule_data_base. (print_rule_data_base): Call it. Thu Oct 14 14:54:03 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (install_default_suffix_rules): New function, broken out of install_default_implicit_rules. (install_default_implicit_rules): Move suffix rule code there. * make.h: Declare install_default_suffix_rules. * main.c (main): Call install_default_suffix_rules before reading makefiles. Move convert_to_pattern call before install_default_implicit_rules. * job.h (struct child): Make `pid' member type `pid_t' instead of `int'. * compatMakefile (RANLIB): New variable, set by configure. (glob/libglob.a): Pass RANLIB value down to submake. Fixes for SCO 3.2 "devsys 4.2" from pss@tfn.com (Peter Salvitti). * make.h: Include before for SCO lossage. * job.c [! getdtablesize] [! HAVE_GETDTABLESIZE]: If NOFILE is not defined but NOFILES_MAX is, define it to be that. Mon Oct 11 19:47:33 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * GNUmakefile (make-$(version).tar): Depend on acconfig.h, so it is distributed. Sun Oct 3 15:15:33 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (default_terminal_rules): Add `-G $@' to SCCS get cmds. Tue Sep 28 14:18:20 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Add ^ to SH_CHARS; it is another symbol for | in some shells. * main.c (main): Add it to CMD_DEFS quoting list as well. Mon Sep 20 18:05:24 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Remove '=' from SH_CHARS. Only punt on '=' if it is unquoted in a word before the first word without an unquoted '='. * main.c (define_makeflags): Set v_export for MAKEFLAGS. Fri Sep 17 00:37:18 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (update_file_1): Use .DEFAULT cmds for phony targets. * make.h [_AIX && _POSIX_SOURCE]: Define POSIX. * commands.c (delete_child_targets): Don't delete phony files. * job.c (start_job_command): Set COMMANDS_RECURSE in FLAGS if we see a `+' at the beginning of the command line. Thu Sep 9 17:57:14 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.6. Wed Sep 8 20:14:21 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (define_makeflags): Define MAKEFLAGS with o_file, not o_env. Mon Aug 30 12:31:58 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * expand.c (variable_expand): Fatal on an unterminated reference. Thu Aug 19 16:27:53 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.5. * variable.c (define_automatic_variables): Define new o_default variable `MAKE_VERSION' from version_string and remote_description. * make.h (version_string, remote_description): Declare these here. * main.c: Don't declare version_string. (print_version): Don't declare remote_description. Wed Aug 18 15:01:24 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Free space pointed to by CONDITIONALS before restoring the old pointer. Mon Aug 16 17:33:36 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile ($(objs)): Depend on config.h. * GNUmakefile (build.sh.in): Depend on compatMakefile. * configure.in: Touch stamp-config after AC_OUTPUT. Fri Aug 13 16:04:22 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.4. Thu Aug 12 17:18:57 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h: Include instead of "config.h". Wed Aug 11 02:35:25 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (main): Make all variables interned from ENVP be v_export. * variable.c (try_variable_definition): In v_default case, don't check for an o_file variable that `getenv' finds. * job.c (reap_children): New local variable ANY_LOCAL; set it while setting ANY_REMOTE. If !ANY_LOCAL, don't wait for local kids. * main.c (main): Don't call decode_env_switches on MFLAGS. DOC THIS. * function.c (expand_function): #if 0 out freeing of ENVP since it is environ. Mon Aug 9 17:37:20 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.3. * remote-stub.c (remote_status): Set errno to ECHILD before return. * job.c (reap_children): Scan the chain for remote children and never call remote_status if there are none. * function.c (expand_function: `shell'): #if 0 out calling target_environment; just set ENVP to environ instead. * job.c (reap_children): Check for negative return from remote_status and fatal for it. When blocking local child wait returns 0, then try a blocking call to remote_status. Tue Aug 3 00:19:00 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (clean): Delete make.info* and make.dvi here. (distclean): Not here. * dep.h (RM_*): Use #defines instead of enum to avoid lossage from compilers that don't like enum values used as ints. Mon Aug 2 16:46:34 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (loadavg): Add $(LOADLIBES). Sun Aug 1 16:01:15 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.2. * compatMakefile (loadavg, check-loadavg): New targets. (check): Depend on check-loadavg. * compatMakefile (glob/libglob.a): Depend on config.h. * misc.c (log_access): Write to stderr instead of stdout. Fri Jul 30 00:07:02 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68.1. Thu Jul 29 23:26:40 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in (SYS_SIGLIST_DECLARED): In test program include #ifdef HAVE_UNISTD_H. * compatMakefile (.PHONY): Put after `all' et al. * configure.in: Add AC_IRIX_SUN. Wed Jul 28 17:41:12 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.68. Mon Jul 26 14:36:49 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.8. Sun Jul 25 22:09:08 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.7. * compatMakefile ($(infodir)/make.info): Don't use $(instname). Run install-info script if present. Fri Jul 23 16:03:50 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h [STAT_MACROS_BROKEN]: Test this instead of [uts]. * configure.in: Add AC_STAT_MACROS_BROKEN. Wed Jul 14 18:48:11 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.6. * read.c (read_makefile): Recognize directive `-include', like `include' but sets RM_DONTCARE flag. * variable.c (target_environment): If FILE is nil, use current_variable_set_list in place of FILE->variables. * function.c (expand_function: `shell'): Get an environment for the child from target_environment instead of using environ. * dep.h: Declare read_all_makefiles here. (RM_*): Define new enum constants. * read.c (read_makefile): Second arg is FLAGS instead of TYPE. Treat it as a bit mask containing RM_*. (read_all_makefiles): For default makefiles, set D->changed to RM_DONTCARE instead of 1. * main.c: Don't declare read_all_makefiles here. (main): Check `changed' member of read_makefiles elts for RM_* flags instead of specific integer values. Mon Jul 12 22:42:17 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h [sequent && i386]: #undef POSIX. From trost@cse.ogi.edu. Thu Jul 8 19:51:23 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * vpath.c (construct_vpath_list): If ELEM is zero 0, free PATTERN as well as VPATH. (build_vpath_lists): Empty `vpaths' around construct_vpath_list call for $(VPATH). Expand $(strip $(VPATH)), not just $(VPATH). * rule.c (convert_suffix_rule): Use alloca instead of xmalloc for PERCENTS, whose storage is not consumed by create_pattern_rule. * make.h [__mips && _SYSTYPE_SVR3]: #undef POSIX. Wed Jun 30 18:11:40 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.5. * rule.c (max_pattern_targets): New variable. (count_implicit_rule_limits): Compute its value. * rule.h: Declare it. * implicit.c (pattern_search): Make TRYRULES max_target_patterns times bigger. Move adding new TRYRULES elt inside the inner targets loop, so each matching target gets its own elt in MATCHES and CHECKED_LASTSLASH. * file.c (remove_intermediates): If SIG!=0 say `intermediate file' instead of just `file' in error msg. Fri Jun 25 14:55:15 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv): Turn off --warn-undefined-variables around expansion of SHELL and IFS. * read.c (tilde_expand): Likewise for HOME. (read_all_makefiles): Likewise for MAKEFILES. * vpath.c (build_vpath_lists): Likewise for VPATH. * main.c (warn_undefined_variables_flag): New flag variable. (switches): Add --warn-undefined-variables. * make.h (warn_undefined_variables_flag): Declare it. * expand.c (warn_undefined): New function. (reference_variable): Call it if the variable is undefined. (variable_expand): In substitution ref, call warn_undefined if the variable is undefined. * default.c (default_pattern_rules): Add `%.c: %.w %.ch' and `%.tex: %.w %.ch' rules. (default_suffix_rules: .w.c, .w.tex): Pass three args: $< - $@. (default_suffixes): Add `.ch'. Mon Jun 21 17:55:39 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (default_suffixes): Replace `.cweb' with `.w'. (default_suffix_rules): Rename `.cweb.c' and `.cweb.tex' to `.w.c' and `.w.tex'. Fri Jun 11 14:42:09 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile ($(bindir)/$(instname)): Add missing backslash. Thu Jun 10 18:14:08 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.4. * read.c (multi_glob): Don't free OLD and OLD->name in the FOUND!=0 fork. Use new block-local variable F instead of clobbering OLD. * ar.c (glob_pattern_p): New function, snarfed from glob/glob.c. (ar_glob): Call it; return nil immediately if MEMBER_PATTERN contains no metacharacters. Wed Jun 9 16:25:35 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * ar.c (ar_glob{_match,_alphacompare}): New function. * dep.h [! NO_ARCHIVES]: Declare it. * read.c (multi_glob) [! NO_ARCHIVES]: Use it on archive member elts. * read.c (read_makefile): Pass flag (1) to parse_file_seq, not to multi_glob (which doesn't take a 3rd arg). * rule.c (install_pattern_rule): Likewise. * default.c (set_default_suffixes): Here too. * function.c (string_glob): Don't pass gratuitous arg to multi_glob. * read.c (parse_file_seq) [! NO_ARCHIVES]: Add post-processing loop to translate archive refs "lib(a b)" into "lib(a) lib(b)". Mon Jun 7 19:26:51 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (installdirs): Actually pass directory names. ($(bindir)/$(instname)): Test chgrp&&chmod exit status with `if'; if it fails, echo a warning msg, but don't make the rule fail. * read.c (tilde_expand): New function, broken out of tilde_expand. (multi_glob): Call it. (construct_include_path): Expand ~ in directory names. * dep.h: Declare tilde_expand. * main.c (enter_command_line_file): Expand ~ at the start of NAME. (main): Expand ~ in -C args. * read.c (read_makefile): Expand ~ in FILENAME unless TYPE==2. Fri Jun 4 13:34:47 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (decode_env_switches): Use xmalloc instead of alloca for ARGS. * main.c (main): Put result of alloca in temporary variable with simple assignment, to make SGI compiler happy. Thu Jun 3 20:15:46 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.3. * main.c (main): Before re-execing, remove intermediate files, and print the data base under -p. Sexier debugging message. * implicit.c (pattern_search): Allocate an extra copy of the name of a winning intermediate file when putting it in FOUND_FILES. Wed Jun 2 16:38:08 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Pass flag (1) to parse_file_seq, not to multi_glob (which doesn't take a 3rd arg). * dir.c (dir_contents_file_exists_p): When reading dirents, ignore chars within D_NAMLEN that are NULs. * main.c (decode_switches): Don't savestring ARGV[0] to put it into `other_args'. For string switch, don't savestring `optarg'. (main): Don't free elts of makefiles->list that are "-". Use alloca'd rather than savestring'd storage for elts of makefiles->list that are temporary file names. * read.c (read_all_makefiles): Don't free *MAKEFILES. * file.c (enter_file): Don't strip `./'s. * main.c (enter_command_line_file): New function. (main): Use it in place of enter_file for command-line goals from other_files, and for old_files and new_files. Mon May 31 18:41:40 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.2. * compatMakefile (.SUFFIXES): Add .info. ($(infodir)/$(instname).info): Find make.info* in cwd if there, else in $srcdir. Use basename to remove dir name from installed name. Thu May 27 17:35:02 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * implicit.c (pattern_search): When interning FOUND_FILES, try lookup_file first; if found, free the storage for our copy of the name. Wed May 26 14:31:20 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67.1. * main.c (decode_switches): In usage msg, write `--switch=ARG' or `--switch[=OPTARG]' rather than `--switch ARG' or `--switch [ARG]'. Mon May 24 16:17:31 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * rule.c (convert_suffix_rule): New function. (convert_to_pattern): Use it instead of doing all the work here several times. For target suffix `.a', generate both the archive magic rule and the normal rule. * compatMakefile (distclean): Remove stamp-config. Sat May 22 16:15:18 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.67. * file.c (remove_intermediates): Don't write extra space after `rm'. * main.c (struct command_switch.type): Remove `usage_and_exit'. (print_usage_flag): New variable. (switches: --help): Make type `flag', to set print_usage_flag. (init_switches): Remove `usage_and_exit' case. (decode_switches): Likewise. (decode_switches): Print usage if print_usage_flag is set. When printing usage, die with status of BAD. (main): Die with 0 if print_version_flag. Fri May 21 16:09:28 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.66. Wed May 19 21:30:44 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (installdirs): New target. (install): Depend on it. Sun May 16 20:15:07 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.65.2. Fri May 14 16:40:09 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * vpath.c (construct_vpath_list): In removal loop for DIRPATH==0, set LASTPATH to PATH, not NEXT. * dir.c (read_dirstream): Break out of loop after incrementing DS->buckets such that it reaches DIRFILE_BUCKETS; avoid trying to dereference DS->contents->files[DIRFILE_BUCKETS]. * read.c (read_makefile): Clear no_targets after reading a targetful rule line. * main.c (main): If print_version_flag is set, exit after printing the version. (switches): Change --version docstring to say it exits. * make.h [butterfly]: #undef POSIX. Wed May 12 15:20:21 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.65.1. * arscan.c (ar_scan) [! AIAMAG]: Don't declare LONG_NAME. [AIAMAG]: Pass TRUNCATE flag arg to (*FUNCTION), always zero. * function.c (handle_function): Use fatal instead of makefile_fatal when reading_filename is nil. * configure.in: Add AC_GETGROUPS_T. * job.c (search_path): Use GETGROUPS_T in place of gid_t. Sun May 9 15:41:25 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.65. Fri May 7 18:34:56 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * function.c (handle_function): Fatal for unmatched paren. Thu May 6 16:13:41 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.64.3. * commands.c (handling_fatal_signal): New variable. (fatal_error_signal): Set it. * job.c (reap_children): Avoid nonreentrant operations if that is set. * make.h: Declare handling_fatal_signal. * expand.c (reference_variable): New function, snippet of code broken out of simple-reference case of variable_expand. (variable_expand): Use it for simple refs. (variable_expand): When checking for a computed variable name, notice a colon that comes before the final CLOSEPAREN. Expand only up to the colon, and then replace the pending text with a copy containing the expanded name and fall through to subst ref handling. (variable_expand): Don't bother expanding the name if a colon appears before the first $. (expand_argument): Use alloca instead of savestring. (variable_expand): For subst ref, expand both sides of = before passing to [pat]subst_expand. Use find_percent instead of lindex to check the lhs for a %. Wed May 5 14:45:52 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.64.2. Mon May 3 17:00:32 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * arscan.c (ar_name_equal) [AIAMAG]: Abort if TRUNCATED is nonzero. * read.c (read_makefile): Pass extra arg of 1 to parse_file_seq, not to multi_glob. Thu Apr 29 19:47:33 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.64.1. * arscan.c (ar_scan): New local flag var LONG_NAME. Set it when we read the member name in any of the fashions that allow it to be arbitrarily long. Pass its negation to FUNCTION. (describe_member): Take TRUNCATED from ar_scan and print it. (ar_name_equal): Take new arg TRUNCATED; if nonzero, compare only the first sizeof (struct ar_hdr.ar_name) chars. (ar_member_pos): Take TRUNCATED from ar_scan, pass to ar_name_equal. * ar.c (ar_member_date_1): Likewise. Wed Apr 28 21:18:22 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (reap_children): Before calling start_job_command to start the next command line, reset C->remote by calling start_remote_job_p. Mon Apr 26 15:56:15 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * arscan.c (ar_scan): New local var NAMEMAP. In loop, rename NAME to NAMEBUF; new var NAME is a pointer; new flag IS_NAMEMAP. When extracting the member name, always put a null at its end first. If the name is "//" or "/ARFILENAMES", set IS_NAMEMAP. If we have already read in NAMEMAP, and NAME looks like " /N", get full name from NAMEMAP+N. Else if NAME looks like "#1/N", read N chars from the elt data to be the full name. At end of loop, if IS_NAMEMAP, read the elt's data into alloca'd NAMEMAP. (ar_name_equal): #if 0 truncating code. * make.h: Don't declare vfork at all. It returns int anyway, unless declared it; and we conflicted with some systems. * main.c (define_makeflags): If FLAGSTRING[1] is '-', define MAKEFLAGS to all of FLAGSTRING, not &FLAGSTRING[1]. Don't want to define it to something like "-no-print-directory". Use %g format instead of %f for floating-valued things. Thu Apr 22 18:40:58 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * GNUmakefile (Makefile.in): Use a substitution ref on nolib-deps to change remote-%.dep to remote-stub.dep. Wed Apr 21 15:17:54 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.64. Fri Apr 16 14:22:22 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (install): Remove - prefix from chgrp+chmod. * Version 3.63.8. Thu Apr 15 18:24:07 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * acconfig.h: New file; contains "#undef SCCS_GET" for autoheader. * configure.in: If /usr/sccs/get exists, define SCCS_GET to that, else to "get". * default.c (default_variables): Set GET to macro SCCS_GET. * read.c (parse_file_seq): Take extra arg STRIP; strip `./' only if nonzero. I hope this is the last time this argument is added or removed. (read_makefile): Pass it 1 when parsing include file names. Pass it 1 when parsing target file names. Pass it 1 when parsing static pattern target pattern names. * rule.c (install_pattern_rule): Pass it 1 when parsing rule deps. * default.c (set_default_suffixes): Pass it 1 when parsing default_suffixes. * function.c (string_glob): Pass it 0 here. Wed Apr 14 11:32:05 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * misc.c (log_access): New function. ({init,user,make,child}_access): Call it. (child_access): Abort if !access_inited. * main.c (switches: --no-print-directory): Use 1 instead of -1 for single-letter option. (init_switches, decode_switches, define_makeflags): An option with no single-letter version is no longer indicated by a value of -1; instead a value that is !isalnum. (init_switches): Don't put such switches into the string, only into the long_option table. * make.h [!NSIG] [!_NSIG]: #define NSIG 32. * job.c [HAVE_WAITPID]: Remove #undef HAVE_UNION_WAIT. AIX's bsdcc defined WIF* to use union wait. * main.c (struct command_switch): Change member `c' to type int. (switches): Make const. (decode_switches): Use `const struct command_switch *'. (define_makeflags): Likewise. * default.c (default_suffix_rules): Add `-o $@' to makeinfo rules. Mon Apr 12 12:30:04 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.63.7. * configure.in (AC_HAVE_HEADERS): Check for string.h and memory.h. Removed AC_MEMORY_H. * make.h [USG, NeXT]: Don't test these. [HAVE_STRING_H]: Test this to include string.h and define ANSI_STRING. [HAVE_MEMORY_H]: Test this instead of NEED_MEMORY_H. [! ANSI_STRING]: Put decls of bcopy et al here. [sparc]: Don't test this for alloca.h; HAVE_ALLOCA_H is sufficient. [HAVE_SIGSETMASK]: Test this rather than USG. [__GNU_LIBRARY__ || POSIX]: Don't #include again. * main.c (main): Handle SIGCHLD if defined, and SIGCLD if defined. It doesn't hurt to do both if they are both defined, and testing USG is useless. * dir.c: Rationalize directory header conditionals. * arscan.c [HAVE_FCNTL_H]: Test this rather than USG || POSIX. * default.c (default_suffixes): Add `.txinfo'. (default_suffix_rules): Add `.txinfo.info' and `.txinfo.dvi' rules. * variable.c (try_variable_definition): Replace RECURSIVE flag with enum FLAVOR, which can be simple, recursive, or append. Recognize += as append flavor. Set new variable VALUE in a switch on FLAVOR. For append flavor, prepend the variable's old value. If the variable was previously defined recursive, set FLAVOR to recursive; if it was defined simple, expand the new value before appending it to the old value. Pass RECURSIVE flag to define_variable iff FLAVOR == recursive. * variable.c (try_variable_definition): Use alloca and bcopy for NAME, instead of savestring. Might as well use stack storage since we free it immediately anyway. Thu Apr 8 18:04:43 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (start_waiting_jobs): Move decl of JOB outside of loop. * main.c (define_makeflags): Rename `struct flag' member `switch' to `cs', which is not a reserved word. Wed Apr 7 15:30:51 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (new_job): Call start_waiting_jobs first thing. (start_waiting_job): Changed return type from void to int. Return 0 when putting the child on the waiting_jobs chain. (start_waiting_jobs): Don't check load and job_slots here. Always take a job off the chain and call start_waiting_job on it; give up and return when start_waiting_job returns zero. * main.c (define_makeflags: struct flag): Change member `char c' to `struct command_switch *switch'. (ADD_FLAG): Set that to CS instead of CS->c. If CS->c is -1, increment FLAGSLEN for the long name. When writing out FLAGS, handle FLAGS->switch->c == -1 and write the long name instead. * compatMakefile (stamp-config): New target of old config.h rule. Touch stamp-config after running config.status. (config.h): Just depend on stamp-config, and have empty commands. Mon Apr 5 20:14:02 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c [HAVE_WAITPID]: #undef HAVE_UNION_WAIT. * configure.in (AC_HAVE_FUNCS): Check for psignal. Fri Apr 2 17:15:46 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (long_option_aliases): Remove "new"; it is already an unambiguous prefix of "new-file". Sun Mar 28 16:57:17 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.63.6. Wed Mar 24 14:26:19 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * vpath.c (selective_vpath_search): When adding the name-within-directory at the end of NAME, and we don't add a slash, don't copy FILENAME in one char too far into NAME. * variable.c (define_automatic_variables): Find default_shell's length with strlen, not numerology. Wed Mar 17 20:02:27 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (define_makeflags): Add the elts of a string option in reverse order, so they come out right when reversed again. Fri Mar 12 15:38:45 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (make.info): Use `-o make.info'. Thu Mar 11 14:13:00 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (REMOTE): Set to @REMOTE@; change comments to reflect new use. (objs): Replace remote.o with remote-$(REMOTE).o. (srcs): Replace remote.c with remote-$(REMOTE).c. (remote.o): Rule removed. * configure.in (REMOTE): Subst this in Makefile et al; default "stub". Use AC_WITH to grok --with-customs arg to set REMOTE=cstms. * GNUmakefile (build.sh.in): Filter out remote-% from objs list. * build.template (REMOTE): New var; set to @REMOTE@. (objs): Add remote-${REMOTE}.o. Wed Mar 10 15:12:24 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.63.5. * implicit.c (pattern_search): Fix "dependent"->"dependency" in "Rejecting impossible" -d msg. * file.c (file_hash_enter): New local vars {OLD,NEW}BUCKET. Store mod'd values there; never mod {OLD,NEW}HASH. Mon Mar 8 13:32:48 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * remake.c [eta10]: Include instead of . * compatMakefile (VPATH): Set this to @srcdir@. (srcdir): Set this to $(VPATH). * main.c (main): New local var DIRECTORY_BEFORE_CHDIR. Save in it a copy of CURRENT_DIRECTORY after the first getcwd. Use it instead of CURRENT_DIRECTORY when chdir'ing back before re-execing. * remake.c (notice_finished_file): Pass missing SEARCH arg to f_mtime. * read.c (read_makefile): Remove extraneous arg to parse_file_seq. Mon Feb 22 14:19:38 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile ($(infodir)/$(instname).info): Use , instead of / as the sed delimiter char. Sun Feb 21 14:11:04 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.63.4. * rule.h (struct rule): Removed `subdir' member. * rule.c (new_pattern_rule): No need to clear it. (count_implicit_rule_limits): Set the `changed' flag in each dep that refers to a nonexistent directory. No longer set rule-global `subdir' flag with that information. (print_rule_data_base): Don't record info on `subdir' flags. * implicit.c (pattern_search): Check the DEP->changed flag rather than the (now gone) RULE->subdir flag. Also test CHECK_LASTSLASH; if it is set, the file might exist even though the DEP->changed flag is set. * rule.c (count_implicit_rule_limits): Pass "", not ".", as file name arg to dir_file_exists_p to check for existence of directory. * implicit.c (pattern_search): Inside dep-finding loop, set CHECK_LASTSLASH from the value recorded in CHECKED_LASTSLASH[I], rather than computing it anew. * commands.c (set_file_variables): Must alloca space for PERCENT and copy it, to avoid leaving the trailing `)' in the value. * misc.c (remove_comments): Fixed backslash-checking loop condition to allow it to look at the first char on the line. P2 >= LINE, not P2 > LINE. * compatMakefile ($(bindir)/$(instname)): Before moving $@.new to $@, rm $@.old and mv $@ to $@.old. * variable.c (try_variable_definition): Take new args FILENAME and LINENO. Fatal if the variable name is empty. * read.c (read_makefile): Change callers. * main.c (main): Likewise. * compatMakefile (group): Define to @KMEM_GROUP@, autoconf magic that configure will replace with the group owning /dev/kmem. Mon Feb 8 14:26:43 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * vpath.c (vpath_search): Take second arg MTIME_PTR, pass thru to selective_vpath_search. (selective_vpath_search): Take second arg MTIME_PTR. If the dir cache thinks a file exists, stat it to make sure, and put the modtime in *MTIME_PTR. * remake.c (library_search): Take second arg MTIME_PTR. When we find a match, record its mtime there. Pass MTIME_PTR through to vpath_search to do same. (f_mtime): Pass &MTIME as new 2nd arg to {vpath,library}_search; store it in FILE->last_mtime if set nonzero. * implicit.c (pattern_search): Pass nil 2nd arg to vpath_search. * compatMakefile (remote.o): Prepend `$(srcdir)/' to `remote-*.c', so globbing looks somewhere it will find things. * compatMakefile ($(infodir)/$(instname).info): Install `make.info*' not `$(srcdir)/make.info*'; no need to use basename. Fri Feb 5 12:52:43 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.63.3. * compatMakefile (install): Add missing ;\s. Make -, @, and + prefixes on a pre-expanded command line affect all lines in the expansion, not just the first. * commands.h (struct commands): Replace `lines_recurse' member with `lines_flags'. (COMMANDS_{RECURSE,SILENT,NOERROR}): New macros, bits to set in that flag byte. * commands.c (chop_commands): Set `lines_flags' instead of `lines_recurse'. Record not only + but also @ and - prefixes. * remake.c (notice_finished_file): Check the COMMANDS_RECURSE bit in FILE->cmds->lines_flags, rather than FILE->cmds->lines_recurse. * job.c (start_job_command): Replaced RECURSIVE and NOPRINT local var with FLAGS; initialize it to the appropriate `lines_flags' byte. Set CHILD->noerror if the COMMANDS_NOERROR bit is set in FLAGS. Set the COMMANDS_SILENT bit in FLAGS for a @ prefix. * remake.c (update_goal_chain): Set G->file to its prev after checking for G being finished, since that check needs to examine G->file. * configure.in (union wait check) [HAVE_WAITPID]: Try using waitpid with a `union wait' STATUS arg. If waitpid and union wait don't work together, we should not use union wait. * Version 3.63.2. * remake.c (update_goal_chain): When G->file->updated, move G->file to its prev. We aren't finished until G->file is nil. Thu Feb 4 12:53:04 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (starting_directory): New global variable. (main): Set it to cwd after doing -Cs. (log_working_directory): Use it, rather than computing each time. * make.h: Declare it. * compatMakefile (SHELL): Define to /bin/sh for losing Unix makes. * main.c (decode_env_switches): Allocate (1 + LEN + 1) words for ARGV, rather than LEN words plus one byte. Wed Feb 3 18:13:52 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile ($(bindir)/$(instname)): Put - before install_setgid command line, so its failure won't be an error. (infodir): New variable. (install): Depend on $(infodir)/$(instname).info. ($(infodir)/$(instname).info): New target. * read.c (read_makefile): If FILENAMES is nil when we see a line starting with a tab, don't treat it as a command. Just fall through, rather than giving an error. * read.c (read_makefile): If the NO_TARGETS flag is set when we see a command line, don't clear it before continuing. We want subsequent command lines to be ignored as well. * job.c (new_job): Before expanding each command line, collapse backslash-newline combinations that are inside var or fn references. Mon Feb 1 16:00:13 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (exec_prefix): Default to $(prefix), not /usr/local. * compatMakefile (make.info): Pass -I$(srcdir) to makeinfo. * job.c [POSIX] (unblock_sigs): Made global. [!POSIX] (unblock_sigs): Move defns to job.h. * job.h [POSIX] (unblock_sigs): Declare. Sun Jan 31 19:11:05 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * read.c (read_makefile): In vpath parsing, after finding the pattern token, take entire rest of line as the search path, not just the next token. * compatMakefile (remote.o): Depend on remote-*.c. Thu Jan 28 16:40:29 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * commands.c (set_file_variables): Don't define any F or D versions. * variable.c (define_automatic_variables): Define them here as recursively-expanded variables that use the dir and notdir funcs. * variable.c (target_environment): In v_default case, don't export o_default or o_automatic variables. * configure.in (union wait check): Remove ` and ' inside C code; they confuse the shell script. Mon Jan 25 13:10:42 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.63.1. * vpath.c (construct_vpath_list): When skipping further processing of an elt that is ".", don't also skip the code that pushes P past the next separator. * compatMakefile (distclean): Don't remove make-*. * configure.in (HAVE_UNION_WAIT): Try to use WEXITSTATUS if it's defined. If one cannot use WEXITSTATUS with a `union wait' argument, we don't want to believe the system has `union wait' at all. * remake.c (update_file): Do nothing to print "up to date" msgs. (update_goal_chain): Do it here instead. Use the `changed' flag of each goal's `struct dep' to keep track of whether files_remade (now commands_started) changed around a call to update_file for that goal. When a goal is finished, and its file's update_status is zero (i.e., success or nothing done), test the `changed' flag and give an "up to date" msg iff it is clear. * make.h (files_remade): Renamed to commands_started. * remake.c: Changed defn. (update_goal_chain): Changed uses. * job.c (start_job_command): Increment commands_started here. (reap_children): Not here. * remake.c (update_goal_chain): Don't do anything with files' `prev' members. update_file now completely handles this. * variable.c (target_environment): Don't expand recursive variables if they came from the environment. * main.c (define_makeflags): For flags with omitted optional args, store {"", 0} with ADD_FLAG. When constructing FLAGSTRING, a flag so stored cannot have more flags appended to the same word. Fri Jan 22 14:46:16 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (print_variable_set): In vars/bucket calculation, don't spuriously multiply by 100. * Version 3.63. * job.c [!HAVE_UNION_WAIT] (WTERMSIG, WCOREDUMP, WEXITSTATUS): Don't define if already defined. * remake.c (update_file): Don't keep track of the command_state before calling update_file_1. Remove local variable COMMANDS_FINISHED, and don't test it to decide to print the "is up to date" msg. Testing for files_remade having changed should always be sufficient. The old method lost when we are called in the goal chain run on a makefile, because the makefile's command_state is already `cs_finished' from the makefile chain run. * misc.c [HAVE_SETRE[GU]ID]: Test these to decl setre[gu]id. * configure.in: Rewrote wait checking. Use AC_HAVE_HEADERS to check for . Use AC_HAVE_FUNCS to check for waitpid and wait3. Use a compile check to test just for `union wait'. * job.c: Rewrote conditionals accordingly. [HAVE_WAITPID]: Test this only to define WAIT_NOHANG. [HAVE_WAIT3]: Likewise. [HAVE_UNION_WAIT]: Test this to define WAIT_T and W*. * configure.in: Set CFLAGS and LDFLAGS before all checks. * dir.c: Add static forward decls of {open,read}_dirstream. Thu Jan 21 17:18:00 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.31. * job.c [NGROUPS_MAX && NGROUPS_MAX==0]: #undef NGROUPS_MAX. * compatMakefile (CFLAGS, LDFLAGS): Set to @CFLAGS@/@LDFLAGS@. * build.template (CFLAGS, LDFLAGS): Same here. * configure.in: AC_SUBST(CFLAGS) and LDFLAGS. Set them to -g if not defined in the environment. * remake.c (library_search): Use LIBNAME consistently, setting it only once, to be the passed name sans `-l'. Pass new var FILE to be modified by vpath_search. Mon Jan 18 14:53:54 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.30. * job.c (start_waiting_jobs): Return when job_slots_used is equal to job_slots. * configure.in: Add AC_CONST for the sake of getopt. * read.c (read_makefile): Continue after parsing `override' directive, rather than falling through to lossage. Check for EOL or blank after "override define". * compatMakefile (.c.o, remote.o): Put $(CFLAGS) after other switches. Fri Jan 15 12:52:52 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.29. * main.c (define_makeflags): After writing everything into FLAGSTRING, only back up two chars if [-1] is a dash, meaning we just wrote " -". Always terminate the string at *P. * remake.c (library_search): When constructing names in std dirs, use &(*LIB)[2] for the stem, not LIBNAME (which points at the buffer we are writing into!). Thu Jan 14 13:50:06 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Set IN_IGNORED_DEFINE for "override define" when IGNORING is true. * compatMakefile (distclean): Remove config.status and build.sh. Wed Jan 13 16:01:12 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.28. * misc.c (xmalloc, xrealloc): Cast result of malloc/realloc to (char *). * arscan.c (ar_scan) [AIAMAG]: Cast read arg to (char *). * variable.c (define_automatic_variables): Override SHELL value for origin o_env_override as well as o_env. * GNUmakefile (build.sh.in): Don't replace %globobjs%. Instead, add the names of the glob objects (w/subdir) to %objs%. * build.template (globobjs): Removed. Take basename of $objs before linking. Tue Jan 12 12:31:06 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.27. * configure.in (AC_OUTPUT): Also edit build.sh. * build.template: New file. * GNUmakefile (build.sh.in): New rule to create it from build.template. (make-$(version).tar.Z): Depend on build.sh.in. * main.c (die): Call print_data_base if -p. (main): Don't call it here. * compatMakefile (defines): Add @DEFS@. configure should turn this into -DHAVE_CONFIG_H. Mon Jan 11 14:39:23 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.26. * misc.c (init_access): Surround with #ifdef GETLOADAVG_PRIVILEGED. ({make,user,child}_access) [! GETLOADAVG_PRIVILEGED]: Make no-op. * compatMakefile (install_setgid): New var, set by configure. (install): Install setgid $(group) only if $(install_setgid) is true. Fri Jan 8 15:31:55 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (load_too_high): If getloadavg fails with errno==0, give a message saying that load limits are not supported. * vpath.c (construct_vpath_list): Rewrote path deletion code to not try to use PATH's next link after freeing PATH. * main.c (define_makeflags): Rewritten; now handles string-valued option, and has no arbitrary limits. (switches): Set `toenv' flag for -I and -v. * main.c (decode_env_switches): Cast return value of alloca to char *. * misc.c (child_access) [HAVE_SETREUID, HAVE_SETREGID]: Use setre[gu]id in place of set[gu]id. Wed Jan 6 15:06:12 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (main): Define MAKEOVERRIDES, MAKE, and MAKE_COMMAND with origin o_default. * make.h [POSIX]: Don't test this to use ANSI_STRING. Testing STDC_HEADERS should be sufficient. * job.h: Declare start_waiting_jobs. * read.c (read_makefile): Add missing parens in if stmt that find conditional directives. * main.c (main): Declare init_dir. * implicit.c (pattern_search): Always use two % specs in a DEBUGP2, and always pass two non-nil args. Cast field width args to int. Add missing parens in !RULE->subdir if stmt. * function.c (expand_function, patsubst_expand): Add parens around assignments inside `while' stmts. * commands.c (print_commands): Cast field width args to int. * read.c (do_define): Cast return value of alloca to (char *). * main.c (init_switches): New function, broken out of decode_switches. (decode_switches): Take new arg ENV. If set, ignore non-option args; print no error msgs; ignore options with clear `env' flags. (decode_env_switches): Rewritten to chop envar value into words and pass them to decode_switches. (switches): Set `env' flag for -I and -v. * dir.c (init_dir): Cast free to __glob_closedir_hook's type. Tue Jan 5 14:52:15 1993 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.25. * job.c [HAVE_SYS_WAIT || !USG]: Don't #include and . interacts badly with , and we don't need these anyway. * configure.in (AC_HAVE_FUNCS): Check for setre[gu]id. * misc.c ({user,make}_access): Test #ifndef HAVE_SETRE[GU]ID, not #ifdef POSIX || USG. SunOS 4.1 is supposedly POSIX.1 compliant, but its set[gu]id functions aren't; its setre[gu]id functions work. * misc.c ({user,make,child}_access): Give name of caller in error msgs. * job.c (load_too_high): Say "cannot enforce load limit" in error msg. * configure.in: Call AC_PROG_CC. * compatMakefile (CC): Define to @CC@ (autoconf magic). * compatMakefile: Add .NOEXPORT magic target. Mon Jan 4 17:00:03 1993 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (print_version): Updated copyright to include 93. Thu Dec 31 12:26:15 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * make.h [_AIX]: Don't declare alloca. Tue Dec 29 13:45:13 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.24. * compatMakefile (objs): Add signame.o. (srcs): Add signame.[ch]. * compatMakefile (srcs): Add config.h.in. (remote.o): Add -I. before -I$(srcdir). Mon Dec 28 15:51:26 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.23. * read.c (readline): Fatal when LEN==0, indicating a line starting with a NUL. (readline): Take new arg LINENO, for use in error msg. (read_makefile, do_define): Pass it. * compatMakefile (glob/libglob.a): Pass -DHAVE_CONFIG_H in CPPFLAGS. (.c.o): Add -I. before -I$(srcdir). Wed Dec 23 12:12:04 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Accept and ignore a rule with no targets. * compatMakefile (ALLOCA_SRC): New variable. (srcs): Include its value. * read.c (struct conditional): Renamed member `max_ignoring' to `allocated'; added new member `seen_else'. (conditional_line): Initialize seen_else flag when starting an `if...'; set it when we see an `else'; fatal if set when we see `else'. (read_makefile): Fatal "missing `endif'" if there are any pending conditionals, not just if we are still ignoring. Tue Dec 22 15:36:28 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (manext): Set to 1, not l. ($(mandir)/$(instname).$(manext)): Use $(srcdir) for make.man in cmds. * file.c (file_hash_enter): Don't call uniquize_deps here. * read.c (record_files): Likewise. * implicit.c (pattern_search): Likewise. * commands.c (set_file_variables): Call it only here. * default.c (default_variables) [__convex__]: FC=fc. * variable.c (target_environment): Expand the values of recursively expanded variables when putting them into the environment. * expand.c (recursively_expand): Made global. * make.h (recursively_expand): Declare it. * remake.c (check_dep): Set FILE->command_state to cs_deps_running when a dep's command_state is cs_running or cs_deps_running. * read.c (read_makefile): Changed error msg for spurious cmds to not say "first target". Sun Dec 20 17:56:09 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * configure.in: Do AC_CONFIG_HEADER right after AC_INIT. * make.h (HAVE_CONFIG_H): #include "config.h", then #define this. * compatMakefile (config.h, configure, config.h.in): New rules. (defines): Removed @DEFS@. Thu Dec 17 16:11:40 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (realclean): Just depend on distclean; no cmds. (distclean): Do what realclean did before; also remove Makefile and config.h; don't remove configure. (info, dvi): New targets; depend on make.{info,dvi}. (doc): Removed target. (MAKEINFO, TEXI2DVI): New vars. (make.info, make.dvi): Use them instead of explicit cmds. Wed Dec 16 16:25:24 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * configure.in: Added fcntl.h to AC_HAVE_HEADERS. getloadavg cares. Wed Dec 9 15:21:01 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (long_option_aliases): Add --new-file alias for -W. * default.c (default_variables): Change all C++ to CXX and C++FLAGS to CXXFLAGS. * read.c (do_define): Expand the variable name before using it. * main.c (main): Define variable "MAKE_COMMAND" to argv[0]; define "MAKE=$(MAKE_COMMAND) $(MAKEOVERRIDES)" always. * remake.c (library_search): Search for libNAME.a in cwd; look in vpath before looking in standard dirs, not after. Changed order of std dirs to: /lib, /usr/lib, ${prefix}/lib. Mon Nov 23 14:57:34 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * default.c (default_pattern_rules, default_terminal_rules): Added brackets around initializers. * variable.c (try_variable_definition): Don't check for LINE[0]=='\t'. (try_variable_definition): Expand the name before defining the var. * job.c (init_siglist): Removed function. Removed decl of `sys_siglist'. * make.h [! HAVE_SYS_SIGLIST]: #include "signame.h". [HAVE_SYS_SIGLIST && !SYS_SIGLIST_DECLARED]: Declare sys_siglist only under these conditions. * main.c (main): Don't declare init_siglist. (main) [! HAVE_SYS_SIGLIST]: Call signame_init instead of init_siglist. Wed Nov 18 14:52:51 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (record_files): Don't try to append to FIRSTDEPS if it's nil; instead just set it to MOREDEPS. Mon Nov 16 17:49:17 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * vpath.c (construct_vpath_list): Initialize P to DIRPATH before loop that sets MAXELEM. Fri Nov 13 18:23:18 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.22. Thu Nov 12 15:45:31 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (start_job_command): Under -n, increment files_remade after processing (i.e., printing) all command lines. Tue Nov 10 15:33:53 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * read.c (record_files): Append new deps if this rule has no commands; prepend them to existing deps if this rule has no commands. * dir.c (open_dirstream): Return nil if DIR->contents->files is nil. * read.c (parse_file_seq): Removed last arg STRIP. Always strip `./'s. (read_makefile): Changed callers. * function.c (string_glob): Likewise. * rule.c (install_pattern_rule): Likewise. Mon Nov 9 17:50:16 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (files_remade): Made global. (notice_finished_file): Don't increment files_remade here; this function gets called in many situations where no remaking was in fact done. * job.c (reap_children): Do it here instead, when we know that actual commands have been run for the file. * make.h (files_remade): Declare it. Thu Nov 5 18:26:10 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * vpath.c (construct_vpath_list): Allow blanks as well as colons to separate elts in the search path. * read.c (read_makefile): Don't fatal on extra tokens in `vpath'. The search path can contain spaces now. Tue Nov 3 20:44:32 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (check): New target; no-op. * file.c (file_hash_enter): Mod OLDHASH by FILE_BUCKETS after testing for OLDHASH==0 but before using the value. (rename_file): Don't mod OLDHASH by FILE_BUCKETS before passing it to file_hash_enter. * file.c (rename_file): Notice when OLDFILE->cmds came from default.c, and don't try to print ->filename in that case. Sun Oct 25 01:48:23 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (update_file): Don't process F->also_make here. (notice_finished_file): Don't process FILE->also_make if no attempt to update FILE was actually made. Fixed to call f_mtime directly to refresh their modtimes. Sat Oct 24 22:08:59 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (find_percent): Don't increment P again after skipping an escaped %. * expand.c (variable_expand): In call to patsubst_expand, don't find `%'s ourselves; let that function do it. * read.c (read_makefile: record_waiting_files): Don't call record_files if FILENAMES is nil. (read_makefile): All alternatives in the parsing, except for rule lines, fall through to the end of the loop. At the end of the loop, do record_waiting_files so we notice later spurious cmds. Fri Oct 23 15:57:37 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (define_automatic_variables): Free old value of SHELL before replacing it. Thu Oct 15 18:57:56 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (.c.o): Add -I$(srcdir)/glob to flags. * dir.c (open_dirstream): Cast return value to __ptr_t. * default.c (default_variables: "GET") [_IBMR2]: Use USG defn. * make.h (MAXPATHLEN): Moved out of #ifndef POSIX. (GET_PATH_MAX): Moved from #ifdef POSIX to #ifdef PATH_MAX #else. Define as (get_path_max ()). [! PATH_MAX] (NEED_GET_PATH_MAX): Define. [! PATH_MAX] (get_path_max): Declare fn. * misc.c [NEED_GET_PATH_MAX] (get_path_max): New function. Mon Oct 12 13:34:45 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.21. * job.c (sys_siglist): Only declare #ifndef SYS_SIGLIST_DECLARED. * make.h [! HAVE_SYS_SIGLIST && HAVE__SYS_SIGLIST]: #define SYS_SIGLIST_DECLARED. * dir.c (file_impossible): When initializing DIR->contents, set DIR->contents->dirstream to nil. * compatMakefile (GLOB): Define new variable. (objs): Use it, rather than glob/libglob.a explicitly. * read.c (parse_file_seq): When stripping "./", handle cases like ".///foo" and "./////". * file.c (lookup_file, enter_file): Likewise. Sun Oct 11 17:00:35 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * dir.c (struct dirstream, {open,read}_dirstream): New data type and functions to read a directory sequentially. (init_dir): New function to hook it into glob. * main.c (main): Call init_dir. * compatMakefile (objs): Added glob/libglob.a. * configure.in: Remove code to test for glob. Fri Oct 9 12:08:30 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (record_files): Generalized test for NAME pointing somewhere into F->name. * variable.c (define_variable_in_set): Free old value when replacing. * read.c (do_define): Free the linebuffer before returning. (record_files): When clearing .SUFFIXES deps, free their data. (multi_glob): Free OLD and its data when replacing it with results of glob run. * commands.c (set_file_variables): Use alloca in place of xmalloc for temp space for $^, $?, et al. * dir.c (struct directory): New member `contents' replaces `files' and `dirstream'. (struct directory_contents): New type. (directories_contents): New hash table. (dir_struct_file_exists_p): Take a struct directory_contents. (dir_file_exists_p): Pass it the `contents' member of the dir found. (dir_struct_file_exists_p): Renamed to dir_contents_file_exists_p; made static. Return 0 if DIR is nil (meaning it couldn't be stat'd). (dir_file_exists_p, find_directory): Change all callers. (file_impossible): Use DIR->contents, initializing it if nil. (print_dir_data_base): Use DIR->contents, and print out device and inode numbers with each directory. * Changes for performance win from John Gilmore : * dir.c (DIRECTORY_BUCKETS): Increase to 199. (DIRFILE_BUCKETS): Decrease to 107. (find_directory): Allocate and zero a multiple of sizeof (struct dirfile *), not of sizeof (struct dirfile). (dir_struct_file_exists_p): New function, nearly all code from dir_file_exists_p. (dir_file_exists_p): Just call find_directory+dir_struct_file_exists_p. * vpath.c (selective_vpath_search): Remove redundant dir_file_exists_p call. * configure.in: Comment out glob check; always use our code. Fri Oct 2 19:41:20 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * make.h [! HAVE_SYS_SIGLIST && HAVE__SYS_SIGLIST]: #define HAVE_SYS_SIGLIST; after doing #define sys_siglist _sys_siglist, we do have it. Wed Sep 30 19:21:01 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (main): Don't do -w automatically if -s. Tue Sep 29 21:07:55 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (printed_version): Move variable inside print_version. (print_version): Return immediately if printed_version is set. (die): Don't test printed_version here. (decode_switches): Under -v, do print_version before giving usage. (DESCRIPTION_COLUMN): New macro. (decode_switches): Use it when printing the usage message. Leave at least two spaces between options and their descriptions. Fri Sep 25 13:12:42 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.20. Wed Sep 16 16:15:22 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * read.c (read_makefile): Save errno value from trying to open FILENAME, and restore it before erring; otherwise we get the errno value from the last elt of the search path. Tue Sep 15 15:12:47 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (long_option_aliases): Add --stop for -S. * read.c (word1eq): Do strncmp before dereferencing someplace that may be out in space. Wed Sep 9 15:50:41 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (notice_finished_file): If all the command lines were recursive, don't do the touching. * job.c (start_job_command): Don't check for + here. * commands.c (chop_commands): Do it here instead. * default.c (default_terminal_rules): Prepend + to cmds for RCS. Wed Sep 2 17:53:08 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (objs): Include $(ALLOCA). * make.h [CRAY]: Move #define signal bsdsignal to before #includes. Thu Aug 27 17:45:43 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * read.c (default_include_directories): Add INCLUDEDIR first. * compatMakefile (includedir): Define. (defines): Add -D for INCLUDEDIR="$(includedir)". * read.c (read_makefile): Grok multiple files in `include'; globbing too. * remake.c (library_search): New function. (library_file_mtime): Remove function. (f_mtime): Use library_search instead of library_file_mtime. * compatMakefile (libdir): Define. (defines): Add -D for LIBDIR="$(libdir)". * make.texinfo (Libraries/Search): Document change. * file.c (rename_file): Fix file_hash_enter call with missing arg. Wed Aug 26 17:10:46 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.19. * main.c (main): Set command_state to cs_finished for temp files made for stdin makefiles. * main.c (decode_switches): Don't tell getopt to return non-option args in order. Ignore an argument of `-'. Thu Aug 20 13:36:04 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c (start_job_command): If (touch_flag && !RECURSIVE), ignore the command line and go to the next. (notice_finished_file): Under -t, touch FILE. * remake.c (remake_file): Don't touch it here. Wed Aug 19 16:06:09 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * function.c (pattern_matches): Use temporary for strlen (WORD) instead of two function calls. * compatMakefile (LOAD_AVG): Remove variable and comments. Tue Aug 18 14:58:58 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * make.texinfo (Running): Node renamed to `make Invocation'. Fri Aug 14 12:27:10 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * arscan.c (ar_name_equal): Don't compare [MAX-3..MAX] if NAMELEN != MEMLEN. Thu Aug 13 17:50:09 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.18. * main.c: Don't #include ; make.h already does. Mon Aug 10 17:03:01 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * implicit.c (pattern_search): Fixed copying of suffix when building also_make elts. * function.c (expand_function: `shell'): Make sure BUFFER is null-terminated before replacing newlines. * compatMakefile (mandir): Use man$(manext), not always manl. Sun Aug 2 01:42:50 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * rule.c (new_pattern_rule): Not static. * rule.h: Declare it. * file.c (file_hash_enter): New function, most code from rename_file. (rename_file): Call it. * file.h (file_hash_enter): Declare it. * dep.h: Doc fix. Thu Jul 30 15:40:48 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (decode_switches): Handle usage_and_exit when building long options vector. * default.c (default_terminal_rules): Make RCS rules use $(CHECKOUT,v). (default_variables): Define CHECKOUT,v (hairy). * make.h [!HAVE_SYS_SIGLIST && HAVE__SYS_SIGLIST]: #define sys_siglist to _sys_siglist. Sun Jul 26 16:56:32 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * NEWS: Add header and tail copyright info like Emacs NEWS. * make.h [ANSI_STRING]: Don't #define index, rindex, bcmp, bzero, bcopy if already #define'd. [STDC_HEADERS] (qsort, abort, exit): Declare here. [! __GNU_LIBRARY__ && !POSIX]: Not here. * make.h [_AIX]: #pragma alloca first thing. * job.c (start_waiting_job): Set the command_state to cs_running when we queue a job on waiting_jobs. Fri Jul 24 02:16:28 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.c (define_automatic_variables): Use "" instead of nil for empty value. Thu Jul 23 22:31:18 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.17. * main.c (struct command_switch.type): Add alternative usage_and_exit. (command_switches): Add -h/--help. Thu Jul 16 14:27:50 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * GNUmakefile (make-$(version).tar.Z): Include NEWS, not CHANGES. * README.template: Mention NEWS. * CHANGES: Renamed to NEWS. * main.c [! STDC_HEADERS] [sun]: Don't declare exit. Tue Jul 14 18:48:41 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (main): Set -o files' command_states to cs_finished. * rule.c (count_implicit_rule_limits): Decrement num_pattern_rules when tossing a rule. * main.c (main): Use alloca only in simple local var assignment, for braindead SGI compiler. * rule.c (print_rule_data_base): Barf if num_pattern_rules is inconsistent with the number computed when listing them. Mon Jul 13 17:51:53 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * commands.c (set_file_variables): For $? and $^ elts that are archive member refs, use member name only. Fri Jul 10 00:05:04 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * variable.h (struct variable.export): Add new alternative v_ifset. * variable.c (target_environment): Check for it. (define_automatic_variables): Set it for MAKEFILES. Thu Jul 9 21:24:28 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (objs): Remove getloadavg.o; $(extras) gets it. (remote.o): Use $(srcdir)/remote.c, not $remote.c<. (distclean, mostlyclean): New targets. Tue Jul 7 19:12:49 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.16. * compatMakefile (config.status): Remove rule. * job.c (start_waiting_job): Free C after using C->file, not before. Sat Jul 4 20:51:49 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * commands.c, job.c, main.c, make.h, remote-cstms.c: Use #ifdef HAVE_* instead of #ifndef *_MISSING. * configure.in: Use AC_HAVE_FUNCS instead of AC_MISSING_FUNCS (gone). Thu Jul 2 18:47:52 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * main.c (main): makelevel>0 or -C implies -w. Tue Jun 30 20:50:17 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * file.c, job.c, function.c: Don't #include . make.h: Do it here instead. * arscan.c (ar_member_touch): Don't declare errno. Thu Jun 25 17:06:55 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * GNUmakefile (make-$(version).tar.Z): Depend on INSTALL, configure.in. * remake.c (update_file): If commands or deps are running after update_file_1 returns, break out of the :: rule (->prev) loop and just return. * job.c (job_next_command): New function; code from start_job. (start_job_command): Renamed from start_job. Call job_next_command and recurse for empty command lines and -n. (start_waiting_job): Call start_job_command, not start_job. (new_job): Call job_next_command to prime the child structure, and then call start_waiting_job. (reap_children): Use job_next_command and start_job_command. (start_waiting_job): Call start_remote_job_p here, and store its result in C->remote. If zero, check the load average and maybe put C on waiting_jobs. (start_job_command): Test CHILD->remote rather than calling start_remote_job_p. Don't do load avg checking at all here. * main.c (main): Don't handle SIGILL, SIGIOT, SIGEMT, SIGBUS, SIGSEGV, SIGFPE or SIGTRAP. * compatMakefile (glob/libglob.a): Don't pass srcdir to sub-make. configure will set it in glob/Makefile. Wed Jun 24 19:40:34 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * dir.c [DIRENT] (direct): Don't define to dirent. [! DIRENT] (direct): Define to dirent. (dir_file_exists_p): Use struct dirent instead of struct direct. * make.h (getcwd): No space between macro and ( for args! * job.c (start_job): Don't put the job on waiting_jobs if job_slots_used==0. * make.texinfo (Missing): Shortened title. Tue Jun 23 18:42:21 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * file.c (remove_intermediates): Print "rm" commands under -n. Mon Jun 22 16:20:02 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.15. Fri Jun 19 16:20:26 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * arscan.c [M_UNIX]: #undef M_XENIX. Wed Jun 17 17:59:28 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * default.c (default_terminal_rules): Put @ prefix on RCS cmds. Tue Jun 16 19:24:17 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile (getloadavg.o): Removed special rule. (CFLAGS): Don't include $(defines). (.c.o): Define suffix rule. (glob/libglob.a): Pass CPPFLAGS=$(defines) to submake. (GETOPT_SRC, srcs, tagsrcs): Prefix files with $(srcdir)/. * arscan.c (ar_name_equal): Moved local vars inside #if'd block. * make.h (max): Removed. * expand.c (variable_buffer_output): Don't use it. * compatMakefile (INSTALL): Define. (Makefile): New rule to make from Makefile.in. (srcdir): Define. (VPATH): Define. (getloadavg.o, remote.o): Use autoconf $foo< hack. * commands.c (fatal_error_signal): Removed return. Mon Jun 15 17:42:51 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.14. * make.texinfo (Summary): New node. (Special Targets): Mention .EXPORT_ALL_VARIABLES here. * variable.c (max): Moved to make.h. * compatMakefile (objs, srcs): Added ar & arscan. * job.c (start_waiting_job): New function, 2nd half of new_job. (new_job): Call it. (start_waiting_jobs): New function. * remake.c (update_goal_chain): Call start_waiting_jobs at the top of the main loop. * compatMakefile (objs, srcs): Removed load, added getloadavg. Fri Jun 12 19:33:16 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c (load_too_high): New function. Uses getloadavg. (waiting_jobs): New variable. (start_job): Don't call wait_to_start_job. Instead, if load_too_high returns nonzero, add the child to the `waiting_jobs' chain and return without starting the job. Thu Jun 11 00:05:28 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * expand.c (variable_buffer_output): Made global again. * variable.h: And declare it. * arscan.c (PORTAR): Define for all systems if PORT5AR is not defined. (AR_NAMELEN, AR_TRAILING_SLASH): Removed. (ar_scan): Don't use it. Don't #ifdef AR_TRAILING_SLASH; just look for a slash in the archive at run time. (ar_name_equal): Rewrote .o hacking to not use AR_NAMELEN, and to cope with trailing-slash and non-trailing-slash archives. * main.c (main) [! SETVBUF_REVERSED]: Test this instead of USGr3 et al. [SETVBUF_REVERSED]: Always allocate a buffer ourselves. * load.c (load_average) [sgi]: Use sysmp call. * compatMakefile (INSTALL_DATA, INSTALL_PROGRAM): Define. ($(bindir)/$(instname), $(mandir)/make.$(manext)): Use them. * make.h [HAVE_VFORK_H]: #include . (vfork, VFORK_NAME): Don't define. * job.c (start_job): Use "vfork" in place of VFORK_NAME. * make.h [HAVE_LIMITS_H, HAVE_SYS_PARAM_H]: If #define'd, #include the each file. Rearranged PATH_MAX hacking. * job.c: Rearranged NGROUPS_MAX hacking. * remake.c (fstat, time): Don't declare. * compatMakefile (defines): Value is @DEFS@. (LOADLIBES): Value is @LIBS@. (extras): Value is @LIBOBJS@. (ARCHIVES, ARCHIVES_SRC, ALLOCASRC): Removed. * arscan.c, ar.c: Surround body with #ifndef NO_ARCHIVES. * misc.c [! HAVE_UNISTD_H]: Test instead of !POSIX to decl get*id. * make.h [GETCWD_MISSING]: Test instead of !USG && !POSIX et al. (getcwd): Just declare if present. If not, declare as a macro using getwd, and declare getwd. [PATH_MAX] (GET_PATH_MAX): #define to PATH_MAX. * main.c (main, log_working_directory): Use getcwd instead of getwd. * main.c (main) [SETLINEBUF_MISSING]: Test this instead of USG. * make.h (SIGHANDLER, SIGNAL): Removed. (RETSIGTYPE): Define if not #define'd. * main.c (main): Use signal in place of SIGNAL. * main.c [SYS_SIGLIST_MISSING]: Test instead of USG. * job.c (search_path) [GETGROUPS_MISSING]: Test instead of USG. [HAVE_UNISTD_H]: Test instead of POSIX to not decl getgroups. * main.c [! HAVE_UNISTD_H]: Test instead of !POSIX to decl chdir. [! STDC_HEADERS]: Test instead of !POSIX to decl exit & atof. * job.c (child_handler), commands.c (fatal_error_signal): Return RETSIGTYPE instead of int. * main.c (main): Declare fatal_error_signal and child_handler here to return RETSIGTYPE; removed top-level decl of former. * commands.c (fatal_error_signal), job.c (unblock_sigs, start_job), main.c [SIGSETMASK_MISSING]: Test this instead of USG. Wed Jun 10 22:06:13 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c [HAVE_WAITPID]: Test this instead of USG. [! HAVE_UNISTD_H]: Test this instead of !POSIX to declare misc fns. (GID_T): Don't #define. (search_path): Use gid_t instead of GID_T. [GETDTABLESIZE_MISSING, SYS_SIGLIST_MISSING, DUP2_MISSING]: Test these individually instead of USG for all. * make.h (ctime): Don't declare. #include time.h instead. [HAVE_UNISTD_H]: #include and #define POSIX #ifdef _POSIX_VERSION. * dir.c [__GNU_LIBRARY__] (D_NAMLEN): Define to use d_namlen member. * make.h [NEED_MEMORY_H]: Only include memory.h #ifdef this. * arscan.c: Removed #ifdef mess about string.h et al. Just #include make.h instead. * make.h (fstat, atol): Declare. * commands.c (fatal_error_signal): Don't use sigmask to check for propagated signals; use ||s instead. (PROPAGATED_SIGNAL_MASK): Removed. (fatal_error_signal) [POSIX]: Use sigprocmask in place of sigsetmask. * variable.c (variable_buffer, variable_buffer_length, initialize_variable_output, variable_output): Moved to expand.c; made all static. (struct output_state, save_variable_output, restore_variable_output): Removed. * expand.c (initialize_variable_output): Put a NUL at the beginning of the new buffer after allocating it. (allocated_variable_expand_for_file): Don't use {save,restore}_variable_output. Do it by hand instead, keeping state on the stack instead of malloc'ing it. (allocated_variable_expand): Removed. * variable.h (allocated_variable_expand): Define here as macro. (variable_buffer_output, initialize_variable_output, save_variable_output, restore_variable_output): Removed decls. * read.c (conditional_line): For an if cmd, if any elt of the conditionals stack is ignoring, just push a new level that ignores and return 1; don't evaluate the condition. Thu Jun 4 21:01:20 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (main): Put #ifdef's around frobbing SIGSYS and SIGBUS. * job.c (getdtablesize): Don't declare or #define if already #define'd. Wed Jun 3 23:42:36 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * file.c (snap_deps): If `.EXPORT_ALL_VARIABLES' is a target, set export_all_variables. * make.texinfo (Variables/Recursion): Document .EXPORT_ALL_VARIABLES. Tue Jun 2 21:08:35 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.13. * commands.c (set_file_variables): Calculate length for ^D and ?D individually, making sure to give them at least enough space for "./". * make.h [CRAY]: #define signal to bsdsignal. * default.c (default_variables) [CRAY]: Define PC, SEGLDR, CF77PPFLAGS, CF77PP, CFT, CF, and FC. * arscan.c (AR_HDR_SIZE): Define to sizeof (struct ar_hdr), if it wasn't defined by . Thu May 28 00:56:53 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.12. Tue May 26 01:26:30 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * rule.c (new_pattern_rule): Initialize LASTRULE to nil, not pattern_rules. Mon May 25 19:02:15 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (decode_switches): Initialize all the long_option elt members. Thu May 21 16:34:24 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * make.texinfo (Text Functions): Correct filter-out description. Tue May 19 20:50:01 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * compatMakefile (realclean): Don't remove backup files. * main.c (decode_switches): Allocate ARGC+1 elts in `other_args'. Sun May 17 16:38:48 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.62.11. Thu May 14 16:42:33 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * job.c (reap_children): Don't die if wait returns EINTR. Wed May 13 18:28:25 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c (reap_children): Always run the next command for a successful target. If we are going to die, we don't want to leave the target partially made. Tue May 12 00:39:19 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): After loop, if we only have one word, check it for being a shell command. * main.c (decode_switches): Allocate ARGC slots in other_args to begin with, so we never need to worry about growing it. If we get a non-option arg and POSIXLY_CORRECT is in the environment, break out of the loop. After the loop, add all remaining args to other_args list. * main.c (decode_switches): For positive_int and floating switches when optarg is nil, use next arg if it looks right (start with a digit, or maybe decimal point for floating). * variable.c (define_automatic_variables): Always set SHELL to default if it comes from the environment. Set its export bit. * make.texinfo (Environment): Document change. Mon May 11 00:32:46 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.62.10. * compatMakefile (tags, TAGS): Use vars for cmds. (ETAGS, CTAGS): Define. * main.c (decode_switches): If a switches elt has a nil long_name, make the long option name elt be "". Fixed loop to not ignore all the options. * make.texinfo (Option Summary): Added long options. * main.c (switches): Changed -m's description to "-b". (decode_switches): When printing the usage message, don't print switches whose descriptions start with -. When constructing the list of names for switch -C, search the switches vector for switches whose descriptions are "-C". * main.c (switches): Call -S --no-keep-going, not --dont-keep-going. Call -I --include-dir, not --include-path. (long_option_aliases): Added --new == -W, --assume-new == -W, --assume-old == -o, --max-load == -l, --dry-run == -n, --recon == -n, --makefile == -f. * main.c (switches): Removed bogus "silent" elt. (long_option_aliases): Define new var. (decode_switches): Add long_option_aliases onto the end of the long options vector created for getopt_long. Look through long_option_aliases for extra names to list in usage message. Sat May 9 00:21:05 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (log_working_directory): Fixed to properly not print the leaving message when we haven't printed the entering message. Fri May 8 21:55:35 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * main.c (struct command_switch): Added elts `long_name', `description', and `argdesc'. (switches): Added initializers for new members. (decode_switches): Rewritten to use getopt_long. * compatMakefile (GETOPT, GETOPT_SRC): Define. (objs, srcs): Include them. * job.c (child_died): Renamed to dead_children; made static. (child_handler): Increment dead_children instead of setting child_died. (reap_children): Decrement dead_children instead of clearing child_died. The point of all this is to avoid printing "waiting for unfinished jobs" when we don't actually need to block. This happened when multiple SIGCHLDs before reap_children was called. * job.c (reap_children): If ERR is set, so we don't call start_job on the child being reaped, instead set its command_state to cs_finished. (reap_children, child_handler, new_job): I added several debugging printf's while fixing this. I left them in if (debug_flag) because they may be useful for debugging this stuff again. Wed May 6 22:02:37 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * read.c (read_makefile): v_export is not 1. Mon May 4 17:27:37 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.9. * variable.c (export_all_variables): New variable. (target_environment): Export variables whose `export' member is v_default if export_all_variables is set and their names are benign. * variable.h: Declare export_all_variables. * read.c (read_makefile): If export or unexport is given with no args, set or clear export_all_variables, respectively. * variable.c (target_environment): Exclude MAKELEVEL in the loop, so it isn't duplicated when we add it at the end. Sun May 3 17:44:48 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.8. * variable.h (struct variable): Added new member `export'. * variable.c (define_variable_in_set): Initialize it to v_default. (target_environment): Don't check for .NOEXPORT. Export variables whose `export' member is v_default and that would have been exported under .NOEXPORT, and variables whose `export' member is v_export. (try_variable_definition): Return the variable defined. * variable.h (try_variable_definition): Changed decl. * read.c (read_makefile): Recognize `export' and `unexport' directives. Fri May 1 11:39:38 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * main.c (main) [POSIX]: Reversed args to sigaddset. Thu Apr 30 17:33:32 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c [POSIX || !USG] (unblock_sigs): New fn. (start_job): Block signals before forking. (new_job): Unblock signals after putting the new child on the chain. * main.c (main) [POSIX]: Use sigset_t fatal_signal_set instead of int fatal_signal_mask. * load.c [sgi] (LDAV_CVT): Define. Wed Apr 29 17:15:59 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.62.7. * load.c (load_average) [sgi]: Clear the high bit of the address from the symbol table before looking it up in kmem. * misc.c (fatal, makefile_fatal): Put *** in fatal error messages. (remake_file): No longer needed in message here. * main.c (die): Call reap_children with BLOCK==1. Tue Apr 28 20:44:35 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * rule.c (freerule): Don't set LASTRULE->next if LASTRULE is nil. Sun Apr 26 15:09:51 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * rule.c (count_implicit_rule_limits): Initialize LASTRULE to nil, not to head of chain. Extract next ptr before we might do freerule, and use that for next iteration. (freerule): Still do next ptr frobbing if LASTRULE is nil. Tue Apr 21 03:16:29 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * job.c (child_error): Removed extra %s from error msg format. * Version 3.62.6. * job.c (reap_children): Don't start later commands in a sequence if ERR is nonzero. * job.c (new_job): Always call reap_children with BLOCK==0 first thing. * job.c (reap_children): New function; work that used to be done in child_handler. (child_died): New global var. (child_handler): Now just sets child_died. (wait_for_children): Removed. (unknown_children_possible, block_signals, unblock_signals, push_signals_blocked_p, pop_signals_blocked_p): Removed. (child_execute_job): Removed call to unblock_signals. (new_job): Removed calls to push_signals_blocked_p and pop_signals_blocked_p. * job.h: Declare reap_children, not wait_for_children. * commands.c (fatal_error_signal), job.c (new_job), load.c [LDAV_BASED] (wait_to_start_job), main.c (die), remake.c (update_goal_chain), function.c (expand_function: `shell'): Changed wait_for_children calls to reap_children. Some needed to be loops to wait for all children to die. * commands.c (fatal_error_signal), main.c (main, log_working_directory), function.c (expand_function): Removed calls to push_signals_blocked_p and pop_signals_blocked_p. * job.h: Removed decls. * job.h: Added copyright notice. Wed Apr 15 02:02:40 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (child_error): No *** for ignored error. Tue Apr 14 18:31:21 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * implicit.c (DEBUGP2): Use do ... while (0) instead of if ... else to avoid compiler warnings. * read.c (parse_file_seq): Don't remove ./ when it is followed by a blank. Mon Apr 13 21:56:15 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h (DEBUGPR): Use do ... while (0) instead of if ... else to avoid compiler warnings. * remake.c (notice_finished_file): Run file_mtime on the also_make files, so vpath_search can happen. * GNUmakefile (tests): Use perl test suite from csa@sw.stratus.com. (alpha-files): Include test suite tar file. Fri Apr 3 00:50:13 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * Version 3.62.5. Wed Apr 1 05:31:18 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * remake.c (update_file, update_file_1): Do check_renamed on elts of dep chains when traversing them. Something unrelated might have renamed one of the files the dep chain points to. * file.c (rename_file): If FILE has been renamed, follow its `renamed' ptr, so we get to the final real FILE. Using the renamed ones loses because they are not in the hash table, so the removal code loops infinitely. * read.c (read_all_makefiles): Clobber null terminator into MAKEFILES expansion, so string passed to read_makefile is properly terminated. Mon Mar 30 20:18:02 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * commands.c (set_file_variables): $* for archive member with explicit cmds is stem of member, not of whole `lib(member)'. Thu Mar 26 15:24:38 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.62.4. Tue Mar 24 05:20:51 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * rule.c (new_pattern_rule): Rules are identical only if all their targets match (regardless of order). Wed Mar 11 13:49:54 1992 Roland McGrath (roland@geech.gnu.ai.mit.edu) * remake.c (remake_file): Changed error "no way to make" to "no rule to make". Fiat Hugh. * make.texinfo (Last Resort): Describe %:: rules and new .DEFAULT behavior. * remake.c (update_file_1): Only use .DEFAULT cmds if FILE is not a target. Tue Mar 10 18:13:13 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * remote-stub.c, remote-cstms.c (start_remote_job): Take new arg, environment to pass to child. * job.c (start_job): Pass it. Mon Mar 9 19:00:11 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * file.c (enter_file): Also strip ./s here, to get command-line target names. * remote-cstms.c: Add comment telling people to leave me alone. * compatMakefile (manpage install): Remove target before copying. Tue Mar 3 18:43:21 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.texinfo (Missing): Renamed to "Incompatibilities and ...". Added paragraph describing $? incompatibility with Unix and POSIX.2. Sun Mar 1 15:50:54 1992 Roland McGrath (roland@nutrimat.gnu.ai.mit.edu) * function.c (expand_function: `shell'): Don't declare fork or pipe. Use vfork instead of fork. Tue Feb 25 22:05:32 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * make.texinfo (Chained Rules): Clarify .PRECIOUS to save intermediate files. * load.c [sun] (LDAV_CVT): Define to divide by FSCALE. Sun Feb 16 02:05:16 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * Version 3.62.3. Sat Feb 15 17:12:20 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * compatMakefile (makeinfo): Use emacs batch-texinfo-format fn. Fri Feb 14 00:11:55 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * read.c (read_makefile): Correctly handle define & endef in ifdefs. * read.c (record_files): Pass arg for %s in error msg. * main.c (main) [__IBMR2, POSIX]: Use correct (a la USGr3) setvbuf call. Wed Feb 12 12:07:39 1992 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * make.texinfo (Libraries/Search): Say it does /usr/local/lib too. Sun Feb 9 23:06:24 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * read.c (read_makefile): Check for extraneous `endef' when ignoring. Thu Feb 6 16:15:48 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * Version 3.62.2. Tue Feb 4 20:04:46 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Correctly ignore whitespace after backslash-NL. Fri Jan 31 18:30:05 1992 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * compatMakefile: Ignore errors from chgrp and chmod when installing. Wed Jan 29 18:13:30 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * main.c (main): When setting MAKELEVEL in the env to re-exec, allocate space so as not to clobber past the end of the old string. * make.h [HAVE_ALLOCA_H]: Include * compatMakefile (defines): Document HAVE_ALLOCA_H. Mon Jan 20 13:40:05 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * make.h [VFORK_MISSING]: Use fork instead. * compatMakefile (defines): Document same. * job.c (construct_command_argv_internal): Don't create an empty arg if backslash-NL is at beginning of word. Sun Jan 19 16:26:53 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * main.c [DGUX]: Call setvbuf as for USGr3. * job.c (construct_command_argv_internal): Notice correctly that backslash-NL is the end of the arg (because it is replaced with a space). Thu Jan 16 18:42:38 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): If SHELL is nil, set it to default_shell before proceeding. * make.h [sgi]: No alloca.h, after all. Wed Jan 15 12:30:04 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * read.c (multi_glob): Cons up the chain of the results of glob from back to front, so it comes out in forward order. * job.c (construct_command_argv_internal): Don't eat char following backslash-NL. Mon Jan 13 19:16:56 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * Version 3.62.1. * default.c (default_variables) [ultrix]: GET=get, like USG. * job.c (construct_command_argv_internal): Remove tabs following backslash-NL combos in the input line, so they don't show up when that line is printed. * read.c (read_makefile): Don't collapse_continuations the line on input; do it on the copy we do remove_comments on. For rule lines, collapse_continuations the line after chopping ";cmds" off the end, so we don't eat conts in the cmds. Give error for ";cmds" with no rule. * job.c (construct_command_argv_internal): Eat backslash-NL combos when constructing the line to recurse on for slow, too. Sat Jan 11 02:20:27 1992 Roland McGrath (roland@albert.gnu.ai.mit.edu) * file.c (enter_file): Don't strip leading `./'s. * read.c (parse_file_seq): Take new arg STRIP; if nonzero, do it here. * default.c (set_default_suffixes), function.c (string_glob), read.c (read_makefile), rule.c (install_pattern_rule): Change callers. * default.c (default_variables) [_IBMR2]: FC=xlf * job.c (construct_command_argv_internal): Turn backslash-NL and following whitespace into a single space, rather than just eating the backslash. * make.texinfo (Copying): @include gpl.texinfo, rather than duplicating its contents. Fri Nov 8 20:06:03 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Make sure not to bother processing an empty line. * Version 3.62.0. * job.c (construct_command_argv_internal): Always recurse for slow; simple case didn't handle finding newlines. Tue Nov 5 18:51:10 1991 Roland McGrath (roland@wookumz.gnu.ai.mit.edu) * job.c (construct_command_argv_internal): Set RESTP properly when slow; don't \ify past a newline. Fri Nov 1 19:34:28 1991 Roland McGrath (roland@churchy.gnu.ai.mit.edu) * make.h [sgi]: #include . See ChangeLog.1, available in the Git repository at: https://git.savannah.gnu.org/cgit/make.git/tree/ for earlier changes. Copyright (C) 1991-2007 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: ChangeLog.3 ================================================ 2013-10-09 Paul Smith Version 4.0 released. * configure.ac: Updated for the release. * NEWS: Updated for the release. * maintMakefile (tag-release): New target to add a Git tag. * read.c (eval): Typo fix. * ChangeLog.1: Typo fixes. * w32/subproc/sub_proc.c (process_cleanup): Typo fix. 2013-10-07 Eli Zaretskii * w32/compat/posixfcn.c (tmpfile): Move declaration of h before the first executable statement. Reported by Gisle Vanem . 2013-10-05 Paul Smith * makeint.h (MAP_USERFUNC): A new map type for function names. * main.c (initialize_stopchar_map): Set up the function name map. * gnumake.h (gmk_func_ptr): Define a type for function pointers. (gmk_add_function): Convert the last argument to FLAGS. (GMK_FUNC_*): Define flags for the function. Change the default behavior to "expand" since that's the most common one. * function.c (function_table_entry): Use new function pointer type. (lookup_function): Accept any valid function name character based on the MAP_USERFUNC values. (define_new_function): Use the new calling signature. Verify that registered functions have valid names. * guile.c (guile_gmake_setup): Use new calling signatures. * loadapi.c (gmk_add_function): Ditto. * variable.h (define_new_function): Ditto. * doc/make.texi (Loaded Object API): Make the registered function API documentation more clear. 2013-10-03 Eli Zaretskii * function.c (abspath): Reset root_len to one for Cygwin only when HAVE_DOS_PATHS is defined. Suggested by Christopher Faylor. 2013-10-02 Eli Zaretskii * w32/compat/posixfcn.c (tmpfile): New function, a replacement for the Windows libc version. Fix $abspath on Cygwin when HAVE_DOS_PATHS is in effect. * function.c (IS_ABSOLUTE) [__CYGWIN__]: Special definition for Cygwin. (abspath) [__CYGWIN__]: Reset root_len to 1 if the absolute file name has the Posix /foo/bar form. [HAVE_DOS_PATHS]: Use root_len instead of hard-coded 2. 2013-10-01 Paul Smith * configure.ac: Update version to 3.99.93. * NEWS: Ditto. 2013-09-30 Paul Smith * guile.c: Portability fixes for Guile 1.8. 2013-09-29 Paul Smith * output.c (output_dump): Always write Enter/Leave messages to stdio. (log_working_directory): This now always writes to stdio, so we don't need the struct output parameter anymore. (output_start): Show the working directory when output_sync is not set or is recursive. * main.c (main): Ensure the special "already shown Enter message" token is removed from MAKE_RESTARTS before the user can see it. * function.c (func_shell_base): If the output_context stderr exists but is invalid, write to the real stderr. Fixes suggested by Frank Heckenbach . * output.c: Guard unistd.h inclusion, add io.h. * gnumake.h: Move GMK_EXPORT before the declarations. * make_msvc_net2003.vcproj: Add missing files. Changes for MSVC suggested by Gerte Hoogewerf * function.c (func_shell_base) [EMX]: Fix EMX support for output-sync. * job.c (child_execute_job) [EMX]: Ditto. * job.h (child_execute_job) [EMX]: Ditto. * w32/compat/posixfcn.c: Invert the test for NO_OUTPUT_SYNC. * guile.c (GSUBR_TYPE): Pre-2.0 Guile doesn't provide a typedef for gsubr pointers. Create one. (guile_define_module): Use it. (internal_guile_eval): Force UTF-8 encoding for Guile strings. * main.c (main): Clear GNUMAKEFLAGS after parsing, to avoid proliferation of options. * NEWS: Document it. * doc/make.texi (Options/Recursion): Ditto. 2013-09-23 Eli Zaretskii * w32/compat/posixfcn.c: Fix the forgotten OUTPUT_SYNC conditional. * job.h: Ditto, but in a comment. 2013-09-22 Paul Smith * configure.ac: Update version to 3.99.92. * NEWS: Ditto. * implicit.c (pattern_search): After second expansion be sure to handle order-only markers inside the expansion properly. Fixes Savannah bug #31155. * guile.c (guile_define_module): Technically a void* cannot contain a pointer-to-function and some compilers warn about this. Cast the function pointers. * load.c (load_object): Ditto. * read.c (eval): If load_file() returns -1, don't add this to the "to be rebuilt" list. * doc/make.texi (load Directive): Document it. * guile.c (guile_gmake_setup): Don't initialize Guile so early. (func_guile): Lazily initialize Guile the first time the $(guile ..) function is invoked. Guile can steal file descriptors which confuses our jobserver FD checking, so we don't want to initialize it before we have to. VMS port updates by Hartmut Becker * makefile.com: Add output to the filelist. * output.c (va_copy): Add an implementation of this macro for VMS. * commands.c: Ensure filedef.h is #included before dep.h. * dir.c: Ditto. * file.c: Ditto. * guile.c: Ditto. * main.c: Ditto. * misc.c: Ditto. * read.c: Ditto. * rule.c: Ditto. * variable.c: Ditto. * readme.vms: Renamed to README.VMS and updates for this release. * Makefile.am: Ditto. * NEWS: Ditto. * README.template: Ditto. * Makefile.DOS.template: Ditto. 2013-09-21 Paul Smith * maintMakefile (check-alt-config): Create a target to test alternative configurations. Each one will build make with a different configuration then run the test suite. Invert the output-sync #define to NO_OUTPUT_SYNC * configure.ac: Don't set OUTPUT_SYNC. * makeint.h: Ditto. * main.c: Use NO_OUTPUT_SYNC instead of OUTPUT_SYNC. * output.c: Ditto. * output.h: Ditto. * job.h: Ditto. * job.c: Ditto. * config.ami.template: Set NO_OUTPUT_SYNC. * config.h-vms.template: Ditto. * config.h.W32.template: Ditto. * configh.dos.template: Ditto. Output generated while reading makefiles should be synced. * main.c (make_sync): Define a context for syncing while reading makefiles and other top-level operations. (main): If we request syncing, enable it while we are parsing options, reading makefiles, etc. to capture that output. Just before we start to run rules, dump the output if any. (die): Dump any output we've been syncing before we die * output.h (OUTPUT_SET): Disable output_context if not syncout. Stderr generated from shell functions in recipes should be synced. * job.h (FD_STDIN, FD_STDOUT, FD_STDERR): Create new macros to avoid magic numbers. (child_execute_job): Take a FD for stderr. * job.c (child_execute_job): Handle STDERR FD's in addition to stdin and stdout. (start_job_command): Call child_execute_job() with the new STDERR parameter. Instead of performing the dup() here, send it to child_execute_job() where it's already being done. * function.c (func_shell_base): Pass the OUTPUT_CONTEXT stderr to child_execute_job() if it's set, otherwise FD_STDERR. * main.c (main): Pass FD_STDERR to child_execute_job(). 2013-09-19 Paul Smith * main.c (main): Set MAKE_RESTARTS to negative before re-exec if we've already generated an "Entering" message. If we are started and notice that MAKE_RESTARTS is negative, assume we already wrote "Entering" and don't write it again. 2013-09-18 Paul Smith * main.c (main): Set starting_directory before we write any errors. Fixes Savannah bug #40043. 2013-09-16 Eli Zaretskii * output.c [WINDOWS32]: Include windows.h and sub_proc.h, to avoid compiler warnings for CLOSE_ON_EXEC. 2013-09-16 Paul Smith * configure.ac: Update version to 3.99.91. * NEWS: Ditto. 2013-09-15 Paul Smith * doc/make.texi (Error Messages): Add a bit more info to the section on static pattern errors, since they're common. Fixes Savannah bug #31326. * read.c (eval_makefile): If the file open fails with an unrecoverable error, stop now rather than trying to make it. Fixes Savannah bug #27374. * main.c (main): Perform the validation of the jobserver FDs early, before we read makefiles, to ensure that something hasn't opened and used those FDs for some other reason. Fixes Savannah bug #39934. * main.c (main): Don't set MAKEFLAGS in the environment when we restart. We have the original command line flags so keep the original MAKEFLAGS settings as well. Fixes Savannah bug #39203. 2013-09-14 Paul Smith * main.c (decode_debug_flags): Add support for the "n" flag to disable all debugging. * make.1: Document the "n" (none) flag. * doc/make.texi (Options Summary): Ditto. * NEWS: Ditto. Fixes Savannah bug #35248. * misc.c (close_stdout): Move to output.c. * main.c (main): Move atexit call to output_init(). * makeint.h: Remove close_stdout() declaration. * output.c (output_init): Add close_stdout at exit only if it's open. Fixes Savannah bug #33134. Suggested by David Boyce . 2013-09-14 Paul Smith * misc.c (set_append_mode, open_tmpfd, open_tmpfile): Move to output.c. * misc.h: Ditto. * output.h: Ditto. * main.c (main): Move stdio init into output.c:output_init(). Change open_tmpfile() to output_tmpfile(). * output.c: Rename open_*() to output_*(). set_append_mode() and open_tmpfd() are static. (_outputs, log_working_directory): Accept a struct output and print to that rather than the global context. (output_dump): In recurse mode print enter/leave once for the whole makefile. (output_init): Initialize this processes stdio as well as child's. * vmsjobs.c: Reformat to be closer to convention. 2013-09-12 Paul Smith Rework output to handle synchronization and directory logging more reliably. * output.c: New file. Implement lazy synchronization and directory logging so that we manage them "just in time", and the destination of the output is set via a global state variable. * output.h: New file. * function.c (func_shell_base): Ensure the output is set up before running a shell command, in case it writes to stderr. (func_error): Use outputs() to generate output. * job.h (struct child): Add struct output to track the child's output. * job.c: Use struct output in the child structure to track output. (child_out, sync_init, assign_child_tempfiles, pump_from_tmp) (acquire_semaphore, release_semaphore, sync_output): Move most of the output_sync handling to output.c. (child_error): Set output, then use simple message() and error() not _s versions. * main.c (log_working_directory): Moved to output.c (trace_option, decode_trace_flags) Remove. Remove support for different trace modes; we don't use it anymore. (die) Invoke output_close() before we exit. * misc.c (message_s, error_s): Removed; no longer needed. (message, error, fatal, perror_with_name, pfatal_with_name): Moved to output.c. * makeint.h: Remove message_s(), error_s(), and log_working_directory(). Remove the TRACE_* macros. * doc/make.texi: Enhance documentation for output sync, and remove MODE assignment for --trace. * make.1: Remove MODE assignment for --trace. * Makefile.am: Add new files. * NMakefile.template: Ditto. * SMakefile.template: Ditto. * build_w32.bat: Ditto. * dosbuild.bat: Ditto. * make.lnk: Ditto. * make_nsvc_net2003.vcproj: Ditto. * makefile.vms: Ditto. * po/POTFILES.in: Ditto. 2013-08-22 Petr Machata * function.c (func_shell_base): Get rid of any avoidable limit on stack size for processes spawned via $(shell). 2013-07-22 Paul Smith * implicit.c (pattern_search): Use PARSE_SIMPLE_SEQ() even for non-second expansion prerequisites, to handle globbing in patterns. Fixes Savannah bug #39310. * dep.h (PARSE_SIMPLE_SEQ): Macro for simple file sequence parsing. * default.c (set_default_suffixes): Use it. * file.c (split_prereqs): Ditto. * main.c (main): Ditto. * read.c (eval): Ditto. * rule.c (install_pattern_rule): Ditto. * file.c (split_prereqs): Use PARSEFS_NONE instead of 0. 2013-07-21 Paul Smith Cleanups detected by cppcheck. Fixes Savannah bug #39158. * arscan.c (ar_scan): Reduce the scope of local variables. * dir.c (vms_hash): Ditto. (find_directory): Ditto. (file_impossible_p): Ditto. * expand.c (variable_expand_string): Ditto. * function.c (func_sort): Ditto. (func_and): Ditto. * job.c (reap_children): Ditto. (exec_command): Ditto. * main.c (main): Ditto. * misc.c (collapse_continuations): Ditto. * read.c (eval): Ditto. (parse_file_seq): Ditto. * vpath.c (gpath_search): Ditto. (selective_vpath_search): Ditto. * job.c (is_bourne_compatible_shell): Simplify for non-Windows systems. * remake.c (f_mtime): Remove duplicate test. * signame.c (strsignal): Fix bogus conditional. * job.c (assign_child_tempfiles): Assign OUTFD to -1 for safety. (start_job_command): Don't test output_sync and sync_cmd: redundant. Changes suggested by Frank Heckenbach . 2013-07-14 Paul Smith * filedef.h (update_status): Convert UPDATE_STATUS from a char to an enumeration. Some systems declare "char" to be "unsigned" which broke the code (which expected to be able to use -1 as a flag). Using magic values was unpleasant, so rather than just force "signed char" I reworked it to use an enum. * dep.h (update_goal_chain): Return an update_status value not int. * remake.c (touch_file): Ditto. (update_goal_chain): Track the update_status enum. * file.c (enter_file): Use new enumeration values with update_status. (remove_intermediates): Ditto. (print_file): Ditto. * commands.c (execute_file_commands): Ditto. * job.c (reap_children): Ditto. (start_job_command): Ditto. (start_waiting_job): Ditto. * main.c (main): Ditto. * remake.c (update_file): Ditto. (complain): Ditto. (update_file_1): Ditto. (notice_finished_file): Ditto. (remake_file): Ditto. * vmsjobs.c (vmsHandleChildTerm): Ditto. 2013-07-09 Paul Smith * implicit.c (pattern_search): Keep a local copy of the number of deps in deplist: the global max might change due to recursion. Fixes a bug reported by Martin d'Anjou . 2013-06-28 Paul Smith * misc.c (set_append_mode): Set the O_APPEND flag on a file descriptor. (open_tmpfd): Set append mode on the temporary file descriptor. * main.c (main): Set append mode on stdout and stderr. * makeint.h (set_append_mode): Declare it. 2013-06-22 Eli Zaretskii * build_w32.bat (LinkGCC): Prevent a comment from being displayed at build time. * job.c (construct_command_argv_internal) [WINDOWS32]: Use case-insensitive comparison with internal commands of non-Unix shells. * main.c (find_and_set_default_shell): Don't use file_exists_p or dir_file_exists_p, as those call readdir, which can fail if PATH includes directories with non-ASCII characters, and that would cause Make to fail at startup with confusing diagnostics. See https://sourceforge.net/mailarchive/message.php?msg_id=30846737 for the details. 2013-06-22 Paul Smith Improve performance by using a character map to determine where we want to stop searching strings, rather than discrete comparisons. * read.c (find_char_unquote): Pass a stop map instead of various flags and use that to check when to stop parsing the string. (eval): Use the new find_char_unquote() calling signature. (remove_comments): Ditto. (unescape_char): Ditto. (find_percent_cached): Ditto. (parse_file_seq): Use a stop-map flag. * main.c (stopchar_map): Character map definition. (initialize_stopchar_map): Initialize the map definition. (main): Invoke the map initialization function. * misc.c (end_of_token_w32): Remove unused function. * dir.c (dosify): Use STOP_SET to check for stop chars. * main.c (main): Ditto. * misc.c (end_of_token): Ditto. * function.c (subst_expand): Ditto. (func_notdir_suffix): Ditto. (func_basename_dir): Ditto. (abspath): Ditto. * job.c (is_bourne_compatible_shell): Ditto. * variable.c (parse_variable_definition): Ditto. * read.c (eval): Ditto. (conditional_line): Ditto. (find_percent_cached): Ditto. * dep.h (PARSE_FILE_SEQ): Update function declaration. * default.c (set_default_suffixes): Update PARSE_FILE_SEQ() call. * file.c (split_prereqs): Ditto. * function.c (string_glob): Ditto. * implicit.c (pattern_search): Ditto. * rule.c (install_pattern_rule): Ditto. * main.c (main): Ditto. 2013-06-21 Paul Smith * main.c (verify_flag): Global variable to determine whether to verify the database or not. (decode_debug_flags): If debug mode, enable verify_flag. (main): If MAKE_MAINTAINER_MODE, enable verify_flag, otherwise not. (die): Only verify the database if verify_flag is set. * file.c (enter_file): Don't check caching unless verify_flag. * makeint.h: Export verify_flag. 2013-05-27 Paul Smith * variable.c (define_automatic_variables): Create a new variable MAKE_HOST. 2013-05-27 Hartmut Becker * function.c (func_shell_base) [VMS]: Support VMS. * makefile.com [VMS]: Ditto. * makefile.vms [VMS]: Ditto. * makeint.h [VMS]: Ditto. * vmsjobs.c [VMS]: Ditto. * job.h: Define RECORD_SYNC_MUTEX() when OUTPUT_SYNC is not set. * load.c (unload_file): Fix signature if MAKE_LOAD is not set. 2013-05-26 Paul Smith * remake.c (f_mtime): Ensure that archive file names are in the string cache. Fixes Savannah bug #38442. * read.c (readline): To be safe, move the entire buffer if we detect a CR. Fixes Savannah bug #38945. * job.c (new_job): Compare OUT to the beginning of the OUT var/function, not IN. Fixes Savannah bug #39035. 2013-05-22 Paul Smith * main.c (switches[]): Order switches so simple flags all come first. (define_makeflags): Rework to make option passing more reliable and the code less tricksy. Ensure simple flags are kept in the initial batch of flags. Do not allow any flags with options in that batch. If there are only non-simple flags MAKEFLAGS begins with ' '. (print_data_base): Print the version. Fixes part of Savannah #35336. * read.c (eval_buffer): Initialize lineno. 2013-05-18 Alexey Pavlov (tiny change) * w32/Makefile.am (libw32_a_SOURCES): Add compat/posixfcn.c. * configure.ac (OUTPUT_SYNC): Define for mingw32 target. * job.c (construct_command_argv_internal) [WINDOWS32]: Add "move". Fixes Savannah bug #30714. * guile.c: Move inclusion of makeint.h before gnumake.h. This order must be observed when building Make, because gnumake.h must be included with GMK_BUILDING_MAKE defined, which makeint.h already does. Otherwise, the linker will look for, and fail to find, gmk_* functions in some external dynamic library. 2013-05-17 Benno Schulenberg * main.c (decode_output_sync_flags): Fix output message. * read.c (EXTRANEOUS): Ditto. (record_files): Ditto. * remake.c (update_file_1): Ditto. 2013-05-17 Eli Zaretskii * main.c (prepare_mutex_handle_string): Define conditioned on OUTPUT_SYNC. * build_w32.bat: Copy config.h.W32 to config.h regardless of whether or not we are building from SCM. 2013-05-17 Paul Smith * configure.ac: Update version to 3.99.90. * NEWS: Ditto. * Source (*.[ch]): Remove TABs, use GNU coding styles. * ALL: Update copyright. * hash.c (CALLOC): Use xcalloc() to handle out of memory errors. * makeint.h: Prototype new unload_file() function. * load.c (unload_file): Create a function to unload a file. (struct load_list): Type to remember loaded objects. (loaded_syms): Global variable of remembered loaded objects so we can unload them later. We don't have to remove from the list because the only time we unload is if we're about to re-exec. (load_object): Remove unneeded extra DLP argument. (load_file): Remove unneeded extra DLP argument. * filedef.h (struct file): Remove the DLP pointer and add the LOADED bit flag. Saves 32/64 bytes per file, as this pointer is almost never needed. * read.c (eval): Set the new LOADED bit flag on the file. * file.c (rehash_file): Merge the loaded bitfield. * commands.c (execute_file_commands): Call unload_file() instead of dlclose() directly. 2013-05-14 Paul Smith * doc/make.texi (Loaded Object API): Document the requirement for the plugin_is_GPL_compatible symbol. * load.c (load_object): Check for plugin_is_GPL_compatible symbol. 2013-05-13 Paul Smith * filedef.h (struct file): Add a builtin flag. * file.c (enter_file): Unset the builtin flag. (rehash_file): Ditto. (print_file): Don't print builtin files if we've omitted them. * default.c (undefine_default_variables): New function: go through the default variables and undefine them. (set_default_suffixes): Mark these suffix rules as builtin. * makeint.h: Prototype. * main.c (main): Handle addition of -r and -R to MAKEFLAGS in the makefile. Fixes Savannah bug #20501. * main.c (define_makeflags): Assign o_env_override level to MAKEFLAGS to ensure it's set even in the presence of -e. Fixes Savannah bug #2216. * makeint.h (TRACE_NONE, TRACE_RULE, TRACE_DIRECTORY): Define constants for the trace mode. * main.c: Add new --trace mode parsing. (decode_trace_flags): New function. (decode_switches): Call it. (define_makeflags): Fix a bug with long-name options. * misc.c (fatal): Remove special output-sync handling. * make.1: Document new --trace mode flags. * doc/make.texi (Options Summary): Ditto. 2013-05-11 Eli Zaretskii * job.c (child_out): Output the newline following the message before fllush-ing the stream. Avoids displaying the following failure message, which goes to stderr, on the same line. 2013-05-06 Eli Zaretskii * gnumake.h (GMK_EXPORT) [_WIN32]: Move the dllexport declaration here from makeint.h. * makeint.h (GMK_BUILDING_MAKE) [WINDOWS32]: Define before including gnumake.h. * doc/make.texi (Loaded Object Example): Add a note about building shared objects on MS-Windows. 2013-05-05 Paul Smith * makeint.h (OUTPUT_SYNC_LINE, OUTPUT_SYNC_RECURSE): Rename output-sync options "job" to "line" and "make" to "recurse". * main.c (decode_output_sync_flags): Ditto. * job.c (reap_children): Ditto. (start_job_command): Ditto. * make.1: Ditto. * doc/make.texi (Parallel Output): Ditto. * job.c (child_out): Write newlines explicitly, and don't do anything if the message is empty. (sync_output): Put working dir messages around stdout AND stderr. (start_job_command): Move the tmp file assignment earlier. After we do it, write the command line to the temp file to get the order correct. * misc.c (message): Remove special handling for output_sync. (error): Ditto. 2013-05-04 Paul Smith * loadapi.c (gmk_alloc): New function. * gnumake.h: Add gmk_alloc(). Clean GMK_EXPORT a bit to avoid MAIN. * makeint.h (GMK_EXPORT): New handling, vs. MAIN. * doc/make.texi (Loaded Object API): Add information on the memory handling functions. (Loaded Object Example): Create an example. * job.c (pump_from_tmp): (Rename) Write to stdout/stderr using FILE* rather than fd. It's not a good idea to mix and match. 2013-05-04 Eli Zaretskii * makeint.h (ftruncate) [_MSC_VER]: Redirect to _chsize. (_S_ISDIR): If not defined (MinGW64), define to S_ISDIR. 2013-05-04 Paul Smith * job.c (child_out): Handle EINTR and incomplete write scenarios. (sync_init): New function: separate the initialization code. (assign_child_tempfiles): Remove truncation from this function, (sync_output): and add it here after output is generated. (reap_children): Always call sync_output() in case output_sync was reset after the child started, due to error. (start_job_command): Create new sync_cmd variable. Use new method for initializing the handle. If we're not syncing the output be sure any output we've saved is dumped immediately before starting the child. 2013-05-04 Eli Zaretskii * job.c (start_job_command): Make the condition for creating a temporary output file be identical to the Posix code branch. Suggested by Frank Heckenbach . 2013-05-03 Eli Zaretskii * w32/subproc/sub_proc.c: Include makeint.h. Remove a private incompatible prototype of xmalloc. (batch_file_with_spaces): New function, detects Windows batch files whose names include whitespace characters. (process_begin): If exec_name is a batch file with whitespace characters in its name, pass NULL as the first argument to CreateProcess. This avoids weird failures due to buggy quoting by CreateProcess. For the details, see the discussion starting at https://lists.gnu.org/archive/html/make-w32/2013-04/msg00008.html. * load.c (load_object, load_file): Accept an additional argument DLP and return in it a pointer that can be used to unload the dynamic object. * read.c (eval): Call load_file with an additional argument, and record the pointer returned there in the 'struct file' object of dynamic objects in that object's 'struct file'. * commands.c (execute_file_commands): Unload dynamic objects before remaking them, to avoid failure to remake if the OS doesn't allow overwriting objects that are in use. * filedef.h (struct file): New member dlopen_ptr. * gnumake.h (GMK_EXPORT): Define to dllexport/dllimport decorations for Windows and to nothing on other platforms. (gmk_eval, gmk_expand, gmk_add_function): Add GMK_EXPORT qualifier to prototypes. * makeint.h (MAIN): Define before including gnumake.h, to give correct dllexport decorations to exported functions. (load_file): Adjust prototype. * loadapi.c: Don't include gnumake.h, since makeint.h already includes it, and takes care of defining MAIN before doing so. * build_w32.bat (LinkGCC): Produce an import library for functions exported by Make for loadable dynamic objects. * w32/compat/posixfcn.c (dlclose): New function. * w32/include/dlfcn.h (dlclose): Add prototype. 2013-05-01 Eli Zaretskii * job.c (start_job_command) [WINDOWS32]: Make the same fix for MS-Windows as the previous commit did for Posix platforms. (construct_command_argv_internal): Don't treat a backslash as an escape character before whitespace, if the shell is not a Posix shell. For the description of the problem, see https://lists.gnu.org/archive/html/make-w32/2013-04/msg00014.html. 2013-05-01 Paul Smith * job.c (start_job_command): Don't redirect output for recursive make jobs, unless we're in makefile synchronization mode. 2013-04-30 Stefano Lattarini (tiny change) build: enable the 'silent-rules' automake options * configure.ac (AM_INIT_AUTOMAKE): Here. The future major Automake version 2.0 (ETA about one, one and half year from now) will enable it by default, so better prepare ourselves. 2013-04-30 Stefano Lattarini (tiny change) build: require Autoconf >= 2.62 and Automake >= 1.11.1 Older versions of those tools should be considered fully obsolete. Also, GNU make already requires Gettext >= 0.18.1, which has been released six months after Automake 1.11.1 and two years after Autoconf 2.62; so the new requirement shouldn't be problematic for people already bootstrapping GNU make from the Git repository. * configure.ac (AC_PREREQ): Require Autoconf 2.62 or later. (AM_INIT_AUTOMAKE): Require Automake 1.11.1 or later (1.11 had some serious bugs, and should not be used). 2013-04-30 Stefano Lattarini (tiny change) build: get rid of 'HAVE_ANSI_COMPILER' C preprocessor conditional GNU make already assume C89 or later throughout the codebase, and that preprocessor conditional was no longer used anyway. * configure.ac: Remove AC_DEFINE of HAVE_ANSI_COMPILER. * config.ami.template: Remove #define of HAVE_ANSI_COMPILER. * config.h-vms.template: Likewise. * config.h.W32.template: Likewise. * configh.dos.template: Likewise. 2013-04-30 Stefano Lattarini (tiny change) cosmetics: fix few innocuous typos Most of these were found using Lucas De Marchi's 'codespell' tool. * ChangeLog: Fix minor typos. * ChangeLog.2: Likewise. * README.Amiga: Likewise. * TODO.private: Likewise. * function.c: Likewise. * glob/glob.h: Likewise. * job.c: Likewise. * main.c: Likewise. * readme.vms: Likewise. * remake.c: Likewise. * tests/ChangeLog: Likewise. * tests/NEWS: Likewise. * tests/README: Likewise. * tests/scripts/variables/private: Likewise. * vmsdir.h: Likewise. * signame.c: Likewise. While at it, improve line wrapping in the touched comment. 2013-04-29 Eli Zaretskii * w32/include/dlfcn.h: New file. * w32/compat/posixfcn.c: Include dlfcn.h. (dlopen, dlerror, dlsym) [MAKE_LOAD]: New functions, in support of dynamic loading. * config.h.W32.template (MAKE_LOAD): Define. * load.c (load_object) [HAVE_DOS_PATHS]: Support backslashes and drive letters in file names of dynamic objects. * job.c (construct_command_argv_internal) [WINDOWS32]: Return right after generating new_argv for one_shell case. This fixes the Windows build for both Unixy shell and stock Windows shells. 2013-04-28 Eli Zaretskii * dir.c (local_stat) [WINDOWS32]: Use the wrapper on MS-Windows. If the argument ends in "dir/.", make sure the parent dir exists and is indeed a directory. Fixes Savannah bug #37065. 2013-04-28 Paul Smith * makeint.h (message_s, error_s): Functions that print to strings rather than directly to files. * misc.c (message_s, error_s): Create them. * job.c (child_error): Print error messages to the output sync logs, if one exists, rather then directly to the terminal. (reap_children): Move the per-line sync after child_error(). * configure.ac: Remove support for pre-ANSI variadic function calls. * makeint.h: Ditto. * misc.c: Ditto. * config.ami.template: Ditto. * config.h-vms.template: Ditto. * config.h.W32.template: Ditto. * configh.dos.template: Ditto. Implement a "per-job" output synchronization option. * main.c (decode_output_sync_flags): Recognize the new option. * makeint.h (OUTPUT_SYNC_JOB): Add new values for "job" * job.c (assign_child_tempfiles): In per-job mode, truncate the temp file for re-use by the next job. (sync_output): Don't close the temp files as we may still use them. (free_child): Close the temp files here as we definitely don't need them. (new_job): In per-job output mode, sync_output() after each job. * job.h (struct child): Avoid ifdefs. * make.1: Add new options to the man page. * doc/make.texi (Parallel Output): Break documentation on input and output into separate sections for readability. Document the new "job" and "none" modes. 2013-04-27 Paul Smith * job.c (construct_command_argv_internal): Fix oneshell support for non-POSIX-sh shells. * load.c (load_object): Extract all POSIX-isms into a separate function for portability. (load_file): Check the .LOADED variable first and don't invoke load_object() if it's already been loaded. 2013-04-27 Eli Zaretskii * read.c (record_files): Pay attention to .ONESHELL in MS-Windows. * job.c (construct_command_argv_internal): Support .ONESHELL on MS-Windows, when the shell is not a Unixy shell. 2013-04-27 Eli Zaretskii * job.c: Fix compilation error on GNU/Linux due to "label at end of compound statement". 2013-04-27 Frank Heckenbach (tiny change) * job.c (sync_output): Don't discard the output if acquire_semaphore fails; instead, dump the output unsynchronized. 2013-04-27 Eli Zaretskii Support --output-sync on MS-Windows. * w32/compat/posixfcn.c: New file, with emulations of Posix functions and Posix functionality for MS-Windows. * w32/subproc/sub_proc.c: Include io.h. (process_noinherit): New function, forces a file descriptor to not be inherited by child processes. (process_easy): Accept two additional arguments, and use them to set up the standard output and standard error handles of the child process. * w32/include/sub_proc.h (process_easy): Adjust prototype. (process_noinherit): Add prototype. * read.c [WINDOWS32]: Include windows.h and sub_proc.h. * makeint.h (LOCALEDIR) [WINDOWS32}: Define to NULL if not defined. This is needed because the MS-Windows build doesn't have a canonical place for LOCALEDIR. (WIN32_LEAN_AND_MEAN) [WINDOWS32]: Define, to avoid getting from windows.h header too much stuff that could conflict with the code. * main.c : New static variable. : Add support for "--sync-mutex" switch. (decode_output_sync_flags): Decode the --sync-mutex= switch. (prepare_mutex_handle_string) [WINDOWS32]: New function. (main): Add "output-sync" to .FEATURES. * job.h (CLOSE_ON_EXEC) [WINDOWS32]: Define to call process_noinherit. (F_GETFD, F_SETLKW, F_WRLCK, F_UNLCK, struct flock) [WINDOWS32]: New macros. (RECORD_SYNC_MUTEX): New macro, a no-op for Posix platforms. (sync_handle_t): New typedef. * job.c : Change type to sync_handle_t. (FD_NOT_EMPTY): Seek to the file's end. Suggested by Frank Heckenbach . (pump_from_tmp_fd) [WINDOWS32]: Switch to_fd to binary mode for the duration of this function, and then change back before returning. (start_job_command) [WINDOWS32]: Support output_sync mode on MS-Windows. Use a system-wide mutex instead of locking stdout/stderr. Call process_easy with two additional arguments: child->outfd and child->errfd. (exec_command) [WINDOWS32]: Pass two additional arguments, both -1, to process_easy, to adjust for the changed function signature. * function.c (windows32_openpipe) [WINDOWS32]: This function now returns an int, which is -1 if it fails and zero otherwise. It also calls 'error' instead of 'fatal', to avoid exiting prematurely. (func_shell_base) [WINDOWS32]: Call perror_with_name if windows32_openpipe fails, now that it always returns. This avoids a compiler warning that error_prefix is not used in the MS-Windows build. * config.h.W32.template (OUTPUT_SYNC): Define. * build_w32.bat: Add w32/compat/posixfcn.c to compilation and linking commands. 2013-04-20 Stefano Lattarini (tiny change) * README.git: Our autoconf input file is 'configure.ac', not 'configure.in'. Adjust accordingly. * build_w32.bat: Likewise. * config.h-vms.template: Likewise. * Makefile.DOS.template: Likewise. 2013-04-16 Paul Smith * misc.c (open_tmpfd): Add a new function that returns a temporary file by file descriptor. (open_tmpfile): Move here from main.c. * job.c (assign_child_tempfiles): Use the new open_tmpfd(). 2013-04-15 Paul Smith * makeint.h (OUTPUT_SYNC_TARGET, OUTPUT_SYNC_MAKE): Rename. * job.c (start_job_command): Use new constants. * main.c: New -O argument format. * doc/make.texi (Options Summary): Document the argument to -O. * make.1: Ditto. * main.c (define_makeflags): Don't add space between a single-char option and its argument. 2013-04-06 Paul Smith * doc/make.texi (Implicit Variables): Clarify LDFLAGS vs. LDLIBS. Fixes Savannah bug #37970. * remake.c (check_dep): Reconsider files waiting on prerequisites, as they may have finished. Fixes Savannah bug #37703. 2013-02-28 Paul Smith * function.c (func_realpath): On Solaris (at least) realpath() can fail due to EINTR, so loop it. Fixes Savannah bug #38420. 2013-02-25 Paul Smith Add a proposed supported API for GNU make loaded objects. * doc/make.texi (Loaded Object API): Document it. * Makefile.am (make_SOURCES): Add new loadapi.c. * dep.h: Remove eval_buffer(); moved to loadapi.c:gmk_eval(). * read.c (eval_buffer): Change eval_buffer() signature. * main.c (main): Change eval_buffer() signature. * variable.h (define_new_function): Change func_ptr signature. * load.c (SYMBOL_EXTENSION): Change the extension. * loadapi.c: Implement the new API. * gnumake.h (gmk_eval): New function prototype. (gmk_expand) Ditto. (gmk_add_function) Ditto. * gmk-default.scm (gmk-eval): Remove: now implemented in guile.c. * guile.c (guile_expand_wrapper): Use gmk_expand() (guile_eval_wrapper): Implement eval here to avoid double-expansion. (guile_define_module): Define gmk-eval. (func_guile): Use new func_ptr calling model. (guile_gmake_setup): Use gmk_add_function() to declare $(guile ...) * function.c (function_table_entry): Provide alternative func_ptr. (func_eval): New signature for eval_buffer(); (function_table_init): New initialization for function_table_entry. (expand_builtin_function): Support alternative invocation signature. (define_new_function): Ditto. 2013-01-20 Paul Smith * gnumake.h: New file to contain externally-visible content. * makeint.h: Include gnumake.h. Move gmk_floc type to gnumake.h. * Makefile.am (include_HEADERS): Install the gnumake.h header. * makeint.h: Change struct floc to gmk_floc typedef. * Many: Use the new typedef. * make.h: Rename to makeint.h. * Many: Use the new name makeint.h. 2013-01-19 Paul Smith * doc/make.texi (load Directive): Update to discuss location of loaded object file. (Remaking Loaded Objects): Document remaking of loaded objects. * main.c (main): Rename READ_MAKEFILES to READ_FILES. * read.c: Change READ_MAKEFILES to READ_FILES since it now contains loaded object files as well. (read_all_makefiles): Ditto. (eval_makefile): Ditto. (eval): Add any loaded file to the READ_FILES list, so that it will be considered for re-build. * load.c (load_file): Return the simple filename (no symbol) in the LDNAME argument (now a const char **). This filename should no longer have "./" prepended: modify the function to always check the current directory if the name has no "/", before using the normal methods. * make.h: Change the load_file() prototype. * README.git: Add a bit more documentation on Git workflow & rules. 2013-01-13 Paul Smith * main.c (main): Restore all make flags after re-exec is complete. Fixes Savannah bug #38051. 2013-01-12 Paul Smith Convert CVS archive to Git. * configure.in: Rename to configure.ac. * README.cvs: Rename to README.git and rework for Git. * maintMakefile: Use git clean for cleanup. * ChangeLog: Use new Git repository URL. * ChangeLog.2: Ditto. * Makefile.am: Change documentation for Git * Makefile.DOS.template: Ditto. * README.template: Ditto. * build_w32.bat: Ditto. * prepare_w32.bat: Ditto. * .cvsignore: Rename to .gitignore, and change to Git format. 2012-12-08 Eli Zaretskii * job.c (create_batch_file): Fix last change: always increment the counter of batch files before trying to use it. 2012-12-07 Eli Zaretskii * job.c (construct_command_argv_internal): Remove " from sh_chars_dos[]. Ignore an escaped backslash inside a string quoted with "..". This lifts the 4KB or 8KB command-line length limitation imposed by the Windows shells when a command uses quoted strings, because we now don't call the shell in that case. * job.c (create_batch_file): Declare the counter of batch files static, to avoid having 2 jobs using the same file name and stepping on each other's toes. When all 64K names are used up, make one more loop looking for slots that became vacant. This avoids leaving behind temporary batch files in the temporary directory, which happens frequently on a fast machine when using parallel builds. (reap_children): Add debug message for when removal of a temporary batch file fails. 2012-10-29 Paul Smith New feature: "load" directive for dynamically-loaded objects. * NEWS: Document new "load" directive. * doc/make.texi (Extending make): New chapter on extensions to make. * configure.in: Check for dlopen/dlsym/dlerror and -ldl. * Makefile.am (make_SOURCES): Add new file load.c. * make.h: Prototype for load_file(). * main.c (main): Add "load" to .FEATURES if it's available. * read.c (eval): Parse "load" and "-load" directives. 2012-09-29 Paul Smith * configure.in: Require a new version of gettext (1.18.1). Fixes Savannah bug #37307. 2012-09-09 Paul Smith * configure.in (bsd_signal): Define _GNU_SOURCE, a la make.h. Fixes Savannah bug #32247. * remake.c (update_file_1): Force intermediate files to be considered, not pruned, if their non-intermediate parent needs to be remade. Fixes Savannah bug #30653. * job.c (construct_command_argv_internal): Keep the command line on the heap for very long lines. Fixes Savannah bug #36451. * function.c (func_realpath): BSD realpath(3) doesn't fail if the file does not exist: use stat. Fixes Savannah bug #35919. * file.c (expand_deps): Duplicate the current variable buffer, not the old pointer. Fixes Savannah bug #36925. * read.c (eval): If we detect an initial UTF-8 BOM, skip it. Fixes Savannah bug #36529. (record_target_var): Remove unused variable "fname". (eval): Use the correct pointer when adding to the variable buffer. Fixes Savannah bug #36106. 2012-09-09 Eli Zaretskii * read.c (unescape_char): Fix a thinko in the last change. 2012-09-09 Paul Smith * default.c (default_variables): Use a correct default LIBPPATERNS for MacOS. Fixes Savannah bug #37197. * read.c (record_files): Reset the default macro values if .POSIX is set. Fixes Savannah bug #37069. (parse_file_seq): Break out of an infinite loop if we're not making progress when parsing archive references. 2012-09-01 Eli Zaretskii * README.W32.template: Update for job-server and Guile support. * read.c (unescape_char): Advance 'p' after copying the unescaped characters. Otherwise the backslashes are incorrectly erased from the original string. 2012-03-05 Paul Smith Update copyright notices to use year ranges, as allowed by clarifications in the GNU Maintainer's Manual. 2012-03-04 Paul Smith * read.c (unescape_char): New function to remove escapes from a char. (record_files): Call it on the dependency string to unescape ":". Fixes Savannah bug #12126 and bug #16545. * make.h (CSTRLEN): Determine the length of a constant string. * main.c: Use the new macro. * read.c: Ditto. * variable.h: Ditto. * function.c: Simplify checks for function alternatives. * expand.c (variable_append): If the current set is local and the next one is not a parent, then treat the next set as local as well. Fixes Savannah bug #35468. 2012-03-03 Paul Smith * acinclude.m4 (AC_STRUCT_ST_MTIM_NSEC): Add support for AIX 5.2+ nanosecond timestamps. Fixes Savannah bug #32485. Convert uses of `foo' for quoting to 'foo' to reflect changes in the GNU Coding Standards. Fixes Savannah bug #34530. * job.c (construct_command_argv_internal): In oneshell we need to break the SHELLFLAGS up for argv. Fixes Savannah bug #35397. * function.c (func_filter_filterout): Recompute the length of each filter word in case it was compressed due to escape chars. Don't reset the string as it's freed. Fixes Savannah bug #35410. * misc.c (collapse_continuations): Only use POSIX-style backslash/newline handling if the .POSIX target is set. Addresses Savannah bug #16670 without backward-incompatibility. * NEWS: Document behavior change. * doc/make.texi (Splitting Lines): New section describing how to use backslash/newline to split long lines. 2012-02-26 Paul Smith * implicit.c (pattern_search): Check the stem length to avoid stack overflows in stem_str. Fixes Savannah bug #35525. 2012-02-03 Eli Zaretskii * w32/subproc/sub_proc.c (proc_stdin_thread, proc_stdout_thread) (proc_stderr_thread, process_pipe_io): Ifdef away unused functions. * w32/subproc/w32err.c (map_windows32_error_to_string) [_MSC_VER]: Don't use TLS storage for szMessageBuffer. Ifdef away special code for handling Winsock error codes. Make the function return a `const char *'. Suggested by Ozkan Sezer. Fixes Savannah bug #34832. 2012-01-29 Paul Smith * gmk-default.scm (to-string-maybe): Variables map to empty strings. In Guile 2.0, (define ...) results in a variable object so make sure that maps to an empty string in make. * variable.c (parse_variable_definition): New POSIX assignment ::= Take a struct variable to return more information after parsing. (assign_variable_definition): New parse_variable_definition() call. * variable.h: New declaration of parse_variable_definition(). * read.c (do_define): New parse_variable_definition() call. (parse_var_assignment): Ditto. (get_next_mword): Parse ::= as a variable assignment. * doc/make.texi (Flavors): Describe the new ::= syntax. * NEWS: Mention the ::= operator. * variable.h (struct variable): Rearrange elts to reduce struct size. * function.c (func_file): Create a new function, $(file ...) * doc/make.texi (File Function): Document the $(file ..) function. * NEWS: Announce it. * gmk-default.scm (to-string-maybe): Use a more portable way to test for unprintable characters. * configure.in [GUILE]: Guile 1.6 doesn't have pkg-config * build_w32.bat: Ditto. 2012-01-28 Eli Zaretskii * config.h.W32.template: Update from config.h.in. Support a Windows build with Guile. * README.W32.template: Update with instructions for building with Guile. * build_w32.bat: Support building with Guile. * make.h [HAVE_STDINT_H]: Include stdint.h. * main.c (main, clean_jobserver): Move declarations of variables not used in the WINDOWS32 build to the #else branch, to avoid compiler warnings. Fix failures on MS-Windows when Make's standard handles are invalid. This can happen when Make is invoked from a GUI application. * w32/subproc/sub_proc.c (process_init_fd): Don't dereference pproc if it is a NULL pointer. (process_begin, process_cleanup): Don't try to close pipe handles whose value is INVALID_HANDLE_VALUE. (process_easy): Initialize hIn, hOut, and hErr to INVALID_HANDLE_VALUE. If DuplicateHandle fails with ERROR_INVALID_HANDLE, duplicate a handle for the null device instead of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE or STD_ERROR_HANDLE. Don't try to close pipe handles whose value is INVALID_HANDLE_VALUE. * function.c (windows32_openpipe): Initialize hIn and hErr to INVALID_HANDLE_VALUE. If DuplicateHandle fails with ERROR_INVALID_HANDLE, duplicate a handle for the null device instead of STD_INPUT_HANDLE or STD_ERROR_HANDLE. Fix indentation. Don't try to close handles whose value is INVALID_HANDLE_VALUE. 2012-01-25 Eli Zaretskii * function.c (define_new_function): Fix format strings in calls to `fatal'. 2012-01-17 Paul Smith * guile.c (func_guile): Handle NULL returns from Guile. 2012-01-16 Paul Smith * make.h (PATH_SEPARATOR_CHAR): Allow resetting for crosscompiling for Windows. Patch by Chris Sutcliffe Fixes Savannah bug #34818. 2012-01-15 Paul Smith * variable.h: Prototype an interface for defining new make functions. * function.c (define_new_function): Define it. (func_guile): Remove the "guile" function. (function_table_init): Ditto. * guile.c (func_guile): Add the "guile" function here. (setup_guile): Call define_new_function() to define it. (guile_eval_string): Obsolete. * all: Update copyright notices. 2012-01-12 Paul Smith Support GNU Guile as an embedded extension language for GNU make. * NEWS: Note the new Guile capability. * Makefile.am (EXTRA_DIST, make_SOURCES): Add new guile source files. (AM_CFLAGS): Add Guile compiler flags. (guile): Add a rule for converting default SCM into a C header. * configure.in: Add support for --with-guile. Also, convert the entire file to properly escaped autoconf m4, and utilize newer features such as AS_IF() and AS_CASE(). * doc/make.texi (Guile Function): Document the GNU guile integration. * make.h (guile_eval_string, guile_boot): Prototypes for Guile. * main.c (main): Run guile_boot() to handle main(). (real_main): All the previous content of main() is here. (real_main): Add "guile" to the .FEATURES variable. * function.c (func_guile): Call Guile. * guile.c: New file implementing GNU make integration with GNU Guile. * gmk-default.scm: The integration of GNU make with Guile uses Guile itself for much of the parsing and conversion of return types, etc. This implementation is embedded into GNU make. * config.h-vms.template: Disable Guile support. * config.h.W32.template: Ditto. * configh.dos.template: Ditto. * config.ami.template: Ditto. * makefile.vms: Add new Guile files. * Makefile.DOS.template: Ditto. * Makefile.ami: Ditto. * NMakefile.template: Ditto. * SMakefile.template: Ditto. * build_w32.bat: Ditto. * dosbuild.bat: Ditto. * make_msvc_net2001.vcproj: Ditto. 2011-11-15 Paul Smith * main.c (main): Use %ld when printing DWORD values. * job.c (new_job): Ditto. * w32/include/sub_proc.h: Use const. * w32/subproc/sub_proc.c (open_jobserver_semaphore): Use const. Fixes Savannah bug #34830. Changes suggested by Ozkan Sezer. * configure.in (MAKE_JOBSERVER): Enable jobserver on W32 systems. * config.h.W32.template (MAKE_JOBSERVER): Ditto. 2011-11-14 Paul Smith * read.c (eval): parse_file_seq() might shorten the string due to backslash removal. Start parsing again at the colon. Fixes Savannah bug #33399. 2011-11-13 Paul Smith * file.c (file_timestamp_cons): Match up data types to avoid warnings. * filedef.h: Ditto. * misc.c (concat): Ditto. * read.c (eval): Assign value to avoid warnings. * function.c (func_shell_base): Use fork() instead of vfork() to avoid warnings. * make.h (INTEGER_TYPE_SIGNED): Use <=0 to avoid warnings. Fixes Savannah bug #34608. * job.c (construct_command_argv): Remove _p. (construct_command_argv_internal): Remove _ptr. Fixes Savannah bug #32567. * main.c (clean_jobserver): Don't write the free token to the pipe. Change suggested by Tim Newsome * acinclude.m4 (AC_STRUCT_ST_MTIM_NSEC): Add support for Darwin. * filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Ditto. Patch provided by Troy Runkel 2011-10-11 Troy Runkel * config.h.W32: Enable job server support for Windows. * main.c [WINDOWS32]: Include sub_proc.h (main): Create a named semaphore to implement the job server. (clean_jobserver): Free the job server semaphore when make is finished. * job.c [WINDOWS32]: Define WAIT_NOHANG (reap_children): Support non-blocking wait for child processes. (free_child): Release job server semaphore when child process finished. (job_noop): Don't define function on Windows. (set_child_handler_action_flags): Don't define function on Windows. (new_job): Wait for job server semaphore or child process termination. (exec_command): Pass new parameters to process_wait_for_any. * w32/include/sub_proc.h [WINDOWS32]: New/updated EXTERN_DECL entries. * w32/subproc/sub_proc.c [WINDOWS32]: Added job server implementation. (open_jobserver_semaphore): Open existing job server semaphore by name. (create_jobserver_semaphore): Create new job server named semaphore. (free_jobserver_semaphore): Close existing job server semaphore. (acquire_jobserver_semaphore): Decrement job server semaphore count. (release_jobserver_semaphore): Increment job server semaphore count. (has_jobserver_semaphore): Returns whether job server semaphore exists. (get_jobserver_semaphore_name): Returns name of job server semaphore. (wait_for_semaphore_or_child_process): Wait for either the job server semaphore to become signalled or a child process to terminate. (process_wait_for_any_private): Support for non-blocking wait for child. (process_wait_for_any): Added support for non-blocking wait for child. (process_file_io): Pass new parameters to process_wait_for_any_private. 2011-09-18 Paul Smith * main.c (main): If we're re-exec'ing and we're the master make, then restore the job_slots value so it goes back into MAKEFLAGS properly. See Savannah bug #33873. * remake.c (library_search): STD_DIRS is computed when other static vars like buflen etc. are computed, so it must be static as well. See Savannah bug #32511. 2011-09-16 Paul Smith * maintMakefile (do-po-update): Apparently we have to avoid certificate checks on the https://translationproject.org site now. 2011-09-12 Paul Smith * read.c (eval): Ensure exported variables are defined in the global scope. Fixes Savannah bug #32498. 2011-09-11 Paul Smith * Makefile.am (dist-hook): Remove w32/Makefile and .deps/ from the dist file. Fixes Savannah bug #31489. * doc/make.texi (Complex Makefile): Add a hint about using #!/usr/bin/make (for Savannah support request #106459) 2011-09-02 Paul Smith * remake.c (touch_file): If we have both -n and -t, -n takes precedence. Patch from Michael Witten 2011-08-29 Paul Smith * expand.c (variable_expand_string): Always allocate a new buffer for a string we're expanding. The string we're working on can get freed while we work on it (for example if it's the value of a variable which modifies itself using an eval operation). See Savannah patch #7534 for the original report by Lubomir Rintel. 2011-06-12 Paul Smith * read.c (parse_file_seq): Move the check for empty members out of the loop so we can go to the next member properly. Another fix for Savannah bug #30612. * config.h-vms.template: Newer versions of VMS have strncasecmp() Patch provided by: Hartmut Becker 2011-05-07 Paul Smith * expand.c (variable_append): Add a LOCAL argument to track whether this is the first invocation or not. If it's not and private_var is set, then skip this variable and try the next one. Fixes Savannah bug #32872. * read.c (parse_file_seq): Ensure existence checks use glob(). 2011-05-07 Eli Zaretskii * job.c (construct_command_argv_internal): Don't assume shellflags is always non-NULL. Escape-protect characters special to the shell when copying the value of SHELL into new_line. Fixes Savannah bug #23922. 2011-05-02 Paul Smith * doc/make.texi (Special Variables): Add documentation for the new words in .FEATURES. Fixes Savannah bug #32058. (Flavor Function): Rewrite the section on the flavor function. Fixes Savannah bug #31582. * function.c (func_sort): Use the same algorithm to count the number of words we will get after the split, as we use to split. Based on a patch from Matthias Hopf. Fixes Savannah bug #33125. * make.h: Make global variable stack_limit extern. Fixes Savannah bug #32753. 2011-05-01 Paul Smith * read.c (parse_file_seq): Don't try to invoke glob() unless there are potential wildcard characters in the filename. Performance enhancement suggested by Michael Meeks 2011-04-29 Boris Kolpackov * read.c (eval_makefile): Delay caching of the file name until after all the expansions and searches. 2011-04-17 David A. Wheeler * doc/make.texi (Reading Makefiles): Document "!=". (Setting): Ditto. (Features): Ditto. * variable.h (enum variable_flavor): New type "f_shell". * variable.c (shell_result): Send a string to the shell and store the output. (do_variable_definition): Handle f_shell variables: expand the value, then send it to the shell and store the result. (parse_variable_definition): Parse "!=" shell assignments. * read.c (get_next_mword): Treat "!=" as a varassign word. * function.c (fold_newlines): If trim_newlines is set remove all trailing newlines; otherwise remove only the last newline. (func_shell_base): Move the guts of the shell function here. (func_shell): Call func_shell_base(). 2011-02-21 Paul Smith * strcache.c (various): Increase performance based on comments from Ralf Wildenhues . Stop looking for a buffer when we find the first one that fits, not the best fit. If there is not enough free space in a buffer move it to a separate list so we don't have to walk it again. * make.h (NDEBUG): Turn off asserts unless maintainer mode is set. (strcache_add_len, strcache_setbufsize): Use unsigned length/size. * maintMakefile (AM_CPPFLAGS): Enable MAKE_MAINTAINER_MODE. * remake.c (complain): Move translation lookups closer to use. 2011-02-13 Paul Smith * doc/make.texi: Clean up references to "static" variables and semicolon errors. Patch from Michael Witten . 2010-12-27 Paul Smith * make.1: Update the header/footer info in the man page. 2010-11-28 Paul Smith * read.c (record_target_var): Don't reset v if it's the same as the global version. Fixes Savannah bug #31743. 2010-11-06 Paul Smith * variable.c (print_auto_variable): Print auto variables; ignore others. (print_noauto_variable): Print non-auto variables; ignore others. (print_variable_set): Allow the caller to select which type to print. (print_target_variables): Show all the non-auto variables for a target. * default.c (install_default_suffix_rules): Initialize recipe_prefix. * rule.c (install_pattern_rule): Ditto. * read.c (record_files): Pass in the current recipe prefix. Remember it in the struct command for these targets. (eval): Remember the value of RECIPEPREFIX when we start parsing. Do not remove recipe prefixes from the recipe here: we'll do it later. * job.c (start_job_command): Remove recipe prefix characters early, before we print the output or chop it up. * file.c (print_file): If recipe_prefix is not standard, reset it in -p output. Assign target variables in -p output as well. * commands.c (chop_commands): Max command lines is USHRT_MAX. Set any_recurse as a bitfield. * make.h (USHRT_MAX): Define if not set. 2010-10-27 Paul Smith * commands.h (struct commands): Rearrange to make better use of memory. Add new recipe_prefix value. 2010-10-26 Paul Smith * doc/make.texi (Setting): Document the treatment of backslash-newline in variable values. * misc.c (collapse_continuations): Do not collapse multiple backslash-newlines into a single space. Fixes Savannah bug #16670. 2010-08-29 Paul Smith * doc/make.texi (Implicit Variables): Document LDLIBS and LOADLIBES. Fixes Savannah bug #30807. (Instead of Execution): Mention that included makefiles are still rebuilt even with -n. Fixes Savannah bug #30762. * configure.in: Bump to 3.82.90. * make.h: Add trace_flag variable. * main.c (switches): Add --trace option. (trace_flag): Declare variable. * job.c (start_job_command): Show recipe if trace_flag is set. (new_job): Show trace messages if trace_flag is set. * doc/make.texi (Options Summary): Document the new --trace option. * make.1: Add --trace documentation. * NEWS: Mention --trace. * job.c (child_error): Show recipe filename/linenumber on error. Also show "(ignored)" when appropriate even for signals/coredumps. * NEWS: Mention file/linenumber change. * main.c (main): Print version info when DB_BASIC is set. * job.c (construct_command_argv_internal): If shellflags is not set, choose an appropriate default value. Fixes Savannah bug #30748. 2010-08-27 Eli Zaretskii * variable.c (define_automatic_variables) [__MSDOS__ || WINDOWS32]: Remove trailing backslashes in $(@D), $( * NEWS: Accidentally forgot to back out the sorted wildcard enhancement in 3.82, so update NEWS. Also add NEWS about the error check for explicit and pattern targets in the same rule, added to 3.82. * main.c (main): Add "oneshell" to $(.FEATURES) (forgot to add this in 3.82!) * read.c (parse_file_seq): Fix various errors parsing archives with multiple objects in the parenthesis, as well as wildcards. Fixes Savannah bug #30612. 2010-08-10 Paul Smith * main.c (main): Expand MAKEFLAGS before adding it to the environment when re-exec'ing. Fixes Savannah bug #30723. 2010-08-07 Eli Zaretskii * w32/subproc/build.bat: Make all 3 cl.exe compile command lines use the same /I switches. Fixes Savannah bug #30662. * function.c (func_shell) [WINDOWS32]: Reset just_print_flag around the call to construct_command_argv, so that a temporary batch file _is_ created when needed for $(shell). Fixes Savannah bug #16362. 2010-08-07 Juan Manuel Guerrero * configh.dos.template (HAVE_STRNCASECMP): Define. 2010-07-28 Paul Smith Version 3.82 released. * configure.in: Change release version. * NEWS: Change the date. * read.c (parse_file_seq): Remove GLOB_NOSORT for backward-compatibility. We'll add it back in next release. * NEWS: Note it. 2010-07-24 Eli Zaretskii * job.c (pid2str) [WINDOWS32]: Fix CPP conditionals for using %Id format. 2010-07-18 Paul Smith * configure.in: Switch bsd_signal to AC_CHECK_DECLS() to make sure we have a declaration. Fixes Savannah bug #25713 (maybe?) * doc/make.texi (Complex Makefile): Cleanup variable assignments. (One Shell): New subsection for the .ONESHELL special target. Patches by Ozkan Sezer : * misc.c (strncasecmp): Local implementation for systems without. * config.h.W32.template (HAVE_STRNICMP): Define on Windows. * configure.in: Check for strncasecmp/strncmpi/strnicmp. * job.c [WINDOWS32]: Don't define dup2 on Windows. (pid2str): Use "%Id" even with MSVC (exec_command): Cast to pid_t when calling pid2str(). * w32/subproc/sub_proc.c [WINDOWS32]: Include config.h first. Use stddef.h on MSVC to get intptr_t. * w32/subproc/misc.c [WINDOWS32]: Include config.h first. * w32/compat/dirent.c [WINDOWS32]: Include config.h first. (readdir): Cast -1 to correct type for d_ino. * w32/pathstuff.c [WINDOWS32]: Ensure make.h is included first. * make.h [WINDOWS32]: Don't prototype alloca() on Windows. Add configuration for strncasecmp(). * main.c (ADD_SIG) [WINDOWS32]: Avoid warnings in MSVC. * config.h.W32.template [WINDOWS32]: Don't warn on unsafe functions or variables. * NMakefile.template [WINDOWS32]: Remove /MACHINE:I386. * main.c (clean_jobserver): Cast due to MSVC brokenness. (decode_switches): Ditto. * vpath.c (construct_vpath_list): Ditto. * rule.c (freerule): Ditto. * ar.c (ar_glob): Ditto. 2010-07-16 Boris Kolpackov * misc.c (concat): Fix buffer overrun. 2010-07-12 Paul Smith Update copyrights to add 2010. * build_w32.bat: Support for MSVC Windows x86_64 builds. * job.c: Don't define execve() on MSVC/64bit. Patch by Viktor Szakats. Fixes Savannah bug #27590. 2010-07-12 Eli Zaretskii * make.h (alloca) [!__GNUC__]: Don't define prototype. (int w32_kill): Use pid_t for process ID argument. Fixes Savannah bug #27809. 2010-07-12 Paul Smith Integrated new .ONESHELL feature. Patch by David Boyce . Modified by me. * NEWS: Add a note about the new feature. * job.c (is_bourne_compatible_shell): Determine whether we're using a standard POSIX shell or not. (start_job_command): Accept '-ec' as POSIX shell flags. (construct_command_argv_internal): If one_shell is set and we are using a POSIX shell, remove "interior" prefix characters such as "@", "+", "-". Also treat "\n" as a special character when choosing the slow path, if ONESHELL is set. * job.h (is_bourne_compatible_argv): Define the new function. * make.h (one_shell): New global variable to remember setting. * main.c: Declare it. * read.c (record_files): Set it. * commands.c (chop_commands): If one_shell is set, don't chop commands into multiple lines; just keep one line. 2010-07-09 Eli Zaretskii * w32/subproc/sub_proc.c: Include stdint.h. (sub_process_t): Use intptr_t for file handles and pid_t for process ID. (process_pipes, process_init_fd, process_begin): Use intptr_t for file handles and pid_t for process ID. Fixes Savannah bug #27809. Patch by Ozkan Sezer * function.c (abspath): Support absolute file names in UNC format. Fixes Savannah bug #30312. * job.c (pid2str) [WINDOWS32]: Don't use %Id with GCC < 4.x. (exec_command) [WINDOWS32]: Use pid2str instead of non-portable %Id. * main.c (handle_runtime_exceptions): Use %p to print addresses, to DTRT on both 32-bit and 64-bit hosts. Savannah bug #27809. * job.c (w32_kill, start_job_command, create_batch_file): Use pid_t for process IDs and intptr_t for the 1st arg of _open_osfhandle. * function.c (windows32_openpipe): Use pid_t for process IDs and intptr_t for the 1st arg of _open_osfhandle. (func_shell): Use pid_t for process IDs. * main.c (main) [WINDOWS32]: Pacify the compiler. * config.h.W32.template (pid_t): Add a definition for 64-bit Windows builds that don't use GCC. Fixes Savannah bug #27809. Patch by Ozkan Sezer 2010-07-07 Paul Smith * configure.in: Bump to a new prerelease version 3.81.91. 2010-07-06 Paul Smith * main.c (main): Set a default value of "-c" for .SHELLFLAGS. * NEWS: Mention the new behavior of .POSIX and the new .SHELLFLAGS variable. * job.c (construct_command_argv): Retrieve the .SHELLFLAGS value and pass it to construct_command_argv_internal(). (construct_command_argv_internal): If .SHELLFLAGS is non-standard use the slow path. Use that value instead of hard-coded "-c". 2010-07-05 Paul Smith * implicit.c (pattern_search): lastslash can be const. * dir.c (downcase): Remove unused variable. * hash.c (hash_init): Cast sizeof for error message. * arscan.c (ar_scan): Cast to char* for WINDOWS32. (ar_member_touch): Ditto. * ar.c (glob_pattern_p): Avoid symbol collision: open -> opened * signame.c (strsignal): Ditto: signal -> sig * job.c (create_batch_file): Ditto: error -> error_string (pid2str): Portably convert a pid_t into a string (reap_children): Use it. (start_waiting_job): Use it. Savannah bug #27809. Patch by Ozkan Sezer 2010-07-03 Paul Smith * read.c (parse_file_seq): All archive groups must end with ')' as the LAST character in a word. If there is no word ending in ')' then it's not an archive group. Fixes Savannah bug #28525. 2010-07-01 Paul Smith * main.c (main): Append optional features using separate calls. Not as efficient but not all compilers allow conditionals inside macro calls. Fixes Savannah bug #29244. 2010-01-10 Paul Smith * make.h (patheq): Rename strieq() to patheq() for clarity. * dir.c (dir_contents_file_exists_p): Use it. * dir.c (file_impossible): Convert xmalloc/memset to xcalloc. * file.c (enter_file): Ditto. * job.c (new_job): Ditto. 2009-12-11 Eli Zaretskii * job.c (construct_command_argv_internal) [WINDOWS32]: Add "echo." and a few more commands that are built into cmd.exe. Fixes Savannah bug #28126. * file.c (lookup_file) [HAVE_DOS_PATHS]: Treat '\\' like we do with '/'. 2009-11-15 Paul Smith Patches for VMS provided by Hartmut Becker * vmsjobs.c (ctrlYPressed) [VMS]: Deal with CTRL-Y. (vmsHandleChildTerm) [VMS]: Ditto. (astYHandler) [VMS]: Ditto. (tryToSetupYAst) [VMS]: Ditto. (child_execute_job) [VMS]: Ditto. * vmsify.c (trnlog) [VMS]: Fix const errors. (vmsify) [VMS]: Ditto. * readme.vms [VMS]: Update with notes for 3.82. * job.h (comname) [VMS]: Remember the temporary command filename * dir.c (vmsify) [VMS]: Fix const errors. (vms_hash) [VMS]: Ditto. (vmsstat_dir) [VMS]: Ditto. (find_directory) [VMS]: Fix case-insensitive option for VMS (dir_contents_file_exists_p) [VMS]: Ditto. (file_impossible) [VMS]: Ditto. * config.h-vms.template (HAVE_FDOPEN) [VMS]: Have it. (HAVE_STRCASECMP) [VMS]: Ditto. * arscan.c (VMS_get_member_info) [VMS]: Fix timezone computation. (ar_scan) [VMS]: Fix const error. 2009-11-12 Boris Kolpackov * vpath.c (vpath_search, selective_vpath_search): Add index arguments which allows the caller to get the index of the matching directory. * make.h (vpath_search): Update prototype. * remake.c (library_search): Implement linker-compatible library search. Use the new VPATH_SEARCH index functionality to keep track of the directory index for each match. Select the match with the lowest directory index. * implicit.c (pattern_search): Pass NULL for the index arguments in the VPATH_SEARCH call. * doc/make.texi (Directory Search for Link Libraries): Describe the new search behavior. * NEWS: Add a note about the new behavior. 2009-10-25 Paul Smith * AUTHORS, et.al.: Update copyright years. * implicit.c (stemlen_compare): Fix qsort() compare bug that caused implicit rules with equal stem lengths to be sorted indeterminately. 2009-10-24 Paul Smith * main.c (usage): Add --eval to the usage string. (switches): Add the --eval switch. (main): If --eval is given, add them to the simply-expanded variable -*-eval-flags-*- (necessary to allow recursion to work properly). (define_makeflags): Add -*-eval-flags-*- to MAKEFLAGS. * NEWS: Describe the new --eval command line argument. * doc/make.texi (Options Summary): Document --eval. * dep.h: eval_buffer() returns void. * read.c (eval_buffer): Ditto. (eval): Ditto. * variable.h (define_variable_cname): New macro for constant variable names. * default.c (set_default_suffixes): Use it. * main.c (main): Ditto. (handle_non_switch_argument): Ditto. (define_makeflags): Ditto. * read.c (read_all_makefiles): Ditto. * variable.c (define_automatic_variables): Ditto. * commands.c (dep_hash_cmp): Avoid casts. (dep_hash_1): Ditto. (dep_hash_2): Ditto. 2009-10-22 Boris Kolpackov * read.c (read_all_makefiles): Mark the default makefile dependency dontcare. 2009-10-07 Boris Kolpackov * read.c (do_undefine): Free the expanded variable name. * commands.c (dep_hash_cmp, set_file_variables): Move the order-only to normal upgrade logic from dep_hash_cmp to set_file_variables. 2009-10-06 Boris Kolpackov * dep.h (uniquize_deps): Remove. * read.c (uniquize_deps): Merge into set_file_variables in commands.c. (dep_hash_1, dep_hash_2, dep_hash_cmp): Move to commands.c. * commands.c (set_file_variables): Avoid modifying the dep chain to achieve uniqueness. Fixes savannah bug 25780. * implicit.c (pattern_search): Instead of re-setting all automatic variables for each rule we try, just update $*. 2009-10-06 Boris Kolpackov * variable.h (undefine_variable_in_set): New function declaration. (undefine_variable_global): New macro. * variable.c (undefine_variable_in_set): New function implementation. * read.c (vmodifiers): Add undefine_v modifier. (parse_var_assignment): Parse undefine. (do_undefine): Handle the undefine directive. (eval): Call do_undefine if undefine_v is set. * main.c (.FEATURES): Add a keyword to indicate the new feature. * doc/make.texi (Undefine Directive): Describe the new directive. * NEWS: Add a note about the new directive. 2009-10-05 Boris Kolpackov * implicit.c (pattern_search): Initialize file variables only if we need to parse a rule that requires the second expansion. 2009-10-03 Paul Smith * make.h: Include even on systems where __GNUC__ is defined. Not sure why it was done the other way. Requested by David Boyce . 2009-09-30 Boris Kolpackov * dep.h (dep): Add the DONTCARE bitfield. * filedef.h (file):Add the NO_DIAG bitfield. * read.c (eval_makefile): Set the DONTCARE flag in struct dep, not struct file (a file can be a dependency of many targets, some don't care, some do). * remake.c (update_goal_chain): Propagate DONTCARE from struct dep to struct file before updating the goal and restore it afterwards. (update_file): Don't prune the dependency graph if this target has failed but the diagnostics hasn't been issued. (complain): Scan the file's dependency graph to find the file that caused the failure. (update_file_1): Use NO_DIAG instead of DONTCARE to decide whether to print diagnostics. Fixes Savannah bugs #15110, #25493, #12686, and #17740. 2009-09-28 Paul Smith * doc/make.texi (Pattern Intro): Move the match algorithm discussion into the "Pattern Match" node. (Pattern Match): Expand on the pattern rule matching algorithm. 2009-09-28 Andreas Buening * job.c (construct_command_argv_internal) [OS2]: Don't eat too much of the command line on a single pass. 2009-09-28 Boris Kolpackov * varible.c (create_pattern_var): Insert variables into the PATTERN_VARS list in the shortest patterns first order. * implicit.c (tryrule): Add STEMLEN and ORDER members. These are used to sort the rules. (stemlen_compare): Compare two tryrule elements. (pattern_search): Sort the rules so that they are in the shortest stem first order. * main.c (.FEATURES): Add a keyword to indicate the new behavior. * doc/make.texi (Pattern-specific Variable Values): Describe the new pattern-specific variables application order. (Introduction to Pattern Rules): Describe the new pattern rules search order. * NEWS: Add a note about the new behavior. 2009-09-27 Paul Smith * doc/make.texi (Double-Colon): Mention that pattern rules with double-colons have a different meaning. Savannah bug #27497. 2009-09-27 Juan Manuel Guerrero * configh.dos.template: Remove unconditional definition of SYS_SIGLIST_DECLARED. Include because ports of GCC 4.3.0 and later no longer include it, so macros like __DJGPP_MINOR__ are no longer defined automatically. * Makefile.DOS.template (INCLUDES): Use $(prefix) and the corresponding variables to define LIBDIR, INCLUDEDIR and LOCALEDIR instead of using the hardcoded ones. (SUBDIRS): doc subdir added. (INFO_DEPS, DVIS): Values changed to 'make.info' and 'make.dvi'. (TEXI2HTML, TEXI2HTML_FLAGS): Removed. Use makeinfo --html to create html formated docs. texi2html may not be ported to DOS. (make.info, make.dvi, make.ps, make.html): Make targets depend on 'make.texi'. (.texi.info, .texi, .texi.dvi): Now invoked recursively. Change -I switch to look in ./ instead of ./doc. (html): Target depend on html-recursive instead of make_1.html. (make_1.html): Removed. (mostlyclean-aminfo): Use $(srcdir)/doc instead of ./ as prefix. (all-recursive): Allow for more than one subdir in the build process. (mostlyclean-recursive, clean-recursive, distclean-recursive) (maintainer-clean-recursive, check-recursive): Enter in doc/ too. (tags-recursive): Allow for more than one subdir in the build process. (info-recursive, dvi-recursive, ps-recursive, html-recursive): New targets. Enter into doc/ to produce the targets. (all-am): $(INFO_DEPS) replaced by info. 2009-09-26 Paul Smith * read.c (record_files): Use free_ns() to free struct nameseq. (eval): Ditto. * rule.c (freerule): Use free_dep_chain(). * read.c (record_files): Free FILENAMES chain for implicit rules. (eval): Static pattern targets go into the string cache. * function.c (string_glob): Free NAME in the nameseq chain. 2009-09-25 Boris Kolpackov * implicit.c (pattern_search): Terminate early if we haven't found any rules to try (performance improvement). 2009-09-25 Boris Kolpackov * implicit.c (pattern_search): Merge three parallel arrays, TRYRULES, MATCHES, and CHECKED_LASTSLASH, into one array of struct TRYRULE. In the old version the latter two arrays had insufficient length. 2009-09-24 Paul Smith * implicit.c (pattern_search): Add back support for order-only prerequisites for secondary expansion implicit rules, that were accidentally dropped. If we find a "|", enable order-only mode and set IGNORE_MTIME on all deps that are seen afterward. (pattern_search): Fix memory leaks: for intermediate files where we've already set the file variable and pattern variable sets, be sure to either save or free them as appropriate. 2009-09-23 Paul Smith Rework the way secondary expansion is stored, for efficiency. This changes secondary expansion so that ONLY WHEN we know we have a possibility of needing secondary expansion, do we defer the secondary expansion. This means more parsing the deps but we use a lot less memory (due to the strcache). Also, this fixes Savannah bug #18622. * read.c (eval): Don't parse the dep string here anymore. (record_files): Take the dep argument as an unparsed string. If secondary expansion is enabled AND the prereq string has a '$' in it, then set NEED_2ND_EXPANSION and keep the entire string. Otherwise, parse the dep string here to construct the dep list with the names in the strcache. * misc.c (copy_dep_chain): For NEED_2ND_EXPANSION, we need to duplicate the name string (others are in the strcache). * implicit.c: Remove struct idep and free_idep_chain(): unused. (struct patdeps): New structure to store prereq information. (pattern_search): Use the NEED_2ND_EXPANSION flag to determine which prerequisites need expansion, and expand only those. * file.c (split_prereqs): Break parse_prereqs() into two parts: this and enter_prereqs(). split_prereqs() takes a fully-expanded string and splits it into a DEP list, handling order-only prereqs. (enter_prereqs): This function enters a list of DEPs into the file database. If there's a stem defined, expand any pattern chars. (expand_deps): Only try to expand DEPs which have NEED_2ND_EXPANSION set. Use the above functions. (snap_deps): Only perform second expansion on prereqs that need it, as defined by the NEED_2ND_EXPANSION flag. (print_prereqs): New function to print the prereqs (print_file): Call print_prereqs() rather than print inline. * hash.h (STRING_COMPARE): Take advantage of strcache() by comparing pointers. (STRING_N_COMPARE): Ditto. (ISTRING_COMPARE): Ditto. * dep.h (PARSE_FILE_SEQ): New macro to reduce casts. (parse_file_seq): Return void* * read.c (parse_file_seq): Return void*. (eval): Invoke macroized version of parse_file_seq() * default.c (set_default_suffixes): Ditto. * file.c (split_prereqs): Ditto. * function.c (string_glob): Ditto. * main.c (main): Ditto. * rule.c (install_pattern_rule): Ditto. * filedef.h: Add split_prereqs(), enter_prereqs(), etc. 2009-09-16 Paul Smith * misc.c (alloc_dep, free_dep): Now that we have xcalloc(), convert to macros. * dep.h: Create alloc_dep() / free_dep() macros. * implicit.c (pattern_search): Take advantage of the new parse_file_seq() to add the directory prefix to each prereq. * dep.h: Remove multi_glob() and enhance parse_file_seq() to do it all. Avoid reversing chains. Support adding prefixes. * read.c (parse_file_seq): Rewrite to support globbing. Allow for cached/non-cached results. (eval): Remove multi_glob() & invoke new parse_file_seq(). * rule.c (install_pattern_rule): Ditto. * main.c (main): Ditto. * implicit.c (pattern_search): Ditto. * function.c (string_glob): Ditto. * file.c (parse_prereqs): Ditto. * default.c (set_default_suffixes): Ditto. * variable.c (parse_variable_definition): Don't run off the end of the string if it ends in whitespace (found with valgrind). * commands.c (set_file_variables): Keep space for all targets in $? if -B is given (found with valgrind). 2009-09-15 Paul Smith * misc.c (concat): Make concat() variadic so it takes >3 arguments. (xcalloc): Add new function. * make.h: New declarations. * ar.c (ar_glob_match): New calling method for concat(). * main.c (main): Ditto. (decode_env_switches): Ditto. * read.c (eval_makefile): Ditto. (tilde_expand): Ditto. (parse_file_seq): Ditto. * variable.c (target_environment): Ditto. (sync_Path_environment): Ditto. * ar.c (ar_glob_match): Use xcalloc(). * dir.c (file_impossible): Ditto. * file.c (enter_file): Ditto. * job.c (new_job): Ditto. * read.c (parse_file_seq): Ditto. * vmsfunctions.c (opendir): Ditto. 2009-09-14 Rafi Einstein (tiny patch) * w32/subproc/sub_proc.c (process_begin): Check *ep non-NULL inside the loop that looks up environment for PATH. 2009-08-31 Eli Zaretskii * function.c (windows32_openpipe): Update envp after calling sync_Path_environment. 2009-08-02 Paul Smith * remake.c (notice_finished_file): Ensure file->cmds is not null before looping through them. Fixes Savannah bug #21824. * doc/make.texi (Wildcard Examples): Clarify when objects is wildcard-expanded. Fixes Savannah bug #24509. Patch by Martin Dorey. (Include): Clarify the behavior of -include. Fixes Savannah bug #18963. 2009-08-01 Paul Smith * doc/make.texi (Catalogue of Rules): Clarify where -c, -F, etc. come on the command line. Fixes Savannah bug #27093. * expand.c (expand_argument): If the argument is large enough use xmalloc() instead of alloca(). Fixes Savannah bug #27143. * variable.c (do_variable_definition): Avoid using alloca() to hold values, which can be large. Fixes Savannah bug #23960. * job.c (new_job): Use memmove() instead of strcpy() since both pointers are in the same memory block. Fixes Savannah bug #27148. Patch by Petr Machata. 2009-07-29 Ralf Wildenhues * job.c (construct_command_argv_internal): Add "ulimit" and "unset" to the sh_cmds for Unixy shells. 2009-07-29 Ralf Wildenhues * configure.in: Move side-effects outside AC_CACHE_VAL arguments that set make_cv_sys_gnu_glob, so they are also correctly set when the cache has been populated before. 2009-07-04 Eli Zaretskii * function.c (func_realpath) [!HAVE_REALPATH]: Require the file to exist, as realpath(3) does where it's supported. 2006-07-04 Eli Zaretskii * function.c (IS_ABSOLUTE, ROOT_LEN): New macros. (abspath): Support systems that define HAVE_DOS_PATHS (have drive letters in their file names). Use IS_PATHSEP instead of a literal '/' comparison. Fixes Savannah bug #26886. 2009-06-14 Paul Smith * remake.c (update_file_1): Remember the original file we marked as updating, so we can clear that flag again. If we find a target via vpath, FILE might change. (check_dep): Ditto. Fixes Savannah bug #13529. Patch by Reid Madsen . 2009-06-13 Paul Smith * doc/make.texi (MAKEFILES Variable): Be explicit that files included by MAKEFILES cannot give default goals. * read.c (eval): If set_default is not set, pass the no-default-goal value when we read included makefiles. Fixes Savannah bug #13401. * ar.c (ar_name): Ensure that targets with empty parens aren't considered archive member references: archive members must have a non-empty "member" string. Fixes Savannah bug #18435. * function.c (string_glob): Rely on multi_glob() to determine whether files exist or not. Remove call to file_exists_p() which is not always correct. Fixes Savannah bug #21231. * read.c (multi_glob): Add a new argument EXISTS_ONLY; if true then only files that really exist will be returned. * dep.h: Add new argument to multi_glob(). * rule.c (install_pattern_rule): Ditto. * read.c (eval): Ditto. * main.c (main): Ditto. * implicit.c (pattern_search): Ditto. * file.c (parse_prereqs): Ditto. * default.c (set_default_suffixes): Ditto. 2009-06-09 Paul Smith * commands.c (set_file_variables): If always_make_flag is set, always add the prereq to $?. Fixes Savannah bug #17825. * remake.c (update_file_1): When rebuilding deps of FILE, also try to rebuild the deps of all the also_make targets for that file. Fixes Savannah bug #19108. * implicit.c (pattern_search): Undo test for is_target, added by BorisK on 21 Sep 2004. This goes against step 5c in the "Implicit Rule Search Algorithm". Fixes Savannah bug #17752. * main.c (clean_jobserver): Clear the jobserver_fds options and set job_slots to the default when we clean up. (define_makeflags): Return the new MAKEFLAGS value. (main): Reset MAKEFLAGS in the environment when we re-exec. Fixes Savannah bug #18124. 2009-06-08 Paul Smith * read.c (eval): Collapse continuations post-semicolon on target- specific variables. Fixes Savannah bug #17521. 2009-06-07 Paul Smith * job.c (reap_children): For older systems without waitpid() (are there any of these left?) run wait(2) inside EINTRLOOP to handle EINTR errors. Fixes Savannah bug #16401. * (various): Debug message cleanup. Fixes Savannah bug #16469. * main.c: Fix bsd_signal() typedef. Fixes Savannah bug #16473. * file.c (snap_deps): Set SNAPPED_DEPS at the start of snapping, not the end, to catch second expansion $(eval ...) defining new target/prereq relationships during snap_deps. Fixes Savannah bug #24622. * read.c (record_files): The second-expansion "f->updating" hack was not completely correct: if assumed that the target with commands always had prerequisites; if one didn't then the ordering was messed up. Fixed for now to use f->updating to decide whether to preserve the last element in the deps list... but this whole area of constructing and reversing the deps list is too confusing and needs to be reworked. Fixes Savannah bug #21198. 2009-06-06 Paul Smith * hash.c (hash_insert): Remove useless test for NULL. Fixes Savannah bug #21823. * make.h: Move SET_STACK_SIZE determination to make.h. * main.c (main): New global variable, STACK_LIMIT, holds the original stack limit when make was started. * job.c (start_job_command): Reset the stack limit, if we changed it. Fixes Savannah bug #22010. * remake.c (check_dep): Only set the target's state to not-started if it's not already running. Found this while testing -j10 builds of glibc: various targets were being rebuilt multiple times. Fix from Knut St. Osmundsen; fixes a problem reported in Savannah bug #15919. * read.c (multi_glob): Don't pass GLOB_NOCHECK to glob(3); instead handle the GLOB_NOMATCH error. This is to work around Sourceware.org Bugzilla bug 10246. 2009-06-04 Paul Smith * read.c (eval): Skip initial whitespace (ffeed, vtab, etc.) * maintMakefile: Modify access of config and gnulib Savannah modules to use GIT instead of CVS. * main.c (main): Initialize the LENGTH field in SHELL_VAR. Fixes Savannah bug #24655. * read.c (eval_buffer): Don't dereference reading_file if it's NULL; this can happen during some invocations of $(eval ...) for example. Fixes Savannah bug #24588. Patch by Lars Jessen 2009-06-02 Paul Smith * configure.in: Check for fileno() * read.c (eval_makefile): If fileno() is available, set CLOSE_ON_EXEC for the makefile file so invocations of $(shell ...) don't inherit it. Fixes Savannah bug #24277. 2009-06-01 Paul Smith * main.c (main): The previous fix for .DEFAULT_GOAL had issues; expansion was handled incorrectly. Rework the default goal handling to save the variable only. Remove default_goal_file and default_goal_name. * read.c (eval): Check default_goal_var, not default_goal_name. * read.c (record_target_var): Don't check default_goal_file here. 2009-05-31 Paul Smith * main.c (main): Expand the .DEFAULT_GOAL variable before using it, and if the multi_glob() returns nothing (say it expanded to nothing but spaces) then don't crash. Fixes Savannah bug #25697. * doc/make.texi (Quick Reference): Add $(if ..), $(or ..), and $(and ..) to the reference. Fixes Savannah bug #25694. * make.1: Be clear that some recipes will be executed even with -n. * doc/make.texi: Ditto. Fixes Savannah bug #25460. * doc/make.texi (Override Directive): Make more clear how overrides and appends interact. Elucidates part of Savannah bug #26207. * read.c (record_target_var): Don't reset the origin on target-specific variables; try_variable_definition() will handle this correctly. Fixes Savannah bug #26207. * maintMakefile (do-po-update): Copy PO files into $(top_srcdir). Fixes Savannah bug #25712. * implicit.c (pattern_search): Keep a pointer to the beginning of the filename and save that instead of the constructed pointer. Fixes Savannah bug #26593. Patch by Mark Seaborn 2009-05-30 Paul Smith * doc/make.texi (Multi-Line): Add a description of the new abilities of define/endef. Rename "Sequences" to "Multi-Line" and fix some "command sequence" vs. "recipe" syntax. * read.c (do_define): Modify to allow assignment tokens (=, :=, etc.) after a define, to create variables with those flavors. 2009-05-25 Paul Smith Reworked the parser for variable assignments to allow multiple modifiers, and in any order. Also allows variable and prerequisites to be modifier names ('export', 'private', etc.) * NEWS: Add notes about user-visible changes. * read.c (struct vmodifiers): Remember what modifiers were seen. (parse_var_assignment): New function to parse variable assignments. (eval): Call the new function. Handle variable assignments earlier. * variable.c (parse_variable_definition): Only parse; don't create var. (assign_variable_definition): Call parse, then create the var. 2009-05-24 Paul Smith * doc/make.texi: Fix the ISBN for the GNU make manual. Incorrect value noticed by Hans Stol . 2009-03-14 Eli Zaretskii * w32/pathstuff.c (convert_Path_to_windows32): Fix last change. Fixes Savannah bug #25412. * w32/subproc/sub_proc.c : Update Copyright years. Add prototype for xmalloc. (find_file): Accept 3 arguments PATH_VAR, FULL_FNAME, and FULL_LEN instead of an LPOFSTRUCT pointer. Use xmalloc instead of malloc. Loop over an array of extensions, instead of duplicating the same code inline. Use SearchPath followed by CreateFile, instead of the obsolete OpenFile. Fixes Savannah bug #17277. (process_begin): Find $(PATH) in `envp', and pass a pointer to it to `find_file'. Fixes Savannah bug #25662. 2009-03-07 Eli Zaretskii * function.c (func_shell): Don't close pipedes[1] if it is -1. Fixes Savannah bug #20495. 2009-02-28 Ralf Wildenhues * doc/make.texi (Instead of Execution): Document interaction of -t with phony targets. 2009-02-23 Ramon Garcia Introduce a new keyword "private" which applies to target-specific variables and prevents their values from being inherited. * variable.h (struct variable): Add private_var flag to each variable. Add a flag to specify which list entry switches to the parent target. * variable.c (define_variable_in_set): Initialize private_var flag. (lookup_variable): Skip private variables in parent contexts. (initialize_file_variables): Set next_is_parent appropriately. (print_variable): Show the private_var flag. * read.c (eval): Recognize the private keyword. (record_target_var): Set private_var. * doc/make.texi (Suppressing Inheritance): Add documentation. 2008-10-26 Paul Smith * configure.in: Check for strndup(). * misc.c (xstrndup): Rename savestring to xstrndup. Use strndup if it's available. * make.h: Rename savestring to xstrndup. * commands.c (chop_commands): Ditto. * function.c (func_foreach): Ditto. * read.c (eval, record_files): Ditto. * variable.c (define_variable_in_set): Ditto. 2008-09-30 Eli Zaretskii * build_w32.bat (GCCBuild): Use "-gdwarf-2 -g3" instead of "-gstabs+ -ggdb3". * w32/subproc/build.bat (GCCBuild): Likewise. 2008-09-30 David Russo (tiny change) * job.c (construct_command_argv_internal): Avoid extra backslash in batch-mode Unixy shells. Under DB_JOBS, display the contents of the batch file. 2008-05-31 Eli Zaretskii * README.W32.template: Remove obsolete text about non-support for -jN without Unixy shell. Remove obsolete text about not supplying Visual Studio project files (we do supply them). Modify text to prefer GCC builds to MSC builds. 2008-04-02 Ralf Wildenhues * doc/make.texi (Empty Targets): Fix typo. 2008-03-27 Paul Smith Fix Savannah bug #22379: * ar.c (ar_glob_match): Zero the allocated structure. * read.c (parse_file_seq): Ditto. 2008-03-08 Brian Dessent * maintMakefile: Update Translation Project location. 2008-01-26 Eli Zaretskii * variable.c (target_environment): Don't use shell_var if its `value' field is NULL. 2007-12-22 Eli Zaretskii Suggested by Juan Manuel Guerrero : * Makefile.DOS.template (info_TEXINFOS): Remove unused variable. (TEXINFOS): Value changed to `doc/make.texi'. (.SUFFIXES): Use .texi instead of .texinfo. (make.info, make.dvi): Depend on doc/make.texi. (.texi.info): New target, instead of ".texinfo.info". Change -I switch to $(MAKEINFO) to look in doc/. Use --no-split. (.texi): New target, instead of ".texinfo". Change -I switch to $(MAKEINFO) to look in doc/. Use --no-split. (.texi.dvi): New target, instead of ".texinfo.dvi". Change -I switch to $(MAKEINFO) to look in doc/. (install-info-am, uninstall-info): Don't look for "*.i[0-9]" and "*.i[0-9][0-9]" (due to --no-split above). (noinst_TEXINFOS, TEXI2HTML, TEXI2HTML_FLAGS): New variables. (html, make_1.html): New targets. (.PHONY): Add "html". (.SUFFIXES): Add .html. 2007-12-22 Juan Manuel Guerrero (tiny change) * configh.dos.template [__DJGPP__]: Replace HAVE_SYS_SIGLIST with HAVE_DECL_SYS_SIGLIST. * job.c (child_execute_job): Remove __MSDOS__ because MSDOS/DJGPP build does not use child_execute_job. * variable.c (define_automatic_variables) [__MSDOS__]: Always export the SHELL environment variable to the child. 2007-12-22 Eli Zaretskii * config.h.W32: Include sys/types.h. [!_PID_T_] (pid_t): Define only if not already defined by sys/types.h. * vpath.c (construct_vpath_list) [HAVE_DOS_PATHS]: Support VPATH values that use `:' in drive letters, when PATH_SEPARATOR_CHAR is also `:'. 2007-11-04 Paul Smith * doc/make.texi: Convert references to "commands", "command lines", and "command script" to "recipe". * NEWS: Ditto. * commands.c, file.c, job.c, remake.c, read.c, variable.c, main.c: Ditto. 2007-10-27 Bruno Haible * remake.c (f_mtime): Print time difference values between 100 and ULONG_MAX in fixed-point notation rather than in exponention notation. 2007-10-12 Eli Zaretskii * variable.c (do_variable_definition): Allow $(SHELL) to expand to a more complex value than a simple shell: if it's not a default shell now then expand it and see if is a default shell then. 2007-10-10 Eli Zaretskii * dir.c (find_directory) [WINDOWS32]: Remove trailing slashes from pathnames, with const strings. * build_w32.bat [WINDOWS32]: If no config.h.W32 exists, create one from the template (used for building from CVS, not a dist). 2007-10-10 Paul Smith * make.h: Add a prototype for w32_kill() (change suggested by Yongwei Wu ). 2007-09-21 Eli Zaretskii * w32/pathstuff.c (convert_Path_to_windows32): Handle quoted directories in Path. 2007-09-12 Paul Smith * doc/make.texi: Applied wording cleanups from Savannah patch #6195. Provided by Diego Biurrun (Complex Makefile): Remove .PHONY setting for tar: patch #6196. Provided by Diego Biurrun 2007-09-11 Paul Smith * doc/make.texi (Special Variables): Moved this into the "How to Use Variables" chapter. Added a table entry for .RECIPEPREFIX. (MAKEFILE_LIST) No longer a section; this was added into the "Special Variables" section. (Rule Introduction): Reference .RECIPEPREFIX. (Simple Makefile): Ditto. (Rule Syntax): Ditto. (Command Syntax): Ditto. (Error Messages): Ditto. 2007-09-10 Paul Smith * commands.c (print_commands): Don't print an extra line in the command scripts. Prefix the command scripts with cmd_prefix, not \t. * read.c (construct_include_path): Add the full string to the cache; we were chopping the last char. * NEWS: Announce the .RECIPEPREFIX special variable. * variable.c (lookup_special_var): Rename from handle_special_var(). (lookup_variable): Call the new name. (set_special_var): New function: handle setting of special variables. When setting .RECIPEPREFIX, reset the cmd_prefix global variable. (do_variable_definition): Call it. * make.h (RECIPEPREFIX_DEFAULT): Define the default command prefix char. (RECIPEPREFIX_NAME): Define the command prefix special variable name. * main.c (main): Create the .RECIPEPREFIX special variable. * read.c (eval): Remove the cmd_prefix characters from the command scripts here, so they're not stored in the commands array at all, rather than waiting and stripping them out during command construction. * job.c (construct_command_argv_internal): Don't skip cmd_prefix here. 2007-08-15 Paul Smith * doc/make.texi (GNU Free Documentation License): The fdl.texi file has had the section info removed, so add some to make.texi before we include it. 2007-08-15 Icarus Sparry * remake.c (check_dep): Reset the target state for intermediate files. They might have been considered before but not updated then (order-only for example) but they will be this time. Fixes Savannah bug #'s 3330 and 15919. 2007-07-21 Eli Zaretskii Fix Savannah bug #20549: * function.c (func_shell): Call construct_command_argv with zero value of FLAGS. * job.c (construct_command_argv_internal): New argument FLAGS; all callers changed. [WINDOWS32]: If FLAGS has the COMMANDS_RECURSE bit set, ignore just_print_flag. * job.h (construct_command_argv_internal): Update prototype. 2007-07-13 Paul Smith * file.c (expand_deps): Use variable_buffer as the start of the buffer, not the original pointer (in case it was reallocated). Fix suggested by Rafi Einstein . Fixes Savannah bug #20452. 2007-07-04 Paul Smith * (ALL FILES): Update to GPLv3. * (ALL FILES): Update copyright for 2007. * main.c (print_version): Move the host type info to the second line. 2007-06-29 Thiemo Seufer * maintMakefile: Update Translation Project location. 2007-06-13 Paul Smith * doc/make.texi (Reading Makefiles): "Expansion of deferred" -> "Expansion of a deferred" Fixes Savannah bug #20018. * expand.c (variable_expand_for_file): Preserve the value of reading_file rather than setting it to 0 at the end. Fixes Savannah bug #20033. 2007-05-11 Paul Smith * job.c (new_job): Add debug info to specify where make found the command script it is running to build a target. Fixes Savannah bug #18617. * default.c (default_suffixes,default_suffix_rules,default_variables): Add support for Objective C. Fixes Savannah bug #16389. Based on a patch provided by Peter O'Gorman . * function.c (func_lastword): Initialize p. * doc/make.texi (Eval Function, Implicit Variables, Special Targets): Doc fixes noticed by Bob . Patch from Dave Korn 2007-05-08 Paul Smith Fix Savannah bug #19656: * configure.in: Check for strcasecmp(), strcmpi(), and stricmp(). * make.h: Change all case-insensitive string compares to use strcasecmp() (from POSIX). If we don't have that but do have one of the others, define strcasecmp to be one of those instead. If we don't have any, declare a prototype for our own version. * misc.c (strcasecmp): Use this if we can't find any native case-insensitive string comparison function. * vmsfunctions.c: Remove strcmpi(); we'll use misc.c:strcasecmp(). * main.c (find_and_set_default_shell): Use strcasecmp() instead of strcmpi(). * job.c (_is_unixy_shell, construct_command_argv_internal): Use strcasecmp() instead of stricmp(). * hash.h (ISTRING_COMPARE, return_ISTRING_COMPARE): Use strcasecmp() instead of strcmpi(). * acinclude.m4: Remove the strcasecmp() check from here. 2007-03-21 Paul Smith * configure.in: Don't turn on case-insensitive file system support if --disable-... is given. Fixes Savannah bug #19348. 2007-03-19 Paul Smith * ALL: Use the strcache for all file name strings, or other strings which we will never free. The goal is to save memory by avoiding duplicate copies of strings. However, at the moment this doesn't save much memory in most situations: due to secondary expansion we actually save prerequisite lists twice (once before the secondary expansion, and then again after it's been parsed into individual file names in the dep list). We will resolve this in a future change, by doing the parsing up-front for targets where secondary expansion is not set. Moving things into the strcache also allows us to use const pointers in many more places. 2007-01-03 Paul Smith * make.h (ENULLLOOP): Reset errno after each failed invocation of the function, not just the first. Fixes Savannah bug #18680. 2006-11-18 Paul Smith * strcache.c (strcache_add_len): Don't allocate a new buffer unless the string is not already nil-terminated. Technically this is a violation of the standard, since we may be passed an array that is not long enough to test one past. However, in make this is never true since we only use nil-terminated strings or sub-strings thereof. * read.c (eval, do_define): Use cmd_prefix instead of '\t'. * main.c: New global cmd_prefix, defaults to '\t'. * job.c (construct_command_argv_internal): Use cmd_prefix instead of '\t'. * dir.c: Constified. (dir_contents_file_exists_p): Check for an error return from readdir(), just in case. * commands.c: Constified. * default.c: Constified. * expand.c: Constified. * function.c: Partial constification. * variable.c: Partial constification. * vmsify.c: Constification. Hard to test this but I hope I didn't screw it up! * vpath.c: Partial constification. * w32/pathstuff.c: Partial constification. 2006-11-16 Eli Zaretskii * main.c (main) [HAVE_DOS_PATHS]: Treat DOS style argv[0] with backslashes and drive letters as absolute. 2006-10-22 Paul Smith * main.c (struct command_switch): Use const and void*. 2006-10-21 Paul Smith * ar.c: Constified. * arscan.c: Constified. 2006-09-30 Paul Smith * doc/make.texi (MAKEFILE_LIST Variable): Modify reference to point to lastword since the example was updated. Fixes Savannah bug #16304. (Secondary Expansion): Correct example description. Fixes Savannah bug #16468. (Makefile Contents): Clarify that comments cannot appear within variable references or function calls. Fixes Savannah bug #16577. (Special Targets): Clarify how .NOTPARALLEL works in recursion. Fixes Savannah bug #17701. Reported by Ralf Wildenhues : (Prerequisite Types): Added an example of using order-only prerequisites. Fixes Savannah bug #17880. (Rule Syntax): "lise" -> "list" (Multiple Rules): ... -> @dots{} (Splitting Lines): ditto. * remake.c (update_file_1): Prereqs that don't exist should be considered changed, for the purposes of $?. Fixes Savannah bug #16051. * make.1: Remove extraneous "+". Fixes Savannah bug #16652. 2006-09-06 Paul D. Smith * configure.in: Include sys/types.h when checking for sys/wait.h. 2006-08-18 Eli Zaretskii * configure.in (PATH_SEPARATOR_CHAR): Define to the value of $PATH_SEPARATOR. * make.h (PATH_SEPARATOR_CHAR): Define only if still undefined. Normally, it is defined in config.h. * config/dospaths.m4 : Define to yes on Cygwin as well. * job.c (construct_command_argv_internal) [HAVE_DOS_PATHS]: Define sh_chars_sh for Windows platforms that emulate Unix. 2006-05-07 Paul D. Smith * README.OS2.template: Updates provided by Andreas Buening . 2006-04-30 Paul D. Smith * make.h: Include if HAVE_DIRECT_H. * config.h.W32.template (HAVE_DIRECT_H): Set it if it's available. 2006-04-26 Paul D. Smith * README.cvs: Add a reminder to notify the GNU translation robot. * doc/make.texi: Change @direcategory (requested by Karl Berry). 2006-04-20 Paul D. Smith * maintMakefile (po-check): Use Perl instead of grep -E, for systems that don't have extended grep. (cvsclean): Use $(PERL) instead of perl. 2006-04-09 Paul D. Smith * maintMakefile: Add some extra warning options (GCC 4.1 only?) * expand.c, implicit.c, main.c, read.c: Rename variables so that inner-scope variables don't mask outer-scope variables. * ar.c, arscan.c, commands.c, default.c, dir.c, expand.c, file.c: * function.c, getloadavg.c, implicit.c, job.c, main.c, misc.c, read.c: * remake.c, remote-cstms.c, rule.c, strcache.c, variable.c: * vmsfunctions.c, vmsify.c, vpath.c: Remove all casts of returned values from memory allocation functions: they return void* and so don't need to be cast. Also remove (char *) casts of arguments to xrealloc(). * configure.in: Remove checks for memcpy/memmove/strchr. * make.h: Remove bcmp/bcopy/bzero/strchr/strrchr macros. * ar.c, arscan.c, commands.c, dir.c: Convert all bzero/bcopy/bcmp calls to memset/memcpy/memmove/memcmp calls. * expand.c, file.c, function.c, getloadavg.c, implicit.c: Ditto. * job.c, main.c, misc.c, read.c, remake.c, rule.c: Ditto. * variable.c, vpath.c: Ditto. * make.h (EXIT_FAILURE): Should be 1, not 0. 2006-04-06 Paul D. Smith * configure.in: Removed AM_C_PROTOTYPES. Starting now on we require an ISO C 1989 standard compiler and runtime library. * Makefile.am: Remove the ansi2knr feature. * make.h: Remove the PARAMS() macro definition and all uses of it. * amiga.h, ar.c, arscan.c: Remove all uses of the PARAMS() macro. * commands.c, commands.h, config.h-vms.template: Ditto. * dep.h, dir.c, expand.c, filedef.h, function.c: Ditto. * implicit.c, job.c, job.h, main.c, read.c, remake.c: Ditto. * rule.c, rule.h, variable.h, vmsdir.h, vmsjobs.c, vpath.c: Ditto. * NEWS: Update. 2006-04-01 Paul D. Smith Version 3.81 released. * NEWS: Updated for 3.81. * README.cvs: Mention that vpath builds are not supported out of CVS. Fixes Savannah bug #16236. Remove update of make.texi from the list of things to do; we use version.texi now. 2006-03-26 Paul D. Smith * doc/make.texi: Clean up licensing. Use @copying and version.texi support from automake, as described in the Texinfo manual. 2006-03-25 Eli Zaretskii * implicit.c (pattern_search) [HAVE_DOS_PATHS]: Don't compare b with lastslash, since the latter points to filename, not to target. * job.c (construct_command_argv_internal) [HAVE_DOS_PATHS]: Declare and define sh_chars_sh[]. 2006-03-23 Paul D. Smith * configure.in: Look for build.sh.in in $srcdir so it will be built for remote configurations as well. * Makefile.am: Make sure to clean up build.sh during distclean. Fixes Savannah bug #16166. * misc.c (log_access): Takes a const char *. * function.c (fold_newlines): Takes an unsigned int *. Both fixes for Savannah bug #16170. 2006-03-22 Boris Kolpackov * implicit.c (pattern_search): Call set_file_variables only if we have prerequisites that need second expansion. Fixes Savannah bug #16140. 2006-03-19 Paul D. Smith * remake.c (update_file): Add alloca(0) to clean up alloca'd memory on hosts that don't support it directly. * README.cvs: Add information on steps for making a release (to make sure I don't forget any). * main.c (clean_jobserver): Move jobserver cleanup code into a new function. (die): Cleanup code was removed from here; call the new function. (main): If we are re-execing, clean up the jobserver first so we don't leak file descriptors. Reported by Craig Fithian 2006-03-17 Paul D. Smith * maintMakefile (do-po-update): Rewrite this rule to clean up and allow multiple concurrent runs. Patch from Joseph Myers 2006-03-17 Boris Kolpackov * dep.h (struct dep): Add the stem field. * misc.c (alloc_dep, free_dep): New functions. (copy_dep_chain): Copy stem. (free_dep_chain): Use free_dep. * read.c (record_files): Store stem in the dependency line. * file.c (expand_deps): Use stem stored in the dependency line. Use free_dep_chain instead of free_ns_chain. * implicit.c (pattern_search): Use alloc_dep and free_dep. * read.c (read_all_makefiles, eval_makefile, eval): Ditto. * main.c (main, handle_non_switch_argument): Ditto. * remake.c (check_dep): Ditto. * rule.c (convert_suffix_rule, freerule): Ditto. 2006-03-14 Paul D. Smith * expand.c (variable_append): Instead of appending everything then expanding the result, we expand (or not, if it's simple) each part as we add it. (allocated_variable_append): Don't expand the final result. Fixes Savannah bug #15913. 2006-03-09 Paul Smith * remake.c (update_file_1): Revert the change of 3 Jan 2006 which listed non-existent files as changed. Turns out there's a bug in the Linux kernel builds which means that this change causes everything to rebuild every time. We will re-introduce this fix in the next release, to give them time to fix their build system. Fixes Savannah bug #16002. Introduces Savannah bug #16051. * implicit.c (pattern_search) [DOS_PATHS]: Look for DOS paths if we *don't* find UNIX "/". Reported by David Ergo 2006-03-04 Eli Zaretskii * variable.c (do_variable_definition) [WINDOWS32]: Call the shell locator function find_and_set_default_shell if SHELL came from the command line. 2006-02-20 Paul D. Smith * variable.c (merge_variable_set_lists): It's legal for *setlist0 to be null; don't core in that case. 2006-02-19 Paul D. Smith * commands.c (set_file_variables): Realloc, not malloc, the static string values to avoid memory leaks. * expand.c (recursively_expand_for_file): Only set reading_file to an initialized value. * implicit.c (pattern_search): We need to make a copy of the stem if we get it from an intermediate dep, since those get freed. * file.c (lookup_file) [VMS]: Don't lowercase special targets that begin with ".". (enter_file) [VMS]: Ditto. Patch provided by Hartmut Becker . 2006-02-24 Eli Zaretskii * job.c (construct_command_argv_internal): Fix last change. * w32/subproc/sub_proc.c (process_pipe_io): Make dwStdin, dwStdout, and dwStderr unsigned int: avoids compiler warnings in the calls to _beginthreadex. * expand.c (recursively_expand_for_file): Initialize `save' to prevent compiler warnings. 2006-02-18 Eli Zaretskii * job.c (construct_command_argv_internal): Don't create a temporary script/batch file if we are under -n. Call _setmode to switch the script file stream to text mode. 2006-02-17 Paul D. Smith * variable.c (merge_variable_set_lists): Don't try to merge the global_setlist. Not only is this useless, but it can lead to circularities in the linked list, if global_setlist->next in one list gets set to point to another list which also ends in global_setlist. Fixes Savannah bug #15757. 2006-02-15 Paul D. Smith Fix for Savannah bug #106. * expand.c (expanding_var): Keep track of which variable we're expanding. If no variable is being expanded, it's the same as reading_file. * make.h (expanding_var): Declare it. * expand.c (recursively_expand_for_file): Set expanding_var to the current variable we're expanding, unless there's no file info in it (could happen if it comes from the command line or a default variable). Restore it before we exit. * expand.c (variable_expand_string): Use the expanding_var file info instead of the reading_file info. * function.c (check_numeric): Ditto. (func_word): Ditto. (func_wordlist): Ditto. (func_error): Ditto. (expand_builtin_function): Ditto. (handle_function): Ditto. 2006-02-14 Paul D. Smith * read.c (eval): Even if the included filenames expands to the empty string we still need to free the allocated buffer. * implicit.c (pattern_search): If we allocated a variable set for an impossible file, free it. * variable.c (free_variable_set): New function. * variable.h: Declare it. * read.c (read_all_makefiles): Makefile names are kept in the strcache, so there's never any need to alloc/free them. (eval): Ditto. * main.c (main): Add "archives" to the .FEATURES variable if archive support is enabled. * doc/make.texi (Special Variables): Document it. 2006-02-13 Paul D. Smith * implicit.c (pattern_search): Add checking for DOS pathnames to the pattern rule target LASTSLASH manipulation. Fixes Savannah bug #11183. 2006-02-11 Paul D. Smith * (ALL FILES): Updated copyright and license notices. 2006-02-10 Paul D. Smith A new internal capability: the string cache is a read-only cache of strings, with a hash table interface for fast lookup. Nothing in the cache will ever be freed, so there's no need for reference counting, etc. This is the beginning of a full solution for Savannah bug #15182, but for now we only store makefile names here. * strcache.c: New file. Implement a read-only string cache. * make.h: Add prototypes for new functions. * main.c (initialize_global_hash_tables): Initialize the string cache. (print_data_base): Print string cache stats. * read.c (eval_makefile): Use the string cache to store makefile names. Rewrite the string allocation to be sure we free everything. 2006-02-10 Eli Zaretskii * dir.c (dir_contents_file_exists_p): Don't opendir if the directory time stamp didn't change, except on FAT filesystems. Suggested by J. David Bryan . 2006-02-09 Paul D. Smith * function.c (func_or): Implement a short-circuiting OR function. (func_and): Implement a short-circuiting AND function. (function_table_init): Update the table with the new functions. * doc/make.texi (Conditional Functions): Changed the "if" section to one on general conditional functions. Added documentation for $(and ...) and $(or ...) functions. * NEWS: Note new $(and ...) and $(or ...) functions. 2006-02-08 Boris Kolpackov * job.h (struct child): Add the dontcare bitfield. * job.c (new_job): Cache dontcare flag. * job.c (reap_children): Use cached dontcare flag instead of the one in struct file. Fixes Savannah bug #15641. 2006-02-06 Paul D. Smith * vpath.c (selective_vpath_search): If the file we find has a timestamp from -o or -W, use that instead of the real time. * remake.c (f_mtime): If the mtime is a special token from -o or -W, don't overwrite it with the real mtime. Fixes Savannah bug #15341. Updates from Markus Mauhart : * w32/subproc/sub_proc.c (process_begin): Remove no-op tests. (process_signal, process_last_err, process_exit_code): Manage invalid handle values. (process_{outbuf,errbuf,outcnt,errcnt,pipes}): Unused and don't manage invalid handles; remove them. * job.c (start_job_command) [WINDOWS32]: Jump out on error. * config.h.W32.template [WINDOWS32]: Set flags for Windows builds. * README.cvs: Updates for building from CVS. 2006-02-05 Paul D. Smith * file.c (enter_file): Keep track of the last double_colon entry, to avoid walking the list every time we want to add a new one. Fixes Savannah bug #15533. * filedef.h (struct file): Add a new LAST pointer. * dir.c (directory_contents_hash_cmp): Don't use subtraction to do the comparison. For 64-bits systems the result of the subtraction might not fit into an int. Use comparison instead. Fixes Savannah bug #15534. * doc/make.texi: Update the chapter on writing commands to reflect the changes made in 3.81 for backslash/newline and SHELL handling. 2006-02-01 Paul D. Smith * dir.c (dir_contents_file_exists_p) [WINDOWS32]: Make sure variable st is not used when it's not initialized. Patch from Eli Zaretskii . 2006-01-31 Paul D. Smith * README.W32.template: Applied patch #4785 from Markus Mauhart . * README.cvs: Applied patch #4786 from Markus Mauhart . * make_msvc_net2003.vcproj [WINDOWS32]: New version from J. Grant . * main.c: Update the copyright year in the version output. * prepare_w32.bat: Remove this file from the distribution. 2006-01-21 Eli Zaretskii * remake.c (update_goal_chain): Set g->changed instead of incrementing it, as it is only 8-bit wide, and could overflow if many commands got started in update_file. * w32/include/sub_proc.h: Add a prototype for process_used_slots. * w32/subproc/sub_proc.c: Change dimension of proc_array[] to MAXIMUM_WAIT_OBJECTS. (process_wait_for_any_private): Change dimension of handles[] array to MAXIMUM_WAIT_OBJECTS. (process_used_slots): New function. (process_register): Don't register more processes than the available number of slots. (process_easy): Don't start new processes if all slots are used up. * job.c (load_too_high, start_waiting_jobs) [WINDOWS32]: If there are already more children than sub_proc.c can handle, behave as if the load were too high. (start_job_command): Fix a typo in error message when process_easy fails. 2006-01-14 Eli Zaretskii * main.c (main) [WINDOWS32]: Don't refuse to run with -jN, even if the shell is not sh.exe. * job.c (create_batch_file): Renamed from create_batch_filename; all callers changed. Don't close the temporary file; return its file descriptor instead. New arg FD allows to return the file descriptor. (construct_command_argv_internal): Use _fdopen instead of fopen to open the batch file. 2006-01-04 Paul D. Smith * readme.vms: Updates for case-insensitive VMS file systems from Hartmut Becker . * dir.c (vms_hash): Ditto. * vmsify.c (copyto): Ditto. * vmsfunctions.c (readdir): Ditto. * make.1: Add a section on the exit codes for make. * doc/make.texi: A number of minor updates to the documentation. 2006-01-03 Paul D. Smith * remake.c (update_file_1): Mark a prerequisite changed if it doesn't exist. * read.c (eval): Be sure to strip off trailing whitespace from the prerequisites list properly. Also, initialize all fields in struct dep when creating a new one. 2005-12-28 Paul D. Smith * config.h.W32.template [WINDOWS32]: Add in some pragmas to disable warnings for MSC. Patch by Rob Tulloh . 2005-12-17 Eli Zaretskii * doc/make.texi (Execution): Add a footnote about changes in handling of backslash-newline sequences. Mention the differences on MS-DOS and MS-Windows. * NEWS: More details about building the MinGW port and a pointer to README.W32. Fix the section name that describes the new backward-incompatible processing of backslash-newline sequences. The special processing of SHELL set to "cmd" is only relevant to MS-Windows, not MS-DOS. 2005-12-17 Eli Zaretskii * main.c (handle_runtime_exceptions): Cast exrec->ExceptionAddress to DWORD, to avoid compiler warnings. * job.c (exec_command): Cast hWaitPID and hPID to DWORD, and use %ld in format, to avoid compiler warnings. * doc/make.texi (Special Targets): Fix a typo. (Appending): Fix cross-reference to Setting. (Special Variables, Secondary Expansion, File Name Functions) (Flavor Function, Pattern Match, Quick Reference): Ensure two periods after a sentence. (Execution): Add @: after "e.g.". (Environment): Fix punctuation. (Target-specific, Call Function, Quick Reference): Add @: after "etc." (Shell Function, Target-specific): Add @: after "vs." 2005-12-14 Boris Kolpackov * read.c (record_target_var): Initialize variable's export field with v_default instead of leaving it "initialized" by whatever garbage happened to be on the heap. 2005-12-12 Paul D. Smith * make.1: Fix some display errors and document all existing options. Patch by Mike Frysinger . 2005-12-11 Paul D. Smith * implicit.c (pattern_search): If 2nd expansion is not set for this implicit rule, replace the pattern with the stem directly, and don't re-expand the variable list. Along with the other .SECONDEXPANSION changes below, fixes bug #13781. 2005-12-09 Boris Kolpackov * implicit.c (pattern_search): Mark other files that this rule builds as targets so that they are not treated as intermediates by the pattern rule search algorithm. Fixes bug #13022. 2005-12-07 Boris Kolpackov * remake.c (notice_finished_file): Propagate the change of modification time to all the double-colon entries only if it is the last one to be updated. Fixes bug #14334. 2005-11-17 Boris Kolpackov * function.c (func_flavor): Implement the flavor function which returns the flavor of a variable. * doc/make.texi (Functions for Transforming Text): Document it. * NEWS: Add it to the list of new functions. 2005-11-14 Boris Kolpackov * read.c (construct_include_path): Set the .INCLUDE_DIRS special variable. * doc/make.texi (Special Variables): Document .INCLUDE_DIRS. * NEWS: Add .INCLUDE_DIRS to the list of new special variables. 2005-10-26 Paul Smith * read.c (record_files): Don't set deps flags if there are no deps. * maintMakefile: We only need to build the templates when we are creating a distribution, so don't do it for "all". 2005-10-24 Paul D. Smith Make secondary expansion optional: its enabled by declaring the special target .SECONDEXPANSION. * NEWS: Update information on second expansion capabilities. * doc/make.texi (Secondary Expansion): Document the .SECONDEXPANSION special target and its behavior. * dep.h (struct dep): Add a flag STATICPATTERN, set to true if the prerequisite list was found in a static pattern rule. (free_dep_chain): Declare a prototype. * file.c (parse_prereqs): New function: break out some complexity from expand_deps(). (expand_deps): If we aren't doing second expansion, replace % with the stem for static pattern rules. Call the new function. * filedef.h (parse_prereqs): Declare a prototype. * implicit.c (pattern_search): Initialize the new staticpattern field. * main.c (second_expansion): Declare a global variable to remember if the special target has been seen. Initialize the new staticpattern field for prerequisites. * make.h: Extern for second_expansion. * misc.c (free_dep_chain): New function: frees a struct dep list. * read.c (read_all_makefiles): Initialize the staticpattern field. (eval_makefile): Ditto. (record_files): Check for the .SECONDEXPANSION target and set second_expansion global if it's found. Use the new free_dep_chain() instead of doing it by hand. Set the staticpattern field for prereqs of static pattern targets. 2005-10-16 Paul D. Smith * main.c (main): Set CURDIR to be a file variable instead of a default, so that values of CURDIR inherited from the environment won't override the make value. 2005-09-26 Paul D. Smith * job.c (construct_command_argv_internal): If the line is empty remember to free the temporary argv strings. Fixes bug # 14527. 2005-09-16 Paul D. Smith * job.c (start_job_command): The noerror flag is a boolean (single bit); set it appropriately. Reported by Mark Eichin 2005-08-29 Paul D. Smith * function.c (func_error): On Windows, output from $(info ...) seems to come in the wrong order. Try to force it with fflush(). 2005-08-10 Boris Kolpackov * read.c (record_files): Move code that sets stem for static pattern rules out of the if (!two_colon) condition so it is also executed for two-colon rules. Fixes Savannah bug #13881. 2005-08-08 Paul D. Smith * make.h: Don't test that __STDC__ is non-0. Some compilers (Windows for example) set it to 0 to denote "ISO C + extensions". Fixes bug # 13594. 2005-08-07 Paul D. Smith * w32/pathstuff.c (getcwd_fs): Fix warning about assignment in a conditional (slightly different version of a fix from Eli). Fix a bug reported by Michael Matz : patch included. If make is running in parallel without -k and two jobs die in a row, but not too close to each other, then make will quit without waiting for the rest of the jobs to die. * main.c (die): Don't reset err before calling reap_children() the second time: we still want it to be in the error condition. * job.c (reap_children): Use a static variable, rather than err, to control whether or not the error message should be printed. 2005-08-06 Eli Zaretskii * w32/subproc/sub_proc.c: Include signal.h. (process_pipe_io, process_file_io): Pass a pointer to a local DWORD variable to GetExitCodeProcess. If the exit code is CONTROL_C_EXIT, put SIGINT into pproc->signal. * job.c [WINDOWS32]: Include windows.h. (main_thread) [WINDOWS32]: New global variable. (reap_children) [WINDOWS32]: Get the handle for the main thread and store it in main_thread. * commands.c [WINDOWS32]: Include windows.h and w32err.h. (fatal_error_signal) [WINDOWS32]: Suspend the main thread before doing anything else. When we are done, close the main thread handle and exit with status 130. 2005-07-30 Eli Zaretskii * w32/subproc/sub_proc.c (process_begin): Don't pass a NULL pointer to fprintf. * main.c (find_and_set_default_shell): If found a DOSish shell, set sh_found and the value of default_shell, and report the findings in debug mode. * job.c (construct_command_argv_internal): Check unixy_shell, not no_default_sh_exe, to decide whether to use Unixy or DOSish builtin commands. * README.W32: Update with info about the MinGW build. * build_w32.bat: Support MinGW. * w32/subproc/build.bat: Likewise. * w32/subproc/sub_proc.c (process_easy): Fix format strings for printing DWORD args. * function.c (windows32_openpipe): Fix format strings for printing DWORD args. * job.c (reap_children) [WINDOWS32]: Don't declare 'status' and 'reap_mode'. (start_job_command): Fix format string for printing the result of process_easy. (start_job_command) [WINDOWS32]: Do not define. (exec_command): Fix format string for printing HANDLE args. * main.c (handle_runtime_exceptions): Fix sprintf format strings to avoid compiler warnings. (open_tmpfile): Declare fd only if HAVE_FDOPEN is defined. (Note: some of these fixes were submitted independently by J. Grant) 2005-07-30 J. Grant * prepare_w32.bat: Copy config.h.w32 to config.h if not exist. * make_msvc_net2003.vcproj, make_msvc_net2003.sln: MSVC Project files. * Makefile.am (EXTRA_DIST): Add MSVC Project files. 2005-07-15 Paul Smith * job.c (construct_command_argv_internal) [DOS,WINDOWS32,OS/2]: If we don't have a POSIX shell, then revert to the old backslash-newline behavior (where they are stripped). Fixes bug #13665. 2005-07-08 Paul D. Smith * config.h.W32.template: Reorder to match the standard config.h, for easier comparisons. From J. Grant * maintMakefile: Remove .dep_segment before overwriting it, in case it's not writable or noclobber is set. * expand.c (variable_expand_string): Cast result of pointer arithmetic to avoid a warning. * main.c (switches): Add full-fledged final initializer. 2005-07-06 Paul D. Smith * configure.in: IRIX has _sys_siglist. Tru64 UNIX has __sys_siglist. * signame.c (strsignal): If we found _sys_siglist[] or __sys_siglist[] use those instead of sys_siglist[]. From Albert Chin 2005-07-04 Paul D. Smith * config.h-vms.template [VMS]: Latest VMS has its own glob() and globfree(); set up to use the GNU versions. From Martin Zinser 2005-07-03 Paul D. Smith From J. Grant : * README.W32.template: Update the Windows and tested MSVC versions. * NMakefile.template (CFLAGS_any): Change warning level from W3 to W4. * w32/subproc/NMakefile (CFLAGS_any): Ditto. * build_w32.bat: Ditto. * w32/subproc/build.bat: Ditto. 2005-06-28 Paul D. Smith * signame.c: HAVE_DECL_* macros are set to 0, not undef, if the declaration was checked but not present. 2005-06-27 Paul D. Smith * dir.c (find_directory): Change type of fs_serno/fs_flags/fs_len to unsigned long. Fixes Savannah bug #13550. * w32/subproc/sub_proc.c: Remove (HANDLE) casts on lvalues. (process_pipe_io): Initialize tStdin/tStdout/tStderr variables. Fixes Savannah bug #13551. 2005-06-26 Paul D. Smith * make.h: Fix bug in ANSI_STRING/strerror() handling; only define it if ANSI_STRING is not set. 2005-06-25 Paul D. Smith * read.c (eval): If no filenames are passed to any of the "include" variants, don't print an error. * doc/make.texi (Include): Document this. Fixes Savannah bug #1761. * job.c (construct_command_argv_internal): Sanitize handling of backslash/newline pairs according to POSIX: that is, keep the backslash-newline in the command script, but remove a following TAB character, if present. In the fast path, make sure that the behavior matches what the shell would do both inside and outside of quotes. In the slow path, quote the backslash and put a literal newline in the string. Fixes Savannah bug #1332. * doc/make.texi (Execution): Document the new behavior and give some examples. * NEWS: Make a note of the new behavior. * make.h [WINDOWS32]: #include . Fixes Savannah bug #13478. * remake.c (name_mtime): If the stat() of a file fails and the -L option was given and the file is a symlink, take the best mtime of the symlink we can get as the mtime of the file and don't fail. Fixes Savannah bug #13280. * read.c (find_char_unquote): Accept a new argument IGNOREVARS. If it's set, then don't stop on STOPCHARs or BLANKs if they're inside a variable reference. Make this function static as it's only used here. (eval): Call find_char_unquote() with IGNOREVARS set when we're parsing an unexpanded line looking for semicolons. Fixes Savannah bug #1454. * misc.c (remove_comments): Move this to read.c and make it static as it's only used there. Call find_char_unquote() with new arg. * make.h: Remove prototypes for find_char_unquote() and remove_comments() since they're static now. * main.c (main): If we see MAKE_RESTARTS in the environment, unset its export flag and obtain its value. When we need to re-exec, increment the value and add it into the environment. * doc/make.texi (Special Variables): Document MAKE_RESTARTS. * NEWS: Mention MAKE_RESTARTS. * main.c (always_make_set): New variable. Change the -B option to set this one instead. (main): When checking makefiles, only set always_make_flag if always_make_set is set AND the restarts flag is 0. When building normal targets, set it IFF always_make_set is set. (main): Avoid infinite recursion with -W, too: only set what-if files to NEW before we check makefiles if we've never restarted before. If we have restarted, set what-if files to NEW _after_ we check makefiles. Fixes Savannah bug #7566: 2005-06-17 Paul D. Smith * default.c: Change VMS implicit rules to use $$$$ instead of $$ in the prerequisites list. 2005-06-12 Paul D. Smith Fix Savannah bug # 1328. * configure.in: Check for atexit(). * misc.c (close_stdout): Test stdout to see if writes to it have failed. If so, be sure to exit with a non-0 error code. Based on code found in gnulib. * make.h: Prototype. * main.c (main): Install close_stdout() with atexit(). 2005-06-10 Paul D. Smith VMS build updates from Hartmut Becker : * vmsjobs.c [VMS]: Updates to compile on VMS: add some missing headers; make vmsWaitForChildren() static; extern vmsify(). * job.c [VMS]: Move vmsWaitForChildren() prototype to be global. Don't create child_execute_job() here (it's in vmsjobs.c). * makefile.vms (job.obj) [VMS]: Add vmsjobs.c as a prerequisite. 2005-06-09 Paul D. Smith * variable.c (push_new_variable_scope): File variables point directly to the global_setlist variable. So, inserting a new scope in front of that has no effect on those variables: they don't go through current_variable_set_list. If we're pushing a scope and the current scope is global, push it "the other way" so that the new setlist is in the global_setlist variable, and next points to a new setlist with the global variable set. (pop_variable_scope): Properly undo a push with the new semantics. Fixes Savannah bug #11913. 2005-05-31 Boris Kolpackov * job.c (reap_children): Don't die of the command failed but the dontcare flag is set. Fixes Savannah bug #13216. * implicit.c (pattern_search): When creating a target from an implicit rule match, lookup pattern target and set precious flag in a newly created target. Fixes Savannah bug #13218. 2005-05-13 Paul D. Smith Implement "if... else if... endif" syntax. * read.c (eval): Push all checks for conditional words ("ifeq", "else", etc.) down into the conditional_line() function. (conditional_line): Rework to allow "else if..." clause. New return value -2 for lines which are not conditionals. The ignoring flag can now also be 2, which means "already parsed a true branch". If that value is seen no other branch of this conditional can be considered true. In the else parsing if there is extra text after the else, invoke conditional_line() recursively to see if it's another conditional. If not, it's an error. If so, raise the conditional value to this level instead of creating a new conditional nesting level. Special check for "else" and "endif", which aren't allowed on the "else" line. * doc/make.texi (Conditional Syntax): Document the new syntax. 2005-05-09 Paul D. Smith * Makefile.am (EXTRA_make_SOURCES): Add vmsjobs.c (MAYBE_W32): Rework how SUBDIRS are handled so that "make dist" recurses to the w32 directory, even on non-Windows systems. Use the method suggested in the automake manual. * configure.in: Add w32/Makefile to AC_CONFIG_FILES. * maintMakefile (gnulib-url): They moved the texinfo.tex files. 2005-05-07 Paul D. Smith * main.c (die): If we're dying with a fatal error (not that a command has failed), write back any leftover tokens before we go. * job.c (set_child_handler_action_flags): If there are jobs waiting for the load to go down, set an alarm to go off in 1 second. This allows us to wake up from a potentially long-lasting read() and start a new job if the load has gone down. Turn it off after the read. (job_noop): Dummy signal handler function. (new_job): Invoke it with the new semantics. * docs/make.texi: Document secondary expansion. Various cleanups and random work. 2005-05-03 Paul D. Smith Rename .DEFAULT_TARGET to .DEFAULT_GOAL: in GNU make terminology the targets which are to ultimately be made are called "goals"; see the GNU make manual. Also, MAKECMDGOALS, etc. * filedef.h, read.c, main.c: Change .DEFAULT_TARGET to .DEFAULT_GOAL, and default_target_name to default_goal_name. * doc/make.texi (Special Variables): Document .DEFAULT_GOAL. 2005-05-02 Paul D. Smith * job.c, vmsjobs.c (vmsWaitForChildren, vms_redirect, vms_handle_apos, vmsHandleChildTerm, reEnableAst, astHandler, tryToSetupYAst, child_execute_job) [VMS]: Move VMS-specific functions to vmsjobs.c. #include it into jobs.c. Grant Taylor reports that -j# can lose jobserver tokens. I found that this happens when an exported recursive variable contains a $(shell ...) function reference: in this situation we could "forget" to write back a token. * job.c, job.h: Add variable jobserver_tokens: counts the tokens we have. It's not reliable to depend on the number of children in our linked list so keep a separate count. (new_job): Check jobserver_tokens rather than children && waiting_jobs. Increment jobserver_tokens when we get one. (free_child): If jobserver_tokens is 0, internal error. If it's >1, write a token back to the jobserver pipe (we don't write a token for the "free" job). Decrement jobserver_tokens. * main.c: Add variable master_job_slots. (main): Set it to hold the number of jobs requested if we're the master process, when using the jobserver. (die): Sanity checks: first test jobserver_tokens to make sure this process isn't holding any tokens we didn't write back. Second, if master_job_slots is set count the tokens left in the jobserver pipe and ensure it's the same as master_job_slots (- 1). 2005-04-24 Paul D. Smith Grant Taylor reports that -j# in conjunction with -l# can lose jobserver tokens, because waiting jobs are not consulted properly when checking for the "free" token. * job.c (free_child): Count waiting_jobs as having tokens. * job.c (new_job): Ditto. Plus, call start_waiting_jobs() here to handle jobs waiting for the load to drop. 2005-04-23 Paul D. Smith * main.c (main): Be careful to not core if a variable setting in the environment doesn't contain an '='. This is illegal but can happen in broken setups. Reported by Joerg Schilling . 2005-04-12 Paul D. Smith The second expansion feature causes significant slowdown. Timing a complex makefile (GCC 4.1) shows a slowdown from .25s to just read the makefile before the feature, to 11+s to do the same operations after the feature. Additionally, memory usage increased drastically. To fix this I added some intelligence that avoids the overhead of the second expansion unless it's required. * dep.h: Add a new boolean field, need_2nd_expansion. * read.c (eval): When creating the struct dep for the target, check if the name contains a "$"; if so set need_2nd_expansion to 1. (record_files): If there's a "%" in a static pattern rule, it gets converted to "$*" so set need_2nd_expansion to 1. * file.c (expand_deps): Rework to be more efficient. Only perform initialize_file_variables(), set_file_variables(), and variable_expand_for_file() if the need_2nd_expansion is set. * implicit.c (pattern_search): Default need_2nd_expansion to 0. (pattern_search): Ditto. * main.c (handle_non_switch_argument): Ditto. (main): Ditto. * read.c (read_all_makefiles): Ditto. (eval_makefile): Ditto. 2005-04-07 Paul D. Smith * main.c (main) [WINDOWS32]: Export PATH to sub-shells, not Path. * variable.c (sync_Path_environment): Ditto. Patch by Alessandro Vesely. Fixes Savannah bug #12209. * main.c (main): Define the .FEATURES variable. * NEWS: Announce .FEATURES. * doc/make.texi (Special Variables): Document .FEATURES. * remake.c (check_dep): If a file is .PHONY, update it even if it's marked intermediate. Fixes Savannah bug #12331. 2005-03-15 Boris Kolpackov * file.c (expand_deps): Factor out the second expansion and prerequisite line parsing logic from snap_deps(). * file.c (snap_deps): Use expand_deps(). Expand and parse prerequisites of the .SUFFIXES special target first. Fixes Savannah bug #12320. 2005-03-13 Paul D. Smith * main.c (main) [MSDOS]: Export SHELL in MSDOS. Requested by Eli Zaretskii. 2005-03-11 Paul D. Smith * signame.c (strsignal): HAVE_DECL_SYS_SIGLIST is 0 when not available, not undefined (from Earnie Boyd). 2005-03-10 Boris Kolpackov * implicit.c (pattern_search): Mark an intermediate target as precious if it happened to be a prerequisite of some (other) target. Fixes Savannah bug #12267. 2005-03-09 Paul D. Smith * read.c (eval_makefile): Add alloca(0). (eval_buffer): Ditto. 2005-03-09 Boris Kolpackov * main.c (main): Use o_file instead of o_default when defining the .DEFAULT_TARGET special variable. * read.c (eval): Use define_variable_global() instead of define_variable() when setting new value for the .DEFAULT_TARGET special variable. Fixes Savannah bug #12266. 2005-03-04 Boris Kolpackov * imlicit.c (pattern_search): Mark files for which an implicit rule has been found as targets. Fixes Savannah bug #12202. 2005-03-04 Paul D. Smith * AUTHORS: Update. * doc/make.texi (Automatic Variables): Document $|. 2005-03-03 Boris Kolpackov * read.c (record_files): Instead of substituting % with actual stem value in dependency list replace it with $*. This fixes stem triple expansion bug. * implicit.c (pattern_search): Copy stem to a separate buffer and make it a properly terminated string. Assign this buffer instead of STEM (which is not terminated) to f->stem. Instead of substituting % with actual stem value in dependency list replace it with $*. This fixes stem triple expansion bug. 2005-03-01 Paul D. Smith * commands.c (fatal_error_signal) [WINDOWS32]: Don't call kill() on Windows, as it takes a handle not a pid. Just exit. Fix from patch #3679, provided by Alessandro Vesely. * configure.in: Update check for sys_siglist[] from autoconf manual. * signame.c (strsignal): Update to use the new autoconf macro. 2005-03-01 Boris Kolpackov * read.c (record_files): Add a check for the list of prerequisites of a static pattern rule being empty. Fixes Savannah bug #12180. 2005-02-28 Paul D. Smith * doc/make.texi (Text Functions): Update docs to allow the end ordinal for $(wordlist ...) to be 0. * function.c (func_wordlist): Fail if the start ordinal for $(wordlist ...) is <1. Matches documentation. Resolves Savannah support request #103195. * remake.c (update_goal_chain): Fix logic for stopping in -q: previously we were stopping when !-q, exactly the opposite. This has been wrong since version 1.34, in 1994! (update_file): If we got an error don't break out to run more double-colon rules: just return immediately. Fixes Savannah bug #7144. 2005-02-27 Paul D. Smith * misc.c (end_of_token): Make argument const. * make.h: Update prototype. * function.c (abspath, func_realpath, func_abspath): Use PATH_VAR() and GET_PATH_MAX instead of PATH_MAX. * dir.c (downcase): Use PATH_VAR() instead of PATH_MAX. * read.c (record_files): Ditto. * variable.c (do_variable_definition): Ditto. * function.c (func_error): Create a new function $(info ...) that simply prints the message to stdout with no extras. (function_table_init): Add new function to the table. * NEWS: Add $(info ...) reference. * doc/make.texi (Make Control Functions): Document it. New feature: if the system supports symbolic links, and the user provides the -L/--check-symlink-time flag, then use the latest mtime between the symlink(s) and the target file. * configure.in (MAKE_SYMLINKS): Check for lstat() and readlink(). If both are available, define MAKE_SYMLINKS. * main.c: New variable: check_symlink_flag. (usage): Add a line for -L/--check-symlink-times to the help string. (switches): Add -L/--check-symlink-times command line argument. (main): If MAKE_SYMLINKS is not defined but the user specified -L, print a warning and disable it again. * make.h: Declare check_symlink_flag. * remake.c (name_mtime): If MAKE_SYMLINKS and check_symlink_flag, if the file is a symlink then check each link in the chain and choose the NEWEST mtime we find as the mtime for the file. The newest mtime might be the file itself! * NEWS: Add information about this new feature. * doc/make.texi (Options Summary): Add -L/--check-symlink-times docs. Avoid core dumps described in Savannah bug # 12124: * file.c: New variable snapped_deps remember whether we've run snap_deps(). (snap_deps): Set it. * filedef.h: Extern it. * read.c (record_files): Check snapped_deps; if it's set then we're trying to eval a new target/prerequisite relationship from within a command script, which we don't support. Fatal. 2005-02-28 Boris Kolpackov Implementation of the .DEFAULT_TARGET special variable. * read.c (eval): If necessary, update default_target_name when reading rules. * read.c (record_files): Update default_target_file if default_target_name has changed. * main.c (default_target_name): Define. * main.c (main): Enter .DEFAULT_TARGET as make variable. If default_target_name is set use default_target_file as a root target to make. * filedef.h (default_target_name): Declare. * dep.h (free_dep_chain): * misc.c (free_dep_chain): Change to operate on struct nameseq and change name to free_ns_chain. * file.c (snap_deps): Update to use free_ns_chain. 2005-02-27 Boris Kolpackov Implementation of the second expansion in explicit rules, static pattern rules and implicit rules. * read.c (eval): Refrain from chopping up rule's dependencies. Store them in a struct dep as a single dependency line. Remove the code that implements SySV-style automatic variables. * read.c (record_files): Adjust the code that handles static pattern rules to expand all percents instead of only the first one. Reverse the order in which dependencies are stored so that when the second expansion reverses them again they appear in the makefile order (with some exceptions, see comments in the code). Remove the code that implements SySV-style automatic variables. * file.c (snap_deps): Implement the second expansion and chopping of dependency lines for explicit rules. * implicit.c (struct idep): Define an auxiliary data type to hold implicit rule's dependencies after stem substitution and expansion. * implicit.c (free_idep_chain): Implement. * implicit.c (get_next_word): Implement helper function for parsing implicit rule's dependency lines into words taking into account variable expansion requests. Used in the stem splitting code. * implicit.c (pattern_search): Implement the second expansion for implicit rules. Also fixes bug #12091. * commands.h (set_file_variables): Declare. * commands.c (set_file_variables): Remove static specifier. * dep.h (free_dep_chain): Declare. * misc.c (free_dep_chain): Implement. * variable.h (variable_expand_for_file): Declare. * expand.c (variable_expand_for_file): Remove static specifier. * make.h (strip_whitespace): Declare. * function.c (strip_whitespace): Remove static specifier. 2005-02-26 Paul D. Smith * main.c (main): Check for ferror() when reading makefiles from stdin. Apparently some shells in Windows don't close pipes properly and require this check. 2005-02-24 Jonathan Grant * configure.in: Add MinGW configuration options, and extra w32 code directory. * Makefile.am: Add MinGW configuration options, and extra w32 code directory. * main.c: Determine correct program string (after last \ without .exe). * subproc/sub_proc.c: `GetExitCodeProcess' from incompatible pointer type fix x2 * w32/Makefile.am: Import to build win32 lib of sub_proc etc. * subproc/w32err.c: MSVC thread directive not applied to MinGW builds. * tests/run_make_tests.pl, tests/test_driver.pl: MSYS testing environment support. 2004-04-16 Dmitry V. Levin * function.c (func_shell): When initializing error_prefix, check that reading file name is not null. This fixes long-standing segfault in cases like "make 'a1=$(shell :)' 'a2:=$(a1)'". 2005-02-09 Paul D. Smith * maintMakefile: Update the CVS download URL to simplify them. Also, the ftp://ftp.gnu.org/GNUinfo site was removed so I'm downloading the .texi files from Savannah now. Fixed these issues reported by Markus Mauhart : * main.c (handle_non_switch_argument): Only add variables to command_variables if they're not already there: duplicate settings waste space and can be confusing to read. * w32/include/sub_proc.h: Remove WINDOWS32. It's not needed since this header is never included by non-WINDOWS32 code, and it requires to define which isn't always included first. * dir.c (read_dirstream) [MINGW]: Use proper macro names when testing MINGW32 versions. * main.c (log_working_directory): flush stdout to be sure the WD change is printed before any stderr messages show up. 2005-02-01 Paul D. Smith * maintMakefile (po_repo): Update the GNU translation site URL. 2004-12-01 Paul D. Smith * main.c (main): Change char* env_shell to struct variable shell_var. * variable.c (target_environment): Use new shell_var. 2004-11-30 Paul D. Smith * configure.in: The old way we avoided creating build.sh from build.sh.in before build.sh.in exists doesn't work anymore; we have to use raw M4 (thanks to Andreas Schwab for the help!). This also keeps automake from complaining. * Makefile.am (README): Add a dummy target so automake won't complain that this file doesn't exist when we checkout from CVS. * maintMakefile (.dep_segment): Rewrite this rule since newer versions of automake don't provide DEP_FILES. 2004-11-30 Boris Kolpackov Implementation of `realpath' and `abspath' built-in functions. * configure.in: Check for realpath. * function.c (abspath): Return an absolute file name that does not contain any `.' or `..' components, nor repeated `/'. * function.c (func_abspath): For each name call abspath. * function.c (func_realpath): For each name call realpath from libc or delegate to abspath if realpath is not available. * doc/make.texi (Functions for File Names): Document new functions. * doc/make.texi (Quick Reference): Ditto. 2004-11-28 Paul D. Smith * main.c (main) [WINDOWS32]: Remove any trailing slashes from -C arguments. Fixes bug #10252. Fix for bug #1276: Handle SHELL according to POSIX requirements. * main.c (main): Set SHELL to v_noexport by default. Remember the original environment setting of SHELL in the env_shell variable. * main.h: Export new env_shell variable. * variable.c (target_environment): If we find a v_noexport variable for SHELL, add a SHELL variable with the env_shell value. * doc/make.texi (Quick Reference): Document the POSIX behavior. * doc/make.texi (Variables/Recursion): Ditto. 2004-11-28 Paul D. Smith * main.c (find_and_set_default_shell) [WINDOWS32]: check for equality of "cmd"/"cmd.exe", not inequality. Fixes bug #11155. Patch by Alessandro Vesely. 2004-11-12 Paul D. Smith * job.c (child_execute_job) [VMS]: Don't treat "#" as a comment on the command line if it's inside a string. Patch by: Hartmut Becker 2004-10-21 Boris Kolpackov * function.c (func_lastword): New function: return last word from the list of words. * doc/make.texi: Document $(lastword ). Fix broken links in Quick Reference section. 2004-10-06 Paul D. Smith Apply patch from Alessandro Vesely, provided with bug # 9748. Fix use of tmpnam() to work with Borland C. * job.c (construct_command_argv_internal) [WINDOWS32]: Remove construction of a temporary filename, and call new function create_batch_filename(). (create_batch_filename) [WINDOWS32]: New function to create a temporary filename. 2004-10-05 Boris Kolpackov * read.c (record_target_var): Expand simple pattern-specific variable. * variable.c (initialize_file_variables): Do not expand simple pattern-specific variable. 2004-09-28 Boris Kolpackov * remake.c (update_file_1): When rebuilding makefiles inherit dontcare flag from a target that triggered update. 2004-09-27 Boris Kolpackov * variable.c (initialize_file_variables): Mark pattern-specific variable as a per-target and copy export status. 2004-09-21 Boris Kolpackov * file.c (snap_deps): Mark .PHONY prerequisites as targets. * implicit.c (pattern_search): When considering an implicit rule's prerequisite check that it is actually a target rather then just an entry in the file hashtable. 2004-09-21 Paul D. Smith * read.c (readstring): Fix some logic errors in backslash handling. (eval): Remove some unnecessary processing in buffer handling. (record_target_var): Assert that parse_variable_definition() succeeded. Reported by: Markus Mauhart . * misc.c: Removed the sindex() function. All instances of this function were trivially replaceable by the standard strstr() function, and that function will always have better (or certainly no worse) performance than the very simple-minded algorithm sindex() used. This can matter with complex makefiles. * make.h: Remove the prototype for sindex(). * function.c (subst_expand): Convert sindex() call to strstr(). This means we no longer need to track the TLEN value so remove that. (func_findstring): Convert sindex() to strstr(). * commands.c (chop_commands): Convert sindex() calls to strstr(). Suggested by: Markus Mauhart . * main.c (find_and_set_default_shell) [WINDOWS32]: Implement the idea behind Savannah Patch #3144 from david.baird@homemail.com. If SHELL is set to CMD.EXE then assume it's batch-mode and non-unixy. I wrote the code differently from the patch, though, to make it safer. This also resolves bug #9174. 2004-09-20 Paul D. Smith * expand.c (variable_expand_string): Modify to invoke patsubst_expand() instead of subst_expand(); the latter didn't handle suffix patterns correctly. * function.c (subst_expand): Remove the SUFFIX_ONLY parameter; it was used only from variable_expand_string() and is no longer used there. (func_subst): Ditto, on call to subst_expand(). (patsubst_expand): Require the percent pointers to point to the character after the %, not to the % itself. * read.c (record_files): New call criteria for patsubst_expand(). * variable.h: Remove SUFFIX_ONLY from subst_expand() prototype. This is to fix a bug reported by Markus Mauhart . 2004-09-19 Paul D. Smith * function.c (subst_expand): Fix a check in by_word: look for a previous blank if we're beyond the beginning of the string, not the beginning of the word. Bugs reported by Markus Mauhart . 2004-05-16 Paul D. Smith * remake.c (update_goal_chain): Change the argument specifying whether we're rebuilding makefiles to be a global variable, REBUILDING_MAKEFILES. (complain): Extract the code that complains about no rules to make a target into a separate function. (update_file_1): If we tried to rebuild a file during the makefile rebuild phase and it was dontcare, then no message was printed. If we then try to build the same file during the normal build, print a message this time. (remake_file): Don't complain about un-remake-able files when we're rebuilding makefiles. 2004-05-11 Paul D. Smith * job.c (construct_command_argv_internal): OS/2 patches from Andreas Buening . 2004-05-10 Paul D. Smith * remake.c (update_file): Don't walk the double-colon chain unless this is a double-colon rule. Fix suggested by Boris Kolpackov . * makefile.vms (CFLAGS): Remove glob/globfree (see readme.vms docs) * readme.vms: New section describing OpenVMS support and issues. * default.c (default_variables): Add support for IA64. * job.c (tryToSetupYAst) [VMS]: On VMS running make in batch mode without some privilege aborts make with the error %SYSTEM-F-NOPRIV. It happens when setting up a handler for pressing Ctrl+Y and the input device is no terminal. The change catches this error and just continues. Patches by Hartmut Becker 2004-04-25 Paul D. Smith * commands.c (set_file_variables): Set $< properly in the face of order-only prerequisites. Patch from Boris Kolpackov 2004-04-21 Bob Byrnes * main.c (main): Notice failures to remake makefiles. 2004-03-28 Paul D. Smith Patches for Acorn RISC OS by Peter Naulls * job.c: No default shell for RISC OS. (load_too_high): Hard-code the return to 1. (construct_command_argv_internal): No sh_chars or sh_cmds. * getloadavg.c: Don't set LOAD_AVE_TYPE on RISC OS. 2004-03-20 Paul D. Smith * variable.c (do_variable_definition): Don't append from the global set if a previous non-appending target-specific variable definition exists. Reported by Oliver Schmidt (with fix). * expand.c (reference_variable): Don't give up on variables with no value that have the target-specific append flag set: they might have a value after all. Reported by Oliver Schmidt (with fix) and also by Maksim A. Nikulin . * rule.c (count_implicit_rule_limits): Don't delete patterns which refer to absolute pathnames in directories that don't exist: some portion of the makefile could create those directories before we match the pattern. Fixes bugs #775 and #108. Fixes from Jonathan R. Grant : * main.c (main): Free makefile_mtimes if we have any. * README.W32.template: Update documentation for the current status of the MS-Windows port. * NMakefile.template (MAKE): Add "MAKE = nmake". A conflicting environment variable is sometimes already defined which causes the build to fail. * main.c (debug_signal_handler): Only define this function if SIGUSR1 is available. Fixes for OS/2 from Andreas Beuning : * configure.in [OS/2]: Relocate setting of HAVE_SA_RESTART for OS/2. * README.OS2.template: Documentation updates. * build.template: Add LIBINTL into LOADLIBES. Add $CFLAGS to the link line for safety. * maintMakefile (build.sh.in): Remove an extraneous ")". * job.c (child_execute_job): Close saved FDs. * job.c (exec_command) [OS/2]: exec_command(): If the command can't be exec'ed and if the shell is not Unix-sh, then try again with argv = { "cmd", "/c", ... }. Normally, this code is never reached for the cmd shell unless the command really doesn't exist. (construct_command_argv_internal) [OS/2]: The code for cmd handling now uses new_argv = { "cmd", "/c", "original line", NULL}. The CMD builtin commands are case insensitive so use strcasecmp(). 2004-03-19 Paul D. Smith * read.c (do_define): Re-order line counter increment so the count is accurate (we were losing one line per define). Reported by Dave Yost . 2004-03-06 Paul D. Smith * configure.in (HAVE_ANSI_COMPILER): Define if we have an ANSI/ISO compiler. * make.h: Convert uses of __STDC__ to HAVE_ANSI_COMPILER. * misc.c (message,error,fatal): Ditto. * configh.dos.template: Define HAVE_ANSI_COMPILER. * config.h.W32.template: Ditto. * config.h-vms.template: Ditto. * config.ami.template: Ditto. 2004-03-04 Paul D. Smith * README.template: Add a note about broken /bin/sh on SunOS 4.1.3_U1 & 4.1.4. Fix up Savannah links. * misc.c (message, error, fatal): Don't use "..." if we're using varargs. ansi2knr should handle this but it doesn't work: it translates "..." to va_dcl etc. but _AFTER_ the preprocessor is done. On many systems (SunOS for example) va_dcl is a #define. So, force the use of the non-"..." version on pre-ANSI compilers. * maintMakefile (sign-dist): Create some rules to help automate the new GNU ftp upload method. 2004-02-24 Paul D. Smith * config.h.W32.template: Add HAVE_STDARG_H * config.h-vms.template: Ditto. * config.ami.template: Ditto. 2004-02-23 Jonathan Grant * README.W32.template: Add a notation about -j with BATCH_MODE_ONLY. * build_w32.bat: Remove extra "+". 2004-02-23 Paul D. Smith * make.h: Create an UNUSED macro to mark unused parameters. * (many): Clean up warnings by applying UNUSED, fixing signed/unsigned incompatibilities, etc. * acinclude.m4 (AC_STRUCT_ST_MTIM_NSEC): Add quoting to silence autoconf warnings. * filedef.h: Name the command_state enumeration. * file.c (set_command_state): Use the enumeration in the function argument. * configure.in: Explicitly set SET_MAKE to empty, to disable MAKE=make even when no make already exists. Fix bug #3823. 2004-02-22 Paul D. Smith * maintMakefile: Perl script to clean up all non-CVS files. Use it on all the subdirectories for the cvs-clean target. * main.c (decode_switches): Require non-empty strings for all our string command-line options. Fixes Debian bug # 164165. * configure.in: Check for stdarg.h and varargs.h. * make.h (USE_VARIADIC): Set this if we can use variadic functions for printing messages. * misc.c: Check USE_VARIADIC instead of (obsolete) HAVE_STDVARARGS. (message): Ditto. (error): Ditto. (fatal): Ditto. A number of patches for OS/2 support from Andreas Buening : * job.c (child_handler) [OS/2]: Allow this on OS/2 but we have to disable the SIGCHLD handler. (reap_children) [OS/2]: Remove special handling of job_rfd. (set_child_handler_action_flags) [OS/2]: Use this function in OS/2. (new_job) [OS/2]: Disable the SIGCHLD handler on OS/2. * main.c (main) [OS/2]: Special handling for paths in OS/2. * configure.in [OS/2]: Force SA_RESTART for OS/2. * Makefile.am (check-regression): Use $(EXEEXT) for Windows-type systems. 2004-02-21 Paul D. Smith * w32/subproc/sub_proc.c (process_easy) [W32]: Christoph Schulz reports that if process_begin() fails we don't handle the error condition correctly in all cases. * w32/subproc/w32err.c (map_windows32_error_to_string): Make sure to have a newline on the message. * job.c (construct_command_argv_internal): Add "test" to UNIX sh_cmds[]. Fixes Savannah bug # 7606. 2004-02-04 Paul D. Smith * job.c (vms_handle_apos) [VMS]: Fix various string handling situations in VMS DCL. Fixes Savannah bug #5533. Fix provided by Hartmut Becker . 2004-01-21 Paul D. Smith * job.c (load_too_high): Implement an algorithm to control the "thundering herd" problem when using -l to control job creation via the load average. The system only recomputes the load once a second but we can start many jobs in a second. To solve this we keep track of the number of jobs started in the last second and apply a weight to try to guess what a correct load would be. The algorithm was provided by Thomas Riedl . Also fixes bug #4693. (reap_children): Decrease the job count for this second. (start_job_command): Increase the job count for this second. * read.c (conditional_line): Expand the text after ifn?def before checking to see if it's a single word. Fixes bug #7257. 2004-01-09 Paul D. Smith * file.c (print_file): Recurse to print all targets in double-colon rules. Fixes bug #4518, reported (with patch) by Andrew Chatham . 2004-01-07 Paul D. Smith * acinclude.m4: Remove make_FUNC_SETVBUF_REVERSED. * configure.in: Change make_FUNC_SETVBUF_REVERSED to AC_FUNC_SETVBUF_REVERSED. * doc/make.texi (Target-specific): Fix Savannah bug #1772. (MAKE Variable): Fix Savannah bug #4898. * job.c (construct_command_argv_internal): Add "!" to the list of shell escape chars. POSIX sh allows it to appear before a command, to negate the exit code. Fixes bug #6404. * implicit.c (pattern_search): When matching an implicit rule, remember which dependencies have the ignore_mtime flag set. Original fix provided in Savannah patch #2349, by Benoit Poulot-Cazajous . 2003-11-22 Paul D. Smith * README.W32.template (Outputs): Clarification on -j with BATCH_MODE_ONLY_SEHLL suggested by Jonathan R. Grant . 2003-11-02 Paul D. Smith * function.c (func_if): Strip all the trailing whitespace from the condition, then don't expand it. Fixed bug # 5798. * expand.c (recursively_expand_for_file): If we're expanding a variable with no file context, then use the variable's context. Fixes bug # 6195. 2003-10-21 Paul D. Smith * main.c (log_working_directory): Add newlines to printf()s. * README.cvs: Add a note to ignore warnings during autoreconf. * maintMakefile (po_repo): Set a new URL for PO file updates. (get-config/config.guess get-config/config.sub): Get these files from the Savannah config project instead of ftp.gnu.org. 2003-10-05 Paul Eggert * main.c (main): Avoid potential subscript error if environ has short strings. 2003-08-22 Paul D. Smith * misc.c (xmalloc, xrealloc): Add one to 0 sizes, to cater to systems which don't yet implement the C89 standard :-/. 2003-07-18 Paul D. Smith * dir.c (directory_contents_hash_1, directory_contents_hash_1) [WINDOWS32]: Initialize hash. 2003-06-19 Earnie Boyd * dir.c (read_dirstream): Provide a workaround for broken versions of the MinGW dirent structure. 2003-05-30 Earnie Boyd * w32/include/dirent.h: Add __MINGW32__ filter. 2003-05-30 Earnie Boyd * make.h: Add global declaration of *make_host. * main.c (print_usage): Remove local declaration of *make_host. (print_version): Display "This program built for ..." after Copyright notice. 2003-05-30 Earnie Boyd * doc/make.texi: Change "ifinfo" to "ifnottex" as suggested by the execution of "makeinfo --html make.texi". 2003-04-30 Paul D. Smith * build.template: Make some changes to maybe allow this script to work on DOS/Windows/OS2 systems. Suggested by Andreas Buening. * README.OS2.template: New file for OS/2 support. Original contributed by Andreas Buening. * configure.in: Invoke new pds_AC_DOS_PATHS macro to test for DOS-style paths. 2003-04-19 Paul D. Smith Fix bug #1405: allow a target to match multiple pattern-specific variables. * rule.c (create_pattern_var, lookup_pattern_var): Move these to variable.c, where they've always belonged. * rule.h: Move the prototypes and struct pattern_var as well. * variable.c (initialize_file_variables): Invoke lookup_pattern_var() in a loop, until no more matches are found. If a match is found, create a new variable set for the target's pattern variables. Then merge the contents of each matching pattern variable set into the target's pattern variable set. (lookup_pattern_var): Change this function to be usable in a loop. It takes a starting position: if NULL, start at the beginning; if non-NULL, start with the pattern variable after that position, and return the next matching pattern. (create_pattern_var): Create a unique instance of pattern-specific variables for every definition in the makefile. Don't combine the same pattern together. This allows us to process the variable handling properly even when the same pattern is used multiple times. (parse_variable_definition): New function: break out the parsing of a variable definition line from try_variable_definition. (try_variable_definition): Call parse_variable_definition to parse. (print_variable_data_base): Print out pattern-specific variables. * variable.h (struct variable): Remember when a variable is conditional. Also remember its flavor. (struct pattern_var): Instead of keeping a variable set, we just keep a single variable for each pattern. * read.c (record_target_var): Each pattern variable contains only a single variable, not a set, so create it properly. * doc/make.texi (Pattern-specific): Document the new behavior. 2003-04-17 Paul D. Smith * dir.c (file_exists_p) [VMS]: Patch provided with Bug #3018 by Jean-Pierre Portier . I don't understand the file/directory naming rules for VMS so I can't tell whether this is correct or not. 2003-04-09 Paul D. Smith * configure.in (HAVE_DOS_PATHS): Define this on systems that need DOS-style pathnames: backslash separators and drive specifiers. 2003-03-28 Paul D. Smith * file.c (snap_deps): If .SECONDARY with no targets is given, set the intermediate flag on all targets. Fixes bug #2515. 2003-03-24 Paul D. Smith * configure.in, Makefile.am, glob/Makefile.am, doc/Makefile.am: Upgrade to autoconf 2.57 and automake 1.7.3. * job.c: More OS/2 changes from Andreas Buening. * file.c (print_file): Fix variable initialization. Fixes bug #2892. * remake.c (notice_finished_file): * make.h (ENULLLOOP): Set errno = 0 before invoking the command; some calls (like readdir()) return NULL in valid situations without resetting errno. Fixes bug #2846. 2003-02-25 Paul D. Smith Port to OS/2 (__EMX__) by Andreas Buening . * job.c (_is_unixy_shell) [OS/2]: New function. Set default shell to /bin/sh. (reap_children): Close the job_rfd pipe here since we don't use a SIGCHLD handler. (set_child_handler_action_flags): define this to empty on OS/2. (start_job_command): Close the jobserver pipe and use child_execute_job() instead of fork/exec. (child_execute_job): Rewrite to handle stdin/stdout FDs and spawn rather than exec'ing, then reconfigure stdin/stdout. (exec_command): Rewrite to use spawn instead of exec. Return the PID of the child. * main.c (main) [OS/2]: Call initialize_main(). Handle argv[0] as in DOS. Handle the TEMP environment variable as in DOS. Don't use a SIGCHLD handler on OS/2. Choose a shell as in DOS. Don't use -j in DOS mode. Use child_execute_job() instead of exec_command(). * function.c (func_shell) [OS/2]: Can't use fork/exec on OS/2: use spawn() instead. * job.h [OS/2]: Move CLOSE_ON_EXEC here from job.c. Add prototypes that return values. * remake.c (f_mtime) [OS/2]: Handle FAT timestamp offsets for OS/2. * read.c (readline) [OS/2]: Don't handle CRLF specially on OS/2. * default.c (default_suffixes) [OS/2]: Set proper default suffixes for OS/2. * vpath.c (construct_vpath_list) [OS/2]: Handle OS/2 paths like DOS paths. 2003-02-24 Paul D. Smith * default.c [VMS]: New default rules for .cxx -> .obj compiles. * job.c (child_execute_job) [VMS]: New code for handling spawn(). (child_execute_job) [VMS]: Handle error status properly. Patches provided by Hartmut Becker . * function.c (func_shell): Use EINTRLOOP() while reading from the subshell pipe (Fixes bug #2502). * job.c (free_child): Use EINTRLOOP() while writing tokens to the jobserver pipe. * main.c (main): Ditto. 2003-01-30 Paul D. Smith * read.c (eval): eval() was not fully reentrant, because the collapsed buffer was static. Change it to be an automatic variable so that eval() can be invoked recursively. Fixes bug # 2238. (eval): Apply patch # 1022: fix memory reference error on long target-specific variable lines. Patch provided by Steve Brown . * function.c (check_numeric): Combine the is_numeric() function into this function, since it's only called from one place. Constify this function. Have it print the incorrect string in the error message. Fixes bug #2407. (strip_whitespace): Constify. (func_if): Constify. * expand.c (expand_argument): Constify. 2003-01-29 Paul D. Smith Fix bug # 2169, also reported by other people on various systems. * make.h: Some systems, such as Solaris and PTX, do not fully implement POSIX-compliant SA_RESTART functionality; important system calls like stat() and readdir() can still fail with EINTR even if SA_RESTART has been set on the signal handler. So, introduce macros EINTRLOOP() and ENULLLOOP() which can loop on EINTR for system calls which return -1 or 0 (NULL), respectively, on error. Also, remove the old atomic_stat()/atomic_readdir() and HAVE_BROKEN_RESTART handling. * configure.in: Remove setting of HAVE_BROKEN_RESTART. * arscan.c (ar_member_touch): Use EINTRLOOP() to wrap fstat(). * remake.c (touch_file): Ditto. * commands.c (delete_target): Use EINTRLOOP() to wrap stat(). * read.c (construct_include_path): Ditto. * remake.c (name_mtime): Ditto. * vpath.c (selective_vpath_search): Ditto. * dir.c (find_directory): Ditto. (local_stat): Ditto. (find_directory): Use ENULLLOOP() to wrap opendir(). (dir_contents_file_exists_p): Use ENULLLOOP() to wrap readdir(). * misc.c: Remove HAVE_BROKEN_RESTART, atomic_stat(), and atomic_readdir() handling. 2003-01-22 Paul D. Smith * function.c (func_call): Fix Bug #1744. If we're inside a recursive invocation of $(call ...), mask any of the outer invocation's arguments that aren't used by this one, so that this invocation doesn't "inherit" them accidentally. 2002-12-05 Paul D. Smith * function.c (subst_expand): Valery Khamenia reported a pathological performance hit when doing substitutions on very large values with lots of words: turns out we were invoking strlen() a ridiculous number of times. Instead of having each call to sindex() call strlen() again, keep track of how much of the text we've seen and pass the length to sindex(). 2002-11-19 Paul D. Smith * README.cvs, configure.in: Upgrade to require autoconf 2.56. 2002-11-16 Paul D. Smith * NMakefile.template (OBJS): Add hash.c object file. * SMakefile.template (srcs): Ditto. * Makefile.ami (objs): Ditto. * build_w32.bat: Ditto. * Makefile.DOS.template: Remove extra dependencies. 2002-10-25 Paul D. Smith * expand.c (install_variable_buffer): New function. Install a new variable_buffer context and return the previous one. (restore_variable_buffer): New function. Free the current variable_buffer context and put a previously saved one back. * variable.h: Prototypes for {install,restore}_variable_buffer. * function.c (func_eval): Push a new variable_buffer context before we eval, then restore the old one when we're done. Fixes Bug #1517. * read.c (install_conditionals): New function. Install a new conditional context and return the previous one. (restore_conditionals): New function. Free the current conditional context and put a previously saved one back. (eval): Use the {install,restore}_conditionals for "include" handling. (eval_buffer): Use {install,restore}_conditionals to preserve the present conditional state before we evaluate the buffer. Fixes Bug #1516. * doc/make.texi (Quick Reference): Add references to $(eval ...) and $(value ...). (Recursion): Add a variable index entry for CURDIR. * README.cvs: Update to appropriate versions. * Makefile.am (nodist_loadavg_SOURCES): automake gurus point out I don't need to copy loadavg.c: automake is smart enough to create it for me. Still have a bug in automake related to ansi2knr tho. 2002-10-14 Paul D. Smith * remake.c (notice_finished_file): Only touch targets if they have at least one command (as per POSIX). Resolve Bug #1418. * *.c: Convert to using ANSI C-style function definitions. * Makefile.am: Enable the ansi2knr feature of automake. * configure.in: ditto. 2002-10-13 Paul D. Smith * commands.c (set_file_variables): Bug #1379: Don't use alloca() for automatic variable values like $^, etc. In the case of very large lists of prerequisites this causes problems. Instead reuse a static buffer (resizeable) for each variable. * read.c (eval): Fix Bug #1391: allow "export" keyword in target-specific variable definitions. Check for it and set an "exported" flag. (record_target_var): Set the export field to v_export if the "exported" flag is set. * doc/make.texi (Target-specific): Document the ability to use "export". * doc/make.texi: Change the name of the section on automatic variables from "Automatic" to "Automatic Variables". Added text clarifying the scope of automatic variables. 2002-10-04 Paul D. Smith * read.c (eval): Allow SysV $$@ variables to use {} braces as well as () braces. (record_files): Ditto. * expand.c (variable_expand_string): In $(A:x=y) expansion limit the search for the '=' to only within the enclosing parens. 2002-10-03 Paul D. Smith Version 3.80 released. * dir.c: Change hash functions to use K&R function definition style. * function.c: Ditto. * read.c: Ditto. * variable.c: Ditto. Update to automake 1.7. * Makefile.am (AUTOMAKE_OPTIONS): Update to require 1.7. (pdf): Remove this target as automake now provides one. * configure.in: Change AM_CONFIG_HEADER to AC_CONFIG_HEADERS. 2002-09-30 Martin P.J. Zinser * makefile.com: Updates for GNU make 3.80. * makefile.vms: Ditto. 2002-09-23 Paul D. Smith * read.c (enum make_word_type): Remove w_comment. (get_next_mword): Don't treat comment characters as special; where this function is used we will never see a comment (it's stripped before we get here) and treating comments specially means that targets like "foo\#bar" aren't handled properly. 2002-09-18 Paul D. Smith * doc/make.texi (Bugs): Update with some info on Savannah, etc. * read.c (eval): Expansion of arguments to export/unexport was ignoring all arguments after the first one. Change the algorithm to expand the whole line once, then parse the results. 2002-09-17 Paul D. Smith Fix Bug #940 (plus another bug I found while looking at this): * read.c (record_target_var): enter_file() will add a new entry if it's a double-colon target: we don't want to do that in this situation. Invoke lookup_file() and only enter_file() if it does not already exist. If the file we get back is a double-colon then add this variable to the "root" double-colon target. * variable.c (initialize_file_variables): If this file is a double-colon target but is not the "root" target, then initialize the root and make the root's variable list the parent of our variable list. 2002-09-13 Paul D. Smith * doc/make.texi (MAKE Variable): Add some indexing for "+". * hash.c (round_up_2): Get rid of a warning. 2002-09-12 Paul D. Smith * Makefile.am (loadavg_SOURCES, loadavg.c): Tiptoe around automake so it doesn't complain about getloadavg.c. * commands.c (set_file_variables): Make sure we always alloca() at least 1 character for the value of $? (for '\0'). 2002-09-11 Paul D. Smith * hash.h (STRING_COMPARE, ISTRING_COMPARE, STRING_N_COMPARE): Fix macro to use RESULT instead of the incorrect _RESULT_. * make.h (HAVE_BROKEN_RESTART): Add prototypes for atomic_stat() and atomic_readdir(). We need to #include dirent.h to get this to work. * misc.c (atomic_readdir): Fix typos. 2002-09-10 Paul D. Smith * read.c (eval): Expand variable lists given to export and unexport, so that "export $(LIST_OF_VARIABLES)" (etc.) works. (conditional_line): Ditto for "ifdef". Fixes bug #103. * doc/make.texi (Variables/Recursion): Document this. (Conditional Syntax): And here. 2002-09-09 Paul D. Smith * configure.in: Check for memmove(). 2002-09-07 Paul D. Smith * configure.in (HAVE_BROKEN_RESTART): Define this on PTX systems; Michael Sterrett reports that while it has SA_RESTART, it does not work properly. * misc.c (atomic_stat): If HAVE_BROKEN_RESTART, create a function that invokes stat() and loops to do it again if it returns EINTR. (atomic_readdir): Ditto, with readdir(). * make.h (stat, readdir): If HAVE_BROKEN_RESTART, alias stat() and readdir() to atomic_stat() and atomic_readdir(). 2002-09-04 Paul D. Smith * implicit.c (pattern_search): Daniel reports that GNU make sometimes doesn't recognize that targets can be made, when directories can be created as prerequisites. He reports that changing the order of predicates in the DEP->changed flag test so that lookup_file() is always performed, solves this problem. 2002-08-08 Paul D. Smith * configure.in: Require a newer version of gettext. * misc.c (perror_with_name): Translate the format string (for right-to-left language support). (pfatal_with_name): Ditto. * main.c: Create a static array of strings to store the usage text. This is done to facilitate translations. (struct command_switch): Remove argdesc and description fields. (switches): Remove values for obsolete fields. (print_usage): Print each element of the usage array. * hash.c: Change function definitions to be K&R style. 2002-08-02 Paul D. Smith * NEWS: Remove the mention of .TARGETS; we aren't going to publish this one because it's too hard to get right. We'll look at it for a future release. * main.c (main): Don't create the .TARGETS variable. * variable.c (handle_special_var): Don't handle .TARGETS. 2002-08-01 Paul D. Smith * main.c (switches): Add a new option, -B (--always-make). If specified, make will rebuild all targets that it encounters even if they don't appear to be out of date. (always_make_flag): New flag. * make.h: Extern always_make_flag. * remake.c (update_file_1): Check always_make_flag; if it's set we will always rebuild any target we can, even if none of its prerequisites are newer. * NEWS: Mention it. * doc/make.texi (Shell Function): Make it clear that make variables marked as "export" are not passed to instances of the shell function. Add new introspection variable .VARIABLES and .TARGETS. * variable.c (handle_special_var): New function. If the variable reference passed in is "special" (.VARIABLES or .TARGETS), calculate the new value if necessary. .VARIABLES is handled here: walk through the hash of defined variables and construct a value which is a list of the names. .TARGETS is handled by build_target_list(). (lookup_variable): Invoke handle_special_var(). * file.c (build_target_list): Walk through the hask of known files and construct a list of the names of all the ones marked as targets. * main.c (main): Initialize them to empty (and as simple variables). * doc/make.texi (Special Variables): Document them. * NEWS: Mention them. * variable.h (struct variable): Add a new flag "exportable" which is true if the variable name is valid for export. * variable.c (define_variable_in_set): Set "exportable" when a new variable is defined. (target_environment): Use the "exportable" flag instead of re-checking the name here... an efficiency improvement. 2002-07-31 Paul D. Smith * config.h-vms.template: Updates to build on VMS. Thanks to Brian_Benning@aksteel.com for helping verify the build. * makefile.com: Build the new hash.c file. * hash.h: Use strcpmi(), not stricmp(), in the HAVE_CASE_INSENSITIVE_FS case. 2002-07-30 Paul D. Smith * hash.h (ISTRING_COMPARE, return_ISTRING_COMPARE): Add missing backslashes to the HAVE_CASE_INSENSITIVE_FS case. Reported by . 2002-07-10 Paul D. Smith * variable.c (pop_variable_scope): Remove variable made unused by new hash infrastructure. * read.c (dep_hash_cmp): Rewrite this to handle ignore_mtime comparisons as well as name comparisons. * variable.h: Add a prototype for new hash_init_function_table(). * file.c (lookup_file): Remove variables made unused by new hash infrastructure. * dir.c (directory_contents_hash_2): Missing return of hash value. (dir_contents_file_exists_p): Remove variables made unused by new hash infrastructure. Installed Greg McGary's integration of the hash functions from the GNU id-utils package: 2002-07-10 Greg McGary * scripts/functions/filter-out: Add literals to to the pattern space in order to add complexity, and trigger use of an internal hash table. Fix documentation strings. * scripts/targets/INTERMEDIATE: Reverse order of files passed to expected `rm' command. 2002-07-10 Greg McGary * Makefile.am (SRCS): Add hash.c (noinst_HEADERS): Add hash.h * hash.c: New file, taken from id-utils. * hash.h: New file, taken from id-utils. * make.h (HASH, HASHI): Remove macros. (find_char_unquote): Change arglist in decl. (hash_init_directories): New function decl. * variable.h (hash.h): New #include. (MAKELEVEL_NAME, MAKELEVEL_LENGTH): New constants. * filedef.h (hash.h): New #include. (struct file) [next]: Remove member. (file_hash_enter): Remove function decl. (init_hash_files): New function decl. * ar.c (ar_name): Delay call to strlen until needed. * main.c (initialize_global_hash_tables): New function. (main): Call it. Use MAKELEVEL_NAME & MAKELEVEL_LENGTH. * misc.c (remove_comments): Pass char constants to find_char_unquote. * remake.c (notice_finished_file): Update last_mtime on `prev' chain. * dir.c (hash.h): New #include. (struct directory_contents) [next, files]: Remove members. [ctime]: Add member for VMS. [dirfiles]: Add hash-table member. (directory_contents_hash_1, directory_contents_hash_2, directory_contents_hash_cmp): New functions. (directories_contents): Change type to `struct hash_table'. (struct directory) [next]: Remove member. (directory_hash_1, directory_hash_2, directory_hash_cmp): New funcs. (directory): Change type to `struct hash_table'. (struct dirfile) [next]: Remove member. [length]: Add member. [impossible]: widen type to fill alignment gap. (dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp): New functions. (find_directory): Use new hash table package. (dir_contents_file_exists_p): Likewise. (file_impossible): Likewise. (file_impossible_p): Likewise. (print_dir_data_base): Likewise. (open_dirstream): Likewise. (read_dirstream): Likewise. (hash_init_directories): New function. * file.c (hash.h): New #include. (file_hash_1, file_hash_2, file_hash_cmp): New functions. (files): Change type to `struct hash_table'. (lookup_file): Use new hash table package. (enter_file): Likewise. (remove_intermediates): Likewise. (snap_deps): Likewise. (print_file_data_base): Likewise. * function.c (function_table_entry_hash_1, function_table_entry_hash_2, function_table_entry_hash_cmp): New functions. (lookup_function): Remove `table' argument. Use new hash table package. (struct a_word) [chain, length]: New members. (a_word_hash_1, a_word_hash_2, a_word_hash_cmp): New functions. (struct a_pattern): New struct. (func_filter_filterout): Pass through patterns noting boundaries and '%', if present. Note a_word length. Use a hash table if arglists are large enough to justify cost. (function_table_init): Renamed from function_table. (function_table): Declare as `struct hash_table'. (FUNCTION_TABLE_ENTRIES): New constant. (hash_init_function_table): New function. * read.c (hash.h): New #include. (read_makefile): Pass char constants to find_char_unquote. (dep_hash_1, dep_hash_2, dep_hash_cmp): New functions. (uniquize_deps): Use hash table to efficiently identify duplicates. (find_char_unquote): Accept two char-constant stop chars, rather than a string constant, avoiding zillions of calls to strchr. Tighten inner search loops to test only for desired delimiters. * variable.c (variable_hash_1, variable_hash_2, variable_hash_cmp): New functions. (variable_table): Declare as `struct hash_table'. (global_variable_set): Remove initialization. (init_hash_global_variable_set): New function. (define_variable_in_set): Use new hash table package. (lookup_variable): Likewise. (lookup_variable_in_set): Likewise. (initialize_file_variables): Likewise. (pop_variable_scope): Likewise. (create_new_variable_set): Likewise. (merge_variable_sets): Likewise. (define_automatic_variables): Likewise. (target_environment): Likewise. (print_variable_set): Likewise. 2002-07-10 Paul D. Smith Implement the SysV make syntax $$@, $$(@D), and $$(@F) in the prerequisite list. A real SysV make will expand the entire prerequisites list _twice_: we don't do that as it's a big backward-compatibility problem. We only replace those specific variables. * read.c (record_files): Replace any $@, $(@D), and $(@F) variable references left in the list of prerequisites. Check for .POSIX as we record targets, so we can disable non-POSIX behavior while reading makefiles as well as running them. (eval): Check the prerequisite list to see if we have anything that looks like a SysV prerequisite variable reference. 2002-07-09 Paul D. Smith * doc/make.texi (Prerequisite Types): Add a new section describing order-only prerequisites. * read.c (uniquize_deps): If we have the same file as both a normal and order-only prereq, get rid of the order-only prereq, since the normal one supersedes it. 2002-07-08 Paul D. Smith * AUTHORS: Added Greg McGary to the AUTHORS file. * NEWS: Blurbed order-only prerequisites. * file.c (print_file): Show order-only deps properly when printing the database. * maintMakefile: Add "update" targets for wget'ing the latest versions of various external files. Taken from Makefile.maint in autoconf, etc. * dosbuild.bat: Somehow we got _double_ ^M's. Remove them. Reported by Eli Zaretskii . 2002-07-07 Paul D. Smith * po/*.po: Remove. We'll use wget to retrieve them at release time. * variable.c (do_variable_definition) [W32]: On W32 using cmd rather than a shell you get an exception. Make sure we look up the variable. Patch provided by Eli Zaretskii . * remake.c (notice_finished_file): Fix handling of -t flag. Patch provided by Henning Makholm . * implicit.c (pattern_search): Some systems apparently run short of stack space, and using alloca() in this function caused an overrun. I modified it to use xmalloc() on the two variables which seemed like they might get large. Fixes Bug #476. * main.c (print_version): Update copyright notice to conform with GNU standards. (print_usage): Update help output. * function.c (func_eval): Create a new make function, $(eval ...). Expand the arguments, put them into a buffer, then invoke eval_buffer() on the resulting string. (func_quote): Create a new function, $(quote VARNAME). Inserts the value of the variable VARNAME without expanding it any further. * read.c (struct ebuffer): Change the linebuffer structure to an "eval buffer", which can be either a file or a buffer. (eval_makefile): Move the code in the old read_makefile() which located a makefile into here: create a struct ebuffer with that information. Have it invoke the new function eval() with that ebuffer. (eval_buffer): Create a new function that creates a struct ebuffer that holds a string buffer instead of a file. Have it invoke eval() with that ebuffer. (eval): New function that contains the guts of the old read_makefile() function: this function parses makefiles. Obtains data to parse from the provided ebuffer. Some modifications to make the flow of the function cleaner and clearer. Still could use some work here... (do_define): Takes a struct ebuffer instead of a FILE*. Read the contents of the define/endef variable from the ebuffer. (readstring): Read the next line from a string-style ebuffer. (readline): Read the next line from an ebuffer. If it's a string ebuffer, invoke readstring(). If it's a FILE* ebuffer, read it from the file. * dep.h (eval_buffer): Prototype eval_buffer(); * variable.c (do_variable_definition): Make sure that all non-target-specific variables are registered in the global set. If we're invoked from an $(eval ...) we might be inside a $(call ...) or other function which has pushed a variable scope; we still want to define our variables from evaluated makefile code in the global scope. 2002-07-03 Greg McGary * dep.h (struct dep) [ignore_mtime]: New member. [changed]: convert to a bitfield. * implicit.c (pattern_search): Zero ignore_mtime. * main.c (main, handle_non_switch_argument): Likewise. * rule.c (convert_suffix_rule): Likewise. * read.c (read_all_makefiles, read_makefile, multi_glob): Likewise. (read_makefile): Parse '|' in prerequisite list. (uniquize_deps): Consider ignore_mtime when comparing deps. * remake.c (update_file_1, check_dep): Don't force remake for dependencies that have d->ignore_mtime. * commands.c (FILE_LIST_SEPARATOR): New constant. (set_file_variables): Don't include a prerequisite in $+, $^ or $? if d->ignore_mtime. Define $|. 2002-06-18 Paul D. Smith * make.texinfo: Updates for next revision. New date/rev/etc. Recreate all Info menus. Change license on the manual to the GNU Free Documentation License. A number of typos. (Variables Simplify): Don't use "-" before it's defined. (Automatic Prerequisites): Rewrite the target example to work properly if the compile fails. Remove incorrect comments about how "set -e" behaves. (Text Functions): Move the "word", "wordlist", "words", and "firstword" functions here, from "File Name Functions". * make-stds.texi: Update from latest GNU version. * fdl.texi: (created) Import the latest GNU version. 2002-06-06 Paul D. Smith * variable.c (do_variable_definition): New function: extract the part of try_variable_definition() that actually sets the value into a separate function. (try_variable_definition): Call do_variable_definition() after parsing the variable definition string. (define_variable_in_set): Make the name argument const. * variable.h (enum variable_flavor): Make public. (do_variable_definition): Create prototype. * read.c (read_all_makefiles): Create a new built-in variable, MAKEFILE_LIST. (read_makefile): Add each makefile read in to this variable value. 2002-05-18 Eli Zaretskii * Makefile.DOS.template: Tweak according to changes in the distribution. Add back the dependencies of *.o files. * configh.dos.template: Synchronize with config.h.in. 2002-05-09 Paul D. Smith * file.c (file_timestamp_now): Use K&R function declaration. * getloadavg.c (getloadavg): Merge setlocale() fix from sh-utils getloadavg.c. Autoconf thinks QNX is SVR4-like, but it isn't, so #undef it. Remove predefined setup of NLIST_STRUCT. Decide whether to include nlist.h based on HAVE_NLIST_H. Change obsolete NLIST_NAME_UNION to new HAVE_STRUCT_NLIST_N_UN_N_NAME. * configure.in (NLIST_STRUCT): Define this if we have nlist.h and nlist.n_name is a pointer rather than an array. * acinclude.m4 (make_FUNC_SETVBUF_REVERSED): Grab the latest version of AC_FUNC_SETVBUF_REVERSED from autoconf CVS. * configure.in: Use it instead of the old version. * main.c (main): Prefer setvbuf() to setlinebuf(). 2002-05-08 Paul D. Smith * Makefile.am (make_LDADD): Add GETLOADAVG_LIBS. (loadavg_LDADD): Ditto. 2002-04-29 Paul D. Smith * expand.c (recursively_expand_for_file): Rename recursively_expand() to recursively_expand_for_file() and provide an extra argument, struct file. If the argument is provided, set the variable scope to that of the file before expanding. * variable.h (recursively_expand): Make this a macro that invokes recursively_expand_for_file() with a NULL file pointer. * variable.c (target_environment): Call the renamed function and provide the current file context. Fixes Debian bug #144306. 2002-04-28 Paul D. Smith Allow $(call ...) user-defined variables to be self-referencing without throwing an error. Allows implementation of transitive closures, among other possibly useful things. Requested by: Philip Guenther * variable.h (struct variable): Add a new field: exp_count, and new macros to hold its size and maximum value. (warn_undefined): Make this a macro. * variable.c (define_variable_in_set): Initialize it. * expand.c (recursively_expand): If we detect recursive expansion of a variable, check the exp_count field. If it's greater than 0 allow the recursion and decrement the count. (warn_undefined): Remove this (now a macro in variable.h). * function.c (func_call): Before we expand the user-defined function, modify its exp_count field to contain the maximum number of recursive calls we'll allow. After the call, reset it to 0. 2002-04-21 Paul D. Smith Modified to use latest autoconf (2.53), automake (1.6.1), and gettext (0.11.1). We're using gettext's new "external" support, to avoid including libintl source with GNU make. * README.cvs: New file. Explain how to build GNU make from CVS. * configure.in: Modify checking for the system glob library. Use AC_EGREP_CPP instead of AC_TRY_CPP. Remove the setting of GLOBDIR (we will always put "glob" in SUBDIRS, so automake etc. will manage it correctly). Set an automake conditional USE_LOCAL_GLOB to decide whether to compile the glob library. * getloadavg.c (main): Include make.h in the "TEST" program to avoid warnings. * Makefile.am: Remove special rules for loadavg. Replace them with Automake capabilities for building extra programs. * signame.c: This file does nothing if the system provide strsignal(). If not, it implements strsignal(). If the system doesn't define sys_siglist, then we make our own; otherwise we use the system version. * signame.h: Removed. * main.c (main): No need to invoke signame_init(). Update copyright. * ABOUT-NLS: Removed. * gettext.c: Removed. * gettext.h: Get a simplified copy from the gettext package. * po/*: Created. * i18n/*.po: Moved to po/. * i18n/: Removed. * config/*: Created. Contains package configuration helper files. * config.guess, config.sub: Moved to config directory. * configure.in (AC_CONFIG_FILES): Add po/Makefile.in, config/Makefile. Rework to use new-style autoconf features. Use the "external" mode for gettext. Make the build.sh config file conditional on whether build.sh.in exists, to avoid autoconf errors. * acinclude.m4: Removed almost all macros as being obsolete. Rewrote remaining macros to use AC_DEFINE. * acconfig.h: Removed. * Makefile.am (EXTRA_DIST): Add config/config.rpath. Use a conditional to handle customs support. Remove special handling for i18n features. 2002-04-20 Paul D. Smith * function.c (func_call): Don't mark the argument variables $1, etc. as recursive. They've already been fully expanded so there's no need to do it again, and doing so strips escaped $'s. Reported by Sebastian Glita . * remake.c (notice_finished_file): Walk through double-colon entries via the prev field, not the next field! Reported by Greg McGary . * main.c (main): If the user specifies -q and asks for a specific target which is a makefile, we got an assert. In that case it turns out we should continue normally instead. * i18n/de.po, i18n/fr.po: Installed an updated translation. * i18n/he.po: Installed a new translation. 2002-01-07 Paul D. Smith * i18n/es.po, i18n/ru.po: Installed an updated translation. 2001-12-04 Paul D. Smith * i18n/ja.po: Installed an updated translation. 2001-09-06 Paul Eggert * configure.in (AC_CHECK_HEADERS): Add sys/resource.h. (AC_CHECK_FUNCS): Add getrlimit, setrlimit. * main.c: Include if it, getrlimit, and setrlimit are available. (main): Get rid of any avoidable limit on stack size. 2001-09-04 Paul D. Smith * i18n/da.po: Installed an updated translation. 2001-08-03 Paul D. Smith * i18n/fr.po: Installed an updated translation. Resolves Debian bug #106720. 2001-06-13 Paul D. Smith * i18n/da.po, configure.in (ALL_LINGUAS): Installed a new translation. 2001-06-11 Paul D. Smith * i18n/ko.po: Installed a new translation. 2001-05-06 Paul D. Smith Modify the EINTR handling. * job.c (new_job): Reorganize the jobserver algorithm. Reorder the way in which we manage the file descriptor/signal handler race trap to be more efficient. 2001-05-06 Paul Eggert Restart almost all system calls that are interrupted, instead of worrying about EINTR. The lone exception is the read() for job tokens. * configure.in (HAVE_SA_RESTART): New macro. (MAKE_JOBSERVER): Define to 1 only if HAVE_SA_RESTART. * main.c (main): Use SA_RESTART instead of the old, nonstandard SA_INTERRUPT. * configure.in (AC_CHECK_FUNCS): Add bsd_signal. * main.c (bsd_signal): New function or macro, if the implementation doesn't supply it. (The bsd_signal function will be in POSIX 1003.1-200x.) (HANDLESIG): Remove. (main, FATAL_SIG): Use bsd_signal instead of signal or HANDLESIG. * make.h (EINTR_SET): Remove. (SA_RESTART): New macro. * arscan.c (ar_member_touch): Don't worry about EINTR. * function.c (func_shell): Likewise. * job.c (reap_children, free_child, new_job): Likewise. * main.c (main): Likewise. * remake.c (touch_file, name_mtime): Likewise. * arscan.c (ar_member_touch): Fix bug uncovered by EINTR removal; if fstat failed with errno!=EINTR, the error was ignored. * job.c (set_child_handler_action_flags): New function. (new_job): Use it to temporarily clear the SIGCHLD action flags while reading the token. 2001-05-02 Paul D. Smith * job.c (start_job_command): Don't add define/endef per-line flags to the top-level flags setting. 2001-04-03 Paul D. Smith * arscan.c (VMS_get_member_info,ar_scan) [VMS]: VMS sets the low bit on error, so check for odd return values, not non-0 return values. (VMS_get_member_info): Calculate the timezone differences correctly. Reported by John Fowler . 2001-03-14 Paul D. Smith * variable.c (lookup_variable) [VMS]: Null-terminate the variable value before invoking define_variable(). Reported by John Fowler . 2001-02-07 Paul D. Smith * read.c (record_target_var): If we reset the variable due to a command-line variable setting overriding it, turn off the "append" flag. 2001-01-17 Paul D. Smith * variable.c (lookup_variable) [VMS]: When getting values from the environment, allocate enough space for the _value_ plus escapes, not enough space for the name plus escapes :-/. Reported by John Fowler . * remake.c (f_mtime): Removed the "***" prefix from the mod time warnings that make generates, so it doesn't look like an error. Reported by Karl Berry . Fix for PR/2020: Rework appended target-specific variables. I'm fairly confident this algorithm is finally correct. * expand.c (allocated_variable_append): Rewrite. Instead of expanding each appended variable then adding all the expanded strings together, we append all the unexpanded values going up through the variable set contexts, then expand the final result. This behaves just like non-target-specific appended variable values, while the old way didn't in various corner cases. (variable_append): New function: recursively append the unexpanded value of a variable, walking from the outermost variable scope to the innermost. * variable.c (lookup_variable): Remove the code that looked up the variable set list if the found variable was "append". We don't need this anymore. (lookup_variable_in_set): Make this non-static so we can use it elsewhere. (try_variable_definition): Use lookup_variable_in_set() rather than faking out current_variable_set_list by hand (cleanup). * variable.h: Add a prototype for the now non-static lookup_variable_in_set(). 2000-11-17 Paul D. Smith * remake.c (f_mtime) [WINDOWS32]: On various advice, I changed the WINDOWS32 port to assume timestamps can be up to 3 seconds away before throwing a fit. 2000-11-17 Paul D. Smith * read.c (readline): CRLF calculations had a hole, if you hit the buffer grow scenario just right. Reworked the algorithm to avoid the need for len or lastlen at all. Problem description with sample code chages provided by Chris Faylor . 2000-10-24 Paul D. Smith * gettext.c (SWAP): Declare this with the prototype, otherwise some systems don't work (non-32-bit? Reported for Cray T3E). Reported by Thorstein Thorsteinsson . 2000-10-05 Paul D. Smith * acinclude.m4 (AM_LC_MESSAGES): Remove undefined macro AM_LC_MESSAGES; it doesn't seem to do anything anyway?? * i18n/gl.po, configure.in (ALL_LINGUAS): New Galician translation. 2000-09-22 Paul D. Smith * gettext.c: Don't #define _GETTEXT_H here; we only include some parts of the real gettext.h here, and we expect to really include the real gettext.h later. If we keep this #define, it's ignored. 2000-09-21 Paul D. Smith * main.c (log_working_directory): Rework the text to use complete sentences, to make life simpler for the translators. 2000-08-29 Paul D. Smith * file.c (remove_intermediates): Print a debug message before we remove intermediate files, so the user (if she uses -d) knows what's going on. 2000-08-21 Paul D. Smith * variable.c (try_variable_definition): Change how we handle target-specific append variable defns: instead of just setting the value, expand it as an append _but_ only within the current target's context. Otherwise we lose all but the last value if the variable is appended more than once within the current target context. Fixes PR/1831. 2000-08-16 Paul D. Smith * function.c (func_shell): Nul-terminate the buffer before printing an exec error message (just in case it's not!). Fixes PR/1860, reported by Joey Hess . 2000-07-25 Paul D. Smith * job.c (construct_command_argv_internal): Add "~" to the list of sh_chars[] which disallow optimizing out the shell call. 2000-07-23 Paul Eggert * NEWS, make.texinfo: Document .LOW_RESOLUTION_TIME, which supersedes --disable-nsec-timestamps. * make.texinfo: Consistently use "time stamp" instead of "timestamp". * README: Remove --disable-nsec-timestamps. * filedef.h (struct file.low_resolution_time): New member. * file.c (snap_deps): Add support for .LOW_RESOLUTION_TIME. * remake.c (update_file_1): Avoid spurious rebuilds due to low resolution time stamps, generalizing the earlier code that applied only to archive members. (f_mtime): Archive members always have low resolution time stamps. * configure.in: Remove --disable-nsec-timestamps, as this has been superseded by .LOW_RESOLUTION_TIME. 2000-07-23 Paul Eggert * configure.in (enable_nsec_timestamps): Renamed from make_cv_nsec_timestamps, since enable/disable options shouldn't be cached. 2000-07-23 Bruno Haible and Paul Eggert * file.c (file_timestamp_now): Use preprocessor-time check for FILE_TIMESTAMP_HI_RES so that clock_gettime is not linked unless needed. * filedef.h (FILE_TIMESTAMP_HI_RES): Remove definition; "configure" now does this. * configure.in (jm_AC_TYPE_UINTMAX_T): Move up, to before high resolution file timestamp check, since that check now uses uintmax_t. (FILE_TIMESTAMP_HI_RES): Define to nonzero if the code should use high resolution file timestamps. (HAVE_CLOCK_GETTIME): Do not define if !FILE_TIMESTAMP_HI_RES, so that we don't link in clock_gettime unnecessarily. 2000-07-17 Paul D. Smith * i18n/ja.po: New version of the translation file. 2000-07-07 Paul D. Smith * remake.c (f_mtime): If NO_FLOAT is defined, don't bother with the offset calculation. (name_mtime): Replace EINTR test with EINTR_SET macro. 2000-07-07 Paul Eggert Fix for PR/1811: * remake.c (update_file_1): Avoid spurious rebuilds of archive members due to their timestamp resolution being only one second. (f_mtime): Avoid spurious warnings of timestamps in the future due to the clock's resolution being lower than file timestamps'. When warning about future timestamps, report only the discrepancy, not the absolute value of the timestamp and the current time. * file.c (file_timestamp_now): New arg RESOLUTION. * filedef.h (file_timestamp_now): Likewise. (FILE_TIMESTAMP_NS): Now returns int. All uses changed. 2000-07-05 Paul D. Smith * variable.c (lookup_variable) [VMS]: Remove vestigial references to listp. Fixes PR/1793. 2000-06-26 Paul Eggert * Makefile.am (MAINTAINERCLEANFILES): New macro, with stamp-pot in it. * dir.c (vms_hash): Ensure ctype macro args are nonnegative. * remake.c (f_mtime): Remove unused var memtime. 2000-06-25 Martin Buchholz * make.texinfo, NEWS, TODO.private: Minor spelling corrections. Ran spell-check on make.texinfo. 2000-06-23 Paul D. Smith * main.c (main): Replace EXIT_SUCCESS, EXIT_FAILURE, and EXIT_TROUBLE with MAKE_SUCCESS, MAKE_FAILURE, and MAKE_TROUBLE. * make.h: Define these macros. * Version 3.79.1 released. * configure.in: Add a new option, --disable-nsec-timestamps, to avoid using sub-second timestamps on systems that support it. It can lead to problems, e.g. if your makefile relies on "cp -p". * README.template: Document the issue with "cp -p". * config.guess, config.sub: Updated. See ChangeLog.2, available in the Git repository at: https://git.savannah.gnu.org/cgit/make.git/tree/ for earlier changes. Copyright (C) 2000-2013 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: Makefile.am ================================================ # This is a -*-Makefile-*-, or close enough # # Copyright (C) 1997-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . AUTOMAKE_OPTIONS = dist-lzip silent-rules std-options subdir-objects nostdinc ACLOCAL_AMFLAGS = -I m4 MAKE_HOST = @MAKE_HOST@ SUBDIRS = lib po doc bin_PROGRAMS = make include_HEADERS = src/gnumake.h man_MANS = doc/make.1 make_SRCS = src/ar.c src/arscan.c src/commands.c src/commands.h \ src/debug.h src/default.c src/dep.h src/dir.c src/expand.c \ src/file.c src/filedef.h src/function.c src/getopt.c \ src/getopt.h src/getopt1.c src/gettext.h src/guile.c \ src/hash.c src/hash.h src/implicit.c src/job.c src/job.h \ src/load.c src/loadapi.c src/main.c src/makeint.h src/misc.c \ src/mkcustom.h src/os.h src/output.c src/output.h src/read.c \ src/remake.c src/rule.c src/rule.h src/shuffle.h src/shuffle.c \ src/signame.c src/strcache.c src/variable.c src/variable.h \ src/version.c src/vpath.c src/warning.c src/warning.h w32_SRCS = src/w32/pathstuff.c src/w32/w32os.c src/w32/compat/dirent.c \ src/w32/compat/posixfcn.c src/w32/include/dirent.h \ src/w32/include/dlfcn.h src/w32/include/pathstuff.h \ src/w32/include/sub_proc.h src/w32/include/w32err.h \ src/w32/subproc/misc.c src/w32/subproc/proc.h \ src/w32/subproc/sub_proc.c src/w32/subproc/w32err.c w32_utf8_SRCS = src/w32/utf8.rc src/w32/utf8.manifest vms_SRCS = src/vms_exit.c src/vms_export_symbol.c src/vms_progname.c \ src/vmsdir.h src/vmsfunctions.c src/vmsify.c glob_SRCS = lib/fnmatch.c lib/fnmatch.h lib/glob.c lib/glob.h alloca_SRCS = lib/alloca.c loadavg_SRCS = lib/getloadavg.c make_SOURCES = $(make_SRCS) EXTRA_make_SOURCES = $(vms_SRCS) if HAVE_GUILE _GUILE_CFLAGS = $(GUILE_CFLAGS) _GUILE_LIBS = $(GUILE_LIBS) else _GUILE_CFLAGS = _GUILE_LIBS = endif make_LDADD = $(LIBOBJS) $(_GUILE_LIBS) lib/libgnu.a $(GETLOADAVG_LIBS) \ @LIBINTL@ localedir = $(datadir)/locale AM_CPPFLAGS = -Isrc -I$(top_srcdir)/src -Ilib -I$(top_srcdir)/lib \ -DLIBDIR=\"$(libdir)\" -DLOCALEDIR=\"$(localedir)\" # If prefix is not a standard location, look in prefix as well if !KNOWN_PREFIX AM_CPPFLAGS += -DINCLUDEDIR=\"$(includedir)\" endif AM_CFLAGS = $(_GUILE_CFLAGS) if WINDOWSENV make_SOURCES += $(w32_SRCS) AM_CPPFLAGS += -I $(top_srcdir)/src/w32/include else make_SOURCES += src/posixos.c endif UTF8OBJ = src/w32/utf8.$(OBJEXT) if HAVE_WINDRES make_LDADD += $(UTF8OBJ) endif $(UTF8OBJ) : $(w32_utf8_SRCS) $(WINDRES) -o $@ -i $< if USE_CUSTOMS make_SOURCES += src/remote-cstms.c else make_SOURCES += src/remote-stub.c endif # Extra stuff to include in the distribution. mk_FILES = Basic.mk mk/msdosdjgpp.mk mk/VMS.mk mk/Windows32.mk # We don't need this, since the standard automake output will do. #mk/Posix.mk.in m4_FILES = m4/gnulib-cache.m4 test_FILES = tests/run_make_tests tests/run_make_tests.bat \ tests/run_make_tests.pl tests/test_driver.pl \ tests/config-flags.pm.in tests/config_flags_pm.com \ tests/config-flags.pm.W32 \ tests/mkshadow tests/thelp.pl tests/guile.supp tests/README # test/scripts are added via dist-hook below. EXTRA_DIST = ChangeLog INSTALL README build.sh build.cfg.in $(man_MANS) \ src/mkconfig.h README.customs README.OS2 README.zOS \ README.DOS builddos.bat src/configh.dos \ README.W32 build_w32.bat src/config.h.W32 \ README.VMS makefile.com src/config.h-vms src/vmsjobs.c \ vms_export_symbol_test.com \ src/gmk-default.scm src/gmk-default.h \ $(mk_FILES) $(m4_FILES) $(test_FILES) $(w32_utf8_SRCS) # --------------- Generate the Guile default module content src/guile.$(OBJEXT): src/gmk-default.h src/gmk-default.h: $(top_srcdir)/src/gmk-default.scm (echo 'static const char *const GUILE_module_defn = " '\\ \ && sed -e 's/;.*//' -e '/^[ \t]*$$/d' -e 's/"/\\"/g' -e 's/$$/ \\/' \ $(top_srcdir)/src/gmk-default.scm \ && echo '";') > src/gmk-default.h # --------------- Local DIST Section # Install the mk and tests subdirectories # dist-hook: (cd $(top_srcdir); \ sub=`find tests/scripts -follow \( -name .git -o -name .deps -o -name work -o -name .gitignore -o -name \*.orig -o -name \*.rej -o -name \*~ -o -name \*.out -o -name Makefile \) -prune -o -type f -print`; \ $(AMTAR) chf - $$sub) \ | (cd $(distdir); $(AMTAR) xfBp -) # --------------- Local CHECK Section check-local: check-regression @banner=" Regression PASSED: $(PACKAGE_STRING) ($(MAKE_HOST)) built with $(CC) "; \ dashes=`echo "$$banner" | sed s/./=/g`; \ echo; \ echo "$$dashes"; \ echo "$$banner"; \ echo "$$dashes"; \ echo # > check-regression # # Look for the make test suite, and run it if found and we can find perl. # MAKETESTFLAGS = .PHONY: check-regression GMK_OUTDIR = .. testlog = test-suite.log testresult = tests/.test-result errorpre = makeerror-$(PACKAGE_VERSION)-$(host_triplet) testfiles = $(testlog) $(testresult) $(errorfile) MOSTLYCLEANFILES = $(testfiles) errordetails = config.status config.log src/config.h src/mkconfig.h \ $(testlog) tests/work # Create a 4-letter random sequence rand_value = c = "abcdefghijklmnopqrstuvwxyz0123456789" rand_char = substr(c,int(rand()*36),1) rand_string = $(AWK) 'BEGIN{srand(); $(rand_value); print $(rand_char) "" $(rand_char) "" $(rand_char) "" $(rand_char);}' check-regression: tests/config-flags.pm $(AM_V_at) rm -f $(testfiles) $(AM_V_at) if test -f '$(top_srcdir)/tests/run_make_tests.pl'; then \ ulimit -n 128; \ if $(PERL) -v >/dev/null 2>&1; then \ echo "cd tests && $(PERL) $(PERLFLAGS) $(abs_top_srcdir)/tests/run_make_tests.pl -make $(GMK_OUTDIR)/make$(EXEEXT) $(MAKETESTFLAGS)"; \ (cd tests && $(PERL) $(PERLFLAGS) '$(abs_top_srcdir)/tests/run_make_tests.pl' -make '$(GMK_OUTDIR)/make$(EXEEXT)' $(MAKETESTFLAGS); echo $$? >.test-result) 2>&1 | tee $(testlog); \ export TAR_OPTIONS='$(filter-out --sort%,$(TAR_OPTIONS))'; \ er=$$(cat $(testresult)); if test "$$er" -ne 0; then \ dirnm="$(errorpre)-$$($(rand_string))"; fnm="$$dirnm.tar.gz"; \ rm -rf "$$dirnm"; mkdir "$$dirnm"; \ $(AMTAR) chf - $(errordetails) | (cd "$$dirnm"; $(AMTAR) xf -); \ $(AMTAR) chf - "$$dirnm" | eval GZIP= gzip $(GZIP_ENV) -c >"$$fnm"; \ echo "*** Testing FAILED! Details: $$fnm"; \ echo '*** Please report to <$(PACKAGE_BUGREPORT)>'; echo; \ exit $$er; \ fi; \ else \ echo "Can't find a working Perl ($(PERL)); the test suite requires Perl."; \ fi; \ else \ echo "Can't find the $(PACKAGE_NAME) test suite ($(top_srcdir)/tests)."; \ fi # --------------- Maintainer's Section # Tell automake that I haven't forgotten about this file and it will be # created before we build a distribution (see maintMakefile in the Git # distribution). README: @MAINT_MAKEFILE@ ================================================ FILE: NEWS ================================================ GNU Make NEWS -*-indented-text-*- History of user-visible changes. 26 February 2023 See the end of this file for copyrights and conditions. All user-visible changes are more fully described in the GNU Make manual, which is contained in this distribution as the file doc/make.texi. See the README file and the GNU Make manual for instructions for reporting bugs. Version 4.4.90 (26 Feb 2023) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=111&set=custom * WARNING: Removed AmigaOS support! This version of GNU Make no longer supports AmigaOS. If you need support for AmigaOS please use one of the older versions of GNU Make. * WARNING: Loaded Object ABI incompatibility! This release changes the loaded object feature from "technology preview" to fully-supported feature. However, it introduces an ABI incompatibility with previous releases: the setup function now takes an ABI version as its first argument. At compile time you can test the GMK_ABI_VERSION constant to detect which ABI should be used. At runtime your initialization function can check the provided ABI version to verify it's being loaded correctly. * WARNING: Backward-incompatibility! Parsing of the first argument in ifeq/ifneq with () has been cleaned up. When locating the separating "," any variable reference (single char as well as using $() or ${}) is skipped. However parentheses that are not part of or contained in variable references will not be counted. This means that things like "ifeq ((foo,bar),)" are now syntax errors. Use a variable to hide the comma if needed: "COMMA = ," / "ifeq ((foo$(COMMA)bar),)". See https://savannah.gnu.org/bugs/index.php?64402 * WARNING: Backward-incompatibility! If -e is given all environment variables will now have an origin of "environment override" even if they are not otherwise set in the makefile. See https://savannah.gnu.org/bugs/index.php?64803 * WARNING: Backward-incompatibility! The behavior of appending to pattern-specific variables has been clarified when combined with command-line settings or -e overrides. See https://savannah.gnu.org/bugs/index.php?64822 * NOTE: Deprecated behavior. The check in GNU Make 4.3 for suffix rules with prerequisites didn't check single-suffix rules, only double-suffix rules. Add the missing check. * New feature: Any assignment operator can be made conditional GNU Make has long supported the conditional operator "?=" which creates a recursive variable set to a value if and only if the variable is not already defined. In this release, the "?" can precede any assignment operator to make it conditional. For example, "?:=" creates a simply-expanded variable and expands the right-hand side if and only if the variable is not already defined. The constructs "?::=", "?:::=", and "?!=" also behave as expected. * New feature: Unload function for loaded objects When a loaded object needs to be unloaded by GNU Make, it will invoke an unload function (if one is defined) beforehand that allows the object to perform cleanup operations. Original idea and implementation: Dmitry Goncharov * New feature: Makefile warning reporting control A new option "--warn" controls reporting of warnings for makefiles. Actions can be set to "ignore", "warn", or "error". Two new warnings are reported: assigning to invalid variable names, and referencing invalid variable names (both set to "warn" by default), in addition to the existing warning for undefined variables (defaults to "ignore"). "--warn-undefined-variables" is deprecated, and is translated to "--warn=undefined-vars" internally. * New feature: Control warnings with the .WARNINGS variable In addition to --warn from the command line, which takes effect for make invoked recursively, warnings can be controlled only for the current instance of make using the .WARNINGS variable. * New feature: Printing targets defined by the makefile A new option "--print-targets" will print all explicit, non-special targets defined in the makefiles, one per line, then exit with success. No recipes are invoked and no makefiles are re-built. * Warnings for detecting circular dependencies are controllable via warning reporting, with the name "circular-dep". * 'make --print-data-base' (or 'make -p') now outputs time of day using the same form as for file timestamps, e.g., "2023-05-10 10:43:57.570558743". Previously it used the form "Wed May 10 10:43:57 2023", which has less detail and is harder to compare. * Conditional statements starting with the recipe prefix were sometimes interpreted in previous versions. As per the documentation, lines starting with the recipe prefix are now never considered conditional statements. * Tests in the regression test suite now are run in their own directory to avoid cross-contamination and allow cleanup if the tests are interrupted. More information is printed about failing tests. Version 4.4.1 (26 Feb 2023) This release is primarily a bug-fix release. A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=110&set=custom * WARNING: Backward-incompatibility! In previous releases it was not well-defined when updates to MAKEFLAGS made inside a makefile would be visible. This release ensures they are visible immediately, even when invoking $(shell ...) functions. Also, command line variable assignments are now always present in MAKEFLAGS, even when parsing makefiles. Implementation provided by Dmitry Goncharov * New feature: Parallel builds of archives Previously it was not possible to use parallel builds with archives. It is still not possible using the built-in rules, however you can now override the built-in rules with a slightly different set of rules and use parallel builds with archive creation. See the "Dangers When Using Archives" section of the GNU Make manual, and https://savannah.gnu.org/bugs/index.php?14927 * Previously target-specific variables would inherit their "export" capability from parent target-specific variables even if they were marked private. Now private parent target-specific variables have no affect. For more details see https://savannah.gnu.org/bugs/index.php?61463 * Disable FIFO jobserver on GNU/Hurd and Cygwin Experimentation shows that the new FIFO-based jobserver doesn't work well on GNU/Hurd or Cygwin: revert these systems to use the pipe-based jobserver. * Updates to allow building on OS/2 Provided by KO Myung-Hun * New platform: GNU Make is supported on z/OS Thanks to Igor Todorovski for the patches and testing assistance. Version 4.4 (31 Oct 2022) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=109&set=custom * WARNING: Deprecation! The following systems are deprecated in this release: - OS/2 (EMX) - AmigaOS - Xenix - Cray In the NEXT release of GNU Make, support for these systems will be removed. If you want to see them continue to be supported, contact . * WARNING: Future backward-incompatibility! In the NEXT release of GNU Make, pattern rules will implement the same behavior change for multiple targets as explicit grouped targets, below: if any target of the rule is needed by the build, the recipe will be invoked if any target of the rule is missing or out of date. During testing some makefiles were found to contain pattern rules that do not build all targets; this can cause issues so we are delaying this change for one release cycle to allow these makefiles to be updated. GNU Make shows a warning if it detects this situation: "pattern recipe did not update peer target". * WARNING: Backward-incompatibility! GNU Make now uses temporary files in more situations than previous releases. If your build system sets TMPDIR (or TMP or TEMP on Windows) and deletes the contents during the build, or uses restrictive permissions, this may cause problems. You can choose an alternative temporary directory only for use by GNU Make by setting the new MAKE_TMPDIR environment variable before invoking make. Note that this value CANNOT be set inside the makefile, since make needs to find its temporary directory before the makefiles are parsed. * WARNING: Backward-incompatibility! Previously each target in a explicit grouped target rule was considered individually: if the targets needed by the build were not out of date the recipe was not run even if other targets in the group were out of date. Now if any of the grouped targets are needed by the build, then if any of the grouped targets are out of date the recipe is run and all targets in the group are considered updated. * WARNING: Backward-incompatibility! Previously if --no-print-directory was seen anywhere in the environment or command line it would take precedence over any --print-directory. Now, the last setting of directory printing options seen will be used, so a command line such as "--no-print-directory -w" _will_ show directory entry/exits. * WARNING: Backward-incompatibility! Previously the order in which makefiles were remade was not explicitly stated, but it was (roughly) the inverse of the order in which they were processed by make. In this release, the order in which makefiles are rebuilt is the same order in which make processed them, and this is defined to be true in the GNU Make manual. * WARNING: Backward-incompatibility! Previously only simple (one-letter) options were added to the MAKEFLAGS variable that was visible while parsing makefiles. Now, all options are available in MAKEFLAGS. If you want to check MAKEFLAGS for a one-letter option, expanding "$(firstword -$(MAKEFLAGS))" is a reliable way to return the set of one-letter options which can be examined via findstring, etc. * WARNING: Backward-incompatibility! Previously makefile variables marked as export were not exported to commands started by the $(shell ...) function. Now, all exported variables are exported to $(shell ...). If this leads to recursion during expansion, then for backward-compatibility the value from the original environment is used. To detect this change search for 'shell-export' in the .FEATURES variable. * WARNING: New build requirement GNU Make utilizes facilities from GNU Gnulib: Gnulib requires certain C99 features in the C compiler and so these features are required by GNU Make: https://www.gnu.org/software/gnulib/manual/html_node/C99-features-assumed.html The configure script should verify the compiler has these features. * New feature: The .WAIT special target If the .WAIT target appears between two prerequisites of a target, then GNU Make will wait for all of the targets to the left of .WAIT in the list to complete before starting any of the targets to the right of .WAIT. This feature is available in some other versions of make, and it will be required by an upcoming version of the POSIX standard for make. Different patches were made by Alexey Neyman (2005) and Steffen Nurpmeso (2020) that were useful but the result is a different implementation (closer to Alexey's idea). * New feature: .NOTPARALLEL accepts prerequisites If the .NOTPARALLEL special target has prerequisites then all prerequisites of those targets will be run serially (as if .WAIT was specified between each prerequisite). * New feature: The .NOTINTERMEDIATE special target .NOTINTERMEDIATE disables intermediate behavior for specific files, for all files built using a pattern, or for the entire makefile. Implementation provided by Dmitry Goncharov * New feature: The $(let ...) function This function allows user-defined functions to define a set of local variables: values can be assigned to these variables from within the user-defined function and they will not impact global variable assignments. Implementation provided by Jouke Witteveen * New feature: The $(intcmp ...) function This function allows conditional evaluation controlled by a numerical comparison. Implementation provided by Jouke Witteveen * New feature: Improved support for -l / --load-average On systems that provide /proc/loadavg (Linux), GNU Make will use it to determine the number of runnable jobs and use this as the current load, avoiding the need for heuristics. Implementation provided by Sven C. Dack * New feature: The --shuffle command line option This option reorders goals and prerequisites to simulate non-determinism that may be seen using parallel build. Shuffle mode allows a form of "fuzz testing" of parallel builds to verify that all prerequisites are correctly described in the makefile. Implementation provided by Sergei Trofimovich * New feature: The --jobserver-style command line option and named pipes A new jobserver method is used on systems where mkfifo(3) is supported. This solves a number of obscure issues related to using the jobserver and recursive invocations of GNU Make. This change means that sub-makes will connect to the jobserver even if they are not marked as recursive. It also means that other tools that want to participate in the jobserver will need to be enhanced as described in the GNU Make manual. You can force GNU Make to use the simple pipe-based jobserver (perhaps if you are integrating with other tools or older versions of GNU Make) by adding the '--jobserver-style=pipe' option to the command line of the top-level invocation of GNU Make, or via MAKEFLAGS or GNUMAKEFLAGS. To detect this change search for 'jobserver-fifo' in the .FEATURES variable. * Some POSIX systems (*BSD) do not allow locks to be taken on pipes, which caused the output sync feature to not work properly there. Also multiple invocations of make redirecting to the same output file (e.g., /dev/null) would cause hangs. Instead of locking stdout (which does have some useful performance characteristics, but is not portable) create a temporary file and lock that. Windows continues to use a mutex as before. * GNU Make has sometimes chosen unexpected, and sub-optimal, chains of implicit rules due to the definition of "ought to exist" in the implicit rule search algorithm, which considered any prerequisite mentioned in the makefile as "ought to exist". This algorithm has been modified to prefer prerequisites mentioned explicitly in the target being built and only if that results in no matching rule, will GNU Make consider prerequisites mentioned in other targets as "ought to exist". Implementation provided by Dmitry Goncharov * GNU Make was performing secondary expansion of all targets, even targets which didn't need to be considered during the build. In this release only targets which are considered will be secondarily expanded. Implementation provided by Dmitry Goncharov * If the MAKEFLAGS variable is modified in a makefile, it will be re-parsed immediately rather than after all makefiles have been read. Note that although all options are parsed immediately, some special effects won't appear until after all makefiles are read. * The -I option accepts an argument "-" (e.g., "-I-") which means "reset the list of search directories to empty". Among other things this can be used to prevent GNU Make from searching in its default list of directories. * New debug option "print" will show the recipe to be run, even when silent mode is set, and new debug option "why" will show why a target is rebuilt (which prerequisites caused the target to be considered out of date). Implementation provided by David Boyce * The existing --trace option is made equivalent to --debug=print,why * Target-specific variables can now be marked "unexport". * Exporting / unexporting target-specific variables is handled correctly, so that the attribute of the most specific variable setting is used. * Special targets like .POSIX are detected upon definition, ensuring that any change in behavior takes effect immediately, before the next line is parsed. * When the pipe-based jobserver is enabled and GNU Make decides it is invoking a non-make sub-process and closes the jobserver pipes, it will now add a new option to the MAKEFLAGS environment variable that disables the jobserver. This prevents sub-processes that invoke make from accidentally using other open file descriptors as jobserver pipes. For more information see https://savannah.gnu.org/bugs/?57242 and https://savannah.gnu.org/bugs/?62397 * A long-standing issue with the directory cache has been resolved: changes made as a side-effect of some other target's recipe are now noticed as expected. * GNU Make can now be built for MS-Windows using the Tiny C tcc compiler. Port provided by Christian Jullien Version 4.3 (19 Jan 2020) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=108&set=custom * WARNING: Backward-incompatibility! Number signs (#) appearing inside a macro reference or function invocation no longer introduce comments and should not be escaped with backslashes: thus a call such as: foo := $(shell echo '#') is legal. Previously the number sign needed to be escaped, for example: foo := $(shell echo '\#') Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable: H := \# foo := $(shell echo '$H') This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable. * WARNING: Backward-incompatibility! Previously appending using '+=' to an empty variable would result in a value starting with a space. Now the initial space is only added if the variable already contains some value. Similarly, appending an empty string does not add a trailing space. * WARNING: Backward-incompatibility! Previously using the .SILENT pseudo-target in a makefile would force all sub-makes to be invoked with the '-s' option, effectively making all sub-makes silent as well. In this release .SILENT only affects the current invocation of make. A side-effect of this is that .SILENT will no longer enable the --no-print-directory option, which using -s will do. * NOTE: Deprecated behavior. Contrary to the documentation, suffix rules with prerequisites are being treated BOTH as simple targets AND as pattern rules. Further, the prerequisites are ignored by the pattern rules. POSIX specifies that in order to be a suffix rule there can be no prerequisites defined. In this release if POSIX mode is enabled then rules with prerequisites cannot be suffix rules. If POSIX mode is not enabled then the previous behavior is preserved (a pattern rule with no extra prerequisites is created) AND a warning about this behavior is generated: warning: ignoring prerequisites on suffix rule definition The POSIX behavior will be adopted as the only behavior in a future release of GNU Make so please resolve any warnings. * New feature: Grouped explicit targets Pattern rules have always had the ability to generate multiple targets with a single invocation of the recipe. It's now possible to declare that an explicit rule generates multiple targets with a single invocation. To use this, replace the ":" token with "&:" in the rule. To detect this feature search for 'grouped-target' in the .FEATURES special variable. Implementation contributed by Kaz Kylheku * New feature: .EXTRA_PREREQS variable Words in this variable are considered prerequisites of targets but they are not added to any of the automatic variable values when expanding the recipe. This variable can either be global (applies to all targets) or a target-specific variable. To detect this feature search for 'extra-prereqs' in the .FEATURES special variable. Implementation contributed by Christof Warlich * Makefiles can now specify the '-j' option in their MAKEFLAGS variable and this will cause make to enable that parallelism mode. * GNU Make will now use posix_spawn() on systems where it is available. If you prefer to use fork/exec even on systems where posix_spawn() is present, you can use the --disable-posix-spawn option to configure. Implementation contributed by Aron Barath * Error messages printed when invoking non-existent commands have been cleaned up and made consistent. * The previous limit of 63 jobs under -jN on MS-Windows is now increased to 4095. That limit includes the subprocess started by the $(shell) function. * A new option --no-silent has been added, that cancels the effect of the -s/--silent/--quiet flag. * A new option -E has been added as a short alias for --eval. * All wildcard expansion within GNU Make, including $(wildcard ...), will sort the results. See https://savannah.gnu.org/bugs/index.php?52076 * Interoperate with newer GNU libc and musl C runtime libraries. * Performance improvements provided by Paolo Bonzini GNU Make Developer News * Import the GNU standard bootstrap script to replace the hand-rolled "make update" method for building code from a GNU Make Git repository. * Rework the source distribution to move source files into the src/* subdirectory. This aligns with modern best practices in GNU. * Replace local portability code with Gnulib content. Unfortunately due to a problem with Gnulib support for getloadavg, this forces a requirement on Automake 1.16 or above in order to build from Git. See README.git. Version 4.2.1 (10 Jun 2016) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=107&set=custom This release is a bug-fix release. Version 4.2 (22 May 2016) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=106&set=custom * New variable: $(.SHELLSTATUS) is set to the exit status of the last != or $(shell ...) function invoked in this instance of make. This will be "0" if successful or not "0" if not successful. The variable value is unset if no != or $(shell ...) function has been invoked. * The $(file ...) function can now read from a file with $(file * The interface to GNU Make's "jobserver" is stable as documented in the manual, for tools which may want to access it. WARNING: Backward-incompatibility! The internal-only command line option --jobserver-fds has been renamed for publishing, to --jobserver-auth. * The amount of parallelism can be determined by querying MAKEFLAGS, even when the job server is enabled (previously MAKEFLAGS would always contain only "-j", with no number, when job server was enabled). * VMS-specific changes: * Perl test harness now works. * Full support for converting Unix exit status codes to VMS exit status codes. BACKWARD INCOMPATIBILITY Notice: On a child failure the VMS exit code is now the encoded Unix exit status that Make usually generates, not the VMS exit status of the child. Version 4.1 (05 Oct 2014) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=105&set=custom * New variables: $(MAKE_TERMOUT) and $(MAKE_TERMERR) are set to non-empty values if stdout or stderr, respectively, are believed to be writing to a terminal. These variables are exported by default. * Allow a no-text-argument form of the $(file ...) function. Without a text argument nothing is written to the file: it is simply opened in the requested mode, then closed again. * Change the fatal error for mixed explicit and implicit rules, that was introduced in GNU Make 3.82, to a non-fatal error. However, this syntax is still deprecated and may return to being illegal in a future version of GNU make. Makefiles that rely on this syntax should be fixed. See https://savannah.gnu.org/bugs/?33034 * VMS-specific changes: * Support for library files added, including support for using the GNV ar utility. * Partial support for properly encoding Unix exit status codes into VMS exit status codes. WARNING: Backward-incompatibility! These are different exit status codes than Make exited with in the past. * Macros to hold the current make command are set up to translate the argv[0] string to a VMS format path name and prefix it with "MCR " so that the macro has a space in it. WARNING: Backward-incompatibility! This may break complex makefiles that do processing on those macros. This is unlikely because so much in that area was not and is still not currently working on VMS, it is unlikely to find such a complex makefile, so this is more likely to impact construction of a future makefile. * A command file is always used to run the commands for a recipe. WARNING: Backward-incompatibility! Running the make self tests has exposed that there are significant differences in behavior when running with the command file mode. It is unknown if this will be noticed by most existing VMS makefiles. Version 4.0 (09 Oct 2013) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=101&set=custom * WARNING: Backward-incompatibility! If .POSIX is specified, then make adheres to the POSIX backslash/newline handling requirements, which introduces the following changes to the standard backslash/newline handling in non-recipe lines: * Any trailing space before the backslash is preserved * Each backslash/newline (plus subsequent whitespace) is converted to a single space * New feature: GNU Guile integration This version of GNU Make can be compiled with GNU Guile integration. GNU Guile serves as an embedded extension language for make. See the "Guile Function" section in the GNU Make manual for details. Currently GNU Guile 1.8 and 2.0+ are supported. In Guile 1.8 there is no support for internationalized character sets. In Guile 2.0+, scripts can be encoded in UTF-8. * New command line option: --output-sync (-O) enables grouping of output by target or by recursive make. This is useful during parallel builds to avoid mixing output from different jobs together giving hard-to-understand results. Original implementation by David Boyce . Reworked and enhanced by Frank Heckenbach . Windows support by Eli Zaretskii . * New command line option: --trace enables tracing of targets. When enabled the recipe to be invoked is printed even if it would otherwise be suppressed by .SILENT or a "@" prefix character. Also before each recipe is run the makefile name and linenumber where it was defined are shown as well as the prerequisites that caused the target to be considered out of date. * New command line option argument: --debug now accepts a "n" (none) flag which disables all debugging settings that are currently enabled. * New feature: The "job server" capability is now supported on Windows. Implementation contributed by Troy Runkel * New feature: The .ONESHELL capability is now supported on Windows. Support added by Eli Zaretskii . * New feature: "!=" shell assignment operator as an alternative to the $(shell ...) function. Implemented for compatibility with BSD makefiles. Note there are subtle differences between "!=" and $(shell ...). See the description in the GNU Make manual. WARNING: Backward-incompatibility! Variables ending in "!" previously defined as "variable!= value" will now be interpreted as shell assignment. Change your assignment to add whitespace between the "!" and "=": "variable! = value" * New feature: "::=" simple assignment operator as defined by POSIX in 2012. This operator has identical functionality to ":=" in GNU Make, but will be portable to any implementation of make conforming to a sufficiently new version of POSIX (see https://austingroupbugs.net/view.php?id=330). It is not necessary to define the .POSIX target to access this operator. * New feature: Loadable objects This version of GNU Make contains a "technology preview": the ability to load dynamic objects into the make runtime. These objects can be created by the user and can add extended functionality, usable by makefiles. * New function: $(file ...) writes to a file. * New variable: $(GNUMAKEFLAGS) will be parsed for make flags, just like MAKEFLAGS is. It can be set in the environment or the makefile, containing GNU Make-specific flags to allow your makefile to be portable to other versions of make. Once this variable is parsed, GNU Make will set it to the empty string so that flags will not be duplicated on recursion. * New variable: `MAKE_HOST' gives the name of the host architecture make was compiled for. This is the same value you see after 'Built for' when running 'make --version'. * Behavior of MAKEFLAGS and MFLAGS is more rigorously defined. All simple flags are grouped together in the first word of MAKEFLAGS. No options that accept arguments appear in the first word. If no simple flags are present MAKEFLAGS begins with a space. Flags with both short and long versions always use the short versions in MAKEFLAGS. Flags are listed in alphabetical order using ASCII ordering. MFLAGS never begins with "- ". * Setting the -r and -R options in MAKEFLAGS inside a makefile now works as expected, removing all built-in rules and variables, respectively. * If a recipe fails, the makefile name and linenumber of the recipe are shown. * A .RECIPEPREFIX setting is remembered per-recipe and variables expanded in that recipe also use that recipe prefix setting. * In -p output, .RECIPEPREFIX settings are shown and all target-specific variables are output as if in a makefile, instead of as comments. * On MS-Windows, recipes that use ".." quoting will no longer force invocation of commands via temporary batch files and stock Windows shells, they will be short-circuited and invoked directly. (In other words, " is no longer a special character for stock Windows shells.) This avoids hitting shell limits for command length when quotes are used, but nothing else in the command requires the shell. This change could potentially mean some minor incompatibilities in behavior when the recipe uses quoted string on shell command lines. Version 3.82 (28 Jul 2010) A complete list of bugs fixed in this version is available here: https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=104&set=custom * Compiling GNU Make now requires a conforming ISO C 1989 compiler and standard runtime library. * WARNING: Backward-incompatibility! The POSIX standard for make was changed in the 2008 version in a fundamentally incompatible way: make is required to invoke the shell as if the '-e' flag were provided. Because this would break many makefiles that have been written to conform to the original text of the standard, the default behavior of GNU Make remains to invoke the shell with simply '-c'. However, any makefile specifying the .POSIX special target will follow the new POSIX standard and pass '-e' to the shell. See also .SHELLFLAGS below. * WARNING: Backward-incompatibility! The '$?' variable now contains all prerequisites that caused the target to be considered out of date, even if they do not exist (previously only existing targets were provided in $?). * WARNING: Backward-incompatibility! Wildcards were not documented as returning sorted values, but the results have been sorted up until this release.. If your makefiles require sorted results from wildcard expansions, use the $(sort ...) function to request it explicitly. * WARNING: Backward-incompatibility! As a result of parser enhancements, three backward-compatibility issues exist: first, a prerequisite containing an "=" cannot be escaped with a backslash any longer. You must create a variable containing an "=" and use that variable in the prerequisite. Second, variable names can no longer contain whitespace, unless you put the whitespace in a variable and use the variable. Third, in previous versions of make it was sometimes not flagged as an error for explicit and pattern targets to appear in the same rule. Now this is always reported as an error. * WARNING: Backward-incompatibility! The pattern-specific variables and pattern rules are now applied in the shortest stem first order instead of the definition order (variables and rules with the same stem length are still applied in the definition order). This produces the usually-desired behavior where more specific patterns are preferred. To detect this feature search for 'shortest-stem' in the .FEATURES special variable. * WARNING: Backward-incompatibility! The library search behavior has changed to be compatible with the standard linker behavior. Prior to this version for prerequisites specified using the -lfoo syntax make first searched for libfoo.so in the current directory, vpath directories, and system directories. If that didn't yield a match, make then searched for libfoo.a in these directories. Starting with this version make searches first for libfoo.so and then for libfoo.a in each of these directories in order. * New command line option: --eval=STRING causes STRING to be evaluated as makefile syntax (akin to using the $(eval ...) function). The evaluation is performed after all default rules and variables are defined, but before any makefiles are read. * New special variable: .RECIPEPREFIX allows you to reset the recipe introduction character from the default (TAB) to something else. The first character of this variable value is the new recipe introduction character. If the variable is set to the empty string, TAB is used again. It can be set and reset at will; recipes will use the value active when they were first parsed. To detect this feature check the value of $(.RECIPEPREFIX). * New special variable: .SHELLFLAGS allows you to change the options passed to the shell when it invokes recipes. By default the value will be "-c" (or "-ec" if .POSIX is set). * New special target: .ONESHELL instructs make to invoke a single instance of the shell and provide it with the entire recipe, regardless of how many lines it contains. As a special feature to allow more straightforward conversion of makefiles to use .ONESHELL, any recipe line control characters ('@', '+', or '-') will be removed from the second and subsequent recipe lines. This happens _only_ if the SHELL value is deemed to be a standard POSIX-style shell. If not, then no interior line control characters are removed (as they may be part of the scripting language used with the alternate SHELL). * New variable modifier 'private': prefixing a variable assignment with the modifier 'private' suppresses inheritance of that variable by prerequisites. This is most useful for target- and pattern-specific variables. * New make directive: 'undefine' allows you to undefine a variable so that it appears as if it was never set. Both $(flavor) and $(origin) functions will return 'undefined' for such a variable. To detect this feature search for 'undefine' in the .FEATURES special variable. * The parser for variable assignments has been enhanced to allow multiple modifiers ('export', 'override', 'private') on the same line as variables, including define/endef variables, and in any order. Also, it is possible to create variables and targets named as these modifiers. * The 'define' make directive now allows a variable assignment operator after the variable name, to allow for simple, conditional, or appending multi-line variable assignment. * VMS-specific changes: * Michael Gehre (at VISTEC-SEMI dot COM) supplied a fix for a problem with timestamps of object modules in OLBs. The timestamps were not correctly adjusted to GMT based time, if the local VMS time was using a daylight saving algorithm and if daylight saving was switched off. * John Eisenbraun (at HP dot COM) supplied fixes and and an enhancement to append output redirection in action lines. * Rework of ctrl+c and ctrl+y handling. * Fix a problem with cached strings, which showed on case-insensitive file systems. * Build fixes for const-ified code in VMS specific sources. * A note on appending the redirected output. With this change, a simple mechanism is implemented to make ">>" work in action lines. In VMS there is no simple feature like ">>" to have DCL command or program output redirected and appended to a file. GNU Make for VMS already implements the redirection of output. If such a redirection is detected, an ">" on the action line, GNU Make creates a DCL command procedure to execute the action and to redirect its output. Based on that, now ">>" is also recognized and a similar but different command procedure is created to implement the append. The main idea here is to create a temporary file which collects the output and which is appended to the wanted output file. Then the temporary file is deleted. This is all done in the command procedure to keep changes in make small and simple. This obviously has some limitations but it seems good enough compared with the current ">" implementation. (And in my opinion, redirection is not really what GNU Make has to do.) With this approach, it may happen that the temporary file is not yet appended and is left in SYS$SCRATCH. The temporary file names look like "CMDxxxxx.". Any time the created command procedure can not complete, this happens. Pressing Ctrl+Y to abort make is one case. In case of Ctrl+Y the associated command procedure is left in SYS$SCRATCH as well. Its name is CMDxxxxx.COM. * Change in the Ctrl+Y handling. The CtrlY handler now uses $delprc to delete all children. This way also actions with DCL commands will be stopped. As before the CtrlY handler then sends SIGQUIT to itself, which is handled in common code. * Change in deleteing temporary command files. Temporary command files are now deleted in the vms child termination handler. That deletes them even if a Ctrl+C was pressed. * The behavior of pressing Ctrl+C is not changed. It still has only an effect, after the current action is terminated. If that doesn't happen or takes too long, Ctrl+Y should be used instead. Version 3.81 (01 Apr 2006) * GNU Make is ported to OS/2. * GNU Make is ported to MinGW. The MinGW build is only supported by the build_w32.bat batch file; see the file README.W32 for more details. * WARNING: Future backward-incompatibility! Up to and including this release, the '$?' variable does not contain any prerequisite that does not exist, even though that prerequisite might have caused the target to rebuild. Starting with the _next_ release of GNU Make, '$?' will contain all prerequisites that caused the target to be considered out of date. See https://savannah.gnu.org/bugs/?16051 * WARNING: Backward-incompatibility! GNU Make now implements a generic "second expansion" feature on the prerequisites of both explicit and implicit (pattern) rules. In order to enable this feature, the special target '.SECONDEXPANSION' must be defined before the first target which takes advantage of it. If this feature is enabled then after all rules have been parsed the prerequisites are expanded again, this time with all the automatic variables in scope. This means that in addition to using standard SysV $$@ in prerequisites lists, you can also use complex functions such as $$(notdir $$@) etc. This behavior applies to implicit rules, as well, where the second expansion occurs when the rule is matched. However, this means that when '.SECONDEXPANSION' is enabled you must double-quote any "$" in your filenames; instead of "foo: boo$$bar" you now must write "foo: foo$$$$bar". Note that the SysV $$@ etc. feature, which used to be available by default, is now ONLY available when the .SECONDEXPANSION target is defined. If your makefiles take advantage of this SysV feature you will need to update them. * WARNING: Backward-incompatibility! In order to comply with POSIX, the way in which GNU Make processes backslash-newline sequences in recipes has changed. If your makefiles use backslash-newline sequences inside of single-quoted strings in recipes you will be impacted by this change. See the GNU Make manual subsection "Splitting Recipe Lines" (node "Splitting Lines"), in section "Recipe Syntax", chapter "Writing Recipe in Rules", for details. * WARNING: Backward-incompatibility! Some previous versions of GNU Make had a bug where "#" in a function invocation such as $(shell ...) was treated as a make comment. A workaround was to escape these with backslashes. This bug has been fixed: if your makefile uses "\#" in a function invocation the backslash is now preserved, so you'll need to remove it. * New command line option: -L (--check-symlink-times). On systems that support symbolic links, if this option is given then GNU Make will use the most recent modification time of any symbolic links that are used to resolve target files. The default behavior remains as it always has: use the modification time of the actual target file only. * The "else" conditional line can now be followed by any other valid conditional on the same line: this does not increase the depth of the conditional nesting, so only one "endif" is required to close the conditional. * All pattern-specific variables that match a given target are now used (previously only the first match was used). * Target-specific variables can be marked as exportable using the "export" keyword. * In a recursive $(call ...) context, any extra arguments from the outer call are now masked in the context of the inner call. * Implemented a solution for the "thundering herd" problem with "-j -l". This version of GNU Make uses an algorithm suggested by Thomas Riedl to track the number of jobs started in the last second and artificially adjust GNU Make's view of the system's load average accordingly. * New special variables available in this release: - .INCLUDE_DIRS: Expands to a list of directories that make searches for included makefiles. - .FEATURES: Contains a list of special features available in this version of GNU Make. - .DEFAULT_GOAL: Set the name of the default goal make will use if no goals are provided on the command line. - MAKE_RESTARTS: If set, then this is the number of times this instance of make has been restarted (see "How Makefiles Are Remade" in the manual). - New automatic variable: $| (added in 3.80, actually): contains all the order-only prerequisites defined for the target. * New functions available in this release: - $(lastword ...) returns the last word in the list. This gives identical results as $(word $(words ...) ...), but is much faster. - $(abspath ...) returns the absolute path (all "." and ".." directories resolved, and any duplicate "/" characters removed) for each path provided. - $(realpath ...) returns the canonical pathname for each path provided. The canonical pathname is the absolute pathname, with all symbolic links resolved as well. - $(info ...) prints its arguments to stdout. No makefile name or line number info, etc. is printed. - $(flavor ...) returns the flavor of a variable. - $(or ...) provides a short-circuiting OR conditional: each argument is expanded. The first true (non-empty) argument is returned; no further arguments are expanded. Expands to empty if there are no true arguments. - $(and ...) provides a short-circuiting AND conditional: each argument is expanded. The first false (empty) argument is returned; no further arguments are expanded. Expands to the last argument if all arguments are true. * Changes made for POSIX compatibility: - Only touch targets (under -t) if they have a recipe. - Setting the SHELL make variable does NOT change the value of the SHELL environment variable given to programs invoked by make. As an enhancement to POSIX, if you export the make variable SHELL then it will be set in the environment, just as before. * On MS Windows systems, explicitly setting SHELL to a pathname ending in "cmd" or "cmd.exe" (case-insensitive) will force GNU Make to use the DOS command interpreter in batch mode even if a UNIX-like shell could be found on the system. * On VMS there is now support for case-sensitive filesystems such as ODS5. See the README.VMS file for information. * Parallel builds (-jN) no longer require a working Bourne shell on Windows platforms. They work even with the stock Windows shells, such as cmd.exe and command.com. * Updated to autoconf 2.59, automake 1.9.5, and gettext 0.14.1. Users should not be impacted. * New translations for Swedish, Chinese (simplified), Ukrainian, Belarusian, Finnish, Kinyarwandan, and Irish. Many updated translations. A complete list of bugs fixed in this version is available here: https://savannah.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=103 Version 3.80 (03 Oct 2002) * A new feature exists: order-only prerequisites. These prerequisites affect the order in which targets are built, but they do not impact the rebuild/no-rebuild decision of their dependents. That is to say, they allow you to require target B be built before target A, without requiring that target A will always be rebuilt if target B is updated. Patch for this feature provided by Greg McGary . * For compatibility with SysV make, GNU Make now supports the peculiar syntax $$@, $$(@D), and $$(@F) in the prerequisites list of a rule. This syntax is only valid within explicit and static pattern rules: it cannot be used in implicit (suffix or pattern) rules. Edouard G. Parmelan provided a patch implementing this feature; however, I decided to implement it in a different way. * The argument to the "ifdef" conditional is now expanded before it's tested, so it can be a constructed variable name. Similarly, the arguments to "export" (when not used in a variable definition context) and "unexport" are also now expanded. * A new function is defined: $(value ...). The argument to this function is the _name_ of a variable. The result of the function is the value of the variable, without having been expanded. * A new function is defined: $(eval ...). The arguments to this function should expand to makefile commands, which will then be evaluated as if they had appeared in the makefile. In combination with define/endef multiline variable definitions this is an extremely powerful capability. The $(value ...) function is also sometimes useful here. * A new built-in variable is defined, $(MAKEFILE_LIST). It contains a list of each makefile GNU Make has read, or started to read, in the order in which they were encountered. So, the last filename in the list when a makefile is just being read (before any includes) is the name of the current makefile. * A new built-in variable is defined: $(.VARIABLES). When it is expanded it returns a complete list of variable names defined by all makefiles at that moment. * A new command line option is defined, -B or --always-make. If specified GNU Make will consider all targets out-of-date even if they would otherwise not be. * The arguments to $(call ...) functions were being stored in $1, $2, etc. as recursive variables, even though they are fully expanded before assignment. This means that escaped dollar signs ($$ etc.) were not behaving properly. Now the arguments are stored as simple variables. This may mean that if you added extra escaping to your $(call ...) function arguments you will need to undo it now. * The variable invoked by $(call ...) can now be recursive: unlike other variables it can reference itself and this will not produce an error when it is used as the first argument to $(call ...) (but only then). * New pseudo-target .LOW_RESOLUTION_TIME, superseding the configure option --disable-nsec-timestamps. You might need this if your build process depends on tools like "cp -p" preserving time stamps, since "cp -p" (right now) doesn't preserve the subsecond portion of a time stamp. * Updated translations for French, Galician, German, Japanese, Korean, and Russian. New translations for Croatian, Danish, Hebrew, and Turkish. * Updated internationalization support to Gettext 0.11.5. GNU Make now uses Gettext's "external" feature, and does not include any internationalization code itself. Configure will search your system for an existing implementation of GNU Gettext (only GNU Gettext is acceptable) and use it if it exists. If not, NLS will be disabled. See ABOUT-NLS for more information. * Updated to autoconf 2.54 and automake 1.7. Users should not be impacted. * VMS-specific changes: * In default.c define variable ARCH as IA64 for VMS on Itanium systems. * In makefile.vms avoid name collision for glob and globfree. * This is the VMS port of GNU Make done by Hartmut.Becker@compaq.com. It is based on the specific version 3.77k and on 3.78.1. 3.77k was done by Klaus Kämpf , the code was based on the VMS port of GNU Make 3.60 by Mike Moretti. It was ported on OpenVMS/Alpha V7.1, DECC V5.7-006. It was re-build and tested on OpenVMS/Alpha V7.2, OpenVMS/VAX 7.1 and 5.5-2. Different versions of DECC were used. VAXC was tried: it fails; but it doesn't seem worth to get it working. There are still some PTRMISMATCH warnings during the compile. Although perl is working on VMS the test scripts don't work. The function $shell is still missing. There is a known bug in some of the VMS CRTLs. It is in the shipped versions of VMS V7.2 and V7.2-1 and in the currently (October 1999) available ECOs for VMS V7.1 and newer versions. It is fixed in versions shipped with newer VMS versions and all ECO kits after October 1999. It only shows up during the daylight saving time period (DST): stat() returns a modification time 1 hour ahead. This results in GNU Make warning messages. For a just created source you will see: $ gmake x.exe gmake.exe;1: *** Warning: File 'x.c' has modification time in the future (940582863 > 940579269) cc /obj=x.obj x.c link x.obj /exe=x.exe gmake.exe;1: *** Warning: Clock skew detected. Your build may be incomplete. A complete list of bugs fixed in this version is available here: https://savannah.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=102 Version 3.79.1 (23 Jun 2000) * .SECONDARY with no prerequisites now prevents any target from being removed because make thinks it's an intermediate file, not just those listed in the makefile. * New configure option --disable-nsec-timestamps, but this was superseded in later versions by the .LOW_RESOLUTION_TIME pseudo-target. Version 3.79 (04 Apr 2000) * GNU Make optionally supports internationalization and locales via the GNU gettext (or local gettext if suitable) package. See the ABOUT-NLS file for more information on configuring GNU Make for NLS. * Previously, GNU Make quoted variables such as MAKEFLAGS and MAKEOVERRIDES for proper parsing by the shell. This allowed them to be used within make build scripts. However, using them there is not proper behavior: they are meant to be passed to subshells via the environment. Unfortunately the values were not quoted properly to be passed through the environment. This meant that make didn't properly pass some types of command line values to submakes. With this version we change that behavior: now these variables are quoted properly for passing through the environment, which is the correct way to do it. If you previously used these variables explicitly within a make rule you may need to re-examine your use for correctness given this change. * A new pseudo-target .NOTPARALLEL is available. If defined, the current makefile is run serially regardless of the value of -j. However, submakes are still eligible for parallel execution. * The --debug option has changed: it now allows optional flags controlling the amount and type of debugging output. By default only a minimal amount information is generated, displaying the names of "normal" targets (not makefiles) that were deemed out of date and in need of being rebuilt. Note that the -d option behaves as before: it takes no arguments and all debugging information is generated. * The `-p' (print database) output now includes filename and linenumber information for variable definitions, to aid debugging. * The wordlist function no longer reverses its arguments if the "start" value is greater than the "end" value. If that's true, nothing is returned. * Hartmut Becker provided many updates for the VMS port of GNU Make. See the README.VMS file for more details. * VMS-specific changes: * Fix a problem with automatically remaking makefiles. GNU Make uses an execve to restart itself after a successful remake of the makefile. On UNIX systems execve replaces the running program with a new one and resets all signal handling to the default. On VMS execve creates a child process, signal and exit handlers of the parent are still active, and, unfortunately, corrupt the exit code from the child. Fix in job.c: ignore SIGCHLD. * Added some switches to reflect latest features of DECC. Modifications in makefile.vms. * Set some definitions to reflect latest features of DECC. Modifications in config.h-vms (which is copied to config.h). * Added extern strcmpi declaration to avoid 'implicitly declared' messages. Modification in make.h. * Default rule for C++, conditionals for gcc (GCC_IS_NATIVE) or DEC/Digital/ Compaq c/c++ compilers. Modifications in default.c. * Usage of opendir() and friends, suppress file version. Modifications in dir.c. * Added VMS specific code to handle ctrl+c and ctrl+y to abort make. Modifications in job.c. * Added support to have case sensitive targets and dependencies but to still use case blind file names. This is especially useful for Java makefiles on VMS: .SUFFIXES : .SUFFIXES : .class .java .java.class : javac "$< HelloWorld.class : HelloWorld.java * A new macro WANT_CASE_SENSITIVE_TARGETS in config.h-vms was introduced. It needs to be enabled to get this feature; default is disabled. The macro HAVE_CASE_INSENSITIVE_FS must not be touched: it is still enabled. Modifications in file.c and config.h-vms. * Bootstrap make to start building make is still makefile.com, but make needs to be re-made with a make to make a correct version: ignore all possible warnings, delete all objects, rename make.exe to a different name and run it. * Made some minor modifications to the bootstrap build makefile.com. Version 3.78 (22 Sep 1999) * Two new functions, $(error ...) and $(warning ...) are available. The former will cause make to fail and exit immediately upon expansion of the function, with the text provided as the error message. The latter causes the text provided to be printed as a warning message, but make proceeds normally. * A new function $(call ...) is available. This allows users to create their own parameterized macros and invoke them later. Original implementation of this function was provided by Han-Wen Nienhuys . * A new function $(if ...) is available. It provides if-then-else capabilities in a builtin function. Original implementation of this function was provided by Han-Wen Nienhuys . * Make defines a new variable, .LIBPATTERNS. This variable controls how library dependency expansion (dependencies like ``-lfoo'') is performed. * Make accepts CRLF sequences as well as traditional LF, for compatibility with makefiles created on other operating systems. * Make accepts a new option: -R, or --no-builtin-variables. This option disables the definition of the rule-specific builtin variables (CC, LD, AR, etc.). Specifying this option forces -r (--no-builtin-rules) as well. * A "job server" feature, suggested by Howard Chu . On systems that support POSIX pipe(2) semantics, GNU Make can now pass -jN options to submakes rather than forcing them all to use -j1. The top make and all its sub-make processes use a pipe to communicate with each other to ensure that no more than N jobs are started across all makes. To get the old behavior of -j back, you can configure make with the --disable-job-server option. * The confusing term "dependency" has been replaced by the more accurate and standard term "prerequisite", both in the manual and in all GNU Make output. * GNU Make supports the "big archive" library format introduced in AIX 4.3. * GNU Make supports large files on AIX, HP-UX, and IRIX. These changes were provided by Paul Eggert . (Large file support for Solaris and Linux was introduced in 3.77, but the configuration had issues: these have also been resolved). * The Windows 95/98/NT (W32) version of GNU Make now has native support for the Cygnus Cygwin release B20.1 shell (bash). * The GNU Make regression test suite, long available separately "under the table", has been integrated into the release. You can invoke it by running "make check" in the distribution. Note that it requires Perl (either Perl 4 or Perl 5) to run. Version 3.77 (28 Jul 1998) * Implement BSD make's "?=" variable assignment operator. The variable is assigned the specified value only if that variable is not already defined. * Make defines a new variable, "CURDIR", to contain the current working directory (after the -C option, if any, has been processed). Modifying this variable has no effect on the operation of make. * Make defines a new default RCS rule, for new-style master file storage: ``% :: RCS/%'' (note no ``,v'' suffix). Make defines new default rules for DOS-style C++ file naming conventions, with ``.cpp'' suffixes. All the same rules as for ``.cc'' and ``.C'' suffixes are provided, along with LINK.cpp and COMPILE.cpp macros (which default to the same value as LINK.cc and COMPILE.cc). Note CPPFLAGS is still C preprocessor flags! You should use CXXFLAGS to change C++ compiler flags. * A new feature, "target-specific variable values", has been added. This is a large change so please see the appropriate sections of the manual for full details. Briefly, syntax like this: TARGET: VARIABLE = VALUE defines VARIABLE as VALUE within the context of TARGET. This is similar to SunOS make's "TARGET := VARIABLE = VALUE" feature. Note that the assignment may be of any type, not just recursive, and that the override keyword is available. COMPATIBILITY: This new syntax means that if you have any rules where the first or second dependency has an equal sign (=) in its name, you'll have to escape them with a backslash: "foo : bar\=baz". Further, if you have any dependencies which already contain "\=", you'll have to escape both of them: "foo : bar\\\=baz". * A new appendix listing the most common error and warning messages generated by GNU Make, with some explanation, has been added to the GNU Make User's Manual. * Updates to the GNU Make Customs library support (see README.customs). * Updates to the Windows 95/NT port from Rob Tulloh (see README.W32), and to the DOS port from Eli Zaretski (see README.DOS). * VMS-specific changes: * This is the VMS port of GNU Make. It is based on the VMS port of GNU Make 3.60 by Mike Moretti. This port was done by Klaus Kämpf * There is first-level support available from proGIS Software, Germany. Visit their web-site at https://www.progis.de to get information about other vms software and forthcoming updates to gnu make. * /bin/sh style I/O redirection is supported. You can now write lines like mcr sys$disk:[]program.exe < input.txt > output.txt &> error.txt * Makefile variables are looked up in the current environment. You can set symbols or logicals in DCL and evaluate them in the Makefile via $(). Variables defined in the Makefile override VMS symbols/logicals ! * Functions for file names are working now. See the GNU Make manual for $(dir ...) and $(wildcard ...). Unix-style and VMS-style names are supported as arguments. * The default rules are set up for GNU C. Building an executable from a single source file is as easy as 'make file.exe'. * The variable $(ARCH) is predefined as ALPHA or VAX resp. Makefiles for different VMS systems can now be written by checking $(ARCH) as in ifeq ($(ARCH),ALPHA) $(ECHO) "On the Alpha" else $(ECHO) "On the VAX" endif * Command lines of excessive length are correctly broken and written to a batch file in sys$scratch for later execution. There's no limit to the lengths of commands (and no need for .opt files :-) any more. * Empty commands are handled correctly and don't end in a new DCL process. Version 3.76.1 (19 Sep 1997) * Small (but serious) bug fix. Quick rollout to get into the GNU source CD. Version 3.76 (16 Sep 1997) * GNU Make now uses automake to control Makefile.in generation. This should make it more consistent with the GNU standards. * VPATH functionality has been changed to incorporate the VPATH+ patch, previously maintained by Paul Smith . See the manual. * Make defines a new variable, `MAKECMDGOALS', to contain the goals that were specified on the command line, if any. Modifying this variable has no effect on the operation of make. * A new function, `$(wordlist S,E,TEXT)', is available: it returns a list of words from number S to number E (inclusive) of TEXT. * Instead of an error, detection of future modification times gives a warning and continues. The warning is repeated just before GNU Make exits, so it is less likely to be lost. * Fix the $(basename) and $(suffix) functions so they only operate on the last filename, not the entire string: Command Old Result New Result ------- ---------- ---------- $(basename a.b) a a $(basename a.b/c) a a.b/c $(suffix a.b) b b $(suffix a.b/c) b/c * The $(strip) function now removes newlines as well as TABs and spaces. * The $(shell) function now changes CRLF (\r\n) pairs to a space as well as newlines (\n). * Updates to the Windows 95/NT port from Rob Tulloh (see README.W32). * Eli Zaretskii has updated the port to 32-bit protected mode on MSDOS and MS-Windows, building with the DJGPP v2 port of GNU C/C++ compiler and utilities. See README.DOS for details, and direct all questions concerning this port to Eli Zaretskii or DJ Delorie . * VMS-specific changes: * John W. Eaton has updated the VMS port to support libraries and VPATH. * The cd command is supported if it's called as $(CD). This invokes the 'builtin_cd' command which changes the directory. Calling 'set def' doesn't do the trick, since a sub-shell is spawned for this command, the directory is changed *in this sub-shell* and the sub-shell ends. * Libraries are not supported. They were in GNU Make 3.60 but somehow I didn't care porting the code. If there is enough interest, I'll do it at some later time. * The variable $^ separates files with commas instead of spaces (It's the natural thing to do for VMS). * See defaults.c for VMS default suffixes and my definitions for default rules and variables. * The shell function is not implemented yet. * Load average routines haven't been implemented for VMS yet. * The default include directory for including other makefiles is SYS$SYSROOT:[SYSLIB] (I don't remember why I didn't just use SYS$LIBRARY: instead; maybe it wouldn't work that way). * The default makefiles make looks for are: makefile.vms, gnumakefile, makefile., and gnumakefile. . * The stat() function and handling of time stamps in VMS is broken, so I replaced it with a hack in vmsfunctions.c. I will provide a full rewrite somewhere in the future. Be warned, the time resolution inside make is less than what vms provides. This might be a problem on the faster Alphas. * You can use a : in a filename only if you precede it with a backslash ('\'). E.g.- hobbes\:[bogas.files] * Make ignores success, informational, or warning errors (-S-, -I-, or -W-). But it will stop on -E- and -F- errors. (unless you do something to override this in your makefile, or whatever). * Remote stuff isn't implemented yet. * Multiple line DCL commands, such as "if" statements, must be put inside command files. You can run a command file by using \@. Version 3.75 (27 Aug 1996) * The directory messages printed by `-w' and implicitly in sub-makes, are now omitted if Make runs no commands and has no other messages to print. * Make now detects files that for whatever reason have modification times in the future and gives an error. Files with such impossible timestamps can result from unsynchronized clocks, or archived distributions containing bogus timestamps; they confuse Make's dependency engine thoroughly. * The new directive `sinclude' is now recognized as another name for `-include', for compatibility with some other Makes. * Aaron Digulla has contributed a port to AmigaDOS. See README.Amiga for details, and direct all Amiga-related questions to . * Rob Tulloh of Tivoli Systems has contributed a port to Windows NT or 95. See README.W32 for details, and direct all Windows-related questions to . * VMS-specific changes: * Lots of default settings are adapted for VMS. See default.c. * Long command lines are now converted to command files. * Comma (',') as a separator is now allowed. See makefile.vms for an example. Version 3.73 (05 Apr 1995) * Converted to use Autoconf version 2, so `configure' has some new options. See INSTALL for details. * You can now send a SIGUSR1 signal to Make to toggle printing of debugging output enabled by -d, at any time during the run. Version 3.72 (04 Nov 1994) * DJ Delorie has ported Make to MS-DOS using the GO32 extender. He is maintaining the DOS port, not the GNU Make maintainer; please direct bugs and questions for DOS to . MS-DOS binaries are available for FTP from ftp.simtel.net in /pub/simtelnet/gnu/djgpp/. * The `MAKEFLAGS' variable (in the environment or in a makefile) can now contain variable definitions itself; these are treated just like command line variable definitions. Make will automatically insert any variable definitions from the environment value of `MAKEFLAGS' or from the command line, into the `MAKEFLAGS' value exported to children. The `MAKEOVERRIDES' variable previously included in the value of `$(MAKE)' for sub-makes is now included in `MAKEFLAGS' instead. As before, you can reset `MAKEOVERRIDES' in your makefile to avoid putting all the variables in the environment when its size is limited. * If `.DELETE_ON_ERROR' appears as a target, Make will delete the target of a rule if it has changed when its recipe exits with a nonzero status, just as when the recipe gets a signal. * The automatic variable `$+' is new. It lists all the dependencies like `$^', but preserves duplicates listed in the makefile. This is useful for linking rules, where library files sometimes need to be listed twice in the link order. * You can now specify the `.IGNORE' and `.SILENT' special targets with dependencies to limit their effects to those files. If a file appears as a dependency of `.IGNORE', then errors will be ignored while running the recipe to update that file. Likewise if a file appears as a dependency of `.SILENT', then the recipe to update that file will not be printed before it is run. (This change was made to conform to POSIX.2.) Version 3.71 (21 May 1994) * The automatic variables `$(@D)', `$(%D)', `$(*D)', `$(. ================================================ FILE: README.DOS ================================================ Port of GNU Make to 32-bit protected mode on MSDOS and MS-Windows. Builds with DJGPP v2 port of GNU C/C++ compiler and utilities. New (since 3.74) DOS-specific features: 1. Supports long filenames when run from DOS box on Windows 9x. 2. Supports both stock DOS COMMAND.COM and Unix-style shells (details in 'Notes' below). 3. Supports DOS drive letters in dependencies and pattern rules. 4. Better support for DOS-style backslashes in pathnames (but see 'Notes' below). 5. The $(shell) built-in can run arbitrary complex commands, including pipes and redirection, even when COMMAND.COM is your shell. 6. Can be built without floating-point code (see below). 7. Supports signals in child programs and restores the original directory if the child was interrupted. 8. Can be built without (a previous version of) Make. 9. The build process requires only standard tools. (Optional targets like "check:" still need additional programs, though, see below.) 10. Beginning with v3.78, the test suite works in the DJGPP environment (requires Perl and auxiliary tools; see below). To install a binary distribution: Simply unzip the makNNNb.zip file (where NNN is the version number) preserving the directory structure (-d switch if you use PKUNZIP). If you are installing Make on Windows 9X or Windows 2000, use an unzip program that supports long filenames in zip files. After unzipping, make sure the directory with make.exe is on your PATH, and that's all you need to use Make. To build from sources: 1. Unzip the archive, preserving the directory structure (-d switch if you use PKUNZIP). If you build Make on Windows 9X or Windows 2000, use an unzip program that supports long filenames in zip files. If you are unpacking an official GNU source distribution, use either DJTAR (which is part of the DJGPP development environment), or the DJGPP port of GNU Tar. 2. If you have a working Make already, you can run: make -f Basic.mk 3. If you don't have a working Make already you can bootstrap one by running: .\builddos.bat 4. If you are building from outside of the source directory, you need to tell Make where the sources are, like this: make -f c:/djgpp/gnu/make/Basic.mk SRCDIR=c:/djgpp/gnu/make or: c:/djgpp/gnu/make/builddos.bat c:/djgpp/gnu/make 5. To run the test suite, type "make check". This requires a Unix shell (I used the DJGPP port of Bash 2.03), Perl, Sed, Fileutils and Sh-utils. 6. To install copy make.exe to the preferred location. Since GNU Make 4.3, support for customized platform installations has been removed. If you'd like to collaborate on reinstating these capabilities, contact bug-make@gnu.org. Notes: ----- 1. The shell issue. This is probably the most significant improvement, first introduced in the port of GNU Make 3.75. The original behavior of GNU Make is to invoke commands directly, as long as they don't include characters special to the shell or internal shell commands, because that is faster. When shell features like redirection or filename wildcards are involved, Make calls the shell. This port supports both DOS shells (the stock COMMAND.COM and its 4DOS/NDOS replacements), and Unix-style shells (tested with the venerable Stewartson's 'ms_sh' 2.3 and the DJGPP port of 'bash' by Daisuke Aoyama ). When the $SHELL variable points to a Unix-style shell, Make works just like you'd expect on Unix, calling the shell for any command that involves characters special to the shell or internal shell commands. The only difference is that, since there is no standard way to pass command lines longer than the infamous DOS 126-character limit, this port of Make writes the command line to a temporary disk file and then invokes the shell on that file. If $SHELL points to a DOS-style shell, however, Make will not call it automatically, as it does with Unix shells. Stock COMMAND.COM is too dumb and would unnecessarily limit the functionality of Make. For example, you would not be able to use long command lines in commands that use redirection or pipes. Therefore, when presented with a DOS shell, this port of Make will emulate most of the shell functionality, like redirection and pipes, and shall only call the shell when a batch file or a command internal to the shell is invoked. (Even when a command is an internal shell command, Make will first search the $PATH for it, so that if a Makefile calls 'mkdir', you can install, say, a port of GNU 'mkdir' and have it called in that case.) The key to all this is the extended functionality of 'spawn' and 'system' functions from the DJGPP library; this port just calls 'system' where it would invoke the shell on Unix. The most important aspect of these functions is that they use a special mechanism to pass long (up to 16KB) command lines to DJGPP programs. In addition, 'system' emulates some internal commands, like 'cd' (so that you can now use forward slashes with it, and can also change the drive if the directory is on another drive). Another aspect worth mentioning is that you can call Unix shell scripts directly, provided that the shell whose name is mentioned on the first line of the script is installed anywhere along the $PATH. It is impossible to tell here everything about these functions; refer to the DJGPP library reference for more details. The $(shell) built-in is implemented in this port by calling 'popen'. Since 'popen' calls 'system', the above considerations are valid for $(shell) as well. In particular, you can put arbitrary complex commands, including pipes and redirection, inside $(shell), which is in many cases a valid substitute for the Unix-style command substitution (`command`) feature. 2. "SHELL=/bin/sh" -- or is it? Many Unix Makefiles include a line which sets the SHELL, for those versions of Make which don't have this as the default. Since many DOS systems don't have 'sh' installed (in fact, most of them don't even have a '/bin' directory), this port takes such directives with a grain of salt. It will only honor such a directive if the basename of the shell name (like 'sh' in the above example) can indeed be found in the directory that is mentioned in the SHELL= line ('/bin' in the above example), or in the current working directory, or anywhere on the $PATH (in that order). If the basename doesn't include a filename extension, Make will look for any known extension that indicates an executable file (.exe, .com, .bat, .btm, .sh, and even .sed and .pl). If any such file is found, then $SHELL will be defined to the exact pathname of that file, and that shell will hence be used for the rest of processing. But if the named shell is *not* found, the line which sets it will be effectively ignored, leaving the value of $SHELL as it was before. Since a lot of decisions that this port makes depend on the gender of the shell, I feel it doesn't make any sense to tailor Make's behavior to a shell which is nowhere to be found. Note that the above special handling of "SHELL=" only happens for Makefiles; if you set $SHELL in the environment or on the Make command line, you are expected to give the complete pathname of the shell, including the filename extension. The default value of $SHELL is computed as on Unix (see the Make manual for details), except that if $SHELL is not defined in the environment, $COMSPEC is used. Also, if an environment variable named $MAKESHELL is defined, it takes precedence over both $COMSPEC and $SHELL. Note that, unlike Unix, $SHELL in the environment *is* used to set the shell (since on MSDOS, it's unlikely that the interactive shell will not be suitable for Makefile processing). The bottom line is that you can now write Makefiles where some of the targets require a real (i.e. Unix-like) shell, which will nevertheless work when such shell is not available (provided, of course, that the commands which should always work, don't require such a shell). More important, you can convert Unix Makefiles to MSDOS and leave the line which sets the shell intact, so that people who do have Unixy shell could use it for targets which aren't converted to DOS (like 'install' and 'uninstall', for example). 3. Default directories. GNU Make knows about standard directories where it searches for library and include files mentioned in the Makefile. Since MSDOS machines don't have standard places for these, this port will search ${DJDIR}/lib and ${DJDIR}/include respectively. $DJDIR is defined automatically by the DJGPP startup code as the root of the DJGPP installation tree (unless you've tampered with the DJGPP.ENV file). This should provide reasonable default values, unless you moved parts of DJGPP to other directories. 4. Letter-case in filenames. If you run Make on Windows 9x, you should be aware of the letter-case issue. Make is internally case-sensitive, but all file operations are case-insensitive on Windows 9x, so e.g. files 'FAQ', 'faq' and 'Faq' all refer to the same file, as far as Windows is concerned. The underlying DJGPP C library functions honor the letter-case of the filenames they get from the OS, except that by default, they down-case 8+3 DOS filenames which are stored in upper case in the directory and would break many Makefiles otherwise. (The details of which filenames are converted to lower case are explained in the DJGPP libc docs, under the '_preserve_fncase' and '_lfn_gen_short_fname' functions, but as a thumb rule, any filename that is stored in upper case in the directory, is a valid DOS 8+3 filename and doesn't include characters invalid on MSDOS FAT filesystems, will be automatically down-cased.) User reports that I have indicate that this default behavior is generally what you'd expect; however, your input is most welcome. In any case, if you hit a situation where you must force Make to get the 8+3 DOS filenames in upper case, set FNCASE=y in the environment or in the Makefile. 5. DOS-style pathnames. There are a lot of places throughout the program sources which make implicit assumptions about the pathname syntax. In particular, the directories are assumed to be separated by '/', and any pathname which doesn't begin with a '/' is assumed to be relative to the current directory. This port attempts to support DOS-style pathnames which might include the drive letter and use backslashes instead of forward slashes. However, this support is not complete; I feel that pursuing this support too far might break some more important features, particularly if you use a Unix-style shell (where a backslash is a quote character). I only consider support of backslashes desirable because some Makefiles invoke non-DJGPP programs which don't understand forward slashes. A notable example of such programs is the standard programs which come with MSDOS. Otherwise, you are advised to stay away from backslashes whenever possible. In particular, filename globbing won't work on pathnames with backslashes, because the GNU 'glob' library doesn't support them (backslash is special in filename wildcards, and I didn't want to break that). One feature which *does* work with backslashes is the filename- related built-in functions such as $(dir), $(notdir), etc. Drive letters in pathnames are also fully supported. Bug reports: ----------- Bugs that are clearly related to the MSDOS/DJGPP port should be reported first on the comp.os.msdos.djgpp news group (if you cannot post to Usenet groups, write to the DJGPP mailing list, , which is an email gateway into the above news group). For other bugs, please follow the procedure explained in the "Bugs" chapter of the Info docs. If you don't have an Info reader, look up that chapter in the 'make.i1' file with any text browser/editor. Enjoy, Eli Zaretskii ------------------------------------------------------------------------------- Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: README.OS2 ================================================ Port of GNU Make to OS/2. Features of GNU Make that do not work under OS/2: - remote job execution - dynamic load balancing Special features of the OS/2 version: Due to the fact that some people might want to use sh syntax in Makefiles while others might want to use OS/2's native shell cmd.exe, GNU Make supports both shell types. The following list defines the order that is used to determine the shell: 1. The shell specified by the environment variable MAKESHELL. 2. The shell specified by the SHELL variable within a Makefile. Like Unix, SHELL is NOT taken from the environment. 3. The shell specified by the COMSPEC environment variable. 4. The shell specified by the OS2_SHELL environment variable. 5. If none of the above is defined /bin/sh is used as default. This happens e.g. in the make testsuite. Note: - Points 3 and 4 can be turned off at compile time by adding -DNO_CMD_DEFAULT to the CPPFLAGS. - DOS support is not tested for EMX and therefore might not work. - The UNIXROOT environment variable is supported to find /bin/sh if it is not on the current drive. COMPILATION OF GNU MAKE FOR OS/2: I. ***** SPECIAL OPTIONS ***** - At compile time you can turn off that cmd is used as default shell (but only /bin/sh). Simply set CPPFLAGS="-DNO_CMD_DEFAULT" and make will not use cmd unless you cause it to do so by setting MAKESHELL to cmd or by specifying SHELL=cmd in your Makefile. - At compile time you can set CPPFLAGS="-DNO_CHDIR2" to turn off that GNU Make prints drive letters. This is necessary if you want to run the testsuite. II. ***** REQUIREMENTS FOR THE COMPILATION ***** A standard Unix like build environment: - sh compatible shell (ksh, bash, ash, but tested only with pdksh 5.2.14 release 2) If you use pdksh it is recommended to update to 5.2.14 release 2. Older versions may not work! You can get this version at https://www.math.ohio-state.edu/~ilya/software/os2/pdksh-5.2.14-bin-2.zip - GNU file utilities (make sure that install.exe from the file utilities is in front of your PATH before X:\OS2\INSTALL\INSTALL.EXE. I recommend also to change the filename to ginstall.exe instead of install.exe to avoid confusion with X:\OS2\INSTALL\INSTALL.EXE) - GNU shell utilities - GNU text utilities - gawk - grep - sed - GNU Make 3.79.1 (special OS/2 patched version) or higher - perl 5.005 or higher - GNU texinfo (you can use 3.1 (gnuinfo.zip), but I recommend 4.0) If you want to recreate the configuration files (developers only!) you need also: GNU m4 1.4, autoconf 2.59, automake 1.9.6 (or compatible) III. ***** COMPILATION AND INSTALLATION ***** a) ** Developers only - Everyone else should skip this section ** To recreate the configuration files use: export EMXSHELL=ksh aclocal -I m4 automake autoconf autoheader b) Installation into x:/usr Note: Although it is possible to compile make using "./configure", "make", "make install" this is not recommended. In particular, you must ALWAYS use LDFLAGS="-Zstack 0x6000" because the default stack size is far to small and make will not work properly! Recommended environment variables and installation options: export ac_executable_extensions=".exe" export CPPFLAGS="-D__ST_MT_ERRNO__" export CFLAGS="-O2 -Zomf -Zmt" export LDFLAGS="-Zcrtdll -Zlinker /exepack:2 -Zlinker /pm:vio -Zstack 0x6000" export RANLIB="echo" ./configure --prefix=x:/usr --infodir=x:/usr/share/info --mandir=x:/usr/share/man make AR=emxomfar make install Note: If you use gcc 2.9.x I recommend to set also LIBS="-lgcc" Note: You can add -DNO_CMD_DEFAULT and -DNO_CHDIR2 to CPPFLAGS. See section I. for details. Note: If you use Open Watcom Linker instead of IBM Linker, remove '-Zlinker /exepack:2' from LDFLAGS. IV. ***** NLS support ***** GNU Make has NLS (National Language Support), with the following caveats: a) It will only work with GNU gettext, and b) GNU gettext support is not included in the GNU Make package. Therefore, if you wish to enable the internationalization features of GNU Make you must install GNU gettext on your system before configuring GNU Make. You can choose the languages to be installed. To install support for English, German and French only enter: export LINGUAS="en de fr" If you don't specify LINGUAS all languages are installed. If you don't want NLS support (English only) use the option --disable-nls for the configure script. Note if GNU gettext is not installed then NLS will not be enabled regardless of this flag. V. ***** Running the make test suite ***** To run the included make test suite you have to set CPPFLAGS="-D__ST_MT_ERRNO__ -DNO_CMD_DEFAULT -DNO_CHDIR2" before you compile make. This is due to some restrictions of the testsuite itself. -DNO_CMD_DEFAULT causes make to use /bin/sh as default shell in every case. Normally you could simply set MAKESHELL="/bin/sh" to do this but the testsuite ignores the environment. -DNO_CHDIR2 causes make not to use drive letters for directory names (i.e. _chdir2() and _getcwd2() are NOT used). The testsuite interprets the whole output of make, especially statements like make[1]: Entering directory 'C:/somewhere/make-3.79.1/tests' where the testsuite does not expect the drive letter. This would be interpreted as an error even if there is none. To run the testsuite do the following: export CPPFLAGS="-D__ST_MT_ERRNO__ -DNO_CMD_DEFAULT -DNO_CHDIR2" export CFLAGS="-Zomf -O2 -Zmt" export LDFLAGS="-Zcrtdll -s -Zlinker /exepack:2 -Zlinker /pm:vio -Zstack 0x6000" export RANLIB="echo" ./configure --prefix=x:/usr --disable-nls make AR=emxomfar make check All tests should work fine with the exception of one of the "INCLUDE_DIRS" tests which will fail if your /usr/include directory is on a drive different from the make source tree. ------------------------------------------------------------------------------- Copyright (C) 2003-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: README.VMS ================================================ Overview: -*-text-mode-*- --------- This version of GNU Make has been tested on: OpenVMS V8.3/V8.4 (Alpha) and V8.4 (Integrity) AND V7.3 (VAX) This version of GNU Make is intended to be run from DCL to run make scripts with a special syntax that is described below. It likely will not be able to run unmodified Unix makefiles. There is an older implementation of GNU Make that was ported to GNV. Work is now in progress to merge that port to get a single version of GNU Make available. When that merge is done, GNU Make will auto detect that it is running under a POSIX shell and then operate as close to GNU Make on Unix as possible. The descriptions below are for running GNU Make from DCL or equivalent. Recipe differences: ------------------- GNU Make for OpenVMS can not currently run native Unix make files because of differences in the implementation. I am trying to document the current behavior in this section. This is based on the information in the file NEWS. and running the test suite. TODO: More tests are needed to validate and demonstrate the OpenVMS expected behavior. In some cases the older behavior of GNU Make when run from DCL is not compatible with standard makefile behavior. This behavior can be changed when running GNU Make from DCL by setting either DCL symbols or logical names of the format GNV$. The settings are enabled with a string starting with one of '1', 'T', or 'E' for "1", "TRUE", or "ENABLE". They are disabled with a '0', 'F', or 'D' for "1", "FALSE", or "DISABLE". If they are not explicitly set to one of these values, then they will be set to their default values. The value of the setting DECC$FILENAME_UNIX_REPORT or DECC$FILENAME_UNIX_ONLY will now cause the $(dir x) function to return './' or '[]' as appropriate. The name GNV$MAKE_OLD_VMS when enabled will cause GNU Make to behave as much as the older method as can be done with out disabling VMS features. When it is disabled GNU Make have the new behavior which more closely matches Unix Make behavior. The default is currently the old behavior when running GNU Make from DCL. In the future this may change. When running make from GNV Bash the new behavior is the default. This is a global setting that sets the default behavior for several other options that can be individually changed. Many of the individual settings are to make it so that the self tests for GNU Make need less VMS specific modifications. The name GNV$MAKE_COMMA when enabled will cause GNU Make to expect a comma for a path separator and use a comma for the separator for a list of files. When disabled, it will cause GNU Make to use a colon for a path separator and a space for the separator for a list of files. The default is to be enabled if the GNU Make is set to the older behavior. The name GNV$MAKE_SHELL_SIM when enabled will cause GNU Make to try to simulate a POSIX shell more closely. The following behaviors occur: * Single quotes are converted to double quotes and any double quotes inside of them are doubled. No environment variable expansion is simulated. * A exit command status will be converted to a POSIX Exit where 0 is success and non-zero is failure. * The $ character will cause environment variable expansion. * Environment variables can be set on the command line before a command. VMS generally uses logical name search lists instead of path variables where the resolution is handled by VMS independent of the program. Which means that it is likely that nothing will notice if the default path specifier is changed in the future. Currently the built in VMS specific macros and recipes depend on the comma being used as a file list separator. TODO: Remove this dependency as other functions in GNU Make depend on a space being used as a separator. The format for recipes are a combination of Unix macros, a subset of simulated UNIX commands, some shell emulation, and OpenVMS commands. This makes the resulting makefiles unique to the OpenVMS port of GNU Make. If you are creating a OpenVMS specific makefile from scratch, you should also look at MMK (Madgoat Make) available at https://github.com/endlesssoftware/mmk MMK uses full OpenVMS syntax and a persistent sub-process is used for the recipe lines, allowing multiple line rules. The default makefile search order is "makefile.vms", "gnumakefile", "makefile". TODO: See if that lookup is case sensitive. When Make is invoked from DCL, it will create a foreign command using the name of executable image, with any facility prefix removed, for the duration of the make program, so it can be used internally to recursively run make(). The macro MAKE_COMMAND will be set to this foreign command. When make is launched from an exec*() command from a C program, the foreign command is not created. The macro MAKE_COMMAND will be set to the actual command passed as argv[0] to the exec*() function. If the DCL symbol or logical name GNV$MAKE_USE_MCR exists, then the macro MAKE_COMMAND will be set to be an "MCR" command with the absolute path used by DCL to launch make. The foreign command will not be created. The macro MAKE is set to be the same value as the macro MAKE_COMMAND on all platforms. Each recipe command is normally run as a separate spawned processes, except for the cases documented below where a temporary DCL command file may be used. BUG: Testing has shown that the commands in the temporary command files are not always created properly. This issue is still under investigation. Any macros marked as exported are temporarily created as DCL symbols for child images to use. DCL symbol substitution is not done with these commands. Untested: Symbol substitution. When a temporary DCL command file is used, DCL symbol substitution will work. For VMS 7.3-1 and earlier, command lines are limited to 255 characters or 1024 characters in a command file. For VMS 7.3-2 and later, command lines are limited to 4059 characters or 8192 characters in a command file. VMS limits each token of a command line to 256 characters, and limits a command line to 127 tokens. Command lines above the limit length are written to a command file in sys$scratch:. In order to handle Unix style extensions to VMS DCL, GNU Make has parsed the recipe commands and them modified them as needed. The parser has been re-written to resolve numerous bugs in handling valid VMS syntax and potential buffer overruns. The new parser may need whitespace characters where DCL does not require it, and also may require that quotes are matched were DCL forgives if they are not. There is a small chance that existing VMS specific makefiles will be affected. The '<', '>' was previously implemented using command files. Now GNU Make will check to see if the is already a VMS "PIPE" command and if it is not, will convert the command to a VMS "PIPE" command. The '>>' redirection has been implemented by using a temporary command file. This will be described later. The DCL symbol or logical name GNV$MAKE_USE_CMD_FILE when set to a string starting with one of '1','T', or 'E' for "1", "TRUE", or "ENABLE", then temporary DCL command files are always used for running commands. Some recipe strings with embedded new lines will not be handled correctly when a command file is used. GNU Make generally does text comparisons for the targets and sources. The make program itself can handle either Unix or OpenVMS format filenames, but normally does not do any conversions from one format to another. TODO: The OpenVMS format syntax handling is incomplete. TODO: ODS-5 EFS support is missing. BUG: The internal routines to convert filenames to and from OpenVMS format do not work correctly. Note: In the examples below, line continuations such as a backslash may have been added to make the examples easier to read in this format. BUG: That feature does not completely work at this time. Since the OpenVMS utilities generally expect OpenVMS format paths, you will usually have to use OpenVMS format paths for rules and targets. BUG: Relative OpenVMS paths may not work in targets, especially combined with vpaths. This is because GNU Make will just concatenate the directories as it does on Unix. The variables $^ and $@ separate files with commas instead of spaces. This is controlled by the name GNV$MAKE_COMMA as documented in the previous section. While this may seem the natural thing to do with OpenVMS, it actually causes problems when trying to use other make functions that expect the files to be separated by spaces. If you run into this, you need the following workaround to convert the output. TODO: Look at have the $^ and $@ use spaces like on Unix and have and easy to use function to do the conversions and have the built in OpenVMS specific recipes and macros use it. Example: comma := , empty := space := $(empty) $(empty) foo: $(addsuffix .3,$(subs $(comma),$(space),$^) Makefile variables are looked up in the current environment. You can set symbols or logicals in DCL and evaluate them in the Makefile via $(). Variables defined in the Makefile override OpenVMS symbols/logicals. OpenVMS logical and symbols names show up as "environment" using the origin function. when the "-e" option is specified, the origin function shows them as "environment override". On POSIX the test scripts indicate that they should show up just as "environment". When GNU Make reads in a symbol or logical name into the environment, it converts any dollar signs found to double dollar signs for convenience in using DCL symbols and logical names in recipes. When GNU Make exports a DCL symbol for a child process, if the first dollar sign found is followed by second dollar sign, then all double dollar signs will be converted to single dollar signs. The variable $(ARCH) is predefined as IA64, ALPHA or VAX respectively. Makefiles for different OpenVMS systems can now be written by checking $(ARCH). Since IA64 and ALPHA are similar, usually just a check for VAX or not VAX is sufficient. You may have to update makefiles that assume VAX if not ALPHA. ifeq ($(ARCH),VAX) $(ECHO) "On the VAX" else $(ECHO) "On the ALPHA or IA64" endif Empty commands are handled correctly and don't end in a new DCL process. The exit command needs to have OpenVMS exit codes. To pass a POSIX code back to the make script, you need to encode it by multiplying it by 8 and then adding %x1035a002 for a failure code and %x1035a001 for a success. Make will interpret any POSIX code other than 0 as a failure. TODO: Add an option have simulate POSIX exit commands in recipes. Lexical functions can be used in pipes to simulate shell file test rules. Example: POSIX: b : c ; [ -f $@ ] || echo >> $@ OpenVMS: b : c ; if f$$search("$@") then pipe open/append xx $@ ; write xx "" ; close xx You can also use pipes and turning messages off to silently test for a failure. x = %x1035a00a %.b : %.c pipe set mess/nofac/noiden/nosev/notext ; type $^/output=$@ || exit $(x) Runtime issues: The OpenVMS C Runtime has a convention for encoding a POSIX exit status into to OpenVMS exit codes. These status codes will have the hex value of 0x35a000. OpenVMS exit code may also have a hex value of %x10000000 set on them. This is a flag to tell DCL not to write out the exit code. To convert an OpenVMS encoded POSIX exit status code to the original code You subtract %x35a000 and any flags from the OpenVMS code and divide it by 8. WARNING: Backward-incompatibility! The make program exit now returns the same encoded POSIX exit code as on Unix. Previous versions returned the OpenVMS exit status code if that is what caused the recipe to fail. TODO: Provide a way for scripts calling make to obtain that OpenVMS status code. Make internally has two error codes, MAKE_FAILURE and MAKE_TROUBLE. These will have the error "-E-" severity set on exit. MAKE_TROUBLE is returned only if the option "-q" or "--question" is used and has a POSIX value of 1 and an OpenVMS status of %x1035a00a. MAKE_FAILURE has a POSIX value of 2 and an OpenVMS status of %x1035a012. Output from GNU Make may have single quotes around some values where on other platforms it does not. Also output that would be in double quotes on some platforms may show up as single quotes on VMS. There may be extra blank lines in the output on VMS. https://savannah.gnu.org/bugs/?func=detailitem&item_id=41760 There may be a "Waiting for unfinished jobs..." show up in the output. Error messages generated by Make or Unix utilities may slightly vary from POSIX platforms. Typically the case may be different. When make deletes files, on POSIX platforms it writes out 'rm' and the list of files. On VMS, only the files are written out, one per line. TODO: VMS There may be extra leading white space or additional or missing whitespace in the output of recipes. GNU Make uses sys$scratch: for the tempfiles that it creates. The OpenVMS CRTL library maps /tmp to sys$scratch if the TMP: logical name does not exist. As the CRTL may use both sys$scratch: and /tmp internally, if you define the TMP logical name to be different than SYS$SCRATCH:, you may end up with only some temporary files in TMP: and some in SYS$SCRATCH: The default include directory for including other makefiles is SYS$SYSROOT:[SYSLIB] (I don't remember why I didn't just use SYS$LIBRARY: instead; maybe it wouldn't work that way). TODO: A better default may be desired. If the device for a file in a recipe does not exist, on OpenVMS an error message of "stat: : no such device or address" will be output. Make ignores success, informational, or warning errors (-S-, -I-, or -W-). But it will stop on -E- and -F- errors. (unless you do something to override this in your makefile, or whatever). Unix compatibility features: ---------------------------- If the command 'echo' is seen, any single quotes on the line will be converted to double quotes. The variable $(CD) is implemented as a built in Change Directory command. This invokes the 'builtin_cd' Executing a 'set default' recipe doesn't do the trick, since it only affects the sub-process spawned for that command. The 'builtin_cd' is generally expected to be on its own line. The 'builtin_cd' either from the expansion of $(CD) or directly put in a recipe line will be executed before any other commands in that recipe line. DCL parameter substitution will not work for the 'builtin_cd' command. Putting a 'builtin_cd' in a pipeline or an IF-THEN line should not be done because the 'builtin_cd' is always executed and executed first. The directory change is persistent. Unix shell style I/O redirection is supported. You can now write lines like: "mcr sys$disk:[]program.exe < input.txt > output.txt &> error.txt" POSIX shells have ":" as a null command. These are now handled. https://savannah.gnu.org/bugs/index.php?41761 A note on appending the redirected output. A simple mechanism is implemented to make ">>" work in action lines. In OpenVMS there is no simple feature like ">>" to have DCL command or program output redirected and appended to a file. GNU Make for OpenVMS implements the redirection of ">>" by using a command procedure. The current algorithm creates the output file if it does not exist and then uses the DCL open/append to extend it. SYS$OUTPUT is then directed to that file. The implementation supports only one redirected append output to a file and that redirection is done before any other commands in that line are executed, so it redirects all output for that command. The older implementation wrote the output to a temporary file in in sys$scratch: and then attempted to append the file to the existing file. The temporary file names looked like "CMDxxxxx.". Any time the created command procedure can not complete, this happens. Pressing CTRL+Y to abort make is one case. In case of CTRL+Y the associated command procedure is left in SYS$SCRATCH:. The command procedures will be named gnv$make_cmd*.com. The CtrlY handler now uses $delprc to delete all children. This way also actions with DCL commands will be stopped. As before the CtrlY handler then sends SIGQUIT to itself, which is handled in common code. Temporary command files are now deleted in the OpenVMS child termination handler. That deletes them even if a CTRL+C was pressed. TODO: Does the previous section about >> leaving files still apply? The behavior of pressing CTRL+C is not changed. It still has only an effect, after the current action is terminated. If that doesn't happen or takes too long, CTRL+Y should be used instead. Build Options: Added support to have case sensitive targets and dependencies but to still use case blind file names. This is especially useful for Java makefiles on VMS: .SUFFIXES : .SUFFIXES : .class .java .java.class : javac "$<" HelloWorld.class : HelloWorld.java A new macro WANT_CASE_SENSITIVE_TARGETS in config.h-vms was introduced. It needs to be enabled to get this feature; default is disabled. TODO: This should be a run-time setting based on if the process has been set to case sensitive. Unimplemented functionality: The new feature "Loadable objects" is not yet supported. If you need it, please send a change request or submit a bug report. The new option --output-sync (-O) is accepted but has no effect: GNU Make for OpenVMS does not support running multiple commands simultaneously. Self test failures and todos: ----------------------------- The test harness can not handle testing some of the VMS specific modes because of the features needed for to be set for the Perl to run. Need to find a way to set the VMS features before running make as a child. GNU Make was not currently translating the OpenVMS encoded POSIX values returned to it back to the POSIX values. I have temporarily modified the Perl test script to compensate for it. This should be being handled internally to Make. TODO: Verify and update the Perl test script. The features/parallelism test was failing. OpenVMS is executing the rules in sequence not in parallel as this feature was not implemented. GNU Make on VMS no longer claims it is implemented. TODO: Implement it. Symlink support is not present. Symlinks are supported by OpenVMS 8.3 and later. Error messages should be suppressed with the "-" at the beginning of a line. On openVMS they were showing up. TODO: Is this still an issue? The internal vmsify and unixify OpenVMS to/from UNIX are not handling logical names correctly. Build instructions: ------------------- Don't use the HP C V7.2-001 compiler, which has an incompatible change how __STDC__ is defined. This results at least in compile time warnings. Make a 1st version $ @makefile.com ! ignore any compiler and/or linker warning $ copy make.exe 1st-make.exe Use the 1st version to generate a 2nd version as a test. $ mc sys$disk:[]1st-make clean ! ignore any file not found messages $ mc sys$disk:[]1st-make Verify your 2nd version by building Make again. $ copy make.exe 2nd-make.exe $ mc sys$disk:[]2nd-make clean $ mc sys$disk:[]2nd-make Running the tests: ------------------ Running the tests on OpenVMS requires the following software to be installed as most of the tests are Unix oriented. * Perl 5.18 or later. https://sourceforge.net/projects/vmsperlkit/files/ * GNV 2.1.3 + Updates including a minimum of: * Bash 4.3.30 * ld_tools 3.0.2 * coreutils 8.21 https://sourceforge.net/p/gnv/wiki/InstallingGNVPackages/ https://sourceforge.net/projects/gnv/files/ As the test scripts need to create some foreign commands that persist after the test is run, it is recommend that either you use a sub-process or a dedicated login to run the tests. To get detailed information for running the tests: $ set default [.tests] $ @run_make_tests help Running the script with no parameters will run all the tests. After the the test script has been run once in a session, assuming that you built make in sys$disk:[make], you can redefined the "bin" logical name as follows: $ define bin sys$disk:[make],gnv$gnu:[bin] Then you can use Perl to run the scripts. $ perl run_make_tests.pl Acknowledgments: ---------------- See NEWS. for details of past changes. These are the currently known contributors to this port. Hartmut Becker John Malmberg Michael Gehre John Eisenbraun Klaus Kaempf Mike Moretti John W. Eaton ================================================ FILE: README.W32 ================================================ This version of GNU Make has been tested on: Microsoft Windows 2000/XP/2003/Vista/7/8/10/11 It has also been used on Windows 95/98/NT, and on OS/2. It builds with the MinGW port of GCC (tested with GCC 3.4.2, 4.8.1, and 4.9.3). It also builds with MSVC 2.x, 4.x, 5.x, 6.x, 2005, 2008, 2010, 2012, 2013, and 2015 as well as with .NET 7.x and .NET 2003. Building with Guile is supported (tested with Guile 2.0.x). To build with Guile, you will need, in addition to Guile itself, its dependency libraries and the pkg-config program. The latter is used to figure out which compilation and link switches and libraries need to be mentioned on the compiler command lines to correctly link with Guile. A Windows port of pkg-config can be found on ezwinports site: https://sourceforge.net/projects/ezwinports/ The libraries on which Guile depends can vary depending on your version and build of Guile. At the very least, the Boehm's GC library will be needed, and typically also GNU MP, libffi, libunistring, and libtool's libltdl. Whoever built the port of Guile you have should also provide you with these dependencies or a URL where to download them. A precompiled 32-bit Windows build of Guile is available from the ezwinports site mentioned above. The Windows port of GNU Make is maintained jointly by various people. It was originally made by Rob Tulloh. It is currently maintained by Eli Zaretskii. Do this first, regardless of the build method you choose: --------------------------------------------------------- 1. If you have special requirements, edit config.h.W32 to your liking (especially the shell-related defines, or HAVE_CASE_INSENSITIVE_FS which corresponds to './configure --enable-case-insensitive-file-system'). We don't recommend to define HAVE_CASE_INSENSITIVE_FS, but you may wish to consider that if you have a lot of files whose names are in upper case, while Makefile rules are written for lower-case versions. If you don't have special requirements no changes are needed. Building with (MinGW-)GCC using build_w32.bat --------------------------------------------- 2. Open a W32 command prompt for your installed (MinGW-)GCC, setup a correct PATH and other environment variables for it, then execute ... .\build_w32.bat gcc This produces gnumake.exe in the GccRel directory. If you want a version of GNU Make built with debugging enabled, add the --debug option. Output goes into the GccDebug directory. The batch file will probe for Guile installation, and will build gnumake.exe with Guile if it finds it. If you have Guile installed, but want to build Make without Guile support, type .\build_w32.bat --without-guile gcc Building with (MSVC++-)cl using build_w32.bat --------------------------------------------- 2. Open a command shell, then execute ... .\build_w32.bat This produces a 64bit Release build of gnumake.exe in .\WinRel, using the compiler found on the %Path%. If no compiler is found, the batch file will probe your system and choose the newest MSVC version it can find. If you want a 32bit version of GNU Make, add the --x86 option. If you want a Debug build of GNU Make, add the --debug option. Output will go into the .\WinDebug directory. The batch file will probe for Guile installation, and will build gnumake.exe with Guile if it finds it. If Guile is installed, but you prefer to build GNU Make without Guile support, add the --without-guile option. Building with (MinGW-)GCC using GNU Make ---------------------------------------- 2. If you already have a version of GNU Make available you can use it to build this version. Open a W32 command prompt for your installed (MinGW-)GCC, setup a correct PATH and other environment variables for it, then execute ... make -f Basic.mk TOOLCHAIN=gcc This produces GccRel\gnumake.exe. If you want a version of GNU Make built with debugging enabled, add the TARGET_TYPE=debug option: make -f Basic.mk TOOLCHAIN=gcc TARGET_TYPE=debug The makefile doesn't support Guile integration. Use build_w32.bat if you want to build with Guile support. Building with (MSVC++-)cl using GNU Make ---------------------------------------- 2. If you already have a version of GNU Make available you can use it to build this version. Open a W32 command prompt for your installed (MSVC++-)cl, setup a correct PATH and other environment variables for it (usually via executing vcvars32.bat or vsvars32.bat from the cl-installation, or using a corresponding start menu entry from the cl-installation), then execute ... make -f Basic.mk This produces an optimized WinRel/gnumake.exe. If you want a version of GNU Make built with debugging enabled, add the TARGET_TYPE=debug option: make -f Basic.mk TARGET_TYPE=debug The makefile doesn't support Guile integration. Use build_w32.bat if you want to build with Guile support. Running the test suite ---------------------- 3. You will need an installation of Perl. Be sure to use a relatively modern version: older versions will sometimes throw spurious errors. To run the suite after building using GNU Make, use: make -f Basic.mk check Alternatively if you'd like to run tests by hand, use: cd tests .\run_make_tests.bat -make I've found seems to want forward-slashes in the path. For example if building with .\build_w32.bat non-debug, use: cd tests .\run_make_tests.bat -make ../WinRel/gnumake.exe I've tested this with the MSYS2 shell and POSIX tools installation that you get by installing Git for Windows. ------------------- -- Notes/Caveats -- ------------------- GNU Make on Windows 32-bit platforms: This version of make is ported natively to Windows32 platforms (Windows NT 3.51, Windows NT 4.0, Windows 2000, Windows XP, Windows 95, and Windows 98). It does not rely on any 3rd party software or add-on packages for building. The only thing needed is a Windows compiler. Two compilers supported officially are the MinGW port of GNU GCC, and the various versions of the Microsoft C compiler. Do not confuse this port of GNU Make with other Windows32 projects which provide a GNU Make binary. These are separate projects and are not connected to this port effort. GNU Make and sh.exe: This port prefers if you have a working sh.exe somewhere on your system. If you don't have sh.exe, the port falls back to MSDOS mode for launching programs (via a batch file). The MSDOS mode style execution has not been tested that carefully though (The author uses GNU bash as sh.exe). There are very few true ports of Bourne shell for NT right now. There is a version of GNU bash available from Cygnus "Cygwin" porting effort (https://www.cygwin.com/). Other possibilities are the MKS version of sh.exe, or building your own with a package like NutCracker (DataFocus) or Portage (Consensys). Also MinGW includes sh. GNU Make and brain-dead shells (BATCH_MODE_ONLY_SHELL): Some versions of Bourne shell do not behave well when invoked as 'sh -c' from CreateProcess(). The main problem is they seem to have a hard time handling quoted strings correctly. This can be circumvented by writing commands to be executed to a batch file and then executing the command by calling 'sh file'. To work around this difficulty, this version of make supports a batch mode. When BATCH_MODE_ONLY_SHELL is defined at compile time, make forces all command lines to be executed via script files instead of by command line. In this mode you must have a working sh.exe in order to use parallel builds (-j). A native Windows32 system with no Bourne shell will also run in batch mode. All command lines will be put into batch files and executed via $(COMSPEC) (%COMSPEC%). However, parallel builds ARE supported with Windows shells (cmd.exe and command.com). See the next section about some peculiarities of parallel builds on Windows. Support for parallel builds Parallel builds (-jN) are supported in this port. The number of concurrent processes has a hard limit of 4095. GNU Make and Cygnus GNU Windows32 tools: Good news! Make now has native support for Cygwin sh. To enable, define the HAVE_CYGWIN_SHELL in config.h and rebuild make from scratch. This version of make tested with B20.1 of Cygwin. Do not define BATCH_MODE_ONLY_SHELL if you use HAVE_CYGWIN_SHELL. GNU Make and the MKS shell: There is now semi-official support for the MKS shell. To turn this support on, define HAVE_MKS_SHELL in the config.h.W32 before you build make. Do not define BATCH_MODE_ONLY_SHELL if you turn on HAVE_MKS_SHELL. GNU Make handling of drive letters in pathnames (PATH, vpath, VPATH): There is a caveat that should be noted with respect to handling single character pathnames on Windows systems. When colon is used in PATH variables, make tries to be smart about knowing when you are using colon as a separator versus colon as a drive letter. Unfortunately, something as simple as the string 'x:/' could be interpreted 2 ways: (x and /) or (x:/). Make chooses to interpret a letter plus colon (e.g. x:/) as a drive letter pathname. If it is necessary to use single character directories in paths (VPATH, vpath, Path, PATH), the user must do one of two things: a. Use semicolon as the separator to disambiguate colon. For example use 'x;/' if you want to say 'x' and '/' are separate components. b. Qualify the directory name so that there is more than one character in the path(s) used. For example, none of these settings are ambiguous: ./x:./y /some/path/x:/some/path/y x:/some/path/x:x:/some/path/y Please note that you are free to mix colon and semi-colon in the specification of paths. Make is able to figure out the intended result and convert the paths internally to the format needed when interacting with the operating system, providing the path is not within quotes, e.g. "x:/test/test.c". You are encouraged to use colon as the separator character. This should ease the pain of deciding how to handle various path problems which exist between platforms. If colon is used on both Unix and Windows systems, then no ifdef'ing will be necessary in the makefile source. Pathnames and white space: Unlike Unix, Windows 95/NT systems encourage pathnames which contain white space (e.g. C:\Program Files\). These sorts of pathnames are valid on Unix too, but are never encouraged. There is at least one place in make (VPATH/vpath handling) where paths containing white space will simply not work. There may be others too. I chose to not try and port make in such a way so that these sorts of paths could be handled. I offer these suggestions as workarounds: 1. Use 8.3 notation. i.e. "x:/long~1/", which is actually "x:\longpathtest". Type "dir /x" to view these filenames within the cmd.exe shell. 2. Rename the directory so it does not contain white space. If you are unhappy with this choice, this is free software and you are free to take a crack at making this work. The code in w32/pathstuff.c and vpath.c would be the places to start. Pathnames and Case insensitivity: Unlike Unix, Windows 95/NT systems are case insensitive but case preserving. For example if you tell the file system to create a file named "Target", it will preserve the case. Subsequent access to the file with other case permutations will succeed (i.e. opening a file named "target" or "TARGET" will open the file "Target"). By default, GNU Make retains its case sensitivity when comparing target names and existing files or directories. It can be configured, however, into a case preserving and case insensitive mode by adding a define for HAVE_CASE_INSENSITIVE_FS to config.h.W32. For example, the following makefile will create a file named Target in the directory subdir which will subsequently be used to satisfy the dependency of SUBDIR/DepTarget on SubDir/TARGET. Without HAVE_CASE_INSENSITIVE_FS configured, the dependency link will not be made: subdir/Target: touch $@ SUBDIR/DepTarget: SubDir/TARGET cp $^ $@ Reliance on this behavior also eliminates the ability of GNU Make to use case in comparison of matching rules. For example, it is not possible to set up a C++ rule using %.C that is different than a C rule using %.c. GNU Make will consider these to be the same rule and will issue a warning. SAMBA/NTFS/VFAT: I have not had any success building the debug version of this package using SAMBA as my file server. The reason seems to be related to the way VC++ 4.0 changes the case name of the pdb filename it is passed on the command line. It seems to change the name always to to lower case. I contend that the VC++ compiler should not change the casename of files that are passed as arguments on the command line. I don't think this was a problem in MSVC 2.x, but I know it is a problem in MSVC 4.x. The package builds fine on VFAT and NTFS filesystems. Most all of the development I have done to date has been using NTFS and long file names. I have not done any considerable work under VFAT. VFAT users may wish to be aware that this port of make does respect case sensitivity. FAT: Version 3.76 added support for FAT filesystems. Make works around some difficulties with stat'ing of files and caching of filenames and directories internally. Bug reports: Please submit bugs via the normal bug reporting mechanism which is described in the GNU Make manual and the base README. ------------------------------------------------------------------------------- Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: README.customs ================================================ -*-indented-text-*- GNU Make can utilize the Customs library, distributed with Pmake, to provide builds distributed across multiple hosts. In order to utilize this capability, you must first download and build the Customs library. It is contained in the Pmake distribution, which can be obtained at: ftp://ftp.icsi.berkeley.edu/pub/ai/stolcke/software/ This integration was tested (superficially) with Pmake 2.1.33. BUILDING CUSTOMS ---------------- First, build pmake and Customs. You need to build pmake first, because Customs require pmake to build. Unfortunately, this is not trivial; please see the pmake and Customs documentation for details. The best place to look for instructions is in the pmake-2.1.33/INSTALL file. Note that the 2.1.33 Pmake distribution comes with a set of patches to GNU Make, distributed in the pmake-2.1.33/etc/gnumake/ directory. These patches are based on GNU Make 3.75 (there are patches for earlier versions of GNU Make, also). The parts of this patchfile which relate directly to Customs support have already been incorporated into this version of GNU Make, so you should _NOT_ apply the patch file. However, there are a few non-Customs specific (as far as I could tell) changes here which are not incorporated (for example, the modification to try expanding -lfoo to libfoo.so). If you rely on these changes you'll need to re-apply them by hand. Install the Customs library and header files according to the documentation. You should also install the man pages (contrary to comments in the documentation, they weren't installed automatically for me; I had to cd to the 'pmake-2.1.33/doc' directory and run 'pmake install' there directly). BUILDING GNU MAKE ----------------- Once you've installed Customs, you can build GNU Make to use it. When configuring GNU Make, merely use the '--with-customs=DIR' option. Provide the directory containing the 'lib' and 'include/customs' subdirectories as DIR. For example, if you installed the customs library in /usr/local/lib and the headers in /usr/local/include/customs, then you'd pass '--with-customs=/usr/local' as an option to configure. Run make (or use build.sh) normally to build GNU Make as described in the INSTALL file. See the documentation for Customs for information on starting and configuring Customs. INVOKING CUSTOMS-IZED GNU MAKE ----------------------------- One thing you should be aware of is that the default build environment for Customs requires root permissions. Practically, this means that GNU make must be installed setuid root to use Customs. If you don't want to do this, you can build Customs such that root permissions are not necessary. Andreas Stolcke writes: > pmake, gnumake or any other customs client program is not required to > be suid root if customs was compiled WITHOUT the USE_RESERVED_PORTS > option in customs/config.h. Make sure the "customs" service in > /etc/services is defined accordingly (port 8231 instead of 1001). > Not using USE_RESERVED_PORTS means that a user with programming > skills could impersonate another user by writing a fake customs > client that pretends to be someone other than himself. See the > discussion in etc/SECURITY. PROBLEMS -------- SunOS 4.1.x: The customs/sprite.h header file #includes the header files; this conflicts with GNU Make's configuration so you'll get a compile error if you use GCC (or any other ANSI-capable C compiler). I commented out the #include in sprite.h:107: #if defined(sun) || defined(ultrix) || defined(hpux) || defined(sgi) /* #include */ #else YMMV. ------------------------------------------------------------------------------- Copyright (C) 1998-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: README.git ================================================ -*-text-*- ------------------------------------------------------------------------------- Copyright (C) 2002-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ------------------------------------------------------------------------------- Obtaining Git Code ------------------ This seems redundant, since if you're reading this you most likely have already performed this step; however, for completeness, you can obtain the GNU make source code via Git from the FSF's Savannah project : $ git clone git://git.savannah.gnu.org/make.git Changes using Git ----------------- If you do not have push privileges to the GNU Make Git repository, see the README file section "Submitting Patches" for information. If you have push privileges to the GNU Make Git repository keep this information in mind: Starting with GNU Make 4.0 we no longer keep a separate ChangeLog file in source control. We use the Gnulib git-to-changelog conversion script to convert the Git comments into ChangeLog-style entries for release. As a result, please format your Git comments carefully so they will look clean after conversion. In particular, each line of your comment will have a TAB added before it so be sure your comment lines are not longer than 72 characters; prefer 70 or less. Please use standard ChangeLog formats for your commit messages (sans the leading TAB of course). Rule #1: Don't rewrite pushed history on master (no "git push --force"). Rule #2: Feel free to rewrite pushed history on personal branches. Rule #3: Squash-merge or rebase + merge --ff-only, rather than merging from personal branches into master. Typical simple workflow might be: * Edit files / make / make check * Use "git status" and "git diff" to verify your changes * Use "git add" to stage the changes you want to make * Use "git commit" to commit the staged changes to your local repository * Use "git pull -r" to accept new changes from the upstream repository * Use "git push" to push your commits back to the upstream repository For Emacs users, there are many options for Git integration but I strongly recommend Magit: https://magit.vc/ It makes the workflow much clearer, and has advanced features such as constructing multiple commits from various files and even from different diff chunks in the same file. There is a video available which helps a lot. Coding Standards ---------------- GNU Make code adheres to the GNU Coding Standards. Please use only spaces and no TAB characters in source code. Additionally, GNU Make is a foundational bootstrap package for the GNU project; as such it is conservative about language features it expects. However, GNU Make does rely on the Gnulib portability library, and Gnulib currently requires a ISO C99 compiler. So features in ISO C99 can be assumed. Building From Git for POSIX --------------------------- To build GNU Make from Git on POSIX systems such as GNU/Linux, you will need to install the following extra software: * autoconf >= 2.69 * automake >= 1.16.1 * autopoint * texinfo (for makeinfo) * gettext * pkg-config * GCC * GNU Make (POSIX make is not sufficient) And any tools that those utilities require (GNU m4, etc.) To run the tests you must install Perl. To create dist files you will additionally need: * lzip (to create tar.lz dist files) * texlive (or some other TeX package) GNU Make requires Gnulib to provide some facilities. If you want to maintain a local installation of gnulib you can set GNULIB_SRCDIR to point to it. Otherwise, ./bootstrap will obtain a clone for you. Due to issues with gnulib's getloadavg, you must have automake 1.16.1 or above. This version may not yet be available through GNU/Linux package managers. If you need to install from source be sure to set ACLOCAL_PATH to point to the pkg-config location (e.g., /usr/share/aclocal). If you want to build from Git with a non-GCC compiler, add "MAKE_CFLAGS=" to your make command line (or at least remove any flags your compiler does not support). When building from Git you must build in the source directory: "VPATH builds" from remote directories are not supported. Once you've created a distribution, of course, you can unpack it and do a VPATH build from there. After checking out the code, you will need to run the bootstrap script: $ ./bootstrap Alternatively you can just pull content from remote locations with: $ ./bootstrap --pull And/or just re-generate auto-generatable files with: $ ./bootstrap --gen (Running ./bootstrap does both in one step.) At this point you have successfully brought your Git copy of the GNU make source directory up to the point where it can be treated more-or-less like the official package you would get from ftp.gnu.org. That is, you can just run: $ ./configure $ make check to build and test GNU Make. NOTE! This method builds GNU Make in "maintainer mode". Make programs built in this mode will be slower, possibly MUCH slower: there are various sanity checks enabled. Further this mode assumes a modern GCC, GNU libc, and well-formed system headers and enables a high level of warnings AND enables -Werror to turn warnings into failures. If you want to build from Git with "maintainer mode" disabled, add "MAKE_MAINTAINER_MODE=" to the make command line. If you want to turn off the extra warning flags, add "MAKE_CFLAGS=" to the make command line. If you want to keep the warnings but not fail, add "EXTRA_CFLAGS=-Wno-error" to the make command line. For example: $ ./configure $ make check MAKE_MAINTAINER_MODE= MAKE_CFLAGS= $ make install Building From Git for Windows ----------------------------- If you have a UNIX emulation like CYGWIN you can opt to run the general build procedure above; it will work. Consult README.W32 for information on options you might want to use when running ./configure. If you can't or don't want to do that, then first run the .\bootstrap.bat script to "prime" your Git workspace: > .\bootstrap.bat Next, follow the instructions in the README.W32 file. Note, neither of these methods are tested regularly by the GNU Make maintainers. Building for Windows from a distribution tarball IS tested regularly. NOTE! "Maintainer mode" (see above) IS ENABLED when building from Git using the build_w32.bat file. Debugging and Testing --------------------- These instructions have been tested on GNU systems. I have no idea if they work on non-GNU systems (Windows, MacOS, etc.) * Alternate Configurations: The maintMakefile has a rule for running configure with various different options, with and without packages. Run: make check-alt-config * Valgrind: You can run all tests under valgrind by passing the -memcheck option: (cd tests && ./run_make_tests -make ../make -memcheck) Note, this is slow! Also some tests will fail because of invoking valgrind. * ASAN: You can build with ASAN and run tests, like this: make clean make -j8 CFLAGS='-ggdb3 -fsanitize=address' LDFLAGS='-ggdb3 -fsanitize=address' Then to check for corruption only but not memory leaks run: ASAN_OPTIONS='detect_stack_after_use_return=true:detect_leaks=false' make check To check for leaks too run: make check Note that ASAN is reporting many more errors than valgrind. I don't know which one is wrong: I haven't looked at them closely. Creating a Package ------------------ Once you have performed the above steps (including the configuration and build) you can create a GNU Make package. This is very simple, just run: $ make dist-gzip and, if you like: $ make dist-lzip Even better, you should run this: $ make distcheck Which will build both .gz and .lz package files, then unpack one into a temporary location, try to build it and repack it, then verifying that everything works, you get the same results, _and_ no extraneous files are left over after the "distclean" rule. This package can be unpacked and built to give a "normal" (non-maintainer mode) result. Steps to Release ---------------- Here are the things that need to be done (in more or less this order) before making an official release. If something breaks such that you need to change code, be sure to start over again sufficiently that everything is consistent (that's why we don't finalize the Git tag, etc. until the end). * Update the configure.ac file with the new release number. * Update the EDITION value in the doc/make.texi file. * Update the doc/make.1 file with the release date. * Update the NEWS file with the release number and date. * Ensure the Savannah bug list URL in the NEWS file uses the correct "Fixed Release" ID number. * Run "make distcheck" to be sure it all works. * Run "make check-alt-config" to be sure alternative configurations work * run "make tag-release" to create a Git tag for the release * Push everything: git push --tags origin master The safest thing is to create an entirely new repository and build the final package from there: git clone git://git.savannah.gnu.org/make.git make-release cd make-release If you don't want to create a new repository then run "git clean -fdx". Then: ./bootstrap ./configure make distcheck Perform test builds on whichever systems you have access to. Use a previous announcement as a template to create an announcement in a text file then sign it with GPG: gpg --clearsign Or, use your mail client's PGP/GPG signing capabilities. NOTE! In order to publish a package on the FSF FTP site you need to have my GPG private key, and my passphrase to unlock it. Depending on your distribution (whether GnuPG is integrated with your keyring etc.) the upload operation will either pop up a window asking for the GPG key passphrase one time, or else it will use the CLI to ask for the GPG passphrase _THREE_ times. Sigh. Publishing a Release Candidate ------------------------------ Usually I publish one or two release candidates for people to test before making an official release. Release candidates use a GNU numbering scheme, which add a ".9x" release number to the PREVIOUS major release. So the first release candidate for GNU Make 4.4 would be GNU Make 4.3.90, the second release candidate would be 4.3.91, etc. Upload a release candidate using: make upload-alpha Announce a release candidate to these mailing lists: To: bug-make@gnu.org BCC: help-make@gnu.org, make-w32@gnu.org, make-alpha@gnu.org You will have to approve the BCC's on the mailing list admin sites. Send separate copies to (don't use CC as replies will go to these lists): * coordinator@translationproject.org * platform-testers@gnu.org Publishing a Release -------------------- When publishing a final release there are extra steps that need to be taken: * Run "make update-makeweb" to get a copy of the GNU Make web pages * Run "make update-gnuweb" to get a copy of the GNU website boilerplate pages * Update the web page boilerplate if necessary: ( cd ~/src/make/make-web \ && ~/src/gnu-www/www/server/standards/patch-from-parent \ make.html \ ~/src/gnu-www/www/server/standards/boilerplate.html ) * Run "make gendocs" (requires gnulib) to generate the manual files for the GNU Make web pages. * Follow the directions from gendocs for the web page repository Manage the Savannah project for GNU Make: * In Savannah edit the "Component Version" field and choose the "SCM" entry. Modify the "Value", "Rank", and "Description" values for the to refer to the new release. The "Rank" field should be 10 less than the previous release so it orders properly. * In Savannah edit the "Fixed Release" field and choose the "SCM" entry. Modify the "Value", "Rank", and "Description" values for the to refer to the new release. The "Rank" field should be 10 less than the previous release so it orders properly. * In Savannah create a new entry for the "Component Version" field: - Value: SCM - Rank: 20 - Descr: Issues found in code retrieved from Source Code Management (Git), rather than a distributed version. Please include the SHA you are working with. * In Savannah create a new entry for the "Fix Release" field: - Value: SCM - Rank: 20 - Descr: Fixed in Source Code Management (Git). The fix will be included in the next release of GNU Make. Upload a release using: make upload-ftp Announce a release to these mailing lists: To: info-gnu@gnu.org, bug-make@gnu.org BCC: help-make@gnu.org, make-w32@gnu.org, make-alpha@gnu.org You will have to approve the BCC's on the mailing list admin sites. Send separate copies to (don't use CC as replies will go to these lists): * coordinator@translationproject.org * platform-testers@gnu.org Announce on Savannah: * Add a news item to the Savannah project site. Start the next release: * Update configure.ac and add a ".90" to the release number. * Update the NEWS file with a new section for the release / date. * Update the Savannah URL for the bugs fixed in the NEWS section. Appendix A - For The Brave -------------------------- For those of you who trust me implicitly, or are just brave (or foolhardy), here is a canned sequence of commands to build a GNU Make distribution package from a virgin Git source checkout (assuming all the prerequisites are available of course). This list is eminently suitable for a quick swipe o' the mouse and a swift click o' mouse-2 into an xterm. Go for it! For a debugging version: ./bootstrap && ./configure CFLAGS=-g && make check For an optimized version ./bootstrap && ./configure && make check ================================================ FILE: README.in ================================================ This directory contains the @PACKAGE_VERSION@ release of @PACKAGE_NAME@. See the file NEWS for the user-visible changes from previous releases. In addition, there have been bugs fixed. >> If you are trying to build GNU Make from a Git clone rather than a >> downloaded source distribution, see the README.git file for instructions. Please check the system-specific notes below for any caveats related to your operating system. This README assumes you are building on a POSIX-based operating system. For ports to other operating systems please see the system-specific README files, as described in the "Ports" section below. For source distribution building and installation instructions, see the file INSTALL. If you need to build GNU Make and have no other 'make' program to use, you can use the shell script 'build.sh' instead. To do this, first run 'configure' as described in INSTALL. Then, instead of typing 'make' to build the program, type 'sh build.sh'. This will compile the program in the current directory. Then you will have a 'make' program that you can use for './make install', or whatever else. Some systems' 'make' programs cannot process the Makefile for GNU Make. If you get errors from your system's 'make' when building GNU Make, try using 'build.sh' instead. GNU Make is free software. See the file COPYING for copying conditions. GNU Make is copyright by the Free Software Foundation. Copyright notices condense sequential years into a range; e.g. "1987-1994" means all years from 1987 to 1994 inclusive. Downloading ----------- GNU Make can be obtained in many different ways. See a description here: https://www.gnu.org/software/software.html Documentation ------------- GNU Make is fully documented in the GNU Make manual, which is contained in this distribution as the file make.texi. You can also find on-line and preformatted (PostScript and DVI) versions at the FSF's web site. There is information there about ordering hardcopy documentation. https://www.gnu.org/ https://www.gnu.org/doc/doc.html https://www.gnu.org/manual/manual.html Development ----------- GNU Make development is hosted by Savannah, the FSF's online development management tool. Savannah is here: https://savannah.gnu.org And the GNU Make development page is here: https://savannah.gnu.org/projects/make/ You can find most information concerning the development of GNU Make at this site. Regression Tests ---------------- GNU Make contains a suite of regression tests. To run them use "make check" after building GNU Make. If they fail a tar package will be created containing useful information, which can be emailed (as an attachment) to the mailing list. Please note that since these tests rely on known-good-output comparisons, they can show spurious failures on some systems (particularly non-POSIX systems such as Windows). Bug Reporting ------------- If you need help using GNU Make, try asking on . If you found a bug, you can send a bug reports to . Please see the section of the GNU Make manual entitled 'Problems and Bugs' for information on submitting useful and complete bug reports. You do not need to subscribe to these lists first. You can also use the online bug tracking system in the Savannah GNU Make project to submit new problem reports or search for existing ones: https://savannah.gnu.org/bugs/?group=make We prefer to use the bug tracking system ONLY for bugs or enhancements, not for help requests: please use the mailing lists to get help. Submitting Patches ------------------ If you'd like to propose a change to GNU Make, you can provide a patch with your changes. If you are making your changes in a Git workspace you can run "git format-patch" to create a patch file. If not, you can use the diff(1) utility to create a patch file; please use "diff -u". Once you have a patch you can submit it in any of these ways: * Create a bug on Savannah and add the patch as an attachment: https://savannah.gnu.org/bugs/?group=make&func=additem * Send the patch via email to : be sure to add it as an attachment to avoid interference by email processors. All non-trivial changes require FSF copyright paperwork to be completed before they can be accepted. Contact for help. Git Access ---------- The GNU Make source repository is available via Git from the GNU Savannah Git server; look here for details: https://savannah.gnu.org/git/?group=make Please note: you won't be able to build GNU Make from Git without installing appropriate maintainer's tools, such as GNU m4, automake, autoconf, Perl, GNU make, and GCC. See the README.git file for instructions on how to build GNU Make once these tools are available. We make no guarantees about the contents or quality of the latest code in the Git repository: it is not unheard of for code that is known to be broken to be checked in. Use at your own risk. System-specific Notes --------------------- One area that is often a problem in configuration and porting is the code to check the system's current load average. To make it easier to test and debug this code, you can do 'make check-loadavg' to see if it works properly on your system. (You must run 'configure' beforehand, but you need not build 'make' itself to run this test.) Another potential source of porting problems is the support for large files (LFS) in configure for those operating systems that provide it. Please report any bugs that you find in this area. If you run into difficulties, then as a workaround you should be able to disable LFS by adding the '--disable-largefile' option to the 'configure' script. On systems that support micro- and nano-second timestamp values and where stat(2) provides this information, GNU Make will use it when comparing timestamps to get the most accurate possible result. However, note that many current implementations of tools that *set* timestamps do not preserve micro- or nano-second granularity. This means that "cp -p" and other similar tools (tar, etc.) may not exactly duplicate timestamps with micro- and nano-second granularity on some systems. If your build system contains rules that depend on proper behavior of tools like "cp -p", you should consider using the .LOW_RESOLUTION_TIME pseudo-target to force make to treat them properly. See the manual for details. Ports ----- - See README.customs for details on integrating GNU Make with the Customs distributed build environment from the Pmake distribution. - See README.VMS for details about GNU Make on OpenVMS. - See README.zOS for details about GNU Make on z/OS. - See README.W32 for details about GNU Make on Windows NT, 95, or 98. - See README.DOS for compilation instructions on MS-DOS and MS-Windows using DJGPP tools. A precompiled binary of the MSDOS port of GNU Make is available as part of DJGPP; see the WWW page https://www.delorie.com/djgpp/ for more information. The Cygwin project maintains its own port of GNU Make. That port may have patches which are not present in this version. If you are using Cygwin you should use their version of GNU Make, and if you have questions about it you should start by asking on those mailing lists and forums. Please note there are two _separate_ ports of GNU Make for Microsoft systems: a native Windows port built with (for example) MSVC or MinGW, and a DOS-based port built with DJGPP. Please be sure you are looking at the right README! ------------------------------------------------------------------------------- Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: README.zOS ================================================ -*-text-*- GNU Make has been ported to z/OS, tested on z/OS V2R4. PREREQUISITES ------------- Building GNU Make requires certain tools be installed on your z/OS system. These tools can be downloaded from: https://github.com/ZOSOpenTools For detailed instructions on how to set up these tools, visit https://zosopentools.github.io/meta/#/Guides/Pre-req You will need curl, tar, and gzip to download and unpack the GNU Make release package, but presumably you've already worked this out if you're reading this document! You will need the IBM C/C++ compiler. You can download a web deliverable add-on feature to your XL C/C++ compiler here: https://www-40.ibm.com/servers/resourcelink/svc00100.nsf/pages/xlCC++V241ForZOsV24 Alternatively, you can install and manage C/C++ for Open Enterprise Languages on z/OS using RedHat OpenShift Container Platform and IBM Z and Cloud Modernization Stack. GNU Make has a dependency on the ZOSLIB library, which is documented here: https://zosopentools.github.io/meta/#/Guides/Zoslib. To obtain the latest release of zoslib, you can download it from here: https://github.com/ZOSOpenTools/zoslibport/releases. BUILDING -------- If you are trying to build from a checked-out Git workspace, see README.git. Before building GNU Make, you will need to ensure that the following environment variables are set, to turn on z/OS enhanced ASCII support: export _BPXK_AUTOCVT=ON export _CEE_RUNOPTS="$_CEE_RUNOPTS FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)" export _TAG_REDIR_ERR=txt export _TAG_REDIR_IN=txt export _TAG_REDIR_OUT=txt To ensure proper functioning of xlclang, set the following environment variables before building: export _CC_CCMODE=1 export _C89_CCMODE=1 export _CXX_CCMODE=1 Set PATH_TO_ZOSLIB to the location of your zoslib installation; e.g.: PATH_TO_ZOSLIB=$HOME/zopen/prod/zoslib Invoke ./configure as follows: ./configure \ CC=xlclang \ CPPFLAGS="-DNSIG=42 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE -D_OPEN_SYS_FILE_EXT=1 -D_AE_BIMODAL=1 -D_ENHANCED_ASCII_EXT=0xFFFFFFF -DZOSLIB_OVERRIDE_CLIB=1" \ CFLAGS="-qascii -std=gnu11 -qnocsect -qenum=int -I$PATH_TO_ZOSLIB/include" \ LDFLAGS="-L$PATH_TO_ZOSLIB/lib" \ LIBS="-lzoslib $PATH_TO_ZOSLIB/lib/CXXRT64.x" If you have an instance of make already available you can build with: make If not, you can build with: ./build.sh TESTING ------- To run the regression tests you'll need to install Perl and enable it. Then you can run: ./make check INSTALLING ---------- Copy the "make" program to wherever you want it to be installed, on your PATH. ================================================ FILE: TODO.private ================================================ -*-Indented-Text-*- GNU Make TODO List ------------------ This list comes both from the authors and from users of GNU make. They are listed in no particular order! Also, I don't guarantee that all of them will be ultimately deemed "good ideas" and implemented. These are just the ones that, at first blush, seem to have some merit (and that I can remember). However, if you see something here you really, really want, speak up. All other things being equal, I will tend to implement things that seem to maximize user satisfaction. If you want to implement some of them yourself, barring the ones I've marked below, have at it! Please contact me first to let me know you're working on it, and give me some info about the design--and, critically, information about any user-visible syntax change, etc. The Top Item ------------ If you know perl (or want to learn DejaGNU or similar), the number one priority on my list of things I don't have time to do right now is fixing up the GNU make test suite. Most importantly it needs to be made "parallelizable", so more than one regression can run at the same time (essentially, make the "work" directory local). Also, the CWD during the test should be in the work directory or, better, a test-specific temporary directory so each test gets a new directory; right now sometimes tests leak files into the main directory which causes subsequent tests to fail (some tests may need to be tweaked). Beyond that, any cleanup done to make writing, reading, or handling tests simpler would be great! Please feel free to make whatever changes you like to the current tests, given some high-level goals, and that you'll port the current tests to whatever you do :). The Rest of the List -------------------- 1) Option to check more than timestamps to determine if targets have changed. This is also a very big one. It's _close_ to my plate :), and I have very definite ideas about how I would like it done. Please pick something else unless you must have this feature. If you try it, please work _extremely_ closely with me on it. 1a) Possibly a special case of this is the .KEEP_STATE feature of Sun's make. Some great folks at W U. in Canada did an implementation of this for a class project. Their approach is reasonable and workable, but doesn't really fit into my ideas for #2. Maybe that's OK. I have paperwork for their work so if you want to do this one talk to me to get what they've already done. [K R Praveen ] 2) Currently you can use "%.foo %.bar : %.baz" to mean that one invocation of the rule builds both targets. GNU make needs a way to do that for explicit rules, too. I heard a rumor that some versions of make all you to say "a.foo + a.bar : a.baz" to do this (i.e., a "+" means one invocation builds both). Don't know if this is the best syntax or not... what if you say "a.foo + a.bar a.bam : a.baz"; what does that mean? 3) Multi-token pattern rule matching (allow %1/%2.c : %1/obj/%2.o, etc., or something like that). Maybe using regex? 4) Provide a .TARGETS variable, containing the names of the targets defined in the makefile. Actually, I now think a $(targets ...) function, at least, might be better than a MAKETARGETS variable. The argument would be types of targets to list: "phony" is the most useful one. I suppose "default" might also be useful. Maybe some others; check the bitfields to see what might be handy. 5) Some sort of operating-system independent way of handling paths would be outstanding, so makefiles can be written for UNIX, VMS, DOS, MS-Windows, Amiga, etc. with a minimum of specialization. Or, perhaps related/instead of, some sort of meta-quoting syntax so make can deal with filenames containing spaces, colons, etc. I dunno, maybe something like $[...]? This may well not be worth doing until #1 is done. 6) Right now the .PRECIOUS, .INTERMEDIATE, and .SECONDARY pseudo-targets have different capabilities. For example, .PRECIOUS can take a "%", the others can't. Etc. These should all work the same, insofar as that makes sense. 7) Improved debugging/logging/etc. capabilities. Part of this is done: I introduced a number of debugging enhancements. Tim Magill is (I think) looking into options to control output more selectively. One thing I want to do in debugging is add a flag to allow debugging of variables as they're expanded (!). This would be incredibly verbose, but could be invaluable when nothing else seems to work and you just can't figure it out. The way variables are expanded now means this isn't 100% trivial, but it probably won't be hard. ------------------------------------------------------------------------------- Copyright (C) 1997-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: autogen.sh ================================================ #!/bin/sh # Convenience script for regenerating all autogeneratable files that are # omitted from the version control repository. In particular, this script # also regenerates all aclocal.m4, config.h.in, Makefile.in, configure files # with new versions of autoconf or automake. # Copyright (C) 2003-2024 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Originally written by Paul Eggert. The canonical version of this # script is maintained as top/autogen.sh in gnulib. However, to be # useful to your package, you should place a copy of it under version # control in the top-level directory of your package. The intent is # that all customization can be done with a bootstrap.conf file also # maintained in your version control; gnulib comes with a template # build-aux/bootstrap.conf to get you started. # # Alternatively, you can use an autogen.sh script that is specific # to your package. me="$0" medir=`dirname "$me"` # Read the function library and the configuration. . "$medir"/bootstrap-funclib.sh autogen "$@" ================================================ FILE: autopull.sh ================================================ #!/bin/sh # Convenience script for fetching auxiliary files that are omitted from # the version control repository of this package. # Copyright (C) 2003-2024 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Originally written by Paul Eggert. The canonical version of this # script is maintained as top/autopull.sh in gnulib. However, to be # useful to your package, you should place a copy of it under version # control in the top-level directory of your package. The intent is # that all customization can be done with a bootstrap.conf file also # maintained in your version control; gnulib comes with a template # build-aux/bootstrap.conf to get you started. # # Alternatively, you can use an autopull.sh script that is specific # to your package. me="$0" medir=`dirname "$me"` # Read the function library and the configuration. . "$medir"/bootstrap-funclib.sh autopull "$@" ================================================ FILE: bootstrap ================================================ #! /bin/sh # Bootstrap this package from checked-out sources. scriptversion=2022-12-27.07; # UTC # Copyright (C) 2003-2023 Free Software Foundation, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Originally written by Paul Eggert. The canonical version of this # script is maintained as top/bootstrap in gnulib. However, to be # useful to your package, you should place a copy of it under version # control in the top-level directory of your package. The intent is # that all customization can be done with a bootstrap.conf file also # maintained in your version control; gnulib comes with a template # build-aux/bootstrap.conf to get you started. # Please report bugs or propose patches to bug-gnulib@gnu.org. me="$0" medir=`dirname "$me"` # Read the function library and the configuration. . "$medir"/bootstrap-funclib.sh usage() { cat <. # Originally written by Paul Eggert. The canonical version of this # script is maintained as top/bootstrap-funclib.sh in gnulib. However, # to be useful to your package, you should place a copy of it under # version control in the top-level directory of your package. The # intent is that all customization can be done with a bootstrap.conf # file also maintained in your version control; gnulib comes with a # template build-aux/bootstrap.conf to get you started. nl=' ' # Ensure file names are sorted consistently across platforms. LC_ALL=C export LC_ALL # Honor $PERL, but work even if there is none. PERL="${PERL-perl}" default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git # Copyright year, for the --version output. copyright_year=`echo "$scriptlibversion" | sed -e 's/[^0-9].*//'` copyright="Copyright (C) ${copyright_year} Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law." # warnf_ FORMAT-STRING ARG1... warnf_ () { warnf_format_=$1 shift nl=' ' case $* in *$nl*) me_=$(printf "$me"|tr "$nl|" '??') printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;; *) printf "$me: $warnf_format_" "$@" ;; esac >&2 } # warn_ WORD1... warn_ () { # If IFS does not start with ' ', set it and emit the warning in a subshell. case $IFS in ' '*) warnf_ '%s\n' "$*";; *) (IFS=' '; warn_ "$@");; esac } # die WORD1... die() { warn_ "$@"; exit 1; } # ------------------------------ Configuration. ------------------------------ # Directory that contains package-specific gnulib modules and/or overrides. local_gl_dir=gl # Name of the Makefile.am # XXX Not used. gnulib_mk=gnulib.mk # List of gnulib modules needed. gnulib_modules= # Any gnulib files needed that are not in modules. gnulib_files= # A function to be called for each unrecognized option. Returns 0 if # the option in $1 has been processed by the function. Returns 1 if # the option has not been processed by the function. Override it via # your own definition in bootstrap.conf bootstrap_option_hook() { return 1; } # A function to be called in order to print the --help information # corresponding to user-defined command-line options. bootstrap_print_option_usage_hook() { :; } # A function to be called at the end of autopull.sh. # Override it via your own definition in bootstrap.conf. bootstrap_post_pull_hook() { :; } # A function to be called right after gnulib-tool is run. # Override it via your own definition in bootstrap.conf. bootstrap_post_import_hook() { :; } # A function to be called after everything else in this script. # Override it via your own definition in bootstrap.conf. bootstrap_epilogue() { :; } # The command to download all .po files for a specified domain into a # specified directory. Fill in the first %s with the destination # directory and the second with the domain name. po_download_command_format=\ "wget --mirror --level=1 -nd -nv -A.po -P '%s' \ https://translationproject.org/latest/%s/" # Prefer a non-empty tarname (4th argument of AC_INIT if given), else # fall back to the package name (1st argument with munging). extract_package_name=' /^AC_INIT(\[*/{ s/// /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{ s//\1/ s/[],)].*// p q } s/[],)].*// s/^GNU // y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g p } ' package=$(${AUTOCONF:-autoconf} --trace AC_INIT:\$4 configure.ac 2>/dev/null) if test -z "$package"; then package=$(sed -n "$extract_package_name" configure.ac) \ || die 'cannot find package name in configure.ac' fi gnulib_name=lib$package build_aux=build-aux source_base=lib m4_base=m4 doc_base=doc tests_base=tests gnulib_extra_files=" build-aux/install-sh build-aux/mdate-sh build-aux/texinfo.tex build-aux/depcomp build-aux/config.guess build-aux/config.sub doc/INSTALL " # Additional gnulib-tool options to use. Use "\newline" to break lines. gnulib_tool_option_extras= # Other locale categories that need message catalogs. EXTRA_LOCALE_CATEGORIES= # Additional xgettext options to use. Use "\\\newline" to break lines. XGETTEXT_OPTIONS='\\\ --flag=_:1:pass-c-format\\\ --flag=N_:1:pass-c-format\\\ --flag=error:3:c-format --flag=error_at_line:5:c-format\\\ ' # Package bug report address and copyright holder for gettext files COPYRIGHT_HOLDER='Free Software Foundation, Inc.' MSGID_BUGS_ADDRESS=bug-$package@gnu.org # Files we don't want to import. # XXX Not used. excluded_files= # File that should exist in the top directory of a checked out hierarchy, # but not in a distribution tarball. checkout_only_file=README-hacking # Set this to '.cvsignore .gitignore' in bootstrap.conf if you want # those files to be generated in directories like lib/, m4/, and po/. # Or set it to 'auto' to make this script select which to use based # on which version control system (if any) is used in the source directory. vc_ignore=auto # Set this to true in bootstrap.conf to enable --bootstrap-sync by # default. bootstrap_sync=false # Override the default configuration, if necessary. # Make sure that bootstrap.conf is sourced from the current directory # if we were invoked as "sh bootstrap". conffile=`dirname "$me"`/bootstrap.conf test -r "$conffile" && . "$conffile" # ------------------------- Build-time prerequisites ------------------------- check_exists() { if test "$1" = "--verbose"; then ($2 --version /dev/null 2>&1 if test $? -ge 126; then # If not found, run with diagnostics as one may be # presented with env variables to set to find the right version ($2 --version /dev/null 2>&1 fi test $? -lt 126 } # Note this deviates from the version comparison in automake # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a # but this should suffice as we won't be specifying old # version formats or redundant trailing .0 in bootstrap.conf. # If we did want full compatibility then we should probably # use m4_version_compare from autoconf. sort_ver() { # sort -V is not generally available ver1="$1" ver2="$2" # split on '.' and compare each component i=1 while : ; do p1=$(echo "$ver1" | cut -d. -f$i) p2=$(echo "$ver2" | cut -d. -f$i) if [ ! "$p1" ]; then echo "$1 $2" break elif [ ! "$p2" ]; then echo "$2 $1" break elif [ ! "$p1" = "$p2" ]; then if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison echo "$2 $1" elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison echo "$1 $2" else # numeric, then lexicographic comparison lp=$(printf "%s\n%s\n" "$p1" "$p2" | LANG=C sort -n | tail -n1) if [ "$lp" = "$p2" ]; then echo "$1 $2" else echo "$2 $1" fi fi break fi i=$(($i+1)) done } get_version_sed=' # Move version to start of line. s/.*[v ]\([0-9]\)/\1/ # Skip lines that do not start with version. /^[0-9]/!d # Remove characters after the version. s/[^.a-z0-9-].*// # The first component must be digits only. s/^\([0-9]*\)[a-z-].*/\1/ #the following essentially does s/5.005/5.5/ s/\.0*\([1-9]\)/.\1/g p q' get_version() { app=$1 $app --version >/dev/null 2>&1 || { $app --version; return 1; } $app --version 2>&1 | sed -n "$get_version_sed" } check_versions() { ret=0 while read app req_ver; do # We only need libtoolize from the libtool package. if test "$app" = libtool; then app=libtoolize fi # Exempt git if git is not needed. if test "$app" = git; then $check_git || continue fi # Honor $APP variables ($TAR, $AUTOCONF, etc.) appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_') test "$appvar" = TAR && appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. PERL::*) ;; # Keep perl modules as-is *) eval "app=\${$appvar-$app}" ;; esac # Handle the still-experimental Automake-NG programs specially. # They remain named as the mainstream Automake programs ("automake", # and "aclocal") to avoid gratuitous incompatibilities with # pre-existing usages (by, say, autoreconf, or custom autogen.sh # scripts), but correctly identify themselves (as being part of # "GNU automake-ng") when asked their version. case $app in automake-ng|aclocal-ng) app=${app%-ng} ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || { warn_ "Error: '$app' not found or not from Automake-NG" ret=1 continue } ;; # Another check is for perl modules. These can be written as # e.g. perl::XML::XPath in case of XML::XPath module, etc. perl::*) # Extract module name app="${app#perl::}" if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then warn_ "Error: perl module '$app' not found" ret=1 fi continue ;; esac if [ "$req_ver" = "-" ]; then # Merely require app to exist; not all prereq apps are well-behaved # so we have to rely on $? rather than get_version. if ! check_exists --verbose $app; then warn_ "Error: '$app' not found" ret=1 fi else # Require app to produce a new enough version string. inst_ver=$(get_version $app) if [ ! "$inst_ver" ]; then warn_ "Error: '$app' not found" ret=1 else latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2) if [ ! "$latest_ver" = "$inst_ver" ]; then warnf_ '%s\n' \ "Error: '$app' version == $inst_ver is too old" \ " '$app' version >= $req_ver is required" ret=1 fi fi fi done return $ret } print_versions() { echo "Program Min_version" echo "----------------------" printf %s "$buildreq" echo "----------------------" # can't depend on column -t } # check_build_prerequisites check_git check_build_prerequisites() { check_git="$1" # gnulib-tool requires at least automake and autoconf. # If either is not listed, add it (with minimum version) as a prerequisite. case $buildreq in *automake*) ;; *) buildreq="automake 1.9 $buildreq" ;; esac case $buildreq in *autoconf*) ;; *) buildreq="autoconf 2.59 $buildreq" ;; esac # When we can deduce that gnulib-tool will require patch, # and when patch is not already listed as a prerequisite, add it, too. if test -d "$local_gl_dir" \ && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then case $buildreq in *patch*) ;; *) buildreq="patch - $buildreq" ;; esac fi if ! printf '%s' "$buildreq" | check_versions; then echo >&2 if test -f README-prereq; then die "See README-prereq for how to get the prerequisite programs" else die "Please install the prerequisite programs" fi fi # Warn the user if autom4te appears to be broken; this causes known # issues with at least gettext 0.18.3. probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -) if test "x$probe" != xhi; then warn_ "WARNING: your autom4te wrapper eats stdin;" warn_ "if bootstrap fails, consider upgrading your autotools" fi } # find_tool ENVVAR NAMES... # ------------------------- # Search for a required program. Use the value of ENVVAR, if set, # otherwise find the first of the NAMES that can be run. # If found, set ENVVAR to the program name, die otherwise. # # FIXME: code duplication, see also gnu-web-doc-update. find_tool () { find_tool_envvar=$1 shift find_tool_names=$@ eval "find_tool_res=\$$find_tool_envvar" if test x"$find_tool_res" = x; then for i; do if check_exists $i; then find_tool_res=$i break fi done fi if test x"$find_tool_res" = x; then warn_ "one of these is required: $find_tool_names;" die "alternatively set $find_tool_envvar to a compatible tool" fi eval "$find_tool_envvar=\$find_tool_res" eval "export $find_tool_envvar" } # --------------------- Preparing GNULIB_SRCDIR for use. --------------------- # This is part of autopull.sh, but bootstrap needs it too, for self-upgrading. cleanup_gnulib() { status=$? # XXX It's a bad idea to erase the submodule directory if it contains local # modifications. rm -fr "$gnulib_path" exit $status } git_modules_config () { test -f .gitmodules && git config --file .gitmodules "$@" } prepare_GNULIB_SRCDIR () { if test -n "$GNULIB_SRCDIR"; then # Use GNULIB_SRCDIR directly. # We already checked that $GNULIB_SRCDIR references a directory. # Verify that it contains a gnulib checkout. test -f "$GNULIB_SRCDIR/gnulib-tool" \ || die "Error: --gnulib-srcdir or \$GNULIB_SRCDIR is specified, but does not contain gnulib-tool" elif $use_git; then gnulib_path=$(git_modules_config submodule.gnulib.path) test -z "$gnulib_path" && gnulib_path=gnulib # Get gnulib files. Populate $gnulib_path, possibly updating a # submodule, for use in the rest of the script. if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git \ && git_modules_config submodule.gnulib.url >/dev/null; then # Use GNULIB_REFDIR as a reference. echo "$0: getting gnulib files..." if git submodule -h|grep -- --reference > /dev/null; then # Prefer the one-liner available in git 1.6.4 or newer. git submodule update --init --reference "$GNULIB_REFDIR" \ "$gnulib_path" || exit $? else # This fallback allows at least git 1.5.5. if test -f "$gnulib_path"/gnulib-tool; then # Since file already exists, assume submodule init already complete. git submodule update -- "$gnulib_path" || exit $? else # Older git can't clone into an empty directory. rmdir "$gnulib_path" 2>/dev/null git clone --reference "$GNULIB_REFDIR" \ "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \ && git submodule init -- "$gnulib_path" \ && git submodule update -- "$gnulib_path" \ || exit $? fi fi else # GNULIB_REFDIR is not set or not usable. Ignore it. if git_modules_config submodule.gnulib.url >/dev/null; then echo "$0: getting gnulib files..." git submodule init -- "$gnulib_path" || exit $? git submodule update -- "$gnulib_path" || exit $? elif [ ! -d "$gnulib_path" ]; then echo "$0: getting gnulib files..." trap cleanup_gnulib HUP INT PIPE TERM shallow= if test -z "$GNULIB_REVISION"; then if git clone -h 2>&1 | grep -- --depth > /dev/null; then shallow='--depth 2' fi git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ || cleanup_gnulib else if git fetch -h 2>&1 | grep -- --depth > /dev/null; then shallow='--depth 2' fi mkdir -p "$gnulib_path" # Only want a shallow checkout of $GNULIB_REVISION, but git does not # support cloning by commit hash. So attempt a shallow fetch by commit # hash to minimize the amount of data downloaded and changes needed to # be processed, which can drastically reduce download and processing # time for checkout. If the fetch by commit fails, a shallow fetch can # not be performed because we do not know what the depth of the commit # is without fetching all commits. So fallback to fetching all commits. git -C "$gnulib_path" init git -C "$gnulib_path" remote add origin \ ${GNULIB_URL:-$default_gnulib_url} git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \ || git -C "$gnulib_path" fetch origin \ || cleanup_gnulib git -C "$gnulib_path" reset --hard FETCH_HEAD fi trap - HUP INT PIPE TERM fi fi GNULIB_SRCDIR=$gnulib_path # Verify that the submodule contains a gnulib checkout. test -f "$gnulib_path/gnulib-tool" \ || die "Error: $gnulib_path is supposed to contain a gnulib checkout, but does not contain gnulib-tool" fi # XXX Should this be done if $use_git is false? if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \ && ! git_modules_config submodule.gnulib.url >/dev/null; then (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib fi # $GNULIB_SRCDIR now points to the version of gnulib to use, and # we no longer need to use git or $gnulib_path below here. } # -------- Upgrading bootstrap to the version found in GNULIB_SRCDIR. -------- upgrade_bootstrap () { if test -f "$medir"/bootstrap-funclib.sh; then update_lib=true { cmp -s "$medir"/bootstrap "$GNULIB_SRCDIR/top/bootstrap" \ && cmp -s "$medir"/bootstrap-funclib.sh "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" \ && cmp -s "$medir"/autopull.sh "$GNULIB_SRCDIR/top/autopull.sh" \ && cmp -s "$medir"/autogen.sh "$GNULIB_SRCDIR/top/autogen.sh"; \ } else update_lib=false cmp -s "$medir"/bootstrap "$GNULIB_SRCDIR/build-aux/bootstrap" fi || { if $update_lib; then echo "$0: updating bootstrap & companions and restarting..." else echo "$0: updating bootstrap and restarting..." fi case $(sh -c 'echo "$1"' -- a) in a) ignored=--;; *) ignored=ignored;; esac exec sh -c \ '{ if '$update_lib' && test -f "$1"; then cp "$1" "$3"; else cp "$2" "$3"; fi; } && { if '$update_lib' && test -f "$4"; then cp "$4" "$5"; else rm -f "$5"; fi; } && { if '$update_lib' && test -f "$6"; then cp "$6" "$7"; else rm -f "$7"; fi; } && { if '$update_lib' && test -f "$8"; then cp "$8" "$9"; else rm -f "$9"; fi; } && shift && shift && shift && shift && shift && shift && shift && shift && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ $ignored \ "$GNULIB_SRCDIR/top/bootstrap" "$GNULIB_SRCDIR/build-aux/bootstrap" "$medir/bootstrap" \ "$GNULIB_SRCDIR/top/bootstrap-funclib.sh" "$medir/bootstrap-funclib.sh" \ "$GNULIB_SRCDIR/top/autopull.sh" "$medir/autopull.sh" \ "$GNULIB_SRCDIR/top/autogen.sh" "$medir/autogen.sh" \ "$0" "$@" --no-bootstrap-sync } } # ---------------------------------------------------------------------------- if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then use_gnulib=false else use_gnulib=true fi # -------- Fetch auxiliary files from the network. -------------------------- autopull_usage() { cat </dev/null 2>&1 && unset CDPATH # Parse options. # Use git to update gnulib sources use_git=true for option do case $option in --help) autopull_usage return;; --version) set -e echo "autopull.sh $scriptlibversion" echo "$copyright" return 0 ;; --skip-po) SKIP_PO=t;; --force) checkout_only_file=;; --bootstrap-sync) bootstrap_sync=true;; --no-bootstrap-sync) bootstrap_sync=false;; --no-git) use_git=false;; *) bootstrap_option_hook $option || die "$option: unknown option";; esac done $use_git || test -n "$GNULIB_SRCDIR" \ || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option" test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \ || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory" if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then die "Running this script from a non-checked-out distribution is risky." fi check_build_prerequisites $use_git if $use_gnulib || $bootstrap_sync; then prepare_GNULIB_SRCDIR if $bootstrap_sync; then upgrade_bootstrap fi fi # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6. # Also find the compatible sha1 utility on the BSDs if test x"$SKIP_PO" = x; then find_tool SHA1SUM sha1sum gsha1sum shasum sha1 fi # See if we can use gnulib's git-merge-changelog merge driver. if $use_git && test -d .git && check_exists git; then if git config merge.merge-changelog.driver >/dev/null ; then : elif check_exists git-merge-changelog; then echo "$0: initializing git-merge-changelog driver" git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver' git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B' else echo "$0: consider installing git-merge-changelog from gnulib" fi fi case $SKIP_PO in '') if test -d po; then update_po_files po $package || return fi if test -d runtime-po; then update_po_files runtime-po $package-runtime || return fi;; esac # --------------------------------------------------------------------------- bootstrap_post_pull_hook \ || die "bootstrap_post_pull_hook failed" # Don't proceed if there are uninitialized submodules. In particular, # autogen.sh will remove dangling links, which might be links into # uninitialized submodules. # But it's OK if the 'gnulib' submodule is uninitialized, as long as # GNULIB_SRCDIR is set. if $use_git; then # Uninitialized submodules are listed with an initial dash. uninitialized=`git submodule | grep '^-' | awk '{ print $2 }'` if test -n "$GNULIB_SRCDIR"; then uninitialized=`echo "$uninitialized" | grep -v '^gnulib$'` fi if test -n "$uninitialized"; then die "Some git submodules are not initialized: "`echo "$uninitialized" | tr '\n' ',' | sed -e 's|,$|.|'`" Either use option '--no-git', or run 'git submodule update --init' and bootstrap again." fi fi echo "$0: done. Now you can run './autogen.sh'." } # ----------------------------- Get translations. ----------------------------- download_po_files() { subdir=$1 domain=$2 echo "$me: getting translations into $subdir for $domain..." cmd=$(printf "$po_download_command_format" "$subdir" "$domain") eval "$cmd" } # Mirror .po files to $po_dir/.reference and copy only the new # or modified ones into $po_dir. Also update $po_dir/LINGUAS. # Note po files that exist locally only are left in $po_dir but will # not be included in LINGUAS and hence will not be distributed. update_po_files() { # Directory containing primary .po files. # Overwrite them only when we're sure a .po file is new. po_dir=$1 domain=$2 # Mirror *.po files into this dir. # Usually contains *.s1 checksum files. ref_po_dir="$po_dir/.reference" test -d $ref_po_dir || mkdir $ref_po_dir || return download_po_files $ref_po_dir $domain \ && ls "$ref_po_dir"/*.po 2>/dev/null | sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g') test "$langs" = '*' && langs=x for po in $langs; do case $po in x) continue;; esac new_po="$ref_po_dir/$po.po" cksum_file="$ref_po_dir/$po.s1" if ! test -f "$cksum_file" || ! test -f "$po_dir/$po.po" || ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then echo "$me: updated $po_dir/$po.po..." cp "$new_po" "$po_dir/$po.po" \ && $SHA1SUM < "$new_po" > "$cksum_file" || return fi done } # -------- Generate files automatically from existing sources. -------------- autogen_usage() { cat < /dev/null 2>&1 elif test -d .svn; then svn log -r HEAD "$file" > /dev/null 2>&1 elif test -d CVS; then grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null | grep '^/[^/]*/[0-9]' > /dev/null else warn_ "no version control for $file?" false fi } # Strip blank and comment lines to leave significant entries. gitignore_entries() { sed '/^#/d; /^$/d' "$@" } # If $STR is not already on a line by itself in $FILE, insert it at the start. # Entries are inserted at the start of the ignore list to ensure existing # entries starting with ! are not overridden. Such entries support # whitelisting exceptions after a more generic blacklist pattern. insert_if_absent() { file=$1 str=$2 test -f $file || touch $file test -r $file || die "Error: failed to read ignore file: $file" duplicate_entries=$(gitignore_entries $file | sort | uniq -d) if [ "$duplicate_entries" ] ; then die "Error: Duplicate entries in $file: " $duplicate_entries fi linesold=$(gitignore_entries $file | wc -l) linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l) if [ $linesold != $linesnew ] ; then { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \ || die "insert_if_absent $file $str: failed" fi } # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with # insert_if_absent. insert_vc_ignore() { vc_ignore_file="$1" pattern="$2" case $vc_ignore_file in *.gitignore) # A .gitignore entry that does not start with '/' applies # recursively to subdirectories, so prepend '/' to every # .gitignore entry. pattern=$(echo "$pattern" | sed s,^,/,);; esac insert_if_absent "$vc_ignore_file" "$pattern" } symlink_to_dir() { src=$1/$2 dst=${3-$2} test -f "$src" && { # If the destination directory doesn't exist, create it. # This is required at least for "lib/uniwidth/cjk.h". dst_dir=$(dirname "$dst") if ! test -d "$dst_dir"; then mkdir -p "$dst_dir" # If we've just created a directory like lib/uniwidth, # tell version control system(s) it's ignorable. # FIXME: for now, this does only one level parent=$(dirname "$dst_dir") for dot_ig in x $vc_ignore; do test $dot_ig = x && continue ig=$parent/$dot_ig insert_vc_ignore $ig "${dst_dir##*/}" done fi if $copy; then { test ! -h "$dst" || { echo "$me: rm -f $dst" && rm -f "$dst" } } && test -f "$dst" && cmp -s "$src" "$dst" || { echo "$me: cp -fp $src $dst" && cp -fp "$src" "$dst" } else # Leave any existing symlink alone, if it already points to the source, # so that broken build tools that care about symlink times # aren't confused into doing unnecessary builds. Conversely, if the # existing symlink's timestamp is older than the source, make it afresh, # so that broken tools aren't confused into skipping needed builds. See # . test -h "$dst" && src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && test "$src_i" = "$dst_i" && both_ls=$(ls -dt "$src" "$dst") && test "X$both_ls" = "X$dst$nl$src" || { dot_dots= case $src in /*) ;; *) case /$dst/ in *//* | */../* | */./* | /*/*/*/*/*/) die "invalid symlink calculation: $src -> $dst";; /*/*/*/*/) dot_dots=../../../;; /*/*/*/) dot_dots=../../;; /*/*/) dot_dots=../;; esac;; esac echo "$me: ln -fs $dot_dots$src $dst" && ln -fs "$dot_dots$src" "$dst" } fi } } # Regenerate all autogeneratable files that are omitted from the # version control repository. In particular, regenerate all # aclocal.m4, config.h.in, Makefile.in, configure files with new # versions of autoconf or automake. autogen() { # Ensure that CDPATH is not set. Otherwise, the output from cd # would cause trouble in at least one use below. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Environment variables that may be set by the user. : "${AUTOPOINT=autopoint}" : "${AUTORECONF=autoreconf}" if test "$vc_ignore" = auto; then vc_ignore= test -d .git && vc_ignore=.gitignore test -d CVS && vc_ignore="$vc_ignore .cvsignore" fi # Parse options. # Whether to use copies instead of symlinks. copy=false for option do case $option in --help) autogen_usage return;; --version) set -e echo "autogen.sh $scriptlibversion" echo "$copyright" return 0 ;; --force) checkout_only_file=;; --copy) copy=true;; *) bootstrap_option_hook $option || die "$option: unknown option";; esac done test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \ || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory" if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then die "Running this script from a non-checked-out distribution is risky." fi if $use_gnulib; then if test -z "$GNULIB_SRCDIR"; then gnulib_path=$(test -f .gitmodules && git config --file .gitmodules submodule.gnulib.path) test -z "$gnulib_path" && gnulib_path=gnulib GNULIB_SRCDIR=$gnulib_path fi fi # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac. found_aux_dir=no grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'])' configure.ac \ >/dev/null && found_aux_dir=yes grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \ >/dev/null && found_aux_dir=yes test $found_aux_dir = yes \ || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it" # If $build_aux doesn't exist, create it now, otherwise some bits # below will malfunction. If creating it, also mark it as ignored. if test ! -d $build_aux; then mkdir $build_aux for dot_ig in x $vc_ignore; do test $dot_ig = x && continue insert_vc_ignore $dot_ig $build_aux done fi check_build_prerequisites false use_libtool=0 # We'd like to use grep -E, to see if any of LT_INIT, # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac, # but that's not portable enough (e.g., for Solaris). grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \ && use_libtool=1 grep '^[ ]*LT_INIT' configure.ac >/dev/null \ && use_libtool=1 if test $use_libtool = 1; then find_tool LIBTOOLIZE glibtoolize libtoolize fi if $use_gnulib; then gnulib_tool=$GNULIB_SRCDIR/gnulib-tool <$gnulib_tool || return fi # NOTE: we have to be careful to run both autopoint and libtoolize # before gnulib-tool, since gnulib-tool is likely to provide newer # versions of files "installed" by these two programs. # Then, *after* gnulib-tool (see below), we have to be careful to # run autoreconf in such a way that it does not run either of these # two just-pre-run programs. # Import from gettext. with_gettext=yes grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \ with_gettext=no if test $with_gettext = yes || test $use_libtool = 1; then tempbase=.bootstrap$$ trap "rm -f $tempbase.0 $tempbase.1" HUP INT PIPE TERM > $tempbase.0 > $tempbase.1 && find . ! -type d -print | sort > $tempbase.0 || return if test $with_gettext = yes; then # Released autopoint has the tendency to install macros that have been # obsoleted in current gnulib, so run this before gnulib-tool. echo "$0: $AUTOPOINT --force" $AUTOPOINT --force || return fi # Autoreconf runs aclocal before libtoolize, which causes spurious # warnings if the initial aclocal is confused by the libtoolized # (or worse out-of-date) macro directory. # libtoolize 1.9b added the --install option; but we support back # to libtoolize 1.5.22, where the install action was default. if test $use_libtool = 1; then install= case $($LIBTOOLIZE --help) in *--install*) install=--install ;; esac echo "running: $LIBTOOLIZE $install --copy" $LIBTOOLIZE $install --copy fi find . ! -type d -print | sort >$tempbase.1 old_IFS=$IFS IFS=$nl for file in $(comm -13 $tempbase.0 $tempbase.1); do IFS=$old_IFS parent=${file%/*} version_controlled_file "$parent" "$file" || { for dot_ig in x $vc_ignore; do test $dot_ig = x && continue ig=$parent/$dot_ig insert_vc_ignore "$ig" "${file##*/}" done } done IFS=$old_IFS rm -f $tempbase.0 $tempbase.1 trap - HUP INT PIPE TERM fi # Import from gnulib. if $use_gnulib; then gnulib_tool_options="\ --no-changelog\ --aux-dir=$build_aux\ --doc-base=$doc_base\ --lib=$gnulib_name\ --m4-base=$m4_base/\ --source-base=$source_base/\ --tests-base=$tests_base\ --local-dir=$local_gl_dir\ $gnulib_tool_option_extras\ " if test $use_libtool = 1; then case "$gnulib_tool_options " in *' --libtool '*) ;; *) gnulib_tool_options="$gnulib_tool_options --libtool" ;; esac fi echo "$0: $gnulib_tool $gnulib_tool_options --import ..." $gnulib_tool $gnulib_tool_options --import $gnulib_modules \ || die "gnulib-tool failed" for file in $gnulib_files; do symlink_to_dir "$GNULIB_SRCDIR" $file \ || die "failed to symlink $file" done fi bootstrap_post_import_hook \ || die "bootstrap_post_import_hook failed" # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some # gnulib-populated directories. Such .m4 files would cause aclocal to fail. # The following requires GNU find 4.2.3 or newer. Considering the usual # portability constraints of this script, that may seem a very demanding # requirement, but it should be ok. Ignore any failure, which is fine, # since this is only a convenience to help developers avoid the relatively # unusual case in which a symlinked-to .m4 file is git-removed from gnulib # between successive runs of this script. find "$m4_base" "$source_base" \ -depth \( -name '*.m4' -o -name '*.[ch]' \) \ -type l -xtype l -delete > /dev/null 2>&1 # Invoke autoreconf with --force --install to ensure upgrades of tools # such as ylwrap. AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS" # Some systems (RHEL 5) are using ancient autotools, for which the # --no-recursive option had not been invented. Detect that lack and # omit the option when it's not supported. FIXME in 2017: remove this # hack when RHEL 5 autotools are updated, or when they become irrelevant. case $($AUTORECONF --help) in *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";; esac # Tell autoreconf not to invoke autopoint or libtoolize; they were run above. echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS" AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \ || die "autoreconf failed" # Get some extra files from gnulib, overriding existing files. for file in $gnulib_extra_files; do case $file in */INSTALL) dst=INSTALL;; build-aux/*) dst=$build_aux/${file#build-aux/};; *) dst=$file;; esac symlink_to_dir "$GNULIB_SRCDIR" $file $dst \ || die "failed to symlink $file" done if test $with_gettext = yes; then # Create gettext configuration. echo "$0: Creating po/Makevars from po/Makevars.template ..." rm -f po/Makevars sed ' /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/ /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/ /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'| /^XGETTEXT_OPTIONS *=/{ s/$/ \\/ a\ '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+} } ' po/Makevars.template >po/Makevars \ || die 'cannot generate po/Makevars' # If the 'gettext' module is in use, grab the latest Makefile.in.in. # If only the 'gettext-h' module is in use, assume autopoint already # put the correct version of this file into place. case $gnulib_modules in *gettext-h*) ;; *gettext*) cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \ || die "cannot create po/Makefile.in.in" ;; esac if test -d runtime-po; then # Similarly for runtime-po/Makevars, but not quite the same. rm -f runtime-po/Makevars sed ' /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/ /^subdir *=.*/s/=.*/= runtime-po/ /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/ /^XGETTEXT_OPTIONS *=/{ s/$/ \\/ a\ '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+} } ' po/Makevars.template >runtime-po/Makevars \ || die 'cannot generate runtime-po/Makevars' # Copy identical files from po to runtime-po. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po) fi fi bootstrap_epilogue echo "$0: done. Now you can run './configure'." } # ---------------------------------------------------------------------------- # Local Variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptlibversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: ================================================ FILE: bootstrap.bat ================================================ @echo off :: Copyright (C) 2018-2024 Free Software Foundation, Inc. :: This file is part of GNU Make. :: :: GNU Make is free software; you can redistribute it and/or modify it under :: the terms of the GNU General Public License as published by the Free :: Software Foundation; either version 3 of the License, or (at your option) :: any later version. :: :: GNU Make is distributed in the hope that it will be useful, but WITHOUT :: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or :: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for. :: more details. :: :: You should have received a copy of the GNU General Public License along :: with this program. If not, see . setlocal set "svurl=https://git.savannah.gnu.org/cgit" set "gnuliburl=%svurl%/gnulib.git/plain" where curl >nul 2>&1 if ERRORLEVEL 1 ( echo Cannot find curl: it must be installed for bootstrap exit /b 1 ) where sed >nul 2>&1 if ERRORLEVEL 1 ( echo Cannot find sed: it must be installed for bootstrap echo Hint: you can use the sed provided in the Git for Windows install exit /b 1 ) if exist lib goto Downloads mkdir lib if ERRORLEVEL 1 exit /b 1 :Downloads echo -- Downloading Gnulib modules call :Download lib getloadavg.c call :Download lib intprops.h call :Download lib intprops-internal.h echo -- Configuring the workspace copy /Y gl\lib\*.* lib > nul :: In general it's tricky to use special characters as arguments to a program :: in Windows batch files; the quoting rules are obscure and have changed over :: time which means older systems may behave differently. However, Windows :: echo is a dumb program that just writes out its command line without much :: interpreting: all we have to be careful of is ^ quoting. So, use echo :: to create script files to use with sed -f rather than using sed -e. :: Create a sed script to convert templates if exist convert.sed del /Q convert.sed echo s,@PACKAGE@,make,g > convert.sed if ERRORLEVEL 1 goto Failed echo s,@PACKAGE_BUGREPORT@,bug-make@gnu.org,g >> convert.sed if ERRORLEVEL 1 goto Failed echo s,@PACKAGE_NAME@,GNU Make,g >> convert.sed if ERRORLEVEL 1 goto Failed echo s,@PACKAGE_TARNAME@,make,g >> convert.sed if ERRORLEVEL 1 goto Failed echo s,@PACKAGE_URL@,https://www.gnu.org/software/make/,g >> convert.sed echo s/^^AC_INIT^(\[GNU.Make\],\[\^([0-9.]*\^)\].*/s,@PACKAGE_VERSION@,\1,g/p > cac.sed sed -n -f cac.sed configure.ac >> convert.sed if ERRORLEVEL 1 goto Failed :: Get the list of sources from Makefile.am echo s,\\\n,,g > mam.sed echo s,[ \t][ \t]*, ,g >> mam.sed echo s, [^^ ]*\.h,,g >> mam.sed echo s,src/,$^(src^),g >> mam.sed echo s,lib/,$^(lib^),g >> mam.sed echo s/^^\^([A-Za-z0-9]*\^)_SRCS *= *\^(.*\^)/s,%%\1_SOURCES%%,\2,/p > mam2.sed sed -z -f mam.sed Makefile.am | sed -n -f mam2.sed >> convert.sed if ERRORLEVEL 1 goto Failed echo - Creating Basic.mk sed -f convert.sed Basic.mk.template > Basic.mk if ERRORLEVEL 1 goto Failed echo - Creating src\mkconfig.h sed -f convert.sed src\mkconfig.h.in > src\mkconfig.h if ERRORLEVEL 1 goto Failed echo - Creating src\gmk-default.h echo static const char *const GUILE_module_defn = ^" \ > src\gmk-default.h echo s/;.*// > gmk.sed echo /^^[ \t]*$/d >> gmk.sed echo s/"/\\"/g >> gmk.sed echo s/$/ \\/ >> gmk.sed sed -f gmk.sed src\gmk-default.scm >> src\gmk-default.h if ERRORLEVEL 1 goto Failed echo ^";>> src\gmk-default.h :: These files would be created by bootstrap; they are not needed on Windows :: but our makefile depends on them echo >> lib\alloca.in.h del /Q convert.sed cac.sed mam.sed mam2.sed gmk.sed echo. echo Done. Run build_w32.bat to build GNU Make. goto :EOF :Download if exist "%1\%2" goto :EOF echo - Downloading %1\%2 curl -sS -o "%1\%2" "%gnuliburl%/%1/%2" if ERRORLEVEL 1 exit /b 1 goto :EOF :Failed echo *** Bootstrap failed. echo Resolve the issue, or use the configured source in the release tarball exit /b 1 ================================================ FILE: bootstrap.conf ================================================ # Bootstrap configuration. -*-shell-script-*- # Copyright (C) 2018-2024 Free Software Foundation, Inc. # GNU Make is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # You should have received a copy of the GNU General Public License along with # this program. If not, see . # Allow bootstrap to know that this is not a package checkout_only_file=README.git # Choose a specific version of gnulib, when checking out GNULIB_REVISION=stable-202401 # Always copy files rather than symlink copy=true # Additional xgettext options to use. Use "\\\newline" to break lines. # Ensure that all our magical output macros are correctly marked as # C (printf) format strings. XGETTEXT_OPTIONS='\\\ --from-code=UTF-8\\\ --flag=_:1:pass-c-format\\\ --flag=N_:1:pass-c-format\\\ --flag=DB:2:c-format --flag=DBF:2:c-format --flag=DBS:2:c-format\\\ --flag=O:3:c-format --flag=OSN:3:c-format --flag=ONS:3:c-format\\\ --flag=OS:3:c-format --flag=OSS:3:c-format --flag=OSSS:3:c-format\\\ --flag=ON:3:c-format --flag=ONN:3:c-format\\\ ' # We manage our own .gitignore files vc_ignore= # Build prerequisites buildreq="\ autoconf 2.69 automake 1.16.1 " gnulib_name=libgnu gnulib_files="doc/make-stds.texi m4/sig_atomic_t.m4" # Using the full strtoll module pulls in a lot of stuff. But, it's pretty # simple to use just the base source file, so pull that. We'll use it in # src/misc.c if strtoll() is not found. gnulib_files="$gnulib_files lib/strtol.c" gnulib_modules="\ alloca fdl findprog-in getloadavg host-cpu-c-abi largefile make-glob make-macros" ================================================ FILE: build.cfg.in ================================================ # Configuration for building GNU Make in the absence of any 'make' program. # @configure_input@ # Copyright (C) 1993-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # See Makefile.in for comments describing these variables. top_srcdir='@top_srcdir@' prefix='@prefix@' exec_prefix=`eval echo @exec_prefix@` CC='@CC@' AR='@AR@' CFLAGS='@CFLAGS@ @GUILE_CFLAGS@' CPPFLAGS='@CPPFLAGS@' DEFS='@DEFS@' ARFLAGS='@ARFLAGS@' LDFLAGS='@AM_LDFLAGS@ @LDFLAGS@' ALLOCA='@ALLOCA@' LOADLIBES='@LIBS@ @GUILE_LIBS@ @LIBINTL@' REMOTE='@REMOTE@' OBJEXT='@OBJEXT@' EXEEXT='@EXEEXT@' ================================================ FILE: build.sh ================================================ #!/bin/sh # Shell script to build GNU Make in the absence of any 'make' program. # Copyright (C) 1993-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # Get configure-generated values . ./build.cfg die () { echo "$*" 1>&2; exit 1; } usage () { echo "$0 [-k]"; exit $1; } keep_going=false : ${OUTDIR:=.} OUTLIB="$OUTDIR/lib" # Directory to find libraries in for '-lXXX'. libdir=$exec_prefix/lib # Directory to search by default for included makefiles. includedir=$prefix/include localedir=$prefix/share/locale defines="-DLOCALEDIR=\"$localedir\" -DLIBDIR=\"$libdir\" -DINCLUDEDIR=\"$includedir\"" # Look up a make variable value. # It can handle simple recursion where variables are separate words. # Print the value to stdout. get_mk_var () { v=$(sed -e :a -e '/\\$/N; s/\\\n//; ta' "$1" | sed -n "s=^ *$2 *\= *==p") for w in $v; do case $w in (\$[\(\{]*[\)\}]) w=${w#\$[\(\{]}; (get_mk_var "$1" "${w%[\)\}]}") ;; (*) echo "$w" ;; esac done } # Compile source files. Object files are put into $objs. compile () { success=true objs= for ofile in "$@"; do # We should try to use a Makefile variable like libgnu_a_SOURCES or # something but just hardcode it. file="${ofile%.$OBJEXT}.c" case $file in (lib/libgnu_a-*.c) file="lib/${file#lib/libgnu_a-}" ;; esac echo "compiling $file..." of="$OUTDIR/$ofile" mkdir -p "${of%/*}" || exit 1 if $CC $cflags $CPPFLAGS $CFLAGS -c -o "$of" "$top_srcdir/$file"; then : worked else $keep_going || die "Compilation failed." success=false fi objs="${objs:+$objs }$of" done $success } # Use config.status to convert a .in file. Output file is put into $out. # $out will be empty if no conversion was needed. convert () { out= base=$1 var="GENERATE_$(echo $base | tr 'a-z./+' A-Z__X)" # Is this file disabled? grep "${var}_FALSE\"]=\"\"" config.status >/dev/null && return 0 # If there's no .in file then no conversion needed in="$top_srcdir/lib/$(echo ${base%.*}.in.${base##*.} | tr / _)" test -f "$in" || return 0 # Not disabled, so create it out="$OUTLIB/$base" mkdir -p "${out%/*}" # First perform the normal replacements, using config.status sed -e 's|@GUARD_PREFIX@|GL|g' \ -e 's/@GNULIB_UNISTD_H_GETOPT@/0/g' \ "$in" > "${out}_" ./config.status --file "${out}__:${out}_" int="${out}__" # Then see if there any files we need to include. Unfortunately there's no # algorithmic conversion so we just have to hard-code it. incls=$(sed -n 's/.*definitions* of \(_[^ $]*\).*/\1/p' "$in") for inc in $incls; do case $inc in (_GL_FUNCDECL_RPL) fn=$(get_mk_var lib/Makefile CXXDEFS_H) ;; (_GL_ARG_NONNULL) fn=$(get_mk_var lib/Makefile ARG_NONNULL_H) ;; (_GL_WARN_ON_USE) fn=$(get_mk_var lib/Makefile WARN_ON_USE_H) ;; (_Noreturn) fn=$(get_mk_var lib/Makefile _NORETURN_H) ;; (*) echo "Unknown file replacement: $inc"; exit 1 ;; esac fn="$top_srcdir/lib/${fn##*/}" test -f "$fn" || { echo "Missing file: $fn"; exit 1; } sed "/definitions* of $inc/r $fn" "$int" > "${int}_" int=${int}_ done # Done! mv "$int" "$out" } # Get source files provided from gnulib and convert to object files LIBOBJS= for lo in $( (get_mk_var lib/Makefile libgnu_a_OBJECTS; get_mk_var lib/Makefile libgnu_a_LIBADD) | sed "s=\$[\(\{]OBJEXT[\)\}]=$OBJEXT=g"); do LIBOBJS="${LIBOBJS:+$LIBOBJS }lib/$lo" done # Get object files from the Makefile OBJS=$(get_mk_var Makefile make_OBJECTS | sed "s=\$[\(\{]OBJEXT[\)\}]=$OBJEXT=g") while test -n "$1"; do case $1 in (-k) keep_going=true; shift ;; (--) shift; break ;; (-[h?]) usage 0 ;; (-*) echo "Unknown option: $1"; usage 1 ;; esac done test -z "$1" || die "Unknown argument: $*" # Generate gnulib header files that would normally be created by make set -e for b in $(get_mk_var lib/Makefile BUILT_SOURCES); do convert $b done set +e # Build the gnulib library cflags="$DEFS -I$OUTLIB -Ilib -I$top_srcdir/lib -I$OUTDIR/src -Isrc -I$top_srcdir/src" compile $LIBOBJS || die "Compilation failed." echo "creating libgnu.a..." $AR $ARFLAGS "$OUTLIB"/libgnu.a $objs || die "Archive of libgnu failed." # Compile the source files into those objects. cflags="$DEFS $defines -I$OUTDIR/src -Isrc -I$top_srcdir/src -I$OUTLIB -Ilib -I$top_srcdir/lib" compile $OBJS || die "Compilation failed." # Link all the objects together. echo "linking make..." $CC $CFLAGS $LDFLAGS -L"$OUTLIB" -o "$OUTDIR/makenew$EXEEXT" $objs -lgnu $LOADLIBES || die "Link failed." mv -f "$OUTDIR/makenew$EXEEXT" "$OUTDIR/make$EXEEXT" || exit 1 echo done. ================================================ FILE: build_w32.bat ================================================ @echo off :: Copyright (C) 1996-2024 Free Software Foundation, Inc. :: This file is part of GNU Make. :: :: GNU Make is free software; you can redistribute it and/or modify it under :: the terms of the GNU General Public License as published by the Free :: Software Foundation; either version 3 of the License, or (at your option) :: any later version. :: :: GNU Make is distributed in the hope that it will be useful, but WITHOUT :: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or :: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for. :: more details. :: :: You should have received a copy of the GNU General Public License along :: with this program. If not, see . setlocal if not "%RECURSEME%"=="%~0" ( set "RECURSEME=%~0" %ComSpec% /s /c ""%~0" %*" goto :EOF ) call :Reset if "%1" == "-h" goto Usage if "%1" == "--help" goto Usage echo. echo Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10/11 echo. set MAKE=gnumake set GUILE=Y set COMPILER=cl.exe set RC=rc.exe set O=obj set ARCH=x64 set DEBUG=N set DIRENT=Y set VERBOSE=N if exist maintMakefile ( set MAINT=Y ) else ( set MAINT=N ) :ParseSW if "%1" == "--verbose" goto SetVerbose if "%1" == "--debug" goto SetDebug if "%1" == "--without-guile" goto NoGuile if "%1" == "--x86" goto Set32Bit if "%1" == "gcc" goto SetCC if "%1" == "tcc" goto SetTCC if "%1" == "" goto DoneSW goto Usage :SetVerbose set VERBOSE=Y shift goto ParseSW :SetDebug set DEBUG=Y echo - Building without compiler optimizations shift goto ParseSW :NoGuile set GUILE=N echo - Building without Guile shift goto ParseSW :Set32Bit set ARCH=x86 echo - Building 32bit GNU Make shift goto ParseSW :SetCC set COMPILER=gcc set RC=windres set O=o echo - Building with GCC shift goto ParseSW :SetTCC set COMPILER=tcc set RC=windres set O=o echo - Building with TinyC shift goto ParseSW :DoneSW if "%MAINT%" == "Y" echo - Enabling maintainer mode if "%COMPILER%" == "gcc" goto FindGcc if "%COMPILER%" == "tcc" goto FindTcc :: Find a compiler. Visual Studio requires a lot of effort to locate :-/. call %COMPILER% >nul 2>&1 if not ERRORLEVEL 1 goto FoundMSVC :: Visual Studio 15 2017 and above provides the "vswhere" tool call :FindVswhere if ERRORLEVEL 1 goto LegacyVS for /f "tokens=* usebackq" %%i in (`"%VSWHERE%" -latest -property installationPath`) do ( set InstallPath=%%i ) set "VSVARS=%InstallPath%\VC\Auxiliary\Build\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC :: No "vswhere" or it can't find a compiler. Go old-school. :LegacyVS set "VSVARS=%VS150COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS71COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%VS70COMNTOOLS%\..\..\VC\vcvarsall.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%V6TOOLS%\VC98\Bin\vcvars32.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%V6TOOLS%\VC97\Bin\vcvars32.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat" call :CheckMSVC if not ERRORLEVEL 1 goto FoundMSVC :: We did not find anything--fail echo No MSVC compiler available. echo Please run vcvarsall.bat and/or configure your Path. exit 1 :FoundMSVC set OUTDIR=.\WinRel set LNKOUT=./WinRel set "OPTS=/O2 /D NDEBUG" set LINKOPTS= if "%DEBUG%" == "Y" set OUTDIR=.\WinDebug if "%DEBUG%" == "Y" set LNKOUT=./WinDebug if "%DEBUG%" == "Y" set "OPTS=/Zi /Od /D _DEBUG" if "%DEBUG%" == "Y" set LINKOPTS=/DEBUG if "%MAINT%" == "Y" set "OPTS=%OPTS% /D MAKE_MAINTAINER_MODE" :: Show the compiler version that we found :: Unfortunately this also shows a "usage" note; I can't find anything better. echo. call %COMPILER% goto FindRC :FindGcc set OUTDIR=.\GccRel set LNKOUT=./GccRel set OPTS=-O2 set DIRENT=N if "%DEBUG%" == "Y" set OPTS=-O0 if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug if "%DEBUG%" == "Y" set LNKOUT=./GccDebug if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE" :: Show the compiler version that we found echo. call %COMPILER% --version if not ERRORLEVEL 1 goto FindRC echo No %COMPILER% found. exit 1 :FindTcc set OUTDIR=.\TccRel set LNKOUT=./TccRel set OPTS=-O2 if "%DEBUG%" == "Y" set OPTS=-O0 if "%DEBUG%" == "Y" set OUTDIR=.\TccDebug if "%DEBUG%" == "Y" set LNKOUT=./TccDebug if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE" :: Show the compiler version that we found echo. call %COMPILER% -v if not ERRORLEVEL 1 goto FindRC echo No %COMPILER% found. exit 1 :FindRC set HAVE_RC=Y call where %RC% >nul 2>&1 if not ERRORLEVEL 1 goto Build echo. echo %RC% was not found. Building without UTF-8 resource. set HAVE_RC=N :Build echo. :: Clean the directory if it exists if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR% :: Recreate it mkdir %OUTDIR% mkdir %OUTDIR%\src mkdir %OUTDIR%\src\w32 mkdir %OUTDIR%\src\w32\compat mkdir %OUTDIR%\src\w32\subproc mkdir %OUTDIR%\lib if "%GUILE%" == "Y" call :ChkGuile if not exist src\config.h.W32 goto NotConfig echo. echo Compiling %OUTDIR% version copy src\config.h.W32 %OUTDIR%\src\config.h copy lib\glob.in.h %OUTDIR%\lib\glob.h copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h if exist %OUTDIR%\link.sc del %OUTDIR%\link.sc call :Compile src/ar call :Compile src/arscan call :Compile src/commands call :Compile src/default call :Compile src/dir call :Compile src/expand call :Compile src/file call :Compile src/function call :Compile src/getopt call :Compile src/getopt1 call :Compile src/guile GUILE call :Compile src/hash call :Compile src/implicit call :Compile src/job call :Compile src/load call :Compile src/loadapi call :Compile src/main GUILE call :Compile src/misc call :Compile src/output call :Compile src/read call :Compile src/remake call :Compile src/remote-stub call :Compile src/rule call :Compile src/shuffle call :Compile src/signame call :Compile src/strcache call :Compile src/variable call :Compile src/version call :Compile src/vpath call :Compile src/warning call :Compile src/w32/pathstuff call :Compile src/w32/w32os call :Compile src/w32/compat/posixfcn call :Compile src/w32/subproc/misc call :Compile src/w32/subproc/sub_proc call :Compile src/w32/subproc/w32err call :Compile lib/fnmatch call :Compile lib/glob call :Compile lib/getloadavg :: Compile dirent unless it is supported by compiler library (like with gcc). if "%DIRENT%" == "Y" call :Compile src\w32\compat\dirent :: Compile UTF-8 resource if a resource compiler is available. if "%HAVE_RC%" == "Y" call :ResourceCompile src/w32/utf8 call :Link echo. if exist %OUTDIR%\%MAKE%.exe goto Success echo %OUTDIR% build FAILED! exit 1 :Success echo %OUTDIR% build succeeded. if exist Basic.mk copy /Y Basic.mk Makefile if not exist tests\config-flags.pm copy /Y tests\config-flags.pm.W32 tests\config-flags.pm call :Reset goto :EOF :: :: Subroutines :: :Compile if "%VERBOSE%" == "N" echo - Compiling %1.c echo %LNKOUT%/%1.%O% >>%OUTDIR%\link.sc set EXTRAS= if "%2" == "GUILE" set "EXTRAS=%GUILECFLAGS%" if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%" if "%COMPILER%" == "gcc" goto GccCompile if "%COMPILER%" == "tcc" goto TccCompile :: MSVC Compile if "%VERBOSE%" == "Y" echo on call %COMPILER% /nologo /MT /W4 /EHsc %OPTS% /I %OUTDIR%/src /I src /I %OUTDIR%/lib /I lib /I src/w32/include /D _CONSOLE /D HAVE_CONFIG_H /FR%OUTDIR% /Fp%OUTDIR%\%MAKE%.pch /Fo%OUTDIR%\%1.%O% /Fd%OUTDIR%\%MAKE%.pdb %EXTRAS% /c %1.c @echo off goto CompileDone :GccCompile :: GCC Compile if "%VERBOSE%" == "Y" echo on call %COMPILER% -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c @echo off goto CompileDone :TccCompile :: TCC Compile if "%VERBOSE%" == "Y" echo on call %COMPILER% -mthreads -Wall -std=c11 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -D_cdecl= -D_MSC_VER -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c @echo off goto CompileDone :ResourceCompile if "%VERBOSE%" == "N" echo - Compiling %1.rc echo %LNKOUT%/%1.%O% >>%OUTDIR%\link.sc if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%" if "%COMPILER%" == "gcc" goto GccResourceCompile if "%COMPILER%" == "tcc" goto TccResourceCompile :: MSVC Resource Compile if "%VERBOSE%" == "Y" echo on call %RC% /fo %OUTDIR%\%1.%O% %1.rc @echo off goto CompileDone :GccResourceCompile :: GCC Resource Compile if "%VERBOSE%" == "Y" echo on call %RC% -o %OUTDIR%/%1.%O% -i %1.rc @echo off goto CompileDone :TccResourceCompile :: TCC Resource Compile goto GccResourceCompile :CompileDone if not exist "%OUTDIR%\%1.%O%" exit 1 goto :EOF :Link echo. echo - Linking %LNKOUT%/%MAKE%.exe if "%COMPILER%" == "gcc" goto GccLink if "%COMPILER%" == "tcc" goto TccLink :: MSVC Link echo %GUILELIBS% kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib >>%OUTDIR%\link.sc if "%VERBOSE%" == "Y" echo on call link.exe /NOLOGO /SUBSYSTEM:console /PDB:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc @echo off goto :EOF :GccLink :: GCC Link if "%VERBOSE%" == "Y" echo on echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc call %COMPILER% -mthreads -gdwarf-2 -g3 %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc -Wl,--out-implib=%LNKOUT%/libgnumake-1.dll.a @echo off goto :EOF :TccLink :: TCC Link if "%VERBOSE%" == "Y" echo on echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc call %COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc @echo off goto :EOF :ChkGuile :: Build with Guile is supported only on NT and later versions if not "%OS%" == "Windows_NT" goto NoGuile call pkg-config --help > %OUTDIR%\guile.tmp 2> NUL if ERRORLEVEL 1 goto NoPkgCfg set PKGMSC= if not "%COMPILER%" == "gcc" set PKGMSC=--msvc-syntax echo Checking for Guile 2.0 call pkg-config --cflags --short-errors "guile-2.0" > %OUTDIR%\gl-c2.tmp 2> NUL if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c2.tmp call pkg-config --libs --static --short-errors %PKGMSC% "guile-2.0" > %OUTDIR%\gl-l2.tmp 2> NUL if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l2.tmp if not "%GUILECFLAGS%" == "" goto GuileDone echo Checking for Guile 1.8 call pkg-config --cflags --short-errors "guile-1.8" > %OUTDIR%\gl-c18.tmp 2> NUL if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c18.tmp call pkg-config --libs --static --short-errors %PKGMSC% "guile-1.8" > %OUTDIR%\gl-l18.tmp 2> NUL if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l18.tmp if not "%GUILECFLAGS%" == "" goto GuileDone echo - No Guile found, building without Guile goto GuileDone :NoPkgCfg echo - pkg-config not found, building without Guile :GuileDone if "%GUILECFLAGS%" == "" goto :EOF echo - Guile found: building with Guile set "GUILECFLAGS=%GUILECFLAGS% -DHAVE_GUILE" goto :EOF :FindVswhere set VSWHERE=vswhere call "%VSWHERE%" -help >nul 2>&1 if not ERRORLEVEL 1 exit /b 0 set "VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere" call "%VSWHERE%" -help >nul 2>&1 if ERRORLEVEL 1 exit /b 1 goto :EOF :CheckMSVC if not exist "%VSVARS%" exit /b 1 call "%VSVARS%" %ARCH% if ERRORLEVEL 1 exit /b 1 call %COMPILER% >nul 2>&1 if ERRORLEVEL 1 exit /b 1 goto :EOF :NotConfig echo. echo *** This workspace is not configured. echo Either retrieve the configured source in the release tarball echo or, if building from Git, run the .\bootstrap.bat script first. exit /b 1 :Usage echo Usage: %0 [options] [gcc] OR [tcc] echo Options: echo. --without-guile Do not compile Guile support even if found echo. --debug Make a Debug build--default is Release echo. --x86 Make a 32bit binary--default is 64bit echo. --help Display these instructions and exit echo. echo. "gcc" means compile with GCC, "tcc" means compile with Tiny C's TCC goto :EOF :Reset set ARCH= set COMPILER= set DEBUG= set GUILE= set GUILECFLAGS= set GUILELIBS= set LINKOPTS= set MAKE= set NOGUILE= set O= set OPTS= set OUTDIR= set LNKOUT= set PKGMSC= set VSVARS= goto :EOF ================================================ FILE: builddos.bat ================================================ @echo off rem Copyright (C) 1998-2024 Free Software Foundation, Inc. rem This file is part of GNU Make. rem rem GNU Make is free software; you can redistribute it and/or modify it under rem the terms of the GNU General Public License as published by the Free rem Software Foundation; either version 3 of the License, or (at your option) rem any later version. rem rem GNU Make is distributed in the hope that it will be useful, but WITHOUT rem ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or rem FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for. rem more details. rem rem You should have received a copy of the GNU General Public License along rem with this program. If not, see . echo Building Make for MSDOS with DJGPP rem The SmallEnv trick protects against too small environment block, rem in which case the values will be truncated and the whole thing rem goes awry. COMMAND.COM will say "Out of environment space", but rem many people don't care, so we force them to care by refusing to go. rem Where is the srcdir? set XSRC=. if not "%XSRC%"=="." goto SmallEnv if "%1%"=="" goto SrcDone if "%1%"=="." goto SrcDone set XSRC=%1 if not "%XSRC%"=="%1" goto SmallEnv :SrcDone if not exist src mkdir src if not exist lib mkdir lib copy /Y %XSRC%\src\configh.dos .\src\config.h copy /Y %XSRC%\lib\glob.in.h .\lib\glob.h copy /Y %XSRC%\lib\fnmatch.in.h .\lib\fnmatch.h rem Echo ON so they will see what is going on. @echo on gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/commands.c -o commands.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/output.c -o output.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/job.c -o job.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/dir.c -o dir.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/file.c -o file.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/misc.c -o misc.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -DLOCALEDIR=\"/dev/env/DJDIR/share/locale\" -O2 -g %XSRC%/src/main.c -o main.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -DINCLUDEDIR=\"/dev/env/DJDIR/include\" -O2 -g %XSRC%/src/read.c -o read.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -DLIBDIR=\"/dev/env/DJDIR/lib\" -O2 -g %XSRC%/src/remake.c -o remake.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/rule.c -o rule.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/implicit.c -o implicit.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/default.c -o default.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/variable.c -o variable.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/warning.c -o warning.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/expand.c -o expand.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/function.c -o function.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/vpath.c -o vpath.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/hash.c -o hash.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/strcache.c -o strcache.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/version.c -o version.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/ar.c -o ar.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/arscan.c -o arscan.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/signame.c -o signame.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/remote-stub.c -o remote-stub.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/getopt.c -o getopt.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/getopt1.c -o getopt1.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/shuffle.c -o shuffle.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/load.c -o load.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/lib/glob.c -o lib/glob.o gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/lib/fnmatch.c -o lib/fnmatch.o @echo off echo commands.o > respf.$$$ for %%f in (job output dir file misc main read remake rule implicit default variable warning load) do echo %%f.o >> respf.$$$ for %%f in (expand function vpath hash strcache version ar arscan signame remote-stub getopt getopt1 shuffle) do echo %%f.o >> respf.$$$ for %%f in (lib\glob lib\fnmatch) do echo %%f.o >> respf.$$$ gcc -c -I./src -I%XSRC%/src -I./lib -I%XSRC%/lib -DHAVE_CONFIG_H -O2 -g %XSRC%/src/guile.c -o guile.o echo guile.o >> respf.$$$ @echo Linking... @echo on gcc -o make.exe @respf.$$$ @echo off if not exist make.exe echo Make.exe build failed... if exist make.exe echo make.exe is now built! if exist make.exe del respf.$$$ if exist make.exe copy /Y %XSRC%\Basic.mk Makefile goto End :SmallEnv echo Your environment is too small. Please enlarge it and run me again. :End set XRSC= @echo on ================================================ FILE: configure.ac ================================================ # Process this file with autoconf to produce a configure script. # # Copyright (C) 1993-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . AC_INIT([GNU Make],[4.4.90],[bug-make@gnu.org]) AC_PREREQ([2.69]) # Autoconf setup AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_SRCDIR([src/vpath.c]) AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_LIBOBJ_DIR([lib]) # Automake setup # We have to enable "foreign" because ChangeLog is auto-generated # Automake 1.15 and gnulib don't get along: gnulib has some strange error # in the way it handles getloadavg.c which causes make distcheck to fail. # https://lists.gnu.org/archive/html/bug-gnulib/2018-06/msg00024.html AM_INIT_AUTOMAKE([1.16.1 foreign -Werror -Wall]) # Checks for programs. AC_USE_SYSTEM_EXTENSIONS AC_PROG_CC AC_PROG_CXX AC_DEFINE_UNQUOTED(MAKE_CXX, ["$CXX"], [Default C++ compiler.]) # Configure gnulib gl_EARLY gl_INIT AC_PROG_INSTALL AC_PROG_RANLIB AC_PROG_CPP AC_CHECK_PROG([AR], [ar], [ar], [ar]) # Perl is needed for the test suite (only) AC_CHECK_PROG([PERL], [perl], [perl], [perl]) # Specialized system macros AC_CANONICAL_HOST AC_C_BIGENDIAN # Enable gettext, in "external" mode. AM_GNU_GETTEXT_VERSION([0.19.4]) AM_GNU_GETTEXT([external]) # Checks for libraries. AC_SEARCH_LIBS([strerror],[cposix]) AC_SEARCH_LIBS([getpwnam], [sun]) AC_HEADER_DIRENT AC_HEADER_STAT AC_CHECK_HEADERS([stdlib.h string.h strings.h locale.h unistd.h limits.h \ memory.h sys/param.h sys/resource.h sys/time.h sys/select.h \ sys/file.h fcntl.h spawn.h]) AM_PROG_CC_C_O AC_C_CONST AC_TYPE_UID_T AC_TYPE_PID_T AC_TYPE_OFF_T AC_TYPE_SIZE_T AC_TYPE_SSIZE_T AC_TYPE_INTMAX_T AC_TYPE_UINTMAX_T # Check for sig_atomic_t gt_TYPE_SIG_ATOMIC_T # Find out whether our struct stat returns nanosecond resolution timestamps. AC_STRUCT_ST_MTIM_NSEC AC_CACHE_CHECK([whether to use high resolution file timestamps], [make_cv_file_timestamp_hi_res], [ make_cv_file_timestamp_hi_res=no AS_IF([test "$ac_cv_struct_st_mtim_nsec" != no], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #if HAVE_INTTYPES_H # include #endif]], [[char a[0x7fffffff < (uintmax_t)-1 >> 30 ? 1 : -1];]])], [make_cv_file_timestamp_hi_res=yes]) ])]) AS_IF([test "$make_cv_file_timestamp_hi_res" = yes], [val=1], [val=0]) AC_DEFINE_UNQUOTED([FILE_TIMESTAMP_HI_RES], [$val], [Use high resolution file timestamps if nonzero.]) AS_IF([test "$make_cv_file_timestamp_hi_res" = yes], [ # Solaris 2.5.1 needs -lposix4 to get the clock_gettime function. # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4. AC_SEARCH_LIBS([clock_gettime], [rt posix4]) AS_IF([test "$ac_cv_search_clock_gettime" != no], [ AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to 1 if you have the clock_gettime function.]) ]) ]) # See if we have a standard version of gettimeofday(). Since actual # implementations can differ, just make sure we have the most common # one. AC_CACHE_CHECK([for standard gettimeofday], [ac_cv_func_gettimeofday], [ac_cv_func_gettimeofday=no AC_RUN_IFELSE([AC_LANG_SOURCE([[#include int main () { struct timeval t; t.tv_sec = -1; t.tv_usec = -1; return gettimeofday (&t, 0) != 0 || t.tv_sec < 0 || t.tv_usec < 0; }]])], [ac_cv_func_gettimeofday=yes], [ac_cv_func_gettimeofday=no], [ac_cv_func_gettimeofday="no (cross-compiling)"])]) AS_IF([test "$ac_cv_func_gettimeofday" = yes], [ AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [Define to 1 if you have a standard gettimeofday function]) ]) AC_CHECK_FUNCS([strtoll strdup strndup stpcpy memrchr mempcpy umask mkstemp \ mktemp fdopen dup dup2 getcwd realpath sigsetmask sigaction \ getgroups seteuid setegid setlinebuf setreuid setregid \ mkfifo getrlimit setrlimit setvbuf pipe strerror strsignal \ lstat readlink atexit isatty ttyname pselect posix_spawn \ posix_spawnattr_setsigmask]) # We need to check declarations, not just existence, because on Tru64 this # function is not declared without special flags, which themselves cause # other problems. We'll just use our own. AC_CHECK_DECLS([bsd_signal], [], [], [[#define _GNU_SOURCE 1 #include ]]) AC_FUNC_FORK # Rumor has it that strcasecmp lives in -lresolv on some odd systems. # It doesn't hurt much to use our own if we can't find it so I don't # make the effort here. AC_CHECK_FUNCS([strcasecmp strncasecmp strcmpi strncmpi stricmp strnicmp]) # strcoll() is used by the GNU glob library AC_FUNC_STRCOLL AC_FUNC_CLOSEDIR_VOID # dir.c and our glob.c use dirent.d_type if available AC_STRUCT_DIRENT_D_TYPE # See if the user wants to add (or not) GNU Guile support AC_ARG_WITH([guile], [AS_HELP_STRING([--with-guile], [Support GNU Guile for embedded scripting])]) # Annoyingly, each version of Guile comes with it's own PC file so we have to # specify them as individual packages. Ugh. PKG_PROG_PKG_CONFIG AS_IF([test "x$with_guile" != xno], [ guile_versions="3.0 2.2 2.0 1.8" guile_version=no have_guile=no AC_MSG_CHECKING([for GNU Guile]) for v in $guile_versions; do PKG_CHECK_EXISTS([guile-$v], [guile_version=$v; have_guile=yes; break], []) done AC_MSG_RESULT([$guile_version]) AS_IF([test "$have_guile" = yes], [ PKG_CHECK_MODULES(GUILE, [guile-$guile_version]) # Unfortunately pkg doesn't help in multi-arch environments where the # package is installed for some architectures but not others; we need # to try to link. keep_CPPFLAGS="$CPPFLAGS" keep_LIBS="$LIBS" CPPFLAGS="$CPPFLAGS $GUILE_CFLAGS" LIBS="$LIBS $GUILE_LIBS" AC_CHECK_HEADER([libguile.h], [have_guile=yes], [have_guile=no], [/* Avoid configuration error warnings. */]) AS_IF([test "$have_guile" = yes], [ AC_MSG_CHECKING([whether we can link GNU Guile]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include static void * guile_init (void *arg) { (void) arg; return 0; } ]], [[ scm_with_guile (guile_init, 0); ]])], [have_guile=yes], [have_guile=no]) AC_MSG_RESULT([$have_guile])]) CPPFLAGS="$keep_CPPFLAGS" LIBS="$keep_LIBS" ]) ]) AS_IF([test "$have_guile" = yes], [AC_DEFINE([HAVE_GUILE], [1], [Embed GNU Guile support])]) AM_CONDITIONAL([HAVE_GUILE], [test "$have_guile" = "yes"]) AC_CHECK_DECLS([sys_siglist, _sys_siglist, __sys_siglist], , , [AC_INCLUDES_DEFAULT #include /* NetBSD declares sys_siglist in unistd.h. */ #if HAVE_UNISTD_H # include #endif ]) # Check out the wait reality. AC_CHECK_HEADERS([sys/wait.h],[],[],[[#include ]]) AC_CHECK_FUNCS([waitpid wait3]) AC_CACHE_CHECK([for union wait], [make_cv_union_wait], [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include #include ]], [[union wait status; int pid; pid = wait (&status); #ifdef WEXITSTATUS /* Some POSIXoid systems have both the new-style macros and the old union wait type, and they do not work together. If union wait conflicts with WEXITSTATUS et al, we don't want to use it at all. */ if (WEXITSTATUS (status) != 0) pid = -1; #ifdef WTERMSIG /* If we have WEXITSTATUS and WTERMSIG, just use them on ints. */ -- blow chunks here -- #endif #endif #ifdef HAVE_WAITPID /* Make sure union wait works with waitpid. */ pid = waitpid (-1, &status, 0); #endif ]])], [make_cv_union_wait=yes], [make_cv_union_wait=no]) ]) AS_IF([test "$make_cv_union_wait" = yes], [ AC_DEFINE([HAVE_UNION_WAIT], [1], [Define to 1 if you have the 'union wait' type in .]) ]) # If we're building on Windows/DOS/OS/2, add some support for DOS drive specs. AS_IF([test "$PATH_SEPARATOR" = ';'], [ AC_DEFINE([HAVE_DOS_PATHS], [1], [Define to 1 if your system requires backslashes or drive specs in pathnames.]) ]) # See if the user wants to use pmake's "customs" distributed build capability AC_SUBST([REMOTE]) REMOTE=stub use_customs=false AC_ARG_WITH([customs], [AS_HELP_STRING([--with-customs=DIR],[enable remote jobs via Customs--see README.customs])], [ AS_CASE([$withval], [n|no], [:], [make_cppflags="$CPPFLAGS" AS_CASE([$withval], [y|ye|yes], [:], [CPPFLAGS="$CPPFLAGS -I$with_customs/include/customs" make_ldflags="$LDFLAGS -L$with_customs/lib"]) CF_NETLIBS AC_CHECK_HEADER([customs.h], [use_customs=true REMOTE=cstms LIBS="$LIBS -lcustoms" LDFLAGS="$make_ldflags"], [with_customs=no CPPFLAGS="$make_cppflags" make_badcust=yes]) ]) ]) # Tell automake about this, so it can include the right .c files. AM_CONDITIONAL([USE_CUSTOMS], [test "$use_customs" = true]) # See if the user asked to handle case insensitive file systems. AH_TEMPLATE([HAVE_CASE_INSENSITIVE_FS], [Use case insensitive file names]) AC_ARG_ENABLE([case-insensitive-file-system], AS_HELP_STRING([--enable-case-insensitive-file-system],[assume file systems are case insensitive]), [AS_IF([test "$enableval" = yes], [AC_DEFINE([HAVE_CASE_INSENSITIVE_FS])])]) # See if we can handle the job server feature, and if the user wants it. AC_ARG_ENABLE([job-server], AS_HELP_STRING([--disable-job-server],[disallow recursive make communication during -jN]), [make_cv_job_server="$enableval" user_job_server="$enableval"], [make_cv_job_server="yes"]) AS_IF([test "$ac_cv_func_waitpid" = no && test "$ac_cv_func_wait3" = no], [has_wait_nohang=no], [has_wait_nohang=yes]) AC_CACHE_CHECK([for SA_RESTART], [make_cv_sa_restart], [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[return SA_RESTART;]])], [make_cv_sa_restart=yes], [make_cv_sa_restart=no])]) AS_IF([test "$make_cv_sa_restart" != no], [ AC_DEFINE([HAVE_SA_RESTART], [1], [Define to 1 if defines the SA_RESTART constant.]) ]) # Only allow jobserver on systems that support it AS_CASE([/$ac_cv_func_pipe/$ac_cv_func_sigaction/$make_cv_sa_restart/$has_wait_nohang/], [*/no/*], [make_cv_job_server=no]) # Also supported on OS2 and MinGW AS_CASE([$host_os], [os2*|mingw*], [make_cv_job_server=yes]) # If we support it and the user didn't disable it, build with jobserver AS_CASE([/$make_cv_job_server/$user_job_server/], [*/no/*], [: no jobserver], [AC_DEFINE(MAKE_JOBSERVER, 1, [Define to 1 to enable job server support in GNU Make.]) ]) # If dl*() functions are supported we can enable the load operation AC_CHECK_DECLS([dlopen, dlsym, dlerror], [], [], [[#include ]]) AC_ARG_ENABLE([load], AS_HELP_STRING([--disable-load],[disable support for the 'load' operation]), [make_cv_load="$enableval" user_load="$enableval"], [make_cv_load="yes"]) AS_CASE([/$ac_cv_have_decl_dlopen/$ac_cv_have_decl_dlsym/$ac_cv_have_decl_dlerror/], [*/no/*], [make_cv_load=no]) # We might need -ldl AS_IF([test "$make_cv_load" = yes], [ AC_SEARCH_LIBS([dlopen], [dl], [], [make_cv_load=]) ]) AS_CASE([/$make_cv_load/$user_load/], [*/no/*], [make_cv_load=no], [AC_DEFINE(MAKE_LOAD, 1, [Define to 1 to enable 'load' support in GNU Make.]) ]) # If we want load support, we might need to link with export-dynamic. # See if we can figure it out. Unfortunately this is very difficult. # For example passing -rdynamic to the SunPRO linker gives a warning # but succeeds and creates a shared object, not an executable! AS_IF([test "$make_cv_load" = yes], [ AC_MSG_CHECKING([if the linker accepts -Wl,--export-dynamic]) old_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -Wl,--export-dynamic" AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){}])], [AC_MSG_RESULT([yes]) AC_SUBST([AM_LDFLAGS], [-Wl,--export-dynamic])], [AC_MSG_RESULT([no]) AC_MSG_CHECKING([if the linker accepts -rdynamic]) LDFLAGS="$old_LDFLAGS -rdynamic" AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){}])], [AC_MSG_RESULT([yes]) AC_SUBST([AM_LDFLAGS], [-rdynamic])], [AC_MSG_RESULT([no])]) ]) LDFLAGS="$old_LDFLAGS" ]) # if we have both lstat() and readlink() then we can support symlink # timechecks. AS_IF([test "$ac_cv_func_lstat" = yes && test "$ac_cv_func_readlink" = yes], [ AC_DEFINE([MAKE_SYMLINKS], [1], [Define to 1 to enable symbolic link timestamp checking.]) ]) # Use posix_spawn if we have support and the user didn't disable it AC_ARG_ENABLE([posix-spawn], AS_HELP_STRING([--disable-posix-spawn],[disable support for posix_spawn()]), [make_cv_posix_spawn="$enableval" user_posix_spawn="$enableval"], [make_cv_posix_spawn="yes"]) AS_CASE([/$ac_cv_header_spawn/$ac_cv_func_posix_spawn/], [*/no/*], [make_cv_posix_spawn=no]) AS_IF([test "$make_cv_posix_spawn" = yes], AC_CACHE_CHECK([for posix_spawn that fails synchronously], [make_cv_synchronous_posix_spawn], [make_cv_synchronous_posix_spawn=no AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include extern char **environ; int main () { char path[[]] = "./xxx-non-existent"; char *argv[[]] = {path, 0}; return posix_spawn (0, path, 0, 0, argv, environ) == ENOENT ? 0 : 1; }]])], [make_cv_synchronous_posix_spawn=yes], [make_cv_synchronous_posix_spawn=no], [make_cv_synchronous_posix_spawn="no (cross-compiling)"])])) AS_CASE([/$user_posix_spawn/$make_cv_posix_spawn/$make_cv_synchronous_posix_spawn/], [*/no/*], [make_cv_posix_spawn=no], [AC_DEFINE(USE_POSIX_SPAWN, 1, [Define to 1 to use posix_spawn().]) ]) # Find the SCCS commands, so we can include them in our default rules. AC_CACHE_CHECK([for location of SCCS get command], [make_cv_path_sccs_get], [ AS_IF([test -f /usr/sccs/get], [make_cv_path_sccs_get=/usr/sccs/get], [make_cv_path_sccs_get=get]) ]) AC_DEFINE_UNQUOTED([SCCS_GET], ["$make_cv_path_sccs_get"], [Define to the name of the SCCS 'get' command.]) ac_clean_files="$ac_clean_files s.conftest conftoast" # Remove these later. AS_IF([(/usr/sccs/admin -n s.conftest || admin -n s.conftest) >/dev/null 2>&1 && test -f s.conftest], [ # We successfully created an SCCS file. AC_CACHE_CHECK([if SCCS get command understands -G], [make_cv_sys_get_minus_G], [AS_IF([$make_cv_path_sccs_get -Gconftoast s.conftest >/dev/null 2>&1 && test -f conftoast], [make_cv_sys_get_minus_G=yes], [make_cv_sys_get_minus_G=no]) ]) AS_IF([test "$make_cv_sys_get_minus_G" = yes], [AC_DEFINE([SCCS_GET_MINUS_G], [1], [Define to 1 if the SCCS 'get' command understands the '-G' option.]) ]) ]) rm -f s.conftest conftoast # Let the makefile know what our build host is AC_DEFINE_UNQUOTED([MAKE_HOST],["$host"],[Build host information.]) MAKE_HOST="$host" AC_SUBST([MAKE_HOST]) w32_target_env=no AM_CONDITIONAL([WINDOWSENV], [false]) AM_CONDITIONAL([HAVE_WINDRES], [false]) AS_CASE([$host], [*-*-mingw32], [AM_CONDITIONAL([WINDOWSENV], [true]) w32_target_env=yes AC_DEFINE([MK_OS_W32], [1], [Build for the Windows32 API.]) AC_DEFINE([HAVE_DOS_PATHS], [1], [Support DOS-style pathnames.]) # Windows host tools. # If windres is available, make will use UTF-8. AC_CHECK_TOOL([WINDRES], [windres], [:]) AM_CONDITIONAL([HAVE_WINDRES], [test "$WINDRES" != ':']) ]) AC_DEFINE_UNQUOTED([PATH_SEPARATOR_CHAR],['$PATH_SEPARATOR'], [Define to the character that separates directories in PATH.]) AC_DEFINE_UNQUOTED([HAVE_DECL_GETLOADAVG],[$HAVE_DECL_GETLOADAVG], [Define to 1 if you have the declaration of 'getloadavg'.]) # Remember that we ran configure to generate config.h AC_DEFINE([MK_CONFIGURE], [1], [Define to 1 if config.h is generated by running the configure script.]) # Include the Maintainer's Makefile section, if it's here. MAINT_MAKEFILE=/dev/null AS_IF([test -r "$srcdir/maintMakefile"], [ MAINT_MAKEFILE="$srcdir/maintMakefile" ]) AC_SUBST_FILE([MAINT_MAKEFILE]) # Allow building with dmalloc AM_WITH_DMALLOC # Add custom header to config.h AH_BOTTOM([/* Include customized declarations. */ #include "../src/mkcustom.h"]) # Forcibly disable SET_MAKE. If it's set it breaks things like the test # scripts, etc. SET_MAKE= # Sanity check and inform the user of what we found AS_IF([test "x$make_badcust" = xyes], [ echo echo "WARNING: --with-customs specified but no customs.h could be found;" echo " disabling Customs support." echo ]) AS_CASE([$with_customs], [""|n|no|y|ye|yes], [:], [AS_IF([test -f "$with_customs/lib/libcustoms.a"], [:], [ echo echo "WARNING: '$with_customs/lib' does not appear to contain the" echo " Customs library. You must build and install Customs" echo " before compiling GNU Make." echo ])]) AS_IF([test "x$has_wait_nohang" = xno], [ echo echo "WARNING: Your system has neither waitpid() nor wait3()." echo " Without one of these, signal handling is unreliable." echo " You should be aware that running GNU Make with -j" echo " could result in erratic behavior." echo ]) AS_IF([test "x$make_cv_job_server" = xno && test "x$user_job_server" = xyes], [ echo echo "WARNING: Make job server requires a POSIX-ish system that" echo " supports the pipe(), sigaction(), and either" echo " waitpid() or wait3() functions. Your system doesn't" echo " appear to provide one or more of those." echo " Disabling job server support." echo ]) AS_IF([test "x$make_cv_load" = xno && test "x$user_load" = xyes], [ echo echo "WARNING: 'load' support requires a POSIX-ish system that" echo " supports the dlopen(), dlsym(), and dlerror() functions." echo " Your system doesn't appear to provide one or more of these." echo " Disabling 'load' support." echo ]) AS_IF([test "x$make_cv_posix_spawn" = xno && test "x$user_posix_spawn" = xyes], [ echo echo "WARNING: posix_spawn() is not supported on this system." echo ]) # autoconf initializes $prefix to NONE. AM_CONDITIONAL([KNOWN_PREFIX], [test "x$prefix" = xNONE -o "x$prefix" = x/usr/local \ -o "x$prefix" = x/usr/gnu -o "x$prefix" = x/usr]) # Specify what files are to be created. AC_CONFIG_FILES([build.cfg tests/config-flags.pm \ Makefile lib/Makefile doc/Makefile po/Makefile.in]) # We don't need this: the standard automake output suffices for POSIX systems. #mk/Posix.mk # Put build.sh in the build directory so it's easy to find AC_CONFIG_LINKS([build.sh:build.sh]) # OK, do it! AC_OUTPUT dnl Local Variables: dnl comment-start: "dnl " dnl comment-end: "" dnl comment-start-skip: "\\bdnl\\b\\s *" dnl compile-command: "make configure config.h.in" dnl End: ================================================ FILE: doc/.gitignore ================================================ manual/ make.t2d/ make.t2p/ gendocs_template fdl.texi make-stds.texi stamp-vti version.texi make.info* make*.html make.aux make.cp make.cps make.dvi make.fn make.fns make.ky make.log make.pdf make.pg make.ps make.toc make.tp make.vr ================================================ FILE: doc/Makefile.am ================================================ # -*-Makefile-*-, or close enough # Copyright (C) 2000-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . TEXI2HTML = texi2html TEXI2HTML_FLAGS = -split_chapter info_TEXINFOS = make.texi make_TEXINFOS = fdl.texi make-stds.texi CLEANFILES = make*.html ================================================ FILE: doc/make.1 ================================================ .TH MAKE 1 "26 May 2023" "GNU" "User Commands" .SH NAME make \- GNU Make utility to maintain groups of programs .SH SYNOPSIS .B make [\fIOPTION\fR]... [\fITARGET\fR]... .SH DESCRIPTION .LP The .I make utility will determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. The manual describes the GNU implementation of .BR make , which was written by Richard Stallman and Roland McGrath, and is currently maintained by Paul Smith. Our examples show C programs, since they are very common, but you can use .B make with any programming language whose compiler can be run with a shell command. In fact, .B make is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change. .LP To prepare to use .BR make , you must write a file called the .I makefile that describes the relationships among files in your program, and provides commands for updating each file. In a program, typically the executable file is updated from object files, which are in turn made by compiling source files. .LP Once a suitable makefile exists, each time you change some source files, this simple shell command: .sp 1 .RS .B make .RE .sp 1 suffices to perform all necessary recompilations. The .B make program uses the makefile description and the last-modification times of the files to decide which of the files need to be updated. For each of those files, it issues the commands recorded in the makefile. .LP .B make executes commands in the .I makefile to update one or more .IR targets , where .I target is typically a program. If no .B \-f option is present, .B make will look for the makefiles .IR GNUmakefile , .IR makefile , and .IR Makefile , in that order. .LP Normally you should call your makefile either .I makefile or .IR Makefile . (We recommend .I Makefile because it appears prominently near the beginning of a directory listing, right near other important files such as .IR README .) The first name checked, .IR GNUmakefile , is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU Make, and will not be understood by other versions of .BR make . If .I makefile is '\-', the standard input is read. .LP .B make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist. .SH OPTIONS .sp 1 .TP 0.5i \fB\-b\fR, \fB\-m\fR These options are ignored for compatibility with other versions of .BR make . .TP 0.5i \fB\-B\fR, \fB\-\-always\-make\fR Unconditionally make all targets. .TP 0.5i \fB\-C\fR \fIdir\fR, \fB\-\-directory\fR=\fIdir\fR Change to directory .I dir before reading the makefiles or doing anything else. If multiple .B \-C options are specified, each is interpreted relative to the previous one: .BR "\-C " / .BR "\-C " etc is equivalent to .BR "\-C " /etc. This is typically used with recursive invocations of .BR make . .TP 0.5i .B \-d Print debugging information in addition to normal processing. The debugging information says which files are being considered for remaking, which file-times are being compared and with what results, which files actually need to be remade, which implicit rules are considered and which are applied---everything interesting about how .B make decides what to do. .TP 0.5i .BI \-\-debug "[=FLAGS]" Print debugging information in addition to normal processing. If the .I FLAGS are omitted, then the behavior is the same as if .B \-d was specified. .I FLAGS may be any or all of the following names, comma- or space-separated. Only the first character is significant: the rest may be omitted: .I all for all debugging output (same as using .BR \-d ), .I basic for basic debugging, .I verbose for more verbose basic debugging, .I implicit for showing implicit rule search operations, .I jobs for details on invocation of commands, .I makefile for debugging while remaking makefiles, .I print shows all recipes that are run even if they are silent, and .I why shows the reason .BR make decided to rebuild each target. Use .I none to disable all previous debugging flags. .TP 0.5i \fB\-e\fR, \fB\-\-environment\-overrides\fR Give variables taken from the environment precedence over variables from makefiles. .TP 0.5i \fB\-E\fR \fIstring\fR, \fB\-\-eval\fR \fIstring\fR Interpret \fIstring\fR using the \fBeval\fR function, before parsing any makefiles. .TP 0.5i \fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR, \fB\-\-makefile\fR=\fIFILE\fR Use .I file as a makefile. .TP 0.5i \fB\-i\fR, \fB\-\-ignore\-errors\fR Ignore all errors in commands executed to remake files. .TP 0.5i \fB\-I\fR \fIdir\fR, \fB\-\-include\-dir\fR=\fIdir\fR Specifies a directory .I dir to search for included makefiles. If several .B \-I options are used to specify several directories, the directories are searched in the order specified. Unlike the arguments to other flags of .BR make , directories given with .B \-I flags may come directly after the flag: .BI \-I dir is allowed, as well as .B \-I .IR dir . This syntax is allowed for compatibility with the C preprocessor's .B \-I flag. .TP 0.5i \fB\-j\fR [\fIjobs\fR], \fB\-\-jobs\fR[=\fIjobs\fR] Specifies the number of .I jobs (commands) to run simultaneously. If there is more than one .B \-j option, the last one is effective. If the .B \-j option is given without an argument, .BR make will not limit the number of jobs that can run simultaneously. .TP 0.5i \fB\--jobserver-style=\fR\fIstyle\fR The style of jobserver to use. The .I style may be one of .BR fifo , .BR pipe , or .B sem (Windows only). .TP 0.5i \fB\-k\fR, \fB\-\-keep\-going\fR Continue as much as possible after an error. While the target that failed, and those that depend on it, cannot be remade, the other dependencies of these targets can be processed all the same. .TP 0.5i \fB\-l\fR [\fIload\fR], \fB\-\-load\-average\fR[=\fIload\fR] Specifies that no new jobs (commands) should be started if there are others jobs running and the load average is at least .I load (a floating-point number). With no argument, removes a previous load limit. .TP 0.5i \fB\-L\fR, \fB\-\-check\-symlink\-times\fR Use the latest mtime between symlinks and target. .TP 0.5i \fB\-n\fR, \fB\-\-just\-print\fR, \fB\-\-dry\-run\fR, \fB\-\-recon\fR Print the commands that would be executed, but do not execute them (except in certain circumstances). .TP 0.5i \fB\-o\fR \fIfile\fR, \fB\-\-old\-file\fR=\fIfile\fR, \fB\-\-assume\-old\fR=\fIfile\fR Do not remake the file .I file even if it is older than its dependencies, and do not remake anything on account of changes in .IR file . Essentially the file is treated as very old and its rules are ignored. .TP 0.5i \fB\-O\fR[\fItype\fR], \fB\-\-output\-sync\fR[=\fItype\fR] When running multiple jobs in parallel with \fB-j\fR, ensure the output of each job is collected together rather than interspersed with output from other jobs. If .I type is not specified or is .B target the output from the entire recipe for each target is grouped together. If .I type is .B line the output from each command line within a recipe is grouped together. If .I type is .B recurse output from an entire recursive make is grouped together. If .I type is .B none output synchronization is disabled. .TP 0.5i \fB\-p\fR, \fB\-\-print\-data\-base\fR Print the data base (rules and variable values) that results from reading the makefiles; then execute as usual or as otherwise specified. This also prints the version information given by the .B \-v switch (see below). To print the built-in data base only, use .IR "make \-p \-f/dev/null" . .TP 0.5i \fB\-\-print\-targets\fR Print each target defined as a result of reading the makefiles, one target per line, then exit with success. Implicit rule targets are not printed, nor are special targets (target names that consist of "." followed by all upper-case letters). No recipe commands are invoked and no makefiles are rebuilt. .TP 0.5i \fB\-q\fR, \fB\-\-question\fR ``Question mode''. Do not run any commands, or print anything; just return an exit status that is zero if the specified targets are already up to date, nonzero otherwise. .TP 0.5i \fB\-r\fR, \fB\-\-no\-builtin\-rules\fR Eliminate use of the built\-in implicit rules. Also clear out the default list of suffixes for suffix rules. .TP 0.5i \fB\-R\fR, \fB\-\-no\-builtin\-variables\fR Don't define any built\-in variables. .TP 0.5i \fB\-s\fR, \fB\-\-silent\fR, \fB\-\-quiet\fR Silent operation; do not print the commands as they are executed. .TP 0.5i .B \-\-no\-silent Cancel the effect of the \fB\-s\fR option. .TP 0.5i \fB\-S\fR, \fB\-\-no\-keep\-going\fR, \fB\-\-stop\fR Cancel the effect of the .B \-k option. .TP 0.5i \fB\-t\fR, \fB\-\-touch\fR Touch files (mark them up to date without really changing them) instead of running their commands. This is used to pretend that the commands were done, in order to fool future invocations of .BR make . .TP 0.5i .B \-\-trace Information about the disposition of each target is printed (why the target is being rebuilt and what commands are run to rebuild it). .TP 0.5i \fB\-v\fR, \fB\-\-version\fR Print the version of the .B make program plus a copyright, a list of authors and a notice that there is no warranty. .TP 0.5i \fB\-w\fR, \fB\-\-print\-directory\fR Print a message containing the working directory before and after other processing. This may be useful for tracking down errors from complicated nests of recursive .B make commands. .TP 0.5i .B \-\-no\-print\-directory Turn off .BR \-w , even if it was turned on implicitly. .TP 0.5i .BI \-\-shuffle "[=MODE]" Enable shuffling of goal and prerequisite ordering. .I MODE is one of .I none to disable shuffle mode, .I random to shuffle prerequisites in random order, .I reverse to consider prerequisites in reverse order, or an integer .I which enables .I random mode with a specific .I seed value. If .I MODE is omitted the default is .IR random . .TP 0.5i \fB\-W\fR \fIfile\fR, \fB\-\-what\-if\fR=\fIfile\fR, \fB\-\-new\-file\fR=\fIfile\fR, \fB\-\-assume\-new\fR=\fIfile\fR Pretend that the target .I file has just been modified. When used with the .B \-n flag, this shows you what would happen if you were to modify that file. Without .BR \-n , it is almost the same as running a .I touch command on the given file before running .BR make , except that the modification time is changed only in the imagination of .BR make . .TP 0.5i \fB\-\-warn\fR[=\fIARG[\fR,\fIARG\fR]] Control warning reporting for makefiles. This option can appear multiple times. In case of conflicts, later settings override earlier settings. .I ARG can be an action; one of .IR ignore , .IR warn , or .I error to set the default action for all warnings, or it can be a specific warning: .I circular-dep (finding a circular dependency), .I invalid-ref (referencing an invalid variable name), .I invalid-var (assigning to an invalid variable name), or .I undefined-var (referencing an undefined variable). The behavior of each warning can be set by adding .BI : action after the warning name. If an action is not specified the default is .IR warn . If no .I ARG is provided the action for all warnings is .IR warn . If no .B \-\-warn option is provided the default action for .I invalid-var and .I invalid-ref is .I warn and the default action for .I undefined-var is .IR ignore . .TP 0.5i .B \-\-warn\-undefined\-variables A deprecated alternative for .BR \-\-warn=undefined-var . .SH "EXIT STATUS" GNU Make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed. A status of one will be returned if the .B \-q flag was used and .B make determines that a target needs to be rebuilt. A status of two will be returned if any errors were encountered. .SH "SEE ALSO" The full documentation for .B make is maintained as a Texinfo manual. If the .B info and .B make programs are properly installed at your site, the command .IP .B info make .PP should give you access to the complete manual. .SH BUGS See the chapter ``Problems and Bugs'' in .IR "The GNU Make Manual" . .SH AUTHOR This manual page contributed by Dennis Morse of Stanford University. Further updates contributed by Mike Frysinger. It has been reworked by Roland McGrath. Maintained by Paul Smith. .SH "COPYRIGHT" Copyright \(co 1992\(en1993, 1996\(en2024 Free Software Foundation, Inc. This file is part of .IR "GNU Make" . .LP GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. .LP GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. .LP You should have received a copy of the GNU General Public License along with this program. If not, see .IR https://www.gnu.org/licenses/ . ================================================ FILE: doc/make.texi ================================================ \input texinfo @c -*- Texinfo -*- @c %**start of header @setfilename make.info @include version.texi @set EDITION 0.77 @settitle GNU Make @setchapternewpage odd @c Combine the variable and function indices: @syncodeindex vr fn @c Combine the program and concept indices: @syncodeindex pg cp @c FSF publishers: format makebook.texi instead of using this file directly. @c ISBN confirmed by Jasimin Huang on 25 Mar 2009 @set ISBN 1-882114-83-3 @c %**end of header @copying This file documents the GNU implementation of the @code{make} utility. @code{make} determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them. This is Edition @value{EDITION}, last updated @value{UPDATED}, of @cite{The GNU Make Manual}, for GNU @code{make} version @value{VERSION}. Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled ``GNU Free Documentation License.'' (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and modify this GNU manual. Buying copies from the FSF supports it in developing GNU and promoting software freedom.'' @end quotation @end copying @c finalout @c ISPELL CHECK: done, 10 June 1993 --roland @c ISPELL CHECK: done, 2000-06-25 --Martin Buchholz @c ISPELL CHECK: done, 2023-08-30 --pds @dircategory Software development @direntry * Make: (make). Remake files automatically. @end direntry @iftex @shorttitlepage GNU Make @end iftex @titlepage @title GNU Make @subtitle A Program for Directing Recompilation @subtitle GNU @code{make} Version @value{VERSION} @subtitle @value{UPDATED-MONTH} @author Richard M. Stallman, Roland McGrath, Paul D. Smith @page @vskip 0pt plus 1filll @insertcopying @sp 2 Published by the Free Software Foundation @* 51 Franklin St. -- Fifth Floor @* Boston, MA 02110-1301 USA @* ISBN @value{ISBN} @* @sp 2 Cover art by Etienne Suvasa. @end titlepage @summarycontents @contents @ifnottex @node Top, Overview, (dir), (dir) @top GNU Make @insertcopying @end ifnottex @menu * Overview:: Overview of @code{make}. * Introduction:: An introduction to @code{make}. * Makefiles:: Makefiles tell @code{make} what to do. * Rules:: Rules describe when a file must be remade. * Recipes:: Recipes say how to remake a file. * Using Variables:: You can use variables to avoid repetition. * Conditionals:: Use or ignore parts of the makefile based on the values of variables. * Functions:: Many powerful ways to manipulate text. * Invoking make: Running. How to invoke @code{make} on the command line. * Implicit Rules:: Use implicit rules to treat many files alike, based on their file names. * Archives:: How @code{make} can update library archives. * Extending make:: Using extensions to @code{make}. * Integrating make:: Integrating @code{make} with other tools. * Features:: Features GNU Make has over other @code{make}s. * Missing:: What GNU Make lacks from other @code{make}s. * Makefile Conventions:: Conventions for writing makefiles for GNU programs. * Quick Reference:: A quick reference for experienced users. * Error Messages:: A list of common errors generated by @code{make}. * Troubleshooting:: Advice on finding problems. * Complex Makefile:: A real example of a straightforward, but nontrivial, makefile. * GNU Free Documentation License:: License for copying this manual. * Concept Index:: Index of Concepts. * Name Index:: Index of Functions, Variables, & Directives. @detailmenu --- The Detailed Node Listing --- Overview of @code{make} * Preparing:: Preparing and running @code{make}. * Reading:: On reading this text. * Bugs:: Problems and bugs. An Introduction to Makefiles * Rule Introduction:: What a rule looks like. * Simple Makefile:: A simple makefile. * How Make Works:: How @code{make} processes this makefile. * Variables Simplify:: Variables make makefiles simpler. * make Deduces:: Letting @code{make} deduce the recipes. * Combine By Prerequisite:: Another style of makefile. * Cleanup:: Rules for cleaning the directory. Writing Makefiles * Makefile Contents:: What makefiles contain. * Makefile Names:: How to name your makefile. * Include:: How one makefile can use another makefile. * MAKEFILES Variable:: The environment can specify extra makefiles. * Remaking Makefiles:: How makefiles get remade. * Overriding Makefiles:: How to override part of one makefile with another makefile. * Reading Makefiles:: How makefiles are read in. * Parsing Makefiles:: How makefiles are parsed. * Secondary Expansion:: How and when secondary expansion is performed. What Makefiles Contain * Splitting Lines:: Splitting long lines in makefiles Writing Rules * Rule Example:: An example explained. * Rule Syntax:: General syntax explained. * Prerequisite Types:: There are two types of prerequisites. * Wildcards:: Using wildcard characters such as `*'. * Directory Search:: Searching other directories for source files. * Phony Targets:: Using a target that is not a real file's name. * Force Targets:: You can use a target without a recipe or prerequisites to mark other targets as phony. * Empty Targets:: When only the date matters and the files are empty. * Special Targets:: Targets with special built-in meanings. * Multiple Targets:: When to make use of several targets in a rule. * Multiple Rules:: How to use several rules with the same target. * Static Pattern:: Static pattern rules apply to multiple targets and can vary the prerequisites according to the target name. * Double-Colon:: How to use a special kind of rule to allow several independent rules for one target. * Automatic Prerequisites:: How to automatically generate rules giving prerequisites from source files themselves. Using Wildcard Characters in File Names * Wildcard Examples:: Several examples. * Wildcard Pitfall:: Problems to avoid. * Wildcard Function:: How to cause wildcard expansion where it does not normally take place. Searching Directories for Prerequisites * General Search:: Specifying a search path that applies to every prerequisite. * Selective Search:: Specifying a search path for a specified class of names. * Search Algorithm:: When and how search paths are applied. * Recipes/Search:: How to write recipes that work together with search paths. * Implicit/Search:: How search paths affect implicit rules. * Libraries/Search:: Directory search for link libraries. Static Pattern Rules * Static Usage:: The syntax of static pattern rules. * Static versus Implicit:: When are they better than implicit rules? Writing Recipes in Rules * Recipe Syntax:: Recipe syntax features and pitfalls. * Echoing:: How to control when recipes are echoed. * Execution:: How recipes are executed. * Parallel:: How recipes can be executed in parallel. * Errors:: What happens after a recipe execution error. * Interrupts:: What happens when a recipe is interrupted. * Recursion:: Invoking @code{make} from makefiles. * Canned Recipes:: Defining canned recipes. * Empty Recipes:: Defining useful, do-nothing recipes. Recipe Syntax * Splitting Recipe Lines:: Breaking long recipe lines for readability. * Variables in Recipes:: Using @code{make} variables in recipes. Recipe Execution * One Shell:: One shell for all lines in a recipe. * Choosing the Shell:: How @code{make} chooses the shell used to run recipes. Parallel Execution * Parallel Disable:: Disabling parallel execution * Parallel Output:: Handling output during parallel execution * Parallel Input:: Handling input during parallel execution Recursive Use of @code{make} * MAKE Variable:: The special effects of using @samp{$(MAKE)}. * Variables/Recursion:: How to communicate variables to a sub-@code{make}. * Options/Recursion:: How to communicate options to a sub-@code{make}. * -w Option:: How the @samp{-w} or @samp{--print-directory} option helps debug use of recursive @code{make} commands. How to Use Variables * Variable Naming:: Choosing names for variables. * Reference:: How to use the value of a variable. * Flavors:: Variables come in two flavors. * Expanding:: How text is expanded by @code{make}. * Values:: All the ways variables get their values. * Setting:: How to set a variable in the makefile. * Substitution Refs:: Substituting values in variable expansion. * Override Directive:: How to set a variable in the makefile even if the user has set it with a command argument. * Multi-Line:: An alternate way to set a variable to a multi-line string. * Undefine Directive:: How to undefine a variable so that it appears as if it was never set. * Environment:: Variable values can come from the environment. * Target-specific:: Variable values can be defined on a per-target basis. * Pattern-specific:: Target-specific variable values can be applied to a group of targets that match a pattern. * Suppressing Inheritance:: Suppress inheritance of variables. * Special Variables:: Variables with special meaning or behavior. Basics of Variable References * Computed Names:: Computing the name of a variable reference. The Two Flavors of Variables * Recursive Variables:: Recursive variables delay expansion. * Simple Variables:: Simple variables expand immediately. Setting Variables * Immediate Assignment:: Recursive variables with immediate expansion. * Shell Assignment:: Assigning variables to shell output. * Conditional Assignment:: Assigning variables only if not yet defined. * Appending Assignment:: How to append to the value of a variable. * Whitespace in Values:: Leading and trailing whitespace in values. Conditional Parts of Makefiles * Conditional Example:: Example of a conditional * Conditional Syntax:: The syntax of conditionals. * Testing Flags:: Conditionals that test flags. Functions for Transforming Text * Syntax of Functions:: How to write a function call. * Text Functions:: General-purpose text manipulation functions. * File Name Functions:: Functions for manipulating file names. * Conditional Functions:: Functions that implement conditions. * Let Function:: Local variables. * Foreach Function:: Repeat some text with controlled variation. * File Function:: Write text to a file. * Call Function:: Expand a user-defined function. * Value Function:: Return the un-expanded value of a variable. * Eval Function:: Evaluate the arguments as makefile syntax. * Origin Function:: Find where a variable got its value. * Flavor Function:: Find out the flavor of a variable. * Make Control Functions:: Functions that control how make runs. * Shell Function:: Substitute the output of a shell command. * Guile Function:: Use GNU Guile embedded scripting language. How to Run @code{make} * Makefile Arguments:: How to specify which makefile to use. * Goals:: How to use goal arguments to specify which parts of the makefile to use. * Instead of Execution:: How to use mode flags to specify what kind of thing to do with the recipes in the makefile other than simply execute them. * Avoiding Compilation:: How to avoid recompiling certain files. * Overriding:: How to override a variable to specify an alternate compiler and other things. * Testing:: How to proceed past some errors, to test compilation. * Warnings:: How to control reporting of makefile issues. * Temporary Files:: Where @code{make} keeps its temporary files. * Options Summary:: Summary of Options Using Implicit Rules * Using Implicit:: How to use an existing implicit rule to get the recipes for updating a file. * Catalogue of Rules:: A list of built-in rules. * Implicit Variables:: How to change what predefined rules do. * Chained Rules:: How to use a chain of implicit rules. * Pattern Rules:: How to define new implicit rules. * Last Resort:: How to define a recipe for rules which cannot find any. * Suffix Rules:: The old-fashioned style of implicit rule. * Implicit Rule Search:: The precise algorithm for applying implicit rules. Defining and Redefining Pattern Rules * Pattern Intro:: An introduction to pattern rules. * Pattern Examples:: Examples of pattern rules. * Automatic Variables:: How to use automatic variables in the recipe of implicit rules. * Pattern Match:: How patterns match. * Match-Anything Rules:: Precautions you should take prior to defining rules that can match any target file whatever. * Canceling Rules:: How to override or cancel built-in rules. Using @code{make} to Update Archive Files * Archive Members:: Archive members as targets. * Archive Update:: The implicit rule for archive member targets. * Archive Pitfalls:: Dangers to watch out for when using archives. * Archive Suffix Rules:: You can write a special kind of suffix rule for updating archives. Implicit Rule for Archive Member Targets * Archive Symbols:: How to update archive symbol directories. Extending GNU @code{make} * Guile Integration:: Using Guile as an embedded scripting language. * Loading Objects:: Loading dynamic objects as extensions. GNU Guile Integration * Guile Types:: Converting Guile types to @code{make} strings. * Guile Interface:: Invoking @code{make} functions from Guile. * Guile Example:: Example using Guile in @code{make}. Loading Dynamic Objects * load Directive:: Loading dynamic objects as extensions. * Initializing Functions:: How initializing functions are called. * Remaking Loaded Objects:: How loaded objects get remade. * Loaded Object API:: Programmatic interface for loaded objects. * Loaded Object Example:: Example of a loaded object Integrating GNU @code{make} * Job Slots:: Share job slots with GNU Make. * Terminal Output:: Control output to terminals. Sharing Job Slots with GNU @code{make} * POSIX Jobserver:: Using the jobserver on POSIX systems. * Windows Jobserver:: Using the jobserver on Windows systems. Quick Reference * Makefile Directives:: All makefile directives. * Makefile Functions:: All makefile built-in functions. * Automatic Variable Reference:: All automatic variables for recipes. * Special Variable Reference:: All special variables for makefiles. Troubleshooting Make and Makefiles * Parse Error:: Syntax errors when parsing makefiles. * Command Failure:: Recipe commands exit with error codes. * Wrong Rule:: @code{make} chooses the wrong rule. * No Rule Found:: No rule was found to build a target. * Extra Rebuilds:: Targets are rebuilt unnecessarily. * Missing Rebuilds:: Out-of-date targets are not rebuilt. * Troubleshooting Strategies:: Strategies used for troubleshooting issues. @end detailmenu @end menu @node Overview @comment node-name, next, previous, up @chapter Overview of @code{make} The @code{make} utility determines which files in a project are out of date, and runs commands to bring them up to date. This manual describes the GNU project's implementation of @code{make}, GNU Make, which was created by Richard Stallman and Roland McGrath. Paul D. Smith has handled development and maintenance since Version 3.76 (1997). GNU @code{make} conforms to @cite{IEEE Standard 1003.1-2024} (POSIX.1-2024). @cindex POSIX @cindex IEEE Standard 1003.1 @cindex standards conformance Our examples show C programs, since they are common, but you can use @code{make} with any programming language whose compiler can be run with a shell command. Indeed, @code{make} is not limited to compiling programs: it can be used to automate any task where some files need to be updated automatically whenever other files have been changed. @menu * Preparing:: Preparing and running @code{make}. * Reading:: On reading this text. * Bugs:: Problems and bugs. @end menu @node Preparing @section Preparing and Running Make To use @code{make}, you must write a file, called a @dfn{makefile}, that describes the relationships among files in your project and provides commands for updating each file. For example, in a typical C program the executable file is updated from object files, which are in turn made by compiling source files. Once a suitable makefile exists, each time you change some source files, this simple shell command: @example make @end example @noindent suffices to perform all necessary recompilations. The @code{make} program uses the information in the makefile and the last-modification times of the files to decide which of the files need to be updated. For each of those files, it issues the recipes provided in the makefile. You can provide command line arguments to @code{make} to control which files should be recompiled, or how. @xref{Running, ,How to Run @code{make}}. @node Reading @section How to Read This Manual If you are new to @code{make}, or are looking for a general introduction, read the first few sections of each chapter, skipping the later sections. In each chapter, the first few sections contain introductory or general information and the later sections contain specialized or technical information. @ifnottex The exception is the second chapter, @ref{Introduction, ,An Introduction to Makefiles}, all of which is introductory. @end ifnottex @iftex The exception is @ref{Introduction, ,An Introduction to Makefiles}, all of which is introductory. @end iftex If you are familiar with other @code{make} programs, see @ref{Features, ,Features of GNU @code{make}}, which lists the enhancements GNU Make has, and @ref{Missing, ,Incompatibilities and Missing Features}, which explains the few things GNU Make lacks that others have. For a quick summary, see @ref{Options Summary}, @ref{Quick Reference}, and @ref{Special Targets}. If you have a makefile already and it is not working as you expect, @pxref{Troubleshooting, ,Troubleshooting Make and Makefiles}. @node Bugs @section Problems and Bugs @cindex reporting bugs @cindex bugs, reporting @cindex problems and bugs, reporting If you have problems with GNU @code{make} or think you've found a bug, please report it to the developers; we cannot promise to do anything but we might well want to fix it. Before reporting a bug, make sure you've actually found a real bug. Carefully reread the documentation and see if it really says you can do what you're trying to do. If it's not clear whether you should be able to do something or not, report that too; it's a bug in the documentation! Before reporting a bug or trying to fix it yourself, try to isolate it to the smallest possible makefile that reproduces the problem. Then send us the makefile and the exact results @code{make} gave you, including any error or warning messages. Please don't paraphrase these messages: it's best to cut and paste them into your report. When generating this small makefile, be sure to not use any non-free or unusual tools in your recipes: you can almost always emulate what such a tool would do with simple shell commands. Finally, be sure to explain what you expected to occur; this will help us decide whether the problem was really in the documentation. Once you have a precise problem you can report it in one of two ways. Either send electronic mail to: @example bug-make@@gnu.org @end example @noindent or use our Web-based project management tool, at: @example https://savannah.gnu.org/projects/make/ @end example @noindent In addition to the information above, please be careful to include the version number of @code{make} you are using. You can get this information with the command @samp{make --version}. Be sure also to include the type of machine and operating system you are using. If you have a code change you'd like to submit, see the @file{README} file section ``Submitting Patches'' for information. @node Introduction @comment node-name, next, previous, up @chapter An Introduction to Makefiles You need a file called a @dfn{makefile} to tell @code{make} what to do. For example, the makefile might tell @code{make} how to compile and link a program. @cindex makefile A makefile is a combination of two different ``languages'' in a single file. Most of the makefile is written to be parsed by @code{make}, but also included in the makefile are @emph{recipes} which contain the commands used to update targets. These commands are passed to a shell to be parsed and run so they use shell syntax, not @code{make} syntax. It's important to keep in mind the difference between these two syntaxes when writing makefiles. For a detailed description of the content of makefiles, @pxref{Makefile Contents, ,What Makefiles Contain}. A makefile is not a procedural list of steps to be taken. Instead, it describes a @dfn{directed acyclic graph}, where each node in the graph is a potential target to be created and each edge in the graph is a prerequisite relationship. Every rule in a makefile defines (or updates) a node and (optionally) some of the edges starting from that node. In this chapter, we will discuss a simple makefile that describes how to compile and link a text editor which consists of eight C source files and three header files. The makefile can also tell @code{make} how to run miscellaneous commands when explicitly asked (for example, to remove certain files as a clean-up operation). To see a more complex example of a makefile, see @ref{Complex Makefile}. When @code{make} recompiles the editor, each changed C source file must be recompiled. If a header file has changed, each C source file that includes the header file must be recompiled to be safe. Each compilation produces an object file corresponding to the source file. Finally, if any source file has been recompiled, all the object files, whether newly made or saved from previous compilations, must be linked together to produce the new executable editor. @cindex recompilation @cindex editor @menu * Rule Introduction:: What a rule looks like. * Simple Makefile:: A simple makefile. * How Make Works:: How @code{make} processes this makefile. * Variables Simplify:: Variables make makefiles simpler. * make Deduces:: Letting @code{make} deduce the recipes. * Combine By Prerequisite:: Another style of makefile. * Cleanup:: Rules for cleaning the directory. @end menu @node Rule Introduction @comment node-name, next, previous, up @section What a Rule Looks Like @cindex rule, introduction to @cindex makefile rule parts @cindex parts of makefile rule A simple makefile consists of ``rules'' with the following shape: @cindex targets, introduction to @cindex prerequisites, introduction to @cindex recipes, introduction to @example @group @var{target} @dots{} : @var{prerequisites} @dots{} @var{recipe} @dots{} @dots{} @end group @end example A @dfn{target} is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as @samp{clean} (@pxref{Phony Targets}). A @dfn{prerequisite} is a file that is used as input to create the target. A target often depends on several files. @cindex tabs in rules A @dfn{recipe} is an action that @code{make} carries out. A recipe may have more than one command, either on the same line or each on its own line. @strong{Please note:} you need to put a tab character at the beginning of every recipe line! This is an obscurity that catches the unwary. If you prefer to prefix your recipes with a character other than tab, you can set the @code{.RECIPEPREFIX} variable to an alternate character (@pxref{Special Variables}). Usually a recipe is in a rule with prerequisites and serves to create a target file if any of the prerequisites change. However, the rule that specifies a recipe for the target need not have prerequisites. For example, the rule containing the delete command associated with the target @samp{clean} does not have prerequisites. A @dfn{rule}, then, explains how and when to remake certain files which are the targets of the particular rule. @code{make} carries out the recipe on the prerequisites to create or update the target. A rule can also explain how and when to carry out an action. @xref{Rules, , Writing Rules}. A makefile may contain other text besides rules, but a simple makefile need only contain rules. Rules may look somewhat more complicated than shown in this template, but all fit the pattern more or less. @node Simple Makefile @section A Simple Makefile @cindex simple makefile @cindex makefile, simple Here is a straightforward makefile that describes the way an executable file called @code{edit} depends on eight object files which, in turn, depend on eight C source and three header files. In this example, all the C files include @file{defs.h}, but only those defining editing commands include @file{command.h}, and only low level files that change the editor buffer include @file{buffer.h}. @example @group edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o @end group @end example @noindent We split each long line into two lines using backslash/newline; this is like using one long line, but is easier to read. @xref{Splitting Lines, , Splitting Long Lines}. @cindex continuation lines @cindex @code{\} (backslash), for continuation lines @cindex backslash (@code{\}), for continuation lines @cindex quoting newline, in makefile @cindex newline, quoting, in makefile To use this makefile to create the executable file called @file{edit}, type: @example make @end example To use this makefile to delete the executable file and all the object files from the directory, type: @example make clean @end example In the example makefile, the targets include the executable file @samp{edit}, and the object files @samp{main.o}, @samp{kbd.o}, etc. The prerequisites are files such as @samp{main.c} and @samp{defs.h}. You can see that each @samp{.o} file is both a target and a prerequisite: this is common in makefiles. Recipes include @w{@samp{cc -c main.c}} and @w{@samp{cc -c kbd.c}}. When a target is a program, it needs to be recompiled or relinked if any of its prerequisites change. In addition, any prerequisites that are themselves automatically generated should be updated first. In this example, @file{edit} depends on the eight object files; the object file @file{main.o} depends on the source file @file{main.c} and on the header file @file{defs.h}. A recipe may follow each line that contains a target and prerequisites. These recipes say how to update the target file. A tab character (or whatever character is specified by the @code{.RECIPEPREFIX} variable; @pxref{Special Variables}) must come at the beginning of every line in the recipe to distinguish recipes from other lines in the makefile. (Bear in mind that @code{make} does not know anything about how the recipes work. It is up to you to supply recipes that will update the target file properly. All @code{make} does is execute the recipe you have specified when the target file needs to be updated.) @cindex recipe The target @samp{clean} is not a file, but merely the name of an action. Since you normally do not want to carry out the actions in this rule, @samp{clean} is not a prerequisite of any other rule. Consequently, @code{make} never does anything with it unless you tell it specifically. Note that this rule not only is not a prerequisite, it also does not have any prerequisites, so the only purpose of the rule is to run the specified recipe. Targets that do not refer to files but are just actions are called @dfn{phony targets}. @xref{Phony Targets}, for information about this kind of target. @xref{Errors, , Errors in Recipes}, to see how to cause @code{make} to ignore errors from @code{rm} or any other command. @cindex @code{clean} target @cindex @code{rm} (shell command) @node How Make Works @comment node-name, next, previous, up @section How @code{make} Processes a Makefile @cindex processing a makefile @cindex makefile, how @code{make} processes By default, @code{make} starts with the first target (not targets whose names start with @samp{.} unless they also contain one or more @samp{/}). This is called the @dfn{default goal}. (@dfn{Goals} are the targets that @code{make} strives ultimately to update. You can override this behavior using the command line (@pxref{Goals, , Arguments to Specify the Goals}) or with the @code{.DEFAULT_GOAL} special variable (@pxref{Special Variables, , Other Special Variables}). @cindex default goal @cindex goal, default @cindex goal In the simple example of the previous section, the default goal is to update the executable program @file{edit}; therefore, we put that rule first. Thus, when you give the command: @example make @end example @noindent @code{make} reads the makefile in the current directory and begins by processing the first rule. In the example, this rule is for relinking @file{edit}; but before @code{make} can fully process this rule, it must process the rules for the files that @file{edit} depends on, which in this case are the object files. Each of these files is processed according to its own rule. These rules say to update each @samp{.o} file by compiling its source file. The recompilation must be done if the source file, or any of the header files named as prerequisites, is more recent than the object file, or if the object file does not exist. The other rules are processed because their targets appear as prerequisites of the goal. If some other rule is not depended on by the goal (or anything it depends on, etc.), that rule is not processed, unless you tell @code{make} to do so (with a command such as @w{@code{make clean}}). Before recompiling an object file, @code{make} considers updating its prerequisites, the source file and header files. This makefile does not specify anything to be done for them---the @samp{.c} and @samp{.h} files are not the targets of any rules---so @code{make} does nothing for these files. But @code{make} would update automatically generated C programs, such as those made by Bison or Yacc, by their own rules at this time. After recompiling whichever object files need it, @code{make} decides whether to relink @file{edit}. This must be done if the file @file{edit} does not exist, or if any of the object files are newer than it. If an object file was just recompiled, it is now newer than @file{edit}, so @file{edit} is relinked. @cindex relinking Thus, if we change the file @file{insert.c} and run @code{make}, @code{make} will compile that file to update @file{insert.o}, and then link @file{edit}. If we change the file @file{command.h} and run @code{make}, @code{make} will recompile the object files @file{kbd.o}, @file{command.o} and @file{files.o} and then link the file @file{edit}. @node Variables Simplify @section Variables Make Makefiles Simpler @cindex variables @cindex simplifying with variables In our example, we had to list all the object files twice in the rule for @file{edit} (repeated here): @example @group edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o @end group @end example @cindex @code{objects} Such duplication is error-prone; if a new object file is added to the system, we might add it to one list and forget the other. We can eliminate the risk and simplify the makefile by using a variable. @dfn{Variables} allow a text string to be defined once and substituted in multiple places later (@pxref{Using Variables, ,How to Use Variables}). @cindex @code{OBJECTS} @cindex @code{objs} @cindex @code{OBJS} @cindex @code{obj} @cindex @code{OBJ} It is standard practice for every makefile to have a variable named @code{objects}, @code{OBJECTS}, @code{objs}, @code{OBJS}, @code{obj}, or @code{OBJ} which is a list of all object file names. We would define such a variable @code{objects} with a line like this in the makefile: @example @group objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o @end group @end example @noindent Then, each place we want to put a list of the object file names, we can substitute the variable's value by writing @samp{$(objects)} (@pxref{Using Variables, ,How to Use Variables}). Here is how the complete simple makefile looks when you use a variable for the object files: @example @group objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm edit $(objects) @end group @end example @node make Deduces @section Letting @code{make} Deduce the Recipes @cindex deducing recipes (implicit rules) @cindex implicit rule, introduction to @cindex rule, implicit, introduction to It is not necessary to spell out the recipes for compiling the individual C source files, because @code{make} can figure them out: it has an @dfn{implicit rule} for updating a @samp{.o} file from a correspondingly named @samp{.c} file using a @samp{cc -c} command. For example, it will use the recipe @samp{cc -c main.c -o main.o} to compile @file{main.c} into @file{main.o}. We can therefore omit the recipes from the rules for the object files. @xref{Implicit Rules, ,Using Implicit Rules}. When a @samp{.c} file is used automatically in this way, it is also automatically added to the list of prerequisites. We can therefore omit the @samp{.c} files from the prerequisites, provided we omit the recipe. Here is the entire example, with both of these changes, and a variable @code{objects} as suggested above: @example @group objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) main.o : defs.h kbd.o : defs.h command.h command.o : defs.h command.h display.o : defs.h buffer.h insert.o : defs.h buffer.h search.o : defs.h buffer.h files.o : defs.h buffer.h command.h utils.o : defs.h .PHONY : clean clean : rm edit $(objects) @end group @end example @noindent This is how we would write the makefile in actual practice. (The complications associated with @samp{clean} are described elsewhere. See @ref{Phony Targets}, and @ref{Errors, ,Errors in Recipes}.) Because implicit rules are so convenient, they are important. You will see them used frequently. @node Combine By Prerequisite @section Another Style of Makefile @cindex combining rules by prerequisite When the objects of a makefile are created only by implicit rules, an alternative style of makefile is possible. In this style of makefile, you group entries by their prerequisites instead of by their targets. Here is what one looks like: @example @group objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) $(objects) : defs.h kbd.o command.o files.o : command.h display.o insert.o search.o files.o : buffer.h @end group @end example @noindent Here @file{defs.h} is given as a prerequisite of all the object files; @file{command.h} and @file{buffer.h} are prerequisites of the specific object files listed for them. Whether this is better is a matter of taste: it is more compact, but some people dislike it because they find it clearer to put all the information about each target in one place. @node Cleanup @section Rules for Cleaning the Directory @cindex cleaning up @cindex removing, to clean up Compiling a program is not the only thing you might want to write rules for. Makefiles commonly tell how to do a few other things besides compiling a program: for example, how to delete all the object files and executables so that the directory is @samp{clean}. @cindex @code{clean} target Here is how we could write a @code{make} rule for cleaning our example editor: @example @group clean: rm edit $(objects) @end group @end example In practice, we might want to write the rule in a somewhat more complicated manner to handle unanticipated situations. We would do this: @example @group .PHONY : clean clean : -rm edit $(objects) @end group @end example @noindent This prevents @code{make} from getting confused by an actual file called @file{clean} and causes it to continue in spite of errors from @code{rm}. (See @ref{Phony Targets}, and @ref{Errors, ,Errors in Recipes}.) @noindent A rule such as this should not be placed at the beginning of the makefile, because we do not want it to run by default! Thus, in the example makefile, we want the rule for @code{edit}, which recompiles the editor, to remain the default goal. Since @code{clean} is not a prerequisite of @code{edit}, this rule will not run at all if we give the command @samp{make} with no arguments. In order to make the rule run, we have to type @samp{make clean}. @xref{Running, ,How to Run @code{make}}. @node Makefiles @chapter Writing Makefiles @cindex makefile, how to write The information that tells @code{make} how to recompile a system comes from reading a data base called the @dfn{makefile}. @menu * Makefile Contents:: What makefiles contain. * Makefile Names:: How to name your makefile. * Include:: How one makefile can use another makefile. * MAKEFILES Variable:: The environment can specify extra makefiles. * Remaking Makefiles:: How makefiles get remade. * Overriding Makefiles:: How to override part of one makefile with another makefile. * Reading Makefiles:: How makefiles are read in. * Parsing Makefiles:: How makefiles are parsed. * Secondary Expansion:: How and when secondary expansion is performed. @end menu @node Makefile Contents @section What Makefiles Contain Makefiles contain five kinds of things: @dfn{explicit rules}, @dfn{implicit rules}, @dfn{variable definitions}, @dfn{directives}, and @dfn{comments}. Rules, variables, and directives are described at length in later chapters. @itemize @bullet @cindex rule, explicit, definition of @cindex explicit rule, definition of @item An @dfn{explicit rule} says when and how to remake one or more files, called the rule's @dfn{targets}. It lists the other files that the targets depend on, called the @dfn{prerequisites} of the target, and may also give a recipe to use to create or update the targets. @xref{Rules, ,Writing Rules}. @cindex rule, implicit, definition of @cindex implicit rule, definition of @item An @dfn{implicit rule} says when and how to remake a class of files based on their names. It describes how a target may depend on a file with a name similar to the target and gives a recipe to create or update such a target. @xref{Implicit Rules, ,Using Implicit Rules}. @cindex variable definition @item A @dfn{variable definition} is a line that specifies a text string value for a variable that can be substituted into the text later. The simple makefile example shows a variable definition for @code{objects} as a list of all object files (@pxref{Variables Simplify, , Variables Make Makefiles Simpler}). @cindex directive @item A @dfn{directive} is an instruction for @code{make} to do something special while reading the makefile. These include: @itemize @bullet @item Reading another makefile (@pxref{Include, ,Including Other Makefiles}). @item Deciding (based on the values of variables) whether to use or ignore a part of the makefile (@pxref{Conditionals, ,Conditional Parts of Makefiles}). @item Defining a variable from a verbatim string containing multiple lines (@pxref{Multi-Line, ,Defining Multi-Line Variables}). @end itemize @cindex comments, in makefile @cindex @code{#} (comments), in makefile @item @samp{#} in a line of a makefile starts a @dfn{comment}. It and the rest of the line are ignored, except that a trailing backslash not escaped by another backslash will continue the comment across multiple lines. A line containing just a comment (with perhaps spaces before it) is effectively blank, and is ignored. If you want a literal @code{#}, escape it with a backslash (e.g., @code{\#}). Comments may appear on any line in the makefile, although they are treated specially in certain situations. You cannot use comments within variable references or function calls: any instance of @code{#} will be treated literally (rather than as the start of a comment) inside a variable reference or function call. Comments within a recipe are passed to the shell, just as with any other recipe text. The shell decides how to interpret it: whether or not this is a comment is up to the shell. Within a @code{define} directive, comments are not ignored during the definition of the variable, but rather kept intact in the value of the variable. When the variable is expanded they will either be treated as @code{make} comments or as recipe text, depending on the context in which the variable is evaluated. @end itemize @menu * Splitting Lines:: Splitting long lines in makefiles @end menu @node Splitting Lines @subsection Splitting Long Lines @cindex splitting long lines @cindex long lines, splitting @cindex backslash (@code{\}), to quote newlines Makefiles use a ``line-based'' syntax in which the newline character is special and marks the end of a statement. GNU @code{make} has no limit on the length of a statement line, up to the amount of memory in your computer. However, it is difficult to read lines which are too long to display without wrapping or scrolling. So, you can format your makefiles for readability by adding newlines into the middle of a statement: you do this by escaping the internal newlines with a backslash (@code{\}) character. Where we need to make a distinction we will refer to ``physical lines'' as a single line ending with a newline (regardless of whether it is escaped) and a ``logical line'' being a complete statement including all escaped newlines up to the first non-escaped newline. The way in which backslash/newline combinations are handled depends on whether the statement is a recipe line or a non-recipe line. Handling of backslash/newline in a recipe line is discussed later (@pxref{Splitting Recipe Lines}). Outside of recipe lines, backslash/newlines are converted into a single space character. Once that is done, all whitespace around the backslash/newline is condensed into a single space: this includes all whitespace preceding the backslash, all whitespace at the beginning of the line after the backslash/newline, and any consecutive backslash/newline combinations. If the @code{.POSIX} special target is defined then backslash/newline handling is modified slightly to conform to POSIX: first, whitespace preceding a backslash is not removed and second, consecutive backslash/newlines are not condensed. @subsubheading Splitting Without Adding Whitespace @cindex whitespace, avoiding on line split @cindex removing whitespace from split lines If you need to split a line but do @emph{not} want any whitespace added, you can utilize a subtle trick: replace your backslash/newline pairs with the three characters dollar sign, backslash, and newline: @example var := one$\ word @end example After @code{make} removes the backslash/newline and condenses the following line into a single space, this is equivalent to: @example var := one$ word @end example Then @code{make} will perform variable expansion. The variable reference @samp{$ } refers to a variable with the one-character name `` '' (space) which does not exist, and so expands to the empty string, giving a final assignment which is the equivalent of: @example var := oneword @end example @node Makefile Names @section What Name to Give Your Makefile @cindex makefile name @cindex name of makefile @cindex default makefile name @cindex file name of makefile @c following paragraph rewritten to avoid overfull hbox By default, when @code{make} looks for the makefile, it tries the following names, in order: @file{GNUmakefile}, @file{makefile} and @file{Makefile}. @findex Makefile @findex GNUmakefile @findex makefile @cindex @code{README} Normally you should call your makefile either @file{makefile} or @file{Makefile}. (We recommend @file{Makefile} because it appears prominently near the beginning of a directory listing, right near other important files such as @file{README}.) The first name checked, @file{GNUmakefile}, is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU @code{make}, and will not be understood by other versions of @code{make}. Other @code{make} programs look for @file{makefile} and @file{Makefile}, but not @file{GNUmakefile}. If @code{make} finds none of these names, it does not use any makefile. Then you must specify a goal with a command argument, and @code{make} will attempt to figure out how to remake it using only its built-in implicit rules. @xref{Implicit Rules, ,Using Implicit Rules}. @cindex @code{-f} @cindex @code{--file} @cindex @code{--makefile} If you want to use a nonstandard name for your makefile, you can specify the makefile name with the @samp{-f} or @samp{--file} option. The arguments @w{@samp{-f @var{name}}} or @w{@samp{--file=@var{name}}} tell @code{make} to read the file @var{name} as the makefile. If you use more than one @samp{-f} or @samp{--file} option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names @file{GNUmakefile}, @file{makefile} and @file{Makefile} are not checked automatically if you specify @samp{-f} or @samp{--file}. @cindex specifying makefile name @cindex makefile name, how to specify @cindex name of makefile, how to specify @cindex file name of makefile, how to specify @node Include @section Including Other Makefiles @cindex including other makefiles @cindex makefile, including @findex include The @code{include} directive tells @code{make} to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: @example include @var{filenames}@dots{} @end example @noindent @var{filenames} can contain shell file name patterns. If @var{filenames} is empty, nothing is included and no error is printed. @cindex shell file name pattern (in @code{include}) @cindex shell wildcards (in @code{include}) @cindex wildcard, in @code{include} Extra spaces are allowed and ignored at the beginning of the line, but the first character must not be a tab (or the value of @code{.RECIPEPREFIX})---if the line begins with a tab, it will be considered a recipe line. Whitespace is required between @code{include} and the file names, and between file names; extra whitespace is ignored there and at the end of the directive. A comment starting with @samp{#} is allowed at the end of the line. If the file names contain any variable or function references, they are expanded. @xref{Using Variables, ,How to Use Variables}. For example, if you have three @file{.mk} files, @file{a.mk}, @file{b.mk}, and @file{c.mk}, and @code{$(bar)} expands to @code{bish bash}, then the following expression @example include foo *.mk $(bar) @end example is equivalent to @example include foo a.mk b.mk c.mk bish bash @end example When @code{make} processes an @code{include} directive, it suspends reading of the containing makefile and reads from each listed file in turn. When that is finished, @code{make} resumes reading the makefile in which the directive appears. One occasion for using @code{include} directives is when several programs, handled by individual makefiles in various directories, need to use a common set of variable definitions (@pxref{Setting, ,Setting Variables}) or pattern rules (@pxref{Pattern Rules, ,Defining and Redefining Pattern Rules}). Another such occasion is when you want to generate prerequisites from source files automatically; the prerequisites can be put in a file that is included by the main makefile. This practice is generally cleaner than that of somehow appending the prerequisites to the end of the main makefile as has been traditionally done with other versions of @code{make}. @xref{Automatic Prerequisites}. @cindex prerequisites, automatic generation @cindex automatic generation of prerequisites @cindex generating prerequisites automatically @cindex @code{-I} @cindex @code{--include-dir} @cindex included makefiles, default directories @cindex default directories for included makefiles @findex /usr/gnu/include @findex /usr/local/include @findex /usr/include If the specified name does not start with a slash (or a drive letter and colon when GNU Make is compiled with MS-DOS / MS-Windows path support), and the file is not found in the current directory, several other directories are searched. First, any directories you have specified with the @samp{-I} or @samp{--include-dir} options are searched (@pxref{Options Summary, ,Summary of Options}). Then the following directories (if they exist) are searched, in this order: @file{@var{prefix}/include} (normally @file{/usr/local/include} @footnote{GNU Make compiled for MS-DOS and MS-Windows behaves as if @var{prefix} has been defined to be the root of the DJGPP tree hierarchy.}) @file{/usr/gnu/include}, @file{/usr/local/include}, @file{/usr/include}. The @code{.INCLUDE_DIRS} variable will contain the current list of directories that make will search for included files. @xref{Special Variables, ,Other Special Variables}. You can avoid searching in these default directories by adding the command line option @code{-I} with the special value @code{-} (e.g., @code{-I-}) to the command line. This will cause @code{make} to forget any already-set include directories, including the default directories. If an included makefile cannot be found in any of these directories it is not an immediately fatal error; processing of the makefile containing the @code{include} continues. Once it has finished reading makefiles, @code{make} will try to remake any that are out of date or don't exist. @xref{Remaking Makefiles, ,How Makefiles Are Remade}. Only after it has failed to find a rule to remake the makefile, or it found a rule but the recipe failed, will @code{make} diagnose the missing makefile as a fatal error. If you want @code{make} to simply ignore a makefile which does not exist or cannot be remade, with no error message, use the @w{@code{-include}} directive instead of @code{include}, like this: @example -include @var{filenames}@dots{} @end example This acts like @code{include} in every way except that there is no error (not even a warning) if any of the @var{filenames} (or any prerequisites of any of the @var{filenames}) do not exist or cannot be remade. For compatibility with some other @code{make} implementations, @code{sinclude} is another name for @w{@code{-include}}. @node MAKEFILES Variable @section The Variable @code{MAKEFILES} @cindex makefile, and @code{MAKEFILES} variable @cindex including (@code{MAKEFILES} variable) @vindex MAKEFILES If the environment variable @code{MAKEFILES} is defined, @code{make} considers its value as a list of names (separated by whitespace) of additional makefiles to be read before the others. This works much like the @code{include} directive: various directories are searched for those files (@pxref{Include, ,Including Other Makefiles}). In addition, the default goal is never taken from one of these makefiles (or any makefile included by them) and it is not an error if the files listed in @code{MAKEFILES} are not found. @cindex recursion, and @code{MAKEFILES} variable The main use of @code{MAKEFILES} is in communication between recursive invocations of @code{make} (@pxref{Recursion, ,Recursive Use of @code{make}}). It usually is not desirable to set the environment variable before a top-level invocation of @code{make}, because it is usually better not to mess with a makefile from outside. However, if you are running @code{make} without a specific makefile, a makefile in @code{MAKEFILES} can do useful things to help the built-in implicit rules work better, such as defining search paths (@pxref{Directory Search}). Some users are tempted to set @code{MAKEFILES} in the environment automatically on login, and program makefiles to expect this to be done. This is a very bad idea, because such makefiles will fail to work if run by anyone else. It is much better to write explicit @code{include} directives in the makefiles. @xref{Include, , Including Other Makefiles}. @node Remaking Makefiles @section How Makefiles Are Remade @cindex updating makefiles @cindex remaking makefiles @cindex makefile, remaking of Sometimes makefiles can be remade from other files, such as RCS or SCCS files. If a makefile can be remade from other files, you probably want @code{make} to get an up-to-date version of the makefile to read in. To this end, after reading in all makefiles @code{make} will consider each as a goal target, in the order in which they were processed, and attempt to update it. If parallel builds (@pxref{Parallel, ,Parallel Execution}) are enabled then makefiles will be rebuilt in parallel as well. If a makefile has a rule which says how to update it (found either in that very makefile or in another one) or if an implicit rule applies to it (@pxref{Implicit Rules, ,Using Implicit Rules}), it will be updated if necessary. After all makefiles have been checked, if any have actually been changed, @code{make} starts with a clean slate and reads all the makefiles over again. (It will also attempt to update each of them over again, but normally this will not change them again, since they are already up to date.) Each restart will cause the special variable @code{MAKE_RESTARTS} to be updated (@pxref{Special Variables}). If you know that one or more of your makefiles cannot be remade and you want to keep @code{make} from performing an implicit rule search on them, perhaps for efficiency reasons, you can use any normal method of preventing implicit rule look-up to do so. For example, you can write an explicit rule with the makefile as the target, and an empty recipe (@pxref{Empty Recipes, ,Using Empty Recipes}). If the makefiles specify a double-colon rule to remake a file with a recipe but no prerequisites, that file will always be remade (@pxref{Double-Colon}). In the case of makefiles, a makefile that has a double-colon rule with a recipe but no prerequisites will be remade every time @code{make} is run, and then again after @code{make} starts over and reads the makefiles in again. This would cause an infinite loop: @code{make} would constantly remake the makefile and restart, and never do anything else. So, to avoid this, @code{make} will @strong{not} attempt to remake makefiles which are specified as targets of a double-colon rule with a recipe but no prerequisites. Phony targets (@pxref{Phony Targets}) have the same effect: they are never considered up-to-date and so an included file marked as phony would cause @code{make} to restart continuously. To avoid this @code{make} will not attempt to remake makefiles which are marked phony. You can take advantage of this to optimize startup time: if you know you don't need your @file{Makefile} to be remade you can prevent make from trying to remake it by adding either: @example .PHONY: Makefile @end example or: @example Makefile:: ; @end example If you do not specify any makefiles to be read with @samp{-f} or @samp{--file} options, @code{make} will try the default makefile names; @pxref{Makefile Names, ,What Name to Give Your Makefile}. Unlike makefiles explicitly requested with @samp{-f} or @samp{--file} options, @code{make} is not certain that these makefiles should exist. However, if a default makefile does not exist but can be created by running @code{make} rules, you probably want the rules to be run so that the makefile can be used. Therefore, if none of the default makefiles exists, @code{make} will try to make each of them until it succeeds in making one, or it runs out of names to try. Note that it is not an error if @code{make} cannot find or make any makefile; a makefile is not always necessary. When you use the @samp{-t} or @samp{--touch} option (@pxref{Instead of Execution, ,Instead of Executing Recipes}), you would not want to use an out-of-date makefile to decide which targets to touch. So the @samp{-t} option has no effect on updating makefiles; they are really updated even if @samp{-t} is specified. Likewise, @samp{-q} (or @samp{--question}) and @samp{-n} (or @samp{--just-print}) do not prevent updating of makefiles, because an out-of-date makefile would result in the wrong output for other targets. Thus, @samp{make -f mfile -n foo} will update @file{mfile}, read it in, and then print the recipe to update @file{foo} and its prerequisites without running it. The recipe printed for @file{foo} will be the one specified in the updated contents of @file{mfile}. However, on occasion you might actually wish to prevent updating of even the makefiles. You can do this by specifying the makefiles as goals in the command line as well as specifying them as makefiles. When the makefile name is specified explicitly as a goal, the options @samp{-t} and so on do apply to them. Thus, @samp{make -f mfile -n mfile foo} would read the makefile @file{mfile}, print the recipe needed to update it without actually running it, and then print the recipe needed to update @file{foo} without running that. The recipe for @file{foo} will be the one specified by the existing contents of @file{mfile}. @node Overriding Makefiles @section Overriding Part of Another Makefile @cindex overriding makefiles @cindex makefile, overriding Sometimes it is useful to have a makefile that is mostly just like another makefile. You can often use the @samp{include} directive to include one in the other, and add more targets or variable definitions. However, it is invalid for two makefiles to give different recipes for the same target. But there is another way. @cindex match-anything rule, used to override In the containing makefile (the one that wants to include the other), you can use a match-anything pattern rule to say that to remake any target that cannot be made from the information in the containing makefile, @code{make} should look in another makefile. @xref{Pattern Rules}, for more information on pattern rules. For example, if you have a makefile called @file{Makefile} that says how to make the target @samp{foo} (and other targets), you can write a makefile called @file{GNUmakefile} that contains: @example foo: frobnicate > foo %: force @@$(MAKE) -f Makefile $@@ force: ; @end example If you say @samp{make foo}, @code{make} will find @file{GNUmakefile}, read it, and see that to make @file{foo}, it needs to run the recipe @samp{frobnicate > foo}. If you say @samp{make bar}, @code{make} will find no way to make @file{bar} in @file{GNUmakefile}, so it will use the recipe from the pattern rule: @samp{make -f Makefile bar}. If @file{Makefile} provides a rule for updating @file{bar}, @code{make} will apply the rule. And likewise for any other target that @file{GNUmakefile} does not say how to make. The way this works is that the pattern rule has a pattern of just @samp{%}, so it matches any target whatever. The rule specifies a prerequisite @file{force}, to guarantee that the recipe will be run even if the target file already exists. We give the @file{force} target an empty recipe to prevent @code{make} from searching for an implicit rule to build it---otherwise it would apply the same match-anything rule to @file{force} itself and create a prerequisite loop! @node Reading Makefiles @section How @code{make} Reads a Makefile @cindex reading makefiles @cindex makefile, reading GNU @code{make} does its work in two distinct phases. During the first phase it reads all the makefiles, included makefiles, etc. and internalizes all the variables and their values and implicit and explicit rules, and builds a dependency graph of all the targets and their prerequisites. During the second phase, @code{make} uses this internalized data to determine which targets need to be updated and run the recipes necessary to update them. It's important to understand this two-phase approach because it has a direct impact on how variable and function expansion happens; this is often a source of some confusion when writing makefiles. Below is a summary of the different constructs that can be found in a makefile, and the phase in which expansion happens for each part of the construct. We say that expansion is @dfn{immediate} if it happens during the first phase: @code{make} will expand that part of the construct as the makefile is parsed. We say that expansion is @dfn{deferred} if it is not immediate. Expansion of a deferred construct part is delayed until the construct is used: either when it is referenced in an immediate context, or when it is needed during the second phase. You may not be familiar with some of these constructs yet. You can reference this section as you become familiar with them, in later chapters. @subheading Variable Assignment @cindex =, expansion @cindex :=, expansion @cindex ::=, expansion @cindex :::=, expansion @cindex !=, expansion @cindex +=, expansion @cindex define, expansion Variable definitions are parsed as follows: @example @var{immediate} = @var{deferred} @var{immediate} := @var{immediate} @var{immediate} ::= @var{immediate} @var{immediate} :::= @var{immediate-with-escape} @var{immediate} += @var{deferred} or @var{immediate} @var{immediate} != @var{immediate} define @var{immediate} @var{deferred} endef define @var{immediate} = @var{deferred} endef define @var{immediate} := @var{immediate} endef define @var{immediate} ::= @var{immediate} endef define @var{immediate} :::= @var{immediate-with-escape} endef define @var{immediate} += @var{deferred} or @var{immediate} endef define @var{immediate} != @var{immediate} endef @end example For the append operator @samp{+=}, the right-hand side is considered immediate if the variable was previously set as a simple variable (@samp{:=} or @samp{::=}), and deferred otherwise. For the @var{immediate-with-escape} operator @samp{:::=}, the value on the right-hand side is immediately expanded but then escaped (that is, all instances of @code{$} in the result of the expansion are replaced with @code{$$}). For the shell assignment operator @samp{!=}, the right-hand side is evaluated immediately and handed to the shell. The result is stored in the variable named on the left, and that variable is considered a recursively expanded variable (and will thus be re-evaluated on each reference). @subsubheading Conditional Assignment Modifier @cindex ?=, expansion @cindex ?:=, expansion @cindex ?::=, expansion @cindex ?:::=, expansion @cindex ?!=, expansion Adding a conditional modifier (@pxref{Conditional Assignment, ,Conditional Variable Assignment}) to an assignment operator does not change the expansion style for that operator: if the variable is not defined then the assignment will be made using expansion as defined above. If the variable is already defined, then the right-hand side of the assignment is ignored and not expanded. @subheading Conditional Directives @cindex ifdef, expansion @cindex ifeq, expansion @cindex ifndef, expansion @cindex ifneq, expansion Conditional directives are parsed immediately. This means, for example, that automatic variables cannot be used in conditional directives, as automatic variables are not set until the recipe for that rule is invoked. If you need to use automatic variables in a conditional directive you @emph{must} move the condition into the recipe and use shell conditional syntax instead. @subheading Rule Definition @cindex target, expansion @cindex prerequisite, expansion @cindex implicit rule, expansion @cindex pattern rule, expansion @cindex explicit rule, expansion A rule is always expanded the same way, regardless of the form: @example @var{immediate} : @var{immediate} ; @var{deferred} @var{deferred} @end example That is, the target and prerequisite sections are expanded immediately, and the recipe used to build the target is always deferred. This is true for explicit rules, pattern rules, suffix rules, static pattern rules, and simple prerequisite definitions. @node Parsing Makefiles @section How Makefiles Are Parsed @cindex parsing makefiles @cindex makefiles, parsing GNU @code{make} parses makefiles line-by-line. Parsing proceeds using the following steps: @enumerate @item Read in a full logical line, including backslash-escaped lines (@pxref{Splitting Lines, , Splitting Long Lines}). @item Remove comments (@pxref{Makefile Contents, , What Makefiles Contain}). @item If the line begins with the recipe prefix character and we are in a rule context, add the line to the current recipe and read the next line (@pxref{Recipe Syntax}). @item Expand elements of the line which appear in an @emph{immediate} expansion context (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). @item Scan the line for a separator character, such as @samp{:} or @samp{=}, to determine whether the line is a macro assignment or a rule (@pxref{Recipe Syntax}). @item Internalize the resulting operation and read the next line. @end enumerate An important consequence of this is that a macro can expand to an entire rule, @emph{if it is one line long}. This will work: @example myrule = target : ; echo built $(myrule) @end example However, this will not work because @code{make} does not re-split lines after it has expanded them: @example define myrule target: echo built endef $(myrule) @end example The above makefile results in the definition of a target @samp{target} with prerequisites @samp{echo} and @samp{built}, as if the makefile contained @code{target: echo built}, rather than a rule with a recipe. Newlines still present in a line after expansion is complete are ignored as normal whitespace. In order to properly expand a multi-line macro you must use the @code{eval} function: this causes the @code{make} parser to be run on the results of the expanded macro (@pxref{Eval Function}). @node Secondary Expansion @section Secondary Expansion @cindex secondary expansion @cindex expansion, secondary @findex .SECONDEXPANSION Previously we learned that GNU @code{make} works in two distinct phases: a read-in phase and a target-update phase (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). GNU Make also has the ability to enable a @emph{second expansion} of the prerequisites (only) for some or all targets defined in the makefile. In order for this second expansion to occur, the special target @code{.SECONDEXPANSION} must be defined before the first prerequisite list that makes use of this feature. If @code{.SECONDEXPANSION} is defined then when GNU @code{make} needs to check the prerequisites of a target, the prerequisites are expanded a @emph{second time}. In most circumstances this secondary expansion will have no effect, since all variable and function references will have been expanded during the initial parsing of the makefiles. In order to take advantage of the secondary expansion phase of the parser, then, it's necessary to @emph{escape} the variable or function reference in the makefile. In this case the first expansion merely un-escapes the reference but doesn't expand it, and expansion is left to the secondary expansion phase. For example, consider this makefile: @example .SECONDEXPANSION: ONEVAR = onefile TWOVAR = twofile myfile: $(ONEVAR) $$(TWOVAR) @end example After the first expansion phase the prerequisites list of the @file{myfile} target will be @code{onefile} and @code{$(TWOVAR)}; the first (un-escaped) variable reference to @var{ONEVAR} is expanded, while the second (escaped) variable reference is simply un-escaped, without being recognized as a variable reference. Now during the secondary expansion the first word is expanded again but since it contains no variable or function references it remains the value @file{onefile}, while the second word is now a normal reference to the variable @var{TWOVAR}, which is expanded to the value @file{twofile}. The final result is that there are two prerequisites, @file{onefile} and @file{twofile}. Obviously, this is not a very interesting case since the same result could more easily have been achieved simply by having both variables appear, un-escaped, in the prerequisites list. One difference becomes apparent if the variables are reset; consider this example: @example .SECONDEXPANSION: AVAR = top onefile: $(AVAR) twofile: $$(AVAR) AVAR = bottom @end example Here the prerequisite of @file{onefile} will be expanded immediately, and resolve to the value @file{top}, while the prerequisite of @file{twofile} will not be full expanded until the secondary expansion and yield a value of @file{bottom}. This is marginally more exciting, but the true power of this feature only becomes apparent when you discover that secondary expansions always take place within the scope of the automatic variables for that target. This means that you can use variables such as @code{$@@}, @code{$*}, etc. during the second expansion and they will have their expected values, just as in the recipe. All you have to do is defer the expansion by escaping the @code{$}. Also, secondary expansion occurs for both explicit and implicit (pattern) rules. Knowing this, the possible uses for this feature increase dramatically. For example: @example .SECONDEXPANSION: main_OBJS := main.o try.o test.o lib_OBJS := lib.o api.o main lib: $$($$@@_OBJS) @end example Here, after the initial expansion the prerequisites of both the @file{main} and @file{lib} targets will be @code{$($@@_OBJS)}. During the secondary expansion, the @code{$@@} variable is set to the name of the target and so the expansion for the @file{main} target will yield @code{$(main_OBJS)}, or @code{main.o try.o test.o}, while the secondary expansion for the @file{lib} target will yield @code{$(lib_OBJS)}, or @code{lib.o api.o}. You can also mix in functions here, as long as they are properly escaped: @example main_SRCS := main.c try.c test.c lib_SRCS := lib.c api.c .SECONDEXPANSION: main lib: $$(patsubst %.c,%.o,$$($$@@_SRCS)) @end example This version allows users to specify source files rather than object files, but gives the same resulting prerequisites list as the previous example. Evaluation of automatic variables during the secondary expansion phase, especially of the target name variable @code{$$@@}, behaves similarly to evaluation within recipes. However, there are some subtle differences and ``corner cases'' which come into play for the different types of rule definitions that @code{make} understands. The subtleties of using the different automatic variables are described below. @subheading Secondary Expansion of Explicit Rules @cindex secondary expansion and explicit rules @cindex explicit rules, secondary expansion of During the secondary expansion of explicit rules, @code{$$@@} and @code{$$%} evaluate, respectively, to the file name of the target and, when the target is an archive member, the target member name. The @code{$$<} variable evaluates to the first prerequisite in the first rule for this target. @code{$$^} and @code{$$+} evaluate to the list of all prerequisites of rules @emph{that have already appeared} for the same target (@code{$$+} with repetitions and @code{$$^} without). The following example will help illustrate these behaviors: @example .SECONDEXPANSION: foo: foo.1 bar.1 $$< $$^ $$+ # line #1 foo: foo.2 bar.2 $$< $$^ $$+ # line #2 foo: foo.3 bar.3 $$< $$^ $$+ # line #3 @end example In the first prerequisite list, all three variables (@code{$$<}, @code{$$^}, and @code{$$+}) expand to the empty string. In the second, they will have values @code{foo.1}, @code{foo.1 bar.1}, and @code{foo.1 bar.1} respectively. In the third they will have values @code{foo.1}, @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1 foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1} respectively. Rules undergo secondary expansion in makefile order, except that the rule with the recipe is always evaluated last. The variables @code{$$?} and @code{$$*} are not available and expand to the empty string. @subheading Secondary Expansion of Static Pattern Rules @cindex secondary expansion and static pattern rules @cindex static pattern rules, secondary expansion of Rules for secondary expansion of static pattern rules are identical to those for explicit rules, above, with one exception: for static pattern rules the @code{$$*} variable is set to the pattern stem. As with explicit rules, @code{$$?} is not available and expands to the empty string. @subheading Secondary Expansion of Implicit Rules @cindex secondary expansion and implicit rules @cindex implicit rules, secondary expansion of As @code{make} searches for an implicit rule, it substitutes the stem and then performs secondary expansion for every rule with a matching target pattern. The value of the automatic variables is derived in the same fashion as for static pattern rules. As an example: @example .SECONDEXPANSION: foo: bar foo foz: fo%: bo% %oo: $$< $$^ $$+ $$* @end example When the implicit rule is tried for target @file{foo}, @code{$$<} expands to @file{bar}, @code{$$^} expands to @file{bar boo}, @code{$$+} also expands to @file{bar boo}, and @code{$$*} expands to @file{f}. Note that the directory prefix (D), as described in @ref{Implicit Rule Search, ,Implicit Rule Search Algorithm}, is appended (after expansion) to all the patterns in the prerequisites list. As an example: @example .SECONDEXPANSION: /tmp/foo.o: %.o: $$(addsuffix /%.c,foo bar) foo.h @@echo $^ @end example The prerequisite list printed, after the secondary expansion and directory prefix reconstruction, will be @file{/tmp/foo/foo.c /tmp/bar/foo.c foo.h}. If you are not interested in this reconstruction, you can use @code{$$*} instead of @code{%} in the prerequisites list. @node Rules @chapter Writing Rules @cindex writing rules @cindex rule, how to write @cindex target @cindex prerequisite A @dfn{rule} appears in the makefile and says when and how to remake certain files, called the rule's @dfn{targets} (most often only one per rule). It lists the other files that are the @dfn{prerequisites} of the target, and the @dfn{recipe} to use to create or update the target. @cindex default goal @cindex goal, default The order of rules is not significant, except for determining the @dfn{default goal}: the target for @code{make} to consider, if you do not otherwise specify one. The default goal is the first target of the first rule in the first makefile. There are two exceptions: a target starting with a period is not a default unless it also contains one or more slashes, @samp{/}; and, a target that defines a pattern rule has no effect on the default goal. (@xref{Pattern Rules, ,Defining and Redefining Pattern Rules}.) Therefore, we usually write the makefile so that the first rule is the one for compiling the entire program or all the programs described by the makefile (often with a target called @samp{all}). @xref{Goals, ,Arguments to Specify the Goals}. @menu * Rule Example:: An example explained. * Rule Syntax:: General syntax explained. * Prerequisite Types:: There are two types of prerequisites. * Wildcards:: Using wildcard characters such as `*'. * Directory Search:: Searching other directories for source files. * Phony Targets:: Using a target that is not a real file's name. * Force Targets:: You can use a target without a recipe or prerequisites to mark other targets as phony. * Empty Targets:: When only the date matters and the files are empty. * Special Targets:: Targets with special built-in meanings. * Multiple Targets:: When to make use of several targets in a rule. * Multiple Rules:: How to use several rules with the same target. * Static Pattern:: Static pattern rules apply to multiple targets and can vary the prerequisites according to the target name. * Double-Colon:: How to use a special kind of rule to allow several independent rules for one target. * Automatic Prerequisites:: How to automatically generate rules giving prerequisites from source files themselves. @end menu @ifnottex @node Rule Example @section Rule Example Here is an example of a rule: @example foo.o : foo.c defs.h # module for twiddling the frobs cc -c -g foo.c @end example Its target is @file{foo.o} and its prerequisites are @file{foo.c} and @file{defs.h}. It has one command in the recipe: @samp{cc -c -g foo.c}. The recipe starts with a tab to identify it as a recipe. This rule says two things: @itemize @bullet @item How to decide whether @file{foo.o} is out of date: it is out of date if it does not exist, or if either @file{foo.c} or @file{defs.h} is more recent than it. @item How to update the file @file{foo.o}: by running @code{cc} as stated. The recipe does not explicitly mention @file{defs.h}, but we presume that @file{foo.c} includes it, and that is why @file{defs.h} was added to the prerequisites. @end itemize @end ifnottex @node Rule Syntax @section Rule Syntax @cindex rule syntax @cindex syntax of rules In general, a rule looks like this: @example @var{targets} : @var{prerequisites} @var{recipe} @dots{} @end example @noindent or like this: @example @var{targets} : @var{prerequisites} ; @var{recipe} @var{recipe} @dots{} @end example @cindex targets @cindex rule targets The @var{targets} are file names, separated by spaces. Wildcard characters may be used (@pxref{Wildcards, ,Using Wildcard Characters in File Names}) and a name of the form @file{@var{a}(@var{m})} represents member @var{m} in archive file @var{a} (@pxref{Archive Members, ,Archive Members as Targets}). Usually there is only one target per rule, but occasionally there is a reason to have more (@pxref{Multiple Targets, , Multiple Targets in a Rule}). @cindex recipes @cindex tab character (in commands) The @var{recipe} lines start with a tab character (or the first character in the value of the @code{.RECIPEPREFIX} variable; @pxref{Special Variables}). The first recipe line may appear on the line after the prerequisites, with a tab character, or may appear on the same line, with a semicolon. Either way, the effect is the same. There are other differences in the syntax of recipes. @xref{Recipes, ,Writing Recipes in Rules}. @cindex dollar sign (@code{$}), in rules @cindex @code{$}, in rules @cindex rules, and @code{$} Because dollar signs are used to start @code{make} variable references, if you really want a dollar sign in a target or prerequisite you must write two of them, @samp{$$} (@pxref{Using Variables, ,How to Use Variables}). If you have enabled secondary expansion (@pxref{Secondary Expansion}) and you want a literal dollar sign in the prerequisites list, you must actually write @emph{four} dollar signs (@samp{$$$$}). You may split a long line by inserting a backslash followed by a newline, but this is not required, as @code{make} places no limit on the length of a line in a makefile. A rule tells @code{make} two things: when the targets are out of date, and how to update them when necessary. @cindex prerequisites @cindex rule prerequisites The criterion for being out of date is specified in terms of the @var{prerequisites}, which consist of file names separated by spaces. (Wildcards and archive members (@pxref{Archives}) are allowed here too.) A target is out of date if it does not exist or if it is older than any of the prerequisites (by comparison of last-modification times). The idea is that the contents of the target file are computed based on information in the prerequisites, so if any of the prerequisites changes, the contents of the existing target file are no longer necessarily valid. How to update is specified by a @var{recipe}. This is one or more lines to be executed by the shell (normally @samp{sh}), but with some extra features (@pxref{Recipes, ,Writing Recipes in Rules}). @node Prerequisite Types @comment node-name, next, previous, up @section Types of Prerequisites @cindex prerequisite types @cindex types of prerequisites @cindex prerequisites, normal @cindex normal prerequisites @cindex prerequisites, order-only @cindex order-only prerequisites There are two different types of prerequisites understood by GNU @code{make}: normal prerequisites, described in the previous section, and @dfn{order-only} prerequisites. A normal prerequisite makes two statements: first, it imposes an order in which recipes will be invoked: the recipes for all prerequisites of a target will be completed before the recipe for the target is started. Second, it imposes a dependency relationship: if any prerequisite is newer than the target, then the target is considered out-of-date and must be rebuilt. Normally, this is exactly what you want: if a target's prerequisite is updated, then the target should also be updated. Occasionally you may want to ensure that a prerequisite is built before a target, but @emph{without} forcing the target to be updated if the prerequisite is updated. @dfn{Order-only} prerequisites are used to create this type of relationship. Order-only prerequisites can be specified by placing a pipe symbol (@code{|}) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only: @example @var{targets} : @var{normal-prerequisites} | @var{order-only-prerequisites} @end example The normal prerequisites section may of course be empty. Also, you may still declare multiple lines of prerequisites for the same target: they are appended appropriately (normal prerequisites are appended to the list of normal prerequisites; order-only prerequisites are appended to the list of order-only prerequisites). Note that if you declare the same file to be both a normal and an order-only prerequisite, the normal prerequisite takes precedence (since they have a strict superset of the behavior of an order-only prerequisite). Order-only prerequisites are never checked when determining if the target is out of date; even order-only prerequisites marked as phony (@pxref{Phony Targets}) will not cause the target to be rebuilt. Consider an example where your targets are to be placed in a separate directory, and that directory might not exist before @code{make} is run. In this situation, you want the directory to be created before any targets are placed into it but, because the timestamps on directories change whenever a file is added, removed, or renamed, we certainly don't want to rebuild all the targets whenever the directory's timestamp changes. One way to manage this is with order-only prerequisites: make the directory an order-only prerequisite on all the targets: @example OBJDIR := objdir OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o) $(OBJDIR)/%.o : %.c $(COMPILE.c) $(OUTPUT_OPTION) $< all: $(OBJS) $(OBJS): | $(OBJDIR) $(OBJDIR): mkdir $(OBJDIR) @end example Now the rule to create the @file{objdir} directory will be run, if needed, before any @samp{.o} is built, but no @samp{.o} will be built because the @file{objdir} directory timestamp changed. @node Wildcards @section Using Wildcard Characters in File Names @cindex wildcard @cindex file name with wildcards @cindex globbing (wildcards) @cindex @code{*} (wildcard character) @cindex @code{?} (wildcard character) @cindex @code{[@dots{}]} (wildcard characters) A single file name can specify many files using @dfn{wildcard characters}. The wildcard characters in @code{make} are @samp{*}, @samp{?} and @samp{[@dots{}]}, the same as in the Bourne shell. For example, @file{*.c} specifies a list of all the files (in the working directory) whose names end in @samp{.c}. If an expression matches multiple files then the results will be sorted.@footnote{Some older versions of GNU @code{make} did not sort the results of wildcard expansion.} However multiple expressions will not be globally sorted. For example, @file{*.c *.h} will list all the files whose names end in @samp{.c}, sorted, followed by all the files whose names end in @samp{.h}, sorted. @cindex @code{~} (tilde) @cindex tilde (@code{~}) @cindex home directory The character @samp{~} at the beginning of a file name also has special significance. If alone, or followed by a slash, it represents your home directory. For example @file{~/bin} expands to @file{/home/you/bin}. If the @samp{~} is followed by a word, the string represents the home directory of the user named by that word. For example @file{~john/bin} expands to @file{/home/john/bin}. On systems which don't have a home directory for each user (such as MS-DOS or MS-Windows), this functionality can be simulated by setting the environment variable @var{HOME}. Wildcard expansion is performed by @code{make} automatically in targets and in prerequisites. In recipes, the shell is responsible for wildcard expansion. In other contexts, wildcard expansion happens only if you request it explicitly with the @code{wildcard} function. The special significance of a wildcard character can be turned off by preceding it with a backslash. Thus, @file{foo\*bar} would refer to a specific file whose name consists of @samp{foo}, an asterisk, and @samp{bar}. @menu * Wildcard Examples:: Several examples. * Wildcard Pitfall:: Problems to avoid. * Wildcard Function:: How to cause wildcard expansion where it does not normally take place. @end menu @node Wildcard Examples @subsection Wildcard Examples Wildcards can be used in the recipe of a rule, where they are expanded by the shell. For example, here is a rule to delete all the object files: @example @group clean: rm -f *.o @end group @end example @cindex @code{rm} (shell command) Wildcards are also useful in the prerequisites of a rule. With the following rule in the makefile, @samp{make print} will print all the @samp{.c} files that have changed since the last time you printed them: @example print: *.c lpr -p $? touch print @end example @cindex @code{print} target @cindex @code{lpr} (shell command) @cindex @code{touch} (shell command) @noindent This rule uses @file{print} as an empty target file; see @ref{Empty Targets, ,Empty Target Files to Record Events}. (The automatic variable @samp{$?} is used to print only those files that have changed; see @ref{Automatic Variables}.) Wildcard expansion does not happen when you define a variable. Thus, if you write this: @example objects = *.o @end example @noindent then the value of the variable @code{objects} is the actual string @samp{*.o}. However, if you use the value of @code{objects} in a target or prerequisite, wildcard expansion will take place there. If you use the value of @code{objects} in a recipe, the shell may perform wildcard expansion when the recipe runs. To set @code{objects} to the expansion, instead use: @example objects := $(wildcard *.o) @end example @noindent @xref{Wildcard Function}. @node Wildcard Pitfall @subsection Pitfalls of Using Wildcards @cindex wildcard pitfalls @cindex pitfalls of wildcards @cindex mistakes with wildcards @cindex errors with wildcards @cindex problems with wildcards Now here is an example of a naive way of using wildcard expansion, that does not do what you would intend. Suppose you would like to say that the executable file @file{foo} is made from all the object files in the directory, and you write this: @example objects = *.o foo : $(objects) cc -o foo $(CFLAGS) $(objects) @end example @noindent The value of @code{objects} is the actual string @samp{*.o}. Wildcard expansion happens in the rule for @file{foo}, so that each @emph{existing} @samp{.o} file becomes a prerequisite of @file{foo} and will be recompiled if necessary. But what if you delete all the @samp{.o} files? When a wildcard matches no files, it is left as it is, so then @file{foo} will depend on the oddly-named file @file{*.o}. Since no such file is likely to exist, @code{make} will give you an error saying it cannot figure out how to make @file{*.o}. This is not what you want! Actually it is possible to obtain the desired result with wildcard expansion, but you need more sophisticated techniques, including the @code{wildcard} function and string substitution. @ifnottex @xref{Wildcard Function, ,The Function @code{wildcard}}. @end ifnottex @iftex These are described in the following section. @end iftex @cindex wildcards and MS-DOS/MS-Windows backslashes @cindex backslashes in pathnames and wildcard expansion Microsoft operating systems (MS-DOS and MS-Windows) use backslashes to separate directories in pathnames, like so: @example c:\foo\bar\baz.c @end example This is equivalent to the Unix-style @file{c:/foo/bar/baz.c} (the @file{c:} part is the so-called drive letter). When @code{make} runs on these systems, it supports backslashes as well as the Unix-style forward slashes in pathnames. However, this support does @emph{not} include the wildcard expansion, where backslash is a quote character. Therefore, you @emph{must} use Unix-style slashes in these cases. @node Wildcard Function @subsection The Function @code{wildcard} @findex wildcard Wildcard expansion happens automatically in rules. But wildcard expansion does not normally take place when a variable is set, or inside the arguments of a function. If you want to do wildcard expansion in such places, you need to use the @code{wildcard} function, like this: @example $(wildcard @var{pattern}@dots{}) @end example @noindent This string, used anywhere in a makefile, is replaced by a space-separated list of names of existing files that match one of the given file name patterns. If no existing file name matches a pattern, then that pattern is omitted from the output of the @code{wildcard} function. Note that this is different from how unmatched wildcards behave in rules, where they are used verbatim rather than ignored (@pxref{Wildcard Pitfall}). As with wildcard expansion in rules, the results of the @code{wildcard} function are sorted. But again, each individual expression is sorted separately, so @samp{$(wildcard *.c *.h)} will expand to all files matching @samp{.c}, sorted, followed by all files matching @samp{.h}, sorted. One use of the @code{wildcard} function is to get a list of all the C source files in a directory, like this: @example $(wildcard *.c) @end example We can change the list of C source files into a list of object files by replacing the @samp{.c} suffix with @samp{.o} in the result, like this: @example $(patsubst %.c,%.o,$(wildcard *.c)) @end example @noindent (Here we have used another function, @code{patsubst}. @xref{Text Functions, ,Functions for String Substitution and Analysis}.) Thus, a makefile to compile all C source files in the directory and then link them together could be written as follows: @example objects := $(patsubst %.c,%.o,$(wildcard *.c)) foo : $(objects) cc -o foo $(objects) @end example @noindent (This takes advantage of the implicit rule for compiling C programs, so there is no need to write explicit rules for compiling the files. @xref{Flavors, ,The Two Flavors of Variables}, for an explanation of @samp{:=}, which is a variant of @samp{=}.) @node Directory Search @section Searching Directories for Prerequisites @cindex vpath @cindex search path for prerequisites (@code{VPATH}) @cindex directory search (@code{VPATH}) For large systems, it is often desirable to put sources in a separate directory from the binaries. The @dfn{directory search} features of @code{make} facilitate this by searching several directories automatically to find a prerequisite. When you redistribute the files among directories, you do not need to change the individual rules, just the search paths. @menu * General Search:: Specifying a search path that applies to every prerequisite. * Selective Search:: Specifying a search path for a specified class of names. * Search Algorithm:: When and how search paths are applied. * Recipes/Search:: How to write recipes that work together with search paths. * Implicit/Search:: How search paths affect implicit rules. * Libraries/Search:: Directory search for link libraries. @end menu @node General Search @subsection @code{VPATH}: Search Path for All Prerequisites @vindex VPATH The value of the @code{make} variable @code{VPATH} specifies a list of directories that @code{make} should search. Most often, the directories are expected to contain prerequisite files that are not in the current directory; however, @code{make} uses @code{VPATH} as a search list for both prerequisites and targets of rules. Thus, if a file that is listed as a target or prerequisite does not exist in the current directory, @code{make} searches the directories listed in @code{VPATH} for a file with that name. If a file is found in one of them, that file may become the prerequisite (see below). Rules may then specify the names of files in the prerequisite list as if they all existed in the current directory. @xref{Recipes/Search, ,Writing Recipes with Directory Search}. In the @code{VPATH} variable, directory names are separated by colons or blanks. The order in which directories are listed is the order followed by @code{make} in its search. (On MS-DOS and MS-Windows, semi-colons are used as separators of directory names in @code{VPATH}, since the colon can be used in the pathname itself, after the drive letter.) For example, @example VPATH = src:../headers @end example @noindent specifies a path containing two directories, @file{src} and @file{../headers}, which @code{make} searches in that order. With this value of @code{VPATH}, the following rule, @example foo.o : foo.c @end example @noindent is interpreted as if it were written like this: @example foo.o : src/foo.c @end example @noindent assuming the file @file{foo.c} does not exist in the current directory but is found in the directory @file{src}. @node Selective Search @subsection The @code{vpath} Directive @findex vpath Similar to the @code{VPATH} variable, but more selective, is the @code{vpath} directive (note lower case), which allows you to specify a search path for a particular class of file names: those that match a particular pattern. Thus you can supply certain search directories for one class of file names and other directories (or none) for other file names. There are three forms of the @code{vpath} directive: @table @code @item vpath @var{pattern} @var{directories} Specify the search path @var{directories} for file names that match @var{pattern}. The search path, @var{directories}, is a list of directories to be searched, separated by colons (semi-colons on MS-DOS and MS-Windows) or blanks, just like the search path used in the @code{VPATH} variable. @item vpath @var{pattern} Clear out the search path associated with @var{pattern}. @c Extra blank line makes sure this gets two lines. @item vpath Clear all search paths previously specified with @code{vpath} directives. @end table A @code{vpath} pattern is a string containing a @samp{%} character. The string must match the file name of a prerequisite that is being searched for, the @samp{%} character matching any sequence of zero or more characters (as in pattern rules; @pxref{Pattern Rules, ,Defining and Redefining Pattern Rules}). For example, @code{%.h} matches files that end in @code{.h}. (If there is no @samp{%}, the pattern must match the prerequisite exactly, which is not useful very often.) @cindex @code{%}, quoting in @code{vpath} @cindex @code{\} (backslash), to quote @code{%} @cindex backslash (@code{\}), to quote @code{%} @cindex quoting @code{%}, in @code{vpath} @samp{%} characters in a @code{vpath} directive's pattern can be quoted with preceding backslashes (@samp{\}). Backslashes that would otherwise quote @samp{%} characters can be quoted with more backslashes. Backslashes that quote @samp{%} characters or other backslashes are removed from the pattern before it is compared to file names. Backslashes that are not in danger of quoting @samp{%} characters go unmolested. When a prerequisite fails to exist in the current directory, if the @var{pattern} in a @code{vpath} directive matches the name of the prerequisite file, then the @var{directories} in that directive are searched just like (and before) the directories in the @code{VPATH} variable. For example, @example vpath %.h ../headers @end example @noindent tells @code{make} to look for any prerequisite whose name ends in @file{.h} in the directory @file{../headers} if the file is not found in the current directory. If several @code{vpath} patterns match the prerequisite file's name, then @code{make} processes each matching @code{vpath} directive one by one, searching all the directories mentioned in each directive. @code{make} handles multiple @code{vpath} directives in the order in which they appear in the makefile; multiple directives with the same pattern are independent of each other. @need 750 Thus, @example @group vpath %.c foo vpath % blish vpath %.c bar @end group @end example @noindent will look for a file ending in @samp{.c} in @file{foo}, then @file{blish}, then @file{bar}, while @example @group vpath %.c foo:bar vpath % blish @end group @end example @noindent will look for a file ending in @samp{.c} in @file{foo}, then @file{bar}, then @file{blish}. @node Search Algorithm @subsection How Directory Searches are Performed @cindex algorithm for directory search @cindex directory search algorithm When a prerequisite is found through directory search, regardless of type (general or selective), the pathname located may not be the one that @code{make} actually provides you in the prerequisite list. Sometimes the path discovered through directory search is thrown away. The algorithm @code{make} uses to decide whether to keep or abandon a path found via directory search is as follows: @enumerate @item If a target file does not exist at the path specified in the makefile, directory search is performed. @item If the directory search is successful, that path is kept and this file is tentatively stored as the target. @item All prerequisites of this target are examined using this same method. @item After processing the prerequisites, the target may or may not need to be rebuilt: @enumerate a @item If the target does @emph{not} need to be rebuilt, the path to the file found during directory search is used for any prerequisite lists which contain this target. In short, if @code{make} doesn't need to rebuild the target then you use the path found via directory search. @item If the target @emph{does} need to be rebuilt (is out-of-date), the pathname found during directory search is @emph{thrown away}, and the target is rebuilt using the file name specified in the makefile. In short, if @code{make} must rebuild, then the target is rebuilt locally, not in the directory found via directory search. @end enumerate @end enumerate This algorithm may seem complex, but in practice it is quite often exactly what you want. @cindex traditional directory search (GPATH) @cindex directory search, traditional (GPATH) Other versions of @code{make} use a simpler algorithm: if the file does not exist, and it is found via directory search, then that pathname is always used whether or not the target needs to be built. Thus, if the target is rebuilt it is created at the pathname discovered during directory search. @vindex GPATH If, in fact, this is the behavior you want for some or all of your directories, you can use the @code{GPATH} variable to indicate this to @code{make}. @code{GPATH} has the same syntax and format as @code{VPATH} (that is, a space- or colon-delimited list of pathnames). If an out-of-date target is found by directory search in a directory that also appears in @code{GPATH}, then that pathname is not thrown away. The target is rebuilt using the expanded path. @node Recipes/Search @subsection Writing Recipes with Directory Search @cindex recipes, and directory search @cindex directory search (@code{VPATH}), and recipes When a prerequisite is found in another directory through directory search, this cannot change the recipe of the rule; they will execute as written. Therefore, you must write the recipe with care so that it will look for the prerequisite in the directory where @code{make} finds it. This is done with the @dfn{automatic variables} such as @samp{$^} (@pxref{Automatic Variables}). For instance, the value of @samp{$^} is a list of all the prerequisites of the rule, including the names of the directories in which they were found, and the value of @samp{$@@} is the target. Thus: @example foo.o : foo.c cc -c $(CFLAGS) $^ -o $@@ @end example @noindent (The variable @code{CFLAGS} exists so you can specify flags for C compilation by implicit rules; we use it here for consistency so it will affect all C compilations uniformly; @pxref{Implicit Variables, ,Variables Used by Implicit Rules}.) Often the prerequisites include header files as well, which you do not want to mention in the recipe. The automatic variable @samp{$<} is just the first prerequisite: @example VPATH = src:../headers foo.o : foo.c defs.h hack.h cc -c $(CFLAGS) $< -o $@@ @end example @node Implicit/Search @subsection Directory Search and Implicit Rules @cindex @code{VPATH}, and implicit rules @cindex directory search (@code{VPATH}), and implicit rules @cindex search path for prerequisites (@code{VPATH}), and implicit rules @cindex implicit rule, and directory search @cindex implicit rule, and @code{VPATH} @cindex rule, implicit, and directory search @cindex rule, implicit, and @code{VPATH} The search through the directories specified in @code{VPATH} or with @code{vpath} also happens during consideration of implicit rules (@pxref{Implicit Rules, ,Using Implicit Rules}). For example, when a file @file{foo.o} has no explicit rule, @code{make} considers implicit rules, such as the built-in rule to compile @file{foo.c} if that file exists. If such a file is lacking in the current directory, the appropriate directories are searched for it. If @file{foo.c} exists (or is mentioned in the makefile) in any of the directories, the implicit rule for C compilation is applied. The recipes of implicit rules normally use automatic variables as a matter of necessity; consequently they will use the file names found by directory search with no extra effort. @node Libraries/Search @subsection Directory Search for Link Libraries @cindex link libraries, and directory search @cindex libraries for linking, directory search @cindex directory search (@code{VPATH}), and link libraries @cindex @code{VPATH}, and link libraries @cindex search path for prerequisites (@code{VPATH}), and link libraries @cindex @code{-l} (library search) @cindex link libraries, patterns matching @cindex @code{.LIBPATTERNS}, and link libraries @vindex .LIBPATTERNS Directory search applies in a special way to libraries used with the linker. This special feature comes into play when you write a prerequisite whose name is of the form @samp{-l@var{name}}. (You can tell something strange is going on here because the prerequisite is normally the name of a file, and the @emph{file name} of a library generally looks like @file{lib@var{name}.a}, not like @samp{-l@var{name}}.) When a prerequisite's name has the form @samp{-l@var{name}}, @code{make} handles it specially by searching for the file @file{lib@var{name}.so}, and, if it is not found, for the file @file{lib@var{name}.a} in the current directory, in directories specified by matching @code{vpath} search paths and the @code{VPATH} search path, and then in the directories @file{/lib}, @file{/usr/lib}, and @file{@var{prefix}/lib} (normally @file{/usr/local/lib}, but MS-DOS/MS-Windows versions of @code{make} behave as if @var{prefix} is defined to be the root of the DJGPP installation tree). For example, if there is a @file{/usr/lib/libcurses.a} library on your system (and no @file{/usr/lib/libcurses.so} file), then @example @group foo : foo.c -lcurses cc $^ -o $@@ @end group @end example @noindent would cause the command @samp{cc foo.c /usr/lib/libcurses.a -o foo} to be executed when @file{foo} is older than @file{foo.c} or than @file{/usr/lib/libcurses.a}. Although the default set of files to be searched for is @file{lib@var{name}.so} and @file{lib@var{name}.a}, this is customizable via the @code{.LIBPATTERNS} variable. Each word in the value of this variable is a pattern string. When a prerequisite like @samp{-l@var{name}} is seen, @code{make} will replace the percent in each pattern in the list with @var{name} and perform the above directory searches using each library file name. The default value for @code{.LIBPATTERNS} is @samp{lib%.so lib%.a}, which provides the default behavior described above. You can turn off link library expansion completely by setting this variable to an empty value. @node Phony Targets @section Phony Targets @cindex phony targets @cindex targets, phony @cindex targets without a file A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance. If you write a rule whose recipe will not create the target file, the recipe will be executed every time the target comes up for remaking. Here is an example: @example @group clean: rm *.o temp @end group @end example @noindent Because the @code{rm} command does not create a file named @file{clean}, probably no such file will ever exist. Therefore, the @code{rm} command will be executed every time you say @samp{make clean}. @cindex @code{rm} (shell command) @cindex using .PHONY In this example, the @file{clean} target will not work properly if a file named @file{clean} is ever created in this directory. Since it has no prerequisites, @file{clean} would always be considered up to date and its recipe would not be executed. To avoid this problem you can explicitly declare the target to be phony by making it a prerequisite of the special target @code{.PHONY} (@pxref{Special Targets, ,Special Built-in Target Names}) as follows: @example @group .PHONY: clean clean: rm *.o temp @end group @end example @noindent Once this is done, @samp{make clean} will run the recipe regardless of whether there is a file named @file{clean}. Prerequisites of @code{.PHONY} are always interpreted as literal target names, never as patterns (even if they contain @samp{%} characters). To always rebuild a pattern rule consider using a ``force target'' (@pxref{Force Targets, ,Rules without Recipes or Prerequisites}). Phony targets are also useful in conjunction with recursive invocations of @code{make} (@pxref{Recursion, ,Recursive Use of @code{make}}). In this situation the makefile will often contain a variable which lists a number of sub-directories to be built. A simplistic way to handle this is to define one rule with a recipe that loops over the sub-directories, like this: @example @group SUBDIRS = foo bar baz subdirs: for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir; \ done @end group @end example There are problems with this method, however. First, any error detected in a sub-make is ignored by this rule, so it will continue to build the rest of the directories even when one fails. This can be overcome by adding shell commands to note the error and exit, but then it will do so even if @code{make} is invoked with the @code{-k} option, which is unfortunate. Second, and perhaps more importantly, you cannot take full advantage of @code{make}'s ability to build targets in parallel (@pxref{Parallel, ,Parallel Execution}), since there is only one rule. Each individual makefile's targets will be built in parallel, but only one sub-directory will be built at a time. By declaring the sub-directories as @code{.PHONY} targets (you must do this as the sub-directory obviously always exists; otherwise it won't be built) you can remove these problems: @example @group SUBDIRS = foo bar baz .PHONY: subdirs $(SUBDIRS) subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@@ foo: baz @end group @end example Here we've also declared that the @file{foo} sub-directory cannot be built until after the @file{baz} sub-directory is complete; this kind of relationship declaration is particularly important when attempting parallel builds. The implicit rule search (@pxref{Implicit Rules}) is skipped for @code{.PHONY} targets. This is why declaring a target as @code{.PHONY} is good for performance, even if you are not worried about the actual file existing. A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time @code{make} considers that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal (@pxref{Goals, ,Arguments to Specify the Goals}). You should not declare an included makefile as phony. Phony targets are not intended to represent real files, and because the target is always considered out of date make will always rebuild it then re-execute itself (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}). To avoid this, @code{make} will not re-execute itself if an included file marked as phony is re-built. Phony targets can have prerequisites. When one directory contains multiple programs, it is most convenient to describe all of the programs in one makefile @file{./Makefile}. Since the target remade by default will be the first one in the makefile, it is common to make this a phony target named @samp{all} and give it, as prerequisites, all the individual programs. For example: @example all : prog1 prog2 prog3 .PHONY : all prog1 : prog1.o utils.o cc -o prog1 prog1.o utils.o prog2 : prog2.o cc -o prog2 prog2.o prog3 : prog3.o sort.o utils.o cc -o prog3 prog3.o sort.o utils.o @end example @noindent Now you can say just @samp{make} to remake all three programs, or specify as arguments the ones to remake (as in @samp{make prog1 prog3}). Phoniness is not inherited: the prerequisites of a phony target are not themselves phony, unless explicitly declared to be so. When one phony target is a prerequisite of another, it serves as a subroutine of the other. For example, here @samp{make cleanall} will delete the object files, the difference files, and the file @file{program}: @example .PHONY: cleanall cleanobj cleandiff cleanall : cleanobj cleandiff rm program cleanobj : rm *.o cleandiff : rm *.diff @end example @node Force Targets @section Rules without Recipes or Prerequisites @cindex force targets @cindex targets, force @cindex @code{FORCE} @cindex rule, no recipe or prerequisites If a rule has no prerequisites or recipe, and the target of the rule is a nonexistent file, then @code{make} imagines this target to have been updated whenever its rule is run. This implies that all targets depending on this one will always have their recipe run. An example will illustrate this: @example @group clean: FORCE rm $(objects) FORCE: @end group @end example Here the target @samp{FORCE} satisfies the special conditions, so the target @file{clean} that depends on it is forced to run its recipe. There is nothing special about the name @samp{FORCE}, but that is one name commonly used this way. As you can see, using @samp{FORCE} this way has the same results as using @samp{.PHONY: clean}. Using @samp{.PHONY} is more explicit and more efficient. However, other versions of @code{make} do not support @samp{.PHONY}; thus @samp{FORCE} appears in many makefiles. @xref{Phony Targets}. @node Empty Targets @section Empty Target Files to Record Events @cindex empty targets @cindex targets, empty @cindex recording events with empty targets The @dfn{empty target} is a variant of the phony target; it is used to hold recipes for an action that you request explicitly from time to time. Unlike a phony target, this target file can really exist; but the file's contents do not matter, and usually are empty. The purpose of the empty target file is to record, with its last-modification time, when the rule's recipe was last executed. It does so because one of the commands in the recipe is a @code{touch} command to update the target file. The empty target file should have some prerequisites (otherwise it doesn't make sense). When you ask to remake the empty target, the recipe is executed if any prerequisite is more recent than the target; in other words, if a prerequisite has changed since the last time you remade the target. Here is an example: @example print: foo.c bar.c lpr -p $? touch print @end example @cindex @code{print} target @cindex @code{lpr} (shell command) @cindex @code{touch} (shell command) @noindent With this rule, @samp{make print} will execute the @code{lpr} command if either source file has changed since the last @samp{make print}. The automatic variable @samp{$?} is used to print only those files that have changed (@pxref{Automatic Variables}). @node Special Targets @section Special Built-in Target Names @cindex special targets @cindex built-in special targets @cindex targets, built-in special Certain names have special meanings if they appear as targets. @table @code @findex .PHONY @item .PHONY The prerequisites of the special target @code{.PHONY} are considered to be phony targets. When it is time to consider such a target, @code{make} will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is. @xref{Phony Targets, ,Phony Targets}. @findex .SUFFIXES @item .SUFFIXES The prerequisites of the special target @code{.SUFFIXES} are the list of suffixes to be used in checking for suffix rules. @xref{Suffix Rules, , Old-Fashioned Suffix Rules}. @findex .DEFAULT@r{, special target} @item .DEFAULT The recipe specified for @code{.DEFAULT} is used for any target for which no rules are found (either explicit rules or implicit rules). @xref{Last Resort}. If a @code{.DEFAULT} recipe is specified, every file mentioned as a prerequisite, but not as a target in a rule, will have that recipe executed on its behalf. @xref{Implicit Rule Search, ,Implicit Rule Search Algorithm}. @findex .PRECIOUS @item .PRECIOUS @cindex precious targets @cindex preserving with @code{.PRECIOUS} The targets which @code{.PRECIOUS} depends on are given the following special treatment: if @code{make} is killed or interrupted during the execution of their recipes, the target is not deleted. @xref{Interrupts, ,Interrupting or Killing @code{make}}. Also, if the target is an intermediate file, it will not be deleted after it is no longer needed, as is normally done. @xref{Chained Rules, ,Chains of Implicit Rules}. In this latter respect it overlaps with the @code{.SECONDARY} special target. You can also list the target pattern of an implicit rule (such as @samp{%.o}) as a prerequisite file of the special target @code{.PRECIOUS} to preserve intermediate files created by rules whose target patterns match that file's name. @findex .INTERMEDIATE @item .INTERMEDIATE @cindex intermediate targets, explicit The targets which @code{.INTERMEDIATE} depends on are treated as intermediate files. @xref{Chained Rules, ,Chains of Implicit Rules}. @code{.INTERMEDIATE} with no prerequisites has no effect. @findex .NOTINTERMEDIATE @item .NOTINTERMEDIATE @cindex not intermediate targets, explicit Prerequisites of the special target @code{.NOTINTERMEDIATE} are never considered intermediate files. @xref{Chained Rules, ,Chains of Implicit Rules}. @code{.NOTINTERMEDIATE} with no prerequisites causes all targets to be treated as not intermediate. If the prerequisite is a target pattern then targets that are built using that pattern rule are not considered intermediate. @findex .SECONDARY @item .SECONDARY @cindex secondary targets @cindex preserving with @code{.SECONDARY} The targets which @code{.SECONDARY} depends on are treated as intermediate files, except that they are never automatically deleted. @xref{Chained Rules, ,Chains of Implicit Rules}. @code{.SECONDARY} can be used to avoid redundant rebuilds in some unusual situations. For example: @example @group hello.bin: hello.o bye.o $(CC) -o $@@ $^ %.o: %.c $(CC) -c -o $@@ $< .SECONDARY: hello.o bye.o @end group @end example Suppose @file{hello.bin} is up to date in regards to the source files, @emph{but} the object file @file{hello.o} is missing. Without @code{.SECONDARY} make would rebuild @file{hello.o} then rebuild @file{hello.bin} even though the source files had not changed. By declaring @file{hello.o} as @code{.SECONDARY} @code{make} will not need to rebuild it and won't need to rebuild @file{hello.bin} either. Of course, if one of the source files @emph{were} updated then all object files would be rebuilt so that the creation of @file{hello.bin} could succeed. @code{.SECONDARY} with no prerequisites causes all targets to be treated as secondary (i.e., no target is removed because it is considered intermediate). @item .SECONDEXPANSION If @code{.SECONDEXPANSION} is mentioned as a target anywhere in the makefile, then all prerequisite lists defined @emph{after} it appears will be expanded a second time after all makefiles have been read in. @xref{Secondary Expansion, ,Secondary Expansion}. @findex .DELETE_ON_ERROR @item .DELETE_ON_ERROR @cindex removing targets on failure If @code{.DELETE_ON_ERROR} is mentioned as a target anywhere in the makefile, then @code{make} will delete the target of a rule if it has changed and its recipe exits with a nonzero exit status, just as it does when it receives a signal. @xref{Errors, ,Errors in Recipes}. @findex .IGNORE @item .IGNORE If you specify prerequisites for @code{.IGNORE}, then @code{make} will ignore errors in execution of the recipe for those particular files. The recipe for @code{.IGNORE} (if any) is ignored. If mentioned as a target with no prerequisites, @code{.IGNORE} says to ignore errors in execution of recipes for all files. This usage of @samp{.IGNORE} is supported only for historical compatibility. Since this affects every recipe in the makefile, it is not very useful; we recommend you use the more selective ways to ignore errors in specific recipes. @xref{Errors, ,Errors in Recipes}. @findex .LOW_RESOLUTION_TIME @item .LOW_RESOLUTION_TIME If you specify prerequisites for @code{.LOW_RESOLUTION_TIME}, @command{make} assumes that these files are created by commands that generate low resolution time stamps. The recipe for the @code{.LOW_RESOLUTION_TIME} target are ignored. The high resolution file time stamps of many modern file systems lessen the chance of @command{make} incorrectly concluding that a file is up to date. Unfortunately, some hosts do not provide a way to set a high resolution file time stamp, so commands like @samp{cp -p} that explicitly set a file's time stamp must discard its sub-second part. If a file is created by such a command, you should list it as a prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make} does not mistakenly conclude that the file is out of date. For example: @example @group .LOW_RESOLUTION_TIME: dst dst: src cp -p src dst @end group @end example Since @samp{cp -p} discards the sub-second part of @file{src}'s time stamp, @file{dst} is typically slightly older than @file{src} even when it is up to date. The @code{.LOW_RESOLUTION_TIME} line causes @command{make} to consider @file{dst} to be up to date if its time stamp is at the start of the same second that @file{src}'s time stamp is in. Due to a limitation of the archive format, archive member time stamps are always low resolution. You need not list archive members as prerequisites of @code{.LOW_RESOLUTION_TIME}, as @command{make} does this automatically. @findex .SILENT @item .SILENT If you specify prerequisites for @code{.SILENT}, then @code{make} will not print the recipe used to remake those particular files before executing them. The recipe for @code{.SILENT} is ignored. If mentioned as a target with no prerequisites, @code{.SILENT} says not to print any recipes before executing them. You may also use more selective ways to silence specific recipe command lines. @xref{Echoing, ,Recipe Echoing}. If you want to silence all recipes for a particular run of @code{make}, use the @samp{-s} or @w{@samp{--silent}} option (@pxref{Options Summary}). @findex .EXPORT_ALL_VARIABLES @item .EXPORT_ALL_VARIABLES Simply by being mentioned as a target, this tells @code{make} to export all variables to child processes by default. This is an alternative to using @code{export} with no arguments. @xref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}. @findex .NOTPARALLEL @item .NOTPARALLEL @cindex parallel execution, overriding If @code{.NOTPARALLEL} is mentioned as a target with no prerequisites, all targets in this invocation of @code{make} will be run serially, even if the @samp{-j} option is given. Any recursively invoked @code{make} command will still run recipes in parallel (unless its makefile also contains this target). If @code{.NOTPARALLEL} has targets as prerequisites, then all the prerequisites of those targets will be run serially. This implicitly adds a @code{.WAIT} between each prerequisite of the listed targets. @xref{Parallel Disable, , Disabling Parallel Execution}. @item .ONESHELL @cindex recipe execution, single invocation If @code{.ONESHELL} is mentioned as a target, then when a target is built all lines of the recipe will be given to a single invocation of the shell rather than each line being invoked separately. @xref{Execution, ,Recipe Execution}. @findex .POSIX @item .POSIX @cindex POSIX-conforming mode, setting If @code{.POSIX} is mentioned as a target, then the makefile will be parsed and run in POSIX-conforming mode. This does @emph{not} mean that only POSIX-conforming makefiles will be accepted: all advanced GNU @code{make} features are still available. Rather, this target causes @code{make} to behave as required by POSIX in those areas where @code{make}'s default behavior differs. In particular, if this target is mentioned then recipes will be invoked as if the shell had been passed the @code{-e} flag: the first failing command in a recipe will cause the recipe to fail immediately. @end table Any defined implicit rule suffix also counts as a special target if it appears as a target, and so does the concatenation of two suffixes, such as @samp{.c.o}. These targets are suffix rules, an obsolete way of defining implicit rules (but a way still widely used). In principle, any target name could be special in this way if you break it in two and add both pieces to the suffix list. In practice, suffixes normally begin with @samp{.}, so these special target names also begin with @samp{.}. @xref{Suffix Rules, ,Old-Fashioned Suffix Rules}. @node Multiple Targets @section Multiple Targets in a Rule @cindex multiple targets @cindex several targets in a rule @cindex targets, multiple @cindex rule, with multiple targets When an explicit rule has multiple targets they can be treated in one of two possible ways: as independent targets or as grouped targets. The manner in which they are treated is determined by the separator that appears after the list of targets. @subsubheading Rules with Independent Targets @cindex independent targets @cindex targets, independent Rules that use the standard target separator, @code{:}, define independent targets. This is equivalent to writing the same rule once for each target, with duplicated prerequisites and recipes. Typically, the recipe would use automatic variables such as @samp{$@@} to specify which target is being built. Rules with independent targets are useful in two cases: @itemize @bullet @item You want just prerequisites, no recipe. For example: @example kbd.o command.o files.o: command.h @end example @noindent gives an additional prerequisite to each of the three object files mentioned. It is equivalent to writing: @example kbd.o: command.h command.o: command.h files.o: command.h @end example @item Similar recipes work for all the targets. The automatic variable @samp{$@@} can be used to substitute the particular target to be remade into the commands (@pxref{Automatic Variables}). For example: @example @group bigoutput littleoutput : text.g generate text.g -$(subst output,,$@@) > $@@ @end group @end example @noindent is equivalent to @example bigoutput : text.g generate text.g -big > bigoutput littleoutput : text.g generate text.g -little > littleoutput @end example @noindent Here we assume the hypothetical program @code{generate} makes two types of output, one if given @samp{-big} and one if given @samp{-little}. @xref{Text Functions, ,Functions for String Substitution and Analysis}, for an explanation of the @code{subst} function. @end itemize Suppose you would like to vary the prerequisites according to the target, much as the variable @samp{$@@} allows you to vary the recipe. You cannot do this with multiple targets in an ordinary rule, but you can do it with a @dfn{static pattern rule}. @xref{Static Pattern, ,Static Pattern Rules}. @subsubheading Rules with Grouped Targets @cindex grouped targets @cindex targets, grouped If instead of independent targets you have a recipe that generates multiple files from a single invocation, you can express that relationship by declaring your rule to use @emph{grouped targets}. A grouped target rule uses the separator @code{&:} (the @samp{&} here is used to imply ``all''). When @code{make} builds any one of the grouped targets, it understands that all the other targets in the group are also updated as a result of the invocation of the recipe. Furthermore, if only some of the grouped targets are out of date or missing @code{make} will realize that running the recipe will update all of the targets. Finally, if any of the grouped targets are out of date, all the grouped targets are considered out of date. As an example, this rule defines a grouped target: @example @group foo bar biz &: baz boz echo $^ > foo echo $^ > bar echo $^ > biz @end group @end example During the execution of a grouped target's recipe, the automatic variable @samp{$@@} is set to the name of the particular target in the group which triggered the rule. Caution must be used if relying on this variable in the recipe of a grouped target rule. Unlike independent targets, a grouped target rule @emph{must} include a recipe. However, targets that are members of a grouped target may also appear in independent target rule definitions that do not have recipes. Each target may have only one recipe associated with it. If a grouped target appears in either an independent target rule or in another grouped target rule with a recipe, you will get a warning and the latter recipe will replace the former recipe. Additionally the target will be removed from the previous group and appear only in the new group. If you would like a target to appear in multiple groups, then you must use the double-colon grouped target separator, @code{&::} when declaring all of the groups containing that target. Grouped double-colon targets are each considered independently, and each grouped double-colon rule's recipe is executed at most once, if at least one of its multiple targets requires updating. @node Multiple Rules @section Multiple Rules for One Target @cindex multiple rules for one target @cindex several rules for one target @cindex rule, multiple for one target @cindex target, multiple rules for one One file can be the target of several rules. All the prerequisites mentioned in all the rules are merged into one list of prerequisites for the target. If the target is older than any prerequisite from any rule, the recipe is executed. There can only be one recipe to be executed for a file. If more than one rule gives a recipe for the same file, @code{make} uses the last one given and prints an error message. (As a special case, if the file's name begins with a dot, no error message is printed. This odd behavior is only for compatibility with other implementations of @code{make}@dots{} you should avoid using it). Occasionally it is useful to have the same target invoke multiple recipes which are defined in different parts of your makefile; you can use @dfn{double-colon rules} (@pxref{Double-Colon}) for this. An extra rule with just prerequisites can be used to give a few extra prerequisites to many files at once. For example, makefiles often have a variable, such as @code{objects}, containing a list of all the compiler output files in the system being made. An easy way to say that all of them must be recompiled if @file{config.h} changes is to write the following: @example objects = foo.o bar.o foo.o : defs.h bar.o : defs.h test.h $(objects) : config.h @end example This could be inserted or taken out without changing the rules that really specify how to make the object files, making it a convenient form to use if you wish to add the additional prerequisite intermittently. Another wrinkle is that the additional prerequisites could be specified with a variable that you set with a command line argument to @code{make} (@pxref{Overriding, ,Overriding Variables}). For example, @example @group extradeps= $(objects) : $(extradeps) @end group @end example @noindent means that the command @samp{make extradeps=foo.h} will consider @file{foo.h} as a prerequisite of each object file, but plain @samp{make} will not. If none of the explicit rules for a target has a recipe, then @code{make} searches for an applicable implicit rule to find one @pxref{Implicit Rules, ,Using Implicit Rules}). @node Static Pattern @section Static Pattern Rules @cindex static pattern rule @cindex rule, static pattern @cindex pattern rules, static (not implicit) @cindex varying prerequisites @cindex prerequisites, varying (static pattern) @dfn{Static pattern rules} are rules which specify multiple targets and construct the prerequisite names for each target based on the target name. They are more general than ordinary rules with multiple targets because the targets do not have to have identical prerequisites. Their prerequisites must be @emph{analogous}, but not necessarily @emph{identical}. @menu * Static Usage:: The syntax of static pattern rules. * Static versus Implicit:: When are they better than implicit rules? @end menu @node Static Usage @subsection Syntax of Static Pattern Rules @cindex static pattern rule, syntax of @cindex pattern rules, static, syntax of Here is the syntax of a static pattern rule: @example @var{targets} @dots{}: @var{target-pattern}: @var{prereq-patterns} @dots{} @var{recipe} @dots{} @end example @noindent The @var{targets} list specifies the targets that the rule applies to. The targets can contain wildcard characters, just like the targets of ordinary rules (@pxref{Wildcards, ,Using Wildcard Characters in File Names}). @cindex target pattern, static (not implicit) @cindex stem The @var{target-pattern} and @var{prereq-patterns} say how to compute the prerequisites of each target. Each target is matched against the @var{target-pattern} to extract a part of the target name, called the @dfn{stem}. This stem is substituted into each of the @var{prereq-patterns} to make the prerequisite names (one from each @var{prereq-pattern}). Each pattern normally contains the character @samp{%} just once. When the @var{target-pattern} matches a target, the @samp{%} can match any part of the target name; this part is called the @dfn{stem}. The rest of the pattern must match exactly. For example, the target @file{foo.o} matches the pattern @samp{%.o}, with @samp{foo} as the stem. The targets @file{foo.c} and @file{foo.out} do not match that pattern. @cindex prerequisite pattern, static (not implicit) The prerequisite names for each target are made by substituting the stem for the @samp{%} in each prerequisite pattern. For example, if one prerequisite pattern is @file{%.c}, then substitution of the stem @samp{foo} gives the prerequisite name @file{foo.c}. It is legitimate to write a prerequisite pattern that does not contain @samp{%}; then this prerequisite is the same for all targets. @cindex @code{%}, quoting in static pattern @cindex @code{\} (backslash), to quote @code{%} @cindex backslash (@code{\}), to quote @code{%} @cindex quoting @code{%}, in static pattern @samp{%} characters in pattern rules can be quoted with preceding backslashes (@samp{\}). Backslashes that would otherwise quote @samp{%} characters can be quoted with more backslashes. Backslashes that quote @samp{%} characters or other backslashes are removed from the pattern before it is compared to file names or has a stem substituted into it. Backslashes that are not in danger of quoting @samp{%} characters go unmolested. For example, the pattern @file{the\%weird\\%pattern\\} has @samp{the%weird\} preceding the operative @samp{%} character, and @samp{pattern\\} following it. The final two backslashes are left alone because they cannot affect any @samp{%} character. Here is an example, which compiles each of @file{foo.o} and @file{bar.o} from the corresponding @file{.c} file: @example @group objects = foo.o bar.o all: $(objects) $(objects): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@@ @end group @end example @noindent Here @samp{$<} is the automatic variable that holds the name of the prerequisite and @samp{$@@} is the automatic variable that holds the name of the target; see @ref{Automatic Variables}. Each target specified must match the target pattern; a warning is issued for each target that does not. If you have a list of files, only some of which will match the pattern, you can use the @code{filter} function to remove non-matching file names (@pxref{Text Functions, ,Functions for String Substitution and Analysis}): @example files = foo.elc bar.o lose.o $(filter %.o,$(files)): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@@ $(filter %.elc,$(files)): %.elc: %.el emacs -f batch-byte-compile $< @end example @noindent In this example the result of @samp{$(filter %.o,$(files))} is @file{bar.o lose.o}, and the first static pattern rule causes each of these object files to be updated by compiling the corresponding C source file. The result of @w{@samp{$(filter %.elc,$(files))}} is @file{foo.elc}, so that file is made from @file{foo.el}. Another example shows how to use @code{$*} in static pattern rules: @vindex $*@r{, and static pattern} @example @group bigoutput littleoutput : %output : text.g generate text.g -$* > $@@ @end group @end example @noindent When the @code{generate} command is run, @code{$*} will expand to the stem, either @samp{big} or @samp{little}. @node Static versus Implicit @subsection Static Pattern Rules versus Implicit Rules @cindex rule, static pattern versus implicit @cindex static pattern rule, versus implicit A static pattern rule has much in common with an implicit rule defined as a pattern rule (@pxref{Pattern Rules, ,Defining and Redefining Pattern Rules}). Both have a pattern for the target and patterns for constructing the names of prerequisites. The difference is in how @code{make} decides @emph{when} the rule applies. An implicit rule @emph{can} apply to any target that matches its pattern, but it @emph{does} apply only when the target has no recipe otherwise specified, and only when the prerequisites can be found. If more than one implicit rule appears applicable, only one applies; the choice depends on the order of rules. By contrast, a static pattern rule applies to the precise list of targets that you specify in the rule. It cannot apply to any other target and it invariably does apply to each of the targets specified. If two conflicting rules apply, and both have recipes, that's an error. The static pattern rule can be better than an implicit rule for these reasons: @itemize @bullet @item You may wish to override the usual implicit rule for a few files whose names cannot be categorized syntactically but can be given in an explicit list. @item If you cannot be sure of the precise contents of the directories you are using, you may not be sure which other irrelevant files might lead @code{make} to use the wrong implicit rule. The choice might depend on the order in which the implicit rule search is done. With static pattern rules, there is no uncertainty: each rule applies to precisely the targets specified. @end itemize @node Double-Colon @section Double-Colon Rules @cindex double-colon rules @cindex rule, double-colon (@code{::}) @cindex multiple rules for one target (@code{::}) @cindex @code{::} rules (double-colon) @dfn{Double-colon} rules are explicit rules written with @samp{::} instead of @samp{:} after the target names. They are handled differently from ordinary rules when the same target appears in more than one rule. Pattern rules with double-colons have an entirely different meaning (@pxref{Match-Anything Rules}). When a target appears in multiple rules, all the rules must be the same type: all ordinary, or all double-colon. If they are double-colon, each of them is independent of the others. Each double-colon rule's recipe is executed if the target is older than any prerequisites of that rule. If there are no prerequisites for that rule, its recipe is always executed (even if the target already exists). This can result in executing none, any, or all of the double-colon rules. Double-colon rules with the same target are in fact completely separate from one another. Each double-colon rule is processed individually, just as rules with different targets are processed. The double-colon rules for a target are executed in the order they appear in the makefile. However, the cases where double-colon rules really make sense are those where the order of executing the recipes would not matter. Double-colon rules are somewhat obscure and not often very useful; they provide a mechanism for cases in which the method used to update a target differs depending on which prerequisite files caused the update, and such cases are rare. Each double-colon rule should specify a recipe; if it does not, an implicit rule will be used if one applies. @xref{Implicit Rules, ,Using Implicit Rules}. @node Automatic Prerequisites @section Generating Prerequisites Automatically @cindex prerequisites, automatic generation @cindex automatic generation of prerequisites @cindex generating prerequisites automatically In the makefile for a program, many of the rules you need to write often say only that some object file depends on some header file. For example, if @file{main.c} uses @file{defs.h} via an @code{#include}, you would write: @example main.o: defs.h @end example @noindent You need this rule so that @code{make} knows that it must remake @file{main.o} whenever @file{defs.h} changes. You can see that for a large program you would have to write dozens of such rules in your makefile. And, you must always be very careful to update the makefile every time you add or remove an @code{#include}. @cindex @code{#include} @cindex @code{-M} (to compiler) To avoid this hassle, most modern C compilers can write these rules for you, by looking at the @code{#include} lines in the source files. Usually this is done with the @samp{-M} option to the compiler. For example, the command: @example cc -M main.c @end example @noindent generates the output: @example main.o : main.c defs.h @end example @noindent Thus you no longer have to write all those rules yourself. The compiler will do it for you. Note that such a rule constitutes mentioning @file{main.o} in a makefile, so it can never be considered an intermediate file by implicit rule search. This means that @code{make} won't ever remove the file after using it; @pxref{Chained Rules, ,Chains of Implicit Rules}. @cindex @code{make depend} With old @code{make} programs, it was traditional practice to use this compiler feature to generate prerequisites on demand with a command like @samp{make depend}. That command would create a file @file{depend} containing all the automatically-generated prerequisites; then the makefile could use @code{include} to read them in (@pxref{Include}). In GNU @code{make}, the feature of remaking makefiles makes this practice obsolete---you need never tell @code{make} explicitly to regenerate the prerequisites, because it always regenerates any makefile that is out of date. @xref{Remaking Makefiles}. The practice we recommend for automatic prerequisite generation is to have one makefile corresponding to each source file. For each source file @file{@var{name}.c} there is a makefile @file{@var{name}.d} which lists what files the object file @file{@var{name}.o} depends on. That way only the source files that have changed need to be rescanned to produce the new prerequisites. Here is the pattern rule to generate a file of prerequisites (i.e., a makefile) called @file{@var{name}.d} from a C source file called @file{@var{name}.c}: @smallexample @group %.d: %.c @@set -e; rm -f $@@; \ $(CC) -M $(CPPFLAGS) $< > $@@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@@ : ,g' < $@@.$$$$ > $@@; \ rm -f $@@.$$$$ @end group @end smallexample @noindent @xref{Pattern Rules}, for information on defining pattern rules. The @samp{-e} flag to the shell causes it to exit immediately if the @code{$(CC)} command (or any other command) fails (exits with a nonzero status). @cindex @code{-e} (shell flag) @cindex @code{-MM} (to GNU compiler) With the GNU C compiler, you may wish to use the @samp{-MM} flag instead of @samp{-M}. This omits prerequisites on system header files. @xref{Preprocessor Options, , Options Controlling the Preprocessor, gcc, Using GNU CC}, for details. @cindex @code{sed} (shell command) The purpose of the @code{sed} command is to translate (for example): @example main.o : main.c defs.h @end example @noindent into: @example main.o main.d : main.c defs.h @end example @noindent @cindex @code{.d} This makes each @samp{.d} file depend on all the source and header files that the corresponding @samp{.o} file depends on. @code{make} then knows it must regenerate the prerequisites whenever any of the source or header files changes. Once you've defined the rule to remake the @samp{.d} files, you then use the @code{include} directive to read them all in. @xref{Include}. For example: @example @group sources = foo.c bar.c include $(sources:.c=.d) @end group @end example @noindent (This example uses a substitution variable reference to translate the list of source files @samp{foo.c bar.c} into a list of prerequisite makefiles, @samp{foo.d bar.d}. @xref{Substitution Refs}, for full information on substitution references.) Since the @samp{.d} files are makefiles like any others, @code{make} will remake them as necessary with no further work from you. @xref{Remaking Makefiles}. Note that the @samp{.d} files contain target definitions; you should be sure to place the @code{include} directive @emph{after} the first, default goal in your makefiles or run the risk of having a random object file become the default goal. @xref{How Make Works}. @node Recipes @chapter Writing Recipes in Rules @cindex recipes @cindex recipes, how to write @cindex writing recipes The recipe of a rule consists of one or more shell command lines to be executed, one at a time, in the order they appear. Typically, the result of executing these commands is that the target of the rule is brought up to date. Users use many different shell programs, but recipes in makefiles are always interpreted by @file{/bin/sh} unless the makefile specifies otherwise. @xref{Execution, ,Recipe Execution}. @menu * Recipe Syntax:: Recipe syntax features and pitfalls. * Echoing:: How to control when recipes are echoed. * Execution:: How recipes are executed. * Parallel:: How recipes can be executed in parallel. * Errors:: What happens after a recipe execution error. * Interrupts:: What happens when a recipe is interrupted. * Recursion:: Invoking @code{make} from makefiles. * Canned Recipes:: Defining canned recipes. * Empty Recipes:: Defining useful, do-nothing recipes. @end menu @node Recipe Syntax @section Recipe Syntax @cindex recipe syntax @cindex syntax of recipe Makefiles have the unusual property that there are really two distinct syntaxes in one file. Most of the makefile uses @code{make} syntax (@pxref{Makefiles, ,Writing Makefiles}). However, recipes are meant to be interpreted by the shell and so they are written using shell syntax. The @code{make} program does not try to understand shell syntax: it performs only a very few specific translations on the content of the recipe before handing it to the shell. Each line in the recipe must start with a tab (or the first character in the value of the @code{.RECIPEPREFIX} variable; @pxref{Special Variables}), except that the first recipe line may be attached to the target-and-prerequisites line with a semicolon in between. @emph{Any} line in the makefile that begins with a tab and appears in a ``rule context'' (that is, after a rule has been started until another rule or variable definition) will be considered part of a recipe for that rule. Blank lines and lines of just comments may appear among the recipe lines; they are ignored. Some consequences of these rules include: @itemize @bullet @item A blank line that begins with a tab is not blank: it's an empty recipe (@pxref{Empty Recipes}). @cindex comments, in recipes @cindex recipes, comments in @cindex @code{#} (comments), in recipes @item A comment in a recipe is not a @code{make} comment; it will be passed to the shell as-is. Whether the shell treats it as a comment or not depends on your shell. @item A variable definition in a ``rule context'' which is indented by a tab as the first character on the line, will be considered part of a recipe, not a @code{make} variable definition, and passed to the shell. @item A conditional expression (@code{ifdef}, @code{ifeq}, etc. @pxref{Conditional Syntax, ,Syntax of Conditionals}) in a ``rule context'' which is indented by a tab as the first character on the line, will be considered part of a recipe and be passed to the shell. @end itemize @menu * Splitting Recipe Lines:: Breaking long recipe lines for readability. * Variables in Recipes:: Using @code{make} variables in recipes. @end menu @node Splitting Recipe Lines @subsection Splitting Recipe Lines @cindex recipes, splitting @cindex splitting recipes @cindex recipes, backslash (@code{\}) in @cindex recipes, quoting newlines in @cindex backslash (@code{\}), in recipes @cindex @code{\} (backslash), in recipes @cindex quoting newline, in recipes @cindex newline, quoting, in recipes One of the few ways in which @code{make} does interpret recipes is checking for a backslash just before the newline. As in normal makefile syntax, a single logical recipe line can be split into multiple physical lines in the makefile by placing a backslash before each newline. A sequence of lines like this is considered a single recipe line, and one instance of the shell will be invoked to run it. However, in contrast to how they are treated in other places in a makefile (@pxref{Splitting Lines, , Splitting Long Lines}), backslash/newline pairs are @emph{not} removed from the recipe. Both the backslash and the newline characters are preserved and passed to the shell. How the backslash/newline is interpreted depends on your shell. If the first character of the next line after the backslash/newline is the recipe prefix character (a tab by default; @pxref{Special Variables}), then that character (and only that character) is removed. Whitespace is never added to the recipe. For example, the recipe for the all target in this makefile: @example @group all : @@echo no\ space @@echo no\ space @@echo one \ space @@echo one\ space @end group @end example @noindent consists of four separate shell commands where the output is: @example @group nospace nospace one space one space @end group @end example As a more complex example, this makefile: @example @group all : ; @@echo 'hello \ world' ; echo "hello \ world" @end group @end example @noindent will invoke one shell with a command of: @example @group echo 'hello \ world' ; echo "hello \ world" @end group @end example @noindent which, according to shell quoting rules, will yield the following output: @example @group hello \ world hello world @end group @end example @noindent Notice how the backslash/newline pair was removed inside the string quoted with double quotes (@code{"@dots{}"}), but not from the string quoted with single quotes (@code{'@dots{}'}). This is the way the default shell (@file{/bin/sh}) handles backslash/newline pairs. If you specify a different shell in your makefiles it may treat them differently. Sometimes you want to split a long line inside of single quotes, but you don't want the backslash/newline to appear in the quoted content. This is often the case when passing scripts to languages such as Perl, where extraneous backslashes inside the script can change its meaning or even be a syntax error. One simple way of handling this is to place the quoted string, or even the entire command, into a @code{make} variable then use the variable in the recipe. In this situation the newline quoting rules for makefiles will be used, and the backslash/newline will be removed. If we rewrite our example above using this method: @example @group HELLO = 'hello \ world' all : ; @@echo $(HELLO) @end group @end example @noindent we will get output like this: @example @group hello world @end group @end example If you like, you can also use target-specific variables (@pxref{Target-specific, ,Target-specific Variable Values}) to obtain a tighter correspondence between the variable and the recipe that uses it. @node Variables in Recipes @subsection Using Variables in Recipes @cindex variable references in recipes @cindex recipes, using variables in The other way in which @code{make} processes recipes is by expanding any variable references in them (@pxref{Reference,Basics of Variable References}). This occurs after make has finished reading all the makefiles and the target is determined to be out of date; so, the recipes for targets which are not rebuilt are never expanded. Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. They also have the same quoting rules: if you want a dollar sign to appear in your recipe, you must double it (@samp{$$}). For shells like the default shell, that use dollar signs to introduce variables, it's important to keep clear in your mind whether the variable you want to reference is a @code{make} variable (use a single dollar sign) or a shell variable (use two dollar signs). For example: @example @group LIST = one two three all: for i in $(LIST); do \ echo $$i; \ done @end group @end example @noindent results in the following command being passed to the shell: @example @group for i in one two three; do \ echo $i; \ done @end group @end example @noindent which generates the expected result: @example @group one two three @end group @end example @node Echoing @section Recipe Echoing @cindex echoing of recipes @cindex silent operation @cindex @code{@@} (in recipes) @cindex recipes, echoing @cindex printing of recipes Normally @code{make} prints each line of the recipe before it is executed. We call this @dfn{echoing} because it gives the appearance that you are typing the lines yourself. When a line starts with @samp{@@}, the echoing of that line is suppressed. The @samp{@@} is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an @code{echo} command to indicate progress through the makefile: @example @@echo About to make distribution files @end example Note that the start of a recipe line is interpreted differently when using @code{.ONESHELL} (@pxref{One Shell, ,Using One Shell}). @cindex @code{-n} @cindex @code{--just-print} @cindex @code{--dry-run} @cindex @code{--recon} When @code{make} is given the flag @samp{-n} or @samp{--just-print} it only echoes most recipes, without executing them. @xref{Options Summary, ,Summary of Options}. In this case even the recipe lines starting with @samp{@@} are printed. This flag is useful for finding out which recipes @code{make} thinks are necessary without actually doing them. @cindex @code{-s} @cindex @code{--silent} @cindex @code{--quiet} The @samp{-s} or @samp{--silent} flag to @code{make} prevents all echoing, as if all recipes started with @samp{@@}. A rule in the makefile for the special target @code{.SILENT} without prerequisites has the same effect (@pxref{Special Targets, ,Special Built-in Target Names}). @node Execution @section Recipe Execution @cindex recipe, execution @cindex execution, of recipes @vindex @code{SHELL} @r{(recipe execution)} When it is time to execute recipes to update a target, they are executed by invoking a new sub-shell for each line of the recipe, unless the @code{.ONESHELL} special target is in effect (@pxref{One Shell, ,Using One Shell}) (In practice, @code{make} may take shortcuts that do not affect the results.) @cindex @code{cd} (shell command) @cindex shell variables, setting in recipes @cindex recipes setting shell variables @strong{Please note:} this implies that setting shell variables and invoking shell commands such as @code{cd} that set a context local to each process will not affect the following lines in the recipe.@footnote{On MS-DOS, the value of current working directory is @strong{global}, so changing it @emph{will} affect the following recipe lines on those systems.} If you want to use @code{cd} to affect the next statement, put both statements in a single recipe line. Then @code{make} will invoke one shell to run the entire line, and the shell will execute the statements in sequence. For example: @example foo : bar/lose cd $( ../$@@ @end example @noindent Here we use the shell AND operator (@code{&&}) so that if the @code{cd} command fails, the script will fail without trying to invoke the @code{gobble} command in the wrong directory, which could cause problems (in this case it would certainly cause @file{../foo} to be truncated, at least). @menu * One Shell:: One shell for all lines in a recipe. * Choosing the Shell:: How @code{make} chooses the shell used to run recipes. @end menu @node One Shell @subsection Using One Shell @cindex recipe lines, single shell @cindex @code{.ONESHELL}, use of @findex .ONESHELL Sometimes you would prefer that all the lines in the recipe be passed to a single invocation of the shell. There are generally two situations where this is useful: first, it can improve performance in makefiles where recipes consist of many command lines, by avoiding extra processes. Second, you might want newlines to be included in your recipe command (for example perhaps you are using a very different interpreter as your @code{SHELL}). If the @code{.ONESHELL} special target appears anywhere in the makefile then @emph{all} recipe lines for each target will be provided to a single invocation of the shell. Newlines between recipe lines will be preserved. For example: @example .ONESHELL: foo : bar/lose cd $( ../$@@ @end example @noindent would now work as expected even though the commands are on different recipe lines. If @code{.ONESHELL} is provided, then only the first line of the recipe will be checked for the special prefix characters (@samp{@@}, @samp{-}, and @samp{+}). Subsequent lines will include the special characters in the recipe line when the @code{SHELL} is invoked. If you want your recipe to start with one of these special characters you'll need to arrange for them to not be the first characters on the first line, perhaps by adding a comment or similar. For example, this would be a syntax error in Perl because the first @samp{@@} is removed by make: @example .ONESHELL: SHELL = /usr/bin/perl .SHELLFLAGS = -e show : @@f = qw(a b c); print "@@f\n"; @end example @noindent However, either of these alternatives would work properly: @example .ONESHELL: SHELL = /usr/bin/perl .SHELLFLAGS = -e show : # Make sure "@@" is not the first character on the first line @@f = qw(a b c); print "@@f\n"; @end example @noindent or @example .ONESHELL: SHELL = /usr/bin/perl .SHELLFLAGS = -e show : my @@f = qw(a b c); print "@@f\n"; @end example As a special feature, if @code{SHELL} is determined to be a POSIX-style shell, the special prefix characters in ``internal'' recipe lines will be @emph{removed} before the recipe is processed. This feature is intended to allow existing makefiles to add the @code{.ONESHELL} special target and still run properly without extensive modifications. Since the special prefix characters are not legal at the beginning of a line in a POSIX shell script this is not a loss in functionality. For example, this works as expected: @example .ONESHELL: foo : bar/lose @@cd $(@@D) @@gobble $(@@F) > ../$@@ @end example Even with this special feature, however, makefiles with @code{.ONESHELL} will behave differently in ways that could be noticeable. For example, normally if any line in the recipe fails, that causes the rule to fail and no more recipe lines are processed. Under @code{.ONESHELL} a failure of any but the final recipe line will not be noticed by @code{make}. You can modify @code{.SHELLFLAGS} to add the @code{-e} option to the shell which will cause any failure anywhere in the command line to cause the shell to fail, but this could itself cause your recipe to behave differently. Ultimately you may need to harden your recipe lines to allow them to work with @code{.ONESHELL}. @node Choosing the Shell @subsection Choosing the Shell @cindex shell, choosing the @cindex @code{SHELL}, value of @cindex @code{.SHELLFLAGS}, value of @vindex SHELL @vindex .SHELLFLAGS The program used as the shell is taken from the variable @code{SHELL}. If this variable is not set in your makefile, the program @file{/bin/sh} is used as the shell. The argument(s) passed to the shell are taken from the variable @code{.SHELLFLAGS}. The default value of @code{.SHELLFLAGS} is @code{-c} normally, or @code{-ec} in POSIX-conforming mode. @cindex environment, @code{SHELL} in Unlike most variables, the variable @code{SHELL} is never set from the environment. This is because the @code{SHELL} environment variable is used to specify your personal choice of shell program for interactive use. It would be very bad for personal choices like this to affect the functioning of makefiles. @xref{Environment, ,Variables from the Environment}. Furthermore, when you do set @code{SHELL} in your makefile that value is @emph{not} exported in the environment to recipe lines that @code{make} invokes. Instead, the value inherited from the user's environment, if any, is exported. You can override this behavior by explicitly exporting @code{SHELL} (@pxref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}), forcing it to be passed in the environment to recipe lines. However, on MS-DOS and MS-Windows the value of @code{SHELL} in the environment @strong{is} used, since on those systems most users do not set this variable, and therefore it is most likely set specifically to be used by @code{make}. On MS-DOS, if the setting of @code{SHELL} is not suitable for @code{make}, you can set the variable @code{MAKESHELL} to the shell that @code{make} should use; if set it will be used as the shell instead of the value of @code{SHELL}. @subsubheading Choosing a Shell in DOS and Windows @cindex shell, in DOS and Windows @cindex DOS, choosing a shell in @cindex Windows, choosing a shell in Choosing a shell in MS-DOS and MS-Windows is much more complex than on other systems. @vindex COMSPEC On MS-DOS, if @code{SHELL} is not set, the value of the variable @code{COMSPEC} (which is always set) is used instead. @cindex @code{SHELL}, MS-DOS specifics The processing of lines that set the variable @code{SHELL} in Makefiles is different on MS-DOS. The stock shell, @file{command.com}, is ridiculously limited in its functionality and many users of @code{make} tend to install a replacement shell. Therefore, on MS-DOS, @code{make} examines the value of @code{SHELL}, and changes its behavior based on whether it points to a Unix-style or DOS-style shell. This allows reasonable functionality even if @code{SHELL} points to @file{command.com}. If @code{SHELL} points to a Unix-style shell, @code{make} on MS-DOS additionally checks whether that shell can indeed be found; if not, it ignores the line that sets @code{SHELL}. In MS-DOS, GNU @code{make} searches for the shell in the following places: @enumerate @item In the precise place pointed to by the value of @code{SHELL}. For example, if the makefile specifies @samp{SHELL = /bin/sh}, @code{make} will look in the directory @file{/bin} on the current drive. @item In the current directory. @item In each of the directories in the @code{PATH} variable, in order. @end enumerate In every directory it examines, @code{make} will first look for the specific file (@file{sh} in the example above). If this is not found, it will also look in that directory for that file with one of the known extensions which identify executable files. For example @file{.exe}, @file{.com}, @file{.bat}, @file{.btm}, @file{.sh}, and some others. If any of these attempts is successful, the value of @code{SHELL} will be set to the full pathname of the shell as found. However, if none of these is found, the value of @code{SHELL} will not be changed, and thus the line that sets it will be effectively ignored. This is so @code{make} will only support features specific to a Unix-style shell if such a shell is actually installed on the system where @code{make} runs. Note that this extended search for the shell is limited to the cases where @code{SHELL} is set from the Makefile; if it is set in the environment or command line, you are expected to set it to the full pathname of the shell, exactly as things are on Unix. The effect of the above DOS-specific processing is that a Makefile that contains @samp{SHELL = /bin/sh} (as many Unix makefiles do), will work on MS-DOS unaltered if you have e.g.@: @file{sh.exe} installed in some directory along your @code{PATH}. @node Parallel @section Parallel Execution @cindex recipes, execution in parallel @cindex parallel execution @cindex execution, in parallel @cindex job slots @cindex @code{-j} @cindex @code{--jobs} GNU @code{make} knows how to execute several recipes at once. Normally, @code{make} will execute only one recipe at a time, waiting for it to finish before executing the next. However, the @samp{-j} or @samp{--jobs} option tells @code{make} to execute many recipes simultaneously. You can inhibit parallelism for some or all targets from within the makefile (@pxref{Parallel Disable, ,Disabling Parallel Execution}). On MS-DOS, the @samp{-j} option has no effect, since that system doesn't support multi-processing. If the @samp{-j} option is followed by an integer, this is the number of recipes to execute at once; this is called the number of @dfn{job slots}. If there is nothing looking like an integer after the @samp{-j} option, there is no limit on the number of job slots. The default number of job slots is one, which means serial execution (one thing at a time). Handling recursive @code{make} invocations raises issues for parallel execution. For more information on this, see @ref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. If a recipe fails (is killed by a signal or exits with a nonzero status), and errors are not ignored for that recipe (@pxref{Errors, ,Errors in Recipes}), the remaining recipe lines to remake the same target will not be run. If a recipe fails and the @samp{-k} or @samp{--keep-going} option was not given (@pxref{Options Summary, ,Summary of Options}), @code{make} aborts execution. If make terminates for any reason (including a signal) with child processes running, it waits for them to finish before actually exiting. @cindex load average @cindex limiting jobs based on load @cindex jobs, limiting based on load @cindex @code{-l} (load average) @cindex @code{--max-load} @cindex @code{--load-average} When the system is heavily loaded, you will probably want to run fewer jobs than when it is lightly loaded. You can use the @samp{-l} option to tell @code{make} to limit the number of jobs to run at once, based on the load average. The @samp{-l} or @samp{--max-load} option is followed by a floating-point number. For example, @example -l 2.5 @end example @noindent will not let @code{make} start more than one job if the load average is above 2.5. The @samp{-l} option with no following number removes the load limit, if one was given with a previous @samp{-l} option. More precisely, when @code{make} goes to start up a job, and it already has at least one job running, it checks the current load average; if it is not lower than the limit given with @samp{-l}, @code{make} waits until the load average goes below that limit, or until all the other jobs finish. By default, there is no load limit. @menu * Parallel Disable:: Disabling parallel execution * Parallel Output:: Handling output during parallel execution * Parallel Input:: Handling input during parallel execution @end menu @node Parallel Disable @subsection Disabling Parallel Execution @cindex disabling parallel execution @cindex parallel execution, disabling If a makefile completely and accurately defines the dependency relationships between all of its targets, then @code{make} will correctly build the goals regardless of whether parallel execution is enabled or not. This is the ideal way to write makefiles. However, sometimes some or all of the targets in a makefile cannot be executed in parallel and it's not feasible to add the prerequisites needed to inform @code{make}. In that case the makefile can use various methods to disable parallel execution. @cindex .NOTPARALLEL special target If the @code{.NOTPARALLEL} special target with no prerequisites is specified anywhere then the entire instance of @code{make} will be run serially, regardless of the parallel setting. For example: @example @group all: one two three one two three: ; @@sleep 1; echo $@@ .NOTPARALLEL: @end group @end example Regardless of how @code{make} is invoked, the targets @file{one}, @file{two}, and @file{three} will be run serially. If the @code{.NOTPARALLEL} special target has prerequisites, then each of those prerequisites will be considered a target and all prerequisites of these targets will be run serially. Note that only when building this target will the prerequisites be run serially: if some other target lists the same prerequisites and is not in @code{.NOTPARALLEL} then these prerequisites may be run in parallel. For example: @example @group all: base notparallel base: one two three notparallel: one two three one two three: ; @@sleep 1; echo $@@ .NOTPARALLEL: notparallel @end group @end example Here @samp{make -j base} will run the targets @file{one}, @file{two}, and @file{three} in parallel, while @samp{make -j notparallel} will run them serially. If you run @samp{make -j all} then they @emph{will} be run in parallel since @file{base} lists them as prerequisites and is not serialized. The @code{.NOTPARALLEL} target should not have commands. @cindex .WAIT special target @findex .WAIT Finally you can control the serialization of specific prerequisites in a fine-grained way using the @code{.WAIT} special target. When this target appears in a prerequisite list and parallel execution is enabled, @code{make} will not build any of the prerequisites to the @emph{right} of @code{.WAIT} until all prerequisites to the @emph{left} of @code{.WAIT} have completed. For example: @example @group all: one two .WAIT three one two three: ; @@sleep 1; echo $@@ @end group @end example If parallel execution is enabled, @code{make} will try to build @file{one} and @file{two} in parallel but will not try to build @file{three} until both are complete. As with targets provided to @code{.NOTPARALLEL}, @code{.WAIT} takes effect only when building the target in whose prerequisite list it appears. If the same prerequisites are present in other targets, without @code{.WAIT}, then they may still be run in parallel. Because of this, neither @code{.NOTPARALLEL} with targets nor @code{.WAIT} are as reliable for controlling parallel execution as defining a prerequisite relationship. However they are easy to use and may be sufficient in less complex situations. The @code{.WAIT} prerequisite will not be present in any of the automatic variables for the rule. You can create an actual target @code{.WAIT} in your makefile for portability but this is not required to use this feature. If a @code{.WAIT} target is created it should not have prerequisites or commands. The @code{.WAIT} feature is also implemented in other versions of @code{make} and it's specified in the POSIX standard for @code{make}. @node Parallel Output @subsection Output During Parallel Execution @cindex output during parallel execution @cindex parallel execution, output during When running several recipes in parallel the output from each recipe appears as soon as it is generated, with the result that messages from different recipes may be interspersed, sometimes even appearing on the same line. This can make reading the output very difficult. @cindex @code{--output-sync} @cindex @code{-O} To avoid this you can use the @samp{--output-sync} (@samp{-O}) option. This option instructs @code{make} to save the output from the commands it invokes and print it all once the commands are completed. Additionally, if there are multiple recursive @code{make} invocations running in parallel, they will communicate so that only one of them is generating output at a time. If working directory printing is enabled (@pxref{-w Option, ,The @samp{--print-directory} Option}), the enter/leave messages are printed around each output grouping. If you prefer not to see these messages add the @samp{--no-print-directory} option to @code{MAKEFLAGS}. There are four levels of granularity when synchronizing output, specified by giving an argument to the option (e.g., @samp{-Oline} or @samp{--output-sync=recurse}). @table @code @item none This is the default: all output is sent directly as it is generated and no synchronization is performed. @item line Output from each individual line of the recipe is grouped and printed as soon as that line is complete. If a recipe consists of multiple lines, they may be interspersed with lines from other recipes. @item target Output from the entire recipe for each target is grouped and printed once the target is complete. This is the default if the @code{--output-sync} or @code{-O} option is given with no argument. @item recurse Output from each recursive invocation of @code{make} is grouped and printed once the recursive invocation is complete. @end table Regardless of the mode chosen, the total build time will be the same. The only difference is in how the output appears. The @samp{target} and @samp{recurse} modes both collect the output of the entire recipe of a target and display it uninterrupted when the recipe completes. The difference between them is in how recipes that contain recursive invocations of @code{make} are treated (@pxref{Recursion, ,Recursive Use of @code{make}}). For all recipes which have no recursive lines, the @samp{target} and @samp{recurse} modes behave identically. If the @samp{recurse} mode is chosen, recipes that contain recursive @code{make} invocations are treated the same as other targets: the output from the recipe, including the output from the recursive @code{make}, is saved and printed after the entire recipe is complete. This ensures output from all the targets built by a given recursive @code{make} instance are grouped together, which may make the output easier to understand. However it also leads to long periods of time during the build where no output is seen, followed by large bursts of output. If you are not watching the build as it proceeds, but instead viewing a log of the build after the fact, this may be the best option for you. If you are watching the output, the long gaps of quiet during the build can be frustrating. The @samp{target} output synchronization mode detects when @code{make} is going to be invoked recursively, using the standard methods, and it will not synchronize the output of those lines. The recursive @code{make} will perform the synchronization for its targets and the output from each will be displayed immediately when it completes. Be aware that output from recursive lines of the recipe are not synchronized (for example if the recursive line prints a message before running @code{make}, that message will not be synchronized). The @samp{line} mode can be useful for front-ends that are watching the output of @code{make} to track when recipes are started and completed. Some programs invoked by @code{make} may behave differently if they determine they're writing output to a terminal versus a file (often described as ``interactive'' vs. ``non-interactive'' modes). For example, many programs that can display colorized output will not do so if they determine they are not writing to a terminal. If your makefile invokes a program like this then using the output synchronization options will cause the program to believe it's running in ``non-interactive'' mode even though the output will ultimately go to the terminal. @node Parallel Input @subsection Input During Parallel Execution @cindex input during parallel execution @cindex parallel execution, input during @cindex standard input Two processes cannot both take input from the same device at the same time. To make sure that only one recipe tries to take input from the terminal at once, @code{make} will invalidate the standard input streams of all but one running recipe. If another recipe attempts to read from standard input it will usually incur a fatal error (a @samp{Broken pipe} signal). @cindex broken pipe It is unpredictable which recipe will have a valid standard input stream (which will come from the terminal, or wherever you redirect the standard input of @code{make}). The first recipe run will always get it first, and the first recipe started after that one finishes will get it next, and so on. We will change how this aspect of @code{make} works if we find a better alternative. In the mean time, you should not rely on any recipe using standard input at all if you are using the parallel execution feature; but if you are not using this feature, then standard input works normally in all recipes. @node Errors @section Errors in Recipes @cindex errors (in recipes) @cindex recipes, errors in @cindex exit status (errors) After each shell invocation returns, @code{make} looks at its exit status. If the shell completed successfully (the exit status is zero), the next line in the recipe is executed in a new shell; after the last line is finished, the rule is finished. If there is an error (the exit status is nonzero), @code{make} gives up on the current rule, and perhaps on all rules. Sometimes the failure of a certain recipe line does not indicate a problem. For example, you may use the @code{mkdir} command to ensure that a directory exists. If the directory already exists, @code{mkdir} will report an error, but you probably want @code{make} to continue regardless. @cindex @code{-} (in recipes) To ignore errors in a recipe line, write a @samp{-} at the beginning of the line's text (after the initial tab). The @samp{-} is discarded before the line is passed to the shell for execution. Note that the beginning of a recipe line is interpreted differently when using @code{.ONESHELL} (@pxref{One Shell, ,Using One Shell}). For example, @example @group clean: -rm -f *.o @end group @end example @cindex @code{rm} (shell command) @noindent This causes @code{make} to continue even if @code{rm} is unable to remove a file. @cindex @code{-i} @cindex @code{--ignore-errors} When you run @code{make} with the @samp{-i} or @samp{--ignore-errors} flag, errors are ignored in all recipes of all rules. A rule in the makefile for the special target @code{.IGNORE} has the same effect, if there are no prerequisites. This is less flexible but sometimes useful. When errors are to be ignored, because of either a @samp{-} or the @samp{-i} flag, @code{make} treats an error return just like success, except that it prints out a message that tells you the status code the shell exited with, and says that the error has been ignored. When an error happens that @code{make} has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly. No further recipes will be executed for these targets, since their preconditions have not been achieved. @cindex @code{-k} @cindex @code{--keep-going} Normally @code{make} gives up immediately in this circumstance, returning a nonzero status. However, if the @samp{-k} or @samp{--keep-going} flag is specified, @code{make} continues to consider the other prerequisites of the pending targets, remaking them if necessary, before it gives up and returns nonzero status. For example, after an error in compiling one object file, @samp{make -k} will continue compiling other object files even though it already knows that linking them will be impossible. @xref{Options Summary, ,Summary of Options}. The usual behavior assumes that your purpose is to get the specified targets up to date; once @code{make} learns that this is impossible, it might as well report the failure immediately. The @samp{-k} option says that the real purpose is to test as many of the changes made in the program as possible, perhaps to find several independent problems so that you can correct them all before the next attempt to compile. This is why Emacs' @code{compile} command passes the @samp{-k} flag by default. @cindex Emacs (@code{M-x compile}) @findex .DELETE_ON_ERROR@r{, errors in recipes} @cindex deletion of target files @cindex removal of target files @cindex target, deleting on error Usually when a recipe line fails, if it has changed the target file at all, the file is corrupted and cannot be used---or at least it is not completely updated. Yet the file's time stamp says that it is now up to date, so the next time @code{make} runs, it will not try to update that file. The situation is just the same as when the shell is killed by a signal; @pxref{Interrupts}. So generally the right thing to do is to delete the target file if the recipe fails after beginning to change the file. @code{make} will do this if @code{.DELETE_ON_ERROR} appears as a target. This is almost always what you want @code{make} to do, but it is not historical practice; so for compatibility, you must explicitly request it. @node Interrupts @section Interrupting or Killing @code{make} @cindex interrupt @cindex signal @cindex deletion of target files @cindex removal of target files @cindex target, deleting on interrupt @cindex killing (interruption) If @code{make} gets a fatal signal while a shell is executing, it may delete the target file that the recipe was supposed to update. This is done if the target file's last-modification time has changed since @code{make} first checked it. The purpose of deleting the target is to make sure that it is remade from scratch when @code{make} is next run. Why is this? Suppose you type @kbd{Ctrl-c} while a compiler is running, and it has begun to write an object file @file{foo.o}. The @kbd{Ctrl-c} kills the compiler, resulting in an incomplete file whose last-modification time is newer than the source file @file{foo.c}. But @code{make} also receives the @kbd{Ctrl-c} signal and deletes this incomplete file. If @code{make} did not do this, the next invocation of @code{make} would think that @file{foo.o} did not require updating---resulting in a strange error message from the linker when it tries to link an object file half of which is missing. @cindex .PRECIOUS, preserving targets You can prevent the deletion of a target file in this way by making the special target @code{.PRECIOUS} depend on it. Before remaking a target, @code{make} checks to see whether it appears on the prerequisites of @code{.PRECIOUS}, and thereby decides whether the target should be deleted if a signal happens. Some reasons why you might do this are that the target is updated in some atomic fashion, or exists only to record a modification-time (its contents do not matter), or must exist at all times to prevent other sorts of trouble. Although @code{make} does its best to clean up there are certain situations in which cleanup is impossible. For example, @code{make} may be killed by an uncatchable signal. Or, one of the programs make invokes may be killed or crash, leaving behind an up-to-date but corrupt target file: @code{make} will not realize that this failure requires the target to be cleaned. Or @code{make} itself may encounter a bug and crash. For these reasons it's best to write @emph{defensive recipes}, which won't leave behind corrupted targets even if they fail. Most commonly these recipes create temporary files rather than updating the target directly, then rename the temporary file to the final target name. Some compilers already behave this way, so that you don't need to write a defensive recipe. @node Recursion @section Recursive Use of @code{make} @cindex recursion @cindex subdirectories, recursion for Recursive use of @code{make} means using @code{make} as a command in a makefile. This technique is useful when you want separate makefiles for various subsystems that compose a larger system. For example, suppose you have a sub-directory @file{subdir} which has its own makefile, and you would like the containing directory's makefile to run @code{make} on the sub-directory. You can do it by writing this: @example subsystem: cd subdir && $(MAKE) @end example @noindent or, equivalently, this (@pxref{Options Summary, ,Summary of Options}): @example subsystem: $(MAKE) -C subdir @end example @cindex @code{-C} @cindex @code{--directory} You can write recursive @code{make} commands just by copying this example, but there are many things to know about how they work and why, and about how the sub-@code{make} relates to the top-level @code{make}. You may also find it useful to declare targets that invoke recursive @code{make} commands as @samp{.PHONY} (for more discussion on when this is useful, see @ref{Phony Targets}). @vindex @code{CURDIR} For your convenience, when GNU @code{make} starts (after it has processed any @code{-C} options) it sets the variable @code{CURDIR} to the pathname of the current working directory. This value is never touched by @code{make} again: in particular note that if you include files from other directories the value of @code{CURDIR} does not change. The value has the same precedence it would have if it were set in the makefile (by default, an environment variable @code{CURDIR} will not override this value). Note that setting this variable has no impact on the operation of @code{make} (it does not cause @code{make} to change its working directory, for example). @menu * MAKE Variable:: The special effects of using @samp{$(MAKE)}. * Variables/Recursion:: How to communicate variables to a sub-@code{make}. * Options/Recursion:: How to communicate options to a sub-@code{make}. * -w Option:: How the @samp{-w} or @samp{--print-directory} option helps debug use of recursive @code{make} commands. @end menu @node MAKE Variable @subsection How the @code{MAKE} Variable Works @vindex MAKE @cindex recursion, and @code{MAKE} variable Recursive @code{make} commands should always use the variable @code{MAKE}, not the explicit command name @samp{make}, as shown here: @example @group subsystem: cd subdir && $(MAKE) @end group @end example The value of this variable is the file name with which @code{make} was invoked. If this file name was @file{/bin/make}, then the recipe executed is @samp{cd subdir && /bin/make}. If you use a special version of @code{make} to run the top-level makefile, the same special version will be executed for recursive invocations. @cindex @code{cd} (shell command) @cindex +, and recipes As a special feature, using the variable @code{MAKE} in the recipe of a rule alters the effects of the @samp{-t} (@samp{--touch}), @samp{-n} (@samp{--just-print}), or @samp{-q} (@w{@samp{--question}}) option. Using the @code{MAKE} variable has the same effect as using a @samp{+} character at the beginning of the recipe line. @xref{Instead of Execution, ,Instead of Executing the Recipes}. This special feature is only enabled if the @code{MAKE} variable appears directly in the recipe: it does not apply if the @code{MAKE} variable is referenced through expansion of another variable. In the latter case you must use the @samp{+} token to get these special effects. Note that the beginning of a recipe line is interpreted differently when using @code{.ONESHELL} (@pxref{One Shell, ,Using One Shell}). Consider the command @samp{make -t} in the above example. (The @samp{-t} option marks targets as up to date without actually running any recipes; see @ref{Instead of Execution}.) Following the usual definition of @samp{-t}, a @samp{make -t} command in the example would create a file named @file{subsystem} and do nothing else. What you really want it to do is run @samp{@w{cd subdir &&} @w{make -t}}; but that would require executing the recipe, and @samp{-t} says not to execute recipes. @cindex @code{-t}, and recursion @cindex recursion, and @code{-t} @cindex @code{--touch}, and recursion The special feature makes this do what you want: whenever a recipe line of a rule contains the variable @code{MAKE}, the flags @samp{-t}, @samp{-n} and @samp{-q} do not apply to that line. Recipe lines containing @code{MAKE} are executed normally despite the presence of a flag that causes most recipes not to be run. The usual @code{MAKEFLAGS} mechanism passes the flags to the sub-@code{make} (@pxref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}), so your request to touch the files, or print the recipes, is propagated to the subsystem. @node Variables/Recursion @subsection Communicating Variables to a Sub-@code{make} @cindex sub-@code{make} @cindex environment, and recursion @cindex exporting variables @cindex variables, environment @cindex variables, exporting @cindex recursion, and environment @cindex recursion, and variables Variable values of the top-level @code{make} can be passed to the sub-@code{make} through the environment by explicit request. These variables are defined in the sub-@code{make} as defaults, but they do not override variables defined in the makefile used by the sub-@code{make} unless you use the @samp{-e} switch (@pxref{Options Summary, ,Summary of Options}). To pass down, or @dfn{export}, a variable, @code{make} adds the variable and its value to the environment for running each line of the recipe. The sub-@code{make}, in turn, uses the environment to initialize its table of variable values. @xref{Environment, ,Variables from the Environment}. Except by explicit request, @code{make} exports a variable only if it is either defined in the environment initially, or if set on the command line and its name consists only of letters, numbers, and underscores. @cindex SHELL, exported value The value of the @code{make} variable @code{SHELL} is not exported. Instead, the value of the @code{SHELL} variable from the invoking environment is passed to the sub-@code{make}. You can force @code{make} to export its value for @code{SHELL} by using the @code{export} directive, described below. @xref{Choosing the Shell}. The special variable @code{MAKEFLAGS} is always exported (unless you unexport it). @code{MAKEFILES} is exported if you set it to anything. @code{make} automatically passes down variable values that were defined on the command line, by putting them in the @code{MAKEFLAGS} variable. @iftex See the next section. @end iftex @ifnottex @xref{Options/Recursion}. @end ifnottex Variables are @emph{not} normally passed down if they were created by default by @code{make} (@pxref{Implicit Variables, ,Variables Used by Implicit Rules}). The sub-@code{make} will define these for itself. @findex export If you want to export specific variables to a sub-@code{make}, use the @code{export} directive, like this: @example export @var{variable} @dots{} @end example @noindent @findex unexport If you want to @emph{prevent} a variable from being exported, use the @code{unexport} directive, like this: @example unexport @var{variable} @dots{} @end example @noindent In both of these forms, the arguments to @code{export} and @code{unexport} are expanded, and so could be variables or functions which expand to a (list of) variable names to be (un)exported. GNU Make will add any variable you export to the environment of all child processes. However, be aware that some child processes themselves will not accept all types of variables. For example, many modern shells will clean the incoming environment by removing or hiding any environment variable whose name is invalid for the shell (e.g., alphanumeric plus underscore). There is nothing GNU Make can do about the behavior of these child processes: if you want your makefile to be maximally portable you should choose simple variable names for all exported variables. As a convenience, you can define a variable and export it at the same time by doing: @example export @var{variable} = value @end example @noindent has the same result as: @example @var{variable} = value export @var{variable} @end example @noindent and @example export @var{variable} := value @end example @noindent has the same result as: @example @var{variable} := value export @var{variable} @end example Likewise, @example export @var{variable} += value @end example @noindent is just like: @example @var{variable} += value export @var{variable} @end example @noindent @xref{Appending Assignment, ,Appending More Text to Variables}. You may notice that the @code{export} and @code{unexport} directives work in @code{make} in the same way they work in the shell, @code{sh}. If you want all variables to be exported by default, you can use @code{export} by itself: @example export @end example @noindent This tells @code{make} that variables which are not explicitly mentioned in an @code{export} or @code{unexport} directive should be exported. Any variable given in an @code{unexport} directive will still @emph{not} be exported. @findex .EXPORT_ALL_VARIABLES Another way to export variables by default is to add the special target @code{.EXPORT_ALL_VARIABLES} to your makefile. This will be ignored by other variants of @code{make}. When using @code{export} by itself or @code{.EXPORT_ALL_VARIABLES} to export variables by default, only variables whose names consist solely of alphanumerics and underscores will be exported. To export other variables you must specifically mention them in an @code{export} directive. Adding a variable's value to the environment requires it to be expanded. If expanding a variable has side-effects (such as the @code{info} or @code{eval} or similar functions) then these side-effects will be seen every time a command is invoked. You can avoid this by ensuring that such variables have names which are not exportable by default. However, a better solution is to @emph{not} use this ``export by default'' facility at all, and instead explicitly @code{export} the relevant variables by name. Be aware that exporting all variables can have serious performance impacts, especially for recursive variables used in conjunction with the @code{shell} function. We recommend you avoid this and instead export only the specific variables needed to run your commands. If you do need to export all variables, use simple variable assignment wherever possible, especially when invoking the @code{shell} function. You can use @code{unexport} by itself to tell @code{make} @emph{not} to export variables by default. Since this is the default behavior, you would only need to do this if @code{export} had been used by itself earlier (in an included makefile, perhaps). You @strong{cannot} use @code{export} and @code{unexport} by themselves to have variables exported for some recipes and not for others. The last @code{export} or @code{unexport} directive that appears by itself determines the behavior for the entire run of @code{make}. @vindex MAKELEVEL @cindex recursion, level of As a special feature, the variable @code{MAKELEVEL} is changed when it is passed down from level to level. This variable's value is a string which is the depth of the level as a decimal number. The value is @samp{0} for the top-level @code{make}; @samp{1} for a sub-@code{make}, @samp{2} for a sub-sub-@code{make}, and so on. The incrementation happens when @code{make} sets up the environment for a recipe. The main use of @code{MAKELEVEL} is to test it in a conditional directive (@pxref{Conditionals, ,Conditional Parts of Makefiles}); this way you can write a makefile that behaves one way if run recursively and another way if run directly by you. @vindex MAKEFILES You can use the variable @code{MAKEFILES} to cause all sub-@code{make} commands to use additional makefiles. The value of @code{MAKEFILES} is a whitespace-separated list of file names. This variable, if defined in the outer-level makefile, is passed down through the environment; then it serves as a list of extra makefiles for the sub-@code{make} to read before the usual or specified ones. @xref{MAKEFILES Variable, ,The Variable @code{MAKEFILES}}. @node Options/Recursion @subsection Communicating Options to a Sub-@code{make} @cindex options, and recursion @cindex recursion, and options @vindex MAKEFLAGS Flags such as @samp{-s} and @samp{-k} are passed automatically to the sub-@code{make} through the variable @code{MAKEFLAGS}. This variable is set up automatically by @code{make} to contain the flag letters that @code{make} received. Thus, if you do @w{@samp{make -ks}} then @code{MAKEFLAGS} gets the value @samp{ks}. As a consequence, every sub-@code{make} gets a value for @code{MAKEFLAGS} in its environment. In response, it takes the flags from that value and processes them as if they had been given as arguments. @xref{Options Summary, ,Summary of Options}. This means that, unlike other environment variables, @code{MAKEFLAGS} specified in the environment take precedence over @code{MAKEFLAGS} specified in the makefile. The value of @code{MAKEFLAGS} is a possibly empty group of characters representing single-letter options that take no argument, followed by a space and any options that take arguments or which have long option names. If an option has both single-letter and long options, the single-letter option is always preferred. If there are no single-letter options on the command line, then the value of @code{MAKEFLAGS} starts with a space. @cindex command line variable definitions, and recursion @cindex variables, command line, and recursion @cindex recursion, and command line variable definitions Likewise variables defined on the command line are passed to the sub-@code{make} through @code{MAKEFLAGS}. Words in the value of @code{MAKEFLAGS} that contain @samp{=}, @code{make} treats as variable definitions just as if they appeared on the command line. @xref{Overriding, ,Overriding Variables}. @cindex @code{-C}, and recursion @cindex @code{-f}, and recursion @cindex @code{-o}, and recursion @cindex @code{-W}, and recursion @cindex @code{--directory}, and recursion @cindex @code{--file}, and recursion @cindex @code{--old-file}, and recursion @cindex @code{--assume-old}, and recursion @cindex @code{--assume-new}, and recursion @cindex @code{--new-file}, and recursion @cindex recursion, and @code{-C} @cindex recursion, and @code{-f} @cindex recursion, and @code{-o} @cindex recursion, and @code{-W} The options @samp{-C}, @samp{-f}, @samp{-o}, and @samp{-W} are not put into @code{MAKEFLAGS}; these options are not passed down. @cindex @code{-j}, and recursion @cindex @code{--jobs}, and recursion @cindex recursion, and @code{-j} @cindex job slots, and recursion The @samp{-j} option is a special case (@pxref{Parallel, ,Parallel Execution}). If you set it to some numeric value @samp{N} and your operating system supports it (most any UNIX system will; others typically won't), the parent @code{make} and all the sub-@code{make}s will communicate to ensure that there are only @samp{N} jobs running at the same time between them all. Note that any job that is marked recursive (@pxref{Instead of Execution, ,Instead of Executing Recipes}) doesn't count against the total jobs (otherwise we could get @samp{N} sub-@code{make}s running and have no slots left over for any real work!) If your operating system doesn't support the above communication, then no @samp{-j} is added to @code{MAKEFLAGS}, so that sub-@code{make}s run in non-parallel mode. If the @w{@samp{-j}} option were passed down to sub-@code{make}s you would get many more jobs running in parallel than you asked for. If you give @samp{-j} with no numeric argument, meaning to run as many jobs as possible in parallel, this is passed down, since multiple infinities are no more than one. If you do not want to pass the other flags down, you must change the value of @code{MAKEFLAGS}, for example like this: @example subsystem: cd subdir && $(MAKE) MAKEFLAGS= @end example @vindex MAKEOVERRIDES The command line variable definitions really appear in the variable @code{MAKEOVERRIDES}, and @code{MAKEFLAGS} contains a reference to this variable. If you do want to pass flags down normally, but don't want to pass down the command line variable definitions, you can reset @code{MAKEOVERRIDES} to empty, like this: @example MAKEOVERRIDES = @end example @noindent @cindex Arg list too long @cindex E2BIG This is not usually useful to do. However, some systems have a small fixed limit on the size of the environment, and putting so much information into the value of @code{MAKEFLAGS} can exceed it. If you see the error message @samp{Arg list too long}, this may be the problem. (For strict compliance with POSIX, changing @code{MAKEOVERRIDES} does not affect @code{MAKEFLAGS} if the special target @samp{.POSIX} appears in the makefile. You probably do not care about this.) @vindex MFLAGS A similar variable @code{MFLAGS} exists also, for historical compatibility. It has the same value as @code{MAKEFLAGS} except that it does not contain the command line variable definitions, and it always begins with a hyphen unless it is empty (@code{MAKEFLAGS} begins with a hyphen only when it begins with an option that has no single-letter version, such as @samp{--no-print-directory}). @code{MFLAGS} was traditionally used explicitly in the recursive @code{make} command, like this: @example subsystem: cd subdir && $(MAKE) $(MFLAGS) @end example @noindent but now @code{MAKEFLAGS} makes this usage redundant. If you want your makefiles to be compatible with old @code{make} programs, use this technique; it will work fine with more modern @code{make} versions too. @cindex setting options from environment @cindex options, setting from environment @cindex setting options in makefiles @cindex options, setting in makefiles The @code{MAKEFLAGS} variable can also be useful if you want to have certain options, such as @samp{-k} (@pxref{Options Summary, ,Summary of Options}), set each time you run @code{make}. You simply put a value for @code{MAKEFLAGS} in your environment. You can also set @code{MAKEFLAGS} in a makefile, to specify additional flags that should also be in effect for that makefile. (Note that you cannot use @code{MFLAGS} this way. That variable is set only for compatibility; @code{make} does not interpret a value you set for it in any way.) When @code{make} interprets the value of @code{MAKEFLAGS} (either from the environment or from a makefile), it first prepends a hyphen if the value does not already begin with one. Then it chops the value into words separated by blanks, and parses these words as if they were options given on the command line (except that @samp{-C}, @samp{-f}, @samp{-h}, @samp{-o}, @samp{-W}, and their long-named versions are ignored; and there is no error for an invalid option). If you do put @code{MAKEFLAGS} in your environment, you should be sure not to include any options that will drastically affect the actions of @code{make} and undermine the purpose of makefiles and of @code{make} itself. For instance, the @samp{-t}, @samp{-n}, and @samp{-q} options, if put in one of these variables, could have disastrous consequences and would certainly have at least surprising and probably annoying effects. If you'd like to run other implementations of @code{make} in addition to GNU @code{make}, and hence do not want to add GNU @code{make}-specific flags to the @code{MAKEFLAGS} variable, you can add them to the @code{GNUMAKEFLAGS} variable instead. This variable is parsed just before @code{MAKEFLAGS}, in the same way as @code{MAKEFLAGS}. When @code{make} constructs @code{MAKEFLAGS} to pass to a recursive @code{make} it will include all flags, even those taken from @code{GNUMAKEFLAGS}. As a result, after parsing @code{GNUMAKEFLAGS} GNU @code{make} sets this variable to the empty string to avoid duplicating flags during recursion. It's best to use @code{GNUMAKEFLAGS} only with flags which won't materially change the behavior of your makefiles. If your makefiles require GNU Make anyway then simply use @code{MAKEFLAGS}. Flags such as @samp{--no-print-directory} or @samp{--output-sync} may be appropriate for @code{GNUMAKEFLAGS}. @node -w Option @subsection The @samp{--print-directory} Option @cindex directories, printing them @cindex printing directories @cindex recursion, and printing directories If you use several levels of recursive @code{make} invocations, the @samp{-w} or @w{@samp{--print-directory}} option can make the output a lot easier to understand by showing each directory as @code{make} starts processing it and as @code{make} finishes processing it. For example, if @samp{make -w} is run in the directory @file{/u/gnu/make}, @code{make} will print a line of the form: @example make: Entering directory `/u/gnu/make'. @end example @noindent before doing anything else, and a line of the form: @example make: Leaving directory `/u/gnu/make'. @end example @noindent when processing is completed. @cindex @code{-C}, and @code{-w} @cindex @code{--directory}, and @code{--print-directory} @cindex recursion, and @code{-w} @cindex @code{-w}, and @code{-C} @cindex @code{-w}, and recursion @cindex @code{--print-directory}, and @code{--directory} @cindex @code{--print-directory}, and recursion @cindex @code{--no-print-directory} @cindex @code{--print-directory}, disabling @cindex @code{-w}, disabling Normally, you do not need to specify this option because @samp{make} does it for you: @samp{-w} is turned on automatically when you use the @samp{-C} option, and in sub-@code{make}s. @code{make} will not automatically turn on @samp{-w} if you also use @samp{-s}, which says to be silent, or if you use @samp{--no-print-directory} to explicitly disable it. @node Canned Recipes @section Defining Canned Recipes @cindex canned recipes @cindex recipes, canned @cindex sequences of commands @cindex commands, sequences of When the same sequence of commands is useful in making various targets, you can define it as a canned sequence with the @code{define} directive, and refer to the canned sequence from the recipes for those targets. The canned sequence is actually a variable, so the name must not conflict with other variable names. Here is an example of defining a canned recipe: @example define run-yacc = yacc $(firstword $^) mv y.tab.c $@@ endef @end example @cindex @code{yacc} @noindent Here @code{run-yacc} is the name of the variable being defined; @code{endef} marks the end of the definition; the lines in between are the commands. The @code{define} directive does not expand variable references and function calls in the canned sequence; the @samp{$} characters, parentheses, variable names, and so on, all become part of the value of the variable you are defining. @xref{Multi-Line, ,Defining Multi-Line Variables}, for a complete explanation of @code{define}. The first command in this example runs Yacc on the first prerequisite of whichever rule uses the canned sequence. The output file from Yacc is always named @file{y.tab.c}. The second command moves the output to the rule's target file name. To use the canned sequence, substitute the variable into the recipe of a rule. You can substitute it like any other variable (@pxref{Reference, ,Basics of Variable References}). Because variables defined by @code{define} are recursively expanded variables, all the variable references you wrote inside the @code{define} are expanded now. For example: @example foo.c : foo.y $(run-yacc) @end example @noindent @samp{foo.y} will be substituted for the variable @samp{$^} when it occurs in @code{run-yacc}'s value, and @samp{foo.c} for @samp{$@@}. This is a realistic example, but this particular one is not needed in practice because @code{make} has an implicit rule to figure out these commands based on the file names involved (@pxref{Implicit Rules, ,Using Implicit Rules}). @cindex @@, and @code{define} @cindex -, and @code{define} @cindex +, and @code{define} In recipe execution, each line of a canned sequence is treated just as if the line appeared on its own in the rule, preceded by a tab. In particular, @code{make} invokes a separate sub-shell for each line. You can use the special prefix characters that affect command lines (@samp{@@}, @samp{-}, and @samp{+}) on each line of a canned sequence. @xref{Recipes, ,Writing Recipes in Rules}. For example, using this canned sequence: @example define frobnicate = @@echo "frobnicating target $@@" frob-step-1 $< -o $@@-step-1 frob-step-2 $@@-step-1 -o $@@ endef @end example @noindent @code{make} will not echo the first line, the @code{echo} command. But it @emph{will} echo the following two recipe lines. On the other hand, prefix characters on the recipe line that refers to a canned sequence apply to every line in the sequence. So the rule: @example frob.out: frob.in @@$(frobnicate) @end example @noindent does not echo @emph{any} recipe lines. (@xref{Echoing, ,Recipe Echoing}, for a full explanation of @samp{@@}.) @node Empty Recipes @section Using Empty Recipes @cindex empty recipes @cindex recipes, empty It is sometimes useful to define recipes which do nothing. This is done simply by giving a recipe that consists of nothing but whitespace. For example: @example target: ; @end example @noindent defines an empty recipe for @file{target}. You could also use a line beginning with a recipe prefix character to define an empty recipe, but this would be confusing because such a line looks empty. @findex .DEFAULT@r{, and empty recipes} You may be wondering why you would want to define a recipe that does nothing. One reason this is useful is to prevent a target from getting implicit recipes (from implicit rules or the @code{.DEFAULT} special target; @pxref{Implicit Rules} and @pxref{Last Resort, ,Defining Last-Resort Default Rules}). Empty recipes can also be used to avoid errors for targets that will be created as a side-effect of another recipe: if the target does not exist the empty recipe ensures that @code{make} won't complain that it doesn't know how to build the target, and @code{make} will assume the target is out of date. You may be inclined to define empty recipes for targets that are not actual files, but only exist so that their prerequisites can be remade. However, this is not the best way to do that, because the prerequisites may not be remade properly if the target file actually does exist. @xref{Phony Targets, ,Phony Targets}, for a better way to do this. @node Using Variables @chapter How to Use Variables @cindex variable @cindex value A makefile @dfn{variable} is a name defined to represent a string of text, called the variable's @dfn{value}. (In some other versions of @code{make}, variables are called @dfn{macros}.) @cindex macro Variable values can contain lists of file names, options to pass to compilers, programs to run, directories to look in for source files, directories to write output in, or anything else you can imagine. There are two different ways, called @dfn{flavors}, that a variable can hold its value internally (@pxref{Flavors, The Two Flavors of Variables}). The flavor of the variable is specified by the assignment operator used when it is defined (@pxref{Setting, ,Setting Variables}). When a variable is @dfn{referenced} in targets, prerequisites, recipes, and other parts of the makefile (@pxref{Reference, ,Basics of Variable References}), the reference is replaced with the value of the variable. This is called @dfn{expanding} the variable (@pxref{Expanding, ,How Expansion Works}). A variable reference is not always expanded immediately as the makefile is parsed; expansion can be deferred until later depending on the context. @xref{Reading Makefiles, ,How @code{make} Reads a Makefile}. When a variable reference is expanded, the value it expands to is that of its most recent definition at the time of expansion. In other words, variables in @code{make} are @dfn{dynamically scoped}. @menu * Variable Naming:: Choosing names for variables. * Reference:: How to use the value of a variable. * Flavors:: Variables come in two flavors. * Expanding:: How text is expanded by @code{make}. * Values:: All the ways variables get their values. * Setting:: How to set a variable in the makefile. * Substitution Refs:: Substituting values in variable expansion. * Override Directive:: How to set a variable in the makefile even if the user has set it with a command argument. * Multi-Line:: An alternate way to set a variable to a multi-line string. * Undefine Directive:: How to undefine a variable so that it appears as if it was never set. * Environment:: Variable values can come from the environment. * Target-specific:: Variable values can be defined on a per-target basis. * Pattern-specific:: Target-specific variable values can be applied to a group of targets that match a pattern. * Suppressing Inheritance:: Suppress inheritance of variables. * Special Variables:: Variables with special meaning or behavior. @end menu @node Variable Naming @section Names of Variables @cindex names of variables @cindex variables, names of A variable name may be any sequence of characters not containing @samp{:}, @samp{#}, @samp{=}, or whitespace. Variable names are case-sensitive. For instance the names @samp{foo}, @samp{FOO}, and @samp{Foo} all refer to different variables. It is traditional to use upper case letters in variable names, but we recommend using lower case letters for variable names that serve internal purposes in the makefile, and reserving upper case for parameters that control implicit rules or for parameters that the user should override with command options. @xref{Overriding, ,Overriding Variables}. Although GNU Make allows most characters to be part of a variable name, shells generally only support variable names containing letters, numbers, and underscores. Consider this when defining variables that need to be exported to the shell. @xref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}. Variable names beginning with @samp{.} followed by uppercase letters are reserved by the POSIX standard. GNU Make reserves variable names beginning with @samp{.} and containing uppercase letters and non-alphabetic characters. These variables may be given special meaning in future versions of GNU Make. A few variables have names that are a single punctuation character or just a few characters. These are the @dfn{automatic variables}, and they have particular specialized uses. @xref{Automatic Variables}. @node Reference @section Basics of Variable References @cindex variables, how to reference @cindex reference to variables @cindex @code{$}, in variable reference @cindex dollar sign (@code{$}), in variable reference To reference a variable's value, write a dollar sign (@samp{$}) followed by the name of the variable in parentheses or braces: both @code{$(foo)} and @code{$@{foo@}} are references to the variable @samp{foo}. If the variable name consists of a single character then the parenthesis or braces can be omitted. Thus @code{$A} is a reference to the variable @samp{A}. We recommend using parenthesis or braces even for single-letter variable names to avoid confusion (e.g., @code{$foo} refers to the variable @samp{f} followed by the string @samp{oo} which may not be clear) unless omitting them gives significant readability improvements. One place where readability is often improved by omitting parentheses and braces is with automatic variables (@pxref{Automatic Variables}). This special behavior of @samp{$} is why you must write @samp{$$} to have the effect of a single dollar sign in a makefile. Variable references can be used in any context: targets, prerequisites, recipes, most directives, and new variable values. Here is an example of a common case, where a variable holds the names of all the object files in a program: @example @group objects = program.o foo.o utils.o program : $(objects) cc -o program $(objects) $(objects) : defs.h @end group @end example @menu * Computed Names:: Computing the name of a variable reference. @end menu @node Computed Names @subsection Computed Variable Names @cindex nested variable reference @cindex computed variable name @cindex variables, computed names @cindex variables, nested references @cindex variables, @samp{$} in name @cindex @code{$}, in variable name @cindex dollar sign (@code{$}), in variable name Most of the time static variable names are sufficient, but in more complex situations it can be extremely useful to dynamically construct variable names. This can be achieved by using a variable reference inside a reference to a variable. This is referred to as a @dfn{computed variable name} or a @dfn{nested variable reference}. For example, @example x = y y = z a := $($(x)) @end example @noindent defines the variable @samp{a} to have the value @code{z}, in this way: @code{make} first expands @code{$(x)} to the value @code{y}, which means @code{$($(x))} expands to @code{$(y)}, and @code{$(y)} expands to the string @code{z}. Thus the name of the variable to reference is not stated explicitly; it is computed by expansion of @samp{$(x)}. The previous example shows two levels of nesting, but any number of levels are possible. For example, here are three levels: @example x = y y = z z = u a := $($($(x))) @end example @noindent Here the innermost @code{$(x)} expands to @samp{y}, so @code{$($(x))} expands to @code{$(y)} which in turn expands to @samp{z}; now we have @code{$(z)}, which expands to @samp{u}. References to recursively-expanded variables within a variable name are re-expanded in the usual fashion. For example: @example x = $(y) y = z z = Hello a := $($(x)) @end example @noindent defines @samp{a} as @code{Hello}: @code{$($(x))} becomes @code{$($(y))} which becomes @code{$(z)} which becomes @samp{Hello}. Nested variable references can also contain modified references and function invocations (@pxref{Functions, ,Functions for Transforming Text}), just like any other reference. For example, using the @code{subst} function (@pxref{Text Functions, ,Functions for String Substitution and Analysis}): @example @group x = variable1 variable2 := Hello y = $(subst 1,2,$(x)) z = y a := $($($(z))) @end group @end example @noindent eventually defines @code{a} as @samp{Hello}. It is doubtful that anyone would ever want to write a nested reference as convoluted as this one, but it works: @code{$($($(z)))} expands to @code{$($(y))} which becomes @code{$($(subst 1,2,$(x)))}. This gets the value @samp{variable1} from @samp{x} and changes it by substitution to @samp{variable2}, so that the entire string becomes @code{$(variable2)}, a simple variable reference whose value is @samp{Hello}. A computed variable name need not consist entirely of a single variable reference. It can contain several variable references, as well as some invariant text. For example, @example @group a_dirs := dira dirb 1_dirs := dir1 dir2 @end group @group a_files := filea fileb 1_files := file1 file2 @end group @group ifeq "$(use_a)" "yes" a1 := a else a1 := 1 endif @end group @group ifeq "$(use_dirs)" "yes" df := dirs else df := files endif dirs := $($(a1)_$(df)) @end group @end example @noindent will give @samp{dirs} the same value as @samp{a_dirs}, @samp{1_dirs}, @samp{a_files} or @samp{1_files} depending on the settings of @samp{use_a} and @samp{use_dirs}. Computed variable names can also be used in substitution references: @example @group a_objects := a.o b.o c.o 1_objects := 1.o 2.o 3.o sources := $($(a1)_objects:.o=.c) @end group @end example @noindent defines @samp{sources} as either @samp{a.c b.c c.c} or @samp{1.c 2.c 3.c}, depending on the value of @samp{a1}. The only restriction on this sort of use of nested variable references is that they cannot specify part of the name of a function to be called. This is because the test for a recognized function name is done before the expansion of nested references. For example, @example @group ifdef do_sort func := sort else func := strip endif @end group @group bar := a d b g q c @end group @group foo := $($(func) $(bar)) @end group @end example @noindent attempts to give @samp{foo} the value of the variable @samp{sort a d b g q c} or @samp{strip a d b g q c}, rather than giving @samp{a d b g q c} as the argument to either the @samp{sort} or the @samp{strip} function. This restriction could be removed in the future if that change is shown to be a good idea. You can also use computed variable names in the left-hand side of a variable assignment, or in a @samp{define} directive, as in: @example dir = foo $(dir)_sources := $(wildcard $(dir)/*.c) define $(dir)_print = lpr $($(dir)_sources) endef @end example @noindent This example defines the variables @samp{dir}, @samp{foo_sources}, and @samp{foo_print}. Note that @dfn{nested variable references} are quite different from @dfn{recursively expanded variables} (@pxref{Flavors, ,The Two Flavors of Variables}), though both are used together in complex ways when doing makefile programming. @node Flavors @section The Two Flavors of Variables @cindex flavors of variables @cindex variables, flavors There are two different ways that a variable in GNU Make can behave when a reference is expanded; we call them the @dfn{flavors} of variables. The assignment operator used to set the variable's value (@pxref{Setting, , Setting Variables}) determines both the way in which the value is handled during assignment, and also the flavor of the variable's value after assignment. Although there are a number of different assignment operators, all variables will end up as one of the two flavors. @menu * Recursive Variables:: Recursive variables delay expansion. * Simple Variables:: Simple variables expand immediately. @end menu @node Recursive Variables @subsection Recursively Expanded Variable Assignment @cindex recursive variable expansion @cindex recursively expanded variables @cindex variables, recursively expanded The first flavor of variable is a @dfn{recursively expanded} variable. This is the standard type of variable supported by all versions of @code{make} and defined by POSIX. When a recursively expanded variable is expanded due to a variable reference, the value of the variable is also expanded. This is called @dfn{recursive expansion}. Consider this makefile: @example foo = $(bar) bar = $(ugh) ugh = Huh? all: ; @@echo $(foo) @end example After @code{make} parses this makefile the value of the variable @code{foo} will be the string @samp{$(bar)}, the value of the variable @code{bar} will be the string @samp{$(ugh)}, and the value of the variable @code{ugh} will be the string @samp{Huh?}. If you run @code{make} with this makefile, it will print @samp{Huh?}: the variable reference @samp{$(foo)} expands to @samp{$(bar)} which expands to @samp{$(ugh)} which finally expands to @samp{Huh?}. The big advantage of this flavor of variable is that it can refer to variables which have not been defined yet. This means: @example CFLAGS = $(include_dirs) -O include_dirs = -Ifoo -Ibar @end example @noindent will do what was intended, even though when @code{CFLAGS} was set the variable @samp{include_dirs} was not set yet: when @code{CFLAGS} is expanded in a recipe it will expand to the value of @code{include_dirs} at that time, yielding @samp{-Ifoo -Ibar -O}. This flavor also allows variables to contain references to automatic variables (@pxref{Automatic Variables}); since automatic variables are not set until a recipe is going to be run it would not work if the variable's value was expanded when the variable was assigned. There are also a number of disadvantages. The first one is that programmers are not used to this type of assignment and may be confused. In a makefile like this: @example @group CFLAGS = -g DEBUG_FLAGS = $(CFLAGS) CFLAGS = -O2 OPT_FLAGS = $(CFLAGS) @end group @end example @noindent when @code{DEBUG_FLAGS} and @code{OPT_FLAGS} are expanded later they will @emph{both} contain the value @samp{-O2}; each assignment to @code{CFLAGS} overwrites the previous assignment and whatever the last value was, will be seen when references to @samp{$(CFLAGS)} are expanded. Another disadvantage is that you cannot reference a variable in its own value; for instance this: @cindex loops in variable expansion @cindex variables, loops in expansion @example CFLAGS = $(CFLAGS) -O @end example @noindent will generate an error due to an infinite loop in the variable expansion. If you want to append to the end of the variable you can use the @samp{+=} assignment operator (@pxref{Appending Assignment, , Appending More Text to Variables}) to deal with this. The fact that a ``recursively expanded'' variable cannot contain a recursive reference to itself is one of those idiosyncratic proofs that naming is hard in computer science. A third disadvantage is that the value will be re-expanded every time the variable is referenced. If the expansion of that variable is expensive--for example if it contains functions (@pxref{Functions, ,Functions for Transforming Text}) which are expensive to execute--this can impact the performance of @code{make}. It may also cause functions like @code{wildcard} and @code{shell} to give unpredictable results since you cannot easily control when they are called, or how many times. @node Simple Variables @subsection Simply Expanded Variable Assignment To avoid the problems and inconveniences of recursively expanded variables, GNU Make provides another flavor of variable value: @dfn{simply expanded variables}. The value of a simply expanded variable is expanded only once, immediately when the variable is assigned in the makefile. All references to variables and functions in its value are resolved at the time the variable is assigned. When the variable is later expanded it is not re-expanded (thus it is not ``recursive''): the stored value is used verbatim as the result of the expansion. If we write the example from the previous section using simply expanded variables (note the use of @samp{:=} for assignment), we will get more traditional behavior: @example @group CFLAGS = -g DEBUG_FLAGS := $(CFLAGS) CFLAGS = -O2 OPT_FLAGS := $(CFLAGS) @end group @end example Now the value of @code{DEBUG_FLAGS} will be @samp{-g} while the value of @code{OPT_FLAGS} is @samp{-O2} as expected. Simply expanded variables simplify makefile programming because they work like variables in most other programming languages. They allow you to redefine a variable using its own value. And they make the use of functions more efficient since they are expanded only one time, not each time the variable is referenced. @node Expanding @section How Expansion Works @cindex expanding variables @cindex variables, expanding The process of @dfn{expanding} a string in @code{make} means, to replace each variable reference (@pxref{Reference, ,Basics of Variable References}) with the value of that variable. All text which is not part of a variable reference is preserved in the result. Expansion proceeds from @emph{right to left} and from @emph{inside out}. For example, given the following text: @example save the $(shell $(date)) for $(event) @end example @noindent the expansion would keep the static string @samp{save the } (starting from right to left), then expand the variable named @code{date} (going from inside out) and use the result as the argument to the GNU Make function @code{shell} (@pxref{Shell Function, ,The @code{shell} Function}). The output of that shell command is appended into the result of the expansion. Then the static string @samp{ for } is added, and finally the expansion of the variable @code{event}. The expansion of a variable that has not been defined is not an error: instead it silently expands to an empty string. This behavior is required by POSIX; however it can be controlled in GNU Make (@pxref{Warnings, ,Makefile Warnings}). Although expansion always proceeds in the same way, deciding @emph{when} text is expanded depends on the context in which it's used: often text is expanded as the makefile is parsed. In other situations the expansion is delayed (for example the text of a recipe is not expanded until the recipe is invoked). @xref{Reading Makefiles, ,How @code{make} Reads a Makefile}. Also, deciding how to interpret the value of a variable during expansion depends on the type of variable. @xref{Flavors, ,The Two Flavors of Variables}. @node Values @section How Variables Get Their Values @cindex variables, how they get their values @cindex value, how a variable gets it Variables can get values in several different ways: @itemize @bullet @item You can specify an overriding value on the command line when you run @code{make}. @xref{Overriding, ,Overriding Variables}. @item You can specify a value in the makefile, either with an assignment (@pxref{Setting, ,Setting Variables}) or with a verbatim definition (@pxref{Multi-Line, ,Defining Multi-Line Variables}). @item You can specify a short-lived value with the @code{let} function (@pxref{Let Function}) or with the @code{foreach} function (@pxref{Foreach Function}). @item Variables and their values in the environment when @code{make} is invoked are imported as @code{make} variables. @xref{Environment, ,Variables from the Environment}. @item Several variables are given new values for each rule that @code{make} invokes, before the recipe for that rule is expanded. @xref{Automatic Variables}. @item Several variables have default initial values. @xref{Implicit Variables, ,Variables Used by Implicit Rules}. @end itemize @node Setting @section Setting Variables @cindex setting variables @cindex variables, setting @cindex = @cindex := @cindex ::= A makefile variable is set by writing a line starting with the variable name followed by one of the assignment operators @code{=}, @code{:=}, @code{::=}, @code{:::=}, or @code{!=}. Whitespace can optionally come before the variable name, between the variable name and the operator, and after the operator but before the value, and is discarded. Whatever text follows becomes the value of the variable. For example: @example objects = main.o foo.o bar.o utils.o @end example @noindent defines a variable named @code{objects} to contain the value @samp{main.o foo.o bar.o utils.o}. The whitespace before and after the assignment operator is ignored. If there is ambiguity between the end of the variable name and the start of the assignment operator (@pxref{Setting, ,Setting Variables}), GNU Make always prefers the operator. For example: @example FOO?=bar @end example @noindent will always be parsed into the tokens @samp{FOO}, @samp{?=}, and @samp{bar}. On the other hand, this: @example FOO? = bar @end example @noindent will be parsed as @samp{FOO?}, @samp{=}, and @samp{bar}. For this reason, among others, it's a best practice to always add whitespace around operators when setting @code{make} variables. There is no limit on the length of the value of a variable, except the amount of memory on the computer. You can split the value of a variable into multiple physical lines, for readability, by adding backslashes (@pxref{Splitting Lines, ,Splitting Long Lines}). The assignment operator controls two things: first, how the value (the string after the operator) is handled when the variable is set, and second how the value is handled when the variable is expanded (i.e., its flavor: @pxref{Flavors, The Two Flavors of Variables}). The @samp{=} operator creates a @emph{recursively expanded} variable. The value of the variable @emph{is not} expanded when the variable is defined: the right hand side of the assignment operator is used verbatim as the value of the variable. The @samp{:=} and @samp{::=} operators create a @emph{simply expanded} variable. The value of the variable @emph{is} expanded when the variable is defined. These operators are interchangeable: @samp{:=} is specific to GNU Make while @samp{::=} has the same behavior and is specified by POSIX. The @samp{:::=} operator creates a @emph{recursively expanded} variable, like @samp{=}. The value of the variable @emph{is} expanded when the variable is defined, like @samp{:=} / @samp{::=}. After the expansion, the resulting value is @emph{escaped} by substituting each dollar sign in the value with two dollar signs (@samp{$$}). @xref{Immediate Assignment, ,Immediately Expanded Variable Assignment}. The shell assignment operator @samp{!=} creates a @emph{recursively expanded} variable. The value of the variable is obtained by passing the expanded right-hand side to the shell as a command, and collecting its output. @xref{Shell Assignment, Shell Variable Assignment}. Each of these assignment operators can also be prefixed with a question mark (@samp{?}) to make them @dfn{conditional}. The right-hand side is only considered if the variable is not yet set. If it is set, the value of the assignment is ignored. @xref{Conditional Assignment, ,Conditional Variable Assignment}. Finally, more text can be added to an already-set variable value using the appending assignment operator @samp{+=}. @xref{Appending Assignment, ,Appending More Text to Variables}. @menu * Immediate Assignment:: Recursive variables with immediate expansion. * Shell Assignment:: Assigning variables to shell output. * Conditional Assignment:: Assigning variables only if not yet defined. * Appending Assignment:: How to append to the value of a variable. * Whitespace in Values:: Leading and trailing whitespace in values. @end menu @node Immediate Assignment @subsection Immediately Expanded Variable Assignment @cindex immediate variable assignment @cindex variables, immediate assignment @cindex :::= The @samp{:::=} assignment operator allows for immediate expansion, but unlike simple assignment the resulting variable is recursive and will be re-expanded again on every use. In order to avoid unexpected results, after the value is immediately expanded it will automatically be quoted: all instances of @samp{$} in the value after expansion will be converted into @samp{$$}. This type of assignment uses the @samp{:::=} operator. For example, @example @group var = first OUT :::= $(var) var = second @end group @end example @noindent results in the @code{OUT} variable containing the text @samp{first}, while here: @example @group var = one$$two OUT :::= $(var) var = three @end group @end example @noindent results in the @code{OUT} variable containing the text @samp{one$$two}. The value is expanded when the variable is assigned, so the result is the expansion of the first value of @code{var}, @samp{one$two}; then the value is re-escaped before the assignment is complete giving the final result of @samp{one$$two}. This is generally equivalent to the GNU Make @samp{:=} / @samp{::=} assignment operators, but there are a few differences: First, since the variable is a recursive variable when appending to it with the @samp{+=} operator the value on the right-hand side is not expanded immediately as it would be using @samp{:=} / @samp{::=}. Second, expansion of these variables is slightly less efficient since they will be re-expanded when they are referenced. However since all dollar signs are escaped the expansion simply un-escapes the value, it won't expand any variables or run any functions. Here is another example: @example @group var = one$$two OUT :::= $(var) OUT += $(var) var = three$$four @end group @end example After this, the value of @code{OUT} is the text @samp{one$$two $(var)}. When this variable is used it will be expanded and the result will be @samp{one$two three$four}. This style of assignment is equivalent to the traditional BSD @code{make} @samp{:=} assignment operator, and different from GNU Make's @samp{:=} assignment operator. The @samp{:::=} assignment operator was added to POSIX to provide portability. @node Shell Assignment @subsection Shell Variable Assignment @cindex shell variable assignment @cindex variables, shell assignment @cindex != The shell assignment operator @samp{!=} creates a @emph{recursively expanded} variable. The value of the variable is computed by first expanding the right-hand side of the assignment then invoking a shell and passing the expanded value to the shell as a script to run. The output generated by the shell (to standard out) is used as the value of the variable. If the last character of output is a newline, that character is removed; all other newlines are replaced by spaces. For example: @example hash != printf '\043' file_list != find . -name '*.c' @end example Because the variable is recursively expanded you must take care to ensure that, if the shell script outputs dollar signs which you don't want to be expanded by @code{make} when the variable is expanded, you escape them with two dollar signs. The @samp{!=} operator is portable to some other versions of @code{make} and is defined in the latest POSIX specifications. Alternatively, you can set a simply expanded variable to the result of running a program using the @code{shell} function call. @xref{Shell Function, , The @code{shell} Function}. For example: @example hash := $(shell printf '\043') var := $(shell find . -name "*.c") @end example As with the @code{shell} function, the exit status of the just-invoked shell script is stored in the @code{.SHELLSTATUS} variable when assigning with @samp{!=}. @node Conditional Assignment @subsection Conditional Variable Assignment @cindex conditional variable assignment @cindex variables, conditional assignment @cindex ?= @cindex ?:= @cindex ?::= @cindex ?:::= @cindex ?!= Any non-appending assignment operator (@samp{=}, @samp{:=}, @samp{::=}, @samp{:::=}, @samp{!=}) can be prefixed with a conditional modifier, @samp{?}. When this modifier is used, the assignment will proceed normally according to the base assignment operator, @emph{only if} the variable is not already defined. If the variable is already defined, the assignment is ignored and the right-hand side (value) of the assignment is not processed. For example this statement: @example FOO ?= bar @end example @noindent is equivalent to this (@pxref{Origin Function, ,The @code{origin} Function}): @example ifeq ($(origin FOO), undefined) FOO = bar endif @end example More generally a statement of the form: @example NAME ? VALUE @end example will do nothing if the variable @code{NAME} is defined, and will perform the operation @samp{NAME VALUE} for any assignment operation @samp{} if @code{NAME} is not defined. Note that a variable set to an empty value is still considered to be defined, so assignments modified with @samp{?} will not set that variable. @node Appending Assignment @subsection Appending More Text to Variables @cindex += @cindex appending to variables @cindex variables, appending to Often it is useful to add more text to the value of a variable already defined. You do this with a line containing @samp{+=}, like this: @example objects += another.o @end example @noindent This takes the value of the variable @code{objects}, and adds the text @samp{another.o} to it (preceded by a single space, if it has a value already). Thus: @example objects = main.o foo.o bar.o utils.o objects += another.o @end example @noindent sets @code{objects} to @samp{main.o foo.o bar.o utils.o another.o}. Using @samp{+=} is similar to: @example objects = main.o foo.o bar.o utils.o objects := $(objects) another.o @end example @noindent but differs in ways that become important when you use more complex values. When the variable in question has not been defined before, @samp{+=} acts just like normal @samp{=}: it defines a recursively-expanded variable. However, when there @emph{is} a previous definition, exactly what @samp{+=} does depends on what flavor of variable you defined originally. @xref{Flavors, ,The Two Flavors of Variables}, for an explanation of the two flavors of variables. When you add to a variable's value with @samp{+=}, @code{make} acts essentially as if you had included the extra text in the initial definition of the variable. If you defined it first with @samp{:=} or @samp{::=}, making it a simply-expanded variable, @samp{+=} adds to that simply-expanded definition, and expands the new text before appending it to the old value just as @samp{:=} does (see @ref{Setting, ,Setting Variables}, for a full explanation of @samp{:=} or @samp{::=}). In fact, @example variable := value variable += more @end example @noindent is exactly equivalent to: @noindent @example variable := value variable := $(variable) more @end example On the other hand, when you use @samp{+=} with a variable that you defined first to be recursively-expanded using plain @samp{=} or @samp{:::=}, @code{make} appends the un-expanded text to the existing value, whatever it is. This means that @example @group variable = value variable += more @end group @end example @noindent is roughly equivalent to: @example @group temp = value variable = $(temp) more @end group @end example @noindent except that of course it never defines a variable called @code{temp}. The importance of this comes when the variable's old value contains variable references. Take this common example: @example CFLAGS = $(includes) -O @dots{} CFLAGS += -pg # enable profiling @end example @noindent The first line defines the @code{CFLAGS} variable with a reference to another variable, @code{includes}. (@code{CFLAGS} is used by the rules for C compilation; @pxref{Catalogue of Rules, ,Catalogue of Built-In Rules}.) Using @samp{=} for the definition makes @code{CFLAGS} a recursively-expanded variable, meaning @w{@samp{$(includes) -O}} is @emph{not} expanded when @code{make} processes the definition of @code{CFLAGS}. Thus, @code{includes} need not be defined yet for its value to take effect. It only has to be defined before any reference to @code{CFLAGS}. If we tried to append to the value of @code{CFLAGS} without using @samp{+=}, we might do it like this: @example CFLAGS := $(CFLAGS) -pg # enable profiling @end example @noindent This is pretty close, but not quite what we want. Using @samp{:=} redefines @code{CFLAGS} as a simply-expanded variable; this means @code{make} expands the text @w{@samp{$(CFLAGS) -pg}} before setting the variable. If @code{includes} is not yet defined, we get @w{@samp{ -O -pg}}, and a later definition of @code{includes} will have no effect. Conversely, by using @samp{+=} we set @code{CFLAGS} to the @emph{unexpanded} value @w{@samp{$(includes) -O -pg}}. Thus we preserve the reference to @code{includes}, so if that variable gets defined at any later point, a reference like @samp{$(CFLAGS)} still uses its value. @node Whitespace in Values @subsection Whitespace in Variable Values @cindex spaces, in variable values @cindex whitespace, in variable values @cindex variables, spaces in values As described above, leading whitespace (whitespace between the assignment operator and the first non-whitespace character of the value) is discarded. All whitespace after this is preserved, @emph{including} trailing spaces. Unwanted trailing whitespace can cause your makefile to behave in unexpected ways: consider a variable reference such as @samp{$(dir)/file.c} if the variable @samp{dir} had an unexpected trailing space in its value. If your text editor has settings to automatically strip all trailing spaces from files when they are saved, or to make trailing whitespace visible somehow, it's a good idea to enable these facilities for makefiles. You may occasionally need to define a variable value that begins with whitespace. To force whitespace at the beginning of a value you can use a variable reference that expands to the empty string. For example: @example @group emptystring := space := $(emptystring) $(emptystring) @end group @end example The space between the assignment operator and the variable reference @samp{$(emptystring)} will be discarded, then the rest of the string is expanded. The @samp{emptystring} variables expand to no text, leaving just the space as the value. The second reference to @samp{$(emptystring)} is used to avoid having the trailing space stripped by editors and to make the intent simpler to understand. You don't have to use a second variable reference; you could also use a comment such as: @example @group emptystring := space := $(emptystring) #<-one space @end group @end example @noindent to achieve the same effect. Conversely, if you do @emph{not} want any whitespace at the end of the variable value you must not put whitespace plus a comment on the end of the variable value, such as this: @example dir := /foo/bar # directory to put the frobs in @end example @noindent Here the value of the variable @code{dir} is @w{@samp{/foo/bar }} (with four trailing spaces), which was probably not the intention. For this reason adding comments to the end of variable assignment lines is discouraged in makefiles, and using preceding comment lines is preferred; for example: @example @group # directory to put the frobs in dir := /foo/bar @end group @end example Another option is to make extensive use of the @code{strip} function (@pxref{Text Functions}) to ensure variable expansions have no leading or trailing whitespace. @node Substitution Refs @section Substitution References @cindex modified variable reference @cindex substitution variable reference @cindex variables, modified reference @cindex variables, substitution reference @cindex variables, substituting suffix in @cindex suffix, substituting in variables A @dfn{substitution reference} substitutes the value of a variable with alterations that you specify. It has the form @samp{$(@var{var}:@var{a}=@var{b})} (or @samp{$@{@var{var}:@var{a}=@var{b}@}}) and its meaning is to take the value of the variable @var{var}, replace every @var{a} at the end of a word with @var{b} in that value, and substitute the resulting string. When we say ``at the end of a word'', we mean that @var{a} must appear either followed by whitespace or at the end of the value in order to be replaced; other occurrences of @var{a} in the value are unaltered. For example: @example foo := a.o b.o l.a c.o bar := $(foo:.o=.c) @end example @noindent sets @samp{bar} to @samp{a.c b.c l.a c.c}. @xref{Setting, ,Setting Variables}. A substitution reference is shorthand for the @code{patsubst} expansion function (@pxref{Text Functions, ,Functions for String Substitution and Analysis}): @samp{$(@var{var}:@var{a}=@var{b})} is equivalent to @samp{$(patsubst %@var{a},%@var{b},@var{var})}. We provide substitution references as well as @code{patsubst} for compatibility with other implementations of @code{make}. Another type of substitution reference lets you use the full power of the @code{patsubst} function. It has the same form @samp{$(@var{var}:@var{a}=@var{b})} described above, except that now @var{a} must contain a single @samp{%} character. This case is equivalent to @samp{$(patsubst @var{a},@var{b},$(@var{var}))}. @xref{Text Functions, ,Functions for String Substitution and Analysis}, for a description of the @code{patsubst} function. For example: @example @group foo := a.o b.o l.a c.o bar := $(foo:%.o=%.c) @end group @end example @noindent sets @samp{bar} to @samp{a.c b.c l.a c.c}. @node Override Directive @section The @code{override} Directive @findex override @cindex overriding with @code{override} @cindex variables, overriding If a variable has been set with a command argument (@pxref{Overriding, ,Overriding Variables}), then ordinary assignments in the makefile are ignored. If you want to set the variable in the makefile even though it was set with a command argument, you can use an @code{override} directive, which is a line that looks like this: @example override @var{variable} = @var{value} @end example @noindent or @example override @var{variable} := @var{value} @end example To append more text to a variable defined on the command line, use: @example override @var{variable} += @var{more text} @end example @noindent @xref{Appending Assignment, ,Appending More Text to Variables}. Variable assignments marked with the @code{override} flag have a higher priority than all other assignments, except another @code{override}. Subsequent assignments or appends to this variable which are not marked @code{override} will be ignored. The @code{override} directive was not invented for escalation in the war between makefiles and command arguments. It was invented so you can alter and add to values that the user specifies with command arguments. For example, suppose you always want the @samp{-g} switch when you run the C compiler, but you would like to allow the user to specify the other switches with a command argument just as usual. You could use this @code{override} directive: @example override CFLAGS += -g @end example You can also use @code{override} directives with @code{define} directives (@pxref{Multi-Line, , Defining Multi-Line Variables}). This is done as you might expect: @example override define foo = bar endef @end example @node Multi-Line @section Defining Multi-Line Variables @findex define @findex endef @cindex multi-line variable definition @cindex variables, multi-line @cindex verbatim variable definition @cindex defining variables verbatim @cindex variables, defining verbatim Another way to set the value of a variable is to use the @code{define} directive. This directive has an unusual syntax which allows newline characters to be included in the value, which is convenient for defining both canned sequences of commands (@pxref{Canned Recipes, ,Defining Canned Recipes}), and also sections of makefile syntax to use with @code{eval} (@pxref{Eval Function}). The @code{define} directive is followed on the same line by the name of the variable being defined and an (optional) assignment operator, and nothing more. The value to give the variable appears on the following lines. The end of the value is marked by a line containing just the word @code{endef}. Aside from this difference in syntax, @code{define} works just like any other variable definition. The variable name may contain function and variable references, which are expanded when the directive is read to find the actual variable name to use. The final newline before the @code{endef} is not included in the value; if you want your value to contain a trailing newline you must include a blank line. For example in order to define a variable that contains a newline character you must use @emph{two} empty lines, not one: @example define newline endef @end example You may omit the variable assignment operator if you prefer. If omitted, @code{make} assumes it to be @samp{=} and creates a recursively-expanded variable (@pxref{Flavors, ,The Two Flavors of Variables}). When using a @samp{+=} operator, the value is appended to the previous value as with any other append operation: with a single space separating the old and new values. You may nest @code{define} directives: @code{make} will keep track of nested directives and report an error if they are not all properly closed with @code{endef}. Note that lines beginning with the recipe prefix character are considered part of a recipe, so any @code{define} or @code{endef} strings appearing on such a line will not be considered @code{make} directives. @example define two-lines echo foo echo $(bar) endef @end example @need 800 When used in a recipe, the previous example is functionally equivalent to this: @example two-lines = echo foo; echo $(bar) @end example @noindent since two commands separated by semicolon behave much like two separate shell commands. However, note that using two separate lines means @code{make} will invoke the shell twice, running an independent sub-shell for each line. @xref{Execution, ,Recipe Execution}. If you want variable definitions made with @code{define} to take precedence over command-line variable definitions, you can use the @code{override} directive together with @code{define}: @example override define two-lines = foo $(bar) endef @end example @noindent @xref{Override Directive, ,The @code{override} Directive}. @node Undefine Directive @section Undefining Variables @findex undefine @cindex undefining variable If you want to clear a variable, setting its value to empty is usually sufficient. Expanding such a variable will yield the same result (empty string) regardless of whether it was set or not. However, if you are using the @code{flavor} (@pxref{Flavor Function}) and @code{origin} (@pxref{Origin Function}) functions, there is a difference between a variable that was never set and a variable with an empty value. In such situations you may want to use the @code{undefine} directive to make a variable appear as if it was never set. For example: @example @group foo := foo bar = bar undefine foo undefine bar $(info $(origin foo)) $(info $(flavor bar)) @end group @end example This example will print ``undefined'' for both variables. If you want to undefine a command-line variable definition, you can use the @code{override} directive together with @code{undefine}, similar to how this is done for variable definitions: @example override undefine CFLAGS @end example @node Environment @section Variables from the Environment @cindex variables, environment @cindex environment Variables in @code{make} can come from the environment in which @code{make} is run. Every environment variable that @code{make} sees when it starts up is transformed into a @code{make} variable with the same name and value. However, an explicit assignment in the makefile, or with a command argument, overrides the environment. (If the @samp{-e} flag is specified, then values from the environment override assignments in the makefile. @xref{Options Summary, ,Summary of Options}. But this is not recommended practice.) Thus, by setting the variable @code{CFLAGS} in your environment, you can cause all C compilations in most makefiles to use the compiler switches you prefer. This is safe for variables with standard or conventional meanings because you know that no makefile will use them for other things. (Note this is not totally reliable; some makefiles set @code{CFLAGS} explicitly and therefore are not affected by the value in the environment.) When @code{make} runs a recipe, some variables defined in the makefile are placed into the environment of each command @code{make} invokes. By default, only variables that came from the @code{make}'s environment or set on its command line are placed into the environment of the commands. You can use the @code{export} directive to pass other variables. @xref{Variables/Recursion, , Communicating Variables to a Sub-@code{make}}, for full details. Other use of variables from the environment is not recommended. It is not wise for makefiles to depend for their functioning on environment variables set up outside their control, since this would cause different users to get different results from the same makefile. This is against the whole purpose of most makefiles. @cindex SHELL, import from environment Such problems would be especially likely with the variable @code{SHELL}, which is normally present in the environment to specify the user's choice of interactive shell. It would be very undesirable for this choice to affect @code{make}; so, @code{make} handles the @code{SHELL} environment variable in a special way; see @ref{Choosing the Shell}. @node Target-specific @section Target-specific Variable Values @cindex target-specific variables @cindex variables, target-specific Variable values in @code{make} are usually global; that is, they are the same regardless of where they are evaluated (unless they're reset, of course). Exceptions to that are variables defined with the @code{let} function (@pxref{Let Function}) or the @code{foreach} function (@pxref{Foreach Function}, and automatic variables (@pxref{Automatic Variables}). Another exception are @dfn{target-specific variable values}. This feature allows you to define different values for the same variable, based on the target that @code{make} is currently building. As with automatic variables, these values are only available within the context of a target's recipe (and in other target-specific assignments). Set a target-specific variable value like this: @example @var{target} @dots{} : @var{variable-assignment} @end example Target-specific variable assignments can be prefixed with any or all of the special keywords @code{export}, @code{unexport}, @code{override}, or @code{private}; these apply their normal behavior to this instance of the variable only. Multiple @var{target} values create a target-specific variable value for each member of the target list individually. The @var{variable-assignment} can be any valid form of assignment; recursive (@samp{=}), simple (@samp{:=} or @samp{::=}), immediate (@samp{::=}), shell (@samp{!=}), or appending (@samp{+=}), and may be preceded by a conditional modifier (@samp{?}). The variable that appears within the @var{variable-assignment} is evaluated within the context of the target: thus, any previously-defined target-specific variable values will be in effect. Note that this variable is actually distinct from any ``global'' value: the two variables do not have to have the same flavor (recursive vs.@: simple). Target-specific variables have the same priority as any other makefile variable. Variables provided on the command line (and in the environment if the @samp{-e} option is in force) will take precedence. Specifying the @code{override} directive will allow the target-specific variable value to be preferred. There is one more special feature of target-specific variables: when you define a target-specific variable that variable value is also in effect for all prerequisites of this target, and all their prerequisites, etc.@: (unless those prerequisites override that variable with their own target-specific variable value). So, for example, a statement like this: @example prog : CFLAGS = -g prog : prog.o foo.o bar.o @end example @noindent will set @code{CFLAGS} to @samp{-g} in the recipe for @file{prog}, but it will also set @code{CFLAGS} to @samp{-g} in the recipes that create @file{prog.o}, @file{foo.o}, and @file{bar.o}, and any recipes which create their prerequisites. Be aware that a given prerequisite will only be built once per invocation of make, at most. If the same file is a prerequisite of multiple targets, and each of those targets has a different value for the same target-specific variable, then the first target to be built will cause that prerequisite to be built and the prerequisite will inherit the target-specific value from the first target. It will ignore the target-specific values from any other targets. @node Pattern-specific @section Pattern-specific Variable Values @cindex pattern-specific variables @cindex variables, pattern-specific In addition to target-specific variable values (@pxref{Target-specific, ,Target-specific Variable Values}), GNU @code{make} supports pattern-specific variable values. In this form, the variable is defined for any target that matches the pattern specified. Set a pattern-specific variable value like this: @example @var{pattern} @dots{} : @var{variable-assignment} @end example where @var{pattern} is a %-pattern. As with target-specific variable values, multiple @var{pattern} values create a pattern-specific variable value for each pattern individually. The @var{variable-assignment} can be any valid form of assignment. Any command line variable setting will take precedence, unless @code{override} is specified. For example: @example %.o : CFLAGS = -O @end example @noindent will assign @code{CFLAGS} the value of @samp{-O} for all targets matching the pattern @samp{%.o}. If a target matches more than one pattern, the matching pattern-specific variables with longer stems are interpreted first. This results in more specific variables taking precedence over the more generic ones, for example: @example %.o: %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@@ lib/%.o: CFLAGS := -fPIC -g %.o: CFLAGS := -g all: foo.o lib/bar.o @end example In this example the first definition of the @code{CFLAGS} variable will be used to update @file{lib/bar.o} even though the second one also applies to this target. Pattern-specific variables which result in the same stem length are considered in the order in which they were defined in the makefile. Pattern-specific variables are searched after any target-specific variables defined explicitly for that target, and before target-specific variables defined for the parent target. @node Suppressing Inheritance @section Suppressing Inheritance @findex private @cindex suppressing inheritance @cindex inheritance, suppressing As described in previous sections, @code{make} variables are inherited by prerequisites. This capability allows you to modify the behavior of a prerequisite based on which targets caused it to be rebuilt. For example, you might set a target-specific variable on a @code{debug} target, then running @samp{make debug} will cause that variable to be inherited by all prerequisites of @code{debug}, while just running @samp{make all} (for example) would not have that assignment. Sometimes, however, you may not want a variable to be inherited. For these situations, @code{make} provides the @code{private} modifier. Although this modifier can be used with any variable assignment, it makes the most sense with target- and pattern-specific variables. Any variable marked @code{private} will be visible to its local target but will not be inherited by prerequisites of that target. A global variable marked @code{private} will be visible in the global scope but will not be inherited by any target, and hence will not be visible in any recipe. As an example, consider this makefile: @example EXTRA_CFLAGS = prog: private EXTRA_CFLAGS = -L/usr/local/lib prog: a.o b.o @end example Due to the @code{private} modifier, @samp{a.o} and @samp{b.o} will not inherit the @code{EXTRA_CFLAGS} variable assignment from the @code{prog} target. @node Special Variables @comment node-name, next, previous, up @section Other Special Variables @cindex makefiles, and special variables @cindex special variables GNU @code{make} supports some variables that have special properties. @table @code @vindex MAKEFILE_LIST @cindex makefiles, and @code{MAKEFILE_LIST} variable @cindex including (@code{MAKEFILE_LIST} variable) @item MAKEFILE_LIST Contains the name of each makefile that is parsed by @code{make}, in the order in which it was parsed. The name is appended just before @code{make} begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile. Once the current makefile has used @code{include}, however, the last word will be the just-included makefile. If a makefile named @code{Makefile} has this content: @example @group name1 := $(lastword $(MAKEFILE_LIST)) include inc.mk name2 := $(lastword $(MAKEFILE_LIST)) all: @@echo name1 = $(name1) @@echo name2 = $(name2) @end group @end example @noindent then you would expect to see this output: @example @group name1 = Makefile name2 = inc.mk @end group @end example @vindex .DEFAULT_GOAL @item .DEFAULT_GOAL Sets the default goal to be used if no targets were specified on the command line (@pxref{Goals, , Arguments to Specify the Goals}). The @code{.DEFAULT_GOAL} variable allows you to discover the current default goal, restart the default goal selection algorithm by clearing its value, or to explicitly set the default goal. The following example illustrates these cases: @example @group # Query the default goal. ifeq ($(.DEFAULT_GOAL),) $(warning no default goal is set) endif .PHONY: foo foo: ; @@echo $@@ $(warning default goal is $(.DEFAULT_GOAL)) # Reset the default goal. .DEFAULT_GOAL := .PHONY: bar bar: ; @@echo $@@ $(warning default goal is $(.DEFAULT_GOAL)) # Set our own. .DEFAULT_GOAL := foo @end group @end example This makefile prints: @example @group no default goal is set default goal is foo default goal is bar foo @end group @end example Note that assigning more than one target name to @code{.DEFAULT_GOAL} is invalid and will result in an error. @vindex MAKE_RESTARTS @item MAKE_RESTARTS This variable is set only if this instance of @code{make} has restarted (@pxref{Remaking Makefiles, , How Makefiles Are Remade}): it will contain the number of times this instance has restarted. Note this is not the same as recursion (counted by the @code{MAKELEVEL} variable). You should not set, modify, or export this variable. @vindex MAKE_TERMOUT @vindex MAKE_TERMERR @item MAKE_TERMOUT @itemx MAKE_TERMERR When @code{make} starts it will check whether stdout and stderr will show their output on a terminal. If so, it will set @code{MAKE_TERMOUT} and @code{MAKE_TERMERR}, respectively, to the name of the terminal device (or @code{true} if this cannot be determined). If set these variables will be marked for export. These variables will not be changed by @code{make} and they will not be modified if already set. These values can be used (particularly in combination with output synchronization (@pxref{Parallel Output, ,Output During Parallel Execution}) to determine whether @code{make} itself is writing to a terminal; they can be tested to decide whether to force recipe commands to generate colorized output for example. If you invoke a sub-@code{make} and redirect its stdout or stderr it is your responsibility to reset or unexport these variables as well, if your makefiles rely on them. @vindex .RECIPEPREFIX @item .RECIPEPREFIX The first character of the value of this variable is used as the character make assumes is introducing a recipe line. If the variable is empty (as it is by default) that character is the standard tab character. For example, this is a valid makefile: @example @group .RECIPEPREFIX = > all: > @@echo Hello, world @end group @end example The value of @code{.RECIPEPREFIX} can be changed multiple times; once set it stays in effect for all rules parsed until it is modified. @vindex .VARIABLES @item .VARIABLES Expands to a list of the @emph{names} of all global variables defined so far. This includes variables which have empty values, as well as built-in variables (@pxref{Implicit Variables, , Variables Used by Implicit Rules}), but does not include any variables which are only defined in a target-specific context. Note that any value you assign to this variable will be ignored; it will always return its special value. @c @vindex .TARGETS @c @item .TARGETS @c The second special variable is @code{.TARGETS}. When expanded, the @c value consists of a list of all targets defined in all makefiles read @c up until that point. Note it's not enough for a file to be simply @c mentioned in the makefile to be listed in this variable, even if it @c would match an implicit rule and become an ``implicit target''. The @c file must appear as a target, on the left-hand side of a ``:'', to be @c considered a target for the purposes of this variable. @vindex .FEATURES @item .FEATURES Expands to a list of special features supported by this version of @code{make}. Possible values include, but are not limited to: @table @samp @item archives Supports @code{ar} (archive) files using special file name syntax. @xref{Archives, ,Using @code{make} to Update Archive Files}. @item check-symlink Supports the @code{-L} (@code{--check-symlink-times}) flag. @xref{Options Summary, ,Summary of Options}. @item else-if Supports ``else if'' non-nested conditionals. @xref{Conditional Syntax, ,Syntax of Conditionals}. @item extra-prereqs Supports the @code{.EXTRA_PREREQS} special target. @item grouped-target Supports grouped target syntax for explicit rules. @xref{Multiple Targets, ,Multiple Targets in a Rule}. @item guile Has GNU Guile available as an embedded extension language. @xref{Guile Integration, ,GNU Guile Integration}. @item jobserver Supports ``job server'' enhanced parallel builds. @xref{Parallel, ,Parallel Execution}. @item jobserver-fifo Supports ``job server'' enhanced parallel builds using named pipes. @xref{Integrating make, ,Integrating GNU @code{make}}. @item load Supports dynamically loadable objects for creating custom extensions. @xref{Loading Objects, ,Loading Dynamic Objects}. @item notintermediate Supports the @code{.NOTINTERMEDIATE} special target. @xref{Integrating make, ,Integrating GNU @code{make}}. @item oneshell Supports the @code{.ONESHELL} special target. @xref{One Shell, ,Using One Shell}. @item order-only Supports order-only prerequisites. @xref{Prerequisite Types, ,Types of Prerequisites}. @item output-sync Supports the @code{--output-sync} command line option. @xref{Options Summary, ,Summary of Options}. @item second-expansion Supports secondary expansion of prerequisite lists. @item shell-export Supports exporting @code{make} variables to @code{shell} functions. @item shortest-stem Uses the ``shortest stem'' method of choosing which pattern, of multiple applicable options, will be used. @xref{Pattern Match, ,How Patterns Match}. @item target-specific Supports target-specific and pattern-specific variable assignments. @xref{Target-specific, ,Target-specific Variable Values}. @item undefine Supports the @code{undefine} directive. @xref{Undefine Directive}. @end table @vindex .INCLUDE_DIRS @item .INCLUDE_DIRS Expands to a list of directories that @code{make} searches for included makefiles (@pxref{Include, , Including Other Makefiles}). Note that modifying this variable's value does not change the list of directories which are searched. @vindex .EXTRA_PREREQS @item .EXTRA_PREREQS Each word in this variable is a new prerequisite which is added to targets for which it is set. These prerequisites differ from normal prerequisites in that they do not appear in any of the automatic variables (@pxref{Automatic Variables}). This allows prerequisites to be defined which do not impact the recipe. Consider a rule to link a program: @example myprog: myprog.o file1.o file2.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@@ $^ $(LDLIBS) @end example Now suppose you want to enhance this makefile to ensure that updates to the compiler cause the program to be re-linked. You can add the compiler as a prerequisite, but you must ensure that it's not passed as an argument to link command. You'll need something like this: @example myprog: myprog.o file1.o file2.o $(CC) $(CC) $(CFLAGS) $(LDFLAGS) -o $@@ \ $(filter-out $(CC),$^) $(LDLIBS) @end example Then consider having multiple extra prerequisites: they would all have to be filtered out. Using @code{.EXTRA_PREREQS} and target-specific variables provides a simpler solution: @example myprog: myprog.o file1.o file2.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@@ $^ $(LDLIBS) myprog: .EXTRA_PREREQS = $(CC) @end example This feature can also be useful if you want to add prerequisites to a makefile you cannot easily modify: you can create a new file such as @file{extra.mk}: @example myprog: .EXTRA_PREREQS = $(CC) @end example then invoke @code{make -f extra.mk -f Makefile}. Setting @code{.EXTRA_PREREQS} globally will cause those prerequisites to be added to all targets (which did not themselves override it with a target-specific value). Note @code{make} is smart enough not to add a prerequisite listed in @code{.EXTRA_PREREQS} as a prerequisite to itself. @item .WARNINGS Changes the actions taken when @code{make} detects warning conditions in the makefile. @xref{Warnings, ,Makefile Warnings}. @end table @node Conditionals @chapter Conditional Parts of Makefiles @cindex conditionals A @dfn{conditional} directive causes part of a makefile to be obeyed or ignored depending on the values of variables. Conditionals can compare the value of one variable to another, or the value of a variable to a constant string. Conditionals control what @code{make} actually ``sees'' in the makefile, so they @emph{cannot} be used to control recipes at the time of execution. @menu * Conditional Example:: Example of a conditional * Conditional Syntax:: The syntax of conditionals. * Testing Flags:: Conditionals that test flags. @end menu @node Conditional Example @section Example of a Conditional The following example of a conditional tells @code{make} to use one set of libraries if the @code{CC} variable is @samp{gcc}, and a different set of libraries otherwise. It works by controlling which of two recipe lines will be used for the rule. The result is that @samp{CC=gcc} as an argument to @code{make} changes not only which compiler is used but also which libraries are linked. @example libs_for_gcc = -lgnu normal_libs = foo: $(objects) ifeq ($(CC),gcc) $(CC) -o foo $(objects) $(libs_for_gcc) else $(CC) -o foo $(objects) $(normal_libs) endif @end example This conditional uses three directives: one @code{ifeq}, one @code{else} and one @code{endif}. The @code{ifeq} directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared. The lines of the makefile following the @code{ifeq} are obeyed if the two arguments match; otherwise they are ignored. The @code{else} directive causes the following lines to be obeyed if the previous conditional failed. In the example above, this means that the second alternative linking command is used whenever the first alternative is not used. It is optional to have an @code{else} in a conditional. The @code{endif} directive ends the conditional. Every conditional must end with an @code{endif}. Unconditional makefile text follows. As this example illustrates, conditionals work at the textual level: the lines of the conditional are treated as part of the makefile, or ignored, according to the condition. This is why the larger syntactic units of the makefile, such as rules, may cross the beginning or the end of the conditional. When the variable @code{CC} has the value @samp{gcc}, the above example has this effect: @example foo: $(objects) $(CC) -o foo $(objects) $(libs_for_gcc) @end example @noindent When the variable @code{CC} has any other value, the effect is this: @example foo: $(objects) $(CC) -o foo $(objects) $(normal_libs) @end example Equivalent results can be obtained in another way by conditionally assigning a variable and then using the variable unconditionally: @example libs_for_gcc = -lgnu normal_libs = ifeq ($(CC),gcc) libs = $(libs_for_gcc) else libs = $(normal_libs) endif foo: $(objects) $(CC) -o foo $(objects) $(libs) @end example @node Conditional Syntax @section Syntax of Conditionals @findex ifdef @findex ifeq @findex ifndef @findex ifneq @findex else @findex endif The syntax of a simple conditional with no @code{else} is as follows: @example @var{conditional-directive} @var{text-if-true} endif @end example @noindent The @var{text-if-true} may be any lines of text, to be considered as part of the makefile if the condition is true. If the condition is false, no text is used instead. The syntax of a complex conditional is as follows: @example @var{conditional-directive} @var{text-if-true} else @var{text-if-false} endif @end example or: @example @var{conditional-directive-one} @var{text-if-one-is-true} else @var{conditional-directive-two} @var{text-if-two-is-true} else @var{text-if-one-and-two-are-false} endif @end example @noindent There can be as many ``@code{else} @var{conditional-directive}'' clauses as necessary. Once a given condition is true, @var{text-if-true} is used and no other clause is used; if no condition is true then @var{text-if-false} is used. The @var{text-if-true} and @var{text-if-false} can be any number of lines of text. The syntax of the @var{conditional-directive} is the same whether the conditional is simple or complex; after an @code{else} or not. There are four different directives that test different conditions. Here is a table of them: @table @code @item ifeq (@var{arg1}, @var{arg2}) @itemx ifeq '@var{arg1}' '@var{arg2}' @itemx ifeq "@var{arg1}" "@var{arg2}" @itemx ifeq "@var{arg1}" '@var{arg2}' @itemx ifeq '@var{arg1}' "@var{arg2}" Expand all variable references in @var{arg1} and @var{arg2} and compare them. If they are identical, the @var{text-if-true} is effective; otherwise, the @var{text-if-false}, if any, is effective. Often you want to test if a variable has a non-empty value. When the value results from complex expansions of variables and functions, expansions you would consider empty may actually contain whitespace characters and thus are not seen as empty. However, you can use the @code{strip} function (@pxref{Text Functions}) to avoid interpreting whitespace as a non-empty value. For example: @example @group ifeq ($(strip $(foo)),) @var{text-if-empty} endif @end group @end example @noindent will evaluate @var{text-if-empty} even if the expansion of @code{$(foo)} contains whitespace characters. @item ifneq (@var{arg1}, @var{arg2}) @itemx ifneq '@var{arg1}' '@var{arg2}' @itemx ifneq "@var{arg1}" "@var{arg2}" @itemx ifneq "@var{arg1}" '@var{arg2}' @itemx ifneq '@var{arg1}' "@var{arg2}" Expand all variable references in @var{arg1} and @var{arg2} and compare them. If they are different, the @var{text-if-true} is effective; otherwise, the @var{text-if-false}, if any, is effective. @item ifdef @var{variable-name} The @code{ifdef} form takes the @emph{name} of a variable as its argument, not a reference to a variable. If the value of that variable has a non-empty value, the @var{text-if-true} is effective; otherwise, the @var{text-if-false}, if any, is effective. Variables that have never been defined have an empty value. The text @var{variable-name} is expanded, so it could be a variable or function that expands to the name of a variable. For example: @example bar = true foo = bar ifdef $(foo) frobozz = yes endif @end example The variable reference @code{$(foo)} is expanded, yielding @code{bar}, which is considered to be the name of a variable. The variable @code{bar} is not expanded, but its value is examined to determine if it is non-empty. Note that @code{ifdef} only tests whether a variable has a value. It does not expand the variable to see if that value is nonempty. Consequently, tests using @code{ifdef} return true for all definitions except those like @code{foo =}. To test for an empty value, use @w{@code{ifeq ($(foo),)}}. For example, @example bar = foo = $(bar) ifdef foo frobozz = yes else frobozz = no endif @end example @noindent sets @samp{frobozz} to @samp{yes}, while: @example foo = ifdef foo frobozz = yes else frobozz = no endif @end example @noindent sets @samp{frobozz} to @samp{no}. @item ifndef @var{variable-name} If the variable @var{variable-name} has an empty value, the @var{text-if-true} is effective; otherwise, the @var{text-if-false}, if any, is effective. The rules for expansion and testing of @var{variable-name} are identical to the @code{ifdef} directive. @end table Extra spaces are allowed and ignored at the beginning of the conditional directive line, but a tab is not allowed. (If the line begins with a tab, it will be considered part of a recipe for a rule.) Aside from this, extra spaces or tabs may be inserted with no effect anywhere except within the directive name or within an argument. A comment starting with @samp{#} may appear at the end of the line. The other two directives that play a part in a conditional are @code{else} and @code{endif}. Each of these directives is written as one word, with no arguments. Extra spaces are allowed and ignored at the beginning of the line, and spaces or tabs at the end. A comment starting with @samp{#} may appear at the end of the line. Conditionals affect which lines of the makefile @code{make} uses. If the condition is true, @code{make} reads the lines of the @var{text-if-true} as part of the makefile; if the condition is false, @code{make} ignores those lines completely. It follows that syntactic units of the makefile, such as rules, may safely be split across the beginning or the end of the conditional. @code{make} evaluates conditionals when it reads a makefile. Consequently, you cannot use automatic variables in the tests of conditionals because they are not defined until recipes are run (@pxref{Automatic Variables}). To prevent intolerable confusion, it is not permitted to start a conditional in one makefile and end it in another. However, you may write an @code{include} directive within a conditional, provided you do not attempt to terminate the conditional inside the included file. @node Testing Flags @section Conditionals that Test Flags You can write a conditional that tests @code{make} command flags such as @samp{-t} by using the variable @code{MAKEFLAGS} together with the @code{findstring} function (@pxref{Text Functions, , Functions for String Substitution and Analysis}). This is useful when @code{touch} is not enough to make a file appear up to date. Recall that @code{MAKEFLAGS} will put all single-letter options (such as @samp{-t}) into the first word, and that word will be empty if no single-letter options were given. To work with this, it's helpful to add a value at the start to ensure there's a word: for example @samp{-$(MAKEFLAGS)}. The @code{findstring} function determines whether one string appears as a substring of another. If you want to test for the @samp{-t} flag, use @samp{t} as the first string and the first word of @code{MAKEFLAGS} as the other. For example, here is how to arrange to use @samp{ranlib -t} to finish marking an archive file up to date: @example archive.a: @dots{} ifneq (,$(findstring t,$(firstword -$(MAKEFLAGS)))) +touch archive.a +ranlib -t archive.a else ranlib archive.a endif @end example @noindent The @samp{+} prefix marks those recipe lines as ``recursive'' so that they will be executed despite use of the @samp{-t} flag. @xref{Recursion, ,Recursive Use of @code{make}}. @node Functions @chapter Functions for Transforming Text @cindex functions @dfn{Functions} allow you to do text processing in the makefile to compute the files to operate on or the commands to use in recipes. You use a function in a @dfn{function call}, where you give the name of the function and some text (the @dfn{arguments}) for the function to operate on. The result of the function's processing is substituted into the makefile at the point of the call, just as a variable might be substituted. @menu * Syntax of Functions:: How to write a function call. * Text Functions:: General-purpose text manipulation functions. * File Name Functions:: Functions for manipulating file names. * Conditional Functions:: Functions that implement conditions. * Let Function:: Local variables. * Foreach Function:: Repeat some text with controlled variation. * File Function:: Write text to a file. * Call Function:: Expand a user-defined function. * Value Function:: Return the un-expanded value of a variable. * Eval Function:: Evaluate the arguments as makefile syntax. * Origin Function:: Find where a variable got its value. * Flavor Function:: Find out the flavor of a variable. * Make Control Functions:: Functions that control how make runs. * Shell Function:: Substitute the output of a shell command. * Guile Function:: Use GNU Guile embedded scripting language. @end menu @node Syntax of Functions @section Function Call Syntax @cindex @code{$}, in function call @cindex dollar sign (@code{$}), in function call @cindex arguments of functions @cindex functions, syntax of A function call resembles a variable reference. It can appear anywhere a variable reference can appear, and it is expanded using the same rules as variable references. A function call looks like this: @example $(@var{function} @var{arguments}) @end example @noindent or like this: @example $@{@var{function} @var{arguments}@} @end example Here @var{function} is a function name; one of a short list of names that are part of @code{make}. You can also essentially create your own functions by using the @code{call} built-in function. The @var{arguments} are the arguments of the function. They are separated from the function name by one or more spaces or tabs, and if there is more than one argument, then they are separated by commas. Such whitespace and commas are not part of an argument's value. The delimiters which you use to surround the function call, whether parentheses or braces, can appear in an argument only in matching pairs; the other kind of delimiters may appear singly. If the arguments themselves contain other function calls or variable references, it is wisest to use the same kind of delimiters for all the references; write @w{@samp{$(subst a,b,$(x))}}, not @w{@samp{$(subst a,b,$@{x@})}}. This is because it is clearer, and because only one type of delimiter is matched to find the end of the reference. Each argument is expanded before the function is invoked, unless otherwise noted below. The substitution is done in the order in which the arguments appear. @subsubheading Special Characters @cindex special characters in function arguments @cindex function arguments, special characters in When using characters that are special to @code{make} as function arguments, you may need to hide them. GNU @code{make} doesn't support escaping characters with backslashes or other escape sequences; however, because arguments are split before they are expanded you can hide them by putting them into variables. Characters you may need to hide include: @itemize @bullet @item Commas @item Initial whitespace in the first argument @item Unmatched open parenthesis or brace @item An open parenthesis or brace if you don't want it to start a matched pair @end itemize For example, you can define variables @code{comma} and @code{space} whose values are isolated comma and space characters, then substitute these variables where such characters are wanted, like this: @example @group comma:= , empty:= space:= $(empty) $(empty) foo:= a b c bar:= $(subst $(space),$(comma),$(foo)) # @r{bar is now `a,b,c'.} @end group @end example @noindent Here the @code{subst} function replaces each space with a comma, through the value of @code{foo}, and substitutes the result. @node Text Functions @section Functions for String Substitution and Analysis @cindex functions, for text Here are some functions that operate on strings: @table @code @item $(subst @var{from},@var{to},@var{text}) @findex subst Performs a textual replacement on the text @var{text}: each occurrence of @var{from} is replaced by @var{to}. The result is substituted for the function call. For example, @example $(subst ee,EE,feet on the street) @end example produces the value @samp{fEEt on the strEEt}. @item $(patsubst @var{pattern},@var{replacement},@var{text}) @findex patsubst Finds whitespace-separated words in @var{text} that match @var{pattern} and replaces them with @var{replacement}. Here @var{pattern} may contain a @samp{%} which acts as a wildcard, matching any number of any characters within a word. If @var{replacement} also contains a @samp{%}, the @samp{%} is replaced by the text that matched the @samp{%} in @var{pattern}. Words that do not match the pattern are kept without change in the output. Only the first @samp{%} in the @var{pattern} and @var{replacement} is treated this way; any subsequent @samp{%} is unchanged. If @var{pattern} does not contain a @samp{%} then the entire word must compare equal to be a match. @cindex @code{%}, quoting in @code{patsubst} @cindex @code{\} (backslash), to quote @code{%} @cindex backslash (@code{\}), to quote @code{%} @cindex quoting @code{%}, in @code{patsubst} @samp{%} characters in @code{patsubst} function invocations can be quoted with preceding backslashes (@samp{\}). Backslashes that would otherwise quote @samp{%} characters can be quoted with more backslashes. Backslashes that quote @samp{%} characters or other backslashes are removed from the pattern before it is compared to file names or has a stem substituted into it. Backslashes that are not in danger of quoting @samp{%} characters go unmolested. For example, the pattern @file{the\%weird\\%pattern\\} has @samp{the%weird\} preceding the operative @samp{%} character, and @samp{pattern\\} following it. The final two backslashes are left alone because they cannot affect any @samp{%} character. Whitespace between words is folded into single space characters; leading and trailing whitespace is discarded. For example, @example $(patsubst %.c,%.o,x.c.c bar.c) @end example @noindent produces the value @samp{x.c.o bar.o}, while @example $(patsubst foo.c,foo.o,foo.c foobar.c) @end example @noindent produces the value @samp{foo.o foobar.c}. Substitution references (@pxref{Substitution Refs, ,Substitution References}) are a simpler way to get the effect of the @code{patsubst} function. @item $(strip @var{string}) @cindex stripping whitespace @cindex whitespace, stripping @cindex spaces, stripping @findex strip Removes leading and trailing whitespace from @var{string} and replaces each internal sequence of one or more whitespace characters with a single space. Thus, @samp{$(strip a b c )} results in @w{@samp{a b c}}. The function @code{strip} can be very useful when used in conjunction with conditionals. When comparing something with the empty string @samp{} using @code{ifeq} or @code{ifneq}, you usually want a string of just whitespace to match the empty string (@pxref{Conditionals}). Thus, the following may fail to have the desired results: @example .PHONY: all ifneq "$(needs_made)" "" all: $(needs_made) else all:;@@echo 'Nothing to make!' endif @end example @noindent Replacing the variable reference @w{@samp{$(needs_made)}} with the function call @w{@samp{$(strip $(needs_made))}} in the @code{ifneq} directive would make it more robust. @item $(findstring @var{find},@var{in}) @findex findstring @cindex searching for strings @cindex finding strings @cindex strings, searching for Searches @var{in} for an occurrence of @var{find}. If it occurs, the value is @var{find}; otherwise, the value is empty. You can use this function in a conditional to test for the presence of a specific substring in a given string. Thus, the two examples, @example $(findstring a,a b c) $(findstring a,b c) @end example @noindent produce the values @samp{a} and @samp{} (the empty string), respectively. @xref{Testing Flags}, for a practical application of @code{findstring}. @need 750 @findex filter @cindex filtering words @cindex words, filtering @item $(filter @var{pattern}@dots{},@var{text}) Returns all whitespace-separated words in @var{text} that @emph{do} match any of the @var{pattern} words, removing any words that @emph{do not} match. Each word in @var{pattern} is compared to every word in @var{text} using the same algorithm as the @code{patsubst} function above. @example sources := foo.c bar.c baz.s ugh.h foo: $(sources) cc $(filter %.c %.s,$(sources)) -o foo @end example @noindent says that @file{foo} depends on @file{foo.c}, @file{bar.c}, @file{baz.s} and @file{ugh.h} but only @file{foo.c}, @file{bar.c} and @file{baz.s} should be specified in the command to the compiler. @item $(filter-out @var{pattern}@dots{},@var{text}) @findex filter-out @cindex filtering out words @cindex words, filtering out Returns all whitespace-separated words in @var{text} that @emph{do not} match any of the @var{pattern} words, removing the words that @emph{do} match one or more. Each word in @var{pattern} is compared to every word in @var{text} using the same algorithm as the @code{patsubst} function above. This is the exact opposite of the @code{filter} function. For example, given: @example @group objects = main1.o foo.o main2.o bar.o remain1.o mains = main1.o main2.o @end group @end example @noindent the following generates a list which contains all the object files not in @samp{mains}: @example $(filter-out $(mains),$(objects)) @end example @noindent This would expand to @samp{foo.o bar.o remain1.o}. @need 1500 @findex sort @cindex sorting words @item $(sort @var{list}) Sorts the words of @var{list} in lexical order, removing duplicate words. The output is a list of words separated by single spaces. Thus, @example $(sort foo bar lose) @end example @noindent returns the value @samp{bar foo lose}. @cindex removing duplicate words @cindex duplicate words, removing @cindex words, removing duplicates Incidentally, since @code{sort} removes duplicate words, you can use it for this purpose even if you don't care about the sort order. @item $(word @var{n},@var{text}) @findex word @cindex word, selecting a @cindex selecting a word Returns the @var{n}th word of @var{text}. The legitimate values of @var{n} start from 1. If @var{n} is bigger than the number of words in @var{text}, the value is empty. For example, @example $(word 2, foo bar baz) @end example @noindent returns @samp{bar}. @item $(wordlist @var{s},@var{e},@var{text}) @findex wordlist @cindex words, selecting lists of @cindex selecting word lists Returns the list of words in @var{text} starting with word @var{s} and ending with word @var{e} (inclusive). The legitimate values of @var{s} start from 1; @var{e} may start from 0. If @var{s} is bigger than the number of words in @var{text}, the value is empty. If @var{e} is bigger than the number of words in @var{text}, words up to the end of @var{text} are returned. If @var{s} is greater than @var{e}, nothing is returned. For example, @example $(wordlist 2, 3, foo bar baz) @end example @noindent returns @samp{bar baz}. @item $(words @var{text}) @findex words @cindex words, finding number Returns the number of words in @var{text}. Thus, the last word of @var{text} is @w{@code{$(word $(words @var{text}),@var{text})}}. @item $(firstword @var{names}@dots{}) @findex firstword @cindex words, extracting first The argument @var{names} is regarded as a series of names, separated by whitespace. The value is the first name in the series. The rest of the names are ignored. For example, @example $(firstword foo bar) @end example @noindent produces the result @samp{foo}. Although @code{$(firstword @var{text})} is the same as @code{$(word 1,@var{text})}, the @code{firstword} function is retained for its simplicity. @item $(lastword @var{names}@dots{}) @findex lastword @cindex words, extracting last The argument @var{names} is regarded as a series of names, separated by whitespace. The value is the last name in the series. For example, @example $(lastword foo bar) @end example @noindent produces the result @samp{bar}. Although @code{$(lastword @var{text})} is the same as @code{$(word $(words @var{text}),@var{text})}, the @code{lastword} function was added for its simplicity and better performance. @end table Here is a realistic example of the use of @code{subst} and @code{patsubst}. Suppose that a makefile uses the @code{VPATH} variable to specify a list of directories that @code{make} should search for prerequisite files (@pxref{General Search, , @code{VPATH} Search Path for All Prerequisites}). This example shows how to tell the C compiler to search for header files in the same list of directories. The value of @code{VPATH} is a list of directories separated by colons, such as @samp{src:../headers}. First, the @code{subst} function is used to change the colons to spaces: @example $(subst :, ,$(VPATH)) @end example @noindent This produces @samp{src ../headers}. Then @code{patsubst} is used to turn each directory name into a @samp{-I} flag. These can be added to the value of the variable @code{CFLAGS}, which is passed automatically to the C compiler, like this: @example override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH))) @end example @noindent The effect is to append the text @samp{-Isrc -I../headers} to the previously given value of @code{CFLAGS}. The @code{override} directive is used so that the new value is assigned even if the previous value of @code{CFLAGS} was specified with a command argument (@pxref{Override Directive, , The @code{override} Directive}). @node File Name Functions @section Functions for File Names @cindex functions, for file names @cindex file name functions Several of the built-in expansion functions relate specifically to taking apart file names or lists of file names. Each of the following functions performs a specific transformation on a file name. The argument of the function is regarded as a series of file names, separated by whitespace. (Leading and trailing whitespace is ignored.) Each file name in the series is transformed in the same way and the results are concatenated with single spaces between them. @table @code @item $(dir @var{names}@dots{}) @findex dir @cindex directory part @cindex file name, directory part Extracts the directory-part of each file name in @var{names}. The directory-part of the file name is everything up through (and including) the last slash in it. If the file name contains no slash, the directory part is the string @samp{./}. For example, @example $(dir src/foo.c hacks) @end example @noindent produces the result @samp{src/ ./}. @item $(notdir @var{names}@dots{}) @findex notdir @cindex file name, nondirectory part @cindex nondirectory part Extracts all but the directory-part of each file name in @var{names}. If the file name contains no slash, it is left unchanged. Otherwise, everything through the last slash is removed from it. A file name that ends with a slash becomes an empty string. This is unfortunate, because it means that the result does not always have the same number of whitespace-separated file names as the argument had; but we do not see any other valid alternative. For example, @example $(notdir src/foo.c hacks) @end example @noindent produces the result @samp{foo.c hacks}. @item $(suffix @var{names}@dots{}) @findex suffix @cindex suffix, function to find @cindex file name suffix Extracts the suffix of each file name in @var{names}. If the file name contains a period, the suffix is everything starting with the last period. Otherwise, the suffix is the empty string. This frequently means that the result will be empty when @var{names} is not, and if @var{names} contains multiple file names, the result may contain fewer file names. For example, @example $(suffix src/foo.c src-1.0/bar.c hacks) @end example @noindent produces the result @samp{.c .c}. @item $(basename @var{names}@dots{}) @findex basename @cindex basename @cindex file name, basename of Extracts all but the suffix of each file name in @var{names}. If the file name contains a period, the basename is everything up to (and not including) the last period. Periods in the directory part are ignored. If there is no period, the basename is the entire file name. For example, @example $(basename src/foo.c src-1.0/bar hacks) @end example @noindent produces the result @samp{src/foo src-1.0/bar hacks}. @c plural convention with dots (be consistent) @item $(addsuffix @var{suffix},@var{names}@dots{}) @findex addsuffix @cindex suffix, adding @cindex file name suffix, adding The argument @var{names} is regarded as a series of names, separated by whitespace; @var{suffix} is used as a unit. The value of @var{suffix} is appended to the end of each individual name and the resulting larger names are concatenated with single spaces between them. For example, @example $(addsuffix .c,foo bar) @end example @noindent produces the result @samp{foo.c bar.c}. @item $(addprefix @var{prefix},@var{names}@dots{}) @findex addprefix @cindex prefix, adding @cindex file name prefix, adding The argument @var{names} is regarded as a series of names, separated by whitespace; @var{prefix} is used as a unit. The value of @var{prefix} is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them. For example, @example $(addprefix src/,foo bar) @end example @noindent produces the result @samp{src/foo src/bar}. @item $(join @var{list1},@var{list2}) @findex join @cindex joining lists of words @cindex words, joining lists Concatenates the two arguments word by word: the two first words (one from each argument) concatenated form the first word of the result, the two second words form the second word of the result, and so on. So the @var{n}th word of the result comes from the @var{n}th word of each argument. If one argument has more words than the other, the extra words are copied unchanged into the result. For example, @samp{$(join a b,.c .o)} produces @samp{a.c b.o}. Whitespace between the words in the lists is not preserved; it is replaced with a single space. This function can merge the results of the @code{dir} and @code{notdir} functions, to produce the original list of files which was given to those two functions. @item $(wildcard @var{pattern}) @cindex wildcard, function The argument @var{pattern} is a file name pattern, typically containing wildcard characters (as in shell file name patterns). The result of @code{wildcard} is a space-separated list of the names of existing files that match the pattern. @xref{Wildcards, ,Using Wildcard Characters in File Names}. @item $(realpath @var{names}@dots{}) @findex realpath @cindex realpath @cindex file name, realpath of For each file name in @var{names} return the canonical absolute name. A canonical name does not contain any @code{.} or @code{..} components, nor any repeated path separators (@code{/}) or symlinks. In case of a failure the empty string is returned. Consult the @code{realpath(3)} documentation for a list of possible failure causes. @item $(abspath @var{names}@dots{}) @findex abspath @cindex abspath @cindex file name, abspath of For each file name in @var{names} return an absolute name that does not contain any @code{.} or @code{..} components, nor any repeated path separators (@code{/}). Note that, in contrast to the @code{realpath} function, @code{abspath} does not resolve symlinks and does not require the file names to refer to existing files or directories. Use the @code{wildcard} function to test for existence. @end table @node Conditional Functions @section Functions for Conditionals @cindex conditional expansion There are four functions that provide conditional expansion. A key aspect of these functions is that not all of the arguments are expanded initially. Only those arguments which need to be expanded, will be expanded. @table @code @item $(if @var{condition},@var{then-part}[,@var{else-part}]) @findex if The @code{if} function provides support for conditional expansion in a functional context (as opposed to the GNU @code{make} makefile conditionals such as @code{ifeq} (@pxref{Conditional Syntax, ,Syntax of Conditionals})). The first argument, @var{condition}, first has all preceding and trailing whitespace stripped, then is expanded. If it expands to any non-empty string, then the condition is considered to be true. If it expands to an empty string, the condition is considered to be false. If the condition is true then the second argument, @var{then-part}, is evaluated and this is used as the result of the evaluation of the entire @code{if} function. If the condition is false then the third argument, @var{else-part}, is evaluated and this is the result of the @code{if} function. If there is no third argument, the @code{if} function evaluates to nothing (the empty string). Note that only one of the @var{then-part} or the @var{else-part} will be evaluated, never both. Thus, either can contain side-effects (such as @code{shell} function calls, etc.) @item $(or @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) @findex or The @code{or} function provides a ``short-circuiting'' OR operation. Each argument is expanded, in order. If an argument expands to a non-empty string the processing stops and the result of the expansion is that string. If, after all arguments are expanded, all of them are false (empty), then the result of the expansion is the empty string. @item $(and @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) @findex and The @code{and} function provides a ``short-circuiting'' AND operation. Each argument is expanded, in order. If an argument expands to an empty string the processing stops and the result of the expansion is the empty string. If all arguments expand to a non-empty string then the result of the expansion is the expansion of the last argument. @item $(intcmp @var{lhs},@var{rhs}[,@var{lt-part}[,@var{eq-part}[,@var{gt-part}]]]) @findex intcmp The @code{intcmp} function provides support for numerical comparison of integers. This function has no counterpart among the GNU @code{make} makefile conditionals. The left-hand side, @var{lhs}, and right-hand side, @var{rhs}, are expanded and parsed as integral numbers in base 10. Expansion of the remaining arguments is controlled by how the numerical left-hand side compares to the numerical right-hand side. If there are no further arguments, then the function expands to empty if the left-hand side and right-hand side do not compare equal, or to their numerical value if they do compare equal. Else if the left-hand side is strictly less than the right-hand side, the @code{intcmp} function evaluates to the expansion of the third argument, @var{lt-part}. If both sides compare equal, then the @code{intcmp} function evaluates to the expansion of the fourth argument, @var{eq-part}. If the left-hand side is strictly greater than the right-hand side, then the @code{intcmp} function evaluates to the expansion of the fifth argument, @var{gt-part}. If @var{gt-part} is missing, it defaults to @var{eq-part}. If @var{eq-part} is missing, it defaults to the empty string. Thus both @samp{$(intcmp 9,7,hello)} and @samp{$(intcmp 9,7,hello,world,)} evaluate to the empty string, while @samp{$(intcmp 9,7,hello,world)} (notice the absence of a comma after @code{world}) evaluates to @samp{world}. @end table @node Let Function @section The @code{let} Function @findex let @cindex variables, local The @code{let} function provides a means to limit the scope of a variable. The assignment of the named variables in a @code{let} expression is in effect only within the text provided by the @code{let} expression, and this assignment doesn't impact that named variable in any outer scope. Additionally, the @code{let} function enables list unpacking by assigning all unassigned values to the last named variable. The syntax of the @code{let} function is: @example $(let @var{var} [@var{var} ...],[@var{list}],@var{text}) @end example @noindent The first two arguments, @var{var} and @var{list}, are expanded before anything else is done; note that the last argument, @var{text}, is @strong{not} expanded at the same time. Next, each word of the expanded value of @var{list} is bound to each of the variable names, @var{var}, in turn, with the final variable name being bound to the remainder of the expanded @var{list}. In other words, the first word of @var{list} is bound to the first variable @var{var}, the second word to the second variable @var{var}, and so on. If there are more variable names in @var{var} than there are words in @var{list}, the remaining @var{var} variable names are set to the empty string. If there are fewer @var{var}s than words in @var{list} then the last @var{var} is set to all remaining words in @var{list}. The variables in @var{var} are assigned as simply-expanded variables during the execution of @code{let}. @xref{Flavors, ,The Two Flavors of Variables}. After all variables are thus bound, @var{text} is expanded to provide the result of the @code{let} function. For example, this macro reverses the order of the words in the list that it is given as its first argument: @example reverse = $(let first rest,$1,\ $(if $(rest),$(call reverse,$(rest)) )$(first)) all: ; @@echo $(call reverse,d c b a) @end example @noindent will print @code{a b c d}. When first called, @code{let} will expand @var{$1} to @code{d c b a}. It will then assign @var{first} to @code{d} and assign @var{rest} to @code{c b a}. It will then expand the if-statement, where @code{$(rest)} is not empty so we recursively invoke the @var{reverse} function with the value of @var{rest} which is now @code{c b a}. The recursive invocation of @code{let} assigns @var{first} to @code{c} and @var{rest} to @code{b a}. The recursion continues until @code{let} is called with just a single value, @code{a}. Here @var{first} is @code{a} and @var{rest} is empty, so we do not recurse but simply expand @code{$(first)} to @code{a} and return, which adds @code{ b}, etc. After the @var{reverse} call is complete, the @var{first} and @var{rest} variables are no longer set. If variables by those names existed beforehand, they are not affected by the expansion of the @code{reverse} macro. @node Foreach Function @section The @code{foreach} Function @findex foreach @cindex words, iterating over The @code{foreach} function is similar to the @code{let} function, but very different from other functions. It causes one piece of text to be used repeatedly, each time with a different substitution performed on it. The @code{foreach} function resembles the @code{for} command in the shell @code{sh} and the @code{foreach} command in the C-shell @code{csh}. The syntax of the @code{foreach} function is: @example $(foreach @var{var},@var{list},@var{text}) @end example @noindent The first two arguments, @var{var} and @var{list}, are expanded before anything else is done; note that the last argument, @var{text}, is @strong{not} expanded at the same time. Then for each word of the expanded value of @var{list}, the variable named by the expanded value of @var{var} is set to that word, and @var{text} is expanded. Presumably @var{text} contains references to that variable, so its expansion will be different each time. The result is that @var{text} is expanded as many times as there are whitespace-separated words in @var{list}. The multiple expansions of @var{text} are concatenated, with spaces between them, to make the result of @code{foreach}. This simple example sets the variable @samp{files} to the list of all files in the directories in the list @samp{dirs}: @example dirs := a b c d files := $(foreach dir,$(dirs),$(wildcard $(dir)/*)) @end example Here @var{text} is @samp{$(wildcard $(dir)/*)}. The first repetition finds the value @samp{a} for @code{dir}, so it produces the same result as @samp{$(wildcard a/*)}; the second repetition produces the result of @samp{$(wildcard b/*)}; and the third, that of @samp{$(wildcard c/*)}. This example has the same result (except for setting @samp{dirs}) as the following example: @example files := $(wildcard a/* b/* c/* d/*) @end example When @var{text} is complicated, you can improve readability by giving it a name, with an additional variable: @example find_files = $(wildcard $(dir)/*) dirs := a b c d files := $(foreach dir,$(dirs),$(find_files)) @end example @noindent Here we use the variable @code{find_files} this way. We use plain @samp{=} to define a recursively-expanding variable, so that its value contains an actual function call to be re-expanded under the control of @code{foreach}; a simply-expanded variable would not do, since @code{wildcard} would be called only once at the time of defining @code{find_files}. Like the @code{let} function, the @code{foreach} function has no permanent effect on the variable @var{var}; its value and flavor after the @code{foreach} function call are the same as they were beforehand. The other values which are taken from @var{list} are in effect only temporarily, during the execution of @code{foreach}. The variable @var{var} is a simply-expanded variable during the execution of @code{foreach}. If @var{var} was undefined before the @code{foreach} function call, it is undefined after the call. @xref{Flavors, ,The Two Flavors of Variables}. You must take care when using complex variable expressions that result in variable names because many strange things are valid variable names, but are probably not what you intended. For example, @smallexample files := $(foreach Esta-escrito-en-espanol!,b c ch,$(find_files)) @end smallexample @noindent might be useful if the value of @code{find_files} references the variable whose name is @samp{Esta-escrito-en-espanol!} (es un nombre bastante largo, no?), but it is more likely to be a mistake. @node File Function @section The @code{file} Function @findex file @cindex writing to a file @cindex file, writing to @cindex reading from a file @cindex file, reading from The @code{file} function allows the makefile to write to or read from a file. Two modes of writing are supported: overwrite, where the text is written to the beginning of the file and any existing content is lost, and append, where the text is written to the end of the file, preserving the existing content. In both cases the file is created if it does not exist. It is a fatal error if the file cannot be opened for writing, or if the write operation fails. The @code{file} function expands to the empty string when writing to a file. When reading from a file, the @code{file} function expands to the verbatim contents of the file, except that the final newline (if there is one) will be stripped. Attempting to read from a non-existent file expands to the empty string. The syntax of the @code{file} function is: @example $(file @var{op} @var{filename}[,@var{text}]) @end example When the @code{file} function is evaluated all its arguments are expanded first, then the file indicated by @var{filename} will be opened in the mode described by @var{op}. The operator @var{op} can be @code{>} to indicate the file will be overwritten with new content, @code{>>} to indicate the current contents of the file will be appended to, or @code{<} to indicate the contents of the file will be read in. The @var{filename} specifies the file to be written to or read from. There may optionally be whitespace between the operator and the file name. When reading files, it is an error to provide a @var{text} value. When writing files, @var{text} will be written to the file. If @var{text} does not already end in a newline a final newline will be written (even if @var{text} is the empty string). If the @var{text} argument is not given at all, nothing will be written. For example, the @code{file} function can be useful if your build system has a limited command line size and your recipe runs a command that can accept arguments from a file as well. Many commands use the convention that an argument prefixed with an @code{@@} specifies a file containing more arguments. Then you might write your recipe in this way: @example @group program: $(OBJECTS) $(file >$@@.in,$^) $(CMD) $(CMDFLAGS) @@$@@.in @@rm $@@.in @end group @end example If the command required each argument to be on a separate line of the input file, you might write your recipe like this: @example @group program: $(OBJECTS) $(file >$@@.in) $(foreach O,$^,$(file >>$@@.in,$O)) $(CMD) $(CMDFLAGS) @@$@@.in @@rm $@@.in @end group @end example @node Call Function @section The @code{call} Function @findex call @cindex functions, user defined @cindex user defined functions The @code{call} function is unique in that it can be used to create new parameterized functions. You can write a complex expression as the value of a variable, then use @code{call} to expand it with different values. The syntax of the @code{call} function is: @example $(call @var{variable},@var{param},@var{param},@dots{}) @end example When @code{make} expands this function, it assigns each @var{param} to temporary variables @code{$(1)}, @code{$(2)}, etc. The variable @code{$(0)} will contain @var{variable}. There is no maximum number of parameter arguments. There is no minimum, either, but it doesn't make sense to use @code{call} with no parameters. Then @var{variable} is expanded as a @code{make} variable in the context of these temporary assignments. Thus, any reference to @code{$(1)} in the value of @var{variable} will resolve to the first @var{param} in the invocation of @code{call}. Note that @var{variable} is the @emph{name} of a variable, not a @emph{reference} to that variable. Therefore you would not normally use a @samp{$} or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.) If @var{variable} is the name of a built-in function, the built-in function is always invoked (even if a @code{make} variable by that name also exists). The @code{call} function expands the @var{param} arguments before assigning them to temporary variables. This means that @var{variable} values containing references to built-in functions that have special expansion rules, like @code{foreach} or @code{if}, may not work as you expect. Some examples may make this clearer. This macro simply reverses its arguments: @smallexample reverse = $(2) $(1) foo = $(call reverse,a,b) @end smallexample @noindent Here @code{foo} will contain @samp{b a}. This one is slightly more interesting: it defines a macro to search for the first instance of a program in @code{PATH}: @smallexample pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) LS := $(call pathsearch,ls) @end smallexample @noindent Now the variable @code{LS} contains @code{/bin/ls} or similar. The @code{call} function can be nested. Each recursive invocation gets its own local values for @code{$(1)}, etc.@: that mask the values of higher-level @code{call} functions. For example, here is an implementation of a @dfn{map} function: @smallexample map = $(foreach a,$(2),$(call $(1),$(a))) @end smallexample Now you can @code{map} a function that normally takes only one argument, such as @code{origin}, to multiple values in one step: @smallexample o = $(call map,origin,o map MAKE) @end smallexample and end up with @code{o} containing something like @samp{file file default}. A final caution: be careful when adding whitespace to the arguments to @code{call}. As with other functions, any whitespace contained in the second and subsequent arguments is kept; this can cause strange effects. It's generally safest to remove all extraneous whitespace when providing parameters to @code{call}. @node Value Function @comment node-name, next, previous, up @section The @code{value} Function @findex value @cindex variables, unexpanded value The @code{value} function provides a way for you to use the value of a variable @emph{without} having it expanded. Please note that this does not undo expansions which have already occurred; for example if you create a simply expanded variable its value is expanded during the definition; in that case the @code{value} function will return the same result as using the variable directly. The syntax of the @code{value} function is: @example $(value @var{variable}) @end example Note that @var{variable} is the @emph{name} of a variable, not a @emph{reference} to that variable. Therefore you would not normally use a @samp{$} or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.) The result of this function is a string containing the value of @var{variable}, without any expansion occurring. For example, in this makefile: @example @group FOO = $PATH all: @@echo $(FOO) @@echo $(value FOO) @end group @end example @noindent The first output line would be @code{ATH}, since the ``$P'' would be expanded as a @code{make} variable, while the second output line would be the current value of your @code{$PATH} environment variable, since the @code{value} function avoided the expansion. The @code{value} function is most often used in conjunction with the @code{eval} function (@pxref{Eval Function}). @node Eval Function @comment node-name, next, previous, up @section The @code{eval} Function @findex eval @cindex evaluating makefile syntax @cindex makefile syntax, evaluating The @code{eval} function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the @code{eval} function is expanded, then the results of that expansion are parsed as makefile syntax. The expanded results can define new @code{make} variables, targets, implicit or explicit rules, etc. The result of the @code{eval} function is always the empty string; thus, it can be placed virtually anywhere in a makefile without causing syntax errors. It's important to realize that the @code{eval} argument is expanded @emph{twice}; first by the @code{eval} function, then the results of that expansion are expanded again when they are parsed as makefile syntax. This means you may need to provide extra levels of escaping for ``$'' characters when using @code{eval}. The @code{value} function (@pxref{Value Function}) can sometimes be useful in these situations, to circumvent unwanted expansions. Here is an example of how @code{eval} can be used; this example combines a number of concepts and other functions. Although it might seem overly complex to use @code{eval} in this example, rather than just writing out the rules, consider two things: first, the template definition (in @code{PROGRAM_template}) could need to be much more complex than it is here; and second, you might put the complex, ``generic'' part of this example into another makefile, then include it in all the individual makefiles. Now your individual makefiles are quite straightforward. @example @group PROGRAMS = server client server_OBJS = server.o server_priv.o server_access.o server_LIBS = priv protocol client_OBJS = client.o client_api.o client_mem.o client_LIBS = protocol # Everything after this is generic .PHONY: all all: $(PROGRAMS) define PROGRAM_template = $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) ALL_OBJS += $$($(1)_OBJS) endef $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog)))) $(PROGRAMS): $(LINK.o) $^ $(LDLIBS) -o $@@ clean: rm -f $(ALL_OBJS) $(PROGRAMS) @end group @end example @node Origin Function @section The @code{origin} Function @findex origin @cindex variables, origin of @cindex origin of variable The @code{origin} function is unlike most other functions in that it does not operate on the values of variables; it tells you something @emph{about} a variable. Specifically, it tells you where it came from. The syntax of the @code{origin} function is: @example $(origin @var{variable}) @end example Note that @var{variable} is the @emph{name} of a variable to inquire about, not a @emph{reference} to that variable. Therefore you would not normally use a @samp{$} or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.) The result of this function is a string telling you how the variable @var{variable} was defined: @table @samp @item undefined if @var{variable} was never defined. @item default if @var{variable} has a default definition, as is usual with @code{CC} and so on. @xref{Implicit Variables, ,Variables Used by Implicit Rules}. Note that if you have redefined a default variable, the @code{origin} function will return the origin of the later definition. @item environment if @var{variable} was inherited from the environment provided to @code{make}. @item environment override if @var{variable} was inherited from the environment provided to @code{make}, and is overriding a setting for @var{variable} in the makefile as a result of the @w{@samp{-e}} option (@pxref{Options Summary, ,Summary of Options}). @item file if @var{variable} was defined in a makefile. @item command line if @var{variable} was defined on the command line. @item override if @var{variable} was defined with an @code{override} directive in a makefile (@pxref{Override Directive, ,The @code{override} Directive}). @item automatic if @var{variable} is an automatic variable defined for the execution of the recipe for each rule (@pxref{Automatic Variables}). @end table This information is primarily useful (other than for your curiosity) to determine if you want to believe the value of a variable. For example, suppose you have a makefile @file{foo} that includes another makefile @file{bar}. You want a variable @code{bletch} to be defined in @file{bar} if you run the command @w{@samp{make -f bar}}, even if the environment contains a definition of @code{bletch}. However, if @file{foo} defined @code{bletch} before including @file{bar}, you do not want to override that definition. This could be done by using an @code{override} directive in @file{foo}, giving that definition precedence over the later definition in @file{bar}; unfortunately, the @code{override} directive would also override any command line definitions. So, @file{bar} could include: @example @group ifdef bletch ifeq "$(origin bletch)" "environment" bletch = barf, gag, etc. endif endif @end group @end example @noindent If @code{bletch} has been defined from the environment, this will redefine it. If you want to override a previous definition of @code{bletch} if it came from the environment, even under @samp{-e}, you could instead write: @example @group ifneq "$(findstring environment,$(origin bletch))" "" bletch = barf, gag, etc. endif @end group @end example Here the redefinition takes place if @samp{$(origin bletch)} returns either @samp{environment} or @samp{environment override}. @xref{Text Functions, , Functions for String Substitution and Analysis}. @node Flavor Function @section The @code{flavor} Function @findex flavor @cindex variables, flavor of @cindex flavor of variable The @code{flavor} function, like the @code{origin} function, does not operate on the values of variables but rather it tells you something @emph{about} a variable. Specifically, it tells you the flavor of a variable (@pxref{Flavors, ,The Two Flavors of Variables}). The syntax of the @code{flavor} function is: @example $(flavor @var{variable}) @end example Note that @var{variable} is the @emph{name} of a variable to inquire about, not a @emph{reference} to that variable. Therefore you would not normally use a @samp{$} or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.) The result of this function is a string that identifies the flavor of the variable @var{variable}: @table @samp @item undefined if @var{variable} was never defined. @item recursive if @var{variable} is a recursively expanded variable. @item simple if @var{variable} is a simply expanded variable. @end table @node Make Control Functions @section Functions That Control Make @cindex functions, for controlling make @cindex controlling make These functions control the way make runs. Generally, they are used to provide information to the user of the makefile or to cause make to stop if some sort of environmental error is detected. @table @code @item $(error @var{text}@dots{}) @findex error @cindex error, stopping on @cindex stopping make Generates a fatal error where the message is @var{text}. Note that the error is generated whenever this function is evaluated. So, if you put it inside a recipe or on the right side of a recursive variable assignment, it won't be evaluated until later. The @var{text} will be expanded before the error is generated. For example, @example ifdef ERROR1 $(error error is $(ERROR1)) endif @end example @noindent will generate a fatal error during the read of the makefile if the @code{make} variable @code{ERROR1} is defined. Or, @example ERR = $(error found an error!) .PHONY: err err: ; $(ERR) @end example @noindent will generate a fatal error while @code{make} is running, if the @code{err} target is invoked. @item $(warning @var{text}@dots{}) @findex warning @cindex warnings, printing @cindex printing user warnings This function works similarly to the @code{error} function, above, except that @code{make} doesn't exit. Instead, @var{text} is expanded and the resulting message is displayed, but processing of the makefile continues. The result of the expansion of this function is the empty string. @item $(info @var{text}@dots{}) @findex info @cindex printing messages This function does nothing more than print its (expanded) argument(s) to standard output. No makefile name or line number is added. The result of the expansion of this function is the empty string. @end table @node Shell Function @section The @code{shell} Function @findex shell @cindex command expansion @cindex backquotes @cindex shell command, function for The @code{shell} function is unlike any other function other than the @code{wildcard} function (@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it communicates with the world outside of @code{make}. The @code{shell} function provides for @code{make} the same facility that backquotes (@samp{`}) provide in most shells: it does @dfn{command expansion}. This means that it takes as an argument a shell command and expands to the output of the command. The only processing @code{make} does on the result is to convert each newline (or carriage-return / newline pair) to a single space. If there is a trailing (carriage-return and) newline it will simply be removed. The commands run by calls to the @code{shell} function are run when the function calls are expanded (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). Because this function involves spawning a new shell, you should carefully consider the performance implications of using the @code{shell} function within recursively expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The Two Flavors of Variables}). An alternative to the @code{shell} function is the @samp{!=} assignment operator; it provides a similar behavior but has subtle differences (@pxref{Setting, , Setting Variables}). The @samp{!=} assignment operator is included in newer POSIX standards. @vindex .SHELLSTATUS After the @code{shell} function or @samp{!=} assignment operator is used, its exit status is placed in the @code{.SHELLSTATUS} variable. Here are some examples of the use of the @code{shell} function: @example contents := $(shell cat foo) @end example @noindent sets @code{contents} to the contents of the file @file{foo}, with a space (rather than a newline) separating each line. @example files := $(shell echo *.c) @end example @noindent sets @code{files} to the expansion of @samp{*.c}. Unless @code{make} is using a very strange shell, this has the same result as @w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file exists). All variables that are marked as @code{export} will also be passed to the shell started by the @code{shell} function. It is possible to create a variable expansion loop: consider this @file{makefile}: @example export HI = $(shell echo hi) all: ; @@echo $$HI @end example When @code{make} wants to run the recipe it must add the variable @var{HI} to the environment; to do so it must be expanded. The value of this variable requires an invocation of the @code{shell} function, and to invoke it we must create its environment. Since @var{HI} is exported, we need to expand it to create its environment. And so on. In this obscure case @code{make} will use the value of the variable from the environment provided to @code{make}, or else the empty string if there was none, rather than looping or issuing an error. This is often what you want; for example: @example export PATH = $(shell echo /usr/local/bin:$$PATH) @end example However, it would be simpler and more efficient to use a simply-expanded variable here (@samp{:=}) in the first place. @node Guile Function @section The @code{guile} Function @findex guile @cindex Guile If GNU @code{make} is built with support for GNU Guile as an embedded extension language then the @code{guile} function will be available. The @code{guile} function takes one argument which is first expanded by @code{make} in the normal fashion, then passed to the GNU Guile evaluator. The result of the evaluator is converted into a string and used as the expansion of the @code{guile} function in the makefile. See @ref{Guile Integration, ,GNU Guile Integration} for details on writing extensions to @code{make} in Guile. You can determine whether GNU Guile support is available by checking the @code{.FEATURES} variable for the word @var{guile}. @node Running @chapter How to Run @code{make} A makefile that says how to recompile a program can be used in more than one way. The simplest use is to recompile every file that is out of date. Usually, makefiles are written so that if you run @code{make} with no arguments, it does just that. But you might want to update only some of the files; you might want to use a different compiler or different compiler options; you might want just to find out which files are out of date without changing them. By giving arguments when you run @code{make}, you can do any of these things and many others. @cindex exit status of make The exit status of @code{make} is always one of three values: @table @code @item 0 The exit status is zero if @code{make} is successful. @item 2 The exit status is two if @code{make} encounters any errors. It will print messages describing the particular errors. @item 1 The exit status is one if you use the @samp{-q} flag and @code{make} determines that some target is not already up to date. @xref{Instead of Execution, ,Instead of Executing Recipes}. @end table @menu * Makefile Arguments:: How to specify which makefile to use. * Goals:: How to use goal arguments to specify which parts of the makefile to use. * Instead of Execution:: How to use mode flags to specify what kind of thing to do with the recipes in the makefile other than simply execute them. * Avoiding Compilation:: How to avoid recompiling certain files. * Overriding:: How to override a variable to specify an alternate compiler and other things. * Testing:: How to proceed past some errors, to test compilation. * Warnings:: How to control reporting of makefile issues. * Temporary Files:: Where @code{make} keeps its temporary files. * Options Summary:: Summary of Options @end menu @node Makefile Arguments @section Arguments to Specify the Makefile @cindex @code{--file} @cindex @code{--makefile} @cindex @code{-f} The way to specify the name of the makefile is with the @samp{-f} or @samp{--file} option (@samp{--makefile} also works). For example, @samp{-f altmake} says to use the file @file{altmake} as the makefile. If you use the @samp{-f} flag several times and follow each @samp{-f} with an argument, all the specified files are used jointly as makefiles. If you do not use the @samp{-f} or @samp{--file} flag, the default is to try @file{GNUmakefile}, @file{makefile}, and @file{Makefile}, in that order, and use the first of these three which exists or can be made (@pxref{Makefiles, ,Writing Makefiles}). @node Goals @section Arguments to Specify the Goals @cindex goal, how to specify The @dfn{goals} are the targets that @code{make} should strive ultimately to update. Other targets are updated as well if they appear as prerequisites of goals, or prerequisites of prerequisites of goals, etc. By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe. If the first rule in the makefile has several targets, only the first target in the rule becomes the default goal, not the whole list. You can manage the selection of the default goal from within your makefile using the @code{.DEFAULT_GOAL} variable (@pxref{Special Variables, , Other Special Variables}). You can also specify a different goal or goals with command line arguments to @code{make}. Use the name of the goal as an argument. If you specify several goals, @code{make} processes each of them in turn, in the order you name them. Any target in the makefile may be specified as a goal (unless it starts with @samp{-} or contains an @samp{=}, in which case it will be parsed as a switch or variable definition, respectively). Even targets not in the makefile may be specified, if @code{make} can find implicit rules that say how to make them. @vindex MAKECMDGOALS @code{Make} will set the special variable @code{MAKECMDGOALS} to the list of goals you specified on the command line. If no goals were given on the command line, this variable is empty. Note that this variable should be used only in special circumstances. An example of appropriate use is to avoid including @file{.d} files during @code{clean} rules (@pxref{Automatic Prerequisites}), so @code{make} won't create them only to immediately remove them again: @example @group sources = foo.c bar.c ifeq (,$(filter clean,$(MAKECMDGOALS))) include $(sources:.c=.d) endif @end group @end example One use of specifying a goal is if you want to compile only a part of the program, or only one of several programs. Specify as a goal each file that you wish to remake. For example, consider a directory containing several programs, with a makefile that starts like this: @example .PHONY: all all: size nm ld ar as @end example If you are working on the program @code{size}, you might want to say @w{@samp{make size}} so that only the files of that program are recompiled. Another use of specifying a goal is to make files that are not normally made. For example, there may be a file of debugging output, or a version of the program that is compiled specially for testing, which has a rule in the makefile but is not a prerequisite of the default goal. Another use of specifying a goal is to run the recipe associated with a phony target (@pxref{Phony Targets}) or empty target (@pxref{Empty Targets, ,Empty Target Files to Record Events}). Many makefiles contain a phony target named @file{clean} which deletes everything except source files. Naturally, this is done only if you request it explicitly with @w{@samp{make clean}}. Following is a list of typical phony and empty target names. @xref{Standard Targets}, for a detailed list of all the standard target names which GNU software packages use. @table @file @item all @cindex @code{all} @r{(standard target)} Make all the top-level targets the makefile knows about. @item clean @cindex @code{clean} @r{(standard target)} Delete all files that are normally created by running @code{make}. @item mostlyclean @cindex @code{mostlyclean} @r{(standard target)} Like @samp{clean}, but may refrain from deleting a few files that people normally don't want to recompile. For example, the @samp{mostlyclean} target for GCC does not delete @file{libgcc.a}, because recompiling it is rarely necessary and takes a lot of time. @item distclean @cindex @code{distclean} @r{(standard target)} @itemx realclean @cindex @code{realclean} @r{(standard target)} @itemx clobber @cindex @code{clobber} @r{(standard target)} Any of these targets might be defined to delete @emph{more} files than @samp{clean} does. For example, this would delete configuration files or links that you would normally create as preparation for compilation, even if the makefile itself cannot create these files. @item install @cindex @code{install} @r{(standard target)} Copy the executable file into a directory that users typically search for commands; copy any auxiliary files that the executable uses into the directories where it will look for them. @item print @cindex @code{print} @r{(standard target)} Print listings of the source files that have changed. @item tar @cindex @code{tar} @r{(standard target)} Create a tar file of the source files. @item shar @cindex @code{shar} @r{(standard target)} Create a shell archive (shar file) of the source files. @item dist @cindex @code{dist} @r{(standard target)} Create a distribution file of the source files. This might be a tar file, or a shar file, or a compressed version of one of the above, or even more than one of the above. @item TAGS @cindex @code{TAGS} @r{(standard target)} Update a tags table for this program. @item check @cindex @code{check} @r{(standard target)} @itemx test @cindex @code{test} @r{(standard target)} Perform self tests on the program this makefile builds. @end table @node Instead of Execution @section Instead of Executing Recipes @cindex execution, instead of @cindex recipes, instead of executing The makefile tells @code{make} how to tell whether a target is up to date, and how to update each target. But updating the targets is not always what you want. Certain options specify other activities for @code{make}. @comment Extra blank lines make it print better. @table @samp @item -n @itemx --just-print @itemx --dry-run @itemx --recon @cindex @code{--just-print} @cindex @code{--dry-run} @cindex @code{--recon} @cindex @code{-n} ``No-op''. Causes @code{make} to print the recipes that are needed to make the targets up to date, but not actually execute them. Note that some recipes are still executed, even with this flag (@pxref{MAKE Variable, ,How the @code{MAKE} Variable Works}). Also any recipes needed to update included makefiles are still executed (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}). @item -t @itemx --touch @cindex @code{--touch} @cindex touching files @cindex target, touching @cindex @code{-t} ``Touch''. Marks targets as up to date without actually changing them. In other words, @code{make} pretends to update the targets but does not really change their contents; instead only their modification times are updated. @item -q @itemx --question @cindex @code{--question} @cindex @code{-q} @cindex question mode ``Question''. Silently check whether the targets are up to date, but do not execute recipes; the exit code shows whether any updates are needed. @item -W @var{file} @itemx --what-if=@var{file} @itemx --assume-new=@var{file} @itemx --new-file=@var{file} @cindex @code{--what-if} @cindex @code{-W} @cindex @code{--assume-new} @cindex @code{--new-file} @cindex what if @cindex files, assuming new ``What if''. Each @samp{-W} flag is followed by a file name. The given files' modification times are recorded by @code{make} as being the present time, although the actual modification times remain the same. You can use the @samp{-W} flag in conjunction with the @samp{-n} flag to see what would happen if you were to modify specific files. @end table With the @samp{-n} flag, @code{make} prints the recipe that it would normally execute but usually does not execute it. With the @samp{-t} flag, @code{make} ignores the recipes in the rules and uses (in effect) the command @code{touch} for each target that needs to be remade. The @code{touch} command is also printed, unless @samp{-s} or @code{.SILENT} is used. For speed, @code{make} does not actually invoke the program @code{touch}. It does the work directly. With the @samp{-q} flag, @code{make} prints nothing and executes no recipes, but the exit status code it returns is zero if and only if the targets to be considered are already up to date. If the exit status is one, then some updating needs to be done. If @code{make} encounters an error, the exit status is two, so you can distinguish an error from a target that is not up to date. It is an error to use more than one of these three flags in the same invocation of @code{make}. @cindex +, and recipe execution The @samp{-n}, @samp{-t}, and @samp{-q} options do not affect recipe lines that begin with @samp{+} characters or contain the strings @samp{$(MAKE)} or @samp{$@{MAKE@}}. Note that only the line containing the @samp{+} character or the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} is run regardless of these options. Other lines in the same rule are not run unless they too begin with @samp{+} or contain @samp{$(MAKE)} or @samp{$@{MAKE@}} (@xref{MAKE Variable, ,How the @code{MAKE} Variable Works}.) @cindex phony targets and recipe execution The @samp{-t} flag prevents phony targets (@pxref{Phony Targets}) from being updated, unless there are recipe lines beginning with @samp{+} or containing @samp{$(MAKE)} or @samp{$@{MAKE@}}. The @samp{-W} flag provides two features: @itemize @bullet @item If you also use the @samp{-n} or @samp{-q} flag, you can see what @code{make} would do if you were to modify some files. @item Without the @samp{-n} or @samp{-q} flag, when @code{make} is actually executing recipes, the @samp{-W} flag can direct @code{make} to act as if some files had been modified, without actually running the recipes for those files. @end itemize Note that the options @samp{-p} and @samp{-v} allow you to obtain other information about @code{make} or about the makefiles in use (@pxref{Options Summary, ,Summary of Options}). @node Avoiding Compilation @section Avoiding Recompilation of Some Files @cindex @code{-o} @cindex @code{--old-file} @cindex @code{--assume-old} @cindex files, assuming old @cindex files, avoiding recompilation of @cindex recompilation, avoiding Sometimes you may have changed a source file but you do not want to recompile all the files that depend on it. For example, suppose you add a macro or a declaration to a header file that many other files depend on. Being conservative, @code{make} assumes that any change in the header file requires recompilation of all dependent files, but you know that they do not need to be recompiled and you would rather not waste the time waiting for them to compile. If you anticipate the problem before changing the header file, you can use the @samp{-t} flag. This flag tells @code{make} not to run the recipes in the rules, but rather to mark the target up to date by changing its last-modification date. You would follow this procedure: @enumerate @item Use the command @samp{make} to recompile the source files that really need recompilation, ensuring that the object files are up-to-date before you begin. @item Make the changes in the header files. @item Use the command @samp{make -t} to mark all the object files as up to date. The next time you run @code{make}, the changes in the header files will not cause any recompilation. @end enumerate If you have already changed the header file at a time when some files do need recompilation, it is too late to do this. Instead, you can use the @w{@samp{-o @var{file}}} flag, which marks a specified file as ``old'' (@pxref{Options Summary, ,Summary of Options}). This means that the file itself will not be remade, and nothing else will be remade on its account. Follow this procedure: @enumerate @item Recompile the source files that need compilation for reasons independent of the particular header file, with @samp{make -o @var{headerfile}}. If several header files are involved, use a separate @samp{-o} option for each header file. @item Touch all the object files with @samp{make -t}. @end enumerate @node Overriding @section Overriding Variables @cindex overriding variables with arguments @cindex variables, overriding with arguments @cindex command line variables @cindex variables, command line An argument that contains @samp{=} specifies the value of a variable: @samp{@var{v}=@var{x}} sets the value of the variable @var{v} to @var{x}. If you specify a value in this way, all ordinary assignments of the same variable in the makefile are ignored; we say they have been @dfn{overridden} by the command line argument. The most common way to use this facility is to pass extra flags to compilers. For example, in a properly written makefile, the variable @code{CFLAGS} is included in each recipe that runs the C compiler, so a file @file{foo.c} would be compiled something like this: @example cc -c $(CFLAGS) foo.c @end example Thus, whatever value you set for @code{CFLAGS} affects each compilation that occurs. The makefile probably specifies the usual value for @code{CFLAGS}, like this: @example CFLAGS=-g @end example Each time you run @code{make}, you can override this value if you wish. For example, if you say @samp{make CFLAGS='-g -O'}, each C compilation will be done with @samp{cc -c -g -O}. (This also illustrates how you can use quoting in the shell to enclose spaces and other special characters in the value of a variable when you override it.) The variable @code{CFLAGS} is only one of many standard variables that exist just so that you can change them this way. @xref{Implicit Variables, , Variables Used by Implicit Rules}, for a complete list. You can also program the makefile to look at additional variables of your own, giving the user the ability to control other aspects of how the makefile works by changing the variables. When you override a variable with a command line argument, you can define either a recursively-expanded variable or a simply-expanded variable. The examples shown above make a recursively-expanded variable; to make a simply-expanded variable, write @samp{:=} or @samp{::=} instead of @samp{=}. But, unless you want to include a variable reference or function call in the @emph{value} that you specify, it makes no difference which kind of variable you create. There is one way that the makefile can change a variable that you have overridden. This is to use the @code{override} directive, which is a line that looks like this: @samp{override @var{variable} = @var{value}} (@pxref{Override Directive, ,The @code{override} Directive}). @node Testing @section Testing the Compilation of a Program @cindex testing compilation @cindex compilation, testing Normally, when an error happens in executing a shell command, @code{make} gives up immediately, returning a nonzero status. No further recipes are executed for any target. The error implies that the goal cannot be correctly remade, and @code{make} reports this as soon as it knows. When you are compiling a program that you have just changed, this is not what you want. Instead, you would rather that @code{make} try compiling every file that can be tried, to show you as many compilation errors as possible. @cindex @code{-k} @cindex @code{--keep-going} On these occasions, you should use the @samp{-k} or @samp{--keep-going} flag. This tells @code{make} to continue to consider the other prerequisites of the pending targets, remaking them if necessary, before it gives up and returns nonzero status. For example, after an error in compiling one object file, @samp{make -k} will continue compiling other object files even though it already knows that linking them will be impossible. In addition to continuing after failed shell commands, @samp{make -k} will continue as much as possible after discovering that it does not know how to make a target or prerequisite file. This will always cause an error message, but without @samp{-k}, it is a fatal error (@pxref{Options Summary, ,Summary of Options}). The usual behavior of @code{make} assumes that your purpose is to get the goals up to date; once @code{make} learns that this is impossible, it might as well report the failure immediately. The @samp{-k} flag allows testing as many of the changes made in the program as possible, perhaps to find several independent problems so that you can correct them all before the next attempt to compile. This is why Emacs' @kbd{M-x compile} command passes the @samp{-k} flag by default. @node Warnings @section Makefile Warnings @cindex warnings @cindex enabling warnings GNU Make can detect some types of incorrect usage in makefiles. When one of these incorrect usages is detected, GNU Make can perform one of these actions: @table @samp @item ignore @cindex warning action ignore @cindex ignore, warning action Ignore the usage. @item warn @cindex warning action warn @cindex warn, warning action Show a warning about the usage and continue processing the makefile. @item error @cindex warning action error @cindex error, warning action Show an error for the usage and immediately stop processing the makefile. @end table @noindent The types of warnings GNU Make can detect are: @table @samp @item circular-dep @findex circular-dep @cindex warning circular dependency Finding a loop in the dependency graph (the prerequisites of a target contain or depend on the target itself). If the action is not @samp{error}, the circular reference is dropped from the graph before continuing. The default action is @samp{warn}. @item invalid-ref @findex invalid-ref @cindex warning invalid reference Using an invalid variable name in a variable reference. The default action is @samp{warn}. @item invalid-var @findex invalid-var @cindex warning invalid variable Assigning to an invalid variable name (e.g., a name containing whitespace). The default action is @samp{warn}. @item undefined-var @findex undefined-var @cindex warning undefined variable Referencing a variable that has not been defined. The default action is @samp{ignore}. Note the deprecated @code{--warn-undefined-variables} option sets the action for this warning to @samp{warn}. @end table The actions for these warnings can be changed by specifying warning control options. Each warning control option consists of either a warning type, or a warning action, or a warning type and warning action separated by a colon (@code{:}). Multiple control options are separated by either whitespace or commas. If the control option is just a warning type, then the action associated with that type is set to @code{warn}. If the option is just an action, then that action is applied to all warning types (a ``global action''). ``Global actions'' take precedence over default actions. Actions associated with a specific warning type take precedence over ``global actions'' and default actions. If multiple control options provide actions for the same warning type, the last action specified will be used. There are two ways to specify control options: using the @code{--warn} command line option, or using the @code{.WARNINGS} variable. @subsubheading The @code{.WARNINGS} variable @vindex .WARNINGS Warning control options provided in the @code{.WARNINGS} variable take effect as soon as the variable assignment is parsed and will last until this instance of @code{make} finishes parsing all makefiles. These settings will not be passed to recursive invocations of @code{make}. Note that the value of this variable is expanded immediately, even if the recursive expansion assignment operator (@code{=}) is used. Each assignment of @code{.WARNINGS} completely replaces any previous settings. If you want to preserve the previous settings, use the @code{+=} assignment operator. Currently, assigning @code{.WARNINGS} as a target-specific or pattern-specific variable has no effect. This may change in the future. @subsubheading The @code{--warn} option @cindex @code{--warn} The @code{--warn} option can be specified on the command line, or by adding it to the @code{MAKEFLAGS} variable (@pxref{Recursion, ,Recursive Use of @code{make}}). Settings added to @code{MAKEFLAGS} take affect after the assignment is parsed. This option is passed to sub-makes through the @code{MAKEFLAGS} variable. The @code{--warn} option can be provided multiple times: the effects are cumulative with later options overriding over earlier options. When GNU Make provides warning settings to sub-makes, they are all combined into a single @code{--warn} option in @code{MAKEFLAGS} with a standard order. Specifying @code{--warn} with no arguments is equivalent to using @code{--warn=warn}, which sets the action for all warning types to @samp{warn}. Any action specified with an @code{--warn} option will take precedence over actions provided in the makefile with @code{.WARNINGS}. This means if you use @code{--warn=error}, for example, all warnings will be treated as errors regardless of any @code{.WARNINGS} assignments. @node Temporary Files @section Temporary Files @cindex temporary files In some situations, @code{make} will need to create its own temporary files. These files must not be disturbed while @code{make} is running, including all recursively-invoked instances of @code{make}. All temporary filenames created by GNU Make will start with the letters @samp{Gm}. @cindex @code{MAKE_TMPDIR} If the environment variable @code{MAKE_TMPDIR} is set then all temporary files created by @code{make} will be placed there. @cindex @code{TMPDIR} @cindex @code{TMP} @cindex @code{TEMP} If @code{MAKE_TMPDIR} is not set, then the standard location for temporary files for the current operating system will be used. For POSIX systems this will be the location set in the @code{TMPDIR} environment variable, or else the system's default location (e.g., @file{/tmp}) is used. On Windows, first @code{TMP} then @code{TEMP} will be checked, then @code{TMPDIR}, and finally the system default temporary file location will be used. Note that this directory must already exist or @code{make} will fail: @code{make} will not attempt to create it. These variables @emph{cannot} be set from within a makefile: GNU @code{make} must have access to this location before it begins reading the makefiles. @node Options Summary @section Summary of Options @cindex options @cindex flags @cindex switches Here is a table of all the options @code{make} understands: @table @samp @item -b @cindex @code{-b} @itemx -m @cindex @code{-m} These options are ignored for compatibility with other versions of @code{make}. @item -B @cindex @code{-B} @itemx --always-make @cindex @code{--always-make} Consider all targets out-of-date. GNU @code{make} proceeds to consider targets and their prerequisites using the normal algorithms; however, all targets so considered are always remade regardless of the status of their prerequisites. To avoid infinite recursion, if @code{MAKE_RESTARTS} (@pxref{Special Variables, , Other Special Variables}) is set to a number greater than 0 this option is disabled when considering whether to remake makefiles (@pxref{Remaking Makefiles, , How Makefiles Are Remade}). @item -C @var{dir} @cindex @code{-C} @itemx --directory=@var{dir} @cindex @code{--directory} Change to directory @var{dir} before reading the makefiles. If multiple @samp{-C} options are specified, each is interpreted relative to the previous one: @samp{-C / -C etc} is equivalent to @samp{-C /etc}. This is typically used with recursive invocations of @code{make} (@pxref{Recursion, ,Recursive Use of @code{make}}). @item -d @cindex @code{-d} @c Extra blank line here makes the table look better. Print debugging information in addition to normal processing. The debugging information says which files are being considered for remaking, which file-times are being compared and with what results, which files actually need to be remade, which implicit rules are considered and which are applied---everything interesting about how @code{make} decides what to do. The @code{-d} option is equivalent to @samp{--debug=a} (see below). @item --debug[=@var{options}] @cindex @code{--debug} @c Extra blank line here makes the table look better. Print debugging information in addition to normal processing. Various levels and types of output can be chosen. With no arguments, print the ``basic'' level of debugging. Possible arguments are below; only the first character is considered, and values must be comma- or space-separated. @table @code @item a (@i{all}) All types of debugging output are enabled. This is equivalent to using @samp{-d}. @item b (@i{basic}) Basic debugging prints each target that was found to be out-of-date, and whether the build was successful or not. @item v (@i{verbose}) A level above @samp{basic}; includes messages about which makefiles were parsed, prerequisites that did not need to be rebuilt, etc. This option also enables @samp{basic} messages. @item i (@i{implicit}) Prints messages describing the implicit rule searches for each target. This option also enables @samp{basic} messages. @item j (@i{jobs}) Prints messages giving details on the invocation of specific sub-commands. @item m (@i{makefile}) By default, debug messages are not enabled while trying to remake the makefiles. This option enables messages while rebuilding makefiles, too. The @samp{all} option enables this option as well. This option also enables @samp{basic} messages. @item p (@i{print}) Prints the recipe to be executed, even when the recipe is normally silent (due to @code{.SILENT} or @samp{@@}). @item w (@i{why}) Explains why each target must be remade by showing which prerequisites are more up to date than the target. @item n (@i{none}) Disable all debugging currently enabled. If additional debugging flags are encountered after this they will still take effect. @end table @item -e @cindex @code{-e} @itemx --environment-overrides @cindex @code{--environment-overrides} Give variables taken from the environment precedence over variables from makefiles. @xref{Environment, ,Variables from the Environment}. @item -E @var{string} @cindex @code{-E} @item --eval=@var{string} @cindex @code{--eval} @c Extra blank line here makes the table look better. Evaluate @var{string} as makefile syntax. This is a command-line version of the @code{eval} function (@pxref{Eval Function}). The evaluation is performed after the default rules and variables have been defined, but before any makefiles are read. @item -f @var{file} @cindex @code{-f} @itemx --file=@var{file} @cindex @code{--file} @itemx --makefile=@var{file} @cindex @code{--makefile} Read the file named @var{file} as a makefile. @xref{Makefiles, ,Writing Makefiles}. @item -h @cindex @code{-h} @itemx --help @cindex @code{--help} @c Extra blank line here makes the table look better. Remind you of the options that @code{make} understands and then exit. @item -i @cindex @code{-i} @itemx --ignore-errors @cindex @code{--ignore-errors} Ignore all errors in recipes executed to remake files. @xref{Errors, ,Errors in Recipes}. @item -I @var{dir} @cindex @code{-I} @itemx --include-dir=@var{dir} @cindex @code{--include-dir} Specifies a directory @var{dir} to search for included makefiles. @xref{Include, ,Including Other Makefiles}. If several @samp{-I} options are used to specify several directories, the directories are searched in the order specified. If the directory @var{dir} is a single dash (@code{-}) then any already-specified directories up to that point (including the default directory paths) will be discarded. You can examine the current list of directories to be searched via the @code{.INCLUDE_DIRS} variable. @item -j [@var{jobs}] @cindex @code{-j} @itemx --jobs[=@var{jobs}] @cindex @code{--jobs} Specifies the number of recipes (jobs) to run simultaneously. With no argument, @code{make} runs as many recipes simultaneously as possible. If there is more than one @samp{-j} option, the last one is effective. @xref{Parallel, ,Parallel Execution}, for more information on how recipes are run. Note that this option is ignored on MS-DOS. @item --jobserver-style=[@var{style}] @cindex @code{--jobserver-style} Chooses the style of jobserver to use. This option only has effect if parallel builds are enabled (@pxref{Parallel, ,Parallel Execution}). On POSIX systems @var{style} can be one of @code{fifo} (the default) or @code{pipe}. On Windows the only acceptable @var{style} is @code{sem} (the default). This option is useful if you need to use an older version of GNU @code{make}, or a different tool that requires a specific jobserver style. @item -k @cindex @code{-k} @itemx --keep-going @cindex @code{--keep-going} Continue as much as possible after an error. While the target that failed, and those that depend on it, cannot be remade, the other prerequisites of these targets can be processed all the same. @xref{Testing, ,Testing the Compilation of a Program}. @item -l [@var{load}] @cindex @code{-l} @itemx --load-average[=@var{load}] @cindex @code{--load-average} @itemx --max-load[=@var{load}] @cindex @code{--max-load} Specifies that no new recipes should be started if there are other recipes running and the load average is at least @var{load} (a floating-point number). With no argument, removes a previous load limit. @xref{Parallel, ,Parallel Execution}. @item -L @cindex @code{-L} @itemx --check-symlink-times @cindex @code{--check-symlink-times} On systems that support symbolic links, this option causes @code{make} to consider the timestamps on any symbolic links in addition to the timestamp on the file referenced by those links. When this option is provided, the most recent timestamp among the file and the symbolic links is taken as the modification time for this target file. @item -n @cindex @code{-n} @itemx --just-print @cindex @code{--just-print} @itemx --dry-run @cindex @code{--dry-run} @itemx --recon @cindex @code{--recon} @c Extra blank line here makes the table look better. Print the recipe that would be executed, but do not execute it (except in certain circumstances). @xref{Instead of Execution, ,Instead of Executing Recipes}. @item -o @var{file} @cindex @code{-o} @itemx --old-file=@var{file} @cindex @code{--old-file} @itemx --assume-old=@var{file} @cindex @code{--assume-old} Do not remake the file @var{file} even if it is older than its prerequisites, and do not remake anything on account of changes in @var{file}. Essentially the file is treated as very old and its rules are ignored. @xref{Avoiding Compilation, ,Avoiding Recompilation of Some Files}. @item -O[@var{type}] @cindex @code{-O} @itemx --output-sync[=@var{type}] @cindex @code{--output-sync} @cindex output during parallel execution @cindex parallel execution, output during Ensure that the complete output from each recipe is printed in one uninterrupted sequence. This option is only useful when using the @code{--jobs} option to run multiple recipes simultaneously (@pxref{Parallel, ,Parallel Execution}) Without this option output will be displayed as it is generated by the recipes. With no type or the type @samp{target}, output from the entire recipe of each target is grouped together. With the type @samp{line}, output from each line in the recipe is grouped together. With the type @samp{recurse}, the output from an entire recursive make is grouped together. With the type @samp{none}, no output synchronization is performed. @xref{Parallel Output, ,Output During Parallel Execution}. @item -p @cindex @code{-p} @itemx --print-data-base @cindex @code{--print-data-base} @cindex data base of @code{make} rules @cindex predefined rules and variables, printing Print the data base (rules and variable values) that results from reading the makefiles; then execute as usual or as otherwise specified. This also prints the version information given by the @samp{-v} switch (see below). To print the data base without trying to remake any files, use @w{@samp{make -qp}}. To print the data base of predefined rules and variables, use @w{@samp{make -p -f /dev/null}}. The data base output contains file name and line number information for recipe and variable definitions, so it can be a useful debugging tool in complex environments. @item --print-targets @cindex @code{--print-targets} @cindex print @file{makefile} targets @cindex targets, printing Print all the targets defined by reading the makefiles, one target per line, then exit immediately with success. No implicit targets are printed. No special targets (target names consisting of ``.'' followed by all upper-case letters) are printed. No commands are run, including commands that would rebuild makefiles (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}); if makefiles need to be rebuilt then the targets listed might be outdated. Also, @code{make} will not generate any errors or warnings for missing @code{include} files. @item -q @cindex @code{-q} @itemx --question @cindex @code{--question} ``Question mode''. Do not run any recipes, or print anything; just return an exit status that is zero if the specified targets are already up to date, one if any remaking is required, or two if an error is encountered. @xref{Instead of Execution, ,Instead of Executing Recipes}. @item -r @cindex @code{-r} @itemx --no-builtin-rules @cindex @code{--no-builtin-rules} Eliminate use of the built-in implicit rules (@pxref{Implicit Rules, ,Using Implicit Rules}). You can still define your own by writing pattern rules (@pxref{Pattern Rules, ,Defining and Redefining Pattern Rules}). The @samp{-r} option also clears out the default list of suffixes for suffix rules (@pxref{Suffix Rules, ,Old-Fashioned Suffix Rules}). But you can still define your own suffixes with a rule for @code{.SUFFIXES}, and then define your own suffix rules. Note that only @emph{rules} are affected by the @code{-r} option; default variables remain in effect (@pxref{Implicit Variables, ,Variables Used by Implicit Rules}); see the @samp{-R} option below. @item -R @cindex @code{-R} @itemx --no-builtin-variables @cindex @code{--no-builtin-variables} Eliminate use of the built-in rule-specific variables (@pxref{Implicit Variables, ,Variables Used by Implicit Rules}). You can still define your own, of course. The @samp{-R} option also automatically enables the @samp{-r} option (see above), since it doesn't make sense to have implicit rules without any definitions for the variables that they use. @item -s @cindex @code{-s} @itemx --silent @cindex @code{--silent} @itemx --quiet @cindex @code{--quiet} @c Extra blank line here makes the table look better. Silent operation; do not print the recipes as they are executed. @xref{Echoing, ,Recipe Echoing}. @item -S @cindex @code{-S} @itemx --no-keep-going @cindex @code{--no-keep-going} @itemx --stop @cindex @code{--stop} @c Extra blank line here makes the table look better. Cancel the effect of the @samp{-k} option. This is never necessary except in a recursive @code{make} where @samp{-k} might be inherited from the top-level @code{make} via @code{MAKEFLAGS} (@pxref{Recursion, ,Recursive Use of @code{make}}) or if you set @samp{-k} in @code{MAKEFLAGS} in your environment. @item --shuffle[=@var{mode}] @cindex @code{--shuffle} @c Extra blank line here makes the table look better. This option enables a form of fuzz-testing of prerequisite relationships. When parallelism is enabled (@samp{-j}) the order in which targets are built becomes less deterministic. If prerequisites are not fully declared in the makefile this can lead to intermittent and hard-to-track-down build failures. The @samp{--shuffle} option forces @code{make} to purposefully reorder goals and prerequisites so target/prerequisite relationships still hold, but ordering of prerequisites of a given target are reordered as described below. The order in which prerequisites are listed in automatic variables is not changed by this option. The @code{.NOTPARALLEL} pseudo-target disables shuffling for that makefile. Also any prerequisite list which contains @code{.WAIT} will not be shuffled. @xref{Parallel Disable, ,Disabling Parallel Execution}. The @samp{--shuffle=} option accepts these values: @table @code @item random Choose a random seed for the shuffle. This is the default if no mode is specified. The chosen seed is also provided to sub-@code{make} commands. The seed is included in error messages so that it can be re-used in future runs to reproduce the problem or verify that it has been resolved. @item reverse Reverse the order of goals and prerequisites, rather than a random shuffle. @item @var{seed} Use @samp{random} shuffle initialized with the specified seed value. The @var{seed} is an integer. @item none Disable shuffling. This negates any previous @samp{--shuffle} options. @end table @item -t @cindex @code{-t} @itemx --touch @cindex @code{--touch} @c Extra blank line here makes the table look better. Touch files (mark them up to date without really changing them) instead of running their recipes. This is used to pretend that the recipes were done, in order to fool future invocations of @code{make}. @xref{Instead of Execution, ,Instead of Executing Recipes}. @item --trace @cindex @code{--trace} Show tracing information for @code{make} execution. Using @code{--trace} is shorthand for @code{--debug=print,why}. @item -v @cindex @code{-v} @itemx --version @cindex @code{--version} Print the version of the @code{make} program plus a copyright, a list of authors, and a notice that there is no warranty; then exit. @item -w @cindex @code{-w} @itemx --print-directory @cindex @code{--print-directory} Print a message containing the working directory both before and after executing the makefile. This may be useful for tracking down errors from complicated nests of recursive @code{make} commands. @xref{Recursion, ,Recursive Use of @code{make}}. (In practice, you rarely need to specify this option since @samp{make} does it for you; see @ref{-w Option, ,The @samp{--print-directory} Option}.) @item --no-print-directory @cindex @code{--no-print-directory} Disable printing of the working directory under @code{-w}. This option is useful when @code{-w} is turned on automatically, but you do not want to see the extra messages. @xref{-w Option, ,The @samp{--print-directory} Option}. @item -W @var{file} @cindex @code{-W} @itemx --what-if=@var{file} @cindex @code{--what-if} @itemx --new-file=@var{file} @cindex @code{--new-file} @itemx --assume-new=@var{file} @cindex @code{--assume-new} Pretend that the target @var{file} has just been modified. When used with the @samp{-n} flag, this shows you what would happen if you were to modify that file. Without @samp{-n}, it is almost the same as running a @code{touch} command on the given file before running @code{make}, except that the modification time is changed only in the imagination of @code{make}. @xref{Instead of Execution, ,Instead of Executing Recipes}. @item --warn[=@var{arg}[,@var{arg}]] @cindex @code{--warn} @cindex warnings Specify the handling of @ref{Warnings, ,Makefile Warnings} detected in makefiles. @item --warn-undefined-variables @cindex @code{--warn-undefined-variables} @cindex variables, warning for undefined @cindex undefined variables, warning message A deprecated name for @code{--warn=undefined-var}. @xref{Warnings, ,Makefile Warnings}. @end table @node Implicit Rules @chapter Using Implicit Rules @cindex implicit rule @cindex rule, implicit Certain standard ways of remaking target files are used very often. For example, one customary way to make an object file is from a C source file using the C compiler, @code{cc}. @dfn{Implicit rules} tell @code{make} how to use customary techniques so that you do not have to specify them in detail when you want to use them. For example, there is an implicit rule for C compilation. File names determine which implicit rules are run. For example, C compilation typically takes a @file{.c} file and makes a @file{.o} file. So @code{make} applies the implicit rule for C compilation when it sees this combination of file name endings. A chain of implicit rules can apply in sequence; for example, @code{make} will remake a @file{.o} file from a @file{.y} file by way of a @file{.c} file. @iftex @xref{Chained Rules, ,Chains of Implicit Rules}. @end iftex The built-in implicit rules use several variables in their recipes so that, by changing the values of the variables, you can change the way the implicit rule works. For example, the variable @code{CFLAGS} controls the flags given to the C compiler by the implicit rule for C compilation. @iftex @xref{Implicit Variables, ,Variables Used by Implicit Rules}. @end iftex You can define your own implicit rules by writing @dfn{pattern rules}. @iftex @xref{Pattern Rules, ,Defining and Redefining Pattern Rules}. @end iftex @dfn{Suffix rules} are a more limited way to define implicit rules. Pattern rules are more general and clearer, but suffix rules are retained for compatibility. @iftex @xref{Suffix Rules, ,Old-Fashioned Suffix Rules}. @end iftex @menu * Using Implicit:: How to use an existing implicit rule to get the recipes for updating a file. * Catalogue of Rules:: A list of built-in rules. * Implicit Variables:: How to change what predefined rules do. * Chained Rules:: How to use a chain of implicit rules. * Pattern Rules:: How to define new implicit rules. * Last Resort:: How to define a recipe for rules which cannot find any. * Suffix Rules:: The old-fashioned style of implicit rule. * Implicit Rule Search:: The precise algorithm for applying implicit rules. @end menu @node Using Implicit @section Using Implicit Rules @cindex implicit rule, how to use @cindex rule, implicit, how to use To allow @code{make} to find a customary method for updating a target file, all you have to do is refrain from specifying recipes yourself. Either write a rule with no recipe, or don't write a rule at all. Then @code{make} will figure out which implicit rule to use based on which kind of source file exists or can be made. For example, suppose the makefile looks like this: @example foo : foo.o bar.o cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS) @end example @noindent Because you mention @file{foo.o} but do not give a rule for it, @code{make} will automatically look for an implicit rule that tells how to update it. This happens whether or not the file @file{foo.o} currently exists. If an implicit rule is found, it can supply both a recipe and one or more prerequisites (the source files). You would want to write a rule for @file{foo.o} with no recipe if you need to specify additional prerequisites, such as header files, that the implicit rule cannot supply. Each implicit rule has a target pattern and prerequisite patterns. There may be many implicit rules with the same target pattern. For example, numerous rules make @samp{.o} files: one, from a @samp{.c} file with the C compiler; another, from a @samp{.p} file with the Pascal compiler; and so on. The rule that actually applies is the one whose prerequisites exist or can be made. So, if you have a file @file{foo.c}, @code{make} will run the C compiler; otherwise, if you have a file @file{foo.p}, @code{make} will run the Pascal compiler; and so on. Of course, when you write the makefile, you know which implicit rule you want @code{make} to use, and you know it will choose that one because you know which possible prerequisite files are supposed to exist. @xref{Catalogue of Rules, ,Catalogue of Built-In Rules}, for a catalogue of all the predefined implicit rules. Above, we said an implicit rule applies if the required prerequisites ``exist or can be made''. A file ``can be made'' if it is mentioned explicitly in the makefile as a target or a prerequisite, or if an implicit rule can be recursively found for how to make it. When an implicit prerequisite is the result of another implicit rule, we say that @dfn{chaining} is occurring. @xref{Chained Rules, ,Chains of Implicit Rules}. In general, @code{make} searches for an implicit rule for each target, and for each double-colon rule, that has no recipe. A file that is mentioned only as a prerequisite is considered a target whose rule specifies nothing, so implicit rule search happens for it. @xref{Implicit Rule Search, ,Implicit Rule Search Algorithm}, for the details of how the search is done. Note that explicit prerequisites do not influence implicit rule search. For example, consider this explicit rule: @example foo.o: foo.p @end example @noindent The prerequisite on @file{foo.p} does not necessarily mean that @code{make} will remake @file{foo.o} according to the implicit rule to make an object file, a @file{.o} file, from a Pascal source file, a @file{.p} file. For example, if @file{foo.c} also exists, the implicit rule to make an object file from a C source file is used instead, because it appears before the Pascal rule in the list of predefined implicit rules (@pxref{Catalogue of Rules, , Catalogue of Built-In Rules}). If you do not want an implicit rule to be used for a target that has no recipe, you can give that target an empty recipe by writing a semicolon (@pxref{Empty Recipes, ,Defining Empty Recipes}). @node Catalogue of Rules @section Catalogue of Built-In Rules @cindex implicit rule, predefined @cindex rule, implicit, predefined Here is a catalogue of predefined implicit rules which are always available unless the makefile explicitly overrides or cancels them. @xref{Canceling Rules, ,Canceling Implicit Rules}, for information on canceling or overriding an implicit rule. The @samp{-r} or @samp{--no-builtin-rules} option cancels all predefined rules. This manual only documents the default rules available on POSIX-based operating systems. Other operating systems, such as VMS, Windows, OS/2, etc. may have different sets of default rules. To see the full list of default rules and variables available in your version of GNU @code{make}, run @samp{make -p} in a directory with no makefile. Not all of these rules will always be defined, even when the @samp{-r} option is not given. Many of the predefined implicit rules are implemented in @code{make} as suffix rules, so which ones will be defined depends on the @dfn{suffix list} (the list of prerequisites of the special target @code{.SUFFIXES}). The default suffix list is: @code{.out}, @code{.a}, @code{.ln}, @code{.o}, @code{.c}, @code{.cc}, @code{.C}, @code{.cpp}, @code{.p}, @code{.f}, @code{.F}, @code{.m}, @code{.r}, @code{.y}, @code{.l}, @code{.ym}, @code{.lm}, @code{.s}, @code{.S}, @code{.mod}, @code{.sym}, @code{.def}, @code{.h}, @code{.info}, @code{.dvi}, @code{.tex}, @code{.texinfo}, @code{.texi}, @code{.txinfo}, @code{.w}, @code{.ch} @code{.web}, @code{.sh}, @code{.elc}, @code{.el}. All of the implicit rules described below whose prerequisites have one of these suffixes are actually suffix rules. If you modify the suffix list, the only predefined suffix rules in effect will be those named by one or two of the suffixes that are on the list you specify; rules whose suffixes fail to be on the list are disabled. @xref{Suffix Rules, ,Old-Fashioned Suffix Rules}, for full details on suffix rules. @table @asis @item Compiling C programs @cindex C, rule to compile @pindex cc @pindex gcc @pindex .o @pindex .c @file{@var{n}.o} is made automatically from @file{@var{n}.c} with a recipe of the form @w{@samp{$(CC) $(CPPFLAGS) $(CFLAGS) -c}}. @item Compiling C++ programs @cindex C++, rule to compile @pindex g++ @pindex .cc @pindex .cpp @pindex .C @file{@var{n}.o} is made automatically from @file{@var{n}.cc}, @file{@var{n}.cpp}, or @file{@var{n}.C} with a recipe of the form @w{@samp{$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c}}. We encourage you to use the suffix @samp{.cc} or @samp{.cpp} for C++ source files instead of @samp{.C} to better support case-insensitive file systems. @item Compiling Pascal programs @cindex Pascal, rule to compile @pindex pc @pindex .p @file{@var{n}.o} is made automatically from @file{@var{n}.p} with the recipe @samp{$(PC) $(PFLAGS) -c}. @item Compiling Fortran and Ratfor programs @cindex Fortran, rule to compile @cindex Ratfor, rule to compile @pindex f77 @pindex .f @pindex .r @pindex .F @file{@var{n}.o} is made automatically from @file{@var{n}.r}, @file{@var{n}.F} or @file{@var{n}.f} by running the Fortran compiler. The precise recipe used is as follows: @table @samp @item .f @samp{$(FC) $(FFLAGS) -c}. @item .F @samp{$(FC) $(FFLAGS) $(CPPFLAGS) -c}. @item .r @samp{$(FC) $(FFLAGS) $(RFLAGS) -c}. @end table @item Preprocessing Fortran and Ratfor programs @file{@var{n}.f} is made automatically from @file{@var{n}.r} or @file{@var{n}.F}. This rule runs just the preprocessor to convert a Ratfor or preprocessable Fortran program into a strict Fortran program. The precise recipe used is as follows: @table @samp @item .F @samp{$(FC) $(CPPFLAGS) $(FFLAGS) -F}. @item .r @samp{$(FC) $(FFLAGS) $(RFLAGS) -F}. @end table @item Compiling Modula-2 programs @cindex Modula-2, rule to compile @pindex m2c @pindex .sym @pindex .def @pindex .mod @file{@var{n}.sym} is made from @file{@var{n}.def} with a recipe of the form @w{@samp{$(M2C) $(M2FLAGS) $(DEFFLAGS)}}. @file{@var{n}.o} is made from @file{@var{n}.mod}; the form is: @w{@samp{$(M2C) $(M2FLAGS) $(MODFLAGS)}}. @need 1200 @item Assembling and preprocessing assembler programs @cindex assembly, rule to compile @pindex as @pindex .s @file{@var{n}.o} is made automatically from @file{@var{n}.s} by running the assembler, @code{as}. The precise recipe is @samp{$(AS) $(ASFLAGS)}. @pindex .S @file{@var{n}.s} is made automatically from @file{@var{n}.S} by running the C preprocessor, @code{cpp}. The precise recipe is @w{@samp{$(CPP) $(CPPFLAGS)}}. @item Linking a single object file @cindex linking, predefined rule for @pindex ld @pindex .o @file{@var{n}} is made automatically from @file{@var{n}.o} by running the C compiler to link the program. The precise recipe used is @w{@samp{$(CC) $(LDFLAGS) @var{n}.o $(LOADLIBES) $(LDLIBS)}}. This rule does the right thing for a simple program with only one source file. It will also do the right thing if there are multiple object files (presumably coming from various other source files), one of which has a name matching that of the executable file. Thus, @example x: y.o z.o @end example @noindent when @file{x.c}, @file{y.c} and @file{z.c} all exist will execute: @example @group cc -c x.c -o x.o cc -c y.c -o y.o cc -c z.c -o z.o cc x.o y.o z.o -o x rm -f x.o rm -f y.o rm -f z.o @end group @end example @noindent In more complicated cases, such as when there is no object file whose name derives from the executable file name, you must write an explicit recipe for linking. Each kind of file automatically made into @samp{.o} object files will be automatically linked by using the compiler (@samp{$(CC)}, @samp{$(FC)} or @samp{$(PC)}; the C compiler @samp{$(CC)} is used to assemble @samp{.s} files) without the @samp{-c} option. This could be done by using the @samp{.o} object files as intermediates, but it is faster to do the compiling and linking in one step, so that's how it's done. @item Yacc for C programs @pindex yacc @cindex Yacc, rule to run @pindex .y @file{@var{n}.c} is made automatically from @file{@var{n}.y} by running Yacc with the recipe @samp{$(YACC) $(YFLAGS)}. @item Lex for C programs @pindex lex @cindex Lex, rule to run @pindex .l @file{@var{n}.c} is made automatically from @file{@var{n}.l} by running Lex. The actual recipe is @samp{$(LEX) $(LFLAGS)}. @item Lex for Ratfor programs @file{@var{n}.r} is made automatically from @file{@var{n}.l} by running Lex. The actual recipe is @samp{$(LEX) $(LFLAGS)}. The convention of using the same suffix @samp{.l} for all Lex files regardless of whether they produce C code or Ratfor code makes it impossible for @code{make} to determine automatically which of the two languages you are using in any particular case. If @code{make} is called upon to remake an object file from a @samp{.l} file, it must guess which compiler to use. It will guess the C compiler, because that is more common. If you are using Ratfor, make sure @code{make} knows this by mentioning @file{@var{n}.r} in the makefile. Or, if you are using Ratfor exclusively, with no C files, remove @samp{.c} from the list of implicit rule suffixes with: @example @group .SUFFIXES: .SUFFIXES: .o .r .f .l @dots{} @end group @end example @item Making Lint Libraries from C, Yacc, or Lex programs @pindex lint @cindex @code{lint}, rule to run @pindex .ln @file{@var{n}.ln} is made from @file{@var{n}.c} by running @code{lint}. The precise recipe is @w{@samp{$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i}}. The same recipe is used on the C code produced from @file{@var{n}.y} or @file{@var{n}.l}. @item @TeX{} and Web @cindex @TeX{}, rule to run @cindex Web, rule to run @pindex tex @pindex cweave @pindex weave @pindex tangle @pindex ctangle @pindex .dvi @pindex .tex @pindex .web @pindex .w @pindex .ch @file{@var{n}.dvi} is made from @file{@var{n}.tex} with the recipe @samp{$(TEX)}. @file{@var{n}.tex} is made from @file{@var{n}.web} with @samp{$(WEAVE)}, or from @file{@var{n}.w} (and from @file{@var{n}.ch} if it exists or can be made) with @samp{$(CWEAVE)}. @file{@var{n}.p} is made from @file{@var{n}.web} with @samp{$(TANGLE)} and @file{@var{n}.c} is made from @file{@var{n}.w} (and from @file{@var{n}.ch} if it exists or can be made) with @samp{$(CTANGLE)}. @item Texinfo and Info @cindex Texinfo, rule to format @cindex Info, rule to format @pindex texi2dvi @pindex makeinfo @pindex .texinfo @pindex .info @pindex .texi @pindex .txinfo @file{@var{n}.dvi} is made from @file{@var{n}.texinfo}, @file{@var{n}.texi}, or @file{@var{n}.txinfo}, with the recipe @w{@samp{$(TEXI2DVI) $(TEXI2DVI_FLAGS)}}. @file{@var{n}.info} is made from @file{@var{n}.texinfo}, @file{@var{n}.texi}, or @file{@var{n}.txinfo}, with the recipe @w{@samp{$(MAKEINFO) $(MAKEINFO_FLAGS)}}. @item RCS @cindex RCS, rule to extract from @pindex co @pindex ,v @r{(RCS file extension)} Any file @file{@var{n}} is extracted if necessary from an RCS file named either @file{@var{n},v} or @file{RCS/@var{n},v}. The precise recipe used is @w{@samp{$(CO) $(COFLAGS)}}. @file{@var{n}} will not be extracted from RCS if it already exists, even if the RCS file is newer. The rules for RCS are terminal (@pxref{Match-Anything Rules, ,Match-Anything Pattern Rules}), so RCS files cannot be generated from another source; they must actually exist. @item SCCS @cindex SCCS, rule to extract from @pindex get @pindex s. @r{(SCCS file prefix)} Any file @file{@var{n}} is extracted if necessary from an SCCS file named either @file{s.@var{n}} or @file{SCCS/s.@var{n}}. The precise recipe used is @w{@samp{$(GET) $(GFLAGS)}}. The rules for SCCS are terminal (@pxref{Match-Anything Rules, ,Match-Anything Pattern Rules}), so SCCS files cannot be generated from another source; they must actually exist. @pindex .sh For the benefit of SCCS, a file @file{@var{n}} is copied from @file{@var{n}.sh} and made executable (by everyone). This is for shell scripts that are checked into SCCS. Since RCS preserves the execution permission of a file, you do not need to use this feature with RCS. We recommend that you avoid using SCCS. RCS is widely held to be superior, and is also free. By choosing free software in place of comparable (or inferior) proprietary software, you support the free software movement. @end table Usually, you want to change only the variables listed in the table above, which are documented in the following section. However, the recipes in built-in implicit rules actually use variables such as @code{COMPILE.c}, @code{LINK.p}, and @code{PREPROCESS.S}, whose values contain the recipes listed above. @code{make} follows the convention that the rule to compile a @file{.@var{x}} source file uses the variable @code{COMPILE.@var{x}}. Similarly, the rule to produce an executable from a @file{.@var{x}} file uses @code{LINK.@var{x}}; and the rule to preprocess a @file{.@var{x}} file uses @code{PREPROCESS.@var{x}}. @vindex OUTPUT_OPTION Every rule that produces an object file uses the variable @code{OUTPUT_OPTION}. @code{make} defines this variable either to contain @samp{-o $@@}, or to be empty, depending on a compile-time option. You need the @samp{-o} option to ensure that the output goes into the right file when the source file is in a different directory, as when using @code{VPATH} (@pxref{Directory Search}). However, compilers on some systems do not accept a @samp{-o} switch for object files. If you use such a system, and use @code{VPATH}, some compilations will put their output in the wrong place. A possible workaround for this problem is to give @code{OUTPUT_OPTION} the value @w{@samp{; mv $*.o $@@}}. @node Implicit Variables @section Variables Used by Implicit Rules @cindex flags for compilers The recipes in built-in implicit rules make liberal use of certain predefined variables. You can alter the values of these variables in the makefile, with arguments to @code{make}, or in the environment to alter how the implicit rules work without redefining the rules themselves. You can cancel all variables used by implicit rules with the @samp{-R} or @samp{--no-builtin-variables} option. For example, the recipe used to compile a C source file actually says @samp{$(CC) -c $(CFLAGS) $(CPPFLAGS)}. The default values of the variables used are @samp{cc} and nothing, resulting in the command @samp{cc -c}. By redefining @samp{CC} to @samp{ncc}, you could cause @samp{ncc} to be used for all C compilations performed by the implicit rule. By redefining @samp{CFLAGS} to be @samp{-g}, you could pass the @samp{-g} option to each compilation. @emph{All} implicit rules that do C compilation use @samp{$(CC)} to get the program name for the compiler and @emph{all} include @samp{$(CFLAGS)} among the arguments given to the compiler. The variables used in implicit rules fall into two classes: those that are names of programs (like @code{CC}) and those that contain arguments for the programs (like @code{CFLAGS}). (The ``name of a program'' may also contain some command arguments, but it must start with an actual executable program name.) If a variable value contains more than one argument, separate them with spaces. The following tables describe some of the more commonly used built-in variables. This list is not exhaustive, and the default values shown here may not be what @code{make} selects for your environment. To see the complete list of predefined variables for your instance of GNU @code{make} you can run @samp{make -p} in a directory with no makefiles. Here is a table of some of the more common variables used as names of programs in built-in rules: @table @code @item AR @vindex AR Archive-maintaining program; default @samp{ar}. @pindex ar @item AS @vindex AS Program for compiling assembly files; default @samp{as}. @pindex as @item CC @vindex CC Program for compiling C programs; default @samp{cc}. @pindex cc @item CXX @vindex CXX Program for compiling C++ programs; default @samp{g++}. @pindex g++ @item CPP @vindex CPP Program for running the C preprocessor, with results to standard output; default @samp{$(CC) -E}. @item FC @vindex FC Program for compiling or preprocessing Fortran and Ratfor programs; default @samp{f77}. @pindex f77 @item M2C @vindex M2C Program to use to compile Modula-2 source code; default @samp{m2c}. @pindex m2c @item PC @vindex PC Program for compiling Pascal programs; default @samp{pc}. @pindex pc @item CO @vindex CO Program for extracting a file from RCS; default @samp{co}. @pindex co @item GET @vindex GET Program for extracting a file from SCCS; default @samp{get}. @pindex get @item LEX @vindex LEX Program to use to turn Lex grammars into source code; default @samp{lex}. @pindex lex @item YACC @vindex YACC Program to use to turn Yacc grammars into source code; default @samp{yacc}. @pindex yacc @item LINT @vindex LINT Program to use to run lint on source code; default @samp{lint}. @pindex lint @item MAKEINFO @vindex MAKEINFO Program to convert a Texinfo source file into an Info file; default @samp{makeinfo}. @pindex makeinfo @item TEX @vindex TEX Program to make @TeX{} @sc{dvi} files from @TeX{} source; default @samp{tex}. @pindex tex @item TEXI2DVI @vindex TEXI2DVI Program to make @TeX{} @sc{dvi} files from Texinfo source; default @samp{texi2dvi}. @pindex texi2dvi @item WEAVE @vindex WEAVE Program to translate Web into @TeX{}; default @samp{weave}. @pindex weave @item CWEAVE @vindex CWEAVE Program to translate C Web into @TeX{}; default @samp{cweave}. @pindex cweave @item TANGLE @vindex TANGLE Program to translate Web into Pascal; default @samp{tangle}. @pindex tangle @item CTANGLE @vindex CTANGLE Program to translate C Web into C; default @samp{ctangle}. @pindex ctangle @item RM @vindex RM Command to remove a file; default @samp{rm -f}. @pindex rm @end table Here is a table of variables whose values are additional arguments for the programs above. The default values for all of these is the empty string, unless otherwise noted. @table @code @item ARFLAGS @vindex ARFLAGS Flags to give the archive-maintaining program; default @samp{rv}. @item ASFLAGS @vindex ASFLAGS Extra flags to give to the assembler (when explicitly invoked on a @samp{.s} or @samp{.S} file). @item CFLAGS @vindex CFLAGS Extra flags to give to the C compiler. @item CXXFLAGS @vindex CXXFLAGS Extra flags to give to the C++ compiler. @item COFLAGS @vindex COFLAGS Extra flags to give to the RCS @code{co} program. @item CPPFLAGS @vindex CPPFLAGS Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). @item FFLAGS @vindex FFLAGS Extra flags to give to the Fortran compiler. @item GFLAGS @vindex GFLAGS Extra flags to give to the SCCS @code{get} program. @item LDFLAGS @vindex LDFLAGS Extra flags to give to compilers when they are supposed to invoke the linker, @samp{ld}, such as @code{-L}. Libraries (@code{-lfoo}) should be added to the @code{LDLIBS} variable instead. @item LDLIBS @vindex LDLIBS @vindex LOADLIBES Library flags or names given to compilers when they are supposed to invoke the linker, @samp{ld}. @code{LOADLIBES} is a deprecated (but still supported) alternative to @code{LDLIBS}. Non-library linker flags, such as @code{-L}, should go in the @code{LDFLAGS} variable. @item LFLAGS @vindex LFLAGS Extra flags to give to Lex. @item YFLAGS @vindex YFLAGS Extra flags to give to Yacc. @item PFLAGS @vindex PFLAGS Extra flags to give to the Pascal compiler. @item RFLAGS @vindex RFLAGS Extra flags to give to the Fortran compiler for Ratfor programs. @item LINTFLAGS @vindex LINTFLAGS Extra flags to give to lint. @end table @node Chained Rules @section Chains of Implicit Rules @cindex chains of rules @cindex rule, implicit, chains of Sometimes a file can be made by a sequence of implicit rules. For example, a file @file{@var{n}.o} could be made from @file{@var{n}.y} by running first Yacc and then @code{cc}. Such a sequence is called a @dfn{chain}. If the file @file{@var{n}.c} exists, or is mentioned in the makefile, no special searching is required: @code{make} finds that the object file can be made by C compilation from @file{@var{n}.c}; later on, when considering how to make @file{@var{n}.c}, the rule for running Yacc is used. Ultimately both @file{@var{n}.c} and @file{@var{n}.o} are updated. @cindex intermediate files @cindex files, intermediate However, even if @file{@var{n}.c} does not exist and is not mentioned, @code{make} knows how to envision it as the missing link between @file{@var{n}.o} and @file{@var{n}.y}! In this case, @file{@var{n}.c} is called an @dfn{intermediate file}. Once @code{make} has decided to use the intermediate file, it is entered in the data base as if it had been mentioned in the makefile, along with the implicit rule that says how to create it. Intermediate files are remade using their rules just like all other files. But intermediate files are treated differently in two ways. The first difference is what happens if the intermediate file does not exist. If an ordinary file @var{b} does not exist, and @code{make} considers a target that depends on @var{b}, it invariably creates @var{b} and then updates the target from @var{b}. But if @var{b} is an intermediate file, then @code{make} can leave well enough alone: it won't create @var{b} unless one of its prerequisites is out of date. This means the target depending on @var{b} won't be rebuilt either, unless there is some other reason to update that target: for example the target doesn't exist or a different prerequisite is newer than the target. The second difference is that if @code{make} @emph{does} create @var{b} in order to update something else, it deletes @var{b} later on after it is no longer needed. Therefore, an intermediate file which did not exist before @code{make} also does not exist after @code{make}. @code{make} reports the deletion to you by printing a @samp{rm} command showing which file it is deleting. You can explicitly mark a file as intermediate by listing it as a prerequisite of the special target @code{.INTERMEDIATE}. This takes effect even if the file is mentioned explicitly in some other way. A file cannot be intermediate if it is mentioned in the makefile as a target or prerequisite, so one way to avoid the deletion of intermediate files is by adding it as a prerequisite to some target. However, doing so can cause make to do extra work when searching pattern rules (@pxref{Implicit Rule Search, ,Implicit Rule Search Algorithm}). As an alternative, listing a file as a prerequisite of the special target @code{.NOTINTERMEDIATE} forces it to not be considered intermediate (just as any other mention of the file will do). Also, listing the target pattern of a pattern rule as a prerequisite of @code{.NOTINTERMEDIATE} ensures that no targets generated using that pattern rule are considered intermediate. You can disable intermediate files completely in your makefile by providing @code{.NOTINTERMEDIATE} as a target with no prerequisites: in that case it applies to every file in the makefile. @cindex intermediate files, preserving @cindex preserving intermediate files @cindex secondary files If you do not want @code{make} to create a file merely because it does not already exist, but you also do not want @code{make} to automatically delete the file, you can mark it as a @dfn{secondary} file. To do this, list it as a prerequisite of the special target @code{.SECONDARY}. Marking a file as secondary also marks it as intermediate. A chain can involve more than two implicit rules. For example, it is possible to make a file @file{foo} from @file{RCS/foo.y,v} by running RCS, Yacc and @code{cc}. Then both @file{foo.y} and @file{foo.c} are intermediate files that are deleted at the end. No single implicit rule can appear more than once in a chain. This means that @code{make} will not even consider such a ridiculous thing as making @file{foo} from @file{foo.o.o} by running the linker twice. This constraint has the added benefit of preventing any infinite loop in the search for an implicit rule chain. There are some special implicit rules to optimize certain cases that would otherwise be handled by rule chains. For example, making @file{foo} from @file{foo.c} could be handled by compiling and linking with separate chained rules, using @file{foo.o} as an intermediate file. But what actually happens is that a special rule for this case does the compilation and linking with a single @code{cc} command. The optimized rule is used in preference to the step-by-step chain because it comes earlier in the ordering of rules. Finally, for performance reasons @code{make} will not consider non-terminal match-anything rules (i.e., @samp{%:}) when searching for a rule to build a prerequisite of an implicit rule (@pxref{Match-Anything Rules}). @node Pattern Rules @section Defining and Redefining Pattern Rules You define an implicit rule by writing a @dfn{pattern rule}. A pattern rule looks like an ordinary rule, except that its target contains the character @samp{%} (exactly one of them). The target is considered a pattern for matching file names; the @samp{%} can match any nonempty substring, while other characters match only themselves. The prerequisites likewise use @samp{%} to show how their names relate to the target name. Thus, a pattern rule @samp{%.o : %.c ; @var{recipe}} describes a process for building any file @file{@var{stem}.o} from another file @file{@var{stem}.c} using the recipe @var{recipe}. It is not possible to create a pattern rule that does not have a recipe; omitting the recipe removes that pattern rule instead (@pxref{Canceling Rules, ,Canceling Implicit Rules}). Note that expansion using @samp{%} in pattern rules occurs @strong{after} any variable or function expansions, which take place when the makefile is read. @xref{Using Variables, , How to Use Variables}, and @ref{Functions, ,Functions for Transforming Text}. @menu * Pattern Intro:: An introduction to pattern rules. * Pattern Examples:: Examples of pattern rules. * Automatic Variables:: How to use automatic variables in the recipe of implicit rules. * Pattern Match:: How patterns match. * Match-Anything Rules:: Precautions you should take prior to defining rules that can match any target file whatever. * Canceling Rules:: How to override or cancel built-in rules. @end menu @node Pattern Intro @subsection Introduction to Pattern Rules @cindex pattern rule @cindex rule, pattern A pattern rule contains the character @samp{%} (exactly one of them) in the target; otherwise, it looks exactly like an ordinary rule. The target is a pattern for matching file names; the @samp{%} matches any nonempty substring, while other characters match only themselves. @cindex target pattern, implicit @cindex @code{%}, in pattern rules For example, @samp{%.c} as a pattern matches any file name that ends in @samp{.c}. @samp{s.%.c} as a pattern matches any file name that starts with @samp{s.}, ends in @samp{.c} and is at least five characters long. (There must be at least one character to match the @samp{%}.) The substring that the @samp{%} matches is called the @dfn{stem}. @samp{%} in a prerequisite of a pattern rule stands for the same stem that was matched by the @samp{%} in the target. In order for the pattern rule to apply, its target pattern must match the file name under consideration and all of its prerequisites (after pattern substitution) must name files that exist or can be made. These files become prerequisites of the target. @cindex prerequisite pattern, implicit Thus, a rule of the form @example %.o : %.c ; @var{recipe}@dots{} @end example @noindent specifies how to make a file @file{@var{n}.o}, with another file @file{@var{n}.c} as its prerequisite, provided that @file{@var{n}.c} exists or can be made. There may also be prerequisites that do not use @samp{%}; such a prerequisite attaches to every file made by this pattern rule. These unvarying prerequisites are useful occasionally. A pattern rule need not have any prerequisites that contain @samp{%}, or in fact any prerequisites at all. Such a rule is effectively a general wildcard. It provides a way to make any file that matches the target pattern. @xref{Last Resort}. More than one pattern rule may match a target. In this case @code{make} will choose the ``best fit'' rule. @xref{Pattern Match, ,How Patterns Match}. @cindex multiple targets, in pattern rule @cindex target, multiple in pattern rule Pattern rules may have more than one target; however, every target must contain a @code{%} character. Multiple target patterns in pattern rules are always treated as grouped targets (@pxref{Multiple Targets, , Multiple Targets in a Rule}) regardless of whether they use the @code{:} or @code{&:} separator. There is one exception: if a pattern target is out of date or does not exist and the makefile does not need to build it, then it will not cause the other targets to be considered out of date. Note that this historical exception will be removed in future versions of GNU @code{make} and should not be relied on. If this situation is detected @code{make} will generate a warning @emph{pattern recipe did not update peer target}; however, @code{make} cannot detect all such situations. Please be sure that your recipe updates @emph{all} the target patterns when it runs. @node Pattern Examples @subsection Pattern Rule Examples Here are some examples of pattern rules actually predefined in @code{make}. First, the rule that compiles @samp{.c} files into @samp{.o} files: @example %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@@ @end example @noindent defines a rule that can make any file @file{@var{x}.o} from @file{@var{x}.c}. The recipe uses the automatic variables @samp{$@@} and @samp{$<} to substitute the names of the target file and the source file in each case where the rule applies (@pxref{Automatic Variables}). Here is a second built-in rule: @example % :: RCS/%,v $(CO) $(COFLAGS) $< @end example @noindent defines a rule that can make any file @file{@var{x}} whatsoever from a corresponding file @file{@var{x},v} in the sub-directory @file{RCS}. Since the target is @samp{%}, this rule will apply to any file whatever, provided the appropriate prerequisite file exists. The double colon makes the rule @dfn{terminal}, which means that its prerequisite may not be an intermediate file (@pxref{Match-Anything Rules, ,Match-Anything Pattern Rules}). @need 500 This pattern rule has two targets: @example @group %.tab.c %.tab.h: %.y bison -d $< @end group @end example @noindent @c The following paragraph is rewritten to avoid overfull hboxes This tells @code{make} that the recipe @samp{bison -d @var{x}.y} will make both @file{@var{x}.tab.c} and @file{@var{x}.tab.h}. If the file @file{foo} depends on the files @file{parse.tab.o} and @file{scan.o} and the file @file{scan.o} depends on the file @file{parse.tab.h}, when @file{parse.y} is changed, the recipe @samp{bison -d parse.y} will be executed only once, and the prerequisites of both @file{parse.tab.o} and @file{scan.o} will be satisfied. (Presumably the file @file{parse.tab.o} will be recompiled from @file{parse.tab.c} and the file @file{scan.o} from @file{scan.c}, while @file{foo} is linked from @file{parse.tab.o}, @file{scan.o}, and its other prerequisites, and it will execute happily ever after.) @node Automatic Variables @subsection Automatic Variables @cindex automatic variables @cindex variables, automatic @cindex variables, and implicit rule Suppose you are writing a pattern rule to compile a @samp{.c} file into a @samp{.o} file: how do you write the @samp{cc} command so that it operates on the right source file name? You cannot write the name in the recipe, because the name is different each time the implicit rule is applied. What you do is use a special feature of @code{make}, the @dfn{automatic variables}. These variables have values computed afresh for each rule that is executed, based on the target and prerequisites of the rule. In this example, you would use @samp{$@@} for the object file name and @samp{$<} for the source file name. @cindex automatic variables in prerequisites @cindex prerequisites, and automatic variables It's very important that you recognize the limited scope in which automatic variable values are available: they only have values within the recipe. In particular, you cannot use them anywhere within the target list of a rule; they have no value there and will expand to the empty string. Also, they cannot be accessed directly within the prerequisite list of a rule. A common mistake is attempting to use @code{$@@} within the prerequisites list; this will not work. However, there is a special feature of GNU @code{make}, secondary expansion (@pxref{Secondary Expansion}), which will allow automatic variable values to be used in prerequisite lists. Here is a table of automatic variables: @table @code @vindex $@@ @vindex @@ @r{(automatic variable)} @item $@@ The file name of the target of the rule. If the target is an archive member, then @samp{$@@} is the name of the archive file. In a pattern rule that has multiple targets (@pxref{Pattern Intro, ,Introduction to Pattern Rules}), @samp{$@@} is the name of whichever target caused the rule's recipe to be run. @vindex $% @vindex % @r{(automatic variable)} @item $% The target member name, when the target is an archive member. @xref{Archives}. For example, if the target is @file{foo.a(bar.o)} then @samp{$%} is @file{bar.o} and @samp{$@@} is @file{foo.a}. @samp{$%} is empty when the target is not an archive member. @vindex $< @vindex < @r{(automatic variable)} @item $< The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (@pxref{Implicit Rules}). @vindex $? @vindex ? @r{(automatic variable)} @item $? The names of all the prerequisites that are newer than the target, with spaces between them. If the target does not exist, all prerequisites will be included. For prerequisites which are archive members, only the named member is used (@pxref{Archives}). @samp{$?} is useful even in explicit rules when you wish to operate on only the prerequisites that have changed. For example, suppose that an archive named @file{lib} is supposed to contain copies of several object files. This rule copies just the changed object files into the archive: @example @group lib: foo.o bar.o lose.o win.o ar r lib $? @end group @end example @cindex prerequisites, list of changed @cindex list of changed prerequisites @vindex $^ @vindex ^ @r{(automatic variable)} @item $^ The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the named member is used (@pxref{Archives}). A target has only one prerequisite on each other file it depends on, no matter how many times each file is listed as a prerequisite. So if you list a prerequisite more than once for a target, the value of @code{$^} contains just one copy of the name. This list does @strong{not} contain any of the order-only prerequisites; for those see the @samp{$|} variable, below. @cindex prerequisites, list of all @cindex list of all prerequisites @vindex $+ @vindex + @r{(automatic variable)} @item $+ This is like @samp{$^}, but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order. @vindex $| @vindex | @r{(automatic variable)} @item $| The names of all the order-only prerequisites, with spaces between them. @vindex $* @vindex * @r{(automatic variable)} @item $* The stem with which an implicit rule matches (@pxref{Pattern Match, ,How Patterns Match}). If the target is @file{dir/a.foo.b} and the target pattern is @file{a.%.b} then the stem is @file{dir/foo}. The stem is useful for constructing names of related files. @cindex stem, variable for In a static pattern rule, the stem is part of the file name that matched the @samp{%} in the target pattern. In an explicit rule, there is no stem; so @samp{$*} cannot be determined in that way. Instead, if the target name ends with a recognized suffix (@pxref{Suffix Rules, ,Old-Fashioned Suffix Rules}), @samp{$*} is set to the target name minus the suffix. For example, if the target name is @samp{foo.c}, then @samp{$*} is set to @samp{foo}, since @samp{.c} is a suffix. GNU @code{make} does this bizarre thing only for compatibility with other implementations of @code{make}. You should generally avoid using @samp{$*} except in implicit rules or static pattern rules. If the target name in an explicit rule does not end with a recognized suffix, @samp{$*} is set to the empty string for that rule. @end table Of the variables listed above, four have values that are single file names, and three have values that are lists of file names. These seven have variants that get just the file's directory name or just the file name within the directory. The variant variables' names are formed by appending @samp{D} or @samp{F}, respectively. The functions @code{dir} and @code{notdir} can be used to obtain a similar effect (@pxref{File Name Functions, , Functions for File Names}). Note, however, that the @samp{D} variants all omit the trailing slash which always appears in the output of the @code{dir} function. Here is a table of the variants: @table @samp @vindex $(@@D) @vindex @@D @r{(automatic variable)} @item $(@@D) The directory part of the file name of the target, with the trailing slash removed. If the value of @samp{$@@} is @file{dir/foo.o} then @samp{$(@@D)} is @file{dir}. This value is @file{.} if @samp{$@@} does not contain a slash. @vindex $(@@F) @vindex @@F @r{(automatic variable)} @item $(@@F) The file-within-directory part of the file name of the target. If the value of @samp{$@@} is @file{dir/foo.o} then @samp{$(@@F)} is @file{foo.o}. @samp{$(@@F)} is equivalent to @samp{$(notdir $@@)}. @vindex $(*D) @vindex *D @r{(automatic variable)} @item $(*D) @vindex $(*F) @vindex *F @r{(automatic variable)} @itemx $(*F) The directory part and the file-within-directory part of the stem; @file{dir} and @file{foo} in this example. @vindex $(%D) @vindex %D @r{(automatic variable)} @item $(%D) @vindex $(%F) @vindex %F @r{(automatic variable)} @itemx $(%F) The directory part and the file-within-directory part of the target archive member name. This makes sense only for archive member targets of the form @file{@var{archive}(@var{member})} and is useful only when @var{member} may contain a directory name. (@xref{Archive Members, ,Archive Members as Targets}.) @vindex $(_gmk_unload (void); @end example If the function does not exist, it will not be called. Note that only one unload function may be defined per loaded object, regardless of how many different setup methods are provided in that loaded object. If your loaded object provides multiple setup methods that require unload support it's up to you to coordinate which setups have been invoked in the unload function. @node Initializing Functions @subsection Initializing Functions @cindex loaded object initializing function @cindex initializing function, for loaded objects The initializing function defined by the loaded object must have this signature: @example int (unsigned int abi_version, const gmk_floc *floc); @end example Where @emph{} is described in the previous section. The @code{abi_version} value will be the value of the @code{GMK_ABI_VERSION} constant (see the @file{gnumake.h} file) for this GNU Make release. The @code{floc} pointer provides the file name and line number of the invocation of the @code{load} operation. The initializing function should return an @code{int}, which must be @code{0} on failure and non-@code{0} on success. If the return value is @code{-1}, then GNU Make will @emph{not} attempt to rebuild the object file (@pxref{Remaking Loaded Objects, ,How Loaded Objects Are Remade}). @node Remaking Loaded Objects @subsection How Loaded Objects Are Remade @cindex updating loaded objects @cindex remaking loaded objects @cindex loaded objects, remaking of Loaded objects undergo the same re-make procedure as makefiles (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}). If any loaded object is recreated, then @code{make} will start from scratch and re-read all the makefiles, and reload the object files again. It is not necessary for the loaded object to do anything special to support this. It's up to the makefile author to provide the rules needed for rebuilding the loaded object. @node Loaded Object API @subsection Loaded Object Interface @cindex loaded object API @cindex interface for loaded objects To be useful, loaded objects must be able to interact with GNU @code{make}. This interaction includes both interfaces the loaded object provides to makefiles and also interfaces @code{make} provides to the loaded object to manipulate @code{make}'s operation. The interface between loaded objects and @code{make} is defined by the @file{gnumake.h} C header file. All loaded objects written in C should include this header file. Any loaded object not written in C will need to implement the interface defined in this header file. Typically, a loaded object will register one or more new GNU @code{make} functions using the @code{gmk_add_function} routine from within its setup function. The implementations of these @code{make} functions may make use of the @code{gmk_expand} and @code{gmk_eval} routines to perform their tasks, then optionally return a string as the result of the function expansion. @subsubheading Loaded Object Licensing @cindex loaded object licensing @cindex plugin_is_GPL_compatible Every dynamic extension should define the global symbol @code{plugin_is_GPL_compatible} to assert that it has been licensed under a GPL-compatible license. If this symbol does not exist, @code{make} emits a fatal error and exits when it tries to load your extension. The declared type of the symbol should be @code{int}. It does not need to be in any allocated section, though. The code merely asserts that the symbol exists in the global scope. Something like this is enough: @example int plugin_is_GPL_compatible; @end example @subsubheading Data Structures @table @code @item gmk_floc This structure represents a filename/location pair. It is provided when defining items, so GNU @code{make} can inform the user where the definition occurred if necessary. @end table @subsubheading Checking Versions @findex gmk_get_version The @code{gmk_get_version} allows loaded objects to check which loaded object API version is supported by GNU Make. The API version is specified as two values: the @emph{major} version and the @emph{minor} version. Note, these two values are not the same as the version of GNU Make! The @emph{major} version is incremented when there is a change to the loaded object ABI, which might cause . It is called as: @example void gmk_get_version (unsigned int *major, unsigned int *minor); @end example @table @code @item major If not NULL, the major version number is placed here. @item minor If not NULL, the minor version number is placed here. @end table @subsubheading Registering Functions @findex gmk_add_function There is currently one way for makefiles to invoke operations provided by the loaded object: through the @code{make} function call interface. A loaded object can register one or more new functions which may then be invoked from within the makefile in the same way as any other function. Use @code{gmk_add_function} to create a new @code{make} function. Its arguments are as follows: @table @code @item name The function name. This is what the makefile should use to invoke the function. The name must be between 1 and 255 characters long and it may only contain alphanumeric, period (@samp{.}), dash (@samp{-}), and underscore (@samp{_}) characters. It may not begin with a period. @item func_ptr A pointer to a function that @code{make} will invoke when it expands the function in a makefile. This function must be defined by the loaded object. @item min_args The minimum number of arguments the function will accept. Must be between 0 and 255. GNU @code{make} will check this and fail before invoking @code{func_ptr} if the function was invoked with too few arguments. @item max_args The maximum number of arguments the function will accept. Must be between 0 and 255. GNU @code{make} will check this and fail before invoking @code{func_ptr} if the function was invoked with too many arguments. If the value is 0, then any number of arguments is accepted. If the value is greater than 0, then it must be greater than or equal to @code{min_args}. @item flags Flags that specify how this function will operate; the desired flags should be OR'd together. If the @code{GMK_FUNC_NOEXPAND} flag is given then the function arguments will not be expanded before the function is called; otherwise they will be expanded first. @end table @subsubheading Registered Function Interface @findex gmk_func_ptr A function registered with @code{make} must match the @code{gmk_func_ptr} type. It will be invoked with three parameters: @code{name} (the name of the function), @code{argc} (the number of arguments to the function), and @code{argv} (an array of pointers to arguments to the function). The last pointer (that is, @code{argv[argc]}) will be null (@code{0}). The return value of the function is the result of expanding the function. If the function expands to nothing the return value may be null. Otherwise, it must be a pointer to a string created with @code{gmk_alloc}. Once the function returns, @code{make} owns this string and will free it when appropriate; it cannot be accessed by the loaded object. @subsubheading GNU @code{make} Facilities There are some facilities exported by GNU @code{make} for use by loaded objects. Typically these would be run from within the setup function and/or the functions registered via @code{gmk_add_function}, to retrieve or modify the data @code{make} works with. @table @code @item gmk_expand @findex gmk_expand This function takes a string and expands it using @code{make} expansion rules. The result of the expansion is returned in a nil-terminated string buffer. The caller is responsible for calling @code{gmk_free} with a pointer to the returned buffer when done. @item gmk_eval @findex gmk_eval This function takes a buffer and evaluates it as a segment of makefile syntax. This function can be used to define new variables, new rules, etc. It is equivalent to using the @code{eval} @code{make} function. @end table Note that there is a difference between @code{gmk_eval} and calling @code{gmk_expand} with a string using the @code{eval} function: in the latter case the string will be expanded @emph{twice}; once by @code{gmk_expand} and then again by the @code{eval} function. Using @code{gmk_eval} the buffer is only expanded once, at most (as it's read by the @code{make} parser). @subsubheading Memory Management Some systems allow for different memory management schemes. Thus you should never pass memory that you've allocated directly to any @code{make} function, nor should you attempt to directly free any memory returned to you by any @code{make} function. Instead, use the @code{gmk_alloc} and @code{gmk_free} functions. In particular, the string returned to @code{make} by a function registered using @code{gmk_add_function} @emph{must} be allocated using @code{gmk_alloc}, and the string returned from the @code{make} @code{gmk_expand} function @emph{must} be freed (when no longer needed) using @code{gmk_free}. @table @code @item gmk_alloc @findex gmk_alloc Return a pointer to a newly-allocated buffer. This function will always return a valid pointer; if not enough memory is available @code{make} will exit. @code{gmk_alloc} does not initialize allocated memory. @item gmk_free @findex gmk_free Free a buffer returned to you by @code{make}. Once the @code{gmk_free} function returns the string will no longer be valid. If NULL is passed to @code{gmk_free}, no operation is performed. @end table @node Loaded Object Example @subsection Example Loaded Object @cindex loaded object example @cindex example of loaded objects Let's suppose we wanted to write a new GNU @code{make} function that would create a temporary file and return its name. We would like our function to take a prefix as an argument. First we can write the function in a file @file{mk_temp.c}: @example @group #include #include #include #include #include #include int plugin_is_GPL_compatible; struct tmpfile @{ struct tmpfile *next; char *name; @}; static struct tmpfile *files = NULL; @end group @group static char * gen_tmpfile(const char *nm, unsigned int argc, char **argv) @{ int fd; /* Compute the size of the filename and allocate space for it. */ int len = strlen (argv[0]) + 6 + 1; char *buf = gmk_alloc (len); strcpy (buf, argv[0]); strcat (buf, "XXXXXX"); fd = mkstemp(buf); if (fd >= 0) @{ struct tmpfile *new = malloc (sizeof (struct tmpfile)); new->name = strdup (buf); new->next = files; files = new; /* Don't leak the file descriptor. */ close (fd); return buf; @} /* Failure. */ fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno)); gmk_free (buf); return NULL; @} @end group @group int mk_temp_gmk_setup (unsigned int abi, const gmk_floc *floc) @{ printf ("mk_temp abi %u plugin loaded from %s:%lu\n", abi, floc->filenm, floc->lineno); /* Register the function with make name "mk-temp". */ gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1); return 1; @} @end group @group void mk_temp_gmk_close () @{ while (files) @{ struct tmpfile *f = files; files = f->next; printf ("mk_temp removing %s\n", f->name); remove (f->name); free (f->name); free (f); @} printf ("mk_temp plugin closed\n"); @} @end group @end example Next, we will write a @file{Makefile} that can build this shared object, load it, and use it: @example @group all: @@echo Temporary file: $(mk-temp tmpfile.) @@echo Temporary file: $(mk-temp tmpfile.) -load mk_temp.so mk_temp.so: mk_temp.c $(CC) -shared -fPIC -o $@@ $< @end group @end example On MS-Windows, due to peculiarities of how shared objects are produced, the compiler needs to scan the @dfn{import library} produced when building @code{make}, typically called @file{libgnumake-@var{version}.dll.a}, where @var{version} is the version of the load object API. So the recipe to produce a shared object will look like this on Windows (assuming the API version is 1): @example @group mk_temp.dll: mk_temp.c $(CC) -shared -o $@@ $< -lgnumake-1 @end group @end example Now when you run @code{make} you'll see something like: @example @group $ make cc -shared -fPIC -o mk_temp.so mk_temp.c mk_temp abi 1 plugin loaded from Makefile:5 Temporary file: tmpfile.OYkGMT Temporary file: tmpfile.sYsJO0 mk_temp removing tmpfile.sYsJO0 mk_temp removing tmpfile.OYkGMT mk_temp plugin closed @end group @end example @node Integrating make @chapter Integrating GNU @code{make} @cindex make integration GNU @code{make} is often one component in a larger system of tools, including integrated development environments, compiler toolchains, and others. The role of @code{make} is to start commands and determine whether they succeeded or not: no special integration is needed to accomplish that. However, sometimes it is convenient to bind @code{make} more tightly with other parts of the system, both higher-level (tools that invoke @code{make}) and lower-level (tools that @code{make} invokes). @menu * Job Slots:: Share job slots with GNU Make. * Terminal Output:: Control output to terminals. @end menu @node Job Slots @section Sharing Job Slots with GNU @code{make} @cindex job slots, sharing @cindex tools, sharing job slots GNU @code{make} has the ability to run multiple recipes in parallel (@pxref{Parallel, ,Parallel Execution}) and to cap the total number of parallel jobs even across recursive invocations of @code{make} (@pxref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}). Tools that @code{make} invokes which are also able to run multiple operations in parallel, either using multiple threads or multiple processes, can be enhanced to participate in GNU @code{make}'s job management facility to ensure that the total number of active threads/processes running on the system does not exceed the maximum number of slots provided to GNU @code{make}. @cindex jobserver GNU @code{make} uses a method called the ``jobserver'' to control the number of active jobs across recursive invocations. The actual implementation of the jobserver varies across different operating systems, but some fundamental aspects are always true. @cindex @code{--jobserver-auth} First, @code{make} will provide information necessary for accessing the jobserver through the environment to its children, in the @code{MAKEFLAGS} environment variable. Tools which want to participate in the jobserver protocol will need to parse this environment variable and find the word starting with @code{--jobserver-auth=}. The value of this option will describe how to communicate with the jobserver. The interpretation of this value is described in the sections below. Be aware that the @code{MAKEFLAGS} variable may contain multiple instances of the @code{--jobserver-auth=} option. Only the @emph{last} instance is relevant. Second, every command @code{make} starts has one implicit job slot reserved for it before it starts. Any tool which wants to participate in the jobserver protocol should assume it can always run one job without having to contact the jobserver at all. Finally, it's critical that tools that participate in the jobserver protocol return the exact number of slots they obtained from the jobserver back to the jobserver before they exit, even under error conditions. Remember that the implicit job slot should @strong{not} be returned to the jobserver! Returning too few slots means that those slots will be lost for the rest of the build process; returning too many slots means that extra slots will be available. The top-level @code{make} command will print an error message at the end of the build if it detects an incorrect number of slots available in the jobserver. As an example, suppose you are implementing a linker which provides for multi-threaded operation. You would like to enhance the linker so that if it is invoked by GNU @code{make} it can participate in the jobserver protocol to control how many threads are used during link. First you will need to modify the linker to determine if the @code{MAKEFLAGS} environment variable is set. Next you will need to parse the value of that variable to determine if the jobserver is available, and how to access it. If it is available then you can access it to obtain job slots controlling how much parallelism your tool can use. Once done your tool must return those job slots back to the jobserver. @menu * POSIX Jobserver:: Using the jobserver on POSIX systems. * Windows Jobserver:: Using the jobserver on Windows systems. @end menu @node POSIX Jobserver @subsection POSIX Jobserver Interaction @cindex jobserver on POSIX On POSIX systems the jobserver is implemented in one of two ways: on systems that support it, GNU @code{make} will create a named pipe and use that for the jobserver. In this case the auth option will have the form @code{--jobserver-auth=fifo:PATH} where @samp{PATH} is the pathname of the named pipe. To access the jobserver you should open the named pipe path and read/write to it as described below. @cindex @code{--jobserver-style} If the system doesn't support named pipes, or if the user provided the @code{--jobserver-style} option and specified @samp{pipe}, then the jobserver will be implemented as a simple UNIX pipe. In this case the auth option will have the form @code{--jobserver-auth=R,W} where @samp{R} and @samp{W} are non-negative integers representing file descriptors: @samp{R} is the read file descriptor and @samp{W} is the write file descriptor. If either or both of these file descriptors are negative, it means the jobserver is disabled for this process. When using a simple pipe, only command lines that @code{make} understands to be recursive invocations of @code{make} (@pxref{MAKE Variable, ,How the @code{MAKE} Variable Works}) will have access to the jobserver. When writing makefiles you must be sure to mark the command as recursive (most commonly by prefixing the command line with the @code{+} indicator (@pxref{Recursion, ,Recursive Use of @code{make}}). Note that the read side of the jobserver pipe is set to ``blocking'' mode. This should not be changed. In both implementations of the jobserver, the pipe will be pre-loaded with one single-character token for each available job. To obtain an extra slot you must read a single character from the jobserver; to release a slot you must write a single character back into the jobserver. It's important that when you release the job slot, you write back the same character you read. Don't assume that all tokens are the same character; different characters may have different meanings to GNU @code{make}. The order is not important, since @code{make} has no idea in what order jobs will complete anyway. There are various error conditions you must consider to ensure your implementation is robust: @itemize @bullet @item If you have a command-line argument controlling the parallel operation of your tool, consider whether your tool should detect situations where both the jobserver and the command-line argument are specified, and how it should react. @item If your tool does not recognize the format of the @code{--jobserver-auth} string, it should assume the jobserver is using a different style and it cannot connect. @item If your tool determines that the @code{--jobserver-auth} option references a simple pipe but that the file descriptors specified are closed, this means that the calling @code{make} process did not think that your tool was a recursive @code{make} invocation (e.g., the command line was not prefixed with a @code{+} character). You should notify your users of this situation. @item Your tool should be sure to write back the tokens it read, even under error conditions. This includes not only errors in your tool but also outside influences such as interrupts (@code{SIGINT}), etc. You may want to install signal handlers to manage this write-back. @item Your tool may also examine the first word of the @code{MAKEFLAGS} variable and look for the character @code{n}. If this character is present then @code{make} was invoked with the @samp{-n} option and your tool may want to stop without performing any operations. @end itemize @node Windows Jobserver @subsection Windows Jobserver Interaction @cindex jobserver on Windows On Windows systems the jobserver is implemented as a named semaphore. The semaphore will be set with an initial count equal to the number of available slots; to obtain a slot you must wait on the semaphore (with or without a timeout). To release a slot, release the semaphore. To access the semaphore you must parse the @code{MAKEFLAGS} variable and look for the argument string @code{--jobserver-auth=NAME} where @samp{NAME} is the name of the named semaphore. Use this name with @code{OpenSemaphore} to create a handle to the semaphore. @cindex @code{--jobserver-style} for Windows The only valid style for @code{--jobserver-style} is @samp{sem}. There are various error conditions you must consider to ensure your implementation is robust: @itemize @bullet @item Usually you will have a command-line argument controlling the parallel operation of your tool. Consider whether your tool should detect situations where both the jobserver and the command-line argument are specified, and how it should react. @item Your tool should be sure to release the semaphore for the tokens it read, even under error conditions. This includes not only errors in your tool but also outside influences such as interrupts (@code{SIGINT}), etc. You may want to install signal handlers to manage this write-back. @end itemize @node Terminal Output @section Synchronized Terminal Output @cindex parallel output to terminal @cindex terminal, output to Normally GNU @code{make} will invoke all commands with access to the same standard and error outputs that @code{make} itself was started with. A number of tools will detect whether the output is a terminal or not-a-terminal, and use this information to change the output style. For example if the output goes to a terminal the tool may add control characters that set color, or even change the location of the cursor. If the output is not going to a terminal then these special control characters are not emitted so that they don't corrupt log files, etc. The @code{--output-sync} (@pxref{Parallel Output, ,Output During Parallel Execution}) option will defeat the terminal detection. When output synchronization is enabled GNU @code{make} arranges for all command output to be written to a file, so that its output can be written as a block without interference from other commands. This means that all tools invoked by @code{make} will believe that their output is not going to be displayed on a terminal, even when it will be (because @code{make} will display it there after the command is completed). In order to facilitate tools which would like to determine whether or not their output will be displayed on a terminal, GNU @code{make} will set the @code{MAKE_TERMOUT} and @code{MAKE_TERMERR} environment variables before invoking any commands. Tools which would like to determine whether standard or error output (respectively) will be displayed on a terminal can check these environment variables to determine if they exist and contain a non-empty value. If so the tool can assume that the output will (eventually) be displayed on a terminal. If the variables are not set or have an empty value, then the tool should fall back to its normal methods of detecting whether output is going to a terminal or not. The content of the variables can be parsed to determine the type of terminal which will be used to display the output. Similarly, environments which invoke @code{make} and would like to capture the output and eventually display it on a terminal (or some display which can interpret terminal control characters) can set these variables before invoking @code{make}. GNU @code{make} will not modify these environment variables if they already exist when it starts. @node Features @chapter Features of GNU @code{make} @cindex features of GNU @code{make} @cindex portability @cindex compatibility Here is a summary of the features of GNU @code{make}, for comparison with and credit to other versions of @code{make}. We consider the features of @code{make} in 4.2 BSD systems as a baseline. If you are concerned with writing portable makefiles, you should not use the features of @code{make} listed here, nor the ones in @ref{Missing}. Many features come from the version of @code{make} in System V. @itemize @bullet @item The @code{VPATH} variable and its special meaning. @xref{Directory Search, , Searching Directories for Prerequisites}. This feature exists in System V @code{make}, but is undocumented. It is documented in 4.3 BSD @code{make} (which says it mimics System V's @code{VPATH} feature). @item Included makefiles. @xref{Include, ,Including Other Makefiles}. Allowing multiple files to be included with a single directive is a GNU extension. @item Variables are read from and communicated via the environment. @xref{Environment, ,Variables from the Environment}. @item Options passed through the variable @code{MAKEFLAGS} to recursive invocations of @code{make}. @xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. @item The automatic variable @code{$%} is set to the member name in an archive reference. @xref{Automatic Variables}. @item The automatic variables @code{$@@}, @code{$*}, @code{$<}, @code{$%}, and @code{$?} have corresponding forms like @code{$(@@F)} and @code{$(@@D)}. We have generalized this to @code{$^} as an obvious extension. @xref{Automatic Variables}. @item Substitution variable references. @xref{Reference, ,Basics of Variable References}. @item The command line options @samp{-b} and @samp{-m}, accepted and ignored. In System V @code{make}, these options actually do something. @item Execution of recursive commands to run @code{make} via the variable @code{MAKE} even if @samp{-n}, @samp{-q} or @samp{-t} is specified. @xref{Recursion, ,Recursive Use of @code{make}}. @item Support for suffix @samp{.a} in suffix rules. @xref{Archive Suffix Rules}. This feature is obsolete in GNU @code{make}, because the general feature of rule chaining (@pxref{Chained Rules, ,Chains of Implicit Rules}) allows one pattern rule for installing members in an archive (@pxref{Archive Update}) to be sufficient. @item The arrangement of lines and backslash/newline combinations in recipes is retained when the recipes are printed, so they appear as they do in the makefile, except for the stripping of initial whitespace. @end itemize The following features were inspired by various other versions of @code{make}. In some cases it is unclear exactly which versions inspired which others. @itemize @bullet @item Pattern rules using @samp{%}. This has been implemented in several versions of @code{make}. We're not sure who invented it first, but it's been spread around a bit. @xref{Pattern Rules, ,Defining and Redefining Pattern Rules}. @item Rule chaining and implicit intermediate files. This was implemented by Stu Feldman in his version of @code{make} for AT&T Eighth Edition Research Unix, and later by Andrew Hume of AT&T Bell Labs in his @code{mk} program (where he terms it ``transitive closure''). We do not really know if we got this from either of them or thought it up ourselves at the same time. @xref{Chained Rules, ,Chains of Implicit Rules}. @item The automatic variable @code{$^} containing a list of all prerequisites of the current target. We did not invent this, but we have no idea who did. @xref{Automatic Variables}. The automatic variable @code{$+} is a simple extension of @code{$^}. @item The ``what if'' flag (@samp{-W} in GNU @code{make}) was (as far as we know) invented by Andrew Hume in @code{mk}. @xref{Instead of Execution, ,Instead of Executing Recipes}. @item The concept of doing several things at once (parallelism) exists in many incarnations of @code{make} and similar programs, though not in the System V or BSD implementations. @xref{Execution, ,Recipe Execution}. @item A number of different build tools that support parallelism also support collecting output and displaying as a single block. @xref{Parallel Output, ,Output During Parallel Execution}. @item Modified variable references using pattern substitution come from SunOS 4. @xref{Reference, ,Basics of Variable References}. This functionality was provided in GNU @code{make} by the @code{patsubst} function before the alternate syntax was implemented for compatibility with SunOS 4. It is not altogether clear who inspired whom, since GNU @code{make} had @code{patsubst} before SunOS 4 was released. @item The special significance of @samp{+} characters preceding recipe lines (@pxref{Instead of Execution, ,Instead of Executing Recipes}) is mandated by @cite{IEEE Standard 1003.1-2024} (POSIX). @item The @samp{+=} syntax to append to the value of a variable comes from SunOS 4 @code{make}. @xref{Appending Assignment, , Appending More Text to Variables}. @item The syntax @w{@samp{@var{archive}(@var{mem1} @var{mem2}@dots{})}} to list multiple members in a single archive file comes from SunOS 4 @code{make}. @xref{Archive Members}. @item The @code{-include} directive to include makefiles with no error for a nonexistent file comes from SunOS 4 @code{make}. (But note that SunOS 4 @code{make} does not allow multiple makefiles to be specified in one @code{-include} directive.) The same feature appears with the name @code{sinclude} in SGI @code{make} and perhaps others. @item The @code{!=} shell assignment operator exists in many BSD of @code{make} and is purposefully implemented here to behave identically to those implementations. @item Various build management tools are implemented using scripting languages such as Perl or Python and thus provide a natural embedded scripting language, similar to GNU @code{make}'s integration of GNU Guile. @end itemize The remaining features are inventions new in GNU @code{make}: @itemize @bullet @item Use the @samp{-v} or @samp{--version} option to print version and copyright information. @item Use the @samp{-h} or @samp{--help} option to summarize the options to @code{make}. @item Simply-expanded variables. @xref{Flavors, ,The Two Flavors of Variables}. @item Pass command line variable assignments automatically through the variable @code{MAKE} to recursive @code{make} invocations. @xref{Recursion, ,Recursive Use of @code{make}}. @item Use the @samp{-C} or @samp{--directory} command option to change directory. @xref{Options Summary, ,Summary of Options}. @item Make verbatim variable definitions with @code{define}. @xref{Multi-Line, ,Defining Multi-Line Variables}. @item Declare phony targets with the special target @code{.PHONY}. Andrew Hume of AT&T Bell Labs implemented a similar feature with a different syntax in his @code{mk} program. This seems to be a case of parallel discovery. @xref{Phony Targets, ,Phony Targets}. @item Manipulate text by calling functions. @xref{Functions, ,Functions for Transforming Text}. @item Use the @samp{-o} or @samp{--old-file} option to pretend a file's modification-time is old. @xref{Avoiding Compilation, ,Avoiding Recompilation of Some Files}. @item Conditional execution. This feature has been implemented numerous times in various versions of @code{make}; it seems a natural extension derived from the features of the C preprocessor and similar macro languages and is not a revolutionary concept. @xref{Conditionals, ,Conditional Parts of Makefiles}. @item Specify a search path for included makefiles. @xref{Include, ,Including Other Makefiles}. @item Specify extra makefiles to read with an environment variable. @xref{MAKEFILES Variable, ,The Variable @code{MAKEFILES}}. @item Strip leading sequences of @samp{./} from file names, so that @file{./@var{file}} and @file{@var{file}} are considered to be the same file. @item Use a special search method for library prerequisites written in the form @samp{-l@var{name}}. @xref{Libraries/Search, ,Directory Search for Link Libraries}. @item Allow suffixes for suffix rules (@pxref{Suffix Rules, ,Old-Fashioned Suffix Rules}) to contain any characters. In other versions of @code{make}, they must begin with @samp{.} and not contain any @samp{/} characters. @item Keep track of the current level of @code{make} recursion using the variable @code{MAKELEVEL}. @xref{Recursion, ,Recursive Use of @code{make}}. @item Provide any goals given on the command line in the variable @code{MAKECMDGOALS}. @xref{Goals, ,Arguments to Specify the Goals}. @item Specify static pattern rules. @xref{Static Pattern, ,Static Pattern Rules}. @item Provide selective @code{vpath} search. @xref{Directory Search, ,Searching Directories for Prerequisites}. @item Provide computed variable references. @xref{Reference, ,Basics of Variable References}. @item Update makefiles. @xref{Remaking Makefiles, ,How Makefiles Are Remade}. System V @code{make} has a very, very limited form of this functionality in that it will check out SCCS files for makefiles. @item Various new built-in implicit rules. @xref{Catalogue of Rules, ,Catalogue of Built-In Rules}. @item Load dynamic objects which can modify the behavior of @code{make}. @xref{Loading Objects, ,Loading Dynamic Objects}. @end itemize @node Missing @chapter Incompatibilities and Missing Features @cindex incompatibilities @cindex missing features @cindex features, missing The @code{make} programs in various other systems support a few features that are not implemented in GNU @code{make}. The POSIX standard (@cite{IEEE Standard 1003.1-2024}) which specifies @code{make} does not require any of these features. @itemize @bullet @item A target of the form @samp{@var{file}((@var{entry}))} stands for a member of archive file @var{file}. The member is chosen, not by name, but by being an object file which defines the linker symbol @var{entry}. This feature was not put into GNU @code{make} because of the non-modularity of putting knowledge into @code{make} of the internal format of archive file symbol tables. @xref{Archive Symbols, ,Updating Archive Symbol Directories}. @item Suffixes (used in suffix rules) that end with the character @samp{~} have a special meaning to System V @code{make}; they refer to the SCCS file that corresponds to the file one would get without the @samp{~}. For example, the suffix rule @samp{.c~.o} would make the file @file{@var{n}.o} from the SCCS file @file{s.@var{n}.c}. For complete coverage, a whole series of such suffix rules is required. @xref{Suffix Rules, ,Old-Fashioned Suffix Rules}. In GNU @code{make}, this entire series of cases is handled by two pattern rules for extraction from SCCS, in combination with the general feature of rule chaining. @xref{Chained Rules, ,Chains of Implicit Rules}. @item In System V and 4.3 BSD @code{make}, files found by @code{VPATH} search (@pxref{Directory Search, ,Searching Directories for Prerequisites}) have their names changed inside recipes. We feel it is much cleaner to always use automatic variables and thus make this feature unnecessary. @item In some Unix @code{make}s, the automatic variable @code{$*} appearing in the prerequisites of a rule has the amazingly strange ``feature'' of expanding to the full name of the @emph{target of that rule}. We cannot imagine what went on in the minds of Unix @code{make} developers to do this; it is utterly inconsistent with the normal definition of @code{$*}. @vindex * @r{(automatic variable), unsupported bizarre usage} @item In some Unix @code{make}s, implicit rule search (@pxref{Implicit Rules, ,Using Implicit Rules}) is apparently done for @emph{all} targets, not just those without recipes. This means you can do: @example @group foo.o: cc -c foo.c @end group @end example @noindent and Unix @code{make} will intuit that @file{foo.o} depends on @file{foo.c}. We feel that such usage is broken. The prerequisite properties of @code{make} are well-defined (for GNU @code{make}, at least), and doing such a thing simply does not fit the model. @item GNU @code{make} does not include any built-in implicit rules for compiling or preprocessing EFL programs. If we hear of anyone who is using EFL, we will gladly add them. @item It appears that in SVR4 @code{make}, a suffix rule can be specified with no recipe, and it is treated as if it had an empty recipe (@pxref{Empty Recipes}). For example: @example .c.a: @end example @noindent will override the built-in @file{.c.a} suffix rule. We feel that it is cleaner for a rule without a recipe to always simply add to the prerequisite list for the target. The above example can be easily rewritten to get the desired behavior in GNU @code{make}: @example .c.a: ; @end example @item Some versions of @code{make} invoke the shell with the @samp{-e} flag, except under @samp{-k} (@pxref{Testing, ,Testing the Compilation of a Program}). The @samp{-e} flag tells the shell to exit as soon as any program it runs returns a nonzero status. We feel it is cleaner to write each line of the recipe to stand on its own and not require this special treatment. @end itemize @comment The makefile standards are in a separate file that is also @comment included by standards.texi. @include make-stds.texi @node Quick Reference @appendix Quick Reference This appendix summarizes the directives, text manipulation functions, and special variables which GNU @code{make} understands. @xref{Special Targets}, @ref{Catalogue of Rules, ,Catalogue of Built-In Rules}, and @ref{Options Summary, ,Summary of Options}, for other summaries. @menu * Makefile Directives:: All makefile directives. * Makefile Functions:: All makefile built-in functions. * Automatic Variable Reference:: All automatic variables for recipes. * Special Variable Reference:: All special variables for makefiles. @end menu @node Makefile Directives @appendixsec Makefile Directives Reference Here is a summary of the directives GNU @code{make} recognizes: @table @code @item define @var{variable} @itemx define @var{variable} = @itemx define @var{variable} := @itemx define @var{variable} ::= @itemx define @var{variable} :::= @itemx define @var{variable} != @itemx define @var{variable} ?= @itemx define @var{variable} ?:= @itemx define @var{variable} ?::= @itemx define @var{variable} ?:::= @itemx define @var{variable} ?!= @itemx define @var{variable} += @itemx endef Define multi-line variables.@* @xref{Multi-Line}. @item undefine @var{variable} Undefining variables.@* @xref{Undefine Directive}. @item ifdef @var{variable} @itemx ifndef @var{variable} @itemx ifeq (@var{a},@var{b}) @itemx ifeq "@var{a}" "@var{b}" @itemx ifeq '@var{a}' '@var{b}' @itemx ifneq (@var{a},@var{b}) @itemx ifneq "@var{a}" "@var{b}" @itemx ifneq '@var{a}' '@var{b}' @itemx else @itemx endif Conditionally evaluate part of the makefile.@* @xref{Conditionals}. @item include @var{file} @itemx -include @var{file} @itemx sinclude @var{file} Include another makefile.@* @xref{Include, ,Including Other Makefiles}. @item override @var{variable-assignment} Define a variable, overriding any previous definition, even one from the command line.@* @xref{Override Directive, ,The @code{override} Directive}. @item export Tell @code{make} to export all variables to child processes by default.@* @xref{Variables/Recursion, , Communicating Variables to a Sub-@code{make}}. @item export @var{variable} @itemx export @var{variable-assignment} @itemx unexport @var{variable} Tell @code{make} whether or not to export a particular variable to child processes.@* @xref{Variables/Recursion, , Communicating Variables to a Sub-@code{make}}. @item private @var{variable-assignment} Do not allow this variable assignment to be inherited by prerequisites.@* @xref{Suppressing Inheritance}. @item vpath @var{pattern} @var{path} Specify a search path for files matching a @samp{%} pattern.@* @xref{Selective Search, , The @code{vpath} Directive}. @item vpath @var{pattern} Remove all search paths previously specified for @var{pattern}.@* @xref{Selective Search, , The @code{vpath} Directive}. @item vpath Remove all search paths previously specified in any @code{vpath} directive.@* @xref{Selective Search, , The @code{vpath} Directive}. @end table @node Makefile Functions @appendixsec Makefile Functions Reference Here is a summary of the built-in functions (@pxref{Functions}): @table @code @item $(abspath @var{names}@dots{}) For each file name in @var{names}, expand to an absolute name that does not contain any @code{.} or @code{..} components, but preserves symlinks.@* @xref{File Name Functions, ,Functions for File Names}. @item $(addprefix @var{prefix},@var{names}@dots{}) Prepend @var{prefix} to each word in @var{names}.@* @xref{File Name Functions, ,Functions for File Names}. @item $(addsuffix @var{suffix},@var{names}@dots{}) Append @var{suffix} to each word in @var{names}.@* @xref{File Name Functions, ,Functions for File Names}. @item $(and @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) Evaluate each condition @var{conditionN} one at a time; if any expansion results in the empty string substitute the empty string. If all expansions result in a non-empty string, substitute the expansion of the last @var{condition}.@* @xref{Conditional Functions, ,Functions for Conditionals}. @item $(basename @var{names}@dots{}) Extract the base name (name without suffix) of each file name.@* @xref{File Name Functions, ,Functions for File Names}. @item $(call @var{var},@var{param},@dots{}) Evaluate the variable @var{var} replacing any references to @code{$(1)}, @code{$(2)} with the first, second, etc.@: @var{param} values.@* @xref{Call Function, ,The @code{call} Function}. @item $(dir @var{names}@dots{}) Extract the directory part of each file name.@* @xref{File Name Functions, ,Functions for File Names}. @item $(error @var{text}@dots{}) When this function is expanded, @code{make} prints @var{text} to standard error, then @code{make} exits with a failure code.@* @xref{Make Control Functions, ,Functions That Control Make}. @item $(eval @var{text}) Evaluate @var{text} then read the results as makefile commands. Expands to the empty string.@* @xref{Eval Function, ,The @code{eval} Function}. @item $(file @var{op} @var{filename},@var{text}) Expand the arguments, then open the file @var{filename} using mode @var{op} and write @var{text} to that file.@* @xref{File Function, ,The @code{file} Function}. @item $(filter @var{pattern}@dots{},@var{text}) Select words in @var{text} that match one of the @var{pattern} words.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(filter-out @var{pattern}@dots{},@var{text}) Select words in @var{text} that @emph{do not} match any of the @var{pattern} words.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(findstring @var{find},@var{text}) Locate @var{find} in @var{text}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(firstword @var{names}@dots{}) Extract the first word of @var{names}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(flavor @var{variable}) Return a string describing the flavor of the @code{make} variable @var{variable}.@* @xref{Flavor Function, , The @code{flavor} Function}. @item $(foreach @var{var},@var{words},@var{text}) Evaluate @var{text} with @var{var} bound to each word in @var{words}, and concatenate the results.@* @xref{Foreach Function, ,The @code{foreach} Function}. @item $(if @var{condition},@var{then-part}[,@var{else-part}]) Evaluate the condition @var{condition}; if it's non-empty substitute the expansion of the @var{then-part} otherwise substitute the expansion of the @var{else-part}.@* @xref{Conditional Functions, ,Functions for Conditionals}. @item $(info @var{text}@dots{}) When this function is expanded, @code{make} prints @var{text} to standard output and the function expands to the empty string.@* @xref{Make Control Functions, ,Functions That Control Make}. @item $(intcmp @var{lhs},@var{rhs}[,@var{lt-part}[,@var{eq-part}[,@var{gt-part}]]]) Compare @var{lhs} and @var{rhs} numerically; substitute the expansion of @var{lt-part}, @var{eq-part}, or @var{gt-part} depending on whether the left-hand side is less-than, equal-to, or greater-than the right-hand side, respectively.@* @xref{Conditional Functions, ,Functions for Conditionals}. @item $(join @var{list1},@var{list2}) Join two parallel lists of words.@* @xref{File Name Functions, ,Functions for File Names}. @item $(lastword @var{names}@dots{}) Extract the last word of @var{names}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(let @var{var} [@var{var} ...],@var{words},@var{text}) Evaluate @var{text} with the @var{var}s bound to the words in @var{words}.@* @xref{Let Function, ,The @code{let} Function}. @item $(notdir @var{names}@dots{}) Extract the non-directory part of each file name.@* @xref{File Name Functions, ,Functions for File Names}. @item $(or @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) Evaluate each condition @var{conditionN} one at a time; substitute the first non-empty expansion. If all expansions are empty, substitute the empty string.@* @xref{Conditional Functions, ,Functions for Conditionals}. @item $(origin @var{variable}) Return a string describing how the @code{make} variable @var{variable} was defined.@* @xref{Origin Function, , The @code{origin} Function}. @item $(patsubst @var{pattern},@var{replacement},@var{text}) Replace words matching @var{pattern} with @var{replacement} in @var{text}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(realpath @var{names}@dots{}) For each file name in @var{names}, expand to an absolute name that does not contain any @code{.}, @code{..}, nor symlinks.@* @xref{File Name Functions, ,Functions for File Names}. @item $(shell @var{command}) Execute a shell command and expand to its standard output.@* @xref{Shell Function, , The @code{shell} Function}. @item $(sort @var{list}) Sort the words in @var{list} lexicographically, removing duplicates.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(strip @var{string}) Remove excess whitespace characters from @var{string}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(subst @var{from},@var{to},@var{text}) Replace @var{from} with @var{to} in @var{text}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(suffix @var{names}@dots{}) Extract the suffix (the last @samp{.} and following characters) of each file name.@* @xref{File Name Functions, ,Functions for File Names}. @item $(value @var{var}) Evaluates to the contents of the variable @var{var}, with no expansion performed on it.@* @xref{Value Function, ,The @code{value} Function}. @item $(warning @var{text}@dots{}) When this function is expanded, @code{make} prints @var{text} to standard error, prefixed with the current filename and line number.@* @xref{Make Control Functions, ,Functions That Control Make}. @item $(wildcard @var{pattern}@dots{}) Find file names matching a shell file name pattern (@emph{not} a @samp{%} pattern).@* @xref{Wildcard Function, ,The Function @code{wildcard}}. @item $(word @var{n},@var{text}) Extract the @var{n}th word (one-origin) of @var{text}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(wordlist @var{s},@var{e},@var{text}) Returns the list of words in @var{text} from @var{s} to @var{e}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @item $(words @var{text}) Count the number of words in @var{text}.@* @xref{Text Functions, , Functions for String Substitution and Analysis}. @end table @node Automatic Variable Reference @appendixsec Automatic Variable Reference Here is a summary of the automatic variables. Remember automatic variables @emph{only} have values @emph{inside} a recipe. @xref{Automatic Variables}, for full information. @table @code @item $@@ The file name of the target. @item $% The target member name, when the target is an archive member. @item $< The name of the first prerequisite. @item $? The names of all the prerequisites that are newer than the target, with spaces between them. For prerequisites which are archive members, only the named member is used (@pxref{Archives}). @item $^ @itemx $+ The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the named member is used (@pxref{Archives}). The value of @code{$^} omits duplicate prerequisites, while @code{$+} retains them and preserves their order. @item $* The stem with which an implicit rule matches (@pxref{Pattern Match, ,How Patterns Match}). @item $(@@D) @itemx $(@@F) The directory part and the file-within-directory part of @code{$@@}. @item $(*D) @itemx $(*F) The directory part and the file-within-directory part of @code{$*}. @item $(%D) @itemx $(%F) The directory part and the file-within-directory part of @code{$%}. @item $( tar-`sed -e '/version_string/!d' \ -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \ -e q version.c`.shar.Z @end group @group .PHONY: dist dist: $(SRCS) $(AUX) echo tar-`sed \ -e '/version_string/!d' \ -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \ -e q version.c` > .fname -rm -rf `cat .fname` mkdir `cat .fname` ln $(SRCS) $(AUX) `cat .fname` tar chZf `cat .fname`.tar.Z `cat .fname` -rm -rf `cat .fname` .fname @end group @group tar.zoo: $(SRCS) $(AUX) -rm -rf tmp.dir -mkdir tmp.dir -rm tar.zoo for X in $(SRCS) $(AUX) ; do \ echo $$X ; \ sed 's/$$/^M/' $$X \ > tmp.dir/$$X ; done cd tmp.dir ; zoo aM ../tar.zoo * -rm -rf tmp.dir @end group @end example @node GNU Free Documentation License @appendix GNU Free Documentation License @cindex FDL, GNU Free Documentation License @include fdl.texi @node Concept Index @unnumbered Index of Concepts @printindex cp @node Name Index @unnumbered Index of Functions, Variables, & Directives @printindex fn @bye @c Local Variables: @c eval: (setq fill-column 78) @c End: ================================================ FILE: gl/.gitignore ================================================ *~ #* .#* .*cache *.diff *.patch *.orig *.rej *.out *.log ================================================ FILE: gl/lib/fnmatch.c ================================================ /* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2023 Free Software Foundation, Inc. This file is part of the GNU C Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #if HAVE_CONFIG_H # include #endif /* Enable GNU extensions in fnmatch.h. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #include #include #include #if HAVE_STRING_H || defined _LIBC # include #else # include #endif #if defined STDC_HEADERS || defined _LIBC # include #endif /* For platform which support the ISO C amendement 1 functionality we support user defined character classes. */ #if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) /* Solaris 2.5 has a bug: must be included before . */ # include # include #endif /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #if defined _LIBC || !defined __GNU_LIBRARY__ # if defined STDC_HEADERS || !defined isascii # define ISASCII(c) 1 # else # define ISASCII(c) isascii(c) # endif # ifdef isblank # define ISBLANK(c) (ISASCII (c) && isblank (c)) # else # define ISBLANK(c) ((c) == ' ' || (c) == '\t') # endif # ifdef isgraph # define ISGRAPH(c) (ISASCII (c) && isgraph (c)) # else # define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c)) # endif # define ISPRINT(c) (ISASCII (c) && isprint (c)) # define ISDIGIT(c) (ISASCII (c) && isdigit (c)) # define ISALNUM(c) (ISASCII (c) && isalnum (c)) # define ISALPHA(c) (ISASCII (c) && isalpha (c)) # define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) # define ISLOWER(c) (ISASCII (c) && islower (c)) # define ISPUNCT(c) (ISASCII (c) && ispunct (c)) # define ISSPACE(c) (ISASCII (c) && isspace (c)) # define ISUPPER(c) (ISASCII (c) && isupper (c)) # define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) # define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) # if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) /* The GNU C library provides support for user-defined character classes and the functions from ISO C amendement 1. */ # ifdef CHARCLASS_NAME_MAX # define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX # else /* This shouldn't happen but some implementation might still have this problem. Use a reasonable default value. */ # define CHAR_CLASS_MAX_LENGTH 256 # endif # ifdef _LIBC # define IS_CHAR_CLASS(string) __wctype (string) # else # define IS_CHAR_CLASS(string) wctype (string) # endif # else # define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ # define IS_CHAR_CLASS(string) \ (STREQ (string, "alpha") || STREQ (string, "upper") \ || STREQ (string, "lower") || STREQ (string, "digit") \ || STREQ (string, "alnum") || STREQ (string, "xdigit") \ || STREQ (string, "space") || STREQ (string, "print") \ || STREQ (string, "punct") || STREQ (string, "graph") \ || STREQ (string, "cntrl") || STREQ (string, "blank")) # endif /* Avoid depending on library functions or files whose names are inconsistent. */ # if !defined _LIBC && !defined getenv extern char *getenv (); # endif # ifndef errno extern int errno; # endif /* Match STRING against the filename pattern PATTERN, returning zero if it matches, nonzero if not. */ static int internal_fnmatch (const char *pattern, const char *string, int no_leading_period, int flags) { const char *p = pattern, *n = string; unsigned char c; /* Note that this evaluates C many times. */ # ifdef _LIBC # define FOLD(c) (unsigned char)((flags & FNM_CASEFOLD) ? tolower (c) : (c)) # else # define FOLD(c) (unsigned char)((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c)) # endif while ((c = *p++) != '\0') { c = FOLD (c); switch (c) { case '?': if (*n == '\0') return FNM_NOMATCH; else if (*n == '/' && (flags & FNM_FILE_NAME)) return FNM_NOMATCH; else if (*n == '.' && no_leading_period && (n == string || (n[-1] == '/' && (flags & FNM_FILE_NAME)))) return FNM_NOMATCH; break; case '\\': if (!(flags & FNM_NOESCAPE)) { c = *p++; if (c == '\0') /* Trailing \ loses. */ return FNM_NOMATCH; c = FOLD (c); } if (FOLD ((unsigned char) *n) != c) return FNM_NOMATCH; break; case '*': if (*n == '.' && no_leading_period && (n == string || (n[-1] == '/' && (flags & FNM_FILE_NAME)))) return FNM_NOMATCH; for (c = *p++; c == '?' || c == '*'; c = *p++) { if (*n == '/' && (flags & FNM_FILE_NAME)) /* A slash does not match a wildcard under FNM_FILE_NAME. */ return FNM_NOMATCH; else if (c == '?') { /* A ? needs to match one character. */ if (*n == '\0') /* There isn't another character; no match. */ return FNM_NOMATCH; else /* One character of the string is consumed in matching this ? wildcard, so *??? won't match if there are less than three characters. */ ++n; } } if (c == '\0') /* The wildcard(s) is/are the last element of the pattern. If the name is a file name and contains another slash this does mean it cannot match. */ return ((flags & FNM_FILE_NAME) && strchr (n, '/') != NULL ? FNM_NOMATCH : 0); else { const char *endp; endp = strchr (n, (flags & FNM_FILE_NAME) ? '/' : '\0'); if (endp == NULL) endp = n + strlen (n); if (c == '[') { int flags2 = ((flags & FNM_FILE_NAME) ? flags : (flags & ~FNM_PERIOD)); for (--p; n < endp; ++n) if (internal_fnmatch (p, n, (no_leading_period && (n == string || (n[-1] == '/' && (flags & FNM_FILE_NAME)))), flags2) == 0) return 0; } else if (c == '/' && (flags & FNM_FILE_NAME)) { while (*n != '\0' && *n != '/') ++n; if (*n == '/' && (internal_fnmatch (p, n + 1, flags & FNM_PERIOD, flags) == 0)) return 0; } else { int flags2 = ((flags & FNM_FILE_NAME) ? flags : (flags & ~FNM_PERIOD)); if (c == '\\' && !(flags & FNM_NOESCAPE)) c = *p; c = FOLD (c); for (--p; n < endp; ++n) if (FOLD ((unsigned char) *n) == c && (internal_fnmatch (p, n, (no_leading_period && (n == string || (n[-1] == '/' && (flags & FNM_FILE_NAME)))), flags2) == 0)) return 0; } } /* If we come here no match is possible with the wildcard. */ return FNM_NOMATCH; case '[': { /* Nonzero if the sense of the character class is inverted. */ static int posixly_correct; int not; char cold; if (posixly_correct == 0) posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; if (*n == '\0') return FNM_NOMATCH; if (*n == '.' && no_leading_period && (n == string || (n[-1] == '/' && (flags & FNM_FILE_NAME)))) return FNM_NOMATCH; if (*n == '/' && (flags & FNM_FILE_NAME)) /* `/' cannot be matched. */ return FNM_NOMATCH; not = (*p == '!' || (posixly_correct < 0 && *p == '^')); if (not) ++p; c = *p++; for (;;) { unsigned char fn = FOLD ((unsigned char) *n); if (!(flags & FNM_NOESCAPE) && c == '\\') { if (*p == '\0') return FNM_NOMATCH; c = FOLD ((unsigned char) *p); ++p; if (c == fn) goto matched; } else if (c == '[' && *p == ':') { /* Leave room for the null. */ char str[CHAR_CLASS_MAX_LENGTH + 1]; size_t c1 = 0; # if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) wctype_t wt; # endif const char *startp = p; for (;;) { if (c1 == CHAR_CLASS_MAX_LENGTH) /* The name is too long and therefore the pattern is ill-formed. */ return FNM_NOMATCH; c = *++p; if (c == ':' && p[1] == ']') { p += 2; break; } if (c < 'a' || c >= 'z') { /* This cannot possibly be a character class name. Match it as a normal range. */ p = startp; c = '['; goto normal_bracket; } str[c1++] = c; } str[c1] = '\0'; # if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) wt = IS_CHAR_CLASS (str); if (wt == 0) /* Invalid character class name. */ return FNM_NOMATCH; if (__iswctype (__btowc ((unsigned char) *n), wt)) goto matched; # else if ((STREQ (str, "alnum") && ISALNUM ((unsigned char) *n)) || (STREQ (str, "alpha") && ISALPHA ((unsigned char) *n)) || (STREQ (str, "blank") && ISBLANK ((unsigned char) *n)) || (STREQ (str, "cntrl") && ISCNTRL ((unsigned char) *n)) || (STREQ (str, "digit") && ISDIGIT ((unsigned char) *n)) || (STREQ (str, "graph") && ISGRAPH ((unsigned char) *n)) || (STREQ (str, "lower") && ISLOWER ((unsigned char) *n)) || (STREQ (str, "print") && ISPRINT ((unsigned char) *n)) || (STREQ (str, "punct") && ISPUNCT ((unsigned char) *n)) || (STREQ (str, "space") && ISSPACE ((unsigned char) *n)) || (STREQ (str, "upper") && ISUPPER ((unsigned char) *n)) || (STREQ (str, "xdigit") && ISXDIGIT ((unsigned char) *n))) goto matched; # endif } else if (c == '\0') /* [ (unterminated) loses. */ return FNM_NOMATCH; else { normal_bracket: if (FOLD (c) == fn) goto matched; cold = c; c = *p++; if (c == '-' && *p != ']') { /* It is a range. */ unsigned char cend = *p++; if (!(flags & FNM_NOESCAPE) && cend == '\\') cend = *p++; if (cend == '\0') return FNM_NOMATCH; if (cold <= fn && fn <= FOLD (cend)) goto matched; c = *p++; } } if (c == ']') break; } if (!not) return FNM_NOMATCH; break; matched: /* Skip the rest of the [...] that already matched. */ while (c != ']') { if (c == '\0') /* [... (unterminated) loses. */ return FNM_NOMATCH; c = *p++; if (!(flags & FNM_NOESCAPE) && c == '\\') { if (*p == '\0') return FNM_NOMATCH; /* XXX 1003.2d11 is unclear if this is right. */ ++p; } else if (c == '[' && *p == ':') { do if (*++p == '\0') return FNM_NOMATCH; while (*p != ':' || p[1] == ']'); p += 2; c = *p; } } if (not) return FNM_NOMATCH; } break; default: if (c != FOLD ((unsigned char) *n)) return FNM_NOMATCH; } ++n; } if (*n == '\0') return 0; if ((flags & FNM_LEADING_DIR) && *n == '/') /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */ return 0; return FNM_NOMATCH; # undef FOLD } int fnmatch (const char *pattern, const char *string, int flags) { return internal_fnmatch (pattern, string, flags & FNM_PERIOD, flags); } #endif /* _LIBC or not __GNU_LIBRARY__. */ ================================================ FILE: gl/lib/fnmatch.in.h ================================================ /* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2023 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef _FNMATCH_H #define _FNMATCH_H 1 #ifdef __cplusplus extern "C" { #endif /* We #undef these before defining them because some losing systems (HP-UX A.08.07 for example) define these in . */ #undef FNM_PATHNAME #undef FNM_NOESCAPE #undef FNM_PERIOD /* Bits set in the FLAGS argument to `fnmatch'. */ #define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */ #define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ #define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */ #if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE # define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */ # define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */ # define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ #endif /* Value returned by `fnmatch' if STRING does not match PATTERN. */ #define FNM_NOMATCH 1 /* This value is returned if the implementation does not support `fnmatch'. Since this is not the case here it will never be returned but the conformance test suites still require the symbol to be defined. */ #ifdef _XOPEN_SOURCE # define FNM_NOSYS (-1) #endif /* Match NAME against the filename pattern PATTERN, returning zero if it matches, FNM_NOMATCH if not. */ extern int fnmatch (const char *pattern, const char *name, int flags); #ifdef __cplusplus } #endif #endif /* fnmatch.h */ ================================================ FILE: gl/lib/glob.c ================================================ /* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2023 Free Software Foundation, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /* AIX requires this to be the first thing in the file. */ #if defined _AIX && !defined __GNUC__ #pragma alloca #endif #ifdef HAVE_CONFIG_H # include #endif /* Enable GNU extensions in glob.h. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #include #include #include /* Outcomment the following line for production quality code. */ /* #define NDEBUG 1 */ #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GLOB_INTERFACE_VERSION 1 #if defined _LIBC # define ELIDE_CODE #elif defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1 # include # if _GNU_GLOB_INTERFACE_VERSION == GLOB_INTERFACE_VERSION # define ELIDE_CODE # endif #endif #ifndef ELIDE_CODE #if defined STDC_HEADERS || defined __GNU_LIBRARY__ # include #endif #if defined HAVE_UNISTD_H # include # ifndef POSIX # ifdef _POSIX_VERSION # define POSIX # endif # endif #endif #if !defined _AMIGA && !MK_OS_VMS && !MK_OS_W32 # include #endif #if !defined __GNU_LIBRARY__ && !defined STDC_HEADERS extern int errno; #endif #ifndef __set_errno # define __set_errno(val) errno = (val) #endif #if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__ # include # define NAMLEN(dirent) strlen((dirent)->d_name) #else # define dirent direct # define NAMLEN(dirent) (dirent)->d_namlen # ifdef HAVE_SYS_NDIR_H # include # endif # ifdef HAVE_SYS_DIR_H # include # endif # ifdef HAVE_NDIR_H # include # endif # ifdef HAVE_VMSDIR_H # include "vmsdir.h" # endif /* HAVE_VMSDIR_H */ #endif /* In GNU systems, defines this macro for us. */ #ifdef _D_NAMLEN # undef NAMLEN # define NAMLEN(d) _D_NAMLEN(d) #endif /* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available if the `d_type' member for `struct dirent' is available. */ #if defined(_DIRENT_HAVE_D_TYPE) || defined(HAVE_STRUCT_DIRENT_D_TYPE) # define HAVE_D_TYPE 1 #endif #if (defined POSIX || MK_OS_W32) && !defined __GNU_LIBRARY__ /* Posix does not require that the d_ino field be present, and some systems do not provide it. */ # define REAL_DIR_ENTRY(dp) 1 #else # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) #endif /* POSIX */ #include #include #if !defined HAVE_STRCOLL # define strcoll strcmp #endif #if !defined HAVE_MEMPCPY && __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1 # define HAVE_MEMPCPY 1 # undef mempcpy # define mempcpy(Dest, Src, Len) __mempcpy (Dest, Src, Len) #endif #if !defined __alloca && !defined __GNU_LIBRARY__ # ifdef __GNUC__ # undef alloca # define alloca(n) __builtin_alloca (n) # else /* Not GCC. */ # ifdef HAVE_ALLOCA_H # include # else /* Not HAVE_ALLOCA_H. */ # ifndef _AIX # if MK_OS_W32 # include # else extern char *alloca (); # endif /* MK_OS_W32 */ # endif /* Not _AIX. */ # endif /* sparc or HAVE_ALLOCA_H. */ # endif /* GCC. */ #endif #ifndef __GNU_LIBRARY__ # ifdef STAT_MACROS_BROKEN # undef S_ISDIR # endif # ifndef S_ISDIR # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) # endif #endif /* Some system header files erroneously define these. We want our own definitions from to take precedence. */ #ifndef __GNU_LIBRARY__ # undef FNM_PATHNAME # undef FNM_NOESCAPE # undef FNM_PERIOD #endif #include /* Some system header files erroneously define these. We want our own definitions from to take precedence. */ #ifndef __GNU_LIBRARY__ # undef GLOB_ERR # undef GLOB_MARK # undef GLOB_NOSORT # undef GLOB_DOOFFS # undef GLOB_NOCHECK # undef GLOB_APPEND # undef GLOB_NOESCAPE # undef GLOB_PERIOD #endif #include #if !defined __alloca # define __alloca alloca #endif #ifdef HAVE_GETLOGIN_R extern int getlogin_r (char *, size_t); #else extern char *getlogin (void); #endif static #if __GNUC__ - 0 >= 2 inline #endif const char *next_brace_sub (const char *begin); static int glob_in_dir (const char *pattern, const char *directory, int flags, int (*errfunc) (const char *, int), glob_t *pglob); static int prefix_array (const char *prefix, char **array, size_t n); static int collated_compare (const void *, const void *); #if !defined NO_GLOB_PATTERN_P int __glob_pattern_p (const char *pattern, int quote); #endif /* Find the end of the sub-pattern in a brace expression. We define this as an inline function if the compiler permits. */ static #if __GNUC__ - 0 >= 2 inline #endif const char * next_brace_sub (const char *begin) { unsigned int depth = 0; const char *cp = begin; while (1) { if (depth == 0) { if (*cp != ',' && *cp != '}' && *cp != '\0') { if (*cp == '{') ++depth; ++cp; continue; } } else { while (*cp != '\0' && (*cp != '}' || depth > 0)) { if (*cp == '}') --depth; ++cp; } if (*cp == '\0') /* An incorrectly terminated brace expression. */ return NULL; continue; } break; } return cp; } /* Do glob searching for PATTERN, placing results in PGLOB. The bits defined above may be set in FLAGS. If a directory cannot be opened or read and ERRFUNC is not nil, it is called with the pathname that caused the error, and the `errno' value from the failing call; if it returns non-zero `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ int glob (const char *pattern, int flags, int (*errfunc) (const char *, int), glob_t *pglob) { const char *filename; const char *dirname; size_t dirlen; int status; size_t oldcount; if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) { __set_errno (EINVAL); return -1; } /* POSIX requires all slashes to be matched. This means that with a trailing slash we must match only directories. */ if (pattern[0] && pattern[strlen (pattern) - 1] == '/') flags |= GLOB_ONLYDIR; if (flags & GLOB_BRACE) { const char *begin = strchr (pattern, '{'); if (begin != NULL) { /* Allocate working buffer large enough for our work. Note that we have at least an opening and closing brace. */ size_t firstc; char *alt_start; const char *p; const char *next; const char *rest; size_t rest_len; #ifdef __GNUC__ char onealt[strlen (pattern) - 1]; #else char *onealt = (char *) malloc (strlen (pattern) - 1); if (onealt == NULL) { if (!(flags & GLOB_APPEND)) globfree (pglob); return GLOB_NOSPACE; } #endif /* We know the prefix for all sub-patterns. */ #ifdef HAVE_MEMPCPY alt_start = mempcpy (onealt, pattern, begin - pattern); #else memcpy (onealt, pattern, begin - pattern); alt_start = &onealt[begin - pattern]; #endif /* Find the first sub-pattern and at the same time find the rest after the closing brace. */ next = next_brace_sub (begin + 1); if (next == NULL) { /* It is an illegal expression. */ #ifndef __GNUC__ free (onealt); #endif return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); } /* Now find the end of the whole brace expression. */ rest = next; while (*rest != '}') { rest = next_brace_sub (rest + 1); if (rest == NULL) { /* It is an illegal expression. */ #ifndef __GNUC__ free (onealt); #endif return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); } } /* Please note that we now can be sure the brace expression is well-formed. */ rest_len = strlen (++rest) + 1; /* We have a brace expression. BEGIN points to the opening {, NEXT points past the terminator of the first element, and END points past the final }. We will accumulate result names from recursive runs for each brace alternative in the buffer using GLOB_APPEND. */ if (!(flags & GLOB_APPEND)) { /* This call is to set a new vector, so clear out the vector so we can append to it. */ pglob->gl_pathc = 0; pglob->gl_pathv = NULL; } firstc = pglob->gl_pathc; p = begin + 1; while (1) { int result; /* Construct the new glob expression. */ #ifdef HAVE_MEMPCPY mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len); #else memcpy (alt_start, p, next - p); memcpy (&alt_start[next - p], rest, rest_len); #endif result = glob (onealt, ((flags & ~(GLOB_NOCHECK|GLOB_NOMAGIC)) | GLOB_APPEND), errfunc, pglob); /* If we got an error, return it. */ if (result && result != GLOB_NOMATCH) { #ifndef __GNUC__ free (onealt); #endif if (!(flags & GLOB_APPEND)) globfree (pglob); return result; } if (*next == '}') /* We saw the last entry. */ break; p = next + 1; next = next_brace_sub (p); assert (next != NULL); } #ifndef __GNUC__ free (onealt); #endif if (pglob->gl_pathc != firstc) /* We found some entries. */ return 0; else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) return GLOB_NOMATCH; } } /* Find the filename. */ filename = strrchr (pattern, '/'); #if MK_OS_DOS || MK_OS_W32 /* The case of "d:pattern". Since `:' is not allowed in file names, we can safely assume that wherever it happens in pattern, it signals the filename part. This is so we could some day support patterns like "[a-z]:foo". */ if (filename == NULL) filename = strchr (pattern, ':'); #endif /* MK_OS_DOS || MK_OS_W32 */ if (filename == NULL) { /* This can mean two things: a simple name or "~name". The later case is nothing but a notation for a directory. */ if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~') { dirname = pattern; dirlen = strlen (pattern); /* Set FILENAME to NULL as a special flag. This is ugly but other solutions would require much more code. We test for this special case below. */ filename = NULL; } else { filename = pattern; #ifdef _AMIGA dirname = ""; #else dirname = "."; #endif dirlen = 0; } } else if (filename == pattern) { /* "/pattern". */ dirname = "/"; dirlen = 1; ++filename; } else { char *newp; dirlen = filename - pattern; #if MK_OS_DOS || MK_OS_W32 if (*filename == ':' || (filename > pattern + 1 && filename[-1] == ':')) { char *drive_spec; ++dirlen; drive_spec = (char *) __alloca (dirlen + 1); #ifdef HAVE_MEMPCPY *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; #else memcpy (drive_spec, pattern, dirlen); drive_spec[dirlen] = '\0'; #endif /* For now, disallow wildcards in the drive spec, to prevent infinite recursion in glob. */ if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) return GLOB_NOMATCH; /* If this is "d:pattern", we need to copy `:' to DIRNAME as well. If it's "d:/pattern", don't remove the slash from "d:/", since "d:" and "d:/" are not the same.*/ } #endif newp = (char *) __alloca (dirlen + 1); #ifdef HAVE_MEMPCPY *((char *) mempcpy (newp, pattern, dirlen)) = '\0'; #else memcpy (newp, pattern, dirlen); newp[dirlen] = '\0'; #endif dirname = newp; ++filename; if (filename[0] == '\0' #if MK_OS_DOS || MK_OS_W32 && dirname[dirlen - 1] != ':' && (dirlen < 3 || dirname[dirlen - 2] != ':' || dirname[dirlen - 1] != '/') #endif && dirlen > 1) /* "pattern/". Expand "pattern", appending slashes. */ { int val = glob (dirname, flags | GLOB_MARK, errfunc, pglob); if (val == 0) pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK) | (flags & GLOB_MARK)); return val; } } if (!(flags & GLOB_APPEND)) { pglob->gl_pathc = 0; pglob->gl_pathv = NULL; } oldcount = pglob->gl_pathc; #if !MK_OS_VMS if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~') { if (dirname[1] == '\0' || dirname[1] == '/') { /* Look up home directory. */ #if MK_OS_VMS /* This isn't obvious, RTLs of DECC and VAXC know about "HOME" */ const char *home_dir = getenv ("SYS$LOGIN"); #else const char *home_dir = getenv ("HOME"); #endif # ifdef _AMIGA if (home_dir == NULL || home_dir[0] == '\0') home_dir = "SYS:"; # else # if MK_OS_W32 if (home_dir == NULL || home_dir[0] == '\0') home_dir = "c:/users/default"; /* poor default */ # else # if MK_OS_VMS /* Again, this isn't obvious, if "HOME" isn't known "SYS$LOGIN" should be set */ if (home_dir == NULL || home_dir[0] == '\0') home_dir = "SYS$DISK:[]"; # else if (home_dir == NULL || home_dir[0] == '\0') { int success; char *name; # if defined HAVE_GETLOGIN_R size_t buflen = sysconf (_SC_LOGIN_NAME_MAX) + 1; if (buflen == 0) /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try a moderate value. */ buflen = 20; name = (char *) __alloca (buflen); success = getlogin_r (name, buflen) >= 0; # else success = (name = getlogin ()) != NULL; # endif if (success) { struct passwd *p; # if defined HAVE_GETPWNAM_R size_t pwbuflen = sysconf (_SC_GETPW_R_SIZE_MAX); char *pwtmpbuf; struct passwd pwbuf; int save = errno; if (pwbuflen == -1) /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a moderate value. */ pwbuflen = 1024; pwtmpbuf = (char *) __alloca (pwbuflen); while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) != 0) { if (errno != ERANGE) { p = NULL; break; } pwbuflen *= 2; pwtmpbuf = (char *) __alloca (pwbuflen); __set_errno (save); } # else p = getpwnam (name); # endif if (p != NULL) home_dir = p->pw_dir; } } if (home_dir == NULL || home_dir[0] == '\0') { if (flags & GLOB_TILDE_CHECK) return GLOB_NOMATCH; else home_dir = "~"; /* No luck. */ } # endif /* MK_OS_VMS */ # endif /* MK_OS_W32 */ # endif /* Now construct the full directory. */ if (dirname[1] == '\0') dirname = home_dir; else { char *newp; size_t home_len = strlen (home_dir); newp = (char *) __alloca (home_len + dirlen); # ifdef HAVE_MEMPCPY mempcpy (mempcpy (newp, home_dir, home_len), &dirname[1], dirlen); # else memcpy (newp, home_dir, home_len); memcpy (&newp[home_len], &dirname[1], dirlen); # endif dirname = newp; } } # if !defined _AMIGA && !MK_OS_W32 && !MK_OS_VMS else { char *end_name = strchr (dirname, '/'); const char *user_name; const char *home_dir; if (end_name == NULL) user_name = dirname + 1; else { char *newp; newp = (char *) __alloca (end_name - dirname); # ifdef HAVE_MEMPCPY *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) = '\0'; # else memcpy (newp, dirname + 1, end_name - dirname); newp[end_name - dirname - 1] = '\0'; # endif user_name = newp; } /* Look up specific user's home directory. */ { struct passwd *p; # if defined HAVE_GETPWNAM_R size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); char *pwtmpbuf; struct passwd pwbuf; int save = errno; if (buflen == -1) /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a moderate value. */ buflen = 1024; pwtmpbuf = (char *) __alloca (buflen); while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) { if (errno != ERANGE) { p = NULL; break; } buflen *= 2; pwtmpbuf = __alloca (buflen); __set_errno (save); } # else p = getpwnam (user_name); # endif if (p != NULL) home_dir = p->pw_dir; else home_dir = NULL; } /* If we found a home directory use this. */ if (home_dir != NULL) { char *newp; size_t home_len = strlen (home_dir); size_t rest_len = end_name == NULL ? 0 : strlen (end_name); newp = (char *) __alloca (home_len + rest_len + 1); # ifdef HAVE_MEMPCPY *((char *) mempcpy (mempcpy (newp, home_dir, home_len), end_name, rest_len)) = '\0'; # else memcpy (newp, home_dir, home_len); memcpy (&newp[home_len], end_name, rest_len); newp[home_len + rest_len] = '\0'; # endif dirname = newp; } else if (flags & GLOB_TILDE_CHECK) /* We have to regard it as an error if we cannot find the home directory. */ return GLOB_NOMATCH; } # endif /* Not Amiga && not MK_OS_W32 && not MK_OS_VMS. */ } #endif /* Not MK_OS_VMS. */ /* Now test whether we looked for "~" or "~NAME". In this case we can give the answer now. */ if (filename == NULL) { struct stat st; /* Return the directory if we don't check for error or if it exists. */ if ((flags & GLOB_NOCHECK) || (((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_stat) (dirname, &st) : stat (dirname, &st)) == 0 && S_ISDIR (st.st_mode))) { pglob->gl_pathv = (char **) realloc (pglob->gl_pathv, (pglob->gl_pathc + ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) + 1 + 1) * sizeof (char *)); if (pglob->gl_pathv == NULL) return GLOB_NOSPACE; if (flags & GLOB_DOOFFS) while (pglob->gl_pathc < pglob->gl_offs) pglob->gl_pathv[pglob->gl_pathc++] = NULL; #if defined HAVE_STRDUP pglob->gl_pathv[pglob->gl_pathc] = strdup (dirname); #else { size_t len = strlen (dirname) + 1; char *dircopy = malloc (len); if (dircopy != NULL) pglob->gl_pathv[pglob->gl_pathc] = memcpy (dircopy, dirname, len); } #endif if (pglob->gl_pathv[pglob->gl_pathc] == NULL) { free (pglob->gl_pathv); return GLOB_NOSPACE; } pglob->gl_pathv[++pglob->gl_pathc] = NULL; pglob->gl_flags = flags; return 0; } /* Not found. */ return GLOB_NOMATCH; } if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE))) { /* The directory name contains metacharacters, so we have to glob for the directory, and then glob for the pattern in each directory found. */ glob_t dirs; size_t i; status = glob (dirname, ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE)) | GLOB_NOSORT | GLOB_ONLYDIR), errfunc, &dirs); if (status != 0) return status; /* We have successfully globbed the preceding directory name. For each name we found, call glob_in_dir on it and FILENAME, appending the results to PGLOB. */ for (i = 0; i < dirs.gl_pathc; ++i) { size_t old_pathc; #ifdef SHELL { /* Make globbing interruptible in the bash shell. */ extern int interrupt_state; if (interrupt_state) { globfree (&dirs); globfree (&files); return GLOB_ABORTED; } } #endif /* SHELL. */ old_pathc = pglob->gl_pathc; status = glob_in_dir (filename, dirs.gl_pathv[i], ((flags | GLOB_APPEND) & ~(GLOB_NOCHECK | GLOB_ERR)), errfunc, pglob); if (status == GLOB_NOMATCH) /* No matches in this directory. Try the next. */ continue; if (status != 0) { globfree (&dirs); globfree (pglob); return status; } /* Stick the directory on the front of each name. */ if (prefix_array (dirs.gl_pathv[i], &pglob->gl_pathv[old_pathc], pglob->gl_pathc - old_pathc)) { globfree (&dirs); globfree (pglob); return GLOB_NOSPACE; } } flags |= GLOB_MAGCHAR; /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls. But if we have not found any matching entry and thie GLOB_NOCHECK flag was set we must return the list consisting of the disrectory names followed by the filename. */ if (pglob->gl_pathc == oldcount) { /* No matches. */ if (flags & GLOB_NOCHECK) { size_t filename_len = strlen (filename) + 1; char **new_pathv; struct stat st; /* This is an pessimistic guess about the size. */ pglob->gl_pathv = (char **) realloc (pglob->gl_pathv, (pglob->gl_pathc + ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) + dirs.gl_pathc + 1) * sizeof (char *)); if (pglob->gl_pathv == NULL) { globfree (&dirs); return GLOB_NOSPACE; } if (flags & GLOB_DOOFFS) while (pglob->gl_pathc < pglob->gl_offs) pglob->gl_pathv[pglob->gl_pathc++] = NULL; for (i = 0; i < dirs.gl_pathc; ++i) { const char *dir = dirs.gl_pathv[i]; size_t dir_len = strlen (dir); /* First check whether this really is a directory. */ if (((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_stat) (dir, &st) : stat (dir, &st)) != 0 || !S_ISDIR (st.st_mode)) /* No directory, ignore this entry. */ continue; pglob->gl_pathv[pglob->gl_pathc] = malloc (dir_len + 1 + filename_len); if (pglob->gl_pathv[pglob->gl_pathc] == NULL) { globfree (&dirs); globfree (pglob); return GLOB_NOSPACE; } #ifdef HAVE_MEMPCPY mempcpy (mempcpy (mempcpy (pglob->gl_pathv[pglob->gl_pathc], dir, dir_len), "/", 1), filename, filename_len); #else memcpy (pglob->gl_pathv[pglob->gl_pathc], dir, dir_len); pglob->gl_pathv[pglob->gl_pathc][dir_len] = '/'; memcpy (&pglob->gl_pathv[pglob->gl_pathc][dir_len + 1], filename, filename_len); #endif ++pglob->gl_pathc; } pglob->gl_pathv[pglob->gl_pathc] = NULL; pglob->gl_flags = flags; /* Now we know how large the gl_pathv vector must be. */ new_pathv = (char **) realloc (pglob->gl_pathv, ((pglob->gl_pathc + 1) * sizeof (char *))); if (new_pathv != NULL) pglob->gl_pathv = new_pathv; } else return GLOB_NOMATCH; } globfree (&dirs); } else { status = glob_in_dir (filename, dirname, flags, errfunc, pglob); if (status != 0) return status; if (dirlen > 0) { /* Stick the directory on the front of each name. */ size_t ignore = oldcount; if ((flags & GLOB_DOOFFS) && ignore < pglob->gl_offs) ignore = pglob->gl_offs; if (prefix_array (dirname, &pglob->gl_pathv[ignore], pglob->gl_pathc - ignore)) { globfree (pglob); return GLOB_NOSPACE; } } } if (flags & GLOB_MARK) { /* Append slashes to directory names. */ size_t i; struct stat st; for (i = oldcount; i < pglob->gl_pathc; ++i) if (((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_stat) (pglob->gl_pathv[i], &st) : stat (pglob->gl_pathv[i], &st)) == 0 && S_ISDIR (st.st_mode)) { size_t len = strlen (pglob->gl_pathv[i]) + 2; char *new = realloc (pglob->gl_pathv[i], len); if (new == NULL) { globfree (pglob); return GLOB_NOSPACE; } strcpy (&new[len - 2], "/"); pglob->gl_pathv[i] = new; } } if (!(flags & GLOB_NOSORT)) { /* Sort the vector. */ size_t non_sort = oldcount; if ((flags & GLOB_DOOFFS) && pglob->gl_offs > oldcount) non_sort = pglob->gl_offs; qsort ((void *) &pglob->gl_pathv[non_sort], pglob->gl_pathc - non_sort, sizeof (char *), collated_compare); } return 0; } /* Free storage allocated in PGLOB by a previous `glob' call. */ void globfree (glob_t *pglob) { if (pglob->gl_pathv != NULL) { size_t i; for (i = 0; i < pglob->gl_pathc; ++i) if (pglob->gl_pathv[i] != NULL) free (pglob->gl_pathv[i]); free (pglob->gl_pathv); } } /* Do a collated comparison of A and B. */ static int collated_compare (const void *a, const void *b) { const char *const s1 = *(const char *const * const) a; const char *const s2 = *(const char *const * const) b; if (s1 == s2) return 0; if (s1 == NULL) return 1; if (s2 == NULL) return -1; return strcoll (s1, s2); } /* Prepend DIRNAME to each of N members of ARRAY, replacing ARRAY's elements in place. Return nonzero if out of memory, zero if successful. A slash is inserted between DIRNAME and each elt of ARRAY, unless DIRNAME is just "/". Each old element of ARRAY is freed. */ static int prefix_array (const char *dirname, char **array, size_t n) { size_t i; size_t dirlen = strlen (dirname); #if MK_OS_DOS || MK_OS_W32 char sep_char = '/'; # define DIRSEP_CHAR sep_char #else # define DIRSEP_CHAR '/' #endif if (dirlen == 1 && dirname[0] == '/') /* DIRNAME is just "/", so normal prepending would get us "//foo". We want "/foo" instead, so don't prepend any chars from DIRNAME. */ dirlen = 0; #if MK_OS_DOS || MK_OS_W32 else if (dirlen > 1) { if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':') /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */ --dirlen; else if (dirname[dirlen - 1] == ':') { /* DIRNAME is "d:". Use `:' instead of `/'. */ --dirlen; sep_char = ':'; } } #endif for (i = 0; i < n; ++i) { size_t eltlen = strlen (array[i]) + 1; char *new = (char *) malloc (dirlen + 1 + eltlen); if (new == NULL) { while (i > 0) free (array[--i]); return 1; } #ifdef HAVE_MEMPCPY { char *endp = (char *) mempcpy (new, dirname, dirlen); *endp++ = DIRSEP_CHAR; mempcpy (endp, array[i], eltlen); } #else memcpy (new, dirname, dirlen); new[dirlen] = DIRSEP_CHAR; memcpy (&new[dirlen + 1], array[i], eltlen); #endif free (array[i]); array[i] = new; } return 0; } /* We must not compile this function twice. */ #if !defined NO_GLOB_PATTERN_P /* Return nonzero if PATTERN contains any metacharacters. Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ int __glob_pattern_p (const char *pattern, int quote) { const char *p; int open = 0; for (p = pattern; *p != '\0'; ++p) switch (*p) { case '?': case '*': return 1; case '\\': if (quote && p[1] != '\0') ++p; break; case '[': open = 1; break; case ']': if (open) return 1; break; } return 0; } #endif /* Like `glob', but PATTERN is a final pathname component, and matches are searched for in DIRECTORY. The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. The GLOB_APPEND flag is assumed to be set (always appends). */ static int glob_in_dir (const char *pattern, const char *directory, int flags, int (*errfunc) (const char *, int), glob_t *pglob) { void *stream = NULL; struct globlink { struct globlink *next; char *name; }; struct globlink *names = NULL; size_t nfound; int meta; int save; #if MK_OS_VMS if (*directory == 0) directory = "[]"; #endif meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE)); if (meta == 0) { if (flags & (GLOB_NOCHECK|GLOB_NOMAGIC)) /* We need not do any tests. The PATTERN contains no meta characters and we must not return an error therefore the result will always contain exactly one name. */ flags |= GLOB_NOCHECK; else { /* Since we use the normal file functions we can also use stat() to verify the file is there. */ struct stat st; size_t patlen = strlen (pattern); size_t dirlen = strlen (directory); char *fullname = (char *) __alloca (dirlen + 1 + patlen + 1); # ifdef HAVE_MEMPCPY mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), "/", 1), pattern, patlen + 1); # else memcpy (fullname, directory, dirlen); fullname[dirlen] = '/'; memcpy (&fullname[dirlen + 1], pattern, patlen + 1); # endif if (((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_stat) (fullname, &st) : stat (fullname, &st)) == 0) /* We found this file to be existing. Now tell the rest of the function to copy this name into the result. */ flags |= GLOB_NOCHECK; } nfound = 0; } else { if (pattern[0] == '\0') { /* This is a special case for matching directories like in "*a/". */ names = (struct globlink *) __alloca (sizeof (struct globlink)); names->name = (char *) malloc (1); if (names->name == NULL) goto memory_error; names->name[0] = '\0'; names->next = NULL; nfound = 1; meta = 0; } else { stream = ((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_opendir) (directory) : (void *) opendir (directory)); if (stream == NULL) { if (errno != ENOTDIR && ((errfunc != NULL && (*errfunc) (directory, errno)) || (flags & GLOB_ERR))) return GLOB_ABORTED; nfound = 0; meta = 0; } else { int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) #if defined HAVE_CASE_INSENSITIVE_FS | FNM_CASEFOLD #endif ); nfound = 0; flags |= GLOB_MAGCHAR; while (1) { const char *name; size_t len; struct dirent *d = ((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_readdir) (stream) : readdir ((DIR *) stream)); if (d == NULL) break; if (! REAL_DIR_ENTRY (d)) continue; #ifdef HAVE_D_TYPE /* If we shall match only directories use the information provided by the dirent call if possible. */ if ((flags & GLOB_ONLYDIR) && d->d_type != DT_UNKNOWN && d->d_type != DT_DIR && d->d_type != DT_LNK) continue; #endif name = d->d_name; if (fnmatch (pattern, name, fnm_flags) == 0) { struct globlink *new = (struct globlink *) __alloca (sizeof (struct globlink)); len = NAMLEN (d); new->name = (char *) malloc (len + 1); if (new->name == NULL) goto memory_error; #ifdef HAVE_MEMPCPY *((char *) mempcpy (new->name, name, len)) = '\0'; #else memcpy (new->name, name, len); new->name[len] = '\0'; #endif new->next = names; names = new; ++nfound; } } } } } if (nfound == 0 && (flags & GLOB_NOCHECK)) { size_t len = strlen (pattern); nfound = 1; names = (struct globlink *) __alloca (sizeof (struct globlink)); names->next = NULL; names->name = (char *) malloc (len + 1); if (names->name == NULL) goto memory_error; #ifdef HAVE_MEMPCPY *((char *) mempcpy (names->name, pattern, len)) = '\0'; #else memcpy (names->name, pattern, len); names->name[len] = '\0'; #endif } if (nfound != 0) { pglob->gl_pathv = (char **) realloc (pglob->gl_pathv, (pglob->gl_pathc + ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) + nfound + 1) * sizeof (char *)); if (pglob->gl_pathv == NULL) goto memory_error; if (flags & GLOB_DOOFFS) while (pglob->gl_pathc < pglob->gl_offs) pglob->gl_pathv[pglob->gl_pathc++] = NULL; for (; names != NULL; names = names->next) pglob->gl_pathv[pglob->gl_pathc++] = names->name; pglob->gl_pathv[pglob->gl_pathc] = NULL; pglob->gl_flags = flags; } save = errno; if (stream != NULL) { if (flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir) (stream); else closedir ((DIR *) stream); } __set_errno (save); return nfound == 0 ? GLOB_NOMATCH : 0; memory_error: { save = errno; if (flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir) (stream); else closedir ((DIR *) stream); __set_errno (save); } while (names != NULL) { if (names->name != NULL) free (names->name); names = names->next; } return GLOB_NOSPACE; } #endif /* Not ELIDE_CODE. */ ================================================ FILE: gl/lib/glob.in.h ================================================ /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 1998, 2023 Free Software Foundation, Inc. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef _GLOB_H #define _GLOB_H 1 #include #ifdef __cplusplus extern "C" { #endif /* Bits set in the FLAGS argument to `glob'. */ #define GLOB_ERR (1 << 0)/* Return on read errors. */ #define GLOB_MARK (1 << 1)/* Append a slash to each name. */ #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ #if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \ || defined _GNU_SOURCE) # define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */ # define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ # define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ # define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ # define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error if the user name is not available. */ # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) #else # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ GLOB_PERIOD) #endif /* Error returns from `glob'. */ #define GLOB_NOSPACE 1 /* Ran out of memory. */ #define GLOB_ABORTED 2 /* Read error. */ #define GLOB_NOMATCH 3 /* No matches found. */ #define GLOB_NOSYS 4 /* Not implemented. */ #ifdef _GNU_SOURCE /* Previous versions of this file defined GLOB_ABEND instead of GLOB_ABORTED. Provide a compatibility definition here. */ # define GLOB_ABEND GLOB_ABORTED #endif /* Structure describing a globbing run. */ #if !defined _AMIGA && !MK_OS_VMS /* Buggy compiler. */ struct stat; #endif typedef struct { size_t gl_pathc; /* Count of paths matched by the pattern. */ char **gl_pathv; /* List of matched pathnames. */ size_t gl_offs; /* Slots to reserve in `gl_pathv'. */ int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ /* If the GLOB_ALTDIRFUNC flag is set, the following functions are used instead of the normal file access functions. */ void (*gl_closedir) (void *); struct dirent *(*gl_readdir) (void *); void * (*gl_opendir) (const char *); int (*gl_lstat) (const char *, struct stat *); #if MK_OS_VMS && defined(__DECC) && !defined(_POSIX_C_SOURCE) int (*gl_stat) (const char *, struct stat *, ...); #else int (*gl_stat) (const char *, struct stat *); #endif } glob_t; #ifdef _LARGEFILE64_SOURCE struct stat64; typedef struct { size_t gl_pathc; char **gl_pathv; size_t gl_offs; int gl_flags; /* If the GLOB_ALTDIRFUNC flag is set, the following functions are used instead of the normal file access functions. */ void (*gl_closedir) (void *); struct dirent64 *(*gl_readdir) (void *); void * (*gl_opendir) (const char *); int (*gl_lstat) (const char *, struct stat64 *); int (*gl_stat) (const char *, struct stat64 *); } glob64_t; #endif #if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2 # define glob glob64 # define globfree globfree64 #else # ifdef _LARGEFILE64_SOURCE extern int glob64 (const char *pattern, int flags, int (*errfunc) (const char *, int), glob64_t *pglob); extern void globfree64 (glob64_t *pglob); # endif #endif /* Do glob searching for PATTERN, placing results in PGLOB. The bits defined above may be set in FLAGS. If a directory cannot be opened or read and ERRFUNC is not nil, it is called with the pathname that caused the error, and the `errno' value from the failing call; if it returns non-zero `glob' returns GLOB_ABEND; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ #if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2 extern int glob (const char *pattern, int flags, int (*errfunc) (const char *, int), glob_t *pglob); /* Free storage allocated in PGLOB by a previous `glob' call. */ extern void globfree (glob_t *pglob); #else extern int glob (const char *pattern, int flags, int (*errfunc) (const char *, int), glob_t *pglob) __asm__ ("glob64"); extern void globfree (glob_t *pglob) __asm__ ("globfree64"); #endif #ifdef _GNU_SOURCE /* Return nonzero if PATTERN contains any metacharacters. Metacharacters can be quoted with backslashes if QUOTE is nonzero. This function is not part of the interface specified by POSIX.2 but several programs want to use it. */ extern int glob_pattern_p (const char *pattern, int quote); #endif #ifdef __cplusplus } #endif #endif /* glob.h */ ================================================ FILE: gl/m4/acinclude.m4 ================================================ dnl acinclude.m4 -- Extra macros needed for GNU Make. dnl dnl Automake will incorporate this into its generated aclocal.m4. dnl Copyright (C) 1998-2024 Free Software Foundation, Inc. dnl This file is part of GNU Make. dnl dnl GNU Make is free software; you can redistribute it and/or modify it under dnl the terms of the GNU General Public License as published by the Free dnl Software Foundation; either version 3 of the License, or (at your option) dnl any later version. dnl dnl GNU Make is distributed in the hope that it will be useful, but WITHOUT dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for. dnl more details. dnl dnl You should have received a copy of the GNU General Public License along dnl with this program. If not, see . dnl --------------------------------------------------------------------------- dnl Got this from the lynx 2.8 distribution. dnl by T.E.Dickey dnl and Jim Spath dnl and Philippe De Muyter dnl dnl Created: 1997/1/28 dnl Updated: 1997/12/23 dnl --------------------------------------------------------------------------- dnl After checking for functions in the default $LIBS, make a further check dnl for the functions that are netlib-related (these aren't always in the dnl libc, etc., and have to be handled specially because there are conflicting dnl and broken implementations. dnl Common library requirements (in order): dnl -lresolv -lsocket -lnsl dnl -lnsl -lsocket dnl -lsocket dnl -lbsd AC_DEFUN([CF_NETLIBS],[ cf_test_netlibs=no AC_MSG_CHECKING(for network libraries) AC_CACHE_VAL(cf_cv_netlibs,[ AC_MSG_RESULT(working...) cf_cv_netlibs="" cf_test_netlibs=yes AC_CHECK_FUNCS(gethostname,,[ CF_RECHECK_FUNC(gethostname,nsl,cf_cv_netlibs,[ CF_RECHECK_FUNC(gethostname,socket,cf_cv_netlibs)])]) # # FIXME: sequent needs this library (i.e., -lsocket -linet -lnsl), but # I don't know the entrypoints - 97/7/22 TD AC_CHECK_LIB(inet,main,cf_cv_netlibs="-linet $cf_cv_netlibs") # if test "$ac_cv_func_lsocket" != no ; then AC_CHECK_FUNCS(socket,,[ CF_RECHECK_FUNC(socket,socket,cf_cv_netlibs,[ CF_RECHECK_FUNC(socket,bsd,cf_cv_netlibs)])]) fi # AC_CHECK_FUNCS(gethostbyname,,[ CF_RECHECK_FUNC(gethostbyname,nsl,cf_cv_netlibs)]) ]) LIBS="$LIBS $cf_cv_netlibs" test $cf_test_netlibs = no && echo "$cf_cv_netlibs" >&AC_FD_MSG ])dnl dnl --------------------------------------------------------------------------- dnl Re-check on a function to see if we can pick it up by adding a library. dnl $1 = function to check dnl $2 = library to check in dnl $3 = environment to update (e.g., $LIBS) dnl $4 = what to do if this fails dnl dnl This uses 'unset' if the shell happens to support it, but leaves the dnl configuration variable set to 'unknown' if not. This is a little better dnl than the normal autoconf test, which gives misleading results if a test dnl for the function is made (e.g., with AC_CHECK_FUNC) after this macro is dnl used (autoconf does not distinguish between a null token and one that is dnl set to 'no'). AC_DEFUN([CF_RECHECK_FUNC],[ AC_CHECK_LIB($2,$1,[ CF_UPPER(cf_tr_func,$1) AC_DEFINE_UNQUOTED(HAVE_$cf_tr_func,1,[Define if you have function $1]) ac_cv_func_$1=yes $3="-l$2 [$]$3"],[ ac_cv_func_$1=unknown unset ac_cv_func_$1 2>/dev/null $4], [[$]$3]) ])dnl dnl --------------------------------------------------------------------------- dnl Make an uppercase version of a variable dnl $1=uppercase($2) AC_DEFUN([CF_UPPER], [ changequote(,)dnl $1=`echo $2 | tr '[a-z]' '[A-Z]'` changequote([,])dnl ])dnl dnl --------------------------------------------------------------------------- dnl From Paul Eggert dnl Update for Darwin by Troy Runkel dnl Update for AIX by Olexiy Buyanskyy (Savannah bug 32485) AC_DEFUN([AC_STRUCT_ST_MTIM_NSEC], [AC_CACHE_CHECK([for nanoseconds field of struct stat], ac_cv_struct_st_mtim_nsec, [ac_save_CPPFLAGS="$CPPFLAGS" ac_cv_struct_st_mtim_nsec=no # st_mtim.tv_nsec -- the usual case # st_mtim._tv_nsec -- Solaris 2.6, if # (defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1 # && !defined __EXTENSIONS__) # st_mtim.st__tim.tv_nsec -- UnixWare 2.1.2 # st_mtime_n -- AIX 5.2 and above # st_mtimespec.tv_nsec -- Darwin (Mac OSX) for ac_val in st_mtim.tv_nsec st_mtim._tv_nsec st_mtim.st__tim.tv_nsec st_mtime_n st_mtimespec.tv_nsec; do CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val" AC_TRY_COMPILE([#include #include ], [struct stat s; s.ST_MTIM_NSEC;], [ac_cv_struct_st_mtim_nsec=$ac_val; break]) done CPPFLAGS="$ac_save_CPPFLAGS" ]) if test $ac_cv_struct_st_mtim_nsec != no; then AC_DEFINE_UNQUOTED([ST_MTIM_NSEC], [$ac_cv_struct_st_mtim_nsec], [Define if struct stat contains a nanoseconds field]) fi ] ) ================================================ FILE: gl/m4/dospaths.m4 ================================================ # Test if the system uses DOS-style pathnames (drive specs and backslashes) # By Paul Smith . Based on dos.m4 by Jim Meyering. # # Copyright (C) 1993-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . AC_DEFUN([pds_AC_DOS_PATHS], [ AC_CACHE_CHECK([whether system uses MSDOS-style paths], [ac_cv_dos_paths], [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __EMX__ && !defined __MSYS__ && !defined __CYGWIN__ neither MSDOS nor Windows nor OS2 #endif ]])], [ac_cv_dos_paths=yes], [ac_cv_dos_paths=no])]) AS_IF([test x"$ac_cv_dos_paths" = xyes], [ AC_DEFINE_UNQUOTED([HAVE_DOS_PATHS], 1, [Define if the system uses DOS-style pathnames.])]) ]) ================================================ FILE: gl/m4/getloadavg.m4 ================================================ # Check for getloadavg. # Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2024 Free # Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. #serial 10 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. # New applications should use gl_GETLOADAVG instead. # gl_GETLOADAVG # ------------- AC_DEFUN([gl_GETLOADAVG], [AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) # Persuade glibc to declare getloadavg(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) gl_save_LIBS=$LIBS # getloadavg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0, # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7. HAVE_GETLOADAVG=1 AC_CHECK_FUNC([getloadavg], [], [gl_func_getloadavg_done=no # Some systems with -lutil have (and need) -lkvm as well, some do not. # On Solaris, -lkvm requires nlist from -lelf, so check that first # to get the right answer into the cache. # For kstat on solaris, we need to test for libelf and libkvm to force the # definition of SVR4 below. if test $gl_func_getloadavg_done = no; then AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"]) AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"]) # Check for the 4.4BSD definition of getloadavg. AC_CHECK_LIB([util], [getloadavg], [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes]) fi if test $gl_func_getloadavg_done = no; then # There is a commonly available library for RS/6000 AIX. # Since it is not a standard part of AIX, it might be installed locally. gl_getloadavg_LIBS=$LIBS if test $cross_compiling != yes; then LIBS="-L/usr/local/lib $LIBS" fi AC_CHECK_LIB([getloadavg], [getloadavg], [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes], [LIBS=$gl_getloadavg_LIBS]) fi # Set up the replacement function if necessary. if test $gl_func_getloadavg_done = no; then HAVE_GETLOADAVG=0 # Solaris has libkstat which does not require root. AC_CHECK_LIB([kstat], [kstat_open]) test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes # AIX has libperfstat which does not require root if test $gl_func_getloadavg_done = no; then AC_CHECK_LIB([perfstat], [perfstat_cpu_total]) test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes fi if test $gl_func_getloadavg_done = no; then AC_CHECK_HEADER([sys/dg_sys_info.h], [gl_func_getloadavg_done=yes AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with .]) AC_CHECK_LIB([dgc], [dg_sys_info])]) fi fi]) if test "x$gl_save_LIBS" = x; then GETLOADAVG_LIBS=$LIBS else GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"` fi LIBS=$gl_save_LIBS AC_SUBST([GETLOADAVG_LIBS])dnl # Test whether the system declares getloadavg. Solaris has the function # but declares it in , not . AC_CHECK_HEADERS([sys/loadavg.h]) if test $ac_cv_header_sys_loadavg_h = yes; then HAVE_SYS_LOADAVG_H=1 else HAVE_SYS_LOADAVG_H=0 fi AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0], [[#if HAVE_SYS_LOADAVG_H /* OpenIndiana has a bug: must be included before . */ # include # include #endif #include ]]) ])# gl_GETLOADAVG # gl_PREREQ_GETLOADAVG # -------------------- # Set up the AC_LIBOBJ replacement of 'getloadavg'. AC_DEFUN([gl_PREREQ_GETLOADAVG], [ # Figure out what our getloadavg.c needs. AC_CHECK_HEADERS_ONCE([sys/param.h unistd.h]) # On HPUX9, an unprivileged user can get load averages this way. if test $gl_func_getloadavg_done = no; then AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes]) fi # We cannot check for , because Solaris 2 does not use dwarf (it # uses stabs), but it is still SVR4. We cannot check for because # Irix 4.0.5F has the header but not the library. if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \ && test "$ac_cv_lib_kvm_kvm_open" = yes; then gl_func_getloadavg_done=yes AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.]) fi if test $gl_func_getloadavg_done = no; then AC_CHECK_HEADER([inq_stats/cpustats.h], [gl_func_getloadavg_done=yes AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.]) AC_DEFINE([UMAX4_3], [1], [Define to 1 for Encore UMAX 4.3 that has instead of .])]) fi if test $gl_func_getloadavg_done = no; then AC_CHECK_HEADER([sys/cpustats.h], [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])]) fi if test $gl_func_getloadavg_done = no; then AC_CHECK_HEADERS([mach/mach.h]) fi AC_CHECK_HEADERS([nlist.h], [AC_CHECK_MEMBERS([struct nlist.n_un.n_name], [], [], [#include ]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[struct nlist x; #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME x.n_un.n_name = ""; #else x.n_name = ""; #endif]])], [AC_DEFINE([N_NAME_POINTER], [1], [Define to 1 if the nlist n_name member is a pointer])]) ])dnl ])# gl_PREREQ_GETLOADAVG # ---- GNU Make # These macros are imported from stdlib which we don't want to include # Only the getloadavg content is imported. AC_DEFUN_ONCE([gl_STDLIB_H], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use, and which is not dnl guaranteed by C89. gl_WARN_ON_USE_PREPARE([[#include #if HAVE_SYS_LOADAVG_H /* OpenIndiana has a bug: must be included before . */ # include # include #endif #if HAVE_RANDOM_H # include #endif ]], [getloadavg]) ]) # gl_STDLIB_MODULE_INDICATOR([modulename]) # sets the shell variable that indicates the presence of the given module # to a C preprocessor expression that will evaluate to 1. # This macro invocation must not occur in macros that are AC_REQUIREd. AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], [ dnl Ensure to expand the default settings once only. gl_STDLIB_H_REQUIRE_DEFAULTS gl_MODULE_INDICATOR_SET_VARIABLE([$1]) dnl Define it also as a C macro, for the benefit of the unit tests. gl_MODULE_INDICATOR_FOR_TESTS([$1]) ]) # Initializes the default values for AC_SUBSTed shell variables. # This macro must not be AC_REQUIREd. It must only be invoked, and only # outside of macros or in macros that are not AC_REQUIREd. AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS], [ m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS], [ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOADAVG]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS]) AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) ]) AC_DEFUN([gl_STDLIB_H_DEFAULTS], [ dnl Assume proper GNU behavior unless another module says otherwise. HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) ]) ================================================ FILE: gl/modules/concat-filename ================================================ Description: Construct a full filename by concatenating a directory name, a relative filename, and a suffix. Files: lib/concat-filename.h lib/concat-filename.c Depends-on: filename configure.ac: Makefile.am: lib_SOURCES += concat-filename.c Include: "concat-filename.h" License: LGPLv2+ Maintainer: all ================================================ FILE: gl/modules/findprog-in ================================================ Description: Locating a program in a given path. Files: lib/findprog.h lib/findprog-in.c m4/findprog-in.m4 m4/eaccess.m4 Depends-on: stdbool filename concat-filename configure.ac: gl_FINDPROG_IN Makefile.am: lib_SOURCES += findprog.h findprog-in.c Include: "findprog.h" License: LGPLv2+ Maintainer: all ================================================ FILE: gl/modules/getloadavg ================================================ Description: Return the current system load averages. Files: lib/getloadavg.c m4/getloadavg.m4 Depends-on: snippet/warn-on-use extensions intprops [test $HAVE_GETLOADAVG = 0] stdbool [test $HAVE_GETLOADAVG = 0] configure.ac: gl_STDLIB_H gl_STDLIB_H_REQUIRE_DEFAULTS AC_REQUIRE([AC_CANONICAL_HOST]) gl_GETLOADAVG gl_CONDITIONAL([GL_COND_OBJ_GETLOADAVG], [test $HAVE_GETLOADAVG = 0]) AM_COND_IF([GL_COND_OBJ_GETLOADAVG], [ gl_PREREQ_GETLOADAVG ]) gl_STDLIB_MODULE_INDICATOR([getloadavg]) Makefile.am: if GL_COND_OBJ_GETLOADAVG lib_SOURCES += getloadavg.c endif Include: Link: $(GETLOADAVG_LIBS) License: GPL Maintainer: Jim Meyering ================================================ FILE: gl/modules/make-glob ================================================ Description: GNU Make version of fnmatch()/glob() functions. This is a holdover from a very old version of the globbing library. Files: lib/fnmatch.c lib/fnmatch.in.h lib/glob.c lib/glob.in.h configure.ac: # Check the system to see if it provides GNU glob. If not, use our # local version. Also avoid versions of glibc which have symlink bug # https://sourceware.org/bugzilla/show_bug.cgi?id=866 (test from gnulib) AC_CACHE_CHECK([if system libc has working GNU glob], [make_cv_sys_gnu_glob],[ if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then make_check_symlink=yes else make_check_symlink=no fi if test $cross_compiling = yes || test $make_check_symlink = no; then # When cross-compiling or without symlink support, check the version AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[#include #include #include #include ]], [[ #if _GNU_GLOB_INTERFACE_VERSION == 0 GNU glob not available in libc #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 27) GNU glob in libc has dangling symlink bug #endif ]])], [make_cv_sys_gnu_glob=yes], [make_cv_sys_gnu_glob=no]) else # Check for GNU glob, and that it handles dangling symlinks properly AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#include #include #include #include ]], [[ #if _GNU_GLOB_INTERFACE_VERSION == 0 return 1; #else glob_t found; if (glob ("conf*-globtest", 0, 0, &found) == GLOB_NOMATCH) return 1; globfree (&found); #endif ]])], [make_cv_sys_gnu_glob=yes], [make_cv_sys_gnu_glob=no], [dnl We don't get here. : ]) fi test $make_check_symlink = no || rm -f conf$$-globtest ]) # Tell automake about this, so it can build the right .c files. AM_CONDITIONAL([USE_SYSTEM_GLOB], [test "$make_cv_sys_gnu_glob" = yes]) # Tell build.sh which to use USE_SYSTEM_GLOB="$make_cv_sys_gnu_glob" AC_SUBST([USE_SYSTEM_GLOB]) Makefile.am: if !USE_SYSTEM_GLOB libgnu_a_SOURCES += fnmatch.c BUILT_SOURCES += fnmatch.h fnmatch.h: fnmatch.in.h $(top_builddir)/config.status $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ cat $(srcdir)/fnmatch.in.h; \ } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += fnmatch.h fnmatch.h-t libgnu_a_SOURCES += glob.c BUILT_SOURCES += glob.h glob.h: glob.in.h $(top_builddir)/config.status $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ cat $(srcdir)/glob.in.h; \ } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += glob.h glob.h-t endif EXTRA_DIST += fnmatch.in.h glob.in.h Include: License: LGPLv2+ Maintainer: all, glibc ================================================ FILE: gl/modules/make-macros ================================================ Description: Install m4 macros for GNU Make. Files: m4/acinclude.m4 m4/dospaths.m4 configure.ac: # Check for DOS-style pathnames. pds_AC_DOS_PATHS License: GPLv3+ Maintainer: gnumake ================================================ FILE: maintMakefile ================================================ # Maintainer-only makefile segment. This contains things that are relevant # only if you have the full copy of the GNU Make sources from the Git # tree, not a dist copy. # --------------------- # # Updating everything. # # --------------------- # .PHONY: update update: BUGLIST := bug-make@gnu.org # These are related to my personal setup. GPG_KEYID := 80CB727A20C79BB2 # SRCROOTDIR is just a handy location to keep source files in SRCROOTDIR ?= $(HOME)/src # Where to put the CVS checkout of the GNU web repository GNUWEBDIR ?= $(SRCROOTDIR)/gnu-www # Where to put the CVS checkout of the GNU Make web repository MAKEWEBDIR ?= $(SRCROOTDIR)/make/make-web # Enable Perl warnings for the test suite PERLFLAGS := -w # We like mondo-warnings! # Also force comments to be preserved. This helps when using ccache, in # combination with GCC 7's implicit-fallthrough warning. MAKE_CFLAGS := -C -Wall -Wextra -Werror -Wwrite-strings -Wshadow \ -Wdeclaration-after-statement -Wbad-function-cast -Wformat-security \ -Wtype-limits -Wunused-but-set-parameter -Wlogical-op -Wpointer-arith \ -Wignored-qualifiers -Wformat-signedness -Wduplicated-cond # Allow extra options without overriding MAKE_CFLAGS EXTRA_CFLAGS := AM_CFLAGS += $(MAKE_CFLAGS) $(EXTRA_CFLAGS) # Unfortunately the Guile headers are sometimes broken. Convince GCC # to treat them as system headers so warnings are ignored. GUILE_CFLAGS := $(patsubst -I%,-isystem %,$(GUILE_CFLAGS)) MAKE_MAINTAINER_MODE := -DMAKE_MAINTAINER_MODE AM_CPPFLAGS += $(MAKE_MAINTAINER_MODE) # Create preprocessor output files--GCC specific! %.i : %.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) -E -dD -o $@ $< # Create the mkconfig.h file for non-POSIX config headers all: src/mkconfig.h src/mkconfig.h: src/mkconfig.h.in config.status ./config.status --header=$@ # Build the README all: README README : README.in config.status ./config.status --file=$@ # Construct Makefiles by adding on dependencies, etc. # cvt = $(patsubst $1/%,$$($1)%,$(filter %.c,$2)) Basic.mk: Basic.mk.template .dep_segment Makefile rm -f $@ sed -e 's@%make_SOURCES%@$(call cvt,src,$(make_SRCS))@g' \ -e 's@%w32_SOURCES%@$(call cvt,src,$(w32_SRCS))@g' \ -e 's@%vms_SOURCES%@$(call cvt,src,$(vms_SRCS))@g' \ -e 's@%loadavg_SOURCES%@$(call cvt,lib,$(loadavg_SRCS))@g' \ -e 's@%alloca_SOURCES%@$(call cvt,lib,$(alloca_SRCS))@g' \ -e 's@%glob_SOURCES%@$(call cvt,lib,$(glob_SRCS))@g' \ $< > $@ echo >>$@; echo '# --------------- DEPENDENCIES' >>$@; echo '#' >>$@; \ echo >>$@; echo '$$(OBJECTS): $$(SRCDIR)/src/mkconfig.h' >>$@; \ sed -e 's@^\([^ ]*\)\.o:@$$(OUTDIR)\1.$$(OBJEXT):@' \ -e 's@\([^ ]*\.[ch]\)@$$(SRCDIR)/\1@g' \ -e 's@$$(SRCDIR)/src/config.h@$$(OUTDIR)src/config.h@g' \ -e 's@$$(SRCDIR)/lib/alloca.h@@g' \ -e 's@$$(SRCDIR)/lib/stdbool.h@@g' \ $(word 2,$^) >>$@ chmod a-w $@ # Use automake to build a dependency list file, for Makebase.mk. # # Automake used to have a --generate-deps flag but it's gone now, so we have # to do it ourselves. # DEP_FILES := $(wildcard src/$(DEPDIR)/*.Po) .dep_segment: Makefile.am maintMakefile $(DEP_FILES) rm -f $@ (for f in src/$(DEPDIR)/*.Po; do \ echo ""; \ echo "# $$f"; \ sed -e '/^[^:]*\.[ch] *:/d' \ -e 's, /usr/[^ ]*,,g' \ -e 's, $(srcdir)/, ,g' \ -e '/^ *\\$$/d' \ -e '/^ *$$/d' \ < $$f; \ done) > $@ # Cleaning GIT := git # git-clean: Clean all "ignored" files. Leave untracked files. # git-very-clean: Clean all files that aren't stored in source control. .PHONY: git-clean git-very-clean git-clean: -$(GIT) clean -fdX git-very-clean: git-clean -$(GIT) clean -fdx ## ---------------------- ## ## Generating ChangeLog. ## ## ---------------------- ## # Where the gnulib project has been locally cloned GNULIBDIR ?= $(or $(wildcard $(GNULIB_SRCDIR)),./gnulib) gl2cl-date := 2013-10-10 gl2cl := $(GNULIBDIR)/build-aux/gitlog-to-changelog # Rebuild the changelog whenever a new commit is added ChangeLog: .check-git-HEAD if test -f '$(gl2cl)'; then \ '$(gl2cl)' --since='$(gl2cl-date)' > '$@'; \ else \ echo "WARNING: $(gl2cl) is not available. No $@ generated."; \ fi .check-git-HEAD: FORCE sha="`git rev-parse HEAD`"; \ test -f '$@' && [ "`cat '$@' 2>/dev/null`" = "$$sha" ] \ || echo "$$sha" > '$@' .PHONY: FORCE FORCE:;@: ## ---------------- ## ## Updating files. ## ## ---------------- ## RSYNC = rsync -Lrtvz WGET = wget --passive-ftp -np -nv ftp-gnu = ftp://ftp.gnu.org/gnu move_if_change = if test -r $(target) && cmp -s $(target).t $(target); then \ echo $(target) is unchanged; rm -f $(target).t; \ else \ mv -f $(target).t $(target); \ fi # ------------------- # # Updating PO files. # # ------------------- # # NOTE: This is handled by the bootstrap script now #update: po-update update: po-check # PO archive mirrors --- Be careful; some might not be fully populated! # ftp://ftp.unex.es/pub/gnu-i18n/po/maint/ # ftp://tiger.informatik.hu-berlin.de/pub/po/maint/ po_wget_flags = --recursive --level=1 --no-directories --no-check-certificate po_repo = https://translationproject.org/latest/$(PACKAGE) po_sync = translationproject.org::tp/latest/$(PACKAGE)/ .PHONY: do-po-update po-update do-po-update: tmppo="/tmp/po-$(PACKAGE)-$(PACKAGE_VERSION).$$$$" \ && rm -rf "$$tmppo" \ && mkdir "$$tmppo" \ && $(RSYNC) $(po_sync) "$$tmppo" \ && cp "$$tmppo"/*.po $(top_srcdir)/po \ && rm -rf "$$tmppo" cd po && $(MAKE) update-po $(MAKE) po-check po-update: test -d "po" && $(MAKE) do-po-update # -------------------------- # # Updating GNU build files. # # -------------------------- # # Note: this is handled by the bootstrap script now #update: scm-update .PHONY: scm-update scm-update: get-build-aux/texinfo.tex get-build-aux/config.guess \ get-build-aux/config.sub get-doc/make-stds.texi get-doc/fdl.texi # The following pseudo table associates a local directory and a URL # with each of the files that belongs to some other package and is # regularly updated from the specified URL. cvs-url = https://savannah.gnu.org/cgi-bin/viewcvs/~checkout~ git-url = https://git.savannah.gnu.org/cgit target = $(patsubst get-%,%,$@) config-url = $(git-url)/config.git/plain/$(patsubst get-build-aux/%,%,$@) get-build-aux/config.guess get-build-aux/config.sub: @echo Retrieving $(target) from $(config-url) $(WGET) $(config-url) -O $(target).t \ && $(move_if_change) gnulib-url = $(git-url)/gnulib.git/plain/build-aux/$(patsubst get-build-aux/%,%,$@) get-build-aux/texinfo.tex: @echo Retrieving $(target) from $(gnulib-url) $(WGET) $(gnulib-url) -O $(target).t \ && $(move_if_change) gnustandards-url = $(cvs-url)/gnustandards/gnustandards/$(patsubst get-doc/%,%,$@) get-doc/make-stds.texi get-doc/fdl.texi: @echo Retrieving $(target) from $(gnustandards-url) $(WGET) $(gnustandards-url) -O $(target).t \ && $(move_if_change) # ---------------------------- # # Extra configuration checks. # # ---------------------------- # # Make the dist file contents more regular, if we're using GNU tar. # Suggested by Tzvetelin Katchov export TAR_OPTIONS := --mode=u+w,go-w --owner=0 --group=0 --numeric-owner --sort=name # When I released 4.3 somehow the INSTALL file was missing. # When I tried to build it again, it was there. I have no idea what happened # but add a new check to be sure it doesn't happen again. mk_dist_files = AUTHORS ChangeLog COPYING INSTALL README src/mkconfig.h dist: mk-dist mk-distcheck .PHONY: mk-distcheck mk-distcheck: distdir @echo "Checking for extra installed files..." @for fn in $(mk_dist_files); do \ test -f '$(distdir)'/"$$fn" \ || { echo "Missing dist file: $$fn"; exit 1; }; \ done; true # Make sure that the files in lib/ have been updated from the files in gl/lib/ GL_LIB_FILES := $(wildcard gl/lib/*) mk-dist: @echo "Checking gl/lib files..." @for fn in $(GL_LIB_FILES); do \ cmp $$fn $${fn##gl/} \ || { echo "Run ./bootstrap --gen ?"; exit 1; }; \ done; true # ---------------------------------- # # Alternative configuration checks. # # ---------------------------------- # CFGCHECK_CONFIGFLAGS = CFGCHECK_BUILDFLAGS = # We can't use our mondo warnings as these are used to compile gnulib modules # as well, and that will fail. CFGCHECK_MAKEFLAGS = # CFLAGS='$(AM_CFLAGS)' # We don't support C90 anymore, strictly, but this test still works (with lots # of warnings) and it helps us avoid egregious incompatibilities. checkcfg.strict-c90: CFGCHECK_CONFIGFLAGS = CFLAGS='-std=c90 -pedantic' checkcfg.strict-c90: CFGCHECK_MAKEFLAGS = checkcfg.job-pipe: CFGCHECK_CONFIGFLAGS = CPPFLAGS=-DJOBSERVER_USE_FIFO=0 checkcfg.no-jobserver:CFGCHECK_CONFIGFLAGS = --disable-job-server checkcfg.no-load: CFGCHECK_CONFIGFLAGS = --disable-load checkcfg.no-guile: CFGCHECK_CONFIGFLAGS = --without-guile checkcfg.no-spawn: CFGCHECK_CONFIGFLAGS = --disable-posix-spawn checkcfg.no-sysglob: CFGCHECK_CONFIGFLAGS = make_cv_sys_gnu_glob=no checkcfg.no-loadavg: CFGCHECK_CONFIGFLAGS = ac_cv_func_getloadavg=no \ ac_cv_have_decl_getloadavg=no \ gl_cv_have_raw_decl_getloadavg=no \ ac_cv_lib_util_getloadavg=no \ ac_cv_lib_getloadavg_getloadavg=no checkcfg.no-sync: CFGCHECK_CONFIGFLAGS = CPPFLAGS=-DNO_OUTPUT_SYNC checkcfg.no-archives: CFGCHECK_CONFIGFLAGS = CPPFLAGS=-DNO_ARCHIVES CONFIG_CHECKS := \ checkcfg.strict-c90 \ checkcfg.job-pipe \ checkcfg.no-jobserver \ checkcfg.no-load \ checkcfg.no-guile \ checkcfg.no-spawn \ checkcfg.no-sysglob \ checkcfg.no-loadavg \ checkcfg.no-sync \ checkcfg.no-archives .PHONY: check-alt-config check-alt-config: $(CONFIG_CHECKS) @echo --- $@ SUCCESS # Trick GNU Make so it doesn't run the submake as a recursive make. NR_MAKE = $(MAKE) # Check builds both with build.sh and with make build.sh_SCRIPT = exec >>'checkcfg.$*.log' 2>&1; set -x; \ cd $(distdir)/_build \ && OUTDIR=_bld ../build.sh -k $(CFGCHECK_BUILD_FLAGS) \ && _bld/make GMK_OUTDIR=../_bld $(AM_MAKEFLAGS) check-local \ && _bld/make GMK_OUTDIR=../_bld $(AM_MAKEFLAGS) clean nrmake_SCRIPT = exec >>'checkcfg.$*.log' 2>&1; set -x; \ cd $(distdir)/_build \ && $(NR_MAKE) $(AM_MAKEFLAGS) $(CFGCHECK_MAKEFLAGS) \ && ./make $(AM_MAKEFLAGS) check \ && ./make $(AM_MAKEFLAGS) clean $(CONFIG_CHECKS): checkcfg.%: distdir @echo "Building $@ (output in checkcfg.$*.log)" exec >'checkcfg.$*.log' 2>&1; \ echo "Testing configure with $(CFGCHECK_CONFIGFLAGS)"; set -x; \ rm -rf $(distdir)/_build \ && mkdir $(distdir)/_build \ && cd $(distdir)/_build \ && ../configure --srcdir=.. $(CFGCHECK_CONFIGFLAGS) \ $(AM_DISTCHECK_CONFIGURE_FLAGS) $(DISTCHECK_CONFIGURE_FLAGS) $(build.sh_SCRIPT) $(nrmake_SCRIPT) # Try using Basic.mk. I can't test this on POSIX systems because it is only # used for non-POSIX systems; POSIX systems can just use normal # configure/Makefile.in etc. checkcfg.basicmk: checkcfg.% : distdir @echo "Building $@ (output in checkcfg.$*.log)" exec >'checkcfg.$*.log' 2>&1; \ echo "Testing Basic.mk SRCDIR=.."; set -x; \ rm -rf $(distdir)/_build \ && mkdir $(distdir)/_build \ && cd $(distdir)/_build \ && ../configure --srcdir=.. \ $(AM_DISTCHECK_CONFIGURE_FLAGS) $(DISTCHECK_CONFIGURE_FLAGS) exec >>'checkcfg.$*.log' 2>&1; set -x; \ cd $(distdir)/_build \ && $(NR_MAKE) $(AM_MAKEFLAGS) -f ../Basic.mk SRCDIR=.. $(CFGCHECK_MAKEFLAGS) && ./make $(AM_MAKEFLAGS) -f ../Basic.mk SRCDIR=.. check \ && ./make $(AM_MAKEFLAGS) -f ../Basic.mk SRCDIR=.. clean exec >>'checkcfg.$*.log' 2>&1; \ echo "Testing Basic.mk SRCDIR=."; set -x; \ && rm -rf $(distdir)/_build \ && cd $(distdir) \ && ./configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) $(DISTCHECK_CONFIGURE_FLAGS) \ && $(NR_MAKE) $(AM_MAKEFLAGS) -f Basic.mk '$(CFGCHECK_MAKEFLAGS)' \ && ./make $(AM_MAKEFLAGS) -f Basic.mk check \ && ./make $(AM_MAKEFLAGS) -f Basic.mk clean ## --------------- ## ## Sanity checks. ## ## --------------- ## # Before we build a distribution be sure we run our local checks #distdir: local-check .PHONY: local-check po-check changelog-check # Checks that don't require Git. Run 'changelog-check' last as # previous test may reveal problems requiring new ChangeLog entries. local-check: po-check changelog-check # copyright-check writable-files changelog-check: if head $(top_srcdir)/ChangeLog | grep 'Version $(PACKAGE_VERSION)' >/dev/null; then \ :; \ else \ echo "$(PACKAGE_VERSION) not in ChangeLog" 1>&2; \ exit 1; \ fi # Verify that all source files using _() are listed in po/POTFILES.in. # Ignore src/makeint.h; it defines _(). po-check: if test -f po/POTFILES.in; then \ grep '^[^#]' po/POTFILES.in | sort > $@-1; \ find [a-z]* -name '*.[ch]' | xargs grep -l '\b_(' | grep -v src/makeint.h | sort > $@-2; \ diff -u $@-1 $@-2 || exit 1; \ rm -f $@-1 $@-2; \ fi ## --------------- ## ## Generate docs. ## ## --------------- ## .PHONY: update-makeweb gendocs CVS = cvs makeweb-repo = $(USER)@cvs.sv.gnu.org:/web/make gnuweb-repo = :pserver:anonymous@cvs.sv.gnu.org:/web/www gnuweb-dir = www/server/standards # Get the GNU Make web page boilerplate etc. update-makeweb: test -d '$(MAKEWEBDIR)' || mkdir -p '$(MAKEWEBDIR)' test -d '$(MAKEWEBDIR)'/CVS \ && { cd '$(MAKEWEBDIR)' && $(CVS) update; } \ || { mkdir -p '$(dir $(MAKEWEBDIR))' && cd '$(dir $(MAKEWEBDIR))' \ && $(CVS) -d $(makeweb-repo) co -d '$(notdir $(MAKEWEBDIR))' make; } # Get the GNU web page boilerplate etc. update-gnuweb: test -d '$(GNUWEBDIR)' || mkdir -p '$(GNUWEBDIR)' test -d '$(GNUWEBDIR)/$(gnuweb-dir)'/CVS \ && { cd '$(GNUWEBDIR)/$(gnuweb-dir)' && $(CVS) update; } \ || { cd '$(GNUWEBDIR)' && $(CVS) -d $(gnuweb-repo) co '$(gnuweb-dir)'; } gendocs: update-gnuweb update-makeweb cp $(GNULIBDIR)/doc/gendocs_template doc cd doc \ && rm -rf doc/manual \ && $(GNULIBDIR)/build-aux/gendocs.sh --email '$(BUGLIST)' \ make '$(PACKAGE_NAME) Manual' find '$(MAKEWEBDIR)'/manual \( -name CVS -prune \) -o \( -name '[!.]*' -type f -exec rm -f '{}' \; \) cp -r doc/manual '$(MAKEWEBDIR)' @echo 'Status of $(MAKEWEBDIR) repo:' && cd '$(MAKEWEBDIR)' \ && cvs -q -n update | grep -v '^M ' @echo '- cvs add ' \ && echo '- cvs remove ' \ && echo '- cvs commit' \ && echo '- cvs tag make-$(subst .,-,$(PACKAGE_VERSION))' ## --------------------------------------------- ## ## Submitting Coverity cov-build results to Scan ## ## --------------------------------------------- ## # Note you must have set COVERITY_TOKEN and COVERITY_EMAIL properly # to submit results. COVERITY_PATH can be set to the root of the # cov-build tools if it's not already on your PATH. COV_BUILD_FILE := cov-build.tgz .PHONY: cov-build cov-submit cov-build: $(COV_BUILD_FILE) $(COV_BUILD_FILE): $(filter %.c %.h,$(DISTFILES)) $(MAKE) distdir @echo "Running Coverity cov-build" rm -rf '$(distdir)'/_build mkdir '$(distdir)'/_build cd '$(distdir)'/_build \ && ../configure --srcdir=.. \ $(AM_DISTCHECK_CONFIGURE_FLAGS) $(DISTCHECK_CONFIGURE_FLAGS) \ $(CFGCHECK_MAKEFLAGS) PATH="$${COVERITY_PATH:+$$COVERITY_PATH/bin:}$$PATH"; \ cd '$(distdir)'/_build \ && cov-build --dir cov-int ../build.sh rm -f '$@' (cd '$(distdir)'/_build && tar czf - cov-int) > '$@' cov-submit: $(COV_BUILD_FILE)-submitted $(COV_BUILD_FILE)-submitted: $(COV_BUILD_FILE) @test -n "$(COVERITY_TOKEN)" || { echo 'COVERITY_TOKEN not set'; exit 1; } @test -n "$(COVERITY_EMAIL)" || { echo 'COVERITY_EMAIL not set'; exit 1; } rm -f '$@' case '$(PACKAGE_VERSION)' in \ (*.*.9*) type="daily build"; ext=".$$(date +%Y%m%d)" ;; \ (*) type="release"; ext= ;; \ esac; \ curl --form token='$(COVERITY_TOKEN)' \ --form email='$(COVERITY_EMAIL)' \ --form file='@$<' \ --form version="$(PACKAGE_VERSION)$$ext" \ --form description="$(PACKAGE_NAME) $$type" \ 'https://scan.coverity.com/builds?project=gmake' cp '$<' '$@' ## ------------------------- ## ## Make release targets. ## ## ------------------------- ## .PHONY: tag-release tag-release: case '$(PACKAGE_VERSION)' in \ (*.*.9*) message=" candidate" ;; \ (*) message= ;; \ esac; \ $(GIT) tag -m "$(PACKAGE_NAME) release$$message $(PACKAGE_VERSION)" -u '$(GPG_KEYID)' '$(PACKAGE_VERSION)' ## ------------------------- ## ## GNU FTP upload artifacts. ## ## ------------------------- ## # This target creates the upload artifacts. # Sign it with my key. If you don't have my key/passphrase then sorry, # you're SOL! :) GNUPLOAD := $(GNULIBDIR)/build-aux/gnupload UPLOADS = upload-alpha upload-ftp .PHONY: $(UPLOADS) $(UPLOADS): upload-%: $(DIST_ARCHIVES) $(GNUPLOAD) --user "$(GPG_KEYID)" --to "$*.gnu.org:make" -- $^ # Rebuild Makefile.in if this file is modified. Makefile.in: maintMakefile # Copyright (C) 1997-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . ================================================ FILE: make-gdb.py ================================================ """GDB pretty-printer macros for GNU Make.""" import gdb # pylint: disable=import-error import gdb.printing # pylint: disable=import-error # Memoize types we commonly use _TYPES = {} def getType(tname): """Given a type name return a GDB type.""" global _TYPES if tname not in _TYPES: tn = tname.rstrip('*') if tn not in _TYPES: _TYPES[tn] = gdb.lookup_type(tn) while tn != tname: # Want a pointer type t = tn tn += '*' _TYPES[tn] = _TYPES[t].pointer() return _TYPES[tname] def isNullptr(val): """Return True if the value is a null pointer.""" return int(val.cast(getType('unsigned long long'))) == 0 class ShowArgv(gdb.Command): """Print a null-terminated array of strings. Argument: A char** where the last one is NULL (e.g., argv) """ def __init__(self): """Create the showargv function.""" gdb.Command.__init__(self, "showargv", gdb.COMMAND_USER) def invoke(self, arg, from_tty): """Show the argv.""" args = gdb.string_to_argv(arg) if len(args) != 1: raise gdb.GdbError(self._usage) val = gdb.parse_and_eval(args[0]) if val is None: raise gdb.GdbError('%s is not a valid expression' % (args[0])) strs = [] while not isNullptr(val.dereference()): strs.append('"'+val.dereference().string()+'"') val += 1 gdb.write("[%d] = [%s]\n" % (len(strs), ', '.join(strs))) gdb.flush() ShowArgv() class ShowNextList(gdb.Command): """Print a structure that has a "next" pointer. Argument: A pointer to a struct which contains a "next" member. """ _usage = 'usage: showlist ' def __init__(self): """Create a "showlist" function.""" gdb.Command.__init__(self, "showlist", gdb.COMMAND_USER) def invoke(self, arg, from_tty): """Show the elements in the provided list.""" args = gdb.string_to_argv(arg) if len(args) != 1: raise gdb.GdbError(self._usage) val = gdb.parse_and_eval(args[0]) if val is None: raise gdb.GdbError('%s is not a valid expression' % (args[0])) i = 0 while not isNullptr(val): gdb.write("%s : %s\n" % (val, val.dereference())) gdb.flush() i += 1 val = val['next'] gdb.write("%s contains %d elements\n" % (args[0], i)) gdb.flush() ShowNextList() class FileLocation(object): """Print a file location.""" def __init__(self, val): """Create a FileLocation object.""" self.val = val def to_string(self): """Convert a FileLocation to a string.""" if int(self.val['filenm']): return "%s:%d" % (str(self.val['filenm']), self.val['lineno']) return 'NILF' class StringListPrinter(object): """Print a stringlist.""" def __init__(self, val): """Create a StringListPrinter object.""" self.val = val def to_string(self): """Convert a HashTable into a string.""" return "size=%d, capacity=%d" % (self.val['idx'], self.val['max']) def children(self): """Yield each string in the list.""" i = 0 elts = self.val['list'] while i < self.val['idx']: nm = '[%d] ' % i yield (nm, elts.dereference()) i += 1 elts += 1 def display_hint(self): """Show the display hint for the pretty-printer.""" return 'array' class VariablePrinter(object): """Print a struct variable.""" def __init__(self, val): """Create a VariablePrinter object.""" self.val = val def to_string(self): """Convert a VariablePrinter object into a string.""" if self.val['append']: a = '+=' elif self.val['conditional']: a = '?=' else: a = '=' flags = [] s = str(self.val['flavor']) if s != 'f_bogus': flags.append(s) s = str(self.val['origin']) if s != 'o_default': flags.append(s) s = str(self.val['export']) if s != 'v_default': flags.append(s) return '%s[%s]: "%s" %s "%s"' % ( self.val['fileinfo'], ','.join(flags), self.val['name'].string(), a, self.val['value'].string()) class HashTablePrinter(object): """Pretty-print a hash table.""" DELITEM = None def __init__(self, val): """Create a HashTablePrinter object.""" self.val = val def to_string(self): """Convert a HashTable into a string.""" return "size=%d, capacity=%d, empty=%d, collisions=%d, rehashes=%d" % ( self.val['ht_size'], self.val['ht_capacity'], self.val['ht_empty_slots'], self.val['ht_collisions'], self.val['ht_rehashes']) def children(self): """Yield each ID and value.""" for (i, v) in self.iterator(): nm = '[%d] ' % i yield (nm, i) yield (nm, v) def iterator(self): """Provide an iterator for HashTable.""" if HashTablePrinter.DELITEM is None: HashTablePrinter.DELITEM = gdb.lookup_global_symbol('hash_deleted_item').value() lst = self.val['ht_vec'] for i in range(0, self.val['ht_size']): v = lst[i] if int(v) != 0 and v != HashTablePrinter.DELITEM: yield (i, v) def display_hint(self): """Show the display hint for the pretty-printer.""" return 'map' class VariableSetPrinter(object): """Print a variable_set.""" def __init__(self, val): """Create a variable_set pretty-printer.""" self.tbl = HashTablePrinter(val['table']) def to_string(self): """Convert a variable_set to string.""" return self.tbl.to_string() def children(self): """Iterate through variables and values.""" for (i, v) in self.tbl.iterator(): ptr = v.cast(getType('struct variable*')) nm = '[%d] ' % (i) yield (nm, ptr) yield (nm, str(ptr.dereference())) def display_hint(self): """Show the display hint for the pretty-printer.""" return 'map' class VariableSetListPrinter(object): """Print a variable_set_list.""" GLOBALSET = None def __init__(self, val): """Create a variable_set_list pretty-printer.""" self.val = val def to_string(self): """Convert a variable_set_list to string.""" return str(self.val.address) def children(self): """Iterate through variables and values.""" if VariableSetListPrinter.GLOBALSET is None: block = gdb.lookup_global_symbol('init_hash_global_variable_set').symtab.static_block() VariableSetListPrinter.GLOBALSET = gdb.lookup_symbol( 'global_variable_set', block)[0].value().address ptr = self.val.address i = 0 while not isNullptr(ptr): nm = '[%d] ' % (i) yield (nm, ptr['set']) if int(ptr['set']) == int(VariableSetListPrinter.GLOBALSET): yield (nm, "global_variable_set") else: yield (nm, str(ptr['set'].dereference())) i += 1 ptr = ptr['next'] def display_hint(self): """Show the display hint for the pretty-printer.""" return 'map' def build_pretty_printer(): """Install all the pretty-printers.""" pp = gdb.printing.RegexpCollectionPrettyPrinter("gnumake") pp.add_printer('floc', r'^floc$', FileLocation) pp.add_printer('stringlist', r'^stringlist$', StringListPrinter) pp.add_printer('variable', r'^variable$', VariablePrinter) pp.add_printer('hashtable', r'^hash_table$', HashTablePrinter) pp.add_printer('variableset', r'^variable_set$', VariableSetPrinter) pp.add_printer('variablesetlist', r'^variable_set_list$', VariableSetListPrinter) return pp # Use replace=True so we can re-source this file gdb.printing.register_pretty_printer(gdb.current_objfile(), build_pretty_printer(), replace=True) ================================================ FILE: makefile.com ================================================ $! $! Makefile.com - builds GNU Make for VMS $! $! P1 = LIST will provide compiler listings. $! P2 = DEBUG will build an image with debug information $! P3 = WALL will enable all warning messages (some are suppressed since $! one macro intentionally causes an error condition) $! $! In case of problems with the install you might contact me at $! zinser@decus.de (preferred) or zinser@sysdev.deutsche-boerse.com $ $! hb $! But don't ask Martin Zinser about the lines, I added/changed. $! In case of an error do some cleanup $ on error then $ goto cleanup $! in case somebody set up her/his own symbol for cc $ set symbol/scope=(nolocal,noglobal) $! $! Just some general constants... $! $ true = 1 $ false = 0 $ tmpnam = "temp_" + f$getjpi("","pid") $ tt = tmpnam + ".txt" $ tc = tmpnam + ".c" $! $! Look for the compiler used $! $ lval = "" $ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" $ then $ if f$trnlnm("SYS").eqs."" then def/nolog sys sys$library: $ ccopt = "" $ else $ ccopt = "/decc/prefix=(all,except=(globfree,glob))" $ if f$trnlnm("SYS").eqs."" $ then $ if f$trnlnm("DECC$LIBRARY_INCLUDE").nes."" $ then $ define sys decc$library_include: $ else $ if f$search("SYS$COMMON:[DECC$LIB.REFERENCE]DECC$RTLDEF.DIR").nes."" - then lval = "SYS$COMMON:[DECC$LIB.REFERENCE.DECC$RTLDEF]," $ if f$search("SYS$COMMON:[DECC$LIB.REFERENCE]SYS$STARLET_C.DIR").nes."" - then lval = lval+"SYS$COMMON:[DECC$LIB.REFERENCE.SYS$STARLET_C]," $ lval=lval+"SYS$LIBRARY:" $ define sys 'lval $ endif $ endif $ endif $! $! $ if (p1 .eqs. "LIST") $ then $ ccopt = ccopt + "/list/show=(expan,inclu)" $ endif $! $! Should we build a debug image $! $ if (p2.eqs."DEBUG") $ then $ ccopt = ccopt + "/noopt/debug" $ lopt = "/debug" $ else $ lopt = "" $ endif $! $! Do we want to see all warnings $! $ if (p3.nes."WALL") $ then $ gosub check_cc_qual $ endif $ filelist = "[.src]ar [.src]arscan [.src]commands [.src]default [.src]dir " + - "[.src]expand [.src]file [.src]function [.src]guile " + - "[.src]hash [.src]implicit [.src]job [.src]load [.src]main " + - "[.src]misc [.src]read [.src]remake [.src]remote-stub " + - "[.src]rule [.src]output [.src]signame [.src]variable " + - "[.src]version [.src]shuffle [.src]strcache [.src]vpath " + - "[.src]vmsfunctions [.src]vmsify [.src]vms_progname " + - "[.src]vms_exit [.src]vms_export_symbol " + - "[.lib]alloca [.lib]fnmatch [.lib]glob [.src]getopt1 [.src]getopt" $! $ copy [.src]config.h-vms [.src]config.h $ copy [.lib]fnmatch.in.h [.lib]fnmatch.h $ copy [.lib]glob.in.h [.lib]glob.h $ n=0 $ open/write optf make.opt $ loop: $ cfile = f$elem(n," ",filelist) $ if cfile .eqs. " " then goto linkit $ write sys$output "Compiling ''cfile'..." $ call compileit 'cfile' $ n = n + 1 $ goto loop $ linkit: $ close optf $ link/exe=make make.opt/opt'lopt $ goto cleanup $ $ cleanup: $ if f$trnlnm("SYS").nes."" then $ deassign sys $ if f$trnlnm("OPTF").nes."" then $ close optf $ if f$search("make.opt").nes."" then $ del make.opt;* $ exit $! $!----------------------------------------------------------------------------- $! $! Check if this is a define relating to the properties of the C/C++ $! compiler $! $CHECK_CC_QUAL: $ open/write tmpc 'tc $ ccqual = "/warn=(disable=questcompare)" $ write tmpc "#include " $ write tmpc "unsigned int i = 1;" $ write tmpc "int main(){" $ write tmpc "if (i < 0){printf(""Mission impossible\n"");}}" $ close tmpc $ gosub cc_qual_check $ return $! $!----------------------------------------------------------------------------- $! $! Check for properties of C/C++ compiler $! $CC_QUAL_CHECK: $ cc_qual = false $ set message/nofac/noident/nosever/notext $ cc 'ccqual' 'tmpnam' $ if $status then cc_qual = true $ set message/fac/ident/sever/text $ delete/nolog 'tmpnam'.*;* $ if cc_qual then ccopt = ccopt + ccqual $ return $!----------------------------------------------------------------------------- $! $ compileit : subroutine $ ploc = f$locate("]",p1) $! filnam = p1 $ if ploc .lt. f$length(p1) $ then $ objdir = f$extract(0, ploc+1, p1) $ write optf p1 $ else $ objdir := [] $ write optf objdir+p1 $ endif $ cc'ccopt'/nested=none/include=([],[.src],[.lib])/obj='objdir' - /define=("allocated_variable_expand_for_file=alloc_var_expand_for_file",- "unlink=remove","HAVE_CONFIG_H","VMS") - 'p1' $ exit $ endsubroutine : compileit $! $!----------------------------------------------------------------------------- $!Copyright (C) 1996-2024 Free Software Foundation, Inc. $!This file is part of GNU Make. $! $!GNU Make is free software; you can redistribute it and/or modify it under $!the terms of the GNU General Public License as published by the Free Software $!Foundation; either version 3 of the License, or (at your option) any later $!version. $! $!GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY $!WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS $!FOR A PARTICULAR PURPOSE. See the GNU General Public License for more $!details. $! $!You should have received a copy of the GNU General Public License along with $!this program. If not, see . ================================================ FILE: mk/Posix.mk.in ================================================ # GNU -*-Makefile-*- to build GNU Make on POSIX systems # # POSIX overrides for use with Basic.mk. # # Copyright (C) 2017-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # Very little is needed here since the default Basic.mk assumes POSIX prog_SOURCES += $(src)/posixos.c extra_CPPFLAGS += @GUILE_CFLAGS@ extra_LDFLAGS += @AM_LDFLAGS@ LDLIBS += @LIBOBJS@ @gl_LIBOBS@ @ALLOCA@ LDLIBS += @GUILE_LIBS@ @GETLOADAVG_LIBS@ @LIBINTL@ @LIBS@ ================================================ FILE: mk/VMS.mk ================================================ # GNU -*-Makefile-*- to build GNU Make on VMS # # VMS overrides for use with Basic.mk. # # Copyright (C) 2017-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . src = [.src] lib = [.lib] SRCDIR = [] OBJEXT = .obj EXEEXT = .exe e = s = $e $e c = , defs = HAVE_CONFIG_H ifeq ($(CC),cc) defs += VMS unlink=remove allocated_variable_expand_for_file=alloc_var_expand_for_file else defs += GCC_IS_NATIVE ifeq ($(ARCH),VAX) defs += VAX endif endif extra_CPPFLAGS = /define=($(subst $s,$c,$(patsubst %,"%",$(defs)))) cinclude = /nested=none/include=($(src),$(lib)) ifeq ($(CC),cc) cprefix = /prefix=(all,except=(glob,globfree)) cwarn = /standard=relaxed/warn=(disable=questcompare) endif extra_CFLAGS = $(cinclude)$(cprefix)$(cwarn) #extra_LDFLAGS = /deb extra_LDFLAGS = # If your system needs extra libraries loaded in, define them here. # System V probably need -lPW for alloca. # if on vax, uncomment the following line #LDLIBS = ,c.opt/opt ifeq ($(CC),cc) #LDLIBS =,sys$$library:vaxcrtl.olb/lib else LDLIBS =,gnu_cc_library:libgcc.olb/lib endif # If your system doesn't have alloca, or the one provided is bad, # uncomment this #ALLOCA = $(alloca_SOURCES) # If your system doesn't have alloca.h, or the one provided is bad, # uncomment this #BUILT_SOURCES += $(lib)alloca.h prog_SOURCES += $(ALLOCA) $(glob_SOURCES) $(vms_SOURCES) BUILT_SOURCES += $(lib)fnmatch.h $(lib)glob.h COMPILE.cmd = $(CC) $(extra_CFLAGS)$(CFLAGS)/obj=$@ $(extra_CPPFLAGS)$(CPPFLAGS) $1 LINK.cmd = $(LD)$(extra_LDFLAGS)$(LDFLAGS)/exe=$@ $(subst $s,$c,$1)$(LDLIBS) # Don't know how to do this CHECK.cmd = MKDIR.cmd = create/dir $1 RM.cmd = delete $1 CP.cmd = copy $1 $2 define CLEANSPACE -purge [...] -delete $(PROG); -delete $(src)*.$(OBJEXT); endef $(OUTDIR)$(src)config.h: $(SRCDIR)$(src)config.h-vms $(call CP.cmd,$<,$@) ================================================ FILE: mk/Windows32.mk ================================================ # GNU -*-Makefile-*- to build GNU Make on Windows # # Windows overrides for use with Basic.mk. # # Copyright (C) 2017-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # TARGET_TYPE can be either "release" or "debug" TARGET_TYPE = release # TOOLCHAIN can be either "msvc" or "gcc" TOOLCHAIN = msvc # Translate a POSIX path into a Windows path. Don't bother with drives. # Used only inside recipes, with DOS/CMD tools that require it. P2W = $(subst /,\,$1) prog_SOURCES += $(loadavg_SOURCES) $(glob_SOURCES) $(w32_SOURCES) utf8_SOURCES = $(src)w32/utf8.rc $(src)w32/utf8.manifest BUILT_SOURCES += $(lib)alloca.h $(lib)fnmatch.h $(lib)glob.h w32_LIBS = kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 \ oleaut32 uuid odbc32 odbccp32 CPPFLAGS = CFLAGS = LDFLAGS = # --- Visual Studio msvc_CC = cl.exe msvc_RC = rc.exe msvc_LD = link.exe msvc_CPPFLAGS = /DHAVE_CONFIG_H /DMK_OS_W32=1 /DWIN32 /D_CONSOLE msvc_CPPFLAGS += /I$(OUTDIR)src /I$(SRCDIR)/src /I$(SRCDIR)/src/w32/include /I$(OUTDIR)lib /I$(SRCDIR)/lib msvc_CFLAGS = /nologo /MT /W4 /EHsc msvc_CFLAGS += /FR$(OUTDIR) /Fp$(BASE_PROG).pch /Fd$(BASE_PROG).pdb msvc_LDFLAGS = /nologo /SUBSYSTEM:console /PDB:$(BASE_PROG).pdb msvc_LDLIBS = $(addsuffix .lib,$(w32_LIBS)) msvc_C_SOURCE = /c msvc_RC_SOURCE = msvc_OUTPUT_OPTION = /Fo$@ msvc_LINK_OUTPUT = /OUT:$@ release_msvc_OUTDIR = ./WinRel/ release_msvc_CPPFLAGS = /D NDEBUG release_msvc_CFLAGS = /O2 debug_msvc_OUTDIR = ./WinDebug/ debug_msvc_CPPFLAGS = /D _DEBUG debug_msvc_CFLAGS = /Zi /Od debug_msvc_LDFLAGS = /DEBUG # --- GCC gcc_CC = gcc gcc_RC = windres gcc_LD = $(gcc_CC) release_gcc_OUTDIR = ./GccRel/ debug_gcc_OUTDIR = ./GccDebug/ gcc_CPPFLAGS = -DHAVE_CONFIG_H -I$(OUTDIR)src -I$(SRCDIR)/src -I$(SRCDIR)/src/w32/include -I$(OUTDIR)lib -I$(SRCDIR)/lib gcc_CFLAGS = -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 gcc_LDFLAGS = -mthreads -gdwarf-2 -g3 gcc_LDLIBS = $(addprefix -l,$(w32_libs)) gcc_C_SOURCE = -c gcc_RC_SOURCE = -i gcc_OUTPUT_OPTION = -o $@ gcc_LINK_OUTPUT = -o $@ debug_gcc_CFLAGS = -O0 release_gcc_CFLAGS = -O2 # --- RES_COMPILE.cmd = $(RC) $(OUTPUT_OPTION) $(RC_SOURCE) $1 LINK.cmd = $(LD) $(extra_LDFLAGS) $(LDFLAGS) $(TARGET_ARCH) $1 $(LDLIBS) $(LINK_OUTPUT) CHECK.cmd = cmd /c cd tests \& .\run_make_tests.bat -make ../$(PROG) MKDIR.cmd = cmd /c mkdir $(call P2W,$1) RM.cmd = cmd /c del /F /Q $(call P2W,$1) CP.cmd = cmd /c copy /Y $(call P2W,$1 $2) CC = $($(TOOLCHAIN)_CC) RC = $($(TOOLCHAIN)_RC) LD = $($(TOOLCHAIN)_LD) C_SOURCE = $($(TOOLCHAIN)_C_SOURCE) RC_SOURCE = $($(TOOLCHAIN)_RC_SOURCE) OUTPUT_OPTION = $($(TOOLCHAIN)_OUTPUT_OPTION) LINK_OUTPUT = $($(TOOLCHAIN)_LINK_OUTPUT) OUTDIR = $($(TARGET_TYPE)_$(TOOLCHAIN)_OUTDIR) OBJEXT = obj EXEEXT = .exe _CUSTOM = $($(TOOLCHAIN)_$1) $($(TARGET_TYPE)_$1) $($(TARGET_TYPE)_$(TOOLCHAIN)_$1) # I'm not sure why this builds gnumake rather than make...? PROG = $(OUTDIR)gnumake$(EXEEXT) BASE_PROG = $(basename $(PROG)) extra_CPPFLAGS = $(call _CUSTOM,CPPFLAGS) extra_CFLAGS = $(call _CUSTOM,CFLAGS) extra_LDFLAGS = $(call _CUSTOM,LDFLAGS) LDLIBS = $(call _CUSTOM,LDLIBS) $(OUTDIR)src/config.h: $(SRCDIR)/src/config.h.W32 $(call CP.cmd,$<,$@) w32_UTF8OBJ = $(OUTDIR)src/w32/utf8.$(OBJEXT) $(w32_UTF8OBJ): $(utf8_SOURCES) $(call RES_COMPILE.cmd,$<) ifneq (, $(shell where $(RC) 2>nul)) RESOURCE_OBJECTS = $(w32_UTF8OBJ) endif ================================================ FILE: mk/msdosdjgpp.mk ================================================ # GNU -*-Makefile-*- to build GNU Make on MS-DOS with DJGPP # # MS-DOS overrides for use with Basic.mk. # # Copyright (C) 2017-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . OBJEXT = o EXEEXT = .exe CC = gcc # Translate a POSIX path into a Windows path. Don't bother with drives. # Used only inside recipes, with DOS/CMD tools that require it. P2W = $(subst /,\,$1) prog_SOURCES += $(loadavg_SOURCES) $(glob_SOURCES) BUILT_SOURCES += $(lib)alloca.h $(lib)fnmatch.h $(lib)glob.h INCLUDEDIR = c:/djgpp/include LIBDIR = c:/djgpp/lib LOCALEDIR = c:/djgpp/share MKDIR.cmd = command.com /c mkdir $(call P2W,$1) RM.cmd = command.com /c del /F /Q $(call P2W,$1) CP.cmd = command.com /c copy /Y $(call P2W,$1 $2) $(OUTDIR)src/config.h: $(SRCDIR)/src/configh.dos $(call CP.cmd,$<,$@) ================================================ FILE: po/.gitignore ================================================ * !.gitignore !LINGUAS !POTFILES.in ================================================ FILE: po/LINGUAS ================================================ be bg cs da de es fi fr ga gl he hr id it ja ka ko lt nl pl pt pt_BR ro ru sr sv tr uk vi zh_CN zh_TW ================================================ FILE: po/POTFILES.in ================================================ # List of source files containing translatable strings. # Copyright (C) 2000-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . src/ar.c src/arscan.c src/commands.c src/dir.c src/expand.c src/file.c src/function.c src/getopt.c src/guile.c src/hash.c src/implicit.c src/job.c src/load.c src/main.c src/misc.c src/output.c src/posixos.c src/read.c src/remake.c src/remote-cstms.c src/rule.c src/shuffle.c src/signame.c src/strcache.c src/variable.c src/vmsfunctions.c src/vmsjobs.c src/vpath.c src/warning.c src/warning.h src/w32/w32os.c ================================================ FILE: prepare_vms.com ================================================ $! $! prepare_vms.com - Build config.h-vms from master on VMS. $! $! This is used for building off the master instead of a release tarball. $! $! $! First try ODS-5, Pathworks V6 or UNZIP name. $! $ config_template = f$search("sys$disk:[.src]mkconfig*h.in") $ if config_template .eqs. "" $ then $! $! Try NFS, VMStar, or Pathworks V5 ODS-2 encoded name. $! $ config_template = f$search("sys$disk:[.src]mkconfig.h*in") $ if config_template .eqs. "" $ then $ write sys$output "Could not find mkconfig.h.in!" $ exit 44 $ endif $ endif $ config_template_file = f$parse(config_template,,,"name") $ config_template_type = f$parse(config_template,,,"type") $ config_template = "sys$disk:[.src]" + config_template_file + config_template_type $! $! $! Pull the version from configure.ac $! $ open/read ac_file sys$disk:[]configure.ac $ac_read_loop: $ read ac_file/end=ac_read_loop_end line_in $ key = f$extract(0, 7, line_in) $ if key .nes. "AC_INIT" then goto ac_read_loop $ package = f$element (1,"[",line_in) $ package = f$element (0,"]",package) $ version = f$element (2,"[",line_in) $ version = f$element (0,"]",version) $ac_read_loop_end: $ close ac_file $! $ if (version .eqs. "") $ then $ write sys$output "Unable to determine version!" $ exit 44 $ endif $! $! $ outfile = "sys$disk:[.src]mkconfig.h" $! $! Note the pipe command is close to the length of 255, which is the $! maximum token length prior to VMS V8.2: $! %DCL-W-TKNOVF, command element is too long - shorten $! PDS: Blown out; someone else will have to figure this out $ pipe (write sys$output "sub,@PACKAGE@,make,WHOLE/NOTYPE" ;- write sys$output "sub,@PACKAGE_BUGREPORT@,bug-make@gnu.org,WHOLE/NOTYPE" ;- write sys$output "sub,@PACKAGE_NAME@,GNU Make,WHOLE/NOTYPE" ;- write sys$output "sub,@PACKAGE_TARNAME@,make,WHOLE/NOTYPE" ;- write sys$output "sub,@PACKAGE_URL@,https://www.gnu.org/software/make/,WHOLE/NOTYPE" ;- write sys$output "sub,@PACKAGE_VERSION@,''version',WHOLE/NOTYPE" ;- write sys$output "exit") |- edit/edt 'config_template'/out='outfile'/command=sys$pipe >nla0: $! $ write sys$output "GNU Make version: ", version, " prepared for VMS" ================================================ FILE: scripts/copyright-update ================================================ #!/bin/sh # # Copyright (C) 2014-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # Update GNU Make copyrights using gnulib update-copyright EXCLUDE='^\(\.[a-z].*\|.*/\.[a-z].*\|.*COPYING\|src/hash\.[ch]\|ChangeLog.*\|.*/ChangeLog.*\|INSTALL\|doc/make\.texi\|bootstrap\)$' update=${UPDATE_COPYRIGHT:-${GNULIB_SRCDIR:-../../gnulib}/build-aux/update-copyright} die () { echo "$*"; exit 1; } getfiles () { git ls-files | grep -v "$EXCLUDE" } run () { cmd=$(command -v "$update") || die "Cannot locate update-copyright ($update)" test -x "$cmd" || die "Cannot locate update-copyright ($update)" force=false case $1 in (-v) getfiles | sort; exit 0 ;; (-f) force=true ;; (--) : ;; (-*) echo "usage: $0 [-v]"; exit 1 ;; esac if $force; then : just do it elif test ! -f src/makeint.h; then die "Run in the root of the GNU Make workspace" elif test -f configure; then die "Run in a clean workspace (git clean -fdX)" fi # We use intervals export UPDATE_COPYRIGHT_USE_INTERVALS=1 "$cmd" $(getfiles) echo "*** Update doc/make.texi copyright by hand!" echo "*** Update src/main.c:print_version() copyright by hand!" exit 0 } run "$@" # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . ================================================ FILE: src/ar.c ================================================ /* Interface to 'ar' archives for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #ifndef NO_ARCHIVES #include "filedef.h" #include "dep.h" #include #include /* Return nonzero if NAME is an archive-member reference, zero if not. An archive-member reference is a name like 'lib(member)' where member is a non-empty string. If a name like 'lib((entry))' is used, a fatal error is signaled at the attempt to use this unsupported feature. */ int ar_name (const char *name) { const char *p = strchr (name, '('); const char *end; if (p == NULL || p == name) return 0; end = p + strlen (p) - 1; if (*end != ')' || end == p + 1) return 0; if (p[1] == '(' && end[-1] == ')') OS (fatal, NILF, _("attempt to use unsupported feature: '%s'"), name); return 1; } /* Parse the archive-member reference NAME into the archive and member names. Creates one allocated string containing both names, pointed to by ARNAME_P. MEMNAME_P points to the member. */ void ar_parse_name (const char *name, char **arname_p, char **memname_p) { char *p; *arname_p = xstrdup (name); p = strchr (*arname_p, '('); /* This is never called unless ar_name() is true so p cannot be NULL. */ if (!p) OS (fatal, NILF, "INTERNAL: ar_parse_name: bad name '%s'", *arname_p); *(p++) = '\0'; p[strlen (p) - 1] = '\0'; *memname_p = p; } /* This function is called by 'ar_scan' to find which member to look at. */ /* ARGSUSED */ static intmax_t ar_member_date_1 (int desc UNUSED, const char *mem, int truncated, long int hdrpos UNUSED, long int datapos UNUSED, long int size UNUSED, intmax_t date, int uid UNUSED, int gid UNUSED, unsigned int mode UNUSED, const void *name) { return ar_name_equal (name, mem, truncated) ? date : 0; } /* Return the modtime of NAME. */ time_t ar_member_date (const char *name) { char *arname; char *memname; intmax_t val; ar_parse_name (name, &arname, &memname); /* Make sure we know the modtime of the archive itself because we are likely to be called just before commands to remake a member are run, and they will change the archive itself. But we must be careful not to enter_file the archive itself if it does not exist, because pattern_search assumes that files found in the data base exist or can be made. */ { struct file *arfile; arfile = lookup_file (arname); if (arfile == 0 && file_exists_p (arname)) arfile = enter_file (strcache_add (arname)); if (arfile != 0) (void) f_mtime (arfile, 0); } val = ar_scan (arname, ar_member_date_1, memname); free (arname); return 0 < val && val <= TYPE_MAXIMUM (time_t) ? val : -1; } /* Set the archive-member NAME's modtime to now. */ #if MK_OS_VMS int ar_touch (const char *name) { O (error, NILF, _("touch archive member is not available on VMS")); return -1; } #else int ar_touch (const char *name) { char *arname, *memname; int val; ar_parse_name (name, &arname, &memname); /* Make sure we know the modtime of the archive itself before we touch the member, since this will change the archive modtime. */ { struct file *arfile; arfile = enter_file (strcache_add (arname)); f_mtime (arfile, 0); } val = 1; switch (ar_member_touch (arname, memname)) { case -1: OS (error, NILF, _("touch: archive '%s' does not exist"), arname); break; case -2: OS (error, NILF, _("touch: '%s' is not a valid archive"), arname); break; case -3: perror_with_name ("touch: ", arname); break; case 1: OSS (error, NILF, _("touch: member '%s' does not exist in '%s'"), memname, arname); break; case 0: val = 0; break; default: OS (error, NILF, _("touch: bad return code from ar_member_touch on '%s'"), name); } free (arname); return val; } #endif /* !MK_OS_VMS */ /* State of an 'ar_glob' run, passed to 'ar_glob_match'. */ /* On VMS, (object) modules in libraries do not have suffixes. That is, to find a match for a pattern, the pattern must not have any suffix. So the suffix of the pattern is saved and the pattern is stripped (ar_glob). If there is a match and the match, which is a module name, is added to the chain, the saved suffix is added back to construct a source filename (ar_glob_match). */ struct ar_glob_state { const char *arname; const char *pattern; #if MK_OS_VMS char *suffix; #endif size_t size; struct nameseq *chain; unsigned int n; }; /* This function is called by 'ar_scan' to match one archive element against the pattern in STATE. */ static intmax_t ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED, long int hdrpos UNUSED, long int datapos UNUSED, long int size UNUSED, intmax_t date UNUSED, int uid UNUSED, int gid UNUSED, unsigned int mode UNUSED, const void *arg) { struct ar_glob_state *state = (struct ar_glob_state *)arg; if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0) { /* We have a match. Add it to the chain. */ struct nameseq *new = xcalloc (state->size); #if MK_OS_VMS if (state->suffix) new->name = strcache_add( concat(5, state->arname, "(", mem, state->suffix, ")")); else #endif new->name = strcache_add(concat(4, state->arname, "(", mem, ")")); new->next = state->chain; state->chain = new; ++state->n; } return 0; } /* Return nonzero if PATTERN contains any metacharacters. Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ static int ar_glob_pattern_p (const char *pattern, int quote) { const char *p; int opened = 0; for (p = pattern; *p != '\0'; ++p) switch (*p) { case '?': case '*': return 1; case '\\': if (quote) ++p; break; case '[': opened = 1; break; case ']': if (opened) return 1; break; } return 0; } /* Glob for MEMBER_PATTERN in archive ARNAME. Return a malloc'd chain of matching elements (or nil if none). */ struct nameseq * ar_glob (const char *arname, const char *member_pattern, size_t size) { struct ar_glob_state state; struct nameseq *n; const char **names; unsigned int i; #if MK_OS_VMS char *vms_member_pattern; #endif if (! ar_glob_pattern_p (member_pattern, 1)) return 0; /* Scan the archive for matches. ar_glob_match will accumulate them in STATE.chain. */ state.arname = arname; state.pattern = member_pattern; #if MK_OS_VMS { /* In a copy of the pattern, find the suffix, save it and remove it from the pattern */ char *lastdot; vms_member_pattern = xstrdup(member_pattern); lastdot = strrchr(vms_member_pattern, '.'); state.suffix = lastdot; if (lastdot) { state.suffix = xstrdup(lastdot); *lastdot = 0; } state.pattern = vms_member_pattern; } #endif state.size = size; state.chain = 0; state.n = 0; ar_scan (arname, ar_glob_match, &state); #if MK_OS_VMS /* Deallocate any duplicated string */ free(vms_member_pattern); if (state.suffix) { free(state.suffix); } #endif if (state.chain == 0) return 0; /* Now put the names into a vector for sorting. */ names = alloca (state.n * sizeof (const char *)); i = 0; for (n = state.chain; n != 0; n = n->next) names[i++] = n->name; /* Sort them alphabetically. */ /* MSVC erroneously warns without a cast here. */ qsort ((void *)names, i, sizeof (*names), alpha_compare); /* Put them back into the chain in the sorted order. */ i = 0; for (n = state.chain; n != 0; n = n->next) n->name = names[i++]; return state.chain; } #endif /* Not NO_ARCHIVES. */ ================================================ FILE: src/arscan.c ================================================ /* Library function for scanning an archive file. Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #ifdef TEST /* Hack, the real error() routine eventually pulls in die from main.c */ #define error(a, b, c, d) #endif #ifdef HAVE_FCNTL_H #include #else #include #endif #ifndef NO_ARCHIVES #if MK_OS_VMS #include #include #include #include #include #include #include #include /* This symbol should be present in lbrdef.h. */ #if !defined LBR$_HDRTRUNC #pragma extern_model save #pragma extern_model globalvalue extern unsigned int LBR$_HDRTRUNC; #pragma extern_model restore #endif #include #include const char * vmsify (const char *name, int type); /* Time conversion from VMS to Unix Conversion from local time (stored in library) to GMT (needed for gmake) Note: The tm_gmtoff element is a VMS extension to the ANSI standard. */ static time_t vms_time_to_unix(void *vms_time) { struct tm *tmp; time_t unix_time; unix_time = decc$fix_time(vms_time); tmp = localtime(&unix_time); unix_time -= tmp->tm_gmtoff; return unix_time; } /* VMS library routines need static variables for callback */ static void *VMS_lib_idx; static const void *VMS_saved_arg; static intmax_t (*VMS_function) (); static intmax_t VMS_function_ret; /* This is a callback procedure for lib$get_index */ static int VMS_get_member_info(struct dsc$descriptor_s *module, unsigned long *rfa) { int status, i; const int truncated = 0; /* Member name may be truncated */ time_t member_date; /* Member date */ char *filename; unsigned int buffer_length; /* Actual buffer length */ /* Unused constants - Make does not actually use most of these */ const int file_desc = -1; /* archive file descriptor for reading the data */ const int header_position = 0; /* Header position */ const int data_position = 0; /* Data position in file */ const int data_size = 0; /* Data size */ const int uid = 0; /* member gid */ const int gid = 0; /* member gid */ const int mode = 0; /* member protection mode */ /* End of unused constants */ static struct dsc$descriptor_s bufdesc = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL }; /* Only need the module definition */ struct mhddef *mhd; /* If a previous callback is non-zero, just return that status */ if (VMS_function_ret) { return SS$_NORMAL; } /* lbr_set_module returns more than just the module header. So allocate a buffer which is big enough: the maximum LBR$C_MAXHDRSIZ. That's at least bigger than the size of struct mhddef. If the request is too small, a buffer truncated warning is issued so it can be reissued with a larger buffer. We do not care if the buffer is truncated, so that is still a success. */ mhd = xmalloc(LBR$C_MAXHDRSIZ); bufdesc.dsc$a_pointer = (char *) mhd; bufdesc.dsc$w_length = LBR$C_MAXHDRSIZ; status = lbr$set_module(&VMS_lib_idx, rfa, &bufdesc, &buffer_length, 0); if ((status != LBR$_HDRTRUNC) && !$VMS_STATUS_SUCCESS(status)) { ON(error, NILF, _("lbr$set_module() failed to extract module info, status = %d"), status); lbr$close(&VMS_lib_idx); return status; } #ifdef TEST /* When testing this code, it is useful to know the length returned */ printf ("Input length = %d, actual = %u\n", bufdesc.dsc$w_length, buffer_length); #endif /* Conversion from VMS time to C time. VMS defectlet - mhddef is sub-optimal, for the time, it has a 32 bit longword, mhd$l_datim, and a 32 bit fill instead of two longwords, or equivalent. */ member_date = vms_time_to_unix(&mhd->mhd$l_datim); free(mhd); /* Here we have a problem. The module name on VMS does not have a file type, but the filename pattern in the "VMS_saved_arg" may have one. But only the method being called knows how to interpret the filename pattern. There are currently two different formats being used. This means that we need a VMS specific code in those methods to handle it. */ filename = xmalloc(module->dsc$w_length + 1); /* TODO: We may need an option to preserve the case of the module For now force the module name to lower case */ for (i = 0; i < module->dsc$w_length; i++) filename[i] = _tolower((unsigned char )module->dsc$a_pointer[i]); filename[i] = '\0'; VMS_function_ret = (*VMS_function)(file_desc, filename, truncated, header_position, data_position, data_size, member_date, uid, gid, mode, VMS_saved_arg); free(filename); return SS$_NORMAL; } /* Takes three arguments ARCHIVE, FUNCTION and ARG. Open the archive named ARCHIVE, find its members one by one, and for each one call FUNCTION with the following arguments: archive file descriptor for reading the data, member name, member name might be truncated flag, member header position in file, member data position in file, member data size, member date, member uid, member gid, member protection mode, ARG. NOTE: on VMS systems, only name, date, and arg are meaningful! The descriptor is poised to read the data of the member when FUNCTION is called. It does not matter how much data FUNCTION reads. If FUNCTION returns nonzero, we immediately return what FUNCTION returned. Returns -1 if archive does not exist, Returns -2 if archive has invalid format. Returns 0 if have scanned successfully. */ intmax_t ar_scan (const char *archive, ar_member_func_t function, const void *varg) { char *vms_archive; static struct dsc$descriptor_s libdesc = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL }; const unsigned long func = LBR$C_READ; const unsigned long type = LBR$C_TYP_UNK; const unsigned long index = 1; unsigned long lib_idx; int status; VMS_saved_arg = varg; /* Null archive string can show up in test and cause an access violation */ if (archive == NULL) { /* Null filenames do not exist */ return -1; } /* archive path name must be in VMS format */ vms_archive = (char *) vmsify(archive, 0); status = lbr$ini_control(&VMS_lib_idx, &func, &type, 0); if (!$VMS_STATUS_SUCCESS(status)) { ON(error, NILF, _("lbr$ini_control() failed with status = %d"), status); return -2; } libdesc.dsc$a_pointer = vms_archive; libdesc.dsc$w_length = strlen(vms_archive); status = lbr$open(&VMS_lib_idx, &libdesc, 0, NULL, 0, NULL, 0); if (!$VMS_STATUS_SUCCESS(status)) { /* TODO: A library format failure could mean that this is a file generated by the GNU AR utility and in that case, we need to take the UNIX codepath. This will also take a change to the GNV AR wrapper program. */ switch (status) { case RMS$_FNF: /* Archive does not exist */ return -1; default: #ifndef TEST OSN(error, NILF, _("unable to open library '%s' to lookup member status %d"), archive, status); #endif /* For library format errors, specification says to return -2 */ return -2; } } VMS_function = function; /* Clear the return status, as we are supposed to stop calling the callback function if it becomes non-zero, and this is a static variable. */ VMS_function_ret = 0; status = lbr$get_index(&VMS_lib_idx, &index, VMS_get_member_info, NULL, 0); lbr$close(&VMS_lib_idx); /* Unless a failure occurred in the lbr$ routines, return the the status from the 'function' routine. */ if ($VMS_STATUS_SUCCESS(status)) { return VMS_function_ret; } /* This must be something wrong with the library and an error message should already have been printed. */ return -2; } #else /* !MK_OS_VMS */ /* SCO Unix's compiler defines both of these. */ #ifdef M_UNIX #undef M_XENIX #endif /* On the sun386i and in System V rel 3, ar.h defines two different archive formats depending upon whether you have defined PORTAR (normal) or PORT5AR (System V Release 1). There is no default, one or the other must be defined to have a nonzero value. */ #if (!defined (PORTAR) || PORTAR == 0) && (!defined (PORT5AR) || PORT5AR == 0) #undef PORTAR #ifdef M_XENIX /* According to Jim Sievert , for SCO XENIX defining PORTAR to 1 gets the wrong archive format, and defining it to 0 gets the right one. */ #define PORTAR 0 #else #define PORTAR 1 #endif #endif /* On AIX, define these symbols to be sure to get both archive formats. AIX 4.3 introduced the "big" archive format to support 64-bit object files, so on AIX 4.3 systems we need to support both the "normal" and "big" archive formats. An archive's format is indicated in the "fl_magic" field of the "FL_HDR" structure. For a normal archive, this field will be the string defined by the AIAMAG symbol. For a "big" archive, it will be the string defined by the AIAMAGBIG symbol (at least on AIX it works this way). Note: we'll define these symbols regardless of which AIX version we're compiling on, but this is okay since we'll use the new symbols only if they're present. */ #ifdef _AIX # define __AR_SMALL__ # define __AR_BIG__ #endif #if !MK_OS_W32 # if !defined (__ANDROID__) && !defined (__BEOS__) && !defined(MK_OS_ZOS) # include # else /* These platforms don't have but have archives in the same format * as many other Unices. This was taken from GNU binutils for BeOS. */ # define ARMAG "!\n" /* String that begins an archive file. */ # define SARMAG 8 /* Size of that string. */ # define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ struct ar_hdr { char ar_name[16]; /* Member file name, sometimes / terminated. */ char ar_date[12]; /* File date, decimal seconds since Epoch. */ char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ char ar_mode[8]; /* File mode, in ASCII octal. */ char ar_size[10]; /* File size, in ASCII decimal. */ char ar_fmag[2]; /* Always contains ARFMAG. */ }; # endif # define TOCHAR(_m) (_m) #else /* These should allow us to read Windows (VC++) libraries (according to Frank * Libbrecht ) */ # include # include # include # define ARMAG IMAGE_ARCHIVE_START # define SARMAG IMAGE_ARCHIVE_START_SIZE # define ar_hdr _IMAGE_ARCHIVE_MEMBER_HEADER # define ar_name Name # define ar_mode Mode # define ar_size Size # define ar_date Date # define ar_uid UserID # define ar_gid GroupID /* In Windows the member names have type BYTE so we must cast them. */ # define TOCHAR(_m) ((char *)(_m)) #endif /* Cray's apparently defines this. */ #ifndef AR_HDR_SIZE # define AR_HDR_SIZE (sizeof (struct ar_hdr)) #endif #include "intprops.h" #include "output.h" static uintmax_t parse_int (const char *ptr, const size_t len, const int base, uintmax_t max, const char *type, const char *archive, const char *name) { const char *const ep = ptr + len; const int maxchar = '0' + base - 1; uintmax_t val = 0; /* In all the versions I know of the spaces come last, but be safe. */ while (ptr < ep && *ptr == ' ') ++ptr; while (ptr < ep && *ptr != ' ') { if (*ptr < '0' || *ptr > maxchar || INT_MULTIPLY_WRAPV (val, base, &val) || INT_ADD_WRAPV (val, *ptr - '0', &val) || val > max) OSSS (fatal, NILF, _("invalid %s for archive %s member %s"), type, archive, name); ++ptr; } return val; } /* Takes three arguments ARCHIVE, FUNCTION and ARG. Open the archive named ARCHIVE, find its members one by one, and for each one call FUNCTION with the following arguments: archive file descriptor for reading the data, member name, member name might be truncated flag, member header position in file, member data position in file, member data size, member date, member uid, member gid, member protection mode, ARG. The descriptor is poised to read the data of the member when FUNCTION is called. It does not matter how much data FUNCTION reads. If FUNCTION returns nonzero, we immediately return what FUNCTION returned. Returns -1 if archive does not exist, Returns -2 if archive has invalid format. Returns 0 if have scanned successfully. */ intmax_t ar_scan (const char *archive, ar_member_func_t function, const void *arg) { #ifdef AIAMAG FL_HDR fl_header; # ifdef AIAMAGBIG int big_archive = 0; FL_HDR_BIG fl_header_big; # endif #endif char *namemap = 0; unsigned int namemap_size = 0; int desc = open (archive, O_RDONLY, 0); if (desc < 0) return -1; #ifdef SARMAG { char buf[SARMAG]; int nread; nread = readbuf (desc, buf, SARMAG); if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG)) goto invalid; } #else #ifdef AIAMAG { int nread; nread = readbuf (desc, &fl_header, FL_HSZ); if (nread != FL_HSZ) goto invalid; #ifdef AIAMAGBIG /* If this is a "big" archive, then set the flag and re-read the header into the "big" structure. */ if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG)) { off_t o; big_archive = 1; /* seek back to beginning of archive */ EINTRLOOP (o, lseek (desc, 0, 0)); if (o < 0) goto invalid; /* re-read the header into the "big" structure */ nread = readbuf (desc, &fl_header_big, FL_HSZ_BIG); if (nread != FL_HSZ_BIG) goto invalid; } else #endif /* Check to make sure this is a "normal" archive. */ if (memcmp (fl_header.fl_magic, AIAMAG, SAIAMAG)) goto invalid; } #else { #ifndef M_XENIX int buf; #else unsigned short int buf; #endif int nread; nread = readbuf (desc, &buf, sizeof (buf)); if (nread != sizeof (buf) || buf != ARMAG) goto invalid; } #endif #endif /* Now find the members one by one. */ { #ifdef SARMAG long int member_offset = SARMAG; #else #ifdef AIAMAG long int member_offset; long int last_member_offset; #ifdef AIAMAGBIG if ( big_archive ) { sscanf (fl_header_big.fl_fstmoff, "%20ld", &member_offset); sscanf (fl_header_big.fl_lstmoff, "%20ld", &last_member_offset); } else #endif { sscanf (fl_header.fl_fstmoff, "%12ld", &member_offset); sscanf (fl_header.fl_lstmoff, "%12ld", &last_member_offset); } if (member_offset == 0) { /* Empty archive. */ close (desc); return 0; } #else #ifndef M_XENIX long int member_offset = sizeof (int); #else /* Xenix. */ long int member_offset = sizeof (unsigned short int); #endif /* Not Xenix. */ #endif #endif while (1) { ssize_t nread; struct ar_hdr member_header; #ifdef AIAMAGBIG struct ar_hdr_big member_header_big; #endif #ifdef AIAMAG # define ARNAME_MAX 255 char name[ARNAME_MAX + 1]; int name_len; intmax_t dateval; int uidval, gidval; long int data_offset; #else # define ARNAME_MAX (int)sizeof(member_header.ar_name) char namebuf[ARNAME_MAX + 1]; char *name; int is_namemap; /* Nonzero if this entry maps long names. */ int long_name = 0; #endif long int eltsize; unsigned int eltmode; intmax_t eltdate; int eltuid, eltgid; intmax_t fnval; off_t o; memset(&member_header, '\0', sizeof (member_header)); EINTRLOOP (o, lseek (desc, member_offset, 0)); if (o < 0) goto invalid; #ifdef AIAMAG #define AR_MEMHDR_SZ(x) (sizeof(x) - sizeof (x._ar_name)) #ifdef AIAMAGBIG if (big_archive) { nread = readbuf (desc, &member_header_big, AR_MEMHDR_SZ(member_header_big)); if (nread != AR_MEMHDR_SZ(member_header_big)) goto invalid; sscanf (member_header_big.ar_namlen, "%4d", &name_len); if (name_len < 1 || name_len > ARNAME_MAX) goto invalid; nread = readbuf (desc, name, name_len); if (nread != name_len) goto invalid; name[name_len] = '\0'; sscanf (member_header_big.ar_date, "%12" SCNdMAX, &dateval); sscanf (member_header_big.ar_uid, "%12d", &uidval); sscanf (member_header_big.ar_gid, "%12d", &gidval); sscanf (member_header_big.ar_mode, "%12o", &eltmode); sscanf (member_header_big.ar_size, "%20ld", &eltsize); data_offset = (member_offset + AR_MEMHDR_SZ(member_header_big) + name_len + 2); } else #endif { nread = readbuf (desc, &member_header, AR_MEMHDR_SZ(member_header)); if (nread != AR_MEMHDR_SZ(member_header)) goto invalid; sscanf (member_header.ar_namlen, "%4d", &name_len); if (name_len < 1 || name_len > ARNAME_MAX) goto invalid; nread = readbuf (desc, name, name_len); if (nread != name_len) goto invalid; name[name_len] = '\0'; sscanf (member_header.ar_date, "%12" SCNdMAX, &dateval); sscanf (member_header.ar_uid, "%12d", &uidval); sscanf (member_header.ar_gid, "%12d", &gidval); sscanf (member_header.ar_mode, "%12o", &eltmode); sscanf (member_header.ar_size, "%12ld", &eltsize); data_offset = (member_offset + AR_MEMHDR_SZ(member_header) + name_len + 2); } data_offset += data_offset % 2; fnval = (*function) (desc, name, 0, member_offset, data_offset, eltsize, dateval, uidval, gidval, eltmode, arg); #else /* Not AIAMAG. */ nread = readbuf (desc, &member_header, AR_HDR_SIZE); if (nread == 0) /* No data left means end of file; that is OK. */ break; if (nread != AR_HDR_SIZE #if defined(ARFMAG) || defined(ARFZMAG) || ( # ifdef ARFMAG memcmp (member_header.ar_fmag, ARFMAG, 2) # else 1 # endif && # ifdef ARFZMAG memcmp (member_header.ar_fmag, ARFZMAG, 2) # else 1 # endif ) #endif ) goto invalid; name = namebuf; memcpy (name, member_header.ar_name, sizeof member_header.ar_name); { char *p = name + sizeof member_header.ar_name; do *p = '\0'; while (p > name && *--p == ' '); #ifndef AIAMAG /* If the member name is "//" or "ARFILENAMES/" this may be a list of file name mappings. The maximum file name length supported by the standard archive format is 14 characters. This member will actually always be the first or second entry in the archive, but we don't check that. */ is_namemap = (!strcmp (name, "//") || !strcmp (name, "ARFILENAMES/")); #endif /* Not AIAMAG. */ /* On some systems, there is a slash after each member name. */ if (*p == '/') *p = '\0'; #ifndef AIAMAG /* If the member name starts with a space or a slash, this is an index into the file name mappings (used by GNU ar). Otherwise if the member name looks like #1/NUMBER the real member name appears in the element data (used by 4.4BSD). */ if (! is_namemap && (name[0] == ' ' || name[0] == '/') && namemap != 0) { const char* err; unsigned int name_off = make_toui (name + 1, &err); size_t name_len; if (err|| name_off >= namemap_size) goto invalid; name = namemap + name_off; name_len = strlen (name); if (name_len < 1) goto invalid; long_name = 1; } else if (name[0] == '#' && name[1] == '1' && name[2] == '/') { const char* err; unsigned int name_len = make_toui (name + 3, &err); if (err || name_len == 0 || name_len >= MIN (PATH_MAX, INT_MAX)) goto invalid; name = alloca (name_len + 1); nread = readbuf (desc, name, name_len); if (nread < 0 || (unsigned int) nread != name_len) goto invalid; name[name_len] = '\0'; long_name = 1; } #endif /* Not AIAMAG. */ } #ifndef M_XENIX #define PARSE_INT(_m, _t, _b, _n) \ (_t) parse_int (TOCHAR (member_header._m), sizeof (member_header._m), \ _b, TYPE_MAXIMUM (_t), _n, archive, name) eltmode = PARSE_INT (ar_mode, unsigned int, 8, "mode"); eltsize = PARSE_INT (ar_size, long, 10, "size"); eltdate = PARSE_INT (ar_date, intmax_t, 10, "date"); eltuid = PARSE_INT (ar_uid, int, 10, "uid"); eltgid = PARSE_INT (ar_gid, int, 10, "gid"); #undef PARSE_INT #else /* Xenix. */ eltmode = (unsigned short int) member_header.ar_mode; eltsize = member_header.ar_size; #endif /* Not Xenix. */ fnval = (*function) (desc, name, ! long_name, member_offset, member_offset + AR_HDR_SIZE, eltsize, #ifndef M_XENIX eltdate, eltuid, eltgid, #else /* Xenix. */ member_header.ar_date, member_header.ar_uid, member_header.ar_gid, #endif /* Not Xenix. */ eltmode, arg); #endif /* AIAMAG. */ if (fnval) { (void) close (desc); return fnval; } #ifdef AIAMAG if (member_offset == last_member_offset) /* End of the chain. */ break; #ifdef AIAMAGBIG if (big_archive) sscanf (member_header_big.ar_nxtmem, "%20ld", &member_offset); else #endif sscanf (member_header.ar_nxtmem, "%12ld", &member_offset); if (lseek (desc, member_offset, 0) != member_offset) goto invalid; #else /* If this member maps archive names, we must read it in. The name map will always precede any members whose names must be mapped. */ if (is_namemap) { char *clear; char *limit; if (eltsize > INT_MAX) goto invalid; namemap = alloca (eltsize + 1); nread = readbuf (desc, namemap, eltsize); if (nread != eltsize) goto invalid; namemap_size = eltsize; /* The names are separated by newlines. Some formats have a trailing slash. Null terminate the strings for convenience. */ limit = namemap + eltsize; for (clear = namemap; clear < limit; clear++) { if (*clear == '\n') { *clear = '\0'; if (clear[-1] == '/') clear[-1] = '\0'; } } *limit = '\0'; is_namemap = 0; } member_offset += AR_HDR_SIZE + eltsize; if (member_offset % 2 != 0) member_offset++; #endif } } close (desc); return 0; invalid: close (desc); return -2; } #endif /* !MK_OS_VMS */ /* Return nonzero iff NAME matches MEM. If TRUNCATED is nonzero, MEM may be truncated to sizeof (struct ar_hdr.ar_name) - 1. */ int ar_name_equal (const char *name, const char *mem, int truncated) { const char *p; /* GNU ar allows -P to preserve parent paths, so test the literal name before stripping off the directory. */ if (streq (name, mem)) return 1; p = strrchr (name, '/'); if (p != 0) name = p + 1; #if !MK_OS_VMS if (truncated) { #ifdef AIAMAG /* TRUNCATED should never be set on this system. */ abort (); #else struct ar_hdr hdr; #if !defined (__hpux) && !defined (cray) return strneq (name, mem, sizeof (hdr.ar_name) - 1); #else return strneq (name, mem, sizeof (hdr.ar_name) - 2); #endif /* !__hpux && !cray */ #endif /* !AIAMAG */ } return !strcmp (name, mem); #else /* VMS members do not have suffixes, but the filenames usually have. Do we need to strip VMS disk/directory format paths? Most VMS compilers etc. by default are case insensitive but produce uppercase external names, incl. module names. However the VMS librarian (ar) and the linker by default are case sensitive: they take what they get, usually uppercase names. So for the non-default settings of the compilers etc. there is a need to have a case sensitive mode. */ { int len; len = strlen(mem); int match; char *dot; if ((dot=strrchr(name,'.'))) match = (len == dot - name) && !strncasecmp(name, mem, len); else match = !strcasecmp (name, mem); return match; } #endif /* !MK_OS_VMS */ } #if !MK_OS_VMS /* ARGSUSED */ static intmax_t ar_member_pos (int desc UNUSED, const char *mem, int truncated, long int hdrpos, long int datapos UNUSED, long int size UNUSED, intmax_t date UNUSED, int uid UNUSED, int gid UNUSED, unsigned int mode UNUSED, const void *name) { if (!ar_name_equal (name, mem, truncated)) return 0; return hdrpos; } /* Set date of member MEMNAME in archive ARNAME to current time. Returns 0 if successful, -1 if file ARNAME does not exist, -2 if not a valid archive, -3 if other random system call error (including file read-only), 1 if valid but member MEMNAME does not exist. */ int ar_member_touch (const char *arname, const char *memname) { intmax_t pos = ar_scan (arname, ar_member_pos, memname); off_t opos; int fd; struct ar_hdr ar_hdr; off_t o; int r; int datelen; struct stat statbuf; if (pos < 0) return (int) pos; if (!pos) return 1; opos = (off_t) pos; EINTRLOOP (fd, open (arname, O_RDWR, 0666)); if (fd < 0) return -3; /* Read in this member's header */ EINTRLOOP (o, lseek (fd, opos, 0)); if (o < 0) goto lose; r = readbuf (fd, &ar_hdr, AR_HDR_SIZE); if (r != AR_HDR_SIZE) goto lose; /* The file's mtime is the time we we want. */ EINTRLOOP (r, fstat (fd, &statbuf)); if (r < 0) goto lose; /* Advance member's time to that time */ #if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || MK_OS_W32 datelen = snprintf (TOCHAR (ar_hdr.ar_date), sizeof ar_hdr.ar_date, "%" PRIdMAX, (intmax_t) statbuf.st_mtime); if (! (0 <= datelen && datelen < (int) sizeof ar_hdr.ar_date)) goto lose; memset (ar_hdr.ar_date + datelen, ' ', sizeof ar_hdr.ar_date - datelen); #else ar_hdr.ar_date = statbuf.st_mtime; #endif /* Write back this member's header */ EINTRLOOP (o, lseek (fd, opos, 0)); if (o < 0) goto lose; r = writebuf (fd, &ar_hdr, AR_HDR_SIZE); if (r != AR_HDR_SIZE) goto lose; close (fd); return 0; lose: r = errno; close (fd); errno = r; return -3; } #endif #ifdef TEST intmax_t describe_member (int desc, const char *name, int truncated, long int hdrpos, long int datapos, long int size, intmax_t date, int uid, int gid, unsigned int mode, const void *arg) { extern char *ctime (); time_t d = date; char const *ds; printf (_("Member '%s'%s: %ld bytes at %ld (%ld).\n"), name, truncated ? _(" (name might be truncated)") : "", size, hdrpos, datapos); ds = ctime (&d); printf (_(" Date %s"), ds ? ds : "?"); printf (_(" uid = %d, gid = %d, mode = 0%o.\n"), uid, gid, mode); return 0; } int main (int argc, char **argv) { ar_scan (argv[1], describe_member, NULL); return 0; } #endif /* TEST. */ #endif /* NO_ARCHIVES. */ ================================================ FILE: src/commands.c ================================================ /* Command processing for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "os.h" #include "dep.h" #include "variable.h" #include "job.h" #include "commands.h" #if MK_OS_W32 #include #include "w32err.h" #endif #if MK_OS_VMS # define FILE_LIST_SEPARATOR (vms_comma_separator ? ',' : ' ') #else # define FILE_LIST_SEPARATOR ' ' #endif static unsigned long dep_hash_1 (const void *key) { const struct dep *d = key; return_STRING_HASH_1 (dep_name (d)); } static unsigned long dep_hash_2 (const void *key) { const struct dep *d = key; return_STRING_HASH_2 (dep_name (d)); } static int dep_hash_cmp (const void *x, const void *y) { const struct dep *dx = x; const struct dep *dy = y; return strcmp (dep_name (dx), dep_name (dy)); } /* Set FILE's automatic variables up. * Use STEM to set $*. * If STEM is 0, then set FILE->STEM and $* to the target name with any * suffix in the .SUFFIXES list stripped off. */ void set_file_variables (struct file *file, const char *stem) { struct dep *d; const char *at, *percent, *star, *less; #ifndef NO_ARCHIVES /* If the target is an archive member 'lib(member)', then $@ is 'lib' and $% is 'member'. */ if (ar_name (file->name)) { size_t len; const char *cp; char *p; cp = strchr (file->name, '('); p = alloca (cp - file->name + 1); memcpy (p, file->name, cp - file->name); p[cp - file->name] = '\0'; at = p; len = strlen (cp + 1); p = alloca (len); memcpy (p, cp + 1, len - 1); p[len - 1] = '\0'; percent = p; } else #endif /* NO_ARCHIVES. */ { at = file->name; percent = ""; } /* $* is the stem from an implicit or static pattern rule. */ if (stem == 0) { /* In Unix make, $* is set to the target name with any suffix in the .SUFFIXES list stripped off for explicit rules. We store this in the 'stem' member. */ const char *name; size_t len; #ifndef NO_ARCHIVES if (ar_name (file->name)) { name = strchr (file->name, '(') + 1; len = strlen (name) - 1; } else #endif { name = file->name; len = strlen (name); } for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next) { const char *dn = dep_name (d); size_t slen = strlen (dn); if (len > slen && memcmp (dn, name + (len - slen), slen) == 0) { file->stem = stem = strcache_add_len (name, len - slen); break; } } if (d == 0) file->stem = stem = ""; } star = stem; /* $< is the first not order-only dependency. */ less = ""; for (d = file->deps; d != 0; d = d->next) if (!d->ignore_mtime && !d->ignore_automatic_vars && !d->need_2nd_expansion) { less = dep_name (d); break; } if (file->cmds != 0 && file->cmds == default_file->cmds) /* This file got its commands from .DEFAULT. In this case $< is the same as $@. */ less = at; #define DEFINE_VARIABLE(name, len, value) \ (void) define_variable_for_file (name,len,value,o_automatic,0,file) /* Define the variables. */ DEFINE_VARIABLE ("<", 1, less); DEFINE_VARIABLE ("*", 1, star); DEFINE_VARIABLE ("@", 1, at); DEFINE_VARIABLE ("%", 1, percent); /* Compute the values for $^, $+, $?, and $|. */ { static char *plus_value=0, *bar_value=0, *qmark_value=0; static size_t plus_max=0, bar_max=0, qmark_max=0; size_t qmark_len, plus_len, bar_len; char *cp; char *caret_value; char *qp; char *bp; size_t len; struct hash_table dep_hash; void **slot; /* Compute first the value for $+, which is supposed to contain duplicate dependencies as they were listed in the makefile. */ plus_len = 0; bar_len = 0; for (d = file->deps; d != 0; d = d->next) { if (!d->need_2nd_expansion && !d->ignore_automatic_vars) { if (d->ignore_mtime) bar_len += strlen (dep_name (d)) + 1; else plus_len += strlen (dep_name (d)) + 1; } } if (bar_len == 0) bar_len++; if (plus_len == 0) plus_len++; if (plus_len > plus_max) plus_value = xrealloc (plus_value, plus_max = plus_len); cp = plus_value; qmark_len = plus_len + 1; /* Will be this or less. */ for (d = file->deps; d != 0; d = d->next) if (! d->ignore_mtime && ! d->need_2nd_expansion && ! d->ignore_automatic_vars) { const char *c = dep_name (d); #ifndef NO_ARCHIVES if (ar_name (c)) { c = strchr (c, '(') + 1; len = strlen (c) - 1; } else #endif len = strlen (c); cp = mempcpy (cp, c, len); *cp++ = FILE_LIST_SEPARATOR; if (! (d->changed || always_make_flag)) qmark_len -= len + 1; /* Don't space in $? for this one. */ } /* Kill the last space and define the variable. */ cp[cp > plus_value ? -1 : 0] = '\0'; DEFINE_VARIABLE ("+", 1, plus_value); /* Compute the values for $^, $?, and $|. */ cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */ if (qmark_len > qmark_max) qmark_value = xrealloc (qmark_value, qmark_max = qmark_len); qp = qmark_value; if (bar_len > bar_max) bar_value = xrealloc (bar_value, bar_max = bar_len); bp = bar_value; /* Make sure that no dependencies are repeated in $^, $?, and $|. It would be natural to combine the next two loops but we can't do it because of a situation where we have two dep entries, the first is order-only and the second is normal (see below). */ hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp); for (d = file->deps; d != 0; d = d->next) { if (d->need_2nd_expansion || d->ignore_automatic_vars) continue; slot = hash_find_slot (&dep_hash, d); if (HASH_VACANT (*slot)) hash_insert_at (&dep_hash, d, slot); else { /* Check if the two prerequisites have different ignore_mtime. If so then we need to "upgrade" one that is order-only. */ struct dep* hd = (struct dep*) *slot; if (d->ignore_mtime != hd->ignore_mtime) d->ignore_mtime = hd->ignore_mtime = 0; } } for (d = file->deps; d != 0; d = d->next) { const char *c; if (d->need_2nd_expansion || d->ignore_automatic_vars || hash_find_item (&dep_hash, d) != d) continue; c = dep_name (d); #ifndef NO_ARCHIVES if (ar_name (c)) { c = strchr (c, '(') + 1; len = strlen (c) - 1; } else #endif len = strlen (c); if (d->ignore_mtime) { bp = mempcpy (bp, c, len); *bp++ = FILE_LIST_SEPARATOR; } else { cp = mempcpy (cp, c, len); *cp++ = FILE_LIST_SEPARATOR; if (d->changed || always_make_flag) { qp = mempcpy (qp, c, len); *qp++ = FILE_LIST_SEPARATOR; } } } hash_free (&dep_hash, 0); /* Kill the last spaces and define the variables. */ cp[cp > caret_value ? -1 : 0] = '\0'; DEFINE_VARIABLE ("^", 1, caret_value); qp[qp > qmark_value ? -1 : 0] = '\0'; DEFINE_VARIABLE ("?", 1, qmark_value); bp[bp > bar_value ? -1 : 0] = '\0'; DEFINE_VARIABLE ("|", 1, bar_value); } #undef DEFINE_VARIABLE } /* Chop CMDS up into individual command lines if necessary. Also set the 'lines_flags' and 'any_recurse' members. */ void chop_commands (struct commands *cmds) { unsigned short nlines; unsigned short i; char **lines; /* If we don't have any commands, or we already parsed them, never mind. */ if (!cmds || cmds->command_lines != NULL) return; /* Chop CMDS->commands up into lines in CMDS->command_lines. */ if (one_shell) { size_t l = strlen (cmds->commands); nlines = 1; lines = xmalloc (nlines * sizeof (char *)); lines[0] = xstrdup (cmds->commands); /* Strip the trailing newline. */ if (l > 0 && lines[0][l-1] == '\n') lines[0][l-1] = '\0'; } else { const char *p = cmds->commands; size_t max = 5; nlines = 0; lines = xmalloc (max * sizeof (char *)); while (*p != '\0') { const char *end = p; find_end:; end = strchr (end, '\n'); if (end == NULL) end = p + strlen (p); else if (end > p && end[-1] == '\\') { int backslash = 1; if (end > p + 1) { const char *b; for (b = end - 2; b >= p && *b == '\\'; --b) backslash = !backslash; } if (backslash) { ++end; goto find_end; } } if (nlines == USHRT_MAX) ON (fatal, &cmds->fileinfo, _("recipe has too many lines (limit %hu)"), nlines); if (nlines == max) { max += 2; lines = xrealloc (lines, max * sizeof (char *)); } lines[nlines++] = xstrndup (p, (size_t) (end - p)); p = end; if (*p != '\0') ++p; } } /* Finally, set the corresponding CMDS->lines_flags elements and the CMDS->any_recurse flag. */ cmds->ncommand_lines = nlines; cmds->command_lines = lines; cmds->any_recurse = 0; cmds->lines_flags = xmalloc (nlines); for (i = 0; i < nlines; ++i) { unsigned char flags = 0; const char *p = lines[i]; while (ISBLANK (*p) || *p == '-' || *p == '@' || *p == '+') switch (*(p++)) { case '+': flags |= COMMANDS_RECURSE; break; case '@': flags |= COMMANDS_SILENT; break; case '-': flags |= COMMANDS_NOERROR; break; } /* If no explicit '+' was given, look for MAKE variable references. */ if (! ANY_SET (flags, COMMANDS_RECURSE) && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0)) flags |= COMMANDS_RECURSE; cmds->lines_flags[i] = flags; cmds->any_recurse |= ANY_SET (flags, COMMANDS_RECURSE) ? 1 : 0; } } /* Execute the commands to remake FILE. If they are currently executing, return or have already finished executing, just return. Otherwise, fork off a child process to run the first command line in the sequence. */ void execute_file_commands (struct file *file) { const char *p; /* Don't go through all the preparations if the commands are nothing but whitespace. */ for (p = file->cmds->commands; *p != '\0'; ++p) if (!ISSPACE (*p) && *p != '-' && *p != '@' && *p != '+') break; if (*p == '\0') { /* If there are no commands, assume everything worked. */ set_command_state (file, cs_running); file->update_status = us_success; notice_finished_file (file); return; } /* First set the automatic variables according to this file. */ initialize_file_variables (file, 0); set_file_variables (file, file->stem); /* Some systems don't support overwriting a loaded object so if this one unload it before remaking. Keep its name in .LOADED: it will be rebuilt and loaded again. If rebuilding or loading again fail, then we'll exit anyway and it won't matter. */ if (file->loaded && unload_file (file->name) == 0) { file->loaded = 0; file->unloaded = 1; } /* Start the commands running. */ new_job (file); } /* This is set while we are inside fatal_error_signal, so things can avoid nonreentrant operations. */ volatile sig_atomic_t handling_fatal_signal = 0; /* Handle fatal signals. */ void fatal_error_signal (int sig) { #if MK_OS_DOS extern int dos_status, dos_command_running; if (dos_command_running) { /* That was the child who got the signal, not us. */ dos_status |= (sig << 8); return; } remove_intermediates (1); exit (EXIT_FAILURE); #else /* not MK_OS_DOS */ #if MK_OS_W32 extern HANDLE main_thread; /* Windows creates a separate thread for handling Ctrl+C, so we need to suspend the main thread, or else we will have race conditions when both threads call reap_children. */ if (main_thread) { DWORD susp_count = SuspendThread (main_thread); if (susp_count != 0) fprintf (stderr, "SuspendThread: suspend count = %lu\n", susp_count); else if (susp_count == (DWORD)-1) { DWORD ierr = GetLastError (); fprintf (stderr, "SuspendThread: error %lu: %s\n", ierr, map_windows32_error_to_string (ierr)); } } #endif handling_fatal_signal = 1; /* Set the handling for this signal to the default. It is blocked now while we run this handler. */ signal (sig, SIG_DFL); temp_stdin_unlink (); osync_clear (); jobserver_clear (); /* A termination signal won't be sent to the entire process group, but it means we want to kill the children. */ if (sig == SIGTERM) { struct child *c; for (c = children; c != 0; c = c->next) if (!c->remote && c->pid > 0) (void) kill (c->pid, SIGTERM); } /* If we got a signal that means the user wanted to kill make, remove pending targets. */ if (sig == SIGTERM || sig == SIGINT #ifdef SIGHUP || sig == SIGHUP #endif #ifdef SIGQUIT || sig == SIGQUIT #endif ) { struct child *c; /* Remote children won't automatically get signals sent to the process group, so we must send them. */ for (c = children; c != 0; c = c->next) if (c->remote && c->pid > 0) (void) remote_kill (c->pid, sig); for (c = children; c != 0; c = c->next) delete_child_targets (c); /* Clean up the children. We don't just use the call below because we don't want to print the "Waiting for children" message. */ while (job_slots_used > 0) reap_children (1, 0); } else /* Wait for our children to die. */ while (job_slots_used > 0) reap_children (1, 1); /* Delete any non-precious intermediate files that were made. */ remove_intermediates (1); #ifdef SIGQUIT if (sig == SIGQUIT) /* We don't want to send ourselves SIGQUIT, because it will cause a core dump. Just exit instead. */ exit (MAKE_TROUBLE); #endif #if MK_OS_W32 if (main_thread) CloseHandle (main_thread); /* Cannot call W32_kill with a pid (it needs a handle). The exit status of 130 emulates what happens in Bash. */ exit (130); #else /* Signal the same code; this time it will really be fatal. The signal will be unblocked when we return and arrive then to kill us. */ if (kill (make_pid (), sig) < 0) pfatal_with_name ("kill"); #endif /* not MK_OS_W32 */ #endif /* not MK_OS_DOS */ } /* Delete FILE unless it's precious or not actually a file (phony), and it has changed on disk since we last stat'd it. */ static void delete_target (struct file *file, const char *on_behalf_of) { struct stat st; int e; if (file->precious || file->phony) return; #ifndef NO_ARCHIVES if (ar_name (file->name)) { time_t file_date = (file->last_mtime == NONEXISTENT_MTIME ? (time_t) -1 : (time_t) FILE_TIMESTAMP_S (file->last_mtime)); if (ar_member_date (file->name) != file_date) { if (on_behalf_of) OSS (error, NILF, _("*** [%s] archive member '%s' may be bogus; not deleted"), on_behalf_of, file->name); else OS (error, NILF, _("*** archive member '%s' may be bogus; not deleted"), file->name); } return; } #endif EINTRLOOP (e, stat (file->name, &st)); if (e == 0 && S_ISREG (st.st_mode) && FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime) { if (on_behalf_of) OSS (error, NILF, _("*** [%s] deleting file '%s'"), on_behalf_of, file->name); else OS (error, NILF, _("*** deleting file '%s'"), file->name); if (unlink (file->name) < 0 && errno != ENOENT) /* It disappeared; so what. */ perror_with_name ("unlink: ", file->name); } } /* Delete all non-precious targets of CHILD unless they were already deleted. Set the flag in CHILD to say they've been deleted. */ void delete_child_targets (struct child *child) { struct dep *d; if (child->deleted || child->pid < 0) return; /* Delete the target file if it changed. */ delete_target (child->file, NULL); /* Also remove any non-precious targets listed in the 'also_make' member. */ for (d = child->file->also_make; d != 0; d = d->next) delete_target (d->file, child->file->name); child->deleted = 1; } /* Print out the commands in CMDS. */ void print_commands (const struct commands *cmds) { const char *s; fputs (_("# recipe to execute"), stdout); if (cmds->fileinfo.filenm == 0) puts (_(" (built-in):")); else printf (_(" (from '%s', line %lu):\n"), cmds->fileinfo.filenm, cmds->fileinfo.lineno); s = cmds->commands; while (*s != '\0') { const char *end; int bs; /* Print one full logical recipe line: find a non-escaped newline. */ for (end = s, bs = 0; *end != '\0'; ++end) { if (*end == '\n' && !bs) break; bs = *end == '\\' ? !bs : 0; } printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s); s = end + (end[0] == '\n'); } } ================================================ FILE: src/commands.h ================================================ /* Definition of data structures describing shell commands for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Structure that gives the commands to make a file and information about where these commands came from. */ struct commands { floc fileinfo; /* Where commands were defined. */ char *commands; /* Commands text. */ char **command_lines; /* Commands chopped up into lines. */ unsigned char *lines_flags; /* One set of flag bits for each line. */ unsigned short ncommand_lines;/* Number of command lines. */ char recipe_prefix; /* Recipe prefix for this command set. */ unsigned int any_recurse:1; /* Nonzero if any 'lines_flags' elt has */ /* the COMMANDS_RECURSE bit set. */ }; /* Bits in 'lines_flags'. */ #define COMMANDS_RECURSE 1 /* Recurses: + or $(MAKE). */ #define COMMANDS_SILENT 2 /* Silent: @. */ #define COMMANDS_NOERROR 4 /* No errors: -. */ struct file; struct child; void fatal_error_signal (int sig); void execute_file_commands (struct file *file); void print_commands (const struct commands *cmds); void delete_child_targets (struct child *child); void chop_commands (struct commands *cmds); void set_file_variables (struct file *file, const char *stem); ================================================ FILE: src/config.h-vms ================================================ /* config.h-vms. Generated by hand by Klaus Kmpf -*-C-*- Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "mkconfig.h" #define MK_OS_VMS 1 /* Pull in types.h here to get __CRTL_VER defined for old versions of the compiler which don't define it. */ #ifdef __DECC # include #endif /* Define to 1 if on AIX 3. System headers sometimes define this. We just want to avoid a redefinition error message. */ #ifndef _ALL_SOURCE /* #undef _ALL_SOURCE */ #endif /* Define to 1 if NLS is requested. */ /* #undef ENABLE_NLS */ /* Define as 1 if you have dcgettext. */ /* #undef HAVE_DCGETTEXT */ /* Define as 1 if you have gettext and don't want to use GNU gettext. */ /* #undef HAVE_GETTEXT */ /* Embed GNU Guile support */ /* #undef HAVE_GUILE */ /* Define to 1 if your locale.h file contains LC_MESSAGES. */ /* #undef HAVE_LC_MESSAGES */ /* Define to the installation directory for locales. */ #define LOCALEDIR "" /* Define as 1 if you have the stpcpy function. */ /* #undef HAVE_STPCPY */ /* Define to 1 if the closedir function returns void instead of int. */ /* #undef CLOSEDIR_VOID */ /* Define to empty if the keyword does not work. */ /* #undef const */ /* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. This function is required for alloca.c support on those systems. */ /* #undef CRAY_STACKSEG_END */ /* Define for DGUX with . */ /* #undef DGUX */ /* Define to the widest signed integer type if and do not define. */ #define intmax_t unsigned long /* Define to 'unsigned long' or 'unsigned long long' if doesn't define. */ #define uintmax_t unsigned long /* Define to 'int' if doesn't define. */ /* #undef gid_t */ /* Define to 1 if you have alloca, as a function or macro. */ #define HAVE_ALLOCA 1 /* Define to 1 if you have and it should be used (not on Ultrix). */ /* #undef HAVE_ALLOCA_H */ /* Define to 1 if you have the declaration of 'getloadavg'. */ /* #undef HAVE_DECL_GETLOADAVG */ /* Define to 1 if you have the fdopen function. */ #define HAVE_FDOPEN 1 /* Define to 1 if your system has a working fnmatch function. */ /* #undef HAVE_FNMATCH */ /* Define to 1 if you have the getmntent function. */ /* #undef HAVE_GETMNTENT */ /* Define to 1 if the 'long double' type works. */ /* #undef HAVE_LONG_DOUBLE */ /* Define to 1 if you support file names longer than 14 characters. */ #define HAVE_LONG_FILE_NAMES 1 /* Define to 1 if you have a working 'mmap' system call. */ /* #undef HAVE_MMAP */ /* Define to 1 if system calls automatically restart after interruption by a signal. */ /* #undef HAVE_RESTARTABLE_SYSCALLS */ /* Define to 1 if your struct stat has st_blksize. */ /* #undef HAVE_ST_BLKSIZE */ /* Define to 1 if your struct stat has st_blocks. */ /* #undef HAVE_ST_BLOCKS */ /* Define to 1 if you have the strcoll function and it is properly defined. */ /* #undef HAVE_STRCOLL */ /* Define to 1 if you have the strncasecmp' function. */ #if __CRTL_VER >= 70000000 #define HAVE_STRNCASECMP 1 #endif /* Define to 1 if your struct stat has st_rdev. */ /* #undef HAVE_ST_RDEV */ /* Define to 1 if you have the strftime function. */ /* #undef HAVE_STRFTIME */ /* Define to 1 if you have that is POSIX.1 compatible. */ /* #undef HAVE_SYS_WAIT_H */ /* Define to 1 if your struct tm has tm_zone. */ /* #undef HAVE_TM_ZONE */ /* Define to 1 if you don't have tm_zone but do have the external array tzname. */ /* #undef HAVE_TZNAME */ /* Define to 1 if you have . */ #ifdef __DECC #define HAVE_UNISTD_H 1 #endif /* Define to 1 if utime(file, NULL) sets file's timestamp to the present. */ /* #undef HAVE_UTIME_NULL */ /* Define to 1 if you have the wait3 system call. */ /* #undef HAVE_WAIT3 */ /* Define to 1 if on MINIX. */ /* #undef _MINIX */ /* Define to 1 if your struct nlist has an n_un member. */ /* #undef NLIST_NAME_UNION */ /* Define to 1 if you have . */ /* #undef NLIST_STRUCT */ /* Define to 1 if your C compiler doesn't accept -c and -o together. */ /* #undef NO_MINUS_C_MINUS_O */ /* Define to 'int' if doesn't define. */ /* I assume types.h is available for all 5.0 cc/cxx compilers */ #if __DECC_VER < 50090000 #define pid_t int #endif /* Define to 1 if the system does not provide POSIX.1 features except with this defined. */ /* #undef _POSIX_1_SOURCE */ /* Define to 1 if you need to in order for stat and other things to work. */ /* #undef _POSIX_SOURCE */ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at run-time. STACK_DIRECTION > 0 => grows toward higher addresses STACK_DIRECTION < 0 => grows toward lower addresses STACK_DIRECTION = 0 => direction of growth unknown */ /* #undef STACK_DIRECTION */ /* Define to 1 if the 'S_IS*' macros in do not work properly. */ /* #undef STAT_MACROS_BROKEN */ /* Define to 1 if you have the ANSI C header files. */ /* #undef STDC_HEADERS */ /* Define on System V Release 4. */ /* #undef SVR4 */ /* Define to 1 if 'sys_siglist' is declared by . */ /* #undef SYS_SIGLIST_DECLARED */ /* Define to 'int' if doesn't define. */ #if __DECC_VER < 50090000 #define uid_t int #endif /* Define for Encore UMAX. */ /* #undef UMAX */ /* Define for Encore UMAX 4.3 that has instead of . */ /* #undef UMAX4_3 */ /* Define to the name of the SCCS 'get' command. */ /* #undef SCCS_GET */ /* Define this if the SCCS 'get' command understands the '-G' option. */ /* #undef SCCS_GET_MINUS_G */ /* Define this to enable job server support in GNU Make. */ /* #undef MAKE_JOBSERVER */ /* Define to be the nanoseconds member of struct stat's st_mtim, if it exists. */ /* #undef ST_MTIM_NSEC */ /* Define to 1 if the C library defines the variable 'sys_siglist'. */ /* #undefine HAVE_SYS_SIGLIST */ /* Define to 1 if the C library defines the variable '_sys_siglist'. */ /* #undef HAVE__SYS_SIGLIST */ /* Define to 1 if you have the 'union wait' type in . */ /* #undef HAVE_UNION_WAIT */ /* Define to 1 if you have the dup2 function. */ #define HAVE_DUP2 1 /* Define to 1 if you have the getcwd function. */ #define HAVE_GETCWD 1 /* Define to 1 if you have the getgroups function. */ /* #undef HAVE_GETGROUPS */ /* Define to 1 if you have the gethostbyname function. */ /* #undef HAVE_GETHOSTBYNAME */ /* Define to 1 if you have the gethostname function. */ /* #undef HAVE_GETHOSTNAME */ /* Define to 1 if you have the memmove function. */ #define HAVE_MEMMOVE 1 /* Define to 1 if you have the 'mkfifo' function. */ /* #undef HAVE_MKFIFO */ /* Define to 1 if you have the mktemp function. */ #define HAVE_MKTEMP 1 /* Define to 1 if you have the psignal function. */ /* #undef HAVE_PSIGNAL */ /* Define to 1 if you have the pstat_getdynamic function. */ /* #undef HAVE_PSTAT_GETDYNAMIC */ /* Define to 1 if you have the setegid function. */ /* #undef HAVE_SETEGID */ /* Define to 1 if you have the seteuid function. */ /* #undef HAVE_SETEUID */ /* Define to 1 if you have the setlinebuf function. */ /* #undef HAVE_SETLINEBUF */ /* Define to 1 if you have the setregid function. */ /* #undefine HAVE_SETREGID */ /* Define to 1 if you have the setreuid function. */ /* #define HAVE_SETREUID */ /* Define to 1 if you have the sigsetmask function. */ #define HAVE_SIGSETMASK 1 /* Define to 1 if you have the socket function. */ /* #undef HAVE_SOCKET */ /* Define to 1 if you have the strcasecmp function. */ #define HAVE_STRCASECMP 1 /* Define to 1 if you have the strcmpi function. */ /* #undef HAVE_STRCMPI */ /* Define to 1 if you have the stricmp function. */ /* #undef HAVE_STRICMP */ /* Define to 1 if you have the strsignal function. */ /* #undef HAVE_STRSIGNAL */ /* Define to 1 if you have the `strtoll' function. */ #define HAVE_STRTOLL 1 /* Define to 1 if you have the wait3 function. */ /* #undef HAVE_WAIT3 */ /* Define to 1 if you have the waitpid function. */ /* #undef HAVE_WAITPID */ /* Define to 1 if you have the header file. */ #define HAVE_DIRENT_H 1 /* Define to 1 if you have the header file. */ #ifdef __DECC #define HAVE_FCNTL_H 1 #endif /* Define to 1 if you have the header file. */ #define HAVE_LIMITS_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_MACH_MACH_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_MEMORY_H */ /* Define to 1 if you have the `mempcpy' function. */ /* #undef HAVE_MEMPCPY */ /* Define to 1 if you have the header file. */ /* #undef HAVE_NDIR_H */ /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_DIR_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_NDIR_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_PARAM_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_WAIT_H */ /* Define to 1 if you have the dgc library (-ldgc). */ /* #undef HAVE_LIBDGC */ /* Define to 1 if you have the kstat library (-lkstat). */ /* #undef HAVE_LIBKSTAT * /* Define to 1 if you have the sun library (-lsun). */ /* #undef HAVE_LIBSUN */ /* Define to 1 if you have the `isatty' function. */ /* #undef HAVE_ISATTY */ /* Define to 1 if you have the `ttyname' function. */ /* #undef HAVE_TTYNAME */ /* Use high resolution file timestamps if nonzero. */ #define FILE_TIMESTAMP_HI_RES 0 /* Define for case insensitve filenames */ #define HAVE_CASE_INSENSITIVE_FS 1 /* VMS specific, define it if you want to use case sensitive targets */ /* #undef WANT_CASE_SENSITIVE_TARGETS */ /* VMS specific, V7.0 has opendir() and friends, so it's undefined */ /* If you want to use non-VMS code for opendir() etc. on V7.0 and greater define the first or both macros AND change the compile command to get the non-VMS versions linked: (prefix=(all,except=(opendir,... */ /* #undef HAVE_VMSDIR_H */ /* #undef _DIRENT_HAVE_D_NAMLEN */ /* On older systems without 7.0 backport of CRTL use non-VMS code for opendir() etc. */ #if __CRTL_VER < 70000000 # define HAVE_VMSDIR_H 1 #endif #if defined(HAVE_VMSDIR_H) && defined(HAVE_DIRENT_H) #undef HAVE_DIRENT_H #endif #define HAVE_STDLIB_H 1 #define INCLUDEDIR "sys$sysroot:[syslib]" #define LIBDIR "sys$sysroot:[syslib]" /* Don't use RTL functions of OpenVMS */ #ifdef __DECC #include #include #define getopt gnu_getopt #define optarg gnu_optarg #define optopt gnu_optopt #define optind gnu_optind #define opterr gnu_opterr #define globfree gnu_globfree #define glob gnu_glob #endif /* Define if using alloca.c. */ /* #undef C_ALLOCA */ /* maybe this should be placed into makeint.h */ #if defined(__VAX) && defined(__DECC) #define alloca(n) __ALLOCA(n) #endif /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ /* # undef WORDS_BIGENDIAN */ /* Output sync sypport */ #define NO_OUTPUT_SYNC /* Define to 1 to write even short single-line actions into a VMS/DCL command file; this also enables exporting make environment variables into the (sub-)process, which executes the action. The usual make rules apply whether a shell variable - here a DCL symbol or VMS logical [see CRTL getenv()] - is added to the make environment and is exported. */ #define USE_DCL_COM_FILE 1 /* Build host information. */ #define MAKE_HOST "VMS" /* Include customized declarations. */ #include "../src/mkcustom.h" ================================================ FILE: src/config.h.W32 ================================================ /* config.h.W32 -- hand-massaged config.h file for Windows builds -*-C-*- Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "mkconfig.h" /* Build for the Windows32 API. */ #define MK_OS_W32 1 /* Suppress some Visual C++ warnings. Maybe after the code cleanup for ISO C we can remove some/all of these. */ #if _MSC_VER > 1000 # pragma warning(disable:4100) /* unreferenced formal parameter */ # pragma warning(disable:4130) /* logical operation on address of string constant */ # pragma warning(disable:4131) /* uses old-style declarator */ # pragma warning(disable:4702) /* unreachable code */ # define _CRT_SECURE_NO_WARNINGS 1 /* function or variable may be unsafe */ # define _CRT_NONSTDC_NO_WARNINGS 1 /* functions w/o a leading underscore */ #endif /* Define to 1 if the 'closedir' function returns void instead of 'int'. */ /* #undef CLOSEDIR_VOID */ /* Define to 1 if using 'alloca.c'. */ /* #undef C_ALLOCA */ /* Define to 1 for DGUX with . */ /* #undef DGUX */ /* Define to 1 if translation of program messages to the user's native language is requested. */ /* #undef ENABLE_NLS */ /* Use high resolution file timestamps if nonzero. */ #define FILE_TIMESTAMP_HI_RES 0 /* Define to 1 if you have 'alloca' after including , a header that may be supplied by this distribution. */ #define HAVE_ALLOCA 1 /* Define to 1 if works. */ /* #undef HAVE_ALLOCA_H */ /* Define to 1 if you have the 'atexit' function. */ #define HAVE_ATEXIT 1 /* Use case insensitive file names */ /* #undef HAVE_CASE_INSENSITIVE_FS */ /* Define to 1 if you have the clock_gettime function. */ /* #undef HAVE_CLOCK_GETTIME */ /* Define if the GNU dcgettext() function is already present or preinstalled. */ /* #undef HAVE_DCGETTEXT */ /* Define to 1 if you have the declaration of 'bsd_signal', and to 0 if you don't. */ #define HAVE_DECL_BSD_SIGNAL 0 /* Define to 1 if you have the declaration of `dlerror', and to 0 if you don't. */ #define HAVE_DECL_DLERROR 0 /* Define to 1 if you have the declaration of `dlopen', and to 0 if you don't. */ #define HAVE_DECL_DLOPEN 0 /* Define to 1 if you have the declaration of `dlsym', and to 0 if you don't. */ #define HAVE_DECL_DLSYM 0 /* Define to 1 if you have the declaration of 'getloadavg'. */ /* #undef HAVE_DECL_GETLOADAVG */ /* Define to 1 if you have the declaration of 'sys_siglist', and to 0 if you don't. */ #define HAVE_DECL_SYS_SIGLIST 0 /* Define to 1 if you have the declaration of '_sys_siglist', and to 0 if you don't. */ #define HAVE_DECL__SYS_SIGLIST 0 /* Define to 1 if you have the declaration of '__sys_siglist', and to 0 if you don't. */ #define HAVE_DECL___SYS_SIGLIST 0 /* Define to 1 if you have the header file, and it defines 'DIR'. */ #define HAVE_DIRENT_H 1 /* Define to 1 if you have the header file, and it defines getcwd() and chdir(). */ #if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TINYC__)) && !defined(__INTERIX) # define HAVE_DIRECT_H 1 #endif /* Support DOS-style pathnames. */ #define HAVE_DOS_PATHS 1 /* Define to 1 if you have the 'dup' function. */ #define HAVE_DUP 1 /* Define to 1 if you have the 'dup2' function. */ #define HAVE_DUP2 1 /* Define to 1 if you have the header file. */ #define HAVE_FCNTL_H 1 /* Define to 1 if you have the 'fdopen' function. */ #ifdef __MINGW32__ #define HAVE_FDOPEN 1 #endif /* Define to 1 if you have the `fork' function. */ /* #undef HAVE_FORK */ /* Define to 1 if you have the 'getcwd' function. */ #define HAVE_GETCWD 1 /* Define to 1 if you have the 'getgroups' function. */ /* #undef HAVE_GETGROUPS */ /* Define to 1 if you have the 'gethostbyname' function. */ /* #undef HAVE_GETHOSTBYNAME */ /* Define to 1 if you have the 'gethostname' function. */ /* #undef HAVE_GETHOSTNAME */ /* Define to 1 if you have the 'getrlimit' function. */ /* #undef HAVE_GETRLIMIT */ /* Define if the GNU gettext() function is already present or preinstalled. */ /* #undef HAVE_GETTEXT */ /* Define to 1 if you have a standard gettimeofday function */ #ifdef __MINGW32__ #define HAVE_GETTIMEOFDAY 1 #endif /* Embed GNU Guile support. Windows build sets this on the compilation command line. */ /* #undef HAVE_GUILE */ /* Define if you have the iconv() function. */ /* #undef HAVE_ICONV */ /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_INTTYPES_H 1 #endif /* Define to 1 if you have the `isatty' function. */ #define HAVE_ISATTY 1 /* Define to 1 if you have the 'dgc' library (-ldgc). */ /* #undef HAVE_LIBDGC */ /* Define to 1 if you have the 'kstat' library (-lkstat). */ /* #undef HAVE_LIBKSTAT */ /* Define to 1 if you have the `perfstat' library (-lperfstat). */ /* #undef HAVE_LIBPERFSTAT */ /* Define to 1 if you have the header file. */ #define HAVE_LIMITS_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_LOCALE_H */ /* Define to 1 if the system has the type 'long long int'. */ #define HAVE_LONG_LONG_INT 1 /* Define to 1 if you have the 'lstat' function. */ /* #undef HAVE_LSTAT */ /* Define to 1 if you have the header file. */ /* #undef HAVE_MACH_MACH_H */ /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the `mempcpy' function. */ /* #undef HAVE_MEMPCPY */ /* Define to 1 if you have the `memrchr' function. */ /* #undef HAVE_MEMRCHR */ /* Define to 1 if you have the header file. */ /* #undef HAVE_MINIX_CONFIG_H */ /* Define to 1 if you have the 'mkfifo' function. */ /* #undef HAVE_MKFIFO */ /* Define to 1 if you have the 'mkstemp' function. */ /* #undef HAVE_MKSTEMP */ /* Define to 1 if you have the `mkstemp' function. */ /* #undef HAVE_MKSTEMP */ /* Define to 1 if you have the 'mktemp' function. */ #define HAVE_MKTEMP 1 /* Define to 1 if you have the header file, and it defines 'DIR'. */ /* #undef HAVE_NDIR_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_NLIST_H */ /* Define to 1 if you have the 'pipe' function. */ /* #undef HAVE_PIPE */ /* Define to 1 if you have the `posix_spawn' function. */ /* #undef HAVE_POSIX_SPAWN */ /* Define to 1 if you have the `posix_spawnattr_setsigmask' function. */ /* #undef HAVE_POSIX_SPAWNATTR_SETSIGMASK */ /* Define to 1 if you have the `pselect' function. */ /* #undef HAVE_PSELECT */ /* Define to 1 if you have the 'pstat_getdynamic' function. */ /* #undef HAVE_PSTAT_GETDYNAMIC */ /* Define to 1 if you have the 'readlink' function. */ /* #undef HAVE_READLINK */ /* Define to 1 if you have the 'realpath' function. */ /* #undef HAVE_REALPATH */ /* Define to 1 if defines the SA_RESTART constant. */ /* #undef HAVE_SA_RESTART */ /* Define to 1 if you have the 'setegid' function. */ /* #undef HAVE_SETEGID */ /* Define to 1 if you have the 'seteuid' function. */ /* #undef HAVE_SETEUID */ /* Define to 1 if you have the 'setlinebuf' function. */ /* #undef HAVE_SETLINEBUF */ /* Define to 1 if you have the 'setregid' function. */ /* #undef HAVE_SETREGID */ /* Define to 1 if you have the 'setreuid' function. */ /* #undef HAVE_SETREUID */ /* Define to 1 if you have the 'setrlimit' function. */ /* #undef HAVE_SETRLIMIT */ /* Define to 1 if you have the 'setvbuf' function. */ #define HAVE_SETVBUF 1 /* Define to 1 if you have the 'sigaction' function. */ /* #undef HAVE_SIGACTION */ /* Define to 1 if you have the 'sigsetmask' function. */ /* #undef HAVE_SIGSETMASK */ /* Define to 1 if you have the 'socket' function. */ /* #undef HAVE_SOCKET */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SPAWN_H */ /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_STDINT_H 1 #endif /* Define to 1 if you have the header file. */ #define HAVE_STDIO_H 1 /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the `stpcpy' function. */ /* #undef HAVE_STPCPY */ /* Define to 1 if you have the 'strcasecmp' function. */ #if defined(__MINGW32__) || defined(__TINYC__) #define HAVE_STRCASECMP 1 #endif /* Define to 1 if you have the 'strcmpi' function. */ #define HAVE_STRCMPI 1 /* Define to 1 if you have the 'strcoll' function and it is properly defined. */ #define HAVE_STRCOLL 1 /* Define to 1 if you have the 'strdup' function. */ #define HAVE_STRDUP 1 /* Define to 1 if you have the `strerror' function. */ #define HAVE_STRERROR 1 /* Define to 1 if you have the 'stricmp' function. */ #define HAVE_STRICMP 1 /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_STRINGS_H 1 #endif /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the 'strncasecmp' function. */ #if defined(__MINGW32__) || defined(__TINYC__) #define HAVE_STRNCASECMP 1 #endif /* Define to 1 if you have the 'strncmpi' function. */ /* #undef HAVE_STRNCMPI */ /* Define to 1 if you have the 'strndup' function. */ /* #undef HAVE_STRNDUP */ /* Define to 1 if you have the 'strnicmp' function. */ #ifdef __MINGW32__ #define HAVE_STRNICMP 1 #endif /* Define to 1 if you have the 'strsignal' function. */ /* #undef HAVE_STRSIGNAL */ /* Define to 1 if you have the `strtoll' function. */ #define HAVE_STRTOLL 1 #ifdef __TINYC__ # ifndef strtoll # define strtoll _strtoi64 # endif # ifndef strtoull # define strtoull _strtoui64 # endif #endif /* Define to 1 if `d_type' is a member of `struct dirent'. */ /* SV 57152: MinGW64 version of dirent doesn't support d_type. */ #ifndef __MINGW64__ # define HAVE_STRUCT_DIRENT_D_TYPE 1 #endif /* Define to 1 if 'n_un.n_name' is a member of 'struct nlist'. */ /* #undef HAVE_STRUCT_NLIST_N_UN_N_NAME */ /* Define to 1 if you have the header file, and it defines 'DIR'. */ /* #undef HAVE_SYS_DIR_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_FILE_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_LOADAVG_H */ /* Define to 1 if you have the header file, and it defines 'DIR'. */ /* #undef HAVE_SYS_NDIR_H */ /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_SYS_PARAM_H 1 #endif /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_RESOURCE_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_SELECT_H */ /* Define to 1 if you have the header file. */ #define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_SYS_TIME_H 1 #endif /* Define to 1 if you have the header file. */ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_WAIT_H */ /* Define to 1 if you have the `ttyname' function. */ #define HAVE_TTYNAME 1 char *ttyname (int); /* Define to 1 if the system has the type `intmax_t'. */ #define HAVE_INTMAX_T 1 /* Define to 1 if the system has the type `uintmax_t'. */ #define HAVE_UINTMAX_T 1 /* Define to 1 if you have the `umask' function. */ #if defined(__MINGW32__) || defined(__TINYC__) # define HAVE_UMASK 1 #endif /* Define to 1 if you have the \'union wait' type in . */ /* #undef HAVE_UNION_WAIT */ /* Define to 1 if you have the header file. */ #ifdef __MINGW32__ #define HAVE_UNISTD_H 1 #endif /* Define to 1 if the system has the type 'unsigned long long int'. */ #define HAVE_UNSIGNED_LONG_LONG_INT 1 /* Define to 1 if you have the `vfork' function. */ /* #undef HAVE_VFORK */ /* Define to 1 if you have the header file. */ /* #undef HAVE_VFORK_H */ /* Define to 1 if you have the 'wait3' function. */ /* #undef HAVE_WAIT3 */ /* Define to 1 if you have the 'waitpid' function. */ /* #undef HAVE_WAITPID */ /* Define to 1 if you have the header file. */ /* #undef HAVE_WCHAR_H */ /* Define to 1 if `fork' works. */ /* #undef HAVE_WORKING_FORK */ /* Define to 1 if `vfork' works. */ /* #undef HAVE_WORKING_VFORK */ /* Define to 1 if the system has the type `_Bool'. */ /* #undef HAVE__BOOL */ /* Build host information. */ #define MAKE_HOST "Windows32" /* Define to 1 to enable job server support in GNU Make. */ #define MAKE_JOBSERVER 1 /* Define to 1 to enable 'load' support in GNU Make. */ #define MAKE_LOAD 1 /* Define to 1 to enable symbolic link timestamp checking. */ /* #undef MAKE_SYMLINKS */ /* Define to 1 if your 'struct nlist' has an 'n_un' member. Obsolete, depend on 'HAVE_STRUCT_NLIST_N_UN_N_NAME */ /* #undef NLIST_NAME_UNION */ /* Define to 1 if struct nlist.n_name is a pointer rather than an array. */ /* #undef NLIST_STRUCT */ /* Define to 1 if your C compiler doesn't accept -c and -o together. */ /* #undef NO_MINUS_C_MINUS_O */ /* Define to the character that separates directories in PATH. */ #define PATH_SEPARATOR_CHAR ';' /* Define to the name of the SCCS 'get' command. */ #define SCCS_GET "echo no sccs get" /* Define this if the SCCS 'get' command understands the '-G' option. */ /* #undef SCCS_GET_MINUS_G */ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at run time. STACK_DIRECTION > 0 => grows toward higher addresses STACK_DIRECTION < 0 => grows toward lower addresses STACK_DIRECTION = 0 => direction of growth unknown */ /* #undef STACK_DIRECTION */ /* Define to 1 if the 'S_IS*' macros in do not work properly. */ /* #undef STAT_MACROS_BROKEN */ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Define if struct stat contains a nanoseconds field */ /* #undef ST_MTIM_NSEC */ /* Define to 1 on System V Release 4. */ /* #undef SVR4 */ /* Define to 1 for Encore UMAX. */ /* #undef UMAX */ /* Define to 1 for Encore UMAX 4.3 that has instead of . */ /* #undef UMAX4_3 */ /* Define if using the dmalloc debugging malloc package */ /* #undef WITH_DMALLOC */ /* Define to 1 if on AIX 3. System headers sometimes define this. We just want to avoid a redefinition error message. */ #ifndef _ALL_SOURCE /* # undef _ALL_SOURCE */ #endif /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ /* # undef WORDS_BIGENDIAN */ /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ /* Define for large files, on AIX-style hosts. */ /* #undef _LARGE_FILES */ /* Define to 1 if on MINIX. */ /* #undef _MINIX */ /* Define to 2 if the system does not provide POSIX.1 features except with this defined. */ /* #undef _POSIX_1_SOURCE */ /* Define to 1 if you need to in order for 'stat' and other things to work. */ /* #undef _POSIX_SOURCE */ /* Define to empty if 'const' does not conform to ANSI C. */ /* #undef const */ #ifdef __MINGW32__ # undef __USE_MINGW_ANSI_STDIO # define __USE_MINGW_ANSI_STDIO 1 #endif /* Number of bits in a timestamp, on hosts where this is settable. */ /* #undef _TIME_BITS */ /* For 64-bit time_t on 32-bit mingw. */ #ifdef __MINGW32__ # define __MINGW_USE_VC2005_COMPAT 1 #endif #include /* Define to 'int' if doesn't define. */ #define gid_t int /* Define to 'int' if does not define. */ /* GCC 4.x reportedly defines pid_t. */ #ifndef _PID_T_ #ifdef _WIN64 #define pid_t __int64 #else #define pid_t int #endif #endif /* Define to `int' if does not define. */ #define ssize_t int /* Define to 'int' if doesn't define. */ #define uid_t int /* Define {u,}intmax_t if not defined in or . */ #if !HAVE_STDINT_H && !HAVE_INTTYPES_H #define intmax_t long long #define uintmax_t unsigned long long #endif /* Define if you have that is POSIX.1 compatible. */ /* #undef HAVE_SYS_WAIT_H */ /* Define to the installation directory for locales. */ #define LOCALEDIR "" /* * Refer to README.W32 for info on the following settings */ /* * If you have a shell that does not grok 'sh -c quoted-command-line' * correctly, you need this setting; it is the default for tcc. * Please see below for specific shell support. */ #if defined(__TINYC__) #define BATCH_MODE_ONLY_SHELL 1 #else /*#define BATCH_MODE_ONLY_SHELL 1 */ #endif /* * Define if you have the Cygnus "Cygwin" GNU Windows32 tool set. * Do NOT define BATCH_MODE_ONLY_SHELL if you define HAVE_CYGWIN_SHELL */ /*#define HAVE_CYGWIN_SHELL 1 */ /* * Define if you have the MKS tool set or shell. Do NOT define * BATCH_MODE_ONLY_SHELL if you define HAVE_MKS_SHELL */ /*#define HAVE_MKS_SHELL 1 */ /* * Enforce the mutual exclusivity restriction. */ #ifdef HAVE_MKS_SHELL #undef BATCH_MODE_ONLY_SHELL #endif #ifdef HAVE_CYGWIN_SHELL #undef BATCH_MODE_ONLY_SHELL #endif /* Include customized declarations. */ #include "../src/mkcustom.h" ================================================ FILE: src/configh.dos ================================================ /* configh.dos -- hand-massaged config.h file for MS-DOS builds -*-C-*- Copyright (C) 1994-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "mkconfig.h" #define MK_OS_DOS 1 /* Include this header to make __DJGPP_MINOR__ available because DJGPP ports of GCC 4.3.0 and later no longer do it automatically. */ #include /* Many things are defined already by a system header. */ #include #if __DJGPP__ > 2 || __DJGPP_MINOR__ > 1 /* Define to 1 if 'sys_siglist' is declared by or . */ # define SYS_SIGLIST_DECLARED 1 /* Define to 1 if the C library defines the variable '_sys_siglist'. */ # define HAVE_DECL_SYS_SIGLIST 1 #else /* Define NSIG. */ # define NSIG SIGMAX #endif /* Use high resolution file timestamps if nonzero. */ #define FILE_TIMESTAMP_HI_RES 0 /* Define to 1 if you have 'alloca', as a function or macro. */ #define HAVE_ALLOCA 1 /* Define to 1 if you have the fdopen function. */ #define HAVE_FDOPEN 1 /* Define to 1 if you have the 'getgroups' function. */ #define HAVE_GETGROUPS 1 /* Define to 1 if the system has the type 'long long int'. */ #define HAVE_LONG_LONG_INT 1 /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the mkstemp function. */ #define HAVE_MKSTEMP 1 /* Define to 1 if you have the 'mktemp' function. */ #define HAVE_MKTEMP 1 /* Define to 1 if you have the 'setlinebuf' function. */ #define HAVE_SETLINEBUF 1 /* Define to 1 if you have the 'setvbuf' function. */ #define HAVE_SETVBUF 1 #define SCCS_GET "get" /* Define to 1 if you have the select function. */ #define HAVE_SELECT 1 /* Define to 1 if you have the stricmp function. */ #define HAVE_STRICMP 1 /* Define to 1 if you have the 'strncasecmp' function. */ #define HAVE_STRNCASECMP 1 /* Define to 1 if you have the `strtoll' function. */ #define HAVE_STRTOLL 1 /* Output sync support */ #define NO_OUTPUT_SYNC 1 /* Build host information. */ #define MAKE_HOST "i386-pc-msdosdjgpp" /* Grok DOS paths (drive specs and backslash path element separators) */ #define HAVE_DOS_PATHS 1 /* Define the type of the first arg to select(). */ #define fd_set_size_t int /* Define to the widest signed integer type if and do not define. */ #define intmax_t long long /* Define to `int' if does not define. */ #if __DJGPP__ == 2 && __DJGPP_MINOR__ < 5 #define ssize_t int #endif /* Define to 'unsigned long' or 'unsigned long long' if doesn't define. */ #define uintmax_t unsigned long long /* Include customized declarations. */ #include "../src/mkcustom.h" ================================================ FILE: src/debug.h ================================================ /* Debugging macros and interface. Copyright (C) 1999-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define DB_NONE (0x000) #define DB_BASIC (0x001) #define DB_VERBOSE (0x002) #define DB_JOBS (0x004) #define DB_IMPLICIT (0x008) #define DB_PRINT (0x010) #define DB_WHY (0x020) #define DB_MAKEFILES (0x100) #define DB_ALL (0xfff) extern int db_level; #define ISDB(_l) ((_l)&db_level) /* When adding macros to this list be sure to update the value of XGETTEXT_OPTIONS in the po/Makevars file. */ #define DBS(_l,_x) do{ if(ISDB(_l)) {print_spaces (depth); \ printf _x; fflush (stdout);} }while(0) #define DBF(_l,_x) do{ if(ISDB(_l)) {print_spaces (depth); \ printf (_x, file->name); \ fflush (stdout);} }while(0) #define DB(_l,_x) do{ if(ISDB(_l)) {printf _x; fflush (stdout);} }while(0) ================================================ FILE: src/default.c ================================================ /* Data base of default implicit rules for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include "filedef.h" #include "variable.h" #include "rule.h" #include "dep.h" #include "job.h" #include "commands.h" /* Define GCC_IS_NATIVE if gcc is the native development environment on your system (gcc/bison/flex vs cc/yacc/lex). */ #if MK_OS_DOS || MK_OS_OS2 # define GCC_IS_NATIVE #endif /* This is the default list of suffixes for suffix rules. '.s' must come last, so that a '.o' file will be made from a '.c' or '.p' or ... file rather than from a .s file. */ static char default_suffixes[] #if MK_OS_VMS /* VMS should include all UNIX/POSIX + some VMS extensions */ = ".out .exe .a .olb .hlb .tlb .mlb .ln .o .obj .c .cxx .cc .cpp .pas .p \ .for .f .r .y .l .ym .yl .mar .s .ss .i .ii .mod .sym .def .h .info .dvi \ .tex .texinfo .texi .txinfo .mem .hlp .brn .rnh .rno .rnt .rnx .w .ch .cweb \ .web .com .sh .elc .el"; #elif MK_OS_OS2 = ".out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S \ .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \ .w .ch .web .sh .elc .el .obj .exe .dll .lib"; #else = ".out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S \ .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \ .w .ch .web .sh .elc .el"; #endif static struct pspec default_pattern_rules[] = { #if MK_OS_VMS { "(%)", "%", "@if f$$search(\"$@\") .eqs. \"\" then $(LIBRARY)/CREATE/" "$(or " "$(patsubst %,TEXT,$(filter %.tlb %.TLB,$@))," "$(patsubst %,HELP,$(filter %.hlb %.HLB,$@))," "$(patsubst %,MACRO,$(filter %.mlb %.MLB,$@))," "$(and " "$(patsubst %,SHARE,$(filter %.olb %.OLB,$@))," "$(patsubst %,SHARE,$(filter %.exe %.EXE,$<)))," "OBJECT)" " $@\n" "$(AR) $(ARFLAGS) $@ $<" }, #else { "(%)", "%", "$(AR) $(ARFLAGS) $@ $<" }, #endif /* The X.out rules are only in BSD's default set because BSD Make has no null-suffix rules, so 'foo.out' and 'foo' are the same thing. */ #if MK_OS_VMS { "%.exe", "%", "$(CP) $< $@" }, #endif { "%.out", "%", "@rm -f $@ \n cp $< $@" }, /* Syntax is "ctangle foo.w foo.ch foo.c". */ { "%.c", "%.w %.ch", "$(CTANGLE) $^ $@" }, { "%.tex", "%.w %.ch", "$(CWEAVE) $^ $@" }, { 0, 0, 0 } }; static struct pspec default_terminal_rules[] = { #if MK_OS_VMS /* RCS. */ { "%", "%$$5lv", /* Multinet style */ "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" }, { "%", "[.$$rcs]%$$5lv", /* Multinet style */ "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" }, { "%", "%_v", /* Normal style */ "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" }, { "%", "[.rcs]%_v", /* Normal style */ "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" }, /* SCCS. */ /* ain't no SCCS on vms */ #else /* RCS. */ { "%", "%,v", "$(CHECKOUT,v)" }, { "%", "RCS/%,v", "$(CHECKOUT,v)" }, { "%", "RCS/%", "$(CHECKOUT,v)" }, /* SCCS. */ { "%", "s.%", "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" }, { "%", "SCCS/s.%", "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" }, #endif /* !MK_OS_VMS */ { 0, 0, 0 } }; static const char *default_suffix_rules[] = { #if MK_OS_VMS ".o", "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".obj", "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".s", "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".S", "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".c", "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".cc", "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".C", "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".cpp", "$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".f", "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".m", "$(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".p", "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".F", "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".r", "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".mod", "$(COMPILE.mod) -o $@ -e $@ $^", ".def.sym", "$(COMPILE.def) -o $@ $<", ".sh", "copy $< >$@", ".obj.exe", "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@", ".mar.exe", "$(COMPILE.mar) $^ \n $(LINK.obj) $(subst .mar,.obj,$^) $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@", ".s.o", "$(COMPILE.s) -o $@ $<", ".s.exe", "$(COMPILE.s) $^ \n $(LINK.obj) $(subst .s,.obj,$^) $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@", ".c.exe", "$(COMPILE.c) $^ \n $(LINK.obj) $(subst .c,.obj,$^) $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@", ".cc.exe", #ifdef GCC_IS_NATIVE "$(COMPILE.cc) $^ \n $(LINK.obj) $(CXXSTARTUP),sys$$disk:[]$(subst .cc,.obj,$^) $(LOADLIBES) $(LXLIBS) $(LDLIBS) $(CXXRT0) /exe=$@", #else "$(COMPILE.cc) $^ \n $(CXXLINK.obj) $(subst .cc,.obj,$^) $(LOADLIBES) $(LXLIBS) $(LDLIBS) $(CXXRT0) /exe=$@", ".cxx.exe", "$(COMPILE.cxx) $^ \n $(CXXLINK.obj) $(subst .cxx,.obj,$^) $(LOADLIBES) $(LXLIBS) $(LDLIBS) $(CXXRT0) /exe=$@", #endif ".for.exe", "$(COMPILE.for) $^ \n $(LINK.obj) $(subst .for,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@", ".pas.exe", "$(COMPILE.pas) $^ \n $(LINK.obj) $(subst .pas,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@", ".com", "copy $< >$@", ".mar.obj", "$(COMPILE.mar) /obj=$@ $<", ".s.obj", "$(COMPILE.s) /obj=$@ $<", ".ss.obj", "$(COMPILE.s) /obj=$@ $<", ".c.i", "$(COMPILE.c)/prep /list=$@ $<", ".c.s", "$(COMPILE.c)/noobj/machine /list=$@ $<", ".i.s", "$(COMPILE.c)/noprep/noobj/machine /list=$@ $<", ".c.obj", "$(COMPILE.c) /obj=$@ $<", ".c.o", "$(COMPILE.c) /obj=$@ $<", ".cc.ii", "$(COMPILE.cc)/prep /list=$@ $<", ".cc.ss", "$(COMPILE.cc)/noobj/machine /list=$@ $<", ".ii.ss", "$(COMPILE.cc)/noprep/noobj/machine /list=$@ $<", ".cc.obj", "$(COMPILE.cc) /obj=$@ $<", ".cc.o", "$(COMPILE.cc) /obj=$@ $<", ".cxx.obj", "$(COMPILE.cxx) /obj=$@ $<", ".cxx.o", "$(COMPILE.cxx) /obj=$@ $<", ".for.obj", "$(COMPILE.for) /obj=$@ $<", ".for.o", "$(COMPILE.for) /obj=$@ $<", ".pas.obj", "$(COMPILE.pas) /obj=$@ $<", ".pas.o", "$(COMPILE.pas) /obj=$@ $<", ".y.c", "$(YACC.y) $< \n rename y_tab.c $@", ".l.c", "$(LEX.l) $< \n rename lexyy.c $@", ".texinfo.info", "$(MAKEINFO) $<", ".tex.dvi", "$(TEX) $<", ".cpp.o", "$(COMPILE.cpp) $(OUTPUT_OPTION) $<", ".f.o", "$(COMPILE.f) $(OUTPUT_OPTION) $<", ".m.o", "$(COMPILE.m) $(OUTPUT_OPTION) $<", ".p.o", "$(COMPILE.p) $(OUTPUT_OPTION) $<", ".r.o", "$(COMPILE.r) $(OUTPUT_OPTION) $<", ".mod.o", "$(COMPILE.mod) -o $@ $<", ".c.ln", "$(LINT.c) -C$* $<", ".y.ln", "$(YACC.y) $< \n rename y_tab.c $@", ".l.ln", "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c", #else /* ! MK_OS_VMS */ ".o", "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".s", "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".S", "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".c", "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".cc", "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".C", "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".cpp", "$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".f", "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".m", "$(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".p", "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".F", "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".r", "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@", ".mod", "$(COMPILE.mod) -o $@ -e $@ $^", ".def.sym", "$(COMPILE.def) -o $@ $<", ".sh", "cat $< >$@ \n chmod a+x $@", ".s.o", "$(COMPILE.s) -o $@ $<", ".S.o", "$(COMPILE.S) -o $@ $<", ".c.o", "$(COMPILE.c) $(OUTPUT_OPTION) $<", ".cc.o", "$(COMPILE.cc) $(OUTPUT_OPTION) $<", ".C.o", "$(COMPILE.C) $(OUTPUT_OPTION) $<", ".cpp.o", "$(COMPILE.cpp) $(OUTPUT_OPTION) $<", ".f.o", "$(COMPILE.f) $(OUTPUT_OPTION) $<", ".m.o", "$(COMPILE.m) $(OUTPUT_OPTION) $<", ".p.o", "$(COMPILE.p) $(OUTPUT_OPTION) $<", ".F.o", "$(COMPILE.F) $(OUTPUT_OPTION) $<", ".r.o", "$(COMPILE.r) $(OUTPUT_OPTION) $<", ".mod.o", "$(COMPILE.mod) -o $@ $<", ".c.ln", "$(LINT.c) -C$* $<", ".y.ln", #if MK_OS_DOS "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c", #else "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c", #endif ".l.ln", "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c", ".y.c", #if MK_OS_DOS "$(YACC.y) $< \n mv -f y_tab.c $@", #else "$(YACC.y) $< \n mv -f y.tab.c $@", #endif ".l.c", "@$(RM) $@ \n $(LEX.l) $< > $@", ".ym.m", "$(YACC.m) $< \n mv -f y.tab.c $@", ".lm.m", "@$(RM) $@ \n $(LEX.m) $< > $@", ".F.f", "$(PREPROCESS.F) $(OUTPUT_OPTION) $<", ".r.f", "$(PREPROCESS.r) $(OUTPUT_OPTION) $<", /* This might actually make lex.yy.c if there's no %R% directive in $*.l, but in that case why were you trying to make $*.r anyway? */ ".l.r", "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@", ".S.s", "$(PREPROCESS.S) $< > $@", ".texinfo.info", "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@", ".texi.info", "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@", ".txinfo.info", "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@", ".tex.dvi", "$(TEX) $<", ".texinfo.dvi", "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<", ".texi.dvi", "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<", ".txinfo.dvi", "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<", ".w.c", "$(CTANGLE) $< - $@", /* The '-' says there is no '.ch' file. */ ".web.p", "$(TANGLE) $<", ".w.tex", "$(CWEAVE) $< - $@", /* The '-' says there is no '.ch' file. */ ".web.tex", "$(WEAVE) $<", #endif /* !MK_OS_VMS */ 0, 0, }; static const char *default_variables[] = { #if MK_OS_VMS #ifdef __ALPHA "ARCH", "ALPHA", #endif #ifdef __ia64 "ARCH", "IA64", #endif #ifdef __VAX "ARCH", "VAX", #endif "AR", "library", "LIBRARY", "library", "ARFLAGS", "/replace", "AS", "macro", "MACRO", "macro", #ifdef GCC_IS_NATIVE "CC", "gcc", #else "CC", "cc", #endif "CD", "builtin_cd", "ECHO", "builtin_echo", #ifdef GCC_IS_NATIVE "C++", "gcc/plus", "CXX", "gcc/plus", #else "C++", "cxx", "CXX", "cxx", #ifndef __ia64 "CXXLD", "cxxlink", "CXXLINK", "cxxlink", #else /* CXXLINK is not used on VMS/IA64 */ "CXXLD", "link", "CXXLINK", "link", #endif #endif "CO", "co", "CPP", "$(CC) /preprocess_only", "FC", "fortran", /* System V uses these, so explicit rules using them should work. However, there is no way to make implicit rules use them and FC. */ "F77", "$(FC)", "F77FLAGS", "$(FFLAGS)", "LD", "link", "LEX", "lex", "PC", "pascal", "YACC", "bison/yacc", "YFLAGS", "/Define/Verbose", "BISON", "bison", "MAKEINFO", "makeinfo", "TEX", "tex", "TEXINDEX", "texindex", "RM", "delete/nolog", "CSTARTUP", "", #ifdef GCC_IS_NATIVE "CRT0", ",sys$$library:vaxcrtl.olb/lib,gnu_cc_library:crt0.obj", "CXXSTARTUP", "gnu_cc_library:crtbegin.obj", "CXXRT0", ",sys$$library:vaxcrtl.olb/lib,gnu_cc_library:crtend.obj,gnu_cc_library:gxx_main.obj", "LXLIBS", ",gnu_cc_library:libstdcxx.olb/lib,gnu_cc_library:libgccplus.olb/lib", "LDLIBS", ",gnu_cc_library:libgcc.olb/lib", #else "CRT0", "", "CXXSTARTUP", "", "CXXRT0", "", "LXLIBS", "", "LDLIBS", "", #endif "LINK.o", "$(LD) $(LDFLAGS)", "LINK.obj", "$(LD) $(LDFLAGS)", #ifndef GCC_IS_NATIVE "CXXLINK.obj", "$(CXXLD) $(LDFLAGS)", "COMPILE.cxx", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", #endif "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", "COMPILE.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", "COMPILE.C", "$(COMPILE.cc)", "COMPILE.cpp", "$(COMPILE.cc)", "LINK.C", "$(LINK.cc)", "LINK.cpp", "$(LINK.cc)", "YACC.y", "$(YACC) $(YFLAGS)", "LEX.l", "$(LEX) $(LFLAGS)", "YACC.m", "$(YACC) $(YFLAGS)", "LEX.m", "$(LEX) $(LFLAGS) -t", "COMPILE.for", "$(FC) $(FFLAGS) $(TARGET_ARCH)", "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c", "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c", "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.pas", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)", "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)", "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.mar", "$(MACRO) $(MACROFLAGS)", "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)", "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)", "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c", "PREPROCESS.S", "$(CPP) $(CPPFLAGS)", "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F", "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F", "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", "MV", "rename/new_version", "CP", "copy", ".LIBPATTERNS", "%.olb lib%.a", #else /* !MK_OS_VMS */ "AR", "ar", #ifdef _AIX /* AIX requires object file format specification: choose -Xany. */ "ARFLAGS", "-Xany -rv", #else "ARFLAGS", "-rv", #endif "AS", "as", #ifdef GCC_IS_NATIVE "CC", "gcc", "OBJC", "gcc", #else "CC", "cc", "OBJC", "cc", #endif #ifdef MAKE_CXX "CXX", MAKE_CXX, #else # ifdef GCC_IS_NATIVE # ifdef MK_OS_DOS "CXX", "gpp", /* g++ is an invalid name on MSDOS */ # else "CXX", "gcc", # endif /* __MSDOS__ */ # else "CXX", "g++", # endif #endif /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist, and to the empty string if $@ does exist. */ "CHECKOUT,v", "+$(if $(wildcard $@),,$(CO) $(COFLAGS) $< $@)", "CO", "co", "COFLAGS", "", "CPP", "$(CC) -E", #ifdef CRAY "CF77PPFLAGS", "-P", "CF77PP", "/lib/cpp", "CFT", "cft77", "CF", "cf77", "FC", "$(CF)", #else /* Not CRAY. */ #ifdef _IBMR2 "FC", "xlf", #else #ifdef __convex__ "FC", "fc", #else "FC", "f77", #endif /* __convex__ */ #endif /* _IBMR2 */ /* System V uses these, so explicit rules using them should work. However, there is no way to make implicit rules use them and FC. */ "F77", "$(FC)", "F77FLAGS", "$(FFLAGS)", #endif /* Cray. */ "GET", SCCS_GET, "LD", "ld", #ifdef GCC_IS_NATIVE "LEX", "flex", #else "LEX", "lex", #endif "LINT", "lint", "M2C", "m2c", #ifdef pyr "PC", "pascal", #else #ifdef CRAY "PC", "PASCAL", "SEGLDR", "segldr", #else "PC", "pc", #endif /* CRAY. */ #endif /* pyr. */ #ifdef GCC_IS_NATIVE "YACC", "bison -y", #else "YACC", "yacc", /* Or "bison -y" */ #endif "MAKEINFO", "makeinfo", "TEX", "tex", "TEXI2DVI", "texi2dvi", "WEAVE", "weave", "CWEAVE", "cweave", "TANGLE", "tangle", "CTANGLE", "ctangle", "RM", "rm -f", "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", #ifndef HAVE_CASE_INSENSITIVE_FS /* On case-insensitive filesystems, treat *.C files as *.c files, to avoid erroneously compiling C sources as C++, which will probably fail. */ "COMPILE.C", "$(COMPILE.cc)", #else "COMPILE.C", "$(COMPILE.c)", #endif "COMPILE.cpp", "$(COMPILE.cc)", "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", #ifndef HAVE_CASE_INSENSITIVE_FS "LINK.C", "$(LINK.cc)", #else "LINK.C", "$(LINK.c)", #endif "LINK.cpp", "$(LINK.cc)", "YACC.y", "$(YACC) $(YFLAGS)", "LEX.l", "$(LEX) $(LFLAGS) -t", "YACC.m", "$(YACC) $(YFLAGS)", "LEX.m", "$(LEX) $(LFLAGS) -t", "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c", "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c", "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)", "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)", "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)", "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)", "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)", "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)", "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c", "PREPROCESS.S", "$(CPP) $(CPPFLAGS)", "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F", "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F", "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)", #ifndef NO_MINUS_C_MINUS_O "OUTPUT_OPTION", "-o $@", #endif #ifdef SCCS_GET_MINUS_G "SCCS_OUTPUT_OPTION", "-G$@", #endif #if MK_OS_DOS ".LIBPATTERNS", "lib%.a $(DJDIR)/lib/lib%.a", #elif defined(__APPLE__) ".LIBPATTERNS", "lib%.dylib lib%.a", #elif defined(__CYGWIN__) || MK_OS_W32 ".LIBPATTERNS", "lib%.dll.a %.dll.a lib%.a %.lib lib%.dll %.dll", #else ".LIBPATTERNS", "lib%.so lib%.a", #endif #endif /* !MK_OS_VMS */ /* Make this assignment to avoid undefined variable warnings. */ GNUMAKEFLAGS_NAME, "", 0, 0 }; /* Set up the default .SUFFIXES list. */ void set_default_suffixes (void) { suffix_file = enter_file (strcache_add (".SUFFIXES")); suffix_file->builtin = 1; if (no_builtin_rules_flag) define_variable_cname ("SUFFIXES", "", o_default, 0); else { struct dep *d; const char *p = default_suffixes; suffix_file->deps = enter_prereqs (PARSE_SIMPLE_SEQ ((char **)&p, struct dep), NULL); for (d = suffix_file->deps; d; d = d->next) d->file->builtin = 1; define_variable_cname ("SUFFIXES", default_suffixes, o_default, 0); } } /* Enter the default suffix rules as file rules. This used to be done in install_default_implicit_rules, but that loses because we want the suffix rules installed before reading makefiles, and the pattern rules installed after. */ void install_default_suffix_rules () { const char **s; if (no_builtin_rules_flag) return; for (s = default_suffix_rules; *s != 0; s += 2) { struct file *f = enter_file (strcache_add (s[0])); /* Install the default rule only if there is no user defined rule. */ if (!f->cmds) { f->cmds = xmalloc (sizeof (struct commands)); f->cmds->fileinfo.filenm = NULL; f->cmds->commands = xstrdup (s[1]); f->cmds->command_lines = NULL; f->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT; f->builtin = 1; } } } /* Install the default pattern rules. */ void install_default_implicit_rules (void) { struct pspec *p; if (no_builtin_rules_flag) return; for (p = default_pattern_rules; p->target != 0; ++p) install_pattern_rule (p, 0); for (p = default_terminal_rules; p->target != 0; ++p) install_pattern_rule (p, 1); } void define_default_variables (void) { const char **s; if (no_builtin_variables_flag) return; for (s = default_variables; *s != 0; s += 2) define_variable (s[0], strlen (s[0]), s[1], o_default, 1); } void undefine_default_variables (void) { const char **s; for (s = default_variables; *s != 0; s += 2) undefine_variable_global (NILF, s[0], strlen (s[0]), o_default); } ================================================ FILE: src/dep.h ================================================ /* Definitions of dependency data structures for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Structure used in chains of names, for parsing and globbing. */ #define NAMESEQ(_t) \ _t *next; \ const char *name struct nameseq { NAMESEQ (struct nameseq); }; /* Flag bits for the second argument to 'read_makefile'. These flags are saved in the 'flags' field of each 'struct goaldep' in the chain returned by 'read_all_makefiles'. */ #define RM_NOFLAG 0 #define RM_NO_DEFAULT_GOAL (1 << 0) /* Do not set default goal. */ #define RM_INCLUDED (1 << 1) /* Search makefile search path. */ #define RM_DONTCARE (1 << 2) /* No error if it doesn't exist. */ #define RM_NO_TILDE (1 << 3) /* Don't expand ~ in file name. */ /* Structure representing one dependency of a file. Each struct file's 'deps' points to a chain of these, through 'next'. 'stem' is the stem for this dep line of static pattern rule or NULL. explicit is set when implicit rule search is performed and the prerequisite does not contain %. When explicit is set the file is not intermediate. */ #define DEP(_t) \ NAMESEQ (_t); \ struct file *file; \ _t *shuf; \ const char *stem; \ unsigned int flags : 8; \ unsigned int changed : 1; \ unsigned int ignore_mtime : 1; \ unsigned int staticpattern : 1; \ unsigned int need_2nd_expansion : 1; \ unsigned int ignore_automatic_vars : 1; \ unsigned int is_explicit : 1; \ unsigned int wait_here : 1 struct dep { DEP (struct dep); }; /* Structure representing one goal. The goals to be built constitute a chain of these, chained through 'next'. 'stem' is not used, but it's simpler to include and ignore it. */ struct goaldep { DEP (struct goaldep); int error; floc floc; }; /* Options for parsing lists of filenames. */ #define PARSEFS_NONE 0x0000 #define PARSEFS_NOSTRIP 0x0001 #define PARSEFS_NOAR 0x0002 #define PARSEFS_NOGLOB 0x0004 #define PARSEFS_EXISTS 0x0008 #define PARSEFS_NOCACHE 0x0010 #define PARSEFS_ONEWORD 0x0020 #define PARSEFS_WAIT 0x0040 #define PARSE_FILE_SEQ(_s,_t,_c,_p,_f) \ (_t *)parse_file_seq ((_s),sizeof (_t),(_c),(_p),(_f)) #define PARSE_SIMPLE_SEQ(_s,_t) \ (_t *)parse_file_seq ((_s),sizeof (_t),MAP_NUL,NULL,PARSEFS_NONE) #if MK_OS_VMS void *parse_file_seq (); #else void *parse_file_seq (char **stringp, size_t size, int stopmap, const char *prefix, int flags); #endif char *tilde_expand (const char *name); #ifndef NO_ARCHIVES struct nameseq *ar_glob (const char *arname, const char *member_pattern, size_t size); #endif #define dep_name(d) ((d)->name ? (d)->name : (d)->file->name) #define alloc_seq_elt(_t) xcalloc (sizeof (_t)) void free_ns_chain (struct nameseq *n); #if defined(MAKE_MAINTAINER_MODE) && defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Use inline to get real type-checking. */ #define SI static inline SI struct nameseq *alloc_ns (void) { return alloc_seq_elt (struct nameseq); } SI struct dep *alloc_dep (void) { return alloc_seq_elt (struct dep); } SI struct goaldep *alloc_goaldep (void) { return alloc_seq_elt (struct goaldep); } SI void free_ns (struct nameseq *n) { free (n); } SI void free_dep (struct dep *d) { free_ns ((struct nameseq *)d); } SI void free_goaldep (struct goaldep *g) { free_dep ((struct dep *)g); } SI void free_dep_chain (struct dep *d) { free_ns_chain((struct nameseq *)d); } SI void free_goal_chain (struct goaldep *g) { free_dep_chain((struct dep *)g); } #else # define alloc_ns() alloc_seq_elt (struct nameseq) # define alloc_dep() alloc_seq_elt (struct dep) # define alloc_goaldep() alloc_seq_elt (struct goaldep) # define free_ns(_n) free (_n) # define free_dep(_d) free_ns (_d) # define free_goaldep(_g) free_dep (_g) # define free_dep_chain(_d) free_ns_chain ((struct nameseq *)(_d)) # define free_goal_chain(_g) free_ns_chain ((struct nameseq *)(_g)) #endif struct dep *copy_dep (const struct dep *d); struct dep *copy_dep_chain (const struct dep *d); struct goaldep *read_all_makefiles (const char **makefiles); void eval_buffer (char *buffer, const floc *floc); enum update_status update_goal_chain (struct goaldep *goals); ================================================ FILE: src/dir.c ================================================ /* Directory hashing for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "hash.h" #include "filedef.h" #include "dep.h" #include "debug.h" #ifdef HAVE_DIRENT_H # include # define NAMLEN(dirent) strlen((dirent)->d_name) # if MK_OS_VMS /* its prototype is in vmsdir.h, which is not needed for HAVE_DIRENT_H */ const char *vmsify (const char *name, int type); # endif #else # define dirent direct # define NAMLEN(dirent) (dirent)->d_namlen # ifdef HAVE_SYS_NDIR_H # include # endif # ifdef HAVE_SYS_DIR_H # include # endif # ifdef HAVE_NDIR_H # include # endif # ifdef HAVE_VMSDIR_H # include "vmsdir.h" # endif /* HAVE_VMSDIR_H */ #endif /* In GNU systems, defines this macro for us. */ #ifdef _D_NAMLEN # undef NAMLEN # define NAMLEN(d) _D_NAMLEN(d) #endif #if (defined (POSIX) || MK_OS_VMS || MK_OS_W32) && !defined (__GNU_LIBRARY__) /* Posix does not require that the d_ino field be present, and some systems do not provide it. */ # define REAL_DIR_ENTRY(dp) 1 # define FAKE_DIR_ENTRY(dp) #else # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) # define FAKE_DIR_ENTRY(dp) (dp->d_ino = 1) #endif /* POSIX */ #if MK_OS_DOS #include #include /* If it's MSDOS that doesn't have _USE_LFN, disable LFN support. */ #ifndef _USE_LFN #define _USE_LFN 0 #endif static const char * dosify (const char *filename) { static char dos_filename[14]; char *df; int i; if (filename == NULL || _USE_LFN) return filename; /* FIXME: what about filenames which violate 8+3 constraints, like "config.h.in", or ".emacs"? */ if (strpbrk (filename, "\"*+,;<=>?[\\]|") != NULL) return filename; df = dos_filename; /* First, transform the name part. */ for (i = 0; i < 8 && ! STOP_SET (*filename, MAP_DOT|MAP_NUL); ++i) *df++ = tolower ((unsigned char)*filename++); /* Now skip to the next dot. */ while (! STOP_SET (*filename, MAP_DOT|MAP_NUL)) ++filename; if (*filename != '\0') { *df++ = *filename++; for (i = 0; i < 3 && ! STOP_SET (*filename, MAP_DOT|MAP_NUL); ++i) *df++ = tolower ((unsigned char)*filename++); } /* Look for more dots. */ while (! STOP_SET (*filename, MAP_DOT|MAP_NUL)) ++filename; if (*filename == '.') return filename; *df = '\0'; return dos_filename; } #endif /* MK_OS_DOS */ #if MK_OS_W32 #include "pathstuff.h" #endif #ifdef HAVE_CASE_INSENSITIVE_FS static const char * downcase (const char *filename) { static PATH_VAR (new_filename); char *df; if (filename == NULL) return NULL; df = new_filename; while (*filename != '\0') { *df++ = tolower ((unsigned char)*filename); ++filename; } *df = '\0'; return new_filename; } #endif /* HAVE_CASE_INSENSITIVE_FS */ #if MK_OS_VMS static char * downcase_inplace(char *filename) { char *name; name = filename; while (*name != '\0') { *name = tolower ((unsigned char)*name); ++name; } return filename; } #ifndef _USE_STD_STAT /* VMS 8.2 fixed the VMS stat output to have unique st_dev and st_ino when _USE_STD_STAT is used on the compile line. Prior to _USE_STD_STAT support, the st_dev is a pointer to thread static memory containing the device of the last filename looked up. Todo: find out if the ino_t still needs to be faked on a directory. */ /* Define this if the older VMS_INO_T is needed */ #define VMS_INO_T 1 static int vms_hash (const char *name) { int h = 0; while (*name) { unsigned char uc = (unsigned char) *name; int g; #ifdef HAVE_CASE_INSENSITIVE_FS h = (h << 4) + (isupper (uc) ? tolower (uc) : uc); #else h = (h << 4) + uc; #endif name++; g = h & 0xf0000000; if (g) { h = h ^ (g >> 24); h = h ^ g; } } return h; } /* fake stat entry for a directory */ static int vmsstat_dir (const char *name, struct stat *st) { char *s; int h; DIR *dir; dir = opendir (name); if (dir == NULL) return -1; closedir (dir); s = strchr (name, ':'); /* find device */ if (s) { /* to keep the compiler happy we said "const char *name", now we cheat */ *s++ = '\0'; st->st_dev = (char *)vms_hash (name); h = vms_hash (s); *(s-1) = ':'; } else { st->st_dev = 0; h = vms_hash (name); } st->st_ino[0] = h & 0xff; st->st_ino[1] = h & 0xff00; st->st_ino[2] = h >> 16; return 0; } # define stat(__path, __sbuf) vmsstat_dir (__path, __sbuf) #endif /* _USE_STD_STAT */ #endif /* MK_OS_VMS */ /* Never have more than this many directories open at once. */ #define MAX_OPEN_DIRECTORIES 10 static unsigned int open_directories = 0; /* Hash table of directories. */ #ifndef DIRECTORY_BUCKETS #define DIRECTORY_BUCKETS 199 #endif struct directory_contents { dev_t dev; /* Device and inode numbers of this dir. */ #if MK_OS_W32 /* Inode means nothing on Windows32. Even file key information is * unreliable because it is random per file open and undefined for remote * filesystems. The most unique attribute I can come up with is the fully * qualified name of the directory. Beware though, this is also * unreliable. I'm open to suggestion on a better way to emulate inode. */ char *path_key; time_t ctime; time_t mtime; /* controls check for stale directory cache */ int fs_flags; /* FS_FAT, FS_NTFS, ... */ # define FS_FAT 0x1 # define FS_NTFS 0x2 # define FS_UNKNOWN 0x4 #else # if MK_OS_VMS_INO_T ino_t ino[3]; # else ino_t ino; # endif #endif /* MK_OS_W32 */ struct hash_table dirfiles; /* Files in this directory. */ unsigned long counter; /* command_count value when last read. */ DIR *dirstream; /* Stream reading this directory. */ }; static struct directory_contents * clear_directory_contents (struct directory_contents *dc) { dc->counter = 0; if (dc->dirstream) { --open_directories; closedir (dc->dirstream); dc->dirstream = NULL; } if (dc->dirfiles.ht_vec != NULL) hash_free (&dc->dirfiles, 1); return NULL; } static unsigned long directory_contents_hash_1 (const void *key_0) { const struct directory_contents *key = key_0; unsigned long hash; #if MK_OS_W32 hash = 0; ISTRING_HASH_1 (key->path_key, hash); hash ^= ((unsigned int) key->dev << 4) ^ (unsigned int) key->ctime; #else # if MK_OS_VMS_INO_T hash = (((unsigned int) key->dev << 4) ^ ((unsigned int) key->ino[0] + (unsigned int) key->ino[1] + (unsigned int) key->ino[2])); # else hash = ((unsigned int) key->dev << 4) ^ (unsigned int) key->ino; # endif #endif /* MK_OS_W32 */ return hash; } static unsigned long directory_contents_hash_2 (const void *key_0) { const struct directory_contents *key = key_0; unsigned long hash; #if MK_OS_W32 hash = 0; ISTRING_HASH_2 (key->path_key, hash); hash ^= ((unsigned int) key->dev << 4) ^ (unsigned int) ~key->ctime; #else # if MK_OS_VMS_INO_T hash = (((unsigned int) key->dev << 4) ^ ~((unsigned int) key->ino[0] + (unsigned int) key->ino[1] + (unsigned int) key->ino[2])); # else hash = ((unsigned int) key->dev << 4) ^ (unsigned int) ~key->ino; # endif #endif /* MK_OS_W32 */ return hash; } /* Sometimes it's OK to use subtraction to get this value: result = X - Y; But, if we're not sure of the type of X and Y they may be too large for an int (on a 64-bit system for example). So, use ?: instead. See Savannah bug #15534. NOTE! This macro has side-effects! */ #define MAKECMP(_x,_y) ((_x)<(_y)?-1:((_x)==(_y)?0:1)) static int directory_contents_hash_cmp (const void *xv, const void *yv) { const struct directory_contents *x = xv; const struct directory_contents *y = yv; int result; #if MK_OS_W32 ISTRING_COMPARE (x->path_key, y->path_key, result); if (result) return result; result = MAKECMP(x->ctime, y->ctime); if (result) return result; #else # if MK_OS_VMS_INO_T result = MAKECMP(x->ino[0], y->ino[0]); if (result) return result; result = MAKECMP(x->ino[1], y->ino[1]); if (result) return result; result = MAKECMP(x->ino[2], y->ino[2]); if (result) return result; # else result = MAKECMP(x->ino, y->ino); if (result) return result; # endif #endif /* MK_OS_W32 */ return MAKECMP(x->dev, y->dev); } /* Table of directory contents hashed by device and inode number. */ static struct hash_table directory_contents; struct directory { const char *name; /* Name of the directory. */ unsigned long counter; /* command_count value when last read. Used for non-existent directories. */ /* The directory's contents. This data may be shared by several entries in the hash table, which refer to the same directory (identified uniquely by 'dev' and 'ino') under different names. */ struct directory_contents *contents; }; static unsigned long directory_hash_1 (const void *key) { return_ISTRING_HASH_1 (((const struct directory *) key)->name); } static unsigned long directory_hash_2 (const void *key) { return_ISTRING_HASH_2 (((const struct directory *) key)->name); } static int directory_hash_cmp (const void *x, const void *y) { return_ISTRING_COMPARE (((const struct directory *) x)->name, ((const struct directory *) y)->name); } /* Table of directories hashed by name. */ static struct hash_table directories; /* Hash table of files in each directory. */ struct dirfile { const char *name; /* Name of the file. */ size_t length; short impossible; /* This file is impossible. */ unsigned char type; }; static unsigned long dirfile_hash_1 (const void *key) { return_ISTRING_HASH_1 (((struct dirfile const *) key)->name); } static unsigned long dirfile_hash_2 (const void *key) { return_ISTRING_HASH_2 (((struct dirfile const *) key)->name); } static int dirfile_hash_cmp (const void *xv, const void *yv) { const struct dirfile *x = xv; const struct dirfile *y = yv; int result = (int) (x->length - y->length); if (result) return result; return_ISTRING_COMPARE (x->name, y->name); } #ifndef DIRFILE_BUCKETS #define DIRFILE_BUCKETS 107 #endif static int dir_contents_file_exists_p (struct directory *dir, const char *filename); static struct directory *find_directory (const char *name); /* Find the directory named NAME and return its 'struct directory'. */ static struct directory * find_directory (const char *name) { struct directory *dir; struct directory **dir_slot; struct directory dir_key; struct directory_contents *dc; struct directory_contents **dc_slot; struct directory_contents dc_key; struct stat st; int r; #if MK_OS_W32 char *w32_path; #endif dir_key.name = name; dir_slot = (struct directory **) hash_find_slot (&directories, &dir_key); dir = *dir_slot; if (!HASH_VACANT (dir)) { unsigned long ctr = dir->contents ? dir->contents->counter : dir->counter; /* No commands have run since we parsed this directory so it's good. */ if (ctr == command_count) return dir; DB (DB_VERBOSE, ("Directory %s cache invalidated (count %lu != command %lu)\n", name, ctr, command_count)); if (dir->contents) clear_directory_contents (dir->contents); } else { /* The directory was not found. Create a new entry for it. */ size_t len = strlen (name); dir = xmalloc (sizeof (struct directory)); #if defined(HAVE_CASE_INSENSITIVE_FS) && MK_OS_VMS /* Todo: Why is this only needed on VMS? */ { char *lname = downcase_inplace (xstrdup (name)); dir->name = strcache_add_len (lname, len); free (lname); } #else dir->name = strcache_add_len (name, len); #endif hash_insert_at (&directories, dir, dir_slot); } dir->contents = NULL; dir->counter = command_count; /* See if the directory exists. */ #if MK_OS_W32 { char tem[MAX_PATH+1], *tstart, *tend; size_t len = strlen (name); /* Remove any trailing slashes. Windows32 stat fails even on valid directories if they end in a slash. */ memcpy (tem, name, len + 1); tstart = tem; if (tstart[1] == ':') tstart += 2; for (tend = tem + (len - 1); tend > tstart && ISDIRSEP (*tend); tend--) *tend = '\0'; r = stat (tem, &st); } #else EINTRLOOP (r, stat (name, &st)); #endif if (r < 0) /* Couldn't stat the directory; nothing else to do. */ return dir; /* Search the contents hash table; device and inode are the key. */ memset (&dc_key, '\0', sizeof (dc_key)); dc_key.dev = st.st_dev; #if MK_OS_W32 dc_key.path_key = w32_path = w32ify (name, 1); dc_key.ctime = st.st_ctime; #else # if MK_OS_VMS_INO_T dc_key.ino[0] = st.st_ino[0]; dc_key.ino[1] = st.st_ino[1]; dc_key.ino[2] = st.st_ino[2]; # else dc_key.ino = st.st_ino; # endif #endif dc_slot = (struct directory_contents **) hash_find_slot (&directory_contents, &dc_key); dc = *dc_slot; if (HASH_VACANT (dc)) { /* Nope; this really is a directory we haven't seen before. */ #if MK_OS_W32 char fs_label[BUFSIZ]; char fs_type[BUFSIZ]; unsigned long fs_serno; unsigned long fs_flags; unsigned long fs_len; #endif /* Enter it in the contents hash table. */ dc = xcalloc (sizeof (struct directory_contents)); *dc = dc_key; #if MK_OS_W32 dc->path_key = xstrdup (w32_path); dc->mtime = st.st_mtime; /* NTFS is the only Windows32 filesystem that bumps mtime on a directory when files are added/deleted from a directory. */ w32_path[3] = '\0'; if (GetVolumeInformation (w32_path, fs_label, sizeof (fs_label), &fs_serno, &fs_len, &fs_flags, fs_type, sizeof (fs_type)) == FALSE) dc->fs_flags = FS_UNKNOWN; else if (!strcmp (fs_type, "FAT")) dc->fs_flags = FS_FAT; else if (!strcmp (fs_type, "NTFS")) dc->fs_flags = FS_NTFS; else dc->fs_flags = FS_UNKNOWN; #endif /* MK_OS_W32 */ hash_insert_at (&directory_contents, dc, dc_slot); } /* Point the name-hashed entry for DIR at its contents data. */ dir->contents = dc; /* If the contents have changed, we need to reseed. */ if (dc->counter != command_count) { if (dc->counter) clear_directory_contents (dc); dc->counter = command_count; ENULLLOOP (dc->dirstream, opendir (name)); if (dc->dirstream == NULL) /* Couldn't open the directory: mark this by setting files to NULL. */ dc->dirfiles.ht_vec = NULL; else { hash_init (&dc->dirfiles, DIRFILE_BUCKETS, dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp); /* Keep track of how many directories are open. */ ++open_directories; if (open_directories == MAX_OPEN_DIRECTORIES) /* We have too many directories open already. Read the entire directory and then close it. */ dir_contents_file_exists_p (dir, NULL); } } return dir; } /* Return 1 if the name FILENAME is entered in DIR's hash table. FILENAME must contain no slashes. */ static int dir_contents_file_exists_p (struct directory *dir, const char *filename) { struct dirfile *df; struct dirent *d; struct directory_contents *dc = dir->contents; #if MK_OS_W32 struct stat st; int rehash = 0; #endif if (dc == NULL || dc->dirfiles.ht_vec == NULL) /* The directory could not be stat'd or opened. */ return 0; #if MK_OS_DOS filename = dosify (filename); #endif #ifdef HAVE_CASE_INSENSITIVE_FS filename = downcase (filename); #endif #if MK_OS_OS2 if (filename != NULL) { size_t len = strlen (filename); char *fname = alloca (len + 1); memcpy (fname, filename, len + 1); _fnlwr (fname); /* lower case for FAT drives */ filename = fname; } #endif if (filename != NULL) { struct dirfile dirfile_key; if (*filename == '\0') { /* Checking if the directory exists. */ return 1; } dirfile_key.name = filename; dirfile_key.length = strlen (filename); df = hash_find_item (&dc->dirfiles, &dirfile_key); if (df) return !df->impossible; } /* The file was not found in the hashed list. Try to read the directory further. */ if (dc->dirstream == NULL) { #if MK_OS_W32 /* * Check to see if directory has changed since last read. FAT * filesystems force a rehash always as mtime does not change * on directories (ugh!). */ if (dc->path_key) { if ((dc->fs_flags & FS_FAT) != 0) { dc->mtime = time (NULL); rehash = 1; } else if (stat (dc->path_key, &st) == 0 && st.st_mtime > dc->mtime) { /* reset date stamp to show most recent re-process. */ dc->mtime = st.st_mtime; rehash = 1; } /* If it has been already read in, all done. */ if (!rehash) return 0; /* make sure directory can still be opened; if not return. */ dc->dirstream = opendir (dc->path_key); if (!dc->dirstream) return 0; } else #endif /* The directory has been all read in. */ return 0; } while (1) { /* Enter the file in the hash table. */ size_t len; struct dirfile dirfile_key; struct dirfile **dirfile_slot; ENULLLOOP (d, readdir (dc->dirstream)); if (d == NULL) { if (errno) OSS (fatal, NILF, "readdir %s: %s", dir->name, strerror (errno)); break; } #if MK_OS_VMS && defined(HAVE_DIRENT_H) /* In VMS we get file versions too, which have to be stripped off. Some versions of VMS return versions on Unix files even when the feature option to strip them is set. */ { char *p = strrchr (d->d_name, ';'); if (p) *p = '\0'; } #endif if (!REAL_DIR_ENTRY (d)) continue; len = NAMLEN (d); dirfile_key.name = d->d_name; dirfile_key.length = len; dirfile_slot = (struct dirfile **) hash_find_slot (&dc->dirfiles, &dirfile_key); #if MK_OS_W32 /* * If re-reading a directory, don't cache files that have * already been discovered. */ if (! rehash || HASH_VACANT (*dirfile_slot)) #endif { df = xmalloc (sizeof (struct dirfile)); #if MK_OS_VMS && defined(HAVE_CASE_INSENSITIVE_FS) /* TODO: Why is this only needed on VMS? */ df->name = strcache_add_len (downcase_inplace (d->d_name), len); #else df->name = strcache_add_len (d->d_name, len); #endif #ifdef HAVE_STRUCT_DIRENT_D_TYPE df->type = d->d_type; #endif df->length = len; df->impossible = 0; hash_insert_at (&dc->dirfiles, df, dirfile_slot); } /* Check if the name matches the one we're searching for. */ if (filename != NULL && patheq (d->d_name, filename)) return 1; } /* If the directory has been completely read in, close the stream and reset the pointer to nil. */ if (d == NULL) { --open_directories; closedir (dc->dirstream); dc->dirstream = NULL; } return 0; } /* Return 1 if the name FILENAME in directory DIRNAME is entered in the dir hash table. FILENAME must contain no slashes. */ int dir_file_exists_p (const char *dirname, const char *filename) { #if MK_OS_VMS if (filename && dirname && strpbrk (dirname, ":<[") != NULL) filename = vmsify (filename, 0); #endif return dir_contents_file_exists_p (find_directory (dirname), filename); } /* Return 1 if the file named NAME exists. */ int file_exists_p (const char *name) { const char *dirend; const char *dirname; const char *slash; #ifndef NO_ARCHIVES if (ar_name (name)) return ar_member_date (name) != (time_t) -1; #endif dirend = strrchr (name, '/'); #if MK_OS_VMS if (dirend == NULL) { dirend = strrchr (name, ']'); dirend == NULL ? dirend : dirend++; } if (dirend == NULL) { dirend = strrchr (name, '>'); dirend == NULL ? dirend : dirend++; } if (dirend == NULL) { dirend = strrchr (name, ':'); dirend == NULL ? dirend : dirend++; } #endif /* MK_OS_VMS */ #ifdef HAVE_DOS_PATHS /* Forward and backslashes might be mixed. We need the rightmost one. */ { const char *bslash = strrchr (name, '\\'); if (!dirend || bslash > dirend) dirend = bslash; /* The case of "d:file". */ if (!dirend && name[0] && name[1] == ':') dirend = name + 1; } #endif /* HAVE_DOS_PATHS */ if (dirend == NULL) return dir_file_exists_p (".", name); slash = dirend; if (dirend == name) dirname = "/"; else { char *p; #ifdef HAVE_DOS_PATHS /* d:/ and d: are *very* different... */ if (dirend < name + 3 && name[1] == ':' && (ISDIRSEP (*dirend) || *dirend == ':')) dirend++; #endif p = alloca (dirend - name + 1); memcpy (p, name, dirend - name); p[dirend - name] = '\0'; dirname = p; } #if MK_OS_VMS if (*slash == '/') slash++; #else slash++; #endif return dir_file_exists_p (dirname, slash); } /* Mark FILENAME as 'impossible' for 'file_impossible_p'. This means an attempt has been made to search for FILENAME as an intermediate file, and it has failed. */ void file_impossible (const char *filename) { const char *dirend; const char *p = filename; struct directory *dir; struct dirfile *new; dirend = strrchr (p, '/'); #if MK_OS_VMS if (dirend == NULL) { dirend = strrchr (p, ']'); dirend == NULL ? dirend : dirend++; } if (dirend == NULL) { dirend = strrchr (p, '>'); dirend == NULL ? dirend : dirend++; } if (dirend == NULL) { dirend = strrchr (p, ':'); dirend == NULL ? dirend : dirend++; } #endif #ifdef HAVE_DOS_PATHS /* Forward and backslashes might be mixed. We need the rightmost one. */ { const char *bslash = strrchr (p, '\\'); if (!dirend || bslash > dirend) dirend = bslash; /* The case of "d:file". */ if (!dirend && p[0] && p[1] == ':') dirend = p + 1; } #endif /* HAVE_DOS_PATHS */ if (dirend == NULL) dir = find_directory ("."); else { const char *dirname; const char *slash = dirend; if (dirend == p) dirname = "/"; else { char *cp; #ifdef HAVE_DOS_PATHS /* d:/ and d: are *very* different... */ if (dirend < p + 3 && p[1] == ':' && (ISDIRSEP (*dirend) || *dirend == ':')) dirend++; #endif cp = alloca (dirend - p + 1); memcpy (cp, p, dirend - p); cp[dirend - p] = '\0'; dirname = cp; } dir = find_directory (dirname); #if MK_OS_VMS if (*slash == '/') filename = p = slash + 1; else filename = p = slash; #else filename = p = slash + 1; #endif } if (dir->contents == NULL) /* The directory could not be stat'd. We allocate a contents structure for it, but leave it out of the contents hash table. */ dir->contents = xcalloc (sizeof (struct directory_contents)); if (dir->contents->dirfiles.ht_vec == NULL) hash_init (&dir->contents->dirfiles, DIRFILE_BUCKETS, dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp); /* Make a new entry and put it in the table. */ new = xmalloc (sizeof (struct dirfile)); new->length = strlen (filename); #if defined(HAVE_CASE_INSENSITIVE_FS) && MK_OS_VMS /* todo: Why is this only needed on VMS? */ new->name = strcache_add_len (downcase (filename), new->length); #else new->name = strcache_add_len (filename, new->length); #endif new->impossible = 1; hash_insert (&dir->contents->dirfiles, new); } /* Return nonzero if FILENAME has been marked impossible. */ int file_impossible_p (const char *filename) { const char *dirend; struct directory_contents *dir; struct dirfile *dirfile; struct dirfile dirfile_key; #if MK_OS_VMS int want_vmsify = 0; #endif dirend = strrchr (filename, '/'); #if MK_OS_VMS if (dirend == NULL) { want_vmsify = (strpbrk (filename, "]>:^") != NULL); dirend = strrchr (filename, ']'); } if (dirend == NULL && want_vmsify) dirend = strrchr (filename, '>'); if (dirend == NULL && want_vmsify) dirend = strrchr (filename, ':'); #endif #ifdef HAVE_DOS_PATHS /* Forward and backslashes might be mixed. We need the rightmost one. */ { const char *bslash = strrchr (filename, '\\'); if (!dirend || bslash > dirend) dirend = bslash; /* The case of "d:file". */ if (!dirend && filename[0] && filename[1] == ':') dirend = filename + 1; } #endif /* HAVE_DOS_PATHS */ if (dirend == NULL) dir = find_directory (".")->contents; else { const char *dirname; const char *slash = dirend; if (dirend == filename) dirname = "/"; else { char *cp; #ifdef HAVE_DOS_PATHS /* d:/ and d: are *very* different... */ if (dirend < filename + 3 && filename[1] == ':' && (ISDIRSEP (*dirend) || *dirend == ':')) dirend++; #endif cp = alloca (dirend - filename + 1); memcpy (cp, filename, dirend - filename); cp[dirend - filename] = '\0'; dirname = cp; } dir = find_directory (dirname)->contents; #if MK_OS_VMS if (*slash == '/') filename = slash + 1; else filename = slash; #else filename = slash + 1; #endif } if (dir == NULL || dir->dirfiles.ht_vec == NULL) /* There are no files entered for this directory. */ return 0; #if MK_OS_DOS filename = dosify (filename); #endif #ifdef HAVE_CASE_INSENSITIVE_FS filename = downcase (filename); #endif #if MK_OS_VMS if (want_vmsify) filename = vmsify (filename, 1); #endif dirfile_key.name = filename; dirfile_key.length = strlen (filename); dirfile = hash_find_item (&dir->dirfiles, &dirfile_key); if (dirfile) return dirfile->impossible; return 0; } /* Return the already allocated name in the directory hash table that matches DIR. */ const char * dir_name (const char *dir) { return find_directory (dir)->name; } /* Print the data base of directories. */ void print_dir_data_base (void) { unsigned int files; unsigned int impossible; struct directory **dir_slot; struct directory **dir_end; #if MK_OS_W32 char buf[INTSTR_LENGTH + 1]; #endif puts (_("\n# Directories\n")); files = impossible = 0; dir_slot = (struct directory **) directories.ht_vec; dir_end = dir_slot + directories.ht_size; for ( ; dir_slot < dir_end; dir_slot++) { struct directory *dir = *dir_slot; if (! HASH_VACANT (dir)) { if (dir->contents == NULL) printf (_("# %s: could not be stat'd.\n"), dir->name); else if (dir->contents->dirfiles.ht_vec == NULL) #if MK_OS_W32 printf (_("# %s (key %s, mtime %s): could not be opened.\n"), dir->name, dir->contents->path_key, make_ulltoa ((unsigned long long)dir->contents->mtime, buf)); #elif defined(VMS_INO_T) printf (_("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n"), dir->name, dir->contents->dev, dir->contents->ino[0], dir->contents->ino[1], dir->contents->ino[2]); #else printf (_("# %s (device %ld, inode %ld): could not be opened.\n"), dir->name, (long) dir->contents->dev, (long) dir->contents->ino); #endif else { unsigned int f = 0; unsigned int im = 0; struct dirfile **files_slot; struct dirfile **files_end; files_slot = (struct dirfile **) dir->contents->dirfiles.ht_vec; files_end = files_slot + dir->contents->dirfiles.ht_size; for ( ; files_slot < files_end; files_slot++) { struct dirfile *df = *files_slot; if (! HASH_VACANT (df)) { if (df->impossible) ++im; else ++f; } } #if MK_OS_W32 printf (_("# %s (key %s, mtime %s): "), dir->name, dir->contents->path_key, make_ulltoa ((unsigned long long)dir->contents->mtime, buf)); #elif defined(VMS_INO_T) printf (_("# %s (device %d, inode [%d,%d,%d]): "), dir->name, dir->contents->dev, dir->contents->ino[0], dir->contents->ino[1], dir->contents->ino[2]); #else printf (_("# %s (device %ld, inode %ld): "), dir->name, (long)dir->contents->dev, (long)dir->contents->ino); #endif if (f == 0) fputs (_("No"), stdout); else printf ("%u", f); fputs (_(" files, "), stdout); if (im == 0) fputs (_("no"), stdout); else printf ("%u", im); fputs (_(" impossibilities"), stdout); if (dir->contents->dirstream == NULL) puts ("."); else puts (_(" so far.")); files += f; impossible += im; } } } fputs ("\n# ", stdout); if (files == 0) fputs (_("No"), stdout); else printf ("%u", files); fputs (_(" files, "), stdout); if (impossible == 0) fputs (_("no"), stdout); else printf ("%u", impossible); printf (_(" impossibilities in %lu directories.\n"), directories.ht_fill); } /* Hooks for globbing. */ /* Structure describing state of iterating through a directory hash table. */ struct dirstream { struct directory_contents *contents; /* The directory being read. */ struct dirfile **dirfile_slot; /* Current slot in table. */ }; /* Forward declarations. */ static void *open_dirstream (const char *); static struct dirent *read_dirstream (void *); static void * open_dirstream (const char *directory) { struct dirstream *new; struct directory *dir = find_directory (directory); if (dir->contents == NULL || dir->contents->dirfiles.ht_vec == NULL) /* DIR->contents is nil if the directory could not be stat'd. DIR->contents->dirfiles is nil if it could not be opened. */ return NULL; /* Read all the contents of the directory now. There is no benefit in being lazy, since glob will want to see every file anyway. */ dir_contents_file_exists_p (dir, NULL); new = xmalloc (sizeof (struct dirstream)); new->contents = dir->contents; new->dirfile_slot = (struct dirfile **) new->contents->dirfiles.ht_vec; return new; } static struct dirent * read_dirstream (void *stream) { static char *buf; static size_t bufsz; struct dirstream *const ds = (struct dirstream *) stream; struct directory_contents *dc = ds->contents; struct dirfile **dirfile_end = (struct dirfile **) dc->dirfiles.ht_vec + dc->dirfiles.ht_size; while (ds->dirfile_slot < dirfile_end) { struct dirfile *df = *ds->dirfile_slot++; if (! HASH_VACANT (df) && !df->impossible) { /* The glob interface wants a 'struct dirent', so mock one up. */ struct dirent *d; size_t len = df->length + 1; size_t sz = sizeof (*d) - sizeof (d->d_name) + len; if (sz > bufsz) { bufsz *= 2; if (sz > bufsz) bufsz = sz; buf = xrealloc (buf, bufsz); } d = (struct dirent *) buf; #ifdef __MINGW32__ # if __MINGW32_MAJOR_VERSION < 3 || (__MINGW32_MAJOR_VERSION == 3 && \ __MINGW32_MINOR_VERSION == 0) d->d_name = xmalloc (len); # endif #endif FAKE_DIR_ENTRY (d); #ifdef _DIRENT_HAVE_D_NAMLEN d->d_namlen = len - 1; #endif #ifdef HAVE_STRUCT_DIRENT_D_TYPE d->d_type = df->type; #endif memcpy (d->d_name, df->name, len); return d; } } return NULL; } /* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a * macro for stat64(). If stat is a macro, make a local wrapper function to * invoke it. * * On MS-Windows, stat() "succeeds" for foo/bar/. where foo/bar is a * regular file; fix that here. */ #if !defined(stat) && !MK_OS_W32 || MK_OS_VMS # if !MK_OS_VMS # ifndef HAVE_SYS_STAT_H int stat (const char *path, struct stat *sbuf); # endif # else /* We are done with the fake stat. Go back to the real stat */ # ifdef stat # undef stat # endif # endif # define local_stat stat #else static int local_stat (const char *path, struct stat *buf) { int e; #if MK_OS_W32 size_t plen = strlen (path); /* Make sure the parent of "." exists and is a directory, not a file. This is because 'stat' on Windows normalizes the argument foo/. => foo without checking first that foo is a directory. */ if (plen > 2 && path[plen - 1] == '.' && ISDIRSEP (path[plen - 2])) { char parent[MAX_PATH+1]; strncpy (parent, path, MAX_PATH); parent[MIN(plen - 2, MAX_PATH)] = '\0'; if (stat (parent, buf) < 0 || !_S_ISDIR (buf->st_mode)) return -1; } #endif EINTRLOOP (e, stat (path, buf)); return e; } #endif /* Similarly for lstat. */ #if !defined(lstat) && !MK_OS_W32 || MK_OS_VMS # if !MK_OS_VMS # ifndef HAVE_SYS_STAT_H int lstat (const char *path, struct stat *sbuf); # endif # else /* We are done with the fake lstat. Go back to the real lstat */ # ifdef lstat # undef lstat # endif # endif # define local_lstat lstat #elif MK_OS_W32 /* Windows doesn't support lstat(). */ # define local_lstat local_stat #else static int local_lstat (const char *path, struct stat *buf) { int e; EINTRLOOP (e, lstat (path, buf)); return e; } #endif void dir_setup_glob (glob_t *gl) { gl->gl_offs = 0; gl->gl_opendir = open_dirstream; gl->gl_readdir = read_dirstream; gl->gl_closedir = free; gl->gl_lstat = local_lstat; gl->gl_stat = local_stat; } void hash_init_directories (void) { hash_init (&directories, DIRECTORY_BUCKETS, directory_hash_1, directory_hash_2, directory_hash_cmp); hash_init (&directory_contents, DIRECTORY_BUCKETS, directory_contents_hash_1, directory_contents_hash_2, directory_contents_hash_cmp); } ================================================ FILE: src/expand.c ================================================ /* Variable expansion functions for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include "commands.h" #include "debug.h" #include "filedef.h" #include "job.h" #include "variable.h" #include "rule.h" #include "warning.h" /* Initially, any errors reported when expanding strings will be reported against the file where the error appears. */ const floc **expanding_var = &reading_file; /* The next two describe the variable output buffer. This buffer is used to hold the variable-expansion of a line of the makefile. It is made bigger with realloc whenever it is too small. variable_buffer_length is the size currently allocated. variable_buffer is the address of the buffer. For efficiency, it's guaranteed that the buffer will always have VARIABLE_BUFFER_ZONE extra bytes allocated. This allows you to add a few extra chars without having to call a function. Note you should never use these bytes unless you're _sure_ you have room (you know when the buffer length was last checked. */ #define VARIABLE_BUFFER_ZONE 5 static size_t variable_buffer_length; char *variable_buffer; /* Append LENGTH chars of STRING at PTR which must point into variable_buffer. The buffer will always be kept nul-terminated. The updated pointer into the buffer is returned as the value. Thus, the value returned by each call to variable_buffer_output should be the first argument to the following call. */ char * variable_buffer_output (char *ptr, const char *string, size_t length) { size_t newlen = length + (ptr - variable_buffer); assert (ptr >= variable_buffer); assert (ptr < variable_buffer + variable_buffer_length); if (newlen + VARIABLE_BUFFER_ZONE + 1 > variable_buffer_length) { size_t offset = ptr - variable_buffer; variable_buffer_length = (newlen + 100 > 2 * variable_buffer_length ? newlen + 100 : 2 * variable_buffer_length); variable_buffer = xrealloc (variable_buffer, variable_buffer_length + 1); ptr = variable_buffer + offset; } ptr = mempcpy (ptr, string, length); *ptr = '\0'; return ptr; } /* Return a pointer to the beginning of the variable buffer. This is called from main() and it should never be null afterward. */ char * initialize_variable_output () { /* If we don't have a variable output buffer yet, get one. */ if (!variable_buffer) { variable_buffer_length = 200; variable_buffer = xmalloc (variable_buffer_length); } variable_buffer[0] = '\0'; return variable_buffer; } /* Install a new variable_buffer context, returning the current one for safe-keeping. */ void install_variable_buffer (char **bufp, size_t *lenp) { *bufp = variable_buffer; *lenp = variable_buffer_length; variable_buffer = NULL; initialize_variable_output (); } /* Free the current variable_buffer and restore a previously-saved one. */ void restore_variable_buffer (char *buf, size_t len) { free (variable_buffer); variable_buffer = buf; variable_buffer_length = len; } /* Restore a previously-saved variable_buffer context, and return the current one. */ char * swap_variable_buffer (char *buf, size_t len) { char *p = variable_buffer; variable_buffer = buf; variable_buffer_length = len; return p; } /* Recursively expand V. The returned string is malloc'd. */ static char *allocated_variable_append (const struct variable *v); char * recursively_expand_for_file (struct variable *v, struct file *file) { char *value; const floc *this_var; const floc **saved_varp; struct variable_set_list *savev = 0; int set_reading = 0; size_t nl = strlen (v->name); struct variable *parent = NULL; /* If we're expanding to put into the environment of a shell function then ignore any recursion issues: for backward-compatibility we will use the value of the environment variable we were started with. */ if (v->expanding && env_recursion) { char **ep; DB (DB_VERBOSE, (_("%s:%lu: not recursively expanding %s to export to shell function\n"), v->fileinfo.filenm, v->fileinfo.lineno, v->name)); /* We could create a hash for the original environment for speed, but a reasonably written makefile shouldn't hit this situation... */ for (ep = environ; *ep != 0; ++ep) if (strncmp (*ep, v->name, nl) == 0 && (*ep)[nl] == '=') return xstrdup ((*ep) + nl + 1); /* If there's nothing in the parent environment, use the empty string. This isn't quite correct since the variable should not exist at all, but getting that to work would be involved. */ return xstrdup (""); } /* Don't install a new location if this location is empty. This can happen for command-line variables, builtin variables, etc. */ saved_varp = expanding_var; if (v->fileinfo.filenm) { this_var = &v->fileinfo; expanding_var = &this_var; } /* If we have no other file-reading context, use the variable's context. */ if (!reading_file) { set_reading = 1; reading_file = &v->fileinfo; } if (v->expanding) { if (!v->exp_count) /* Expanding V causes infinite recursion. Lose. */ OS (fatal, *expanding_var, _("recursive variable '%s' references itself (eventually)"), v->name); --v->exp_count; } if (file) install_file_context (file, &savev, NULL); v->expanding = 1; if (v->append) { /* Find a parent definition which is marked override. */ struct variable_set_list *sl; for (sl = current_variable_set_list; sl && !parent; sl = sl->next) { struct variable *vp = lookup_variable_in_set (v->name, nl, sl->set); if (vp && vp != v && vp->origin == o_override) parent = vp; } } if (parent) /* PARENT is an override, V is appending. If V is also an override: override hello := first al%: override hello += second Then construct the value from its appended parts in the parent sets. Else if V is not an override: override hello := first al%: hello += second Then ignore the value of V and use the value of PARENT. */ value = v->origin == o_override ? allocated_variable_append (v) : xstrdup (parent->value); else if (v->origin == o_command || v->origin == o_env_override) /* Avoid appending to a pattern-specific variable, unless the origin of this pattern-specific variable beats or equals the origin of one of the parent definitions of this variable. This is needed, because if there is a command line definition or an env override, then the value defined in the makefile should only be appended in the case of a file override. In the presence of command line definition or env override and absence of makefile override, the value should be expanded, rather than appended. In this case, at parse time record_target_var already set the value of this pattern-specific variable to the value defined on the command line or to the env override value. User provided a command line definition or an env override. PARENT does not have an override directive, so ignore it. */ value = allocated_expand_string (v->value); else if (v->append) /* Construct the value from its appended parts in the parent sets. */ value = allocated_variable_append (v); else /* A definition without appending. */ value = allocated_expand_string (v->value); v->expanding = 0; if (set_reading) reading_file = 0; if (file) restore_file_context (savev, NULL); expanding_var = saved_varp; return value; } /* Expand a simple reference to variable NAME, which is LENGTH chars long. The result is written to PTR which must point into the variable_buffer. Returns a pointer to the new end of the variable_buffer. */ char * expand_variable_output (char *ptr, const char *name, size_t length) { struct variable *v; unsigned int recursive; char *value; v = lookup_variable (name, length); if (!v) warn_undefined (name, length); /* If there's no variable by that name or it has no value, stop now. */ if (!v || (v->value[0] == '\0' && !v->append)) return ptr; /* Remember this since expansion could change it. */ recursive = v->recursive; value = recursive ? recursively_expand (v) : v->value; ptr = variable_buffer_output (ptr, value, strlen (value)); if (recursive) free (value); return ptr; } /* Expand a simple reference to variable NAME, which is LENGTH chars long. The result is written to BUF which must point into the variable_buffer. If BUF is NULL, start at the beginning of the current variable_buffer. Returns a pointer to the START of the expanded value of the variable. The returned value is located inside variable_buffer. The returned value is valid until the next call to one of the functions which use variable_buffer. expand_variable_buf may reallocate variable_buffer and render the passed-in BUF invalid. */ char * expand_variable_buf (char *buf, const char *name, size_t length) { size_t offs; if (!buf) buf = initialize_variable_output (); assert (buf >= variable_buffer); assert (buf < variable_buffer + variable_buffer_length); offs = buf - variable_buffer; expand_variable_output (buf, name, length); return variable_buffer + offs; } /* Expand a simple reference to variable NAME, which is LENGTH chars long. Returns an allocated buffer containing the value. */ char * allocated_expand_variable (const char *name, size_t length) { char *obuf; size_t olen; install_variable_buffer (&obuf, &olen); expand_variable_output (variable_buffer, name, length); return swap_variable_buffer (obuf, olen); } /* Expand a simple reference to variable NAME, which is LENGTH chars long. Error messages refer to the file and line where FILE's commands were found. Expansion uses FILE's variable set list. Returns an allocated buffer containing the value. */ char * allocated_expand_variable_for_file (const char *name, size_t length, struct file *file) { char *result; struct variable_set_list *savev; const floc *savef; if (!file) return allocated_expand_variable (name, length); install_file_context (file, &savev, &savef); result = allocated_expand_variable (name, length); restore_file_context (savev, savef); return result; } /* Scan STRING for variable references and expansion-function calls. Only LENGTH bytes of STRING are actually scanned. If LENGTH is SIZE_MAX, scan until a null byte is found. Write the results to BUF, which must point into variable_buffer. If BUF is NULL, start at the beginning of the current variable_buffer. Return a pointer to BUF, or to the beginning of the new buffer if BUF is NULL. */ char * expand_string_buf (char *buf, const char *string, size_t length) { struct variable *v; const char *p, *p1; char *save; char *o; size_t line_offset; if (!buf) buf = initialize_variable_output (); o = buf; line_offset = buf - variable_buffer; if (length == 0) return variable_buffer; /* We need a copy of STRING: due to eval, it's possible that it will get freed as we process it (it might be the value of a variable that's reset for example). Also having a nil-terminated string is handy. */ save = length == SIZE_MAX ? xstrdup (string) : xstrndup (string, length); p = save; while (1) { /* Copy all following uninteresting chars all at once to the variable output buffer, and skip them. Uninteresting chars end at the next $ or the end of the input. */ p1 = strchr (p, '$'); o = variable_buffer_output (o, p, p1 != 0 ? (size_t) (p1 - p) : strlen (p) + 1); if (p1 == 0) break; p = p1 + 1; /* Dispatch on the char that follows the $. */ switch (*p) { case '$': case '\0': /* $$ or $ at the end of the string means output one $ to the variable output buffer. */ o = variable_buffer_output (o, p1, 1); break; case '(': case '{': /* $(...) or ${...} is the general case of substitution. */ { char openparen = *p; char closeparen = (openparen == '(') ? ')' : '}'; const char *beg = p + 1; char *abeg = NULL; const char *end, *colon; if (handle_function (&o, &p)) break; /* Is there a variable reference inside the parens or braces? If so, expand it before expanding the entire reference. */ end = strchr (beg, closeparen); if (end == NULL) /* Unterminated variable reference. */ O (fatal, *expanding_var, _("unterminated variable reference")); p1 = lindex (beg, end, '$'); if (p1 != NULL) { /* BEG now points past the opening paren or brace. Count parens or braces until it is matched. */ int count = 1; for (p = beg; *p != '\0'; ++p) { if (*p == openparen) ++count; else if (*p == closeparen && --count == 0) break; } /* If COUNT is > 0, there were unmatched opening parens or braces, so we go to the simple case of a variable name such as '$($(a)'. */ if (count == 0) { /* Expand the name. */ abeg = expand_argument (beg, p); beg = abeg; end = strchr (beg, '\0'); } } else /* Advance P to the end of this reference. After we are finished expanding this one, P will be incremented to continue the scan. */ p = end; /* This is not a reference to a built-in function and any variable references inside are now expanded. Is the resultant text a substitution reference? */ colon = lindex (beg, end, ':'); if (colon) { /* This looks like a substitution reference: $(FOO:A=B). */ const char *subst_beg = colon + 1; const char *subst_end = lindex (subst_beg, end, '='); if (subst_end == 0) /* There is no = in sight. Punt on the substitution reference and treat this as a variable name containing a colon, in the code below. */ colon = 0; else { const char *replace_beg = subst_end + 1; const char *replace_end = end; /* Extract the variable name before the colon and look up that variable. */ v = lookup_variable (beg, colon - beg); if (v == 0) warn_undefined (beg, colon - beg); /* If the variable is not empty, perform the substitution. */ if (v != 0 && *v->value != '\0') { char *pattern, *replace, *ppercent, *rpercent; char *value = (v->recursive ? recursively_expand (v) : v->value); /* Copy the pattern and the replacement. Add in an extra % at the beginning to use in case there isn't one in the pattern. */ pattern = alloca (subst_end - subst_beg + 2); *(pattern++) = '%'; memcpy (pattern, subst_beg, subst_end - subst_beg); pattern[subst_end - subst_beg] = '\0'; replace = alloca (replace_end - replace_beg + 2); *(replace++) = '%'; memcpy (replace, replace_beg, replace_end - replace_beg); replace[replace_end - replace_beg] = '\0'; /* Look for %. Set the percent pointers properly based on whether we find one or not. */ ppercent = find_percent (pattern); if (ppercent) { ++ppercent; rpercent = find_percent (replace); if (rpercent) ++rpercent; } else { ppercent = pattern; rpercent = replace; --pattern; --replace; } o = patsubst_expand_pat (o, value, pattern, replace, ppercent, rpercent); if (v->recursive) free (value); } } } if (colon == 0) /* This is an ordinary variable reference. Look up the value of the variable. */ o = expand_variable_output (o, beg, end - beg); free (abeg); } break; default: if (ISSPACE (p[-1])) break; /* A $ followed by a random char is a variable reference: $a is equivalent to $(a). */ o = expand_variable_output (o, p, 1); break; } if (*p == '\0') break; ++p; } free (save); return (variable_buffer + line_offset); } /* Expand an argument for an expansion function. The text starting at STR and ending at END is variable-expanded into a null-terminated string that is returned as the value. This is done without clobbering 'variable_buffer' or the current variable-expansion that is in progress. */ char * expand_argument (const char *str, const char *end) { char *tmp, *alloc = NULL; char *r; if (str == end) return xstrdup (""); if (!end || *end == '\0') return allocated_expand_string (str); if (end - str + 1 > 1000) tmp = alloc = xmalloc (end - str + 1); else tmp = alloca (end - str + 1); memcpy (tmp, str, end - str); tmp[end - str] = '\0'; r = allocated_expand_string (tmp); free (alloc); return r; } /* Expand STRING for FILE, into the current variable_buffer. Error messages refer to the file and line where FILE's commands were found. Expansion uses FILE's variable set list. */ char * expand_string_for_file (const char *string, struct file *file) { char *result; struct variable_set_list *savev; const floc *savef; if (!file) return expand_string (string); install_file_context (file, &savev, &savef); result = expand_string (string); restore_file_context (savev, savef); return result; } /* Like expand_string_for_file, but the returned string is malloc'd. */ char * allocated_expand_string_for_file (const char *string, struct file *file) { char *obuf; size_t olen; install_variable_buffer (&obuf, &olen); expand_string_for_file (string, file); return swap_variable_buffer (obuf, olen); } /* Like allocated_expand_string, but for += target-specific variables. First recursively construct the variable value from its appended parts in any upper variable sets. Then expand the resulting value. */ static char * variable_append (const char *name, size_t length, const struct variable_set_list *set, int local) { const struct variable *v; char *buf = 0; int nextlocal; /* If there's nothing left to check, return the empty buffer. */ if (!set) return initialize_variable_output (); /* If this set is local and the next is not a parent, then next is local. */ nextlocal = local && set->next_is_parent == 0; /* Try to find the variable in this variable set. */ v = lookup_variable_in_set (name, length, set->set); /* If there isn't one, or this one is private, try the set above us. */ if (!v || (!local && v->private_var)) return variable_append (name, length, set->next, nextlocal); /* If this variable type is append, first get any upper values. If not, initialize the buffer. */ if (v->append) buf = variable_append (name, length, set->next, nextlocal); else buf = initialize_variable_output (); /* Append this value to the buffer, and return it. If we already have a value, first add a space. */ if (buf > variable_buffer) buf = variable_buffer_output (buf, " ", 1); /* Either expand it or copy it, depending. */ if (! v->recursive) return variable_buffer_output (buf, v->value, strlen (v->value)); buf = expand_string_buf (buf, v->value, strlen (v->value)); return (buf + strlen (buf)); } static char * allocated_variable_append (const struct variable *v) { /* Construct the appended variable value. */ char *obuf; size_t olen; install_variable_buffer (&obuf, &olen); variable_append (v->name, strlen (v->name), current_variable_set_list, 1); return swap_variable_buffer (obuf, olen); } ================================================ FILE: src/file.c ================================================ /* Target file management for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include "filedef.h" #include "dep.h" #include "job.h" #include "commands.h" #include "variable.h" #include "debug.h" #include "hash.h" #include "shuffle.h" #include "rule.h" /* Remember whether snap_deps has been invoked: we need this to be sure we don't add new rules (via $(eval ...)) afterwards. In the future it would be nice to support this, but it means we'd need to re-run snap_deps() or at least its functionality... it might mean changing snap_deps() to be run per-file, so we can invoke it after the eval... or remembering which files in the hash have been snapped (a new boolean flag?) and having snap_deps() only work on files which have not yet been snapped. */ int snapped_deps = 0; /* Hash table of files the makefile knows how to make. */ static unsigned long file_hash_1 (const void *key) { return_ISTRING_HASH_1 (((struct file const *) key)->hname); } static unsigned long file_hash_2 (const void *key) { return_ISTRING_HASH_2 (((struct file const *) key)->hname); } static int file_hash_cmp (const void *x, const void *y) { return_ISTRING_COMPARE (((struct file const *) x)->hname, ((struct file const *) y)->hname); } static struct hash_table files; /* We can't free files we take out of the hash table, because they are still likely pointed to in various places. The check_renamed() will be used if we come across these, to find the new correct file. This is mainly to prevent leak checkers from complaining. */ static struct file **rehashed_files = NULL; static size_t rehashed_files_len = 0; #define REHASHED_FILES_INCR 5 /* Whether or not .SECONDARY with no prerequisites was given. */ static int all_secondary = 0; /* Access the hash table of all file records. lookup_file given a name, return the struct file * for that name, or nil if there is none. */ struct file * lookup_file (const char *name) { struct file *f; struct file file_key; #if MK_OS_VMS int want_vmsify; #ifndef WANT_CASE_SENSITIVE_TARGETS char *lname; #endif #endif assert (*name != '\0'); /* This is also done in parse_file_seq, so this is redundant for names read from makefiles. It is here for names passed on the command line. */ #if MK_OS_VMS want_vmsify = (strpbrk (name, "]>:^") != NULL); # ifndef WANT_CASE_SENSITIVE_TARGETS if (*name != '.') { const char *n; char *ln; lname = xstrdup (name); for (n = name, ln = lname; *n != '\0'; ++n, ++ln) *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n; *ln = '\0'; name = lname; } # endif while (name[0] == '[' && name[1] == ']' && name[2] != '\0') name += 2; while (name[0] == '<' && name[1] == '>' && name[2] != '\0') name += 2; #endif while (name[0] == '.' && ISDIRSEP (name[1]) && name[2] != '\0') { name += 2; while (ISDIRSEP (*name)) /* Skip following slashes: ".//foo" is "foo", not "/foo". */ ++name; } if (*name == '\0') { /* It was all slashes after a dot. */ name = "./"; #if MK_OS_VMS /* TODO - This section is probably not needed. */ if (want_vmsify) name = "[]"; #endif } file_key.hname = name; f = hash_find_item (&files, &file_key); #if MK_OS_VMS && !defined(WANT_CASE_SENSITIVE_TARGETS) if (*name != '.') free (lname); #endif return f; } /* Look up a file record for file NAME and return it. Create a new record if one doesn't exist. NAME will be stored in the new record so it should be constant or in the strcache etc. */ struct file * enter_file (const char *name) { struct file *f; struct file *new; struct file **file_slot; struct file file_key; assert (*name != '\0'); assert (! verify_flag || strcache_iscached (name)); #if MK_OS_VMS && !defined(WANT_CASE_SENSITIVE_TARGETS) if (*name != '.') { const char *n; char *lname, *ln; lname = xstrdup (name); for (n = name, ln = lname; *n != '\0'; ++n, ++ln) if (isupper ((unsigned char)*n)) *ln = tolower ((unsigned char)*n); else *ln = *n; *ln = '\0'; name = strcache_add (lname); free (lname); } #endif file_key.hname = name; file_slot = (struct file **) hash_find_slot (&files, &file_key); f = *file_slot; if (! HASH_VACANT (f) && !f->double_colon) { f->builtin = 0; return f; } new = xcalloc (sizeof (struct file)); new->name = new->hname = name; new->update_status = us_none; if (HASH_VACANT (f)) { new->last = new; hash_insert_at (&files, new, file_slot); } else { /* There is already a double-colon entry for this file. */ new->double_colon = f; f->last->prev = new; f->last = new; } return new; } /* Rehash FILE to NAME. This is not as simple as resetting the 'hname' member, since it must be put in a new hash bucket, and possibly merged with an existing file called NAME. */ void rehash_file (struct file *from_file, const char *to_hname) { struct file file_key; struct file **file_slot; struct file *to_file; struct file *deleted_file; struct file *f; /* If it's already that name, we're done. */ from_file->builtin = 0; file_key.hname = to_hname; if (! file_hash_cmp (from_file, &file_key)) return; /* Find the end of the renamed list for the "from" file. */ file_key.hname = from_file->hname; check_renamed (from_file); if (file_hash_cmp (from_file, &file_key)) /* hname changed unexpectedly!! */ abort (); /* Remove the "from" file from the hash. */ deleted_file = hash_delete (&files, from_file); if (deleted_file != from_file) /* from_file isn't the one stored in files */ abort (); /* Find where the newly renamed file will go in the hash. */ file_key.hname = to_hname; file_slot = (struct file **) hash_find_slot (&files, &file_key); to_file = *file_slot; /* Change the hash name for this file. */ from_file->hname = to_hname; for (f = from_file->double_colon; f != 0; f = f->prev) f->hname = to_hname; /* If the new name doesn't exist yet just set it to the renamed file. */ if (HASH_VACANT (to_file)) { hash_insert_at (&files, from_file, file_slot); return; } /* TO_FILE already exists under TO_HNAME. We must retain TO_FILE and merge FROM_FILE into it. */ if (from_file->cmds != 0) { if (to_file->cmds == 0) to_file->cmds = from_file->cmds; else if (from_file->cmds != to_file->cmds) { size_t l = strlen (from_file->name); /* We have two sets of commands. We will go with the one given in the rule found through directory search, but give a message to let the user know what's going on. */ if (to_file->cmds->fileinfo.filenm != 0) error (&from_file->cmds->fileinfo, l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH, _("recipe was specified for file '%s' at %s:%lu,"), from_file->name, from_file->cmds->fileinfo.filenm, from_file->cmds->fileinfo.lineno); else error (&from_file->cmds->fileinfo, l, _("recipe for file '%s' was found by implicit rule search,"), from_file->name); l += strlen (to_hname); error (&from_file->cmds->fileinfo, l, _("but '%s' is now considered the same file as '%s'"), from_file->name, to_hname); error (&from_file->cmds->fileinfo, l, _("recipe for '%s' will be ignored in favor of the one for '%s'"), from_file->name, to_hname); } } /* Merge the dependencies of the two files. */ if (to_file->deps == 0) to_file->deps = from_file->deps; else { struct dep *deps = to_file->deps; while (deps->next != 0) deps = deps->next; deps->next = from_file->deps; } merge_variable_set_lists (&to_file->variables, from_file->variables); if (to_file->double_colon && from_file->is_target && !from_file->double_colon) OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"), from_file->name, to_hname); if (!to_file->double_colon && from_file->double_colon) { if (to_file->is_target) OSS (fatal, NILF, _("can't rename double-colon '%s' to single-colon '%s'"), from_file->name, to_hname); else to_file->double_colon = from_file->double_colon; } if (from_file->last_mtime > to_file->last_mtime) /* %%% Kludge so -W wins on a file that gets vpathized. */ to_file->last_mtime = from_file->last_mtime; to_file->mtime_before_update = from_file->mtime_before_update; #define MERGE(field) to_file->field |= from_file->field MERGE (precious); MERGE (loaded); MERGE (tried_implicit); MERGE (updating); MERGE (updated); MERGE (is_target); MERGE (cmd_target); MERGE (phony); /* Don't merge intermediate because this file might be pre-existing */ MERGE (is_explicit); MERGE (secondary); MERGE (notintermediate); MERGE (ignore_vpath); MERGE (snapped); MERGE (suffix); #undef MERGE to_file->builtin = 0; from_file->renamed = to_file; if (rehashed_files_len % REHASHED_FILES_INCR == 0) rehashed_files = xrealloc (rehashed_files, sizeof (struct file *) * (rehashed_files_len + REHASHED_FILES_INCR)); rehashed_files[rehashed_files_len++] = from_file; } /* Rename FILE to NAME. This is not as simple as resetting the 'name' member, since it must be put in a new hash bucket, and possibly merged with an existing file called NAME. */ void rename_file (struct file *from_file, const char *to_hname) { rehash_file (from_file, to_hname); while (from_file) { from_file->name = from_file->hname; from_file = from_file->prev; } } /* Remove all nonprecious intermediate files. If SIG is nonzero, this was caused by a fatal signal, meaning that a different message will be printed, and the message will go to stderr rather than stdout. */ void remove_intermediates (int sig) { struct file **file_slot; struct file **file_end; int doneany = 0; /* If there's no way we will ever remove anything anyway, punt early. */ if (question_flag || touch_flag || all_secondary || no_intermediates) return; if (sig && just_print_flag) return; file_slot = (struct file **) files.ht_vec; file_end = file_slot + files.ht_size; for ( ; file_slot < file_end; file_slot++) if (! HASH_VACANT (*file_slot)) { struct file *f = *file_slot; /* Is this file eligible for automatic deletion? Yes, IFF: it's marked intermediate, it's not secondary, it wasn't given on the command line, and it's either a -include makefile or it's not precious. */ if (f->intermediate && (f->dontcare || !f->precious) && !f->secondary && !f->notintermediate && !f->cmd_target) { int status; if (f->update_status == us_none) /* If nothing would have created this file yet, don't print an "rm" command for it. */ continue; if (just_print_flag) status = 0; else { status = unlink (f->name); if (status < 0 && errno == ENOENT) continue; } if (!f->dontcare) { if (sig) OS (error, NILF, _("*** deleting intermediate file '%s'"), f->name); else { if (! doneany) DB (DB_BASIC, (_("Removing intermediate files...\n"))); if (!run_silent) { if (! doneany) { fputs ("rm ", stdout); doneany = 1; } else putchar (' '); fputs (f->name, stdout); fflush (stdout); } } if (status < 0) { perror_with_name ("\nunlink: ", f->name); /* Start printing over. */ doneany = 0; } } } } if (doneany && !sig) { putchar ('\n'); fflush (stdout); } } /* Given a string containing prerequisites (fully expanded), break it up into a struct dep list. Enter each of these prereqs into the file database. */ struct dep * split_prereqs (char *p) { struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL, PARSEFS_WAIT); if (*p) { /* Files that follow '|' are "order-only" prerequisites that satisfy the dependency by existing: their modification times are irrelevant. */ struct dep *ood; ++p; ood = PARSE_FILE_SEQ (&p, struct dep, MAP_NUL, NULL, PARSEFS_WAIT); if (! new) new = ood; else { struct dep *dp; for (dp = new; dp->next != NULL; dp = dp->next) ; dp->next = ood; } for (; ood != NULL; ood = ood->next) ood->ignore_mtime = 1; } return new; } /* Given a list of prerequisites, enter them into the file database. If STEM is set then first expand patterns using STEM. */ struct dep * enter_prereqs (struct dep *deps, const char *stem) { struct dep *d1; if (deps == 0) return 0; /* If we have a stem, expand the %'s. We use patsubst_expand to translate the prerequisites' patterns into plain prerequisite names. */ if (stem) { const char *pattern = "%"; struct dep *dp = deps, *dl = 0; while (dp != 0) { char *percent; size_t nl = strlen (dp->name) + 1; char *nm = alloca (nl); memcpy (nm, dp->name, nl); percent = find_percent (nm); if (percent) { char *o; /* We have to handle empty stems specially, because that would be equivalent to $(patsubst %,dp->name,) which will always be empty. */ if (stem[0] == '\0') { memmove (percent, percent+1, strlen (percent)); o = variable_buffer_output (variable_buffer, nm, strlen (nm) + 1); } else o = patsubst_expand_pat (variable_buffer, stem, pattern, nm, pattern+1, percent+1); /* If the name expanded to the empty string, ignore it. */ if (variable_buffer[0] == '\0') { struct dep *df = dp; if (dp == deps) dp = deps = deps->next; else dp = dl->next = dp->next; free_dep (df); continue; } /* Save the name. */ dp->name = strcache_add_len (variable_buffer, o - variable_buffer); } dp->stem = stem; dp->staticpattern = 1; dl = dp; dp = dp->next; } } /* Enter them as files, unless they need a 2nd expansion. */ for (d1 = deps; d1 != 0; d1 = d1->next) { if (d1->need_2nd_expansion) continue; d1->file = lookup_file (d1->name); if (d1->file == 0) d1->file = enter_file (d1->name); d1->staticpattern = 0; d1->name = 0; if (!stem) /* This file is explicitly mentioned as a prereq. */ d1->file->is_explicit = 1; } return deps; } /* Expand and parse each dependency line. For each dependency of the file, make the 'struct dep' point at the appropriate 'struct file' (which may have to be created). */ void expand_deps (struct file *f) { struct dep *d; struct dep **dp; const char *fstem; int initialized = 0; int changed_dep = 0; if (f->snapped) return; f->snapped = 1; /* Walk through the dependencies. For any dependency that needs 2nd expansion, expand it then insert the result into the list. */ dp = &f->deps; d = f->deps; while (d != 0) { char *p; struct dep *new, *next; if (! d->name || ! d->need_2nd_expansion) { /* This one is all set already. */ dp = &d->next; d = d->next; continue; } /* If it's from a static pattern rule, convert the initial pattern in each word to "$*" so they'll expand properly. */ if (d->staticpattern) { const char *cs = d->name; size_t nperc = 0; /* Count the number of % in the string. */ while ((cs = strchr (cs, '%')) != NULL) { ++nperc; ++cs; } if (nperc) { /* Allocate enough space to replace all % with $*. */ size_t slen = strlen (d->name) + nperc + 1; const char *pcs = d->name; char *name = xmalloc (slen); char *s = name; /* Substitute the first % in each word. */ cs = strchr (pcs, '%'); while (cs) { s = mempcpy (s, pcs, cs - pcs); *(s++) = '$'; *(s++) = '*'; pcs = ++cs; /* Find the first % after the next whitespace. */ cs = strchr (end_of_token (cs), '%'); } strcpy (s, pcs); free ((char*)d->name); d->name = name; } } /* We're going to do second expansion so initialize file variables for the file. Since the stem for static pattern rules comes from individual dep lines, we will temporarily set f->stem to d->stem. */ if (!initialized) { initialize_file_variables (f, 0); initialized = 1; } set_file_variables (f, d->stem ? d->stem : f->stem); /* Perform second expansion. */ p = expand_string_for_file (d->name, f); /* Free the un-expanded name. */ free ((char*)d->name); /* Parse the prerequisites and enter them into the file database. */ new = split_prereqs (p); /* If there were no prereqs here (blank!) then throw this one out. */ if (new == 0) { *dp = d->next; changed_dep = 1; free_dep (d); d = *dp; continue; } /* Add newly parsed prerequisites. */ fstem = d->stem; next = d->next; changed_dep = 1; free_dep (d); *dp = new; for (dp = &new, d = new; d != 0; dp = &d->next, d = d->next) { d->file = lookup_file (d->name); if (d->file == 0) d->file = enter_file (d->name); d->name = 0; d->stem = fstem; if (!fstem) /* This file is explicitly mentioned as a prereq. */ d->file->is_explicit = 1; } *dp = next; d = *dp; } /* Shuffle mode assumes '->next' and '->shuf' links both traverse the same dependencies (in different sequences). Regenerate '->shuf' so we don't refer to stale data. */ if (changed_dep) shuffle_deps_recursive (f->deps); } /* Add extra prereqs to the file in question. */ struct dep * expand_extra_prereqs (const struct variable *extra) { struct dep *d; struct dep *prereqs = extra ? split_prereqs (expand_string (extra->value)) : NULL; for (d = prereqs; d; d = d->next) { d->file = lookup_file (d->name); if (!d->file) d->file = enter_file (d->name); d->name = NULL; d->ignore_automatic_vars = 1; } return prereqs; } /* Perform per-file snap operations. */ static void snap_file (const void *item, void *arg) { struct file *f = (struct file*)item; struct dep *prereqs = NULL; struct dep *d; /* If we're not doing second expansion then reset updating. */ if (!second_expansion) f->updating = 0; /* More specific setting has priority. */ /* If .SECONDARY is set with no deps, mark all targets as intermediate, unless the target is a prereq of .NOTINTERMEDIATE. */ if (all_secondary && !f->notintermediate) f->intermediate = 1; /* If .NOTINTERMEDIATE is set with no deps, mark all targets as notintermediate, unless the target is a prereq of .INTERMEDIATE. */ if (no_intermediates && !f->intermediate && !f->secondary) f->notintermediate = 1; /* If .EXTRA_PREREQS is set, add them as ignored by automatic variables. */ if (f->variables) { prereqs = expand_extra_prereqs (lookup_variable_in_set ( STRING_SIZE_TUPLE(".EXTRA_PREREQS"), f->variables->set)); if (second_expansion) for (d = prereqs; d; d = d->next) { if (!d->name) d->name = xstrdup (d->file->name); d->need_2nd_expansion = 1; } } else if (f->is_target) prereqs = copy_dep_chain (arg); if (prereqs) { for (d = prereqs; d; d = d->next) if (streq (f->name, dep_name (d))) /* Skip circular dependencies. */ break; if (d) /* We broke early: must have found a circular dependency. */ free_dep_chain (prereqs); else if (!f->deps) f->deps = prereqs; else { d = f->deps; while (d->next) d = d->next; d->next = prereqs; } } } /* Mark the files depended on by .PRECIOUS, .PHONY, .SILENT, and various other special targets. */ void snap_deps (void) { struct file *f; struct file *f2; struct dep *d; /* Remember that we've done this. Once we start snapping deps we can no longer define new targets. */ snapped_deps = 1; /* Now manage all the special targets. */ for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev) for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) f2->precious = 1; for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev) for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) f2->low_resolution_time = 1; for (f = lookup_file (".PHONY"); f != 0; f = f->prev) for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) { /* Mark this file as phony nonexistent target. */ f2->phony = 1; f2->is_target = 1; f2->last_mtime = NONEXISTENT_MTIME; f2->mtime_before_update = NONEXISTENT_MTIME; } for (f = lookup_file (".NOTINTERMEDIATE"); f != 0; f = f->prev) /* Mark .NOTINTERMEDIATE deps as notintermediate files. */ if (f->deps) for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) f2->notintermediate = 1; /* .NOTINTERMEDIATE with no deps marks all files as notintermediate. */ else no_intermediates = 1; /* The same file cannot be both .INTERMEDIATE and .NOTINTERMEDIATE. However, it is possible for a file to be .INTERMEDIATE and also match a .NOTINTERMEDIATE pattern. In that case, the intermediate file has priority over the notintermediate pattern. This priority is enforced by pattern_search. */ for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev) /* Mark .INTERMEDIATE deps as intermediate files. */ for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) if (f2->notintermediate) OS (fatal, NILF, _("%s cannot be both .NOTINTERMEDIATE and .INTERMEDIATE"), f2->name); else f2->intermediate = 1; /* .INTERMEDIATE with no deps does nothing. Marking all files as intermediates is useless since the goal targets would be deleted after they are built. */ for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev) /* Mark .SECONDARY deps as both intermediate and secondary. */ if (f->deps) for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) if (f2->notintermediate) OS (fatal, NILF, _("%s cannot be both .NOTINTERMEDIATE and .SECONDARY"), f2->name); else f2->intermediate = f2->secondary = 1; /* .SECONDARY with no deps listed marks *all* files that way. */ else all_secondary = 1; if (no_intermediates && all_secondary) O (fatal, NILF, _(".NOTINTERMEDIATE and .SECONDARY are mutually exclusive")); f = lookup_file (".EXPORT_ALL_VARIABLES"); if (f != 0 && f->is_target) export_all_variables = 1; f = lookup_file (".IGNORE"); if (f != 0 && f->is_target) { if (f->deps == 0) ignore_errors_flag = 1; else for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) f2->command_flags |= COMMANDS_NOERROR; } f = lookup_file (".SILENT"); if (f != 0 && f->is_target) { if (f->deps == 0) run_silent = 1; else for (d = f->deps; d != 0; d = d->next) for (f2 = d->file; f2 != 0; f2 = f2->prev) f2->command_flags |= COMMANDS_SILENT; } f = lookup_file (".NOTPARALLEL"); if (f != 0 && f->is_target) { struct dep *d2; if (!f->deps) not_parallel = 1; else /* Set a wait point between every prerequisite of each target. */ for (d = f->deps; d != NULL; d = d->next) for (f2 = d->file; f2 != NULL; f2 = f2->prev) if (f2->deps) for (d2 = f2->deps->next; d2 != NULL; d2 = d2->next) d2->wait_here = 1; } { struct dep *prereqs = expand_extra_prereqs (lookup_variable (STRING_SIZE_TUPLE(".EXTRA_PREREQS"))); /* Perform per-file snap operations. */ hash_map_arg(&files, snap_file, prereqs); free_dep_chain (prereqs); } #ifndef NO_MINUS_C_MINUS_O /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */ /* This needs more work: what if the user sets this in the makefile? if (posix_pedantic) define_variable_cname ("OUTPUT_OPTION", "", o_default, 1); */ #endif } /* Set the 'command_state' member of FILE and all its 'also_make's. Don't decrease the state of also_make's (e.g., don't downgrade a 'running' also_make to a 'deps_running' also_make). */ void set_command_state (struct file *file, enum cmd_state state) { struct dep *d; file->command_state = state; for (d = file->also_make; d != 0; d = d->next) if (state > d->file->command_state) d->file->command_state = state; } /* Convert an external file timestamp to internal form. */ FILE_TIMESTAMP file_timestamp_cons (const char *fname, time_t stamp, long int ns) { int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0); FILE_TIMESTAMP s = stamp; FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS; FILE_TIMESTAMP ts = product + offset; if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX) && product <= ts && ts <= ORDINARY_MTIME_MAX)) { char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; const char *f = fname ? fname : _("Current time"); ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX; file_timestamp_sprintf (buf, ts); OSS (error, NILF, _("%s: timestamp out of range: substituting %s"), f, buf); } return ts; } /* Return the current time as a file timestamp, setting *RESOLUTION to its resolution. */ FILE_TIMESTAMP file_timestamp_now (int *resolution) { int r; time_t s; int ns; /* Don't bother with high-resolution clocks if file timestamps have only one-second resolution. The code below should work, but it's not worth the hassle of debugging it on hosts where it fails. */ #if FILE_TIMESTAMP_HI_RES # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME { struct timespec timespec; if (clock_gettime (CLOCK_REALTIME, ×pec) == 0) { r = 1; s = timespec.tv_sec; ns = timespec.tv_nsec; goto got_time; } } # endif # if HAVE_GETTIMEOFDAY { struct timeval timeval; if (gettimeofday (&timeval, 0) == 0) { r = 1000; s = timeval.tv_sec; ns = timeval.tv_usec * 1000; goto got_time; } } # endif #endif r = 1000000000; s = time ((time_t *) 0); ns = 0; #if FILE_TIMESTAMP_HI_RES got_time: #endif *resolution = r; return file_timestamp_cons (0, s, ns); } /* Place into the buffer P a printable representation of the file timestamp TS. */ void file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts) { time_t t = FILE_TIMESTAMP_S (ts); struct tm *tm = localtime (&t); if (tm) { intmax_t year = tm->tm_year; sprintf (p, "%04" PRIdMAX "-%02d-%02d %02d:%02d:%02d", year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); } else if (t < 0) sprintf (p, "%" PRIdMAX, (intmax_t) t); else sprintf (p, "%" PRIuMAX, (uintmax_t) t); p += strlen (p); /* Append nanoseconds as a fraction, but remove trailing zeros. We don't know the actual timestamp resolution, since clock_getres applies only to local times, whereas this timestamp might come from a remote filesystem. So removing trailing zeros is the best guess that we can do. */ sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts)); p += strlen (p) - 1; while (*p == '0') p--; p += *p != '.'; *p = '\0'; } /* Print the data base of files. */ static void print_prereqs (const struct dep *deps) { const struct dep *ood = 0; /* Print all normal dependencies; note any order-only deps. */ for (; deps != 0; deps = deps->next) if (! deps->ignore_mtime) printf (" %s%s", deps->wait_here ? ".WAIT " : "", dep_name (deps)); else if (! ood) ood = deps; /* Print order-only deps, if we have any. */ if (ood) { printf (" | %s%s", ood->wait_here ? ".WAIT " : "", dep_name (ood)); for (ood = ood->next; ood != 0; ood = ood->next) if (ood->ignore_mtime) printf (" %s%s", ood->wait_here ? ".WAIT " : "", dep_name (ood)); } putchar ('\n'); } static void print_file (const void *item) { const struct file *f = item; /* If we're not using builtin targets, don't show them. Ideally we'd be able to delete them altogether but currently there's no facility to ever delete a file once it's been added. */ if (no_builtin_rules_flag && f->builtin) return; putchar ('\n'); if (f->cmds && f->cmds->recipe_prefix != cmd_prefix) { fputs (".RECIPEPREFIX = ", stdout); cmd_prefix = f->cmds->recipe_prefix; if (cmd_prefix != RECIPEPREFIX_DEFAULT) putchar (cmd_prefix); putchar ('\n'); } if (f->variables != 0) print_target_variables (f); if (!f->is_target) puts (_("# Not a target:")); printf ("%s:%s", f->name, f->double_colon ? ":" : ""); print_prereqs (f->deps); if (f->precious) puts (_("# Precious file (prerequisite of .PRECIOUS).")); if (f->phony) puts (_("# Phony target (prerequisite of .PHONY).")); if (f->cmd_target) puts (_("# Command line target.")); if (f->dontcare) puts (_("# A default, MAKEFILES, or -include/sinclude makefile.")); if (f->builtin) puts (_("# Builtin rule")); puts (f->tried_implicit ? _("# Implicit rule search has been done.") : _("# Implicit rule search has not been done.")); if (f->stem != 0) printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem); if (f->intermediate) puts (_("# File is an intermediate prerequisite.")); if (f->notintermediate) puts (_("# File is a prerequisite of .NOTINTERMEDIATE.")); if (f->secondary) puts (_("# File is secondary (prerequisite of .SECONDARY).")); if (f->also_make != 0) { const struct dep *d; fputs (_("# Also makes:"), stdout); for (d = f->also_make; d != 0; d = d->next) printf (" %s", dep_name (d)); putchar ('\n'); } if (f->last_mtime == UNKNOWN_MTIME) puts (_("# Modification time never checked.")); else if (f->last_mtime == NONEXISTENT_MTIME) puts (_("# File does not exist.")); else if (f->last_mtime == OLD_MTIME) puts (_("# File is very old.")); else { char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; file_timestamp_sprintf (buf, f->last_mtime); printf (_("# Last modified %s\n"), buf); } puts (f->updated ? _("# File has been updated.") : _("# File has not been updated.")); switch (f->command_state) { case cs_running: puts (_("# Recipe currently running (THIS IS A BUG).")); break; case cs_deps_running: puts (_("# Dependencies recipe running (THIS IS A BUG).")); break; case cs_not_started: case cs_finished: switch (f->update_status) { case us_none: break; case us_success: puts (_("# Successfully updated.")); break; case us_question: assert (question_flag); puts (_("# Needs to be updated (-q is set).")); break; case us_failed: puts (_("# Failed to be updated.")); break; } break; default: puts (_("# Invalid value in 'command_state' member!")); fflush (stdout); fflush (stderr); abort (); } if (f->variables != 0) print_file_variables (f); if (f->cmds != 0) print_commands (f->cmds); if (f->prev) print_file ((const void *) f->prev); } void print_file_data_base (void) { puts (_("\n# Files")); hash_map (&files, print_file); fputs (_("\n# files hash-table stats:\n# "), stdout); hash_print_stats (&files, stdout); } static void print_target (const void *item) { const struct file *f = item; if (!f->is_target || f->suffix) return; /* Ignore any special targets, as defined by POSIX. */ if (f->name[0] == '.' && isupper ((unsigned char)f->name[1])) { const char *cp = f->name + 1; while (*(++cp) != '\0') if (!isupper ((unsigned char)*cp)) break; if (*cp == '\0') return; } puts (f->name); } void print_targets (void) { hash_map (&files, print_target); } /* Verify the integrity of the data base of files. */ #define VERIFY_CACHED(_p,_n) \ do{ \ if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n), \ _("%s: field '%s' not cached: %s"), _p->name, # _n, _p->_n); \ }while(0) static void verify_file (const void *item) { const struct file *f = item; const struct dep *d; VERIFY_CACHED (f, name); VERIFY_CACHED (f, hname); VERIFY_CACHED (f, vpath); VERIFY_CACHED (f, stem); /* Check the deps. */ for (d = f->deps; d != 0; d = d->next) { if (! d->need_2nd_expansion) VERIFY_CACHED (d, name); VERIFY_CACHED (d, stem); } } void verify_file_data_base (void) { hash_map (&files, verify_file); } #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500) char * build_target_list (char *value) { static unsigned long last_targ_count = 0; if (files.ht_fill != last_targ_count) { size_t max = EXPANSION_INCREMENT (strlen (value)); size_t len; char *p; struct file **fp = (struct file **) files.ht_vec; struct file **end = &fp[files.ht_size]; /* Make sure we have at least MAX bytes in the allocated buffer. */ value = xrealloc (value, max); p = value; len = 0; for (; fp < end; ++fp) if (!HASH_VACANT (*fp) && (*fp)->is_target) { struct file *f = *fp; size_t l = strlen (f->name); len += l + 1; if (len > max) { size_t off = p - value; max += EXPANSION_INCREMENT (l + 1); value = xrealloc (value, max); p = &value[off]; } p = mempcpy (p, f->name, l); *(p++) = ' '; } *(p-1) = '\0'; last_targ_count = files.ht_fill; } return value; } void init_hash_files (void) { hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp); } /* EOF */ ================================================ FILE: src/filedef.h ================================================ /* Definition of target file data structures for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Structure that represents the info on one file that the makefile says how to make. All of these are chained together through 'next'. */ #include "hash.h" struct commands; struct dep; struct variable; struct variable_set_list; struct file { const char *name; const char *hname; /* Hashed filename */ const char *vpath; /* VPATH/vpath pathname */ struct dep *deps; /* all dependencies, including duplicates */ struct commands *cmds; /* Commands to execute for this target. */ const char *stem; /* Implicit stem, if an implicit rule has been used */ struct dep *also_make; /* Targets that are made by making this. */ struct file *prev; /* Previous entry for same file name; used when there are multiple double-colon entries for the same file. */ struct file *last; /* Last entry for the same file name. */ /* File that this file was renamed to. After any time that a file could be renamed, call 'check_renamed' (below). */ struct file *renamed; /* List of variable sets used for this file. */ struct variable_set_list *variables; /* Pattern-specific variable reference for this target, or null if there isn't one. Also see the pat_searched flag, below. */ struct variable_set_list *pat_variables; /* Immediate dependent that caused this target to be remade, or nil if there isn't one. */ struct file *parent; /* For a double-colon entry, this is the first double-colon entry for the same file. Otherwise this is null. */ struct file *double_colon; FILE_TIMESTAMP last_mtime; /* File's modtime, if already known. */ FILE_TIMESTAMP mtime_before_update; /* File's modtime before any updating has been performed. */ unsigned int considered; /* equal to 'considered' if file has been considered on current scan of goal chain */ int command_flags; /* Flags OR'd in for cmds; see commands.h. */ enum update_status /* Status of the last attempt to update. */ { us_success = 0, /* Successfully updated. Must be 0! */ us_none, /* No attempt to update has been made. */ us_question, /* Needs to be updated (-q is is set). */ us_failed /* Update failed. */ } update_status ENUM_BITFIELD (2); enum cmd_state /* State of commands. ORDER IS IMPORTANT! */ { cs_not_started = 0, /* Not yet started. Must be 0! */ cs_deps_running, /* Dep commands running. */ cs_running, /* Commands running. */ cs_finished /* Commands finished. */ } command_state ENUM_BITFIELD (2); unsigned int builtin:1; /* True if the file is a builtin rule. */ unsigned int precious:1; /* Non-0 means don't delete file on quit */ unsigned int loaded:1; /* True if the file is a loaded object. */ unsigned int unloaded:1; /* True if this loaded object was unloaded. */ unsigned int low_resolution_time:1; /* Nonzero if this file's time stamp has only one-second resolution. */ unsigned int tried_implicit:1; /* Nonzero if have searched for implicit rule for making this file; don't search again. */ unsigned int updating:1; /* Nonzero while updating deps of this file */ unsigned int updated:1; /* Nonzero if this file has been remade. */ unsigned int is_target:1; /* Nonzero if file is described as target. */ unsigned int cmd_target:1; /* Nonzero if file was given on cmd line. */ unsigned int phony:1; /* Nonzero if this is a phony file i.e., a prerequisite of .PHONY. */ unsigned int intermediate:1;/* Nonzero if this is an intermediate file. */ unsigned int is_explicit:1; /* Nonzero if explicitly mentioned. */ unsigned int secondary:1; /* Nonzero means remove_intermediates should not delete it. */ unsigned int notintermediate:1; /* Nonzero means a file is a prereq to .NOTINTERMEDIATE. */ unsigned int dontcare:1; /* Nonzero if no complaint is to be made if this target cannot be remade. */ unsigned int ignore_vpath:1;/* Nonzero if we threw out VPATH name. */ unsigned int pat_searched:1;/* Nonzero if we already searched for pattern-specific variables. */ unsigned int no_diag:1; /* True if the file failed to update and no diagnostics has been issued (dontcare). */ unsigned int was_shuffled:1; /* Did we already shuffle 'deps'? used when --shuffle passes through the graph. */ unsigned int snapped:1; /* True if the deps of this file have been secondary expanded. */ unsigned int suffix:1; /* True if this is a suffix rule. */ }; extern struct file *default_file; struct file *lookup_file (const char *name); struct file *enter_file (const char *name); struct dep *split_prereqs (char *prereqstr); struct dep *enter_prereqs (struct dep *prereqs, const char *stem); void expand_deps (struct file *f); struct dep *expand_extra_prereqs (const struct variable *extra); void remove_intermediates (int sig); void snap_deps (void); void rename_file (struct file *file, const char *name); void rehash_file (struct file *file, const char *name); void set_command_state (struct file *file, enum cmd_state state); void notice_finished_file (struct file *file); void init_hash_files (void); void verify_file_data_base (void); char *build_target_list (char *old_list); void print_file_data_base (void); void print_targets (void); int try_implicit_rule (struct file *file, unsigned int depth); int stemlen_compare (const void *v1, const void *v2); #if FILE_TIMESTAMP_HI_RES # define FILE_TIMESTAMP_STAT_MODTIME(fname, st) \ file_timestamp_cons (fname, (st).st_mtime, (st).ST_MTIM_NSEC) #else # define FILE_TIMESTAMP_STAT_MODTIME(fname, st) \ file_timestamp_cons (fname, (st).st_mtime, 0) #endif /* If FILE_TIMESTAMP is 64 bits (or more), use nanosecond resolution. (Multiply by 2**30 instead of by 10**9 to save time at the cost of slightly decreasing the number of available timestamps.) With 64-bit FILE_TIMESTAMP, this stops working on 2514-05-30 01:53:04 UTC, but by then uintmax_t should be larger than 64 bits. */ #define FILE_TIMESTAMPS_PER_S (FILE_TIMESTAMP_HI_RES ? 1000000000 : 1) #define FILE_TIMESTAMP_LO_BITS (FILE_TIMESTAMP_HI_RES ? 30 : 0) #define FILE_TIMESTAMP_S(ts) (((ts) - ORDINARY_MTIME_MIN) \ >> FILE_TIMESTAMP_LO_BITS) #define FILE_TIMESTAMP_NS(ts) ((int) (((ts) - ORDINARY_MTIME_MIN) \ & ((1 << FILE_TIMESTAMP_LO_BITS) - 1))) /* Upper bound on length of string "YYYY-MM-DD HH:MM:SS.NNNNNNNNN" representing a file timestamp. The upper bound is not necessarily 29, since the year might be less than -999 or greater than 9999. Subtract one for the sign bit if in case file timestamps can be negative; subtract FLOOR_LOG2_SECONDS_PER_YEAR to yield an upper bound on how many file timestamp bits might affect the year; 302 / 1000 is log10 (2) rounded up; add one for integer division truncation; add one more for a minus sign if file timestamps can be negative; add 4 to allow for any 4-digit epoch year (e.g. 1970); add 25 to allow for "-MM-DD HH:MM:SS.NNNNNNNNN". */ #define FLOOR_LOG2_SECONDS_PER_YEAR 24 #define FILE_TIMESTAMP_PRINT_LEN_BOUND \ (((sizeof (FILE_TIMESTAMP) * CHAR_BIT - 1 - FLOOR_LOG2_SECONDS_PER_YEAR) \ * 302 / 1000) \ + 1 + 1 + 4 + 25) FILE_TIMESTAMP file_timestamp_cons (char const *, time_t, long int); FILE_TIMESTAMP file_timestamp_now (int *); void file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts); /* Return the mtime of file F (a struct file *), caching it. The value is NONEXISTENT_MTIME if the file does not exist. */ #define file_mtime(f) file_mtime_1 ((f), 1) /* Return the mtime of file F (a struct file *), caching it. Don't search using vpath for the file--if it doesn't actually exist, we don't find it. The value is NONEXISTENT_MTIME if the file does not exist. */ #define file_mtime_no_search(f) file_mtime_1 ((f), 0) FILE_TIMESTAMP f_mtime (struct file *file, int search); #define file_mtime_1(f, v) \ ((f)->last_mtime == UNKNOWN_MTIME ? f_mtime ((f), v) : (f)->last_mtime) /* Special timestamp values. */ /* The file's timestamp is not yet known. */ #define UNKNOWN_MTIME 0 /* The file does not exist. */ #define NONEXISTENT_MTIME 1 /* The file does not exist, and we assume that it is older than any actual file. */ #define OLD_MTIME 2 /* The smallest and largest ordinary timestamps. */ #define ORDINARY_MTIME_MIN (OLD_MTIME + 1) #define ORDINARY_MTIME_MAX ((FILE_TIMESTAMP_S (NEW_MTIME) \ << FILE_TIMESTAMP_LO_BITS) \ + ORDINARY_MTIME_MIN + FILE_TIMESTAMPS_PER_S - 1) #define is_ordinary_mtime(_t) ((_t) >= ORDINARY_MTIME_MIN && (_t) <= ORDINARY_MTIME_MAX) /* Modtime value to use for 'infinitely new'. We used to get the current time from the system and use that whenever we wanted 'new'. But that causes trouble when the machine running make and the machine holding a file have different ideas about what time it is; and can also lose for 'force' targets, which need to be considered newer than anything that depends on them, even if said dependents' modtimes are in the future. */ #define NEW_MTIME INTEGER_TYPE_MAXIMUM (FILE_TIMESTAMP) #define check_renamed(file) \ while ((file)->renamed != 0) (file) = (file)->renamed /* No ; here. */ /* Have we snapped deps yet? */ extern int snapped_deps; ================================================ FILE: src/function.c ================================================ /* Builtin function expansion for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "variable.h" #include "dep.h" #include "job.h" #include "os.h" #include "commands.h" #include "debug.h" struct function_table_entry { union { char *(*func_ptr) (char *output, char **argv, const char *fname); gmk_func_ptr alloc_func_ptr; } fptr; const char *name; unsigned char len; unsigned char minimum_args; unsigned char maximum_args; unsigned int expand_args:1; unsigned int alloc_fn:1; unsigned int adds_command:1; }; static unsigned long function_table_entry_hash_1 (const void *keyv) { const struct function_table_entry *key = keyv; return_STRING_N_HASH_1 (key->name, key->len); } static unsigned long function_table_entry_hash_2 (const void *keyv) { const struct function_table_entry *key = keyv; return_STRING_N_HASH_2 (key->name, key->len); } static int function_table_entry_hash_cmp (const void *xv, const void *yv) { const struct function_table_entry *x = xv; const struct function_table_entry *y = yv; int result = x->len - y->len; if (result) return result; return_STRING_N_COMPARE (x->name, y->name, x->len); } static struct hash_table function_table; /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing each occurrence of SUBST with REPLACE. TEXT is null-terminated. SLEN is the length of SUBST and RLEN is the length of REPLACE. If BY_WORD is nonzero, substitutions are done only on matches which are complete whitespace-delimited words. */ char * subst_expand (char *o, const char *text, const char *subst, const char *replace, size_t slen, size_t rlen, int by_word) { const char *t = text; const char *p; if (slen == 0 && !by_word) { /* The first occurrence of "" in any string is its end. */ o = variable_buffer_output (o, t, strlen (t)); if (rlen > 0) o = variable_buffer_output (o, replace, rlen); return o; } do { if (by_word && slen == 0) /* When matching by words, the empty string should match the end of each word, rather than the end of the whole text. */ p = end_of_token (next_token (t)); else { p = strstr (t, subst); if (p == 0) { /* No more matches. Output everything left on the end. */ o = variable_buffer_output (o, t, strlen (t)); return o; } } /* Output everything before this occurrence of the string to replace. */ if (p > t) o = variable_buffer_output (o, t, p - t); /* If we're substituting only by fully matched words, or only at the ends of words, check that this case qualifies. */ if (by_word && ((p > text && !ISSPACE (p[-1])) || ! STOP_SET (p[slen], MAP_SPACE|MAP_NUL))) /* Struck out. Output the rest of the string that is no longer to be replaced. */ o = variable_buffer_output (o, subst, slen); else if (rlen > 0) /* Output the replacement string. */ o = variable_buffer_output (o, replace, rlen); /* Advance T past the string to be replaced. */ t = p + slen; } while (*t != '\0'); return o; } /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing strings matching PATTERN with REPLACE. If PATTERN_PERCENT is not nil, PATTERN has already been run through find_percent, and PATTERN_PERCENT is the result. If REPLACE_PERCENT is not nil, REPLACE has already been run through find_percent, and REPLACE_PERCENT is the result. Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the character _AFTER_ the %, not to the % itself. */ char * patsubst_expand_pat (char *o, const char *text, const char *pattern, const char *replace, const char *pattern_percent, const char *replace_percent) { size_t pattern_prepercent_len, pattern_postpercent_len; size_t replace_prepercent_len, replace_postpercent_len; const char *t; size_t len; int doneany = 0; /* Record the length of REPLACE before and after the % so we don't have to compute these lengths more than once. */ if (replace_percent) { replace_prepercent_len = replace_percent - replace - 1; replace_postpercent_len = strlen (replace_percent); } else { replace_prepercent_len = strlen (replace); replace_postpercent_len = 0; } if (!pattern_percent) /* With no % in the pattern, this is just a simple substitution. */ return subst_expand (o, text, pattern, replace, strlen (pattern), strlen (replace), 1); /* Record the length of PATTERN before and after the % so we don't have to compute it more than once. */ pattern_prepercent_len = pattern_percent - pattern - 1; pattern_postpercent_len = strlen (pattern_percent); while ((t = find_next_token (&text, &len)) != 0) { int fail = 0; /* Is it big enough to match? */ if (len < pattern_prepercent_len + pattern_postpercent_len) fail = 1; /* Does the prefix match? */ if (!fail && pattern_prepercent_len > 0 && (*t != *pattern || t[pattern_prepercent_len - 1] != pattern_percent[-2] || !strneq (t + 1, pattern + 1, pattern_prepercent_len - 1))) fail = 1; /* Does the suffix match? */ if (!fail && pattern_postpercent_len > 0 && (t[len - 1] != pattern_percent[pattern_postpercent_len - 1] || t[len - pattern_postpercent_len] != *pattern_percent || !strneq (&t[len - pattern_postpercent_len], pattern_percent, pattern_postpercent_len - 1))) fail = 1; if (fail) /* It didn't match. Output the string. */ o = variable_buffer_output (o, t, len); else { /* It matched. Output the replacement. */ /* Output the part of the replacement before the %. */ o = variable_buffer_output (o, replace, replace_prepercent_len); if (replace_percent != 0) { /* Output the part of the matched string that matched the % in the pattern. */ o = variable_buffer_output (o, t + pattern_prepercent_len, len - (pattern_prepercent_len + pattern_postpercent_len)); /* Output the part of the replacement after the %. */ o = variable_buffer_output (o, replace_percent, replace_postpercent_len); } } /* Output a space, but not if the replacement is "". */ if (fail || replace_prepercent_len > 0 || (replace_percent != 0 && len + replace_postpercent_len > 0)) { o = variable_buffer_output (o, " ", 1); doneany = 1; } } if (doneany) /* Kill the last space. */ --o; return o; } /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing strings matching PATTERN with REPLACE. If PATTERN_PERCENT is not nil, PATTERN has already been run through find_percent, and PATTERN_PERCENT is the result. If REPLACE_PERCENT is not nil, REPLACE has already been run through find_percent, and REPLACE_PERCENT is the result. Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the character _AFTER_ the %, not to the % itself. */ char * patsubst_expand (char *o, const char *text, char *pattern, char *replace) { const char *pattern_percent = find_percent (pattern); const char *replace_percent = find_percent (replace); /* If there's a percent in the pattern or replacement skip it. */ if (replace_percent) ++replace_percent; if (pattern_percent) ++pattern_percent; return patsubst_expand_pat (o, text, pattern, replace, pattern_percent, replace_percent); } /* Look up a function by name. */ static const struct function_table_entry * lookup_function (const char *s) { struct function_table_entry function_table_entry_key; const char *e = s; while (STOP_SET (*e, MAP_USERFUNC)) e++; if (e == s || !STOP_SET(*e, MAP_NUL|MAP_SPACE)) return NULL; function_table_entry_key.name = s; function_table_entry_key.len = (unsigned char) (e - s); return hash_find_item (&function_table, &function_table_entry_key); } /* Return 1 if PATTERN matches STR, 0 if not. */ int pattern_matches (const char *pattern, const char *percent, const char *str) { size_t sfxlen, strlength; if (percent == 0) { size_t len = strlen (pattern) + 1; char *new_chars = alloca (len); memcpy (new_chars, pattern, len); percent = find_percent (new_chars); if (percent == 0) return streq (new_chars, str); pattern = new_chars; } sfxlen = strlen (percent + 1); strlength = strlen (str); if (strlength < (percent - pattern) + sfxlen || !strneq (pattern, str, percent - pattern)) return 0; return !strcmp (percent + 1, str + (strlength - sfxlen)); } /* Find the next comma or ENDPAREN (counting nested STARTPAREN and ENDPARENtheses), starting at PTR before END. Return a pointer to next character. If no next argument is found, return NULL. */ static char * find_next_argument (char startparen, char endparen, const char *ptr, const char *end) { int count = 0; for (; ptr < end; ++ptr) if (!STOP_SET (*ptr, MAP_VARSEP|MAP_COMMA)) continue; else if (*ptr == startparen) ++count; else if (*ptr == endparen) { --count; if (count < 0) return NULL; } else if (*ptr == ',' && !count) return (char *)ptr; /* We didn't find anything. */ return NULL; } /* Glob-expand LINE. The returned pointer is only good until the next call to string_glob. */ static char * string_glob (char *line) { static char *result = 0; static size_t length; struct nameseq *chain; size_t idx; chain = PARSE_FILE_SEQ (&line, struct nameseq, MAP_NUL, NULL, /* We do not want parse_file_seq to strip './'s. That would break examples like: $(patsubst ./%.c,obj/%.o,$(wildcard ./?*.c)). */ PARSEFS_NOSTRIP|PARSEFS_NOCACHE|PARSEFS_EXISTS); if (result == 0) { length = 100; result = xmalloc (100); } idx = 0; while (chain != 0) { struct nameseq *next = chain->next; size_t len = strlen (chain->name); if (idx + len + 1 > length) { length += (len + 1) * 2; result = xrealloc (result, length); } memcpy (&result[idx], chain->name, len); idx += len; result[idx++] = ' '; /* Because we used PARSEFS_NOCACHE above, we have to free() NAME. */ free ((char *)chain->name); free (chain); chain = next; } /* Kill the last space and terminate the string. */ if (idx == 0) result[0] = '\0'; else result[idx - 1] = '\0'; return result; } /* Builtin functions */ static char * func_patsubst (char *o, char **argv, const char *funcname UNUSED) { o = patsubst_expand (o, argv[2], argv[0], argv[1]); return o; } static char * func_join (char *o, char **argv, const char *funcname UNUSED) { int doneany = 0; /* Write each word of the first argument directly followed by the corresponding word of the second argument. If the two arguments have a different number of words, the excess words are just output separated by blanks. */ const char *tp; const char *pp; const char *list1_iterator = argv[0]; const char *list2_iterator = argv[1]; do { size_t len1, len2; tp = find_next_token (&list1_iterator, &len1); if (tp != 0) o = variable_buffer_output (o, tp, len1); pp = find_next_token (&list2_iterator, &len2); if (pp != 0) o = variable_buffer_output (o, pp, len2); if (tp != 0 || pp != 0) { o = variable_buffer_output (o, " ", 1); doneany = 1; } } while (tp != 0 || pp != 0); if (doneany) /* Kill the last blank. */ --o; return o; } static char * func_origin (char *o, char **argv, const char *funcname UNUSED) { /* Expand the argument. */ struct variable *v = lookup_variable (argv[0], strlen (argv[0])); if (v == 0) o = variable_buffer_output (o, "undefined", 9); else switch (v->origin) { case o_invalid: abort (); break; case o_default: o = variable_buffer_output (o, "default", 7); break; case o_env: o = variable_buffer_output (o, "environment", 11); break; case o_file: o = variable_buffer_output (o, "file", 4); break; case o_env_override: o = variable_buffer_output (o, "environment override", 20); break; case o_command: o = variable_buffer_output (o, "command line", 12); break; case o_override: o = variable_buffer_output (o, "override", 8); break; case o_automatic: o = variable_buffer_output (o, "automatic", 9); break; } return o; } static char * func_flavor (char *o, char **argv, const char *funcname UNUSED) { struct variable *v = lookup_variable (argv[0], strlen (argv[0])); if (v == 0) o = variable_buffer_output (o, "undefined", 9); else if (v->recursive) o = variable_buffer_output (o, "recursive", 9); else o = variable_buffer_output (o, "simple", 6); return o; } static char * func_notdir_suffix (char *o, char **argv, const char *funcname) { /* Expand the argument. */ const char *list_iterator = argv[0]; const char *p2; int doneany =0; size_t len=0; int is_suffix = funcname[0] == 's'; int is_notdir = !is_suffix; int stop = MAP_DIRSEP | (is_suffix ? MAP_DOT : 0); #if MK_OS_VMS /* For VMS list_iterator points to a comma separated list. To use the common [find_]next_token, create a local copy and replace the commas with spaces. Obviously, there is a problem if there is a ',' in the VMS filename (can only happen on ODS5), the same problem as with spaces in filenames, which seems to be present in make on all platforms. */ char *vms_list_iterator = alloca(strlen(list_iterator) + 1); int i; for (i = 0; list_iterator[i]; i++) if (list_iterator[i] == ',') vms_list_iterator[i] = ' '; else vms_list_iterator[i] = list_iterator[i]; vms_list_iterator[i] = list_iterator[i]; while ((p2 = find_next_token((const char**) &vms_list_iterator, &len)) != 0) #else while ((p2 = find_next_token (&list_iterator, &len)) != 0) #endif { const char *p = p2 + len - 1; while (p >= p2 && ! STOP_SET (*p, stop)) --p; if (p >= p2) { if (is_notdir) ++p; else if (*p != '.') continue; o = variable_buffer_output (o, p, len - (p - p2)); } #ifdef HAVE_DOS_PATHS /* Handle the case of "d:foo/bar". */ else if (is_notdir && p2[0] && p2[1] == ':') { p = p2 + 2; o = variable_buffer_output (o, p, len - (p - p2)); } #endif else if (is_notdir) o = variable_buffer_output (o, p2, len); if (is_notdir || p >= p2) { #if MK_OS_VMS if (vms_comma_separator) o = variable_buffer_output (o, ",", 1); else #endif o = variable_buffer_output (o, " ", 1); doneany = 1; } } if (doneany) /* Kill last space. */ --o; return o; } static char * func_basename_dir (char *o, char **argv, const char *funcname) { /* Expand the argument. */ const char *p3 = argv[0]; const char *p2; int doneany = 0; size_t len = 0; int is_basename = funcname[0] == 'b'; int is_dir = !is_basename; int stop = MAP_DIRSEP | (is_basename ? MAP_DOT : 0) | MAP_NUL; #if MK_OS_VMS /* As in func_notdir_suffix ... */ char *vms_p3 = alloca (strlen(p3) + 1); int i; for (i = 0; p3[i]; i++) if (p3[i] == ',') vms_p3[i] = ' '; else vms_p3[i] = p3[i]; vms_p3[i] = p3[i]; while ((p2 = find_next_token((const char**) &vms_p3, &len)) != 0) #else while ((p2 = find_next_token (&p3, &len)) != 0) #endif { const char *p = p2 + len - 1; while (p >= p2 && ! STOP_SET (*p, stop)) --p; if (p >= p2 && (is_dir)) o = variable_buffer_output (o, p2, ++p - p2); else if (p >= p2 && (*p == '.')) o = variable_buffer_output (o, p2, p - p2); #ifdef HAVE_DOS_PATHS /* Handle the "d:foobar" case */ else if (p2[0] && p2[1] == ':' && is_dir) o = variable_buffer_output (o, p2, 2); #endif else if (is_dir) #if MK_OS_VMS { extern int vms_report_unix_paths; if (vms_report_unix_paths) o = variable_buffer_output (o, "./", 2); else o = variable_buffer_output (o, "[]", 2); } #else o = variable_buffer_output (o, "./", 2); #endif /* !MK_OS_VMS */ else /* The entire name is the basename. */ o = variable_buffer_output (o, p2, len); #if MK_OS_VMS if (vms_comma_separator) o = variable_buffer_output (o, ",", 1); else #endif o = variable_buffer_output (o, " ", 1); doneany = 1; } if (doneany) /* Kill last space. */ --o; return o; } static char * func_addsuffix_addprefix (char *o, char **argv, const char *funcname) { size_t fixlen = strlen (argv[0]); const char *list_iterator = argv[1]; int is_addprefix = funcname[3] == 'p'; int is_addsuffix = !is_addprefix; int doneany = 0; const char *p; size_t len; while ((p = find_next_token (&list_iterator, &len)) != 0) { if (is_addprefix) o = variable_buffer_output (o, argv[0], fixlen); o = variable_buffer_output (o, p, len); if (is_addsuffix) o = variable_buffer_output (o, argv[0], fixlen); o = variable_buffer_output (o, " ", 1); doneany = 1; } if (doneany) /* Kill last space. */ --o; return o; } static char * func_subst (char *o, char **argv, const char *funcname UNUSED) { o = subst_expand (o, argv[2], argv[0], argv[1], strlen (argv[0]), strlen (argv[1]), 0); return o; } static char * func_firstword (char *o, char **argv, const char *funcname UNUSED) { size_t i; const char *words = argv[0]; /* Use a temp variable for find_next_token */ const char *p = find_next_token (&words, &i); if (p != 0) o = variable_buffer_output (o, p, i); return o; } static char * func_lastword (char *o, char **argv, const char *funcname UNUSED) { size_t i; const char *words = argv[0]; /* Use a temp variable for find_next_token */ const char *p = NULL; const char *t; while ((t = find_next_token (&words, &i)) != NULL) p = t; if (p != 0) o = variable_buffer_output (o, p, i); return o; } static char * func_words (char *o, char **argv, const char *funcname UNUSED) { unsigned int i = 0; const char *word_iterator = argv[0]; char buf[INTSTR_LENGTH]; while (find_next_token (&word_iterator, NULL) != 0) ++i; sprintf (buf, "%u", i); o = variable_buffer_output (o, buf, strlen (buf)); return o; } /* Set begpp to point to the first non-whitespace character of the string, * and endpp to point to the last non-whitespace character of the string. * If the string is empty or contains nothing but whitespace, endpp will be * begpp-1. */ char * strip_whitespace (const char **begpp, const char **endpp) { while (*begpp <= *endpp && ISSPACE (**begpp)) (*begpp) ++; while (*endpp >= *begpp && ISSPACE (**endpp)) (*endpp) --; return (char *)*begpp; } static long long parse_numeric (const char *s, const char *msg) { const char *beg = s; const char *end = s + strlen (s) - 1; char *endp; long long num; strip_whitespace (&beg, &end); if (beg > end) OS (fatal, *expanding_var, _("%s: empty value"), msg); errno = 0; num = strtoll (beg, &endp, 10); if (errno == ERANGE) OSS (fatal, *expanding_var, _("%s: '%s' out of range"), msg, s); else if (endp == beg || endp <= end) /* Empty or non-numeric input */ OSS (fatal, *expanding_var, "%s: '%s'", msg, s); return num; } static char * func_word (char *o, char **argv, const char *funcname UNUSED) { const char *end_p; const char *p; long long i; i = parse_numeric (argv[0], _("invalid first argument to 'word' function")); if (i < 1) O (fatal, *expanding_var, _("first argument to 'word' function must be greater than 0")); end_p = argv[1]; while ((p = find_next_token (&end_p, 0)) != 0) if (--i == 0) break; if (i == 0) o = variable_buffer_output (o, p, end_p - p); return o; } static char * func_wordlist (char *o, char **argv, const char *funcname UNUSED) { char buf[INTSTR_LENGTH + 1]; long long start, stop, count; const char* badfirst = _("invalid first argument to 'wordlist' function"); const char* badsecond = _("invalid second argument to 'wordlist' function"); start = parse_numeric (argv[0], badfirst); if (start < 1) OSS (fatal, *expanding_var, "%s: '%s'", badfirst, make_lltoa (start, buf)); stop = parse_numeric (argv[1], badsecond); if (stop < 0) OSS (fatal, *expanding_var, "%s: '%s'", badsecond, make_lltoa (stop, buf)); count = stop - start + 1; if (count > 0) { const char *p; const char *end_p = argv[2]; /* Find the beginning of the "start"th word. */ while (((p = find_next_token (&end_p, 0)) != 0) && --start) ; if (p) { /* Find the end of the "count"th word from start. */ while (--count && (find_next_token (&end_p, 0) != 0)) ; /* Return the stuff in the middle. */ o = variable_buffer_output (o, p, end_p - p); } } return o; } static char * func_findstring (char *o, char **argv, const char *funcname UNUSED) { /* Find the first occurrence of the first string in the second. */ if (strstr (argv[1], argv[0]) != 0) o = variable_buffer_output (o, argv[0], strlen (argv[0])); return o; } static char * func_foreach (char *o, char **argv, const char *funcname UNUSED) { /* expand only the first two. */ char *varname = expand_argument (argv[0], NULL); char *list = expand_argument (argv[1], NULL); const char *body = argv[2]; int doneany = 0; const char *list_iterator = list; const char *p; size_t len; struct variable *var; /* Clean up the variable name by removing whitespace. */ char *vp = next_token (varname); end_of_token (vp)[0] = '\0'; push_new_variable_scope (); var = define_variable (vp, strlen (vp), "", o_automatic, 0); /* loop through LIST, put the value in VAR and expand BODY */ while ((p = find_next_token (&list_iterator, &len)) != 0) { char *result = 0; free (var->value); var->value = xstrndup (p, len); result = allocated_expand_string (body); o = variable_buffer_output (o, result, strlen (result)); o = variable_buffer_output (o, " ", 1); doneany = 1; free (result); } if (doneany) /* Kill the last space. */ --o; pop_variable_scope (); free (varname); free (list); return o; } static char * func_let (char *o, char **argv, const char *funcname UNUSED) { /* expand only the first two. */ char *varnames = expand_argument (argv[0], NULL); char *list = expand_argument (argv[1], NULL); const char *body = argv[2]; const char *vp; const char *vp_next = varnames; const char *list_iterator = list; size_t vlen; push_new_variable_scope (); /* loop through LIST for all but the last VARNAME */ vp = find_next_token (&vp_next, &vlen); NEXT_TOKEN (vp_next); while (*vp_next != '\0') { size_t len; char *p = find_next_token (&list_iterator, &len); if (p && *list_iterator != '\0') { ++list_iterator; p[len] = '\0'; } define_variable (vp, vlen, p ? p : "", o_automatic, 0); vp = find_next_token (&vp_next, &vlen); NEXT_TOKEN (vp_next); } /* set the last VARNAME to the remainder of LIST */ if (vp) define_variable (vp, vlen, next_token (list_iterator), o_automatic, 0); /* Expand the body in the context of the arguments, adding the result to the variable buffer. */ o = expand_string_buf (o, body, SIZE_MAX); pop_variable_scope (); free (varnames); free (list); return o + strlen (o); } struct a_word { struct a_word *chain; char *str; size_t length; int matched; }; static unsigned long a_word_hash_1 (const void *key) { return_STRING_HASH_1 (((struct a_word const *) key)->str); } static unsigned long a_word_hash_2 (const void *key) { return_STRING_HASH_2 (((struct a_word const *) key)->str); } static int a_word_hash_cmp (const void *x, const void *y) { const struct a_word *ax = x; const struct a_word *ay = y; if (ax->length != ay->length) return ax->length > ay->length ? 1 : -1; return_STRING_N_COMPARE (ax->str, ay->str, ax->length); } struct a_pattern { char *str; char *percent; size_t length; }; static char * func_filter_filterout (char *o, char **argv, const char *funcname) { struct a_word *words; struct a_word *word_end; struct a_word *wp; struct a_pattern *patterns; struct a_pattern *pat_end; struct a_pattern *pp; unsigned long pat_count = 0, word_count = 0; struct hash_table a_word_table; int is_filter = funcname[CSTRLEN ("filter")] == '\0'; const char *cp; int literals = 0; int hashing = 0; char *p; size_t len; int doneany = 0; /* Find the number of words and get memory for them. */ cp = argv[1]; while ((p = find_next_token (&cp, NULL)) != 0) ++word_count; if (!word_count) return o; words = xcalloc (word_count * sizeof (struct a_word)); word_end = words + word_count; /* Find the number of patterns and get memory for them. */ cp = argv[0]; while ((p = find_next_token (&cp, NULL)) != 0) ++pat_count; patterns = xcalloc (pat_count * sizeof (struct a_pattern)); pat_end = patterns + pat_count; /* Chop argv[0] up into patterns to match against the words. */ cp = argv[0]; pp = patterns; while ((p = find_next_token (&cp, &len)) != 0) { if (*cp != '\0') ++cp; p[len] = '\0'; pp->str = p; pp->percent = find_percent (p); if (pp->percent == 0) literals++; /* find_percent() might shorten the string so LEN is wrong. */ pp->length = strlen (pp->str); ++pp; } /* Chop ARGV[1] up into words to match against the patterns. */ cp = argv[1]; wp = words; while ((p = find_next_token (&cp, &len)) != 0) { if (*cp != '\0') ++cp; p[len] = '\0'; wp->str = p; wp->length = len; ++wp; } /* Only use a hash table if arg list lengths justifies the cost. */ hashing = (literals > 1 && (literals * word_count) >= 10); if (hashing) { hash_init (&a_word_table, word_count, a_word_hash_1, a_word_hash_2, a_word_hash_cmp); for (wp = words; wp < word_end; ++wp) { struct a_word *owp = hash_insert (&a_word_table, wp); if (owp) wp->chain = owp; } } /* Run each pattern through the words, killing words. */ for (pp = patterns; pp < pat_end; ++pp) { if (pp->percent) for (wp = words; wp < word_end; ++wp) wp->matched |= pattern_matches (pp->str, pp->percent, wp->str); else if (hashing) { struct a_word a_word_key; a_word_key.str = pp->str; a_word_key.length = pp->length; wp = hash_find_item (&a_word_table, &a_word_key); while (wp) { wp->matched |= 1; wp = wp->chain; } } else for (wp = words; wp < word_end; ++wp) wp->matched |= (wp->length == pp->length && memcmp (pp->str, wp->str, wp->length) == 0); } /* Output the words that matched (or didn't, for filter-out). */ for (wp = words; wp < word_end; ++wp) if (is_filter ? wp->matched : !wp->matched) { o = variable_buffer_output (o, wp->str, strlen (wp->str)); o = variable_buffer_output (o, " ", 1); doneany = 1; } if (doneany) /* Kill the last space. */ --o; if (hashing) hash_free (&a_word_table, 0); free (patterns); free (words); return o; } static char * func_strip (char *o, char **argv, const char *funcname UNUSED) { const char *p = argv[0]; int doneany = 0; while (*p != '\0') { int i=0; const char *word_start; NEXT_TOKEN (p); word_start = p; for (i=0; *p != '\0' && !ISSPACE (*p); ++p, ++i) {} if (!i) break; o = variable_buffer_output (o, word_start, i); o = variable_buffer_output (o, " ", 1); doneany = 1; } if (doneany) /* Kill the last space. */ --o; return o; } /* Print a warning or fatal message. */ static char * func_error (char *o, char **argv, const char *funcname) { switch (*funcname) { case 'e': OS (fatal, reading_file, "%s", argv[0]); case 'w': OS (error, reading_file, "%s", argv[0]); break; case 'i': { size_t len = strlen (argv[0]); char *msg = xmalloc (len + 2); memcpy (msg, argv[0], len); msg[len] = '\n'; msg[len + 1] = '\0'; outputs (0, msg); free (msg); break; } default: OS (fatal, *expanding_var, "INTERNAL: func_error: '%s'", funcname); } /* The warning function expands to the empty string. */ return o; } /* chop argv[0] into words, and sort them. */ static char * func_sort (char *o, char **argv, const char *funcname UNUSED) { const char *t; char **words; int wordi; char *p; size_t len; /* Find the maximum number of words we'll have. */ t = argv[0]; wordi = 0; while ((p = find_next_token (&t, NULL)) != 0) { ++t; ++wordi; } words = xmalloc ((wordi == 0 ? 1 : wordi) * sizeof (char *)); /* Now assign pointers to each string in the array. */ t = argv[0]; wordi = 0; while ((p = find_next_token (&t, &len)) != 0) { ++t; p[len] = '\0'; words[wordi++] = p; } if (wordi) { int i; /* Now sort the list of words. */ qsort (words, wordi, sizeof (char *), alpha_compare); /* Now write the sorted list, uniquified. */ for (i = 0; i < wordi; ++i) { len = strlen (words[i]); if (i == wordi - 1 || strlen (words[i + 1]) != len || memcmp (words[i], words[i + 1], len)) { o = variable_buffer_output (o, words[i], len); o = variable_buffer_output (o, " ", 1); } } /* Kill the last space. */ --o; } free (words); return o; } /* Traverse NUMBER consisting of optional leading white space, optional sign, digits, and optional trailing white space. If number is not of the proper form, diagnose with MSG. Otherwise, return the address of of the first character after NUMBER, store into *SIGN an integer consistent with the number's sign (-1, 0, or 1) and store into *NUMSTART the address of NUMBER's first nonzero digit (if NUMBER contains only zero digits, store the address of the first character after NUMBER). */ static const char * parse_textint (const char *number, const char *msg, int *sign, const char **numstart) { const char *after_sign, *after_number; const char *p = next_token (number); int negative = *p == '-'; int nonzero; if (*p == '\0') OS (fatal, *expanding_var, _("%s: empty value"), msg); p += negative || *p == '+'; after_sign = p; while (*p == '0') p++; *numstart = p; while (ISDIGIT (*p)) ++p; after_number = p; nonzero = *numstart != after_number; *sign = negative ? -nonzero : nonzero; /* Check for extra non-whitespace stuff after the value. */ if (after_number == after_sign || *next_token (p) != '\0') OSS (fatal, *expanding_var, "%s: '%s'", msg, number); return after_number; } /* $(intcmp lhs,rhs[,lt-part[,eq-part[,gt-part]]]) LHS and RHS must be integer values (leading/trailing whitespace is ignored). If none of LT-PART, EQ-PART, or GT-PART are given then the function expands to empty if LHS and RHS are not equal, or the numeric value if they are equal. LT-PART is evaluated when LHS is strictly less than RHS, EQ-PART is evaluated when LHS is equal to RHS, and GT-part is evaluated when LHS is strictly greater than RHS. If GT-PART is not provided, it defaults to EQ-PART. When neither EQ-PART nor GT-PART are provided, the function expands to empty if LHS is not strictly less than RHS. */ static char * func_intcmp (char *o, char **argv, const char *funcname UNUSED) { int lsign, rsign; const char *lnum, *rnum; char *lhs_str = expand_argument (argv[0], NULL); char *rhs_str = expand_argument (argv[1], NULL); const char *llim = parse_textint (lhs_str, _("non-numeric first argument to 'intcmp' function"), &lsign, &lnum); const char *rlim = parse_textint (rhs_str, _("non-numeric second argument to 'intcmp' function"), &rsign, &rnum); ptrdiff_t llen = llim - lnum; ptrdiff_t rlen = rlim - rnum; int cmp = lsign - rsign; if (cmp == 0) { cmp = (llen > rlen) - (llen < rlen); if (cmp == 0) cmp = memcmp (lnum, rnum, llen); if (lsign < 0) cmp *= -1; } argv += 2; /* Handle the special case where there are only two arguments. */ if (!*argv && cmp == 0) { if (lsign < 0) o = variable_buffer_output (o, "-", 1); o = variable_buffer_output(o, lnum - !lsign, llen + !lsign); } free (lhs_str); free (rhs_str); if (*argv && cmp >= 0) { ++argv; if (cmp > 0 && *argv && *(argv + 1)) ++argv; } if (*argv) { char *expansion = expand_argument (*argv, NULL); o = variable_buffer_output (o, expansion, strlen (expansion)); free (expansion); } return o; } /* $(if condition,true-part[,false-part]) CONDITION is false iff it evaluates to an empty string. White space before and after condition are stripped before evaluation. If CONDITION is true, then TRUE-PART is evaluated, otherwise FALSE-PART is evaluated (if it exists). Because only one of the two PARTs is evaluated, you can use $(if ...) to create side-effects (with $(shell ...), for example). */ static char * func_if (char *o, char **argv, const char *funcname UNUSED) { const char *begp = argv[0]; const char *endp = begp + strlen (argv[0]) - 1; int result = 0; /* Find the result of the condition: if we have a value, and it's not empty, the condition is true. If we don't have a value, or it's the empty string, then it's false. */ strip_whitespace (&begp, &endp); if (begp <= endp) { char *expansion = expand_argument (begp, endp+1); result = expansion[0] != '\0'; free (expansion); } /* If the result is true (1) we want to eval the first argument, and if it's false (0) we want to eval the second. If the argument doesn't exist we do nothing, otherwise expand it and add to the buffer. */ argv += 1 + !result; if (*argv) { char *expansion = expand_argument (*argv, NULL); o = variable_buffer_output (o, expansion, strlen (expansion)); free (expansion); } return o; } /* $(or condition1[,condition2[,condition3[...]]]) A CONDITION is false iff it evaluates to an empty string. White space before and after CONDITION are stripped before evaluation. CONDITION1 is evaluated. If it's true, then this is the result of expansion. If it's false, CONDITION2 is evaluated, and so on. If none of the conditions are true, the expansion is the empty string. Once a CONDITION is true no further conditions are evaluated (short-circuiting). */ static char * func_or (char *o, char **argv, const char *funcname UNUSED) { for ( ; *argv ; ++argv) { const char *begp = *argv; const char *endp = begp + strlen (*argv) - 1; char *expansion; size_t result = 0; /* Find the result of the condition: if it's false keep going. */ strip_whitespace (&begp, &endp); if (begp > endp) continue; expansion = expand_argument (begp, endp+1); result = strlen (expansion); /* If the result is false keep going. */ if (!result) { free (expansion); continue; } /* It's true! Keep this result and return. */ o = variable_buffer_output (o, expansion, result); free (expansion); break; } return o; } /* $(and condition1[,condition2[,condition3[...]]]) A CONDITION is false iff it evaluates to an empty string. White space before and after CONDITION are stripped before evaluation. CONDITION1 is evaluated. If it's false, then this is the result of expansion. If it's true, CONDITION2 is evaluated, and so on. If all of the conditions are true, the expansion is the result of the last condition. Once a CONDITION is false no further conditions are evaluated (short-circuiting). */ static char * func_and (char *o, char **argv, const char *funcname UNUSED) { char *expansion; while (1) { const char *begp = *argv; const char *endp = begp + strlen (*argv) - 1; size_t result; /* An empty condition is always false. */ strip_whitespace (&begp, &endp); if (begp > endp) return o; expansion = expand_argument (begp, endp+1); result = strlen (expansion); /* If the result is false, stop here: we're done. */ if (!result) break; /* Otherwise the result is true. If this is the last one, keep this result and quit. Otherwise go on to the next one! */ if (*(++argv)) free (expansion); else { o = variable_buffer_output (o, expansion, result); break; } } free (expansion); return o; } static char * func_wildcard (char *o, char **argv, const char *funcname UNUSED) { char *p = string_glob (argv[0]); o = variable_buffer_output (o, p, strlen (p)); return o; } /* $(eval ) Always resolves to the empty string. Treat the arguments as a segment of makefile, and parse them. */ static char * func_eval (char *o, char **argv, const char *funcname UNUSED) { char *buf; size_t len; /* Eval the buffer. Pop the current variable buffer setting so that the eval'd code can use its own without conflicting. */ install_variable_buffer (&buf, &len); eval_buffer (argv[0], NULL); restore_variable_buffer (buf, len); return o; } static char * func_value (char *o, char **argv, const char *funcname UNUSED) { /* Look up the variable. */ struct variable *v = lookup_variable (argv[0], strlen (argv[0])); /* Copy its value into the output buffer without expanding it. */ if (v) o = variable_buffer_output (o, v->value, strlen (v->value)); return o; } /* \r is replaced on UNIX as well. Is this desirable? */ static void fold_newlines (char *buffer, size_t *length, int trim_newlines) { char *dst = buffer; char *src = buffer; char *last_nonnl = buffer - 1; src[*length] = 0; for (; *src != '\0'; ++src) { if (src[0] == '\r' && src[1] == '\n') continue; if (*src == '\n') { *dst++ = ' '; } else { last_nonnl = dst; *dst++ = *src; } } if (!trim_newlines && (last_nonnl < (dst - 2))) last_nonnl = dst - 2; *(++last_nonnl) = '\0'; *length = last_nonnl - buffer; } pid_t shell_function_pid = 0; static int shell_function_completed; void shell_completed (int exit_code, int exit_sig) { char buf[INTSTR_LENGTH]; shell_function_pid = 0; if (exit_sig == 0 && exit_code == 127) shell_function_completed = -1; else shell_function_completed = 1; if (exit_code == 0 && exit_sig > 0) exit_code = 128 + exit_sig; sprintf (buf, "%d", exit_code); define_variable_cname (".SHELLSTATUS", buf, o_override, 0); } #if MK_OS_W32 /*untested*/ #include #include #include "sub_proc.h" int windows32_openpipe (int *pipedes, int errfd, pid_t *pid_p, char **command_argv, char **envp) { SECURITY_ATTRIBUTES saAttr; HANDLE hIn = INVALID_HANDLE_VALUE; HANDLE hErr = INVALID_HANDLE_VALUE; HANDLE hChildOutRd; HANDLE hChildOutWr; HANDLE hProcess, tmpIn, tmpErr; DWORD e; /* Set status for return. */ pipedes[0] = pipedes[1] = -1; *pid_p = (pid_t)-1; saAttr.nLength = sizeof (SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; /* Standard handles returned by GetStdHandle can be NULL or INVALID_HANDLE_VALUE if the parent process closed them. If that happens, we open the null device and pass its handle to process_begin below as the corresponding handle to inherit. */ tmpIn = GetStdHandle (STD_INPUT_HANDLE); if (DuplicateHandle (GetCurrentProcess (), tmpIn, GetCurrentProcess (), &hIn, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { e = GetLastError (); if (e == ERROR_INVALID_HANDLE) { tmpIn = CreateFile ("NUL", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (tmpIn != INVALID_HANDLE_VALUE && DuplicateHandle (GetCurrentProcess (), tmpIn, GetCurrentProcess (), &hIn, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) CloseHandle (tmpIn); } if (hIn == INVALID_HANDLE_VALUE) { ON (error, NILF, _("windows32_openpipe: DuplicateHandle(In) failed (e=%lu)"), e); return -1; } } tmpErr = get_handle_for_fd (errfd); if (DuplicateHandle (GetCurrentProcess (), tmpErr, GetCurrentProcess (), &hErr, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { e = GetLastError (); if (e == ERROR_INVALID_HANDLE) { tmpErr = CreateFile ("NUL", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (tmpErr != INVALID_HANDLE_VALUE && DuplicateHandle (GetCurrentProcess (), tmpErr, GetCurrentProcess (), &hErr, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) CloseHandle (tmpErr); } if (hErr == INVALID_HANDLE_VALUE) { ON (error, NILF, _("windows32_openpipe: DuplicateHandle(Err) failed (e=%lu)"), e); return -1; } } if (! CreatePipe (&hChildOutRd, &hChildOutWr, &saAttr, 0)) { ON (error, NILF, _("CreatePipe() failed (e=%lu)"), GetLastError()); return -1; } hProcess = process_init_fd (hIn, hChildOutWr, hErr); if (!hProcess) { O (error, NILF, _("windows32_openpipe(): process_init_fd() failed")); return -1; } if (! process_begin (hProcess, command_argv, envp, command_argv[0], NULL)) { /* register process for wait */ process_register (hProcess); /* set the pid for returning to caller */ *pid_p = (pid_t) hProcess; /* set up to read data from child */ pipedes[0] = _open_osfhandle ((intptr_t) hChildOutRd, O_RDONLY); /* this will be closed almost right away */ pipedes[1] = _open_osfhandle ((intptr_t) hChildOutWr, O_APPEND); return 0; } else { /* reap/cleanup the failed process */ process_cleanup (hProcess); /* close handles which were duplicated, they weren't used */ if (hIn != INVALID_HANDLE_VALUE) CloseHandle (hIn); if (hErr != INVALID_HANDLE_VALUE) CloseHandle (hErr); /* close pipe handles, they won't be used */ CloseHandle (hChildOutRd); CloseHandle (hChildOutWr); return -1; } } #endif #if MK_OS_DOS FILE * msdos_openpipe (int* pipedes, int *pidp, char *text) { FILE *fpipe=0; /* MSDOS can't fork, but it has 'popen'. */ struct variable *sh = lookup_variable ("SHELL", 5); int e; extern int dos_command_running, dos_status; /* Make sure not to bother processing an empty line. */ NEXT_TOKEN (text); if (*text == '\0') return 0; if (sh) { char buf[PATH_MAX + 7]; /* This makes sure $SHELL value is used by $(shell), even though the target environment is not passed to it. */ sprintf (buf, "SHELL=%s", sh->value); putenv (buf); } e = errno; errno = 0; dos_command_running = 1; dos_status = 0; /* If dos_status becomes non-zero, it means the child process was interrupted by a signal, like SIGINT or SIGQUIT. See fatal_error_signal in commands.c. */ fpipe = popen (text, "rt"); dos_command_running = 0; if (!fpipe || dos_status) { pipedes[0] = -1; *pidp = -1; if (dos_status) errno = EINTR; else if (errno == 0) errno = ENOMEM; if (fpipe) pclose (fpipe); shell_completed (127, 0); } else { pipedes[0] = fileno (fpipe); *pidp = 42; /* Yes, the Meaning of Life, the Universe, and Everything! */ errno = e; } return fpipe; } #endif /* Do shell spawning, with the naughty bits for different OSes. */ #if MK_OS_VMS /* VMS can't do $(shell ...) */ char * func_shell_base (char *o, char **argv, int trim_newlines) { fprintf (stderr, "This platform does not support shell\n"); die (MAKE_TROUBLE); return NULL; } #define func_shell 0 #else char * func_shell_base (char *o, char **argv, int trim_newlines) { struct childbase child = {0}; char *batch_filename = NULL; int errfd; #if MK_OS_DOS FILE *fpipe; #endif char **command_argv = NULL; int pipedes[2]; pid_t pid; #if !MK_OS_DOS #if MK_OS_W32 /* Reset just_print_flag. This is needed on Windows when batch files are used to run the commands, because we normally refrain from creating batch files under -n. */ int j_p_f = just_print_flag; just_print_flag = 0; #endif /* Construct the argument list. */ command_argv = construct_command_argv (argv[0], NULL, NULL, 0, &batch_filename); if (command_argv == 0) { #if MK_OS_W32 just_print_flag = j_p_f; #endif return o; } #endif /* !MK_OS_DOS */ /* Set up the output in case the shell writes something. */ output_start (); errfd = (output_context && output_context->err >= 0 ? output_context->err : FD_STDERR); child.environment = target_environment (NULL, 0); #if MK_OS_DOS fpipe = msdos_openpipe (pipedes, &pid, argv[0]); if (pipedes[0] < 0) { OS (error, reading_file, "pipe: %s", strerror (errno)); pid = -1; goto done; } #elif MK_OS_W32 windows32_openpipe (pipedes, errfd, &pid, command_argv, child.environment); /* Restore the value of just_print_flag. */ just_print_flag = j_p_f; if (pipedes[0] < 0) { /* Open of the pipe failed, mark as failed execution. */ shell_completed (127, 0); OS (error, reading_file, "pipe: %s", strerror (errno)); pid = -1; goto done; } #else if (pipe (pipedes) < 0) { OS (error, reading_file, "pipe: %s", strerror (errno)); pid = -1; goto done; } /* Close handles that are unnecessary for the child process. */ fd_noinherit (pipedes[1]); fd_noinherit (pipedes[0]); child.output.syncout = 1; child.output.out = pipedes[1]; child.output.err = errfd; pid = child_execute_job (&child, 1, command_argv); if (pid < 0) { shell_completed (127, 0); goto done; } #endif { char *buffer; size_t maxlen, i; int cc; /* Record the PID for reap_children. */ shell_function_pid = pid; #if !MK_OS_DOS shell_function_completed = 0; /* Close the write side of the pipe. We test for -1, since pipedes[1] is -1 on MS-Windows, and some versions of MS libraries barf when 'close' is called with -1. */ if (pipedes[1] >= 0) close (pipedes[1]); #endif /* Set up and read from the pipe. */ maxlen = 200; buffer = xmalloc (maxlen + 1); /* Read from the pipe until it gets EOF. */ for (i = 0; ; i += cc) { if (i == maxlen) { maxlen += 512; buffer = xrealloc (buffer, maxlen + 1); } EINTRLOOP (cc, read (pipedes[0], &buffer[i], maxlen - i)); if (cc <= 0) break; } buffer[i] = '\0'; /* Close the read side of the pipe. */ #if MK_OS_DOS if (fpipe) { int st = pclose (fpipe); shell_completed (st, 0); } #else (void) close (pipedes[0]); #endif /* Loop until child_handler or reap_children() sets shell_function_completed to the status of our child shell. */ while (shell_function_completed == 0) reap_children (1, 0); if (batch_filename) { DB (DB_VERBOSE, (_("Cleaning up temporary batch file %s\n"), batch_filename)); remove (batch_filename); free (batch_filename); } shell_function_pid = 0; /* Replace all newlines in the command's output with spaces, and put that in the variable output buffer. */ fold_newlines (buffer, &i, trim_newlines); o = variable_buffer_output (o, buffer, i); free (buffer); } done: if (command_argv) { /* Free the storage only the child needed. */ free (command_argv[0]); free (command_argv); } free_childbase (&child); return o; } static char * func_shell (char *o, char **argv, const char *funcname UNUSED) { return func_shell_base (o, argv, 1); } #endif /* !MK_OS_VMS */ #ifdef EXPERIMENTAL /* equality. Return is string-boolean, i.e., the empty string is false. */ static char * func_eq (char *o, char **argv, char *funcname UNUSED) { int result = ! strcmp (argv[0], argv[1]); if (result) o = variable_buffer_output (o, "1", 1); return o; } /* string-boolean not operator. */ static char * func_not (char *o, char **argv, char *funcname UNUSED) { const char *s = argv[0]; int result = 0; NEXT_TOKEN (s); result = ! (*s); if (result) o = variable_buffer_output (o, "1", 1); return o; } #endif #ifdef HAVE_DOS_PATHS # ifdef __CYGWIN__ # define IS_ABSOLUTE(n) ((n[0] && n[1] == ':') || ISDIRSEP (n[0])) # else # define IS_ABSOLUTE(n) (n[0] && n[1] == ':') # endif # define ROOT_LEN 3 #else # define IS_ABSOLUTE(n) (n[0] == '/') # define ROOT_LEN 1 #endif /* Return the absolute name of file NAME which does not contain any '.', '..' components nor any repeated path separators ('/'). */ static char * abspath (const char *name, char *apath) { char *dest; const char *start, *end, *apath_limit; unsigned long root_len = ROOT_LEN; if (name[0] == '\0') return NULL; apath_limit = apath + GET_PATH_MAX; if (!IS_ABSOLUTE(name)) { /* It is unlikely we would make it until here but just to make sure. */ if (!starting_directory) return NULL; strcpy (apath, starting_directory); #ifdef HAVE_DOS_PATHS if (ISDIRSEP (name[0])) { if (ISDIRSEP (name[1])) { /* A UNC. Don't prepend a drive letter. */ apath[0] = name[0]; apath[1] = name[1]; root_len = 2; } /* We have /foo, an absolute file name except for the drive letter. Assume the missing drive letter is the current drive, which we can get if we remove from starting_directory everything past the root directory. */ apath[root_len] = '\0'; } #endif dest = strchr (apath, '\0'); } else { #if defined(__CYGWIN__) && defined(HAVE_DOS_PATHS) if (ISDIRSEP (name[0])) root_len = 1; #endif memcpy (apath, name, root_len); apath[root_len] = '\0'; dest = apath + root_len; /* Get past the root, since we already copied it. */ name += root_len; #ifdef HAVE_DOS_PATHS if (! ISDIRSEP (apath[root_len - 1])) { /* Convert d:foo into d:./foo and increase root_len. */ apath[2] = '.'; apath[3] = '/'; dest++; root_len++; /* strncpy above copied one character too many. */ name--; } else apath[root_len - 1] = '/'; /* make sure it's a forward slash */ #endif } for (start = end = name; *start != '\0'; start = end) { size_t len; /* Skip sequence of multiple path-separators. */ while (ISDIRSEP (*start)) ++start; /* Find end of path component. */ for (end = start; ! STOP_SET (*end, MAP_DIRSEP|MAP_NUL); ++end) ; len = end - start; if (len == 0) break; else if (len == 1 && start[0] == '.') /* nothing */; else if (len == 2 && start[0] == '.' && start[1] == '.') { /* Back up to previous component, ignore if at root already. */ if (dest > apath + root_len) for (--dest; ! ISDIRSEP (dest[-1]); --dest) ; } else { if (! ISDIRSEP (dest[-1])) *dest++ = '/'; if (dest + len >= apath_limit) return NULL; dest = mempcpy (dest, start, len); *dest = '\0'; } } /* Unless it is root strip trailing separator. */ if (dest > apath + root_len && ISDIRSEP (dest[-1])) --dest; *dest = '\0'; return apath; } static char * func_realpath (char *o, char **argv, const char *funcname UNUSED) { /* Expand the argument. */ const char *p = argv[0]; const char *path = 0; int doneany = 0; size_t len = 0; while ((path = find_next_token (&p, &len)) != 0) { if (len < GET_PATH_MAX) { char *rp; struct stat st; PATH_VAR (in); PATH_VAR (out); strncpy (in, path, len); in[len] = '\0'; #ifdef HAVE_REALPATH ENULLLOOP (rp, realpath (in, out)); # if defined _AIX /* AIX realpath() doesn't remove trailing slashes correctly. */ if (rp) { char *ep = rp + strlen (rp) - 1; while (ep > rp && ep[0] == '/') *(ep--) = '\0'; } # endif #else rp = abspath (in, out); #endif if (rp) { int r; EINTRLOOP (r, stat (out, &st)); if (r == 0) { o = variable_buffer_output (o, out, strlen (out)); o = variable_buffer_output (o, " ", 1); doneany = 1; } } } } /* Kill last space. */ if (doneany) --o; return o; } static char * func_file (char *o, char **argv, const char *funcname UNUSED) { char *fn = argv[0]; if (fn[0] == '>') { size_t len; const char *end; const char *start; char *nm; FILE *fp; const char *mode = "w"; /* We are writing a file. */ ++fn; if (fn[0] == '>') { mode = "a"; ++fn; } start = next_token (fn); if (start[0] == '\0') O (fatal, *expanding_var, _("file: missing filename")); end = end_of_token (start); len = end - start; nm = alloca (len + 1); memcpy (nm, start, len); nm[len] = '\0'; ENULLLOOP (fp, fopen (nm, mode)); if (fp == NULL) OSS (fatal, reading_file, _("open: %s: %s"), nm, strerror (errno)); /* We've changed the contents of a directory, possibly. Another option would be to look up the directory we changed and reset its counter to 0. */ ++command_count; if (argv[1]) { size_t l = strlen (argv[1]); int nl = l == 0 || argv[1][l-1] != '\n'; if (fputs (argv[1], fp) == EOF || (nl && fputc ('\n', fp) == EOF)) OSS (fatal, reading_file, _("write: %s: %s"), nm, strerror (errno)); } if (fclose (fp)) OSS (fatal, reading_file, _("close: %s: %s"), nm, strerror (errno)); } else if (fn[0] == '<') { size_t n = 0; size_t len; const char *end; const char *start; char *nm; FILE *fp; start = next_token (fn + 1); if (start[0] == '\0') O (fatal, *expanding_var, _("file: missing filename")); if (argv[1]) O (fatal, *expanding_var, _("file: too many arguments")); end = end_of_token (start); len = end - start; nm = alloca (len + 1); memcpy (nm, start, len); nm[len] = '\0'; ENULLLOOP (fp, fopen (nm, "r")); if (fp == NULL) { if (errno == ENOENT) { DB (DB_VERBOSE, (_("file: Failed to open '%s': %s\n"), nm, strerror (errno))); return o; } OSS (fatal, reading_file, _("open: %s: %s"), nm, strerror (errno)); } while (1) { char buf[1024]; size_t l = fread (buf, 1, sizeof (buf), fp); if (l > 0) { o = variable_buffer_output (o, buf, l); n += l; } if (ferror (fp)) if (errno != EINTR) OSS (fatal, reading_file, _("read: %s: %s"), nm, strerror (errno)); if (feof (fp)) break; } if (fclose (fp)) OSS (fatal, reading_file, _("close: %s: %s"), nm, strerror (errno)); /* Remove trailing newline. */ if (n && o[-1] == '\n') o -= 1 + (n > 1 && o[-2] == '\r'); } else OS (fatal, *expanding_var, _("file: invalid file operation: %s"), fn); return o; } static char * func_abspath (char *o, char **argv, const char *funcname UNUSED) { /* Expand the argument. */ const char *p = argv[0]; const char *path = 0; int doneany = 0; size_t len = 0; while ((path = find_next_token (&p, &len)) != 0) { if (len < GET_PATH_MAX) { PATH_VAR (in); PATH_VAR (out); strncpy (in, path, len); in[len] = '\0'; if (abspath (in, out)) { o = variable_buffer_output (o, out, strlen (out)); o = variable_buffer_output (o, " ", 1); doneany = 1; } } } /* Kill last space. */ if (doneany) --o; return o; } /* Lookup table for builtin functions. This doesn't have to be sorted; we use a straight lookup. We might gain some efficiency by moving most often used functions to the start of the table. If MAXIMUM_ARGS is 0, that means there is no maximum and all comma-separated values are treated as arguments. EXPAND_ARGS means that all arguments should be expanded before invocation. Functions that do namespace tricks (foreach, let) don't automatically expand. */ static char *func_call (char *o, char **argv, const char *funcname); #define FT_ENTRY(_name, _min, _max, _exp, _func) \ { { (_func) }, STRING_SIZE_TUPLE(_name), (_min), (_max), (_exp), 0, 0 } static struct function_table_entry function_table_init[] = { /* Name MIN MAX EXP? Function */ FT_ENTRY ("abspath", 0, 1, 1, func_abspath), FT_ENTRY ("addprefix", 2, 2, 1, func_addsuffix_addprefix), FT_ENTRY ("addsuffix", 2, 2, 1, func_addsuffix_addprefix), FT_ENTRY ("and", 1, 0, 0, func_and), FT_ENTRY ("basename", 0, 1, 1, func_basename_dir), FT_ENTRY ("call", 1, 0, 1, func_call), FT_ENTRY ("dir", 0, 1, 1, func_basename_dir), FT_ENTRY ("error", 0, 1, 1, func_error), FT_ENTRY ("eval", 0, 1, 1, func_eval), FT_ENTRY ("file", 1, 2, 1, func_file), FT_ENTRY ("filter", 2, 2, 1, func_filter_filterout), FT_ENTRY ("filter-out", 2, 2, 1, func_filter_filterout), FT_ENTRY ("findstring", 2, 2, 1, func_findstring), FT_ENTRY ("firstword", 0, 1, 1, func_firstword), FT_ENTRY ("flavor", 0, 1, 1, func_flavor), FT_ENTRY ("foreach", 3, 3, 0, func_foreach), FT_ENTRY ("if", 2, 3, 0, func_if), FT_ENTRY ("info", 0, 1, 1, func_error), FT_ENTRY ("intcmp", 2, 5, 0, func_intcmp), FT_ENTRY ("join", 2, 2, 1, func_join), FT_ENTRY ("lastword", 0, 1, 1, func_lastword), FT_ENTRY ("let", 3, 3, 0, func_let), FT_ENTRY ("notdir", 0, 1, 1, func_notdir_suffix), FT_ENTRY ("or", 1, 0, 0, func_or), FT_ENTRY ("origin", 0, 1, 1, func_origin), FT_ENTRY ("patsubst", 3, 3, 1, func_patsubst), FT_ENTRY ("realpath", 0, 1, 1, func_realpath), FT_ENTRY ("shell", 0, 1, 1, func_shell), FT_ENTRY ("sort", 0, 1, 1, func_sort), FT_ENTRY ("strip", 0, 1, 1, func_strip), FT_ENTRY ("subst", 3, 3, 1, func_subst), FT_ENTRY ("suffix", 0, 1, 1, func_notdir_suffix), FT_ENTRY ("value", 0, 1, 1, func_value), FT_ENTRY ("warning", 0, 1, 1, func_error), FT_ENTRY ("wildcard", 0, 1, 1, func_wildcard), FT_ENTRY ("word", 2, 2, 1, func_word), FT_ENTRY ("wordlist", 3, 3, 1, func_wordlist), FT_ENTRY ("words", 0, 1, 1, func_words), #ifdef EXPERIMENTAL FT_ENTRY ("eq", 2, 2, 1, func_eq), FT_ENTRY ("not", 0, 1, 1, func_not), #endif }; /* These must come after the definition of function_table. */ static char * expand_builtin_function (char *o, unsigned int argc, char **argv, const struct function_table_entry *entry_p) { char *p; if (argc < entry_p->minimum_args) fatal (*expanding_var, strlen (entry_p->name), _("insufficient number of arguments (%u) to function '%s'"), argc, entry_p->name); /* I suppose technically some function could do something with no arguments, but so far no internal ones do, so just test it for all functions here rather than in each one. We can change it later if necessary. */ if (!argc && !entry_p->alloc_fn) return o; if (!entry_p->fptr.func_ptr) OS (fatal, *expanding_var, _("unimplemented on this platform: function '%s'"), entry_p->name); if (entry_p->adds_command) ++command_count; if (!entry_p->alloc_fn) return entry_p->fptr.func_ptr (o, argv, entry_p->name); /* This function allocates memory and returns it to us. Write it to the variable buffer, then free it. */ p = entry_p->fptr.alloc_func_ptr (entry_p->name, argc, argv); if (p) { o = variable_buffer_output (o, p, strlen (p)); free (p); } return o; } /* Check for a function invocation in *STRINGP. *STRINGP points at the opening ( or { and is not null-terminated. If a function invocation is found, expand it into the buffer at *OP, updating *OP, incrementing *STRINGP past the reference, and return nonzero. If no function is found, return zero and don't change *OP or *STRINGP. */ int handle_function (char **op, const char **stringp) { const struct function_table_entry *entry_p; char openparen = (*stringp)[0]; char closeparen = openparen == '(' ? ')' : '}'; const char *beg; const char *end; int count = 0; char *abeg = NULL; char **argv, **argvp; unsigned int nargs; beg = *stringp + 1; entry_p = lookup_function (beg); if (!entry_p) return 0; /* We found a builtin function. Find the beginning of its arguments (skip whitespace after the name). */ beg += entry_p->len; NEXT_TOKEN (beg); /* Find the end of the function invocation, counting nested use of whichever kind of parens we use. Don't use skip_reference so we can count commas to get a rough estimate of how many arguments we might have. The count might be high, but it'll never be low. */ for (nargs=1, end=beg; *end != '\0'; ++end) if (!STOP_SET (*end, MAP_VARSEP|MAP_COMMA)) continue; else if (*end == ',') ++nargs; else if (*end == openparen) ++count; else if (*end == closeparen && --count < 0) break; if (count >= 0) fatal (*expanding_var, strlen (entry_p->name), _("unterminated call to function '%s': missing '%c'"), entry_p->name, closeparen); *stringp = end; /* Get some memory to store the arg pointers. */ argvp = argv = alloca (sizeof (char *) * (nargs + 2)); /* Chop the string into arguments, then a nul. As soon as we hit MAXIMUM_ARGS (if it's >0) assume the rest of the string is part of the last argument. If we're expanding, store pointers to the expansion of each one. If not, make a duplicate of the string and point into that, nul-terminating each argument. */ if (entry_p->expand_args) { const char *p; for (p=beg, nargs=0; p <= end; ++argvp) { const char *next; ++nargs; if (nargs == entry_p->maximum_args || ((next = find_next_argument (openparen, closeparen, p, end)) == NULL)) next = end; *argvp = expand_argument (p, next); p = next + 1; } } else { size_t len = end - beg; char *p, *aend; abeg = xmalloc (len+1); aend = mempcpy (abeg, beg, len); *aend = '\0'; for (p=abeg, nargs=0; p <= aend; ++argvp) { char *next; ++nargs; if (nargs == entry_p->maximum_args || ((next = find_next_argument (openparen, closeparen, p, aend)) == NULL)) next = aend; *argvp = p; *next = '\0'; p = next + 1; } } *argvp = NULL; /* Finally! Run the function... */ *op = expand_builtin_function (*op, nargs, argv, entry_p); /* Free memory. */ if (entry_p->expand_args) for (argvp=argv; *argvp != 0; ++argvp) free (*argvp); else free (abeg); return 1; } /* User-defined functions. Expand the first argument as either a builtin function or a make variable, in the context of the rest of the arguments assigned to $1, $2, ... $N. $0 is the name of the function. */ static char * func_call (char *o, char **argv, const char *funcname UNUSED) { static unsigned int max_args = 0; char *fname; size_t flen; unsigned int i; int saved_args; const struct function_table_entry *entry_p; struct variable *v; /* Clean up the name of the variable to be invoked. */ fname = next_token (argv[0]); end_of_token (fname)[0] = '\0'; /* Calling nothing is a no-op */ if (*fname == '\0') return o; /* Are we invoking a builtin function? */ entry_p = lookup_function (fname); if (entry_p) { /* How many arguments do we have? */ for (i=0; argv[i+1]; ++i) ; return expand_builtin_function (o, i, argv+1, entry_p); } /* Not a builtin, so the first argument is the name of a variable to be expanded and interpreted as a function. Find it. */ flen = strlen (fname); v = lookup_variable (fname, flen); if (v == 0) warn_undefined (fname, flen); if (v == 0 || *v->value == '\0') return o; /* Set up arguments $(1) .. $(N). $(0) is the function name. */ push_new_variable_scope (); for (i=0; *argv; ++i, ++argv) { char num[INTSTR_LENGTH]; sprintf (num, "%u", i); define_variable (num, strlen (num), *argv, o_automatic, 0); } /* If the number of arguments we have is < max_args, it means we're inside a recursive invocation of $(call ...). Fill in the remaining arguments in the new scope with the empty value, to hide them from this invocation. */ for (; i < max_args; ++i) { char num[INTSTR_LENGTH]; sprintf (num, "%u", i); define_variable (num, strlen (num), "", o_automatic, 0); } /* Expand the function in the context of the arguments, adding the result to the variable buffer. */ v->exp_count = EXP_COUNT_MAX; saved_args = max_args; max_args = i; o = expand_variable_output (o, fname, flen); max_args = saved_args; v->exp_count = 0; pop_variable_scope (); return o + strlen (o); } void define_new_function (const floc *flocp, const char *name, unsigned int min, unsigned int max, unsigned int flags, gmk_func_ptr func) { const char *e = name; struct function_table_entry *ent; size_t len; while (STOP_SET (*e, MAP_USERFUNC)) e++; len = e - name; if (len == 0) O (fatal, flocp, _("empty function name")); if (*name == '.' || *e != '\0') OS (fatal, flocp, _("invalid function name: %s"), name); if (len > 255) OS (fatal, flocp, _("function name too long: %s"), name); if (min > 255) ONS (fatal, flocp, _("invalid minimum argument count (%u) for function %s"), min, name); if (max > 255 || (max && max < min)) ONS (fatal, flocp, _("invalid maximum argument count (%u) for function %s"), max, name); ent = xmalloc (sizeof (struct function_table_entry)); ent->name = strcache_add (name); ent->len = (unsigned char) len; ent->minimum_args = (unsigned char) min; ent->maximum_args = (unsigned char) max; ent->expand_args = ANY_SET(flags, GMK_FUNC_NOEXPAND) ? 0 : 1; ent->alloc_fn = 1; /* We don't know what this function will do. */ ent->adds_command = 1; ent->fptr.alloc_func_ptr = func; ent = hash_insert (&function_table, ent); free (ent); } void hash_init_function_table (void) { hash_init (&function_table, ARRAYLEN (function_table_init) * 2, function_table_entry_hash_1, function_table_entry_hash_2, function_table_entry_hash_cmp); hash_load (&function_table, function_table_init, ARRAYLEN (function_table_init), sizeof (struct function_table_entry)); } ================================================ FILE: src/getopt.c ================================================ /* Getopt for GNU. NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! Copyright (C) 1987-2024 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@gnu.org. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO # define _NO_PROTO #endif #ifdef HAVE_CONFIG_H # include #endif #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ # ifndef const # define const # endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 # include # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION # define ELIDE_CODE # endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ # include # include #endif /* GNU C library. */ #if MK_OS_VMS # include # if HAVE_STRING_H - 0 # include # endif #endif /* This is for other GNU distributions with internationalized messages. When compiling libc, the _ macro is predefined. */ #include "gettext.h" #define _(msgid) gettext (msgid) /* This version of `getopt' appears to the caller like standard Unix 'getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of ARGV so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable POSIXLY_CORRECT disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #include "getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg = NULL; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which causes problems with re-calling getopt as programs generally don't know that. */ int __getopt_initialized = 0; /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the list of option characters. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the list of option characters selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return -1 with `optind' != ARGC. */ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ # include # define my_index strchr #else # if HAVE_STRING_H # include # else # include # endif /* Avoid depending on library functions or files whose names are inconsistent. */ #ifndef getenv extern char *getenv (); #endif static char * my_index (const char *str, int chr) { while (*str) { if (*str == chr) return (char *) str; str++; } return 0; } /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ # if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen (const char *); # endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; static int nonoption_flags_max_len; static int nonoption_flags_len; static int original_argc; static char *const *original_argv; /* Make sure the environment variable bash 2.0 puts in the environment is valid for the getopt call we must make sure that the ARGV passed to getopt is that one passed to the process. */ static void __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) { /* XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ original_argc = argc; original_argv = argv; } # ifdef text_set_element text_set_element (__libc_subinit, store_args_and_env); # endif /* text_set_element */ # define SWAP_FLAGS(ch1, ch2) \ if (nonoption_flags_len > 0) \ { \ char __tmp = __getopt_nonoption_flags[ch1]; \ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ __getopt_nonoption_flags[ch2] = __tmp; \ } #else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) #endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The other is elements [last_nonopt,optind), which contains all the options processed since those non-options were skipped. `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ #if defined __STDC__ && __STDC__ static void exchange (char **); #endif static void exchange (char **argv) { int bottom = first_nonopt; int middle = last_nonopt; int top = optind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ #ifdef _LIBC /* First make sure the handling of the `__getopt_nonoption_flags' string can work normally. Our top argument must be in the range of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and presents new arguments. */ char *new_str = malloc (top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else { memset (__mempcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len), '\0', top + 1 - nonoption_flags_max_len); nonoption_flags_max_len = top + 1; __getopt_nonoption_flags = new_str; } } #endif while (top > middle && middle > bottom) { if (top - middle > middle - bottom) { /* Bottom segment is the short one. */ int len = middle - bottom; register int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; } else { /* Top segment is the short one. */ int len = top - middle; register int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; SWAP_FLAGS (bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; } } /* Update records for the slots the non-options now occupy. */ first_nonopt += (optind - last_nonopt); last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined __STDC__ && __STDC__ static const char *_getopt_initialize (int, char *const *, const char *); #endif static const char * _getopt_initialize (int argc, char *const *argv, const char *optstring) { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ first_nonopt = last_nonopt = optind; nextchar = NULL; posixly_correct = getenv ("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #ifdef _LIBC if (posixly_correct == NULL && argc == original_argc && argv == original_argv) { if (nonoption_flags_max_len == 0) { if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0') nonoption_flags_max_len = -1; else { const char *orig_str = __getopt_nonoption_flags; int len = nonoption_flags_max_len = strlen (orig_str); if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), '\0', nonoption_flags_max_len - len); } } nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; #endif /* Make the compiler happy. */ (void)argc; (void)argv; return optstring; } /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option element. The characters of this element (aside from the initial '-') are option characters. If `getopt' is called repeatedly, it returns successively each of the option characters from each of the option elements. If `getopt' finds another option character, it returns that character, updating `optind' and `nextchar' so that the next call to `getopt' can resume the scan with the following option character or ARGV-element. If there are no more option characters, `getopt' returns -1. Then `optind' is the index in ARGV of the first ARGV-element that is not an option. (The ARGV-elements have been permuted so that those that are not options now come last.) OPTSTRING is a string containing the legitimate option characters. If an option character is seen that is not listed in OPTSTRING, return '?' after printing an error message. If you set `opterr' to zero, the error message is suppressed but we still return '?'. If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'. Two colons mean an option that wants an optional arg; if there is text in the current ARGV-element, it is returned in `optarg', otherwise `optarg' is set to zero. If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the abbreviation is unique or is an exact match for some defined option. If they have an argument, it follows the option name in the same ARGV-element, separated from the option name by a `=', or else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is zero. The elements of ARGV aren't really const, because we permute them. But we pretend they're const in the prototype to be compatible with other systems. LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero. LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a long-named option has been found by the most recent call. If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ int _getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) { optarg = NULL; if (optind == 0 || !__getopt_initialized) { if (optind == 0) optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring); __getopt_initialized = 1; } /* Test whether ARGV[optind] points to a non-option argument. Either it does not have option syntax, or there is an environment flag from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #ifdef _LIBC # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ || (optind < nonoption_flags_len \ && __getopt_nonoption_flags[optind] == '1')) #else # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) last_nonopt = optind; if (first_nonopt > optind) first_nonopt = optind; if (ordering == PERMUTE) { /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (last_nonopt != optind) first_nonopt = optind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ while (optind < argc && NONOPTION_P) optind++; last_nonopt = optind; } /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ if (optind != argc && !strcmp (argv[optind], "--")) { optind++; if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (first_nonopt == last_nonopt) first_nonopt = optind; last_nonopt = argc; optind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ if (optind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (first_nonopt != last_nonopt) optind = first_nonopt; return -1; } /* If we have come to a non-option and did not permute it, either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) { if (ordering == REQUIRE_ORDER) return -1; optarg = argv[optind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't consider it an abbreviated form of a long option that starts with f. Otherwise there would be no way to give the -f short option. On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg "u". This distinction seems to be the most useful approach. */ if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = -1; int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (opterr) fprintf (stderr, _("%s: option '%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; optopt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; optind++; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (opterr) { if (argv[optind - 1][1] == '-') /* --option */ fprintf (stderr, _("%s: option '--%s' doesn't allow an argument\n"), argv[0], pfound->name); else /* +option or -option */ fprintf (stderr, _("%s: option '%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); } nextchar += strlen (nextchar); optopt = pfound->val; return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (opterr) fprintf (stderr, _("%s: option '%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); optopt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } /* Can't find it as a long option. If this is not getopt_long_only, or the option starts with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL) { if (opterr) { if (argv[optind][1] == '-') /* --option */ fprintf (stderr, _("%s: unrecognized option '--%s'\n"), argv[0], nextchar); else /* +option or -option */ fprintf (stderr, _("%s: unrecognized option '%c%s'\n"), argv[0], argv[optind][0], nextchar); } nextchar = (char *) ""; optind++; optopt = 0; return '?'; } } /* Look at and handle the next short option-character. */ { char c = *nextchar++; char *temp = my_index (optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') ++optind; if (temp == NULL || c == ':') { if (opterr) { if (posixly_correct) /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); else fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); } optopt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = 0; int option_index; /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; return c; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; /* optarg is now the argument, see if it's in the table of longopts. */ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (opterr) fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; return '?'; } if (pfound != NULL) { option_index = indfound; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (opterr) fprintf (stderr, _("\ %s: option '-W %s' doesn't allow an argument\n"), argv[0], pfound->name); nextchar += strlen (nextchar); return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (opterr) fprintf (stderr, _("%s: option '%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } nextchar = NULL; return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { if (temp[2] == ':') { /* This is an option that accepts an argument optionally. */ if (*nextchar != '\0') { optarg = nextchar; optind++; } else optarg = NULL; nextchar = NULL; } else { /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; nextchar = NULL; } } return c; } } int getopt (int argc, char *const *argv, const char *optstring) { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); } #endif /* Not ELIDE_CODE. */ #ifdef TEST /* Compile with -DTEST to make an executable for use in testing the above definition of `getopt'. */ int main (int argc, char **argv) { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value '%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ ================================================ FILE: src/getopt.h ================================================ /* Declarations for getopt. Copyright (C) 1989-2024 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@gnu.org. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _GETOPT_H #define _GETOPT_H 1 #ifdef __cplusplus extern "C" { #endif /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ extern char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints for unrecognized options. */ extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is zero. The field `has_arg' is: no_argument (or 0) if the option does not take an argument, required_argument (or 1) if the option requires an argument, optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but left unchanged if the option is not found. To have a long-named option do something other than set an `int' to a compiled-in constant, such as set a value from `optarg', set the option's `flag' field to zero and its `val' field to a nonzero value (the equivalent single-letter option character, if there is one). For long options that have a zero `flag' field, `getopt' returns the contents of the `val' field. */ struct option { #if defined (__STDC__) && __STDC__ const char *name; #else char *name; #endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; int *flag; int val; }; /* Names for the values of the `has_arg' field of `struct option'. */ #define no_argument 0 #define required_argument 1 #define optional_argument 2 #if defined (__STDC__) && __STDC__ #ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ extern int getopt (int argc, char *const *argv, const char *shortopts); #else /* not __GNU_LIBRARY__ */ extern int getopt (); #endif /* __GNU_LIBRARY__ */ extern int getopt_long (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); extern int getopt_long_only (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); /* Internal only. Users should not call this directly. */ extern int _getopt_internal (int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind, int long_only); #else /* not __STDC__ */ extern int getopt (); extern int getopt_long (); extern int getopt_long_only (); extern int _getopt_internal (); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* getopt.h */ ================================================ FILE: src/getopt1.c ================================================ /* getopt_long and getopt_long_only entry points for GNU getopt. Copyright (C) 1987-1994, 1996-2024 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@gnu.org. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "getopt.h" #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE #endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ #include #endif #ifndef NULL #define NULL 0 #endif int getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) { return _getopt_internal (argc, argv, options, long_options, opt_index, 0); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. If an option that starts with '-' (not '--') doesn't match a long option, but does match a short option, it is parsed as a short option instead. */ int getopt_long_only (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) { return _getopt_internal (argc, argv, options, long_options, opt_index, 1); } #endif /* Not ELIDE_CODE. */ #ifdef TEST #include int main (int argc, char **argv) { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, {"delete", 1, 0, 0}, {"verbose", 0, 0, 0}, {"create", 0, 0, 0}, {"file", 1, 0, 0}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "abc:d:0123456789", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value '%s'\n", optarg); break; case 'd': printf ("option d with value '%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ ================================================ FILE: src/gettext.h ================================================ /* Convenience header for conditional use of GNU . Copyright (C) 1995-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _LIBGETTEXT_H #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ #if ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include #else /* Disabled NLS. The casts to 'const char *' serve the purpose of producing warnings for invalid uses of the value returned from these functions. On pre-ANSI systems without 'const', the config.h file is supposed to contain "#define const". */ # define gettext(Msgid) ((const char *) (Msgid)) # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) # define ngettext(Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dngettext(Domainname, Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define textdomain(Domainname) ((const char *) (Domainname)) # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) #endif /* A pseudo function call that serves as a marker for the automated extraction of messages, but does not call gettext(). The run-time translation is done at a different place in the code. The argument, String, should be a literal string. Concatenated strings and other string expressions won't work. The macro's expansion is not parenthesized, so that it is suitable as initializer for static 'char[]' or 'const char[]' variables. */ #define gettext_noop(String) String #endif /* _LIBGETTEXT_H */ ================================================ FILE: src/gmk-default.scm ================================================ ;; Contents of the (GNU Make) Guile module ;; Copyright (C) 2011-2024 Free Software Foundation, Inc. ;; This file is part of GNU Make. ;; ;; GNU Make is free software; you can redistribute it and/or modify it under ;; the terms of the GNU General Public License as published by the Free ;; Software Foundation; either version 3 of the License, or (at your option) ;; any later version. ;; ;; GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ;; details. ;; ;; You should have received a copy of the GNU General Public License along ;; with this program. If not, see . (define (to-string-maybe x) (cond ;; In GNU Make, "false" is the empty string ((or (not x) (unspecified? x) (variable? x) (null? x) (and (string? x) (string-null? x))) #f) ;; We want something not false... not sure about this ((eq? x #t) "#t") ;; Basics ((or (symbol? x) (number? x)) (object->string x)) ((char? x) (string x)) ;; Printable string (no special characters) ((and (string? x) (string-every char-set:printing x)) x) ;; No idea: fail (else (error "Unknown object:" x)))) (define (obj-to-str x) (let ((acc '())) (define (walk x) (cond ((pair? x) (walk (car x)) (walk (cdr x))) ((to-string-maybe x) => (lambda (s) (set! acc (cons s acc)))))) (walk x) (string-join (reverse! acc)))) ;; Return the value of the GNU Make variable V (define (gmk-var v) (gmk-expand (format #f "$(~a)" (obj-to-str v)))) ;; Export the public interfaces (export gmk-expand gmk-eval gmk-var) ================================================ FILE: src/gnumake.h ================================================ /* External interfaces usable by dynamic objects loaded into GNU Make. Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _GNUMAKE_H_ #define _GNUMAKE_H_ #define GMK_ABI_VERSION 1 /* Specify the location of elements read from makefiles. */ typedef struct { const char *filenm; unsigned long lineno; } gmk_floc; typedef char *(*gmk_func_ptr)(const char *nm, unsigned int argc, char **argv); /* When an object is loaded by GNU Make, a setup method will be invoked. The name of the method is either derived from the filename of the object, or specified explicitly in the makefile. It has the signature: int (unsigned int abi_version, const gmk_floc *flocp); The abi_version will be set to GMK_ABI_VERSION. When an object is unloaded by GNU Make, an unload method will be invoked. The name of the method is derived from the filename of the object, with _gmk_unload appended. It has the signature: void _gmk_unload (void); There will only be one unload method invoked regardless of the number of setup methods within the object. */ #ifdef _WIN32 # ifdef GMK_BUILDING_MAKE # define GMK_EXPORT __declspec(dllexport) # else # define GMK_EXPORT __declspec(dllimport) # endif #else # define GMK_EXPORT #endif /* Free memory returned by the gmk_expand() and gmk_free() functions. */ GMK_EXPORT void gmk_free (char *str); /* Allocate memory in GNU Make's context. */ GMK_EXPORT char *gmk_alloc (unsigned int len); /* Run $(eval ...) on the provided string BUFFER. */ GMK_EXPORT void gmk_eval (const char *buffer, const gmk_floc *floc); /* Run GNU Make expansion on the provided string STR. Returns an allocated buffer that the caller must free with gmk_free(). */ GMK_EXPORT char *gmk_expand (const char *str); /* Register a new GNU Make function NAME (maximum of 255 chars long). When the function is expanded in the makefile, FUNC will be invoked with the appropriate arguments. The return value of FUNC must be either NULL, in which case it expands to the empty string, or a pointer to the result of the expansion in a string created by gmk_alloc(). GNU Make will free the memory when it's done. MIN_ARGS is the minimum number of arguments the function requires. MAX_ARGS is the maximum number of arguments (or 0 if there's no maximum). MIN_ARGS and MAX_ARGS may not exceed 255. The FLAGS value may be GMK_FUNC_DEFAULT, or one or more of the following flags OR'd together: GMK_FUNC_NOEXPAND: the arguments to the function will be not be expanded before FUNC is called. */ GMK_EXPORT void gmk_add_function (const char *name, gmk_func_ptr func, unsigned int min_args, unsigned int max_args, unsigned int flags); #define GMK_FUNC_DEFAULT 0x00 #define GMK_FUNC_NOEXPAND 0x01 #endif /* _GNUMAKE_H_ */ ================================================ FILE: src/guile.c ================================================ /* GNU Guile interface for GNU Make. Copyright (C) 2011-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #ifdef HAVE_GUILE #include "gnumake.h" #include "debug.h" #include "filedef.h" #include "dep.h" #include "variable.h" #include /* Pre-2.0 versions of Guile don't have a typedef for gsubr function types. */ #if SCM_MAJOR_VERSION < 2 # define GSUBR_TYPE SCM (*) () /* Guile 1.x doesn't really support i18n. */ # define EVAL_STRING(_s) scm_c_eval_string (_s) #else # define GSUBR_TYPE scm_t_subr # define EVAL_STRING(_s) scm_eval_string (scm_from_utf8_string (_s)) #endif static SCM make_mod = SCM_EOL; static SCM obj_to_str = SCM_EOL; /* Convert an SCM object into a string. */ static char * cvt_scm_to_str (SCM obj) { return scm_to_locale_string (scm_call_1 (obj_to_str, obj)); } /* Perform the GNU Make expansion function. */ static SCM guile_expand_wrapper (SCM obj) { char *str = cvt_scm_to_str (obj); SCM ret; char *res; DB (DB_BASIC, (_("guile: Expanding '%s'\n"), str)); res = gmk_expand (str); ret = scm_from_locale_string (res); free (str); free (res); return ret; } /* Perform the GNU Make eval function. */ static SCM guile_eval_wrapper (SCM obj) { char *str = cvt_scm_to_str (obj); DB (DB_BASIC, (_("guile: Evaluating '%s'\n"), str)); gmk_eval (str, 0); return SCM_BOOL_F; } /* Invoked by scm_c_define_module(), in the context of the GNU Make module. */ static void guile_define_module (void *data UNUSED) { /* Ingest the predefined Guile module for GNU Make. */ #include "gmk-default.h" /* Register a subr for GNU Make's eval capability. */ scm_c_define_gsubr ("gmk-expand", 1, 0, 0, (GSUBR_TYPE) guile_expand_wrapper); /* Register a subr for GNU Make's eval capability. */ scm_c_define_gsubr ("gmk-eval", 1, 0, 0, (GSUBR_TYPE) guile_eval_wrapper); /* Define the rest of the module. */ scm_c_eval_string (GUILE_module_defn); } /* Initialize the GNU Make Guile module. */ static void * guile_init (void *arg UNUSED) { /* Define the module. */ make_mod = scm_c_define_module ("gnu make", guile_define_module, NULL); /* Get a reference to the object-to-string translator, for later. */ obj_to_str = scm_variable_ref (scm_c_module_lookup (make_mod, "obj-to-str")); /* Import the GNU Make module exports into the generic space. */ scm_c_eval_string ("(use-modules (gnu make))"); return NULL; } static void * internal_guile_eval (void *arg) { return cvt_scm_to_str (EVAL_STRING (arg)); } /* This is the function registered with make */ static char * func_guile (const char *funcname UNUSED, unsigned int argc UNUSED, char **argv) { static int init = 0; if (! init) { /* Initialize the Guile interpreter. */ scm_with_guile (guile_init, NULL); init = 1; } if (argv[0] && argv[0][0] != '\0') return scm_with_guile (internal_guile_eval, argv[0]); return NULL; } /* ----- Public interface ----- */ /* We could send the flocp to define_new_function(), but since guile is "kind of" built-in, that didn't seem so useful. */ int guile_gmake_setup (const floc *flocp UNUSED) { /* Create a make function "guile". */ gmk_add_function ("guile", func_guile, 0, 1, GMK_FUNC_DEFAULT); return 1; } #else int guile_gmake_setup (const floc *flocp UNUSED) { return 1; } #endif ================================================ FILE: src/hash.c ================================================ /* hash.c -- hash table maintenance Copyright (C) 1995, 1999, 2002, 2010 Free Software Foundation, Inc. Written by Greg McGary GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "hash.h" #include #define CALLOC(t, n) ((t *) xcalloc (sizeof (t) * (n))) #define MALLOC(t, n) ((t *) xmalloc (sizeof (t) * (n))) #define REALLOC(o, t, n) ((t *) xrealloc ((o), sizeof (t) * (n))) #define CLONE(o, t, n) ((t *) memcpy (MALLOC (t, (n)), (o), sizeof (t) * (n))) static void hash_rehash __P((struct hash_table* ht)); static unsigned long round_up_2 __P((unsigned long rough)); /* Implement double hashing with open addressing. The table size is always a power of two. The secondary ('increment') hash function is forced to return an odd-value, in order to be relatively prime to the table size. This guarantees that the increment can potentially hit every slot in the table during collision resolution. */ void *hash_deleted_item = &hash_deleted_item; /* Force the table size to be a power of two, possibly rounding up the given size. */ void hash_init (struct hash_table *ht, unsigned long size, hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp) { ht->ht_size = round_up_2 (size); ht->ht_empty_slots = ht->ht_size; ht->ht_vec = CALLOC (void *, ht->ht_size); if (ht->ht_vec == 0) { fprintf (stderr, _("can't allocate %lu bytes for hash table: memory exhausted"), ht->ht_size * (unsigned long) sizeof (void *)); exit (MAKE_TROUBLE); } ht->ht_capacity = ht->ht_size - (ht->ht_size / 16); /* 93.75% loading factor */ ht->ht_fill = 0; ht->ht_collisions = 0; ht->ht_lookups = 0; ht->ht_rehashes = 0; ht->ht_hash_1 = hash_1; ht->ht_hash_2 = hash_2; ht->ht_compare = hash_cmp; } /* Load an array of items into 'ht'. */ void hash_load (struct hash_table *ht, void *item_table, unsigned long cardinality, unsigned long size) { char *items = (char *) item_table; while (cardinality--) { hash_insert (ht, items); items += size; } } /* Returns the address of the table slot matching 'key'. If 'key' is not found, return the address of an empty slot suitable for inserting 'key'. The caller is responsible for incrementing ht_fill on insertion. */ void ** hash_find_slot (struct hash_table *ht, const void *key) { void **slot; void **deleted_slot = 0; unsigned int hash_2 = 0; unsigned int hash_1 = (*ht->ht_hash_1) (key); ht->ht_lookups++; for (;;) { hash_1 &= (ht->ht_size - 1); slot = &ht->ht_vec[hash_1]; if (*slot == 0) return (deleted_slot ? deleted_slot : slot); if (*slot == hash_deleted_item) { if (deleted_slot == 0) deleted_slot = slot; } else { if (key == *slot) return slot; if ((*ht->ht_compare) (key, *slot) == 0) return slot; ht->ht_collisions++; } if (!hash_2) hash_2 = (*ht->ht_hash_2) (key) | 1; hash_1 += hash_2; } } void * hash_find_item (struct hash_table *ht, const void *key) { void **slot = hash_find_slot (ht, key); return ((HASH_VACANT (*slot)) ? 0 : *slot); } void * hash_insert (struct hash_table *ht, const void *item) { void **slot = hash_find_slot (ht, item); const void *old_item = *slot; hash_insert_at (ht, item, slot); return (void *)((HASH_VACANT (old_item)) ? 0 : old_item); } void * hash_insert_at (struct hash_table *ht, const void *item, const void *slot) { const void *old_item = *(void **) slot; if (HASH_VACANT (old_item)) { ht->ht_fill++; if (old_item == 0) ht->ht_empty_slots--; old_item = item; } *(void const **) slot = item; if (ht->ht_empty_slots < ht->ht_size - ht->ht_capacity) { hash_rehash (ht); return (void *) hash_find_slot (ht, item); } else return (void *) slot; } void * hash_delete (struct hash_table *ht, const void *item) { void **slot = hash_find_slot (ht, item); return hash_delete_at (ht, slot); } void * hash_delete_at (struct hash_table *ht, const void *slot) { void *item = *(void **) slot; if (!HASH_VACANT (item)) { *(void const **) slot = hash_deleted_item; ht->ht_fill--; return item; } else return 0; } void hash_free_items (struct hash_table *ht) { void **vec = ht->ht_vec; void **end = &vec[ht->ht_size]; for (; vec < end; vec++) { void *item = *vec; if (!HASH_VACANT (item)) free (item); *vec = 0; } ht->ht_fill = 0; ht->ht_empty_slots = ht->ht_size; } void hash_delete_items (struct hash_table *ht) { void **vec = ht->ht_vec; void **end = &vec[ht->ht_size]; for (; vec < end; vec++) *vec = 0; ht->ht_fill = 0; ht->ht_collisions = 0; ht->ht_lookups = 0; ht->ht_rehashes = 0; ht->ht_empty_slots = ht->ht_size; } void hash_free (struct hash_table *ht, int free_items) { if (free_items) hash_free_items (ht); else { ht->ht_fill = 0; ht->ht_empty_slots = ht->ht_size; } free (ht->ht_vec); ht->ht_vec = 0; ht->ht_capacity = 0; } void hash_map (struct hash_table *ht, hash_map_func_t map) { void **slot; void **end = &ht->ht_vec[ht->ht_size]; for (slot = ht->ht_vec; slot < end; slot++) { if (!HASH_VACANT (*slot)) (*map) (*slot); } } void hash_map_arg (struct hash_table *ht, hash_map_arg_func_t map, void *arg) { void **slot; void **end = &ht->ht_vec[ht->ht_size]; for (slot = ht->ht_vec; slot < end; slot++) { if (!HASH_VACANT (*slot)) (*map) (*slot, arg); } } /* Double the size of the hash table in the event of overflow... */ static void hash_rehash (struct hash_table *ht) { unsigned long old_ht_size = ht->ht_size; void **old_vec = ht->ht_vec; void **ovp; if (ht->ht_fill >= ht->ht_capacity) { ht->ht_size *= 2; ht->ht_capacity = ht->ht_size - (ht->ht_size >> 4); } ht->ht_rehashes++; ht->ht_vec = CALLOC (void *, ht->ht_size); for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++) { if (! HASH_VACANT (*ovp)) { void **slot = hash_find_slot (ht, *ovp); *slot = *ovp; } } ht->ht_empty_slots = ht->ht_size - ht->ht_fill; free (old_vec); } void hash_print_stats (struct hash_table *ht, FILE *out_FILE) { fprintf (out_FILE, _("Load=%lu/%lu=%.0f%%, "), ht->ht_fill, ht->ht_size, 100.0 * (double) ht->ht_fill / (double) ht->ht_size); fprintf (out_FILE, _("Rehash=%u, "), ht->ht_rehashes); fprintf (out_FILE, _("Collisions=%lu/%lu=%.0f%%"), ht->ht_collisions, ht->ht_lookups, (ht->ht_lookups ? (100.0 * (double) ht->ht_collisions / (double) ht->ht_lookups) : 0)); } /* Dump all items into a NULL-terminated vector. Use the user-supplied vector, or malloc one. */ void ** hash_dump (struct hash_table *ht, void **vector_0, qsort_cmp_t compare) { void **vector; void **slot; void **end = &ht->ht_vec[ht->ht_size]; if (vector_0 == 0) vector_0 = MALLOC (void *, ht->ht_fill + 1); vector = vector_0; for (slot = ht->ht_vec; slot < end; slot++) if (!HASH_VACANT (*slot)) *vector++ = *slot; *vector = 0; if (compare) qsort (vector_0, ht->ht_fill, sizeof (void *), compare); return vector_0; } /* Round a given number up to the nearest power of 2. */ static unsigned long round_up_2 (unsigned long n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); #if !defined(HAVE_LIMITS_H) || ULONG_MAX > 4294967295 /* We only need this on systems where unsigned long is >32 bits. */ n |= (n >> 32); #endif return n + 1; } #define rol32(v, n) \ ((v) << (n) | ((v) >> (32 - (n)))) /* jhash_mix -- mix 3 32-bit values reversibly. */ #define jhash_mix(a, b, c) \ { \ a -= c; a ^= rol32(c, 4); c += b; \ b -= a; b ^= rol32(a, 6); a += c; \ c -= b; c ^= rol32(b, 8); b += a; \ a -= c; a ^= rol32(c, 16); c += b; \ b -= a; b ^= rol32(a, 19); a += c; \ c -= b; c ^= rol32(b, 4); b += a; \ } /* jhash_final - final mixing of 3 32-bit values (a,b,c) into c */ #define jhash_final(a, b, c) \ { \ c ^= b; c -= rol32(b, 14); \ a ^= c; a -= rol32(c, 11); \ b ^= a; b -= rol32(a, 25); \ c ^= b; c -= rol32(b, 16); \ a ^= c; a -= rol32(c, 4); \ b ^= a; b -= rol32(a, 14); \ c ^= b; c -= rol32(b, 24); \ } /* An arbitrary initial parameter */ #define JHASH_INITVAL 0xdeadbeef #define sum_get_unaligned_32(r, p) \ do { \ unsigned int val; \ memcpy (&val, (p), 4); \ r += val; \ } while(0); unsigned int jhash(unsigned const char *k, int length) { unsigned int a, b, c; /* Set up the internal state */ a = b = c = JHASH_INITVAL + length; /* All but the last block: affect some 32 bits of (a,b,c) */ while (length > 12) { sum_get_unaligned_32(a, k); sum_get_unaligned_32(b, k + 4); sum_get_unaligned_32(c, k + 8); jhash_mix(a, b, c); length -= 12; k += 12; } if (!length) return c; if (length > 8) { sum_get_unaligned_32(a, k); length -= 4; k += 4; } if (length > 4) { sum_get_unaligned_32(b, k); length -= 4; k += 4; } if (length == 4) c += (unsigned)k[3]<<24; if (length >= 3) c += (unsigned)k[2]<<16; if (length >= 2) c += (unsigned)k[1]<<8; c += k[0]; jhash_final(a, b, c); return c; } #define UINTSZ sizeof (unsigned int) #ifdef WORDS_BIGENDIAN /* The ifs are ordered from the first byte in memory to the last. Help the compiler optimize by using static memcpy length. */ #define sum_up_to_nul(r, p, plen, flag) \ do { \ unsigned int val = 0; \ size_t pn = (plen); \ if (pn >= UINTSZ) \ memcpy (&val, (p), UINTSZ); \ else \ memcpy (&val, (p), pn); \ if ((val & 0xFF000000) == 0) \ flag = 1; \ else if ((val & 0xFF0000) == 0) \ r += val & ~0xFFFF, flag = 1; \ else if ((val & 0xFF00) == 0) \ r += val & ~0xFF, flag = 1; \ else \ r += val, flag = (val & 0xFF) == 0; \ } while (0) #else /* First detect the presence of zeroes. If there is none, we can sum the 4 bytes directly. Otherwise, the ifs are ordered as in the big endian case, from the first byte in memory to the last. Help the compiler optimize by using static memcpy length. */ #define sum_up_to_nul(r, p, plen, flag) \ do { \ unsigned int val = 0; \ size_t pn = (plen); \ if (pn >= UINTSZ) \ memcpy (&val, (p), UINTSZ); \ else \ memcpy (&val, (p), pn); \ flag = ((val - 0x01010101) & ~val) & 0x80808080; \ if (!flag) \ r += val; \ else if (val & 0xFF) \ { \ if ((val & 0xFF00) == 0) \ r += val & 0xFF; \ else if ((val & 0xFF0000) == 0) \ r += val & 0xFFFF; \ else \ r += val; \ } \ } while (0) #endif unsigned int jhash_string(unsigned const char *k) { unsigned int a, b, c; unsigned int have_nul = 0; unsigned const char *start = k; size_t klen = strlen ((const char*)k); /* Set up the internal state */ a = b = c = JHASH_INITVAL; /* All but the last block: affect some 32 bits of (a,b,c) */ for (;;) { sum_up_to_nul(a, k, klen, have_nul); if (have_nul) break; k += UINTSZ; assert (klen >= UINTSZ); klen -= UINTSZ; sum_up_to_nul(b, k, klen, have_nul); if (have_nul) break; k += UINTSZ; assert (klen >= UINTSZ); klen -= UINTSZ; sum_up_to_nul(c, k, klen, have_nul); if (have_nul) break; k += UINTSZ; assert (klen >= UINTSZ); klen -= UINTSZ; jhash_mix(a, b, c); } jhash_final(a, b, c); return c + (unsigned) (k - start); } ================================================ FILE: src/hash.h ================================================ /* hash.h -- decls for hash table Copyright (C) 1995, 1999, 2002, 2010 Free Software Foundation, Inc. Written by Greg McGary GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _hash_h_ #define _hash_h_ #include #include #if defined __cplusplus || (defined __STDC__ && __STDC__) || MK_OS_W32 # if !defined __GLIBC__ || !defined __P # undef __P # define __P(protos) protos # endif #else /* Not C++ or ANSI C. */ # undef __P # define __P(protos) () /* We can get away without defining 'const' here only because in this file it is used only inside the prototype for 'fnmatch', which is elided in non-ANSI C where 'const' is problematical. */ #endif /* C++ or ANSI C. */ typedef unsigned long (*hash_func_t) __P((void const *key)); typedef int (*hash_cmp_func_t) __P((void const *x, void const *y)); typedef void (*hash_map_func_t) __P((void const *item)); typedef void (*hash_map_arg_func_t) __P((void const *item, void *arg)); struct hash_table { void **ht_vec; hash_func_t ht_hash_1; /* primary hash function */ hash_func_t ht_hash_2; /* secondary hash function */ hash_cmp_func_t ht_compare; /* comparison function */ unsigned long ht_size; /* total number of slots (power of 2) */ unsigned long ht_capacity; /* usable slots, limited by loading-factor */ unsigned long ht_fill; /* items in table */ unsigned long ht_empty_slots; /* empty slots not including deleted slots */ unsigned long ht_collisions; /* # of failed calls to comparison function */ unsigned long ht_lookups; /* # of queries */ unsigned int ht_rehashes; /* # of times we've expanded table */ }; typedef int (*qsort_cmp_t) __P((void const *, void const *)); void hash_init __P((struct hash_table *ht, unsigned long size, hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp)); void hash_load __P((struct hash_table *ht, void *item_table, unsigned long cardinality, unsigned long size)); void **hash_find_slot __P((struct hash_table *ht, void const *key)); void *hash_find_item __P((struct hash_table *ht, void const *key)); void *hash_insert __P((struct hash_table *ht, const void *item)); void *hash_insert_at __P((struct hash_table *ht, const void *item, void const *slot)); void *hash_delete __P((struct hash_table *ht, void const *item)); void *hash_delete_at __P((struct hash_table *ht, void const *slot)); void hash_delete_items __P((struct hash_table *ht)); void hash_free_items __P((struct hash_table *ht)); void hash_free __P((struct hash_table *ht, int free_items)); void hash_map __P((struct hash_table *ht, hash_map_func_t map)); void hash_map_arg __P((struct hash_table *ht, hash_map_arg_func_t map, void *arg)); void hash_print_stats __P((struct hash_table *ht, FILE *out_FILE)); void **hash_dump __P((struct hash_table *ht, void **vector_0, qsort_cmp_t compare)); extern unsigned jhash(unsigned char const *key, int n); extern unsigned jhash_string(unsigned char const *key); extern void *hash_deleted_item; #define HASH_VACANT(item) ((item) == 0 || (void *) (item) == hash_deleted_item) /* hash and comparison macros for case-sensitive string keys. */ /* Due to the strcache, it's not uncommon for the string pointers to be identical. Take advantage of that to short-circuit string compares. */ #define STRING_HASH_1(KEY, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY); \ (RESULT) += jhash_string(_key_); \ } while (0) #define return_STRING_HASH_1(KEY) do { \ unsigned long _result_ = 0; \ STRING_HASH_1 ((KEY), _result_); \ return _result_; \ } while (0) /* No need for a second hash because jhash already provides pretty good results. However, do evaluate the arguments to avoid warnings. */ #define STRING_HASH_2(KEY, RESULT) do { \ (void)(KEY); \ } while (0) #define return_STRING_HASH_2(KEY) do { \ unsigned long _result_ = 0; \ STRING_HASH_2 ((KEY), _result_); \ return _result_; \ } while (0) #define STRING_COMPARE(X, Y, RESULT) do { \ RESULT = (X) == (Y) ? 0 : strcmp ((X), (Y)); \ } while (0) #define return_STRING_COMPARE(X, Y) do { \ return (X) == (Y) ? 0 : strcmp ((X), (Y)); \ } while (0) #define STRING_N_HASH_1(KEY, N, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY); \ (RESULT) += jhash(_key_, N); \ } while (0) #define return_STRING_N_HASH_1(KEY, N) do { \ unsigned long _result_ = 0; \ STRING_N_HASH_1 ((KEY), (N), _result_); \ return _result_; \ } while (0) /* No need for a second hash because jhash already provides pretty good results. However, do evaluate the arguments to avoid warnings. */ #define STRING_N_HASH_2(KEY, N, RESULT) do { \ (void)(KEY); \ (void)(N); \ } while (0) #define return_STRING_N_HASH_2(KEY, N) do { \ unsigned long _result_ = 0; \ STRING_N_HASH_2 ((KEY), (N), _result_); \ return _result_; \ } while (0) #define STRING_N_COMPARE(X, Y, N, RESULT) do { \ RESULT = (X) == (Y) ? 0 : memcmp ((X), (Y), (N)); \ } while (0) #define return_STRING_N_COMPARE(X, Y, N) do { \ return (X) == (Y) ? 0 : memcmp ((X), (Y), (N)); \ } while (0) #ifdef HAVE_CASE_INSENSITIVE_FS /* hash and comparison macros for case-insensitive string _key_s. */ #define ISTRING_HASH_1(KEY, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ while (*++_key_) \ (RESULT) += (tolower (*_key_) << (_key_[1] & 0xf)); \ } while (0) #define return_ISTRING_HASH_1(KEY) do { \ unsigned long _result_ = 0; \ ISTRING_HASH_1 ((KEY), _result_); \ return _result_; \ } while (0) #define ISTRING_HASH_2(KEY, RESULT) do { \ unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ while (*++_key_) \ (RESULT) += (tolower (*_key_) << (_key_[1] & 0x7)); \ } while (0) #define return_ISTRING_HASH_2(KEY) do { \ unsigned long _result_ = 0; \ ISTRING_HASH_2 ((KEY), _result_); \ return _result_; \ } while (0) #define ISTRING_COMPARE(X, Y, RESULT) do { \ RESULT = (X) == (Y) ? 0 : strcasecmp ((X), (Y)); \ } while (0) #define return_ISTRING_COMPARE(X, Y) do { \ return (X) == (Y) ? 0 : strcasecmp ((X), (Y)); \ } while (0) #else #define ISTRING_HASH_1(KEY, RESULT) STRING_HASH_1 ((KEY), (RESULT)) #define return_ISTRING_HASH_1(KEY) return_STRING_HASH_1 (KEY) #define ISTRING_HASH_2(KEY, RESULT) STRING_HASH_2 ((KEY), (RESULT)) #define return_ISTRING_HASH_2(KEY) return_STRING_HASH_2 (KEY) #define ISTRING_COMPARE(X, Y, RESULT) STRING_COMPARE ((X), (Y), (RESULT)) #define return_ISTRING_COMPARE(X, Y) return_STRING_COMPARE ((X), (Y)) #endif /* hash and comparison macros for integer _key_s. */ #define INTEGER_HASH_1(KEY, RESULT) do { \ (RESULT) += ((unsigned long)(KEY)); \ } while (0) #define return_INTEGER_HASH_1(KEY) do { \ unsigned long _result_ = 0; \ INTEGER_HASH_1 ((KEY), _result_); \ return _result_; \ } while (0) #define INTEGER_HASH_2(KEY, RESULT) do { \ (RESULT) += ~((unsigned long)(KEY)); \ } while (0) #define return_INTEGER_HASH_2(KEY) do { \ unsigned long _result_ = 0; \ INTEGER_HASH_2 ((KEY), _result_); \ return _result_; \ } while (0) #define INTEGER_COMPARE(X, Y, RESULT) do { \ (RESULT) = X - Y; \ } while (0) #define return_INTEGER_COMPARE(X, Y) do { \ int _result_; \ INTEGER_COMPARE (X, Y, _result_); \ return _result_; \ } while (0) /* hash and comparison macros for address keys. */ #define ADDRESS_HASH_1(KEY, RESULT) INTEGER_HASH_1 (((unsigned long)(KEY)) >> 3, (RESULT)) #define ADDRESS_HASH_2(KEY, RESULT) INTEGER_HASH_2 (((unsigned long)(KEY)) >> 3, (RESULT)) #define ADDRESS_COMPARE(X, Y, RESULT) INTEGER_COMPARE ((X), (Y), (RESULT)) #define return_ADDRESS_HASH_1(KEY) return_INTEGER_HASH_1 (((unsigned long)(KEY)) >> 3) #define return_ADDRESS_HASH_2(KEY) return_INTEGER_HASH_2 (((unsigned long)(KEY)) >> 3) #define return_ADDRESS_COMPARE(X, Y) return_INTEGER_COMPARE ((X), (Y)) #endif /* not _hash_h_ */ ================================================ FILE: src/implicit.c ================================================ /* Implicit rule searching for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "rule.h" #include "dep.h" #include "debug.h" #include "variable.h" #include "job.h" /* struct child, used inside commands.h */ #include "commands.h" /* set_file_variables */ #include "shuffle.h" #include static int pattern_search (struct file *file, int archive, unsigned int depth, unsigned int recursions, int allow_compat_rules); /* For a FILE which has no commands specified, try to figure out some from the implicit pattern rules. Returns 1 if a suitable implicit rule was found, after modifying FILE to contain the appropriate commands and deps, or returns 0 if no implicit rule was found. */ int try_implicit_rule (struct file *file, unsigned int depth) { DBF (DB_IMPLICIT, _("Looking for an implicit rule for '%s'.\n")); /* The order of these searches was previously reversed. My logic now is that since the non-archive search uses more information in the target (the archive search omits the archive name), it is more specific and should come first. */ if (pattern_search (file, 0, depth, 0, 0)) return 1; #ifndef NO_ARCHIVES /* If this is an archive member reference, use just the archive member name to search for implicit rules. */ if (ar_name (file->name)) { DBF (DB_IMPLICIT, _("Looking for archive-member implicit rule for '%s'.\n")); if (pattern_search (file, 1, depth, 0, 0)) return 1; DBS (DB_IMPLICIT, (_("No archive-member implicit rule found for '%s'.\n"), file->name)); } #endif return 0; } /* Scans the BUFFER for the next word with whitespace as a separator. Returns the pointer to the beginning of the word. LENGTH hold the length of the word. */ static const char * get_next_word (const char *buffer, size_t *length) { const char *p = buffer, *beg; char c; /* Skip any leading whitespace. */ NEXT_TOKEN (p); beg = p; c = *(p++); if (c == '\0') return 0; while (1) { /* Each time through the loop, "c" has the current char and "p" points to the next char. */ switch (c) { case '\0': case ' ': case '\t': goto done_word; case '$': /* This is a variable reference, so skip it. */ p = skip_reference (p); break; case '|': goto done; default: break; } c = *(p++); } done_word: --p; done: if (length) *length = p - beg; return beg; } /* This structure stores information about the expanded prerequisites for a pattern rule. NAME is always set to the strcache'd name of the prereq. FILE and PATTERN will be set for intermediate files only. IGNORE_MTIME is copied from the prerequisite we expanded. */ struct patdeps { const char *name; const char *pattern; struct file *file; unsigned int ignore_mtime : 1; unsigned int ignore_automatic_vars : 1; unsigned int is_explicit : 1; unsigned int wait_here : 1; }; /* This structure stores information about pattern rules that we need to try. */ struct tryrule { struct rule *rule; /* Stem length for this match. */ size_t stemlen; /* Index of the target in this rule that matched the file. */ unsigned int matches; /* Definition order of this rule. Used to implement stable sort.*/ unsigned int order; /* Nonzero if the LASTSLASH logic was used in matching this rule. */ char checked_lastslash; }; int stemlen_compare (const void *v1, const void *v2) { const struct tryrule *r1 = v1; const struct tryrule *r2 = v2; int r = (int) (r1->stemlen - r2->stemlen); return r != 0 ? r : (int) (r1->order - r2->order); } /* Search the pattern rules for a rule with an existing dependency to make FILE. If a rule is found, the appropriate commands and deps are put in FILE and 1 is returned. If not, 0 is returned. If ARCHIVE is nonzero, FILE->name is of the form "LIB(MEMBER)". A rule for "(MEMBER)" will be searched for, and "(MEMBER)" will not be chopped up into directory and filename parts. If an intermediate file is found by pattern search, the intermediate file is set up as a target by the recursive call and is also made a dependency of FILE. DEPTH is used for debugging messages. */ static int pattern_search (struct file *file, int archive, unsigned int depth, unsigned int recursions, int allow_compat_rules) { /* Filename we are searching for a rule for. */ const char *filename = archive ? strchr (file->name, '(') : file->name; /* Length of FILENAME. */ size_t namelen = strlen (filename); /* The last slash in FILENAME (or nil if there is none). */ const char *lastslash; /* This is a file-object used as an argument in recursive calls. It never contains any data except during a recursive call. */ struct file *int_file = 0; /* List of dependencies found recursively. */ unsigned int max_deps = max_pattern_deps; struct patdeps *deplist = xmalloc (max_deps * sizeof (struct patdeps)); struct patdeps *pat = deplist; /* Names of possible dependencies are constructed in this buffer. We may replace % by $(*F) for second expansion, increasing the length. */ size_t deplen = namelen + max_pattern_dep_length + 4; char *depname = alloca (deplen); #ifndef NDEBUG char *dend = depname + deplen; #endif /* The start and length of the stem of FILENAME for the current rule. */ const char *stem = 0; size_t stemlen = 0; size_t fullstemlen = 0; /* Buffer in which we store all the rules that are possibly applicable. */ struct tryrule *tryrules = xmalloc (num_pattern_rules * max_pattern_targets * sizeof (struct tryrule)); /* Number of valid elements in TRYRULES. */ unsigned int nrules; /* The index in TRYRULES of the rule we found. */ unsigned int foundrule; /* Nonzero if should consider intermediate files as dependencies. */ int intermed_ok; /* Nonzero if we have initialized file variables for this target. */ int file_vars_initialized = 0; /* Nonzero if we have matched a pattern-rule target that is not just '%'. */ int specific_rule_matched = 0; unsigned int ri; /* uninit checks OK */ int found_compat_rule = 0; struct rule *rule; char *pathdir = NULL; size_t pathlen; PATH_VAR (stem_str); /* @@ Need to get rid of stem, stemlen, etc. */ ++depth; #ifndef NO_ARCHIVES if (archive || ar_name (filename)) lastslash = 0; else #endif { /* Set LASTSLASH to point at the last slash in FILENAME but not counting any slash at the end. (foo/bar/ counts as bar/ in directory foo/, not empty in directory foo/bar/.) */ lastslash = memrchr (filename, '/', namelen - 1); #if MK_OS_VMS if (lastslash == NULL) lastslash = strrchr (filename, ']'); if (lastslash == NULL) lastslash = strrchr (filename, '>'); if (lastslash == NULL) lastslash = strrchr (filename, ':'); #endif #ifdef HAVE_DOS_PATHS /* Handle backslashes (possibly mixed with forward slashes) and the case of "d:file". */ { char *bslash = memrchr (filename, '\\', namelen - 1); if (lastslash == 0 || bslash > lastslash) lastslash = bslash; if (lastslash == 0 && filename[0] && filename[1] == ':') lastslash = filename + 1; } #endif } pathlen = lastslash ? lastslash - filename + 1 : 0; /* First see which pattern rules match this target and may be considered. Put them in TRYRULES. */ nrules = 0; for (rule = pattern_rules; rule != 0; rule = rule->next) { unsigned int ti; /* If the pattern rule has deps but no commands, ignore it. Users cancel built-in rules by redefining them without commands. */ if (rule->deps != 0 && rule->cmds == 0) continue; /* If this rule is in use by a parent pattern_search, don't use it here. */ if (rule->in_use) { DBS (DB_IMPLICIT, (_("Avoiding implicit rule recursion for rule '%s'.\n"), get_rule_defn (rule))); continue; } for (ti = 0; ti < rule->num; ++ti) { const char *target = rule->targets[ti]; const char *suffix = rule->suffixes[ti]; char check_lastslash; /* Rules that can match any filename and are not terminal are ignored if we're recursing, so that they cannot be intermediate files. */ if (recursions > 0 && target[1] == '\0' && !rule->terminal) continue; if (rule->lens[ti] > namelen) /* It can't possibly match. */ continue; /* From the lengths of the filename and the pattern parts, find the stem: the part of the filename that matches the %. */ stem = filename + (suffix - target - 1); stemlen = namelen - rule->lens[ti] + 1; /* Set CHECK_LASTSLASH if FILENAME contains a directory prefix and the target pattern does not contain a slash. */ check_lastslash = 0; if (lastslash) { #if MK_OS_VMS check_lastslash = strpbrk (target, "/]>:") == NULL; #else check_lastslash = strchr (target, '/') == 0; #endif #ifdef HAVE_DOS_PATHS /* Didn't find it yet: check for DOS-type directories. */ if (check_lastslash) { char *b = strchr (target, '\\'); check_lastslash = !(b || (target[0] && target[1] == ':')); } #endif } if (check_lastslash) { /* If so, don't include the directory prefix in STEM here. */ if (pathlen > stemlen) continue; stemlen -= pathlen; stem += pathlen; } /* Check that the rule pattern matches the text before the stem. */ if (check_lastslash) { if (stem > (lastslash + 1) && !strneq (target, lastslash + 1, stem - lastslash - 1)) continue; } else if (stem > filename && !strneq (target, filename, stem - filename)) continue; /* Check that the rule pattern matches the text after the stem. We could test simply use streq, but this way we compare the first two characters immediately. This saves time in the very common case where the first character matches because it is a period. */ if (*suffix != stem[stemlen] || (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1]))) continue; /* Record if we match a rule that not all filenames will match. */ if (target[1] != '\0') specific_rule_matched = 1; /* A rule with no dependencies and no commands exists solely to set specific_rule_matched when it matches. Don't try to use it. */ if (rule->deps == 0 && rule->cmds == 0) continue; /* Record this rule in TRYRULES and the index of the matching target in MATCHES. If several targets of the same rule match, that rule will be in TRYRULES more than once. */ tryrules[nrules].rule = rule; tryrules[nrules].matches = ti; tryrules[nrules].stemlen = stemlen + (check_lastslash ? pathlen : 0); tryrules[nrules].order = nrules; tryrules[nrules].checked_lastslash = check_lastslash; ++nrules; } } /* Bail out early if we haven't found any rules. */ if (nrules == 0) goto done; /* Sort the rules to place matches with the shortest stem first. This way the most specific rules will be tried first. */ if (nrules > 1) qsort (tryrules, nrules, sizeof (struct tryrule), stemlen_compare); /* If we have found a matching rule that won't match all filenames, retroactively reject any non-"terminal" rules that do always match. */ if (specific_rule_matched) for (ri = 0; ri < nrules; ++ri) if (!tryrules[ri].rule->terminal) { unsigned int j; for (j = 0; j < tryrules[ri].rule->num; ++j) if (tryrules[ri].rule->targets[j][1] == '\0') { tryrules[ri].rule = 0; break; } } /* Try each rule once without intermediate files, then once with them. */ for (intermed_ok = 0; intermed_ok < 2; ++intermed_ok) { pat = deplist; if (intermed_ok) DBS (DB_IMPLICIT, (_("Trying harder.\n"))); /* Try each pattern rule till we find one that applies. If it does, expand its dependencies (as substituted) and chain them in DEPS. */ for (ri = 0; ri < nrules; ri++) { struct dep *dep; char check_lastslash; unsigned int failed = 0; int file_variables_set = 0; unsigned int deps_found = 0; /* NPTR points to the part of the prereq we haven't processed. */ const char *nptr = 0; int order_only = 0; unsigned int matches; rule = tryrules[ri].rule; /* RULE is nil when we discover that a rule, already placed in TRYRULES, should not be applied. */ if (rule == 0) continue; /* Reject any terminal rules if we're looking to make intermediate files. */ if (intermed_ok && rule->terminal) continue; /* From the lengths of the filename and the matching pattern parts, find the stem: the part of the filename that matches the %. */ matches = tryrules[ri].matches; stem = filename + (rule->suffixes[matches] - rule->targets[matches]) - 1; stemlen = (namelen - rule->lens[matches]) + 1; check_lastslash = tryrules[ri].checked_lastslash; if (check_lastslash) { stem += pathlen; stemlen -= pathlen; /* We need to add the directory prefix, so set it up. */ if (! pathdir) { pathdir = alloca (pathlen + 1); memcpy (pathdir, filename, pathlen); pathdir[pathlen] = '\0'; } } DBS (DB_IMPLICIT, (_("Trying pattern rule '%s' with stem '%.*s'.\n"), get_rule_defn (rule), (int) stemlen, stem)); if (stemlen + (check_lastslash ? pathlen : 0) > GET_PATH_MAX) { DBS (DB_IMPLICIT, (_("Stem too long: '%s%.*s'.\n"), check_lastslash ? pathdir : "", (int) stemlen, stem)); continue; } if (!check_lastslash) { memcpy (stem_str, stem, stemlen); stem_str[stemlen] = '\0'; } else { /* We want to prepend the directory from the original FILENAME onto the stem. */ memcpy (stem_str, filename, pathlen); memcpy (stem_str + pathlen, stem, stemlen); stem_str[pathlen + stemlen] = '\0'; } /* If there are no prerequisites, then this rule matches. */ if (rule->deps == 0) break; /* Mark this rule as in use so a recursive pattern_search won't try to use it. */ rule->in_use = 1; /* Try each prerequisite; see if it exists or can be created. We'll build a list of prereq info in DEPLIST. Due to 2nd expansion we may have to process multiple prereqs for a single dep entry. */ pat = deplist; dep = rule->deps; nptr = dep_name (dep); while (1) { struct dep *dl, *d; /* If we're out of name to parse, start the next prereq. */ if (! nptr) { dep = dep->next; if (dep == 0) break; nptr = dep_name (dep); } /* If we don't need a second expansion, just replace the %. */ if (! dep->need_2nd_expansion) { char *p; int is_explicit = 1; const char *cp = strchr (nptr, '%'); if (cp == 0) strcpy (depname, nptr); else { char *o = depname; if (check_lastslash) o = mempcpy (o, filename, pathlen); o = mempcpy (o, nptr, cp - nptr); o = mempcpy (o, stem, stemlen); strcpy (o, cp + 1); is_explicit = 0; } /* Parse the expanded string. It might have wildcards. */ p = depname; dl = PARSE_FILE_SEQ (&p, struct dep, MAP_NUL, NULL, PARSEFS_ONEWORD|PARSEFS_WAIT); for (d = dl; d != NULL; d = d->next) { ++deps_found; d->ignore_mtime = dep->ignore_mtime; d->ignore_automatic_vars = dep->ignore_automatic_vars; d->wait_here |= dep->wait_here; d->is_explicit = is_explicit; } /* We've used up this dep, so next time get a new one. */ nptr = 0; } /* We have to perform second expansion on this prereq. In an ideal world we would take the dependency line, substitute the stem, re-expand the whole line and chop it into individual prerequisites. Unfortunately this won't work because of the "check_lastslash" twist. Instead, we will have to go word by word, taking $()'s into account. For each word we will substitute the stem, re-expand, chop it up, and, if check_lastslash != 0, add the directory part to each resulting prerequisite. */ else { int add_dir = 0; size_t len; const char *end; struct dep **dptr; int is_explicit; const char *cp; char *p; nptr = get_next_word (nptr, &len); if (nptr == 0) continue; end = nptr + len; /* See if this is a transition to order-only prereqs. */ if (! order_only && len == 1 && nptr[0] == '|') { order_only = 1; nptr = end; continue; } /* If the dependency name has %, substitute the stem. If we just replace % with the stem value then later, when we do the 2nd expansion, we will re-expand this stem value again. This is not good if you have certain characters in your stem (like $). Instead, we will replace % with $* or $(*F) and allow the second expansion to take care of it for us. This way (since $* and $(*F) are simple variables) there won't be additional re-expansion of the stem. */ cp = lindex (nptr, end, '%'); if (cp == 0) { memcpy (depname, nptr, len); depname[len] = '\0'; is_explicit = 1; } else { /* Go through all % between NPTR and END. Copy contents of [NPTR, END) to depname, with the first % after NPTR and then each first % after white space replaced with $* or $(*F). depname has enough room to substitute each % with $(*F). */ char *o = depname; is_explicit = 0; for (;;) { size_t i = cp - nptr; assert (o + i < dend); o = mempcpy (o, nptr, i); if (check_lastslash) { add_dir = 1; assert (o + 5 < dend); o = mempcpy (o, "$(*F)", 5); } else { assert (o + 2 < dend); o = mempcpy (o, "$*", 2); } assert (o < dend); ++cp; assert (cp <= end); nptr = cp; if (nptr == end) break; /* Skip the rest of this word then find the next %. No need to worry about order-only, or nested functions: NPTR went though get_next_word. */ while (cp < end && ! END_OF_TOKEN (*cp)) ++cp; cp = lindex (cp, end, '%'); if (cp == 0) break; } len = end - nptr; memcpy (o, nptr, len); o[len] = '\0'; } /* Set up for the next word. */ nptr = end; /* Initialize and set file variables if we haven't already done so. */ if (!file_vars_initialized) { initialize_file_variables (file, 0); set_file_variables (file, stem_str); file_vars_initialized = 1; } /* Update the stem value in $* for this rule. */ else if (!file_variables_set) { define_variable_for_file ( "*", 1, stem_str, o_automatic, 0, file); file_variables_set = 1; } /* Perform the 2nd expansion. */ p = expand_string_for_file (depname, file); dptr = &dl; /* Parse the results into a deps list. */ do { /* Parse the expanded string. */ struct dep *dp = PARSE_FILE_SEQ (&p, struct dep, order_only ? MAP_NUL : MAP_PIPE, add_dir ? pathdir : NULL, PARSEFS_WAIT); *dptr = dp; for (d = dp; d != NULL; d = d->next) { ++deps_found; if (order_only) d->ignore_mtime = 1; d->is_explicit = is_explicit; dptr = &d->next; } /* If we stopped due to an order-only token, note it. */ if (*p == '|') { order_only = 1; ++p; } } while (*p != '\0'); } /* If there are more than max_pattern_deps prerequisites (due to 2nd expansion), reset it and realloc the arrays. */ if (deps_found > max_deps) { size_t l = pat - deplist; /* This might have changed due to recursion. */ max_pattern_deps = MAX(max_pattern_deps, deps_found); max_deps = max_pattern_deps; deplist = xrealloc (deplist, max_deps * sizeof (struct patdeps)); pat = deplist + l; } /* Go through the nameseq and handle each as a prereq name. */ for (d = dl; d != 0; d = d->next) { struct file *df; int is_rule = d->name == dep_name (dep); int explicit = 0; struct dep *dp = 0; if (file_impossible_p (d->name)) { /* If this prereq has already been ruled "impossible", then the rule fails. Don't bother trying it on the second pass either since we know that will fail. */ DBS (DB_IMPLICIT, (is_rule ? _("Rejecting rule '%s' due to impossible rule" " prerequisite '%s'.\n") : _("Rejecting rule '%s' due to impossible implicit" " prerequisite '%s'.\n"), get_rule_defn (rule), d->name)); tryrules[ri].rule = 0; failed = 1; break; } memset (pat, '\0', sizeof (struct patdeps)); pat->ignore_mtime = d->ignore_mtime; pat->ignore_automatic_vars = d->ignore_automatic_vars; pat->wait_here = d->wait_here; pat->is_explicit = d->is_explicit; DBS (DB_IMPLICIT, (is_rule ? _("Trying rule prerequisite '%s'.\n") : _("Trying implicit prerequisite '%s'.\n"), d->name)); df = lookup_file (d->name); if (df && df->is_explicit) pat->is_explicit = 1; /* If we found a file for the dep, set its intermediate flag. df->is_explicit is set when the dep file is mentioned explicitly on some other rule. d->is_explicit is set when the dep file is mentioned explicitly on this rule. E.g.: %.x : %.y ; ... then: one.x: one.y: # df->is_explicit vs. one.x: one.y # d->is_explicit */ if (df && !df->is_explicit && !d->is_explicit) df->intermediate = 1; /* If the pattern prereq is also explicitly mentioned for FILE, skip all tests below since it must be built no matter which implicit rule we choose. */ if (df && df->is_target) /* This prerequisite is mentioned explicitly as a target of some rule. */ explicit = 1; else for (dp = file->deps; dp != 0; dp = dp->next) if (streq (d->name, dep_name (dp))) break; /* If dp is set, this prerequisite is mentioned explicitly as a prerequisite of the current target. */ if (explicit || dp) { (pat++)->name = d->name; DBS (DB_IMPLICIT, (_("'%s' ought to exist.\n"), d->name)); continue; } if (file_exists_p (d->name)) { (pat++)->name = d->name; DBS (DB_IMPLICIT, (_("Found '%s'.\n"), d->name)); continue; } if (df && allow_compat_rules) { (pat++)->name = d->name; DBS (DB_IMPLICIT, (_("Using compatibility rule '%s' due to '%s'.\n"), get_rule_defn (rule), d->name)); continue; } if (df) { /* This prerequisite is mentioned explicitly as a prerequisite on some rule, but it is not a prerequisite of the current target. Therefore, this prerequisite does not qualify as ought-to-exist. Keep note of this rule and continue the search. If a more suitable rule is not found, then use this rule. */ DBS (DB_IMPLICIT, (_("Prerequisite '%s' of rule '%s' does not qualify" " as ought to exist.\n"), d->name, get_rule_defn (rule))); found_compat_rule = 1; } /* This code, given FILENAME = "lib/foo.o", dependency name "lib/foo.c", and VPATH=src, searches for "src/lib/foo.c". */ { const char *vname = vpath_search (d->name, 0, NULL, NULL); if (vname) { DBS (DB_IMPLICIT, (_("Found prerequisite '%s' as VPATH '%s'.\n"), d->name, vname)); (pat++)->name = d->name; continue; } } /* We could not find the file in any place we should look. Look for an implicit rule to make this dependency, but only on the second pass. */ if (intermed_ok) { DBS (DB_IMPLICIT, (d->is_explicit || (df && df->is_explicit) ? _("Looking for a rule with explicit file '%s'.\n") : _("Looking for a rule with intermediate file '%s'.\n"), d->name)); if (int_file == 0) int_file = alloca (sizeof (struct file)); memset (int_file, '\0', sizeof (struct file)); int_file->name = d->name; if (pattern_search (int_file, 0, depth, recursions + 1, allow_compat_rules)) { pat->pattern = int_file->name; int_file->name = d->name; pat->file = int_file; int_file = 0; (pat++)->name = d->name; continue; } /* If we have tried to find P as an intermediate file and failed, mark that name as impossible so we won't go through the search again later. */ if (int_file->variables) free_variable_set (int_file->variables); if (int_file->pat_variables) free_variable_set (int_file->pat_variables); /* Keep prerequisites explicitly mentioned on unrelated rules as "possible" to let compatibility search find such prerequisites. */ if (df == 0) file_impossible (d->name); } /* A dependency of this rule does not exist. Therefore, this rule fails. */ if (intermed_ok) DBS (DB_IMPLICIT, (_("Rejecting rule '%s' " "due to impossible prerequisite '%s'.\n"), get_rule_defn (rule), d->name)); else DBS (DB_IMPLICIT, (_("Not found '%s'.\n"), d->name)); failed = 1; break; } /* Free the ns chain. */ free_dep_chain (dl); if (failed) break; } /* This rule is no longer 'in use' for recursive searches. */ rule->in_use = 0; if (! failed) /* This pattern rule does apply. Stop looking for one. */ break; /* This pattern rule does not apply. Keep looking. */ } /* If we found an applicable rule without intermediate files, don't try with them. */ if (ri < nrules) break; rule = 0; } /* RULE is nil if the loop went through the list but everything failed. */ if (rule == 0) goto done; foundrule = ri; /* If we are recursing, store the pattern that matched FILENAME in FILE->name for use in upper levels. */ if (recursions > 0) /* Kludge-o-matic */ file->name = rule->targets[tryrules[foundrule].matches]; /* DEPLIST lists the prerequisites for the rule we found. This includes the intermediate files, if any. Convert them into entries on the deps-chain of FILE. */ while (pat-- > deplist) { struct dep *dep; const char *s; if (pat->file != 0) { /* If we need to use an intermediate file, make sure it is entered as a target, with the info that was found for it in the recursive pattern_search call. We know that the intermediate file did not already exist as a target; therefore we can assume that the deps and cmds of F below are null before we change them. */ struct file *imf = pat->file; struct file *f = lookup_file (imf->name); if (!f) f = enter_file (imf->name); f->deps = imf->deps; f->cmds = imf->cmds; f->stem = imf->stem; /* Setting target specific variables for a file causes the file to be entered to the database as a prerequisite. Implicit search then treats this file as explicitly mentioned. Preserve target specific variables of this file. */ merge_variable_set_lists(&f->variables, imf->variables); f->pat_variables = imf->pat_variables; f->pat_searched = imf->pat_searched; f->also_make = imf->also_make; f->is_target = 1; f->is_explicit |= imf->is_explicit || pat->is_explicit; f->notintermediate |= imf->notintermediate || no_intermediates; f->intermediate |= !f->is_explicit && !f->notintermediate; f->tried_implicit = 1; imf = lookup_file (pat->pattern); if (imf != 0 && imf->precious) f->precious = 1; for (dep = f->deps; dep != 0; dep = dep->next) { dep->file = enter_file (dep->name); dep->name = 0; dep->file->tried_implicit |= dep->changed; } } dep = alloc_dep (); dep->ignore_mtime = pat->ignore_mtime; dep->is_explicit = pat->is_explicit; dep->ignore_automatic_vars = pat->ignore_automatic_vars; dep->wait_here = pat->wait_here; s = strcache_add (pat->name); if (recursions) dep->name = s; else { dep->file = lookup_file (s); if (dep->file == 0) dep->file = enter_file (s); } if (pat->file == 0 && tryrules[foundrule].rule->terminal) { /* If the file actually existed (was not an intermediate file), and the rule that found it was a terminal one, then we want to mark the found file so that it will not have implicit rule search done for it. If we are not entering a 'struct file' for it now, we indicate this with the 'changed' flag. */ if (dep->file == 0) dep->changed = 1; else dep->file->tried_implicit = 1; } dep->next = file->deps; file->deps = dep; /* The file changed its dependencies; schedule the shuffle. */ file->was_shuffled = 0; } if (!file->was_shuffled) shuffle_deps_recursive (file->deps); if (!tryrules[foundrule].checked_lastslash) { /* Always allocate new storage, since STEM might be on the stack for an intermediate file. */ file->stem = strcache_add_len (stem, stemlen); fullstemlen = stemlen; } else { /* We want to prepend the directory from the original FILENAME onto the stem. */ fullstemlen = pathlen + stemlen; memcpy (stem_str, filename, pathlen); memcpy (stem_str + pathlen, stem, stemlen); stem_str[fullstemlen] = '\0'; file->stem = strcache_add (stem_str); } file->cmds = rule->cmds; file->is_target = 1; /* Set precious and notintermediate flags. */ { struct file *f = lookup_file (rule->targets[tryrules[foundrule].matches]); if (f) { if (f->precious) file->precious = 1; if (f->notintermediate || no_intermediates) file->notintermediate = 1; } } /* If this rule builds other targets, too, put the others into FILE's 'also_make' member. */ if (rule->num > 1) for (ri = 0; ri < rule->num; ++ri) if (ri != tryrules[foundrule].matches) { char *nm = alloca (rule->lens[ri] + fullstemlen + 1); char *p = nm; struct file *f; struct dep *new = alloc_dep (); /* GKM FIMXE: handle '|' here too */ p = mempcpy (p, rule->targets[ri], rule->suffixes[ri] - rule->targets[ri] - 1); p = mempcpy (p, file->stem, fullstemlen); memcpy (p, rule->suffixes[ri], rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1); new->name = strcache_add (nm); new->file = enter_file (new->name); new->next = file->also_make; /* Set precious flag. */ f = lookup_file (rule->targets[ri]); if (f) { if (f->precious) new->file->precious = 1; if (f->notintermediate || no_intermediates) new->file->notintermediate = 1; } /* Set the is_target flag so that this file is not treated as intermediate by the pattern rule search algorithm and file_exists_p cannot pick it up yet. */ new->file->is_target = 1; file->also_make = new; } done: free (tryrules); free (deplist); --depth; if (rule) { DBS (DB_IMPLICIT, (_("Found implicit rule '%s' for '%s'.\n"), get_rule_defn (rule), filename)); return 1; } if (found_compat_rule) { DBS (DB_IMPLICIT, (_("Searching for a compatibility rule for '%s'.\n"), filename)); assert (allow_compat_rules == 0); return pattern_search (file, archive, depth, recursions, 1); } DBS (DB_IMPLICIT, (_("No implicit rule found for '%s'.\n"), filename)); return 0; } ================================================ FILE: src/job.c ================================================ /* Job execution and handling for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include /* Default shell to use. */ #if MK_OS_W32 # include const char *default_shell = "sh.exe"; int no_default_sh_exe = 1; int batch_mode_shell = 1; HANDLE main_thread; #elif MK_OS_DOS /* The default shell is a pointer so we can change it if Makefile says so. It is without an explicit path so we get a chance to search the $PATH for it (since MSDOS doesn't have standard directories we could trust). */ const char *default_shell = "command.com"; int batch_mode_shell = 0; #elif MK_OS_OS2 const char *default_shell = "/bin/sh"; int batch_mode_shell = 0; #elif MK_OS_VMS # include # include const char *default_shell = ""; int batch_mode_shell = 0; #define strsignal vms_strsignal char * vms_strsignal (int status); #ifndef C_FACILITY_NO # define C_FACILITY_NO 0x350000 #endif #ifndef VMS_POSIX_EXIT_MASK # define VMS_POSIX_EXIT_MASK (C_FACILITY_NO | 0xA000) #endif #else const char *default_shell = "/bin/sh"; int batch_mode_shell = 0; #endif #if MK_OS_DOS # include static int execute_by_shell; static int dos_pid = 123; int dos_status; int dos_command_running; #endif /* MK_OS_DOS */ #if MK_OS_VMS # ifndef __GNUC__ # include # endif # include # include static void vmsWaitForChildren (int *); #endif #if MK_OS_W32 # include # include # include # include "sub_proc.h" # include "w32err.h" # include "pathstuff.h" # define WAIT_NOHANG 1 #endif /* MK_OS_W32 */ #if MK_OS_OS2 # include #endif #if defined (HAVE_FCNTL_H) # include #endif #if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT) # include #endif #ifdef HAVE_WAITPID # define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG) #else /* Don't have waitpid. */ # ifdef HAVE_WAIT3 # ifndef wait3 extern int wait3 (); # endif # define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0) # endif /* Have wait3. */ #endif /* Have waitpid. */ #ifdef USE_POSIX_SPAWN # include # include "findprog.h" #endif #if !defined (wait) && !defined (POSIX) int wait (); #endif #ifndef HAVE_UNION_WAIT # define WAIT_T int # ifndef WTERMSIG # define WTERMSIG(x) ((x) & 0x7f) # endif # ifndef WCOREDUMP # define WCOREDUMP(x) ((x) & 0x80) # endif # ifndef WEXITSTATUS # define WEXITSTATUS(x) (((x) >> 8) & 0xff) # endif # ifndef WIFSIGNALED # define WIFSIGNALED(x) (WTERMSIG (x) != 0) # endif # ifndef WIFEXITED # define WIFEXITED(x) (WTERMSIG (x) == 0) # endif #else /* Have 'union wait'. */ # define WAIT_T union wait # ifndef WTERMSIG # define WTERMSIG(x) ((x).w_termsig) # endif # ifndef WCOREDUMP # define WCOREDUMP(x) ((x).w_coredump) # endif # ifndef WEXITSTATUS # define WEXITSTATUS(x) ((x).w_retcode) # endif # ifndef WIFSIGNALED # define WIFSIGNALED(x) (WTERMSIG(x) != 0) # endif # ifndef WIFEXITED # define WIFEXITED(x) (WTERMSIG(x) == 0) # endif #endif /* Don't have 'union wait'. */ #if !defined(HAVE_UNISTD_H) && !MK_OS_W32 int dup2 (); int execve (); void _exit (); # if !MK_OS_VMS int geteuid (); int getegid (); int setgid (); int getgid (); # endif #endif #if HAVE_SYS_LOADAVG_H # include #endif #if HAVE_DECL_GETLOADAVG == 0 int getloadavg (double loadavg[], int nelem); #endif #include "job.h" #include "debug.h" #include "filedef.h" #include "commands.h" #include "variable.h" #include "os.h" #include "dep.h" #include "shuffle.h" #include "warning.h" /* Different systems have different requirements for pid_t. Plus we have to support gettext string translation... Argh. */ static const char * pid2str (pid_t pid) { static char pidstring[100]; #if MK_OS_W32 && (__GNUC__ > 3 || _MSC_VER > 1300) /* %Id is only needed for 64-builds, which were not supported by older versions of Windows compilers. */ sprintf (pidstring, "%Id", pid); #else sprintf (pidstring, "%lu", (unsigned long) pid); #endif return pidstring; } static void free_child (struct child *); static void start_job_command (struct child *child); static int load_too_high (void); static int job_next_command (struct child *); static int start_waiting_job (struct child *); /* Chain of all live (or recently deceased) children. */ struct child *children = 0; /* Number of children currently running. */ unsigned int job_slots_used = 0; /* Nonzero if the 'good' standard input is in use. */ static int good_stdin_used = 0; /* Chain of children waiting to run until the load average goes down. */ static struct child *waiting_jobs = 0; /* Non-zero if we use a *real* shell (always so on Unix). */ int unixy_shell = 1; /* Number of jobs started in the current second. */ unsigned long job_counter = 0; /* Number of jobserver tokens this instance is currently using. */ unsigned int jobserver_tokens = 0; #if MK_OS_W32 /* * The macro which references this function is defined in makeint.h. */ int w32_kill (pid_t pid, int sig) { return ((process_kill ((HANDLE)pid, sig) == TRUE) ? 0 : -1); } /* This function creates a temporary file name with an extension specified * by the unixy arg. * Return an xmalloc'ed string of a newly created temp file and its * file descriptor, or die. */ static char * create_batch_file (char const *base, int unixy, int *fd) { const char *const ext = unixy ? "sh" : "bat"; const char *error_string = NULL; char temp_path[MAX_PATH+1]; /* need to know its length */ unsigned path_size = GetTempPath (sizeof temp_path, temp_path); int path_is_dot = 0; /* The following variable is static so we won't try to reuse a name that was generated a little while ago, because that file might not be on disk yet, since we use FILE_ATTRIBUTE_TEMPORARY below, which tells the OS it doesn't need to flush the cache to disk. If the file is not yet on disk, we might think the name is available, while it really isn't. This happens in parallel builds, where Make doesn't wait for one job to finish before it launches the next one. */ static unsigned uniq = 0; static int second_loop = 0; const size_t sizemax = strlen (base) + strlen (ext) + 10; if (path_size == 0) { path_size = GetCurrentDirectory (sizeof temp_path, temp_path); path_is_dot = 1; } ++uniq; if (uniq >= 0x10000 && !second_loop) { /* If we already had 64K batch files in this process, make a second loop through the numbers, looking for free slots, i.e. files that were deleted in the meantime. */ second_loop = 1; uniq = 1; } while (path_size > 0 && path_size + sizemax < sizeof temp_path && !(uniq >= 0x10000 && second_loop)) { unsigned size = sprintf (temp_path + path_size, "%s%s-%x.%s", temp_path[path_size - 1] == '\\' ? "" : "\\", base, uniq, ext); HANDLE h = CreateFile (temp_path, /* file name */ GENERIC_READ | GENERIC_WRITE, /* desired access */ 0, /* no share mode */ NULL, /* default security attributes */ CREATE_NEW, /* creation disposition */ FILE_ATTRIBUTE_NORMAL | /* flags and attributes */ FILE_ATTRIBUTE_TEMPORARY, /* we'll delete it */ NULL); /* no template file */ if (h == INVALID_HANDLE_VALUE) { const DWORD er = GetLastError (); if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS) { ++uniq; if (uniq == 0x10000 && !second_loop) { second_loop = 1; uniq = 1; } } /* the temporary path is not guaranteed to exist */ else if (path_is_dot == 0) { path_size = GetCurrentDirectory (sizeof temp_path, temp_path); path_is_dot = 1; } else { error_string = map_windows32_error_to_string (er); break; } } else { const unsigned final_size = path_size + size + 1; char *const path = xmalloc (final_size); memcpy (path, temp_path, final_size); *fd = _open_osfhandle ((intptr_t)h, 0); if (unixy) { char *p; int ch; for (p = path; (ch = *p) != 0; ++p) if (ch == '\\') *p = '/'; } return path; /* good return */ } } *fd = -1; if (error_string == NULL) error_string = _("Cannot create a temporary file"); OS (fatal, NILF, "%s", error_string); /* not reached */ return NULL; } #endif /* MK_OS_W32 */ #if MK_OS_OS2 /* returns whether path is assumed to be a unix like shell. */ int _is_unixy_shell (const char *path) { /* list of non unix shells */ const char *known_os2shells[] = { "cmd.exe", "cmd", "4os2.exe", "4os2", "4dos.exe", "4dos", "command.com", "command", NULL }; /* find the rightmost '/' or '\\' */ const char *name = strrchr (path, '/'); const char *p = strrchr (path, '\\'); unsigned i; if (name && p) /* take the max */ name = (name > p) ? name : p; else if (p) /* name must be 0 */ name = p; else if (!name) /* name and p must be 0 */ name = path; if (ISDIRSEP (*name)) name++; i = 0; while (known_os2shells[i] != NULL) { if (strcasecmp (name, known_os2shells[i]) == 0) return 0; /* not a unix shell */ i++; } /* in doubt assume a unix like shell */ return 1; } #endif /* MK_OS_OS2 */ /* determines whether path looks to be a Bourne-like shell. */ int is_bourne_compatible_shell (const char *path) { /* List of known POSIX (or POSIX-ish) shells. */ static const char *unix_shells[] = { "sh", "bash", "dash", "ksh", "rksh", "zsh", "ash", NULL }; const char **s; /* find the last directory separator, or the beginning of the string. */ const char *cp = path + strlen (path); while (cp > path && !ISDIRSEP (cp[-1])) --cp; /* this should be able to deal with extensions on Windows-like systems */ for (s = unix_shells; *s != NULL; ++s) { #if MK_OS_W32 || MK_OS_DOS size_t len = strlen (*s); if ((strlen (cp) >= len && STOP_SET (cp[len], MAP_DOT|MAP_NUL)) && strncasecmp (cp, *s, len) == 0) #else if (strcmp (cp, *s) == 0) #endif return 1; /* a known unix-style shell */ } /* if not on the list, assume it's not a Bourne-like shell */ return 0; } #ifdef POSIX extern sigset_t fatal_signal_set; static void block_sigs () { sigprocmask (SIG_BLOCK, &fatal_signal_set, (sigset_t *) 0); } static void unblock_sigs () { sigprocmask (SIG_UNBLOCK, &fatal_signal_set, (sigset_t *) 0); } void unblock_all_sigs () { sigset_t empty; sigemptyset (&empty); sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0); } #elif defined(HAVE_SIGSETMASK) extern int fatal_signal_mask; static void block_sigs () { sigblock (fatal_signal_mask); } static void unblock_sigs () { sigsetmask (siggetmask () & ~fatal_signal_mask); } void unblock_all_sigs () { sigsetmask (0); } #else #define block_sigs() #define unblock_sigs() void unblock_all_sigs () { } #endif /* Write an error message describing the exit status given in EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME. Append "(ignored)" if IGNORED is nonzero. */ static void child_error (struct child *child, int exit_code, int exit_sig, int coredump, int ignored) { const char *pre = "*** "; const char *post = ""; const char *dump = ""; const struct file *f = child->file; const floc *flocp = &f->cmds->fileinfo; const char *nm; const char *smode; size_t l; if (ignored && run_silent) return; if (exit_sig && coredump) dump = _(" (core dumped)"); if (ignored) { pre = ""; post = _(" (ignored)"); } if (! flocp->filenm) nm = _(""); else { char *a = alloca (strlen (flocp->filenm) + 6 + INTSTR_LENGTH + 1); sprintf (a, "%s:%lu", flocp->filenm, flocp->lineno + flocp->offset); nm = a; } l = strlen (pre) + strlen (nm) + strlen (f->name) + strlen (post); smode = shuffle_get_mode (); if (smode) { #define SHUFFLE_PREFIX " shuffle=" char *a = alloca (CSTRLEN(SHUFFLE_PREFIX) + strlen (smode) + 1); sprintf (a, SHUFFLE_PREFIX "%s", smode); smode = a; l += strlen (smode); #undef SHUFFLE_PREFIX } OUTPUT_SET (&child->output); show_goal_error (); if (exit_sig == 0) error (NILF, l + INTSTR_LENGTH, _("%s[%s: %s] Error %d%s%s"), pre, nm, f->name, exit_code, post, smode ? smode : ""); else { const char *s = strsignal (exit_sig); error (NILF, l + strlen (s) + strlen (dump), "%s[%s: %s] %s%s%s%s", pre, nm, f->name, s, dump, post, smode ? smode : ""); } OUTPUT_UNSET (); } /* Handle a dead child. This handler may or may not ever be installed. If we're using the jobserver feature without pselect(), we need it. First, installing it ensures the read will interrupt on SIGCHLD. Second, we close the dup'd read FD to ensure we don't enter another blocking read without reaping all the dead children. In this case we don't need the dead_children count. If we don't have either waitpid or wait3, then make is unreliable, but we use the dead_children count to reap children as best we can. */ static unsigned int dead_children = 0; void child_handler (int sig UNUSED) { ++dead_children; jobserver_signal (); #if MK_OS_OS2 /* The signal handler must called only once! */ signal (SIGCHLD, SIG_DFL); #endif } extern pid_t shell_function_pid; /* Reap all dead children, storing the returned status and the new command state ('cs_finished') in the 'file' member of the 'struct child' for the dead child, and removing the child from the chain. In addition, if BLOCK nonzero, we block in this function until we've reaped at least one complete child, waiting for it to die if necessary. If ERR is nonzero, print an error message first. */ void reap_children (int block, int err) { #if !MK_OS_W32 WAIT_T status; #endif /* Initially, assume we have some. */ int reap_more = 1; #ifdef WAIT_NOHANG # define REAP_MORE reap_more #else # define REAP_MORE dead_children #endif /* As long as: We have at least one child outstanding OR a shell function in progress, AND We're blocking for a complete child OR there are more children to reap we'll keep reaping children. */ while ((children != 0 || shell_function_pid != 0) && (block || REAP_MORE)) { unsigned int remote = 0; pid_t pid; int exit_code, exit_sig, coredump; struct child *lastc, *c; int child_failed; int any_remote, any_local; int dontcare; if (err && block) { static int printed = 0; /* We might block for a while, so let the user know why. Only print this message once no matter how many jobs are left. */ fflush (stdout); if (!printed) O (error, NILF, _("*** Waiting for unfinished jobs....")); printed = 1; } /* We have one less dead child to reap. As noted in child_handler() above, this count is completely unimportant for all modern, POSIX-y systems that support wait3() or waitpid(). The rest of this comment below applies only to early, broken pre-POSIX systems. We keep the count only because... it's there... The test and decrement are not atomic; if it is compiled into: register = dead_children - 1; dead_children = register; a SIGCHLD could come between the two instructions. child_handler increments dead_children. The second instruction here would lose that increment. But the only effect of dead_children being wrong is that we might wait longer than necessary to reap a child, and lose some parallelism; and we might print the "Waiting for unfinished jobs" message above when not necessary. */ if (dead_children > 0) --dead_children; any_remote = 0; any_local = shell_function_pid != 0; lastc = 0; for (c = children; c != 0; lastc = c, c = c->next) { any_remote |= c->remote; any_local |= ! c->remote; /* If pid < 0, this child never even started. Handle it. */ if (c->pid < 0) { exit_sig = 0; coredump = 0; /* According to POSIX, 127 is used for command not found. */ exit_code = 127; goto process_child; } DB (DB_JOBS, (_("Live child %p (%s) PID %s %s\n"), c, c->file->name, pid2str (c->pid), c->remote ? _(" (remote)") : "")); #if MK_OS_VMS break; #endif } /* First, check for remote children. */ if (any_remote) pid = remote_status (&exit_code, &exit_sig, &coredump, 0); else pid = 0; if (pid > 0) /* We got a remote child. */ remote = 1; else if (pid < 0) { /* A remote status command failed miserably. Punt. */ pfatal_with_name ("remote_status"); } else { /* No remote children. Check for local children. */ #if !MK_OS_DOS && !MK_OS_W32 if (any_local) { #if MK_OS_VMS /* Todo: This needs more untangling multi-process support */ /* Just do single child process support now */ vmsWaitForChildren (&status); pid = c->pid; /* VMS failure status can not be fully translated */ status = $VMS_STATUS_SUCCESS (c->cstatus) ? 0 : (1 << 8); /* A Posix failure can be exactly translated */ if ((c->cstatus & VMS_POSIX_EXIT_MASK) == VMS_POSIX_EXIT_MASK) status = (c->cstatus >> 3 & 255) << 8; #else #ifdef WAIT_NOHANG if (!block) pid = WAIT_NOHANG (&status); else #endif EINTRLOOP (pid, wait (&status)); #endif /* !MK_OS_VMS */ } else pid = 0; if (pid < 0) { /* The wait*() failed miserably. Punt. */ pfatal_with_name ("wait"); } else if (pid > 0) { /* We got a child exit; chop the status word up. */ exit_code = WEXITSTATUS (status); exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0; coredump = WCOREDUMP (status); } else { /* No local children are dead. */ reap_more = 0; if (!block || !any_remote) break; /* Now try a blocking wait for a remote child. */ pid = remote_status (&exit_code, &exit_sig, &coredump, 1); if (pid < 0) pfatal_with_name ("remote_status"); if (pid == 0) /* No remote children either. Finally give up. */ break; /* We got a remote child. */ remote = 1; } #endif /* !MK_OS_DOS, !MK_OS_W32. */ #if MK_OS_DOS /* Life is very different on MSDOS. */ pid = dos_pid - 1; status = dos_status; exit_code = WEXITSTATUS (status); if (exit_code == 0xff) exit_code = -1; exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0; coredump = 0; #endif /* MK_OS_DOS */ #if MK_OS_W32 { HANDLE hPID; HANDLE hcTID, hcPID; DWORD dwWaitStatus = 0; exit_code = 0; exit_sig = 0; coredump = 0; /* Record the thread ID of the main process, so that we could suspend it in the signal handler. */ if (!main_thread) { hcTID = GetCurrentThread (); hcPID = GetCurrentProcess (); if (!DuplicateHandle (hcPID, hcTID, hcPID, &main_thread, 0, FALSE, DUPLICATE_SAME_ACCESS)) { DWORD e = GetLastError (); fprintf (stderr, "Determine main thread ID (Error %lu: %s)\n", e, map_windows32_error_to_string (e)); } else DB (DB_VERBOSE, ("Main thread handle = %p\n", main_thread)); } /* wait for anything to finish */ hPID = process_wait_for_any (block, &dwWaitStatus); if (hPID) { /* was an error found on this process? */ int werr = process_last_err (hPID); /* get exit data */ exit_code = process_exit_code (hPID); /* the extra tests of exit_code are here to prevent map_windows32_error_to_string from calling 'fatal', which will then call reap_children again */ if (werr && exit_code > 0 && exit_code < WSABASEERR) fprintf (stderr, "make (e=%d): %s\n", exit_code, map_windows32_error_to_string (exit_code)); /* signal */ exit_sig = process_signal (hPID); /* cleanup process */ process_cleanup (hPID); coredump = 0; } else if (dwWaitStatus == WAIT_FAILED) { /* The WaitForMultipleObjects() failed miserably. Punt. */ pfatal_with_name ("WaitForMultipleObjects"); } else if (dwWaitStatus == WAIT_TIMEOUT) { /* No child processes are finished. Give up waiting. */ reap_more = 0; break; } pid = (pid_t) hPID; } #endif /* MK_OS_W32 */ } /* Some child finished: increment the command count. */ ++command_count; /* Check if this is the child of the 'shell' function. */ if (!remote && pid == shell_function_pid) { shell_completed (exit_code, exit_sig); break; } /* Search for a child matching the deceased one. */ lastc = 0; for (c = children; c != 0; lastc = c, c = c->next) if (c->pid == pid && c->remote == remote) break; if (c == 0) /* An unknown child died. Ignore it; it was inherited from our invoker. */ continue; DB (DB_JOBS, (exit_sig == 0 && exit_code == 0 ? _("Reaping winning child %p PID %s %s\n") : _("Reaping losing child %p PID %s %s\n"), c, pid2str (c->pid), c->remote ? _(" (remote)") : "")); /* If we have started jobs in this second, remove one. */ if (job_counter) --job_counter; process_child: #if defined(USE_POSIX_SPAWN) /* Some versions of posix_spawn() do not detect errors such as command not found until after they fork. In that case they will exit with a code of 127. Try to detect that and provide a useful error message. Otherwise we'll just show the error below, as normal. */ if (exit_sig == 0 && exit_code == 127 && c->cmd_name) { const char *e = NULL; struct stat st; int r; /* There are various ways that this will show a different error than fork/exec. To really get the right error we'd have to fall back to fork/exec but I don't want to bother with that. Just do the best we can. */ EINTRLOOP(r, stat (c->cmd_name, &st)); if (r < 0) e = strerror (errno); else if (S_ISDIR(st.st_mode) || !(st.st_mode & S_IXUSR)) e = strerror (EACCES); else if (st.st_size == 0) e = strerror (ENOEXEC); if (e) OSS(error, NILF, "%s: %s", c->cmd_name, e); } #endif /* Determine the failure status: 0 for success, 1 for updating target in question mode, 2 for anything else. */ if (exit_sig == 0 && exit_code == 0) child_failed = MAKE_SUCCESS; else if (exit_sig == 0 && exit_code == 1 && question_flag && c->recursive) child_failed = MAKE_TROUBLE; else child_failed = MAKE_FAILURE; if (c->sh_batch_file) { int rm_status; DB (DB_JOBS, (_("Cleaning up temp batch file %s\n"), c->sh_batch_file)); errno = 0; rm_status = remove (c->sh_batch_file); if (rm_status) DB (DB_JOBS, (_("Cleaning up temp batch file %s failed (%d)\n"), c->sh_batch_file, errno)); /* all done with memory */ free (c->sh_batch_file); c->sh_batch_file = NULL; } /* If this child had the good stdin, say it is now free. */ if (c->good_stdin) good_stdin_used = 0; dontcare = c->dontcare; if (child_failed && !c->noerror && !ignore_errors_flag) { /* The commands failed. Write an error message, delete non-precious targets, and abort. */ static int delete_on_error = -1; if (!dontcare && child_failed == MAKE_FAILURE) child_error (c, exit_code, exit_sig, coredump, 0); c->file->update_status = child_failed == MAKE_FAILURE ? us_failed : us_question; if (delete_on_error == -1) { struct file *f = lookup_file (".DELETE_ON_ERROR"); delete_on_error = f != 0 && f->is_target; } if (exit_sig != 0 || delete_on_error) delete_child_targets (c); } else { if (child_failed) { /* The commands failed, but we don't care. */ child_error (c, exit_code, exit_sig, coredump, 1); child_failed = 0; } /* If there are more commands to run, try to start them. */ if (job_next_command (c)) { if (handling_fatal_signal) { /* Never start new commands while we are dying. Since there are more commands that wanted to be run, the target was not completely remade. So we treat this as if a command had failed. */ c->file->update_status = us_failed; } else { /* If we're sync'ing per line, write the previous line's output before starting the next one. */ if (output_sync == OUTPUT_SYNC_LINE) output_dump (&c->output); /* Check again whether to start remotely. Whether or not we want to changes over time. Also, start_remote_job may need state set up by start_remote_job_p. */ c->remote = start_remote_job_p (0); start_job_command (c); /* Fatal signals are left blocked in case we were about to put that child on the chain. But it is already there, so it is safe for a fatal signal to arrive now; it will clean up this child's targets. */ unblock_sigs (); if (c->file->command_state == cs_running) /* We successfully started the new command. Loop to reap more children. */ continue; } if (c->file->update_status != us_success) /* We failed to start the commands. */ delete_child_targets (c); } else /* There are no more commands. We got through them all without an unignored error. Now the target has been successfully updated. */ c->file->update_status = us_success; } /* When we get here, all the commands for c->file are finished. */ /* Synchronize any remaining parallel output. */ output_dump (&c->output); /* At this point c->file->update_status is success or failed. But c->file->command_state is still cs_running if all the commands ran; notice_finished_file looks for cs_running to tell it that it's interesting to check the file's modtime again now. */ if (! handling_fatal_signal) /* Notice if the target of the commands has been changed. This also propagates its values for command_state and update_status to its also_make files. */ notice_finished_file (c->file); /* Block fatal signals while frobnicating the list, so that children and job_slots_used are always consistent. Otherwise a fatal signal arriving after the child is off the chain and before job_slots_used is decremented would believe a child was live and call reap_children again. */ block_sigs (); if (c->pid > 0) { DB (DB_JOBS, (_("Removing child %p PID %s%s from chain.\n"), c, pid2str (c->pid), c->remote ? _(" (remote)") : "")); } /* There is now another slot open. */ if (job_slots_used > 0) job_slots_used -= c->jobslot; /* Remove the child from the chain and free it. */ if (lastc == 0) children = c->next; else lastc->next = c->next; free_child (c); unblock_sigs (); /* If the job failed, and the -k flag was not given, die, unless we are already in the process of dying. */ if (!err && child_failed && !dontcare && !keep_going_flag && /* fatal_error_signal will die with the right signal. */ !handling_fatal_signal) die (child_failed); /* Only block for one child. */ block = 0; } return; } /* Free the storage allocated for CHILD. */ void free_childbase (struct childbase *child) { if (child->environment != 0) { char **ep = child->environment; while (*ep != 0) free (*ep++); free (child->environment); } free (child->cmd_name); } static void free_child (struct child *child) { output_close (&child->output); if (!jobserver_tokens) ONS (fatal, NILF, "INTERNAL: freeing child %p (%s) but no tokens left", child, child->file->name); /* If we're using the jobserver and this child is not the only outstanding job, put a token back into the pipe for it. */ if (jobserver_enabled () && jobserver_tokens > 1) { jobserver_release (1); DB (DB_JOBS, (_("Released token for child %p (%s).\n"), child, child->file->name)); } --jobserver_tokens; if (handling_fatal_signal) /* Don't bother free'ing if about to die. */ return; if (child->command_lines != 0) { unsigned int i; for (i = 0; i < child->file->cmds->ncommand_lines; ++i) free (child->command_lines[i]); free (child->command_lines); } free_childbase ((struct childbase*)child); free (child); } /* Start a job to run the commands specified in CHILD. CHILD is updated to reflect the commands and ID of the child process. NOTE: On return fatal signals are blocked! The caller is responsible for calling 'unblock_sigs', once the new child is safely on the chain so it can be cleaned up in the event of a fatal signal. */ static void start_job_command (struct child *child) { int flags; char *p; #if MK_OS_VMS # define FREE_ARGV(_a) char *argv; #else # define FREE_ARGV(_a) do{ if (_a) { free ((_a)[0]); free (_a); } }while(0) char **argv; #endif /* If we have a completely empty commandset, stop now. */ if (!child->command_ptr) goto next_command; /* Combine the flags parsed for the line itself with the flags specified globally for this target. */ flags = (child->file->command_flags | child->file->cmds->lines_flags[child->command_line - 1]); p = child->command_ptr; child->noerror = ANY_SET (flags, COMMANDS_NOERROR); while (*p != '\0') { if (*p == '@') flags |= COMMANDS_SILENT; else if (*p == '+') flags |= COMMANDS_RECURSE; else if (*p == '-') child->noerror = 1; /* Don't skip newlines. */ else if (!ISBLANK (*p)) break; ++p; } child->recursive = ANY_SET (flags, COMMANDS_RECURSE); /* Update the file's command flags with any new ones we found. We only keep the COMMANDS_RECURSE setting. Even this isn't 100% correct; we are now marking more commands recursive than should be in the case of multiline define/endef scripts where only one line is marked "+". In order to really fix this, we'll have to keep a lines_flags for every actual line, after expansion. */ child->file->cmds->lines_flags[child->command_line - 1] |= flags & COMMANDS_RECURSE; /* POSIX requires that a recipe prefix after a backslash-newline should be ignored. Remove it now so the output is correct. */ { char prefix = child->file->cmds->recipe_prefix; char *p1, *p2; p1 = p2 = p; while (*p1 != '\0') { *(p2++) = *p1; if (p1[0] == '\n' && p1[1] == prefix) ++p1; ++p1; } *p2 = *p1; } /* Figure out an argument list from this command line. */ { char *end = 0; #if MK_OS_VMS /* Skip any leading whitespace */ while (*p) { if (!ISSPACE (*p)) { if (*p != '\\') break; if ((p[1] != '\n') && (p[1] != 'n') && (p[1] != 't')) break; } p++; } argv = p; /* Please note, for VMS argv is a string (not an array of strings) which contains the complete command line, which for multi-line variables still includes the newlines. So detect newlines and set 'end' (which is used for child->command_ptr) instead of (re-)writing construct_command_argv */ if (!one_shell) { char *s = p; int instring = 0; while (*s) { if (*s == '"') instring = !instring; else if (*s == '\\' && !instring && *(s+1) != 0) s++; else if (*s == '\n' && !instring) { end = s; break; } ++s; } } #else argv = construct_command_argv (p, &end, child->file, child->file->cmds->lines_flags[child->command_line - 1] | child->file->command_flags, &child->sh_batch_file); #endif if (end == NULL) child->command_ptr = NULL; else { *end++ = '\0'; child->command_ptr = end; } } /* If -q was given, say that updating 'failed' if there was any text on the command line, or 'succeeded' otherwise. The exit status of 1 tells the user that -q is saying 'something to do'; the exit status for a random error is 2. */ if (argv != 0 && question_flag && NONE_SET (flags, COMMANDS_RECURSE)) { FREE_ARGV (argv); #if MK_OS_VMS /* On VMS, argv[0] can be a null string here */ if (argv[0] != 0) { #endif child->file->update_status = us_question; notice_finished_file (child->file); return; #if MK_OS_VMS } #endif } if (touch_flag && NONE_SET (flags, COMMANDS_RECURSE)) { /* Go on to the next command. It might be the recursive one. We construct ARGV only to find the end of the command line. */ FREE_ARGV (argv); argv = 0; } if (argv == 0) { next_command: #if MK_OS_DOS execute_by_shell = 0; /* in case construct_command_argv sets it */ #endif /* This line has no commands. Go to the next. */ if (job_next_command (child)) start_job_command (child); else { /* No more commands. Make sure we're "running"; we might not be if (e.g.) all commands were skipped due to -n. */ set_command_state (child->file, cs_running); child->file->update_status = us_success; notice_finished_file (child->file); } OUTPUT_UNSET(); return; } /* Are we going to synchronize this command's output? Do so if either we're in SYNC_RECURSE mode or this command is not recursive. We'll also check output_sync separately below in case it changes due to error. */ child->output.syncout = output_sync && (output_sync == OUTPUT_SYNC_RECURSE || NONE_SET (flags, COMMANDS_RECURSE)); OUTPUT_SET (&child->output); if (! child->output.syncout) /* We don't want to sync this command: to avoid misordered output ensure any already-synced content is written. */ output_dump (&child->output); /* Print the command if appropriate. */ if (just_print_flag || ISDB (DB_PRINT) || (NONE_SET (flags, COMMANDS_SILENT) && !run_silent)) OS (message, 0, "%s", p); /* Tell update_goal_chain that a command has been started on behalf of this target. It is important that this happens here and not in reap_children (where we used to do it), because reap_children might be reaping children from a different target. We want this increment to guaranteedly indicate that a command was started for the dependency chain (i.e., update_file recursion chain) we are processing. */ ++commands_started; /* Optimize an empty command. People use this for timestamp rules, so avoid forking a useless shell. Do this after we increment commands_started so make still treats this special case as if it performed some action (makes a difference as to what messages are printed, etc. */ #if !MK_OS_VMS if ( #if MK_OS_DOS || MK_OS_OS2 unixy_shell /* the test is complicated and we already did it */ #else (argv[0] && is_bourne_compatible_shell (argv[0])) #endif && (argv[1] && argv[1][0] == '-' && ((argv[1][1] == 'c' && argv[1][2] == '\0') || (argv[1][1] == 'e' && argv[1][2] == 'c' && argv[1][3] == '\0'))) && (argv[2] && argv[2][0] == ':' && argv[2][1] == '\0') && argv[3] == NULL) { FREE_ARGV (argv); goto next_command; } #endif /* !MK_OS_VMS */ /* If -n was given, recurse to get the next line in the sequence. */ if (just_print_flag && NONE_SET (flags, COMMANDS_RECURSE)) { FREE_ARGV (argv); goto next_command; } /* We're sure we're going to invoke a command: set up the output. */ output_start (); /* Flush the output streams so they won't have things written twice. */ fflush (stdout); fflush (stderr); /* Decide whether to give this child the 'good' standard input (one that points to the terminal or whatever), or the 'bad' one that points to the read side of a broken pipe. */ child->good_stdin = !good_stdin_used; if (child->good_stdin) good_stdin_used = 1; child->deleted = 0; /* Set up the environment for the child. It's a slight inaccuracy to set the environment for recursive make even for command lines that aren't recursive, but I don't want to have to recompute the target environment for each command. Better would be to keep a separate entry for MAKEFLAGS in the environment so it could be replaced on its own. For now just set it for all lines. */ if (child->environment == 0) child->environment = target_environment (child->file, child->file->cmds->any_recurse); #if !MK_OS_DOS && !MK_OS_W32 #if !MK_OS_VMS /* start_waiting_job has set CHILD->remote if we can start a remote job. */ if (child->remote) { int is_remote, used_stdin; pid_t id; if (start_remote_job (argv, child->environment, child->good_stdin ? 0 : get_bad_stdin (), &is_remote, &id, &used_stdin)) /* Don't give up; remote execution may fail for various reasons. If so, simply run the job locally. */ goto run_local; else { if (child->good_stdin && !used_stdin) { child->good_stdin = 0; good_stdin_used = 0; } child->remote = is_remote; child->pid = id; } } else #endif /* !MK_OS_VMS */ { /* Fork the child process. */ run_local: block_sigs (); child->remote = 0; #if MK_OS_VMS child->pid = child_execute_job ((struct childbase *)child, 1, argv); #else jobserver_pre_child (ANY_SET (flags, COMMANDS_RECURSE)); child->pid = child_execute_job ((struct childbase *)child, child->good_stdin, argv); jobserver_post_child (ANY_SET (flags, COMMANDS_RECURSE)); #endif /* !MK_OS_VMS */ } #else /* MK_OS_DOS or MK_OS_W32 */ #if MK_OS_DOS { int proc_return; block_sigs (); dos_status = 0; /* We call 'system' to do the job of the SHELL, since stock DOS shell is too dumb. Our 'system' knows how to handle long command lines even if pipes/redirection is needed; it will only call COMMAND.COM when its internal commands are used. */ if (execute_by_shell) { char *cmdline = argv[0]; /* We don't have a way to pass environment to 'system', so we need to save and restore ours, sigh... */ char **parent_env = environ; environ = child->environment; /* If we have a *real* shell, tell 'system' to call it to do everything for us. */ if (unixy_shell) { /* A *real* shell on MSDOS may not support long command lines the DJGPP way, so we must use 'system'. */ cmdline = argv[2]; /* get past "shell -c" */ } dos_command_running = 1; proc_return = system (cmdline); environ = parent_env; execute_by_shell = 0; /* for the next time */ } else { dos_command_running = 1; proc_return = spawnvpe (P_WAIT, argv[0], argv, child->environment); } /* Need to unblock signals before turning off dos_command_running, so that child's signals will be treated as such (see fatal_error_signal). */ unblock_sigs (); dos_command_running = 0; /* If the child got a signal, dos_status has its high 8 bits set, so be careful not to alter them. */ if (proc_return == -1) dos_status |= 0xff; else dos_status |= (proc_return & 0xff); ++dead_children; child->pid = dos_pid++; } #endif /* MK_OS_DOS */ #if MK_OS_W32 { HANDLE hPID; char* arg0; int outfd = -1; int errfd = -1; /* make UNC paths safe for CreateProcess -- backslash format */ arg0 = argv[0]; if (arg0 && arg0[0] == '/' && arg0[1] == '/') for ( ; arg0 && *arg0; arg0++) if (*arg0 == '/') *arg0 = '\\'; /* make sure CreateProcess() has Path it needs */ sync_Path_environment (); /* Divert child output if output_sync in use. */ if (child->output.syncout) { if (child->output.out >= 0) outfd = child->output.out; if (child->output.err >= 0) errfd = child->output.err; } hPID = process_easy (argv, child->environment, outfd, errfd); if (hPID != INVALID_HANDLE_VALUE) child->pid = (pid_t) hPID; else { int i; unblock_sigs (); fprintf (stderr, _("process_easy() failed to launch process (e=%ld)\n"), process_last_err (hPID)); for (i = 0; argv[i]; i++) fprintf (stderr, "%s ", argv[i]); fprintf (stderr, _("\nCounted %d args in failed launch\n"), i); child->pid = -1; } } #endif /* MK_OS_W32 */ #endif /* MK_OS_DOS or MK_OS_W32 */ /* Bump the number of jobs started in this second. */ if (child->pid >= 0) ++job_counter; /* Set the state to running. */ set_command_state (child->file, cs_running); /* Free the storage used by the child's argument list. */ FREE_ARGV (argv); OUTPUT_UNSET(); #undef FREE_ARGV } /* Try to start a child running. Returns nonzero if the child was started (and maybe finished), or zero if the load was too high and the child was put on the 'waiting_jobs' chain. */ static int start_waiting_job (struct child *c) { struct file *f = c->file; /* If we can start a job remotely, we always want to, and don't care about the local load average. We record that the job should be started remotely in C->remote for start_job_command to test. */ c->remote = start_remote_job_p (1); /* If we are running at least one job already and the load average is too high, make this one wait. */ if (!c->remote && ((job_slots_used > 0 && load_too_high ()) #if MK_OS_W32 || process_table_full () #endif )) { /* Put this child on the chain of children waiting for the load average to go down. */ set_command_state (f, cs_running); c->next = waiting_jobs; waiting_jobs = c; return 0; } /* Start the first command; reap_children will run later command lines. */ start_job_command (c); switch (f->command_state) { case cs_running: c->next = children; if (c->pid > 0) { DB (DB_JOBS, (_("Putting child %p (%s) PID %s%s on the chain.\n"), c, c->file->name, pid2str (c->pid), c->remote ? _(" (remote)") : "")); /* One more job slot is in use. */ ++job_slots_used; assert (c->jobslot == 0); c->jobslot = 1; } children = c; unblock_sigs (); break; case cs_not_started: /* All the command lines turned out to be empty. */ f->update_status = us_success; /* FALLTHROUGH */ case cs_finished: notice_finished_file (f); free_child (c); break; default: assert (f->command_state == cs_finished); break; } return 1; } /* Create a 'struct child' for FILE and start its commands running. */ void new_job (struct file *file) { struct commands *cmds = file->cmds; struct child *c; char **lines; unsigned int i; /* Let any previously decided-upon jobs that are waiting for the load to go down start before this new one. */ start_waiting_jobs (); /* Reap any children that might have finished recently. */ reap_children (0, 0); /* Chop the commands up into lines if they aren't already. */ chop_commands (cmds); /* Start the command sequence, record it in a new 'struct child', and add that to the chain. */ c = xcalloc (sizeof (struct child)); output_init (&c->output); c->file = file; c->sh_batch_file = NULL; /* Cache dontcare flag because file->dontcare can be changed once we return. Check dontcare inheritance mechanism for details. */ c->dontcare = file->dontcare; /* Start saving output in case the expansion uses $(info ...) etc. */ OUTPUT_SET (&c->output); /* Expand the command lines and store the results in LINES. */ lines = xmalloc (cmds->ncommand_lines * sizeof (char *)); for (i = 0; i < cmds->ncommand_lines; ++i) { /* Collapse backslash-newline combinations that are inside variable or function references. These are left alone by the parser so that they will appear in the echoing of commands (where they look nice); and collapsed by construct_command_argv when it tokenizes. But letting them survive inside function invocations loses because we don't want the functions to see them as part of the text. */ char *in, *out, *ref; /* IN points to where in the line we are scanning. OUT points to where in the line we are writing. When we collapse a backslash-newline combination, IN gets ahead of OUT. */ in = out = cmds->command_lines[i]; while ((ref = strchr (in, '$')) != 0) { ++ref; /* Move past the $. */ if (out != in) /* Copy the text between the end of the last chunk we processed (where IN points) and the new chunk we are about to process (where REF points). */ memmove (out, in, ref - in); /* Move both pointers past the boring stuff. */ out += ref - in; in = ref; if (*ref == '(' || *ref == '{') { char openparen = *ref; char closeparen = openparen == '(' ? ')' : '}'; char *outref; int count; char *p; *out++ = *in++; /* Copy OPENPAREN. */ outref = out; /* IN now points past the opening paren or brace. Count parens or braces until it is matched. We don't use skip_reference since we want to handle internal backslash/newlines. */ count = 0; while (*in != '\0') { if (*in == '\\' && in[1] == '\n') { /* We have found a backslash-newline inside a variable or function reference. Eat it and any following whitespace. */ int quoted = 0; for (p = in - 1; p > ref && *p == '\\'; --p) quoted = !quoted; if (quoted) /* There were an even number of backslashes, so this is not really a continuation line. We don't collapse the quoting backslashes here as is done in collapse_continuations, because the line will be collapsed again after expansion. */ *out++ = *in++; else { /* Skip the backslash, newline, and whitespace. */ in += 2; NEXT_TOKEN (in); /* Discard any preceding whitespace that has already been written to the output. */ while (out > outref && ISBLANK (out[-1])) --out; /* Replace it all with a single space. */ *out++ = ' '; } continue; } if (*in == closeparen && --count < 0) break; if (*in == openparen) ++count; *out++ = *in++; } } } /* There are no more references in this line to worry about. Copy the remaining uninteresting text to the output. */ if (out != in) memmove (out, in, strlen (in) + 1); /* Finally, expand the line. */ cmds->fileinfo.offset = i; lines[i] = allocated_expand_string_for_file (cmds->command_lines[i], file); } cmds->fileinfo.offset = 0; c->command_lines = lines; /* Fetch the first command line to be run. */ job_next_command (c); /* Wait for a job slot to be freed up. If we allow an infinite number don't bother; also job_slots will == 0 if we're using the jobserver. */ if (job_slots != 0) while (job_slots_used == job_slots) reap_children (1, 0); #ifdef MAKE_JOBSERVER /* If we are controlling multiple jobs make sure we have a token before starting the child. */ /* This can be inefficient. There's a decent chance that this job won't actually have to run any subprocesses: the command script may be empty or otherwise optimized away. It would be nice if we could defer obtaining a token until just before we need it, in start_job_command. To do that we'd need to keep track of whether we'd already obtained a token (since start_job_command is called for each line of the job, not just once). Also more thought needs to go into the entire algorithm; this is where the old parallel job code waits, so... */ else if (jobserver_enabled ()) while (1) { int got_token; DB (DB_JOBS, ("Need a job token; we %shave children\n", children ? "" : "don't ")); /* If we don't already have a job started, use our "free" token. */ if (!jobserver_tokens) break; /* Prepare for jobserver token acquisition. */ jobserver_pre_acquire (); /* Reap anything that's currently waiting. */ reap_children (0, 0); /* Kick off any jobs we have waiting for an opportunity that can run now (i.e., waiting for load). */ start_waiting_jobs (); /* If our "free" slot is available, use it; we don't need a token. */ if (!jobserver_tokens) break; /* There must be at least one child already, or we have no business waiting for a token. */ if (!children) O (fatal, NILF, "INTERNAL: no children as we go to sleep on read"); /* Get a token. */ got_token = jobserver_acquire (waiting_jobs != NULL); /* If we got one, we're done here. */ if (got_token == 1) { DB (DB_JOBS, (_("Obtained token for child %p (%s).\n"), c, c->file->name)); break; } } #endif ++jobserver_tokens; /* Trace the build. Use message here so that changes to working directories are logged. */ if (ISDB (DB_WHY)) { char *nmbuf = NULL; const char *nm; const char *tp; if (! cmds->fileinfo.filenm) nm = _(""); else { char *n = alloca (strlen (cmds->fileinfo.filenm) + 1 + 11 + 1); sprintf (n, "%s:%lu", cmds->fileinfo.filenm, cmds->fileinfo.lineno); nm = n; } if (c->file->also_make == NULL) tp = c->file->name; else { const struct dep *dp; char *cp; size_t len = strlen (c->file->name); for (dp = c->file->also_make; dp; dp = dp->next) /* space for "', '". */ len += strlen (dp->file->name) + 4; tp = nmbuf = xmalloc (len + 1); cp = stpcpy (nmbuf, c->file->name); for (dp = c->file->also_make; dp; dp = dp->next) cp = stpcpy (stpcpy (cp, "', '"), dp->file->name); } if (c->file->phony) OSS (message, 0, _("%s: update target '%s' due to: target is .PHONY"), nm, tp); else if (c->file->last_mtime == NONEXISTENT_MTIME) OSS (message, 0, _("%s: update target '%s' due to: target does not exist"), nm, tp); else { char *newer = allocated_expand_variable_for_file (STRING_SIZE_TUPLE ("?"), c->file); if (newer[0] != '\0') { OSSS (message, 0, _("%s: update target '%s' due to: %s"), nm, tp, newer); free (newer); } else { /* One or more files didn't exist, and didn't get created. */ size_t len = 0; struct dep *d; for (d = c->file->deps; d != NULL; d = d->next) if (d->file->last_mtime == NONEXISTENT_MTIME) len += strlen (d->file->name) + 1; if (!len) OSS (message, 0, _("%s: update target '%s' due to: unknown reasons"), nm, tp); else { char *cp = newer = alloca (len); for (d = c->file->deps; d != NULL; d = d->next) if (d->file->last_mtime == NONEXISTENT_MTIME) { if (cp > newer) *(cp++) = ' '; cp = stpcpy (cp, d->file->name); } OSSS (message, 0, _("%s: update target '%s' due to: %s"), nm, tp, newer); } } } free (nmbuf); } /* The job is now primed. Start it running. (This will notice if there is in fact no recipe.) */ start_waiting_job (c); if (job_slots == 1 || not_parallel) /* Since there is only one job slot, make things run linearly. Wait for the child to die, setting the state to 'cs_finished'. */ while (file->command_state == cs_running) reap_children (1, 0); OUTPUT_UNSET (); return; } /* Move CHILD's pointers to the next command for it to execute. Returns nonzero if there is another command. */ static int job_next_command (struct child *child) { while (child->command_ptr == 0 || *child->command_ptr == '\0') { /* There are no more lines in the expansion of this line. */ if (child->command_line == child->file->cmds->ncommand_lines) { /* There are no more lines to be expanded. */ child->command_ptr = 0; child->file->cmds->fileinfo.offset = 0; return 0; } else /* Get the next line to run. */ child->command_ptr = child->command_lines[child->command_line++]; } child->file->cmds->fileinfo.offset = child->command_line - 1; return 1; } /* Determine if the load average on the system is too high to start a new job. On systems which provide /proc/loadavg (e.g., Linux), we use an idea provided by Sven C. Dack : retrieve the current number of runnable processes, if it's greater than the requested load we don't allow another job to start. We allow a job to start with equal processes since one of those will be for make itself, which will then pause waiting for jobs to clear. If /proc/loadavg is not available for some reason, we obtain the system load average and compare that. The system load average is only recomputed once every N (N>=1) seconds. However, a very parallel make can easily start tens or even hundreds of jobs in a second, which brings the system to its knees for a while until that first batch of jobs clears out. To avoid this we use a weighted algorithm to try to account for jobs which have been started since the last second, and guess what the load average would be now if it were computed. This algorithm was provided by Thomas Riedl , based on load average being recomputed once per second, which is (apparently) how Solaris operates. Linux recomputes only once every 5 seconds, but Linux is handled by the /proc/loadavg algorithm above. Thomas writes: ! calculate something load-oid and add to the observed sys.load, ! so that latter can catch up: ! - every job started increases jobctr; ! - every dying job decreases a positive jobctr; ! - the jobctr value gets zeroed every change of seconds, ! after its value*weight_b is stored into the 'backlog' value last_sec ! - weight_a times the sum of jobctr and last_sec gets ! added to the observed sys.load. ! ! The two weights have been tried out on 24 and 48 proc. Sun Solaris-9 ! machines, using a several-thousand-jobs-mix of cpp, cc, cxx and smallish ! sub-shelled commands (rm, echo, sed...) for tests. ! lowering the 'direct influence' factor weight_a (e.g. to 0.1) ! resulted in significant excession of the load limit, raising it ! (e.g. to 0.5) took bad to small, fast-executing jobs and didn't ! reach the limit in most test cases. ! ! lowering the 'history influence' weight_b (e.g. to 0.1) resulted in ! exceeding the limit for longer-running stuff (compile jobs in ! the .5 to 1.5 sec. range),raising it (e.g. to 0.5) overrepresented ! small jobs' effects. */ #define LOAD_WEIGHT_A 0.25 #define LOAD_WEIGHT_B 0.25 static int load_too_high (void) { #if MK_OS_DOS || MK_OS_VMS || defined(__riscos__) return 1; #else static double last_sec; static time_t last_now; static int proc_fd = -2; double load, guess; time_t now; #if MK_OS_W32 /* sub_proc.c is limited in the number of objects it can wait for. */ if (process_table_full ()) return 1; #endif if (max_load_average < 0) return 0; /* If we haven't tried to open /proc/loadavg, try now. */ #define LOADAVG "/proc/loadavg" if (proc_fd == -2) { EINTRLOOP (proc_fd, open (LOADAVG, O_RDONLY)); if (proc_fd < 0) DB (DB_JOBS, ("Using system load detection method.\n")); else { DB (DB_JOBS, ("Using " LOADAVG " load detection method.\n")); fd_noinherit (proc_fd); } } /* Try to read /proc/loadavg if we managed to open it. */ if (proc_fd >= 0) { int r; EINTRLOOP (r, lseek (proc_fd, 0, SEEK_SET)); if (r >= 0) { #define PROC_LOADAVG_SIZE 64 char avg[PROC_LOADAVG_SIZE+1]; EINTRLOOP (r, read (proc_fd, avg, PROC_LOADAVG_SIZE)); if (r >= 0) { const char *p; /* The syntax of /proc/loadavg is: <1m> <5m> <15m> / The load is considered too high if there are more jobs running than the requested average. */ avg[r] = '\0'; p = strchr (avg, ' '); if (p) p = strchr (p+1, ' '); if (p) p = strchr (p+1, ' '); if (p && ISDIGIT(p[1])) { unsigned int cnt = make_toui (p+1, NULL); DB (DB_JOBS, ("Running: system = %u / make = %u (max requested = %f)\n", cnt, job_slots_used, max_load_average)); return (double)cnt > max_load_average; } DB (DB_JOBS, ("Failed to parse " LOADAVG ": %s\n", avg)); } } /* If we got here, something went wrong. Give up on this method. */ if (r < 0) DB (DB_JOBS, ("Failed to read " LOADAVG ": %s\n", strerror (errno))); close (proc_fd); proc_fd = -1; } /* Find the real system load average. */ errno = 0; if (getloadavg (&load, 1) != 1) { static int lossage = -1; /* Complain only once for the same error. */ if (lossage == -1 || errno != lossage) { if (errno == 0) /* An errno value of zero means getloadavg is just unsupported. */ O (error, NILF, _("cannot enforce load limits on this operating system")); else perror_with_name (_("cannot enforce load limit: "), "getloadavg"); } lossage = errno; load = 0; } /* If we're in a new second zero the counter and correct the backlog value. Only keep the backlog for one extra second; after that it's 0. */ now = time (NULL); if (last_now < now) { if (last_now == now - 1) last_sec = LOAD_WEIGHT_B * job_counter; else last_sec = 0.0; job_counter = 0; last_now = now; } /* Try to guess what the load would be right now. */ guess = load + (LOAD_WEIGHT_A * (job_counter + last_sec)); DB (DB_JOBS, ("Estimated system load = %f (actual = %f) (max requested = %f)\n", guess, load, max_load_average)); return guess >= max_load_average; #endif } /* Start jobs that are waiting for the load to be lower. */ void start_waiting_jobs (void) { struct child *job; if (waiting_jobs == 0) return; do { /* Check for recently deceased descendants. */ reap_children (0, 0); /* Take a job off the waiting list. */ job = waiting_jobs; waiting_jobs = job->next; /* Try to start that job. We break out of the loop as soon as start_waiting_job puts one back on the waiting list. */ } while (start_waiting_job (job) && waiting_jobs != 0); return; } #if !MK_OS_W32 /* EMX: Start a child process. This function returns the new pid. */ # if MK_OS_OS2 pid_t child_execute_job (struct childbase *child, int good_stdin, char **argv) { pid_t pid; int fdin = good_stdin ? FD_STDIN : get_bad_stdin (); int fdout = FD_STDOUT; int fderr = FD_STDERR; int save_fdin = -1; int save_fdout = -1; int save_fderr = -1; /* Divert child output if we want to capture output. */ if (child->output.syncout) { if (child->output.out >= 0) fdout = child->output.out; if (child->output.err >= 0) fderr = child->output.err; } /* For each FD which needs to be redirected first make a dup of the standard FD to save and mark it close on exec so our child won't see it. Then dup2() the standard FD to the redirect FD, and also mark the redirect FD as close on exec. */ if (fdin != FD_STDIN) { save_fdin = dup (FD_STDIN); if (save_fdin < 0) O (fatal, NILF, _("no more file handles: could not duplicate stdin")); fd_noinherit (save_fdin); dup2 (fdin, FD_STDIN); fd_noinherit (fdin); } if (fdout != FD_STDOUT) { save_fdout = dup (FD_STDOUT); if (save_fdout < 0) O (fatal, NILF, _("no more file handles: could not duplicate stdout")); fd_noinherit (save_fdout); dup2 (fdout, FD_STDOUT); fd_noinherit (fdout); } if (fderr != FD_STDERR) { if (fderr != fdout) { save_fderr = dup (FD_STDERR); if (save_fderr < 0) O (fatal, NILF, _("no more file handles: could not duplicate stderr")); fd_noinherit (save_fderr); } dup2 (fderr, FD_STDERR); fd_noinherit (fderr); } /* Run the command. */ pid = exec_command (argv, child->environment); /* Restore stdout/stdin/stderr of the parent and close temporary FDs. */ if (save_fdin >= 0) { if (dup2 (save_fdin, FD_STDIN) != FD_STDIN) O (fatal, NILF, _("could not restore stdin")); else close (save_fdin); } if (save_fdout >= 0) { if (dup2 (save_fdout, FD_STDOUT) != FD_STDOUT) O (fatal, NILF, _("could not restore stdout")); else close (save_fdout); } if (save_fderr >= 0) { if (dup2 (save_fderr, FD_STDERR) != FD_STDERR) O (fatal, NILF, _("could not restore stderr")); else close (save_fderr); } if (pid < 0) OSS (error, NILF, "%s: %s", argv[0], strerror (errno)); return pid; } #elif !MK_OS_DOS && !MK_OS_VMS /* POSIX: Create a child process executing the command in ARGV. Returns the PID or -1. */ pid_t child_execute_job (struct childbase *child, int good_stdin, char **argv) { const int fdin = good_stdin ? FD_STDIN : get_bad_stdin (); int fdout = FD_STDOUT; int fderr = FD_STDERR; pid_t pid = -1; int r; #if defined(USE_POSIX_SPAWN) char *cmd; posix_spawnattr_t attr; posix_spawn_file_actions_t fa; short flags = 0; #endif /* Divert child output if we want to capture it. */ if (child->output.syncout) { if (child->output.out >= 0) fdout = child->output.out; if (child->output.err >= 0) fderr = child->output.err; } #if !defined(USE_POSIX_SPAWN) { /* The child may clobber environ so remember ours and restore it. */ char **parent_env = environ; pid = vfork (); if (pid != 0) { environ = parent_env; return pid; } } /* We are the child. */ unblock_all_sigs (); #ifdef SET_STACK_SIZE /* Reset limits, if necessary. */ if (stack_limit.rlim_cur) setrlimit (RLIMIT_STACK, &stack_limit); #endif /* For any redirected FD, dup2() it to the standard FD. They are all marked close-on-exec already. */ if (fdin >= 0 && fdin != FD_STDIN) EINTRLOOP (r, dup2 (fdin, FD_STDIN)); if (fdout != FD_STDOUT) EINTRLOOP (r, dup2 (fdout, FD_STDOUT)); if (fderr != FD_STDERR) EINTRLOOP (r, dup2 (fderr, FD_STDERR)); /* Run the command. */ exec_command (argv, child->environment); _exit (127); #else /* USE_POSIX_SPAWN */ if ((r = posix_spawnattr_init (&attr)) != 0) goto done; if ((r = posix_spawn_file_actions_init (&fa)) != 0) { posix_spawnattr_destroy (&attr); goto done; } /* Unblock all signals. */ #ifdef HAVE_POSIX_SPAWNATTR_SETSIGMASK { sigset_t mask; sigemptyset (&mask); r = posix_spawnattr_setsigmask (&attr, &mask); if (r != 0) goto cleanup; flags |= POSIX_SPAWN_SETSIGMASK; } #endif /* have posix_spawnattr_setsigmask() */ /* USEVFORK can give significant speedup on systems where it's available. */ #ifdef POSIX_SPAWN_USEVFORK flags |= POSIX_SPAWN_USEVFORK; #endif /* For any redirected FD, dup2() it to the standard FD. They are all marked close-on-exec already. */ if (fdin >= 0 && fdin != FD_STDIN) if ((r = posix_spawn_file_actions_adddup2 (&fa, fdin, FD_STDIN)) != 0) goto cleanup; if (fdout != FD_STDOUT) if ((r = posix_spawn_file_actions_adddup2 (&fa, fdout, FD_STDOUT)) != 0) goto cleanup; if (fderr != FD_STDERR) if ((r = posix_spawn_file_actions_adddup2 (&fa, fderr, FD_STDERR)) != 0) goto cleanup; /* We can't use the POSIX_SPAWN_RESETIDS flag: when make is invoked under restrictive environments like unshare it will fail with EINVAL. */ /* Apply the spawn flags. */ if ((r = posix_spawnattr_setflags (&attr, flags)) != 0) goto cleanup; /* Look up the program on the child's PATH, if needed. */ { const char *p = NULL; char **pp; for (pp = child->environment; *pp != NULL; ++pp) if ((*pp)[0] == 'P' && (*pp)[1] == 'A' && (*pp)[2] == 'T' && (*pp)[3] == 'H' &&(*pp)[4] == '=') { p = (*pp) + 5; break; } /* execvp() will use a default PATH if none is set; emulate that. */ if (p == NULL) { size_t l = confstr (_CS_PATH, NULL, 0); if (l) { char *dp = alloca (l); confstr (_CS_PATH, dp, l); p = dp; } } cmd = (char *)find_in_given_path (argv[0], p, NULL, 0); } if (!cmd) { r = errno; goto cleanup; } /* Start the program. */ while ((r = posix_spawn (&pid, cmd, &fa, &attr, argv, child->environment)) == EINTR) ; /* posix_spawn() doesn't provide sh fallback like exec() does; implement it here. POSIX doesn't specify the path to sh so use the default. */ if (r == ENOEXEC) { char **nargv; char **pp; size_t l = 0; for (pp = argv; *pp != NULL; ++pp) ++l; nargv = xmalloc (sizeof (char *) * (l + 3)); nargv[0] = (char *)default_shell; nargv[1] = cmd; memcpy (&nargv[2], &argv[1], sizeof (char *) * l); while ((r = posix_spawn (&pid, nargv[0], &fa, &attr, nargv, child->environment)) == EINTR) ; free (nargv); } if (r == 0) { /* Spawn succeeded but may fail later: remember the command. */ free (child->cmd_name); if (cmd != argv[0]) child->cmd_name = cmd; else child->cmd_name = xstrdup(cmd); } cleanup: posix_spawn_file_actions_destroy (&fa); posix_spawnattr_destroy (&attr); done: if (r != 0) pid = -1; #endif /* USE_POSIX_SPAWN */ if (pid < 0) OSS (error, NILF, "%s: %s", argv[0], strerror (r)); return pid; } #endif /* !MK_OS_DOS && !MK_OS_VMS */ #endif /* !MK_OS_W32 */ /* Replace the current process with one running the command in ARGV, with environment ENVP. This function does not return. */ pid_t exec_command (char **argv, char **envp) { #if MK_OS_VMS /* to work around a problem with signals and execve: ignore them */ #ifdef SIGCHLD signal (SIGCHLD,SIG_IGN); #endif /* Run the program. */ execve (argv[0], argv, envp); OSS (error, NILF, "%s: %s", argv[0], strerror (errno)); _exit (EXIT_FAILURE); #else #if MK_OS_W32 HANDLE hPID; HANDLE hWaitPID; int exit_code = EXIT_FAILURE; /* make sure CreateProcess() has Path it needs */ sync_Path_environment (); /* launch command */ hPID = process_easy (argv, envp, -1, -1); /* make sure launch ok */ if (hPID == INVALID_HANDLE_VALUE) { int i; fprintf (stderr, _("process_easy() failed to launch process (e=%ld)\n"), process_last_err (hPID)); for (i = 0; argv[i]; i++) fprintf (stderr, "%s ", argv[i]); fprintf (stderr, _("\nCounted %d args in failed launch\n"), i); exit (EXIT_FAILURE); } /* wait and reap last child */ hWaitPID = process_wait_for_any (1, 0); while (hWaitPID) { /* was an error found on this process? */ int err = process_last_err (hWaitPID); /* get exit data */ exit_code = process_exit_code (hWaitPID); if (err) fprintf (stderr, "make (e=%d, rc=%d): %s\n", err, exit_code, map_windows32_error_to_string (err)); /* cleanup process */ process_cleanup (hWaitPID); /* expect to find only last pid, warn about other pids reaped */ if (hWaitPID == hPID) break; else { char *pidstr = xstrdup (pid2str ((pid_t)hWaitPID)); fprintf (stderr, _("make reaped child pid %s, still waiting for pid %s\n"), pidstr, pid2str ((pid_t)hPID)); free (pidstr); } } /* Use the child's exit code as our exit code */ exit (exit_code); #else /* !MK_OS_W32 */ pid_t pid = -1; # if MK_OS_OS2 /* Run the program. */ pid = spawnvpe (P_NOWAIT, argv[0], argv, envp); if (pid >= 0) return pid; /* the file might have a strange shell extension */ if (errno == ENOENT) errno = ENOEXEC; # elif MK_OS_ZOS /* In z/OS we can't set environ in ASCII mode. */ environ = envp; execvpe(argv[0], argv, envp); # else /* Run the program. Don't use execvpe() as we want the search for argv[0] to use the new PATH, but execvpe() searches before resetting PATH. */ environ = envp; execvp (argv[0], argv); # endif /* !MK_OS_OS2 */ switch (errno) { case ENOENT: OSS (error, NILF, "%s: %s", argv[0], strerror (errno)); break; case ENOEXEC: { /* The file was not a program. Try it as a shell script. */ const char *shell; char **new_argv; int argc; int i=1; # if MK_OS_OS2 /* Do not use $SHELL from the environment */ struct variable *p = lookup_variable ("SHELL", 5); if (p) shell = p->value; else shell = 0; # else shell = getenv ("SHELL"); # endif if (shell == 0) shell = default_shell; argc = 1; while (argv[argc] != 0) ++argc; # if MK_OS_OS2 if (!unixy_shell) ++argc; # endif new_argv = alloca ((1 + argc + 1) * sizeof (char *)); new_argv[0] = (char *)shell; # if MK_OS_OS2 if (!unixy_shell) { new_argv[1] = (char *)"/c"; ++i; --argc; } # endif new_argv[i] = argv[0]; while (argc > 0) { new_argv[i + argc] = argv[argc]; --argc; } # if MK_OS_OS2 pid = spawnvpe (P_NOWAIT, shell, new_argv, envp); if (pid >= 0) break; # elif MK_OS_ZOS /* In z/OS we can't set environ in ASCII mode. */ execvpe(shell, new_argv, envp); # else execvp (shell, new_argv); # endif OSS (error, NILF, "%s: %s", new_argv[0], strerror (errno)); break; } # if MK_OS_OS2 case EINVAL: /* this nasty error was driving me nuts :-( */ O (error, NILF, _("spawnvpe: environment space might be exhausted")); /* FALLTHROUGH */ # endif default: OSS (error, NILF, "%s: %s", argv[0], strerror (errno)); break; } return pid; #endif /* !MK_OS_W32 */ #endif /* !MK_OS_VMS */ } #if !MK_OS_VMS /* Figure out the argument list necessary to run LINE as a command. Try to avoid using a shell. This routine handles only ' quoting, and " quoting when no backslash, $ or ' characters are seen in the quotes. Starting quotes may be escaped with a backslash. If any of the characters in sh_chars is seen, or any of the builtin commands listed in sh_cmds is the first word of a line, the shell is used. If RESTP is not NULL, *RESTP is set to point to the first newline in LINE. If *RESTP is NULL, newlines will be ignored. SHELL is the shell to use, or nil to use the default shell. IFS is the value of $IFS, or nil (meaning the default). FLAGS is the value of lines_flags for this command line. It is used in the Windows32 port to check whether + or $(MAKE) were found in this command line, in which case the effect of just_print_flag is overridden. The returned value is either NULL if the line was empty, or else a pointer to an array of strings. The fist pointer points to the memory used by all the strings, so to free you free the 0'th element then the returned pointer (see the FREE_ARGV macro). */ static char ** construct_command_argv_internal (char *line, char **restp, const char *shell, const char *shellflags, const char *ifs, int flags, char **batch_filename UNUSED) { #if MK_OS_DOS /* MSDOS supports both the stock DOS shell and ports of Unixy shells. We call 'system' for anything that requires ''slow'' processing, because DOS shells are too dumb. When $SHELL points to a real (unix-style) shell, 'system' just calls it to do everything. When $SHELL points to a DOS shell, 'system' does most of the work internally, calling the shell only for its internal commands. However, it looks on the $PATH first, so you can e.g. have an external command named 'mkdir'. Since we call 'system', certain characters and commands below are actually not specific to COMMAND.COM, but to the DJGPP implementation of 'system'. In particular: The shell wildcard characters are in DOS_CHARS because they will not be expanded if we call the child via 'spawnXX'. The ';' is in DOS_CHARS, because our 'system' knows how to run multiple commands on a single line. DOS_CHARS also include characters special to 4DOS/NDOS, so we won't have to tell one from another and have one more set of commands and special characters. */ static const char *sh_chars_dos = "*?[];|<>%^&()"; static const char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date", "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md", "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren", "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":", 0 }; static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^"; static const char *sh_cmds_sh[] = { "cd", "echo", "eval", "exec", "exit", "login", "logout", "set", "umask", "wait", "while", "for", "case", "if", ":", ".", "break", "continue", "export", "read", "readonly", "shift", "times", "trap", "switch", "unset", "ulimit", "command", 0 }; const char *sh_chars; const char **sh_cmds; #elif MK_OS_OS2 static const char *sh_chars_dos = "*?[];|<>%^&()"; static const char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date", "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md", "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren", "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":", 0 }; static const char *sh_chars_os2 = "*?[];|<>%^()\"'&"; static const char *sh_cmds_os2[] = { "call", "cd", "chcp", "chdir", "cls", "copy", "date", "del", "detach", "dir", "echo", "endlocal", "erase", "exit", "for", "goto", "if", "keys", "md", "mkdir", "move", "path", "pause", "prompt", "rd", "rem", "ren", "rename", "rmdir", "set", "setlocal", "shift", "start", "time", "type", "ver", "verify", "vol", ":", 0 }; static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^~'"; static const char *sh_cmds_sh[] = { "echo", "cd", "eval", "exec", "exit", "login", "logout", "set", "umask", "wait", "while", "for", "case", "if", ":", ".", "break", "continue", "export", "read", "readonly", "shift", "times", "trap", "switch", "unset", "command", 0 }; const char *sh_chars; const char **sh_cmds; #elif MK_OS_W32 /* We used to have a double quote (") in sh_chars_dos[] below, but that caused any command line with quoted file names be run through a temporary batch file, which introduces command-line limit of 4K characters imposed by cmd.exe. Since CreateProcess can handle quoted file names just fine, removing the quote lifts the limit from a very frequent use case, because using quoted file names is commonplace on MS-Windows. */ static const char *sh_chars_dos = "|&<>"; static const char *sh_cmds_dos[] = { "assoc", "break", "call", "cd", "chcp", "chdir", "cls", "color", "copy", "ctty", "date", "del", "dir", "echo", "echo.", "endlocal", "erase", "exit", "for", "ftype", "goto", "if", "if", "md", "mkdir", "move", "path", "pause", "prompt", "rd", "rem", "ren", "rename", "rmdir", "set", "setlocal", "shift", "time", "title", "type", "ver", "verify", "vol", ":", 0 }; static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^"; static const char *sh_cmds_sh[] = { "cd", "eval", "exec", "exit", "login", "logout", "set", "umask", "wait", "while", "for", "case", "if", ":", ".", "break", "continue", "export", "read", "readonly", "shift", "times", "trap", "switch", "test", "command", #ifdef BATCH_MODE_ONLY_SHELL "echo", #endif 0 }; const char *sh_chars; const char **sh_cmds; #elif defined(__riscos__) static const char *sh_chars = ""; static const char *sh_cmds[] = { 0 }; #else /* must be UNIX-ish */ static const char *sh_chars = "#;\"*?[]&|<>(){}$`^~!"; static const char *sh_cmds[] = { ".", ":", "alias", "bg", "break", "case", "cd", "command", "continue", "eval", "exec", "exit", "export", "fc", "fg", "for", "getopts", "hash", "if", "jobs", "login", "logout", "read", "readonly", "return", "set", "shift", "test", "times", "trap", "type", "ulimit", "umask", "unalias", "unset", "wait", "while", 0 }; # ifdef HAVE_DOS_PATHS /* This is required if the MSYS/Cygwin ports (which do not define MK_OS_W32) are compiled with HAVE_DOS_PATHS defined, which uses sh_chars_sh directly (see below). The value must be identical to that of sh_chars immediately above. */ static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^~!"; # endif /* HAVE_DOS_PATHS */ #endif size_t i; char *p; #ifndef NDEBUG char *end; #endif char *ap; const char *cap; const char *cp; int instring, word_has_equals, seen_nonequals, last_argument_was_empty; char **new_argv = 0; char *argstr = 0; #if MK_OS_W32 int slow_flag = 0; if (!unixy_shell) { sh_cmds = sh_cmds_dos; sh_chars = sh_chars_dos; } else { sh_cmds = sh_cmds_sh; sh_chars = sh_chars_sh; } #endif /* MK_OS_W32 */ if (restp != NULL) *restp = NULL; /* Make sure not to bother processing an empty line but stop at newline. */ while (ISBLANK (*line)) ++line; if (*line == '\0') return 0; /* See if it is safe to parse commands internally. */ if (shell == 0) shell = default_shell; #if MK_OS_W32 else if (strcmp (shell, default_shell)) { char *s1 = _fullpath (NULL, shell, 0); char *s2 = _fullpath (NULL, default_shell, 0); slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : "")); free (s1); free (s2); } if (slow_flag) goto slow; #else /* not MK_OS_W32 */ #if MK_OS_DOS || MK_OS_OS2 else if (strcasecmp (shell, default_shell)) { extern int _is_unixy_shell (const char *_path); DB (DB_BASIC, (_("$SHELL changed (was '%s', now '%s')\n"), default_shell, shell)); unixy_shell = _is_unixy_shell (shell); /* we must allocate a copy of shell: construct_command_argv() will free * shell after this function returns. */ default_shell = xstrdup (shell); } if (unixy_shell) { sh_chars = sh_chars_sh; sh_cmds = sh_cmds_sh; } else { sh_chars = sh_chars_dos; sh_cmds = sh_cmds_dos; # if MK_OS_OS2 if (_osmode == OS2_MODE) { sh_chars = sh_chars_os2; sh_cmds = sh_cmds_os2; } # endif } #else /* !MK_OS_DOS */ else if (strcmp (shell, default_shell)) goto slow; #endif /* !MK_OS_DOS && !MK_OS_OS2 */ #endif /* not MK_OS_W32 */ if (ifs) for (cap = ifs; *cap != '\0'; ++cap) if (*cap != ' ' && *cap != '\t' && *cap != '\n') goto slow; if (shellflags) if (shellflags[0] != '-' || ((shellflags[1] != 'c' || shellflags[2] != '\0') && (shellflags[1] != 'e' || shellflags[2] != 'c' || shellflags[3] != '\0'))) goto slow; i = strlen (line) + 1; /* More than 1 arg per character is impossible. */ new_argv = xmalloc (i * sizeof (char *)); /* All the args can fit in a buffer as big as LINE is. */ ap = new_argv[0] = argstr = xmalloc (i); #ifndef NDEBUG end = ap + i; #endif /* I is how many complete arguments have been found. */ i = 0; instring = word_has_equals = seen_nonequals = last_argument_was_empty = 0; for (p = line; *p != '\0'; ++p) { assert (ap <= end); if (instring) { /* Inside a string, just copy any char except a closing quote or a backslash-newline combination. */ if (*p == instring) { instring = 0; if (ap == new_argv[0] || *(ap-1) == '\0') last_argument_was_empty = 1; } else if (*p == '\\' && p[1] == '\n') { /* Backslash-newline is handled differently depending on what kind of string we're in: inside single-quoted strings you keep them; in double-quoted strings they disappear. For DOS/Windows/OS2, if we don't have a POSIX shell, we keep the pre-POSIX behavior of removing the backslash-newline. */ if (instring == '"' #if MK_OS_DOS || MK_OS_OS2 || MK_OS_W32 || !unixy_shell #endif ) ++p; else { *(ap++) = *(p++); *(ap++) = *p; } } else if (*p == '\n' && restp != NULL) { /* End of the command line. */ *restp = p; goto end_of_line; } /* Backslash, $, and ` are special inside double quotes. If we see any of those, punt. But on MSDOS, if we use COMMAND.COM, double and single quotes have the same effect. */ else if (instring == '"' && strchr ("\\$`", *p) != 0 && unixy_shell) goto slow; #if MK_OS_W32 /* Quoted wildcard characters must be passed quoted to the command, so give up the fast route. */ else if (instring == '"' && strchr ("*?", *p) != 0 && !unixy_shell) goto slow; else if (instring == '"' && strncmp (p, "\\\"", 2) == 0) *ap++ = *++p; #endif else *ap++ = *p; } else if (strchr (sh_chars, *p) != 0) /* Not inside a string, but it's a special char. */ goto slow; else if (one_shell && *p == '\n') /* In .ONESHELL mode \n is a separator like ; or && */ goto slow; #if MK_OS_DOS else if (*p == '.' && p[1] == '.' && p[2] == '.' && p[3] != '.') /* '...' is a wildcard in DJGPP. */ goto slow; #endif else /* Not a special char. */ switch (*p) { case '=': /* Equals is a special character in leading words before the first word with no equals sign in it. This is not the case with sh -k, but we never get here when using nonstandard shell flags. */ if (! seen_nonequals && unixy_shell) goto slow; word_has_equals = 1; *ap++ = '='; break; case '\\': /* Backslash-newline has special case handling, ref POSIX. We're in the fastpath, so emulate what the shell would do. */ if (p[1] == '\n') { /* Throw out the backslash and newline. */ ++p; /* At the beginning of the argument, skip any whitespace other than newline before the start of the next word. */ if (ap == new_argv[i]) while (ISBLANK (p[1])) ++p; } #if MK_OS_W32 /* Backslash before whitespace is not special if our shell is not Unixy. */ else if (ISSPACE (p[1]) && !unixy_shell) { *ap++ = *p; break; } #endif else if (p[1] != '\0') { #ifdef HAVE_DOS_PATHS /* Only remove backslashes before characters special to Unixy shells. All other backslashes are copied verbatim, since they are probably DOS-style directory separators. This still leaves a small window for problems, but at least it should work for the vast majority of naive users. */ #if MK_OS_DOS /* A dot is only special as part of the "..." wildcard. */ if (strneq (p + 1, ".\\.\\.", 5)) { *ap++ = '.'; *ap++ = '.'; p += 4; } else #endif if (p[1] != '\\' && p[1] != '\'' && !ISSPACE (p[1]) && strchr (sh_chars_sh, p[1]) == 0) /* back up one notch, to copy the backslash */ --p; #endif /* HAVE_DOS_PATHS */ /* Copy and skip the following char. */ *ap++ = *++p; } break; case '\'': case '"': instring = *p; break; case '\n': if (restp != NULL) { /* End of the command line. */ *restp = p; goto end_of_line; } else /* Newlines are not special. */ *ap++ = '\n'; break; case ' ': case '\t': /* We have the end of an argument. Terminate the text of the argument. */ *ap++ = '\0'; new_argv[++i] = ap; last_argument_was_empty = 0; /* Update SEEN_NONEQUALS, which tells us if every word heretofore has contained an '='. */ seen_nonequals |= ! word_has_equals; if (word_has_equals && ! seen_nonequals) /* An '=' in a word before the first word without one is magical. */ goto slow; word_has_equals = 0; /* Prepare for the next word. */ /* If this argument is the command name, see if it is a built-in shell command. If so, have the shell handle it. */ if (i == 1) { int j; for (j = 0; sh_cmds[j] != 0; ++j) { if (streq (sh_cmds[j], new_argv[0])) goto slow; #if MK_OS_OS2 || MK_OS_W32 /* Non-Unix shells are case insensitive. */ if (!unixy_shell && strcasecmp (sh_cmds[j], new_argv[0]) == 0) goto slow; #endif } } /* Skip whitespace chars, but not newlines. */ while (ISBLANK (p[1])) ++p; break; default: *ap++ = *p; break; } } end_of_line: if (instring) /* Let the shell deal with an unterminated quote. */ goto slow; /* Terminate the last argument and the argument list. */ *ap = '\0'; if (new_argv[i][0] != '\0' || last_argument_was_empty) ++i; new_argv[i] = 0; if (i == 1) { int j; for (j = 0; sh_cmds[j] != 0; ++j) if (streq (sh_cmds[j], new_argv[0])) goto slow; } if (new_argv[0] == 0) { /* Line was empty. */ free (argstr); free (new_argv); return 0; } return new_argv; slow:; /* We must use the shell. */ if (new_argv != 0) { /* Free the old argument list we were working on. */ free (argstr); free (new_argv); } #if MK_OS_DOS execute_by_shell = 1; /* actually, call 'system' if shell isn't unixy */ #endif #if MK_OS_W32 /* * Not eating this whitespace caused things like * * sh -c "\n" * * which gave the shell fits. I think we have to eat * whitespace here, but this code should be considered * suspicious if things start failing.... */ /* Make sure not to bother processing an empty line. */ NEXT_TOKEN (line); if (*line == '\0') return 0; #endif /* MK_OS_W32 */ { /* SHELL may be a multi-word command. Construct a command line "$(SHELL) $(.SHELLFLAGS) LINE", with all special chars in LINE escaped. Then recurse, expanding this command line to get the final argument list. */ char *new_line; size_t shell_len = strlen (shell); size_t line_len = strlen (line); size_t sflags_len = shellflags ? strlen (shellflags) : 0; #if MK_OS_W32 char *command_ptr = NULL; /* used for batch_mode_shell mode */ #endif # if MK_OS_OS2 /* is this necessary? */ if (!unixy_shell && shellflags) { size_t len = strlen (shellflags); char *shflags = alloca (len + 1); memcpy (shflags, shellflags, len + 1); shflags[0] = '/'; /* "/c" */ shellflags = shflags; } # endif /* In .ONESHELL mode we are allowed to throw the entire current recipe string at a single shell and trust that the user has configured the shell and shell flags, and formatted the string, appropriately. */ if (one_shell) { /* If the shell is Bourne compatible, we must remove and ignore interior special chars [@+-] because they're meaningless to the shell itself. If, however, we're in .ONESHELL mode and have changed SHELL to something non-standard, we should leave those alone because they could be part of the script. In this case we must also leave in place any leading [@+-] for the same reason. */ /* Remove and ignore interior prefix chars [@+-] because they're meaningless given a single shell. */ #if MK_OS_DOS || MK_OS_OS2 if (unixy_shell) /* the test is complicated and we already did it */ #else if (is_bourne_compatible_shell (shell) #if MK_OS_W32 /* If we didn't find any sh.exe, don't behave is if we did! */ && !no_default_sh_exe #endif ) #endif { const char *f = line; char *t = line; /* Copy the recipe, removing and ignoring interior prefix chars [@+-]: they're meaningless in .ONESHELL mode. */ while (f[0] != '\0') { int esc = 0; /* This is the start of a new recipe line. Skip whitespace and prefix characters but not newlines. */ while (ISBLANK (*f) || *f == '-' || *f == '@' || *f == '+') ++f; /* Copy until we get to the next logical recipe line. */ while (*f != '\0') { *(t++) = *(f++); if (f[-1] == '\\') esc = !esc; else { /* On unescaped newline, we're done with this line. */ if (f[-1] == '\n' && ! esc) break; /* Something else: reset the escape sequence. */ esc = 0; } } } *t = '\0'; } #if MK_OS_W32 else /* non-Posix shell (cmd.exe etc.) */ { const char *f = line; char *t = line; char *tstart = t; int temp_fd; FILE* batch = NULL; int id = GetCurrentProcessId (); PATH_VAR(fbuf); /* Generate a file name for the temporary batch file. */ sprintf (fbuf, "make%d", id); *batch_filename = create_batch_file (fbuf, 0, &temp_fd); DB (DB_JOBS, (_("Creating temporary batch file %s\n"), *batch_filename)); /* Create a FILE object for the batch file, and write to it the commands to be executed. Put the batch file in TEXT mode. */ _setmode (temp_fd, _O_TEXT); batch = _fdopen (temp_fd, "wt"); fputs ("@echo off\n", batch); DB (DB_JOBS, (_("Batch file contents:\n\t@echo off\n"))); /* Copy the recipe, removing and ignoring interior prefix chars [@+-]: they're meaningless in .ONESHELL mode. */ while (*f != '\0') { /* This is the start of a new recipe line. Skip whitespace and prefix characters but not newlines. */ while (ISBLANK (*f) || *f == '-' || *f == '@' || *f == '+') ++f; /* Copy until we get to the next logical recipe line. */ while (*f != '\0') { /* Remove the escaped newlines in the command, and the blanks that follow them. Windows shells cannot handle escaped newlines. */ if (*f == '\\' && f[1] == '\n') { f += 2; while (ISBLANK (*f)) ++f; } *(t++) = *(f++); /* On an unescaped newline, we're done with this line. */ if (f[-1] == '\n') break; } /* Write another line into the batch file. */ if (t > tstart) { char c = *t; *t = '\0'; fputs (tstart, batch); DB (DB_JOBS, ("\t%s", tstart)); tstart = t; *t = c; } } DB (DB_JOBS, ("\n")); fclose (batch); /* Create an argv list for the shell command line that will run the batch file. */ new_argv = xmalloc (2 * sizeof (char *)); new_argv[0] = xstrdup (*batch_filename); new_argv[1] = NULL; return new_argv; } #endif /* MK_OS_W32 */ /* Create an argv list for the shell command line. */ { int n = 1; char *nextp; new_argv = xmalloc ((4 + sflags_len/2) * sizeof (char *)); nextp = new_argv[0] = xmalloc (shell_len + sflags_len + line_len + 3); nextp = mempcpy (nextp, shell, shell_len + 1); /* Chop up the shellflags (if any) and assign them. */ if (! shellflags) { new_argv[n++] = nextp; *(nextp++) = '\0'; } else { /* Parse shellflags using construct_command_argv_internal to handle quotes. */ char **argv; char *f = alloca (sflags_len + 1); memcpy (f, shellflags, sflags_len + 1); argv = construct_command_argv_internal (f, 0, 0, 0, 0, flags, 0); if (argv) { char **a; for (a = argv; *a; ++a) { new_argv[n++] = nextp; nextp = stpcpy (nextp, *a) + 1; } free (argv[0]); free (argv); } } /* Set the command to invoke. */ new_argv[n++] = nextp; memcpy(nextp, line, line_len + 1); new_argv[n++] = NULL; } return new_argv; } new_line = xmalloc ((shell_len*2) + 1 + sflags_len + 1 + (line_len*2) + 1); ap = new_line; /* Copy SHELL, escaping any characters special to the shell. If we don't escape them, construct_command_argv_internal will recursively call itself ad nauseam, or until stack overflow, whichever happens first. */ for (cp = shell; *cp != '\0'; ++cp) { if (strchr (sh_chars, *cp) != 0) *(ap++) = '\\'; *(ap++) = *cp; } *(ap++) = ' '; if (shellflags) { ap = mempcpy (ap, shellflags, sflags_len); *(ap++) = ' '; } #if MK_OS_W32 command_ptr = ap; #endif for (p = line; *p != '\0'; ++p) { if (restp != NULL && *p == '\n') { *restp = p; break; } else if (*p == '\\' && p[1] == '\n') { /* POSIX says we keep the backslash-newline. If we don't have a POSIX shell on DOS/Windows/OS2, mimic the pre-POSIX behavior and remove the backslash/newline. */ #if MK_OS_DOS || MK_OS_OS2 || MK_OS_W32 # define PRESERVE_BSNL unixy_shell #else # define PRESERVE_BSNL 1 #endif if (PRESERVE_BSNL) { *(ap++) = '\\'; /* Only non-batch execution needs another backslash, because it will be passed through a recursive invocation of this function. */ if (!batch_mode_shell) *(ap++) = '\\'; *(ap++) = '\n'; } ++p; continue; } /* DOS shells don't know about backslash-escaping. */ if (unixy_shell && !batch_mode_shell && (*p == '\\' || *p == '\'' || *p == '"' || ISSPACE (*p) || strchr (sh_chars, *p) != 0)) *ap++ = '\\'; #if MK_OS_DOS else if (unixy_shell && strneq (p, "...", 3)) { /* The case of '...' wildcard again. */ ap = stpcpy (ap, "\\.\\.\\"); p += 2; } #endif *ap++ = *p; } if (ap == new_line + shell_len + sflags_len + 2) { /* Line was empty. */ free (new_line); return 0; } *ap = '\0'; #if MK_OS_W32 /* Some shells do not work well when invoked as 'sh -c xxx' to run a command line (e.g. Cygnus GNUWIN32 sh.exe on W32 systems). In these cases, run commands via a script file. */ if (just_print_flag && NONE_SET (flags, COMMANDS_RECURSE)) { /* Need to allocate new_argv, although it's unused, because start_job_command will want to free it and its 0'th element. */ new_argv = xmalloc (2 * sizeof (char *)); new_argv[0] = xstrdup (""); new_argv[1] = NULL; } else if ((no_default_sh_exe || batch_mode_shell) && batch_filename) { int temp_fd; FILE* batch = NULL; int id = GetCurrentProcessId (); PATH_VAR (fbuf); /* create a file name */ sprintf (fbuf, "make%d", id); *batch_filename = create_batch_file (fbuf, unixy_shell, &temp_fd); DB (DB_JOBS, (_("Creating temporary batch file %s\n"), *batch_filename)); /* Create a FILE object for the batch file, and write to it the commands to be executed. Put the batch file in TEXT mode. */ _setmode (temp_fd, _O_TEXT); batch = _fdopen (temp_fd, "wt"); if (!unixy_shell) fputs ("@echo off\n", batch); fputs (command_ptr, batch); fputc ('\n', batch); fclose (batch); DB (DB_JOBS, (_("Batch file contents:%s\n\t%s\n"), !unixy_shell ? "\n\t@echo off" : "", command_ptr)); /* create argv */ new_argv = xmalloc (3 * sizeof (char *)); if (unixy_shell) { new_argv[0] = xstrdup (shell); new_argv[1] = *batch_filename; /* only argv[0] gets freed later */ } else { new_argv[0] = xstrdup (*batch_filename); new_argv[1] = NULL; } new_argv[2] = NULL; } else #endif /* MK_OS_W32 */ if (unixy_shell) new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0, flags, 0); #if MK_OS_OS2 else if (!unixy_shell) { /* new_line is local, must not be freed therefore We use line here instead of new_line because we run the shell manually. */ char *q = new_line; line_len = strlen (line); p = new_line; memcpy (new_line, line, line_len + 1); /* Replace all backslash-newline combination and also following tabs. Important: stop at the first '\n' because that's what the loop above did. The next line starting at restp[0] will be executed during the next call of this function. */ while (*q != '\0' && *q != '\n') { if (q[0] == '\\' && q[1] == '\n') q += 2; /* remove '\\' and '\n' */ else *p++ = *q++; } *p = '\0'; # ifndef NO_CMD_DEFAULT if (strnicmp (new_line, "echo", 4) == 0 && (new_line[4] == ' ' || new_line[4] == '\t')) { /* the builtin echo command: handle it separately */ size_t echo_len = line_len - 5; char *echo_line = new_line + 5; /* special case: echo 'x="y"' cmd works this way: a string is printed as is, i.e., no quotes are removed. But autoconf uses a command like echo 'x="y"' to determine whether make works. autoconf expects the output x="y" so we will do exactly that. Note: if we do not allow cmd to be the default shell we do not need this kind of voodoo */ if (echo_line[0] == '\'' && echo_line[echo_len - 1] == '\'' && strncmp (echo_line + 1, "ac_maketemp=", strlen ("ac_maketemp=")) == 0) { /* remove the enclosing quotes */ memmove (echo_line, echo_line + 1, echo_len - 2); echo_line[echo_len - 2] = '\0'; } } # endif { /* Let the shell decide what to do. Put the command line into the 2nd command line argument and hope for the best ;-) */ size_t sh_len = strlen (shell); /* exactly 3 arguments + NULL */ new_argv = xmalloc (4 * sizeof (char *)); /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times the trailing '\0' */ new_argv[0] = xmalloc (sh_len + line_len + 5); memcpy (new_argv[0], shell, sh_len + 1); new_argv[1] = new_argv[0] + sh_len + 1; memcpy (new_argv[1], "/c", 3); new_argv[2] = new_argv[1] + 3; memcpy (new_argv[2], new_line, line_len + 1); new_argv[3] = NULL; } } #elif MK_OS_DOS else { /* With MSDOS shells, we must construct the command line here instead of recursively calling ourselves, because we cannot backslash-escape the special characters (see above). */ new_argv = xmalloc (sizeof (char *)); line_len = strlen (new_line) - shell_len - sflags_len - 2; new_argv[0] = xmalloc (line_len + 1); strncpy (new_argv[0], new_line + shell_len + sflags_len + 2, line_len); new_argv[0][line_len] = '\0'; } #else else fatal (NILF, CSTRLEN (__FILE__) + INTSTR_LENGTH, _("%s (line %d) Bad shell context (!unixy && !batch_mode_shell)\n"), __FILE__, __LINE__); #endif free (new_line); } return new_argv; } #endif /* !MK_OS_VMS */ /* Figure out the argument list necessary to run LINE as a command. Try to avoid using a shell. This routine handles only ' quoting, and " quoting when no backslash, $ or ' characters are seen in the quotes. Starting quotes may be escaped with a backslash. If any of the characters in sh_chars is seen, or any of the builtin commands listed in sh_cmds is the first word of a line, the shell is used. If RESTP is not NULL, *RESTP is set to point to the first newline in LINE. If *RESTP is NULL, newlines will be ignored. FILE is the target whose commands these are. It is used for variable expansion for $(SHELL) and $(IFS). */ char ** construct_command_argv (char *line, char **restp, struct file *file, int cmd_flags, char **batch_filename) { char *shell, *ifs; char *allocflags = NULL; const char *shellflags; char **argv; { struct variable *var; /* Turn off undefined variables warning while we expand HOME. */ enum warning_action save = warn_get (wt_undefined_var); warn_set (wt_undefined_var, w_ignore); shell = allocated_expand_variable_for_file (STRING_SIZE_TUPLE ("SHELL"), file); #if MK_OS_W32 /* * Convert to forward slashes so that construct_command_argv_internal() * is not confused. */ if (shell) { char *p = w32ify (shell, 0); strcpy (shell, p); } #endif #if MK_OS_OS2 { static const char *unixroot = NULL; static const char *last_shell = ""; static int init = 0; if (init == 0) { unixroot = getenv ("UNIXROOT"); /* unixroot must be NULL or not empty */ if (unixroot && unixroot[0] == '\0') unixroot = NULL; init = 1; } /* if we have an unixroot drive and if shell is not default_shell (which means it's either cmd.exe or the test has already been performed) and if shell is an absolute path without drive letter, try whether it exists e.g.: if "/bin/sh" does not exist use "$UNIXROOT/bin/sh" instead. */ if (unixroot && shell && ISDIRSEP (shell[0]) && !streq (shell, last_shell)) { /* trying a new shell, check whether it exists */ size_t size = strlen (shell); char *buf = xmalloc (size + 7); memcpy (buf, shell, size); memcpy (buf + size, ".exe", 5); /* including the trailing '\0' */ if (access (shell, F_OK) != 0 && access (buf, F_OK) != 0) { /* try the same for the unixroot drive */ memmove (buf + 2, buf, size + 5); buf[0] = unixroot[0]; buf[1] = unixroot[1]; if (access (buf, F_OK) == 0) /* we have found a shell! */ /* free(shell); */ shell = buf; else free (buf); } else free (buf); } } #endif /* MK_OS_OS2 */ var = lookup_variable_for_file (STRING_SIZE_TUPLE (".SHELLFLAGS"), file); if (!var) shellflags = ""; else if (var->origin != o_default) shellflags = allocflags = allocated_expand_string_for_file (var->value, file); else if (posix_pedantic && !ignore_errors_flag && NONE_SET (cmd_flags, COMMANDS_NOERROR)) /* In POSIX mode we default to -ec, unless we're ignoring errors. */ shellflags = "-ec"; else shellflags = "-c"; ifs = allocated_expand_variable_for_file (STRING_SIZE_TUPLE ("IFS"), file); warn_set (wt_undefined_var, save); } argv = construct_command_argv_internal (line, restp, shell, shellflags, ifs, cmd_flags, batch_filename); free (shell); free (allocflags); free (ifs); return argv; } #if !defined(HAVE_DUP2) int dup2 (int old, int new) { int fd; (void) close (new); EINTRLOOP (fd, dup (old)); if (fd != new) { (void) close (fd); errno = EMFILE; return -1; } return fd; } #endif /* !HAVE_DUP2 */ /* On VMS systems, include special VMS functions. */ #if MK_OS_VMS #include "vmsjobs.c" #endif ================================================ FILE: src/job.h ================================================ /* Definitions for managing subprocesses in GNU Make. Copyright (C) 1992-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "output.h" /* Structure describing a running or dead child process. */ #if MK_OS_VMS #define VMSCHILD \ char *comname; /* Temporary command file name */ \ int efn; /* Completion event flag number */ \ int cstatus; /* Completion status */ \ int vms_launch_status; /* non-zero if lib$spawn, etc failed */ #else #define VMSCHILD #endif #define CHILDBASE \ char *cmd_name; /* Allocated copy of command run. */ \ char **environment; /* Environment for commands. */ \ VMSCHILD \ struct output output /* Output for this child. */ struct childbase { CHILDBASE; }; struct child { CHILDBASE; struct child *next; /* Link in the chain. */ struct file *file; /* File being remade. */ char *sh_batch_file; /* Script file for shell commands */ char **command_lines; /* Array of variable-expanded cmd lines. */ char *command_ptr; /* Ptr into command_lines[command_line]. */ unsigned int command_line; /* Index into command_lines. */ pid_t pid; /* Child process's ID number. */ unsigned int remote:1; /* Nonzero if executing remotely. */ unsigned int noerror:1; /* Nonzero if commands contained a '-'. */ unsigned int good_stdin:1; /* Nonzero if this child has a good stdin. */ unsigned int deleted:1; /* Nonzero if targets have been deleted. */ unsigned int recursive:1; /* Nonzero for recursive command ('+' etc.) */ unsigned int jobslot:1; /* Nonzero if it's reserved a job slot. */ unsigned int dontcare:1; /* Saved dontcare flag. */ }; extern struct child *children; /* A signal handler for SIGCHLD, if needed. */ void child_handler (int sig); int is_bourne_compatible_shell(const char *path); void new_job (struct file *file); void reap_children (int block, int err); void start_waiting_jobs (void); void free_childbase (struct childbase* child); char **construct_command_argv (char *line, char **restp, struct file *file, int cmd_flags, char** batch_file); pid_t child_execute_job (struct childbase *child, int good_stdin, char **argv); pid_t exec_command (char **argv, char **envp); void unblock_all_sigs (void); extern unsigned int job_slots_used; extern unsigned int jobserver_tokens; ================================================ FILE: src/load.c ================================================ /* Loading dynamic objects for GNU Make. Copyright (C) 2012-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #if MAKE_LOAD #include #include #include #include #include #include "debug.h" #include "filedef.h" #include "variable.h" /* Tru64 V4.0 does not have this flag */ #ifndef RTLD_GLOBAL # define RTLD_GLOBAL 0 #endif #define GMK_SETUP "_gmk_setup" #define GMK_UNLOAD "_gmk_unload" typedef int (*setup_func_t)(unsigned int abi, const floc *flocp); typedef void (*unload_func_t)(void); struct load_list { struct load_list *next; const char *name; void *dlp; unload_func_t unload; }; static struct load_list *loaded_syms = NULL; static setup_func_t load_object (const floc *flocp, int noerror, const char *ldname, const char *setupnm) { static void *global_dl = NULL; char *buf; const char *fp; char *endp; void *dlp; struct load_list *new; setup_func_t symp; if (! global_dl) { global_dl = dlopen (NULL, RTLD_NOW|RTLD_GLOBAL); if (! global_dl) { const char *err = dlerror (); OS (fatal, flocp, _("failed to open global symbol table: %s"), err); } } /* Find the prefix of the ldname. */ fp = strrchr (ldname, '/'); #ifdef HAVE_DOS_PATHS if (fp) { const char *fp2 = strchr (fp, '\\'); if (fp2 > fp) fp = fp2; } else fp = strrchr (ldname, '\\'); /* The (improbable) case of d:foo. */ if (fp && *fp && fp[1] == ':') fp++; #endif if (!fp) fp = ldname; else ++fp; endp = buf = alloca (strlen (fp) + CSTRLEN (GMK_UNLOAD) + 1); while (isalnum ((unsigned char) *fp) || *fp == '_') *(endp++) = *(fp++); /* If we didn't find a symbol name yet, construct it from the prefix. */ if (! setupnm) { memcpy (endp, GMK_SETUP, CSTRLEN (GMK_SETUP) + 1); setupnm = buf; } DB (DB_VERBOSE, (_("Loading symbol %s from %s\n"), setupnm, ldname)); symp = (setup_func_t) dlsym (global_dl, setupnm); if (symp) return symp; /* If the path has no "/", try the current directory first. */ dlp = NULL; if (! strchr (ldname, '/') #ifdef HAVE_DOS_PATHS && ! strchr (ldname, '\\') #endif ) dlp = dlopen (concat (2, "./", ldname), RTLD_LAZY|RTLD_GLOBAL); /* If we haven't opened it yet, try the default search path. */ if (! dlp) dlp = dlopen (ldname, RTLD_LAZY|RTLD_GLOBAL); /* Still no? Then fail. */ if (! dlp) { const char *err = dlerror (); if (noerror) DB (DB_BASIC, ("%s\n", err)); else OS (error, flocp, "%s", err); return NULL; } DB (DB_VERBOSE, (_("Loaded shared object %s\n"), ldname)); /* Assert that the GPL license symbol is defined. */ symp = (setup_func_t) dlsym (dlp, "plugin_is_GPL_compatible"); if (! symp) OS (fatal, flocp, _("loaded object %s is not declared to be GPL compatible"), ldname); symp = (setup_func_t) dlsym (dlp, setupnm); if (! symp) { const char *err = dlerror (); OSSS (fatal, flocp, _("failed to load symbol %s from %s: %s"), setupnm, ldname, err); } new = xcalloc (sizeof (struct load_list)); new->next = loaded_syms; loaded_syms = new; new->name = ldname; new->dlp = dlp; /* Compute the name of the unload function and look it up. */ memcpy (endp, GMK_UNLOAD, CSTRLEN (GMK_UNLOAD) + 1); new->unload = (unload_func_t) dlsym (dlp, buf); if (new->unload) DB (DB_VERBOSE, (_("Detected symbol %s in %s\n"), buf, ldname)); return symp; } int load_file (const floc *flocp, struct file *file, int noerror) { const char *ldname = file->name; char *buf; char *setupnm = NULL; const char *fp; int r; setup_func_t symp; /* Break the input into an object file name and a symbol name. If no symbol name was provided, compute one from the object file name. */ fp = strchr (ldname, '('); if (fp) { const char *ep; /* There's an open paren, so see if there's a close paren: if so use that as the symbol name. We can't have whitespace: it would have been chopped up before this function is called. */ ep = strchr (fp+1, ')'); if (ep && ep[1] == '\0') { size_t l = fp - ldname; ++fp; if (fp == ep) OS (fatal, flocp, _("empty symbol name for load: %s"), ldname); /* Make a copy of the ldname part. */ buf = alloca (strlen (ldname) + 1); memcpy (buf, ldname, l); buf[l] = '\0'; ldname = buf; /* Make a copy of the symbol name part. */ setupnm = buf + l + 1; memcpy (setupnm, fp, ep - fp); setupnm[ep - fp] = '\0'; } } /* Make sure this name is in the string cache. */ ldname = file->name = strcache_add (ldname); /* If this object has been loaded, we're done: return -1 to ensure make does not rebuild again. If a rebuild is allowed it was set up when this object was initially loaded. */ file = lookup_file (ldname); if (file && file->loaded) return -1; /* Load it! */ symp = load_object (flocp, noerror, ldname, setupnm); if (! symp) return 0; /* Invoke the setup function. */ { unsigned int abi = GMK_ABI_VERSION; r = (*symp) (abi, flocp); } /* If the load didn't fail, add the file to the .LOADED variable. */ if (r) do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value, 0, s_global); return r; } int unload_file (const char *name) { struct load_list **dp = &loaded_syms; /* Unload and remove the entry for this file. */ while (*dp != NULL) { struct load_list *d = *dp; if (streq (d->name, name)) { int rc; DB (DB_VERBOSE, (_("Unloading shared object %s\n"), name)); if (d->unload) (*d->unload) (); rc = dlclose (d->dlp); if (rc) perror_with_name ("dlclose: ", d->name); *dp = d->next; free (d); return rc; } dp = &d->next; } return 0; } void unload_all () { while (loaded_syms) { struct load_list *d = loaded_syms; loaded_syms = loaded_syms->next; if (d->unload) (*d->unload) (); if (dlclose (d->dlp)) perror_with_name ("dlclose: ", d->name); free (d); } } #else int load_file (const floc *flocp, struct file *file UNUSED, int noerror) { if (! noerror) O (fatal, flocp, _("'load' is not supported on this platform")); return 0; } int unload_file (const char *name UNUSED) { O (fatal, NILF, "INTERNAL: cannot unload when load is not supported"); } void unload_all () { } #endif /* MAKE_LOAD */ ================================================ FILE: src/loadapi.c ================================================ /* API for GNU Make dynamic objects. Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "variable.h" #include "dep.h" /* Allocate a buffer in our context, so we can free it. */ char * gmk_alloc (unsigned int len) { return xmalloc (len); } /* Free a buffer returned by gmk_expand(). */ void gmk_free (char *s) { free (s); } /* Evaluate a buffer as make syntax. Ideally eval_buffer() will take const char *, but not yet. */ void gmk_eval (const char *buffer, const gmk_floc *gfloc) { /* Preserve existing variable buffer context. */ char *pbuf; size_t plen; char *s; floc fl; floc *flp; if (gfloc) { fl.filenm = gfloc->filenm; fl.lineno = gfloc->lineno; fl.offset = 0; flp = &fl; } else flp = NULL; install_variable_buffer (&pbuf, &plen); s = xstrdup (buffer); eval_buffer (s, flp); free (s); restore_variable_buffer (pbuf, plen); } /* Expand a string and return an allocated buffer. Caller must call gmk_free() with this buffer. */ char * gmk_expand (const char *ref) { return allocated_expand_string (ref); } /* Register a function to be called from makefiles. */ void gmk_add_function (const char *name, gmk_func_ptr func, unsigned int min, unsigned int max, unsigned int flags) { define_new_function (reading_file, name, min, max, flags, func); } ================================================ FILE: src/main.c ================================================ /* Argument parsing and main program of GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #if MK_OS_W32 # include # include # include "pathstuff.h" # include "sub_proc.h" # include "w32err.h" #endif #if MK_OS_OS2 # include # include #endif #ifdef HAVE_FCNTL_H # include #endif #if MK_OS_VMS int vms_use_mcr_command = 0; int vms_always_use_cmd_file = 0; int vms_gnv_shell = 0; int vms_legacy_behavior = 0; int vms_comma_separator = 0; int vms_unix_simulation = 0; int vms_report_unix_paths = 0; /* Evaluates if a VMS environment option is set, only look at first character */ static int get_vms_env_flag (const char *name, int default_value) { char * value; char x; value = getenv (name); if (value == NULL) return default_value; x = toupper (value[0]); switch (x) { case '1': case 'T': case 'E': return 1; break; case '0': case 'F': case 'D': return 0; } } #endif #if defined HAVE_WAITPID || defined HAVE_WAIT3 # define HAVE_WAIT_NOHANG #endif #ifndef HAVE_UNISTD_H int chdir (); #endif #ifndef STDC_HEADERS # ifndef sun /* Sun has an incorrect decl in a header. */ void exit (int) NORETURN; # endif double atof (); #endif #include "os.h" #include "filedef.h" #include "dep.h" #include "variable.h" #include "job.h" #include "commands.h" #include "rule.h" #include "debug.h" #include "getopt.h" #include "shuffle.h" #include "warning.h" static void clean_jobserver (int status); static void print_data_base (void); static void print_version (void); static void decode_switches (int argc, const char **argv, enum variable_origin origin); static void decode_env_switches (const char *envar, size_t len, enum variable_origin origin); static void disable_builtins (); static char *quote_for_env (char *out, const char *in); static void initialize_global_hash_tables (void); /* True if C is a switch value that corresponds to a short option. */ #define short_option(c) ((c) <= CHAR_MAX) /* The structure used to hold the list of strings given in command switches of a type that takes strlist arguments. */ struct stringlist { const char **list; /* Nil-terminated list of strings. */ unsigned int idx; /* Index into above. */ unsigned int max; /* Number of pointers allocated. */ }; /* The recognized command switches. */ /* Nonzero means do extra verification (that may slow things down). */ int verify_flag; /* Nonzero means do not print commands to be executed (-s). */ static int silent_flag; static const int default_silent_flag = 0; static enum variable_origin silent_origin = o_default; /* Nonzero means either -s was given, or .SILENT-with-no-deps was seen. */ int run_silent = 0; /* Nonzero means just touch the files that would appear to need remaking (-t) */ int touch_flag; /* Nonzero means just print what commands would need to be executed, don't actually execute them (-n). */ int just_print_flag; /* Print debugging info (--debug). */ static struct stringlist *db_flags = 0; static int debug_flag = 0; int db_level = 0; /* Synchronize output (--output-sync). */ char *output_sync_option = 0; /* Environment variables override makefile definitions. */ int env_overrides = 0; /* Nonzero means ignore status codes returned by commands executed to remake files. Just treat them all as successful (-i). */ int ignore_errors_flag = 0; /* Nonzero means print the data base that results from reading the makefile. (-p or --print-data-base). */ int print_data_base_flag = 0; /* Nonzero means don't remake anything, just print a list of targets defined by reading the makefile (--print-targets). */ int print_targets_flag = 0; /* Nonzero means don't remake anything; just return a nonzero status if the specified targets are not up to date (-q). */ int question_flag = 0; /* Nonzero means do not use any of the builtin rules (-r) / variables (-R). */ int no_builtin_rules_flag = 0; int no_builtin_variables_flag = 0; static int old_builtin_rules_flag; static int old_builtin_variables_flag; /* Nonzero means all variables are automatically exported. */ int export_all_variables = 0; /* Nonzero means keep going even if remaking some file fails (-k). */ int keep_going_flag; static const int default_keep_going_flag = 0; static enum variable_origin keep_going_origin = o_default; /* Nonzero means check symlink mtimes. */ int check_symlink_flag = 0; static int print_directory_flag = -1; static const int default_print_directory_flag = -1; static enum variable_origin print_directory_origin = o_default; /* Nonzero means print version information. */ int print_version_flag = 0; /* List of makefiles given with -f switches. */ static struct stringlist *makefiles = 0; /* Size of the stack when we started. */ #ifdef SET_STACK_SIZE struct rlimit stack_limit; #endif /* Number of job slots for parallelism. */ unsigned int job_slots; #define INVALID_JOB_SLOTS (-1) static unsigned int master_job_slots = 0; static int arg_job_slots = INVALID_JOB_SLOTS; static const int default_job_slots = INVALID_JOB_SLOTS; /* Value of job_slots that means no limit. */ static const int inf_jobs = 0; /* Authorization for the jobserver. */ char *jobserver_auth = NULL; /* Style for the jobserver. */ static char *jobserver_style = NULL; /* Shuffle mode for goals and prerequisites. */ static char *shuffle_mode = NULL; /* Handle for the mutex to synchronize output of our children under -O. */ static char *sync_mutex = NULL; /* Maximum load average at which multiple jobs will be run. Negative values mean unlimited, while zero means limit to zero load (which could be useful to start infinite jobs remotely but one at a time locally). */ double max_load_average = -1.0; double default_load_average = -1.0; /* List of directories given with -C switches. */ static struct stringlist *directories = 0; /* List of include directories given with -I switches. */ static struct stringlist *include_dirs = 0; /* List of files given with -o switches. */ static struct stringlist *old_files = 0; /* List of files given with -W switches. */ static struct stringlist *new_files = 0; /* List of strings to be eval'd. */ static struct stringlist *eval_strings = 0; /* If nonzero, we should just print usage and exit. */ static int print_usage_flag = 0; /* Command line warning flags. */ static struct stringlist *warn_flags = 0; /* If nonzero, we should print a warning message for each reference to an undefined variable. */ static int warn_undefined_variables_flag; /* If nonzero, always build all targets, regardless of whether they appear out of date or not. */ static int always_make_set = 0; int always_make_flag = 0; /* If nonzero, we're in the "try to rebuild makefiles" phase. */ int rebuilding_makefiles = 0; /* Remember the original value of the SHELL variable, from the environment. */ struct variable shell_var; /* This character introduces a command: it's the first char on the line. */ char cmd_prefix = '\t'; /* Whether or not .NOTINTERMEDIATE with no prerequisites was given. */ unsigned int no_intermediates; /* Count the number of commands we've invoked, that might change something in the filesystem. Start with 1 so calloc'd memory never matches. */ unsigned long command_count = 1; /* Remember the location of the name of the batch file from stdin. */ static int stdin_offset = -1; /* The usage output. We write it this way to make life easier for the translators, especially those trying to translate to right-to-left languages like Hebrew. */ static const char *const usage[] = { N_("Options:\n"), N_("\ -b, -m Ignored for compatibility.\n"), N_("\ -B, --always-make Unconditionally make all targets.\n"), N_("\ -C DIRECTORY, --directory=DIRECTORY\n\ Change to DIRECTORY before doing anything.\n"), N_("\ -d Print lots of debugging information.\n"), N_("\ --debug[=FLAGS] Print various types of debugging information.\n"), N_("\ -e, --environment-overrides\n\ Environment variables override makefiles.\n"), N_("\ -E STRING, --eval=STRING Evaluate STRING as a makefile statement.\n"), N_("\ -f FILE, --file=FILE, --makefile=FILE\n\ Read FILE as a makefile.\n"), N_("\ -h, --help Print this message and exit.\n"), N_("\ -i, --ignore-errors Ignore errors from recipes.\n"), N_("\ -I DIRECTORY, --include-dir=DIRECTORY\n\ Search DIRECTORY for included makefiles.\n"), N_("\ -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.\n"), N_("\ --jobserver-style=STYLE Select the style of jobserver to use.\n"), N_("\ -k, --keep-going Keep going when some targets can't be made.\n"), N_("\ -l [N], --load-average[=N], --max-load[=N]\n\ Don't start multiple jobs unless load is below N.\n"), N_("\ -L, --check-symlink-times Use the latest mtime between symlinks and target.\n"), N_("\ -n, --just-print, --dry-run, --recon\n\ Don't actually run any recipe; just print them.\n"), N_("\ -o FILE, --old-file=FILE, --assume-old=FILE\n\ Consider FILE to be very old and don't remake it.\n"), N_("\ -O[TYPE], --output-sync[=TYPE]\n\ Synchronize output of parallel jobs by TYPE.\n"), N_("\ -p, --print-data-base Print make's internal database.\n"), N_("\ -q, --question Run no recipe; exit status says if up to date.\n"), N_("\ -r, --no-builtin-rules Disable the built-in implicit rules.\n"), N_("\ -R, --no-builtin-variables Disable the built-in variable settings.\n"), N_("\ --shuffle[={SEED|random|reverse|none}]\n\ Perform shuffle of prerequisites and goals.\n"), N_("\ -s, --silent, --quiet Don't echo recipes.\n"), N_("\ --no-silent Echo recipes (disable --silent mode).\n"), N_("\ -S, --no-keep-going, --stop\n\ Turns off -k.\n"), N_("\ -t, --touch Touch targets instead of remaking them.\n"), N_("\ --trace Print tracing information.\n"), N_("\ -v, --version Print the version number of make and exit.\n"), N_("\ -w, --print-directory Print the current directory.\n"), N_("\ --no-print-directory Turn off -w, even if it was turned on implicitly.\n"), N_("\ -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE\n\ Consider FILE to be infinitely new.\n"), N_("\ --warn[=CONTROL] Control warnings for makefile issues.\n"), NULL }; /* Nonzero if the "--trace" option was given. */ static int trace_flag = 0; /* The structure that describes an accepted command switch. */ struct command_switch { int c; /* The switch character. */ enum /* Type of the value. */ { flag, /* Turn int flag on. */ flag_off, /* Turn int flag off. */ string, /* One string per invocation. */ strlist, /* One string per switch. */ filename, /* A string containing a file name. */ positive_int, /* A positive integer. */ floating, /* A floating-point number (double). */ ignore /* Ignored. */ } type; void *value_ptr; /* Pointer to the value-holding variable. */ unsigned int env:1; /* Can come from MAKEFLAGS. */ unsigned int toenv:1; /* Should be put in MAKEFLAGS. */ unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */ unsigned int specified:1; /* Set if the switch was specified somewhere. Allows switches that are ON by default to appear in MAKEFLAGS when set explicitly. */ const void *noarg_value; /* Pointer to value used if no arg given. */ const void *default_value; /* Pointer to default value. */ const char *long_name; /* Long option name. */ enum variable_origin *origin; /* Origin of the value. */ }; /* The table of command switches. Order matters here: this is the order MAKEFLAGS will be constructed. So be sure all simple flags (single char, no argument) come first. */ #define TEMP_STDIN_OPT (CHAR_MAX+10) #define WARN_OPT (CHAR_MAX+13) static struct command_switch switches[] = { { 'b', ignore, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, 0, "always-make", 0 }, { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0, 0, 0 }, { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, 0, "environment-overrides", 0 }, { 'E', strlist, &eval_strings, 1, 0, 0, 0, 0, 0, "eval", 0 }, { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, 0, "help", 0 }, { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, 0, "ignore-errors", 0 }, { 'k', flag, &keep_going_flag, 1, 1, 0, 0, 0, &default_keep_going_flag, "keep-going", &keep_going_origin }, { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, 0, "check-symlink-times", 0 }, { 'm', ignore, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, 0, "just-print", 0 }, { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, 0, "print-data-base", 0 }, { 'q', flag, &question_flag, 1, 1, 1, 0, 0, 0, "question", 0 }, { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, 0, "no-builtin-rules", 0 }, { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0, 0, "no-builtin-variables", 0 }, { 's', flag, &silent_flag, 1, 1, 0, 0, 0, &default_silent_flag, "silent", &silent_origin }, { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, 0, &default_keep_going_flag, "no-keep-going", &keep_going_origin }, { 't', flag, &touch_flag, 1, 1, 1, 0, 0, 0, "touch", 0 }, { 'v', flag, &print_version_flag, 1, 0, 0, 0, 0, 0, "version", 0 }, { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, &default_print_directory_flag, "print-directory", &print_directory_origin }, /* These options take arguments. */ { 'C', filename, &directories, 0, 0, 0, 0, 0, 0, "directory", 0 }, { 'f', filename, &makefiles, 0, 0, 0, 0, 0, 0, "file", 0 }, { 'I', filename, &include_dirs, 1, 1, 0, 0, 0, 0, "include-dir", 0 }, { 'j', positive_int, &arg_job_slots, 1, 1, 0, 0, &inf_jobs, &default_job_slots, "jobs", 0 }, { 'l', floating, &max_load_average, 1, 1, 0, 0, &default_load_average, &default_load_average, "load-average", 0 }, { 'o', filename, &old_files, 0, 0, 0, 0, 0, 0, "old-file", 0 }, { 'O', string, &output_sync_option, 1, 1, 0, 0, "target", 0, "output-sync", 0 }, { 'W', filename, &new_files, 0, 0, 0, 0, 0, 0, "what-if", 0 }, /* These are long-style options. */ { CHAR_MAX+1, strlist, &db_flags, 1, 1, 0, 0, "basic", 0, "debug", 0 }, { CHAR_MAX+2, string, &jobserver_auth, 1, 1, 0, 0, 0, 0, JOBSERVER_AUTH_OPT, 0 }, { CHAR_MAX+3, flag, &trace_flag, 1, 1, 0, 0, 0, 0, "trace", 0 }, { CHAR_MAX+4, flag_off, &print_directory_flag, 1, 1, 0, 0, 0, &default_print_directory_flag, "no-print-directory", &print_directory_origin }, { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 0, "warn-undefined-variables", 0 }, { CHAR_MAX+7, string, &sync_mutex, 1, 1, 0, 0, 0, 0, "sync-mutex", 0 }, { CHAR_MAX+8, flag_off, &silent_flag, 1, 1, 0, 0, 0, &default_silent_flag, "no-silent", &silent_origin }, { CHAR_MAX+9, string, &jobserver_auth, 1, 0, 0, 0, 0, 0, "jobserver-fds", 0 }, /* There is special-case handling for this in decode_switches() as well. */ { TEMP_STDIN_OPT, filename, &makefiles, 0, 0, 0, 0, 0, 0, "temp-stdin", 0 }, { CHAR_MAX+11, string, &shuffle_mode, 1, 1, 0, 0, "random", 0, "shuffle", 0 }, { CHAR_MAX+12, string, &jobserver_style, 1, 0, 0, 0, 0, 0, "jobserver-style", 0 }, { WARN_OPT, strlist, &warn_flags, 1, 1, 0, 0, "warn", NULL, "warn", NULL }, { CHAR_MAX+14, flag, &print_targets_flag, 1, 1, 0, 0, 0, 0, "print-targets", 0 }, { 0, 0, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL } }; /* Secondary long names for options. */ static struct option long_option_aliases[] = { { "quiet", no_argument, 0, 's' }, { "stop", no_argument, 0, 'S' }, { "new-file", required_argument, 0, 'W' }, { "assume-new", required_argument, 0, 'W' }, { "assume-old", required_argument, 0, 'o' }, { "max-load", optional_argument, 0, 'l' }, { "dry-run", no_argument, 0, 'n' }, { "recon", no_argument, 0, 'n' }, { "makefile", required_argument, 0, 'f' }, }; /* List of goal targets. */ static struct goaldep *goals, *lastgoal; /* List of variables which were defined on the command line (or, equivalently, in MAKEFLAGS). */ struct command_variable { struct command_variable *next; struct variable *variable; }; static struct command_variable *command_variables; /* The name we were invoked with. */ const char *program; /* Our current directory before processing any -C options. */ char *directory_before_chdir; /* Our current directory after processing all -C options. */ char *starting_directory; /* Value of the MAKELEVEL variable at startup (or 0). */ unsigned int makelevel; /* Pointer to the value of the .DEFAULT_GOAL special variable. The value will be the name of the goal to remake if the command line does not override it. It can be set by the makefile, or else it's the first target defined in the makefile whose name does not start with '.'. */ struct variable * default_goal_var; /* Pointer to structure for the file .DEFAULT whose commands are used for any file that has none of its own. This is zero if the makefiles do not define .DEFAULT. */ struct file *default_file; /* Nonzero if we have seen the magic '.POSIX' target. This turns on pedantic compliance with POSIX.2. */ int posix_pedantic; /* Nonzero if we have seen the '.SECONDEXPANSION' target. This turns on secondary expansion of prerequisites. */ int second_expansion; /* Nonzero if we have seen the '.ONESHELL' target. This causes the entire recipe to be handed to SHELL as a single string, potentially containing newlines. */ int one_shell; /* One of OUTPUT_SYNC_* if the "--output-sync" option was given. This attempts to synchronize the output of parallel jobs such that the results of each job stay together. */ int output_sync = OUTPUT_SYNC_NONE; /* Nonzero if we have seen the '.NOTPARALLEL' target. This turns off parallel builds for this invocation of make. */ int not_parallel; /* Nonzero if some rule detected clock skew; we keep track so (a) we only print one warning about it during the run, and (b) we can print a final warning at the end of the run. */ int clock_skew_detected; /* Map of possible stop characters for searching strings. */ #ifndef UCHAR_MAX # define UCHAR_MAX 255 #endif unsigned short stopchar_map[UCHAR_MAX + 1] = {0}; /* If output-sync is enabled we'll collect all the output generated due to options, while reading makefiles, etc. */ struct output make_sync; /* Mask of signals that are being caught with fatal_error_signal. */ #if defined(POSIX) sigset_t fatal_signal_set; #elif defined(HAVE_SIGSETMASK) int fatal_signal_mask; #endif #if !HAVE_DECL_BSD_SIGNAL && !defined bsd_signal # if !defined HAVE_SIGACTION # define bsd_signal signal # else typedef void (*bsd_signal_ret_t) (int); static bsd_signal_ret_t bsd_signal (int sig, bsd_signal_ret_t func) { struct sigaction act, oact; act.sa_handler = func; act.sa_flags = SA_RESTART; sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, sig); if (sigaction (sig, &act, &oact) != 0) return SIG_ERR; return oact.sa_handler; } # endif #endif static void initialize_global_hash_tables (void) { init_hash_global_variable_set (); strcache_init (); init_hash_files (); hash_init_directories (); hash_init_function_table (); } /* This character map locate stop chars when parsing GNU makefiles. Each element is true if we should stop parsing on that character. */ static void initialize_stopchar_map (void) { int i; stopchar_map[(int)'\0'] = MAP_NUL; stopchar_map[(int)'#'] = MAP_COMMENT; stopchar_map[(int)';'] = MAP_SEMI; stopchar_map[(int)'='] = MAP_EQUALS; stopchar_map[(int)':'] = MAP_COLON; stopchar_map[(int)'|'] = MAP_PIPE; stopchar_map[(int)'.'] = MAP_DOT | MAP_USERFUNC; stopchar_map[(int)','] = MAP_COMMA; stopchar_map[(int)'('] = MAP_VARSEP; stopchar_map[(int)'{'] = MAP_VARSEP; stopchar_map[(int)'}'] = MAP_VARSEP; stopchar_map[(int)')'] = MAP_VARSEP; stopchar_map[(int)'$'] = MAP_VARIABLE; stopchar_map[(int)'-'] = MAP_USERFUNC; stopchar_map[(int)'_'] = MAP_USERFUNC; stopchar_map[(int)' '] = MAP_BLANK; stopchar_map[(int)'\t'] = MAP_BLANK; stopchar_map[(int)'/'] = MAP_DIRSEP; #if MK_OS_VMS stopchar_map[(int)':'] |= MAP_DIRSEP; stopchar_map[(int)']'] |= MAP_DIRSEP; stopchar_map[(int)'>'] |= MAP_DIRSEP; #elif defined(HAVE_DOS_PATHS) stopchar_map[(int)'\\'] |= MAP_DIRSEP; #endif for (i = 1; i <= UCHAR_MAX; ++i) { if (isspace (i) && NONE_SET (stopchar_map[i], MAP_BLANK)) /* Don't mark blank characters as newline characters. */ stopchar_map[i] |= MAP_NEWLINE; else if (isalnum (i)) stopchar_map[i] |= MAP_USERFUNC; } } /* This code is stolen from gnulib. If/when we abandon the requirement to work with K&R compilers, we can remove this (and perhaps other parts of GNU Make!) and migrate to using gnulib directly. This is called only through atexit(), which means die() has already been invoked. So, call exit() here directly. Apparently that works...? */ /* Close standard output, exiting with status 'exit_failure' on failure. If a program writes *anything* to stdout, that program should close stdout and make sure that it succeeds before exiting. Otherwise, suppose that you go to the extreme of checking the return status of every function that does an explicit write to stdout. The last printf can succeed in writing to the internal stream buffer, and yet the fclose(stdout) could still fail (due e.g., to a disk full error) when it tries to write out that buffered data. Thus, you would be left with an incomplete output file and the offending program would exit successfully. Even calling fflush is not always sufficient, since some file systems (NFS and CODA) buffer written/flushed data until an actual close call. Besides, it's wasteful to check the return value from every call that writes to stdout -- just let the internal stream state record the failure. That's what the ferror test is checking below. It's important to detect such failures and exit nonzero because many tools (most notably 'make' and other build-management systems) depend on being able to detect failure in other tools via their exit status. */ static void close_stdout (void) { int prev_fail = ferror (stdout); int fclose_fail = fclose (stdout); if (prev_fail || fclose_fail) { if (fclose_fail) perror_with_name (_("write error: stdout"), ""); else O (error, NILF, _("write error: stdout")); exit (MAKE_TROUBLE); } } static const char * expand_command_line_file (const char *name) { const char *cp; char *expanded = 0; if (name[0] == '\0') O (fatal, NILF, _("empty string invalid as file name")); if (name[0] == '~') { expanded = tilde_expand (name); if (expanded && expanded[0] != '\0') name = expanded; } /* This is also done in parse_file_seq, so this is redundant for names read from makefiles. It is here for names passed on the command line. */ while (name[0] == '.' && name[1] == '/') { name += 2; while (name[0] == '/') /* Skip following slashes: ".//foo" is "foo", not "/foo". */ ++name; } if (name[0] == '\0') { /* Nothing else but one or more "./", maybe plus slashes! */ name = "./"; } cp = strcache_add (name); free (expanded); return cp; } /* Toggle -d on receipt of SIGUSR1. */ #ifdef SIGUSR1 static void debug_signal_handler (int sig UNUSED) { db_level = db_level ? DB_NONE : DB_BASIC; } #endif static void decode_debug_flags (void) { const char **pp; if (debug_flag) db_level = DB_ALL; if (trace_flag) db_level |= DB_PRINT | DB_WHY; if (db_flags) for (pp=db_flags->list; *pp; ++pp) { const char *p = *pp; while (1) { switch (tolower (p[0])) { case 'a': db_level |= DB_ALL; break; case 'b': db_level |= DB_BASIC; break; case 'i': db_level |= DB_BASIC | DB_IMPLICIT; break; case 'j': db_level |= DB_JOBS; break; case 'm': db_level |= DB_BASIC | DB_MAKEFILES; break; case 'n': db_level = 0; break; case 'p': db_level |= DB_PRINT; break; case 'v': db_level |= DB_BASIC | DB_VERBOSE; break; case 'w': db_level |= DB_WHY; break; default: OS (fatal, NILF, _("unknown debug level specification '%s'"), p); } while (*(++p) != '\0') if (*p == ',' || *p == ' ') { ++p; break; } if (*p == '\0') break; } } if (db_level) verify_flag = 1; if (! db_level) debug_flag = 0; } static void decode_output_sync_flags (void) { #ifdef NO_OUTPUT_SYNC output_sync = OUTPUT_SYNC_NONE; #else if (output_sync_option) { if (streq (output_sync_option, "none")) output_sync = OUTPUT_SYNC_NONE; else if (streq (output_sync_option, "line")) output_sync = OUTPUT_SYNC_LINE; else if (streq (output_sync_option, "target")) output_sync = OUTPUT_SYNC_TARGET; else if (streq (output_sync_option, "recurse")) output_sync = OUTPUT_SYNC_RECURSE; else OS (fatal, NILF, _("unknown output-sync type '%s'"), output_sync_option); } if (sync_mutex) osync_parse_mutex (sync_mutex); #endif } /* Print a nice usage method and exit. */ static void NORETURN print_usage (int bad) { const char *const *cpp; FILE *usageto; if (print_version_flag) { print_version (); fputs ("\n", stdout); } usageto = bad ? stderr : stdout; fprintf (usageto, _("Usage: %s [options] [target] ...\n"), program); for (cpp = usage; *cpp; ++cpp) fputs (_(*cpp), usageto); if (!remote_description || *remote_description == '\0') fprintf (usageto, _("\nThis program built for %s\n"), make_host); else fprintf (usageto, _("\nThis program built for %s (%s)\n"), make_host, remote_description); fprintf (usageto, _("Report bugs to \n")); die (bad ? MAKE_FAILURE : MAKE_SUCCESS); } #if MK_OS_W32 /* * HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture * exception and print it to stderr instead. * * If ! DB_VERBOSE, just print a simple message and exit. * If DB_VERBOSE, print a more verbose message. * If compiled for DEBUG, let exception pass through to GUI so that * debuggers can attach. */ LONG WINAPI handle_runtime_exceptions (struct _EXCEPTION_POINTERS *exinfo) { PEXCEPTION_RECORD exrec = exinfo->ExceptionRecord; LPSTR cmdline = GetCommandLine (); LPSTR prg = strtok (cmdline, " "); CHAR errmsg[1024]; #ifdef USE_EVENT_LOG HANDLE hEventSource; LPTSTR lpszStrings[1]; #endif if (! ISDB (DB_VERBOSE)) { sprintf (errmsg, _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%p)\n"), prg, exrec->ExceptionCode, exrec->ExceptionAddress); fputs (errmsg, stderr); exit (255); } sprintf (errmsg, _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = 0x%p\n"), prg, exrec->ExceptionCode, exrec->ExceptionFlags, exrec->ExceptionAddress); if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && exrec->NumberParameters >= 2) sprintf (&errmsg[strlen(errmsg)], (exrec->ExceptionInformation[0] ? _("Access violation: write operation at address 0x%p\n") : _("Access violation: read operation at address 0x%p\n")), (PVOID)exrec->ExceptionInformation[1]); /* turn this on if we want to put stuff in the event log too */ #ifdef USE_EVENT_LOG hEventSource = RegisterEventSource (NULL, "GNU Make"); lpszStrings[0] = errmsg; if (hEventSource != NULL) { ReportEvent (hEventSource, /* handle of event source */ EVENTLOG_ERROR_TYPE, /* event type */ 0, /* event category */ 0, /* event ID */ NULL, /* current user's SID */ 1, /* strings in lpszStrings */ 0, /* no bytes of raw data */ lpszStrings, /* array of error strings */ NULL); /* no raw data */ (VOID) DeregisterEventSource (hEventSource); } #endif /* Write the error to stderr too */ fputs (errmsg, stderr); #ifdef DEBUG return EXCEPTION_CONTINUE_SEARCH; #else exit (255); return (255); /* not reached */ #endif } /* * On W32 systems we don't have the luxury of a /bin directory that * is mapped globally to every drive mounted to the system. Since make could * be invoked from any drive, and we don't want to propagate /bin/sh * to every single drive. Allow ourselves a chance to search for * a value for default shell here (if the default path does not exist). */ int find_and_set_default_shell (const char *token) { int sh_found = 0; char *atoken = 0; const char *search_token; const char *tokend; extern const char *default_shell; if (!token) search_token = default_shell; else search_token = atoken = xstrdup (token); /* If the user explicitly requests the DOS cmd shell, obey that request. However, make sure that's what they really want by requiring the value of SHELL either equal, or have a final path element of, "cmd" or "cmd.exe" case-insensitive. */ tokend = search_token + strlen (search_token) - 3; if (((tokend == search_token || (tokend > search_token && ISDIRSEP (tokend[-1]))) && !strcasecmp (tokend, "cmd")) || ((tokend - 4 == search_token || (tokend - 4 > search_token && ISDIRSEP (tokend[-5]))) && !strcasecmp (tokend - 4, "cmd.exe"))) { batch_mode_shell = 1; unixy_shell = 0; default_shell = xstrdup (w32ify (search_token, 0)); DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), default_shell)); sh_found = 1; } else if (!no_default_sh_exe && (token == NULL || !strcmp (search_token, default_shell))) { /* no new information, path already set or known */ sh_found = 1; } else if (_access (search_token, 0) == 0) { /* search token path was found */ default_shell = xstrdup (w32ify (search_token, 0)); DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), default_shell)); sh_found = 1; } else { char *p; struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH")); /* Search Path for shell */ if (v && v->value) { char *ep; p = v->value; ep = strchr (p, PATH_SEPARATOR_CHAR); while (ep && *ep) { PATH_VAR (sh_path); *ep = '\0'; snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token); if (_access (sh_path, 0) == 0) { default_shell = xstrdup (w32ify (sh_path, 0)); sh_found = 1; *ep = PATH_SEPARATOR_CHAR; /* terminate loop */ p += strlen (p); } else { *ep = PATH_SEPARATOR_CHAR; p = ++ep; } ep = strchr (p, PATH_SEPARATOR_CHAR); } /* be sure to check last element of Path */ if (p && *p) { PATH_VAR (sh_path); snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token); if (_access (sh_path, 0) == 0) { default_shell = xstrdup (w32ify (sh_path, 0)); sh_found = 1; } } if (sh_found) DB (DB_VERBOSE, (_("find_and_set_shell() path search set default_shell = %s\n"), default_shell)); } } /* naive test */ if (!unixy_shell && sh_found && (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) { unixy_shell = 1; batch_mode_shell = 0; } #ifdef BATCH_MODE_ONLY_SHELL batch_mode_shell = 1; #endif free (atoken); return (sh_found); } #endif /* MK_OS_W32 */ #if MK_OS_DOS static void msdos_return_to_initial_directory (void) { if (directory_before_chdir) chdir (directory_before_chdir); } #endif /* MK_OS_DOS */ static void reset_jobserver (void) { jobserver_clear (); free (jobserver_auth); jobserver_auth = NULL; } void temp_stdin_unlink () { /* This function is called from a signal handler. Keep async-signal-safe. If there is a temp file from reading from stdin, get rid of it. */ if (stdin_offset >= 0) { const char *nm = makefiles->list[stdin_offset]; int r = 0; stdin_offset = -1; EINTRLOOP(r, unlink (nm)); if (r < 0 && errno != ENOENT && !handling_fatal_signal) perror_with_name (_("unlink (temporary file): "), nm); } } #ifdef MK_OS_ZOS extern char **environ; #endif #if defined(MK_OS_ZOS) int main (int argc, char **argv) #else int main (int argc, char **argv, char **envp) #endif { int makefile_status = MAKE_SUCCESS; struct goaldep *read_files; PATH_VAR (current_directory); unsigned int restarts = 0; unsigned int syncing = 0; int argv_slots; /* The jobslot info we got from our parent process. */ #if MK_OS_W32 const char *unix_path = NULL; const char *windows32_path = NULL; SetUnhandledExceptionFilter (handle_runtime_exceptions); /* start off assuming we have no shell */ unixy_shell = 0; no_default_sh_exe = 1; #endif initialize_variable_output (); /* Useful for attaching debuggers, etc. */ SPIN ("main-entry"); #ifdef HAVE_ATEXIT if (ANY_SET (check_io_state (), IO_STDOUT_OK)) atexit (close_stdout); #endif output_init (&make_sync); initialize_stopchar_map (); warn_init (); #ifdef SET_STACK_SIZE /* Get rid of any avoidable limit on stack size. */ { struct rlimit rlim; /* Set the stack limit huge so that alloca does not fail. */ if (getrlimit (RLIMIT_STACK, &rlim) == 0 && rlim.rlim_cur > 0 && rlim.rlim_cur < rlim.rlim_max) { stack_limit = rlim; rlim.rlim_cur = rlim.rlim_max; setrlimit (RLIMIT_STACK, &rlim); } else stack_limit.rlim_cur = 0; } #endif /* Needed for OS/2 */ initialize_main (&argc, &argv); #ifdef MAKE_MAINTAINER_MODE /* In maintainer mode we always enable verification. */ verify_flag = 1; #endif #if MK_OS_DOS && !defined (_POSIX_SOURCE) /* Request the most powerful version of 'system', to make up for the dumb default shell. */ __system_flags = (__system_redirect | __system_use_shell | __system_allow_multiple_cmds | __system_allow_long_cmds | __system_handle_null_commands | __system_emulate_chdir); #endif /* Set up gettext/internationalization support. */ setlocale (LC_ALL, ""); /* The cast to void shuts up compiler warnings on systems that disable NLS. */ (void)bindtextdomain (PACKAGE, LOCALEDIR); (void)textdomain (PACKAGE); #ifdef POSIX sigemptyset (&fatal_signal_set); #define ADD_SIG(sig) sigaddset (&fatal_signal_set, sig) #else #ifdef HAVE_SIGSETMASK fatal_signal_mask = 0; #define ADD_SIG(sig) fatal_signal_mask |= sigmask (sig) #else #define ADD_SIG(sig) (void)sig #endif #endif #define FATAL_SIG(sig) \ if (bsd_signal (sig, fatal_error_signal) == SIG_IGN) \ bsd_signal (sig, SIG_IGN); \ else \ ADD_SIG (sig); #ifdef SIGHUP FATAL_SIG (SIGHUP); #endif #ifdef SIGQUIT FATAL_SIG (SIGQUIT); #endif #ifdef SIGPIPE FATAL_SIG (SIGPIPE); #endif FATAL_SIG (SIGINT); FATAL_SIG (SIGTERM); #if MK_OS_DOS /* Windows 9X delivers FP exceptions in child programs to their parent! We don't want Make to die when a child divides by zero, so we work around that lossage by catching SIGFPE. */ FATAL_SIG (SIGFPE); #endif #ifdef SIGDANGER FATAL_SIG (SIGDANGER); #endif #ifdef SIGXCPU FATAL_SIG (SIGXCPU); #endif #ifdef SIGXFSZ FATAL_SIG (SIGXFSZ); #endif #undef FATAL_SIG /* Do not ignore the child-death signal. This must be done before any children could possibly be created; otherwise, the wait functions won't work on systems with the SVR4 ECHILD brain damage, if our invoker is ignoring this signal. */ #ifdef HAVE_WAIT_NOHANG # if defined SIGCHLD (void) bsd_signal (SIGCHLD, SIG_DFL); # endif # if defined SIGCLD && SIGCLD != SIGCHLD (void) bsd_signal (SIGCLD, SIG_DFL); # endif #endif output_init (NULL); /* Figure out where this program lives. */ if (argv[0] == 0) argv[0] = (char *)""; if (argv[0][0] == '\0') program = "make"; else { #if defined(HAVE_DOS_PATHS) const char* start = argv[0]; /* Skip an initial drive specifier if present. */ if (isalpha ((unsigned char)start[0]) && start[1] == ':') start += 2; if (start[0] == '\0') program = "make"; else { program = start + strlen (start); while (program > start && ! ISDIRSEP (program[-1])) --program; /* Remove the .exe extension if present. */ { size_t len = strlen (program); if (len > 4 && streq (&program[len - 4], ".exe")) program = xstrndup (program, len - 4); } } #elif MK_OS_VMS set_program_name (argv[0]); program = program_name; { const char *shell; char pwdbuf[256]; char *pwd; shell = getenv ("SHELL"); if (shell != NULL) vms_gnv_shell = 1; /* Need to know if CRTL set to report UNIX paths. Use getcwd as it works on all versions of VMS. */ pwd = getcwd(pwdbuf, 256); if (pwd[0] == '/') vms_report_unix_paths = 1; vms_use_mcr_command = get_vms_env_flag ("GNV$MAKE_USE_MCR", 0); vms_always_use_cmd_file = get_vms_env_flag ("GNV$MAKE_USE_CMD_FILE", 0); /* Legacy behavior is on VMS is older behavior that needed to be changed to be compatible with standard make behavior. For now only completely disable when running under a Bash shell. TODO: Update VMS built in recipes and macros to not need this behavior, at which time the default may change. */ vms_legacy_behavior = get_vms_env_flag ("GNV$MAKE_OLD_VMS", !vms_gnv_shell); /* VMS was changed to use a comma separator in the past, but that is incompatible with built in functions that expect space separated lists. Allow this to be selectively turned off. */ vms_comma_separator = get_vms_env_flag ("GNV$MAKE_COMMA", vms_legacy_behavior); /* Some Posix shell syntax options are incompatible with VMS syntax. VMS requires double quotes for strings and escapes quotes differently. When this option is active, VMS will try to simulate Posix shell simulations instead of using VMS DCL behavior. */ vms_unix_simulation = get_vms_env_flag ("GNV$MAKE_SHELL_SIM", !vms_legacy_behavior); } if (need_vms_symbol () && !vms_use_mcr_command) create_foreign_command (program_name, argv[0]); #else program = strrchr (argv[0], '/'); if (program == 0) program = argv[0]; else ++program; #endif } initialize_global_hash_tables (); /* Ensure the temp directory is set up: we don't want the first time we use it to be in a forked process. */ get_tmpdir (); /* Figure out where we are. */ #if MK_OS_W32 if (getcwd_fs (current_directory, GET_PATH_MAX) == 0) #else if (getcwd (current_directory, GET_PATH_MAX) == 0) #endif { #ifdef HAVE_GETCWD perror_with_name ("getcwd", ""); #else OS (error, NILF, "getwd: %s", current_directory); #endif current_directory[0] = '\0'; directory_before_chdir = 0; } else directory_before_chdir = xstrdup (current_directory); #if MK_OS_DOS /* Make sure we will return to the initial directory, come what may. */ atexit (msdos_return_to_initial_directory); #endif /* Initialize the special variables. */ define_variable_cname ("MAKEFLAGS", "", o_default, 0)->special = 1; define_variable_cname (".VARIABLES", "", o_default, 0)->special = 1; /* define_variable_cname (".TARGETS", "", o_default, 0)->special = 1; */ define_variable_cname (".RECIPEPREFIX", "", o_default, 0)->special = 1; define_variable_cname (WARNINGS_NAME, "", o_default, 0)->special = 1; define_variable_cname (".SHELLFLAGS", "-c", o_default, 0); define_variable_cname (".LOADED", "", o_default, 0); /* Set up .FEATURES Use a separate variable because define_variable_cname() is a macro and some compilers (MSVC) don't like conditionals in macros. */ { const char *features = "target-specific order-only second-expansion" " else-if shortest-stem undefine oneshell nocomment" " grouped-target extra-prereqs notintermediate" " shell-export" #ifndef NO_ARCHIVES " archives" #endif #ifdef MAKE_JOBSERVER " jobserver" # if JOBSERVER_USE_FIFO " jobserver-fifo" # endif #endif #ifndef NO_OUTPUT_SYNC " output-sync" #endif #ifdef MAKE_SYMLINKS " check-symlink" #endif #ifdef HAVE_GUILE " guile" #endif #ifdef MAKE_LOAD " load" #endif #ifdef HAVE_DOS_PATHS " dospaths" #endif #ifdef MAKE_MAINTAINER_MODE " maintainer" #endif #if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_MEMORY__) " sanitize" #endif ; define_variable_cname (".FEATURES", features, o_default, 0); } /* Configure GNU Guile support */ guile_gmake_setup (NILF); /* Read in variables from the environment. It is important that this be done before $(MAKE) is figured out so its definitions will not be from the environment. */ #ifdef MK_OS_ZOS char **envp = environ; #endif { unsigned int i; for (i = 0; envp[i] != 0; ++i) { struct variable *v; const char *ep = envp[i]; /* By default, export all variables culled from the environment. */ enum variable_export export = v_export; size_t len; while (! STOP_SET (*ep, MAP_EQUALS|MAP_NUL)) ++ep; /* If there's no equals sign it's a malformed environment. Ignore. */ if (*ep == '\0') continue; #if MK_OS_W32 if (!unix_path && strneq (envp[i], "PATH=", 5)) unix_path = ep+1; else if (!strnicmp (envp[i], "Path=", 5)) { if (!windows32_path) windows32_path = ep+1; /* PATH gets defined after the loop exits. */ continue; } #endif /* Length of the variable name, and skip the '='. */ len = ep++ - envp[i]; /* If this is MAKE_RESTARTS, check to see if the "already printed the enter statement" flag is set. */ if (len == 13 && memcmp (envp[i], "MAKE_RESTARTS", CSTRLEN ("MAKE_RESTARTS")) == 0) { if (*ep == '-') { OUTPUT_TRACED (); ++ep; } restarts = make_toui (ep, NULL); export = v_noexport; } v = define_variable (envp[i], len, ep, o_env, 1); /* POSIX says the value of SHELL set in the makefile won't change the value of SHELL given to subprocesses. */ if (streq (v->name, "SHELL")) { #if !MK_OS_DOS export = v_noexport; #endif shell_var.name = xstrdup ("SHELL"); shell_var.length = 5; shell_var.value = xstrdup (ep); } v->export = export; } } #if MK_OS_W32 /* If we didn't find a correctly spelled PATH we define PATH as * either the first misspelled value or an empty string */ if (!unix_path) define_variable_cname ("PATH", windows32_path ? windows32_path : "", o_env, 1)->export = v_export; #endif /* Decode the switches. */ if (lookup_variable (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME))) { decode_env_switches (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME), o_command); /* Clear GNUMAKEFLAGS to avoid duplication. */ define_variable_cname (GNUMAKEFLAGS_NAME, "", o_env, 0); } /* Set MAKEFLAGS's origin to command line: in submakes MAKEFLAGS will carry command line switches. This causes env variable MAKEFLAGS to beat makefile modifications to MAKEFLAGS. */ decode_env_switches (STRING_SIZE_TUPLE (MAKEFLAGS_NAME), o_command); #if 0 /* People write things like: MFLAGS="CC=gcc -pipe" "CFLAGS=-g" and we set the -p, -i and -e switches. Doesn't seem quite right. */ decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); #endif /* In output sync mode we need to sync any output generated by reading the makefiles, such as in $(info ...) or stderr from $(shell ...) etc. */ syncing = make_sync.syncout = (output_sync == OUTPUT_SYNC_LINE || output_sync == OUTPUT_SYNC_TARGET); OUTPUT_SET (&make_sync); /* Parse the command line options. Remember the job slots set this way. */ { int env_slots = arg_job_slots; arg_job_slots = INVALID_JOB_SLOTS; decode_switches (argc, (const char **)argv, o_command); argv_slots = arg_job_slots; if (arg_job_slots == INVALID_JOB_SLOTS) arg_job_slots = env_slots; } if (print_usage_flag) print_usage (0); /* Print version information, and exit. */ if (print_version_flag) { print_version (); die (MAKE_SUCCESS); } /* Now that we know we'll be running, force stdout to be line-buffered. */ #ifdef HAVE_SETVBUF setvbuf (stdout, 0, _IOLBF, BUFSIZ); #elif HAVE_SETLINEBUF setlinebuf (stdout); #endif /* Handle shuffle mode argument. */ if (shuffle_mode) { const char *effective_mode; shuffle_set_mode (shuffle_mode); /* Write fixed seed back to argument list to propagate mode and fixed seed to child $(MAKE) runs. */ free (shuffle_mode); effective_mode = shuffle_get_mode (); if (effective_mode) shuffle_mode = xstrdup (effective_mode); else shuffle_mode = NULL; } /* Set a variable specifying whether stdout/stdin is hooked to a TTY. */ #ifdef HAVE_ISATTY if (isatty (fileno (stdout))) if (! lookup_variable (STRING_SIZE_TUPLE ("MAKE_TERMOUT"))) { const char *tty = TTYNAME (fileno (stdout)); define_variable_cname ("MAKE_TERMOUT", tty ? tty : DEFAULT_TTYNAME, o_default, 0)->export = v_export; } if (isatty (fileno (stderr))) if (! lookup_variable (STRING_SIZE_TUPLE ("MAKE_TERMERR"))) { const char *tty = TTYNAME (fileno (stderr)); define_variable_cname ("MAKE_TERMERR", tty ? tty : DEFAULT_TTYNAME, o_default, 0)->export = v_export; } #endif /* Reset in case the switches changed our minds. */ syncing = (output_sync == OUTPUT_SYNC_LINE || output_sync == OUTPUT_SYNC_TARGET); if (make_sync.syncout && ! syncing) output_close (&make_sync); make_sync.syncout = syncing; OUTPUT_SET (&make_sync); /* Figure out the level of recursion. */ { struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME)); if (v && v->value[0] != '\0' && v->value[0] != '-') makelevel = make_toui (v->value, NULL); else makelevel = 0; } /* Set always_make_flag if -B was given and we've not restarted already. */ always_make_flag = always_make_set && (restarts == 0); /* If -R was given, set -r too (doesn't make sense otherwise!) */ if (no_builtin_variables_flag) no_builtin_rules_flag = 1; if (ISDB (DB_BASIC)) { print_version (); /* Flush stdout so the user doesn't have to wait to see the version information while make thinks about things. */ fflush (stdout); } #if !MK_OS_VMS /* Set the "MAKE_COMMAND" variable to the name we were invoked with. (If it is a relative pathname with a slash, prepend our directory name so the result will run the same program regardless of the current dir. If it is a name with no slash, we can only hope that PATH did not find it in the current directory.) */ #if MK_OS_W32 /* * Convert from backslashes to forward slashes for * programs like sh which don't like them. Shouldn't * matter if the path is one way or the other for * CreateProcess(). */ if (strpbrk (argv[0], "/:\\") || strstr (argv[0], "..") || strneq (argv[0], "//", 2)) argv[0] = xstrdup (w32ify (argv[0], 1)); #elif MK_OS_DOS || MK_OS_OS2 if (strchr (argv[0], '\\')) { char *p; argv[0] = xstrdup (argv[0]); for (p = argv[0]; *p; p++) if (*p == '\\') *p = '/'; } /* If argv[0] is not in absolute form, prepend the current directory. This can happen when Make is invoked by another DJGPP program that uses a non-absolute name. */ if (current_directory[0] != '\0' && argv[0] != 0 && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':')) # if MK_OS_OS2 /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */ && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0) # endif ) argv[0] = xstrdup (concat (3, current_directory, "/", argv[0])); #else /* !MK_OS_DOS */ if (current_directory[0] != '\0' && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0 #ifdef HAVE_DOS_PATHS && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':')) && strchr (argv[0], '\\') != 0 #endif ) argv[0] = xstrdup (concat (3, current_directory, "/", argv[0])); #endif /* !MK_OS_DOS */ #endif /* MK_OS_W32 */ /* We may move, but until we do, here we are. */ starting_directory = current_directory; /* If there were -C flags, move ourselves about. */ if (directories != 0) { unsigned int i; for (i = 0; directories->list[i] != 0; ++i) { const char *dir = directories->list[i]; #if MK_OS_W32 /* Windows32 chdir() doesn't work if the directory has a trailing '/' But allow -C/ just in case someone wants that. */ { char *p = (char *)dir + strlen (dir) - 1; while (p > dir && ISDIRSEP (p[0])) --p; p[1] = '\0'; } #endif if (chdir (dir) < 0) pfatal_with_name (dir); } } #if MK_OS_W32 /* * THIS BLOCK OF CODE MUST COME AFTER chdir() CALL ABOVE IN ORDER * TO NOT CONFUSE THE DEPENDENCY CHECKING CODE IN implicit.c. * * The functions in dir.c can incorrectly cache information for "." * before we have changed directory and this can cause file * lookups to fail because the current directory (.) was pointing * at the wrong place when it was first evaluated. */ no_default_sh_exe = !find_and_set_default_shell (NULL); #endif /* MK_OS_W32 */ /* If we chdir'ed, figure out where we are now. */ if (directories) { #if MK_OS_W32 if (getcwd_fs (current_directory, GET_PATH_MAX) == 0) #else if (getcwd (current_directory, GET_PATH_MAX) == 0) #endif { #ifdef HAVE_GETCWD perror_with_name ("getcwd", ""); #else OS (error, NILF, "getwd: %s", current_directory); #endif starting_directory = 0; } else starting_directory = current_directory; } define_variable_cname ("CURDIR", current_directory, o_file, 0); /* Construct the list of include directories to search. This will check for existence so it must be done after chdir. */ construct_include_path (include_dirs ? include_dirs->list : NULL); /* Validate the arg_job_slots configuration before we define MAKEFLAGS so users get an accurate value in their makefiles. At this point arg_job_slots is the argv setting, if there is one, else the MAKEFLAGS env setting, if there is one. */ if (jobserver_auth) { /* We're a child in an existing jobserver group. */ if (argv_slots == INVALID_JOB_SLOTS) { /* There's no -j option on the command line: check authorization. */ if (jobserver_parse_auth (jobserver_auth)) /* Success! Use the jobserver. */ goto job_setup_complete; /* Oops: we have jobserver-auth but it's invalid :(. */ O (error, NILF, _("warning: jobserver unavailable: using -j1 (add '+' to parent make rule)")); arg_job_slots = 1; } /* The user provided a -j setting on the command line so use it: we're the master make of a new jobserver group. */ else if (!restarts && argv_slots != 1) ON (error, NILF, _("warning: -j%d forced in submake: resetting jobserver mode"), argv_slots); /* We can't use our parent's jobserver, so reset. */ reset_jobserver (); } job_setup_complete: /* The extra indirection through $(MAKE_COMMAND) is done for hysterical raisins. */ #if MK_OS_VMS if (vms_use_mcr_command) define_variable_cname ("MAKE_COMMAND", vms_command (argv[0]), o_default, 0); else define_variable_cname ("MAKE_COMMAND", program, o_default, 0); #else define_variable_cname ("MAKE_COMMAND", argv[0], o_default, 0); #endif define_variable_cname ("MAKE", "$(MAKE_COMMAND)", o_default, 1); if (command_variables != 0) { struct command_variable *cv; struct variable *v; size_t len = 0; char *value, *p; /* Figure out how much space will be taken up by the command-line variable definitions. */ for (cv = command_variables; cv != 0; cv = cv->next) { v = cv->variable; len += 2 * strlen (v->name); if (! v->recursive) ++len; ++len; len += 2 * strlen (v->value); ++len; } /* Now allocate a buffer big enough and fill it. */ p = value = xmalloc (len); for (cv = command_variables; cv != 0; cv = cv->next) { v = cv->variable; p = quote_for_env (p, v->name); if (! v->recursive) *p++ = ':'; *p++ = '='; p = quote_for_env (p, v->value); *p++ = ' '; } p[-1] = '\0'; /* Kill the final space and terminate. */ /* Define an unchangeable variable with a name that no POSIX.2 makefile could validly use for its own variable. */ define_variable_cname ("-*-command-variables-*-", value, o_automatic, 0); free (value); /* Define the variable; this will not override any user definition. Normally a reference to this variable is written into the value of MAKEFLAGS, allowing the user to override this value to affect the exported value of MAKEFLAGS. In POSIX-pedantic mode, we cannot allow the user's setting of MAKEOVERRIDES to affect MAKEFLAGS, so a reference to this hidden variable is written instead. */ define_variable_cname ("MAKEOVERRIDES", "${-*-command-variables-*-}", o_default, 1); #if MK_OS_VMS vms_export_dcl_symbol ("MAKEOVERRIDES", "${-*-command-variables-*-}"); #endif } /* Read any stdin makefiles into temporary files. */ if (makefiles != 0) { unsigned int i; for (i = 0; i < makefiles->idx; ++i) if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') { /* This makefile is standard input. Since we may re-exec and thus re-read the makefiles, we read standard input into a temporary file and read from that. */ FILE *outfile; char *newnm; if (stdin_offset >= 0) O (fatal, NILF, _("Makefile from standard input specified twice")); outfile = get_tmpfile (&newnm); if (!outfile) O (fatal, NILF, _("cannot store makefile from stdin to a temporary file")); while (!feof (stdin) && ! ferror (stdin)) { char buf[2048]; size_t n = fread (buf, 1, sizeof (buf), stdin); if (n > 0 && fwrite (buf, 1, n, outfile) != n) OSS (fatal, NILF, _("fwrite: temporary file %s: %s"), newnm, strerror (errno)); } fclose (outfile); /* Replace the name that read_all_makefiles will see with the name of the temporary file. */ makefiles->list[i] = strcache_add (newnm); stdin_offset = i; free (newnm); } } /* Make sure the temporary file is never considered updated. */ if (stdin_offset >= 0) { struct file *f = enter_file (makefiles->list[stdin_offset]); f->updated = 1; f->update_status = us_success; f->command_state = cs_finished; /* Can't be intermediate, or it'll be removed before make re-exec. */ f->intermediate = 0; f->dontcare = 0; /* Avoid re-exec due to stdin temp file timestamps. */ f->last_mtime = f->mtime_before_update = f_mtime (f, 0); } #if !MK_OS_OS2 /* Don't use a SIGCHLD handler for OS/2 */ #if !defined(HAVE_WAIT_NOHANG) || defined(MAKE_JOBSERVER) /* Set up to handle children dying. This must be done before reading in the makefiles so that 'shell' function calls will work. If we don't have a hanging wait we have to fall back to old, broken functionality here and rely on the signal handler and counting children. If we're using the jobs pipe we need a signal handler so that SIGCHLD is not ignored; we need it to interrupt the read(2) of the jobserver pipe if we're waiting for a token. If none of these are true, we don't need a signal handler at all. */ { # if defined SIGCHLD bsd_signal (SIGCHLD, child_handler); # endif # if defined SIGCLD && SIGCLD != SIGCHLD bsd_signal (SIGCLD, child_handler); # endif } #if defined(HAVE_PSELECT) && !defined(MK_OS_ZOS) /* If we have pselect() then we need to block SIGCHLD so it's deferred. */ { sigset_t block; sigemptyset (&block); sigaddset (&block, SIGCHLD); if (sigprocmask (SIG_SETMASK, &block, NULL) < 0) pfatal_with_name ("sigprocmask(SIG_SETMASK, SIGCHLD)"); } #endif #endif #endif /* Let the user send us SIGUSR1 to toggle the -d flag during the run. */ #ifdef SIGUSR1 bsd_signal (SIGUSR1, debug_signal_handler); #endif /* Define the initial list of suffixes for old-style rules. */ set_default_suffixes (); /* Define some internal and special variables. */ define_automatic_variables (); /* Set up the MAKEFLAGS and MFLAGS variables for makefiles to see. Initialize it to be exported but allow the makefile to reset it. */ define_makeflags (0)->export = v_export; /* Define the default variables. */ define_default_variables (); default_file = enter_file (strcache_add (".DEFAULT")); default_goal_var = define_variable_cname (".DEFAULT_GOAL", "", o_file, 0); /* Evaluate all strings provided with --eval. Also set up the $(-*-eval-flags-*-) variable. */ if (eval_strings) { char *p, *endp, *value; unsigned int i; size_t len = (CSTRLEN ("--eval=") + 1) * eval_strings->idx; for (i = 0; i < eval_strings->idx; ++i) { p = xstrdup (eval_strings->list[i]); len += 2 * strlen (p); eval_buffer (p, NULL); free (p); } p = endp = value = xmalloc (len); for (i = 0; i < eval_strings->idx; ++i) { p = stpcpy (p, "--eval="); p = quote_for_env (p, eval_strings->list[i]); endp = p++; *endp = ' '; } *endp = '\0'; define_variable_cname ("-*-eval-flags-*-", value, o_automatic, 0); free (value); } { int old_arg_job_slots = arg_job_slots; old_builtin_rules_flag = no_builtin_rules_flag; old_builtin_variables_flag = no_builtin_variables_flag; /* Read all the makefiles. */ read_files = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); arg_job_slots = INVALID_JOB_SLOTS; /* Decode switches again, for variables set by the makefile. */ decode_env_switches (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME), o_env); /* Clear GNUMAKEFLAGS to avoid duplication. */ define_variable_cname (GNUMAKEFLAGS_NAME, "", o_override, 0); decode_env_switches (STRING_SIZE_TUPLE (MAKEFLAGS_NAME), o_env); #if 0 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); #endif /* If -j is not set in the makefile, or it was set on the command line, reset to use the previous value. */ if (arg_job_slots == INVALID_JOB_SLOTS || argv_slots != INVALID_JOB_SLOTS) arg_job_slots = old_arg_job_slots; else if (jobserver_auth && arg_job_slots != old_arg_job_slots) { /* Makefile MAKEFLAGS set -j, but we already have a jobserver. Make us the master of a new jobserver group. */ if (!restarts) ON (error, NILF, _("warning: -j%d forced in makefile: resetting jobserver mode"), arg_job_slots); /* We can't use our parent's jobserver, so reset. */ reset_jobserver (); } /* Reset in case the switches changed our mind. */ syncing = (output_sync == OUTPUT_SYNC_LINE || output_sync == OUTPUT_SYNC_TARGET); if (make_sync.syncout && ! syncing) output_close (&make_sync); make_sync.syncout = syncing; OUTPUT_SET (&make_sync); disable_builtins (); } #if MK_OS_W32 /* look one last time after reading all Makefiles */ if (no_default_sh_exe) no_default_sh_exe = !find_and_set_default_shell (NULL); #endif /* MK_OS_W32 */ #if MK_OS_DOS || MK_OS_OS2 || MK_OS_VMS /* We need to know what kind of shell we will be using. */ { extern int _is_unixy_shell (const char *_path); struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL")); extern int unixy_shell; extern const char *default_shell; if (shv && *shv->value) { char *shell_path = recursively_expand (shv); if (shell_path && _is_unixy_shell (shell_path)) unixy_shell = 1; else unixy_shell = 0; if (shell_path) default_shell = shell_path; } } #endif /* MK_OS_DOS || MK_OS_OS2 */ /* Final jobserver configuration. If we have jobserver_auth then we are a client in an existing jobserver group, that's already been verified OK above. If we don't have jobserver_auth and jobserver is enabled, then start a new jobserver. arg_job_slots = INVALID_JOB_SLOTS if we don't want -j in MAKEFLAGS arg_job_slots = # of jobs of parallelism job_slots = 0 for no limits on jobs, or when limiting via jobserver. job_slots = 1 for standard non-parallel mode. job_slots >1 for old-style parallelism without jobservers. */ if (jobserver_auth) job_slots = 0; else if (arg_job_slots == INVALID_JOB_SLOTS) job_slots = 1; else job_slots = arg_job_slots; #if MK_OS_DOS || MK_OS_OS2 || MK_OS_VMS if (job_slots != 1 # if MK_OS_OS2 && _osmode != OS2_MODE /* turn off -j if we are in DOS mode */ # endif ) { O (error, NILF, _("parallel jobs (-j) are not supported on this platform")); O (error, NILF, _("resetting to single job (-j1) mode")); arg_job_slots = INVALID_JOB_SLOTS; job_slots = 1; } #endif /* If we have >1 slot at this point, then we're a top-level make. Set up the jobserver. Every make assumes that it always has one job it can run. For the submakes it's the token they were given by their parent. For the top make, we just subtract one from the number the user wants. */ if (job_slots > 1 && jobserver_setup (job_slots - 1, jobserver_style)) { /* Fill in the jobserver_auth for our children. */ jobserver_auth = jobserver_get_auth (); if (jobserver_auth) { /* We're using the jobserver so set job_slots to 0. */ master_job_slots = job_slots; job_slots = 0; } } /* If we're not using parallel jobs, then we don't need output sync. This is so people can enable output sync in GNUMAKEFLAGS or similar, but not have it take effect unless parallel builds are enabled. */ if (syncing && job_slots == 1) { OUTPUT_UNSET (); output_close (&make_sync); syncing = 0; output_sync = OUTPUT_SYNC_NONE; } if (syncing) { /* If there is no mutex we're the base: create one. Else parse it. */ if (!sync_mutex) { osync_setup (); sync_mutex = osync_get_mutex (); } else if (!osync_parse_mutex (sync_mutex)) { /* Parsing failed; continue without output sync. */ osync_clear (); free (sync_mutex); sync_mutex = NULL; syncing = 0; } } if (jobserver_auth) DB (DB_VERBOSE|DB_JOBS, (_("Using jobserver controller %s\n"), jobserver_auth)); if (sync_mutex) DB (DB_VERBOSE, (_("Using output-sync mutex %s\n"), sync_mutex)); #ifndef MAKE_SYMLINKS if (check_symlink_flag) { O (error, NILF, _("symbolic links not supported: disabling -L")); check_symlink_flag = 0; } #endif /* Set up MAKEFLAGS and MFLAGS again, so they will be right. */ define_makeflags (0); /* Make each 'struct goaldep' point at the 'struct file' for the file depended on. Also do magic for special targets. */ snap_deps (); /* Define the file rules for the built-in suffix rules. These will later be converted into pattern rules. */ install_default_suffix_rules (); /* Convert old-style suffix rules to pattern rules. It is important to do this before installing the built-in pattern rules below, so that makefile-specified suffix rules take precedence over built-in pattern rules. */ convert_to_pattern (); /* Install the default implicit pattern rules. This used to be done before reading the makefiles. But in that case, built-in pattern rules were in the chain before user-defined ones, so they matched first. */ install_default_implicit_rules (); /* Compute implicit rule limits and do magic for pattern rules. */ snap_implicit_rules (); /* Construct the listings of directories in VPATH lists. */ build_vpath_lists (); /* Mark files given with -o flags as very old and as having been updated already, and files given with -W flags as brand new (time-stamp as far as possible into the future). If restarts is set we'll do -W later. */ if (old_files != 0) { const char **p; for (p = old_files->list; *p != 0; ++p) { struct file *f = enter_file (*p); f->last_mtime = f->mtime_before_update = OLD_MTIME; f->updated = 1; f->update_status = us_success; f->command_state = cs_finished; } } /* If the user wants to see a list of targets show it now then quit. We do this before rebuilding makefiles to avoid extraneous output. */ if (print_targets_flag) { print_targets (); die (EXIT_SUCCESS); } if (!restarts && new_files != 0) { const char **p; for (p = new_files->list; *p != 0; ++p) { struct file *f = enter_file (*p); f->last_mtime = f->mtime_before_update = NEW_MTIME; } } /* Initialize the remote job module. */ remote_setup (); /* Dump any output we've collected. */ OUTPUT_UNSET (); output_close (&make_sync); if (shuffle_mode) DB (DB_BASIC, (_("Enabled shuffle mode: %s\n"), shuffle_mode)); if (read_files) { /* Update any makefiles if necessary. */ FILE_TIMESTAMP *makefile_mtimes; struct goaldep *skipped_makefiles = NULL; const char **nargv = (const char **) argv; int any_failed = 0; enum update_status status; DB (DB_BASIC, (_("Updating makefiles....\n"))); /* Count the makefiles, and reverse the order so that we attempt to rebuild them in the order they were read. */ { unsigned int num_mkfiles = 0; struct goaldep *d = read_files; read_files = NULL; while (d != NULL) { struct goaldep *t = d; d = d->next; t->next = read_files; read_files = t; ++num_mkfiles; } makefile_mtimes = alloca (num_mkfiles * sizeof (FILE_TIMESTAMP)); } /* Remove any makefiles we don't want to try to update. Record the current modtimes of the others so we can compare them later. */ { struct goaldep *d = read_files; struct goaldep *last = NULL; unsigned int mm_idx = 0; while (d != 0) { int skip = 0; struct file *f = d->file; /* Check for makefiles that are either phony or a :: target with commands, but no dependencies. These will always be remade, which will cause an infinite restart loop, so don't try to remake it (this will only happen if your makefiles are written exceptionally stupidly; but if you work for Athena, that's how you write your makefiles.) */ if (f->phony) skip = 1; else for (f = f->double_colon; f != NULL; f = f->prev) if (f->deps == NULL && f->cmds != NULL) { skip = 1; break; } if (!skip) { makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file); last = d; d = d->next; } else { DB (DB_VERBOSE, (_("Makefile '%s' might loop; not remaking it.\n"), f->name)); if (last) last->next = d->next; else read_files = d->next; if (d->error && ! (d->flags & RM_DONTCARE)) { /* This file won't be rebuilt, was not found, and we care, so remember it to report later. */ d->next = skipped_makefiles; skipped_makefiles = d; any_failed = 1; } else free_goaldep (d); d = last ? last->next : read_files; } } } /* Set up 'MAKEFLAGS' specially while remaking makefiles. */ define_makeflags (1); { int orig_db_level = db_level; if (! ISDB (DB_MAKEFILES)) db_level = DB_NONE; rebuilding_makefiles = 1; status = update_goal_chain (read_files); rebuilding_makefiles = 0; db_level = orig_db_level; } /* Report errors for makefiles that needed to be remade but were not. */ while (skipped_makefiles != NULL) { struct goaldep *d = skipped_makefiles; const char *err = strerror (d->error); OSS (error, &d->floc, _("%s: %s"), dep_name (d), err); skipped_makefiles = skipped_makefiles->next; free_goaldep (d); } /* If we couldn't build something we need but otherwise we succeeded, reset the status. */ if (any_failed && status == us_success) status = us_none; switch (status) { case us_question: /* The only way this can happen is if the user specified -q and asked for one of the makefiles to be remade as a target on the command line. Since we're not actually updating anything with -q we can treat this as "did nothing". */ break; case us_none: { /* Reload any unloaded shared objects. Do not re-exec to have that shared object loaded: a re-exec would cause an infinite loop, because the shared object was not updated. */ struct goaldep *d; for (d = read_files; d; d = d->next) if (d->file->unloaded) { struct file *f = d->file; /* Load the file. 0 means failure. */ if (load_file (&d->floc, f, 0) == 0) OS (fatal, &d->floc, _("%s: failed to load"), f->name); f->unloaded = 0; f->loaded = 1; } } /* No makefiles needed to be updated. If we couldn't read some included file that we care about, fail. */ if (0) { /* This runs afoul of https://savannah.gnu.org/bugs/?61226 The problem is that many makefiles use a "dummy rule" to pretend that an included file is rebuilt, without actually rebuilding it, and this has always worked. There are a number of solutions proposed in that bug but for now we'll put things back so they work the way they did before. */ struct goaldep *d; for (d = read_files; d != 0; d = d->next) if (d->error && ! (d->flags & RM_DONTCARE)) { /* This makefile couldn't be loaded, and we care. */ const char *err = strerror (d->error); OSS (error, &d->floc, _("%s: %s"), dep_name (d), err); any_failed = 1; } } break; case us_failed: /* Failed to update. Figure out if we care. */ { /* Nonzero if any makefile was successfully remade. */ int any_remade = 0; unsigned int i; struct goaldep *d; for (i = 0, d = read_files; d != 0; ++i, d = d->next) { if (d->file->updated) { /* This makefile was updated. */ if (d->file->update_status == us_success) /* It was successfully updated. */ any_remade |= (file_mtime_no_search (d->file) != makefile_mtimes[i]); else if (! (d->flags & RM_DONTCARE)) { FILE_TIMESTAMP mtime; /* The update failed and this makefile was not from the MAKEFILES variable, so we care. */ OS (error, &d->floc, _("failed to remake makefile '%s'"), d->file->name); mtime = file_mtime_no_search (d->file); any_remade |= (mtime != NONEXISTENT_MTIME && mtime != makefile_mtimes[i]); makefile_status = MAKE_FAILURE; any_failed = 1; } } /* This makefile was not found at all. */ else if (! (d->flags & RM_DONTCARE)) { const char *dnm = dep_name (d); /* This is a makefile we care about. See how much. */ if (d->flags & RM_INCLUDED) /* An included makefile. We don't need to die, but we do want to complain. */ OS (error, &d->floc, _("included makefile '%s' was not found"), dnm); else { /* A normal makefile. We must die later. */ OS (error, NILF, _("makefile '%s' was not found"), dnm); any_failed = 1; } } } if (any_remade) goto re_exec; break; } case us_success: re_exec: /* Updated successfully. Re-exec ourselves. */ remove_intermediates (0); if (print_data_base_flag) print_data_base (); clean_jobserver (0); if (makefiles != 0) { /* Makefile names might have changed due to expansion. It's possible we'll need one extra argument: make -Rf- will expand to: make -R --temp-stdin= so allocate more space. */ int mfidx = 0; char** av = argv; const char** nv; nv = nargv = alloca (sizeof (char*) * (argc + 1 + 1)); *(nv++) = *(av++); for (; *av; ++av, ++nv) { char *f; char *a = *av; const char *mf = makefiles->list[mfidx]; assert (strlen (a) > 0); *nv = a; /* Not an option: we handled option args earlier. */ if (a[0] != '-') continue; /* See if this option specifies a filename. If so we need to replace it with the value from makefiles->list. To simplify, we'll replace all possible versions of this flag with a simple "-f". */ /* Handle long options. */ if (a[1] == '-') { if (strcmp (a, "--file") == 0 || strcmp (a, "--makefile") == 0) /* Skip the next arg as we'll combine them. */ ++av; else if (!strneq (a, "--file=", 7) && !strneq (a, "--makefile=", 11)) continue; if (mfidx == stdin_offset) { char *na = alloca (CSTRLEN ("--temp-stdin=") + strlen (mf) + 1); sprintf (na, "--temp-stdin=%s", mf); *nv = na; } else { char *na = alloca (strlen (mf) + 3); sprintf (na, "-f%s", mf); *nv = na; } ++mfidx; continue; } /* Handle short options. If 'f' is the last option, it may be followed by . */ f = strchr (a, 'f'); if (!f) continue; /* If there's an extra argument option skip it. */ if (f[1] == '\0') ++av; if (mfidx == stdin_offset) { const size_t al = f - a; char *na; if (al > 1) { /* Preserve the prior options. */ na = alloca (al + 1); memcpy (na, a, al); na[al] = '\0'; *(nv++) = na; } /* Remove the "f" and any subsequent content. */ na = alloca (CSTRLEN ("--temp-stdin=") + strlen (mf) + 1); sprintf (na, "--temp-stdin=%s", mf); *nv = na; } else if (f[1] == '\0') /* -f or -xyzf . Replace the name. */ *(++nv) = mf; else { /* -f or -xyzf. */ const size_t al = f - a + 1; const size_t ml = strlen (mf) + 1; char *na = alloca (al + ml); memcpy (na, a, al); memcpy (na + al, mf, ml); *nv = na; } ++mfidx; } *nv = NULL; } if (directories != 0 && directories->idx > 0) { int bad = 1; if (directory_before_chdir != 0) { if (chdir (directory_before_chdir) < 0) perror_with_name ("chdir", ""); else bad = 0; } if (bad) O (fatal, NILF, _("couldn't change back to original directory")); } ++restarts; if (ISDB (DB_BASIC)) { const char **p; printf (_("Re-executing[%u]:"), restarts); for (p = nargv; *p != 0; ++p) printf (" %s", *p); putchar ('\n'); fflush (stdout); } { char **p; for (p = environ; *p != 0; ++p) { if (strneq (*p, MAKELEVEL_NAME "=", MAKELEVEL_LENGTH+1)) { *p = alloca (40); sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); #if MK_OS_VMS vms_putenv_symbol (*p); #endif } else if (strneq (*p, "MAKE_RESTARTS=", CSTRLEN ("MAKE_RESTARTS="))) { *p = alloca (40); sprintf (*p, "MAKE_RESTARTS=%s%u", OUTPUT_IS_TRACED () ? "-" : "", restarts); restarts = 0; } } } /* If we didn't set the restarts variable yet, add it. */ if (restarts) { char *b = alloca (40); sprintf (b, "MAKE_RESTARTS=%s%u", OUTPUT_IS_TRACED () ? "-" : "", restarts); putenv (b); } fflush (stdout); fflush (stderr); osync_clear(); /* The exec'd "child" will be another make, of course. */ jobserver_pre_child(1); #if MK_OS_OS2 { /* It is not possible to use execve() here because this would cause the parent process to be terminated with exit code 0 before the child process has been terminated. Therefore it may be the best solution simply to spawn the child process including all file handles and to wait for its termination. */ pid_t pid; int r; struct childbase child; child.cmd_name = NULL; child.output.syncout = 0; child.environment = environ; pid = child_execute_job (&child, 1, (char **)nargv); /* is this loop really necessary? */ do { pid = wait (&r); } while (pid <= 0); /* use the exit code of the child process */ exit (WIFEXITED(r) ? WEXITSTATUS(r) : EXIT_FAILURE); } #else #ifdef SET_STACK_SIZE /* Reset limits, if necessary. */ if (stack_limit.rlim_cur) setrlimit (RLIMIT_STACK, &stack_limit); #endif exec_command ((char **)nargv, environ); #endif jobserver_post_child(1); temp_stdin_unlink (); _exit (127); } if (any_failed) die (MAKE_FAILURE); } /* Set up 'MAKEFLAGS' again for the normal targets. */ define_makeflags (0); /* Set always_make_flag if -B was given. */ always_make_flag = always_make_set; /* If restarts is set we haven't set up -W files yet, so do that now. */ if (restarts && new_files != 0) { const char **p; for (p = new_files->list; *p != 0; ++p) { struct file *f = enter_file (*p); f->last_mtime = f->mtime_before_update = NEW_MTIME; } } temp_stdin_unlink (); /* If there were no command-line goals, use the default. */ if (goals == 0) { char *p; if (default_goal_var->recursive) p = expand_string (default_goal_var->value); else { p = variable_buffer_output (variable_buffer, default_goal_var->value, strlen (default_goal_var->value)); *p = '\0'; p = variable_buffer; } if (*p != '\0') { struct file *f = lookup_file (p); /* If .DEFAULT_GOAL is a non-existent target, enter it into the table and let the standard logic sort it out. */ if (f == 0) { struct nameseq *ns; ns = PARSE_SIMPLE_SEQ (&p, struct nameseq); if (ns) { /* .DEFAULT_GOAL should contain one target. */ if (ns->next != 0) O (fatal, NILF, _(".DEFAULT_GOAL contains more than one target")); f = enter_file (strcache_add (ns->name)); ns->name = 0; /* It was reused by enter_file(). */ free_ns_chain (ns); } } if (f) { goals = alloc_goaldep (); goals->file = f; } } } else lastgoal->next = 0; if (!goals) { struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("MAKEFILE_LIST")); if (v && v->value && v->value[0] != '\0') O (fatal, NILF, _("No targets")); O (fatal, NILF, _("No targets specified and no makefile found")); } /* Shuffle prerequisites to catch makefiles with incomplete depends. */ shuffle_goaldeps_recursive (goals); /* Update the goals. */ DB (DB_BASIC, (_("Updating goal targets....\n"))); { switch (update_goal_chain (goals)) { case us_none: /* Nothing happened. */ /* FALLTHROUGH */ case us_success: /* Keep the previous result. */ break; case us_question: /* We are under -q and would run some commands. */ makefile_status = MAKE_TROUBLE; break; case us_failed: /* Updating failed. POSIX.2 specifies exit status >1 for this; */ makefile_status = MAKE_FAILURE; break; } /* If we detected some clock skew, generate one last warning */ if (clock_skew_detected) O (error, NILF, _("warning: clock skew detected: your build may be incomplete")); /* Exit. */ die (makefile_status); } /* NOTREACHED */ exit (MAKE_SUCCESS); } /* Parsing of arguments, decoding of switches. */ static char options[1 + ARRAYLEN (switches) * 3]; static struct option long_options[ARRAYLEN (switches) + ARRAYLEN (long_option_aliases)]; /* Fill in the string and vector for getopt. */ static void init_switches (void) { char *p; unsigned int c; unsigned int i; if (options[0] != '\0') /* Already done. */ return; p = options; /* Return switch and non-switch args in order, regardless of POSIXLY_CORRECT. Non-switch args are returned as option 1. */ *p++ = '-'; for (i = 0; switches[i].c != '\0'; ++i) { long_options[i].name = (char *) (switches[i].long_name == 0 ? "" : switches[i].long_name); long_options[i].flag = 0; long_options[i].val = switches[i].c; if (short_option (switches[i].c)) *p++ = (char) switches[i].c; switch (switches[i].type) { case flag: case flag_off: case ignore: long_options[i].has_arg = no_argument; break; case string: case strlist: case filename: case positive_int: case floating: if (short_option (switches[i].c)) *p++ = ':'; if (switches[i].noarg_value != 0) { if (short_option (switches[i].c)) *p++ = ':'; long_options[i].has_arg = optional_argument; } else long_options[i].has_arg = required_argument; break; } } *p = '\0'; for (c = 0; c < ARRAYLEN (long_option_aliases); ++c) long_options[i++] = long_option_aliases[c]; long_options[i].name = 0; } /* Non-option argument. It might be a variable definition. Returns 1 if the argument we read was .WAIT, else 0. */ static unsigned int handle_non_switch_argument (const char *arg, enum variable_origin origin) { struct variable *v; if (arg[0] == '-' && arg[1] == '\0') /* Ignore plain '-' for compatibility. */ return 0; #if MK_OS_VMS { /* VMS DCL quoting can result in foo="bar baz" showing up here. Need to remove the double quotes from the value. */ char * eq_ptr; char * new_arg; eq_ptr = strchr (arg, '='); if ((eq_ptr != NULL) && (eq_ptr[1] == '"')) { int len; int seg1; int seg2; len = strlen(arg); new_arg = alloca(len); seg1 = eq_ptr - arg + 1; strncpy(new_arg, arg, (seg1)); seg2 = len - seg1 - 1; strncpy(&new_arg[seg1], &eq_ptr[2], seg2); new_arg[seg1 + seg2] = 0; if (new_arg[seg1 + seg2 - 1] == '"') new_arg[seg1 + seg2 - 1] = 0; arg = new_arg; } } #endif v = try_variable_definition (0, arg, origin, s_global); if (v != 0) { /* It is indeed a variable definition. If we don't already have this one, record a pointer to the variable for later use in define_makeflags. */ struct command_variable *cv; for (cv = command_variables; cv != 0; cv = cv->next) if (cv->variable == v) break; if (! cv) { cv = xmalloc (sizeof (*cv)); cv->variable = v; cv->next = command_variables; command_variables = cv; } } else if (arg[0] != '\0' && origin == o_command) { /* Not an option or variable definition; it must be a goal target. Enter it as a file and add it to the dep chain of goals. Check ARG[0] because if the top makefile resets MAKEOVERRIDES then ARG points to an empty string in the submake. */ struct file *f; if (strcmp (arg, ".WAIT") == 0) return 1; f = enter_file (strcache_add (expand_command_line_file (arg))); f->cmd_target = 1; if (goals == 0) { goals = alloc_goaldep (); lastgoal = goals; } else { lastgoal->next = alloc_goaldep (); lastgoal = lastgoal->next; } lastgoal->file = f; { /* Add this target name to the MAKECMDGOALS variable. */ struct variable *gv; const char *value; gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS")); if (gv == 0) value = f->name; else { /* Paste the old and new values together */ size_t oldlen, newlen; char *vp; oldlen = strlen (gv->value); newlen = strlen (f->name); vp = alloca (oldlen + 1 + newlen + 1); memcpy (vp, gv->value, oldlen); vp[oldlen] = ' '; memcpy (&vp[oldlen + 1], f->name, newlen + 1); value = vp; } define_variable_cname ("MAKECMDGOALS", value, o_default, 0); } } return 0; } /* Called if the makefile resets the MAKEFLAGS variable. */ void reset_makeflags (enum variable_origin origin) { /* Reset to default values. */ env_overrides = 0; decode_env_switches (STRING_SIZE_TUPLE(MAKEFLAGS_NAME), origin); construct_include_path (include_dirs ? include_dirs->list : NULL); disable_builtins (); define_makeflags (rebuilding_makefiles); } /* Decode switches from ARGC and ARGV. They came from the environment if ORIGIN is o_env. */ static void decode_switches (int argc, const char **argv, enum variable_origin origin) { int bad = 0; struct command_switch *cs; struct stringlist *sl; struct stringlist targets; int c; unsigned int found_wait = 0; const char **a; /* This is for safety/double-checking. */ static int using_getopt = 0; assert (using_getopt == 0); using_getopt = 1; /* Get enough space for all the arguments, just in case. */ targets.max = argc + 1; targets.list = alloca (targets.max * sizeof (const char **)); targets.idx = 0; /* getopt does most of the parsing for us. First, get its vectors set up. */ init_switches (); /* Let getopt produce error messages for the command line, but not for options from the environment. */ opterr = origin == o_command; /* Reset getopt's state. */ optind = 0; while (optind < argc) { const char *coptarg; /* Parse the next argument. */ c = getopt_long (argc, (char *const *)argv, options, long_options, NULL); coptarg = optarg; if (c == EOF) /* End of arguments, or "--" marker seen. */ break; else if (c == '?') /* Bad option. We will print a usage message and die later. But continue to parse the other options so the user can see all he did wrong. */ bad = 1; else if (c == 1) /* An argument not starting with a dash. Defer handling until later, since handle_non_switch_argument() might corrupt getopt(). */ targets.list[targets.idx++] = coptarg; else /* An option starting with a dash. */ for (cs = switches; cs->c != '\0'; ++cs) if (cs->c == c) { /* Whether or not we will actually do anything with this switch. We test this individually inside the switch below rather than just once outside it, so that options which are to be ignored still consume args. */ int doit = (origin == o_command || (cs->env && (cs->origin == NULL || origin >= *cs->origin))); if (doit) cs->specified = 1; switch (cs->type) { default: abort (); case ignore: break; case flag: case flag_off: if (doit) { *(int *) cs->value_ptr = cs->type == flag; if (cs->origin) *cs->origin = origin; } break; case string: case strlist: case filename: if (!doit) break; if (! coptarg) coptarg = cs->noarg_value; else if (*coptarg == '\0') { char opt[2] = "c"; const char *op = opt; if (short_option (cs->c)) opt[0] = (char) cs->c; else op = cs->long_name; error (NILF, strlen (op), _("the '%s%s' option requires a non-empty string argument"), short_option (cs->c) ? "-" : "--", op); bad = 1; break; } if (cs->type == string) { char **val = (char **)cs->value_ptr; free (*val); *val = xstrdup (coptarg); if (cs->origin) *cs->origin = origin; break; } sl = *(struct stringlist **) cs->value_ptr; if (sl == 0) { sl = xmalloc (sizeof (struct stringlist)); sl->max = 5; sl->idx = 0; sl->list = xmalloc (5 * sizeof (char *)); *(struct stringlist **) cs->value_ptr = sl; } else if (sl->idx == sl->max - 1) { sl->max += 5; /* MSVC erroneously warns without a cast here. */ sl->list = xrealloc ((void *)sl->list, sl->max * sizeof (char *)); } /* Filter out duplicate options. Order matters for warnings. Allow duplicate makefiles for backward compatibility. */ if (cs->c != 'f' && cs->c != WARN_OPT) { unsigned int k; for (k = 0; k < sl->idx; ++k) if (streq (sl->list[k], coptarg)) break; if (k < sl->idx) break; } if (cs->type == strlist) { sl->list[sl->idx++] = xstrdup (coptarg); if (cs->origin) *cs->origin = origin; } else if (cs->c == TEMP_STDIN_OPT) { if (stdin_offset > 0) fatal (NILF, 0, "INTERNAL: multiple --temp-stdin options provided!"); /* We don't need to expand the temp file. */ stdin_offset = sl->idx; sl->list[sl->idx++] = strcache_add (coptarg); if (cs->origin) *cs->origin = origin; } else { sl->list[sl->idx++] = expand_command_line_file (coptarg); if (cs->origin) *cs->origin = origin; } sl->list[sl->idx] = 0; break; case positive_int: /* See if we have an option argument; if we do require that it's all digits, not something like "10foo". */ if (coptarg == 0 && argc > optind) { const char *cp; for (cp=argv[optind]; ISDIGIT (cp[0]); ++cp) ; if (cp[0] == '\0') coptarg = argv[optind++]; } if (!doit) break; if (coptarg) { const char *err; unsigned int i = make_toui (coptarg, &err); if (err || i == 0) { error (NILF, 0, _("the '-%c' option requires a positive integer argument"), cs->c); bad = 1; } else { *(unsigned int *) cs->value_ptr = i; if (cs->origin) *cs->origin = origin; } } else { *(unsigned int *) cs->value_ptr = *(unsigned int *) cs->noarg_value; if (cs->origin) *cs->origin = origin; } break; case floating: if (coptarg == 0 && optind < argc && (ISDIGIT (argv[optind][0]) || argv[optind][0] == '.')) coptarg = argv[optind++]; if (doit) { *(double *) cs->value_ptr = (coptarg != 0 ? atof (coptarg) : *(double *) cs->noarg_value); if (cs->origin) *cs->origin = origin; } break; } /* We've found the switch. Stop looking. */ break; } } /* There are no more options according to getting getopt, but there may be some arguments left. Since we have asked for non-option arguments to be returned in order, this only happens when there is a "--" argument to prevent later arguments from being options. */ while (optind < argc) targets.list[targets.idx++] = argv[optind++]; targets.list[targets.idx] = NULL; /* Cannot call getopt below this line. */ using_getopt = 0; /* handle_non_switch_argument() can only be called after getopt is done; if one of the arguments is MAKEFLAGS= then it will recurse here and call getopt() again, corrupting the state if the outer method. */ for (a = targets.list; *a; ++a) { const int prior_found_wait = found_wait; found_wait = handle_non_switch_argument (*a, origin); if (prior_found_wait && lastgoal) lastgoal->wait_here = 1; } if (bad && origin == o_command) print_usage (bad); /* If there are any options that need to be decoded do it now. */ decode_debug_flags (); decode_output_sync_flags (); /* Support old-style option. */ if (warn_undefined_variables_flag) { decode_warn_actions ("undefined-var", NULL); warn_undefined_variables_flag = 0; } if (warn_flags) for (const char **pp = warn_flags->list; *pp; ++pp) decode_warn_actions (*pp, NULL); /* Perform any special switch handling. */ run_silent = silent_flag; /* Check variable priorities. */ reset_env_override (); } /* Decode switches from environment variable ENVAR (which is LEN chars long). We do this by chopping the value into a vector of words, prepending a dash to the first word if it lacks one, and passing the vector to decode_switches. */ static void decode_env_switches (const char *envar, size_t len, enum variable_origin origin) { char *value, *p, *buf; int argc; const char **argv; /* Get the variable's value. */ value = expand_variable (envar, len); /* Skip whitespace, and check for an empty value. */ NEXT_TOKEN (value); len = strlen (value); if (len == 0) return; /* Allocate an array that is definitely big enough. */ argv = xmalloc ((1 + len + 1) * sizeof (char *)); /* getopt will look at the arguments starting at ARGV[1]. Prepend a spacer word. */ argv[0] = ""; argc = 1; /* We need a buffer to copy the value into while we split it into words and unquote it. Set up in case we need to prepend a dash later. */ buf = xmalloc (1 + len + 1); buf[0] = '-'; p = buf+1; argv[argc] = p; while (*value != '\0') { if (*value == '\\' && value[1] != '\0') ++value; /* Skip the backslash. */ else if (ISBLANK (*value)) { /* End of the word. */ *p++ = '\0'; argv[++argc] = p; do ++value; while (ISBLANK (*value)); continue; } *p++ = *value++; } *p = '\0'; argv[++argc] = 0; assert (p < buf + len + 2); if (argv[1][0] != '-' && strchr (argv[1], '=') == 0) /* The first word doesn't start with a dash and isn't a variable definition, so add a dash. */ argv[1] = buf; /* Parse those words. */ decode_switches (argc, argv, origin); free (buf); free (argv); } /* Quote the string IN so that it will be interpreted as a single word with no magic by decode_env_switches; also double dollar signs to avoid variable expansion in make itself. Write the result into OUT, returning the address of the next character to be written. Allocating space for OUT twice the length of IN is always sufficient. */ static char * quote_for_env (char *out, const char *in) { while (*in != '\0') { if (*in == '$') *out++ = '$'; else if (ISBLANK (*in) || *in == '\\') *out++ = '\\'; *out++ = *in++; } return out; } /* Disable builtin variables and rules, if -R or -r is specified. This function is called at parse time whenever MAKEFLAGS is modified and also when the parsing phase is over. */ static void disable_builtins () { /* If -R was given, set -r too (doesn't make sense otherwise!) */ if (no_builtin_variables_flag) no_builtin_rules_flag = 1; /* If we've disabled builtin rules, get rid of them. */ if (no_builtin_rules_flag && ! old_builtin_rules_flag) { old_builtin_rules_flag = 1; if (suffix_file && suffix_file->builtin) { free_dep_chain (suffix_file->deps); suffix_file->deps = 0; } define_variable_cname ("SUFFIXES", "", o_default, 0); } /* If we've disabled builtin variables, get rid of them. */ if (no_builtin_variables_flag && ! old_builtin_variables_flag) { old_builtin_variables_flag = 1; undefine_default_variables (); } } /* Define the MAKEFLAGS and MFLAGS variables to reflect the settings of the command switches. Always include options with args. Don't include options with the 'no_makefile' flag set if MAKEFILE. */ struct variable * define_makeflags (int makefile) { const char ref[] = "MAKEOVERRIDES"; const char posixref[] = "-*-command-variables-*-"; const char evalref[] = " $(-*-eval-flags-*-)"; const struct command_switch *cs; struct variable *v; char *bufsave; size_t lensave; char *fp; char c[3]; install_variable_buffer (&bufsave, &lensave); /* Start with a dash, for MFLAGS. */ fp = variable_buffer_output (variable_buffer, "-", 1); #define SHORT_NOT_DEFAULT(_c) \ ((!*(int *) (_c)->value_ptr) == ((_c)->type == flag_off) \ && ((_c)->default_value == NULL || (_c)->specified \ || *(int *) (_c)->value_ptr != *(int *) (_c)->default_value)) /* Add simple options as a group. These can't have args by definion. */ for (cs = switches; cs->c != '\0'; ++cs) if (cs->toenv && short_option (cs->c) && (!makefile || !cs->no_makefile) && (cs->type == flag || cs->type == flag_off) && SHORT_NOT_DEFAULT (cs)) { c[0] = (char)cs->c; fp = variable_buffer_output (fp, c, 1); } memcpy (c, " --", 3); #define ADD_OPT(_c) \ do{ \ if (short_option (cs->c)) \ { \ c[2] = (char)cs->c; \ fp = variable_buffer_output (fp, c, 3); \ } \ else \ { \ c[2] = '-'; \ fp = variable_buffer_output (fp, c, 3); \ fp = variable_buffer_output (fp, cs->long_name, \ strlen (cs->long_name)); \ } \ }while(0) /* Now add more complex flags: ones with options and/or long names. */ for (cs = switches; cs->c != '\0'; ++cs) if (cs->toenv && (!makefile || !cs->no_makefile)) switch (cs->type) { case ignore: break; case flag: case flag_off: /* We did the short flags above. */ if (!short_option (cs->c) && SHORT_NOT_DEFAULT (cs)) ADD_OPT (cs); break; case positive_int: if ((cs->default_value != 0 && (*(unsigned int *) cs->value_ptr == *(unsigned int *) cs->default_value))) break; ADD_OPT (cs); if (!cs->noarg_value || (*(unsigned int *) cs->value_ptr != *(unsigned int *) cs->noarg_value)) { /* Add the value if not omitted. */ char *buf = alloca (30); sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); if (!short_option (cs->c)) fp = variable_buffer_output (fp, "=", 1); fp = variable_buffer_output (fp, buf, strlen (buf)); } break; case floating: if (cs->default_value != 0 && (*(double *) cs->value_ptr == *(double *) cs->default_value)) break; ADD_OPT (cs); if (!cs->noarg_value || (*(double *) cs->value_ptr != *(double *) cs->noarg_value)) { char *buf = alloca (100); sprintf (buf, "%g", *(double *) cs->value_ptr); if (!short_option (cs->c)) fp = variable_buffer_output (fp, "=", 1); fp = variable_buffer_output (fp, buf, strlen (buf)); } break; case string: { char *p = *((char **)cs->value_ptr); if (p) { ADD_OPT (cs); if (!short_option (cs->c)) fp = variable_buffer_output (fp, "=", 1); fp = variable_buffer_output(fp, p, strlen (p)); } } break; case filename: case strlist: if (cs->c == WARN_OPT) fp = encode_warn_flag (fp); else { struct stringlist *sl = *(struct stringlist **) cs->value_ptr; if (sl != 0) { unsigned int i; for (i = 0; i < sl->idx; ++i) { ADD_OPT (cs); if (!short_option (cs->c)) fp = variable_buffer_output (fp, "=", 1); fp = variable_buffer_output (fp, sl->list[i], strlen (sl->list[i])); } } } break; default: abort (); } #undef ADD_OPT #undef SHORT_NOT_DEFAULT /* If no flags at all, get rid of the initial dash. */ if (fp == variable_buffer + 1) fp = variable_buffer; *fp = '\0'; /* Define MFLAGS before appending variable definitions. Omit an initial empty dash. Since MFLAGS is not parsed for flags, there is no reason to override any makefile redefinition. */ define_variable_cname ("MFLAGS", variable_buffer + (variable_buffer[0] == '-' && variable_buffer[1] == ' ' ? 2 : 0), o_env, 1); /* Write a reference to -*-eval-flags-*-, which contains all the --eval flag options. */ if (eval_strings) fp = variable_buffer_output (fp, evalref, CSTRLEN (evalref)); { /* If there are any overrides to add, write a reference to $(MAKEOVERRIDES), which contains command-line variable definitions. Separate the variables from the switches with a "--" arg. */ const char *r = posix_pedantic ? posixref : ref; size_t l = strlen (r); v = lookup_variable (r, l); if (v && v->value && v->value[0] != '\0') { fp = variable_buffer_output (fp, " -- $(", 6); fp = variable_buffer_output (fp, r, l); fp = variable_buffer_output (fp, ")", 1); } } *fp = '\0'; /* If there is a leading dash, omit it. */ fp = variable_buffer; if (fp[0] == '-') ++fp; /* This used to use o_env, but that lost when a makefile defined MAKEFLAGS. Makefiles set MAKEFLAGS to add switches, but we still want to redefine its value with the full set of switches. Then we used o_file, but that lost when users added -e, causing a previous MAKEFLAGS env. var. to take precedence over the new one. Of course, an override or command definition will still take precedence. */ v = define_variable_cname (MAKEFLAGS_NAME, fp, env_overrides ? o_env_override : o_file, 1); v->special = 1; restore_variable_buffer (bufsave, lensave); return v; } /* Return 1 if the working directory change message should be printed. Otherwise, return 0. */ int should_print_dir (void) { if (print_directory_flag >= 0) return print_directory_flag; /* If the user didn't specify any print-directory options, compute the default setting: disable under -s / print in sub-makes and under -C. */ return !silent_flag && (makelevel > 0 || directories != NULL); } /* Print version information. */ static void print_version (void) { static int printed_version = 0; const char *precede = print_data_base_flag ? "# " : ""; if (printed_version) /* Do it only once. */ return; printf ("%sGNU Make %s\n", precede, version_string); if (!remote_description || *remote_description == '\0') printf (_("%sBuilt for %s\n"), precede, make_host); else printf (_("%sBuilt for %s (%s)\n"), precede, make_host, remote_description); #if MK_OS_W32 printf (_("%sANSI code page: %u\n"), precede, GetACP ()); printf (_("%sConsole code page: %u\n"), precede, GetConsoleOutputCP ()); #endif /* Print this untranslated. The coding standards recommend translating the (C) to the copyright symbol, but this string is going to change every year, and none of the rest of it should be translated (including the word "Copyright"), so it hardly seems worth it. */ printf ("%sCopyright (C) 1988-2024 Free Software Foundation, Inc.\n", precede); printf (_("%sLicense GPLv3+: GNU GPL version 3 or later \n\ %sThis is free software: you are free to change and redistribute it.\n\ %sThere is NO WARRANTY, to the extent permitted by law.\n"), precede, precede, precede); printed_version = 1; } /* Print a bunch of information about this and that. */ static void print_data_base (void) { int resolution; char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; file_timestamp_sprintf (buf, file_timestamp_now (&resolution)); print_version (); printf (_("\n# Make data base, printed on %s\n"), buf); print_variable_data_base (); print_dir_data_base (); print_rule_data_base (); print_file_data_base (); print_vpath_data_base (); strcache_print_stats ("#"); file_timestamp_sprintf (buf, file_timestamp_now (&resolution)); printf (_("\n# Finished Make data base on %s\n\n"), buf); } static void clean_jobserver (int status) { /* Sanity: have we written all our jobserver tokens back? If our exit status is 2 that means some kind of syntax error; we might not have written all our tokens so do that now. If tokens are left after any other error code, that's bad. */ if (jobserver_enabled() && jobserver_tokens) { if (status != 2) ON (error, NILF, "INTERNAL: exiting with %u jobserver tokens (should be 0)!", jobserver_tokens); else /* Don't write back the "free" token */ while (--jobserver_tokens) jobserver_release (0); } /* Sanity: If we're the master, were all the tokens written back? */ if (master_job_slots) { /* We didn't write one for ourself, so start at 1. */ unsigned int tokens = 1 + jobserver_acquire_all (); if (tokens != master_job_slots) ONN (error, NILF, "INTERNAL: exiting with %u jobserver tokens available; should be %u!", tokens, master_job_slots); reset_jobserver (); } } /* Exit with STATUS, cleaning up as necessary. */ void die (int status) { static char dying = 0; if (!dying) { int err; dying = 1; if (print_version_flag) print_version (); /* Get rid of a temp file from reading a makefile from stdin. */ temp_stdin_unlink (); /* Wait for children to die. */ err = (status != 0); while (job_slots_used > 0) reap_children (1, err); /* Let the remote job module clean up its state. */ remote_cleanup (); /* Remove the intermediate files. */ remove_intermediates (0); if (print_data_base_flag) print_data_base (); if (verify_flag) verify_file_data_base (); /* Unload plugins before jobserver integrity check in case a plugin participates in jobserver. */ unload_all (); clean_jobserver (status); if (output_context) { /* die() might be called in a recipe output context due to an $(error ...) function. */ output_close (output_context); if (output_context != &make_sync) output_close (&make_sync); OUTPUT_UNSET (); } output_close (NULL); osync_clear (); /* Try to move back to the original directory. This is essential on MS-DOS (where there is really only one process), and on Unix it puts core files in the original directory instead of the -C directory. Must wait until after remove_intermediates(), or unlinks of relative pathnames fail. */ if (directory_before_chdir != 0) { /* If it fails we don't care: shut up GCC. */ int _x UNUSED; _x = chdir (directory_before_chdir); } } exit (status); } ================================================ FILE: src/makeint.h ================================================ /* Miscellaneous global declarations and portability cruft for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* We use instead of "config.h" so that a compilation using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h (which it would do because makeint.h was found in $srcdir). */ #include /* Some versions of GCC (e.g., 10.x) set the warn_unused_result attribute on __builtin_alloca. This causes alloca(0) to fail and is not easily worked around so avoid it via the preprocessor. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98055 */ #if defined (__has_builtin) # if __has_builtin (__builtin_alloca) # define free_alloca() # else # define free_alloca() alloca (0) # endif #else # define free_alloca() alloca (0) #endif /* Disable assert() unless we're a maintainer. Some asserts are compute-intensive. */ #ifndef MAKE_MAINTAINER_MODE # define NDEBUG 1 #endif /* Include the externally-visible content. Be sure to use the local one, and not one installed on the system. Define GMK_BUILDING_MAKE for proper selection of dllexport/dllimport declarations for MS-Windows. */ #if MK_OS_W32 # define GMK_BUILDING_MAKE #endif #include "gnumake.h" #ifdef CRAY /* This must happen before #include so that the declaration therein is changed. */ # define signal bsdsignal #endif /* If we're compiling for the dmalloc debugger, turn off string inlining. */ #if defined(HAVE_DMALLOC_H) && defined(__GNUC__) # define __NO_STRING_INLINES #endif #include #include #include #include #include #if HAVE_SYS_TIME_H # include #endif #include #include #ifndef errno extern int errno; #endif /* Define macros specifying which OS we are building for. */ #if __gnu_hurd__ # define MK_OS_HURD 1 #endif #if __CYGWIN__ # define MK_OS_CYGWIN 1 #endif #if defined(__MVS__) # define MK_OS_ZOS 1 #endif #if defined(__EMX__) # define MK_OS_OS2 1 #endif #ifdef __VMS # define MK_OS_VMS 1 /* In strict ANSI mode, VMS compilers should not be defining the VMS macro. Define it here instead of a bulk edit for the correct code. */ # ifndef VMS # define VMS # endif #endif #ifdef HAVE_UNISTD_H # include /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get POSIX.1 behavior with 'cc -YPOSIX', which predefines POSIX itself! */ # if defined (_POSIX_VERSION) && !defined (ultrix) && !MK_OS_VMS # define POSIX 1 # endif #endif /* Some systems define _POSIX_VERSION but are not really POSIX.1. */ #if (defined (butterfly) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386))) # undef POSIX #endif #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE) # define POSIX 1 #endif #ifndef sigmask # define sigmask(sig) (1 << ((sig) - 1)) #endif #ifndef HAVE_SA_RESTART # define SA_RESTART 0 #endif #ifdef HAVE_VFORK_H # include #endif #ifdef HAVE_LIMITS_H # include #endif #ifdef HAVE_SYS_PARAM_H # include #endif #ifndef PATH_MAX # ifdef MAXPATHLEN # define PATH_MAX MAXPATHLEN # else /* Some systems (HURD) have fully dynamic pathnames with no maximum. Ideally we'd support this but it will take some work. */ # define PATH_MAX 4096 # endif #endif #ifdef PATH_MAX # define GET_PATH_MAX PATH_MAX # define PATH_VAR(var) char var[PATH_MAX+1] #else # define NEED_GET_PATH_MAX 1 # define GET_PATH_MAX (get_path_max ()) # define PATH_VAR(var) char *var = alloca (GET_PATH_MAX+1) unsigned int get_path_max (void); #endif #ifndef CHAR_BIT # define CHAR_BIT 8 #endif #ifndef USHRT_MAX # define USHRT_MAX 65535 #endif #ifndef SIZE_MAX # define SIZE_MAX ((size_t)~(size_t)0) #endif /* Nonzero if the integer type T is signed. Use <= to avoid GCC warnings about always-false expressions. */ #define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0) /* The minimum and maximum values for the integer type T. Use ~ (t) 0, not -1, for portability to 1's complement hosts. */ #define INTEGER_TYPE_MINIMUM(t) \ (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)) #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t)) #ifndef CHAR_MAX # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char) #endif #ifdef STAT_MACROS_BROKEN # ifdef S_ISREG # undef S_ISREG # endif # ifdef S_ISDIR # undef S_ISDIR # endif #endif /* STAT_MACROS_BROKEN. */ #ifndef S_ISREG # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) #endif #ifndef S_ISDIR # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #endif #if MK_OS_VMS # include # include # include # include # include /* Needed to use alloca on VMS. */ # include extern int vms_use_mcr_command; extern int vms_always_use_cmd_file; extern int vms_gnv_shell; extern int vms_comma_separator; extern int vms_legacy_behavior; extern int vms_unix_simulation; #endif #if !defined(__attribute__) && (__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) /* Don't use __attribute__ if it's not supported. */ # define ATTRIBUTE(x) #else # define ATTRIBUTE(x) __attribute__ (x) #endif /* The __-protected variants of 'format' and 'printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) # define __format__ format # define __printf__ printf #endif #define UNUSED ATTRIBUTE ((unused)) #define NORETURN ATTRIBUTE ((noreturn)) #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__) # include # include # define ANSI_STRING 1 #else /* No standard headers. */ # ifdef HAVE_STRING_H # include # define ANSI_STRING 1 # endif # ifdef HAVE_MEMORY_H # include # endif # ifdef HAVE_STDLIB_H # include # else void *malloc (int); void *realloc (void *, int); void free (void *); void abort (void) NORETURN; void exit (int) NORETURN; # endif /* HAVE_STDLIB_H. */ #endif /* Standard headers. */ /* These should be in stdlib.h. Make sure we have them. */ #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 #endif #ifndef EXIT_FAILURE # define EXIT_FAILURE 1 #endif #ifndef ANSI_STRING /* SCO Xenix has a buggy macro definition in . */ #undef strerror #if !defined(__DECC) char *strerror (int errnum); #endif #endif /* !ANSI_STRING. */ #undef ANSI_STRING #if HAVE_INTTYPES_H # include #endif #if HAVE_STDINT_H # include #endif #if HAVE_STRINGS_H # include /* Needed for strcasecmp / strncasecmp. */ #endif #if defined _MSC_VER || defined __MINGW32__ # define MK_PRI64_PREFIX "I64" #else # define MK_PRI64_PREFIX "ll" #endif #ifndef PRIdMAX # define PRIdMAX MK_PRI64_PREFIX "d" #endif #ifndef PRIuMAX # define PRIuMAX MK_PRI64_PREFIX "u" #endif #ifndef SCNdMAX # define SCNdMAX PRIdMAX #endif #define FILE_TIMESTAMP uintmax_t #if !defined(HAVE_STRSIGNAL) char *strsignal (int signum); #endif #if !defined(HAVE_UMASK) typedef int mode_t; extern mode_t umask (mode_t); #endif /* ISDIGIT offers the following features: - Its arg may be any int or unsigned int; it need not be an unsigned char. - It's guaranteed to evaluate its argument exactly once. NOTE! Make relies on this behavior, don't change it! - It's typically faster. POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless it's important to use the locale's definition of 'digit' even when the host does not conform to POSIX. */ #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) /* Test if two strings are equal. Is this worthwhile? Should be profiled. */ #define streq(a, b) \ ((a) == (b) || \ (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1)))) /* Test if two strings are equal, but match case-insensitively on systems which have case-insensitive filesystems. Should only be used for filenames! */ #ifdef HAVE_CASE_INSENSITIVE_FS # define patheq(a, b) \ ((a) == (b) \ || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \ && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1)))) #else # define patheq(a, b) streq(a, b) #endif #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0) #if defined(ENUM_BITFIELDS) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) # define ENUM_BITFIELD(bits) :bits #else # define ENUM_BITFIELD(bits) #endif /* Handle gettext and locales. */ #if HAVE_LOCALE_H # include #else # define setlocale(category, locale) #endif #include #define _(msgid) gettext (msgid) #define N_(msgid) gettext_noop (msgid) #define S_(msg1,msg2,num) ngettext (msg1,msg2,num) /* This is needed for getcwd() and chdir(), on some W32 systems. */ #if defined(HAVE_DIRECT_H) # include #endif #if MK_OS_W32 # include # include # define pipe(_p) _pipe((_p), 512, O_BINARY) # define kill(_pid,_sig) w32_kill((_pid),(_sig)) /* MSVC and Watcom C don't have ftruncate. */ # if defined(_MSC_VER) || defined(__WATCOMC__) # define ftruncate(_fd,_len) _chsize(_fd,_len) # endif /* MinGW64 doesn't have _S_ISDIR. */ # ifndef _S_ISDIR # define _S_ISDIR(m) S_ISDIR(m) # endif void sync_Path_environment (void); int w32_kill (pid_t pid, int sig); int find_and_set_default_shell (const char *token); /* indicates whether or not we have Bourne shell */ extern int no_default_sh_exe; /* is default_shell unixy? */ extern int unixy_shell; /* We don't have a preferred fixed value for LOCALEDIR. */ # ifndef LOCALEDIR # define LOCALEDIR NULL # endif /* Include only the minimal stuff from windows.h. */ # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif #endif /* MK_OS_W32 */ /* ALL_SET() evaluates the second argument twice. */ #define ANY_SET(_v,_m) (((_v)&(_m)) != 0) #define NONE_SET(_v,_m) (! ANY_SET ((_v),(_m))) #define ALL_SET(_v,_m) (((_v)&(_m)) == (_m)) /* Bitmasks for the STOPCHAR array. */ #define MAP_NUL 0x0001 #define MAP_BLANK 0x0002 /* space, TAB */ #define MAP_NEWLINE 0x0004 #define MAP_COMMENT 0x0008 #define MAP_SEMI 0x0010 #define MAP_EQUALS 0x0020 #define MAP_COLON 0x0040 #define MAP_VARSEP 0x0080 #define MAP_PIPE 0x0100 #define MAP_DOT 0x0200 #define MAP_COMMA 0x0400 /* These are the valid characters for a user-defined function. */ #define MAP_USERFUNC 0x2000 /* This means not only a '$', but skip the variable reference. */ #define MAP_VARIABLE 0x4000 /* The set of characters which are directory separators is OS-specific. */ #define MAP_DIRSEP 0x8000 #if MK_OS_VMS # define MAP_VMSCOMMA MAP_COMMA #else # define MAP_VMSCOMMA 0x0000 #endif #define MAP_SPACE (MAP_BLANK|MAP_NEWLINE) /* Handle other OSs. To overcome an issue parsing paths in a DOS/Windows environment when built in a unix based environment, override the PATH_SEPARATOR_CHAR definition unless being built for Cygwin. */ #if defined(HAVE_DOS_PATHS) && !defined(__CYGWIN__) # undef PATH_SEPARATOR_CHAR # define PATH_SEPARATOR_CHAR ';' # define MAP_PATHSEP MAP_SEMI #elif !defined(PATH_SEPARATOR_CHAR) # if MK_OS_VMS # define PATH_SEPARATOR_CHAR (vms_comma_separator ? ',' : ':') # define MAP_PATHSEP (vms_comma_separator ? MAP_COMMA : MAP_SEMI) # else # define PATH_SEPARATOR_CHAR ':' # define MAP_PATHSEP MAP_COLON # endif #elif PATH_SEPARATOR_CHAR == ':' # define MAP_PATHSEP MAP_COLON #elif PATH_SEPARATOR_CHAR == ';' # define MAP_PATHSEP MAP_SEMI #elif PATH_SEPARATOR_CHAR == ',' # define MAP_PATHSEP MAP_COMMA #else # error "Unknown PATH_SEPARATOR_CHAR" #endif #define STOP_SET(_v,_m) ANY_SET(stopchar_map[(unsigned char)(_v)],(_m)) /* True if C is whitespace but not newline. */ #define ISBLANK(c) STOP_SET((c),MAP_BLANK) /* True if C is whitespace including newlines. */ #define ISSPACE(c) STOP_SET((c),MAP_SPACE) /* True if C is nul or whitespace (including newline). */ #define END_OF_TOKEN(c) STOP_SET((c),MAP_SPACE|MAP_NUL) /* Move S past all whitespace (including newlines). */ #define NEXT_TOKEN(s) while (ISSPACE (*(s))) ++(s) /* True if C is a directory separator on the current system. */ #define ISDIRSEP(c) STOP_SET((c),MAP_DIRSEP) /* True if S starts with a drive specifier. */ #if defined(HAVE_DOS_PATHS) # define HAS_DRIVESPEC(_s) ((((_s)[0] >= 'a' && (_s)[0] <= 'z') \ || ((_s)[0] >= 'A' && (_s)[0] <= 'Z')) \ && (_s)[1] == ':') #else # define HAS_DRIVESPEC(_s) 0 #endif /* We can't run setrlimit when using posix_spawn. */ #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && !defined(USE_POSIX_SPAWN) # define SET_STACK_SIZE #endif #ifdef SET_STACK_SIZE # include extern struct rlimit stack_limit; #endif #include #define NILF ((floc *)0) /* Number of elements in an array. */ #define ARRAYLEN(_a) (sizeof (_a) / sizeof ((_a)[0])) /* Number of characters in a string constant. Does NOT include the \0 byte. */ #define CSTRLEN(_s) (sizeof (_s)-1) /* Only usable when NOT calling a macro: only use it for local functions. */ #define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s) /* The number of bytes needed to represent the largest signed and unsigned integers as a string. Does NOT include space for \0 so be sure to add it if needed. Math suggested by Edward Welbourne */ #define INTSTR_LENGTH (53 * sizeof(uintmax_t) / 22 + 3) #define DEFAULT_TTYNAME "true" #ifdef HAVE_TTYNAME # define TTYNAME(_f) ttyname (_f) #else # define TTYNAME(_f) DEFAULT_TTYNAME #endif #if MK_OS_VMS # define DEFAULT_TMPDIR "/sys$scratch/" #elif defined(P_tmpdir) # define DEFAULT_TMPDIR P_tmpdir #else # define DEFAULT_TMPDIR "/tmp" #endif struct file; /* Specify the location of elements read from makefiles. */ typedef struct { const char *filenm; unsigned long lineno; unsigned long offset; } floc; const char *concat (unsigned int, ...); void message (int prefix, size_t length, const char *fmt, ...) ATTRIBUTE ((__format__ (__printf__, 3, 4))); void error (const floc *flocp, size_t length, const char *fmt, ...) ATTRIBUTE ((__format__ (__printf__, 3, 4))); void fatal (const floc *flocp, size_t length, const char *fmt, ...) ATTRIBUTE ((noreturn, __format__ (__printf__, 3, 4))); char *format (const char *prefix, size_t length, const char *fmt, ...) ATTRIBUTE ((__format__ (__printf__, 3, 4))); void out_of_memory (void) NORETURN; /* When adding macros to this list be sure to update the value of XGETTEXT_OPTIONS in the po/Makevars file. */ #define O(_t,_a,_f) _t((_a), 0, (_f)) #define OS(_t,_a,_f,_s) _t((_a), strlen (_s), (_f), (_s)) #define OSS(_t,_a,_f,_s1,_s2) _t((_a), strlen (_s1) + strlen (_s2), \ (_f), (_s1), (_s2)) #define OSSS(_t,_a,_f,_s1,_s2,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3), \ (_f), (_s1), (_s2), (_s3)) #define ON(_t,_a,_f,_n) _t((_a), INTSTR_LENGTH, (_f), (_n)) #define ONN(_t,_a,_f,_n1,_n2) _t((_a), INTSTR_LENGTH*2, (_f), (_n1), (_n2)) #define OSN(_t,_a,_f,_s,_n) _t((_a), strlen (_s) + INTSTR_LENGTH, \ (_f), (_s), (_n)) #define ONS(_t,_a,_f,_n,_s) _t((_a), INTSTR_LENGTH + strlen (_s), \ (_f), (_n), (_s)) enum variable_origin; struct variable; void reset_makeflags (enum variable_origin origin); struct variable *define_makeflags (int makefile); int should_print_dir (void); void temp_stdin_unlink (void); void die (int) NORETURN; void pfatal_with_name (const char *) NORETURN; void perror_with_name (const char *, const char *); #define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s)) unsigned int make_toui (const char*, const char**); char *make_lltoa (long long, char *); char *make_ulltoa (unsigned long long, char *); void make_seed (unsigned int); unsigned int make_rand (void); pid_t make_pid (void); void *xmalloc (size_t); void *xcalloc (size_t); void *xrealloc (void *, size_t); char *xstrdup (const char *); char *xstrndup (const char *, size_t); char *find_next_token (const char **, size_t *); char *next_token (const char *); char *end_of_token (const char *); char *skip_reference (const char *); void collapse_continuations (char *); char *lindex (const char *, const char *, int); int alpha_compare (const void *, const void *); void print_spaces (unsigned int); char *find_percent (char *); const char *find_percent_cached (const char **); const char *get_tmpdir (void); int get_tmpfd (char **); FILE *get_tmpfile (char **); ssize_t writebuf (int, const void *, size_t); ssize_t readbuf (int, void *, size_t); #ifndef HAVE_MEMRCHR void *memrchr(const void *, int, size_t); #endif #ifndef NO_ARCHIVES int ar_name (const char *); void ar_parse_name (const char *, char **, char **); int ar_touch (const char *); time_t ar_member_date (const char *); typedef intmax_t (*ar_member_func_t) (int desc, const char *mem, int truncated, long int hdrpos, long int datapos, long int size, intmax_t date, int uid, int gid, unsigned int mode, const void *arg); intmax_t ar_scan (const char *archive, ar_member_func_t function, const void *arg); int ar_name_equal (const char *name, const char *mem, int truncated); #if !MK_OS_VMS int ar_member_touch (const char *arname, const char *memname); #endif #endif int dir_file_exists_p (const char *, const char *); int file_exists_p (const char *); int file_impossible_p (const char *); void file_impossible (const char *); const char *dir_name (const char *); void print_dir_data_base (void); void dir_setup_glob (glob_t *); void hash_init_directories (void); void define_default_variables (void); void undefine_default_variables (void); void set_default_suffixes (void); void install_default_suffix_rules (void); void install_default_implicit_rules (void); void build_vpath_lists (void); void construct_vpath_list (char *pattern, char *dirpath); const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr, unsigned int* vpath_index, unsigned int* path_index); int gpath_search (const char *file, size_t len); void construct_include_path (const char **arg_dirs); char *strip_whitespace (const char **begpp, const char **endpp); void show_goal_error (void); /* String caching */ void strcache_init (void); void strcache_print_stats (const char *prefix); int strcache_iscached (const char *str); const char *strcache_add (const char *str); const char *strcache_add_len (const char *str, size_t len); /* Guile support */ int guile_gmake_setup (const floc *flocp); /* Loadable object support. Sets to the strcached name of the loaded file. */ int load_file (const floc *flocp, struct file *file, int noerror); int unload_file (const char *name); void unload_all (void); /* Maintainer mode support */ #ifdef MAKE_MAINTAINER_MODE # define SPIN(_s) spin (_s) void spin (const char* suffix); # define DBG(_f) dbg _f void dbg (const char *fmt, ...); #else # define SPIN(_s) /* Never put this code into Git or a release. */ # define DBG(_f) compile-error #endif /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION, because such systems often declare them in header files anyway. */ #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !MK_OS_W32 # if !MK_OS_VMS long int lseek (); # endif # ifdef HAVE_GETCWD # if !MK_OS_VMS && !defined(__DECC) char *getcwd (void); # endif # else char *getwd (void); # define getcwd(buf, len) getwd (buf) # endif #endif /* Not GNU C library or POSIX. */ #if !HAVE_STRCASECMP # if HAVE_STRICMP # define strcasecmp stricmp # elif HAVE_STRCMPI # define strcasecmp strcmpi # endif #endif #if !HAVE_STRNCASECMP # if HAVE_STRNICMP # define strncasecmp strnicmp # elif HAVE_STRNCMPI # define strncasecmp strncmpi # endif #endif #define OUTPUT_SYNC_NONE 0 #define OUTPUT_SYNC_LINE 1 #define OUTPUT_SYNC_TARGET 2 #define OUTPUT_SYNC_RECURSE 3 /* Non-GNU systems may not declare this in unistd.h. */ extern char **environ; extern const floc *reading_file; extern const floc **expanding_var; extern unsigned short stopchar_map[]; extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag; extern int print_data_base_flag, question_flag, touch_flag, always_make_flag; extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag; extern int print_version_flag, check_symlink_flag, posix_pedantic; extern int not_parallel, second_expansion, clock_skew_detected; extern int rebuilding_makefiles, one_shell, output_sync, verify_flag; extern int export_all_variables; extern unsigned long command_count; extern const char *default_shell; /* can we run commands via 'sh -c xxx' or must we use batch files? */ extern int batch_mode_shell; #define GNUMAKEFLAGS_NAME "GNUMAKEFLAGS" #define MAKEFLAGS_NAME "MAKEFLAGS" #define MAKELEVEL_NAME "MAKELEVEL" #define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME)) /* Resetting the command script introduction prefix character. */ #define RECIPEPREFIX_NAME ".RECIPEPREFIX" #define RECIPEPREFIX_DEFAULT '\t' extern char cmd_prefix; /* Setting warning actions. */ #define WARNINGS_NAME ".WARNINGS" extern unsigned int no_intermediates; #if HAVE_MKFIFO /* It seems that mkfifo() is not working correctly, or at least not the way GNU make wants it to work, on: GNU/Hurd, Cygwin, OS2; don't use it there. */ # if !defined(JOBSERVER_USE_FIFO) && !MK_OS_HURD && !MK_OS_CYGWIN && !MK_OS_OS2 # define JOBSERVER_USE_FIFO 1 # endif #endif #define JOBSERVER_AUTH_OPT "jobserver-auth" extern char *jobserver_auth; extern unsigned int job_slots; extern double max_load_average; extern const char *program; #if MK_OS_VMS const char *vms_command (const char *argv0); const char *vms_progname (const char *argv0); void vms_exit (int); # define _exit(foo) vms_exit(foo) # define exit(foo) vms_exit(foo) extern char *program_name; void set_program_name (const char *arv0); int need_vms_symbol (void); int create_foreign_command (const char *command, const char *image); int vms_export_dcl_symbol (const char *name, const char *value); int vms_putenv_symbol (const char *string); void vms_restore_symbol (const char *string); #endif void remote_setup (void); void remote_cleanup (void); int start_remote_job_p (int); int start_remote_job (char **, char **, int, int *, pid_t *, int *); int remote_status (int *, int *, int *, int); void block_remote_children (void); void unblock_remote_children (void); int remote_kill (pid_t id, int sig); void print_variable_data_base (void); void print_vpath_data_base (void); extern char *starting_directory; extern unsigned int makelevel; extern char *version_string, *remote_description, *make_host; extern unsigned int commands_started; extern volatile sig_atomic_t handling_fatal_signal; #ifndef MIN #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) #endif #ifndef MAX #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b)) #endif #define MAKE_SUCCESS 0 #define MAKE_TROUBLE 1 #define MAKE_FAILURE 2 /* Set up heap debugging library dmalloc. */ #ifdef HAVE_DMALLOC_H #include #endif #ifndef initialize_main # if MK_OS_OS2 # define initialize_main(pargc, pargv) \ { _wildcard(pargc, pargv); _response(pargc, pargv); } # else # define initialize_main(pargc, pargv) # endif #endif #if MK_OS_OS2 # if !defined chdir # define chdir _chdir2 # endif # if !defined getcwd # define getcwd _getcwd2 # endif /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of chdir() and getcwd(). This avoids some error messages for the make testsuite but restricts the drive letter support. */ # ifdef NO_CHDIR2 # warning NO_CHDIR2: usage of drive letters restricted # undef chdir # undef getcwd # endif #endif #ifndef initialize_main # define initialize_main(pargc, pargv) #endif /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag properly according to POSIX. So, we try to wrap common system calls with checks for EINTR. Note that there are still plenty of system calls that can fail with EINTR but this, reportedly, gets the vast majority of failure cases. If you still experience failures you'll need to either get a system where SA_RESTART works, or you need to avoid -j. */ #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR) /* While system calls that return integers are pretty consistent about returning -1 on failure and setting errno in that case, functions that return pointers are not always so well behaved. Sometimes they return NULL for expected behavior: one good example is readdir() which returns NULL at the end of the directory--and _doesn't_ reset errno. So, we have to do it ourselves here. */ #define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \ while((_v)==0 && errno==EINTR) ================================================ FILE: src/misc.c ================================================ /* Miscellaneous generic support functions for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "dep.h" #include "os.h" #include "debug.h" #include #include #if MK_OS_W32 # include # include #endif #if MK_OS_OS2 # define INCL_DOS # include #endif #ifdef HAVE_FCNTL_H # include #else # include #endif unsigned int make_toui (const char *str, const char **error) { char *end; unsigned long val = strtoul (str, &end, 10); if (error) { if (str[0] == '\0') *error = "Missing value"; else if (*end != '\0') *error = "Invalid value"; else *error = NULL; } return val; } /* Convert val into a string, written to buf. buf must be large enough to hold the largest possible value, plus a nul byte. Returns buf. We can't use standard PRI* here: those are based on intNN_t types. */ char * make_lltoa (long long val, char *buf) { sprintf (buf, "%" MK_PRI64_PREFIX "d", val); return buf; } char * make_ulltoa (unsigned long long val, char *buf) { sprintf (buf, "%" MK_PRI64_PREFIX "u", val); return buf; } /* Simple random number generator, for use with shuffle. This doesn't need to be truly random, just pretty random. Use our own implementation rather than relying on the C runtime's rand() so we always get the same results for a given seed, regardless of C runtime. */ static unsigned int mk_state = 0; void make_seed (unsigned int seed) { mk_state = seed; } unsigned int make_rand () { /* mk_state must never be 0. */ if (mk_state == 0) mk_state = (unsigned int)(time (NULL) ^ make_pid ()) + 1; /* A simple xorshift RNG. */ mk_state ^= mk_state << 13; mk_state ^= mk_state >> 17; mk_state ^= mk_state << 5; return mk_state; } /* Compare strings *S1 and *S2. Return negative if the first is less, positive if it is greater, zero if they are equal. */ int alpha_compare (const void *v1, const void *v2) { const char *s1 = *((char **)v1); const char *s2 = *((char **)v2); if (*s1 != *s2) return *s1 - *s2; return strcmp (s1, s2); } /* Discard each backslash-newline combination from LINE. Backslash-backslash-newline combinations become backslash-newlines. This is done by copying the text at LINE into itself. */ void collapse_continuations (char *line) { char *out = line; char *in = line; char *q; q = strchr(in, '\n'); if (!q) return; do { char *p = q; int i; size_t out_line_length; if (q > line && q[-1] == '\\') { /* Search for more backslashes. */ i = -2; while (&p[i] >= line && p[i] == '\\') --i; ++i; } else i = 0; /* The number of backslashes is now -I, keep half of them. */ out_line_length = (p - in) + i - i/2; if (out != in) memmove (out, in, out_line_length); out += out_line_length; /* When advancing IN, skip the newline too. */ in = q + 1; if (i & 1) { unsigned int dollar; /* Backslash/newline handling: out points to the final "\". In POSIX, each backslash/newline is replaced by a space. In GNU Make all trailing whitespace, consecutive backslash + newlines, and any leading non-newline whitespace on the next line is reduced to a single space. As a special case, replace "$\" with the empty string. */ while (ISBLANK (*in)) ++in; { const char *dp = out; while (dp > line && dp[-1] == '$') --dp; dollar = (out - dp) % 2; } if (dollar) --out; if (!posix_pedantic) while (out > line && ISBLANK (out[-1])) --out; if (!dollar) *out++ = ' '; } else { /* If the newline isn't quoted, put it in the output. */ *out++ = '\n'; } q = strchr(in, '\n'); } while (q); memmove(out, in, strlen(in) + 1); } /* Print N spaces (used in debug for target-depth). */ void print_spaces (unsigned int n) { while (n-- > 0) putchar (' '); } /* Return a string whose contents concatenate the NUM strings provided This string lives in static, re-used memory. */ const char * concat (unsigned int num, ...) { static size_t rlen = 0; static char *result = NULL; size_t ri = 0; va_list args; va_start (args, num); while (num-- > 0) { const char *s = va_arg (args, const char *); size_t l = xstrlen (s); if (l == 0) continue; if (ri + l > rlen) { rlen = ((rlen ? rlen : 60) + l) * 2; result = xrealloc (result, rlen); } memcpy (result + ri, s, l); ri += l; } va_end (args); /* Get some more memory if we don't have enough space for the terminating '\0'. */ if (ri == rlen) { rlen = (rlen ? rlen : 60) * 2; result = xrealloc (result, rlen); } result[ri] = '\0'; return result; } #ifndef HAVE_UNISTD_H pid_t getpid (); #endif pid_t make_pid () { return getpid (); } /* Like malloc but get fatal error if memory is exhausted. */ /* Don't bother if we're using dmalloc; it provides these for us. */ #ifndef HAVE_DMALLOC_H #undef xmalloc #undef xcalloc #undef xrealloc #undef xstrdup void * xmalloc (size_t size) { /* Make sure we don't allocate 0, for pre-ISO implementations. */ void *result = malloc (size ? size : 1); if (result == 0) out_of_memory (); return result; } void * xcalloc (size_t size) { /* Make sure we don't allocate 0, for pre-ISO implementations. */ void *result = calloc (size ? size : 1, 1); if (result == 0) out_of_memory (); return result; } void * xrealloc (void *ptr, size_t size) { void *result; /* Some older implementations of realloc() don't conform to ISO. */ if (! size) size = 1; result = ptr ? realloc (ptr, size) : malloc (size); if (result == 0) out_of_memory (); return result; } char * xstrdup (const char *ptr) { char *result; #ifdef HAVE_STRDUP result = strdup (ptr); #else result = malloc (strlen (ptr) + 1); #endif if (result == 0) out_of_memory (); #ifdef HAVE_STRDUP return result; #else return strcpy (result, ptr); #endif } #endif /* HAVE_DMALLOC_H */ char * xstrndup (const char *str, size_t length) { char *result; #ifdef HAVE_STRNDUP result = strndup (str, length); if (result == 0) out_of_memory (); #else result = xmalloc (length + 1); if (length > 0) strncpy (result, str, length); result[length] = '\0'; #endif return result; } #ifndef HAVE_MEMRCHR void * memrchr(const void* str, int ch, size_t len) { const char* sp = str; const char* cp = sp; if (len == 0) return NULL; cp += len - 1; while (cp[0] != ch) { if (cp == sp) return NULL; --cp; } return (void*)cp; } #endif /* Limited INDEX: Search through the string STRING, which ends at LIMIT, for the character C. Returns a pointer to the first occurrence, or nil if none is found. Like INDEX except that the string searched ends where specified instead of at the first null. */ char * lindex (const char *s, const char *limit, int c) { while (s < limit) if (*s++ == c) return (char *)(s - 1); return 0; } /* Return the address of the first whitespace or null in the string S. */ char * end_of_token (const char *s) { while (! END_OF_TOKEN (*s)) ++s; return (char *)s; } /* Return the address of the first nonwhitespace or null in the string S. */ char * next_token (const char *s) { NEXT_TOKEN (s); return (char *)s; } /* This function returns P if P points to EOS, or P+1 if P is NOT an open paren or brace, or a pointer to the character after the matching close paren or brace, skipping matched internal parens or braces. It is typically called when we have seen a '$' in a string and we want to treat it as a variable reference and find the end of it: in that case P should point to the character after the '$'. */ char * skip_reference (const char *p) { char openparen = *p; char closeparen; int count = 1; if (openparen == '\0') return (char*)p; if (openparen == '(') closeparen = ')'; else if (openparen == '{') closeparen = '}'; else return (char*)(p+1); while (1) { ++p; if (!STOP_SET (*p, MAP_NUL|MAP_VARSEP)) continue; if (*p == '\0') break; if (*p == openparen) ++count; else if (*p == closeparen && --count == 0) { ++p; break; } } return (char*)p; } /* Find the next token in PTR; return the address of it, and store the length of the token into *LENGTHPTR if LENGTHPTR is not nil. Set *PTR to the end of the token, so this function can be called repeatedly in a loop. */ char * find_next_token (const char **ptr, size_t *lengthptr) { const char *p = next_token (*ptr); if (*p == '\0') return 0; *ptr = end_of_token (p); if (lengthptr != 0) *lengthptr = *ptr - p; return (char *)p; } /* Write a BUFFER of size LEN to file descriptor FD. Retry short writes from EINTR. Return LEN, or -1 on error. */ ssize_t writebuf (int fd, const void *buffer, size_t len) { const char *msg = buffer; size_t l = len; while (l) { ssize_t r; EINTRLOOP (r, write (fd, msg, l)); if (r < 0) return -1; l -= r; msg += r; } return (ssize_t)len; } /* Read until we get LEN bytes from file descriptor FD, into BUFFER. Retry short reads on EINTR. Return 0 at EOF and -1 on error. */ ssize_t readbuf (int fd, void *buffer, size_t len) { char *msg = buffer; while (len) { ssize_t r; EINTRLOOP (r, read (fd, msg, len)); if (r < 0) return -1; if (r == 0) break; len -= r; msg += r; } return (ssize_t)(msg - (char*)buffer); } /* Copy a 'struct dep'. For 2nd expansion deps, dup the name. */ struct dep * copy_dep (const struct dep *d) { struct dep *new = NULL; if (d) { new = xmalloc (sizeof (struct dep)); memcpy (new, d, sizeof (struct dep)); if (new->need_2nd_expansion) new->name = xstrdup (new->name); new->next = 0; } return new; } /* Copy a chain of 'struct dep'. For 2nd expansion deps, dup the name. */ struct dep * copy_dep_chain (const struct dep *d) { struct dep *firstnew = NULL; struct dep *lastnew = NULL; while (d != 0) { struct dep *c = copy_dep (d); if (firstnew == 0) firstnew = lastnew = c; else lastnew = lastnew->next = c; d = d->next; } return firstnew; } /* Free a chain of struct nameseq. For struct dep chains use free_dep_chain. */ void free_ns_chain (struct nameseq *ns) { while (ns != NULL) { struct nameseq *t = ns; ns = ns->next; free_ns (t); } } #ifdef MAKE_MAINTAINER_MODE void spin (const char* type) { char filenm[256]; struct stat dummy; sprintf (filenm, ".make-spin-%s", type); if (stat (filenm, &dummy) == 0) { fprintf (stderr, "SPIN on %s\n", filenm); do #if MK_OS_W32 Sleep (1000); #else sleep (1); #endif while (stat (filenm, &dummy) == 0); } } void dbg (const char *fmt, ...) { FILE *fp = fopen ("/tmp/gmkdebug.log", "a+"); va_list args; char buf[4096]; va_start (args, fmt); vsprintf (buf, fmt, args); va_end (args); fprintf(fp, "%u: %s\n", (unsigned) make_pid (), buf); fflush (fp); fclose (fp); } #endif /* Provide support for temporary files. */ #ifndef HAVE_STDLIB_H # ifdef HAVE_MKSTEMP int mkstemp (char *template); # else char *mktemp (char *template); # endif #endif #ifndef HAVE_UMASK mode_t umask (mode_t mask) { return 0; } #endif #if MK_OS_VMS # define DEFAULT_TMPFILE "sys$scratch:gnv$make_cmdXXXXXX.com" #else # define DEFAULT_TMPFILE "GmXXXXXX" #endif const char * get_tmpdir () { static const char *tmpdir = NULL; if (!tmpdir) { #if MK_OS_DOS || MK_OS_W32 || MK_OS_OS2 # define TMP_EXTRAS "TMP", "TEMP", #else # define TMP_EXTRAS #endif const char *tlist[] = { "MAKE_TMPDIR", "TMPDIR", TMP_EXTRAS NULL }; const char **tp; unsigned int found = 0; for (tp = tlist; *tp; ++tp) if ((tmpdir = getenv (*tp)) != NULL && *tmpdir != '\0') { struct stat st; int r; found = 1; EINTRLOOP(r, stat (tmpdir, &st)); if (r < 0) OSSS (error, NILF, _("%s value %s: %s"), *tp, tmpdir, strerror (errno)); else if (! S_ISDIR (st.st_mode)) OSS (error, NILF, _("%s value %s: not a directory"), *tp, tmpdir); else return tmpdir; } tmpdir = DEFAULT_TMPDIR; if (found) OS (error, NILF, _("using default temporary directory '%s'"), tmpdir); } return tmpdir; } static char * get_tmptemplate () { const char *tmpdir = get_tmpdir (); char *template; char *cp; template = xmalloc (strlen (tmpdir) + CSTRLEN (DEFAULT_TMPFILE) + 2); cp = stpcpy (template, tmpdir); #if !MK_OS_VMS /* It's not possible for tmpdir to be empty. */ if (! ISDIRSEP (cp[-1])) *(cp++) = '/'; #endif strcpy (cp, DEFAULT_TMPFILE); return template; } #if !HAVE_MKSTEMP || !HAVE_FDOPEN /* Generate a temporary filename. This is not safe as another program could snipe our filename after we've generated it: use this only on systems without more secure alternatives. */ static char * get_tmppath () { char *path; # ifdef HAVE_MKTEMP path = get_tmptemplate (); if (*mktemp (path) == '\0') { OSS (error, NILF, _("cannot generate temp path from %s: %s"), path, strerror (errno)); return NULL; } # else path = xmalloc (L_tmpnam + 1); if (tmpnam (path) == NULL) { OS (error, NILF, _("cannot generate temp name: %s"), strerror (errno)); return NULL; } # endif return path; } #endif /* Generate a temporary file and return an fd for it. If name is NULL then the temp file is anonymous and will be deleted when the process exits. If name is not null then *name will point to an allocated buffer, or set to NULL on failure. */ int get_tmpfd (char **name) { int fd = -1; char *tmpnm; mode_t mask; if (name) *name = NULL; else { /* If there's an os-specific way to get an anonymous temp file use it. */ fd = os_anontmp (); if (fd >= 0) return fd; } /* Preserve the current umask, and set a restrictive one for temp files. Only really needed for mkstemp() but won't hurt for the open method. */ mask = umask (0077); #if defined(HAVE_MKSTEMP) tmpnm = get_tmptemplate (); /* It's safest to use mkstemp(), if we can. */ EINTRLOOP (fd, mkstemp (tmpnm)); #else tmpnm = get_tmppath (); if (!tmpnm) return -1; /* Can't use mkstemp(), but try to guard against a race condition. */ EINTRLOOP (fd, open (tmpnm, O_CREAT|O_EXCL|O_RDWR, 0600)); #endif if (fd < 0) { OSS (error, NILF, _("cannot create temporary file %s: %s"), tmpnm, strerror (errno)); free (tmpnm); return -1; } if (name) *name = tmpnm; else { int r; EINTRLOOP (r, unlink (tmpnm)); if (r < 0) OSS (error, NILF, _("cannot unlink temporary file %s: %s"), tmpnm, strerror (errno)); free (tmpnm); } umask (mask); return fd; } /* Return a FILE* for a temporary file, opened in the safest way possible. Set name to point to an allocated buffer containing the name of the file, or NULL on failure. Note, name cannot be NULL! */ FILE * get_tmpfile (char **name) { /* Be consistent with tmpfile, which opens as if by "wb+". */ const char *tmpfile_mode = "wb+"; FILE *file; #if defined(HAVE_FDOPEN) int fd; assert (name); fd = get_tmpfd (name); if (fd < 0) return NULL; assert (*name); ENULLLOOP (file, fdopen (fd, tmpfile_mode)); if (file == NULL) OSS (error, NILF, _("fdopen: temporary file %s: %s"), *name, strerror (errno)); #else /* Preserve the current umask, and set a restrictive one for temp files. */ mode_t mask = umask (0077); assert (name); *name = get_tmppath (); if (!*name) return NULL; /* Although this fopen is insecure, it is executed only on non-fdopen platforms, which should be a rarity nowadays. */ ENULLLOOP (file, fopen (*name, tmpfile_mode)); if (file == NULL) { OSS (error, NILF, _("fopen: temporary file %s: %s"), *name, strerror (errno)); free (*name); *name = NULL; } umask (mask); #endif return file; } #if HAVE_TTYNAME && MK_OS_OS2 /* OS/2 kLIBC has a declaration for ttyname(), so configure finds it. But, it is not implemented! Roll our own. */ char *ttyname (int fd) { ULONG type; ULONG attr; ULONG rc; rc = DosQueryHType (fd, &type, &attr); if (rc) { errno = EBADF; return NULL; } if (type == HANDTYPE_DEVICE) { if (attr & 3) /* 1 = KBD$, 2 = SCREEN$ */ return (char *) "/dev/con"; if (attr & 4) /* 4 = NUL */ return (char *) "/dev/nul"; if (attr & 8) /* 8 = CLOCK$ */ return (char *) "/dev/clock$"; } errno = ENOTTY; return NULL; } #endif #if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI /* If we don't have strcasecmp() (from POSIX), or anything that can substitute for it, define our own version. */ int strcasecmp (const char *s1, const char *s2) { while (1) { int c1 = (unsigned char) *(s1++); int c2 = (unsigned char) *(s2++); if (isalpha (c1)) c1 = tolower (c1); if (isalpha (c2)) c2 = tolower (c2); if (c1 != '\0' && c1 == c2) continue; return (c1 - c2); } } #endif #if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI /* If we don't have strncasecmp() (from POSIX), or anything that can substitute for it, define our own version. */ int strncasecmp (const char *s1, const char *s2, size_t n) { while (n-- > 0) { int c1 = (unsigned char) *(s1++); int c2 = (unsigned char) *(s2++); if (isalpha (c1)) c1 = tolower (c1); if (isalpha (c2)) c2 = tolower (c2); if (c1 != '\0' && c1 == c2) continue; return (c1 - c2); } return 0; } #endif #ifdef NEED_GET_PATH_MAX unsigned int get_path_max (void) { static unsigned int value; if (value == 0) { long x = pathconf ("/", _PC_PATH_MAX); if (x > 0) value = (unsigned int) x; else value = PATH_MAX; } return value; } #endif #if !HAVE_MEMPCPY void * mempcpy (void *dest, const void *src, size_t n) { return (char *) memcpy (dest, src, n) + n; } #endif #if !HAVE_STPCPY char * stpcpy (char *dest, const char *src) { char *d = dest; const char *s = src; do *d++ = *s; while (*s++ != '\0'); return d - 1; } #endif #if !HAVE_STRTOLL # undef UNSIGNED # undef USE_NUMBER_GROUPING # undef USE_WIDE_CHAR # define QUAD 1 # include #endif #if !HAVE_STRERROR char * strerror (int errnum) { static char msg[256]; #define SETMSG(_e, _m) case _e: strcpy(msg, _m); break switch (errnum) { #ifdef EPERM SETMSG (EPERM , "Operation not permitted"); #endif #ifdef ENOENT SETMSG (ENOENT , "No such file or directory"); #endif #ifdef ESRCH SETMSG (ESRCH , "No such process"); #endif #ifdef EINTR SETMSG (EINTR , "Interrupted system call"); #endif #ifdef EIO SETMSG (EIO , "I/O error"); #endif #ifdef ENXIO SETMSG (ENXIO , "No such device or address"); #endif #ifdef E2BIG SETMSG (E2BIG , "Argument list too long"); #endif #ifdef ENOEXEC SETMSG (ENOEXEC, "Exec format error"); #endif #ifdef EBADF SETMSG (EBADF , "Bad file number"); #endif #ifdef ECHILD SETMSG (ECHILD , "No child processes"); #endif #ifdef EAGAIN SETMSG (EAGAIN , "Try again"); #endif #ifdef ENOMEM SETMSG (ENOMEM , "Out of memory"); #endif #ifdef EACCES SETMSG (EACCES , "Permission denied"); #endif #ifdef EFAULT SETMSG (EFAULT , "Bad address"); #endif #ifdef ENOTBLK SETMSG (ENOTBLK, "Block device required"); #endif #ifdef EBUSY SETMSG (EBUSY , "Device or resource busy"); #endif #ifdef EEXIST SETMSG (EEXIST , "File exists"); #endif #ifdef EXDEV SETMSG (EXDEV , "Cross-device link"); #endif #ifdef ENODEV SETMSG (ENODEV , "No such device"); #endif #ifdef ENOTDIR SETMSG (ENOTDIR, "Not a directory"); #endif #ifdef EISDIR SETMSG (EISDIR , "Is a directory"); #endif #ifdef EINVAL SETMSG (EINVAL , "Invalid argument"); #endif #ifdef ENFILE SETMSG (ENFILE , "File table overflow"); #endif #ifdef EMFILE SETMSG (EMFILE , "Too many open files"); #endif #ifdef ENOTTY SETMSG (ENOTTY , "Not a typewriter"); #endif #ifdef ETXTBSY SETMSG (ETXTBSY, "Text file busy"); #endif #ifdef EFBIG SETMSG (EFBIG , "File too large"); #endif #ifdef ENOSPC SETMSG (ENOSPC , "No space left on device"); #endif #ifdef ESPIPE SETMSG (ESPIPE , "Illegal seek"); #endif #ifdef EROFS SETMSG (EROFS , "Read-only file system"); #endif #ifdef EMLINK SETMSG (EMLINK , "Too many links"); #endif #ifdef EPIPE SETMSG (EPIPE , "Broken pipe"); #endif #ifdef EDOM SETMSG (EDOM , "Math argument out of domain of func"); #endif #ifdef ERANGE SETMSG (ERANGE , "Math result not representable"); #endif default: sprintf (msg, "Unknown error %d", errnum); break; } return msg; } #endif ================================================ FILE: src/mkconfig.h.in ================================================ /* Autoconf values for use on non-POSIX systems. Copyright (C) 2022-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Name of package */ #define PACKAGE "@PACKAGE@" /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" /* Define to the full name of this package. */ #define PACKAGE_NAME "@PACKAGE_NAME@" /* Define to the full name and version of this package. */ #define PACKAGE_STRING "@PACKAGE_NAME@ @PACKAGE_VERSION@" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "@PACKAGE_TARNAME@" /* Define to the home page for this package. */ #define PACKAGE_URL "@PACKAGE_URL@" /* Define to the version of this package. */ #define PACKAGE_VERSION "@PACKAGE_VERSION@" ================================================ FILE: src/mkcustom.h ================================================ /* Miscellaneous global declarations and portability cruft for GNU Make. Copyright (C) 2023-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* This file is included at the end of config.h That means it's included _everywhere_ as the first thing, INCLUDING content imported from gnulib. BE AWARE!! */ #undef HAVE_CONFIG_H #define HAVE_CONFIG_H 1 /* Specify we want GNU source code. This must be defined before any system headers are included. */ #define _GNU_SOURCE 1 /* AIX requires this to be the first thing in the file. */ #if HAVE_ALLOCA_H # include #else # ifdef _AIX #pragma alloca # else # if !defined(__GNUC__) && !MK_OS_W32 # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif #endif /* Declare function prototypes for src/misc.c functions if needed. */ #include #if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI int strcasecmp (const char *s1, const char *s2); #endif #if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI int strncasecmp (const char *s1, const char *s2, size_t n); #endif #if !HAVE_MEMPCPY void *mempcpy (void *dest, const void *src, size_t n); #endif #if !HAVE_STPCPY char *stpcpy (char *dest, const char *src); #endif ================================================ FILE: src/os.h ================================================ /* Declarations for operating system interfaces for GNU Make. Copyright (C) 2016-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define IO_UNKNOWN 0x0001 #define IO_COMBINED_OUTERR 0x0002 #define IO_STDIN_OK 0x0004 #define IO_STDOUT_OK 0x0008 #define IO_STDERR_OK 0x0010 #if MK_OS_VMS || MK_OS_DOS # define check_io_state() (IO_STDIN_OK|IO_STDOUT_OK|IO_STDERR_OK) # define fd_inherit(_i) (0) # define fd_noinherit(_i) (0) # define fd_set_append(_i) (-1) # define fd_reset_append(_i,_f) (void)(0) # define os_anontmp() (-1) #else /* Determine the state of stdin/stdout/stderr. */ unsigned int check_io_state (void); /* Set a file descriptor to close/not close in a subprocess. */ void fd_inherit (int fd); void fd_noinherit (int fd); /* If the file descriptor is for a file put it into append mode. Return the original flags for the file descriptor, or -1 if not found. */ int fd_set_append (int fd); /* Reset the append mode to the flags returned by fd_set_append(). */ void fd_reset_append (int fd, int flags); /* Return a file descriptor for a new anonymous temp file, or -1. */ int os_anontmp (void); #endif /* This section provides OS-specific functions to support the jobserver. */ #ifdef MAKE_JOBSERVER /* Returns 1 if the jobserver is enabled, else 0. */ unsigned int jobserver_enabled (void); /* Called in the parent make to set up the jobserver initially. */ unsigned int jobserver_setup (int job_slots, const char *style); /* Called in a child instance to connect to the jobserver. Return 1 if we got a valid auth, else 0. */ unsigned int jobserver_parse_auth (const char* auth); /* Returns an allocated buffer used to pass to child instances. */ char *jobserver_get_auth (void); /* Returns a pointer to a static string used to indicate that the child cannot access the jobserver, or NULL if it always can. */ const char *jobserver_get_invalid_auth (void); /* Clear this instance's jobserver configuration. This method might be invoked from a signal handler. */ void jobserver_clear (void); /* Recover all the jobserver tokens and return the number we got. Will also run jobserver_clear() as a side-effect. */ unsigned int jobserver_acquire_all (void); /* Release a jobserver token. If it fails and is_fatal is 1, fatal. */ void jobserver_release (int is_fatal); /* Notify the jobserver that a child exited. */ void jobserver_signal (void); /* Get ready to start a non-recursive child. */ void jobserver_pre_child (int); /* Complete starting a non-recursive child. */ void jobserver_post_child (int); /* Set up to acquire a new token. */ void jobserver_pre_acquire (void); /* Wait until we can acquire a jobserver token. TIMEOUT is 1 if we have other jobs waiting for the load to go down; in this case we won't wait forever, so we can check the load. Returns 1 if we got a token, or 0 if we stopped waiting due to a child exiting or a timeout. */ unsigned int jobserver_acquire (int timeout); #else #define jobserver_enabled() (0) #define jobserver_setup(_slots, _style) (0) #define jobserver_parse_auth(_auth) (0) #define jobserver_get_auth() (NULL) #define jobserver_get_invalid_auth() (NULL) #define jobserver_clear() (void)(0) #define jobserver_release(_fatal) (void)(0) #define jobserver_acquire_all() (0) #define jobserver_signal() (void)(0) #define jobserver_pre_child(_r) (void)(0) #define jobserver_post_child(_r) (void)(0) #define jobserver_pre_acquire() (void)(0) #define jobserver_acquire(_tmout) (0) #endif /* MAKE_JOBSERVER */ #ifndef NO_OUTPUT_SYNC /* Returns 1 if output sync is enabled, else 0. */ unsigned int osync_enabled (void); /* Called in the parent make to set up output sync initially. */ void osync_setup (void); /* Returns an allocated buffer containing output sync info to pass to child instances, or NULL if not needed. */ char *osync_get_mutex (void); /* Called in a child instance to obtain info on the output sync mutex. Return 1 if we got a valid mutex, else 0. */ unsigned int osync_parse_mutex (const char *mutex); /* Clean up this instance's output sync facilities. This method might be invoked from a signal handler. */ void osync_clear (void); /* Acquire the output sync lock. This will wait until available. Returns 0 if there was an error getting the semaphore. */ unsigned int osync_acquire (void); /* Release the output sync lock. */ void osync_release (void); #else #define osync_enabled() (0) #define osync_setup() (void)(0) #define osync_get_mutex() (0) #define osync_parse_mutex(_s) (0) #define osync_clear() (void)(0) #define osync_acquire() (1) #define osync_release() (void)(0) #endif /* NO_OUTPUT_SYNC */ /* Create a "bad" file descriptor for stdin when parallel jobs are run. */ #if MK_OS_VMS || MK_OS_W32 || MK_OS_DOS # define get_bad_stdin() (-1) #else int get_bad_stdin (void); #endif #if MK_OS_W32 #include /* Needed for HANDLE */ HANDLE get_handle_for_fd (int); #endif ================================================ FILE: src/output.c ================================================ /* Output to stdout / stderr for GNU Make Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "os.h" #include "output.h" /* GNU Make no longer supports pre-ANSI89 environments. */ #include #include #include #ifdef HAVE_UNISTD_H # include #endif #ifdef HAVE_FCNTL_H # include #else # include #endif #if MK_OS_W32 # include # include # include "sub_proc.h" #endif struct output *output_context = NULL; unsigned int stdio_traced = 0; #define OUTPUT_NONE (-1) #define OUTPUT_ISSET(_out) ((_out)->out >= 0 || (_out)->err >= 0) /* Write a string to the current STDOUT or STDERR. */ static void _outputs (struct output *out, int is_err, const char *msg) { FILE *f; if (out && out->syncout) { int fd = is_err ? out->err : out->out; if (fd != OUTPUT_NONE) { size_t len = strlen (msg); int r; EINTRLOOP (r, lseek (fd, 0, SEEK_END)); writebuf (fd, msg, len); return; } } f = is_err ? stderr : stdout; fputs (msg, f); fflush (f); } /* Write a message indicating that we've just entered or left (according to ENTERING) the current directory. */ static int log_working_directory (int entering) { static char *buf = NULL; static size_t len = 0; size_t need; const char *fmt; char *p; /* Get enough space for the longest possible output. */ need = strlen (program) + INTSTR_LENGTH + 2 + 1; if (starting_directory) need += strlen (starting_directory); /* Use entire sentences to give the translators a fighting chance. */ if (makelevel == 0) if (starting_directory == 0) if (entering) fmt = _("%s: Entering an unknown directory\n"); else fmt = _("%s: Leaving an unknown directory\n"); else if (entering) fmt = _("%s: Entering directory '%s'\n"); else fmt = _("%s: Leaving directory '%s'\n"); else if (starting_directory == 0) if (entering) fmt = _("%s[%u]: Entering an unknown directory\n"); else fmt = _("%s[%u]: Leaving an unknown directory\n"); else if (entering) fmt = _("%s[%u]: Entering directory '%s'\n"); else fmt = _("%s[%u]: Leaving directory '%s'\n"); need += strlen (fmt); if (need > len) { buf = xrealloc (buf, need); len = need; } p = buf; if (print_data_base_flag) { *(p++) = '#'; *(p++) = ' '; } if (makelevel == 0) if (starting_directory == 0) sprintf (p, fmt , program); else sprintf (p, fmt, program, starting_directory); else if (starting_directory == 0) sprintf (p, fmt, program, makelevel); else sprintf (p, fmt, program, makelevel, starting_directory); _outputs (NULL, 0, buf); return 1; } #ifndef NO_OUTPUT_SYNC /* Support routine for output_sync() */ static void pump_from_tmp (int from, FILE *to) { static char buffer[8192]; #if MK_OS_W32 int prev_mode; /* "from" is opened by open_tmpfd, which does it in binary mode, so we need the mode of "to" to match that. */ prev_mode = _setmode (fileno (to), _O_BINARY); #endif if (lseek (from, 0, SEEK_SET) == -1) perror ("lseek()"); while (1) { int len; EINTRLOOP (len, read (from, buffer, sizeof (buffer))); if (len < 0) perror ("read()"); if (len <= 0) break; if (fwrite (buffer, len, 1, to) < 1) { perror ("fwrite()"); break; } fflush (to); } #if MK_OS_W32 /* Switch "to" back to its original mode, so that log messages by Make have the same EOL format as without --output-sync. */ _setmode (fileno (to), prev_mode); #endif } /* Returns a file descriptor to a temporary file, that will be automatically deleted on exit. */ int output_tmpfd (void) { int fd = get_tmpfd (NULL); fd_set_append (fd); return fd; } /* Adds file descriptors to the child structure to support output_sync; one for stdout and one for stderr as long as they are open. If stdout and stderr share a device they can share a temp file too. Will reset output_sync on error. */ static void setup_tmpfile (struct output *out) { static unsigned int in_setup = 0; unsigned int io_state; /* If something fails during setup we might recurse back into this function while writing errors. Make sure we don't do so infinitely. */ if (in_setup) return; in_setup = 1; io_state = check_io_state (); if (NONE_SET (io_state, IO_STDOUT_OK|IO_STDERR_OK)) { /* This is probably useless since stdout/stderr aren't working. */ perror_with_name ("output-sync suppressed: ", "stderr"); goto error; } if (ANY_SET (io_state, IO_STDOUT_OK)) { int fd = output_tmpfd (); if (fd < 0) goto error; fd_noinherit (fd); out->out = fd; } if (ANY_SET (io_state, IO_STDERR_OK)) { if (out->out != OUTPUT_NONE && ANY_SET (io_state, IO_COMBINED_OUTERR)) out->err = out->out; else { int fd = output_tmpfd (); if (fd < 0) goto error; fd_noinherit (fd); out->err = fd; } } in_setup = 0; return; /* If we failed to create a temp file, disable output sync going forward. */ error: O (error, NILF, _("cannot open output-sync lock file: suppressing output-sync")); output_close (out); output_sync = OUTPUT_SYNC_NONE; osync_clear (); in_setup = 0; } /* Synchronize the output of jobs in -j mode to keep the results of each job together. This is done by holding the results in temp files, one for stdout and potentially another for stderr, and only releasing them to "real" stdout/stderr when a semaphore can be obtained. */ void output_dump (struct output *out) { #define FD_NOT_EMPTY(_f) ((_f) != OUTPUT_NONE && lseek ((_f), 0, SEEK_END) > 0) int outfd_not_empty = FD_NOT_EMPTY (out->out); int errfd_not_empty = FD_NOT_EMPTY (out->err); if (outfd_not_empty || errfd_not_empty) { int traced = 0; /* Try to acquire the semaphore. If it fails, dump the output unsynchronized; still better than silently discarding it. We want to keep this lock for as little time as possible. */ if (!osync_acquire ()) { O (error, NILF, _("warning: cannot acquire output lock: disabling output sync")); osync_clear (); } /* Log the working directory for this dump. */ if (output_sync != OUTPUT_SYNC_RECURSE && should_print_dir ()) traced = log_working_directory (1); if (outfd_not_empty) pump_from_tmp (out->out, stdout); if (errfd_not_empty && out->err != out->out) pump_from_tmp (out->err, stderr); if (traced) log_working_directory (0); /* Exit the critical section. */ osync_release (); /* Truncate and reset the output, in case we use it again. */ if (out->out != OUTPUT_NONE) { int e; lseek (out->out, 0, SEEK_SET); EINTRLOOP (e, ftruncate (out->out, 0)); } if (out->err != OUTPUT_NONE && out->err != out->out) { int e; lseek (out->err, 0, SEEK_SET); EINTRLOOP (e, ftruncate (out->err, 0)); } } } #endif /* NO_OUTPUT_SYNC */ static int stdout_flags = -1; static int stderr_flags = -1; void output_init (struct output *out) { if (out) { out->out = out->err = OUTPUT_NONE; out->syncout = !!output_sync; return; } /* Force stdout/stderr into append mode (if they are files) to ensure parallel jobs won't lose output due to overlapping writes. */ stdout_flags = fd_set_append (fileno (stdout)); stderr_flags = fd_set_append (fileno (stderr)); } void output_close (struct output *out) { if (! out) { if (stdio_traced) log_working_directory (0); fd_reset_append(fileno (stdout), stdout_flags); fd_reset_append(fileno (stderr), stderr_flags); return; } #ifndef NO_OUTPUT_SYNC output_dump (out); #endif if (out->out >= 0) close (out->out); if (out->err >= 0 && out->err != out->out) close (out->err); output_init (out); } /* We're about to generate output: be sure it's set up. */ void output_start (void) { #ifndef NO_OUTPUT_SYNC /* If we're syncing output make sure the temporary file is set up. */ if (output_context && output_context->syncout) if (! OUTPUT_ISSET(output_context)) setup_tmpfile (output_context); #endif /* If we're not syncing this output per-line or per-target, make sure we emit the "Entering..." message where appropriate. */ if (output_sync == OUTPUT_SYNC_NONE || output_sync == OUTPUT_SYNC_RECURSE) if (! stdio_traced && should_print_dir ()) stdio_traced = log_working_directory (1); } void outputs (int is_err, const char *msg) { if (! msg || *msg == '\0') return; output_start (); _outputs (output_context, is_err, msg); } static struct fmtstring { char *buffer; size_t size; } fmtbuf = { NULL, 0 }; static char * get_buffer (size_t need) { /* Make sure we have room. NEED includes space for \0. */ if (need > fmtbuf.size) { fmtbuf.size += need * 2; fmtbuf.buffer = xrealloc (fmtbuf.buffer, fmtbuf.size); } fmtbuf.buffer[need-1] = '\0'; return fmtbuf.buffer; } /* Print a message on stdout. */ void message (int prefix, size_t len, const char *fmt, ...) { va_list args; char *start; char *p; len += strlen (fmt) + strlen (program) + INTSTR_LENGTH + 4 + 1 + 1; start = p = get_buffer (len); if (prefix) { if (makelevel == 0) sprintf (p, "%s: ", program); else sprintf (p, "%s[%u]: ", program, makelevel); p += strlen (p); } va_start (args, fmt); vsprintf (p, fmt, args); va_end (args); strcat (p, "\n"); assert (start[len-1] == '\0'); outputs (0, start); } /* Print an error message. */ void error (const floc *flocp, size_t len, const char *fmt, ...) { va_list args; char *start; char *p; len += (strlen (fmt) + strlen (program) + (flocp && flocp->filenm ? strlen (flocp->filenm) : 0) + INTSTR_LENGTH + 4 + 1 + 1); start = p = get_buffer (len); if (flocp && flocp->filenm) sprintf (p, "%s:%lu: ", flocp->filenm, flocp->lineno + flocp->offset); else if (makelevel == 0) sprintf (p, "%s: ", program); else sprintf (p, "%s[%u]: ", program, makelevel); p += strlen (p); va_start (args, fmt); vsprintf (p, fmt, args); va_end (args); strcat (p, "\n"); assert (start[len-1] == '\0'); outputs (1, start); } /* Print an error message and exit. */ void fatal (const floc *flocp, size_t len, const char *fmt, ...) { const char *stop = _(". Stop.\n"); va_list args; char *start; char *p; len += (strlen (fmt) + strlen (program) + (flocp && flocp->filenm ? strlen (flocp->filenm) : 0) + INTSTR_LENGTH + 8 + strlen (stop) + 1); start = p = get_buffer (len); if (flocp && flocp->filenm) sprintf (p, "%s:%lu: *** ", flocp->filenm, flocp->lineno + flocp->offset); else if (makelevel == 0) sprintf (p, "%s: *** ", program); else sprintf (p, "%s[%u]: *** ", program, makelevel); p += strlen (p); va_start (args, fmt); vsprintf (p, fmt, args); va_end (args); strcat (p, stop); assert (start[len-1] == '\0'); outputs (1, start); die (MAKE_FAILURE); } /* Format a message and return a pointer to an internal buffer. */ char * format (const char *prefix, size_t len, const char *fmt, ...) { va_list args; size_t plen = prefix ? strlen (prefix) : 0; char *start; char *p; len += strlen (fmt) + plen + 1; start = p = get_buffer (len); if (plen) p = mempcpy (p, prefix, plen); va_start (args, fmt); vsprintf (p, fmt, args); va_end (args); return start; } /* Print an error message from errno. */ void perror_with_name (const char *str, const char *name) { const char *err = strerror (errno); OSSS (error, NILF, _("%s%s: %s"), str, name, err); } /* Print an error message from errno and exit. */ void pfatal_with_name (const char *name) { const char *err = strerror (errno); OSS (fatal, NILF, _("%s: %s"), name, err); /* NOTREACHED */ } /* Print a message about out of memory (not using more heap) and exit. Our goal here is to be sure we don't try to allocate more memory, which means we don't want to use string translations or normal cleanup. */ void out_of_memory () { writebuf (FD_STDOUT, program, strlen (program)); writebuf (FD_STDOUT, STRING_SIZE_TUPLE (": *** virtual memory exhausted\n")); exit (MAKE_FAILURE); } ================================================ FILE: src/output.h ================================================ /* Output to stdout / stderr for GNU Make Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ struct output { int out; int err; unsigned int syncout:1; /* True if we want to synchronize output. */ }; extern struct output *output_context; extern unsigned int stdio_traced; #define FD_STDIN (fileno (stdin)) #define FD_STDOUT (fileno (stdout)) #define FD_STDERR (fileno (stderr)) #define OUTPUT_SET(_new) do{ output_context = (_new)->syncout ? (_new) : NULL; }while(0) #define OUTPUT_UNSET() do{ output_context = NULL; }while(0) #define OUTPUT_TRACED() do{ stdio_traced = 1; }while(0) #define OUTPUT_IS_TRACED() (!!stdio_traced) /* Write a buffer directly to the given file descriptor. This handles errors etc. */ int output_write (int fd, const void *buffer, size_t len); /* Initialize and close a child output structure: if NULL do this program's output (this should only be done once). */ void output_init (struct output *out); void output_close (struct output *out); /* In situations where output may be about to be displayed but we're not sure if we've set it up yet, call this. */ void output_start (void); /* Show a message on stdout or stderr. Will start the output if needed. */ void outputs (int is_err, const char *msg); #if defined(NO_OUTPUT_SYNC) # define output_dump(_o) (void)(0) #else /* Dump any child output content to stdout, and reset it. */ void output_dump (struct output *out); #endif ================================================ FILE: src/posixos.c ================================================ /* POSIX-based operating system interface for GNU Make. Copyright (C) 2016-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #ifdef HAVE_FCNTL_H # include # define FD_OK(_f) (fcntl ((_f), F_GETFD) != -1) #elif defined(HAVE_SYS_FILE_H) # include #endif #if MK_OS_ZOS /* FIXME: HAVE_PSELECT path hangs on z/OS */ #undef HAVE_PSELECT #endif #if !defined(FD_OK) # define FD_OK(_f) 1 #endif #if defined(HAVE_PSELECT) && defined(HAVE_SYS_SELECT_H) # include #endif #include "debug.h" #include "job.h" #include "os.h" #define STREAM_OK(_s) ((fcntl (fileno (_s), F_GETFD) != -1) || (errno != EBADF)) unsigned int check_io_state () { static unsigned int state = IO_UNKNOWN; /* We only need to compute this once per process. */ if (state != IO_UNKNOWN) return state; if (STREAM_OK (stdin)) state |= IO_STDIN_OK; if (STREAM_OK (stdout)) state |= IO_STDOUT_OK; if (STREAM_OK (stderr)) state |= IO_STDERR_OK; if (ALL_SET (state, IO_STDOUT_OK|IO_STDERR_OK)) { struct stat stbuf_o, stbuf_e; if (fstat (fileno (stdout), &stbuf_o) == 0 && fstat (fileno (stderr), &stbuf_e) == 0 && stbuf_o.st_dev == stbuf_e.st_dev && stbuf_o.st_ino == stbuf_e.st_ino) state |= IO_COMBINED_OUTERR; } return state; } #if defined(MAKE_JOBSERVER) #define FIFO_PREFIX "fifo:" /* This section provides OS-specific functions to support the jobserver. */ /* True if this is the root make instance. */ static unsigned char job_root = 0; /* These track the state of the jobserver pipe. Passed to child instances. */ static int job_fds[2] = { -1, -1 }; /* Used to signal read() that a SIGCHLD happened. Always CLOEXEC. If we use pselect() this will never be created and always -1. */ static int job_rfd = -1; /* Token written to the pipe (could be any character...) */ static char token = '+'; /* The type of jobserver we're using. */ enum js_type { js_none = 0, /* No jobserver. */ js_pipe, /* Use a simple pipe as the jobserver. */ js_fifo /* Use a named pipe as the jobserver. */ }; static enum js_type js_type = js_none; /* The name of the named pipe (if used). */ static char *fifo_name = NULL; static int make_job_rfd () { #ifdef HAVE_PSELECT /* Pretend we succeeded. */ return 0; #else EINTRLOOP (job_rfd, dup (job_fds[0])); if (job_rfd >= 0) fd_noinherit (job_rfd); return job_rfd; #endif } static void set_blocking (int fd, int blocking) { /* If we're not using pselect() don't change the blocking. */ #ifdef HAVE_PSELECT int flags; EINTRLOOP (flags, fcntl (fd, F_GETFL)); if (flags >= 0) { int r; flags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK); EINTRLOOP (r, fcntl (fd, F_SETFL, flags)); if (r < 0) pfatal_with_name ("fcntl(O_NONBLOCK)"); } #else (void) fd; (void) blocking; #endif } unsigned int jobserver_setup (int slots, const char *style) { int r; #if JOBSERVER_USE_FIFO if (!style || strcmp (style, "fifo") == 0) { /* Unfortunately glibc warns about uses of mktemp even though we aren't using it in dangerous way here. So avoid this by generating our own temporary file name. The template in misc.c uses 6 X's so be sure this name cannot conflict with that. */ # define FNAME_PREFIX "GmFIFO" const char *tmpdir = get_tmpdir (); fifo_name = xmalloc (strlen (tmpdir) + CSTRLEN (FNAME_PREFIX) + INTSTR_LENGTH + 2); sprintf (fifo_name, "%s/" FNAME_PREFIX "%03" MK_PRI64_PREFIX "d", tmpdir, (long long)make_pid ()); EINTRLOOP (r, mkfifo (fifo_name, 0600)); if (r < 0) { perror_with_name("jobserver mkfifo: ", fifo_name); free (fifo_name); fifo_name = NULL; } else { /* We have to open the read side in non-blocking mode, else it will hang until the write side is open. */ EINTRLOOP (job_fds[0], open (fifo_name, O_RDONLY|O_NONBLOCK)); if (job_fds[0] < 0) OSS (fatal, NILF, _("cannot open jobserver %s: %s"), fifo_name, strerror (errno)); EINTRLOOP (job_fds[1], open (fifo_name, O_WRONLY)); if (job_fds[0] < 0) OSS (fatal, NILF, _("cannot open jobserver %s: %s"), fifo_name, strerror (errno)); js_type = js_fifo; } } #endif if (js_type == js_none) { if (style && strcmp (style, "pipe") != 0) OS (fatal, NILF, _("unknown jobserver auth style '%s'"), style); EINTRLOOP (r, pipe (job_fds)); if (r < 0) pfatal_with_name (_("creating jobs pipe")); js_type = js_pipe; } /* By default we don't send the job pipe FDs to our children. See jobserver_pre_child() and jobserver_post_child(). */ fd_noinherit (job_fds[0]); fd_noinherit (job_fds[1]); if (make_job_rfd () < 0) pfatal_with_name (_("duping jobs pipe")); while (slots--) { EINTRLOOP (r, write (job_fds[1], &token, 1)); if (r != 1) pfatal_with_name (_("init jobserver pipe")); } /* When using pselect() we want the read to be non-blocking. */ set_blocking (job_fds[0], 0); job_root = 1; return 1; } unsigned int jobserver_parse_auth (const char *auth) { int rfd, wfd; /* Given the command-line parameter, parse it. */ /* First see if we're using a named pipe. */ if (strncmp (auth, FIFO_PREFIX, CSTRLEN (FIFO_PREFIX)) == 0) { fifo_name = xstrdup (auth + CSTRLEN (FIFO_PREFIX)); EINTRLOOP (job_fds[0], open (fifo_name, O_RDONLY)); if (job_fds[0] < 0) { OSS (error, NILF, _("cannot open jobserver %s: %s"), fifo_name, strerror (errno)); return 0; } EINTRLOOP (job_fds[1], open (fifo_name, O_WRONLY)); if (job_fds[1] < 0) { OSS (error, NILF, _("cannot open jobserver %s: %s"), fifo_name, strerror (errno)); return 0; } js_type = js_fifo; } /* If not, it must be a simple pipe. */ else if (sscanf (auth, "%d,%d", &rfd, &wfd) == 2) { /* The parent overrode our FDs because we aren't a recursive make. */ if (rfd == -2 || wfd == -2) return 0; /* Make sure our pipeline is valid. */ if (!FD_OK (rfd) || !FD_OK (wfd)) return 0; job_fds[0] = rfd; job_fds[1] = wfd; js_type = js_pipe; } /* Who knows what it is? */ else { OS (error, NILF, _("invalid --jobserver-auth string '%s'"), auth); return 0; } /* Create a duplicate pipe, if needed, that will be closed in the SIGCHLD handler. If this fails with EBADF, the parent closed the pipe on us as it didn't think we were a submake. If so, warn and default to -j1. */ if (make_job_rfd () < 0) { if (errno != EBADF) pfatal_with_name ("jobserver readfd"); jobserver_clear (); return 0; } /* When using pselect() we want the read to be non-blocking. */ set_blocking (job_fds[0], 0); /* By default we don't send the job pipe FDs to our children. See jobserver_pre_child() and jobserver_post_child(). */ fd_noinherit (job_fds[0]); fd_noinherit (job_fds[1]); return 1; } char * jobserver_get_auth () { char *auth; if (js_type == js_fifo) { auth = xmalloc (strlen (fifo_name) + CSTRLEN (FIFO_PREFIX) + 1); sprintf (auth, FIFO_PREFIX "%s", fifo_name); } else { auth = xmalloc ((INTSTR_LENGTH * 2) + 2); sprintf (auth, "%d,%d", job_fds[0], job_fds[1]); } return auth; } const char * jobserver_get_invalid_auth () { /* If we're using a named pipe we don't need to invalidate the jobserver. */ if (js_type == js_fifo) { return NULL; } /* It's not really great that we are assuming the command line option here but other alternatives are also gross. */ return " --" JOBSERVER_AUTH_OPT "=-2,-2"; } unsigned int jobserver_enabled () { return js_type != js_none; } void jobserver_clear () { if (job_fds[0] >= 0) close (job_fds[0]); if (job_fds[1] >= 0) close (job_fds[1]); if (job_rfd >= 0) close (job_rfd); job_fds[0] = job_fds[1] = job_rfd = -1; if (fifo_name) { if (job_root) { int r; EINTRLOOP (r, unlink (fifo_name)); } if (!handling_fatal_signal) { free (fifo_name); fifo_name = NULL; } } js_type = js_none; } void jobserver_release (int is_fatal) { int r; EINTRLOOP (r, write (job_fds[1], &token, 1)); if (r != 1) { if (is_fatal) pfatal_with_name (_("write jobserver")); perror_with_name ("write", ""); } } unsigned int jobserver_acquire_all () { int r; unsigned int tokens = 0; /* Use blocking reads to wait for all outstanding jobs. */ set_blocking (job_fds[0], 1); /* Close the write side, so the read() won't hang forever. */ close (job_fds[1]); job_fds[1] = -1; while (1) { char intake; EINTRLOOP (r, read (job_fds[0], &intake, 1)); if (r != 1) break; ++tokens; } DB (DB_JOBS, ("Acquired all %u jobserver tokens.\n", tokens)); jobserver_clear (); return tokens; } /* Prepare the jobserver to start a child process. */ void jobserver_pre_child (int recursive) { if (recursive && js_type == js_pipe) { fd_inherit (job_fds[0]); fd_inherit (job_fds[1]); } } /* Reconfigure the jobserver after starting a child process. */ void jobserver_post_child (int recursive) { if (recursive && js_type == js_pipe) { fd_noinherit (job_fds[0]); fd_noinherit (job_fds[1]); } } void jobserver_signal () { if (job_rfd >= 0) { close (job_rfd); job_rfd = -1; } } void jobserver_pre_acquire () { /* Make sure we have a dup'd FD. */ if (job_rfd < 0 && job_fds[0] >= 0 && make_job_rfd () < 0) pfatal_with_name (_("duping jobs pipe")); } #ifdef HAVE_PSELECT /* Use pselect() to atomically wait for both a signal and a file descriptor. It also provides a timeout facility so we don't need to use SIGALRM. This method relies on the fact that SIGCHLD will be blocked everywhere, and only unblocked (atomically) within the pselect() call, so we can never miss a SIGCHLD. */ unsigned int jobserver_acquire (int timeout) { struct timespec spec; struct timespec *specp = NULL; sigset_t empty; sigemptyset (&empty); if (timeout) { /* Alarm after one second (is this too granular?) */ spec.tv_sec = 1; spec.tv_nsec = 0; specp = &spec; } while (1) { fd_set readfds; int r; char intake; FD_ZERO (&readfds); FD_SET (job_fds[0], &readfds); r = pselect (job_fds[0]+1, &readfds, NULL, NULL, specp, &empty); if (r < 0) switch (errno) { case EINTR: /* SIGCHLD will show up as an EINTR. */ return 0; case EBADF: /* Someone closed the jobs pipe. That shouldn't happen but if it does we're done. */ O (fatal, NILF, _("job server shut down")); default: pfatal_with_name (_("pselect jobs pipe")); } if (r == 0) /* Timeout. */ return 0; /* The read FD is ready: read it! This is non-blocking. */ EINTRLOOP (r, read (job_fds[0], &intake, 1)); if (r < 0) { /* Someone sniped our token! Try again. */ if (errno == EAGAIN) continue; pfatal_with_name (_("read jobs pipe")); } /* read() should never return 0: only the parent make can reap all the tokens and close the write side...?? */ return r > 0; } } #else /* This method uses a "traditional" UNIX model for waiting on both a signal and a file descriptor. However, it's complex and since we have a SIGCHLD handler installed we need to check ALL system calls for EINTR: painful! Read a token. As long as there's no token available we'll block. We enable interruptible system calls before the read(2) so that if we get a SIGCHLD while we're waiting, we'll return with EINTR and we can process the death(s) and return tokens to the free pool. Once we return from the read, we immediately reinstate restartable system calls. This allows us to not worry about checking for EINTR on all the other system calls in the program. There is one other twist: there is a span between the time reap_children() does its last check for dead children and the time the read(2) call is entered, below, where if a child dies we won't notice. This is extremely serious as it could cause us to deadlock, given the right set of events. To avoid this, we do the following: before we reap_children(), we dup(2) the read FD on the jobserver pipe. The read(2) call below uses that new FD. In the signal handler, we close that FD. That way, if a child dies during the section mentioned above, the read(2) will be invoked with an invalid FD and will return immediately with EBADF. */ static void job_noop (int sig UNUSED) { } /* Set the child handler action flags to FLAGS. */ static void set_child_handler_action_flags (int set_handler, int set_alarm) { struct sigaction sa; #if MK_OS_OS2 /* The child handler must be turned off here. */ signal (SIGCHLD, SIG_DFL); #endif memset (&sa, '\0', sizeof sa); sa.sa_handler = child_handler; sa.sa_flags = set_handler ? 0 : SA_RESTART; #if defined SIGCHLD if (sigaction (SIGCHLD, &sa, NULL) < 0) pfatal_with_name ("sigaction: SIGCHLD"); #endif #if defined SIGCLD && SIGCLD != SIGCHLD if (sigaction (SIGCLD, &sa, NULL) < 0) pfatal_with_name ("sigaction: SIGCLD"); #endif #if defined SIGALRM if (set_alarm) { /* If we're about to enter the read(), set an alarm to wake up in a second so we can check if the load has dropped and we can start more work. On the way out, turn off the alarm and set SIG_DFL. */ if (set_handler) { sa.sa_handler = job_noop; sa.sa_flags = 0; if (sigaction (SIGALRM, &sa, NULL) < 0) pfatal_with_name ("sigaction: SIGALRM"); alarm (1); } else { alarm (0); sa.sa_handler = SIG_DFL; sa.sa_flags = 0; if (sigaction (SIGALRM, &sa, NULL) < 0) pfatal_with_name ("sigaction: SIGALRM"); } } #endif } unsigned int jobserver_acquire (int timeout) { char intake; int got_token; int saved_errno; /* Set interruptible system calls, and read() for a job token. */ set_child_handler_action_flags (1, timeout); EINTRLOOP (got_token, read (job_rfd, &intake, 1)); saved_errno = errno; set_child_handler_action_flags (0, timeout); if (got_token == 1) return 1; /* If the error _wasn't_ expected (EINTR or EBADF), fatal. Otherwise, go back and reap_children(), and try again. */ errno = saved_errno; if (errno != EINTR && errno != EBADF && errno != EAGAIN) pfatal_with_name (_("read jobs pipe")); if (errno == EBADF) DB (DB_JOBS, ("Read returned EBADF.\n")); return 0; } #endif /* HAVE_PSELECT */ #endif /* MAKE_JOBSERVER */ #if !defined(NO_OUTPUT_SYNC) #define MUTEX_PREFIX "fnm:" static int osync_handle = -1; static char *osync_tmpfile = NULL; static unsigned int sync_root = 0; unsigned int osync_enabled () { return osync_handle >= 0; } void osync_setup () { osync_handle = get_tmpfd (&osync_tmpfile); fd_noinherit (osync_handle); sync_root = 1; } char * osync_get_mutex () { char *mutex = NULL; if (osync_enabled ()) { /* Prepare the mutex handle string for our children. */ mutex = xmalloc (strlen (osync_tmpfile) + CSTRLEN (MUTEX_PREFIX) + 1); sprintf (mutex, MUTEX_PREFIX "%s", osync_tmpfile); } return mutex; } unsigned int osync_parse_mutex (const char *mutex) { if (strncmp (mutex, MUTEX_PREFIX, CSTRLEN (MUTEX_PREFIX)) != 0) { OS (error, NILF, _("invalid --sync-mutex string '%s'"), mutex); return 0; } free (osync_tmpfile); osync_tmpfile = xstrdup (mutex + CSTRLEN (MUTEX_PREFIX)); EINTRLOOP (osync_handle, open (osync_tmpfile, O_WRONLY)); if (osync_handle < 0) OSS (fatal, NILF, _("cannot open output sync mutex %s: %s"), osync_tmpfile, strerror (errno)); fd_noinherit (osync_handle); return 1; } void osync_clear () { if (osync_handle >= 0) { close (osync_handle); osync_handle = -1; } if (sync_root && osync_tmpfile) { int r; EINTRLOOP (r, unlink (osync_tmpfile)); free (osync_tmpfile); osync_tmpfile = NULL; } } unsigned int osync_acquire () { if (osync_enabled()) { struct flock fl; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 1; /* We don't want to keep waiting on EINTR. */ if (fcntl (osync_handle, F_SETLKW, &fl) == -1) { perror ("fcntl()"); return 0; } } return 1; } void osync_release () { if (osync_enabled()) { struct flock fl; fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 1; /* We don't want to keep waiting on EINTR. */ if (fcntl (osync_handle, F_SETLKW, &fl) == -1) perror ("fcntl()"); } } #endif /* Create a "bad" file descriptor for stdin when parallel jobs are run. */ int get_bad_stdin () { static int bad_stdin = -1; /* Set up a bad standard input that reads from a broken pipe. */ if (bad_stdin == -1) { /* Make a file descriptor that is the read end of a broken pipe. This will be used for some children's standard inputs. */ int pd[2]; if (pipe (pd) == 0) { /* Close the write side. */ close (pd[1]); /* Save the read side. */ bad_stdin = pd[0]; /* Set the descriptor to close on exec, so it does not litter any child's descriptor table. When it is dup2'd onto descriptor 0, that descriptor will not close on exec. */ fd_noinherit (bad_stdin); } } return bad_stdin; } /* Set file descriptors to be inherited / not inherited by subprocesses. */ #if !defined(F_SETFD) || !defined(F_GETFD) void fd_inherit (int fd) {} void fd_noinherit (int fd) {} #else # ifndef FD_CLOEXEC # define FD_CLOEXEC 1 # endif void fd_inherit (int fd) { int flags; EINTRLOOP (flags, fcntl (fd, F_GETFD)); if (flags >= 0) { int r; flags &= ~FD_CLOEXEC; EINTRLOOP (r, fcntl (fd, F_SETFD, flags)); } } void fd_noinherit (int fd) { int flags; EINTRLOOP (flags, fcntl(fd, F_GETFD)); if (flags >= 0) { int r; flags |= FD_CLOEXEC; EINTRLOOP (r, fcntl(fd, F_SETFD, flags)); } } #endif /* Set a file descriptor referring to a regular file to be in O_APPEND mode. If it fails, just ignore it. */ int fd_set_append (int fd) { int flags = -1; #if defined(F_GETFL) && defined(F_SETFL) && defined(O_APPEND) struct stat stbuf; if (fstat (fd, &stbuf) == 0 && S_ISREG (stbuf.st_mode)) { flags = fcntl (fd, F_GETFL, 0); if (flags >= 0) { int r; EINTRLOOP(r, fcntl (fd, F_SETFL, flags | O_APPEND)); } } #endif return flags; } /* Reset a file descriptor referring to a regular file to be in O_APPEND mode. If it fails, just ignore it. */ void fd_reset_append (int fd, int flags) { #if defined(F_GETFL) && defined(F_SETFL) && defined(O_APPEND) if (flags >= 0) { int r; EINTRLOOP(r, fcntl (fd, F_SETFL, flags)); } #endif } /* Return a file descriptor for a new anonymous temp file, or -1. */ int os_anontmp () { const char *tdir = get_tmpdir (); int fd = -1; #ifdef O_TMPFILE static unsigned int tmpfile_works = 1; if (tmpfile_works) { EINTRLOOP (fd, open (tdir, O_RDWR | O_TMPFILE | O_EXCL, 0600)); if (fd >= 0) return fd; DB (DB_BASIC, (_("Cannot open '%s' with O_TMPFILE: %s.\n"), tdir, strerror (errno))); tmpfile_works = 0; } #endif #if HAVE_DUP /* If we can dup and we are creating temp files in the default location then try tmpfile() + dup() + fclose() to avoid ever having a named file. */ if (streq (tdir, DEFAULT_TMPDIR)) { mode_t mask = umask (0077); FILE *tfile; ENULLLOOP (tfile, tmpfile ()); if (!tfile) { OS (error, NILF, "tmpfile: %s", strerror (errno)); return -1; } umask (mask); EINTRLOOP (fd, dup (fileno (tfile))); if (fd < 0) OS (error, NILF, "dup: %s", strerror (errno)); fclose (tfile); } #endif return fd; } ================================================ FILE: src/read.c ================================================ /* Reading and parsing of makefiles for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #if MK_OS_W32 # include # include "sub_proc.h" #elif MK_OS_VMS struct passwd *getpwnam (char *name); #else # include #endif #include "filedef.h" #include "dep.h" #include "job.h" #include "os.h" #include "commands.h" #include "variable.h" #include "rule.h" #include "debug.h" #include "hash.h" #include "warning.h" /* A 'struct ebuffer' controls the origin of the makefile we are currently eval'ing. */ struct ebuffer { char *buffer; /* Start of the current line in the buffer. */ char *bufnext; /* Start of the next line in the buffer. */ char *bufstart; /* Start of the entire buffer. */ size_t size; /* Malloc'd size of buffer. */ FILE *fp; /* File, or NULL if this is an internal buffer. */ floc floc; /* Info on the file in fp (if any). */ }; /* Track the modifiers we can have on variable assignments */ struct vmodifiers { unsigned int assign_v:1; unsigned int define_v:1; unsigned int undefine_v:1; unsigned int override_v:1; unsigned int private_v:1; enum variable_export export_v ENUM_BITFIELD (2); }; /* Types of "words" that can be read in a makefile. */ enum make_word_type { w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon, w_ampcolon, w_ampdcolon }; /* A 'struct conditionals' contains the information describing all the active conditionals in a makefile. The global variable 'conditionals' contains the conditionals information for the current makefile. It is initialized from the static structure 'toplevel_conditionals' and is later changed to new structures for included makefiles. */ struct conditionals { unsigned int if_cmds; /* Depth of conditional nesting. */ unsigned int allocated; /* Elts allocated in following arrays. */ char *ignoring; /* Are we ignoring or interpreting? 0=interpreting, 1=not yet interpreted, 2=already interpreted */ char *seen_else; /* Have we already seen an 'else'? */ }; static struct conditionals toplevel_conditionals; static struct conditionals *conditionals = &toplevel_conditionals; /* Default directories to search for include files in */ static const char *default_include_directories[] = { #if MK_OS_W32 && !defined(INCLUDEDIR) /* This completely up to the user when they install MSVC or other packages. This is defined as a placeholder. */ # define INCLUDEDIR "." #endif #if defined(INCLUDEDIR) INCLUDEDIR, #endif "/usr/gnu/include", "/usr/local/include", "/usr/include", NULL }; /* List of directories to search for include files in */ static const char **include_directories; /* Maximum length of an element of the above. */ static size_t max_incl_len; /* The filename and pointer to line number of the makefile currently being read in. */ const floc *reading_file = 0; /* The chain of files read by read_all_makefiles. */ static struct goaldep *read_files = 0; static struct goaldep *eval_makefile (const char *filename, unsigned short flags); static void eval (struct ebuffer *buffer, int flags); static long readline (struct ebuffer *ebuf); static void do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf); static struct variable *do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf); static int conditional_line (char *line, size_t len, const floc *flocp); static void check_specials (struct nameseq *filep, int set_default); static void check_special_file (struct file *filep, const floc *flocp); static void record_files (struct nameseq *filenames, int are_also_makes, const char *pattern, const char *pattern_percent, char *depstr, unsigned int cmds_started, char *commands, size_t commands_idx, int two_colon, char prefix, const floc *flocp); static void record_target_var (struct nameseq *filenames, char *defn, enum variable_origin origin, struct vmodifiers *vmod, const floc *flocp); static enum make_word_type get_next_mword (char *buffer, char **startp, size_t *length); static void remove_comments (char *line); static char *find_map_unquote (char *string, int map); static char *find_char_unquote (char *string, int stop); static char *unescape_char (char *string, int c); /* Compare a word, both length and contents. P must point to the word to be tested, and WLEN must be the length. */ #define word1eq(s) (wlen == CSTRLEN (s) && memcmp (s, p, CSTRLEN (s)) == 0) /* Read in all the makefiles and return a chain of targets to rebuild. */ struct goaldep * read_all_makefiles (const char **makefiles) { unsigned int num_makefiles = 0; /* Create *_LIST variables, to hold the makefiles, targets, and variables we will be reading. */ define_variable_cname ("MAKEFILE_LIST", "", o_file, 0); DB (DB_BASIC, (_("Reading makefiles...\n"))); /* If there's a non-null variable MAKEFILES, its value is a list of files to read first thing. But don't let it prevent reading the default makefiles and don't let the default goal come from there. */ { char *value; char *name, *p; size_t length; value = allocated_expand_variable (STRING_SIZE_TUPLE ("MAKEFILES")); /* Set NAME to the start of next token and LENGTH to its length. MAKEFILES is updated for finding remaining tokens. */ p = value; while ((name = find_next_token ((const char **)&p, &length)) != 0) { if (*p != '\0') *p++ = '\0'; eval_makefile (strcache_add (name), RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE); } free (value); } /* Read makefiles specified with -f switches. */ if (makefiles != 0) while (*makefiles != 0) { struct goaldep *d = eval_makefile (*makefiles, 0); if (errno) perror_with_name ("", *makefiles); /* Reuse the storage allocated for the read_file. */ *makefiles = dep_name (d); ++num_makefiles; ++makefiles; } /* If there were no -f switches, try the default names. */ if (num_makefiles == 0) { static const char *default_makefiles[] = #if MK_OS_VMS /* all lower case since readdir() (the vms version) 'lowercasifies' */ /* TODO: Above is not always true, this needs more work */ { "makefile.vms", "gnumakefile", "makefile", 0 }; #else #if MK_OS_W32 { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 }; #else /* !MK_OS_VMS && !MK_OS_W32 */ { "GNUmakefile", "makefile", "Makefile", 0 }; #endif /* !MK_OS_VMS && !MK_OS_W32 */ #endif /* MK_OS_VMS */ const char **p = default_makefiles; while (*p != 0 && !file_exists_p (*p)) ++p; if (*p != 0) { eval_makefile (*p, 0); if (errno) perror_with_name ("", *p); } else { /* No default makefile was found. Add the default makefiles to the 'read_files' chain so they will be updated if possible. */ for (p = default_makefiles; *p != 0; ++p) { struct goaldep *d = alloc_goaldep (); d->file = enter_file (strcache_add (*p)); /* Tell update_goal_chain to bail out as soon as this file is made, and main not to die if we can't make this file. */ d->flags = RM_DONTCARE; d->next = read_files; read_files = d; } } } return read_files; } /* Install a new conditional and return the previous one. */ static struct conditionals * install_conditionals (struct conditionals *new) { struct conditionals *save = conditionals; memset (new, '\0', sizeof (*new)); conditionals = new; return save; } /* Free the current conditionals and reinstate a saved one. */ static void restore_conditionals (struct conditionals *saved) { /* Free any space allocated by conditional_line. */ free (conditionals->ignoring); free (conditionals->seen_else); /* Restore state. */ conditionals = saved; } static struct goaldep * eval_makefile (const char *filename, unsigned short flags) { struct goaldep *deps; struct ebuffer ebuf; const floc *curfile; char *expanded = 0; /* Create a new goaldep entry. */ deps = alloc_goaldep (); deps->next = read_files; read_files = deps; ebuf.floc.filenm = filename; /* Use the original file name. */ ebuf.floc.lineno = 1; ebuf.floc.offset = 0; if (ISDB (DB_VERBOSE)) { printf (_("Reading makefile '%s'"), filename); if (flags & RM_NO_DEFAULT_GOAL) printf (_(" (no default goal)")); if (flags & RM_INCLUDED) printf (_(" (search path)")); if (flags & RM_DONTCARE) printf (_(" (don't care)")); if (flags & RM_NO_TILDE) printf (_(" (no ~ expansion)")); puts ("..."); } /* First, get a stream to read. */ /* Expand ~ in FILENAME unless it came from 'include', in which case it was already done. */ if (!(flags & RM_NO_TILDE) && filename[0] == '~') { expanded = tilde_expand (filename); if (expanded != 0) filename = expanded; } errno = 0; ENULLLOOP (ebuf.fp, fopen (filename, "r")); deps->error = errno; /* Check for unrecoverable errors: out of mem or FILE slots. */ switch (deps->error) { #ifdef EMFILE case EMFILE: #endif #ifdef ENFILE case ENFILE: #endif case ENOMEM: { const char *err = strerror (deps->error); OS (fatal, reading_file, "%s", err); } } /* If the makefile wasn't found and it's either a makefile from the 'MAKEFILES' variable or an included makefile, search the included makefile search path for this makefile. */ if (ebuf.fp == NULL && deps->error == ENOENT && include_directories && ANY_SET (flags, RM_INCLUDED) && !HAS_DRIVESPEC (filename) && !ISDIRSEP (*filename)) { const char **dir; for (dir = include_directories; *dir != NULL; ++dir) { const char *included = concat (3, *dir, "/", filename); ENULLLOOP(ebuf.fp, fopen (included, "r")); if (ebuf.fp) { filename = included; break; } if (errno != ENOENT) { filename = included; deps->error = errno; break; } } } /* Enter the final name for this makefile as a goaldep. */ filename = strcache_add (filename); deps->file = lookup_file (filename); if (deps->file == 0) deps->file = enter_file (filename); filename = deps->file->name; deps->flags = flags; deps->file->is_explicit = 1; free (expanded); if (ebuf.fp == 0) { /* The makefile can't be read at all, give up entirely. If we did some searching errno has the error from the last attempt, rather from FILENAME itself: recover the more accurate one. */ errno = deps->error; deps->file->last_mtime = NONEXISTENT_MTIME; return deps; } /* Success; clear errno. */ deps->error = 0; /* If we tried and failed to read the included file before but this time we succeeded, reset the last mtime. */ if (deps->file->last_mtime == NONEXISTENT_MTIME) deps->file->last_mtime = 0; /* Avoid leaking the makefile to children. */ fd_noinherit (fileno (ebuf.fp)); /* Add this makefile to the list. */ do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file, f_append_value, 0, s_global); /* Evaluate the makefile */ ebuf.size = 200; ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size); curfile = reading_file; reading_file = &ebuf.floc; eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL)); reading_file = curfile; fclose (ebuf.fp); free (ebuf.bufstart); free_alloca (); errno = 0; return deps; } void eval_buffer (char *buffer, const floc *flocp) { struct ebuffer ebuf; struct conditionals *saved; struct conditionals new; const floc *curfile; /* Evaluate the buffer */ ebuf.size = strlen (buffer); ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer; ebuf.fp = NULL; if (flocp) ebuf.floc = *flocp; else if (reading_file) ebuf.floc = *reading_file; else { ebuf.floc.filenm = NULL; ebuf.floc.lineno = 1; ebuf.floc.offset = 0; } curfile = reading_file; reading_file = &ebuf.floc; saved = install_conditionals (&new); eval (&ebuf, 1); restore_conditionals (saved); reading_file = curfile; free_alloca (); } /* Check LINE to see if it's a variable assignment or undefine. It might use one of the modifiers "export", "override", "private", or it might be one of the conditional tokens like "ifdef", "include", etc. If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0. Returns LINE. Returns a pointer to the first non-modifier character, and sets VMOD based on the modifiers found if any, plus V_ASSIGN is 1. */ static char * parse_var_assignment (const char *line, int targvar, struct vmodifiers *vmod) { const char *p; memset (vmod, '\0', sizeof (*vmod)); /* Find the start of the next token. If there isn't one we're done. */ NEXT_TOKEN (line); if (*line == '\0') return (char *) line; p = line; while (1) { size_t wlen; const char *p2; struct variable v; p2 = parse_variable_definition (p, &v); /* If this is a variable assignment, we're done. */ if (p2) break; /* It's not a variable; see if it's a modifier. */ p2 = end_of_token (p); wlen = p2 - p; if (word1eq ("export")) vmod->export_v = v_export; else if (word1eq ("unexport")) vmod->export_v = v_noexport; else if (word1eq ("override")) vmod->override_v = 1; else if (word1eq ("private")) vmod->private_v = 1; else if (!targvar && word1eq ("define")) { /* We can't have modifiers after 'define' */ vmod->define_v = 1; p = next_token (p2); break; } else if (!targvar && word1eq ("undefine")) { /* We can't have modifiers after 'undefine' */ vmod->undefine_v = 1; p = next_token (p2); break; } else /* Not a variable or modifier: this is not a variable assignment. */ return (char *) line; /* It was a modifier. Try the next word. */ p = next_token (p2); if (*p == '\0') return (char *) line; } /* Found a variable assignment or undefine. */ vmod->assign_v = 1; return (char *)p; } /* Read file FILENAME as a makefile and add its contents to the data base. SET_DEFAULT is true if we are allowed to set the default goal. */ static void eval (struct ebuffer *ebuf, int set_default) { char *collapsed = 0; size_t collapsed_length = 0; size_t commands_len = 200; char *commands; size_t commands_idx = 0; unsigned int cmds_started, tgts_started; int ignoring = 0, in_ignored_define = 0; int no_targets = 0; /* Set when reading a rule without targets. */ int also_make_targets = 0; /* Set when reading grouped targets. */ struct nameseq *filenames = 0; char *depstr = 0; long nlines = 0; int two_colon = 0; char prefix = cmd_prefix; const char *pattern = 0; const char *pattern_percent; floc *fstart; floc fi; #define record_waiting_files() \ do \ { \ if (filenames != 0) \ { \ fi.lineno = tgts_started; \ fi.offset = 0; \ record_files (filenames, also_make_targets, pattern, \ pattern_percent, depstr, \ cmds_started, commands, commands_idx, two_colon, \ prefix, &fi); \ filenames = 0; \ } \ commands_idx = 0; \ no_targets = 0; \ pattern = 0; \ also_make_targets = 0; \ } while (0) pattern_percent = 0; cmds_started = tgts_started = 1; fstart = &ebuf->floc; fi.filenm = ebuf->floc.filenm; /* Loop over lines in the file. The strategy is to accumulate target names in FILENAMES, dependencies in DEPS and commands in COMMANDS. These are used to define a rule when the start of the next rule (or eof) is encountered. When you see a "continue" in the loop below, that means we are moving on to the next line. If you see record_waiting_files(), then the statement we are parsing also finishes the previous rule. */ commands = xmalloc (200); while (1) { size_t linelen; char *line; size_t wlen; char *p; char *p2; unsigned int is_rule; struct vmodifiers vmod; /* At the top of this loop, we are starting a brand new line. */ /* Grab the next line to be evaluated */ ebuf->floc.lineno += nlines; nlines = readline (ebuf); /* If there is nothing left to eval, we're done. */ if (nlines < 0) break; line = ebuf->buffer; /* If this is the first line, check for a UTF-8 BOM and skip it. */ if (ebuf->floc.lineno == 1) { unsigned char *ul = (unsigned char *) line; if (ul[0] == 0xEF && ul[1] == 0xBB && ul[2] == 0xBF) { line += 3; if (ISDB(DB_BASIC)) { if (ebuf->floc.filenm) printf (_("Skipping UTF-8 BOM in makefile '%s'\n"), ebuf->floc.filenm); else printf (_("Skipping UTF-8 BOM in makefile buffer\n")); } } } /* If this line is empty, skip it. */ if (line[0] == '\0') continue; linelen = strlen (line); /* Check for a shell command line first. If it is not one, we can stop treating cmd_prefix specially. */ if (line[0] == cmd_prefix) { if (no_targets) /* Ignore the commands in a rule with no targets. */ continue; if (ignoring) /* Yep, this is a shell command, and we don't care. */ continue; /* If there is no preceding rule line, don't treat this line as a command, even though it begins with a recipe prefix. SunOS 4 make appears to behave this way. */ if (filenames != 0) { if (commands_idx == 0) cmds_started = ebuf->floc.lineno; /* Append this command line to the line being accumulated. Skip the initial command prefix character. */ if (linelen + commands_idx > commands_len) { commands_len = (linelen + commands_idx) * 2; commands = xrealloc (commands, commands_len); } memcpy (&commands[commands_idx], line + 1, linelen - 1); commands_idx += linelen - 1; commands[commands_idx++] = '\n'; continue; } } /* This line is not a shell command line. Don't worry about whitespace. Get more space if we need it; we don't need to preserve the current contents of the buffer. */ if (collapsed_length < linelen+1) { collapsed_length = linelen+1; free (collapsed); /* Don't need xrealloc: we don't need to preserve the content. */ collapsed = xmalloc (collapsed_length); } strcpy (collapsed, line); /* Collapse continuation lines. */ collapse_continuations (collapsed); remove_comments (collapsed); /* Get rid if starting space (including formfeed, vtab, etc.) */ p = collapsed; NEXT_TOKEN (p); /* See if this is a variable assignment. We need to do this early, to allow variables with names like 'ifdef', 'export', 'private', etc. */ p = parse_var_assignment (p, 0, &vmod); if (vmod.assign_v) { struct variable *v; enum variable_origin origin = vmod.override_v ? o_override : o_file; /* If we're ignoring then we're done now. */ if (ignoring) { if (vmod.define_v) in_ignored_define = 1; continue; } /* Variable assignment ends the previous rule. */ record_waiting_files (); if (vmod.undefine_v) { do_undefine (p, origin, ebuf); continue; } if (vmod.define_v) v = do_define (p, origin, ebuf); else v = try_variable_definition (fstart, p, origin, s_global); assert (v != NULL); if (vmod.export_v != v_default) v->export = vmod.export_v; if (vmod.private_v) v->private_var = 1; /* This line has been dealt with. */ continue; } /* If this line is completely empty, ignore it. */ if (*p == '\0') continue; p2 = end_of_token (p); wlen = p2 - p; NEXT_TOKEN (p2); is_rule = *p2 == ':' || ((*p2 == '&' || *p2 == '|') && p2[1] == ':'); /* If we're in an ignored define, skip this line (but maybe get out). */ if (in_ignored_define) { /* See if this is an endef line (plus optional comment). */ if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL)) in_ignored_define = 0; continue; } /* Check for conditional state changes. */ { int i = conditional_line (p, wlen, fstart); if (i != -2) { if (i == -1) O (fatal, fstart, _("invalid syntax in conditional")); ignoring = i; continue; } } /* Nothing to see here... move along. */ if (ignoring) continue; /* Manage the "export" keyword used outside of variable assignment as well as "unexport". */ if (word1eq ("export") || word1eq ("unexport")) { int exporting = *p == 'u' ? 0 : 1; /* Export/unexport ends the previous rule. */ record_waiting_files (); /* (un)export by itself causes everything to be (un)exported. */ if (*p2 == '\0') export_all_variables = exporting; else { size_t l; const char *cp; char *ap; /* Expand the line so we can use indirect and constructed variable names in an (un)export command. */ cp = ap = allocated_expand_string (p2); for (p = find_next_token (&cp, &l); p != 0; p = find_next_token (&cp, &l)) { struct variable *v = lookup_variable (p, l); if (v == 0) v = define_variable_global (p, l, "", o_file, 0, fstart); v->export = exporting ? v_export : v_noexport; } free (ap); } continue; } /* Handle the special syntax for vpath. */ if (word1eq ("vpath")) { const char *cp; char *vpat; size_t l; /* vpath ends the previous rule. */ record_waiting_files (); cp = expand_string (p2); p = find_next_token (&cp, &l); if (p != 0) { vpat = xstrndup (p, l); p = find_next_token (&cp, &l); /* No searchpath means remove all previous selective VPATH's with the same pattern. */ } else /* No pattern means remove all previous selective VPATH's. */ vpat = 0; construct_vpath_list (vpat, p); free (vpat); continue; } /* Handle include and variants. */ if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) { /* We have found an 'include' line specifying a nested makefile to be read at this point. */ struct conditionals *save; struct conditionals new_conditionals; struct nameseq *files; /* "-include" (vs "include") says no error if the file does not exist. "sinclude" is an alias for this from SGI. */ int noerror = (p[0] != 'i'); /* Include ends the previous rule. */ record_waiting_files (); p = allocated_expand_string (p2); /* If no filenames, it's a no-op. */ if (*p == '\0') { free (p); continue; } /* Parse the list of file names. Don't expand archive references! */ p2 = p; files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, PARSEFS_NOAR); free (p); /* Save the state of conditionals and start the included makefile with a clean slate. */ save = install_conditionals (&new_conditionals); /* Record the rules that are waiting so they will determine the default goal before those in the included makefile. */ record_waiting_files (); /* Read each included makefile. */ while (files != 0) { struct nameseq *next = files->next; unsigned short flags = (RM_INCLUDED | RM_NO_TILDE | (noerror ? RM_DONTCARE : 0) | (set_default ? 0 : RM_NO_DEFAULT_GOAL)); struct goaldep *d = eval_makefile (files->name, flags); d->floc = *fstart; free_ns (files); files = next; } /* Restore conditional state. */ restore_conditionals (save); continue; } /* Handle the load operations. Allow targets named "load". */ if ((word1eq ("load") || word1eq ("-load")) && !is_rule) { /* A 'load' line specifies a dynamic object to load. */ struct nameseq *files; int noerror = (p[0] == '-'); /* Load ends the previous rule. */ record_waiting_files (); p = allocated_expand_string (p2); /* If no filenames, it's a no-op. */ if (*p == '\0') { free (p); continue; } /* Parse the list of file names. Don't expand archive references or strip "./" */ p2 = p; files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, PARSEFS_NOAR); free (p); /* Load each file. */ while (files != 0) { struct nameseq *next = files->next; const char *name = files->name; struct goaldep *deps; struct file *f; int r; { struct file file = {0}; file.name = name; /* Load the file. 0 means failure. */ r = load_file (&ebuf->floc, &file, noerror); if (! r && ! noerror) OS (fatal, &ebuf->floc, _("%s: failed to load"), name); name = file.name; } f = lookup_file (name); if (!f) f = enter_file (name); f->loaded = 1; f->unloaded = 0; free_ns (files); files = next; /* Return of -1 means don't ever try to rebuild. */ if (r == -1) continue; /* Otherwise add it to the list to be rebuilt. */ deps = alloc_goaldep (); deps->next = read_files; deps->floc = ebuf->floc; read_files = deps; deps->file = f; } continue; } /* This line starts with a tab but was not caught above because there was no preceding target, and the line might have been usable as a variable definition. But now we know it is definitely lossage. */ if (line[0] == cmd_prefix) O (fatal, fstart, _("recipe commences before first target")); /* This line describes some target files. This is complicated by the existence of target-specific variables, because we can't expand the entire line until we know if we have one or not. So we expand the line word by word until we find the first ':', then check to see if it's a target-specific variable. In this algorithm, 'lb_next' will point to the beginning of the unexpanded parts of the input buffer, while 'p2' points to the parts of the expanded buffer we haven't searched yet. */ { enum make_word_type wtype; char *cmdleft, *semip = 0, *lb_next; size_t plen = 0; char *colonp; const char *end, *beg; /* Helpers for whitespace stripping. */ /* Record the previous rule. */ record_waiting_files (); tgts_started = fstart->lineno; /* Search the line for an unquoted ; that is not after an unquoted #. */ cmdleft = find_map_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE); if (cmdleft != 0 && *cmdleft == '#') { /* We found a comment before a semicolon. */ *cmdleft = '\0'; cmdleft = 0; } else if (cmdleft != 0) { /* Found one. Cut the line short there before expanding it. */ semip = cmdleft++; *semip = '\0'; } collapse_continuations (line); /* We can't expand the entire line, since if it's a per-target variable we don't want to expand it. So, walk from the beginning, expanding as we go, and looking for "interesting" chars. The first word is always expandable. */ wtype = get_next_mword (line, &lb_next, &wlen); switch (wtype) { case w_eol: if (cmdleft != 0) O (fatal, fstart, _("missing rule before recipe")); /* This line contained something but turned out to be nothing but whitespace (a comment?). */ continue; case w_colon: case w_dcolon: case w_ampcolon: case w_ampdcolon: /* We accept and ignore rules without targets for compatibility with SunOS 4 make. */ no_targets = 1; continue; default: break; } p2 = expand_string_buf (NULL, lb_next, wlen); while (1) { lb_next += wlen; if (cmdleft == 0) { /* Look for a semicolon in the expanded line. */ cmdleft = find_char_unquote (p2, ';'); if (cmdleft != 0) { size_t p2_off = p2 - variable_buffer; size_t cmd_off = cmdleft - variable_buffer; char *pend = p2 + strlen (p2); /* Append any remnants of lb, then cut the line short at the semicolon. */ *cmdleft = '\0'; /* One school of thought says that you shouldn't expand here, but merely copy, since now you're beyond a ";" and into a command script. However, the old parser expanded the whole line, so we continue that for backwards-compatibility. Also, it wouldn't be entirely consistent, since we do an unconditional expand below once we know we don't have a target-specific variable. */ expand_string_buf (pend, lb_next, SIZE_MAX); lb_next += strlen (lb_next); p2 = variable_buffer + p2_off; cmdleft = variable_buffer + cmd_off + 1; } } colonp = find_char_unquote (p2, ':'); #ifdef HAVE_DOS_PATHS if (colonp > p2) /* The drive spec brain-damage strikes again... Note that the only separators of targets in this context are whitespace and a left paren. If others are possible, add them to the string in the call to strchr. */ while (colonp && ISDIRSEP (colonp[1]) && isalpha ((unsigned char) colonp[-1]) && (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0)) colonp = find_char_unquote (colonp + 1, ':'); #endif if (colonp) { /* If the previous character is '&', back up before '&:' */ if (colonp > p2 && colonp[-1] == '&') --colonp; break; } wtype = get_next_mword (lb_next, &lb_next, &wlen); if (wtype == w_eol) break; p2 += strlen (p2); *(p2++) = ' '; p2 = expand_string_buf (p2, lb_next, wlen); /* We don't need to worry about cmdleft here, because if it was found in the variable_buffer the entire buffer has already been expanded... we'll never get here. */ } p2 = next_token (variable_buffer); /* If we're at EOL we didn't find a separator so we don't know what kind of line this is. */ if (wtype == w_eol) { /* Ignore an empty line. */ if (*p2 == '\0') continue; /* Check for spaces instead of TAB. */ if (cmd_prefix == '\t' && strneq (line, " ", 8)) O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)")); /* Check for conditionals without whitespace afterward. We don't check ifdef/ifndef because there's no real way to miss whitespace there. */ p2 = next_token (line); if (strneq (p2, "if", 2) && ((strneq (&p2[2], "neq", 3) && !STOP_SET (p2[5], MAP_BLANK)) || (strneq (&p2[2], "eq", 2) && !STOP_SET (p2[4], MAP_BLANK)))) O (fatal, fstart, _("missing separator (ifeq/ifneq must be followed by whitespace)")); /* No idea... */ O (fatal, fstart, _("missing separator")); } { char save = *colonp; /* If we have &:, it specifies that the targets are understood to be updated/created together by a single invocation of the recipe. */ if (save == '&') also_make_targets = 1; /* Make the colon the end-of-string so we know where to stop looking for targets. Start there again once we're done. */ *colonp = '\0'; filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq); *colonp = save; p2 = colonp + (save == '&'); } if (!filenames) { /* We accept and ignore rules without targets for compatibility with SunOS 4 make. */ no_targets = 1; continue; } /* This should never be possible; we handled it above. */ assert (*p2 != '\0'); ++p2; /* Is this a one-colon or two-colon entry? */ two_colon = *p2 == ':'; if (two_colon) p2++; /* Test to see if it's a target-specific variable. Copy the rest of the buffer over, possibly temporarily (we'll expand it later if it's not a target-specific variable). PLEN saves the length of the unparsed section of p2, for later. */ if (*lb_next != '\0') { size_t l = p2 - variable_buffer; plen = strlen (p2); variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1); p2 = variable_buffer + l; } p2 = parse_var_assignment (p2, 1, &vmod); if (vmod.assign_v) { /* If there was a semicolon found, add it back, plus anything after it. */ if (semip) { size_t l = p2 - variable_buffer; *semip = ';'; collapse_continuations (semip); variable_buffer_output (p2 + strlen (p2), semip, strlen (semip)+1); p2 = variable_buffer + l; } record_target_var (filenames, p2, vmod.override_v ? o_override : o_file, &vmod, fstart); filenames = 0; continue; } /* This is a normal target, _not_ a target-specific variable. Unquote any = in the dependency list. */ find_char_unquote (lb_next, '='); /* Remember the command prefix for this target. */ prefix = cmd_prefix; /* We have some targets, so don't ignore the following commands. */ no_targets = 0; /* Expand the dependencies, etc. */ if (*lb_next != '\0') { size_t l = p2 - variable_buffer; expand_string_buf (p2 + plen, lb_next, SIZE_MAX); p2 = variable_buffer + l; /* Look for a semicolon in the expanded line. */ if (cmdleft == 0) { cmdleft = find_char_unquote (p2, ';'); if (cmdleft != 0) *(cmdleft++) = '\0'; } } /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */ p = strchr (p2, ':'); while (p != 0 && p[-1] == '\\') { char *q = &p[-1]; int backslash = 0; while (*q-- == '\\') backslash = !backslash; if (backslash) p = strchr (p + 1, ':'); else break; } #ifdef HAVE_DOS_PATHS { int check_again; do { check_again = 0; /* For DOS-style paths, skip a "C:\..." or a "C:/..." */ if (p != 0 && ISDIRSEP (p[1]) && isalpha ((unsigned char)p[-1]) && (p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) { p = strchr (p + 1, ':'); check_again = 1; } } while (check_again); } #endif if (p != 0) { struct nameseq *target; target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL, PARSEFS_NOGLOB); ++p2; if (target == 0) O (fatal, fstart, _("missing target pattern")); else if (target->next != 0) O (fatal, fstart, _("multiple target patterns")); pattern_percent = find_percent_cached (&target->name); pattern = target->name; if (pattern_percent == 0) O (fatal, fstart, _("target pattern contains no '%%'")); free_ns (target); } else pattern = 0; /* Strip leading and trailing whitespaces. */ beg = p2; end = beg + strlen (beg) - 1; strip_whitespace (&beg, &end); /* Put all the prerequisites here; they'll be parsed later. */ if (beg <= end && *beg != '\0') depstr = xstrndup (beg, end - beg + 1); else depstr = 0; commands_idx = 0; if (cmdleft != 0) { /* Semicolon means rest of line is a command. */ size_t l = strlen (cmdleft); cmds_started = fstart->lineno; /* Add this command line to the buffer. */ if (l + 2 > commands_len) { commands_len = (l + 2) * 2; commands = xrealloc (commands, commands_len); } memcpy (commands, cmdleft, l); commands_idx += l; commands[commands_idx++] = '\n'; } check_specials (filenames, set_default); } } #undef word1eq if (conditionals->if_cmds) O (fatal, fstart, _("missing 'endif'")); /* At eof, record the last rule. */ record_waiting_files (); free (collapsed); free (commands); } /* Remove comments from LINE. This will also remove backslashes that escape things. It ignores comment characters that appear inside variable references. */ static void remove_comments (char *line) { char *comment; comment = find_map_unquote (line, MAP_COMMENT|MAP_VARIABLE); if (comment != 0) /* Cut off the line at the #. */ *comment = '\0'; } /* Execute a 'undefine' directive. The undefine line has already been read, and NAME is the name of the variable to be undefined. */ static void do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf) { char *p, *var; /* Expand the variable name and find the beginning (NAME) and end. */ var = allocated_expand_string (name); name = next_token (var); if (*name == '\0') O (fatal, &ebuf->floc, _("empty variable name")); p = name + strlen (name) - 1; while (p > name && ISBLANK (*p)) --p; p[1] = '\0'; undefine_variable_global (&ebuf->floc, name, p - name + 1, origin); free (var); } /* Execute a 'define' directive. The first line has already been read, and NAME is the name of the variable to be defined. The following lines remain to be read. */ static struct variable * do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf) { struct variable *v; struct variable var; floc defstart; int nlevels = 1; size_t length = 100; char *definition = xmalloc (length); size_t idx = 0; char *p, *n; defstart = ebuf->floc; p = parse_variable_definition (name, &var); if (p == NULL) { /* No assignment token, so assume recursive. */ var.flavor = f_recursive; var.conditional = 0; } else { if (var.value[0] != '\0') O (error, &defstart, _("extraneous text after 'define' directive")); /* Chop the string before the assignment token to get the name. */ var.name[var.length] = '\0'; } /* Expand the variable name and find the beginning (NAME) and end. */ n = allocated_expand_string (name); name = next_token (n); if (name[0] == '\0') O (fatal, &defstart, _("empty variable name")); p = name + strlen (name) - 1; while (p > name && ISBLANK (*p)) --p; p[1] = '\0'; /* Now read the value of the variable. */ while (1) { size_t len; char *line; long nlines = readline (ebuf); /* If there is nothing left to be eval'd, there's no 'endef'!! */ if (nlines < 0) O (fatal, &defstart, _("missing 'endef', unterminated 'define'")); ebuf->floc.lineno += nlines; line = ebuf->buffer; collapse_continuations (line); /* If the line doesn't begin with a tab, test to see if it introduces another define, or ends one. Stop if we find an 'endef' */ if (line[0] != cmd_prefix) { p = next_token (line); len = strlen (p); /* If this is another 'define', increment the level count. */ if ((len == 6 || (len > 6 && ISBLANK (p[6]))) && strneq (p, "define", 6)) ++nlevels; /* If this is an 'endef', decrement the count. If it's now 0, we've found the last one. */ else if ((len == 5 || (len > 5 && ISBLANK (p[5]))) && strneq (p, "endef", 5)) { p += 5; remove_comments (p); if (*(next_token (p)) != '\0') O (error, &ebuf->floc, _("extraneous text after 'endef' directive")); if (--nlevels == 0) break; } } /* Add this line to the variable definition. */ len = strlen (line); if (idx + len + 1 > length) { length = (idx + len) * 2; definition = xrealloc (definition, length + 1); } memcpy (&definition[idx], line, len); idx += len; /* Separate lines with a newline. */ definition[idx++] = '\n'; } /* We've got what we need; define the variable. */ if (idx == 0) definition[0] = '\0'; else definition[idx - 1] = '\0'; v = do_variable_definition (&defstart, name, definition, origin, var.flavor, var.conditional, s_global); free (definition); free (n); return (v); } /* Interpret conditional commands "ifdef", "ifndef", "ifeq", "ifneq", "else" and "endif". LINE is the input line, with the command as its first word. FILENAME and LINENO are the filename and line number in the current makefile. They are used for error messages. Value is -2 if the line is not a conditional at all, -1 if the line is an invalid conditional, 0 if following text should be interpreted, 1 if following text should be ignored. */ static int conditional_line (char *line, size_t len, const floc *flocp) { const char *cmdname; enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; unsigned int i; unsigned int o; /* Compare a word, both length and contents. */ #define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s))) #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } /* Make sure this line is a conditional. */ chkword ("ifdef", c_ifdef) else chkword ("ifndef", c_ifndef) else chkword ("ifeq", c_ifeq) else chkword ("ifneq", c_ifneq) else chkword ("else", c_else) else chkword ("endif", c_endif) else return -2; /* Found one: skip past it and any whitespace after it. */ line += len; NEXT_TOKEN (line); #define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname) #define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname) /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */ if (cmdtype == c_endif) { if (*line != '\0') EXTRATEXT (); if (!conditionals->if_cmds) EXTRACMD (); --conditionals->if_cmds; goto DONE; } /* An 'else' statement can either be simple, or it can have another conditional after it. */ if (cmdtype == c_else) { const char *p; if (!conditionals->if_cmds) EXTRACMD (); o = conditionals->if_cmds - 1; if (conditionals->seen_else[o]) O (fatal, flocp, _("only one 'else' per conditional")); /* Change the state of ignorance. */ switch (conditionals->ignoring[o]) { case 0: /* We've just been interpreting. Never do it again. */ conditionals->ignoring[o] = 2; break; case 1: /* We've never interpreted yet. Maybe this time! */ conditionals->ignoring[o] = 0; break; } /* It's a simple 'else'. */ if (*line == '\0') { conditionals->seen_else[o] = 1; goto DONE; } /* The 'else' has extra text. That text must be another conditional and cannot be an 'else' or 'endif'. */ /* Find the length of the next word. */ for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p) ; len = p - line; /* If it's 'else' or 'endif' or an illegal conditional, fail. */ if (word1eq ("else") || word1eq ("endif") || conditional_line (line, len, flocp) < 0) EXTRATEXT (); else { /* conditional_line() created a new level of conditional. Raise it back to this level. */ if (conditionals->ignoring[o] < 2) conditionals->ignoring[o] = conditionals->ignoring[o+1]; --conditionals->if_cmds; } goto DONE; } if (conditionals->allocated == 0) { conditionals->allocated = 5; conditionals->ignoring = xmalloc (conditionals->allocated); conditionals->seen_else = xmalloc (conditionals->allocated); } o = conditionals->if_cmds++; if (conditionals->if_cmds > conditionals->allocated) { conditionals->allocated += 5; conditionals->ignoring = xrealloc (conditionals->ignoring, conditionals->allocated); conditionals->seen_else = xrealloc (conditionals->seen_else, conditionals->allocated); } /* Record that we have seen an 'if...' but no 'else' so far. */ conditionals->seen_else[o] = 0; /* Search through the stack to see if we're already ignoring. */ for (i = 0; i < o; ++i) if (conditionals->ignoring[i]) { /* We are already ignoring, so just push a level to match the next "else" or "endif", and keep ignoring. We don't want to expand variables in the condition. */ conditionals->ignoring[o] = 1; return 1; } if (cmdtype == c_ifdef || cmdtype == c_ifndef) { size_t l; char *var; struct variable *v; char *p; /* Expand the thing we're looking up, so we can use indirect and constructed variable names. */ var = allocated_expand_string (line); /* Make sure there's only one variable name to test. */ p = end_of_token (var); l = p - var; NEXT_TOKEN (p); if (*p != '\0') return -1; var[l] = '\0'; v = lookup_variable (var, l); conditionals->ignoring[o] = ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef)); free (var); } else { /* "ifeq" or "ifneq". */ char *s1, *s2; size_t l; char termin = *line == '(' ? ',' : *line; if (termin != ',' && termin != '"' && termin != '\'') return -1; s1 = ++line; /* Find the end of the first string. */ while (*line != '\0' && *line != termin) if (*line == '$') line = skip_reference (line+1); else ++line; if (*line == '\0') return -1; if (termin == ',') { /* Strip blanks before the comma. */ char *p = line++; while (ISBLANK (p[-1])) --p; *p = '\0'; } else *line++ = '\0'; s2 = expand_string (s1); /* We must allocate a new copy of the expanded string because expand_string re-uses the same buffer. */ l = strlen (s2); s1 = alloca (l + 1); memcpy (s1, s2, l + 1); if (termin != ',') /* Find the start of the second string. */ NEXT_TOKEN (line); termin = termin == ',' ? ')' : *line; if (termin != ')' && termin != '"' && termin != '\'') return -1; /* Find the end of the second string. */ if (termin == ')') { int count = 0; s2 = next_token (line); for (line = s2; *line != '\0'; ++line) { if (*line == '(') ++count; else if (*line == ')') { if (count <= 0) break; else --count; } } } else { ++line; s2 = line; while (*line != '\0' && *line != termin) ++line; } if (*line == '\0') return -1; *(line++) = '\0'; NEXT_TOKEN (line); if (*line != '\0') EXTRATEXT (); s2 = expand_string (s2); conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq)); } DONE: /* Search through the stack to see if we're ignoring. */ for (i = 0; i < conditionals->if_cmds; ++i) if (conditionals->ignoring[i]) return 1; return 0; } /* Record target-specific variable values for files FILENAMES. TWO_COLON is nonzero if a double colon was used. The links of FILENAMES are freed, and so are any names in it that are not incorporated into other data structures. If the target is a pattern, add the variable to the pattern-specific variable value list. */ static void record_target_var (struct nameseq *filenames, char *defn, enum variable_origin origin, struct vmodifiers *vmod, const floc *flocp) { struct nameseq *nextf; struct variable_set_list *global; global = current_variable_set_list; /* If the variable is an append version, store that but treat it as a normal recursive variable. */ for (; filenames != 0; filenames = nextf) { struct variable *v; const char *name = filenames->name; const char *percent; struct pattern_var *p; nextf = filenames->next; free_ns (filenames); /* If it's a pattern target, then add it to the pattern-specific variable list. */ percent = find_percent_cached (&name); if (percent) { /* Get a reference for this pattern-specific variable struct. */ p = create_pattern_var (name, percent); p->variable.fileinfo = *flocp; /* I don't think this can fail since we already determined it was a variable definition. */ v = assign_variable_definition (&p->variable, defn); assert (v != 0); v->origin = origin; if (v->flavor == f_simple) v->value = allocated_expand_string (v->value); else v->value = xstrdup (v->value); } else { struct file *f; /* Get a file reference for this file, and initialize it. We don't want to just call enter_file() because that allocates a new entry if the file is a double-colon, which we don't want in this situation. */ f = lookup_file (name); if (!f) f = enter_file (strcache_add (name)); else if (f->double_colon) f = f->double_colon; initialize_file_variables (f, 1); current_variable_set_list = f->variables; v = try_variable_definition (flocp, defn, origin, s_target); if (!v) O (fatal, flocp, _("malformed target-specific variable definition")); current_variable_set_list = global; } /* Set up the variable to be *-specific. */ v->per_target = 1; v->private_var = vmod->private_v; if (vmod->export_v != v_default) v->export = vmod->export_v; /* If it's not an override, check to see if there was a command-line setting. If so, reset the value. */ if (v->origin != o_override) { struct variable *gv; size_t len = strlen (v->name); gv = lookup_variable (v->name, len); if (gv && v != gv && (gv->origin == o_env_override || gv->origin == o_command)) { free (v->value); v->value = xstrdup (gv->value); v->origin = gv->origin; v->recursive = gv->recursive; v->append = 0; } } } } /* Check for special targets. We used to do this in record_files() but that's too late: by the time we get there we'll have already parsed the next line and it have been mis-parsed because these special targets haven't been considered yet. */ static void check_specials (struct nameseq *files, int set_default) { struct nameseq *t; for (t = files; t != NULL; t = t->next) { const char* nm = t->name; if (!posix_pedantic && streq (nm, ".POSIX")) { posix_pedantic = 1; define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0); /* These default values are based on IEEE Std 1003.1-2008. It requires '-O 1' for [CF]FLAGS, but GCC doesn't allow space between -O and the number so omit it here. */ define_variable_cname ("CC", "c99", o_default, 0); define_variable_cname ("CFLAGS", "-O1", o_default, 0); define_variable_cname ("FC", "fort77", o_default, 0); define_variable_cname ("FFLAGS", "-O1", o_default, 0); define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0); define_variable_cname ("ARFLAGS", "-rv", o_default, 0); continue; } if (!second_expansion && streq (nm, ".SECONDEXPANSION")) { second_expansion = 1; continue; } #if !MK_OS_DOS && !MK_OS_OS2 if (!one_shell && streq (nm, ".ONESHELL")) { one_shell = 1; continue; } #endif /* Determine if this target should be made default. */ if (set_default && default_goal_var->value[0] == '\0') { struct dep *d; int reject = 0; /* We have nothing to do if this is an implicit rule. */ if (strchr (nm, '%') != 0) break; /* See if this target's name does not start with a '.', unless it contains a slash. */ if (*nm == '.' && strchr (nm, '/') == 0 #ifdef HAVE_DOS_PATHS && strchr (nm, '\\') == 0 #endif ) continue; /* If this file is a suffix, it can't be the default goal file. */ for (d = suffix_file->deps; d != 0; d = d->next) { struct dep *d2; if (*dep_name (d) != '.' && streq (nm, dep_name (d))) { reject = 1; break; } for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) { size_t l = strlen (dep_name (d2)); if (!strneq (nm, dep_name (d2), l)) continue; if (streq (nm + l, dep_name (d))) { reject = 1; break; } } if (reject) break; } if (!reject) define_variable_global (".DEFAULT_GOAL", 13, t->name, o_file, 0, NILF); } } } /* Check for special targets. We used to do this in record_files() but that's too late: by the time we get there we'll have already parsed the next line and it have been mis-parsed because these special targets haven't been considered yet. */ static void check_special_file (struct file *file, const floc *flocp) { if (streq (file->name, ".WAIT")) { static unsigned int wpre = 0, wcmd = 0; if (!wpre && file->deps) { O (error, flocp, _(".WAIT should not have prerequisites")); wpre = 1; } if (!wcmd && file->cmds) { O (error, flocp, _(".WAIT should not have commands")); wcmd = 1; } return; } } /* Record a description line for files FILENAMES, with dependencies DEPS, commands to execute described by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED. TWO_COLON is nonzero if a double colon was used. If not nil, PATTERN is the '%' pattern to make this a static pattern rule, and PATTERN_PERCENT is a pointer to the '%' within it. The links of FILENAMES are freed, and so are any names in it that are not incorporated into other data structures. */ static void record_files (struct nameseq *filenames, int are_also_makes, const char *pattern, const char *pattern_percent, char *depstr, unsigned int cmds_started, char *commands, size_t commands_idx, int two_colon, char prefix, const floc *flocp) { struct commands *cmds; struct dep *deps; struct dep *also_make = NULL; const char *implicit_percent; const char *name; /* If we've already snapped deps, that means we're in an eval being resolved after the makefiles have been read in. We can't add more rules at this time, since they won't get snapped and we'll get core dumps. See Savannah bug # 12124. */ if (snapped_deps) O (fatal, flocp, _("prerequisites cannot be defined in recipes")); /* Determine if this is a pattern rule or not. */ name = filenames->name; implicit_percent = find_percent_cached (&name); /* If there's a recipe, set up a struct for it. */ if (commands_idx > 0) { cmds = xmalloc (sizeof (struct commands)); cmds->fileinfo.filenm = flocp->filenm; cmds->fileinfo.lineno = cmds_started; cmds->fileinfo.offset = 0; cmds->commands = xstrndup (commands, commands_idx); cmds->command_lines = 0; cmds->recipe_prefix = prefix; } else if (are_also_makes) O (fatal, flocp, _("grouped targets must provide a recipe")); else cmds = NULL; /* If there's a prereq string then parse it--unless it's eligible for 2nd expansion: if so, snap_deps() will do it. */ if (depstr == 0) deps = 0; else { depstr = unescape_char (depstr, ':'); if (second_expansion && strchr (depstr, '$')) { deps = alloc_dep (); deps->name = depstr; deps->need_2nd_expansion = 1; deps->staticpattern = pattern != 0; } else { deps = split_prereqs (depstr); free (depstr); /* We'll enter static pattern prereqs later when we have the stem. We don't want to enter pattern rules at all so that we don't think that they ought to exist (make manual "Implicit Rule Search Algorithm", item 5c). */ if (! pattern && ! implicit_percent) deps = enter_prereqs (deps, NULL); } } /* For implicit rules, _all_ the targets must have a pattern. That means we can test the first one to see if we're working with an implicit rule; if so we handle it specially. */ if (implicit_percent) { struct nameseq *nextf; const char **targets, **target_pats; unsigned short c; if (pattern != 0) O (fatal, flocp, _("mixed implicit and static pattern rules")); /* Count the targets to create an array of target names. We already have the first one. */ nextf = filenames->next; free_ns (filenames); filenames = nextf; for (c = 1; nextf; ++c, nextf = nextf->next) ; targets = xmalloc (c * sizeof (const char *)); target_pats = xmalloc (c * sizeof (const char *)); targets[0] = name; target_pats[0] = implicit_percent; c = 1; while (filenames) { name = filenames->name; implicit_percent = find_percent_cached (&name); if (implicit_percent == 0) O (fatal, flocp, _("mixed implicit and normal rules")); targets[c] = name; target_pats[c] = implicit_percent; ++c; nextf = filenames->next; free_ns (filenames); filenames = nextf; } create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1); return; } /* Walk through each target and create it in the database. We already set up the first target, above. */ while (1) { struct nameseq *nextf = filenames->next; struct file *f; struct dep *this = 0; free_ns (filenames); /* If this is a static pattern rule: 'targets: target%pattern: prereq%pattern; recipe', make sure the pattern matches this target name. */ if (pattern && !pattern_matches (pattern, pattern_percent, name)) OS (error, flocp, _("target '%s' doesn't match the target pattern"), name); else if (deps) /* If there are multiple targets, copy the chain DEPS for all but the last one. It is not safe for the same deps to go in more than one place in the database. */ this = nextf != 0 ? copy_dep_chain (deps) : deps; /* Find or create an entry in the file database for this target. */ if (!two_colon) { /* Single-colon. Combine this rule with the file's existing record, if any. */ f = enter_file (strcache_add (name)); if (f->double_colon) OS (fatal, flocp, _("target file '%s' has both : and :: entries"), f->name); /* If CMDS == F->CMDS, this target was listed in this rule more than once. Just give a warning since this is harmless. */ if (cmds != 0 && cmds == f->cmds) OS (error, flocp, _("target '%s' given more than once in the same rule"), f->name); /* Check for two single-colon entries both with commands. Check is_target so that we don't lose on files such as .c.o whose commands were preinitialized. */ else if (cmds != 0 && f->cmds != 0 && f->is_target) { size_t l = strlen (f->name); error (&cmds->fileinfo, l, _("warning: overriding recipe for target '%s'"), f->name); error (&f->cmds->fileinfo, l, _("warning: ignoring old recipe for target '%s'"), f->name); } /* Defining .DEFAULT with no deps or cmds clears it. */ if (f == default_file && this == 0 && cmds == 0) f->cmds = 0; if (cmds != 0) f->cmds = cmds; /* Defining .SUFFIXES with no dependencies clears out the list of suffixes. */ if (f == suffix_file && this == 0) { free_dep_chain (f->deps); f->deps = 0; } /* This file is explicitly mentioned as a target. There is no need to set is_explicit in the case of double colon below, because an implicit double colon rule only applies when the prerequisite exists. A prerequisite which exists is not intermediate anyway. */ f->is_explicit = 1; } else { /* Double-colon. Make a new record even if there already is one. */ f = lookup_file (name); /* Check for both : and :: rules. Check is_target so we don't lose on default suffix rules or makefiles. */ if (f != 0 && f->is_target && !f->double_colon) OS (fatal, flocp, _("target file '%s' has both : and :: entries"), f->name); f = enter_file (strcache_add (name)); /* If there was an existing entry and it was a double-colon entry, enter_file will have returned a new one, making it the prev pointer of the old one, and setting its double_colon pointer to the first one. */ if (f->double_colon == 0) /* This is the first entry for this name, so we must set its double_colon pointer to itself. */ f->double_colon = f; f->cmds = cmds; } if (are_also_makes) { struct dep *also = alloc_dep(); also->name = f->name; also->file = f; also->next = also_make; also_make = also; } f->is_target = 1; /* If this is a static pattern rule, set the stem to the part of its name that matched the '%' in the pattern, so you can use $* in the commands. If we didn't do it before, enter the prereqs now. */ if (pattern) { static const char *percent = "%"; char *o = patsubst_expand_pat (variable_buffer, name, pattern, percent, pattern_percent+1, percent+1); f->stem = strcache_add_len (variable_buffer, o - variable_buffer); if (this) { if (! this->need_2nd_expansion) this = enter_prereqs (this, f->stem); else this->stem = f->stem; } } /* Add the dependencies to this file entry. */ if (this != 0) { /* Add the file's old deps and the new ones in THIS together. */ if (f->deps == 0) f->deps = this; else if (cmds != 0) { struct dep *d = this; /* If this rule has commands, put these deps first. */ while (d->next != 0) d = d->next; d->next = f->deps; f->deps = this; } else { struct dep *d = f->deps; /* A rule without commands: put its prereqs at the end. */ while (d->next != 0) d = d->next; d->next = this; } } name = f->name; check_special_file (f, flocp); /* All done! Set up for the next one. */ if (nextf == 0) break; filenames = nextf; /* Reduce escaped percents. If there are any unescaped it's an error */ name = filenames->name; if (find_percent_cached (&name)) O (error, flocp, _("*** mixed implicit and normal rules: deprecated syntax")); } /* If there are also-makes, then populate a copy of the also-make list into each one. Omit the file from its also-make list. */ { struct dep *i; for (i = also_make; i != NULL; i = i->next) { struct file *f = i->file; struct dep *dp; if (f->also_make) { OS (error, &cmds->fileinfo, _("warning: overriding group membership for target '%s'"), f->name); free_dep_chain (f->also_make); f->also_make = NULL; } for (dp = also_make; dp != NULL; dp = dp->next) if (dp->file != f) { struct dep *cpy = copy_dep (dp); cpy->next = f->also_make; f->also_make = cpy; } } free_dep_chain (also_make); } } /* Search STRING for an unquoted STOPMAP. Backslashes quote elements from STOPMAP and backslash. Quoting backslashes are removed from STRING by compacting it into itself. Returns a pointer to the first unquoted STOPCHAR if there is one, or nil if there are none. If MAP_VARIABLE is set, then the complete contents of variable references are skipped, even if the contain STOPMAP characters. */ static char * find_map_unquote (char *string, int stopmap) { size_t string_len = 0; char *p = string; /* Always stop on NUL. */ stopmap |= MAP_NUL; while (1) { while (! STOP_SET (*p, stopmap)) ++p; if (*p == '\0') break; /* If we stopped due to a variable reference, skip over its contents. */ if (*p == '$') { p = skip_reference (p+1); continue; } if (p > string && p[-1] == '\\') { /* Search for more backslashes. */ int i = -2; while (&p[i] >= string && p[i] == '\\') --i; ++i; /* Only compute the length if really needed. */ if (string_len == 0) string_len = strlen (string); /* The number of backslashes is now -I. Copy P over itself to swallow half of them. */ { /* Avoid arithmetic conversion of negative values to unsigned. */ int hi = -(i/2); memmove (&p[i], &p[i/2], (string_len - (p - string)) + hi + 1); p += i/2; } if (i % 2 == 0) /* All the backslashes quoted each other; the STOPCHAR was unquoted. */ return p; /* The STOPCHAR was quoted by a backslash. Look for another. */ } else /* No backslash in sight. */ return p; } /* Never hit a STOPCHAR or blank (with BLANK nonzero). */ return 0; } static char * find_char_unquote (char *string, int stop) { size_t string_len = 0; char *p = string; while (1) { p = strchr(p, stop); if (!p) return NULL; if (p > string && p[-1] == '\\') { /* Search for more backslashes. */ int i = -2; while (&p[i] >= string && p[i] == '\\') --i; ++i; /* Only compute the length if really needed. */ if (string_len == 0) string_len = strlen (string); /* The number of backslashes is now -I. Copy P over itself to swallow half of them. */ { /* Avoid arithmetic conversion of negative values to unsigned. */ int hi = -(i/2); memmove (&p[i], &p[i/2], (string_len - (p - string)) + hi + 1); p += i/2; } if (i % 2 == 0) /* All the backslashes quoted each other; the STOPCHAR was unquoted. */ return p; /* The STOPCHAR was quoted by a backslash. Look for another. */ } else /* No backslash in sight. */ return p; } } /* Unescape a character in a string. The string is compressed onto itself. */ static char * unescape_char (char *string, int c) { char *p = string; char *s = string; while (*s != '\0') { if (*s == '\\') { char *e = s; size_t l; /* We found a backslash. See if it's escaping our character. */ while (*e == '\\') ++e; l = e - s; if (*e != c || l%2 == 0) { /* It's not; just take it all without unescaping. */ memmove (p, s, l); p += l; /* If we hit the end of the string, we're done. */ if (*e == '\0') break; } else if (l > 1) { /* It is, and there's >1 backslash. Take half of them. */ l /= 2; memmove (p, s, l); p += l; } s = e; } *(p++) = *(s++); } *p = '\0'; return string; } /* Search PATTERN for an unquoted % and handle quoting. */ char * find_percent (char *pattern) { return find_char_unquote (pattern, '%'); } /* Return a pointer to the first unescaped %, or NULL if there isn't one. Compress any escape chars up to the first unescaped %, but not afterward. This version is used with strings in the string cache: if there's a need to modify the string to handle escape chars a new version will be added to the string cache and *STRING will be set to that. */ const char * find_percent_cached (const char **string) { const char *p = strchr (*string, '%'); char *new, *np; size_t slen; /* If there is no % or there is but it's not escaped, reuse this string. */ if (!p || p == *string || p[-1] != '\\') return p; /* We must create a new cached string with backslashes compressed. */ slen = strlen (*string); new = alloca (slen + 1); memcpy (new, *string, slen + 1); np = new + (p - *string); do { /* Remember where the percent is. */ char *pp = np; int i = -2; /* This % is preceded by a backslash; search for more backslashes. */ while (&np[i] >= new && np[i] == '\\') --i; ++i; /* The number of backslashes is -I. Copy the string over itself to swallow half of them. */ { /* Avoid arithmetic conversion of negative values to unsigned. */ int hi = -(i/2); memmove (&pp[i], &pp[i/2], (slen - (pp - new)) + hi + 1); } /* Update SLEN and set NP to point after the %. */ slen += i/2 + i%2; np += i/2; /* If all backslashes quoted each other then % was unquoted. */ if (i % 2 == 0) break; np = strchr (np, '%'); } while (np && np[-1] == '\\'); /* Add the new string to the strcache. */ *string = strcache_add (new); /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */ return np ? *string + (np - new) : NULL; } /* Find the next line of text in an eval buffer, combining continuation lines into one line. Return the number of actual lines read (> 1 if continuation lines). Returns -1 if there's nothing left in the buffer. After this function, ebuf->buffer points to the first character of the line we just found. */ /* Read a line of text from a STRING. Since we aren't really reading from a file, don't bother with linenumbers. */ static long readstring (struct ebuffer *ebuf) { char *eol; /* If there is nothing left in this buffer, return 0. */ if (ebuf->bufnext >= ebuf->bufstart + ebuf->size) return -1; /* Set up a new starting point for the buffer, and find the end of the next logical line (taking into account backslash/newline pairs). */ eol = ebuf->buffer = ebuf->bufnext; while (1) { int backslash = 0; const char *bol = eol; const char *p; /* Find the next newline. At EOS, stop. */ p = eol = strchr (eol , '\n'); if (!eol) { ebuf->bufnext = ebuf->bufstart + ebuf->size + 1; return 0; } /* Found a newline; if it's escaped continue; else we're done. */ while (p > bol && *(--p) == '\\') backslash = !backslash; if (!backslash) break; ++eol; } /* Overwrite the newline char. */ *eol = '\0'; ebuf->bufnext = eol+1; return 0; } static long readline (struct ebuffer *ebuf) { char *p; char *end; char *start; long nlines = 0; /* The behaviors between string and stream buffers are different enough to warrant different functions. Do the Right Thing. */ if (!ebuf->fp) return readstring (ebuf); /* When reading from a file, we always start over at the beginning of the buffer for each new line. */ p = start = ebuf->bufstart; end = p + ebuf->size; *p = '\0'; while (fgets (p, (int) (end - p), ebuf->fp) != 0) { char *p2; size_t len; int backslash; len = strlen (p); if (len == 0) { /* This only happens when the first thing on the line is a '\0'. It is a pretty hopeless case, but (wonder of wonders) Athena lossage strikes again! (xmkmf puts NULs in its makefiles.) There is nothing really to be done; we synthesize a newline so the following line doesn't appear to be part of this line. */ O (error, &ebuf->floc, _("warning: NUL character seen; rest of line ignored")); p[0] = '\n'; len = 1; } /* Jump past the text we just read. */ p += len; /* If the last char isn't a newline, the whole line didn't fit into the buffer. Get some more buffer and try again. */ if (p[-1] != '\n') goto more_buffer; /* We got a newline, so add one to the count of lines. */ ++nlines; #if !MK_OS_W32 && !MK_OS_DOS && !MK_OS_OS2 /* Check to see if the line was really ended with CRLF; if so ignore the CR. */ if ((p - start) > 1 && p[-2] == '\r') { --p; memmove (p-1, p, strlen (p) + 1); } #endif backslash = 0; for (p2 = p - 2; p2 >= start; --p2) { if (*p2 != '\\') break; backslash = !backslash; } if (!backslash) { p[-1] = '\0'; break; } /* It was a backslash/newline combo. If we have more space, read another line. */ if (end - p >= 80) continue; /* We need more space at the end of our buffer, so realloc it. Make sure to preserve the current offset of p. */ more_buffer: { size_t off = p - start; ebuf->size *= 2; start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size); p = start + off; end = start + ebuf->size; *p = '\0'; } } if (ferror (ebuf->fp)) pfatal_with_name (ebuf->floc.filenm); /* If we found some lines, return how many. If we didn't, but we did find _something_, that indicates we read the last line of a file with no final newline; return 1. If we read nothing, we're at EOF; return -1. */ return nlines ? nlines : p == ebuf->bufstart ? -1 : 1; } /* Parse the next "makefile word" from the input buffer, and return info about it. This function won't be called in any context where we might need to parse a variable assignment so we don't need to check that. A "makefile word" is one of: w_bogus Should never happen w_eol End of input w_static A static word; cannot be expanded w_variable A word containing one or more variables/functions w_colon A colon w_dcolon A double-colon w_ampcolon An ampersand-colon (&:) token w_ampdcolon An ampersand-double-colon (&::) token w_semicolon A semicolon Note that this function is only used when reading certain parts of the makefile. Don't use it where special rules hold sway (RHS of a variable, in a recipe, etc.) */ static enum make_word_type get_next_mword (char *buffer, char **startp, size_t *length) { enum make_word_type wtype; char *p = buffer, *beg; char c; /* Skip any leading whitespace. */ while (ISSPACE (*p)) ++p; beg = p; c = *(p++); /* Look at the start of the word to see if it's simple. */ switch (c) { case '\0': wtype = w_eol; goto done; case ';': wtype = w_semicolon; goto done; case ':': wtype = w_colon; if (*p == ':') { ++p; wtype = w_dcolon; } goto done; case '&': if (*p == ':') { ++p; if (*p != ':') wtype = w_ampcolon; /* &: */ else { ++p; wtype = w_ampdcolon; /* &:: */ } goto done; } break; default: break; } /* This is some non-operator word. A word consists of the longest string of characters that doesn't contain whitespace, one of [:#], or &:. */ /* We start out assuming a static word; if we see a variable we'll adjust our assumptions then. */ wtype = w_static; while (1) { /* Each time through the loop, "c" has the current character and "p" points to the next character. */ if (END_OF_TOKEN (c)) goto done_word; switch (c) { case ':': #ifdef HAVE_DOS_PATHS /* A word CAN include a colon in its drive spec. The drive spec is allowed either at the beginning of a word, or as part of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */ if ((p - beg == 2 || (p - beg > 2 && p[-3] == '(')) && isalpha ((unsigned char)p[-2])) break; #endif goto done_word; case '$': c = *(p++); if (c == '$') break; if (c == '\0') goto done_word; /* This is a variable reference: note that then skip it. */ wtype = w_variable; p = skip_reference (p-1); break; case '\\': switch (*p) { case ':': case ';': case '=': case '\\': ++p; break; } break; case '&': if (*p == ':') goto done_word; break; default: break; } c = *(p++); } done_word: --p; done: if (startp) *startp = beg; if (length) *length = p - beg; return wtype; } /* Construct the list of include directories from the arguments and the default list. */ void construct_include_path (const char **arg_dirs) { #ifdef VAXC /* just don't ask ... */ stat_t stbuf; #else struct stat stbuf; #endif const char **dirs; const char **cpp; size_t idx; int disable = 0; /* Compute the number of pointers we need in the table. */ idx = ARRAYLEN (default_include_directories); if (arg_dirs) for (cpp = arg_dirs; *cpp != 0; ++cpp) ++idx; #if MK_OS_DOS /* Add one for $DJDIR. */ ++idx; #endif dirs = xmalloc (idx * sizeof (const char *)); idx = 0; max_incl_len = 0; /* First consider any dirs specified with -I switches. Ignore any that don't exist. Restart if we find "-". Remember the maximum string length. */ if (arg_dirs) while (*arg_dirs != 0) { const char *dir = *(arg_dirs++); char *expanded = 0; int e; if (dir[0] == '-' && dir[1] == '\0') { disable = 1; idx = 0; max_incl_len = 0; continue; } if (dir[0] == '~') { expanded = tilde_expand (dir); if (expanded != 0) dir = expanded; } EINTRLOOP (e, stat (dir, &stbuf)); if (e == 0 && S_ISDIR (stbuf.st_mode)) { size_t len = strlen (dir); /* If dir name is written with trailing slashes, discard them. */ while (len > 1 && dir[len - 1] == '/') --len; if (len > max_incl_len) max_incl_len = len; dirs[idx++] = strcache_add_len (dir, len); } free (expanded); } /* Now add the standard default dirs at the end. */ if (!disable) { #if MK_OS_DOS /* The environment variable $DJDIR holds the root of the DJGPP directory tree; add ${DJDIR}/include. */ struct variable *djdir = lookup_variable ("DJDIR", 5); if (djdir) { size_t len = strlen (djdir->value) + 8; char *defdir = alloca (len + 1); strcat (strcpy (defdir, djdir->value), "/include"); dirs[idx++] = strcache_add (defdir); if (len > max_incl_len) max_incl_len = len; } #endif for (cpp = default_include_directories; *cpp != 0; ++cpp) { int e; EINTRLOOP (e, stat (*cpp, &stbuf)); if (e == 0 && S_ISDIR (stbuf.st_mode)) { size_t len = strlen (*cpp); /* If dir name is written with trailing slashes, discard them. */ while (len > 1 && (*cpp)[len - 1] == '/') --len; if (len > max_incl_len) max_incl_len = len; dirs[idx++] = strcache_add_len (*cpp, len); } } } dirs[idx] = 0; /* Now add each dir to the .INCLUDE_DIRS variable. */ do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0, s_global); for (cpp = dirs; *cpp != 0; ++cpp) do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp, o_default, f_append, 0, s_global); free ((void *) include_directories); include_directories = dirs; } /* Expand ~ or ~USER at the beginning of NAME. Return a newly malloc'd string or 0. */ char * tilde_expand (const char *name) { #if !MK_OS_VMS if (name[1] == '/' || name[1] == '\0') { char *home_dir; int is_variable; { /* Turn off undefined variables warning while we expand HOME. */ enum warning_action save = warn_get (wt_undefined_var); warn_set (wt_undefined_var, w_ignore); home_dir = allocated_expand_variable (STRING_SIZE_TUPLE ("HOME")); warn_set (wt_undefined_var, save); } is_variable = home_dir[0] != '\0'; if (!is_variable) { free (home_dir); home_dir = getenv ("HOME"); } # if !MK_OS_W32 if (home_dir == 0 || home_dir[0] == '\0') { char *logname = getlogin (); home_dir = 0; if (logname != 0) { struct passwd *p = getpwnam (logname); if (p != 0) home_dir = p->pw_dir; } } # endif /* !MK_OS_W32 */ if (home_dir != 0) { char *new = xstrdup (concat (2, home_dir, name + 1)); if (is_variable) free (home_dir); return new; } } # if !MK_OS_W32 else { struct passwd *pwent; char *userend = strchr (name + 1, '/'); if (userend != 0) *userend = '\0'; pwent = getpwnam (name + 1); if (pwent != 0) { if (userend == 0) return xstrdup (pwent->pw_dir); *userend = '/'; return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); } else if (userend != 0) *userend = '/'; } # endif /* !MK_OS_W32 */ #endif /* !MK_OS_VMS */ return 0; } /* Parse a string into a sequence of filenames represented as a chain of struct nameseq's and return that chain. Optionally expand the strings via glob(). The string is passed as STRINGP, the address of a string pointer. The string pointer is updated to point at the first character not parsed, which either is a null char or equals STOPMAP. SIZE is how large (in bytes) each element in the new chain should be. This is useful if we want them actually to be other structures that have room for additional info. STOPMAP is a map of characters that tell us to stop parsing. PREFIX, if non-null, is added to the beginning of each filename. FLAGS allows one or more of the following bitflags to be set: PARSEFS_NOSTRIP - Do no strip './'s off the beginning PARSEFS_NOAR - Do not check filenames for archive references PARSEFS_NOGLOB - Do not expand globbing characters PARSEFS_EXISTS - Only return globbed files that actually exist (cannot also set NOGLOB) PARSEFS_NOCACHE - Do not add filenames to the strcache (caller frees) PARSEFS_ONEWORD - Don't break the sequence on whitespace PARSEFS_WAIT - Assume struct dep and handle .WAIT */ void * parse_file_seq (char **stringp, size_t size, int stopmap, const char *prefix, int flags) { /* tmp points to tmpbuf after the prefix, if any. tp is the end of the buffer. */ static char *tmpbuf = NULL; int cachep = NONE_SET (flags, PARSEFS_NOCACHE); struct nameseq *new = 0; struct nameseq **newp = &new; #define NEWELT(_n) do { \ struct nameseq *_ns = xcalloc (size); \ const char *__n = (_n); \ _ns->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \ if (found_wait) { \ ((struct dep*)_ns)->wait_here = 1; \ found_wait = 0; \ } \ *newp = _ns; \ newp = &_ns->next; \ } while(0) char *p; glob_t gl; char *tp; int findmap = stopmap|MAP_VMSCOMMA|MAP_NUL; int found_wait = 0; if (NONE_SET (flags, PARSEFS_ONEWORD)) findmap |= MAP_BLANK; /* Always stop on NUL. */ stopmap |= MAP_NUL; if (size < sizeof (struct nameseq)) size = sizeof (struct nameseq); if (NONE_SET (flags, PARSEFS_NOGLOB)) dir_setup_glob (&gl); /* Get enough temporary space to construct the largest possible target. */ { static size_t tmpbuf_len = 0; size_t l = strlen (*stringp) + 1; if (l > tmpbuf_len) { tmpbuf = xrealloc (tmpbuf, l); tmpbuf_len = l; } } tp = tmpbuf; /* Parse STRING. P will always point to the end of the parsed content. */ p = *stringp; while (1) { const char *name; const char **nlist = 0; char *tildep = 0; int globme = 1; #ifndef NO_ARCHIVES char *arname = 0; char *memname = 0; #endif char *s; size_t nlen; int tot, i; /* Skip whitespace; at the end of the string or STOPCHAR we're done. */ NEXT_TOKEN (p); if (STOP_SET (*p, stopmap)) break; /* There are names left, so find the end of the next name. Throughout this iteration S points to the start. */ s = p; p = find_map_unquote (p, findmap); #if MK_OS_VMS /* convert comma separated list to space separated */ if (p && *p == ',') *p =' '; #endif #ifdef HAVE_DOS_PATHS /* If we stopped due to a drive specifier, skip it. Tokens separated by spaces are treated as separate paths since make doesn't allow path names with spaces. */ if (p && p == s+1 && p[0] == ':' && isalpha ((unsigned char)s[0]) && ISDIRSEP (p[1])) p = find_map_unquote (p+1, findmap); #endif if (!p) p = s + strlen (s); if (ANY_SET (flags, PARSEFS_WAIT) && p - s == CSTRLEN (".WAIT") && memcmp (s, ".WAIT", CSTRLEN (".WAIT")) == 0) { /* Note that we found a .WAIT for the next dep but skip it. */ found_wait = 1; continue; } /* Strip leading "this directory" references. */ if (NONE_SET (flags, PARSEFS_NOSTRIP)) { #if MK_OS_VMS /* Skip leading '[]'s. should only be one set or bug somewhere else */ if (p - s > 2 && s[0] == '[' && s[1] == ']') s += 2; /* Skip leading '<>'s. should only be one set or bug somewhere else */ if (p - s > 2 && s[0] == '<' && s[1] == '>') s += 2; #endif /* Skip leading './'s. */ while (p - s > 2 && s[0] == '.' && s[1] == '/') { /* Skip "./" and all following slashes. */ s += 2; while (*s == '/') ++s; } } /* Extract the filename just found, and skip it. Set NAME to the string, and NLEN to its length. */ if (s == p) { /* The name was stripped to empty ("./"). */ tp[0] = '.'; tp[1] = '/'; tp[2] = '\0'; nlen = 2; } else { #if MK_OS_VMS /* VMS filenames can have a ':' in them but they have to be '\'ed but we need * to remove this '\' before we can use the filename. * xstrdup called because S may be read-only string constant. */ char *n = tp; while (s < p) { if (s[0] == '\\' && s[1] == ':') ++s; *(n++) = *(s++); } n[0] = '\0'; nlen = strlen (tp); #else nlen = p - s; memcpy (tp, s, nlen); tp[nlen] = '\0'; #endif } /* At this point, TP points to the element and NLEN is its length. */ #ifndef NO_ARCHIVES /* If this is the start of an archive group that isn't complete, set up to add the archive prefix for future files. A file list like: "libf.a(x.o y.o z.o)" needs to be expanded as: "libf.a(x.o) libf.a(y.o) libf.a(z.o)" TP == TMP means we're not already in an archive group. Ignore something starting with '(', as that cannot actually be an archive-member reference (and treating it as such results in an empty file name, which causes much lossage). Also if it ends in ")" then it's a complete reference so we don't need to treat it specially. Finally, note that archive groups must end with ')' as the last character, so ensure there's some word ending like that before considering this an archive group. */ if (NONE_SET (flags, PARSEFS_NOAR) && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')') { char *n = strchr (tp, '('); if (n) { /* This looks like the first element in an open archive group. A valid group MUST have ')' as the last character. */ const char *e = p; do { const char *o = e; NEXT_TOKEN (e); /* Find the end of this word. We don't want to unquote and we don't care about quoting since we're looking for the last char in the word. */ while (! STOP_SET (*e, findmap)) ++e; /* If we didn't move, we're done now. */ if (e == o) break; if (e[-1] == ')') { /* Found the end, so this is the first element in an open archive group. It looks like "lib(mem". Reset TP past the open paren. */ nlen -= (n + 1) - tp; tp = n + 1; /* We can stop looking now. */ break; } } while (*e != '\0'); /* If we have just "lib(", part of something like "lib( a b)", go to the next item. */ if (! nlen) continue; } } /* If we are inside an archive group, make sure it has an end. */ if (tp > tmpbuf) { if (tp[nlen-1] == ')') { /* This is the natural end; reset TP. */ tp = tmpbuf; /* This is just ")", something like "lib(a b )": skip it. */ if (nlen == 1) continue; } else { /* Not the end, so add a "fake" end. */ tp[nlen++] = ')'; tp[nlen] = '\0'; } } #endif /* If we're not globbing we're done: add it to the end of the chain. Go to the next item in the string. */ if (ANY_SET (flags, PARSEFS_NOGLOB)) { NEWELT (concat (2, prefix, tmpbuf)); continue; } /* If we get here we know we're doing glob expansion. TP is a string in tmpbuf. NLEN is no longer used. We may need to do more work: after this NAME will be set. */ name = tmpbuf; /* Expand tilde if applicable. */ if (tmpbuf[0] == '~') { tildep = tilde_expand (tmpbuf); if (tildep != 0) name = tildep; } #ifndef NO_ARCHIVES /* If NAME is an archive member reference replace it with the archive file name, and save the member name in MEMNAME. We will glob on the archive name and then reattach MEMNAME later. */ if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name)) { ar_parse_name (name, &arname, &memname); name = arname; } #endif /* !NO_ARCHIVES */ /* glob() is expensive: don't call it unless we need to. */ if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL) { globme = 0; tot = 1; nlist = &name; } else switch (glob (name, GLOB_ALTDIRFUNC, NULL, &gl)) { case GLOB_NOSPACE: out_of_memory (); case 0: /* Success. */ tot = gl.gl_pathc; nlist = (const char **)gl.gl_pathv; break; case GLOB_NOMATCH: /* If we want only existing items, skip this one. */ if (ANY_SET (flags, PARSEFS_EXISTS)) { tot = 0; break; } /* FALLTHROUGH */ default: /* By default keep this name. */ tot = 1; nlist = &name; break; } /* For each matched element, add it to the list. */ for (i = 0; i < tot; ++i) #ifndef NO_ARCHIVES if (memname != 0) { /* Try to glob on MEMNAME within the archive. */ struct nameseq *found = ar_glob (nlist[i], memname, size); if (! found) /* No matches. Use MEMNAME as-is. */ NEWELT (concat (5, prefix, nlist[i], "(", memname, ")")); else { /* We got a chain of items. Attach them. */ if (*newp) (*newp)->next = found; else *newp = found; /* Find and set the new end. Massage names if necessary. */ while (1) { if (! cachep) found->name = xstrdup (concat (2, prefix, name)); else if (prefix) found->name = strcache_add (concat (2, prefix, name)); if (found->next == 0) break; found = found->next; } newp = &found->next; } } else #endif /* !NO_ARCHIVES */ NEWELT (concat (2, prefix, nlist[i])); if (globme) globfree (&gl); #ifndef NO_ARCHIVES free (arname); #endif free (tildep); } *stringp = p; return new; } ================================================ FILE: src/remake.c ================================================ /* Basic dependency engine for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "job.h" #include "commands.h" #include "dep.h" #include "variable.h" #include "warning.h" #include "debug.h" #include #ifdef HAVE_FCNTL_H #include #else #include #endif #if MK_OS_VMS #include #endif #if MK_OS_W32 #include #include #include #if defined(_MSC_VER) && _MSC_VER > 1200 /* VC7 or later supports _stat64 to access 64-bit file size. */ #define STAT _stat64 #else #define STAT stat #endif #endif /* The test for circular dependencies is based on the 'updating' bit in 'struct file'. However, double colon targets have separate 'struct file's; make sure we always use the base of the double colon chain. */ #define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ ->updating = 1) #define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ ->updating = 0) #define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ ->updating) /* Incremented when a command is started (under -n, when one would be). */ unsigned int commands_started = 0; /* Set to the goal dependency. Mostly needed for remaking makefiles. */ static struct goaldep *goal_list; static struct dep *goal_dep; /* Current value for pruning the scan of the goal chain. All files start with considered == 0. */ static unsigned int considered = 0; /* During processing we might drop some dependencies, which can't be freed immediately because they are still in use. Remember them: this is mainly to satisfy leak detectors. */ static struct dep **dropped_list = NULL; static size_t dropped_list_len = 0; #define DROPPED_LIST_INCR 5 static enum update_status update_file (struct file *file, unsigned int depth); static enum update_status update_file_1 (struct file *file, unsigned int depth); static enum update_status check_dep (struct file *file, unsigned int depth, FILE_TIMESTAMP this_mtime, int *must_make); static enum update_status touch_file (struct file *file); static void remake_file (struct file *file); static FILE_TIMESTAMP name_mtime (const char *name); static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr); static void check_also_make (const struct file *file) { struct dep *ad; FILE_TIMESTAMP mtime = file->last_mtime; if (mtime == UNKNOWN_MTIME) mtime = name_mtime (file->name); /* If we updated the file, check its also-make files. */ if (is_ordinary_mtime (mtime) && mtime > file->mtime_before_update) for (ad = file->also_make; ad; ad = ad->next) if (ad->file->last_mtime == NONEXISTENT_MTIME) OS (error, file->cmds ? &file->cmds->fileinfo : NILF, _("warning: pattern recipe did not update peer target '%s'"), ad->file->name); } /* Remake all the goals in the 'struct dep' chain GOALS. Return update_status representing the totality of the status of the goals. If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q, and -n should be disabled for them unless they were also command-line targets, and we should only make one goal at a time and return as soon as one goal whose 'changed' member is nonzero is successfully made. */ enum update_status update_goal_chain (struct goaldep *goaldeps) { unsigned long last_cmd_count = 0; int t = touch_flag, q = question_flag, n = just_print_flag; enum update_status status = us_none; const unsigned int depth = rebuilding_makefiles ? 1 : 0; /* Duplicate the chain so we can remove things from it. */ struct dep *goals_orig = copy_dep_chain ((struct dep *)goaldeps); struct dep *goals = goals_orig; goal_list = rebuilding_makefiles ? goaldeps : NULL; #define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \ : file_mtime (file)) /* Start a fresh batch of consideration. */ ++considered; /* Update all the goals until they are all finished. */ while (goals != 0) { struct dep *gu, *g, *lastgoal; int running = 0, wait = 0; /* Start jobs that are waiting for the load to go down. */ start_waiting_jobs (); /* Check for exited children. If no children have finished since the last time we looked, then block until one exits. If some have exited don't block, so we can possibly do more work. */ reap_children (last_cmd_count == command_count, 0); last_cmd_count = command_count; lastgoal = 0; gu = goals; while (gu != 0) { /* Iterate over all double-colon entries for this file. */ struct file *file, *dchead; int stop = 0, all_updated = 1; g = gu->shuf ? gu->shuf : gu; goal_dep = g; dchead = g->file->double_colon ? g->file->double_colon : g->file; for (file = dchead; file != NULL; file = file->prev) { unsigned int ocommands_started; enum update_status fail; file->dontcare = ANY_SET (g->flags, RM_DONTCARE); check_renamed (file); if (rebuilding_makefiles) { if (file->cmd_target) { touch_flag = t; question_flag = q; just_print_flag = n; } else touch_flag = question_flag = just_print_flag = 0; } /* Save the old value of 'commands_started' so we can compare later. It will be incremented when any commands are actually run. */ ocommands_started = commands_started; stop = 0; /* In the case of double colon rules, only the recipe of the 1st rule should be blocked by .WAIT. The recipes of all subsequent rules for the same file will execute sequentially in order after the 1st. */ wait = file == dchead && g->wait_here && running; if (wait) { DBF (DB_VERBOSE, _(".WAIT is blocking '%s'.\n")); break; } fail = update_file (file, depth); check_renamed (file); running |= (file->command_state == cs_running || file->command_state == cs_deps_running); /* Set the goal's 'changed' flag if any commands were started by calling update_file above. We check this flag below to decide when to give an "up to date" diagnostic. */ if (commands_started > ocommands_started) g->changed = 1; if ((fail || file->updated) && status < us_question) { /* We updated this goal. Update STATUS and decide whether to stop. */ if (file->update_status) { /* Updating failed, or -q triggered. The STATUS value tells our caller which. */ status = file->update_status; /* If -q just triggered, stop immediately. It doesn't matter how much more we run, since we already know the answer to return. */ stop = (question_flag && !keep_going_flag && !rebuilding_makefiles); } else { FILE_TIMESTAMP mtime = MTIME (file); check_renamed (file); if (file->updated && mtime != file->mtime_before_update) { /* Updating was done. If this is a makefile and just_print_flag or question_flag is set (meaning -n or -q was given and this file was specified as a command-line target), don't change STATUS. If STATUS is changed, we will get re-exec'd, and enter an infinite loop. */ if (!rebuilding_makefiles || (!just_print_flag && !question_flag)) status = us_success; if (rebuilding_makefiles && file->dontcare) /* This is a default makefile; stop remaking. */ stop = 1; } } } /* Keep track if any double-colon entry is not finished. When they are all finished, the goal is finished. */ all_updated &= file->updated; file->dontcare = 0; if (stop) break; } /* Reset FILE since it is null at the end of the loop. */ file = g->file; if (wait) break; if (stop || all_updated) { /* If we have found nothing whatever to do for the goal, print a message saying nothing needs doing. */ if (!rebuilding_makefiles /* If the update_status is success, we updated successfully or not at all. G->changed will have been set above if any commands were actually started for this goal. */ && file->update_status == us_success && !g->changed /* Never give a message under -s or -q. */ && !run_silent && !question_flag) OS (message, 1, ((file->phony || file->cmds == 0) ? _("Nothing to be done for '%s'.") : _("'%s' is up to date.")), file->name); /* This goal is finished. Remove it from the chain. */ if (lastgoal == 0) goals = gu->next; else lastgoal->next = gu->next; if (stop) break; } else lastgoal = gu; gu = gu->next; } /* If we reached the end of the dependency graph update CONSIDERED for the next pass. In the case of waiting, increment CONSIDERED to prevent the same file from getting pruned over and over again. */ if (gu == 0 || wait) ++considered; } free_dep_chain (goals_orig); if (rebuilding_makefiles) { touch_flag = t; question_flag = q; just_print_flag = n; } return status; } /* If we're rebuilding an included makefile that failed, and we care about errors, show an error message the first time. */ void show_goal_error (void) { struct goaldep *goal; if ((goal_dep->flags & (RM_INCLUDED|RM_DONTCARE)) != RM_INCLUDED) return; for (goal = goal_list; goal; goal = goal->next) if (goal_dep->file == goal->file) { if (goal->error) { OSS (error, &goal->floc, "%s: %s", goal->file->name, strerror (goal->error)); goal->error = 0; } return; } } /* If FILE is not up to date, execute the commands for it. Return 0 if successful, non-0 if unsuccessful; but with some flag settings, just call 'exit' if unsuccessful. DEPTH is the depth in recursions of this function. We increment it during the consideration of our dependencies, then decrement it again after finding out whether this file is out of date. If there are multiple double-colon entries for FILE, each is considered in turn. */ static enum update_status update_file (struct file *file, unsigned int depth) { enum update_status status = us_success; struct file *f; f = file->double_colon ? file->double_colon : file; /* Prune the dependency graph: if we've already been here on _this_ pass through the dependency graph, we don't have to go any further. We won't reap_children until we start the next pass, so no state change is possible below here until then. */ if (f->considered == considered) { /* Check for the case where a target has been tried and failed but the diagnostics haven't been issued. If we need the diagnostics then we will have to continue. In the case of double colon rules, this file cannot be pruned if this recipe finished (file->command_state == cs_finished) and there are more double colon rules for this file. Instead the recipe of the next double colon rule of this file should be run. */ if (!(f->updated && f->update_status > us_none && !f->dontcare && f->no_diag) && !(file->double_colon && file->command_state == cs_finished && f->prev)) { DBF (DB_VERBOSE, _("Pruning file '%s'.\n")); return f->command_state == cs_finished ? f->update_status : us_success; } } /* This loop runs until we start commands for a double colon rule, or until the chain is exhausted. */ for (; f != 0; f = f->prev) { enum update_status new; f->considered = considered; new = update_file_1 (f, depth); check_renamed (f); /* Clean up any alloca() used during the update. */ free_alloca (); /* If we got an error, don't bother with double_colon etc. */ if (new && !keep_going_flag) return new; if (f->command_state == cs_running || f->command_state == cs_deps_running) /* Don't run other :: rules for this target until this rule is finished. Multiple recipes running in parallel and updating the same target will corrupt the target. */ return us_success; if (new > status) status = new; } return status; } /* Show a message stating the target failed to build. */ static void complain (struct file *file) { /* If this file has no_diag set then it means we tried to update it before in the dontcare mode and failed. The target that actually failed is not necessarily this file but could be one of its direct or indirect dependencies. So traverse this file's dependencies and find the one that actually caused the failure. */ struct dep *d; for (d = file->deps; d != 0; d = d->next) { if (d->file->updated && d->file->update_status > us_none && file->no_diag) { complain (d->file); break; } } if (d == 0) { show_goal_error (); /* Didn't find any dependencies to complain about. */ if (file->parent) { size_t l = strlen (file->name) + strlen (file->parent->name) + 4; const char *m = _("%sNo rule to make target '%s', needed by '%s'%s"); if (!keep_going_flag) fatal (NILF, l, m, "", file->name, file->parent->name, ""); error (NILF, l, m, "*** ", file->name, file->parent->name, "."); } else { size_t l = strlen (file->name) + 4; const char *m = _("%sNo rule to make target '%s'%s"); if (!keep_going_flag) fatal (NILF, l, m, "", file->name, ""); error (NILF, l, m, "*** ", file->name, "."); } file->no_diag = 0; } } /* Consider a single 'struct file' and update it as appropriate. Return an update_status value; use us_success if we aren't sure yet. */ static enum update_status update_file_1 (struct file *file, unsigned int depth) { enum update_status dep_status = us_success; FILE_TIMESTAMP this_mtime; int noexist, must_make, deps_changed; struct file *ofile; struct dep *du, *d, *ad; struct dep amake; int running = 0; DBF (DB_VERBOSE, _("Considering target file '%s'.\n")); if (file->updated) { if (file->update_status > us_none) { DBF (DB_VERBOSE, _("Recently tried and failed to update file '%s'.\n")); /* If the file we tried to make is marked no_diag then no message was printed about it when it failed during the makefile rebuild. If we're trying to build it again in the normal rebuild, print a message now. */ if (file->no_diag && !file->dontcare) complain (file); return file->update_status; } DBF (DB_VERBOSE, _("File '%s' was considered already.\n")); return us_success; } switch (file->command_state) { case cs_not_started: case cs_deps_running: break; case cs_running: DBF (DB_VERBOSE, _("Still updating file '%s'.\n")); return us_success; case cs_finished: DBF (DB_VERBOSE, _("Finished updating file '%s'.\n")); return file->update_status; default: abort (); } /* Determine whether the diagnostics will be issued should this update fail. */ file->no_diag = file->dontcare; /* Notice recursive update of the same file. */ start_updating (file); /* We might change file if we find a different one via vpath; remember this one to turn off updating. */ ofile = file; /* Increase the depth for reporting how we build the file. */ ++depth; /* Looking at the file's modtime beforehand allows the possibility that its name may be changed by a VPATH search, and thus it may not need an implicit rule. If this were not done, the file might get implicit commands that apply to its initial name, only to have that name replaced with another found by VPATH search. */ this_mtime = file_mtime (file); check_renamed (file); noexist = this_mtime == NONEXISTENT_MTIME; if (noexist) { if (file->phony) DBF (DB_BASIC, _("Target '%s' is phony.\n")); else DBF (DB_BASIC, _("File '%s' does not exist.\n")); } else if (is_ordinary_mtime (this_mtime) && file->low_resolution_time) { /* Avoid spurious rebuilds due to low resolution time stamps. */ int ns = FILE_TIMESTAMP_NS (this_mtime); if (ns != 0) OS (error, NILF, _("*** warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"), file->name); this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns; } /* If any also_make target doesn't exist, we must remake this one too. If they do exist choose the oldest mtime so they will rebuild. */ for (ad = file->also_make; ad && !noexist; ad = ad->next) { struct file *adfile = ad->file; FILE_TIMESTAMP fmtime = file_mtime (adfile); noexist = fmtime == NONEXISTENT_MTIME; if (noexist) { check_renamed (adfile); if (adfile->phony) DBS (DB_BASIC, (_("Grouped target peer '%s' of file '%s' is phony.\n"), adfile->name, file->name)); else DBS (DB_BASIC, (_("Grouped target peer '%s' of file '%s' does not exist.\n"), adfile->name, file->name)); } else if (fmtime < this_mtime) this_mtime = fmtime; } must_make = noexist; /* If file was specified as a target with no commands, come up with some default commands. This may also add more also_make files. */ if (!file->phony && file->cmds == 0 && !file->tried_implicit) { try_implicit_rule (file, depth); file->tried_implicit = 1; } if (file->cmds == 0 && !file->is_target && default_file != 0 && default_file->cmds != 0) { DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n")); file->cmds = default_file->cmds; } /* Update all non-intermediate files we depend on, if necessary, and see whether any of them is more recent than this file. We need to walk our deps, AND the deps of any also_make targets to ensure everything happens in the correct order. */ amake.file = file; amake.next = file->also_make; ad = &amake; while (ad) { struct dep *lastd = 0; /* Perform second expansion and enter each dependency name as a file. We only need to do this if second_expansion has been defined; if it hasn't then all deps were expanded as the makefile was read in. */ if (second_expansion) expand_deps (ad->file); /* Find the deps we're scanning */ du = ad->file->deps; ad = ad->next; while (du) { enum update_status new; FILE_TIMESTAMP mtime; int maybe_make; int dontcare = 0; d = du->shuf ? du->shuf : du; if (d->wait_here && running) break; check_renamed (d->file); mtime = file_mtime (d->file); check_renamed (d->file); if (is_updating (d->file)) { /* Avoid macro warning, bacause its output differs from that of older makes. */ if (warn_error (wt_circular_dep)) OSS (fatal, NILF, _("circular %s <- %s dependency detected"), file->name, d->file->name); if (warn_check (wt_circular_dep)) OSS (error, NILF, _("circular %s <- %s dependency dropped"), file->name, d->file->name); if (lastd == 0) file->deps = du->next; else lastd->next = du->next; du = du->next; /* We cannot free D here because our the caller will still have a reference to it when we were called recursively via check_dep below. */ if (dropped_list_len % DROPPED_LIST_INCR == 0) dropped_list = xrealloc (dropped_list, sizeof (struct dep *) * (dropped_list_len + DROPPED_LIST_INCR)); dropped_list[dropped_list_len++] = d; continue; } d->file->parent = file; maybe_make = must_make; /* Inherit dontcare flag from our parent. */ if (rebuilding_makefiles) { dontcare = d->file->dontcare; d->file->dontcare = file->dontcare; } new = check_dep (d->file, depth, this_mtime, &maybe_make); if (new > dep_status) dep_status = new; /* Restore original dontcare flag. */ if (rebuilding_makefiles) d->file->dontcare = dontcare; if (! d->ignore_mtime) must_make = maybe_make; check_renamed (d->file); { struct file *f = d->file; if (f->double_colon) f = f->double_colon; do { running |= (f->command_state == cs_running || f->command_state == cs_deps_running); f = f->prev; } while (f != 0); } if (dep_status && !keep_going_flag) break; if (!running) /* The prereq is considered changed if the timestamp has changed while it was built, OR it doesn't exist. */ d->changed = ((file_mtime (d->file) != mtime) || (mtime == NONEXISTENT_MTIME)); lastd = du; du = du->next; } } /* Now we know whether this target needs updating. If it does, update all the intermediate files we depend on. */ if (must_make || always_make_flag) { for (du = file->deps; du != 0; du = du->next) { d = du->shuf ? du->shuf : du; if (d->wait_here && running) break; if (d->file->intermediate) { enum update_status new; int dontcare = 0; FILE_TIMESTAMP mtime = file_mtime (d->file); check_renamed (d->file); d->file->parent = file; /* Inherit dontcare flag from our parent. */ if (rebuilding_makefiles) { dontcare = d->file->dontcare; d->file->dontcare = file->dontcare; } /* We may have already considered this file, when we didn't know we'd need to update it. Force update_file() to consider it and not prune it. */ d->file->considered = 0; new = update_file (d->file, depth); if (new > dep_status) dep_status = new; /* Restore original dontcare flag. */ if (rebuilding_makefiles) d->file->dontcare = dontcare; check_renamed (d->file); { struct file *f = d->file; if (f->double_colon) f = f->double_colon; do { running |= (f->command_state == cs_running || f->command_state == cs_deps_running); f = f->prev; } while (f != 0); } if (dep_status && !keep_going_flag) break; if (!running) d->changed = ((file->phony && file->cmds != 0) || file_mtime (d->file) != mtime); } } } finish_updating (file); finish_updating (ofile); /* We've decided what we need to do to build the file. */ --depth; if (running) { set_command_state (file, cs_deps_running); DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n")); return us_success; } DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n")); /* If any dependency failed, give up now. */ if (dep_status) { /* I'm not sure if we can't just assign dep_status... */ file->update_status = dep_status == us_none ? us_failed : dep_status; notice_finished_file (file); DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n")); if (depth == 0 && keep_going_flag && !just_print_flag && !question_flag) OS (error, NILF, _("Target '%s' not remade because of errors."), file->name); return dep_status; } if (file->command_state == cs_deps_running) /* The commands for some deps were running on the last iteration, but they have finished now. Reset the command_state to not_started to simplify later bookkeeping. It is important that we do this only when the prior state was cs_deps_running, because that prior state was definitely propagated to FILE's also_make's by set_command_state (called above), but in another state an also_make may have independently changed to finished state, and we would confuse that file's bookkeeping (updated, but not_started is bogus state). */ set_command_state (file, cs_not_started); /* Now record which prerequisites are more recent than this file, so we can define $?. */ deps_changed = 0; for (d = file->deps; d != 0; d = d->next) { FILE_TIMESTAMP d_mtime = file_mtime (d->file); check_renamed (d->file); if (! d->ignore_mtime) { #if 1 /* %%% In version 4, remove this code completely to implement not remaking deps if their deps are newer than their parents. */ if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate) /* We must remake if this dep does not exist and is not intermediate. */ must_make = 1; #endif /* Set DEPS_CHANGED if this dep actually changed. */ deps_changed |= d->changed; } /* Set D->changed if either this dep actually changed, or its dependent, FILE, is older or does not exist. */ d->changed |= noexist || d_mtime > this_mtime; if (!noexist && ISDB (DB_BASIC|DB_VERBOSE)) { const char *fmt = 0; if (d->ignore_mtime) { if (ISDB (DB_VERBOSE)) fmt = _("Prerequisite '%s' is order-only for target '%s'.\n"); } else if (d_mtime == NONEXISTENT_MTIME) { if (ISDB (DB_BASIC)) { if (d->file->phony) fmt = _("Prerequisite '%s' of target '%s' is phony.\n"); else fmt = _("Prerequisite '%s' of target '%s' does not exist.\n"); } } else if (d->changed) { if (ISDB (DB_BASIC)) fmt = _("Prerequisite '%s' is newer than target '%s'.\n"); } else if (ISDB (DB_VERBOSE)) fmt = _("Prerequisite '%s' is older than target '%s'.\n"); if (fmt) { print_spaces (depth+1); printf (fmt, dep_name (d), file->name); fflush (stdout); } } } if (file->double_colon && file->deps == 0) { must_make = 1; DBF (DB_BASIC, _("Target '%s' is double-colon and has no prerequisites.\n")); } else if (!noexist && file->is_target && !deps_changed && file->cmds == 0 && !always_make_flag) { must_make = 0; DBF (DB_VERBOSE, _("No recipe for '%s' and no prerequisites actually changed.\n")); } else if (!must_make && file->cmds != 0 && always_make_flag) { must_make = 1; DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n")); } if (!must_make) { if (ISDB (DB_VERBOSE)) { print_spaces (depth); printf (_("No need to remake target '%s'"), file->name); if (!streq (file->name, file->hname)) printf (_("; using VPATH name '%s'"), file->hname); puts ("."); fflush (stdout); } /* Since make has not created this file, make should not remove it, even if the file is intermediate. */ if (!file->notintermediate && no_intermediates == 0) file->secondary = 1; notice_finished_file (file); /* Since we don't need to remake the file, convert it to use the VPATH filename if we found one. hfile will be either the local name if no VPATH or the VPATH name if one was found. */ while (file) { file->name = file->hname; file = file->prev; } return us_success; } DBF (DB_BASIC, _("Must remake target '%s'.\n")); /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the VPATH. */ if (!streq (file->name, file->hname)) { DB (DB_BASIC, (_(" Ignoring VPATH name '%s'.\n"), file->hname)); file->ignore_vpath = 1; } /* Now, take appropriate actions to remake the file. */ remake_file (file); if (file->command_state != cs_finished) { DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n")); return us_success; } switch (file->update_status) { case us_failed: DBF (DB_BASIC, _("Failed to remake target file '%s'.\n")); break; case us_success: DBF (DB_BASIC, _("Successfully remade target file '%s'.\n")); break; case us_question: DBF (DB_BASIC, _("Target file '%s' needs to be remade under -q.\n")); break; case us_none: break; } file->updated = 1; return file->update_status; } /* Set FILE's 'updated' flag and re-check its mtime and the mtime's of all files listed in its 'also_make' member. Under -t, this function also touches FILE. On return, FILE->update_status will no longer be us_none if it was. */ void notice_finished_file (struct file *file) { struct dep *d; int ran = file->command_state == cs_running; int touched = 0; file->command_state = cs_finished; file->updated = 1; if (touch_flag /* The update status will be: us_success if 0 or more commands (+ or ${MAKE}) were run and won; us_none if this target was not remade; >us_none if some commands were run and lost. We touch the target if it has commands which either were not run or won when they ran (i.e. status is 0). */ && file->update_status == us_success) { if (file->cmds != 0 && file->cmds->any_recurse) { /* If all the command lines were recursive, we don't want to do the touching. */ unsigned int i; for (i = 0; i < file->cmds->ncommand_lines; ++i) if (NONE_SET (file->cmds->lines_flags[i], COMMANDS_RECURSE)) goto have_nonrecursing; } else { have_nonrecursing: if (file->phony) file->update_status = us_success; /* According to POSIX, -t doesn't affect targets with no cmds. */ else if (file->cmds != 0) { /* Should set file's modification date and do nothing else. */ file->update_status = touch_file (file); /* Pretend we ran a real touch command, to suppress the "'foo' is up to date" message. */ commands_started++; /* Request for the timestamp to be updated (and distributed to the double-colon entries). Simply setting ran=1 would almost have done the trick, but messes up with the also_make updating logic below. */ touched = 1; } } } if (file->mtime_before_update == UNKNOWN_MTIME) file->mtime_before_update = file->last_mtime; if ((ran && !file->phony) || touched) { int i = 0; /* If -n, -t, or -q and all the commands are recursive, we ran them so really check the target's mtime again. Otherwise, assume the target would have been updated. */ if ((question_flag || just_print_flag || touch_flag) && file->cmds) { for (i = file->cmds->ncommand_lines; i > 0; --i) if (NONE_SET (file->cmds->lines_flags[i-1], COMMANDS_RECURSE)) break; } /* If there were no commands at all, it's always new. */ else if (file->is_target && file->cmds == 0) i = 1; file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME; } if (file->double_colon) { /* If this is a double colon rule and it is the last one to be updated, propagate the change of modification time to all the double-colon entries for this file. We do it on the last update because it is important to handle individual entries as separate rules with separate timestamps while they are treated as targets and then as one rule with the unified timestamp when they are considered as a prerequisite of some target. */ struct file *f; FILE_TIMESTAMP max_mtime = file->last_mtime; /* Check that all rules were updated and at the same time find the max timestamp. We assume UNKNOWN_MTIME is newer then any other value. */ for (f = file->double_colon; f != 0 && f->updated; f = f->prev) if (max_mtime != UNKNOWN_MTIME && (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime)) max_mtime = f->last_mtime; if (f == 0) for (f = file->double_colon; f != 0; f = f->prev) f->last_mtime = max_mtime; } if (ran && file->update_status != us_none) { /* We actually tried to update FILE, which has updated its also_make's as well (if it worked). If it didn't work, it wouldn't work again for them. So mark them as updated with the same status. */ for (d = file->also_make; d != 0; d = d->next) { d->file->command_state = cs_finished; d->file->updated = 1; d->file->update_status = file->update_status; if (ran && !d->file->phony) { /* Fetch the new modification time. We do this instead of just invalidating the cached time so that a vpath_search can happen. Otherwise, it would never be done because the target is already updated. */ f_mtime (d->file, 0); if (just_print_flag) /* Nothing got updated, but pretend it did. */ d->file->last_mtime = NEW_MTIME; } } /* If the target was created by an implicit rule, and it was updated, warn about any of its also_make targets that don't exist. */ if (file->tried_implicit && file->also_make) check_also_make (file); } else if (file->update_status == us_none) /* Nothing was done for FILE, but it needed nothing done. So mark it now as "succeeded". */ file->update_status = us_success; } /* Check whether another file (whose mtime is THIS_MTIME) needs updating on account of a dependency which is file FILE. If it does, store 1 in *MUST_MAKE_PTR. In the process, update any non-intermediate files that FILE depends on (including FILE itself). Return nonzero if any updating failed. */ static enum update_status check_dep (struct file *file, unsigned int depth, FILE_TIMESTAMP this_mtime, int *must_make_ptr) { struct file *ofile; struct dep *d; enum update_status dep_status = us_success; start_updating (file); /* We might change file if we find a different one via vpath; remember this one to turn off updating. */ ofile = file; if (file->phony || !file->intermediate) { /* If this is a non-intermediate file, update it and record whether it is newer than THIS_MTIME. */ FILE_TIMESTAMP mtime; dep_status = update_file (file, depth); check_renamed (file); mtime = file_mtime (file); check_renamed (file); if (mtime == NONEXISTENT_MTIME || mtime > this_mtime) *must_make_ptr = 1; } else { /* FILE is an intermediate file. */ FILE_TIMESTAMP mtime; if (!file->phony && file->cmds == 0 && !file->tried_implicit) { try_implicit_rule (file, depth); file->tried_implicit = 1; } if (file->cmds == 0 && !file->is_target && default_file != 0 && default_file->cmds != 0) { DBF (DB_IMPLICIT, _("Using default commands for '%s'.\n")); file->cmds = default_file->cmds; } check_renamed (file); mtime = file_mtime (file); check_renamed (file); if (mtime != NONEXISTENT_MTIME && mtime > this_mtime) /* If the intermediate file actually exists and is newer, then we should remake from it. */ *must_make_ptr = 1; else { /* Otherwise, update all non-intermediate files we depend on, if necessary, and see whether any of them is more recent than the file on whose behalf we are checking. */ struct dep *ld; int deps_running = 0; /* If this target is not running, set it's state so that we check it fresh. It could be it was checked as part of an order-only prerequisite and so wasn't rebuilt then, but should be now. */ if (file->command_state != cs_running) { /* If the target was waiting for a dependency it has to be reconsidered, as that dependency might have finished. */ if (file->command_state == cs_deps_running) file->considered = 0; set_command_state (file, cs_not_started); } ld = 0; /* Perform second expansion and enter each dependency name as a file. We only need to do this if second_expansion has been defined; if it hasn't then all deps were expanded as the makefile was read in. */ if (second_expansion) expand_deps (file); d = file->deps; while (d != 0) { enum update_status new; int maybe_make; if (is_updating (d->file)) { OSS (error, NILF, _("circular %s <- %s dependency dropped"), file->name, d->file->name); if (ld == 0) { file->deps = d->next; free_dep (d); d = file->deps; } else { ld->next = d->next; free_dep (d); d = ld->next; } continue; } d->file->parent = file; maybe_make = *must_make_ptr; new = check_dep (d->file, depth+1, this_mtime, &maybe_make); if (new > dep_status) dep_status = new; if (! d->ignore_mtime) *must_make_ptr = maybe_make; check_renamed (d->file); if (dep_status && !keep_going_flag) break; if (d->file->command_state == cs_running || d->file->command_state == cs_deps_running) deps_running = 1; ld = d; d = d->next; } if (deps_running) /* Record that some of FILE's deps are still being made. This tells the upper levels to wait on processing it until the commands are finished. */ set_command_state (file, cs_deps_running); } } finish_updating (file); finish_updating (ofile); return dep_status; } /* Touch FILE. Return us_success if successful, us_failed if not. */ #define TOUCH_ERROR(call) do{ perror_with_name ((call), file->name); \ return us_failed; }while(0) static enum update_status touch_file (struct file *file) { if (!run_silent) OS (message, 0, "touch %s", file->name); /* Print-only (-n) takes precedence over touch (-t). */ if (just_print_flag) return us_success; #ifndef NO_ARCHIVES if (ar_name (file->name)) return ar_touch (file->name) ? us_failed : us_success; else #endif { int fd; EINTRLOOP (fd, open (file->name, O_RDWR | O_CREAT, 0666)); if (fd < 0) TOUCH_ERROR ("touch: open: "); else { struct stat statbuf; char buf = 'x'; int e; EINTRLOOP (e, fstat (fd, &statbuf)); if (e < 0) TOUCH_ERROR ("touch: fstat: "); /* Rewrite character 0 same as it already is. */ EINTRLOOP (e, read (fd, &buf, 1)); if (e < 0) TOUCH_ERROR ("touch: read: "); { off_t o; EINTRLOOP (o, lseek (fd, 0L, 0)); if (o < 0L) TOUCH_ERROR ("touch: lseek: "); } EINTRLOOP (e, write (fd, &buf, 1)); if (e < 0) TOUCH_ERROR ("touch: write: "); /* If file length was 0, we just changed it, so change it back. */ if (statbuf.st_size == 0) { (void) close (fd); EINTRLOOP (fd, open (file->name, O_RDWR | O_TRUNC, 0666)); if (fd < 0) TOUCH_ERROR ("touch: open: "); } (void) close (fd); } } return us_success; } /* Having checked and updated the dependencies of FILE, do whatever is appropriate to remake FILE itself. Return the status from executing FILE's commands. */ static void remake_file (struct file *file) { if (file->cmds == 0) { if (file->phony) /* Phony target. Pretend it succeeded. */ file->update_status = us_success; else if (file->is_target) /* This is a nonexistent target file we cannot make. Pretend it was successfully remade. */ file->update_status = us_success; else { /* This is a dependency file we cannot remake. Fail. */ if (!rebuilding_makefiles || !file->dontcare) complain (file); file->update_status = us_failed; } } else { chop_commands (file->cmds); /* The normal case: start some commands. */ if (!touch_flag || file->cmds->any_recurse) { execute_file_commands (file); return; } /* This tells notice_finished_file it is ok to touch the file. */ file->update_status = us_success; } /* This does the touching under -t. */ notice_finished_file (file); } /* Return the mtime of a file, given a 'struct file'. Caches the time in the struct file to avoid excess stat calls. If the file is not found, and SEARCH is nonzero, VPATH searching and replacement is done. If that fails, a library (-lLIBNAME) is tried and the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into FILE. */ FILE_TIMESTAMP f_mtime (struct file *file, int search) { FILE_TIMESTAMP mtime; unsigned int propagate_timestamp; /* File's mtime is not known; must get it from the system. */ #ifndef NO_ARCHIVES if (ar_name (file->name)) { /* This file is an archive-member reference. */ FILE_TIMESTAMP memmtime; char *arname, *memname; struct file *arfile; time_t member_date; /* Find the archive's name. */ ar_parse_name (file->name, &arname, &memname); /* Find the mtime of the member file (it might not exist). */ memmtime = name_mtime (memname); /* Find the modification time of the archive itself. Also allow for its name to be changed via VPATH search. */ arfile = lookup_file (arname); if (arfile == 0) arfile = enter_file (strcache_add (arname)); mtime = f_mtime (arfile, search); check_renamed (arfile); if (search && strcmp (arfile->hname, arname)) { /* The archive's name has changed. Change the archive-member reference accordingly. */ char *name; size_t arlen, memlen; arlen = strlen (arfile->hname); memlen = strlen (memname); name = alloca (arlen + 1 + memlen + 2); memcpy (name, arfile->hname, arlen); name[arlen] = '('; memcpy (name + arlen + 1, memname, memlen); name[arlen + 1 + memlen] = ')'; name[arlen + 1 + memlen + 1] = '\0'; /* If the archive was found with GPATH, make the change permanent; otherwise defer it until later. */ if (arfile->name == arfile->hname) rename_file (file, strcache_add (name)); else rehash_file (file, strcache_add (name)); check_renamed (file); } free (arname); file->low_resolution_time = 1; if (mtime == NONEXISTENT_MTIME) /* The archive doesn't exist, so its members don't exist either. */ return NONEXISTENT_MTIME; member_date = ar_member_date (file->hname); if (member_date == (time_t) -1 || (memmtime != NONEXISTENT_MTIME && (time_t) FILE_TIMESTAMP_S (memmtime) > member_date)) /* If the member file exists and is newer than the member in the archive, pretend it's nonexistent. This means the member file was updated but not added to the archive yet. */ mtime = NONEXISTENT_MTIME; else mtime = file_timestamp_cons (file->hname, member_date, 0); } else #endif { mtime = name_mtime (file->name); if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath) { /* If name_mtime failed, search VPATH. */ const char *name = vpath_search (file->name, &mtime, NULL, NULL); if (name /* Last resort, is it a library (-lxxx)? */ || (file->name[0] == '-' && file->name[1] == 'l' && (name = library_search (file->name, &mtime)) != 0)) { size_t name_len; if (mtime != UNKNOWN_MTIME) /* vpath_search and library_search store UNKNOWN_MTIME if they didn't need to do a stat call for their work. */ file->last_mtime = mtime; /* If we found it in VPATH, see if it's in GPATH too; if so, change the name right now; if not, defer until after the dependencies are updated. */ #if !MK_OS_VMS name_len = strlen (name) - strlen (file->name) - 1; #else name_len = strlen (name) - strlen (file->name); if (name[name_len - 1] == '/') name_len--; #endif if (gpath_search (name, name_len)) { rename_file (file, name); check_renamed (file); return file_mtime (file); } rehash_file (file, name); check_renamed (file); /* If the result of a vpath search is -o or -W, preserve it. Otherwise, find the mtime of the resulting file. */ if (mtime != OLD_MTIME && mtime != NEW_MTIME) mtime = name_mtime (name); } } } /* Files can have bogus timestamps that nothing newly made will be "newer" than. Updating their dependents could just result in loops. So notify the user of the anomaly with a warning. We only need to do this once, for now. */ if (!clock_skew_detected && mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME && !file->updated) { static FILE_TIMESTAMP adjusted_now; FILE_TIMESTAMP adjusted_mtime = mtime; #if MK_OS_W32 || MK_OS_DOS /* Experimentation has shown that FAT filesystems can set file times up to 3 seconds into the future! Play it safe. */ #define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3 FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS; if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime) adjusted_mtime -= adjustment; #endif /* If the file's time appears to be in the future, update our concept of the present and try once more. */ if (adjusted_now < adjusted_mtime) { int resolution; FILE_TIMESTAMP now = file_timestamp_now (&resolution); adjusted_now = now + (resolution - 1); if (adjusted_now < adjusted_mtime) { double from_now = (FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now) + ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now)) / 1e9)); char from_now_string[100]; if (from_now >= 100.0 && from_now < (double) ULONG_MAX) sprintf (from_now_string, "%lu", (unsigned long) from_now); else sprintf (from_now_string, "%.2g", from_now); OSS (error, NILF, _("warning: file '%s' has modification time %s s in the future"), file->name, from_now_string); clock_skew_detected = 1; } } } /* Store the mtime into all the entries for this file for which it is safe to do so: avoid propagating timestamps to double-colon rules that haven't been examined so they're run or not based on the pre-update timestamp. */ if (file->double_colon) file = file->double_colon; propagate_timestamp = file->updated; do { /* If this file is not implicit but it is intermediate then it was made so by the .INTERMEDIATE target. If this file has never been built by us but was found now, it existed before make started. So, turn off the intermediate bit so make doesn't delete it, since it didn't create it. */ if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started && !file->tried_implicit && file->intermediate) file->intermediate = 0; if (file->updated == propagate_timestamp) file->last_mtime = mtime; file = file->prev; } while (file != 0); return mtime; } /* Return the mtime of the file or archive-member reference NAME. */ /* First, we check with stat(). If the file does not exist, then we return NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then examine each indirection of the symlink and find the newest mtime. This causes one duplicate stat() when -L is being used, but the code is much cleaner. */ static FILE_TIMESTAMP name_mtime (const char *name) { FILE_TIMESTAMP mtime; #if MK_OS_W32 struct STAT st; #else struct stat st; #endif int e; #if MK_OS_W32 { char tem[MAX_PATH+1], *tstart, *tend; const char *p = name + strlen (name); /* Remove any trailing slashes and "."/"..". MS-Windows stat fails on valid directories if NAME ends in a slash, and we need to emulate the Posix behavior where stat on "foo/" or "foo/." succeeds ONLY if "foo" is a directory. */ if (p > name) { memcpy (tem, name, p - name + 1); tstart = tem; if (tstart[1] == ':') tstart += 2; tend = tem + (p - name - 1); if (*tend == '.' && tend > tstart) tend--; if (*tend == '.' && tend > tstart) tend--; for ( ; tend > tstart && ISDIRSEP (*tend); tend--) *tend = '\0'; } else { tem[0] = '\0'; tend = &tem[0]; } #if MK_OS_W32 e = STAT (tem, &st); #else e = stat (tem, &st); #endif if (e == 0 && !_S_ISDIR (st.st_mode) && tend < tem + (p - name - 1)) { errno = ENOTDIR; e = -1; } } #else EINTRLOOP (e, stat (name, &st)); #endif if (e == 0) mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st); else if (errno == ENOENT || errno == ENOTDIR) mtime = NONEXISTENT_MTIME; else { perror_with_name ("stat: ", name); return NONEXISTENT_MTIME; } /* If we get here we either found it, or it doesn't exist. If it doesn't exist see if we can use a symlink mtime instead. */ #ifdef MAKE_SYMLINKS #ifndef S_ISLNK # define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK) #endif if (check_symlink_flag && strlen (name) <= GET_PATH_MAX) { PATH_VAR (lpath); /* Check each symbolic link segment (if any). Find the latest mtime amongst all of them (and the target file of course). Note that we have already successfully dereferenced all the links above. So, if we run into any error trying to lstat(), or readlink(), or whatever, something bizarre-o happened. Just give up and use whatever mtime we've already computed at that point. */ strcpy (lpath, name); while (1) { FILE_TIMESTAMP ltime; PATH_VAR (lbuf); long llen; char *p; EINTRLOOP (e, lstat (lpath, &st)); if (e) { /* Just take what we have so far. */ if (errno != ENOENT && errno != ENOTDIR) perror_with_name ("lstat: ", lpath); break; } /* If this is not a symlink, we're done (we started with the real file's mtime so we don't need to test it again). */ if (!S_ISLNK (st.st_mode)) break; /* If this mtime is newer than what we had, keep the new one. */ ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st); if (ltime > mtime) mtime = ltime; /* Set up to check the file pointed to by this link. */ EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX - 1)); if (llen < 0) { /* Eh? Just take what we have. */ perror_with_name ("readlink: ", lpath); break; } lbuf[llen] = '\0'; /* If the target is fully-qualified or the source is just a filename, then the new path is the target. Otherwise it's the source directory plus the target. */ if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL) strcpy (lpath, lbuf); else if ((p - lpath) + llen + 2 > GET_PATH_MAX) /* Eh? Path too long! Again, just go with what we have. */ break; else /* Create the next step in the symlink chain. */ strcpy (p+1, lbuf); } } #endif return mtime; } /* Search for a library file specified as -lLIBNAME, searching for a suitable library file in the system library directories and the VPATH directories. */ static const char * library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr) { static const char *dirs[] = { "/lib", "/usr/lib", #if MK_OS_W32 && !defined(LIBDIR) /* * This is completely up to the user at product install time. Just define * a placeholder. */ #define LIBDIR "." #endif LIBDIR, /* Defined by configuration. */ 0 }; const char *file = 0; char *libpatterns; FILE_TIMESTAMP mtime; /* Loop variables for the libpatterns value. */ char *p; const char *p2; size_t len; size_t liblen; /* Information about the earliest (in the vpath sequence) match. */ unsigned int best_vpath = 0, best_path = 0; const char **dp; libpatterns = allocated_expand_variable (STRING_SIZE_TUPLE (".LIBPATTERNS")); /* Skip the '-l'. */ lib += 2; liblen = strlen (lib); /* Loop through all the patterns in .LIBPATTERNS, and search on each one. To implement the linker-compatible behavior we have to search through all entries in .LIBPATTERNS and choose the "earliest" one. */ p2 = libpatterns; while ((p = find_next_token (&p2, &len)) != 0) { static char *buf = NULL; static size_t buflen = 0; static size_t libdir_maxlen = 0; static unsigned int std_dirs = 0; char *libbuf; /* Expand the pattern using LIB as a replacement. */ { char c = p[len]; char *p3, *p4; p[len] = '\0'; p3 = find_percent (p); if (!p3) { /* Give a warning if there is no pattern. */ OS (error, NILF, _(".LIBPATTERNS element '%s' is not a pattern"), p); p[len] = c; continue; } p4 = variable_buffer_output (variable_buffer, p, p3-p); p4 = variable_buffer_output (p4, lib, liblen); p4 = variable_buffer_output (p4, p3+1, len - (p3-p)); p[len] = c; libbuf = variable_buffer; } /* Look first for 'libNAME.a' in the current directory. */ mtime = name_mtime (libbuf); if (mtime != NONEXISTENT_MTIME) { if (mtime_ptr != 0) *mtime_ptr = mtime; file = strcache_add (libbuf); /* This by definition will have the best index, so stop now. */ break; } /* Now try VPATH search on that. */ { unsigned int vpath_index, path_index; const char* f = vpath_search (libbuf, mtime_ptr ? &mtime : NULL, &vpath_index, &path_index); if (f) { /* If we have a better match, record it. */ if (file == 0 || vpath_index < best_vpath || (vpath_index == best_vpath && path_index < best_path)) { file = f; best_vpath = vpath_index; best_path = path_index; if (mtime_ptr != 0) *mtime_ptr = mtime; } } } /* Now try the standard set of directories. */ if (!buflen) { for (dp = dirs; *dp != 0; ++dp) { size_t l = strlen (*dp); if (l > libdir_maxlen) libdir_maxlen = l; std_dirs++; } buflen = strlen (libbuf); buf = xmalloc (libdir_maxlen + buflen + 2); } else if (buflen < strlen (libbuf)) { buflen = strlen (libbuf); buf = xrealloc (buf, libdir_maxlen + buflen + 2); } { /* Use the last std_dirs index for standard directories. This was it will always be greater than the VPATH index. */ unsigned int vpath_index = ~((unsigned int)0) - std_dirs; for (dp = dirs; *dp != 0; ++dp) { sprintf (buf, "%s/%s", *dp, libbuf); mtime = name_mtime (buf); if (mtime != NONEXISTENT_MTIME) { if (file == 0 || vpath_index < best_vpath) { file = strcache_add (buf); best_vpath = vpath_index; if (mtime_ptr != 0) *mtime_ptr = mtime; } } vpath_index++; } } } free (libpatterns); return file; } ================================================ FILE: src/remote-cstms.c ================================================ /* GNU Make remote job exportation interface to the Customs daemon. THIS CODE IS NOT SUPPORTED BY THE GNU PROJECT. Please do not send bug reports or questions about it to the Make maintainers. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "job.h" #include "commands.h" #include "debug.h" #if HAVE_SYS_TIME_H # include #endif #include #include "customs.h" char *remote_description = "Customs"; /* File name of the Customs 'export' client command. A full path name can be used to avoid some path-searching overhead. */ #define EXPORT_COMMAND "/usr/local/bin/export" /* ExportPermit gotten by start_remote_job_p, and used by start_remote_job. */ static ExportPermit permit; /* Normalized path name of the current directory. */ static char *normalized_cwd; /* Call once at startup even if no commands are run. */ void remote_setup (void) { } /* Called before exit. */ void remote_cleanup (void) { } /* Return nonzero if the next job should be done remotely. */ int start_remote_job_p (int first_p) { static int inited = 0; int status; int njobs; if (!inited) { /* Allow the user to turn off job exportation (useful while he is debugging Customs, for example). */ if (getenv ("GNU_MAKE_NO_CUSTOMS") != 0) { inited = -1; return 0; } if (ISDB (DB_JOBS)) Rpc_Debug (1); /* Ping the daemon once to see if it is there. */ inited = Customs_Ping () == RPC_SUCCESS ? 1 : -1; if (starting_directory == 0) /* main couldn't figure it out. */ inited = -1; else { /* Normalize the current directory path name to something that should work on all machines exported to. */ normalized_cwd = xmalloc (GET_PATH_MAX); strcpy (normalized_cwd, starting_directory); if (Customs_NormPath (normalized_cwd, GET_PATH_MAX) < 0) /* Path normalization failure means using Customs won't work, but it's not really an error. */ inited = -1; } } if (inited < 0) return 0; njobs = job_slots_used; if (!first_p) njobs -= 1; /* correction for being called from reap_children() */ /* the first job should run locally, or, if the -l flag is given, we use that as clue as to how many local jobs should be scheduled locally */ if (max_load_average < 0 && njobs == 0 || njobs < max_load_average) return 0; status = Customs_Host (EXPORT_SAME, &permit); if (status != RPC_SUCCESS) { DB (DB_JOBS, (_("Customs won't export: %s\n"), Rpc_ErrorMessage (status))); return 0; } return !CUSTOMS_FAIL (&permit.addr); } /* Start a remote job running the command in ARGV, with environment from ENVP. It gets standard input from STDIN_FD. On failure, return nonzero. On success, return zero, and set *USED_STDIN to nonzero if it will actually use STDIN_FD, zero if not, set *ID_PTR to a unique identification, and set *IS_REMOTE to nonzero if the job is remote, zero if it is local (meaning *ID_PTR is a process ID). */ int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote, pid_t *id_ptr, int *used_stdin) { char waybill[MAX_DATA_SIZE], msg[128]; struct hostent *host; struct timeval timeout; struct sockaddr_in sin; int len; int retsock, retport, sock; Rpc_Stat status; pid_t pid; /* Create the return socket. */ retsock = Rpc_UdpCreate (True, 0); if (retsock < 0) { O (error, NILF, "exporting: Couldn't create return socket."); return 1; } /* Get the return socket's port number. */ len = sizeof (sin); if (getsockname (retsock, (struct sockaddr *) &sin, &len) < 0) { (void) close (retsock); perror_with_name ("exporting: ", "getsockname"); return 1; } retport = sin.sin_port; /* Create the TCP socket for talking to the remote child. */ sock = Rpc_TcpCreate (False, 0); /* Create a WayBill to give to the server. */ len = Customs_MakeWayBill (&permit, normalized_cwd, argv[0], argv, envp, retport, waybill); /* Modify the waybill for the child's uid/gid. */ { WayBill *wb = (WayBill *) waybill; wb->ruid = wb->euid; wb->rgid = wb->egid; } /* Send the request to the server, timing out in 20 seconds. */ timeout.tv_usec = 0; timeout.tv_sec = 20; sin.sin_family = AF_INET; sin.sin_port = htons (Customs_Port ()); sin.sin_addr = permit.addr; status = Rpc_Call (sock, &sin, (Rpc_Proc) CUSTOMS_IMPORT, len, (Rpc_Opaque) waybill, sizeof (msg), (Rpc_Opaque) msg, 1, &timeout); host = gethostbyaddr ((char *)&permit.addr, sizeof(permit.addr), AF_INET); { const char *hnm = host ? host->h_name : inet_ntoa (permit.addr); size_t hlen = strlen (hnm); if (status != RPC_SUCCESS) { const char *err = Rpc_ErrorMessage (status); (void) close (retsock); (void) close (sock); error (NILF, hlen + strlen (err), "exporting to %s: %s", hnm, err); return 1; } else if (msg[0] != 'O' || msg[1] != 'k' || msg[2] != '\0') { (void) close (retsock); (void) close (sock); error (NILF, hlen + strlen (msg), "exporting to %s: %s", hnm, msg); return 1; } else { error (NILF, hlen + INTSTR_LENGTH, "*** exported to %s (id %u)", hnm, permit.id); } fflush (stdout); fflush (stderr); } pid = vfork (); if (pid < 0) { /* The fork failed! */ perror_with_name ("fork", ""); return 1; } else if (pid == 0) { /* Child side. Run 'export' to handle the connection. */ static char sock_buf[INTSTR_LENGTH], retsock_buf[INTSTR_LENGTH]; static char id_buf[INTSTR_LENGTH]; static char *new_argv[6] = { EXPORT_COMMAND, "-id", sock_buf, retsock_buf, id_buf, 0 }; /* Set up the arguments. */ (void) sprintf (sock_buf, "%d", sock); (void) sprintf (retsock_buf, "%d", retsock); (void) sprintf (id_buf, "%x", permit.id); /* Get the right stdin. */ if (stdin_fd != 0) (void) dup2 (stdin_fd, 0); /* Unblock signals in the child. */ unblock_all_sigs (); /* Run the command. */ exec_command (new_argv, envp); } /* Parent side. Return the 'export' process's ID. */ (void) close (retsock); (void) close (sock); *is_remote = 0; *id_ptr = pid; *used_stdin = 1; return 0; } /* Get the status of a dead remote child. Block waiting for one to die if BLOCK is nonzero. Set *EXIT_CODE_PTR to the exit status, *SIGNAL_PTR to the termination signal or zero if it exited normally, and *COREDUMP_PTR nonzero if it dumped core. Return the ID of the child that died, 0 if we would have to block and !BLOCK, or < 0 if there were none. */ int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr, int block) { return -1; } /* Block asynchronous notification of remote child death. If this notification is done by raising the child termination signal, do not block that signal. */ void block_remote_children (void) { return; } /* Restore asynchronous notification of remote child death. If this is done by raising the child termination signal, do not unblock that signal. */ void unblock_remote_children (void) { return; } /* Send signal SIG to child ID. Return 0 if successful, -1 if not. */ int remote_kill (pid_t id, int sig) { return -1; } ================================================ FILE: src/remote-stub.c ================================================ /* Template for the remote job exportation interface to GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "job.h" #include "commands.h" char *remote_description = 0; /* Call once at startup even if no commands are run. */ void remote_setup (void) { } /* Called before exit. */ void remote_cleanup (void) { } /* Return nonzero if the next job should be done remotely. */ int start_remote_job_p (int first_p UNUSED) { return 0; } /* Start a remote job running the command in ARGV, with environment from ENVP. It gets standard input from STDIN_FD. On failure, return nonzero. On success, return zero, and set *USED_STDIN to nonzero if it will actually use STDIN_FD, zero if not, set *ID_PTR to a unique identification, and set *IS_REMOTE to zero if the job is local, nonzero if it is remote (meaning *ID_PTR is a process ID). */ int start_remote_job (char **argv UNUSED, char **envp UNUSED, int stdin_fd UNUSED, int *is_remote UNUSED, pid_t *id_ptr UNUSED, int *used_stdin UNUSED) { return -1; } /* Get the status of a dead remote child. Block waiting for one to die if BLOCK is nonzero. Set *EXIT_CODE_PTR to the exit status, *SIGNAL_PTR to the termination signal or zero if it exited normally, and *COREDUMP_PTR nonzero if it dumped core. Return the ID of the child that died, 0 if we would have to block and !BLOCK, or < 0 if there were none. */ int remote_status (int *exit_code_ptr UNUSED, int *signal_ptr UNUSED, int *coredump_ptr UNUSED, int block UNUSED) { errno = ECHILD; return -1; } /* Block asynchronous notification of remote child death. If this notification is done by raising the child termination signal, do not block that signal. */ void block_remote_children (void) { return; } /* Restore asynchronous notification of remote child death. If this is done by raising the child termination signal, do not unblock that signal. */ void unblock_remote_children (void) { return; } /* Send signal SIG to child ID. Return 0 if successful, -1 if not. */ int remote_kill (pid_t id UNUSED, int sig UNUSED) { return -1; } ================================================ FILE: src/rule.c ================================================ /* Pattern and suffix rule internals for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include "filedef.h" #include "dep.h" #include "job.h" #include "commands.h" #include "variable.h" #include "rule.h" static void freerule (struct rule *rule, struct rule *lastrule); /* Chain of all pattern rules. */ struct rule *pattern_rules; /* Pointer to last rule in the chain, so we can add onto the end. */ struct rule *last_pattern_rule; /* Number of rules in the chain. */ unsigned int num_pattern_rules; /* Maximum number of target patterns of any pattern rule. */ unsigned int max_pattern_targets; /* Maximum number of dependencies of any pattern rule. */ unsigned int max_pattern_deps; /* Maximum length of the name of a dependencies of any pattern rule. */ size_t max_pattern_dep_length; /* Pointer to structure for the file .SUFFIXES whose dependencies are the suffixes to be searched. */ struct file *suffix_file; /* Return the rule definition: space separated rule targets, followed by either a colon or two colons in the case of a terminal rule, followed by space separated rule prerequisites, followed by a pipe, followed by order-only prerequisites, if present. */ const char * get_rule_defn (struct rule *r) { if (r->_defn == NULL) { size_t len = 8; /* Reserve for ":: ", " | ", and nul. */ unsigned int k; char *p; const char *sep = ""; const struct dep *dep, *ood = 0; for (k = 0; k < r->num; ++k) len += r->lens[k] + 1; for (dep = r->deps; dep; dep = dep->next) len += strlen (dep_name (dep)) + (dep->wait_here ? CSTRLEN (" .WAIT") : 0) + 1; p = r->_defn = xmalloc (len); for (k = 0; k < r->num; ++k, sep = " ") p = mempcpy (mempcpy (p, sep, strlen (sep)), r->targets[k], r->lens[k]); *p++ = ':'; if (r->terminal) *p++ = ':'; /* Copy all normal dependencies; note any order-only deps. */ for (dep = r->deps; dep; dep = dep->next) if (dep->ignore_mtime == 0) { if (dep->wait_here) p = mempcpy (p, " .WAIT", CSTRLEN (" .WAIT")); p = mempcpy (mempcpy (p, " ", 1), dep_name (dep), strlen (dep_name (dep))); } else if (ood == 0) ood = dep; /* Copy order-only deps, if we have any. */ for (sep = " | "; ood; ood = ood->next, sep = " ") if (ood->ignore_mtime) { p = mempcpy (p, sep, strlen (sep)); if (ood->wait_here) p = mempcpy (p, ".WAIT ", CSTRLEN (".WAIT ")); p = mempcpy (p, dep_name (ood), strlen (dep_name (ood))); } *p = '\0'; } return r->_defn; } /* Compute the maximum dependency length and maximum number of dependencies of all implicit rules. Also sets the subdir flag for a rule when appropriate, possibly removing the rule completely when appropriate. Add any global EXTRA_PREREQS here as well. */ void snap_implicit_rules (void) { char *name = NULL; size_t namelen = 0; struct rule *rule; struct dep *dep; struct dep *prereqs = expand_extra_prereqs (lookup_variable (STRING_SIZE_TUPLE(".EXTRA_PREREQS"))); unsigned int pre_deps = 0; max_pattern_dep_length = 0; for (dep = prereqs; dep; dep = dep->next) { const char *d = dep_name (dep); size_t l = strlen (d); if (second_expansion) { if (!dep->name) dep->name = xstrdup (dep->file->name); dep->need_2nd_expansion = 1; } if (dep->need_2nd_expansion) /* When pattern_search allocates a buffer, allow 5 bytes per each % to substitute each % with $(*F) while avoiding realloc. */ while ((d = strchr (d, '%')) != 0) { l += 4; ++d; } if (l > max_pattern_dep_length) max_pattern_dep_length = l; ++pre_deps; } num_pattern_rules = max_pattern_targets = max_pattern_deps = 0; for (rule = pattern_rules; rule; rule = rule->next) { unsigned int ndeps = pre_deps; struct dep *lastdep = NULL; ++num_pattern_rules; if (rule->num > max_pattern_targets) max_pattern_targets = rule->num; for (dep = rule->deps; dep != 0; dep = dep->next) { const char *dname = dep_name (dep); size_t len = strlen (dname); #if MK_OS_VMS const char *p = strrchr (dname, ']'); const char *p2; if (p == 0) p = strrchr (dname, ':'); p2 = p ? strchr (p, '%') : 0; #else const char *p = strrchr (dname, '/'); const char *p2 = p ? strchr (p, '%') : 0; #endif ndeps++; if (len > max_pattern_dep_length) max_pattern_dep_length = len; if (!dep->next) lastdep = dep; if (p2) { /* There is a slash before the % in the dep name. Extract the directory name. */ if (p == dname) ++p; if ((size_t) (p - dname) > namelen) { namelen = p - dname; name = xrealloc (name, namelen + 1); } memcpy (name, dname, p - dname); name[p - dname] = '\0'; /* In the deps of an implicit rule the 'changed' flag actually indicates that the dependency is in a nonexistent subdirectory. */ dep->changed = !dir_file_exists_p (name, ""); } else /* This dependency does not reside in a subdirectory. */ dep->changed = 0; } if (prereqs) { if (lastdep) lastdep->next = copy_dep_chain (prereqs); else rule->deps = copy_dep_chain (prereqs); } if (ndeps > max_pattern_deps) max_pattern_deps = ndeps; } free (name); free_dep_chain (prereqs); } /* Create a pattern rule from a suffix rule. TARGET is the target suffix; SOURCE is the source suffix. CMDS are the commands. If TARGET is nil, it means the target pattern should be '(%.o)'. If SOURCE is nil, it means there should be no deps. */ static void convert_suffix_rule (const char *target, const char *source, struct commands *cmds) { const char **names, **percents; struct dep *deps; names = xmalloc (sizeof (const char *)); percents = xmalloc (sizeof (const char *)); if (target == 0) { /* Special case: TARGET being nil means we are defining a '.X.a' suffix rule; the target pattern is always '(%.o)'. */ #if MK_OS_VMS *names = strcache_add_len ("(%.obj)", 7); #else *names = strcache_add_len ("(%.o)", 5); #endif *percents = *names + 1; } else { /* Construct the target name. */ size_t len = strlen (target); char *p = alloca (1 + len + 1); p[0] = '%'; memcpy (p + 1, target, len + 1); *names = strcache_add_len (p, len + 1); *percents = *names; } if (source == 0) deps = 0; else { /* Construct the dependency name. */ size_t len = strlen (source); char *p = alloca (1 + len + 1); p[0] = '%'; memcpy (p + 1, source, len + 1); deps = alloc_dep (); deps->name = strcache_add_len (p, len + 1); } create_pattern_rule (names, percents, 1, 0, deps, cmds, 0); } /* Convert old-style suffix rules to pattern rules. All rules for the suffixes on the .SUFFIXES list are converted and added to the chain of pattern rules. */ void convert_to_pattern (void) { struct dep *d, *d2; char *rulename; /* We will compute every potential suffix rule (.x.y) from the list of suffixes in the .SUFFIXES target's dependencies and see if it exists. First find the longest of the suffixes. */ size_t maxsuffix = 0; for (d = suffix_file->deps; d != 0; d = d->next) { size_t l = strlen (dep_name (d)); if (l > maxsuffix) maxsuffix = l; } /* Space to construct the suffix rule target name. */ rulename = alloca ((maxsuffix * 2) + 1); for (d = suffix_file->deps; d != 0; d = d->next) { struct file *f; size_t slen; /* Make a rule that is just the suffix, with no deps or commands. This rule exists solely to disqualify match-anything rules. */ convert_suffix_rule (dep_name (d), 0, 0); if (d->file->cmds != 0) /* Record a pattern for this suffix's null-suffix rule. */ convert_suffix_rule ("", dep_name (d), d->file->cmds); slen = strlen (dep_name (d)); memcpy (rulename, dep_name (d), slen + 1); f = lookup_file (rulename); if (f && f->cmds) { if (!f->deps) f->suffix = 1; else if (!posix_pedantic) { O (error, &f->cmds->fileinfo, _("warning: ignoring prerequisites on suffix rule definition")); f->suffix = 1; } } /* Add every other suffix to this one and see if it exists as a two-suffix rule. */ for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) { size_t s2len; s2len = strlen (dep_name (d2)); /* Can't build something from itself. */ if (slen == s2len && streq (dep_name (d), dep_name (d2))) continue; memcpy (rulename + slen, dep_name (d2), s2len + 1); f = lookup_file (rulename); /* No target, or no commands: it can't be a suffix rule. */ if (f == 0 || f->cmds == 0) continue; /* POSIX says that suffix rules can't have prerequisites. In POSIX mode, don't make this a suffix rule. Previous versions of GNU Make did treat this as a suffix rule and ignored the prerequisites, which is bad. In the future we'll do the same as POSIX, but for now preserve the old behavior and warn about it. */ if (f->deps != 0) { if (posix_pedantic) continue; O (error, &f->cmds->fileinfo, _("warning: ignoring prerequisites on suffix rule definition")); } f->suffix = 1; if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a') /* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'. It also generates a normal '%.a: %.X' rule below. */ convert_suffix_rule (NULL, /* Indicates '(%.o)'. */ dep_name (d), f->cmds); /* The suffix rule '.X.Y:' is converted to the pattern rule '%.Y: %.X'. */ convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds); } } } /* Install the pattern rule RULE (whose fields have been filled in) at the end of the list (so that any rules previously defined will take precedence). If this rule duplicates a previous one (identical target and dependencies), the old one is replaced if OVERRIDE is nonzero, otherwise this new one is thrown out. When an old rule is replaced, the new one is put at the end of the list. Return nonzero if RULE is used; zero if not. */ static int new_pattern_rule (struct rule *rule, int override) { struct rule *r, *lastrule; unsigned int i, j; rule->in_use = 0; rule->terminal = 0; rule->next = 0; /* Search for an identical rule. */ lastrule = 0; for (r = pattern_rules; r != 0; lastrule = r, r = r->next) for (i = 0; i < rule->num; ++i) { for (j = 0; j < r->num; ++j) if (!streq (rule->targets[i], r->targets[j])) break; /* If all the targets matched... */ if (j == r->num) { struct dep *d, *d2; for (d = rule->deps, d2 = r->deps; d != 0 && d2 != 0; d = d->next, d2 = d2->next) if (!streq (dep_name (d), dep_name (d2))) break; if (d == 0 && d2 == 0) { /* All the dependencies matched. */ if (override) { /* Remove the old rule. */ freerule (r, lastrule); /* Install the new one. */ if (pattern_rules == 0) pattern_rules = rule; else last_pattern_rule->next = rule; last_pattern_rule = rule; /* We got one. Stop looking. */ goto matched; } else { /* The old rule stays intact. Destroy the new one. */ freerule (rule, (struct rule *) 0); return 0; } } } } matched:; if (r == 0) { /* There was no rule to replace. */ if (pattern_rules == 0) pattern_rules = rule; else last_pattern_rule->next = rule; last_pattern_rule = rule; } return 1; } /* Install an implicit pattern rule based on the three text strings in the structure P points to. These strings come from one of the arrays of default implicit pattern rules. TERMINAL specifies what the 'terminal' field of the rule should be. */ void install_pattern_rule (struct pspec *p, int terminal) { struct rule *r; const char *ptr; r = xmalloc (sizeof (struct rule)); r->num = 1; r->targets = xmalloc (sizeof (const char *)); r->suffixes = xmalloc (sizeof (const char *)); r->lens = xmalloc (sizeof (unsigned int)); r->_defn = NULL; r->lens[0] = (unsigned int) strlen (p->target); r->targets[0] = p->target; r->suffixes[0] = find_percent_cached (&r->targets[0]); assert (r->suffixes[0] != NULL); ++r->suffixes[0]; ptr = p->dep; r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep); if (new_pattern_rule (r, 0)) { r->terminal = terminal ? 1 : 0; r->cmds = xmalloc (sizeof (struct commands)); r->cmds->fileinfo.filenm = 0; r->cmds->fileinfo.lineno = 0; r->cmds->fileinfo.offset = 0; /* These will all be string literals, but we malloc space for them anyway because somebody might want to free them later. */ r->cmds->commands = xstrdup (p->commands); r->cmds->command_lines = 0; r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT; } } /* Free all the storage used in RULE and take it out of the pattern_rules chain. LASTRULE is the rule whose next pointer points to RULE. */ static void freerule (struct rule *rule, struct rule *lastrule) { struct rule *next = rule->next; free_dep_chain (rule->deps); /* MSVC erroneously warns without a cast here. */ free ((void *)rule->targets); free ((void *)rule->suffixes); free (rule->lens); free ((void *) rule->_defn); /* We can't free the storage for the commands because there are ways that they could be in more than one place: * If the commands came from a suffix rule, they could also be in the 'struct file's for other suffix rules or plain targets given on the same makefile line. * If two suffixes that together make a two-suffix rule were each given twice in the .SUFFIXES list, and in the proper order, two identical pattern rules would be created and the second one would be discarded here, but both would contain the same 'struct commands' pointer from the 'struct file' for the suffix rule. */ free (rule); if (pattern_rules == rule) if (lastrule != 0) abort (); else pattern_rules = next; else if (lastrule != 0) lastrule->next = next; if (last_pattern_rule == rule) last_pattern_rule = lastrule; } /* Create a new pattern rule with the targets in the nil-terminated array TARGETS. TARGET_PERCENTS is an array of pointers to the % in each element of TARGETS. N is the number of items in the array (not counting the nil element). The new rule has dependencies DEPS and commands from COMMANDS. It is a terminal rule if TERMINAL is nonzero. This rule overrides identical rules with different commands if OVERRIDE is nonzero. The storage for TARGETS and its elements and TARGET_PERCENTS is used and must not be freed until the rule is destroyed. */ void create_pattern_rule (const char **targets, const char **target_percents, unsigned short n, int terminal, struct dep *deps, struct commands *commands, int override) { unsigned int i; struct rule *r = xmalloc (sizeof (struct rule)); r->num = n; r->cmds = commands; r->deps = deps; r->targets = targets; r->suffixes = target_percents; r->lens = xmalloc (n * sizeof (unsigned int)); r->_defn = NULL; for (i = 0; i < n; ++i) { r->lens[i] = (unsigned int) strlen (targets[i]); assert (r->suffixes[i] != NULL); ++r->suffixes[i]; } if (new_pattern_rule (r, override)) r->terminal = terminal ? 1 : 0; } /* Print the data base of rules. */ static void /* Useful to call from gdb. */ print_rule (struct rule *r) { fputs (get_rule_defn (r), stdout); putchar ('\n'); if (r->cmds != 0) print_commands (r->cmds); } void print_rule_data_base (void) { unsigned int rules, terminal; struct rule *r; puts (_("\n# Implicit Rules")); rules = terminal = 0; for (r = pattern_rules; r != 0; r = r->next) { ++rules; putchar ('\n'); print_rule (r); if (r->terminal) ++terminal; } if (rules == 0) puts (_("\n# No implicit rules.")); else { printf (_("\n# %u implicit rules, %u (%.1f%%) terminal."), rules, terminal, (double) terminal / (double) rules * 100.0); } if (num_pattern_rules != rules) { /* This can happen if a fatal error was detected while reading the makefiles and thus count_implicit_rule_limits wasn't called yet. */ if (num_pattern_rules != 0) ONN (fatal, NILF, "INTERNAL: num_pattern_rules is wrong! %u != %u", num_pattern_rules, rules); } } ================================================ FILE: src/rule.h ================================================ /* Definitions for using pattern rules in GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Structure used for pattern (implicit) rules. */ struct rule { struct rule *next; const char **targets; /* Targets of the rule. */ unsigned int *lens; /* Lengths of each target. */ const char **suffixes; /* Suffixes (after '%') of each target. */ struct dep *deps; /* Dependencies of the rule. */ struct commands *cmds; /* Commands to execute. */ char *_defn; /* Definition of the rule. */ unsigned short num; /* Number of targets. */ char terminal; /* If terminal (double-colon). */ char in_use; /* If in use by a parent pattern_search. */ }; /* For calling install_pattern_rule. */ struct pspec { const char *target, *dep, *commands; }; extern struct rule *pattern_rules; extern struct rule *last_pattern_rule; extern unsigned int num_pattern_rules; extern unsigned int max_pattern_deps; extern unsigned int max_pattern_targets; extern size_t max_pattern_dep_length; extern struct file *suffix_file; void snap_implicit_rules (void); void convert_to_pattern (void); void install_pattern_rule (struct pspec *p, int terminal); void create_pattern_rule (const char **targets, const char **target_percents, unsigned short num, int terminal, struct dep *deps, struct commands *commands, int override); const char *get_rule_defn (struct rule *rule); void print_rule_data_base (void); ================================================ FILE: src/shuffle.c ================================================ /* Provide prerequisite shuffle support. Copyright (C) 2022-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "shuffle.h" #include "filedef.h" #include "dep.h" /* Supported shuffle modes. */ static void random_shuffle_array (void ** a, size_t len); static void reverse_shuffle_array (void ** a, size_t len); static void identity_shuffle_array (void ** a, size_t len); /* The way goals and rules are shuffled during update. */ enum shuffle_mode { /* No shuffle data is populated or used. */ sm_none, /* Random within dependency list. */ sm_random, /* Inverse order. */ sm_reverse, /* identity order. Differs from SM_NONE by explicitly populating the traversal order. */ sm_identity, }; /* Shuffle configuration. */ static struct { enum shuffle_mode mode; unsigned int seed; void (*shuffler) (void **a, size_t len); char strval[INTSTR_LENGTH + 1]; } config = { sm_none, 0, NULL, "" }; /* Return string value of --shuffle= option passed. If none was passed or --shuffle=none was used function returns NULL. */ const char * shuffle_get_mode () { return config.strval[0] == '\0' ? NULL : config.strval; } void shuffle_set_mode (const char *cmdarg) { /* Parse supported '--shuffle' mode. */ if (strcasecmp (cmdarg, "reverse") == 0) { config.mode = sm_reverse; config.shuffler = reverse_shuffle_array; strcpy (config.strval, "reverse"); } else if (strcasecmp (cmdarg, "identity") == 0) { config.mode = sm_identity; config.shuffler = identity_shuffle_array; strcpy (config.strval, "identity"); } else if (strcasecmp (cmdarg, "none") == 0) { config.mode = sm_none; config.shuffler = NULL; config.strval[0] = '\0'; } else { if (strcasecmp (cmdarg, "random") == 0) config.seed = make_rand (); else { /* Assume explicit seed. */ const char *err; config.seed = make_toui (cmdarg, &err); if (err) OSS (fatal, NILF, _("invalid shuffle mode: %s: '%s'"), err, cmdarg); } config.mode = sm_random; config.shuffler = random_shuffle_array; sprintf (config.strval, "%u", config.seed); } } /* Shuffle array elements using RAND(). */ static void random_shuffle_array (void **a, size_t len) { size_t i; for (i = 0; i < len; i++) { void *t; /* Pick random element and swap. */ unsigned int j = make_rand () % len; if (i == j) continue; /* Swap. */ t = a[i]; a[i] = a[j]; a[j] = t; } } /* Shuffle array elements using reverse order. */ static void reverse_shuffle_array (void **a, size_t len) { size_t i; for (i = 0; i < len / 2; i++) { void *t; /* Pick mirror and swap. */ size_t j = len - 1 - i; /* Swap. */ t = a[i]; a[i] = a[j]; a[j] = t; } } /* Shuffle array elements using identity order. */ static void identity_shuffle_array (void **a UNUSED, size_t len UNUSED) { /* No-op! */ } /* Shuffle list of dependencies by populating '->shuf' field in each 'struct dep'. */ static void shuffle_deps (struct dep *deps) { size_t ndeps = 0; struct dep *dep; void **da; void **dp; for (dep = deps; dep; dep = dep->next) { /* Do not reshuffle prerequisites if any .WAIT is present. */ if (dep->wait_here) return; ndeps++; } if (ndeps == 0) return; /* Allocate array of all deps, store, shuffle, write back. */ da = xmalloc (sizeof (struct dep *) * ndeps); /* Store locally. */ for (dep = deps, dp = da; dep; dep = dep->next, dp++) *dp = dep; /* Shuffle. */ config.shuffler (da, ndeps); /* Write back. */ for (dep = deps, dp = da; dep; dep = dep->next, dp++) dep->shuf = *dp; free (da); } /* Shuffle 'deps' of each 'file' recursively. */ static void shuffle_file_deps_recursive (struct file *f) { struct dep *dep; /* Implicit rules do not always provide any depends. */ if (!f) return; /* Avoid repeated shuffles and loops. */ if (f->was_shuffled) return; f->was_shuffled = 1; shuffle_deps (f->deps); /* Shuffle dependencies. */ for (dep = f->deps; dep; dep = dep->next) shuffle_file_deps_recursive (dep->file); } /* Shuffle goal dependencies first, then shuffle dependency list of each file reachable from goaldep recursively. Used by --shuffle flag to introduce artificial non-determinism in build order. .*/ void shuffle_deps_recursive (struct dep *deps) { struct dep *dep; /* Exit early if shuffling was not requested. */ if (config.mode == sm_none) return; /* Do not reshuffle prerequisites if .NOTPARALLEL was specified. */ if (not_parallel) return; /* Set specific seed at the top level of recursion. */ if (config.mode == sm_random) make_seed (config.seed); shuffle_deps (deps); /* Shuffle dependencies. */ for (dep = deps; dep; dep = dep->next) shuffle_file_deps_recursive (dep->file); } ================================================ FILE: src/shuffle.h ================================================ /* Declarations for target shuffling support. Copyright (C) 2022, 2024-2022 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ struct dep; struct goaldep; void shuffle_set_mode (const char *cmdarg); const char *shuffle_get_mode (void); void shuffle_deps_recursive (struct dep* g); #define shuffle_goaldeps_recursive(_g) do{ \ shuffle_deps_recursive ((struct dep *)_g); \ } while(0) ================================================ FILE: src/signame.c ================================================ /* Convert between signal names and numbers. Copyright (C) 1990-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" /* If the system provides strsignal, we don't need it. */ #if !HAVE_STRSIGNAL /* If the system provides sys_siglist, we'll use that. Otherwise create our own. */ #if !HAVE_DECL_SYS_SIGLIST /* Some systems do not define NSIG in . */ #ifndef NSIG #ifdef _NSIG #define NSIG _NSIG #else #define NSIG 32 #endif #endif /* There is too much variation in Sys V signal numbers and names, so we must initialize them at runtime. */ static const char *undoc; static const char *sys_siglist[NSIG]; /* Table of abbreviations for signals. Note: A given number can appear more than once with different abbreviations. */ #define SIG_TABLE_SIZE (NSIG*2) typedef struct { int number; const char *abbrev; } num_abbrev; static num_abbrev sig_table[SIG_TABLE_SIZE]; /* Number of elements of sig_table used. */ static int sig_table_nelts = 0; /* Enter signal number NUMBER into the tables with ABBREV and NAME. */ static void init_sig (int number, const char *abbrev, const char *name) { /* If this value is ever greater than NSIG it seems like it'd be a bug in the system headers, but... better safe than sorry. We know, for example, that this isn't always true on VMS. */ if (number >= 0 && number < NSIG) sys_siglist[number] = name; if (sig_table_nelts < SIG_TABLE_SIZE) { sig_table[sig_table_nelts].number = number; sig_table[sig_table_nelts++].abbrev = abbrev; } } static int signame_init (void) { int i; undoc = xstrdup (_("unknown signal")); /* Initialize signal names. */ for (i = 0; i < NSIG; i++) sys_siglist[i] = undoc; /* Initialize signal names. */ #if defined (SIGHUP) init_sig (SIGHUP, "HUP", _("Hangup")); #endif #if defined (SIGINT) init_sig (SIGINT, "INT", _("Interrupt")); #endif #if defined (SIGQUIT) init_sig (SIGQUIT, "QUIT", _("Quit")); #endif #if defined (SIGILL) init_sig (SIGILL, "ILL", _("Illegal Instruction")); #endif #if defined (SIGTRAP) init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap")); #endif /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */ #if defined (SIGABRT) init_sig (SIGABRT, "ABRT", _("Aborted")); #endif #if defined (SIGIOT) init_sig (SIGIOT, "IOT", _("IOT trap")); #endif #if defined (SIGEMT) init_sig (SIGEMT, "EMT", _("EMT trap")); #endif #if defined (SIGFPE) init_sig (SIGFPE, "FPE", _("Floating point exception")); #endif #if defined (SIGKILL) init_sig (SIGKILL, "KILL", _("Killed")); #endif #if defined (SIGBUS) init_sig (SIGBUS, "BUS", _("Bus error")); #endif #if defined (SIGSEGV) init_sig (SIGSEGV, "SEGV", _("Segmentation fault")); #endif #if defined (SIGSYS) init_sig (SIGSYS, "SYS", _("Bad system call")); #endif #if defined (SIGPIPE) init_sig (SIGPIPE, "PIPE", _("Broken pipe")); #endif #if defined (SIGALRM) init_sig (SIGALRM, "ALRM", _("Alarm clock")); #endif #if defined (SIGTERM) init_sig (SIGTERM, "TERM", _("Terminated")); #endif #if defined (SIGUSR1) init_sig (SIGUSR1, "USR1", _("User defined signal 1")); #endif #if defined (SIGUSR2) init_sig (SIGUSR2, "USR2", _("User defined signal 2")); #endif /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that is what is in POSIX.1. */ #if defined (SIGCHLD) init_sig (SIGCHLD, "CHLD", _("Child exited")); #endif #if defined (SIGCLD) init_sig (SIGCLD, "CLD", _("Child exited")); #endif #if defined (SIGPWR) init_sig (SIGPWR, "PWR", _("Power failure")); #endif #if defined (SIGTSTP) init_sig (SIGTSTP, "TSTP", _("Stopped")); #endif #if defined (SIGTTIN) init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)")); #endif #if defined (SIGTTOU) init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)")); #endif #if defined (SIGSTOP) init_sig (SIGSTOP, "STOP", _("Stopped (signal)")); #endif #if defined (SIGXCPU) init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded")); #endif #if defined (SIGXFSZ) init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded")); #endif #if defined (SIGVTALRM) init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired")); #endif #if defined (SIGPROF) init_sig (SIGPROF, "PROF", _("Profiling timer expired")); #endif #if defined (SIGWINCH) /* "Window size changed" might be more accurate, but even if that is all that it means now, perhaps in the future it will be extended to cover other kinds of window changes. */ init_sig (SIGWINCH, "WINCH", _("Window changed")); #endif #if defined (SIGCONT) init_sig (SIGCONT, "CONT", _("Continued")); #endif #if defined (SIGURG) init_sig (SIGURG, "URG", _("Urgent I/O condition")); #endif #if defined (SIGIO) /* "I/O pending" has also been suggested. A disadvantage is that signal only happens when the process has asked for it, not every time I/O is pending. Another disadvantage is the confusion from giving it a different name than under Unix. */ init_sig (SIGIO, "IO", _("I/O possible")); #endif #if defined (SIGWIND) init_sig (SIGWIND, "WIND", _("SIGWIND")); #endif #if defined (SIGPHONE) init_sig (SIGPHONE, "PHONE", _("SIGPHONE")); #endif #if defined (SIGPOLL) init_sig (SIGPOLL, "POLL", _("I/O possible")); #endif #if defined (SIGLOST) init_sig (SIGLOST, "LOST", _("Resource lost")); #endif #if defined (SIGDANGER) init_sig (SIGDANGER, "DANGER", _("Danger signal")); #endif #if defined (SIGINFO) init_sig (SIGINFO, "INFO", _("Information request")); #endif #if defined (SIGNOFP) init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available")); #endif return 1; } #endif /* HAVE_DECL_SYS_SIGLIST */ char * strsignal (int sig) { static char buf[] = "Signal 12345678901234567890"; #if ! HAVE_DECL_SYS_SIGLIST # if HAVE_DECL__SYS_SIGLIST # define sys_siglist _sys_siglist # elif HAVE_DECL___SYS_SIGLIST # define sys_siglist __sys_siglist # else static int sig_initted = 0; if (!sig_initted) sig_initted = signame_init (); # endif #endif if (sig > 0 && sig < NSIG) return (char *) sys_siglist[sig]; sprintf (buf, "Signal %d", sig); return buf; } #endif /* HAVE_STRSIGNAL */ ================================================ FILE: src/strcache.c ================================================ /* Constant string caching for GNU Make. Copyright (C) 2006-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include #include "hash.h" /* A string cached here will never be freed, so we don't need to worry about reference counting. We just store the string, and then remember it in a hash so it can be looked up again. */ typedef unsigned short int sc_buflen_t; struct strcache { struct strcache *next; /* The next block of strings. Must be first! */ sc_buflen_t end; /* Offset to the beginning of free space. */ sc_buflen_t bytesfree; /* Free space left in this buffer. */ sc_buflen_t count; /* # of strings in this buffer (for stats). */ char buffer[1]; /* The buffer comes after this. */ }; /* The size (in bytes) of each cache buffer. Try to pick something that will map well into the heap. This must be able to be represented by a short int (<=65535). */ #define CACHE_BUFFER_BASE (8192) #define CACHE_BUFFER_ALLOC(_s) ((_s) - (2 * sizeof (size_t))) #define CACHE_BUFFER_OFFSET (offsetof (struct strcache, buffer)) #define CACHE_BUFFER_SIZE(_s) (CACHE_BUFFER_ALLOC(_s) - CACHE_BUFFER_OFFSET) #define BUFSIZE CACHE_BUFFER_SIZE (CACHE_BUFFER_BASE) static struct strcache *strcache = NULL; static struct strcache *fullcache = NULL; static unsigned long total_buffers = 0; static unsigned long total_strings = 0; static unsigned long total_size = 0; /* Add a new buffer to the cache. Add it at the front to reduce search time. This can also increase the overhead, since it's less likely that older buffers will be filled in. However, GNU Make has so many smaller strings that this doesn't seem to be much of an issue in practice. */ static struct strcache * new_cache (struct strcache **head, sc_buflen_t buflen) { struct strcache *new = xmalloc (buflen + CACHE_BUFFER_OFFSET); new->end = 0; new->count = 0; new->bytesfree = buflen; new->next = *head; *head = new; ++total_buffers; return new; } static const char * copy_string (struct strcache *sp, const char *str, sc_buflen_t len) { /* Add the string to this cache. */ char *res = &sp->buffer[sp->end]; memmove (res, str, len); res[len++] = '\0'; sp->end += len; sp->bytesfree -= len; ++sp->count; return res; } static const char * add_string (const char *str, sc_buflen_t len) { const char *res; struct strcache *sp; struct strcache **spp = &strcache; /* We need space for the nul char. */ sc_buflen_t sz = len + 1; ++total_strings; total_size += sz; /* If the string we want is too large to fit into a single buffer, then no existing cache is large enough. Add it directly to the fullcache. */ if (sz > BUFSIZE) { sp = new_cache (&fullcache, sz); return copy_string (sp, str, len); } /* Find the first cache with enough free space. */ for (; *spp != NULL; spp = &(*spp)->next) if ((*spp)->bytesfree > sz) break; sp = *spp; /* If nothing is big enough, make a new cache at the front. */ if (sp == NULL) { sp = new_cache (&strcache, BUFSIZE); spp = &strcache; } /* Add the string to this cache. */ res = copy_string (sp, str, len); /* If the amount free in this cache is less than the average string size, consider it full and move it to the full list. */ if (total_strings > 20 && sp->bytesfree < (total_size / total_strings) + 1) { *spp = sp->next; sp->next = fullcache; fullcache = sp; } return res; } /* For strings too large for the strcache, we just save them in a list. */ struct hugestring { struct hugestring *next; /* The next string. */ char buffer[1]; /* The string. */ }; static struct hugestring *hugestrings = NULL; static const char * add_hugestring (const char *str, size_t len) { struct hugestring *new = xmalloc (sizeof (struct hugestring) + len); memcpy (new->buffer, str, len); new->buffer[len] = '\0'; new->next = hugestrings; hugestrings = new; return new->buffer; } /* Hash table of strings in the cache. */ static unsigned long str_hash_1 (const void *key) { return_ISTRING_HASH_1 ((const char *) key); } static unsigned long str_hash_2 (const void *key) { return_ISTRING_HASH_2 ((const char *) key); } static int str_hash_cmp (const void *x, const void *y) { return_ISTRING_COMPARE ((const char *) x, (const char *) y); } static struct hash_table strings; static unsigned long total_adds = 0; static const char * add_hash (const char *str, size_t len) { char *const *slot; const char *key; /* If it's too large for the string cache, just copy it. We don't bother trying to match these. */ if (len > USHRT_MAX - 1) return add_hugestring (str, len); /* Look up the string in the hash. If it's there, return it. */ slot = (char *const *) hash_find_slot (&strings, str); key = *slot; /* Count the total number of add operations we performed. */ ++total_adds; if (!HASH_VACANT (key)) return key; /* Not there yet so add it to a buffer, then into the hash table. */ key = add_string (str, (sc_buflen_t)len); hash_insert_at (&strings, key, slot); return key; } /* Returns true if the string is in the cache; false if not. */ int strcache_iscached (const char *str) { struct strcache *sp; for (sp = strcache; sp != 0; sp = sp->next) if (str >= sp->buffer && str < sp->buffer + sp->end) return 1; for (sp = fullcache; sp != 0; sp = sp->next) if (str >= sp->buffer && str < sp->buffer + sp->end) return 1; { struct hugestring *hp; for (hp = hugestrings; hp != 0; hp = hp->next) if (str == hp->buffer) return 1; } return 0; } /* If the string is already in the cache, return a pointer to the cached version. If not, add it then return a pointer to the cached version. Note we do NOT take control of the string passed in. */ const char * strcache_add (const char *str) { return add_hash (str, strlen (str)); } const char * strcache_add_len (const char *str, size_t len) { /* If we're not given a nul-terminated string we have to create one, because the hashing functions expect it. */ if (str[len] != '\0') { char *key = alloca (len + 1); memcpy (key, str, len); key[len] = '\0'; str = key; } return add_hash (str, len); } void strcache_init (void) { hash_init (&strings, 8000, str_hash_1, str_hash_2, str_hash_cmp); } /* Generate some stats output. */ void strcache_print_stats (const char *prefix) { const struct strcache *sp; unsigned long numbuffs = 0, fullbuffs = 0; unsigned long totfree = 0, maxfree = 0, minfree = BUFSIZE; if (! strcache) { printf (_("\n%s No strcache buffers\n"), prefix); return; } /* Count the first buffer separately since it's not full. */ for (sp = strcache->next; sp != NULL; sp = sp->next) { sc_buflen_t bf = sp->bytesfree; totfree += bf; maxfree = (bf > maxfree ? bf : maxfree); minfree = (bf < minfree ? bf : minfree); ++numbuffs; } for (sp = fullcache; sp != NULL; sp = sp->next) { sc_buflen_t bf = sp->bytesfree; totfree += bf; maxfree = (bf > maxfree ? bf : maxfree); minfree = (bf < minfree ? bf : minfree); ++numbuffs; ++fullbuffs; } /* Make sure we didn't lose any buffers. */ assert (total_buffers == numbuffs + 1); printf (_("\n%s strcache buffers: %lu (%lu) / strings = %lu / storage = %lu B / avg = %lu B\n"), prefix, numbuffs + 1, fullbuffs, total_strings, total_size, (total_size / total_strings)); printf (_("%s current buf: size = %hu B / used = %hu B / count = %hu / avg = %u B\n"), prefix, (sc_buflen_t)BUFSIZE, strcache->end, strcache->count, (unsigned int) (strcache->end / strcache->count)); if (numbuffs) { /* Show information about non-current buffers. */ unsigned long sz = total_size - strcache->end; unsigned long cnt = total_strings - strcache->count; sc_buflen_t avgfree = (sc_buflen_t) (totfree / numbuffs); printf (_("%s other used: total = %lu B / count = %lu / avg = %lu B\n"), prefix, sz, cnt, sz / cnt); printf (_("%s other free: total = %lu B / max = %lu B / min = %lu B / avg = %hu B\n"), prefix, totfree, maxfree, minfree, avgfree); } printf (_("\n%s strcache performance: lookups = %lu / hit rate = %lu%%\n"), prefix, total_adds, (long unsigned)(100.0 * (total_adds - total_strings) / total_adds)); fputs (_("# hash-table stats:\n# "), stdout); hash_print_stats (&strings, stdout); } ================================================ FILE: src/variable.c ================================================ /* Internals of variables for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include "filedef.h" #include "debug.h" #include "dep.h" #include "job.h" #include "commands.h" #include "variable.h" #include "os.h" #include "rule.h" #if MK_OS_W32 #include "pathstuff.h" #endif #include "hash.h" #include "warning.h" /* Incremented every time we enter target_environment(). */ unsigned long long env_recursion = 0; /* Incremented every time we add or remove a global variable. */ static unsigned long variable_changenum = 0; /* Chain of all pattern-specific variables. */ static struct pattern_var *pattern_vars = NULL; /* Pointer to the last struct in the pack of a specific size, from 1 to 255.*/ static struct pattern_var *last_pattern_vars[256]; /* Create a new pattern-specific variable struct. The new variable is inserted into the PATTERN_VARS list in the shortest patterns first order to support the shortest stem matching (the variables are matched in the reverse order so the ones with the longest pattern will be considered first). Variables with the same pattern length are inserted in the definition order. */ struct pattern_var * create_pattern_var (const char *target, const char *suffix) { size_t len = strlen (target); struct pattern_var *p = xcalloc (sizeof (struct pattern_var)); if (pattern_vars != 0) { if (len < 256 && last_pattern_vars[len] != 0) { p->next = last_pattern_vars[len]->next; last_pattern_vars[len]->next = p; } else { /* Find the position where we can insert this variable. */ struct pattern_var **v; for (v = &pattern_vars; ; v = &(*v)->next) { /* Insert at the end of the pack so that patterns with the same length appear in the order they were defined .*/ if (*v == 0 || (*v)->len > len) { p->next = *v; *v = p; break; } } } } else { pattern_vars = p; p->next = 0; } p->target = target; p->len = len; p->suffix = suffix + 1; if (len < 256) last_pattern_vars[len] = p; return p; } /* Look up a target in the pattern-specific variable list. */ static struct pattern_var * lookup_pattern_var (struct pattern_var *start, const char *target, size_t targlen) { struct pattern_var *p; for (p = start ? start->next : pattern_vars; p != 0; p = p->next) { const char *stem; size_t stemlen; if (p->len > targlen) /* It can't possibly match. */ continue; /* From the lengths of the filename and the pattern parts, find the stem: the part of the filename that matches the %. */ stem = target + (p->suffix - p->target - 1); stemlen = targlen - p->len + 1; /* Compare the text in the pattern before the stem, if any. */ if (stem > target && !strneq (p->target, target, stem - target)) continue; /* Compare the text in the pattern after the stem, if any. We could test simply using streq, but this way we compare the first two characters immediately. This saves time in the very common case where the first character matches because it is a period. */ if (*p->suffix == stem[stemlen] && (*p->suffix == '\0' || streq (&p->suffix[1], &stem[stemlen+1]))) break; } return p; } /* Hash table of all global variable definitions. */ static unsigned long variable_hash_1 (const void *keyv) { struct variable const *key = (struct variable const *) keyv; return_STRING_N_HASH_1 (key->name, key->length); } static unsigned long variable_hash_2 (const void *keyv) { struct variable const *key = (struct variable const *) keyv; return_STRING_N_HASH_2 (key->name, key->length); } static int variable_hash_cmp (const void *xv, const void *yv) { struct variable const *x = (struct variable const *) xv; struct variable const *y = (struct variable const *) yv; int result = x->length - y->length; if (result) return result; return_STRING_N_COMPARE (x->name, y->name, x->length); } #ifndef VARIABLE_BUCKETS #define VARIABLE_BUCKETS 523 #endif #ifndef PERFILE_VARIABLE_BUCKETS #define PERFILE_VARIABLE_BUCKETS 23 #endif #ifndef SMALL_SCOPE_VARIABLE_BUCKETS #define SMALL_SCOPE_VARIABLE_BUCKETS 13 #endif static struct variable_set global_variable_set; static struct variable_set_list global_setlist = { 0, &global_variable_set, 0 }; struct variable_set_list *current_variable_set_list = &global_setlist; /* Implement variables. */ static void check_valid_name (const floc* flocp, const char *name, size_t length) { const char *cp, *end; if (!warn_check (wt_invalid_var)) return; for (cp = name, end = name + length; cp < end; ++cp) if (ISSPACE (*cp)) break; if (cp == end) return; warning (wt_invalid_var, flocp, ONS (format, 0, _("invalid variable name '%.*s'"), (int)length, name)); } void init_hash_global_variable_set (void) { hash_init (&global_variable_set.table, VARIABLE_BUCKETS, variable_hash_1, variable_hash_2, variable_hash_cmp); } /* Define variable named NAME with value VALUE in SET. VALUE is copied. LENGTH is the length of NAME, which does not need to be null-terminated. ORIGIN specifies the origin of the variable (makefile, command line or environment). If RECURSIVE is nonzero a flag is set in the variable saying that it should be recursively re-expanded. */ struct variable * define_variable_in_set (const char *name, size_t length, const char *value, enum variable_origin origin, int recursive, struct variable_set *set, const floc *flocp) { struct variable *v; struct variable **var_slot; struct variable var_key; check_valid_name (flocp, name, length); if (set == NULL) set = &global_variable_set; var_key.name = (char *) name; var_key.length = (unsigned int) length; var_slot = (struct variable **) hash_find_slot (&set->table, &var_key); v = *var_slot; #if MK_OS_VMS /* VMS does not populate envp[] with DCL symbols and logical names which historically are mapped to environment variables. If the variable is not yet defined, then we need to check if getenv() can find it. Do not do this for origin == o_env to avoid infinite recursion */ if (HASH_VACANT (v) && (origin != o_env)) { struct variable * vms_variable; char * vname = alloca (length + 1); char * vvalue; strncpy (vname, name, length); vvalue = getenv(vname); /* Values starting with '$' are probably foreign commands. We want to treat them as Shell aliases and not look them up here */ if ((vvalue != NULL) && (vvalue[0] != '$')) { vms_variable = lookup_variable(name, length); /* Refresh the slot */ var_slot = (struct variable **) hash_find_slot (&set->table, &var_key); v = *var_slot; } } #endif if (env_overrides && origin == o_env) origin = o_env_override; if (! HASH_VACANT (v)) { if (env_overrides && v->origin == o_env) /* V came from in the environment. Since it was defined before the switches were parsed, it wasn't affected by -e. */ v->origin = o_env_override; /* A variable of this name is already defined. If the old definition is from a stronger source than this one, don't redefine it. */ if ((int) origin >= (int) v->origin) { free (v->value); v->value = xstrdup (value); if (flocp != 0) v->fileinfo = *flocp; else v->fileinfo.filenm = 0; v->origin = origin; v->recursive = recursive; } return v; } /* Create a new variable definition and add it to the hash table. */ v = xcalloc (sizeof (struct variable)); v->name = xstrndup (name, length); v->length = (unsigned int) length; hash_insert_at (&set->table, v, var_slot); if (set == &global_variable_set) ++variable_changenum; v->value = xstrdup (value); if (flocp != 0) v->fileinfo = *flocp; v->origin = origin; v->recursive = recursive; v->export = v_default; v->exportable = 1; /* Check the nul-terminated variable name. */ name = v->name; if (*name != '_' && (*name < 'A' || *name > 'Z') && (*name < 'a' || *name > 'z')) v->exportable = 0; else { for (++name; *name != '\0'; ++name) if (*name != '_' && (*name < 'a' || *name > 'z') && (*name < 'A' || *name > 'Z') && !ISDIGIT(*name)) break; if (*name != '\0') v->exportable = 0; } return v; } /* Undefine variable named NAME in SET. LENGTH is the length of NAME, which does not need to be null-terminated. ORIGIN specifies the origin of the variable (makefile, command line or environment). */ static void free_variable_name_and_value (const void *item) { struct variable *v = (struct variable *) item; free (v->name); free (v->value); } void free_variable_set (struct variable_set_list *list) { hash_map (&list->set->table, free_variable_name_and_value); hash_free (&list->set->table, 1); free (list->set); free (list); } void undefine_variable_in_set (const floc *flocp, const char *name, size_t length, enum variable_origin origin, struct variable_set *set) { struct variable *v; struct variable **var_slot; struct variable var_key; check_valid_name (flocp, name, length); if (set == NULL) set = &global_variable_set; var_key.name = (char *) name; var_key.length = (unsigned int) length; var_slot = (struct variable **) hash_find_slot (&set->table, &var_key); if (env_overrides && origin == o_env) origin = o_env_override; v = *var_slot; if (! HASH_VACANT (v)) { if (env_overrides && v->origin == o_env) /* V came from in the environment. Since it was defined before the switches were parsed, it wasn't affected by -e. */ v->origin = o_env_override; /* Undefine only if this undefinition is from an equal or stronger source than the variable definition. */ if ((int) origin >= (int) v->origin) { hash_delete_at (&set->table, var_slot); free_variable_name_and_value (v); free (v); if (set == &global_variable_set) ++variable_changenum; } } } /* If the variable passed in is "special", handle its special nature. Currently there are two such variables, both used for introspection: .VARIABLES expands to a list of all the variables defined in this instance of make. .TARGETS expands to a list of all the targets defined in this instance of make. Returns the variable reference passed in. */ #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500) static struct variable * lookup_special_var (struct variable *var) { static unsigned long last_changenum = 0; /* This one actually turns out to be very hard, due to the way the parser records targets. The way it works is that target information is collected internally until make knows the target is completely specified. Only when it sees that some new construct (a new target or variable) is defined does make know that the previous one is done. In short, this means that if you do this: all: TARGS := $(.TARGETS) then $(TARGS) won't contain "all", because it's not until after the variable is created that the previous target is completed. Changing this would be a major pain. I think a less complex way to do it would be to pre-define the target files as soon as the first line is parsed, then come back and do the rest of the definition as now. That would allow $(.TARGETS) to be correct without a major change to the way the parser works. if (streq (var->name, ".TARGETS")) var->value = build_target_list (var->value); else */ if (variable_changenum != last_changenum && streq (var->name, ".VARIABLES")) { size_t max = EXPANSION_INCREMENT (strlen (var->value)); size_t len; char *p; struct variable **vp = (struct variable **) global_variable_set.table.ht_vec; struct variable **end = &vp[global_variable_set.table.ht_size]; /* Make sure we have at least MAX bytes in the allocated buffer. */ var->value = xrealloc (var->value, max); /* Walk through the hash of variables, constructing a list of names. */ p = var->value; len = 0; for (; vp < end; ++vp) if (!HASH_VACANT (*vp)) { struct variable *v = *vp; int l = v->length; len += l + 1; if (len > max) { size_t off = p - var->value; max += EXPANSION_INCREMENT (l + 1); var->value = xrealloc (var->value, max); p = &var->value[off]; } p = mempcpy (p, v->name, l); *(p++) = ' '; } *(p-1) = '\0'; /* Remember the current variable change number. */ last_changenum = variable_changenum; } return var; } /* Check the variable name for validity. */ static void check_variable_reference (const char *name, size_t length) { const char *cp, *end; if (!warn_check (wt_invalid_ref)) return; for (cp = name, end = name + length; cp < end; ++cp) if (ISSPACE (*cp)) break; if (cp == end) return; warning (wt_invalid_ref, *expanding_var, ONS (format, 0, _("invalid variable reference '%.*s'"), (int)length, name)); } /* Lookup a variable whose name is a string starting at NAME and with LENGTH chars. NAME need not be null-terminated. Returns address of the 'struct variable' containing all info on the variable, or nil if no such variable is defined. */ struct variable * lookup_variable (const char *name, size_t length) { const struct variable_set_list *setlist; struct variable var_key; int is_parent = 0; check_variable_reference (name, length); var_key.name = (char *) name; var_key.length = (unsigned int) length; for (setlist = current_variable_set_list; setlist != 0; setlist = setlist->next) { const struct variable_set *set = setlist->set; struct variable *v; v = hash_find_item ((struct hash_table *) &set->table, &var_key); if (v && (!is_parent || !v->private_var)) return v->special ? lookup_special_var (v) : v; is_parent |= setlist->next_is_parent; } #if MK_OS_VMS /* VMS doesn't populate envp[] with DCL symbols and logical names, which historically are mapped to environment variables and returned by getenv(). */ { char *vname = alloca (length + 1); char *value; strncpy (vname, name, length); vname[length] = 0; value = getenv (vname); if (value != 0) { char *sptr; int scnt; sptr = value; scnt = 0; while ((sptr = strchr (sptr, '$'))) { scnt++; sptr++; } if (scnt > 0) { char *nvalue; char *nptr; nvalue = alloca (strlen (value) + scnt + 1); sptr = value; nptr = nvalue; while (*sptr) { if (*sptr == '$') { *nptr++ = '$'; *nptr++ = '$'; } else *nptr++ = *sptr; sptr++; } *nptr = '\0'; return define_variable (vname, length, nvalue, o_env, 1); } return define_variable (vname, length, value, o_env, 1); } } #endif /* MK_OS_VMS */ return 0; } /* Lookup a variable whose name is a string starting at NAME and with LENGTH chars. NAME need not be null-terminated. Returns address of the 'struct variable' containing all info on the variable, or nil if no such variable is defined. */ struct variable * lookup_variable_for_file (const char *name, size_t length, struct file *file) { struct variable *var; struct variable_set_list *savev; if (file == NULL) return lookup_variable (name, length); install_file_context (file, &savev, NULL); var = lookup_variable (name, length); restore_file_context (savev, NULL); return var; } /* Lookup a variable whose name is a string starting at NAME and with LENGTH chars in set SET. NAME need not be null-terminated. Returns address of the 'struct variable' containing all info on the variable, or nil if no such variable is defined. */ struct variable * lookup_variable_in_set (const char *name, size_t length, const struct variable_set *set) { struct variable var_key; check_variable_reference (name, length); var_key.name = (char *) name; var_key.length = (unsigned int) length; return hash_find_item ((struct hash_table *) &set->table, &var_key); } /* Initialize FILE's variable set list. If FILE already has a variable set list, the topmost variable set is left intact, but the the rest of the chain is replaced with FILE->parent's setlist. If FILE is a double-colon rule, then we will use the "root" double-colon target's variable set as the parent of FILE's variable set. If we're READING a makefile, don't do the pattern variable search now, since the pattern variable might not have been defined yet. */ void initialize_file_variables (struct file *file, int reading) { struct variable_set_list *l = file->variables; if (l == 0) { l = (struct variable_set_list *) xmalloc (sizeof (struct variable_set_list)); l->set = xmalloc (sizeof (struct variable_set)); hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS, variable_hash_1, variable_hash_2, variable_hash_cmp); file->variables = l; } /* If this is a double-colon, then our "parent" is the "root" target for this double-colon rule. Since that rule has the same name, parent, etc. we can just use its variables as the "next" for ours. */ if (file->double_colon && file->double_colon != file) { initialize_file_variables (file->double_colon, reading); l->next = file->double_colon->variables; l->next_is_parent = 0; return; } if (file->parent == 0) l->next = &global_setlist; else { initialize_file_variables (file->parent, reading); l->next = file->parent->variables; } l->next_is_parent = 1; /* If we're not reading makefiles and we haven't looked yet, see if we can find pattern variables for this target. */ if (!reading && !file->pat_searched) { struct pattern_var *p; const size_t targlen = strlen (file->name); p = lookup_pattern_var (0, file->name, targlen); if (p != 0) { struct variable_set_list *global = current_variable_set_list; /* We found at least one. Set up a new variable set to accumulate all the pattern variables that match this target. */ file->pat_variables = create_new_variable_set (); current_variable_set_list = file->pat_variables; do { /* We found one, so insert it into the set. */ struct variable *v; if (p->variable.flavor == f_simple) { v = define_variable_loc ( p->variable.name, strlen (p->variable.name), p->variable.value, p->variable.origin, 0, &p->variable.fileinfo); v->flavor = f_simple; } else v = do_variable_definition ( &p->variable.fileinfo, p->variable.name, p->variable.value, p->variable.origin, p->variable.flavor, p->variable.conditional, s_pattern); /* Also mark it as a per-target and copy export status. */ v->per_target = p->variable.per_target; v->export = p->variable.export; v->private_var = p->variable.private_var; } while ((p = lookup_pattern_var (p, file->name, targlen)) != 0); current_variable_set_list = global; } file->pat_searched = 1; } /* If we have a pattern variable match, set it up. */ if (file->pat_variables != 0) { file->pat_variables->next = l->next; file->pat_variables->next_is_parent = l->next_is_parent; l->next = file->pat_variables; l->next_is_parent = 0; } } /* Pop the top set off the current variable set list, and free all its storage. */ struct variable_set_list * create_new_variable_set (void) { struct variable_set_list *setlist; struct variable_set *set; set = xmalloc (sizeof (struct variable_set)); hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS, variable_hash_1, variable_hash_2, variable_hash_cmp); setlist = (struct variable_set_list *) xmalloc (sizeof (struct variable_set_list)); setlist->set = set; setlist->next = current_variable_set_list; setlist->next_is_parent = 0; return setlist; } /* Create a new variable set and push it on the current setlist. If we're pushing a global scope (that is, the current scope is the global scope) then we need to "push" it the other way: file variable sets point directly to the global_setlist so we need to replace that with the new one. */ struct variable_set_list * push_new_variable_scope (void) { current_variable_set_list = create_new_variable_set (); if (current_variable_set_list->next == &global_setlist) { /* It was the global, so instead of new -> &global we want to replace &global with the new one and have &global -> new, with current still pointing to &global */ struct variable_set *set = current_variable_set_list->set; current_variable_set_list->set = global_setlist.set; global_setlist.set = set; current_variable_set_list->next = global_setlist.next; global_setlist.next = current_variable_set_list; current_variable_set_list = &global_setlist; } return current_variable_set_list; } void pop_variable_scope (void) { struct variable_set_list *setlist; struct variable_set *set; /* Can't call this if there's no scope to pop! */ assert (current_variable_set_list->next != NULL); if (current_variable_set_list != &global_setlist) { /* We're not pointing to the global setlist, so pop this one. */ setlist = current_variable_set_list; set = setlist->set; current_variable_set_list = setlist->next; } else { /* This set is the one in the global_setlist, but there is another global set beyond that. We want to copy that set to global_setlist, then delete what used to be in global_setlist. */ setlist = global_setlist.next; set = global_setlist.set; global_setlist.set = setlist->set; global_setlist.next = setlist->next; global_setlist.next_is_parent = setlist->next_is_parent; } /* Free the one we no longer need. */ free (setlist); hash_map (&set->table, free_variable_name_and_value); hash_free (&set->table, 1); free (set); } /* Install a new global context for FILE so that errors/warnings are shown in that context. Sets OLDLIST to the previous list, and if not NULL sets OLDFLOC to reading_file and changes reading_file to the current FILE. Use restore_file_context() to undo this. */ void install_file_context (struct file *file, struct variable_set_list **oldlist, const floc **oldfloc) { *oldlist = current_variable_set_list; current_variable_set_list = file->variables; if (oldfloc) { *oldfloc = reading_file; if (file->cmds && file->cmds->fileinfo.filenm) reading_file = &file->cmds->fileinfo; else reading_file = NULL; } } /* Restore a saved global context from OLDLIST. If OLDFLOC is not NULL, set reading_file back to that value. */ void restore_file_context (struct variable_set_list *oldlist, const floc *oldfloc) { current_variable_set_list = oldlist; if (oldfloc) reading_file = oldfloc; } /* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */ static void merge_variable_sets (struct variable_set *to_set, struct variable_set *from_set) { struct variable **from_var_slot = (struct variable **) from_set->table.ht_vec; struct variable **from_var_end = from_var_slot + from_set->table.ht_size; int inc = to_set == &global_variable_set ? 1 : 0; for ( ; from_var_slot < from_var_end; from_var_slot++) if (! HASH_VACANT (*from_var_slot)) { struct variable *from_var = *from_var_slot; struct variable **to_var_slot = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot); if (HASH_VACANT (*to_var_slot)) { hash_insert_at (&to_set->table, from_var, to_var_slot); variable_changenum += inc; } else { /* GKM FIXME: delete in from_set->table */ free (from_var->value); free (from_var); } } } /* Merge SETLIST1 into SETLIST0, freeing unused storage in SETLIST1. */ void merge_variable_set_lists (struct variable_set_list **setlist0, struct variable_set_list *setlist1) { struct variable_set_list *to = *setlist0; struct variable_set_list *last0 = 0; /* If there's nothing to merge, stop now. */ if (!setlist1 || setlist1 == &global_setlist) return; if (to) { /* These loops rely on the fact that all setlists terminate with the global setlist (before NULL). If not, arguably we SHOULD die. */ /* Make sure that setlist1 is not already a subset of setlist0. */ while (to != &global_setlist) { if (to == setlist1) return; to = to->next; } to = *setlist0; while (setlist1 != &global_setlist && to != &global_setlist) { struct variable_set_list *from = setlist1; setlist1 = setlist1->next; merge_variable_sets (to->set, from->set); last0 = to; to = to->next; } } if (setlist1 != &global_setlist) { if (last0 == 0) *setlist0 = setlist1; else last0->next = setlist1; } } /* Define the automatic variables, and record the addresses of their structures so we can change their values quickly. */ void define_automatic_variables (void) { struct variable *v; char buf[200]; sprintf (buf, "%u", makelevel); define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0); sprintf (buf, "%s%s%s", version_string, (remote_description == 0 || remote_description[0] == '\0') ? "" : "-", (remote_description == 0 || remote_description[0] == '\0') ? "" : remote_description); define_variable_cname ("MAKE_VERSION", buf, o_default, 0); define_variable_cname ("MAKE_HOST", make_host, o_default, 0); #if MK_OS_DOS /* Allow to specify a special shell just for Make, and use $COMSPEC as the default $SHELL when appropriate. */ { static char shell_str[] = "SHELL"; const int shlen = sizeof (shell_str) - 1; struct variable *mshp = lookup_variable ("MAKESHELL", 9); struct variable *comp = lookup_variable ("COMSPEC", 7); /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect. */ if (mshp) (void) define_variable (shell_str, shlen, mshp->value, o_env_override, 0); else if (comp) { /* $(COMSPEC) shouldn't override $(SHELL). */ struct variable *shp = lookup_variable (shell_str, shlen); if (!shp) (void) define_variable (shell_str, shlen, comp->value, o_env, 0); } } #elif MK_OS_OS2 { static char shell_str[] = "SHELL"; const int shlen = sizeof (shell_str) - 1; struct variable *shell = lookup_variable (shell_str, shlen); struct variable *replace = lookup_variable ("MAKESHELL", 9); /* if $MAKESHELL is defined in the environment assume o_env_override */ if (replace && *replace->value && replace->origin == o_env) replace->origin = o_env_override; /* if $MAKESHELL is not defined use $SHELL but only if the variable did not come from the environment */ if (!replace || !*replace->value) if (shell && *shell->value && (shell->origin == o_env || shell->origin == o_env_override)) { /* overwrite whatever we got from the environment */ free (shell->value); shell->value = xstrdup (default_shell); shell->origin = o_default; } /* Some people do not like cmd to be used as the default if $SHELL is not defined in the Makefile. With -DNO_CMD_DEFAULT you can turn off this behaviour */ # ifndef NO_CMD_DEFAULT /* otherwise use $COMSPEC */ if (!replace || !*replace->value) replace = lookup_variable ("COMSPEC", 7); /* otherwise use $OS2_SHELL */ if (!replace || !*replace->value) replace = lookup_variable ("OS2_SHELL", 9); # else # warning NO_CMD_DEFAULT: GNU Make will not use CMD.EXE as default shell # endif if (replace && *replace->value) /* overwrite $SHELL */ (void) define_variable (shell_str, shlen, replace->value, replace->origin, 0); else /* provide a definition if there is none */ (void) define_variable (shell_str, shlen, default_shell, o_default, 0); } #endif /* This won't override any definition, but it will provide one if there isn't one there. */ v = define_variable_cname ("SHELL", default_shell, o_default, 0); #if MK_OS_DOS v->export = v_export; /* Export always SHELL. */ #endif /* On MSDOS we do use SHELL from environment, since it isn't a standard environment variable on MSDOS, so whoever sets it, does that on purpose. On OS/2 we do not use SHELL from environment but we have already handled that problem above. */ #if !MK_OS_DOS && !MK_OS_OS2 /* Don't let SHELL come from the environment. */ if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override) { free (v->value); v->origin = o_file; v->value = xstrdup (default_shell); } #endif /* Make sure MAKEFILES gets exported if it is set. */ v = define_variable_cname ("MAKEFILES", "", o_default, 0); v->export = v_ifset; /* Define the magic D and F variables in terms of the automatic variables they are variations of. */ #if MK_OS_DOS || MK_OS_W32 /* For consistency, remove the trailing backslash as well as slash. */ define_variable_cname ("@D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $@)))", o_automatic, 1); define_variable_cname ("%D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $%)))", o_automatic, 1); define_variable_cname ("*D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $*)))", o_automatic, 1); define_variable_cname ("export) { case v_export: break; case v_noexport: return 0; case v_ifset: if (v->origin == o_default) return 0; break; case v_default: if (v->origin == o_default || v->origin == o_automatic) /* Only export default variables by explicit request. */ return 0; /* The variable doesn't have a name that can be exported. */ if (! v->exportable) return 0; if (! export_all_variables && v->origin != o_command && v->origin != o_env && v->origin != o_env_override) return 0; break; } return 1; } /* Create a new environment for FILE's commands. If FILE is nil, this is for the 'shell' function. The child's MAKELEVEL variable is incremented. If recursive is true then we're running a recursive make, else not. */ char ** target_environment (struct file *file, int recursive) { struct variable_set_list *set_list; struct variable_set_list *s; struct hash_table table; struct variable **v_slot; struct variable **v_end; char **result_0; char **result; const char *invalid = NULL; /* If we got no value from the environment then never add the default. */ int added_SHELL = shell_var.value == 0; int found_makelevel = 0; int found_mflags = 0; int found_makeflags = 0; /* If file is NULL we're creating the target environment for $(shell ...) Remember this so we can just ignore recursion. */ if (!file) ++env_recursion; /* We need to update makeflags if (a) we're not recurive, (b) jobserver_auth is enabled, and (c) we need to add invalidation. */ if (!recursive && jobserver_auth) invalid = jobserver_get_invalid_auth (); if (file) set_list = file->variables; else set_list = current_variable_set_list; hash_init (&table, VARIABLE_BUCKETS, variable_hash_1, variable_hash_2, variable_hash_cmp); /* Run through all the variable sets in the list, accumulating variables in TABLE. We go from most specific to least, so the first variable we encounter is the keeper. */ for (s = set_list; s != 0; s = s->next) { struct variable_set *set = s->set; const int islocal = s == set_list; const int isglobal = set == &global_variable_set; v_slot = (struct variable **) set->table.ht_vec; v_end = v_slot + set->table.ht_size; for ( ; v_slot < v_end; v_slot++) if (! HASH_VACANT (*v_slot)) { struct variable **evslot; struct variable *v = *v_slot; if (!islocal && v->private_var) continue; evslot = (struct variable **) hash_find_slot (&table, v); if (HASH_VACANT (*evslot)) { /* We'll always add target-specific variables, since we may discover that they should be exported later: we'll check again below. For global variables only add them if they're exportable. */ if (!isglobal || should_export (v)) hash_insert_at (&table, v, evslot); } else if ((*evslot)->export == v_default) /* We already have a variable but we don't know its status. */ (*evslot)->export = v->export; } } result = result_0 = xmalloc ((table.ht_fill + 3) * sizeof (char *)); v_slot = (struct variable **) table.ht_vec; v_end = v_slot + table.ht_size; for ( ; v_slot < v_end; v_slot++) if (! HASH_VACANT (*v_slot)) { struct variable *v = *v_slot; char *value = v->value; char *cp = NULL; /* This might be here because it was a target-specific variable that we didn't know the status of when we added it. */ if (! should_export (v)) continue; /* If V is recursively expanded and didn't come from the environment, expand its value. If it came from the environment, it should go back into the environment unchanged... except MAKEFLAGS. */ if (v->recursive && ((v->origin != o_env && v->origin != o_env_override) || streq (v->name, MAKEFLAGS_NAME))) value = cp = recursively_expand_for_file (v, file); /* If this is the SHELL variable remember we already added it. */ if (!added_SHELL && streq (v->name, "SHELL")) { added_SHELL = 1; goto setit; } /* If this is MAKELEVEL, update it. */ if (!found_makelevel && streq (v->name, MAKELEVEL_NAME)) { char val[INTSTR_LENGTH + 1]; sprintf (val, "%u", makelevel + 1); free (cp); value = cp = xstrdup (val); found_makelevel = 1; goto setit; } /* If we need to reset jobserver, check for MAKEFLAGS / MFLAGS. */ if (invalid) { if (!found_makeflags && streq (v->name, MAKEFLAGS_NAME)) { char *mf; char *vars; found_makeflags = 1; if (!strstr (value, " --" JOBSERVER_AUTH_OPT "=")) goto setit; /* The invalid option must come before variable overrides. */ vars = strstr (value, " -- "); if (!vars) mf = xstrdup (concat (2, value, invalid)); else { size_t lf = vars - value; size_t li = strlen (invalid); mf = xmalloc (strlen (value) + li + 1); strcpy (mempcpy (mempcpy (mf, value, lf), invalid, li), vars); } free (cp); value = cp = mf; if (found_mflags) invalid = NULL; goto setit; } if (!found_mflags && streq (v->name, "MFLAGS")) { const char *mf; found_mflags = 1; if (!strstr (value, " --" JOBSERVER_AUTH_OPT "=")) goto setit; if (v->origin != o_env) goto setit; mf = concat (2, value, invalid); free (cp); value = cp = xstrdup (mf); if (found_makeflags) invalid = NULL; goto setit; } } #if MK_OS_W32 if (streq (v->name, "Path") || streq (v->name, "PATH")) { if (!cp) cp = xstrdup (value); value = convert_Path_to_windows32 (cp, ';'); goto setit; } #endif setit: *result++ = xstrdup (concat (3, v->name, "=", value)); free (cp); } if (!added_SHELL) *result++ = xstrdup (concat (3, shell_var.name, "=", shell_var.value)); if (!found_makelevel) { char val[MAKELEVEL_LENGTH + 1 + INTSTR_LENGTH + 1]; sprintf (val, "%s=%u", MAKELEVEL_NAME, makelevel + 1); *result++ = xstrdup (val); } *result = NULL; hash_free (&table, 0); if (!file) --env_recursion; return result_0; } static struct variable * set_special_var (struct variable *var, enum variable_origin origin) { if (streq (var->name, MAKEFLAGS_NAME)) reset_makeflags (origin); else if (streq (var->name, RECIPEPREFIX_NAME)) /* The user is resetting the command introduction prefix. This has to happen immediately, so that subsequent rules are interpreted properly. */ cmd_prefix = var->value[0]=='\0' ? RECIPEPREFIX_DEFAULT : var->value[0]; else if (streq (var->name, WARNINGS_NAME)) { /* It's weird but for .WARNINGS to make sense we need to expand them when they are set, even if it's a recursive variable. */ char *actions = allocated_expand_variable (STRING_SIZE_TUPLE (WARNINGS_NAME)); decode_warn_actions (actions, &var->fileinfo); free (actions); } return var; } /* Given a string, shell-execute it and return a malloc'ed string of the * result. This removes only ONE newline (if any) at the end, for maximum * compatibility with the *BSD makes. If it fails, returns NULL. */ static char * shell_result (const char *p) { char *buf; size_t len; char *args[2]; install_variable_buffer (&buf, &len); args[0] = (char *) p; args[1] = NULL; func_shell_base (variable_buffer, args, 0); return swap_variable_buffer (buf, len); } /* Given a variable, a value, and a flavor, define the variable. See the try_variable_definition() function for details on the parameters. */ struct variable * do_variable_definition (const floc *flocp, const char *varname, const char *value, enum variable_origin origin, enum variable_flavor flavor, int conditional, enum variable_scope scope) { const char *newval; char *alloc_value = NULL; struct variable *v; int append = 0; /* Conditional variable definition: only set if the var is not defined. */ if (conditional) { v = lookup_variable (varname, strlen (varname)); if (v) return v; } /* Calculate the variable's new value in VALUE. */ switch (flavor) { case f_simple: /* A simple variable definition "var := value". Expand the value. We have to allocate memory since otherwise it'll clobber the variable buffer, and we may still need that if we're looking at a target-specific variable. */ newval = alloc_value = allocated_expand_string (value); break; case f_expand: { /* A POSIX "var :::= value" assignment. Expand the value, then it becomes a recursive variable. After expansion convert all '$' tokens to '$$' to resolve to '$' when recursively expanded. */ char *t = allocated_expand_string (value); char *np = alloc_value = xmalloc (strlen (t) * 2 + 1); char *op = t; while (op[0] != '\0') { if (op[0] == '$') *(np++) = '$'; *(np++) = *(op++); } *np = '\0'; free (t); newval = alloc_value; break; } case f_shell: { /* A shell definition "var != value". Expand value, pass it to the shell, and store the result in recursively-expanded var. */ char *q = allocated_expand_string (value); alloc_value = shell_result (q); free (q); flavor = f_recursive; newval = alloc_value; break; } case f_recursive: /* A recursive variable definition "var = value". The value is used verbatim. */ newval = value; break; case f_append: case f_append_value: { int override = 0; if (scope == s_global) v = lookup_variable (varname, strlen (varname)); else { /* When appending in a target/pattern variable context, we want to append only with other variables in the context of this target/pattern. */ append = 1; v = lookup_variable_in_set (varname, strlen (varname), current_variable_set_list->set); if (v) { /* Don't append from the global set if a previous non-appending target/pattern-specific variable definition exists. */ if (!v->append) append = 0; if (scope == s_pattern && (v->origin == o_env_override || v->origin == o_command)) { /* This is the case of multiple target/pattern specific definitions/appends, e.g. al%: hello := first al%: hello += second in the presence of a command line definition or an env override. Do not merge x->value and value here. For pattern-specific variables the values are merged in recursively_expand_for_file. */ override = 1; append = 1; } } } if (!v) { /* There was no old value: make this a recursive definition. */ newval = value; flavor = f_recursive; } else if (override) { /* Command line definition / env override takes precedence over a pattern/target-specific append. */ newval = value; /* Set flavor to f_recursive to recursively expand this variable at build time in recursively_expand_for_file. */ flavor = f_recursive; } else { /* Paste the old and new values together in VALUE. */ size_t oldlen, vallen, alloclen; const char *val; char *cp; char *tp = NULL; val = value; if (v->recursive) /* The previous definition of the variable was recursive. The new value is the unexpanded old and new values. */ flavor = f_recursive; else if (flavor != f_append_value) /* The previous definition of the variable was simple. The new value comes from the old value, which was expanded when it was set; and from the expanded new value. Allocate memory for the expansion as we may still need the rest of the buffer if we're looking at a target-specific variable. */ val = tp = allocated_expand_string (val); /* If the new value is empty, nothing to do. */ vallen = strlen (val); if (!vallen) { alloc_value = tp; goto done; } oldlen = strlen (v->value); alloclen = oldlen + 1 + vallen + 1; cp = alloc_value = xmalloc (alloclen); if (oldlen) { char *s; if (streq (varname, MAKEFLAGS_NAME) && (s = strstr (v->value, " -- ")) != NULL) /* We found a separator in MAKEFLAGS. Ignore variable assignments: set_special_var() will reconstruct things. */ cp = mempcpy (cp, v->value, s - v->value); else cp = mempcpy (cp, v->value, oldlen); *(cp++) = ' '; } memcpy (cp, val, vallen + 1); free (tp); newval = alloc_value; } } break; case f_bogus: default: /* Should not be possible. */ abort (); } assert (newval); #if MK_OS_DOS /* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but non-Unix systems don't conform to this default configuration (in fact, most of them don't even have '/bin'). On the other hand, $SHELL in the environment, if set, points to the real pathname of the shell. Therefore, we generally won't let lines like "SHELL=/bin/sh" from the Makefile override $SHELL from the environment. But first, we look for the basename of the shell in the directory where SHELL= points, and along the $PATH; if it is found in any of these places, we define $SHELL to be the actual pathname of the shell. Thus, if you have bash.exe installed as d:/unix/bash.exe, and d:/unix is on your $PATH, then SHELL=/usr/local/bin/bash will have the effect of defining SHELL to be "d:/unix/bash.exe". */ if ((origin == o_file || origin == o_override) && strcmp (varname, "SHELL") == 0) { PATH_VAR (shellpath); extern char * __dosexec_find_on_path (const char *, char *[], char *); /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */ if (__dosexec_find_on_path (p, NULL, shellpath)) { char *tp; for (tp = shellpath; *tp; tp++) if (*tp == '\\') *tp = '/'; v = define_variable_loc (varname, strlen (varname), shellpath, origin, flavor == f_recursive, flocp); } else { const char *shellbase, *bslash; struct variable *pathv = lookup_variable ("PATH", 4); char *path_string; char *fake_env[2]; size_t pathlen = 0; shellbase = strrchr (newval, '/'); bslash = strrchr (newval, '\\'); if (!shellbase || bslash > shellbase) shellbase = bslash; if (!shellbase && newval[1] == ':') shellbase = newval + 1; if (shellbase) shellbase++; else shellbase = newval; /* Search for the basename of the shell (with standard executable extensions) along the $PATH. */ if (pathv) pathlen = strlen (pathv->value); path_string = xmalloc (5 + pathlen + 2 + 1); /* On MSDOS, current directory is considered as part of $PATH. */ sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : ""); fake_env[0] = path_string; fake_env[1] = 0; if (__dosexec_find_on_path (shellbase, fake_env, shellpath)) { char *tp; for (tp = shellpath; *tp; tp++) if (*tp == '\\') *tp = '/'; v = define_variable_loc (varname, strlen (varname), shellpath, origin, flavor == f_recursive, flocp); } else v = lookup_variable (varname, strlen (varname)); free (path_string); } } else #endif /* MK_OS_DOS */ #if MK_OS_W32 if ((origin == o_file || origin == o_override || origin == o_command) && streq (varname, "SHELL")) { extern const char *default_shell; /* Call shell locator function. If it returns TRUE, then set no_default_sh_exe to indicate sh was found and set new value for SHELL variable. */ if (find_and_set_default_shell (newval)) { v = define_variable_in_set (varname, strlen (varname), default_shell, origin, flavor == f_recursive, (scope == s_global ? NULL : current_variable_set_list->set), flocp); no_default_sh_exe = 0; } else { char *tp = alloc_value; alloc_value = allocated_expand_string (newval); if (find_and_set_default_shell (alloc_value)) { v = define_variable_in_set (varname, strlen (varname), newval, origin, flavor == f_recursive, (scope == s_global ? NULL : current_variable_set_list->set), flocp); no_default_sh_exe = 0; } else v = lookup_variable (varname, strlen (varname)); free (tp); } } else v = NULL; /* If not $SHELL, or if $SHELL points to a program we didn't find, just process this variable "as usual". */ if (!v) #endif /* If we are defining variables inside an $(eval ...), we might have a different variable context pushed, not the global context (maybe we're inside a $(call ...) or something. Since this function is only ever invoked in places where we want to define globally visible variables, make sure we define this variable in the global set. */ v = define_variable_in_set (varname, strlen (varname), newval, origin, flavor == f_recursive || flavor == f_expand, (scope == s_global ? NULL : current_variable_set_list->set), flocp); v->append = append; v->conditional = conditional; done: free (alloc_value); return v->special ? set_special_var (v, origin) : v; } /* Parse P (a null-terminated string) as a variable definition. If it is not a variable definition, return NULL and the contents of *VAR are undefined, except NAME points to the first non-space character or EOS. If it is a variable definition, return a pointer to the char after the assignment token and set the following fields (only) of *VAR: name : name of the variable (ALWAYS SET) (NOT NUL-TERMINATED!) length : length of the variable name value : value of the variable (nul-terminated) flavor : flavor of the variable conditional : whether it's a conditional assignment Other values in *VAR are unchanged. */ char * parse_variable_definition (const char *str, struct variable *var) { const char *p = str; const char *end = NULL; NEXT_TOKEN (p); var->name = (char *)p; var->length = 0; var->conditional = 0; /* Walk through STR until we find a valid assignment operator. Each time through this loop P points to the next character to consider. */ while (1) { const char *start; int c = *p++; /* If we find a comment or EOS, it's not a variable definition. */ if (STOP_SET (c, MAP_COMMENT|MAP_NUL)) return NULL; if (ISBLANK (c)) { /* Variable names can't contain spaces so if this is the second set of spaces we know it's not a variable assignment. */ if (end) return NULL; end = p - 1; NEXT_TOKEN (p); continue; } /* This is the start of a token. */ start = p - 1; /* If we see a ? then it could be a conditional assignment. */ if (c == '?') { var->conditional = 1; c = *p++; } /* If we found = we're done! */ if (c == '=') { if (!end) end = start; var->flavor = f_recursive; /* = */ break; } if (c == ':') { if (!end) end = start; /* We need to distinguish :=, ::=, and :::=, versus : outside of an assignment (which means this is not a variable definition). */ c = *p++; if (c == '=') { var->flavor = f_simple; /* := */ break; } if (c == ':') { c = *p++; if (c == '=') { var->flavor = f_simple; /* ::= */ break; } if (c == ':' && *p++ == '=') { var->flavor = f_expand; /* :::= */ break; } } return NULL; } /* See if it's one of the other two-byte operators. */ if (*p == '=') { switch (c) { case '+': var->flavor = f_append; /* += */ break; case '!': var->flavor = f_shell; /* != */ break; default: goto other; } if (!end) end = start; ++p; break; } other: /* We found a char which is not part of an assignment operator. If we've seen whitespace, then we know this is not a variable assignment since variable names cannot contain whitespace. */ if (end) return NULL; if (c == '$') p = skip_reference (p); var->conditional = 0; } /* We found a valid variable assignment: END points to the char after the end of the variable name and P points to the char after the =. */ var->length = (unsigned int) (end - var->name); var->value = next_token (p); return (char *)p; } /* Try to interpret LINE (a null-terminated string) as a variable definition. If LINE was recognized as a variable definition, a pointer to its 'struct variable' is returned. If LINE is not a variable definition, NULL is returned. */ struct variable * assign_variable_definition (struct variable *v, const char *line) { char *name; if (!parse_variable_definition (line, v)) return NULL; /* Expand the name, so "$(foo)bar = baz" works. */ name = alloca (v->length + 1); memcpy (name, v->name, v->length); name[v->length] = '\0'; v->name = allocated_expand_string (name); if (v->name[0] == '\0') O (fatal, &v->fileinfo, _("empty variable name")); return v; } /* Try to interpret LINE (a null-terminated string) as a variable definition. ORIGIN may be o_file, o_override, o_env, o_env_override, or o_command specifying that the variable definition comes from a makefile, an override directive, the environment with or without the -e switch, or the command line. See the comments for assign_variable_definition(). If LINE was recognized as a variable definition, a pointer to its 'struct variable' is returned. If LINE is not a variable definition, NULL is returned. */ struct variable * try_variable_definition (const floc *flocp, const char *line, enum variable_origin origin, enum variable_scope scope) { struct variable v; struct variable *vp; if (flocp != 0) v.fileinfo = *flocp; else v.fileinfo.filenm = 0; if (!assign_variable_definition (&v, line)) return 0; vp = do_variable_definition (flocp, v.name, v.value, origin, v.flavor, v.conditional, scope); free (v.name); return vp; } /* These variables are internal to make, and so considered "defined" for the purposes of warn_undefined even if they are not really defined. */ struct defined_vars { const char *name; size_t len; }; static const struct defined_vars defined_vars[] = { { STRING_SIZE_TUPLE ("MAKECMDGOALS") }, { STRING_SIZE_TUPLE ("MAKE_RESTARTS") }, { STRING_SIZE_TUPLE ("MAKE_TERMOUT") }, { STRING_SIZE_TUPLE ("MAKE_TERMERR") }, { STRING_SIZE_TUPLE ("MAKEOVERRIDES") }, { STRING_SIZE_TUPLE (".DEFAULT") }, { STRING_SIZE_TUPLE ("-*-command-variables-*-") }, { STRING_SIZE_TUPLE ("-*-eval-flags-*-") }, { STRING_SIZE_TUPLE ("VPATH") }, { STRING_SIZE_TUPLE ("GPATH") }, { STRING_SIZE_TUPLE (WARNINGS_NAME) }, { STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME) }, { NULL, 0 } }; void warn_undefined (const char *name, size_t len) { if (warn_check (wt_undefined_var)) { const struct defined_vars *dp; for (dp = defined_vars; dp->name != NULL; ++dp) if (dp->len == len && memcmp (dp->name, name, len) == 0) return; warning (wt_undefined_var, reading_file, ONS (format, 0, _("reference to undefined variable '%.*s'"), (int)len, name)); } } static void set_env_override (const void *item, void *arg UNUSED) { struct variable *v = (struct variable *)item; enum variable_origin old = env_overrides ? o_env : o_env_override; enum variable_origin new = env_overrides ? o_env_override : o_env; if (v->origin == old) v->origin = new; } void reset_env_override () { hash_map_arg (&global_variable_set.table, set_env_override, NULL); } /* Print information for variable V, prefixing it with PREFIX. */ static void print_variable (const void *item, void *arg) { const struct variable *v = item; const char *prefix = arg; const char *origin; switch (v->origin) { case o_automatic: origin = _("automatic"); break; case o_default: origin = _("default"); break; case o_env: origin = _("environment"); break; case o_file: origin = _("makefile"); break; case o_env_override: origin = _("environment under -e"); break; case o_command: origin = _("command line"); break; case o_override: origin = _("'override' directive"); break; case o_invalid: abort (); } fputs ("# ", stdout); fputs (origin, stdout); if (v->private_var) fputs (" private", stdout); if (v->fileinfo.filenm) printf (_(" (from '%s', line %lu)"), v->fileinfo.filenm, v->fileinfo.lineno + v->fileinfo.offset); putchar ('\n'); fputs (prefix, stdout); /* Is this a 'define'? */ if (v->recursive && strchr (v->value, '\n') != 0) printf ("define %s\n%s\nendef\n", v->name, v->value); else { char *p; printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":"); /* Check if the value is just whitespace. */ p = next_token (v->value); if (p != v->value && *p == '\0') /* All whitespace. */ printf ("$(subst ,,%s)", v->value); else if (v->recursive) fputs (v->value, stdout); else /* Double up dollar signs. */ for (p = v->value; *p != '\0'; ++p) { if (*p == '$') putchar ('$'); putchar (*p); } putchar ('\n'); } } static void print_auto_variable (const void *item, void *arg) { const struct variable *v = item; if (v->origin == o_automatic) print_variable (item, arg); } static void print_noauto_variable (const void *item, void *arg) { const struct variable *v = item; if (v->origin != o_automatic) print_variable (item, arg); } /* Print all the variables in SET. PREFIX is printed before the actual variable definitions (everything else is comments). */ static void print_variable_set (struct variable_set *set, const char *prefix, int pauto) { hash_map_arg (&set->table, (pauto ? print_auto_variable : print_variable), (void *)prefix); fputs (_("# variable set hash-table stats:\n"), stdout); fputs ("# ", stdout); hash_print_stats (&set->table, stdout); putc ('\n', stdout); } /* Print the data base of variables. */ void print_variable_data_base (void) { puts (_("\n# Variables\n")); print_variable_set (&global_variable_set, "", 0); puts (_("\n# Pattern-specific Variable Values")); { struct pattern_var *p; unsigned int rules = 0; for (p = pattern_vars; p != 0; p = p->next) { ++rules; printf ("\n%s :\n", p->target); print_variable (&p->variable, (void *)"# "); } if (rules == 0) puts (_("\n# No pattern-specific variable values.")); else printf (_("\n# %u pattern-specific variable values"), rules); } } /* Print all the local variables of FILE. */ void print_file_variables (const struct file *file) { if (file->variables != 0) print_variable_set (file->variables->set, "# ", 1); } void print_target_variables (const struct file *file) { if (file->variables != 0) { size_t l = strlen (file->name); char *t = alloca (l + 3); memcpy (t, file->name, l); t[l] = ':'; t[l+1] = ' '; t[l+2] = '\0'; hash_map_arg (&file->variables->set->table, print_noauto_variable, t); } } #if MK_OS_W32 void sync_Path_environment () { static char *environ_path = NULL; char *oldpath = environ_path; char *path = allocated_expand_string ("PATH=$(PATH)"); if (!path) return; /* Convert the value of PATH into something Windows32 world can grok. Note: convert_Path_to_windows32 must see only the value of PATH, and see it from its first character, to do its tricky job. */ convert_Path_to_windows32 (path + CSTRLEN ("PATH="), ';'); environ_path = path; putenv (environ_path); free (oldpath); } #endif ================================================ FILE: src/variable.h ================================================ /* Definitions for using variables in GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "hash.h" struct file; /* Codes in a variable definition saying where the definition came from. Increasing numeric values signify less-overridable definitions. */ enum variable_origin { o_default, /* Variable from the default set. */ o_env, /* Variable from environment. */ o_file, /* Variable given in a makefile. */ o_env_override, /* Variable from environment, if -e. */ o_command, /* Variable given by user. */ o_override, /* Variable from an 'override' directive. */ o_automatic, /* Automatic variable -- cannot be set. */ o_invalid /* Core dump time. */ }; enum variable_flavor { f_bogus, /* Bogus (error) */ f_simple, /* Simple definition (:= or ::=) */ f_recursive, /* Recursive definition (=) */ f_expand, /* POSIX :::= assignment */ f_append, /* Appending definition (+=) */ f_shell, /* Shell assignment (!=) */ f_append_value /* Append unexpanded value */ }; enum variable_export { v_default = 0, /* Decide in target_environment. */ v_export, /* Export this variable. */ v_noexport, /* Don't export this variable. */ v_ifset /* Export it if it has a non-default value. */ }; enum variable_scope { s_global = 0, /* Global variable. */ s_target, /* Target-specific variable. */ s_pattern /* Pattern-specific variable. */ }; /* Structure that represents one variable definition. Each bucket of the hash table is a chain of these, chained through 'next'. */ #define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */ #define EXP_COUNT_MAX ((1<1, allow this many self-referential expansions. */ enum variable_flavor flavor ENUM_BITFIELD (3); /* Variable flavor. */ enum variable_origin origin ENUM_BITFIELD (3); /* Variable origin. */ enum variable_export export ENUM_BITFIELD (2); /* Export control. */ }; /* Structure that represents a variable set. */ struct variable_set { struct hash_table table; /* Hash table of variables. */ }; /* Structure that represents a list of variable sets. */ struct variable_set_list { struct variable_set_list *next; /* Link in the chain. */ struct variable_set *set; /* Variable set. */ int next_is_parent; /* True if next is a parent target. */ }; /* Structure used for pattern-specific variables. */ struct pattern_var { struct pattern_var *next; const char *suffix; const char *target; size_t len; struct variable variable; }; extern unsigned long long env_recursion; extern char *variable_buffer; extern struct variable_set_list *current_variable_set_list; extern struct variable *default_goal_var; extern struct variable shell_var; /* expand.c */ char *initialize_variable_output (void); char *variable_buffer_output (char *ptr, const char *string, size_t length); void install_variable_buffer (char **bufp, size_t *lenp); void restore_variable_buffer (char *buf, size_t len); char *swap_variable_buffer (char *buf, size_t len); char *expand_string_buf (char *buf, const char *string, size_t length); #define expand_string(s) expand_string_buf (NULL, (s), SIZE_MAX) char *expand_string_for_file (const char *string, struct file *file); char *allocated_expand_string_for_file (const char *line, struct file *file); #define allocated_expand_string(s) allocated_expand_string_for_file ((s), NULL) char *expand_argument (const char *str, const char *end); char *recursively_expand_for_file (struct variable *v, struct file *file); #define recursively_expand(v) recursively_expand_for_file ((v), NULL) char *expand_variable_output (char *ptr, const char *name, size_t length); char *expand_variable_buf (char *buf, const char *name, size_t length); #define expand_variable(n,l) expand_variable_buf (NULL, (n), (l)); char *allocated_expand_variable (const char *name, size_t length); char *allocated_expand_variable_for_file (const char *name, size_t length, struct file *file); /* function.c */ int handle_function (char **op, const char **stringp); int pattern_matches (const char *pattern, const char *percent, const char *str); char *subst_expand (char *o, const char *text, const char *subst, const char *replace, size_t slen, size_t rlen, int by_word); char *patsubst_expand_pat (char *o, const char *text, const char *pattern, const char *replace, const char *pattern_percent, const char *replace_percent); char *patsubst_expand (char *o, const char *text, char *pattern, char *replace); char *func_shell_base (char *o, char **argv, int trim_newlines); void shell_completed (int exit_code, int exit_sig); /* variable.c */ struct variable_set_list *create_new_variable_set (void); void free_variable_set (struct variable_set_list *); struct variable_set_list *push_new_variable_scope (void); void pop_variable_scope (void); void install_file_context (struct file *file, struct variable_set_list **oldlist, const floc **oldfloc); void restore_file_context (struct variable_set_list *oldlist, const floc *oldfloc); void define_automatic_variables (void); void initialize_file_variables (struct file *file, int reading); void print_file_variables (const struct file *file); void print_target_variables (const struct file *file); void merge_variable_set_lists (struct variable_set_list **to_list, struct variable_set_list *from_list); struct variable *do_variable_definition (const floc *flocp, const char *name, const char *value, enum variable_origin origin, enum variable_flavor flavor, int conditional, enum variable_scope scope); char *parse_variable_definition (const char *line, struct variable *v); struct variable *assign_variable_definition (struct variable *v, const char *line); struct variable *try_variable_definition (const floc *flocp, const char *line, enum variable_origin origin, enum variable_scope scope); void init_hash_global_variable_set (void); void hash_init_function_table (void); void define_new_function(const floc *flocp, const char *name, unsigned int min, unsigned int max, unsigned int flags, gmk_func_ptr func); struct variable *lookup_variable (const char *name, size_t length); struct variable *lookup_variable_for_file (const char *name, size_t length, struct file *file); struct variable *lookup_variable_in_set (const char *name, size_t length, const struct variable_set *set); struct variable *define_variable_in_set (const char *name, size_t length, const char *value, enum variable_origin origin, int recursive, struct variable_set *set, const floc *flocp); void warn_undefined (const char* name, size_t length); void reset_env_override (void); /* Define a variable in the current variable set. */ #define define_variable(n,l,v,o,r) \ define_variable_in_set((n),(l),(v),(o),(r),\ current_variable_set_list->set,NILF) /* Define a variable with a constant name in the current variable set. */ #define define_variable_cname(n,v,o,r) \ define_variable_in_set((n),(sizeof (n) - 1),(v),(o),(r),\ current_variable_set_list->set,NILF) /* Define a variable with a location in the current variable set. */ #define define_variable_loc(n,l,v,o,r,f) \ define_variable_in_set((n),(l),(v),(o),(r),\ current_variable_set_list->set,(f)) /* Define a variable with a location in the global variable set. */ #define define_variable_global(n,l,v,o,r,f) \ define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) /* Define a variable in FILE's variable set. */ #define define_variable_for_file(n,l,v,o,r,f) \ define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) void undefine_variable_in_set (const floc *flocp, const char *name, size_t length, enum variable_origin origin, struct variable_set *set); /* Remove variable from the current variable set. */ #define undefine_variable_global(f,n,l,o) \ undefine_variable_in_set((f),(n),(l),(o),NULL) char **target_environment (struct file *file, int recursive); struct pattern_var *create_pattern_var (const char *target, const char *suffix); ================================================ FILE: src/version.c ================================================ /* Record version and build host architecture for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* We use instead of "config.h" so that a compilation using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h (which it would do because makeint.h was found in $srcdir). */ #include #ifndef MAKE_HOST # define MAKE_HOST "unknown" #endif const char *version_string = PACKAGE_VERSION; const char *make_host = MAKE_HOST; /* Local variables: version-control: never End: */ ================================================ FILE: src/vms_exit.c ================================================ /* vms_exit.c * * Wrapper for the VMS exit() command to translate UNIX codes to be * encoded for POSIX, but also have VMS severity levels. * The posix_exit() variant only sets a severity level for status code 1. * * Author: John E. Malmberg */ /* Copyright (C) 2014-2024 Free Software Foundation, Inc. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Per copyright assignment agreement with the Free Software Foundation this software may be available under under other license agreements and copyrights. */ #include #include void decc$exit (int status); #ifndef C_FACILITY_NO # define C_FACILITY_NO 0x350000 #endif /* Lowest legal non-success VMS exit code is 8 */ /* GNU Make only defines codes 0, 1, 2 */ /* So assume any exit code > 8 is a VMS exit code */ #ifndef MAX_EXPECTED_EXIT_CODE # define MAX_EXPECTED_EXIT_CODE 7 #endif /* Build a Posix Exit with VMS severity */ void vms_exit (int status) { int vms_status; /* Fake the __posix_exit with severity added */ /* Undocumented correct way to do this. */ vms_status = 0; /* The default DECC definition is not compatible with doing a POSIX_EXIT */ /* So fix it. */ if (status == EXIT_FAILURE) status = MAKE_FAILURE; /* Trivial case exit success */ if (status == 0) decc$exit (STS$K_SUCCESS); /* Is this a VMS status then just take it */ if (status > MAX_EXPECTED_EXIT_CODE) { /* Make sure that the message inhibit is set since message has */ /* already been displayed. */ vms_status = status | STS$M_INHIB_MSG; decc$exit (vms_status); } /* Unix status codes are limited to 1 byte, so anything larger */ /* is a probably a VMS exit code and needs to be passed through */ /* A lower value can be set for a macro. */ /* Status 0 is always passed through as it is converted to SS$_NORMAL */ /* Always set the message inhibit bit */ vms_status = C_FACILITY_NO | 0xA000 | STS$M_INHIB_MSG; vms_status |= (status << 3); /* STS$K_ERROR is for status that stops makefile that a simple */ /* Rerun of the makefile will not fix. */ if (status == MAKE_FAILURE) vms_status |= STS$K_ERROR; else if (status == MAKE_TROUBLE) { /* Make trouble is for when make was told to do nothing and */ /* found that a target was not up to date. Since a second */ /* of make will produce the same condition, this is of */ /* Error severity */ vms_status |= STS$K_ERROR; } decc$exit (vms_status); } ================================================ FILE: src/vms_export_symbol.c ================================================ /* File: vms_export_symbol.c * * Some programs need special environment variables deported as DCL * DCL symbols. */ /* Copyright (C) 2014-2024 Free Software Foundation, Inc. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Per copyright assignment agreement with the Free Software Foundation this software may be available under under other license agreements and copyrights. */ #include #include #include #include #include #include #include #include #include #pragma member_alignment save #pragma nomember_alignment longword struct item_list_3 { unsigned short len; unsigned short code; void * bufadr; unsigned short * retlen; }; #pragma member_alignment int LIB$GET_SYMBOL (const struct dsc$descriptor_s * symbol, struct dsc$descriptor_s * value, unsigned short * value_len, const unsigned long * table); int LIB$SET_SYMBOL (const struct dsc$descriptor_s * symbol, const struct dsc$descriptor_s * value, const unsigned long * table); int LIB$DELETE_SYMBOL (const struct dsc$descriptor_s * symbol, const unsigned long * table); #define MAX_DCL_SYMBOL_LEN (255) #if __CRTL_VER >= 70302000 && !defined(__VAX) # define MAX_DCL_SYMBOL_VALUE (8192) #else # define MAX_DCL_SYMBOL_VALUE (1024) #endif struct dcl_symbol { struct dcl_symbol * link; struct dsc$descriptor_s name_desc; struct dsc$descriptor_s value_desc; char name[MAX_DCL_SYMBOL_LEN + 1]; /* + 1 byte for null terminator */ char value[MAX_DCL_SYMBOL_VALUE +1]; /* + 1 byte for null terminator */ char pad[3]; /* Pad structure to longword alignment */ }; static struct dcl_symbol * vms_dcl_symbol_head = NULL; /* Restore symbol state to original condition. */ static unsigned long clear_dcl_symbol (struct dcl_symbol * symbol) { const unsigned long symtbl = LIB$K_CLI_LOCAL_SYM; int status; if (symbol->value_desc.dsc$w_length == (unsigned short)-1) status = LIB$DELETE_SYMBOL (&symbol->name_desc, &symtbl); else status = LIB$SET_SYMBOL (&symbol->name_desc, &symbol->value_desc, &symtbl); return status; } /* Restore all exported symbols to their original conditions */ static void clear_exported_symbols (void) { struct dcl_symbol * symbol; symbol = vms_dcl_symbol_head; /* Walk the list of symbols. This is done during exit, * so no need to free memory. */ while (symbol != NULL) { clear_dcl_symbol (symbol); symbol = symbol->link; } } /* Restore the symbol back to the original value * symbol name is either a plain name or of the form "symbol=name" where * the name portion is ignored. */ void vms_restore_symbol (const char * string) { struct dcl_symbol * symbol; char name[MAX_DCL_SYMBOL_LEN + 1]; int status; char * value; int name_len; symbol = vms_dcl_symbol_head; /* Isolate the name from the value */ value = strchr (string, '='); if (value != NULL) { /* Copy the name from the string */ name_len = (value - string); } else name_len = strlen (string); if (name_len > MAX_DCL_SYMBOL_LEN) name_len = MAX_DCL_SYMBOL_LEN; strncpy (name, string, name_len); name[name_len] = 0; /* Walk the list of symbols. The saved symbol is not freed * symbols are likely to be overwritten multiple times, so this * saves time in saving them each time. */ while (symbol != NULL) { int result; result = strcmp (symbol->name, name); if (result == 0) { clear_dcl_symbol (symbol); break; } symbol = symbol->link; } } int vms_export_dcl_symbol (const char * name, const char * value) { struct dcl_symbol * symbol; struct dcl_symbol * next; struct dcl_symbol * link; int found; const unsigned long symtbl = LIB$K_CLI_LOCAL_SYM; struct dsc$descriptor_s value_desc; int string_len; int status; char new_value[MAX_DCL_SYMBOL_VALUE + 1]; char * dollarp; next = vms_dcl_symbol_head; link = vms_dcl_symbol_head; /* Is symbol already exported? */ found = 0; while ((found == 0) && (link != NULL)) { int x; found = !strncasecmp (link->name, name, MAX_DCL_SYMBOL_LEN); if (found) symbol = link; next = link; link = link->link; } /* New symbol, set it up */ if (found == 0) { symbol = malloc (sizeof (struct dcl_symbol)); if (symbol == NULL) return SS$_INSFMEM; /* Construct the symbol descriptor, used for both saving * the old symbol and creating the new symbol. */ symbol->name_desc.dsc$w_length = strlen (name); if (symbol->name_desc.dsc$w_length > MAX_DCL_SYMBOL_LEN) symbol->name_desc.dsc$w_length = MAX_DCL_SYMBOL_LEN; strncpy (symbol->name, name, symbol->name_desc.dsc$w_length); symbol->name[symbol->name_desc.dsc$w_length] = 0; symbol->name_desc.dsc$a_pointer = symbol->name; symbol->name_desc.dsc$b_dtype = DSC$K_DTYPE_T; symbol->name_desc.dsc$b_class = DSC$K_CLASS_S; /* construct the value descriptor, used only for saving * the old symbol. */ symbol->value_desc.dsc$a_pointer = symbol->value; symbol->value_desc.dsc$w_length = MAX_DCL_SYMBOL_VALUE; symbol->value_desc.dsc$b_dtype = DSC$K_DTYPE_T; symbol->value_desc.dsc$b_class = DSC$K_CLASS_S; } if (found == 0) { unsigned long old_symtbl; unsigned short value_len; /* Look up the symbol */ status = LIB$GET_SYMBOL (&symbol->name_desc, &symbol->value_desc, &value_len, &old_symtbl); if (!$VMS_STATUS_SUCCESS (status)) value_len = (unsigned short)-1; else if (old_symtbl != symtbl) value_len = (unsigned short)-1; symbol->value_desc.dsc$w_length = value_len; /* Store it away */ if (value_len != (unsigned short) -1) symbol->value[value_len] = 0; /* Make sure atexit scheduled */ if (vms_dcl_symbol_head == NULL) { vms_dcl_symbol_head = symbol; atexit (clear_exported_symbols); } else { /* Extend the chain */ next->link = symbol; } } /* Create or replace a symbol */ value_desc.dsc$a_pointer = new_value; string_len = strlen (value); if (string_len > MAX_DCL_SYMBOL_VALUE) string_len = MAX_DCL_SYMBOL_VALUE; strncpy (new_value, value, string_len); new_value[string_len] = 0; /* Special handling for GNU Make. GNU Make doubles the dollar signs * in environment variables read in from getenv(). Make exports symbols * with the dollar signs already doubled. So all $$ must be converted * back to $. * If the first $ is not doubled, then do not convert at all. */ dollarp = strchr (new_value, '$'); while (dollarp && dollarp[1] == '$') { int left; dollarp++; left = string_len - (dollarp - new_value - 1); string_len--; if (left > 0) { memmove (dollarp, &dollarp[1], left); dollarp = strchr (&dollarp[1], '$'); } else { /* Ended with $$, simple case */ dollarp[1] = 0; break; } } value_desc.dsc$w_length = string_len; value_desc.dsc$b_dtype = DSC$K_DTYPE_T; value_desc.dsc$b_class = DSC$K_CLASS_S; status = LIB$SET_SYMBOL (&symbol->name_desc, &value_desc, &symtbl); return status; } /* export a DCL symbol using a string in the same syntax as putenv */ int vms_putenv_symbol (const char * string) { char name[MAX_DCL_SYMBOL_LEN + 1]; int status; char * value; int name_len; /* Isolate the name from the value */ value = strchr (string, '='); if (value == NULL) { errno = EINVAL; return -1; } /* Copy the name from the string */ name_len = (value - string); if (name_len > MAX_DCL_SYMBOL_LEN) name_len = MAX_DCL_SYMBOL_LEN; strncpy (name, string, name_len); name[name_len] = 0; /* Skip past the "=" */ value++; /* Export the symbol */ status = vms_export_dcl_symbol (name, value); /* Convert the error to Unix format */ if (!$VMS_STATUS_SUCCESS (status)) { errno = EVMSERR; vaxc$errno = status; return -1; } return 0; } #if __CRTL_VER >= 70301000 # define transpath_parm transpath #else static char transpath[MAX_DCL_SYMBOL_VALUE]; #endif /* Helper callback routine for converting Unix paths to VMS */ static int to_vms_action (char * vms_spec, int flag, char * transpath_parm) { strncpy (transpath, vms_spec, MAX_DCL_SYMBOL_VALUE - 1); transpath[MAX_DCL_SYMBOL_VALUE - 1] = 0; return 0; } #ifdef __DECC # pragma message save /* Undocumented extra parameter use triggers a ptrmismatch warning */ # pragma message disable ptrmismatch #endif /* Create a foreign command only visible to children */ int create_foreign_command (const char * command, const char * image) { char vms_command[MAX_DCL_SYMBOL_VALUE + 1]; int status; vms_command[0] = '$'; vms_command[1] = 0; if (image[0] == '/') { #if __CRTL_VER >= 70301000 /* Current decc$to_vms is reentrant */ decc$to_vms (image, to_vms_action, 0, 1, &vms_command[1]); #else /* Older decc$to_vms is not reentrant */ decc$to_vms (image, to_vms_action, 0, 1); strncpy (&vms_command[1], transpath, MAX_DCL_SYMBOL_VALUE - 1); vms_command[MAX_DCL_SYMBOL_VALUE] = 0; #endif } else { strncpy (&vms_command[1], image, MAX_DCL_SYMBOL_VALUE - 1); vms_command[MAX_DCL_SYMBOL_VALUE] = 0; } status = vms_export_dcl_symbol (command, vms_command); return status; } #ifdef __DECC # pragma message restore #endif #ifdef DEBUG int main(int argc, char ** argv, char **env) { char value[MAX_DCL_SYMBOL_VALUE +1]; int status = 0; int putenv_status; int vms_status; struct dsc$descriptor_s name_desc; struct dsc$descriptor_s value_desc; const unsigned long symtbl = LIB$K_CLI_LOCAL_SYM; unsigned short value_len; unsigned long old_symtbl; int result; const char * vms_command = "vms_export_symbol"; const char * vms_image = "test_image.exe"; const char * vms_symbol1 = "test_symbol1"; const char * value1 = "test_value1"; const char * vms_symbol2 = "test_symbol2"; const char * putenv_string = "test_symbol2=value2"; const char * value2 = "value2"; /* Test creating a foreign command */ vms_status = create_foreign_command (vms_command, vms_image); if (!$VMS_STATUS_SUCCESS (vms_status)) { printf("Create foreign command failed: %d\n", vms_status); status = 1; } name_desc.dsc$a_pointer = (char *)vms_command; name_desc.dsc$w_length = strlen (vms_command); name_desc.dsc$b_dtype = DSC$K_DTYPE_T; name_desc.dsc$b_class = DSC$K_CLASS_S; value_desc.dsc$a_pointer = value; value_desc.dsc$w_length = MAX_DCL_SYMBOL_VALUE; value_desc.dsc$b_dtype = DSC$K_DTYPE_T; value_desc.dsc$b_class = DSC$K_CLASS_S; vms_status = LIB$GET_SYMBOL (&name_desc, &value_desc, &value_len, &old_symtbl); if (!$VMS_STATUS_SUCCESS (vms_status)) { printf ("lib$get_symbol for command failed: %d\n", vms_status); status = 1; } value[value_len] = 0; result = strncasecmp (&value[1], vms_image, value_len - 1); if (result != 0) { printf ("create_foreign_command failed! expected '%s', got '%s'\n", vms_image, &value[1]); status = 1; } /* Test exporting a symbol */ vms_status = vms_export_dcl_symbol (vms_symbol1, value1); if (!$VMS_STATUS_SUCCESS (vms_status)) { printf ("vms_export_dcl_symbol for command failed: %d\n", vms_status); status = 1; } name_desc.dsc$a_pointer = (char *)vms_symbol1; name_desc.dsc$w_length = strlen (vms_symbol1); vms_status = LIB$GET_SYMBOL(&name_desc, &value_desc, &value_len, &old_symtbl); if (!$VMS_STATUS_SUCCESS(vms_status)) { printf ("lib$get_symbol for command failed: %d\n", vms_status); status = 1; } value[value_len] = 0; result = strncmp (value, value1, value_len); if (result != 0) { printf ("vms_export_dcl_symbol failed! expected '%s', got '%s'\n", value1, value); status = 1; } /* Test putenv for DCL symbols */ putenv_status = vms_putenv_symbol (putenv_string); if (putenv_status != 0) { perror ("vms_putenv_symbol"); status = 1; } name_desc.dsc$a_pointer = (char *)vms_symbol2; name_desc.dsc$w_length = strlen(vms_symbol2); vms_status = LIB$GET_SYMBOL (&name_desc, &value_desc, &value_len, &old_symtbl); if (!$VMS_STATUS_SUCCESS (vms_status)) { printf ("lib$get_symbol for command failed: %d\n", vms_status); status = 1; } value[value_len] = 0; result = strncmp (value, value2, value_len); if (result != 0) { printf ("vms_putenv_symbol failed! expected '%s', got '%s'\n", value2, value); status = 1; } vms_restore_symbol (putenv_string); vms_status = LIB$GET_SYMBOL (&name_desc, &value_desc, &value_len, &old_symtbl); if ($VMS_STATUS_SUCCESS (vms_status)) { printf ("lib$get_symbol for command succeeded, should have failed\n"); status = 1; } exit (status); } #endif ================================================ FILE: src/vms_progname.c ================================================ /* File: vms_progname.c * * This module provides a fixup of the program name. * * This module is designed to be a plug in replacement for the * progname module used by many GNU utilities with a few enhancements * needed for GNU Make. * * It does not support the HAVE_DECL_PROGRAM_INVOCATION_* macros at this * time. * * Make sure that the program_name string is set as close as possible to * what the original command was given. * * When run from DCL, The argv[0] element is initialized with an absolute * path name. The decc$ feature logical names can control the format * of this pathname. In some cases it causes the UNIX format name to be * formatted incorrectly. * * This DCL provided name is usually incompatible with what is expected to * be provided by Unix programs and needs to be replaced. * * When run from an exec() call, the argv[0] element is initialized by the * program. This name is compatible with what is expected to be provided * by Unix programs and should be passed through unchanged. * * The DCL provided name can be detected because it always contains the * device name. * * DCL examples: * devname:[dir]program.exe;1 Normal VMS - remove path and .EXE;n * devname:[dir]facility$program.exe;1 Facility also needs removal. * /devname/dir/program.exe * /DISK$VOLUME/dir/program.exe.1 Bug version should not be there. * /DISK$VOLUME/dir/program. Bug Period should not be there. * */ /* Copyright (C) 2014-2024 Free Software Foundation, Inc. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Per copyright assignment agreement with the Free Software Foundation this software may be available under under other license agreements and copyrights. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include #include #include #ifdef USE_PROGNAME_H # include "progname.h" #endif #pragma member_alignment save #pragma nomember_alignment longword struct item_list_3 { unsigned short len; unsigned short code; void * bufadr; unsigned short * retlen; }; struct filescan_itmlst_2 { unsigned short length; unsigned short itmcode; char * component; }; #pragma member_alignment int SYS$GETDVIW (unsigned long efn, unsigned short chan, const struct dsc$descriptor_s * devnam, const struct item_list_3 * itmlst, void * iosb, void (* astadr)(unsigned long), unsigned long astprm, void * nullarg); int SYS$FILESCAN (const struct dsc$descriptor_s * srcstr, struct filescan_itmlst_2 * valuelist, unsigned long * fldflags, struct dsc$descriptor_s *auxout, unsigned short * retlen); /* String containing name the program is called with. To be initialized by main(). */ const char *program_name = NULL; static int internal_need_vms_symbol = 0; static char vms_new_nam[256]; int need_vms_symbol (void) { return internal_need_vms_symbol; } void set_program_name (const char *argv0) { int status; int result; #ifdef DEBUG printf ("original argv0 = %s\n", argv0); #endif /* Posix requires non-NULL argv[0] */ if (argv0 == NULL) { fputs ("A NULL argv[0] was passed through an exec system call.\n", stderr); abort (); } program_name = argv0; result = 0; internal_need_vms_symbol = 0; /* If the path name starts with a /, then it is an absolute path */ /* that may have been generated by the CRTL instead of the command name */ /* If it is the device name between the slashes, then this was likely */ /* from the run command and needs to be fixed up. */ /* If the DECC$POSIX_COMPLIANT_PATHNAMES is set to 2, then it is the */ /* DISK$VOLUME that will be present, and it will still need to be fixed. */ if (argv0[0] == '/') { char * nextslash; int length; struct item_list_3 itemlist[3]; unsigned short dvi_iosb[4]; char alldevnam[64]; unsigned short alldevnam_len; struct dsc$descriptor_s devname_dsc; char diskvolnam[256]; unsigned short diskvolnam_len; internal_need_vms_symbol = 1; /* Get some information about the disk */ /*--------------------------------------*/ itemlist[0].len = (sizeof alldevnam) - 1; itemlist[0].code = DVI$_ALLDEVNAM; itemlist[0].bufadr = alldevnam; itemlist[0].retlen = &alldevnam_len; itemlist[1].len = (sizeof diskvolnam) - 1 - 5; itemlist[1].code = DVI$_VOLNAM; itemlist[1].bufadr = &diskvolnam[5]; itemlist[1].retlen = &diskvolnam_len; itemlist[2].len = 0; itemlist[2].code = 0; /* Add the prefix for the volume name. */ /* SYS$GETDVI will append the volume name to this */ strcpy (diskvolnam, "DISK$"); nextslash = strchr (&argv0[1], '/'); if (nextslash != NULL) { length = nextslash - argv0 - 1; /* Cast needed for HP C compiler diagnostic */ devname_dsc.dsc$a_pointer = (char *)&argv0[1]; devname_dsc.dsc$w_length = length; devname_dsc.dsc$b_dtype = DSC$K_DTYPE_T; devname_dsc.dsc$b_class = DSC$K_CLASS_S; status = SYS$GETDVIW (EFN$C_ENF, 0, &devname_dsc, itemlist, dvi_iosb, NULL, 0, 0); if (!$VMS_STATUS_SUCCESS (status)) { /* If the sys$getdviw fails, then this path was passed by */ /* An exec() program and not from DCL, so do nothing */ /* An example is "/tmp/program" where tmp: does not exist */ #ifdef DEBUG printf ("sys$getdviw failed with status %d\n", status); #endif result = 0; } else if (!$VMS_STATUS_SUCCESS (dvi_iosb[0])) { #ifdef DEBUG printf ("sys$getdviw failed with iosb %d\n", dvi_iosb[0]); #endif result = 0; } else { char * devnam; int devnam_len; char argv_dev[64]; /* Null terminate the returned alldevnam */ alldevnam[alldevnam_len] = 0; devnam = alldevnam; devnam_len = alldevnam_len; /* Need to skip past any leading underscore */ if (devnam[0] == '_') { devnam++; devnam_len--; } /* And remove the trailing colon */ if (devnam[devnam_len - 1] == ':') { devnam_len--; devnam[devnam_len] = 0; } /* Null terminate the returned volnam */ diskvolnam_len += 5; diskvolnam[diskvolnam_len] = 0; /* Check first for normal CRTL behavior */ if (devnam_len == length) { strncpy (vms_new_nam, &argv0[1], length); vms_new_nam[length] = 0; result = (strcasecmp (devnam, vms_new_nam) == 0); } /* If we have not got a match, check for POSIX Compliant */ /* behavior. To be more accurate, we could also check */ /* to see if that feature is active. */ if ((result == 0) && (diskvolnam_len == length)) { strncpy (vms_new_nam, &argv0[1], length); vms_new_nam[length] = 0; result = (strcasecmp (diskvolnam, vms_new_nam) == 0); } } } } else { /* The path did not start with a slash, so it could be VMS format */ /* If it is vms format, it has a volume/device in it as it must */ /* be an absolute path */ struct dsc$descriptor_s path_desc; int status; unsigned long field_flags; struct filescan_itmlst_2 item_list[5]; char * volume; char * name; int name_len; char * ext; path_desc.dsc$a_pointer = (char *)argv0; /* cast ok */ path_desc.dsc$w_length = strlen (argv0); path_desc.dsc$b_dtype = DSC$K_DTYPE_T; path_desc.dsc$b_class = DSC$K_CLASS_S; /* Don't actually need to initialize anything buf itmcode */ /* I just do not like uninitialized input values */ /* Sanity check, this must be the same length as input */ item_list[0].itmcode = FSCN$_FILESPEC; item_list[0].length = 0; item_list[0].component = NULL; /* If the device is present, then it if a VMS spec */ item_list[1].itmcode = FSCN$_DEVICE; item_list[1].length = 0; item_list[1].component = NULL; /* we need the program name and type */ item_list[2].itmcode = FSCN$_NAME; item_list[2].length = 0; item_list[2].component = NULL; item_list[3].itmcode = FSCN$_TYPE; item_list[3].length = 0; item_list[3].component = NULL; /* End the list */ item_list[4].itmcode = 0; item_list[4].length = 0; item_list[4].component = NULL; status = SYS$FILESCAN ((const struct dsc$descriptor_s *)&path_desc, item_list, &field_flags, NULL, NULL); if ($VMS_STATUS_SUCCESS (status) && (item_list[0].length == path_desc.dsc$w_length) && (item_list[1].length != 0)) { char * dollar; int keep_ext; int i; /* We need the filescan to be successful, */ /* same length as input, and a volume to be present */ internal_need_vms_symbol = 1; /* We will assume that we only get to this path on a version */ /* of VMS that does not support the EFS character set */ /* There may be a xxx$ prefix on the image name. Linux */ /* programs do not handle that well, so strip the prefix */ name = item_list[2].component; name_len = item_list[2].length; dollar = strrchr (name, '$'); if (dollar != NULL) { dollar++; name_len = name_len - (dollar - name); name = dollar; } strncpy (vms_new_nam, name, name_len); vms_new_nam[name_len] = 0; /* Commit to using the new name */ program_name = vms_new_nam; /* We only keep the extension if it is not ".exe" */ keep_ext = 0; ext = item_list[3].component; if (item_list[3].length != 1) { keep_ext = 1; if (item_list[3].length == 4) { if ((ext[1] == 'e' || ext[1] == 'E') && (ext[2] == 'x' || ext[2] == 'X') && (ext[3] == 'e' || ext[3] == 'E')) keep_ext = 0; } } if (keep_ext == 1) strncpy (&vms_new_nam[name_len], ext, item_list[3].length); } } if (result) { char * lastslash; char * dollar; char * dotexe; char * lastdot; char * extension; /* This means it is probably the name from a DCL command */ /* Find the last slash which separates the file from the */ /* path. */ lastslash = strrchr (argv0, '/'); if (lastslash != NULL) { int i; lastslash++; /* There may be a xxx$ prefix on the image name. Linux */ /* programs do not handle that well, so strip the prefix */ dollar = strrchr (lastslash, '$'); if (dollar != NULL) { dollar++; lastslash = dollar; } strcpy (vms_new_nam, lastslash); /* In UNIX mode + EFS character set, there should not be a */ /* version present, as it is not possible when parsing to */ /* tell if it is a version or part of the UNIX filename as */ /* UNIX programs use numeric extensions for many reasons. */ lastdot = strrchr (vms_new_nam, '.'); if (lastdot != NULL) { int i; i = 1; while (isdigit ((unsigned char) lastdot[i])) { i++; } if (lastdot[i] == 0) { *lastdot = 0; } } /* Find the .exe on the name (case insensitive) and toss it */ dotexe = strrchr (vms_new_nam, '.'); if (dotexe != NULL) { if ((dotexe[1] == 'e' || dotexe[1] == 'E') && (dotexe[2] == 'x' || dotexe[2] == 'X') && (dotexe[3] == 'e' || dotexe[3] == 'E') && (dotexe[4] == 0)) { *dotexe = 0; } else { /* Also need to handle a null extension because of a */ /* CRTL bug. */ if (dotexe[1] == 0) { *dotexe = 0; } } } /* Commit to new name */ program_name = vms_new_nam; } else { /* There is no way that the code should ever get here */ /* As we already verified that the '/' was present */ fprintf (stderr, "Sanity failure somewhere we lost a '/'\n"); } } } #ifdef DEBUG int main (int argc, char ** argv, char **env) { char command[1024]; set_program_name (argv[0]); printf ("modified argv[0] = %s\n", program_name); return 0; } #endif ================================================ FILE: src/vmsdir.h ================================================ /* dirent.h for vms Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef VMSDIR_H #define VMSDIR_H #include #define MAXNAMLEN 255 #ifndef __DECC #if !defined (__GNUC__) && !defined (__ALPHA) typedef unsigned long u_long; typedef unsigned short u_short; #endif #endif struct direct { off_t d_off; u_long d_fileno; u_short d_reclen; u_short d_namlen; char d_name[MAXNAMLEN + 1]; }; #undef DIRSIZ #define DIRSIZ(dp) \ (((sizeof (struct direct) \ - (MAXNAMLEN+1) \ + ((dp)->d_namlen+1)) \ + 3) & ~3) #define d_ino d_fileno /* compatibility */ /* * Definitions for library routines operating on directories. */ typedef struct DIR { struct direct dir; char d_result[MAXNAMLEN + 1]; #if defined (__ALPHA) || defined (__DECC) struct FAB fab; #else struct fabdef fab; #endif } DIR; #ifndef NULL #define NULL 0 #endif #define rewinddir(dirp) seekdir((dirp), (long)0) DIR *opendir (); struct direct *readdir (DIR *dfd); int closedir (DIR *dfd); const char *vmsify (const char *name, int type); #endif /* VMSDIR_H */ ================================================ FILE: src/vmsfunctions.c ================================================ /* VMS functions Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "debug.h" #include "job.h" #include #include #ifdef __DECC #include #endif #include #include "vmsdir.h" #ifdef HAVE_VMSDIR_H DIR * opendir (char *dspec) { struct DIR *dir = xcalloc (sizeof (struct DIR)); struct NAM *dnam = xmalloc (sizeof (struct NAM)); struct FAB *dfab = &dir->fab; char *searchspec = xmalloc (MAXNAMLEN + 1); *dfab = cc$rms_fab; *dnam = cc$rms_nam; sprintf (searchspec, "%s*.*;", dspec); dfab->fab$l_fna = searchspec; dfab->fab$b_fns = strlen (searchspec); dfab->fab$l_nam = dnam; *dnam = cc$rms_nam; dnam->nam$l_esa = searchspec; dnam->nam$b_ess = MAXNAMLEN; if (! (sys$parse (dfab) & 1)) { free (dir); free (dnam); free (searchspec); return (NULL); } return dir; } #define uppercasify(str) \ do \ { \ char *tmp; \ for (tmp = (str); *tmp != '\0'; tmp++) \ if (islower ((unsigned char)*tmp)) \ *tmp = toupper ((unsigned char)*tmp); \ } \ while (0) struct direct * readdir (DIR *dir) { struct FAB *dfab = &dir->fab; struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam); struct direct *dentry = &dir->dir; int i; memset (dentry, 0, sizeof *dentry); dnam->nam$l_rsa = dir->d_result; dnam->nam$b_rss = MAXNAMLEN; DB (DB_VERBOSE, (".")); if (!((i = sys$search (dfab)) & 1)) { DB (DB_VERBOSE, (_("sys$search() failed with %d\n"), i)); return (NULL); } dentry->d_off = 0; if (dnam->nam$w_fid == 0) dentry->d_fileno = 1; else dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16); dentry->d_reclen = sizeof (struct direct); dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type; strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen); dentry->d_name[dentry->d_namlen] = '\0'; #ifdef HAVE_CASE_INSENSITIVE_FS uppercasify (dentry->d_name); #endif return (dentry); } int closedir (DIR *dir) { if (dir != NULL) { struct FAB *dfab = &dir->fab; struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam); if (dnam != NULL) free (dnam->nam$l_esa); free (dnam); free (dir); } return 0; } #endif /* compiled for OpenVMS prior to V7.x */ /* Argv0 will be a full vms file specification, like node$dka100:[utils.gnumake]make.exe;47 prefix it with "mcr " to make it a vms command, executable for DCL. */ const char * vms_command(const char* argv0) { size_t l = strlen(argv0) + 1; char* s = xmalloc(l + 4); memcpy(s, "mcr ", 4); memcpy(s+4, argv0, l); return s; } /* Argv0 aka argv[0] will be a full vms file specification, like node$dka100:[utils.gnumake]make.exe;47, set up by the CRTL. The vms progname should be ^^^^, the file name without file type .exe and ;version. Use sys$parse to get the name part of the file specification. That is in the above example, pick up "make" and return a copy of that string. If something goes wrong in sys$parse (unlikely, this is a VMS/CRTL supplied file specification) or if there is an empty name part (not easy to produce, but it is possible) just return "make". Some notes ... NAM[L]$M_SYNCHK requests a syntax check, only. NAM is for ODS2 names (shorter parts, output usually converted to UPPERCASE). NAML is for ODS2/ODS5 names (longer parts, output unchanged). NAM$M_NO_SHORT_UPCASE may not be available for older versions of VMS. NAML is not available on older versions of VMS (NAML$C_BID not defined). argv[0] on older versions of VMS (no extended parse style and no CRTL feature DECC$ARGV_PARSE_STYLE) is always in lowercase. */ const char * vms_progname(const char* argv0) { int status; static struct FAB fab; char *progname; const char *fallback = "make"; #ifdef NAML$C_BID static char esa[NAML$C_MAXRSS]; static struct NAML naml; #else static char esa[NAM$C_MAXRSS]; static struct NAM nam; #endif fab = cc$rms_fab; fab.fab$l_fna = (char*)argv0; fab.fab$b_fns = strlen(argv0); #ifdef NAML$C_BID fab.fab$l_naml = &naml; naml = cc$rms_naml; naml.naml$l_long_expand = esa; naml.naml$l_long_expand_alloc = NAML$C_MAXRSS; naml.naml$b_nop = NAML$M_SYNCHK; naml.naml$l_input_flags = NAML$M_NO_SHORT_OUTPUT; #else fab.fab$l_nam = &nam; nam = cc$rms_nam; nam.nam$l_esa = esa; nam.nam$b_ess = NAM$C_MAXRSS; # ifdef NAM$M_NO_SHORT_UPCASE nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_NO_SHORT_UPCASE; # else nam.nam$b_nop = NAM$M_SYNCHK; # endif #endif status = sys$parse(&fab); if (!(status & 1)) return fallback; #ifdef NAML$C_BID if (naml.naml$l_long_name_size == 0) return fallback; progname = xmalloc(naml.naml$l_long_name_size + 1); memcpy(progname, naml.naml$l_long_name, naml.naml$l_long_name_size); progname[naml.naml$l_long_name_size] = '\0'; #else if (nam.nam$b_name == 0) return fallback; progname = xmalloc(nam.nam$b_name + 1); # ifdef NAM$M_NO_SHORT_UPCASE memcpy(progname, nam.nam$l_name, nam.nam$b_name); # else { int i; for (i = 0; i < nam.nam$b_name; i++) progname[i] = tolower(nam.nam$l_name[i]); } # endif progname[nam.nam$b_name] = '\0'; #endif return progname; } ================================================ FILE: src/vmsify.c ================================================ /* vmsify.c -- Module for vms <-> unix file name conversion Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Written by Klaus Kmpf (kkaempf@progis.de) of proGIS Software, Aachen, Germany */ #include #include #include #include "makeint.h" #if MK_OS_VMS #include #include #include #include #include #include #include #include /* Initialize a string descriptor (struct dsc$descriptor_s) for an arbitrary string. ADDR is a pointer to the first character of the string, and LEN is the length of the string. */ #define INIT_DSC_S(dsc, addr, len) do { \ (dsc).dsc$b_dtype = DSC$K_DTYPE_T; \ (dsc).dsc$b_class = DSC$K_CLASS_S; \ (dsc).dsc$w_length = (len); \ (dsc).dsc$a_pointer = (addr); \ } while (0) /* Initialize a string descriptor (struct dsc$descriptor_s) for a NUL-terminated string. S is a pointer to the string; the length is determined by calling strlen(). */ #define INIT_DSC_CSTRING(dsc, s) INIT_DSC_S(dsc, s, strlen(s)) #endif /* copy 'from' to 'to' up to but not including 'upto' return 0 if eos on from return 1 if upto found return 'to' at last char + 1 return 'from' at match + 1 or eos if no match if as_dir == 1, change all '.' to '_' else change all '.' but the last to '_' */ static int copyto (char **to, const char **from, char upto, int as_dir) { const char *s; s = strrchr (*from, '.'); while (**from) { if (**from == upto) { do { (*from)++; } while (**from == upto); return 1; } if (**from == '.') { if ((as_dir == 1) || (*from != s)) **to = '_'; else **to = '.'; } else { #ifdef HAVE_CASE_INSENSITIVE_FS if (isupper ((unsigned char)**from)) **to = tolower ((unsigned char)**from); else #endif **to = **from; } (*to)++; (*from)++; } return 0; } /* get translation of logical name */ static char * trnlog (const char *name) { int stat; static char reslt[1024]; $DESCRIPTOR (reslt_dsc, reslt); short resltlen; struct dsc$descriptor_s name_dsc; char *s; /* * the string isn't changed, but there is no string descriptor with * "const char *dsc$a_pointer" */ INIT_DSC_CSTRING (name_dsc, (char *)name); stat = lib$sys_trnlog (&name_dsc, &resltlen, &reslt_dsc); if ((stat&1) == 0) { return ""; } if (stat == SS$_NOTRAN) { return ""; } reslt[resltlen] = '\0'; s = xmalloc (resltlen+1); strcpy (s, reslt); return s; } static char * showall (char *s) { static char t[512]; char *pt; pt = t; if (strchr (s, '\\') == 0) return s; while (*s) { if (*s == '\\') { *pt++ = *s; } *pt++ = *s++; } return pt; } enum namestate { N_START, N_DEVICE, N_OPEN, N_DOT, N_CLOSED, N_DONE }; /* convert unix style name to vms style type = 0 -> name is a full name (directory and filename part) type = 1 -> name is a directory type = 2 -> name is a filename without directory The following conversions are applied (0) (1) (2) input full name dir name file name 1 ./ [] .dir 2 ../ .dir 3 // : :[000000] :000000.dir 4 //a a: a: a: 5 //a/ a: a: a:000000.dir 9 / [000000] [000000] 000000.dir 10 /a [000000]a [a] [000000]a 11 /a/ [a] [a] [000000]a.dir 12 /a/b [a]b [a.b] [a]b 13 /a/b/ [a.b] [a.b] [a]b.dir 14 /a/b/c [a.b]c [a.b.c] [a.b]c 15 /a/b/c/ [a.b.c] [a.b.c] [a.b]c.dir 16 a a [.a] a 17 a/ [.a] [.a] a.dir 18 a/b [.a]b [.a.b] [.a]b 19 a/b/ [.a.b] [.a.b] [.a]b.dir 20 a/b/c [.a.b]c [.a.b.c] [.a.b]c 21 a/b/c/ [.a.b.c] [.a.b.c] [.a.b]c.dir 22 a.b.c a_b.c [.a_b_c] a_b_c.dir 23 [x][y]z [x.y]z [x.y]z [x.y]z 24 [x][.y]z [x.y]z [x.y]z [x.y]z 25 filenames with '$' are left unchanged if they contain no '/' 25 filenames with ':' are left unchanged 26 filenames with a single pair of '[' ']' are left unchanged The input string is not written to. The result is also const because it's a static buffer; we don't want to change it. */ const char * vmsify (const char *name, int type) { /* max 255 device max 39 directory max 39 filename max 39 filetype max 5 version */ /* todo: VMSMAXPATHLEN is defined for ODS2 names: it needs to be adjusted. */ #define VMSMAXPATHLEN 512 enum namestate nstate; static char vmsname[VMSMAXPATHLEN+1]; const char *fptr; const char *t; char *vptr; int as_dir; int count; const char *s; const char *s1; const char *s2; if (name == 0) return 0; fptr = name; vptr = vmsname; nstate = N_START; /* case 25a */ t = strpbrk (name, "$:"); if (t != 0) { // const char *s1; // const char *s2; if (type == 1) { s1 = strchr (t+1, '['); s2 = strchr (t+1, ']'); } if (*t == '$') { if (strchr (name, '/') == 0) { strcpy (vmsname, name); if ((type == 1) && (s1 != 0) && (s2 == 0)) strcat (vmsname, "]"); return vmsname; } } else { strcpy (vmsname, name); if ((type == 1) && (s1 != 0) && (s2 == 0)) strcat (vmsname, "]"); return vmsname; } } /* case 26 */ t = strchr (name, '['); if (t != 0) { // const char *s; // const char *s1 = strchr (t+1, '['); s1 = strchr (t+1, '['); if (s1 == 0) { strcpy (vmsname, name); if ((type == 1) && (strchr (t+1, ']') == 0)) strcat (vmsname, "]"); return vmsname; } s1--; if (*s1 != ']') { strcpy (vmsname, name); return vmsname; /* not ][, keep unchanged */ } /* we have ][ */ s = name; /* s -> starting char s1 -> ending ']' */ do { strncpy (vptr, s, s1-s); /* copy up to but not including ']' */ vptr += s1-s; if (*s1 == 0) break; s = s1 + 1; /* s -> char behind ']' */ if (*s != '[') /* was '][' ? */ break; /* no, last ] found, exit */ s++; if (*s != '.') *vptr++ = '.'; s1 = strchr (s, ']'); if (s1 == 0) /* no closing ] */ s1 = s + strlen (s); } while (1); *vptr++ = ']'; fptr = s; } else /* no [ in name */ { int state = 0; int rooted = 1; /* flag if logical is rooted, else insert [000000] */ do { switch (state) { case 0: /* start of loop */ if (*fptr == '/') { fptr++; state = 1; } else if (*fptr == '.') { fptr++; state = 10; } else state = 2; break; case 1: /* '/' at start */ if (*fptr == '/') { fptr++; state = 3; } else state = 4; break; case 2: /* no '/' at start */ { const char *s = strchr (fptr, '/'); if (s == 0) /* no '/' (16) */ { if (type == 1) { strcpy (vptr, "[."); vptr += 2; } copyto (&vptr, &fptr, 0, (type==1)); if (type == 1) *vptr++ = ']'; state = -1; } else /* found '/' (17..21) */ { if ((type == 2) && (*(s+1) == 0)) /* 17(2) */ { copyto (&vptr, &fptr, '/', 1); state = 7; } else { strcpy (vptr, "[."); vptr += 2; copyto (&vptr, &fptr, '/', 1); nstate = N_OPEN; state = 9; } } break; } case 3: /* '//' at start */ { // const char *s; // const char *s1; char *vp; while (*fptr == '/') /* collapse all '/' */ fptr++; if (*fptr == 0) /* just // */ { char cwdbuf[VMSMAXPATHLEN+1]; s1 = getcwd(cwdbuf, VMSMAXPATHLEN); if (s1 == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err getcwd */ } s = strchr (s1, ':'); if (s == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err no device */ } strncpy (vptr, s1, s-s1+1); vptr += s-s1+1; state = -1; break; } s = vptr; if (copyto (&vptr, &fptr, '/', 1) == 0) /* copy device part */ { *vptr++ = ':'; state = -1; break; } *vptr = ':'; nstate = N_DEVICE; if (*fptr == 0) /* just '//a/' */ { strcpy (vptr+1, "[000000]"); vptr += 9; state = -1; break; } *vptr = 0; /* check logical for [000000] insertion */ vp = trnlog (s); if (*vp != '\0') { /* found translation */ for (;;) /* loop over all nested logicals */ { char *vp2 = vp + strlen (vp) - 1; if (*vp2 == ':') /* translation ends in ':' */ { vp2 = trnlog (vp); free (vp); if (*vp2 == 0) { rooted = 0; break; } vp = vp2; continue; /* next iteration */ } if (*vp2 == ']') /* translation ends in ']' */ { if (*(vp2-1) == '.') /* ends in '.]' */ { if (strncmp (fptr, "000000", 6) != 0) rooted = 0; } else { strcpy (vmsname, s1); vp = strchr (vmsname, ']'); *vp = '.'; nstate = N_DOT; vptr = vp; } } break; } free (vp); } else rooted = 0; if (*vptr == 0) { nstate = N_DEVICE; *vptr++ = ':'; } else vptr++; if (rooted == 0) { nstate = N_DOT; strcpy (vptr, "[000000."); vptr += 8; vp = vptr-1; } else vp = 0; /* vp-> '.' after 000000 or NULL */ s = strchr (fptr, '/'); if (s == 0) { /* no next '/' */ if (*(vptr-1) == '.') *(vptr-1) = ']'; else if (rooted == 0) *vptr++ = ']'; copyto (&vptr, &fptr, 0, (type == 1)); state = -1; break; } else { while (*(s+1) == '/') /* skip multiple '/' */ s++; } if ((rooted != 0) && (*(vptr-1) != '.')) { *vptr++ = '['; nstate = N_DOT; } else if ((nstate == N_DOT) && (vp != 0) && (*(s+1) == 0)) { if (type == 2) { *vp = ']'; nstate = N_CLOSED; } } state = 9; break; } case 4: /* single '/' at start (9..15) */ if (*fptr == 0) state = 5; else state = 6; break; case 5: /* just '/' at start (9) */ if (type != 2) { *vptr++ = '['; nstate = N_OPEN; } strcpy (vptr, "000000"); vptr += 6; if (type == 2) state = 7; else state = 8; break; case 6: /* chars following '/' at start 10..15 */ { const char *s; *vptr++ = '['; nstate = N_OPEN; s = strchr (fptr, '/'); if (s == 0) /* 10 */ { if (type != 1) { strcpy (vptr, "000000]"); vptr += 7; } copyto (&vptr, &fptr, 0, (type == 1)); if (type == 1) { *vptr++ = ']'; } state = -1; } else /* 11..15 */ { if ( (type == 2) && (*(s+1) == 0)) /* 11(2) */ { strcpy (vptr, "000000]"); nstate = N_CLOSED; vptr += 7; } copyto (&vptr, &fptr, '/', (*(vptr-1) != ']')); state = 9; } break; } case 7: /* add '.dir' and exit */ if ((nstate == N_OPEN) || (nstate == N_DOT)) { char *vp = vptr-1; while (vp > vmsname) { if (*vp == ']') { break; } if (*vp == '.') { *vp = ']'; break; } vp--; } } strcpy (vptr, ".dir"); vptr += 4; state = -1; break; case 8: /* add ']' and exit */ *vptr++ = ']'; state = -1; break; case 9: /* 17..21, fptr -> 1st '/' + 1 */ { const char *s; if (*fptr == 0) { if (type == 2) { state = 7; } else state = 8; break; } s = strchr (fptr, '/'); if (s == 0) { if (type != 1) { if (nstate == N_OPEN) { *vptr++ = ']'; nstate = N_CLOSED; } as_dir = 0; } else { if (nstate == N_OPEN) { *vptr++ = '.'; nstate = N_DOT; } as_dir = 1; } } else { while (*(s+1) == '/') s++; if ( (type == 2) && (*(s+1) == 0)) /* 19(2), 21(2)*/ { if (nstate != N_CLOSED) { *vptr++ = ']'; nstate = N_CLOSED; } as_dir = 1; } else { if (nstate == N_OPEN) { *vptr++ = '.'; nstate = N_DOT; } as_dir = 1; } } if ( (*fptr == '.') /* check for '..' or '../' */ && (*(fptr+1) == '.') && ((*(fptr+2) == '/') || (*(fptr+2) == 0)) ) { char *vp; fptr += 2; if (*fptr == '/') { do { fptr++; } while (*fptr == '/'); } else if (*fptr == 0) type = 1; vptr--; /* vptr -> '.' or ']' */ vp = vptr; for (;;) { vp--; if (*vp == '.') /* one back */ { vptr = vp; nstate = N_OPEN; break; } if (*vp == '[') /* top level reached */ { if (*fptr == 0) { strcpy (vp, "[000000]"); vptr = vp + 8; nstate = N_CLOSED; s = 0; break; } else { vptr = vp+1; nstate = N_OPEN; break; } } } } else { copyto (&vptr, &fptr, '/', as_dir); if (nstate == N_DOT) nstate = N_OPEN; } if (s == 0) { /* 18,20 */ if (type == 1) *vptr++ = ']'; state = -1; } else { if (*(s+1) == 0) { if (type == 2) /* 19,21 */ { state = 7; } else { *vptr++ = ']'; state = -1; } } } break; } case 10: /* 1,2 first is '.' */ if (*fptr == '.') { fptr++; state = 11; } else state = 12; break; case 11: /* 2, '..' at start */ count = 1; if (*fptr != 0) { if (*fptr != '/') /* got ..xxx */ { strcpy (vmsname, name); return vmsname; } do /* got ../ */ { fptr++; while (*fptr == '/') fptr++; if (*fptr != '.') break; if (*(fptr+1) != '.') break; fptr += 2; if ((*fptr == 0) || (*fptr == '/')) count++; } while (*fptr == '/'); } { /* got '..' or '../' */ char *vp; char cwdbuf[VMSMAXPATHLEN+1]; vp = getcwd(cwdbuf, VMSMAXPATHLEN); if (vp == 0) { vmsname[0] = '\0'; return vmsname; /* FIXME, err getcwd */ } strcpy (vptr, vp); vp = strchr (vptr, ']'); if (vp != 0) { nstate = N_OPEN; while (vp > vptr) { vp--; if (*vp == '[') { vp++; strcpy (vp, "000000]"); state = -1; break; } else if (*vp == '.') { if (--count == 0) { if (*fptr == 0) /* had '..' or '../' */ { *vp++ = ']'; state = -1; } else /* had '../xxx' */ { state = 9; } *vp = '\0'; break; } } } } vptr += strlen (vptr); } break; case 12: /* 1, '.' at start */ if (*fptr != 0) { if (*fptr != '/') { strcpy (vmsname, name); return vmsname; } while (*fptr == '/') fptr++; } { char *vp; char cwdbuf[VMSMAXPATHLEN+1]; vp = getcwd(cwdbuf, VMSMAXPATHLEN); if (vp == 0) { vmsname[0] = '\0'; return vmsname; /*FIXME, err getcwd */ } strcpy (vptr, vp); } if (*fptr == 0) { state = -1; break; } else { char *vp = strchr (vptr, ']'); if (vp == 0) { state = -1; break; } *vp = '\0'; nstate = N_OPEN; vptr += strlen (vptr); state = 9; } break; } } while (state > 0); } /* directory conversion done fptr -> filename part of input string vptr -> free space in vmsname */ *vptr++ = 0; return vmsname; } /* convert from vms-style to unix-style dev:[dir1.dir2] //dev/dir1/dir2/ */ const char * unixify (const char *name) { static char piece[512]; const char *s; char *p; if (strchr (name, '/') != 0) /* already in unix style */ { strcpy (piece, name); return piece; } p = piece; *p = 0; /* device part */ s = strchr (name, ':'); if (s != 0) { int l = s - name; *p++ = '/'; *p++ = '/'; strncpy (p, name, l); p += l; } /* directory part */ *p++ = '/'; s = strchr (name, '['); if (s != 0) { s++; switch (*s) { case ']': /* [] */ strcat (p, "./"); break; case '-': /* [- */ strcat (p, "../"); break; case '.': strcat (p, "./"); /* [. */ break; default: s--; break; } s++; while (*s) { if (*s == '.') *p++ = '/'; else *p++ = *s; s++; if (*s == ']') { s++; break; } } if (*s != 0) /* more after ']' ?? */ { if (*(p-1) != '/') *p++ = '/'; strcpy (p, s); /* copy it anyway */ } } else /* no '[' anywhere */ { *p++ = 0; } /* force end with '/' */ if (*(p-1) != '/') *p++ = '/'; *p = 0; return piece; } /* EOF */ ================================================ FILE: src/vmsjobs.c ================================================ /* --------------- Moved here from job.c --------------- This file must be #included in job.c, as it accesses static functions. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include /* TODO - VMS specific header file conditionally included in makeint.h */ #include #include void decc$exit (int status); /* Lowest legal non-success VMS exit code is 8 */ /* GNU Make only defines codes 0, 1, 2 */ /* So assume any exit code > 8 is a VMS exit code */ #ifndef MAX_EXPECTED_EXIT_CODE # define MAX_EXPECTED_EXIT_CODE 7 #endif #if __CRTL_VER >= 70302000 && !defined(__VAX) # define MAX_DCL_LINE_LENGTH 4095 # define MAX_DCL_CMD_LINE_LENGTH 8192 #else # define MAX_DCL_LINE_LENGTH 255 # define MAX_DCL_CMD_LINE_LENGTH 1024 #endif #define MAX_DCL_TOKEN_LENGTH 255 #define MAX_DCL_TOKENS 127 enum auto_pipe { nopipe, add_pipe, dcl_pipe }; char *vmsify (char *name, int type); static int vms_jobsefnmask = 0; /* returns whether path is assumed to be a unix like shell. */ int _is_unixy_shell (const char *path) { return vms_gnv_shell; } #define VMS_GETMSG_MAX 256 static char vms_strsignal_text[VMS_GETMSG_MAX + 2]; char * vms_strsignal (int status) { if (status <= MAX_EXPECTED_EXIT_CODE) sprintf (vms_strsignal_text, "lib$spawn returned %x", status); else { int vms_status; unsigned short * msg_len; unsigned char out[4]; vms_status = SYS$GETMSG (status, &msg_len, vms_strsignal_text, 7, *out); } return vms_strsignal_text; } /* Wait for nchildren children to terminate */ static void vmsWaitForChildren (int *status) { while (1) { if (!vms_jobsefnmask) { *status = 0; return; } *status = sys$wflor (32, vms_jobsefnmask); } return; } static int ctrlYPressed= 0; /* This is called at main or AST level. It is at AST level for DONTWAITFORCHILD and at main level otherwise. In any case it is called when a child process terminated. At AST level it won't get interrupted by anything except a inner mode level AST. */ static int vmsHandleChildTerm (struct childbase *cbase) { struct child *child = (struct child*)cbase; struct child *lastc, *c; int child_failed; int exit_code; /* The child efn is 0 when a built-in or null command is executed successfully with out actually creating a child. */ if (child->efn > 0) { vms_jobsefnmask &= ~(1 << (child->efn - 32)); lib$free_ef (&child->efn); } if (child->comname) { if (!ISDB (DB_JOBS) && !ctrlYPressed) unlink (child->comname); free (child->comname); } (void) sigblock (fatal_signal_mask); /* First check to see if this is a POSIX exit status and handle */ if ((child->cstatus & VMS_POSIX_EXIT_MASK) == VMS_POSIX_EXIT_MASK) { exit_code = (child->cstatus >> 3) & 255; if (exit_code != MAKE_SUCCESS) child_failed = 1; } else { child_failed = !$VMS_STATUS_SUCCESS (child->cstatus); if (child_failed) exit_code = child->cstatus; } /* Search for a child matching the deceased one. */ lastc = 0; #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */ for (c = children; c != 0 && c != child; lastc = c, c = c->next) ; #else c = child; #endif if ($VMS_STATUS_SUCCESS (child->vms_launch_status)) { /* Convert VMS success status to 0 for UNIX code to be happy */ child->vms_launch_status = 0; } /* Set the state flag to say the commands have finished. */ c->file->command_state = cs_finished; notice_finished_file (c->file); (void) sigsetmask (sigblock (0) & ~(fatal_signal_mask)); return 1; } /* VMS: Spawn a process executing the command in ARGV and return its pid. */ /* local helpers to make ctrl+c and ctrl+y working, see below */ #include #include #include static int ctrlMask= LIB$M_CLI_CTRLY; static int oldCtrlMask; static int setupYAstTried= 0; static unsigned short int chan= 0; static void reEnableAst(void) { lib$enable_ctrl (&oldCtrlMask,0); } static int astYHandler (void) { struct child *c; for (c = children; c != 0; c = c->next) if (c->pid > 0) sys$delprc (&c->pid, 0, 0); ctrlYPressed= 1; kill (getpid(),SIGQUIT); return SS$_NORMAL; } static void tryToSetupYAst(void) { $DESCRIPTOR(inputDsc,"SYS$COMMAND"); int status; struct { short int status, count; int dvi; } iosb; unsigned short int loc_chan; setupYAstTried++; if (chan) loc_chan= chan; else { status= sys$assign(&inputDsc,&loc_chan,0,0); if (!(status&SS$_NORMAL)) { lib$signal(status); return; } } status= sys$qiow (0, loc_chan, IO$_SETMODE|IO$M_CTRLYAST,&iosb,0,0, astYHandler,0,0,0,0,0); if (status==SS$_NORMAL) status= iosb.status; if (status!=SS$_NORMAL) { if (!chan) sys$dassgn(loc_chan); if (status!=SS$_ILLIOFUNC && status!=SS$_NOPRIV) lib$signal(status); return; } /* called from AST handler ? */ if (setupYAstTried>1) return; if (atexit(reEnableAst)) fprintf (stderr, _("-warning, you may have to re-enable CTRL-Y handling from DCL.\n")); status= lib$disable_ctrl (&ctrlMask, &oldCtrlMask); if (!(status&SS$_NORMAL)) { lib$signal(status); return; } if (!chan) chan = loc_chan; } /* Check if a token is too long */ #define INC_TOKEN_LEN_OR_RETURN(x) {token->length++; \ if (token->length >= MAX_DCL_TOKEN_LENGTH) \ { token->cmd_errno = ERANGE; return x; }} #define INC_TOKEN_LEN_OR_BREAK {token->length++; \ if (token->length >= MAX_DCL_TOKEN_LENGTH) \ { token->cmd_errno = ERANGE; break; }} #define ADD_TOKEN_LEN_OR_RETURN(add_len, x) {token->length += add_len; \ if (token->length >= MAX_DCL_TOKEN_LENGTH) \ { token->cmd_errno = ERANGE; return x; }} /* Check if we are out of space for more tokens */ #define V_NEXT_TOKEN { if (cmd_tkn_index < MAX_DCL_TOKENS) \ cmd_tokens[++cmd_tkn_index] = NULL; \ else { token.cmd_errno = E2BIG; break; } \ token.length = 0;} #define UPDATE_TOKEN {cmd_tokens[cmd_tkn_index] = strdup(token.text); \ V_NEXT_TOKEN;} #define EOS_ERROR(x) { if (*x == 0) { token->cmd_errno = ERANGE; break; }} struct token_info { char *text; /* Parsed text */ int length; /* Length of parsed text */ char *src; /* Pointer to source text */ int cmd_errno; /* Error status of parse */ int use_cmd_file; /* Force use of a command file */ }; /* Extract a Posix single quoted string from input line */ static char * posix_parse_sq (struct token_info *token) { /* A Posix quoted string with no expansion unless in a string Unix simulation means no lexical functions present. */ char * q; char * p; q = token->text; p = token->src; *q++ = '"'; p++; INC_TOKEN_LEN_OR_RETURN (p); while (*p != '\'' && (token->length < MAX_DCL_TOKEN_LENGTH)) { EOS_ERROR (p); if (*p == '"') { /* Embedded double quotes need to be doubled */ *q++ = '"'; INC_TOKEN_LEN_OR_BREAK; *q = '"'; } else *q = *p; q++; p++; INC_TOKEN_LEN_OR_BREAK; } *q++ = '"'; p++; INC_TOKEN_LEN_OR_RETURN (p); *q = 0; return p; } /* Extract a Posix double quoted string from input line */ static char * posix_parse_dq (struct token_info *token) { /* Unix mode: Any embedded \" becomes doubled. \t is tab, \\, \$ leading character stripped. $ character replaced with \' unless escaped. */ char * q; char * p; q = token->text; p = token->src; *q++ = *p++; INC_TOKEN_LEN_OR_RETURN (p); while (*p != 0) { if (*p == '\\') { switch(p[1]) { case 't': /* Convert tabs */ *q = '\t'; p++; break; case '\\': /* Just remove leading backslash */ case '$': p++; *q = *p; break; case '"': p++; *q = *p; *q++ = '"'; INC_TOKEN_LEN_OR_BREAK; default: /* Pass through unchanged */ *q++ = *p++; INC_TOKEN_LEN_OR_BREAK; } INC_TOKEN_LEN_OR_BREAK; } else if (*p == '$' && isalpha ((unsigned char) p[1])) { /* A symbol we should be able to substitute */ *q++ = '\''; INC_TOKEN_LEN_OR_BREAK; *q = '\''; INC_TOKEN_LEN_OR_BREAK; token->use_cmd_file = 1; } else { *q = *p; INC_TOKEN_LEN_OR_BREAK; if (*p == '"') { p++; q++; break; } } p++; q++; } *q = 0; return p; } /* Extract a VMS quoted string or substitution string from input line */ static char * vms_parse_quotes (struct token_info *token) { /* VMS mode, the \' means that a symbol substitution is starting so while you might think you can just copy until the next \'. Unfortunately the substitution can be a lexical function which can contain embedded strings and lexical functions. Messy, so both types need to be handled together. */ char * q; char * p; q = token->text; p = token->src; int parse_level[MAX_DCL_TOKENS + 1]; int nest = 0; parse_level[0] = *p; if (parse_level[0] == '\'') token->use_cmd_file = 1; *q++ = *p++; INC_TOKEN_LEN_OR_RETURN (p); /* Copy everything until after the next single quote at nest == 0 */ while (token->length < MAX_DCL_TOKEN_LENGTH) { EOS_ERROR (p); *q = *p; INC_TOKEN_LEN_OR_BREAK; if ((*p == parse_level[nest]) && (p[1] != '"')) { if (nest == 0) { *q++ = *p++; break; } nest--; } else { switch(*p) { case '\\': /* Handle continuation on to next line */ if (p[1] != '\n') break; p++; p++; *q = *p; break; case '(': /* Parenthesis only in single quote level */ if (parse_level[nest] == '\'') { nest++; parse_level[nest] == ')'; } break; case '"': /* Double quotes only in parenthesis */ if (parse_level[nest] == ')') { nest++; parse_level[nest] == '"'; } break; case '\'': /* Symbol substitution only in double quotes */ if ((p[1] == '\'') && (parse_level[nest] == '"')) { nest++; parse_level[nest] == '\''; *p++ = *q++; token->use_cmd_file = 1; INC_TOKEN_LEN_OR_BREAK; break; } *q = *p; } } p++; q++; /* Pass through doubled double quotes */ if ((*p == '"') && (p[1] == '"') && (parse_level[nest] == '"')) { *p++ = *q++; INC_TOKEN_LEN_OR_BREAK; *p++ = *q++; INC_TOKEN_LEN_OR_BREAK; } } *q = 0; return p; } /* Extract a $ string from the input line */ static char * posix_parse_dollar (struct token_info *token) { /* $foo becomes 'foo' */ char * q; char * p; q = token->text; p = token->src; token->use_cmd_file = 1; p++; *q++ = '\''; INC_TOKEN_LEN_OR_RETURN (p); while ((isalnum ((unsigned char) *p)) || (*p == '_')) { *q++ = *p++; INC_TOKEN_LEN_OR_BREAK; } *q++ = '\''; while (1) { INC_TOKEN_LEN_OR_BREAK; break; } *q = 0; return p; } const char *vms_filechars = "0123456789abcdefghijklmnopqrstuvwxyz" \ "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]<>:/_-.$"; /* Simple text copy */ static char * parse_text (struct token_info *token, int assignment_hack) { char * q; char * p; int str_len; q = token->text; p = token->src; /* If assignment hack, then this text needs to be double quoted. */ if (vms_unix_simulation && (assignment_hack == 2)) { *q++ = '"'; INC_TOKEN_LEN_OR_RETURN (p); } *q++ = *p++; INC_TOKEN_LEN_OR_RETURN (p); while (*p != 0) { str_len = strspn (p, vms_filechars); if (str_len == 0) { /* Pass through backslash escapes in Unix simulation probably will not work anyway. All any character after a ^ otherwise to support EFS. */ if (vms_unix_simulation && (p[0] == '\\') && (p[1] != 0)) str_len = 2; else if ((p[0] == '^') && (p[1] != 0)) str_len = 2; else if (!vms_unix_simulation && (p[0] == ';')) str_len = 1; if (str_len == 0) { /* If assignment hack, then this needs to be double quoted. */ if (vms_unix_simulation && (assignment_hack == 2)) { *q++ = '"'; INC_TOKEN_LEN_OR_RETURN (p); } *q = 0; return p; } } if (str_len > 0) { ADD_TOKEN_LEN_OR_RETURN (str_len, p); strncpy (q, p, str_len); p += str_len; q += str_len; *q = 0; } } /* If assignment hack, then this text needs to be double quoted. */ if (vms_unix_simulation && (assignment_hack == 2)) { *q++ = '"'; INC_TOKEN_LEN_OR_RETURN (p); } return p; } /* single character copy */ static char * parse_char (struct token_info *token, int count) { char * q; char * p; q = token->text; p = token->src; while (count > 0) { *q++ = *p++; INC_TOKEN_LEN_OR_RETURN (p); count--; } *q = 0; return p; } /* Build a command string from the collected tokens and process built-ins now */ static struct dsc$descriptor_s * build_vms_cmd (char **cmd_tokens, enum auto_pipe use_pipe_cmd, int append_token) { struct dsc$descriptor_s *cmd_dsc; int cmd_tkn_index; char * cmd; int cmd_len; int semicolon_seen; cmd_tkn_index = 0; cmd_dsc = xmalloc (sizeof (struct dsc$descriptor_s)); /* Empty command? */ if (cmd_tokens[0] == NULL) { cmd_dsc->dsc$a_pointer = NULL; cmd_dsc->dsc$w_length = 0; return cmd_dsc; } /* Max DCL command + 1 extra token and trailing space */ cmd = xmalloc (MAX_DCL_CMD_LINE_LENGTH + 256); cmd[0] = '$'; cmd[1] = 0; cmd_len = 1; /* Handle real or auto-pipe */ if (use_pipe_cmd == add_pipe) { /* We need to auto convert to a pipe command */ strcat (cmd, "pipe "); cmd_len += 5; } semicolon_seen = 0; while (cmd_tokens[cmd_tkn_index] != NULL) { /* Check for buffer overflow */ if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } /* Eliminate double ';' */ if (semicolon_seen && (cmd_tokens[cmd_tkn_index][0] == ';')) { semicolon_seen = 0; free (cmd_tokens[cmd_tkn_index++]); if (cmd_tokens[cmd_tkn_index] == NULL) break; } /* Special handling for CD built-in */ if (strncmp (cmd_tokens[cmd_tkn_index], "builtin_cd", 11) == 0) { int result; semicolon_seen = 0; free (cmd_tokens[cmd_tkn_index]); cmd_tkn_index++; if (cmd_tokens[cmd_tkn_index] == NULL) break; DB(DB_JOBS, (_("BUILTIN CD %s\n"), cmd_tokens[cmd_tkn_index])); /* TODO: chdir fails with some valid syntaxes */ result = chdir (cmd_tokens[cmd_tkn_index]); if (result != 0) { /* TODO: Handle failure better */ free (cmd); while (cmd_tokens[cmd_tkn_index] == NULL) free (cmd_tokens[cmd_tkn_index++]); cmd_dsc->dsc$w_length = -1; cmd_dsc->dsc$a_pointer = NULL; return cmd_dsc; } } else if (strncmp (cmd_tokens[cmd_tkn_index], "exit", 5) == 0) { /* Copy the exit command */ semicolon_seen = 0; strcpy (&cmd[cmd_len], cmd_tokens[cmd_tkn_index]); cmd_len += strlen (cmd_tokens[cmd_tkn_index]); free (cmd_tokens[cmd_tkn_index++]); if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } /* Optional whitespace */ if (isspace ((unsigned char) cmd_tokens[cmd_tkn_index][0])) { strcpy (&cmd[cmd_len], cmd_tokens[cmd_tkn_index]); cmd_len += strlen (cmd_tokens[cmd_tkn_index]); free (cmd_tokens[cmd_tkn_index++]); if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } } /* There should be a status, but it is optional */ if (cmd_tokens[cmd_tkn_index][0] == ';') continue; /* If Unix simulation, add '((' */ if (vms_unix_simulation) { strcpy (&cmd[cmd_len], "(("); cmd_len += 2; if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } } /* Add the parameter */ strcpy (&cmd[cmd_len], cmd_tokens[cmd_tkn_index]); cmd_len += strlen (cmd_tokens[cmd_tkn_index]); free (cmd_tokens[cmd_tkn_index++]); if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } /* Add " * 8) .and. %x7f8) .or. %x1035a002" */ if (vms_unix_simulation) { const char *end_str = " * 8) .and. %x7f8) .or. %x1035a002"; strcpy (&cmd[cmd_len], end_str); cmd_len += strlen (end_str); if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } } continue; } /* auto pipe needs spaces before semicolon */ if (use_pipe_cmd == add_pipe) if (cmd_tokens[cmd_tkn_index][0] == ';') { cmd[cmd_len++] = ' '; semicolon_seen = 1; if (cmd_len > MAX_DCL_CMD_LINE_LENGTH) { errno = E2BIG; break; } } else { char ch; ch = cmd_tokens[cmd_tkn_index][0]; if (!(ch == ' ' || ch == '\t')) semicolon_seen = 0; } strcpy (&cmd[cmd_len], cmd_tokens[cmd_tkn_index]); cmd_len += strlen (cmd_tokens[cmd_tkn_index]); free (cmd_tokens[cmd_tkn_index++]); /* Skip the append tokens if they exist */ if (cmd_tkn_index == append_token) { free (cmd_tokens[cmd_tkn_index++]); if (isspace ((unsigned char) cmd_tokens[cmd_tkn_index][0])) free (cmd_tokens[cmd_tkn_index++]); free (cmd_tokens[cmd_tkn_index++]); } } cmd[cmd_len] = 0; cmd_dsc->dsc$w_length = cmd_len; cmd_dsc->dsc$a_pointer = cmd; cmd_dsc->dsc$b_dtype = DSC$K_DTYPE_T; cmd_dsc->dsc$b_class = DSC$K_CLASS_S; return cmd_dsc; } pid_t child_execute_job (struct childbase *child, int good_stdin UNUSED, char *argv) { int i; static struct dsc$descriptor_s *cmd_dsc; static struct dsc$descriptor_s pnamedsc; int spflags = CLI$M_NOWAIT; int status; int comnamelen; char procname[100]; char *p; char *cmd_tokens[(MAX_DCL_TOKENS * 2) + 1]; /* whitespace does not count */ char token_str[MAX_DCL_TOKEN_LENGTH + 1]; struct token_info token; int cmd_tkn_index; int paren_level = 0; enum auto_pipe use_pipe_cmd = nopipe; int append_token = -1; char *append_file = NULL; int unix_echo_cmd = 0; /* Special handle Unix echo command */ int assignment_hack = 0; /* Handle x=y command as piped command */ /* Parse IO redirection. */ child->comname = NULL; DB (DB_JOBS, ("child_execute_job (%s)\n", argv)); while (isspace ((unsigned char)*argv)) argv++; if (*argv == 0) { /* Only a built-in or a null command - Still need to run term AST */ child->cstatus = VMS_POSIX_EXIT_MASK; child->vms_launch_status = SS$_NORMAL; child->efn = 0; vmsHandleChildTerm (child); /* TODO what is this "magic number" */ return 270163; /* Special built-in */ } sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff); pnamedsc.dsc$w_length = strlen (procname); pnamedsc.dsc$a_pointer = procname; pnamedsc.dsc$b_dtype = DSC$K_DTYPE_T; pnamedsc.dsc$b_class = DSC$K_CLASS_S; /* Old */ /* Handle comments and redirection. For ONESHELL, the redirection must be on the first line. Any other redirection token is handled by DCL, that is, the pipe command with redirection can be used, but it should not be used on the first line for ONESHELL. */ /* VMS parser notes: 1. A token is any of DCL verbs, qualifiers, parameters, or punctuation. 2. Only MAX_DCL_TOKENS per line in both one line or command file mode. 3. Each token limited to MAC_DCL_TOKEN_LENGTH 4. If the line to DCL is greater than MAX_DCL_LINE_LENGTH then a command file must be used. 5. Currently a command file must be used symbol substitution is to be performed. 6. Currently limiting command files to 2 * MAX_DCL_TOKENS. Build both a command file token list and command line token list until it is determined that the command line limits are exceeded. */ cmd_tkn_index = 0; cmd_tokens[cmd_tkn_index] = NULL; p = argv; token.text = token_str; token.length = 0; token.cmd_errno = 0; token.use_cmd_file = 0; while (*p != 0) { /* We can not build this command so give up */ if (token.cmd_errno != 0) break; token.src = p; switch (*p) { case '\'': if (vms_unix_simulation || unix_echo_cmd) { p = posix_parse_sq (&token); UPDATE_TOKEN; break; } /* VMS mode, the \' means that a symbol substitution is starting so while you might think you can just copy until the next \'. Unfortunately the substitution can be a lexical function which can contain embedded strings and lexical functions. Messy. */ p = vms_parse_quotes (&token); UPDATE_TOKEN; break; case '"': if (vms_unix_simulation) { p = posix_parse_dq (&token); UPDATE_TOKEN; break; } /* VMS quoted string, can contain lexical functions with quoted strings and nested lexical functions. */ p = vms_parse_quotes (&token); UPDATE_TOKEN; break; case '$': if (vms_unix_simulation) { p = posix_parse_dollar (&token); UPDATE_TOKEN; break; } /* Otherwise nothing special */ p = parse_text (&token, 0); UPDATE_TOKEN; break; case '\\': if (p[1] == '\n') { /* Line continuation, remove it */ p += 2; break; } /* Ordinary character otherwise */ if (assignment_hack != 0) assignment_hack++; if (assignment_hack > 2) { assignment_hack = 0; /* Reset */ if (use_pipe_cmd == nopipe) /* force pipe use */ use_pipe_cmd = add_pipe; token_str[0] = ';'; /* add ; token */ token_str[1] = 0; UPDATE_TOKEN; } p = parse_text (&token, assignment_hack); UPDATE_TOKEN; break; case '!': case '#': /* Unix '#' is VMS '!' which comments out the rest of the line. Historically the rest of the line has been skipped. Not quite the right thing to do, as the f$verify lexical function works in comments. But this helps keep the line lengths short. */ unix_echo_cmd = 0; while (*p != '\n' && *p != 0) p++; break; case '(': /* Subshell, equation, or lexical function argument start */ p = parse_char (&token, 1); UPDATE_TOKEN; paren_level++; break; case ')': /* Close out a paren level */ p = parse_char (&token, 1); UPDATE_TOKEN; paren_level--; /* TODO: Should we diagnose if paren_level goes negative? */ break; case '&': if (isalpha ((unsigned char) p[1]) && !vms_unix_simulation) { /* VMS symbol substitution */ p = parse_text (&token, 0); token.use_cmd_file = 1; UPDATE_TOKEN; break; } if (use_pipe_cmd == nopipe) use_pipe_cmd = add_pipe; if (p[1] != '&') p = parse_char (&token, 1); else p = parse_char (&token, 2); UPDATE_TOKEN; break; case '|': if (use_pipe_cmd == nopipe) use_pipe_cmd = add_pipe; if (p[1] != '|') p = parse_char (&token, 1); else p = parse_char (&token, 2); UPDATE_TOKEN; break; case ';': /* Separator - convert to a pipe command. */ unix_echo_cmd = 0; case '<': if (use_pipe_cmd == nopipe) use_pipe_cmd = add_pipe; p = parse_char (&token, 1); UPDATE_TOKEN; break; case '>': if (use_pipe_cmd == nopipe) use_pipe_cmd = add_pipe; if (p[1] == '>') { /* Parsing would have been simple until support for the >> append redirect was added. Implementation needs: * if not exist output file create empty * open/append gnv$make_temp??? output_file * define/user sys$output gnv$make_temp??? ** And all this done before the command previously tokenized. * command previously tokenized * close gnv$make_temp??? */ p = parse_char (&token, 2); append_token = cmd_tkn_index; token.use_cmd_file = 1; } else p = parse_char (&token, 1); UPDATE_TOKEN; break; case '/': /* Unix path or VMS option start, read until non-path symbol */ if (assignment_hack != 0) assignment_hack++; if (assignment_hack > 2) { assignment_hack = 0; /* Reset */ if (use_pipe_cmd == nopipe) /* force pipe use */ use_pipe_cmd = add_pipe; token_str[0] = ';'; /* add ; token */ token_str[1] = 0; UPDATE_TOKEN; } p = parse_text (&token, assignment_hack); UPDATE_TOKEN; break; case ':': if ((p[1] == 0) || isspace ((unsigned char) p[1])) { /* Unix Null command - treat as comment until next command */ unix_echo_cmd = 0; p++; while (*p != 0) { if (*p == ';') { /* Remove Null command from pipeline */ p++; break; } p++; } break; } /* String assignment */ /* := :== or : */ if (p[1] != '=') p = parse_char (&token, 1); else if (p[2] != '=') p = parse_char (&token, 2); else p = parse_char (&token, 3); UPDATE_TOKEN; break; case '=': /* = or == */ /* If this is not an echo statement, this could be a shell assignment. VMS requires the target to be quoted if it is not a macro substitution */ if (!unix_echo_cmd && vms_unix_simulation && (assignment_hack == 0)) assignment_hack = 1; if (p[1] != '=') p = parse_char (&token, 1); else p = parse_char (&token, 2); UPDATE_TOKEN; break; case '+': case '-': case '*': p = parse_char (&token, 1); UPDATE_TOKEN; break; case '.': /* .xxx. operation, VMS does not require the trailing . */ p = parse_text (&token, 0); UPDATE_TOKEN; break; default: /* Skip repetitive whitespace */ if (isspace ((unsigned char) *p)) { p = parse_char (&token, 1); /* Force to a space or a tab */ if ((token_str[0] != ' ') || (token_str[0] != '\t')) token_str[0] = ' '; UPDATE_TOKEN; while (isspace ((unsigned char) *p)) p++; if (assignment_hack != 0) assignment_hack++; break; } if (assignment_hack != 0) assignment_hack++; if (assignment_hack > 2) { assignment_hack = 0; /* Reset */ if (use_pipe_cmd == nopipe) /* force pipe use */ use_pipe_cmd = add_pipe; token_str[0] = ';'; /* add ; token */ token_str[1] = 0; UPDATE_TOKEN; } p = parse_text (&token, assignment_hack); if (strncasecmp (token.text, "echo", 4) == 0) unix_echo_cmd = 1; else if (strncasecmp (token.text, "pipe", 4) == 0) use_pipe_cmd = dcl_pipe; UPDATE_TOKEN; break; } } /* End up here with a list of tokens to build a command line. Deal with errors detected during parsing. */ if (token.cmd_errno != 0) { while (cmd_tokens[cmd_tkn_index] == NULL) free (cmd_tokens[cmd_tkn_index++]); child->cstatus = VMS_POSIX_EXIT_MASK | (MAKE_TROUBLE << 3); child->vms_launch_status = SS$_ABORT; child->efn = 0; errno = token.cmd_errno; return -1; } /* Save any redirection to append file */ if (append_token != -1) { int file_token; char * lastdot; char * lastdir; char * raw_append_file; file_token = append_token; file_token++; if (isspace ((unsigned char) cmd_tokens[file_token][0])) file_token++; raw_append_file = vmsify (cmd_tokens[file_token], 0); /* VMS DCL needs a trailing dot if null file extension */ lastdot = strrchr(raw_append_file, '.'); lastdir = strrchr(raw_append_file, ']'); if (lastdir == NULL) lastdir = strrchr(raw_append_file, '>'); if (lastdir == NULL) lastdir = strrchr(raw_append_file, ':'); if ((lastdot == NULL) || (lastdot > lastdir)) { append_file = xmalloc (strlen (raw_append_file) + 1); strcpy (append_file, raw_append_file); strcat (append_file, "."); } else append_file = strdup(raw_append_file); } cmd_dsc = build_vms_cmd (cmd_tokens, use_pipe_cmd, append_token); if (cmd_dsc->dsc$a_pointer == NULL) { if (cmd_dsc->dsc$w_length < 0) { free (cmd_dsc); child->cstatus = VMS_POSIX_EXIT_MASK | (MAKE_TROUBLE << 3); child->vms_launch_status = SS$_ABORT; child->efn = 0; return -1; } /* Only a built-in or a null command - Still need to run term AST */ free (cmd_dsc); child->cstatus = VMS_POSIX_EXIT_MASK; child->vms_launch_status = SS$_NORMAL; child->efn = 0; vmsHandleChildTerm (child); /* TODO what is this "magic number" */ return 270163; /* Special built-in */ } if (cmd_dsc->dsc$w_length > MAX_DCL_LINE_LENGTH) token.use_cmd_file = 1; DB(DB_JOBS, (_("DCL: %s\n"), cmd_dsc->dsc$a_pointer)); /* Enforce the creation of a command file if "vms_always_use_cmd_file" is non-zero. Further, this way DCL reads the input stream and therefore does 'forced' symbol substitution, which it doesn't do for one-liners when they are 'lib$spawn'ed. Otherwise the behavior is: Create a *.com file if either the command is too long for lib$spawn, or if a redirect appending to a file is desired, or symbol substitution. */ if (vms_always_use_cmd_file || token.use_cmd_file) { FILE *outfile; int cmd_len; outfile = get_tmpfile (&child->comname); comnamelen = strlen (child->comname); /* The whole DCL "script" is executed as one action, and it behaves as any DCL "script", that is errors stop it but warnings do not. Usually the command on the last line, defines the exit code. However, with redirections there is a prolog and possibly an epilog to implement the redirection. Both are part of the script which is actually executed. So if the redirection encounters an error in the prolog, the user actions will not run; if in the epilog, the user actions ran, but output is not captured. In both error cases, the error of redirection is passed back and not the exit code of the actions. The user should be able to enable DCL "script" verification with "set verify". However, the prolog and epilog commands are not shown. Also, if output redirection is used, the verification output is redirected into that file as well. */ fprintf (outfile, "$ gnv$$make_verify = \"''f$verify(0)'\"\n"); fprintf (outfile, "$ gnv$$make_pid = f$getjpi(\"\",\"pid\")\n"); fprintf (outfile, "$ on error then $ goto gnv$$make_error\n"); /* Handle append redirection */ if (append_file != NULL) { /* If file does not exist, create it */ fprintf (outfile, "$ gnv$$make_al = \"gnv$$make_append''gnv$$make_pid'\"\n"); fprintf (outfile, "$ if f$search(\"%s\") .eqs. \"\" then create %s\n", append_file, append_file); fprintf (outfile, "$ open/append 'gnv$$make_al' %s\n", append_file); /* define sys$output to that file */ fprintf (outfile, "$ define/user sys$output 'gnv$$make_al'\n"); DB (DB_JOBS, (_("Append output to %s\n"), append_file)); free(append_file); } fprintf (outfile, "$ gnv$$make_verify = f$verify(gnv$$make_verify)\n"); /* TODO: Only for ONESHELL there will be several commands separated by '\n'. But there can always be multiple continuation lines. */ fprintf (outfile, "%s\n", cmd_dsc->dsc$a_pointer); fprintf (outfile, "$ gnv$$make_status_2 = $status\n"); fprintf (outfile, "$ goto gnv$$make_exit\n"); /* Exit and clean up */ fprintf (outfile, "$ gnv$$make_error: ! 'f$verify(0)\n"); fprintf (outfile, "$ gnv$$make_status_2 = $status\n"); if (append_token != -1) { fprintf (outfile, "$ deassign sys$output\n"); fprintf (outfile, "$ close 'gnv$$make_al'\n"); DB (DB_JOBS, (_("Append %.*s and cleanup\n"), comnamelen-3, child->comname)); } fprintf (outfile, "$ gnv$$make_exit: ! 'f$verify(0)\n"); fprintf (outfile, "$ exit 'gnv$$make_status_2' + (0*f$verify(gnv$$make_verify))\n"); fclose (outfile); free (cmd_dsc->dsc$a_pointer); cmd_dsc->dsc$a_pointer = xmalloc (256 + 4); sprintf (cmd_dsc->dsc$a_pointer, "$ @%s", child->comname); cmd_dsc->dsc$w_length = strlen (cmd_dsc->dsc$a_pointer); DB (DB_JOBS, (_("Executing %s instead\n"), child->comname)); } child->efn = 0; while (child->efn < 32 || child->efn > 63) { status = LIB$GET_EF ((unsigned long *)&child->efn); if (!$VMS_STATUS_SUCCESS (status)) { if (child->comname) { if (!ISDB (DB_JOBS)) unlink (child->comname); free (child->comname); } return -1; } } SYS$CLREF (child->efn); vms_jobsefnmask |= (1 << (child->efn - 32)); /* Export the child environment into DCL symbols */ if (child->environment != 0) { char **ep = child->environment; while (*ep != 0) { vms_putenv_symbol (*ep); *ep++; } } /* LIB$SPAWN [command-string] [,input-file] [,output-file] [,flags] [,process-name] [,process-id] [,completion-status-address] [,byte-integer-event-flag-num] [,AST-address] [,varying-AST-argument] [,prompt-string] [,cli] [,table] */ #ifndef DONTWAITFORCHILD /* * Code to make ctrl+c and ctrl+y working. * The problem starts with the synchronous case where after lib$spawn is * called any input will go to the child. But with input re-directed, * both control characters won't make it to any of the programs, neither * the spawning nor to the spawned one. Hence the caller needs to spawn * with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr * has to follow to simulate the wanted synchronous behaviour. * The next problem is ctrl+y which isn't caught by the crtl and * therefore isn't converted to SIGQUIT (for a signal handler which is * already established). The only way to catch ctrl+y, is an AST * assigned to the input channel. But ctrl+y handling of DCL needs to be * disabled, otherwise it will handle it. Not to mention the previous * ctrl+y handling of DCL needs to be re-established before make exits. * One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will * make it to the signal handler after the child "normally" terminates. * This isn't enough. It seems reasonable for simple command lines like * a 'cc foobar.c' spawned in a subprocess but it is unacceptable for * spawning make. Therefore we need to abort the process in the AST. * * Prior to the spawn it is checked if an AST is already set up for * ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general * this will work except if make is run in a batch environment, but there * nobody can press ctrl+y. During the setup the DCL handling of ctrl+y * is disabled and an exit handler is established to re-enable it. * If the user interrupts with ctrl+y, the assigned AST will fire, force * an abort to the subprocess and signal SIGQUIT, which will be caught by * the already established handler and will bring us back to common code. * After the spawn (now /nowait) a sys$waitfr simulates the /wait and * enables the ctrl+y be delivered to this code. And the ctrl+c too, * which the crtl converts to SIGINT and which is caught by the common * signal handler. Because signals were blocked before entering this code * sys$waitfr will always complete and the SIGQUIT will be processed after * it (after termination of the current block, somewhere in common code). * And SIGINT too will be delayed. That is ctrl+c can only abort when the * current command completes. Anyway it's better than nothing :-) */ if (!setupYAstTried) tryToSetupYAst(); child->vms_launch_status = lib$spawn (cmd_dsc, /* cmd-string */ NULL, /* input-file */ NULL, /* output-file */ &spflags, /* flags */ &pnamedsc, /* proc name */ &child->pid, &child->cstatus, &child->efn, 0, 0, 0, 0, 0); status = child->vms_launch_status; if ($VMS_STATUS_SUCCESS (status)) { status = sys$waitfr (child->efn); vmsHandleChildTerm (child); } #else child->vms_launch_status = lib$spawn (cmd_dsc, NULL, NULL, &spflags, &pnamedsc, &child->pid, &child->cstatus, &child->efn, vmsHandleChildTerm, child, 0, 0, 0); status = child->vms_launch_status; #endif /* Free the pointer if not a command file */ if (!vms_always_use_cmd_file && !token.use_cmd_file) free (cmd_dsc->dsc$a_pointer); free (cmd_dsc); if (!$VMS_STATUS_SUCCESS (status)) { switch (status) { case SS$_EXQUOTA: errno = EPROCLIM; break; default: errno = EFAIL; } } /* Restore the VMS symbols that were changed */ if (child->environment != 0) { char **ep = child->environment; while (*ep != 0) { vms_restore_symbol (*ep); *ep++; } } /* TODO what is this "magic number" */ return (status & 1) ? 270163 : -1 ; } ================================================ FILE: src/vpath.c ================================================ /* Implementation of pattern-matching file search paths for GNU Make. Copyright (C) 1988-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "filedef.h" #include "variable.h" #if MK_OS_W32 #include "pathstuff.h" #endif /* Structure used to represent a selective VPATH searchpath. */ struct vpath { struct vpath *next; /* Pointer to next struct in the linked list. */ const char *pattern; /* The pattern to match. */ const char *percent; /* Pointer into 'pattern' where the '%' is. */ size_t patlen; /* Length of the pattern. */ const char **searchpath; /* Null-terminated list of directories. */ size_t maxlen; /* Maximum length of any entry in the list. */ }; /* Linked-list of all selective VPATHs. */ static struct vpath *vpaths; /* Structure for the general VPATH given in the variable. */ static struct vpath *general_vpath; /* Structure for GPATH given in the variable. */ static struct vpath *gpaths; /* Reverse the chain of selective VPATH lists so they will be searched in the order given in the makefiles and construct the list from the VPATH variable. */ void build_vpath_lists (void) { struct vpath *new = 0; struct vpath *old, *nexto; char *p; /* Reverse the chain. */ for (old = vpaths; old != 0; old = nexto) { nexto = old->next; old->next = new; new = old; } vpaths = new; /* If there is a VPATH variable with a nonnull expanded value, construct the general VPATH list from it. */ p = expand_variable ("VPATH", 5); NEXT_TOKEN (p); if (*p != '\0') { /* Save the list of vpaths. */ struct vpath *save_vpaths = vpaths; char gp[] = "%"; /* Empty 'vpaths' so the new one will have no next, and 'vpaths' will still be nil if P contains no existing directories. */ vpaths = 0; /* Parse P. */ construct_vpath_list (gp, p); /* Store the created path as the general path, and restore the old list of vpaths. */ general_vpath = vpaths; vpaths = save_vpaths; } /* If there is a GPATH variable with a nonnull expanded value, construct the GPATH list from it. */ p = expand_variable ("GPATH", 5); NEXT_TOKEN (p); if (*p != '\0') { /* Save the list of vpaths. */ struct vpath *save_vpaths = vpaths; char gp[] = "%"; /* Empty 'vpaths' so the new one will have no next, and 'vpaths' will still be nil if P contains no existing directories. */ vpaths = 0; /* Parse P. */ construct_vpath_list (gp, p); /* Store the created path as the GPATH, and restore the old list of vpaths. */ gpaths = vpaths; vpaths = save_vpaths; } } /* Construct the VPATH listing for the PATTERN and DIRPATH given. This function is called to generate selective VPATH lists and also for the general VPATH list (which is in fact just a selective VPATH that is applied to everything). The returned pointer is either put in the linked list of all selective VPATH lists or in the GENERAL_VPATH variable. If DIRPATH is nil, remove all previous listings with the same pattern. If PATTERN is nil, remove all VPATH listings. Existing and readable directories that are not "." given in the DIRPATH separated by the path element separator (defined in makeint.h) are loaded into the directory hash table if they are not there already and put in the VPATH searchpath for the given pattern with trailing slashes stripped off if present (and if the directory is not the root, "/"). The length of the longest entry in the list is put in the structure as well. The new entry will be at the head of the VPATHS chain. */ void construct_vpath_list (char *pattern, char *dirpath) { unsigned int elem; char *p; const char **vpath; size_t maxvpath; unsigned int maxelem; const char *percent = NULL; if (pattern != 0) percent = find_percent (pattern); if (dirpath == 0) { /* Remove matching listings. */ struct vpath *path, *lastpath; lastpath = 0; path = vpaths; while (path != 0) { struct vpath *next = path->next; if (pattern == 0 || (((percent == 0 && path->percent == 0) || (percent - pattern == path->percent - path->pattern)) && streq (pattern, path->pattern))) { /* Remove it from the linked list. */ if (lastpath == 0) vpaths = path->next; else lastpath->next = next; /* Free its unused storage. */ /* MSVC erroneously warns without a cast here. */ free ((void *)path->searchpath); free (path); } else lastpath = path; path = next; } return; } #if MK_OS_W32 convert_vpath_to_windows32 (dirpath, ';'); #endif /* Skip over any initial separators and blanks. */ while (STOP_SET (*dirpath, MAP_BLANK|MAP_PATHSEP)) ++dirpath; /* Figure out the maximum number of VPATH entries and put it in MAXELEM. We start with 2, one before the first separator and one nil (the list terminator) and increment our estimated number for each separator or blank we find. */ maxelem = 2; p = dirpath; while (*p != '\0') if (STOP_SET (*p++, MAP_BLANK|MAP_PATHSEP)) ++maxelem; vpath = xmalloc (maxelem * sizeof (const char *)); maxvpath = 0; elem = 0; p = dirpath; while (*p != '\0') { char *v; size_t len; /* Find the end of this entry. */ v = p; while (*p != '\0' #if defined(HAVE_DOS_PATHS) && (PATH_SEPARATOR_CHAR == ':') /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which also define HAVE_DOS_PATHS would like us to recognize colons after the drive letter in the likes of "D:/foo/bar:C:/xyzzy". */ && (*p != PATH_SEPARATOR_CHAR || (p == v + 1 && ISDIRSEP (p[1]))) #else && *p != PATH_SEPARATOR_CHAR #endif && !ISBLANK (*p)) ++p; len = p - v; /* Make sure there's no trailing slash, but still allow "/" as a directory. */ #if MK_OS_DOS || MK_OS_OS2 || defined(HAVE_DOS_PATHS) /* We need also to leave alone a trailing slash in "d:/". */ if (len > 3 || (len > 1 && v[1] != ':')) #endif if (len > 1 && p[-1] == '/') --len; /* Put the directory on the vpath list. */ if (len > 1 || *v != '.') { vpath[elem++] = dir_name (strcache_add_len (v, len)); if (len > maxvpath) maxvpath = len; } /* Skip over separators and blanks between entries. */ while (STOP_SET (*p, MAP_BLANK|MAP_PATHSEP)) ++p; } if (elem > 0) { struct vpath *path; /* ELEM is now incremented one element past the last entry, to where the nil-pointer terminator goes. Usually this is maxelem - 1. If not, shrink down. */ if (elem < (maxelem - 1)) vpath = xrealloc ((void *)vpath, (elem+1) * sizeof (const char *)); /* Put the nil-pointer terminator on the end of the VPATH list. */ vpath[elem] = NULL; /* Construct the vpath structure and put it into the linked list. */ path = xmalloc (sizeof (struct vpath)); path->searchpath = vpath; path->maxlen = maxvpath; path->next = vpaths; vpaths = path; /* Set up the members. */ path->pattern = strcache_add (pattern); path->patlen = strlen (pattern); path->percent = percent ? path->pattern + (percent - pattern) : 0; } else /* There were no entries, so free whatever space we allocated. */ /* MSVC erroneously warns without a cast here. */ free ((void *)vpath); } /* Search the GPATH list for a pathname string that matches the one passed in. If it is found, return 1. Otherwise we return 0. */ int gpath_search (const char *file, size_t len) { if (gpaths && (len <= gpaths->maxlen)) { const char **gp; for (gp = gpaths->searchpath; *gp != NULL; ++gp) if (strneq (*gp, file, len) && (*gp)[len] == '\0') return 1; } return 0; } /* Search the given VPATH list for a directory where the name pointed to by FILE exists. If it is found, we return a cached name of the existing file and set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no stat call was done). Also set the matching directory index in PATH_INDEX if it is not NULL. Otherwise we return NULL. */ static const char * selective_vpath_search (struct vpath *path, const char *file, FILE_TIMESTAMP *mtime_ptr, unsigned int* path_index) { int not_target; char *name; const char *n; const char *filename; const char **vpath = path->searchpath; size_t maxvpath = path->maxlen; unsigned int i; size_t flen, name_dplen; int exists = 0; /* Find out if *FILE is a target. If and only if it is NOT a target, we will accept prospective files that don't exist but are mentioned in a makefile. */ { struct file *f = lookup_file (file); not_target = f == 0 || !f->is_target; } flen = strlen (file); /* Split *FILE into a directory prefix and a name-within-directory. NAME_DPLEN gets the length of the prefix; FILENAME gets the pointer to the name-within-directory and FLEN is its length. */ n = strrchr (file, '/'); #ifdef HAVE_DOS_PATHS /* We need the rightmost slash or backslash. */ { const char *bslash = strrchr (file, '\\'); if (!n || bslash > n) n = bslash; } #endif name_dplen = n != 0 ? n - file : 0; filename = name_dplen > 0 ? n + 1 : file; if (name_dplen > 0) flen -= name_dplen + 1; /* Get enough space for the biggest VPATH entry, a slash, the directory prefix that came with FILE, another slash (although this one may not always be necessary), the filename, and a null terminator. */ name = alloca (maxvpath + 1 + name_dplen + 1 + flen + 1); /* Try each VPATH entry. */ for (i = 0; vpath[i] != 0; ++i) { int exists_in_cache = 0; char *p = name; size_t vlen = strlen (vpath[i]); /* Put the next VPATH entry into NAME at P and increment P past it. */ p = mempcpy (p, vpath[i], vlen); /* Add the directory prefix already in *FILE. */ if (name_dplen > 0) { #if !MK_OS_VMS *p++ = '/'; #else /* VMS: if this is not in VMS format, treat as Unix format */ if ((*p != ':') && (*p != ']') && (*p != '>')) *p++ = '/'; #endif p = mempcpy (p, file, name_dplen); } #ifdef HAVE_DOS_PATHS /* Cause the next if to treat backslash and slash alike. */ if (p != name && p[-1] == '\\' ) p[-1] = '/'; #endif /* Now add the name-within-directory at the end of NAME. */ #if !MK_OS_VMS if (p != name && p[-1] != '/') { *p = '/'; memcpy (p + 1, filename, flen + 1); } else #else /* VMS use a slash if no directory terminator present */ if (p != name && p[-1] != '/' && p[-1] != ':' && p[-1] != '>' && p[-1] != ']') { *p = '/'; memcpy (p + 1, filename, flen + 1); } else #endif memcpy (p, filename, flen + 1); /* Check if the file is mentioned in a makefile. If *FILE is not a target, that is enough for us to decide this file exists. If *FILE is a target, then the file must be mentioned in the makefile also as a target to be chosen. The restriction that *FILE must not be a target for a makefile-mentioned file to be chosen was added by an inadequately commented change in July 1990; I am not sure off hand what problem it fixes. In December 1993 I loosened this restriction to allow a file to be chosen if it is mentioned as a target in a makefile. This seem logical. Special handling for -W / -o: make sure we preserve the special values here. Actually this whole thing is a little bogus: I think we should ditch the name/hname thing and look into the renamed capability that already exists for files: that is, have a new struct file* entry for the VPATH-found file, and set the renamed field if we use it. */ { struct file *f = lookup_file (name); if (f != 0) { exists = not_target || f->is_target; if (exists && mtime_ptr && (f->last_mtime == OLD_MTIME || f->last_mtime == NEW_MTIME)) { *mtime_ptr = f->last_mtime; mtime_ptr = 0; } } } if (!exists) { /* That file wasn't mentioned in the makefile. See if it actually exists. */ #if MK_OS_VMS /* For VMS syntax just use the original vpath */ if (*p != '/') exists_in_cache = exists = dir_file_exists_p (vpath[i], filename); else #endif { /* Clobber a null into the name at the last slash. Now NAME is the name of the directory to look in. */ *p = '\0'; /* We know the directory is in the hash table now because either construct_vpath_list or the code just above put it there. Does the file we seek exist in it? */ exists_in_cache = exists = dir_file_exists_p (name, filename); } } if (exists) { /* The file is in the directory cache. Now check that it actually exists in the filesystem. The cache may be out of date. When vpath thinks a file exists, but stat fails for it, confusion results in the higher levels. */ struct stat st; #if !MK_OS_VMS /* Put the slash back in NAME. */ *p = '/'; #else /* If the slash was removed, put it back */ if (*p == 0) *p = '/'; #endif if (exists_in_cache) /* Makefile-mentioned file need not exist. */ { int e; EINTRLOOP (e, stat (name, &st)); /* Does it really exist? */ if (e != 0) { exists = 0; continue; } /* Store the modtime into *MTIME_PTR for the caller. */ if (mtime_ptr != 0) { *mtime_ptr = FILE_TIMESTAMP_STAT_MODTIME (name, st); mtime_ptr = 0; } } /* We have found a file. If we get here and mtime_ptr hasn't been set, record UNKNOWN_MTIME to indicate this. */ if (mtime_ptr != 0) *mtime_ptr = UNKNOWN_MTIME; /* Store the name we found and return it. */ if (path_index) *path_index = i; return strcache_add_len (name, (p + 1 - name) + flen); } } return 0; } /* Search the VPATH list whose pattern matches FILE for a directory where FILE exists. If it is found, return the cached name of an existing file, and set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no stat call was done). Also set the matching directory index in VPATH_INDEX and PATH_INDEX if they are not NULL. Otherwise we return 0. */ const char * vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr, unsigned int* vpath_index, unsigned int* path_index) { struct vpath *v; /* If there are no VPATH entries or FILENAME starts at the root, there is nothing we can do. */ if (file[0] == '/' #ifdef HAVE_DOS_PATHS || file[0] == '\\' || file[1] == ':' #endif || (vpaths == 0 && general_vpath == 0)) return 0; if (vpath_index) { *vpath_index = 0; *path_index = 0; } for (v = vpaths; v != 0; v = v->next) { if (pattern_matches (v->pattern, v->percent, file)) { const char *p = selective_vpath_search ( v, file, mtime_ptr, path_index); if (p) return p; } if (vpath_index) ++*vpath_index; } if (general_vpath != 0) { const char *p = selective_vpath_search ( general_vpath, file, mtime_ptr, path_index); if (p) return p; } return 0; } /* Print the data base of VPATH search paths. */ void print_vpath_data_base (void) { unsigned int nvpaths; struct vpath *v; puts (_("\n# VPATH Search Paths\n")); nvpaths = 0; for (v = vpaths; v != 0; v = v->next) { unsigned int i; ++nvpaths; printf ("vpath %s ", v->pattern); for (i = 0; v->searchpath[i] != 0; ++i) printf ("%s%c", v->searchpath[i], v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR); } if (vpaths == 0) puts (_("# No 'vpath' search paths.")); else printf (_("\n# %u 'vpath' search paths.\n"), nvpaths); if (general_vpath == 0) puts (_("\n# No general ('VPATH' variable) search path.")); else { const char **path = general_vpath->searchpath; unsigned int i; fputs (_("\n# General ('VPATH' variable) search path:\n# "), stdout); for (i = 0; path[i] != 0; ++i) printf ("%s%c", path[i], path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR); } } ================================================ FILE: src/w32/compat/dirent.c ================================================ /* Directory entry code for Window platforms. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include "dirent.h" #ifndef __MINGW32__ DIR* opendir(const char* pDirName) { struct stat sb; DIR* pDir; char* pEndDirName; size_t nBufferLen; /* sanity checks */ if (!pDirName) { errno = EINVAL; return NULL; } if (stat(pDirName, &sb) != 0) { errno = ENOENT; return NULL; } if ((sb.st_mode & S_IFMT) != S_IFDIR) { errno = ENOTDIR; return NULL; } /* allocate a DIR structure to return */ pDir = (DIR *) malloc(sizeof (DIR)); if (!pDir) return NULL; /* input directory name length */ nBufferLen = strlen(pDirName); /* copy input directory name to DIR buffer */ strcpy(pDir->dir_pDirectoryName, pDirName); /* point to end of the copied directory name */ pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1]; /* if directory name did not end in '/' or '\', add '/' */ if ((*pEndDirName != '/') && (*pEndDirName != '\\')) { pEndDirName++; *pEndDirName = '/'; } /* now append the wildcard character to the buffer */ pEndDirName++; *pEndDirName = '*'; pEndDirName++; *pEndDirName = '\0'; /* other values defaulted */ pDir->dir_nNumFiles = 0; pDir->dir_hDirHandle = INVALID_HANDLE_VALUE; pDir->dir_ulCookie = __DIRENT_COOKIE; return pDir; } void closedir(DIR *pDir) { /* got a valid pointer? */ if (!pDir) { errno = EINVAL; return; } /* sanity check that this is a DIR pointer */ if (pDir->dir_ulCookie != __DIRENT_COOKIE) { errno = EINVAL; return; } /* close the Windows32 directory handle */ if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE) FindClose(pDir->dir_hDirHandle); free(pDir); return; } struct dirent * readdir(DIR* pDir) { WIN32_FIND_DATA wfdFindData; if (!pDir) { errno = EINVAL; return NULL; } /* sanity check that this is a DIR pointer */ if (pDir->dir_ulCookie != __DIRENT_COOKIE) { errno = EINVAL; return NULL; } if (pDir->dir_nNumFiles == 0) { pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData); if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE) return NULL; } else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData)) return NULL; /* bump count for next call to readdir() */ pDir->dir_nNumFiles++; /* fill in struct dirent values */ pDir->dir_sdReturn.d_ino = (ino_t)-1; strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName); if (wfdFindData.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) pDir->dir_sdReturn.d_type = DT_CHR; else if (wfdFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) pDir->dir_sdReturn.d_type = DT_DIR; else pDir->dir_sdReturn.d_type = DT_REG; return &pDir->dir_sdReturn; } void rewinddir(DIR* pDir) { if (!pDir) { errno = EINVAL; return; } /* sanity check that this is a DIR pointer */ if (pDir->dir_ulCookie != __DIRENT_COOKIE) { errno = EINVAL; return; } /* close the Windows32 directory handle */ if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE) if (!FindClose(pDir->dir_hDirHandle)) errno = EBADF; /* reset members which control readdir() */ pDir->dir_hDirHandle = INVALID_HANDLE_VALUE; pDir->dir_nNumFiles = 0; return; } void seekdir(DIR* pDir, long nPosition) { if (!pDir) return; /* sanity check that this is a DIR pointer */ if (pDir->dir_ulCookie != __DIRENT_COOKIE) return; /* go back to beginning of directory */ rewinddir(pDir); /* loop until we have found position we care about */ for (--nPosition; nPosition && readdir(pDir); nPosition--); /* flag invalid nPosition value */ if (nPosition) errno = EINVAL; return; } #endif /* !__MINGW32__ */ ================================================ FILE: src/w32/compat/posixfcn.c ================================================ /* Replacements for Posix functions and Posix functionality for MS-Windows. Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include #include #include #include #include "os.h" #include "dlfcn.h" #include "job.h" #if MAKE_LOAD /* Support for dynamic loading of objects. */ static DWORD last_err; void * dlopen (const char *file, int mode) { char dllfn[MAX_PATH], *p; HANDLE dllhandle; if ((mode & ~(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL)) != 0) { errno = EINVAL; last_err = ERROR_INVALID_PARAMETER; return NULL; } if (!file) dllhandle = GetModuleHandle (NULL); else { /* MSDN says to be sure to use backslashes in the DLL file name. */ strcpy (dllfn, file); for (p = dllfn; *p; p++) if (*p == '/') *p = '\\'; dllhandle = LoadLibrary (dllfn); } if (!dllhandle) last_err = GetLastError (); return dllhandle; } char * dlerror (void) { static char errbuf[1024]; DWORD ret; if (!last_err) return NULL; ret = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_err, 0, errbuf, sizeof (errbuf), NULL); while (ret > 0 && (errbuf[ret - 1] == '\n' || errbuf[ret - 1] == '\r')) --ret; errbuf[ret] = '\0'; if (!ret) sprintf (errbuf, "Error code %lu", last_err); last_err = 0; return errbuf; } void * dlsym (void *handle, const char *name) { FARPROC addr = NULL; if (!handle || handle == INVALID_HANDLE_VALUE) { last_err = ERROR_INVALID_PARAMETER; return NULL; } addr = GetProcAddress (handle, name); if (!addr) last_err = GetLastError (); return (void *)addr; } int dlclose (void *handle) { if (!handle || handle == INVALID_HANDLE_VALUE) return -1; if (!FreeLibrary (handle)) return -1; return 0; } #endif /* MAKE_LOAD */ /* MS runtime's isatty returns non-zero for any character device, including the null device, which is not what we want. */ int isatty (int fd) { HANDLE fh = get_handle_for_fd (fd); DWORD con_mode; if (fh == INVALID_HANDLE_VALUE) { errno = EBADF; return 0; } if (GetConsoleMode (fh, &con_mode)) return 1; errno = ENOTTY; return 0; } char * ttyname (int fd UNUSED) { /* This "knows" that Make only asks about stdout and stderr. A more sophisticated implementation should test whether FD is open for input or output. We can do that by looking at the mode returned by GetConsoleMode. */ static char name[] = "CONOUT$"; return name; } ================================================ FILE: src/w32/include/dirent.h ================================================ /* Windows version of dirent.h Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _DIRENT_H #define _DIRENT_H #ifdef __MINGW32__ # include # include_next #else #include #include #include #include #ifndef NAME_MAX #define NAME_MAX 255 #endif #define __DIRENT_COOKIE 0xfefeabab /* File types for `d_type'. Windows only supports DT_CHR, DT_DIR, and DT_REG. */ enum { DT_UNKNOWN = 0, # define DT_UNKNOWN DT_UNKNOWN DT_FIFO = 1, # define DT_FIFO DT_FIFO DT_CHR = 2, # define DT_CHR DT_CHR DT_DIR = 4, # define DT_DIR DT_DIR DT_BLK = 6, # define DT_BLK DT_BLK DT_REG = 8, # define DT_REG DT_REG DT_LNK = 10, # define DT_LNK DT_LNK DT_SOCK = 12, # define DT_SOCK DT_SOCK DT_WHT = 14 # define DT_WHT DT_WHT }; struct dirent { ino_t d_ino; /* unused - no equivalent on Windows32. */ unsigned char d_type; char d_name[NAME_MAX+1]; /* must come last due to dir.c assumptions. */ }; typedef struct dir_struct { ULONG dir_ulCookie; HANDLE dir_hDirHandle; DWORD dir_nNumFiles; char dir_pDirectoryName[NAME_MAX+1]; struct dirent dir_sdReturn; } DIR; DIR *opendir(const char *); struct dirent *readdir(DIR *); void rewinddir(DIR *); void closedir(DIR *); void seekdir(DIR *, long); #endif /* !__MINGW32__ */ #endif ================================================ FILE: src/w32/include/dlfcn.h ================================================ /* dlfcn.h replacement for MS-Windows build. Copyright (C) 2013-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DLFCN_H #define DLFCN_H #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_GLOBAL 4 extern void *dlopen (const char *, int); extern void *dlsym (void *, const char *); extern char *dlerror (void); extern int dlclose (void *); #endif /* DLFCN_H */ ================================================ FILE: src/w32/include/pathstuff.h ================================================ /* Definitions for Windows path manipulation. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _PATHSTUFF_H #define _PATHSTUFF_H char *convert_Path_to_windows32(char *Path, char to_delim); char *convert_vpath_to_windows32(char *Path, char to_delim); char *w32ify(const char *file, int resolve); char *getcwd_fs(char *buf, int len); #endif ================================================ FILE: src/w32/include/sub_proc.h ================================================ /* Definitions for Windows process invocation. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SUB_PROC_H #define SUB_PROC_H /* * Component Name: * * $Date$ * * $Source$ * * $Id$ */ #define EXTERN_DECL(entry, args) extern entry args #define VOID_DECL void EXTERN_DECL(HANDLE process_init, (VOID_DECL)); EXTERN_DECL(HANDLE process_init_fd, (HANDLE stdinh, HANDLE stdouth, HANDLE stderrh)); EXTERN_DECL(long process_begin, (HANDLE proc, char **argv, char **envp, char *exec_path, char *as_user)); EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data, int stdin_data_len)); EXTERN_DECL(long process_file_io, (HANDLE proc)); EXTERN_DECL(void process_cleanup, (HANDLE proc)); EXTERN_DECL(HANDLE process_wait_for_any, (int block, DWORD* pdwWaitStatus)); EXTERN_DECL(void process_register, (HANDLE proc)); EXTERN_DECL(HANDLE process_easy, (char** argv, char** env, int outfd, int errfd)); EXTERN_DECL(BOOL process_kill, (HANDLE proc, int signal)); EXTERN_DECL(BOOL process_table_full, (VOID_DECL)); EXTERN_DECL(int process_table_usable_size, (VOID_DECL)); EXTERN_DECL(int process_table_actual_size, (VOID_DECL)); EXTERN_DECL(DWORD process_set_handles, (HANDLE *handles)); EXTERN_DECL(DWORD process_wait_for_multiple_objects, (DWORD, const HANDLE*, BOOL, DWORD)); /* support routines */ EXTERN_DECL(long process_errno, (HANDLE proc)); EXTERN_DECL(long process_last_err, (HANDLE proc)); EXTERN_DECL(long process_exit_code, (HANDLE proc)); EXTERN_DECL(long process_signal, (HANDLE proc)); EXTERN_DECL(char * process_outbuf, (HANDLE proc)); EXTERN_DECL(char * process_errbuf, (HANDLE proc)); EXTERN_DECL(int process_outcnt, (HANDLE proc)); EXTERN_DECL(int process_errcnt, (HANDLE proc)); EXTERN_DECL(void process_pipes, (HANDLE proc, int pipes[3])); #endif ================================================ FILE: src/w32/include/w32err.h ================================================ /* Definitions for Windows error handling. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _W32ERR_H_ #define _W32ERR_H_ #ifndef EXTERN_DECL #define EXTERN_DECL(entry, args) entry args #endif EXTERN_DECL(const char * map_windows32_error_to_string, (DWORD error)); #endif /* !_W32ERR_H */ ================================================ FILE: src/w32/pathstuff.c ================================================ /* Path conversion for Windows pathnames. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include #include "pathstuff.h" /* * Convert delimiter separated vpath to Canonical format. */ char * convert_vpath_to_windows32(char *Path, char to_delim) { char *etok; /* token separator for old Path */ /* * Convert all spaces to delimiters. Note that pathnames which * contain blanks get trounced here. Use 8.3 format as a workaround. */ for (etok = Path; etok && *etok; etok++) if (ISBLANK ((unsigned char) *etok)) *etok = to_delim; return (convert_Path_to_windows32(Path, to_delim)); } /* * Convert delimiter separated path to Canonical format. */ char * convert_Path_to_windows32(char *Path, char to_delim) { char *etok; /* token separator for old Path */ char *p; /* points to element of old Path */ /* is this a multi-element Path ? */ /* FIXME: Perhaps use ":;\"" in strpbrk to convert all quotes to delimiters as well, as a way to handle quoted directories in PATH? */ for (p = Path, etok = strpbrk(p, ":;"); etok; etok = strpbrk(p, ":;")) if ((etok - p) == 1) { if (*(etok - 1) == ';' || *(etok - 1) == ':') { etok[-1] = to_delim; etok[0] = to_delim; p = ++etok; continue; /* ignore empty bucket */ } else if (!isalpha ((unsigned char) *p)) { /* found one to count, handle things like '.' */ *etok = to_delim; p = ++etok; } else if ((*etok == ':') && ((etok = strpbrk(etok+1, ":;")) != NULL)) { /* found one to count, handle drive letter */ *etok = to_delim; p = ++etok; } else /* all finished, force abort */ p += strlen(p); } else if (*p == '"') { /* a quoted directory */ for (p++; *p && *p != '"'; p++) /* skip quoted part */ ; etok = strpbrk(p, ":;"); /* find next delimiter */ if (etok) { *etok = to_delim; p = ++etok; } else p += strlen(p); } else { /* found another one, no drive letter */ *etok = to_delim; p = ++etok; } return Path; } /* * Convert to forward slashes. Resolve to full pathname optionally */ char * w32ify(const char *filename, int resolve) { static char w32_path[FILENAME_MAX]; char *p; if (resolve) { char *fp = _fullpath (NULL, filename, sizeof (w32_path)); strncpy (w32_path, fp, sizeof (w32_path) - 1); free (fp); } else strncpy(w32_path, filename, sizeof (w32_path) - 1); for (p = w32_path; p && *p; p++) if (*p == '\\') *p = '/'; return w32_path; } char * getcwd_fs(char* buf, int len) { char *p = getcwd(buf, len); if (p) { char *q = w32ify(buf, 0); strncpy(buf, q, len); } return p; } #ifdef unused /* * Convert delimiter separated pathnames (e.g. PATH) or single file pathname * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that * _NutPathToNutc() fails to convert, just return the path we were handed * and assume the caller will know what to do with it (It was probably * a mistake to try and convert it anyway due to some of the bizarre things * that might look like pathnames in makefiles). */ char * convert_path_to_nutc(char *path) { int count; /* count of path elements */ char *nutc_path; /* new NutC path */ int nutc_path_len; /* length of buffer to allocate for new path */ char *pathp; /* pointer to nutc_path used to build it */ char *etok; /* token separator for old path */ char *p; /* points to element of old path */ char sep; /* what flavor of separator used in old path */ char *rval; /* is this a multi-element path ? */ for (p = path, etok = strpbrk(p, ":;"), count = 0; etok; etok = strpbrk(p, ":;")) if ((etok - p) == 1) { if (*(etok - 1) == ';' || *(etok - 1) == ':') { p = ++etok; continue; /* ignore empty bucket */ } else if (etok = strpbrk(etok+1, ":;")) /* found one to count, handle drive letter */ p = ++etok, count++; else /* all finished, force abort */ p += strlen(p); } else /* found another one, no drive letter */ p = ++etok, count++; if (count) { count++; /* x1;x2;x3 <- need to count x3 */ /* * Hazard a guess on how big the buffer needs to be. * We have to convert things like c:/foo to /c=/foo. */ nutc_path_len = strlen(path) + (count*2) + 1; nutc_path = xmalloc(nutc_path_len); pathp = nutc_path; *pathp = '\0'; /* * Loop through PATH and convert one element of the path at at * a time. Single file pathnames will fail this and fall * to the logic below loop. */ for (p = path, etok = strpbrk(p, ":;"); etok; etok = strpbrk(p, ":;")) { /* don't trip up on device specifiers or empty path slots */ if ((etok - p) == 1) if (*(etok - 1) == ';' || *(etok - 1) == ':') { p = ++etok; continue; } else if ((etok = strpbrk(etok+1, ":;")) == NULL) break; /* thing found was a Windows32 pathname */ /* save separator */ sep = *etok; /* terminate the current path element -- temporarily */ *etok = '\0'; #ifdef __NUTC__ /* convert to NutC format */ if (_NutPathToNutc(p, pathp, 0) == FALSE) { free(nutc_path); rval = savestring(path, strlen(path)); return rval; } #else *pathp++ = '/'; *pathp++ = p[0]; *pathp++ = '='; *pathp++ = '/'; strcpy(pathp, &p[2]); #endif pathp += strlen(pathp); *pathp++ = ':'; /* use Unix style path separator for new path */ *pathp = '\0'; /* make sure we are null terminaed */ /* restore path separator */ *etok = sep; /* point p to first char of next path element */ p = ++etok; } } else { nutc_path_len = strlen(path) + 3; nutc_path = xmalloc(nutc_path_len); pathp = nutc_path; *pathp = '\0'; p = path; } /* * OK, here we handle the last element in PATH (e.g. c of a;b;c) * or the path was a single filename and will be converted * here. Note, testing p here assures that we don't trip up * on paths like a;b; which have trailing delimiter followed by * nothing. */ if (*p != '\0') { #ifdef __NUTC__ if (_NutPathToNutc(p, pathp, 0) == FALSE) { free(nutc_path); rval = savestring(path, strlen(path)); return rval; } #else *pathp++ = '/'; *pathp++ = p[0]; *pathp++ = '='; *pathp++ = '/'; strcpy(pathp, &p[2]); #endif } else *(pathp-1) = '\0'; /* we're already done, don't leave trailing : */ rval = savestring(nutc_path, strlen(nutc_path)); free(nutc_path); return rval; } #endif ================================================ FILE: src/w32/subproc/misc.c ================================================ /* Process handling for Windows Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include "proc.h" /* * Description: Convert a NULL string terminated UNIX environment block to * an environment block suitable for a windows32 system call * * Returns: TRUE= success, FALSE=fail * * Notes/Dependencies: the environment block is sorted in case-insensitive * order, is double-null terminated, and is a char *, not a char ** */ int _cdecl compare(const void *a1, const void *a2) { return _stricoll(*((char**)a1),*((char**)a2)); } bool_t arr2envblk(char **arr, char **envblk_out, size_t *envsize_needed) { char **tmp; size_t size_needed; int arrcnt; char *ptr; arrcnt = 0; while (arr[arrcnt]) { arrcnt++; } tmp = (char**) calloc(arrcnt + 1, sizeof(char *)); if (!tmp) { return FALSE; } arrcnt = 0; size_needed = *envsize_needed = 0; while (arr[arrcnt]) { tmp[arrcnt] = arr[arrcnt]; size_needed += strlen(arr[arrcnt]) + 1; arrcnt++; } size_needed++; *envsize_needed = size_needed; qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare); ptr = *envblk_out = calloc(size_needed, 1); if (!ptr) { free(tmp); return FALSE; } arrcnt = 0; while (tmp[arrcnt]) { strcpy(ptr, tmp[arrcnt]); ptr += strlen(tmp[arrcnt]) + 1; arrcnt++; } free(tmp); return TRUE; } ================================================ FILE: src/w32/subproc/proc.h ================================================ /* Definitions for Windows Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _PROC_H #define _PROC_H typedef int bool_t; #define E_SCALL 101 #define E_IO 102 #define E_NO_MEM 103 #define E_FORK 104 extern bool_t arr2envblk(char **arr, char **envblk_out, size_t *envsize_needed); #endif ================================================ FILE: src/w32/subproc/sub_proc.c ================================================ /* Process handling for Windows. Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include #include #include /* for _get_osfhandle */ #ifdef _MSC_VER # include /* for intptr_t */ #else # include #endif #include #include /* for msvc _beginthreadex, _endthreadex */ #include #include #include "filedef.h" #include "variable.h" #include "sub_proc.h" #include "proc.h" #include "w32err.h" #include "debug.h" #include "os.h" #define GMAKE_MAXIMUM_WAIT_OBJECTS (MAXIMUM_WAIT_OBJECTS * MAXIMUM_WAIT_OBJECTS) /* We need to move these special-case return codes out-of-band */ #define GMAKE_WAIT_TIMEOUT 0xFFFF0102L #define GMAKE_WAIT_ABANDONED_0 0x00080000L static char *make_command_line(char *shell_name, char *exec_path, char **argv); typedef struct sub_process_t { intptr_t sv_stdin[2]; intptr_t sv_stdout[2]; intptr_t sv_stderr[2]; int using_pipes; char *inp; DWORD incnt; char * volatile outp; volatile DWORD outcnt; char * volatile errp; volatile DWORD errcnt; pid_t pid; int exit_code; int signal; long last_err; long lerrno; } sub_process; /* keep track of children so we can implement a waitpid-like routine */ static sub_process *proc_array[GMAKE_MAXIMUM_WAIT_OBJECTS]; static unsigned int proc_index = 0; static unsigned int fake_exits_pending = 0; /* * Address the scalability limit intrisic to WaitForMultipleOjects by * calling WaitForMultipleObjects on 64 element chunks of the input * array with 0 timeout. Exit with an appropriately conditioned result * or repeat again every 10 ms if no handle has signaled and the * requested timeout was not zero. */ DWORD process_wait_for_multiple_objects( DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds ) { assert(nCount <= GMAKE_MAXIMUM_WAIT_OBJECTS); if (nCount <= MAXIMUM_WAIT_OBJECTS) { DWORD retVal = WaitForMultipleObjects(nCount, lpHandles, bWaitAll, dwMilliseconds); return (retVal == WAIT_TIMEOUT) ? GMAKE_WAIT_TIMEOUT : retVal; } else { for (;;) { DWORD objectCount = nCount; int blockCount = 0; DWORD retVal = 0; assert(bWaitAll == FALSE); /* This logic only works for this use case */ assert(dwMilliseconds == 0 || dwMilliseconds == INFINITE); /* No support for timeouts */ for (; objectCount > 0; blockCount++) { DWORD n = objectCount <= MAXIMUM_WAIT_OBJECTS ? objectCount : MAXIMUM_WAIT_OBJECTS; objectCount -= n; retVal = WaitForMultipleObjects(n, &lpHandles[blockCount * MAXIMUM_WAIT_OBJECTS], FALSE, 0); switch (retVal) { case WAIT_TIMEOUT: retVal = GMAKE_WAIT_TIMEOUT; continue; break; case WAIT_FAILED: fprintf(stderr,"WaitForMultipleOjbects failed waiting with error %lu\n", GetLastError()); break; default: if (retVal >= WAIT_ABANDONED_0) { assert(retVal < WAIT_ABANDONED_0 + MAXIMUM_WAIT_OBJECTS); retVal += blockCount * MAXIMUM_WAIT_OBJECTS - WAIT_ABANDONED_0 + GMAKE_WAIT_ABANDONED_0; } else { assert(retVal < WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS); retVal += blockCount * MAXIMUM_WAIT_OBJECTS; } break; } return retVal; } if (dwMilliseconds == 0) return retVal; Sleep(10); /* Sleep for 10 ms */ } } } /* * Fill a HANDLE list with handles to wait for. */ DWORD process_set_handles(HANDLE *handles) { DWORD count = 0; unsigned int i; /* Build array of handles to wait for */ for (i = 0; i < proc_index; i++) { /* Don't wait on child processes that have already finished */ if (fake_exits_pending && proc_array[i]->exit_code) continue; handles[count++] = (HANDLE) proc_array[i]->pid; } return count; } /* * When a process has been waited for, adjust the wait state * array so that we don't wait for it again */ static void process_adjust_wait_state(sub_process* pproc) { unsigned int i; if (!proc_index) return; for (i = 0; i < proc_index; i++) if (proc_array[i]->pid == pproc->pid) break; if (i < proc_index) { proc_index--; if (i != proc_index) memmove(&proc_array[i], &proc_array[i+1], (proc_index-i) * sizeof(sub_process*)); proc_array[proc_index] = NULL; } } /* * Waits for any of the registered child processes to finish. */ static sub_process * process_wait_for_any_private(int block, DWORD* pdwWaitStatus) { HANDLE handles[GMAKE_MAXIMUM_WAIT_OBJECTS]; DWORD retval, which; unsigned int i; if (!proc_index) return NULL; /* build array of handles to wait for */ for (i = 0; i < proc_index; i++) { handles[i] = (HANDLE) proc_array[i]->pid; if (fake_exits_pending && proc_array[i]->exit_code) break; } /* wait for someone to exit */ if (!fake_exits_pending) { retval = process_wait_for_multiple_objects(proc_index, handles, FALSE, (block ? INFINITE : 0)); which = retval - WAIT_OBJECT_0; } else { fake_exits_pending--; retval = !WAIT_FAILED; which = i; } /* If the pointer is not NULL, set the wait status result variable. */ if (pdwWaitStatus) *pdwWaitStatus = (retval == GMAKE_WAIT_TIMEOUT) ? WAIT_TIMEOUT : retval; /* return pointer to process */ if ((retval == GMAKE_WAIT_TIMEOUT) || (retval == WAIT_FAILED)) { return NULL; } else { sub_process* pproc = proc_array[which]; process_adjust_wait_state(pproc); return pproc; } } /* * Terminate a process. */ BOOL process_kill(HANDLE proc, int signal) { sub_process* pproc = (sub_process*) proc; pproc->signal = signal; return (TerminateProcess((HANDLE) pproc->pid, signal)); } /* * Returns true when we have no more available slots in our process table. */ BOOL process_table_full() { extern int shell_function_pid; /* Reserve slots for jobserver_semaphore if we have one and the shell function if not active */ return(proc_index >= GMAKE_MAXIMUM_WAIT_OBJECTS - jobserver_enabled() - (shell_function_pid == 0)); } /* * Returns the maximum number of job slots we can support when using the jobserver. */ int process_table_usable_size() { /* Reserve slots for jobserver_semaphore and shell function */ return(GMAKE_MAXIMUM_WAIT_OBJECTS - 2); } /* * Returns the actual size of the process table. */ int process_table_actual_size() { return(GMAKE_MAXIMUM_WAIT_OBJECTS); } /* * Use this function to register processes you wish to wait for by * calling process_file_io(NULL) or process_wait_any(). This must be done * because it is possible for callers of this library to reuse the same * handle for multiple processes launches :-( */ void process_register(HANDLE proc) { assert(proc_index < GMAKE_MAXIMUM_WAIT_OBJECTS); proc_array[proc_index++] = (sub_process *) proc; } /* * Public function which works kind of like waitpid(). Wait for any * of the children to die and return results. To call this function, * you must do 1 of things: * * x = process_easy(...); * * or * * x = process_init_fd(); * process_register(x); * * or * * x = process_init(); * process_register(x); * * You must NOT then call process_pipe_io() because this function is * not capable of handling automatic notification of any child * death. */ HANDLE process_wait_for_any(int block, DWORD* pdwWaitStatus) { sub_process* pproc = process_wait_for_any_private(block, pdwWaitStatus); if (!pproc) return NULL; else { /* * Ouch! can't tell caller if this fails directly. Caller * will have to use process_last_err() */ (void) process_file_io(pproc); return ((HANDLE) pproc); } } long process_signal(HANDLE proc) { if (proc == INVALID_HANDLE_VALUE) return 0; return (((sub_process *)proc)->signal); } long process_last_err(HANDLE proc) { if (proc == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE; return (((sub_process *)proc)->last_err); } long process_exit_code(HANDLE proc) { if (proc == INVALID_HANDLE_VALUE) return EXIT_FAILURE; return (((sub_process *)proc)->exit_code); } /* 2006-02: All the following functions are currently unused. All of them would crash gmake if called with argument INVALID_HANDLE_VALUE. Hence whoever wants to use one of this functions must invent and implement a reasonable error handling for this function. char * process_outbuf(HANDLE proc) { return (((sub_process *)proc)->outp); } char * process_errbuf(HANDLE proc) { return (((sub_process *)proc)->errp); } int process_outcnt(HANDLE proc) { return (((sub_process *)proc)->outcnt); } int process_errcnt(HANDLE proc) { return (((sub_process *)proc)->errcnt); } void process_pipes(HANDLE proc, int pipes[3]) { pipes[0] = ((sub_process *)proc)->sv_stdin[0]; pipes[1] = ((sub_process *)proc)->sv_stdout[0]; pipes[2] = ((sub_process *)proc)->sv_stderr[0]; return; } */ HANDLE process_init() { sub_process *pproc; /* * open file descriptors for attaching stdin/stdout/sterr */ HANDLE stdin_pipes[2]; HANDLE stdout_pipes[2]; HANDLE stderr_pipes[2]; SECURITY_ATTRIBUTES inherit; BYTE sd[SECURITY_DESCRIPTOR_MIN_LENGTH]; pproc = malloc(sizeof(*pproc)); memset(pproc, 0, sizeof(*pproc)); /* We can't use NULL for lpSecurityDescriptor because that uses the default security descriptor of the calling process. Instead we use a security descriptor with no DACL. This allows nonrestricted access to the associated objects. */ if (!InitializeSecurityDescriptor((PSECURITY_DESCRIPTOR)(&sd), SECURITY_DESCRIPTOR_REVISION)) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; return((HANDLE)pproc); } inherit.nLength = sizeof(inherit); inherit.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)(&sd); inherit.bInheritHandle = TRUE; /* By convention, parent gets pipe[0], and child gets pipe[1]. This means the READ side of stdin pipe goes into pipe[1] and the WRITE side of the stdout and stderr pipes go into pipe[1]. */ if (CreatePipe( &stdin_pipes[1], &stdin_pipes[0], &inherit, 0) == FALSE || CreatePipe( &stdout_pipes[0], &stdout_pipes[1], &inherit, 0) == FALSE || CreatePipe( &stderr_pipes[0], &stderr_pipes[1], &inherit, 0) == FALSE) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; return((HANDLE)pproc); } /* Mark the parent sides of the pipes as non-inheritable. */ if (SetHandleInformation(stdin_pipes[0], HANDLE_FLAG_INHERIT, 0) == FALSE || SetHandleInformation(stdout_pipes[0], HANDLE_FLAG_INHERIT, 0) == FALSE || SetHandleInformation(stderr_pipes[0], HANDLE_FLAG_INHERIT, 0) == FALSE) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; return((HANDLE)pproc); } pproc->sv_stdin[0] = (intptr_t) stdin_pipes[0]; pproc->sv_stdin[1] = (intptr_t) stdin_pipes[1]; pproc->sv_stdout[0] = (intptr_t) stdout_pipes[0]; pproc->sv_stdout[1] = (intptr_t) stdout_pipes[1]; pproc->sv_stderr[0] = (intptr_t) stderr_pipes[0]; pproc->sv_stderr[1] = (intptr_t) stderr_pipes[1]; pproc->using_pipes = 1; pproc->lerrno = 0; return((HANDLE)pproc); } HANDLE process_init_fd(HANDLE stdinh, HANDLE stdouth, HANDLE stderrh) { sub_process *pproc; pproc = malloc(sizeof(*pproc)); if (pproc) { memset(pproc, 0, sizeof(*pproc)); /* * Just pass the provided file handles to the 'child * side' of the pipe, bypassing pipes altogether. */ pproc->sv_stdin[1] = (intptr_t) stdinh; pproc->sv_stdout[1] = (intptr_t) stdouth; pproc->sv_stderr[1] = (intptr_t) stderrh; pproc->last_err = pproc->lerrno = 0; } return((HANDLE)pproc); } static HANDLE find_file(const char *exec_path, const char *path_var, char *full_fname, DWORD full_len) { HANDLE exec_handle; char *fname; char *ext; DWORD req_len; int i; static const char *extensions[] = /* Should .com come before no-extension case? */ { ".exe", ".cmd", ".bat", "", ".com", NULL }; fname = xmalloc(strlen(exec_path) + 5); strcpy(fname, exec_path); ext = fname + strlen(fname); for (i = 0; extensions[i]; i++) { strcpy(ext, extensions[i]); if (((req_len = SearchPath (path_var, fname, NULL, full_len, full_fname, NULL)) > 0 /* For compatibility with previous code, which used OpenFile, and with Windows operation in general, also look in various default locations, such as Windows directory and Windows System directory. Warning: this also searches PATH in the Make's environment, which might not be what the Makefile wants, but it seems to be OK as a fallback, after the previous SearchPath failed to find on child's PATH. */ || (req_len = SearchPath (NULL, fname, NULL, full_len, full_fname, NULL)) > 0) && req_len <= full_len && (exec_handle = CreateFile(full_fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) { free(fname); return(exec_handle); } } free(fname); return INVALID_HANDLE_VALUE; } /* * Return non-zero of FNAME specifies a batch file and its name * includes embedded whitespace. */ static int batch_file_with_spaces(const char *fname) { size_t fnlen = strlen(fname); return (fnlen > 4 && (_strnicmp(fname + fnlen - 4, ".bat", 4) == 0 || _strnicmp(fname + fnlen - 4, ".cmd", 4) == 0) /* The set of characters in the 2nd arg to strpbrk should be the same one used by make_command_line below to decide whether an argv[] element needs quoting. */ && strpbrk(fname, " \t") != NULL); } /* * Description: Create the child process to be helped * * Returns: success <=> 0 * * Notes/Dependencies: */ long process_begin( HANDLE proc, char **argv, char **envp, char *exec_path, char *as_user) { sub_process *pproc = (sub_process *)proc; char *shell_name = 0; int file_not_found=0; HANDLE exec_handle; char exec_fname[MAX_PATH+1]; const char *path_var = NULL; char **ep; char buf[MAX_PATH+1]; DWORD bytes_returned; DWORD flags; char *command_line; STARTUPINFO startInfo; PROCESS_INFORMATION procInfo; char *envblk=NULL; size_t envsize_needed = 0; int pass_null_exec_path = 0; /* * Shell script detection... if the exec_path starts with #! then * we want to exec shell-script-name exec-path, not just exec-path * NT doesn't recognize #!/bin/sh or #!/etc/Tivoli/bin/perl. We do not * hard-code the path to the shell or perl or whatever: Instead, we * assume it's in the path somewhere (generally, the NT tools * bin directory) */ /* Use the Makefile's value of PATH to look for the program to execute, because it could be different from Make's PATH (e.g., if the target sets its own value. */ if (envp) for (ep = envp; *ep; ep++) { if (strncmp (*ep, "PATH=", 5) == 0 || strncmp (*ep, "Path=", 5) == 0) { path_var = *ep + 5; break; } } exec_handle = find_file(exec_path, path_var, exec_fname, sizeof(exec_fname)); /* * If we couldn't open the file, just assume that Windows will be * somehow able to find and execute it. If the first character * of the command is '/', assume they set SHELL to a Unixy shell * that have some magic mounts known only to it, and run the whole * command via $SHELL -c "COMMAND" instead. */ if (exec_handle == INVALID_HANDLE_VALUE) { if (exec_path[0] == '/') { char *new_argv0; char **argvi = argv; size_t arglen = 0; char *exp = expand_variable ("SHELL", 5); memcpy (buf, exp, strlen(exp) + 1); shell_name = &buf[0]; strcpy(exec_fname, "-c"); /* Construct a single command string in argv[0]. */ while (*argvi) { arglen += strlen(*argvi) + 1; argvi++; } new_argv0 = xmalloc(arglen + 1); new_argv0[0] = '\0'; for (argvi = argv; *argvi; argvi++) { strcat(new_argv0, *argvi); strcat(new_argv0, " "); } /* Remove the extra blank at the end. */ new_argv0[arglen-1] = '\0'; free(argv[0]); argv[0] = new_argv0; argv[1] = NULL; } else file_not_found++; } else { /* Attempt to read the first line of the file */ if (ReadFile( exec_handle, buf, sizeof(buf) - 1, /* leave room for trailing NULL */ &bytes_returned, 0) == FALSE || bytes_returned < 2) { pproc->last_err = GetLastError(); pproc->lerrno = E_IO; CloseHandle(exec_handle); return(-1); } if (buf[0] == '#' && buf[1] == '!') { /* * This is a shell script... Change the command line from * exec_path args to shell_name exec_path args */ char *p; /* Make sure buf is NULL terminated */ buf[bytes_returned] = 0; /* * Depending on the file system type, etc. the first line * of the shell script may end with newline or newline-carriage-return * Whatever it ends with, cut it off. */ p= strchr(buf, '\n'); if (p) *p = 0; p = strchr(buf, '\r'); if (p) *p = 0; /* * Find base name of shell */ shell_name = strrchr( buf, '/'); if (shell_name) { shell_name++; } else { shell_name = &buf[2];/* skipping "#!" */ } } CloseHandle(exec_handle); } flags = 0; if (file_not_found) command_line = make_command_line( shell_name, exec_path, argv); else { /* If exec_fname includes whitespace, CreateProcess behaves erratically and unreliably, and often fails if argv[0] also includes whitespace (and thus will be quoted by make_command_line below). So in that case, we don't pass exec_fname as the 1st arg to CreateProcess, but instead replace argv[0] with exec_fname (to keep its leading directories and extension as found by find_file), and pass NULL to CreateProcess as its 1st arg. This works around the bugs in CreateProcess, which are probably caused by its passing the command to cmd.exe with some incorrect quoting. */ if (!shell_name && batch_file_with_spaces(exec_fname) && _stricmp(exec_path, argv[0]) == 0) { char *new_argv, *p; char **argvi; size_t arglen; int i; pass_null_exec_path = 1; /* Rewrite argv[] replacing argv[0] with exec_fname. */ for (argvi = argv + 1, arglen = strlen(exec_fname) + 1; *argvi; argvi++) { arglen += strlen(*argvi) + 1; } new_argv = xmalloc(arglen); p = strcpy(new_argv, exec_fname) + strlen(exec_fname) + 1; for (argvi = argv + 1, i = 1; *argvi; argvi++, i++) { strcpy(p, *argvi); argv[i] = p; p += strlen(*argvi) + 1; } argv[i] = NULL; free (argv[0]); argv[0] = new_argv; } command_line = make_command_line( shell_name, exec_fname, argv); } if ( command_line == NULL ) { pproc->last_err = 0; pproc->lerrno = E_NO_MEM; return(-1); } if (envp) { if (arr2envblk(envp, &envblk, &envsize_needed) == FALSE) { pproc->lerrno = E_NO_MEM; free( command_line ); if ((pproc->last_err == ERROR_INVALID_PARAMETER || pproc->last_err == ERROR_MORE_DATA) && envsize_needed > 32*1024) { fprintf (stderr, "CreateProcess failed, probably because environment is too large (%Iu bytes).\n", envsize_needed); } pproc->last_err = 0; return(-1); } } if (shell_name || file_not_found || pass_null_exec_path) { exec_path = 0; /* Search for the program in %Path% */ } else { exec_path = exec_fname; } /* * Set up inherited stdin, stdout, stderr for child */ memset(&startInfo, '\0', sizeof(startInfo)); GetStartupInfo(&startInfo); startInfo.dwFlags = STARTF_USESTDHANDLES; startInfo.lpReserved = 0; startInfo.cbReserved2 = 0; startInfo.lpReserved2 = 0; startInfo.hStdInput = (HANDLE)pproc->sv_stdin[1]; startInfo.hStdOutput = (HANDLE)pproc->sv_stdout[1]; startInfo.hStdError = (HANDLE)pproc->sv_stderr[1]; if (as_user) { free(envblk); return -1; } else { DB (DB_JOBS, ("CreateProcess(%s,%s,...)\n", exec_path ? exec_path : "NULL", command_line ? command_line : "NULL")); if (CreateProcess( exec_path, command_line, NULL, 0, /* default security attributes for thread */ TRUE, /* inherit handles (e.g. helper pipes, oserv socket) */ flags, envblk, 0, /* default starting directory */ &startInfo, &procInfo) == FALSE) { pproc->last_err = GetLastError(); pproc->lerrno = E_FORK; fprintf(stderr, "process_begin: CreateProcess(%s, %s, ...) failed.\n", exec_path ? exec_path : "NULL", command_line); free(envblk); free( command_line ); return(-1); } } pproc->pid = (pid_t)procInfo.hProcess; /* Close the thread handle -- we'll just watch the process */ CloseHandle(procInfo.hThread); /* Close the halves of the pipes we don't need */ if ((HANDLE)pproc->sv_stdin[1] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stdin[1]); if ((HANDLE)pproc->sv_stdout[1] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stdout[1]); if ((HANDLE)pproc->sv_stderr[1] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stderr[1]); pproc->sv_stdin[1] = 0; pproc->sv_stdout[1] = 0; pproc->sv_stderr[1] = 0; free( command_line ); free(envblk); pproc->lerrno=0; return 0; } #if 0 /* unused */ static DWORD proc_stdin_thread(sub_process *pproc) { DWORD in_done; for (;;) { if (WriteFile( (HANDLE) pproc->sv_stdin[0], pproc->inp, pproc->incnt, &in_done, NULL) == FALSE) _endthreadex(0); /* This if should never be true for anonymous pipes, but gives us a chance to change I/O mechanisms later. */ if (in_done < pproc->incnt) { pproc->incnt -= in_done; pproc->inp += in_done; } else { _endthreadex(0); } } return 0; /* for compiler warnings only.. not reached. */ } static DWORD proc_stdout_thread(sub_process *pproc) { DWORD bufsize = 1024; char c; DWORD nread; pproc->outp = malloc(bufsize); if (pproc->outp == NULL) _endthreadex(0); pproc->outcnt = 0; for (;;) { if (ReadFile( (HANDLE)pproc->sv_stdout[0], &c, 1, &nread, NULL) == FALSE) { /* map_windows32_error_to_string(GetLastError());*/ _endthreadex(0); } if (nread == 0) _endthreadex(0); if (pproc->outcnt + nread > bufsize) { bufsize += nread + 512; pproc->outp = realloc(pproc->outp, bufsize); if (pproc->outp == NULL) { pproc->outcnt = 0; _endthreadex(0); } } pproc->outp[pproc->outcnt++] = c; } return 0; } static DWORD proc_stderr_thread(sub_process *pproc) { DWORD bufsize = 1024; char c; DWORD nread; pproc->errp = malloc(bufsize); if (pproc->errp == NULL) _endthreadex(0); pproc->errcnt = 0; for (;;) { if (ReadFile( (HANDLE)pproc->sv_stderr[0], &c, 1, &nread, NULL) == FALSE) { /* map_windows32_error_to_string(GetLastError());*/ _endthreadex(0); } if (nread == 0) _endthreadex(0); if (pproc->errcnt + nread > bufsize) { bufsize += nread + 512; pproc->errp = realloc(pproc->errp, bufsize); if (pproc->errp == NULL) { pproc->errcnt = 0; _endthreadex(0); } } pproc->errp[pproc->errcnt++] = c; } return 0; } /* * Purpose: collects output from child process and returns results * * Description: * * Returns: * * Notes/Dependencies: */ long process_pipe_io( HANDLE proc, char *stdin_data, int stdin_data_len) { sub_process *pproc = (sub_process *)proc; bool_t stdin_eof = FALSE, stdout_eof = FALSE, stderr_eof = FALSE; HANDLE childhand = (HANDLE) pproc->pid; HANDLE tStdin = NULL, tStdout = NULL, tStderr = NULL; unsigned int dwStdin, dwStdout, dwStderr; HANDLE wait_list[4]; DWORD wait_count; DWORD wait_return; HANDLE ready_hand; bool_t child_dead = FALSE; BOOL GetExitCodeResult; /* * Create stdin thread, if needed */ pproc->inp = stdin_data; pproc->incnt = stdin_data_len; if (!pproc->inp) { stdin_eof = TRUE; CloseHandle((HANDLE)pproc->sv_stdin[0]); pproc->sv_stdin[0] = 0; } else { tStdin = (HANDLE) _beginthreadex( 0, 1024, (unsigned (__stdcall *) (void *))proc_stdin_thread, pproc, 0, &dwStdin); if (tStdin == 0) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; goto done; } } /* * Assume child will produce stdout and stderr */ tStdout = (HANDLE) _beginthreadex( 0, 1024, (unsigned (__stdcall *) (void *))proc_stdout_thread, pproc, 0, &dwStdout); tStderr = (HANDLE) _beginthreadex( 0, 1024, (unsigned (__stdcall *) (void *))proc_stderr_thread, pproc, 0, &dwStderr); if (tStdout == 0 || tStderr == 0) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; goto done; } /* * Wait for all I/O to finish and for the child process to exit */ while (!stdin_eof || !stdout_eof || !stderr_eof || !child_dead) { wait_count = 0; if (!stdin_eof) { wait_list[wait_count++] = tStdin; } if (!stdout_eof) { wait_list[wait_count++] = tStdout; } if (!stderr_eof) { wait_list[wait_count++] = tStderr; } if (!child_dead) { wait_list[wait_count++] = childhand; } wait_return = WaitForMultipleObjects(wait_count, wait_list, FALSE, /* don't wait for all: one ready will do */ child_dead? 1000 :INFINITE); /* after the child dies, subthreads have one second to collect all remaining output */ if (wait_return == WAIT_FAILED) { /* map_windows32_error_to_string(GetLastError());*/ pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; goto done; } ready_hand = wait_list[wait_return - WAIT_OBJECT_0]; if (ready_hand == tStdin) { CloseHandle((HANDLE)pproc->sv_stdin[0]); pproc->sv_stdin[0] = 0; CloseHandle(tStdin); tStdin = 0; stdin_eof = TRUE; } else if (ready_hand == tStdout) { CloseHandle((HANDLE)pproc->sv_stdout[0]); pproc->sv_stdout[0] = 0; CloseHandle(tStdout); tStdout = 0; stdout_eof = TRUE; } else if (ready_hand == tStderr) { CloseHandle((HANDLE)pproc->sv_stderr[0]); pproc->sv_stderr[0] = 0; CloseHandle(tStderr); tStderr = 0; stderr_eof = TRUE; } else if (ready_hand == childhand) { DWORD ierr; GetExitCodeResult = GetExitCodeProcess(childhand, &ierr); if (ierr == CONTROL_C_EXIT) { pproc->signal = SIGINT; } else { pproc->exit_code = ierr; } if (GetExitCodeResult == FALSE) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; goto done; } child_dead = TRUE; } else { /* ?? Got back a handle we didn't query ?? */ pproc->last_err = 0; pproc->lerrno = E_FAIL; goto done; } } done: if (tStdin != 0) CloseHandle(tStdin); if (tStdout != 0) CloseHandle(tStdout); if (tStderr != 0) CloseHandle(tStderr); if (pproc->lerrno) return(-1); else return(0); } #endif /* unused */ /* * Purpose: collects output from child process and returns results * * Description: * * Returns: * * Notes/Dependencies: */ long process_file_io( HANDLE proc) { sub_process *pproc; HANDLE childhand; DWORD wait_return; BOOL GetExitCodeResult; DWORD ierr; if (proc == NULL) pproc = process_wait_for_any_private(1, 0); else pproc = (sub_process *)proc; /* some sort of internal error */ if (!pproc) return -1; childhand = (HANDLE) pproc->pid; /* * This function is poorly named, and could also be used just to wait * for child death if you're doing your own pipe I/O. If that is * the case, close the pipe handles here. */ if (pproc->sv_stdin[0]) { CloseHandle((HANDLE)pproc->sv_stdin[0]); pproc->sv_stdin[0] = 0; } if (pproc->sv_stdout[0]) { CloseHandle((HANDLE)pproc->sv_stdout[0]); pproc->sv_stdout[0] = 0; } if (pproc->sv_stderr[0]) { CloseHandle((HANDLE)pproc->sv_stderr[0]); pproc->sv_stderr[0] = 0; } /* * Wait for the child process to exit */ wait_return = WaitForSingleObject(childhand, INFINITE); if (wait_return != WAIT_OBJECT_0) { /* map_windows32_error_to_string(GetLastError());*/ pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; goto done2; } GetExitCodeResult = GetExitCodeProcess(childhand, &ierr); if (ierr == CONTROL_C_EXIT) { pproc->signal = SIGINT; } else { pproc->exit_code = ierr; } if (GetExitCodeResult == FALSE) { pproc->last_err = GetLastError(); pproc->lerrno = E_SCALL; } done2: if (pproc->lerrno) return(-1); else return(0); } /* * Description: Clean up any leftover handles, etc. It is up to the * caller to manage and free the input, output, and stderr buffers. */ void process_cleanup( HANDLE proc) { sub_process *pproc = (sub_process *)proc; int i; if (pproc->using_pipes) { for (i= 0; i <= 1; i++) { if ((HANDLE)pproc->sv_stdin[i] && (HANDLE)pproc->sv_stdin[i] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stdin[i]); if ((HANDLE)pproc->sv_stdout[i] && (HANDLE)pproc->sv_stdout[i] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stdout[i]); if ((HANDLE)pproc->sv_stderr[i] && (HANDLE)pproc->sv_stderr[i] != INVALID_HANDLE_VALUE) CloseHandle((HANDLE)pproc->sv_stderr[i]); } } if ((HANDLE)pproc->pid) CloseHandle((HANDLE)pproc->pid); free(pproc); } /* * Description: * Create a command line buffer to pass to CreateProcess * * Returns: the buffer or NULL for failure * Shell case: sh_name a:/full/path/to/script argv[1] argv[2] ... * Otherwise: argv[0] argv[1] argv[2] ... * * Notes/Dependencies: * CreateProcess does not take an argv, so this command creates a * command line for the executable. */ static char * make_command_line( char *shell_name, char *full_exec_path, char **argv) { int argc = 0; char** argvi; int* enclose_in_quotes = NULL; int* enclose_in_quotes_i; size_t bytes_required = 0; char* command_line; char* command_line_i; int have_sh = 0; /* HAVE_CYGWIN_SHELL */ int cygwin_mode = 0; /* HAVE_CYGWIN_SHELL */ #ifdef HAVE_CYGWIN_SHELL cygwin_mode = 1; #endif if (shell_name && full_exec_path) { have_sh = cygwin_mode && strstr(full_exec_path, "sh.exe"); bytes_required = strlen(shell_name) + 1 + strlen(full_exec_path); /* * Skip argv[0] if any, when shell_name is given. * The special case of "-c" in full_exec_path means * argv[0] is not the shell name, but the command string * to pass to the shell. */ if (*argv && strcmp(full_exec_path, "-c")) argv++; /* * Add one for the intervening space. */ if (*argv) bytes_required++; } argvi = argv; while (*(argvi++)) argc++; if (argc) { enclose_in_quotes = (int*) calloc(1, argc * sizeof(int)); if (!enclose_in_quotes) { return NULL; } } /* We have to make one pass through each argv[i] to see if we need * to enclose it in ", so we might as well figure out how much * memory we'll need on the same pass. */ argvi = argv; enclose_in_quotes_i = enclose_in_quotes; while(*argvi) { char* p = *argvi; unsigned int backslash_count = 0; /* * We have to enclose empty arguments in ". */ if (!(*p)) *enclose_in_quotes_i = 1; while(*p) { switch (*p) { case '\"': /* * We have to insert a backslash for each " * and each \ that precedes the ". */ bytes_required += (backslash_count + 1); backslash_count = 0; break; #if !defined(HAVE_MKS_SHELL) && !defined(HAVE_CYGWIN_SHELL) case '\\': backslash_count++; break; #endif /* * At one time we set *enclose_in_quotes_i for '*' or '?' to suppress * wildcard expansion in programs linked with MSVC's SETARGV.OBJ so * that argv in always equals argv out. This was removed. Say you have * such a program named glob.exe. You enter * glob '*' * at the sh command prompt. Obviously the intent is to make glob do the * wildcarding instead of sh. If we set *enclose_in_quotes_i for '*' or '?', * then the command line that glob would see would be * glob "*" * and the _setargv in SETARGV.OBJ would _not_ expand the *. */ case ' ': case '\t': *enclose_in_quotes_i = 1; /* fall through */ default: backslash_count = 0; break; } /* * Add one for each character in argv[i]. */ bytes_required++; p++; } if (*enclose_in_quotes_i) { /* * Add one for each enclosing ", * and one for each \ that precedes the * closing ". */ bytes_required += (backslash_count + 2); } /* * Add one for the intervening space. */ if (*(++argvi)) bytes_required++; enclose_in_quotes_i++; } /* * Add one for the terminating NULL. */ bytes_required++; command_line = (char*) malloc(bytes_required); if (!command_line) { free(enclose_in_quotes); return NULL; } command_line_i = command_line; if (shell_name && full_exec_path) { while(*shell_name) { *(command_line_i++) = *(shell_name++); } *(command_line_i++) = ' '; while(*full_exec_path) { *(command_line_i++) = *(full_exec_path++); } if (*argv) { *(command_line_i++) = ' '; } } argvi = argv; enclose_in_quotes_i = enclose_in_quotes; while(*argvi) { char* p = *argvi; unsigned int backslash_count = 0; if (*enclose_in_quotes_i) { *(command_line_i++) = '\"'; } while(*p) { if (*p == '\"') { if (cygwin_mode && have_sh) { /* HAVE_CYGWIN_SHELL */ /* instead of a \", cygwin likes "" */ *(command_line_i++) = '\"'; } else { /* * We have to insert a backslash for the " * and each \ that precedes the ". */ backslash_count++; while(backslash_count) { *(command_line_i++) = '\\'; backslash_count--; }; } #if !defined(HAVE_MKS_SHELL) && !defined(HAVE_CYGWIN_SHELL) } else if (*p == '\\') { backslash_count++; } else { backslash_count = 0; #endif } /* * Copy the character. */ *(command_line_i++) = *(p++); } if (*enclose_in_quotes_i) { #if !defined(HAVE_MKS_SHELL) && !defined(HAVE_CYGWIN_SHELL) /* * Add one \ for each \ that precedes the * closing ". */ while(backslash_count--) { *(command_line_i++) = '\\'; }; #endif *(command_line_i++) = '\"'; } /* * Append an intervening space. */ if (*(++argvi)) { *(command_line_i++) = ' '; } enclose_in_quotes_i++; } /* * Append the terminating NULL. */ *command_line_i = '\0'; free(enclose_in_quotes); return command_line; } /* * Description: Given an argv and optional envp, launch the process * using the default stdin, stdout, and stderr handles. * Also, register process so that process_wait_for_any_private() * can be used via process_file_io(NULL) or * process_wait_for_any(). * * Returns: * * Notes/Dependencies: */ HANDLE process_easy( char **argv, char **envp, int outfd, int errfd) { HANDLE hIn = INVALID_HANDLE_VALUE; HANDLE hOut = INVALID_HANDLE_VALUE; HANDLE hErr = INVALID_HANDLE_VALUE; HANDLE hProcess, tmpIn, tmpOut, tmpErr; DWORD e; if (process_table_full()) { DB (DB_JOBS, ("process_easy: All process slots used up\n")); return INVALID_HANDLE_VALUE; } /* Standard handles returned by GetStdHandle can be NULL or INVALID_HANDLE_VALUE if the parent process closed them. If that happens, we open the null device and pass its handle to CreateProcess as the corresponding handle to inherit. */ tmpIn = GetStdHandle(STD_INPUT_HANDLE); if (DuplicateHandle(GetCurrentProcess(), tmpIn, GetCurrentProcess(), &hIn, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { if ((e = GetLastError()) == ERROR_INVALID_HANDLE) { tmpIn = CreateFile("NUL", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (tmpIn != INVALID_HANDLE_VALUE && DuplicateHandle(GetCurrentProcess(), tmpIn, GetCurrentProcess(), &hIn, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) CloseHandle(tmpIn); } if (hIn == INVALID_HANDLE_VALUE) { fprintf(stderr, "process_easy: DuplicateHandle(In) failed (e=%lu)\n", e); return INVALID_HANDLE_VALUE; } } if (outfd >= 0) tmpOut = get_handle_for_fd (outfd); else tmpOut = GetStdHandle (STD_OUTPUT_HANDLE); if (DuplicateHandle(GetCurrentProcess(), tmpOut, GetCurrentProcess(), &hOut, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { if ((e = GetLastError()) == ERROR_INVALID_HANDLE) { tmpOut = CreateFile("NUL", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (tmpOut != INVALID_HANDLE_VALUE && DuplicateHandle(GetCurrentProcess(), tmpOut, GetCurrentProcess(), &hOut, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) CloseHandle(tmpOut); } if (hOut == INVALID_HANDLE_VALUE) { fprintf(stderr, "process_easy: DuplicateHandle(Out) failed (e=%lu)\n", e); return INVALID_HANDLE_VALUE; } } if (errfd >= 0) tmpErr = get_handle_for_fd (errfd); else tmpErr = GetStdHandle(STD_ERROR_HANDLE); if (DuplicateHandle(GetCurrentProcess(), tmpErr, GetCurrentProcess(), &hErr, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { if ((e = GetLastError()) == ERROR_INVALID_HANDLE) { tmpErr = CreateFile("NUL", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (tmpErr != INVALID_HANDLE_VALUE && DuplicateHandle(GetCurrentProcess(), tmpErr, GetCurrentProcess(), &hErr, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) CloseHandle(tmpErr); } if (hErr == INVALID_HANDLE_VALUE) { fprintf(stderr, "process_easy: DuplicateHandle(Err) failed (e=%lu)\n", e); return INVALID_HANDLE_VALUE; } } hProcess = process_init_fd(hIn, hOut, hErr); if (process_begin(hProcess, argv, envp, argv[0], NULL)) { fake_exits_pending++; /* process_begin() failed: make a note of that. */ if (!((sub_process*) hProcess)->last_err) ((sub_process*) hProcess)->last_err = -1; ((sub_process*) hProcess)->exit_code = process_last_err(hProcess); /* close up unused handles */ if (hIn != INVALID_HANDLE_VALUE) CloseHandle(hIn); if (hOut != INVALID_HANDLE_VALUE) CloseHandle(hOut); if (hErr != INVALID_HANDLE_VALUE) CloseHandle(hErr); } process_register(hProcess); return hProcess; } ================================================ FILE: src/w32/subproc/w32err.c ================================================ /* Error handling for Windows Copyright (C) 1996-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "makeint.h" #include "w32err.h" /* * Description: the windows32 version of perror() * * Returns: a pointer to a static error * * Notes/Dependencies: I got this from * comp.os.ms-windows.programmer.win32 */ const char * map_windows32_error_to_string (DWORD ercode) { /* * We used to have an MSVC-specific '__declspec (thread)' qualifier * here, with the following comment: * * __declspec (thread) necessary if you will use multiple threads on MSVC * * However, Make was never multithreaded on Windows (except when * Ctrl-C is hit, in which case the main thread is stopped * immediately, so it doesn't matter in this context). The functions * on sub_proc.c that started and stopped additional threads were * never used, and are now #ifdef'ed away. Until we need more than * one thread, we have no problems with the following buffer being * static. (If and when we do need it to be in thread-local storage, * the corresponding GCC qualifier is '__thread'.) */ static char szMessageBuffer[128]; DWORD ret; /* Fill message buffer with a default message in * case FormatMessage fails */ wsprintf (szMessageBuffer, "Error %ld", ercode); /* * Special code for winsock error handling. */ if (ercode > WSABASEERR) { OS (fatal, NILF, "%s", szMessageBuffer); } /* * Default system message handling */ ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, ercode, LANG_NEUTRAL, szMessageBuffer, sizeof(szMessageBuffer), NULL); if (ret) { char *cp; for (cp = szMessageBuffer + ret - 1; cp >= szMessageBuffer; --cp) { if (*cp != '\r' && *cp != '\n') break; *cp = '\0'; } } return szMessageBuffer; } ================================================ FILE: src/w32/utf8.manifest ================================================ UTF-8 ================================================ FILE: src/w32/utf8.rc ================================================ #include CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "utf8.manifest" ================================================ FILE: src/w32/w32os.c ================================================ /* Windows32-based operating system interface for GNU Make. Copyright (C) 2016-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include #include #include #include #include #if _WIN32_WINNT > 0x0601 #include #endif #include "pathstuff.h" #include "sub_proc.h" #include "w32err.h" #include "os.h" #include "debug.h" unsigned int check_io_state () { static unsigned int state = IO_UNKNOWN; HANDLE outfd, errfd; /* We only need to compute this once per process. */ if (state != IO_UNKNOWN) return state; /* Could have used GetHandleInformation, but that isn't supported on Windows 9X. */ outfd = get_handle_for_fd (fileno (stdout)); errfd = get_handle_for_fd (fileno (stderr)); if (get_handle_for_fd (fileno (stdin)) != INVALID_HANDLE_VALUE) state |= IO_STDIN_OK; if (outfd != INVALID_HANDLE_VALUE) state |= IO_STDOUT_OK; if (errfd != INVALID_HANDLE_VALUE) state |= IO_STDERR_OK; if (ALL_SET (state, IO_STDOUT_OK|IO_STDERR_OK)) { unsigned int combined = 0; if (outfd == errfd) combined = IO_COMBINED_OUTERR; else { DWORD outtype = GetFileType (outfd), errtype = GetFileType (errfd); if (outtype == errtype && outtype != FILE_TYPE_UNKNOWN && errtype != FILE_TYPE_UNKNOWN) { if (outtype == FILE_TYPE_CHAR) { /* For character devices, check if they both refer to a console. This loses if both handles refer to the null device (FIXME!), but in that case we don't care in the context of Make. */ DWORD outmode, errmode; /* Each process on Windows can have at most 1 console, so if both handles are for the console device, they are the same. We also compare the console mode to distinguish between stdin and stdout/stderr. */ if (GetConsoleMode (outfd, &outmode) && GetConsoleMode (errfd, &errmode) && outmode == errmode) combined = IO_COMBINED_OUTERR; } else { /* For disk files and pipes, compare their unique attributes. */ BY_HANDLE_FILE_INFORMATION outfi, errfi; /* Pipes get zero in the volume serial number, but do appear to have meaningful information in file index attributes. We test file attributes as well, for a good measure. */ if (GetFileInformationByHandle (outfd, &outfi) && GetFileInformationByHandle (errfd, &errfi) && outfi.dwVolumeSerialNumber == errfi.dwVolumeSerialNumber && outfi.nFileIndexLow == errfi.nFileIndexLow && outfi.nFileIndexHigh == errfi.nFileIndexHigh && outfi.dwFileAttributes == errfi.dwFileAttributes) combined = IO_COMBINED_OUTERR; } } } state |= combined; } return state; } /* A replacement for tmpfile, since the MSVCRT implementation creates the file in the root directory of the current drive, which might not be writable by our user, and also it returns a FILE* and we want a file descriptor. Mostly borrowed from create_batch_file, see job.c. */ int os_anontmp () { char temp_path[MAX_PATH+1]; unsigned path_size = GetTempPath (sizeof (temp_path), temp_path); int using_cwd = 0; /* These variables are static so we won't try to reuse a name that was generated a little while ago, because that file might not be on disk yet, since we use FILE_ATTRIBUTE_TEMPORARY below, which tells the OS it doesn't need to flush the cache to disk. If the file is not yet on disk, we might think the name is available, while it really isn't. This happens in parallel builds. */ static unsigned uniq = 0; static int second_loop = 0; const char base[] = "GmTMPF"; const unsigned sizemax = sizeof (base) - 1 + 4 + 10 + 10; unsigned pid = GetCurrentProcessId (); if (path_size == 0) { path_size = GetCurrentDirectory (sizeof (temp_path), temp_path); using_cwd = 1; } ++uniq; if (uniq >= 0x10000 && !second_loop) { /* If we already had 64K batch files in this process, make a second loop through the numbers, looking for free slots, i.e. files that were deleted in the meantime. */ second_loop = 1; uniq = 1; } while (path_size > 0 && path_size + sizemax < sizeof (temp_path) && (uniq < 0x10000 || !second_loop)) { HANDLE h; sprintf (temp_path + path_size, "%s%s%u-%x.tmp", temp_path[path_size - 1] == '\\' ? "" : "\\", base, pid, uniq); h = CreateFile (temp_path, /* file name */ GENERIC_READ | GENERIC_WRITE | DELETE, /* desired access */ FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ NULL, /* default security attributes */ CREATE_NEW, /* creation disposition */ FILE_ATTRIBUTE_NORMAL | /* flags and attributes */ FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); /* no template file */ if (h != INVALID_HANDLE_VALUE) return _open_osfhandle ((intptr_t)h, 0); { const DWORD er = GetLastError (); if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS) { ++uniq; if (uniq == 0x10000 && !second_loop) { second_loop = 1; uniq = 1; } } /* The temporary path is not guaranteed to exist, or might not be writable by user. Use the current directory as fallback. */ else if (!using_cwd) { path_size = GetCurrentDirectory (sizeof (temp_path), temp_path); using_cwd = 1; } else { errno = EACCES; return -1; } } } if (uniq >= 0x10000) errno = EEXIST; return -1; } #if defined(MAKE_JOBSERVER) /* This section provides OS-specific functions to support the jobserver. */ static char jobserver_semaphore_name[MAX_PATH + 1]; static HANDLE jobserver_semaphore = NULL; unsigned int jobserver_setup (int slots, const char *style) { /* sub_proc.c is limited in the number of objects it can wait for. */ if (style && strcmp (style, "sem") != 0) OS (fatal, NILF, _("unknown jobserver auth style '%s'"), style); if (slots > process_table_usable_size()) { slots = process_table_usable_size(); DB (DB_JOBS, (_("jobserver slots limited to %d\n"), slots)); } sprintf (jobserver_semaphore_name, "gmake_semaphore_%d", _getpid ()); jobserver_semaphore = CreateSemaphore ( NULL, /* Use default security descriptor */ slots, /* Initial count */ slots, /* Maximum count */ jobserver_semaphore_name); /* Semaphore name */ if (jobserver_semaphore == NULL) { DWORD err = GetLastError (); const char *estr = map_windows32_error_to_string (err); ONS (fatal, NILF, _("creating jobserver semaphore: (Error %lu: %s)"), err, estr); } return 1; } unsigned int jobserver_parse_auth (const char *auth) { jobserver_semaphore = OpenSemaphore ( SEMAPHORE_ALL_ACCESS, /* Semaphore access setting */ FALSE, /* Child processes DON'T inherit */ auth); /* Semaphore name */ if (jobserver_semaphore == NULL) { DWORD err = GetLastError (); const char *estr = map_windows32_error_to_string (err); error (NILF, strlen (auth) + INTSTR_LENGTH + strlen (estr), _("unable to open jobserver semaphore '%s': (Error %lu: %s)"), auth, err, estr); return 0; } DB (DB_JOBS, (_("Jobserver client (semaphore %s)\n"), auth)); return 1; } char * jobserver_get_auth () { return xstrdup (jobserver_semaphore_name); } const char * jobserver_get_invalid_auth () { /* Because we're using a semaphore we don't need to invalidate. */ return NULL; } unsigned int jobserver_enabled () { return jobserver_semaphore != NULL; } /* Close jobserver semaphore */ void jobserver_clear () { if (jobserver_semaphore != NULL) { CloseHandle (jobserver_semaphore); jobserver_semaphore = NULL; } } void jobserver_release (int is_fatal) { if (! ReleaseSemaphore ( jobserver_semaphore, /* handle to semaphore */ 1, /* increase count by one */ NULL)) /* not interested in previous count */ { if (is_fatal) { DWORD err = GetLastError (); const char *estr = map_windows32_error_to_string (err); ONS (fatal, NILF, _("release jobserver semaphore: (Error %lu: %s)"), err, estr); } perror_with_name ("release_jobserver_semaphore", ""); } } unsigned int jobserver_acquire_all () { unsigned int tokens = 0; while (1) { DWORD dwEvent = WaitForSingleObject ( jobserver_semaphore, /* Handle to semaphore */ 0); /* DON'T wait on semaphore */ if (dwEvent != WAIT_OBJECT_0) return tokens; ++tokens; } } void jobserver_signal () { } void jobserver_pre_child (int recursive UNUSED) { } void jobserver_post_child (int recursive UNUSED) { } void jobserver_pre_acquire () { } /* Returns 1 if we got a token, or 0 if a child has completed. The Windows implementation doesn't support load detection. */ unsigned int jobserver_acquire (int timeout UNUSED) { HANDLE *handles; DWORD dwHandleCount; DWORD dwEvent; handles = xmalloc(process_table_actual_size() * sizeof(HANDLE)); /* Add jobserver semaphore to first slot. */ handles[0] = jobserver_semaphore; /* Build array of handles to wait for. */ dwHandleCount = 1 + process_set_handles (&handles[1]); dwEvent = process_wait_for_multiple_objects ( dwHandleCount, /* number of objects in array */ handles, /* array of objects */ FALSE, /* wait for any object */ INFINITE); /* wait until object is signalled */ free(handles); if (dwEvent == WAIT_FAILED) { DWORD err = GetLastError (); const char *estr = map_windows32_error_to_string (err); ONS (fatal, NILF, _("semaphore or child process wait: (Error %lu: %s)"), err, estr); } /* WAIT_OBJECT_0 indicates that the semaphore was signalled. */ return dwEvent == WAIT_OBJECT_0; } #endif /* MAKE_JOBSERVER */ #if !defined(NO_OUTPUT_SYNC) #define MUTEX_PREFIX "fnm:" /* Since we're using this with CreateMutex, NULL is invalid. */ static HANDLE osync_handle = NULL; unsigned int osync_enabled () { return osync_handle != NULL; } void osync_setup () { SECURITY_ATTRIBUTES secattr; /* We are the top-level make, and we want the handle to be inherited by our child processes. */ secattr.nLength = sizeof (secattr); secattr.lpSecurityDescriptor = NULL; /* use default security descriptor */ secattr.bInheritHandle = TRUE; osync_handle = CreateMutex (&secattr, FALSE, NULL); if (!osync_handle) { DWORD err = GetLastError (); fprintf (stderr, "CreateMutex: error %lu\n", err); errno = ENOLCK; } } char * osync_get_mutex () { char *mutex = NULL; if (osync_enabled ()) { /* Prepare the mutex handle string for our children. 2 hex digits per byte + 2 characters for "0x" + null. */ mutex = xmalloc ((2 * sizeof (osync_handle)) + 2 + 1); sprintf (mutex, "0x%Ix", (unsigned long long)(DWORD_PTR)osync_handle); } return mutex; } unsigned int osync_parse_mutex (const char *mutex) { char *endp; unsigned long long i; errno = 0; i = strtoull (mutex, &endp, 16); if (errno != 0) OSS (fatal, NILF, _("cannot parse output sync mutex %s: %s"), mutex, strerror (errno)); if (endp[0] != '\0') OS (fatal, NILF, _("invalid output sync mutex: %s"), mutex); osync_handle = (HANDLE) (DWORD_PTR) i; return 1; } void osync_clear () { if (osync_handle) { CloseHandle (osync_handle); osync_handle = NULL; } } unsigned int osync_acquire () { if (osync_enabled()) { DWORD result = WaitForSingleObject (osync_handle, INFINITE); if (result == WAIT_FAILED || result == WAIT_TIMEOUT) return 0; } return 1; } void osync_release () { if (osync_enabled()) /* FIXME: Perhaps we should call ReleaseMutex repatedly until it errors out, to make sure the mutext is released even if we somehow managed to to take ownership multiple times? */ ReleaseMutex (osync_handle); } #endif /* NO_OUTPUT_SYNC */ void fd_inherit(int fd) { HANDLE fh = get_handle_for_fd (fd); if (fh && fh != INVALID_HANDLE_VALUE) SetHandleInformation (fh, HANDLE_FLAG_INHERIT, 1); } void fd_noinherit(int fd) { HANDLE fh = get_handle_for_fd (fd); if (fh && fh != INVALID_HANDLE_VALUE) SetHandleInformation (fh, HANDLE_FLAG_INHERIT, 0); } int fd_set_append (int fd UNUSED) { return -1; } void fd_reset_append (int fd UNUSED, int flags UNUSED) {} HANDLE get_handle_for_fd (int fd) { /* This funcion call is needed to get around the "bad-function-cast"-warning emitted by GCC when casting and assigning in the same statement. */ intptr_t fh = _get_osfhandle (fd); return (HANDLE) fh; } ================================================ FILE: src/warning.c ================================================ /* Control warning output in GNU Make. Copyright (C) 2023-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "makeint.h" #include "warning.h" #include "variable.h" /* Current action for each warning. */ enum warning_action warnings[wt_max]; /* The default behavior of warnings. */ static struct warning_data warn_default; /* Warning settings from the .WARNING variable. */ static struct warning_data warn_variable; /* Warning settings from the command line. */ static struct warning_data warn_flag; static const char *w_action_map[w_error+1] = {NULL, "ignore", "warn", "error"}; static const char *w_name_map[wt_max] = { "circular-dep", "invalid-ref", "invalid-var", "undefined-var" }; #define encode_warn_action(_b,_s) \ variable_buffer_output (_b, w_action_map[_s], strlen (w_action_map[_s])) #define encode_warn_name(_b,_t) \ variable_buffer_output (_b, w_name_map[_t], strlen (w_name_map[_t])) static void set_warnings () { /* Called whenever any warnings could change; resets the current actions. */ for (enum warning_type wt = 0; wt < wt_max; ++wt) warnings[wt] = warn_flag.actions[wt] != w_unset ? warn_flag.actions[wt] : warn_flag.global != w_unset ? warn_flag.global : warn_variable.actions[wt] != w_unset ? warn_variable.actions[wt] : warn_variable.global != w_unset ? warn_variable.global : warn_default.actions[wt]; } void warn_init () { memset (&warn_default, '\0', sizeof (warn_default)); memset (&warn_variable, '\0', sizeof (warn_variable)); memset (&warn_flag, '\0', sizeof (warn_flag)); /* All warnings must have a default. */ warn_default.global = w_warn; warn_default.actions[wt_circular_dep] = w_warn; warn_default.actions[wt_invalid_ref] = w_warn; warn_default.actions[wt_invalid_var] = w_warn; warn_default.actions[wt_undefined_var] = w_ignore; set_warnings (); } static void init_data (struct warning_data *data) { data->global = w_unset; for (enum warning_type wt = 0; wt < wt_max; ++wt) data->actions[wt] = w_unset; } static enum warning_action decode_warn_action (const char *action, size_t length) { for (enum warning_action st = w_ignore; st <= w_error; ++st) { size_t len = strlen (w_action_map[st]); if (length == len && strncasecmp (action, w_action_map[st], length) == 0) return st; } return w_unset; } static enum warning_type decode_warn_name (const char *name, size_t length) { for (enum warning_type wt = 0; wt < wt_max; ++wt) { size_t len = strlen (w_name_map[wt]); if (length == len && strncasecmp (name, w_name_map[wt], length) == 0) return wt; } return wt_max; } void decode_warn_actions (const char *value, const floc *flocp) { struct warning_data *data = &warn_flag; NEXT_TOKEN (value); if (flocp) { data = &warn_variable; /* When a variable is set to empty, reset everything. */ if (*value == '\0') init_data (data); } while (*value != '\0') { enum warning_action action; /* Find the end of the next warning definition. */ const char *ep = value; while (! STOP_SET (*ep, MAP_BLANK|MAP_COMMA|MAP_NUL)) ++ep; /* If the value is just an action set it globally. */ action = decode_warn_action (value, ep - value); if (action != w_unset) data->global = action; else { enum warning_type type; const char *cp = memchr (value, ':', ep - value); int wl, al; if (!cp) cp = ep; wl = (int)(cp - value); type = decode_warn_name (value, wl); if (cp == ep) action = w_warn; else { /* There's a warning action: decode it. */ ++cp; al = (int)(ep - cp); action = decode_warn_action (cp, al); } if (type == wt_max) { if (!flocp) ONS (fatal, NILF, _("unknown warning '%.*s'"), wl, value); ONS (error, flocp, _("unknown warning '%.*s': ignored"), wl, value); } else if (action == w_unset) { if (!flocp) ONS (fatal, NILF, _("unknown warning action '%.*s'"), al, cp); ONS (error, flocp, _("unknown warning action '%.*s': ignored"), al, cp); } else data->actions[type] = action; } value = ep; while (STOP_SET (*value, MAP_BLANK|MAP_COMMA)) ++value; } set_warnings (); } char * encode_warn_flag (char *fp) { enum warning_type wt; char sp = '='; /* See if any warning options are set. */ for (wt = 0; wt < wt_max; ++wt) if (warn_flag.actions[wt] != w_unset) break; if (wt == wt_max && warn_flag.global == w_unset) return fp; /* Something is set so construct a --warn option. */ fp = variable_buffer_output (fp, STRING_SIZE_TUPLE (" --warn")); /* If only a global action set to warn, we're done. */ if (wt == wt_max && warn_flag.global == w_warn) return fp; /* If a global action is set, add it. */ if (warn_flag.global > w_unset) { fp = variable_buffer_output (fp, &sp, 1); sp = ','; fp = encode_warn_action (fp, warn_flag.global); } /* Add any specific actions. */ if (wt != wt_max) for (wt = 0; wt < wt_max; ++wt) { enum warning_action act = warn_flag.actions[wt]; if (act > w_unset) { fp = variable_buffer_output (fp, &sp, 1); sp = ','; fp = encode_warn_name (fp, wt); if (act != w_warn) fp = encode_warn_action (variable_buffer_output (fp, ":", 1), act); } } return fp; } void warn_get_vardata (struct warning_data *data) { memcpy (data, &warn_variable, sizeof (warn_variable)); } void warn_set_vardata (const struct warning_data *data) { memcpy (&warn_variable, data, sizeof (warn_variable)); set_warnings (); } ================================================ FILE: src/warning.h ================================================ /* Control warning output in GNU Make. Copyright (C) 2023-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Types of warnings we can show. These can be rearranged but the first value must be 0. */ enum warning_type { wt_circular_dep = 0, /* A target depends on itself. */ wt_invalid_ref, /* Reference an invalid variable name. */ wt_invalid_var, /* Assign to an invalid variable name. */ wt_undefined_var, /* Reference an undefined variable name. */ wt_max }; /* Action taken for a given warning. Unset must be 0. */ enum warning_action { w_unset = 0, w_ignore, w_warn, w_error }; struct warning_data { enum warning_action global; /* Global setting. */ enum warning_action actions[wt_max]; /* Action for each warning type. */ }; /* Actions taken for each warning. */ extern enum warning_action warnings[wt_max]; /* Get the current action for a given warning. */ #define warn_get(_w) (warnings[_w]) /* Set the current actin for a given warning. Can't use w_unset here. This should only be used for temporary resetting of warnings. */ #define warn_set(_w,_f) do{ warnings[_w] = (_f); }while(0) /* True if we should check for the warning in the first place. */ #define warn_check(_w) (warn_get (_w) > w_ignore) /* Check if the warning is ignored. */ #define warn_ignored(_w) (warn_get (_w) == w_ignore) /* Check if the warning is in "warn" mode. */ #define warn_warned(_w) (warn_get (_w) == w_warn) /* Check if the warning is in "error" mode. */ #define warn_error(_w) (warn_get (_w) == w_error) void warn_init (void); void decode_warn_actions (const char *value, const floc *flocp); char *encode_warn_flag (char *fp); void warn_get_vardata (struct warning_data *data); void warn_set_vardata (const struct warning_data *data); #define warning(_t,_f,_m) \ do{ \ if (warn_check (_t)) \ { \ char *_a = xstrdup (_m); \ if (warn_error (_t)) \ fatal (_f, strlen (_a), "%s", _a); \ error (_f, strlen (_a), _("warning: %s"), _a); \ free (_a); \ } \ }while(0) ================================================ FILE: tests/.gitignore ================================================ .test-result config-flags.pm work ================================================ FILE: tests/ChangeLog.1 ================================================ 2013-10-09 Paul Smith * scripts/features/patspecific_vars: Typo fixes. 2013-10-05 Paul Smith * test_driver.pl (run_all_tests): Rewrite to be more clear. * scripts/features/jobserver: Avoid using $ENV{HOME} as it doesn't exist everywhere. * scripts/features/default_names: End with 1; * scripts/features/loadapi: Use new calling signatures. Verify the NOEXPAND flag works. Test with all valid function name characters. 2013-09-29 Paul Smith * scripts/variables/SHELL: Solaris /bin/sh can't handle options in multiple words; skip that test. * scripts/targets/ONESHELL: Ditto. * scripts/variables/GNUMAKEFLAGS: Verify that GNUMAKEFLAGS is cleared and options are not duplicated. 2013-09-23 Paul Smith * scripts/options/print-directory: Rename dash-w to print-directory to avoid conflicts with dash-W on case-insensitive filesystems. 2013-09-22 Paul Smith * scripts/features/se_implicit: Verify that order-only tokens inside second expansion are parsed correctly. Test for Savannah bug #31155. * run_make_tests.pl (set_more_defaults): If we can't find gnumake.h based on the make program we might be running from a remote build directory. Parse the Makefile for the right path. Fix some test issues on Solaris. * scripts/features/archives: Determine what output ar gives when adding and replacing objects and compare with that. * scripts/features/escape: Solaris /bin/sh doesn't properly handle backslashes inside single quotes, so don't rely on it. * scripts/features/output-sync: false(1) gives different exit codes on different systems; use "exit 1" instead. * scripts/features/parallelism: Increase the timeout for slower systems. 2013-09-21 Paul Smith * scripts/features/archives: Some versions of ar (MacOSX) generate different output when creating archives. Run it and verify the real output. * scripts/features/default_names: MacOSX is, like Windows, case-preserving / case-insensitive. Redo the test to avoid checking for "UNIX". * test_driver.pl (attach_default_output): Don't dup stdout into stderr. Reported by Denis Excoffier * scripts/features/se_explicit: Fix a test that behaves differently with/without archive capability enabled. * scripts/features/output-sync: Don't test output-sync if it's not enabled. We also skip it if parallelism is not enabled, although strictly speaking some of the output-sync tests are valid even without parallelism. * scripts/features/jobserver: Move some tests that require the jobserver from features/parallelism to a separate suite. Only run this if jobserver mode is enabled. * scripts/features/output-sync: Test shell functions writing to stderr in recipes: ensure it's captured via output-sync. Test output generated while reading makefiles and make sure it's captured via output-sync. Make sure that fatal errors dump the output so it's not lost. * scripts/options/dash-w: Add a test for -w flag. 2013-09-15 Paul Smith * scripts/misc/fopen-fail: Check for failure on infinite recursion. * run_make_tests.pl (run_make_test): Allow the answer string to be undef, which means that we shouldn't compare it at all. Only the exit code matters in this case. * test_driver.pl (compare_output): Ditto. Test for Savannah bug #27374. * scripts/features/parallelism: Test broken jobserver on recursion. Test for Savannah bug #39934. * scripts/options/eval: Verify --eval during restart. Test for Savannah bug #39203. 2013-09-14 Paul Smith * scripts/features/output-sync: Verify -Orecurse properly. 2013-09-12 Paul Smith * scripts/features/output-sync: Modify for output sync behavior. * scripts/variables/MAKE_RESTARTS: Ditto. * scripts/variables/MAKEFLAGS: Remove mode for --trace. * scripts/variables/GNUMAKEFLAGS: Ditto. 2013-07-22 Paul Smith * scripts/features/rule_glob: Add tests for wildcards in rules. Test for Savannah bug #39310. 2013-07-09 Paul Smith * scripts/features/se_implicit: Add a test for SE rules depending on other SE rules to be built. 2013-05-26 Paul Smith * scripts/features/archives: Test for Savannah bug #38442. * scripts/misc/bs-nl: Test for Savannah bug #39035. Add a test for Savannah bug #38945. 2013-05-22 Paul Smith * scripts/options/dash-n: Fix results after MAKEFLAGS fixes. * scripts/variables/MAKEFLAGS: Ditto. * scripts/variables/GNUMAKEFLAGS: Ditto. 2013-05-14 Paul Smith * scripts/features/loadapi: Add plugin_is_GPL_compatible symbol. * scripts/features/load: Ditto. 2013-05-13 Paul Smith * scripts/features/output-sync (output_sync_set): Update for new --trace behavior. 2013-05-05 Paul Smith * scripts/features/output-sync (output_sync_set): Remove extraneous enter/leave lines, which are no longer printed. Add tests for syncing command line printing. (output_sync_set): Rename options: "job"->"line"; "make"->"recurse" 2013-05-04 Paul Smith * scripts/features/loadapi: Use the new alloc functions. * scripts/features/output-sync (output_sync_set): New test for ordered recursive output for -Ojob / -Otarget. 2013-05-03 Eli Zaretskii * scripts/features/load: Fix signatures of testload_gmk_setup and explicit_setup, to bring them in line with the documentation. 2013-04-28 Paul Smith * scripts/features/output-sync (output_sync_set): Add tests for the per-job syntax mode. (output_sync_set): Test improved error message location. 2013-04-15 Paul Smith * scripts/features/output-sync (output_sync_set): New arg syntax. 2013-04-14 Paul Smith * scripts/features/output-sync: Rewrite to be more reliable. * test_driver.pl (_run_command): Don't set SIGALRM until after we start the child. Print errors to the top-level output, which will be stderr. (attach_default_output): Use a list of file handles as the stack. (detach_default_output): Ditto. * scripts/features/output-sync: Add a test for output-sync. 2013-02-25 Paul Smith * run_make_tests.pl (valid_option): Support the -srcdir flag. (set_more_defaults): Set up $srcdir if it's not set yet. * scripts/functions/guile: Verify gmk-eval doesn't expand twice. * scripts/features/load: Rework to test just the load capability. * scripts/features/loadapi: New set of tests for the load API. 2013-01-19 Paul Smith * scripts/features/load: Test loaded files with and without "./" prefix. Add tests for automatically rebuilding loaded files if they are out of date or non-existent. 2013-01-13 Paul Smith * scripts/features/archives: Add a check targets that have parens, but are not archives. See Savannah bug #37878. * scripts/options/dash-n: Verify -n is preserved after recursive / re-exec. See Savannah bug #38051. 2013-01-12 Paul Smith * scripts/features/parallelism: Change rule so it doesn't depend on invocation order, etc. 2012-10-29 Paul Smith * scripts/features/load: New test suite for the "load" directive. 2012-09-09 Paul Smith * scripts/functions/file: Get errors in the C locale, not the current locale. Fixes Savannah bug #35764. * scripts/features/escape: Check that backslashes before non-special characters are not removed. * scripts/features/utf8: New test for UTF-8 support. See Savannah bug #36529. * scripts/targets/POSIX: Add tests for default macro values as specified by IEEE Std 1003.1-2008. See Savannah bug #37069. 2012-03-04 Paul Smith * scripts/features/se_explicit: Test $(x:%=%) format in secondary expansion prerequisite lists. See Savannah bug #16545. * scripts/features/escape: Test escaped ":" in prerequisite lists. See Savannah bug #12126. * scripts/variables/private: Test appending private variables in pattern-specific target rules. See Savannah bug #35468. 2012-03-03 Paul Smith * scripts/variables/SHELL: Ensure .SHELLFLAGS works with options separated by whitespace. * scripts/targets/ONESHELL: Try .ONESHELL in combination with whitespace-separated options in .SHELLFLAGS. See Savannah bug #35397. * scripts/functions/filter-out: Add filter tests and test escape operations. See Savannah bug #35410. * guile.supp: Suppress valgrind errors from Guile * run_make_tests.pl: Use the Guile suppression file. * scripts/misc/bs-nl: Check for POSIX and non-POSIX backslash/newline handling. Addresses Savannah bug #16670. 2012-01-29 Paul Smith * scripts/variables/flavors: Add tests for ::= * scripts/variables/define: Ditto * scripts/functions/file: Test the new $(file ...) function. 2012-01-12 Paul Smith * scripts/functions/guile: New regression tests for Guile support. 2011-12-10 Paul Smith * scripts/targets/SECONDARY: Add prereq statements to ensure rules are printed in the right order for test #9 2011-11-14 Paul Smith * scripts/features/double_colon: Check double-colon with escaped filenames. See Savannah bug #33399. 2011-09-18 Paul Smith * scripts/features/parallelism: On re-exec make sure we preserve the value of MAKEFLAGS when necessary. See Savannah bug #33873. * scripts/features/vpath3: Verify handling of -lfoo libraries found via vpath vs. the standard directory search. See Savannah bug #32511. 2011-09-12 Paul Smith * scripts/functions/call: Verify that using export in a $(call ...) context creates a global variable. See Savannah bug #32498. 2011-09-02 Paul Smith * scripts/options/dash-n: Verify that in "-n -t", the -n takes priority. Patch from Michael Witten . 2011-08-29 Paul Smith * scripts/features/varnesting: Test resetting of variables while expanding them. See Savannah patch #7534 2011-06-12 Paul Smith * scripts/features/archives: Check archives with whitespace at the beginning, end, and extra in the middle. Another test for Savannah bug #30612. 2011-05-07 Paul Smith * scripts/variables/private: Ensure we skip private variables when appending. Test for Savannah bug #32872. * scripts/functions/wildcard: Verify wildcard used to test for file existence/non-existence. 2011-05-02 Paul Smith * scripts/functions/sort: Add a test for Savannah bug #33125. 2011-04-17 David A. Wheeler * scripts/features/shell_assignment: Regression for "!=" feature 2010-11-06 Paul Smith * scripts/features/targetvars: Fix known-good output for BS/NL changes. * scripts/functions/call: Ditto. * scripts/variables/special: Ditto. * scripts/misc/bs-nl: New test suite for backslash/newline testing. 2010-08-29 Paul Smith * scripts/features/errors: Add new error message to output text. * scripts/variables/SHELL: Ditto. * scripts/targets/POSIX: Ditto. * scripts/options/dash-k: Ditto. * scripts/features/vpathplus: Ditto. * scripts/features/patternrules: Ditto. * scripts/features/parallelism: Ditto. 2010-08-13 Paul Smith * scripts/features/archives: New regression tests for archive support. Test for fix to Savannah bug #30612. * run_make_tests.pl (set_more_defaults): Set a %FEATURES hash to the features available in $(.FEATURES). 2010-08-10 Paul Smith * scripts/features/reinvoke: Ensure command line variable settings are preserved across make re-exec. Tests Savannah bug #30723. 2010-07-28 Paul Smith * scripts/targets/POSIX: Compatibility issues with Solaris (and Tru64?); "false" returns different exit codes, and set -x shows output with extra whitespace. Run the commands by hand first to find out what the real shell would do, then compare what make does. * scripts/variables/SHELL: Ditto. 2010-07-12 Paul Smith * test_driver.pl: Add a new $perl_name containing the path to Perl. * run_make_tests.pl (run_make_test): Replace the special string #PERL# in a makefile etc. with the path the Perl executable so makefiles can use it. * scripts/targets/ONESHELL: Add a new set of regression tests for the .ONESHELL feature. 2010-07-06 Paul Smith * scripts/variables/SHELL: Test the new .SHELLFLAGS variable. * scripts/targets/POSIX: New file. Test the .POSIX special target. Verify that enabling .POSIX changes the shell flags to set -e. 2010-07-01 Paul Smith * scripts/features/recursion: Add a space to separate command-line args. Fixes Savannah bug #29968. 2009-11-12 Boris Kolpackov * scripts/features/vpath3: Test for the new library search behavior. 2009-10-06 Boris Kolpackov * scripts/features/se_explicit: Enable the test for now fixed Savannah bug 25780. 2009-10-06 Boris Kolpackov * scripts/variables/undefine: Tests for the new undefine feature. 2009-10-03 Paul Smith * scripts/features/parallelism: Test for open Savannah bug #26846. * scripts/variables/MAKE: Rewrite for new run_make_test() format. * scripts/variables/MAKEFLAGS: Created. Add test for Savannah bug #2216 (still open). * scripts/features/include: Test for Savannah bug #102 (still open). 2009-09-30 Boris Kolpackov * scripts/features/include: Add diagnostics issuing tests for cases where targets have been updated and failed with the dontcare flag. Savannah bugs #15110, #25493, #12686, #17740. 2009-09-28 Paul Smith * scripts/functions/shell: Add regression test for Savannah bug #20513 (still open). * scripts/features/se_explicit: Add regression tests for Savannah bug #25780 (still open). * run_make_tests.pl (valid_option): Add a new flag, -all([-_]?tests)? that runs tests we know will fail. This allows us to add regression tests to the test suite for bugs that haven't been fixed yet. 2009-09-28 Boris Kolpackov * scripts/features/patspecific_vars: Add a test for the shortest stem first order. * scripts/features/patternrules: Add a test for the shortest stem first order. 2009-09-24 Paul Smith * scripts/features/se_implicit: Add a test for order-only secondary expansion prerequisites. 2009-09-23 Paul Smith * scripts/features/patternrules: Test that we can remove pattern rules, both single and multiple prerequisites. Savannah bug #18622. * scripts/features/echoing: Rework for run_make_test(). 2009-06-14 Paul Smith * scripts/features/vpath: Verify we don't get bogus circular dependency warnings if we choose a different file via vpath during update. Savannah bug #13529. 2009-06-13 Paul Smith * scripts/variables/MAKEFILES: Verify that MAKEFILES included files (and files included by them) don't set the default goal. Savannah bug #13401. * scripts/functions/wildcard: Test that wildcards with non-existent glob matchers return empty. 2009-06-09 Paul Smith * scripts/options/dash-B: Test the $? works correctly with -B. Savannah bug #17825. * scripts/features/patternrules: Test that dependencies of "also_make" targets are created properly. Savannah bug #19108. * test_driver.pl (compare_output): Create a "run" file for failed tests containing the command that was run. (get_runfile): New function. * run_make_tests.pl (valid_option): Enhanced support for valgrind: allow memcheck and massif tools. * scripts/features/patternrules: Have to comment out a line in the first test due to backing out a change that broke the implicit rule search algorithm. Savannah bug #17752. * scripts/misc/general4: Remove a test that is redundant with patternrules. * scripts/features/parallelism: Add a test for re-exec with jobserver master override. Savannah bug #18124. 2009-06-08 Paul Smith * scripts/features/targetvars: Add a test for continued target vars after a semicolon. Savannah bug #17521. 2009-06-07 Paul Smith * scripts/features/se_explicit: Make sure we catch defining prereqs during snap_deps(). Savannah bug #24622. * scripts/variables/automatic: Check prereq ordering when the target with the recipe has no prereqs. Savannah bug #21198. * scripts/variables/LIBPATTERNS: Add a new set of test for $(.LIBPATTERNS) (previously untested!) 2009-06-04 Paul Smith * scripts/variables/SHELL: The export target-specific SHELL test has an incorrect known-good-value. * scripts/misc/general4: Check for whitespace (ffeed, vtab, etc.) * scripts/features/se_explicit: Add tests for Savannah bug #24588. 2009-05-31 Paul Smith * scripts/variables/DEFAULT_GOAL: Add tests for Savannah bug #25697. * scripts/features/targetvars: Add tests of overrides for Savannah bug #26207. * scripts/features/patspecific_vars: Ditto. * scripts/features/patternrules: Add a test for Savannah bug #26593. 2009-05-30 Paul Smith * scripts/variables/flavors: Update with new variable flavor tests. * scripts/variables/define: Create a new set of tests for define/endef and move those aspects of the flavors suite here. 2009-05-25 Paul Smith * scripts/features/targetvars: Ditto. * scripts/features/export: Test new variable parsing abilities. 2009-02-23 Ramon Garcia * scripts/variables/private: Create a new suite of tests for 'private'. 2007-11-04 Paul Smith * scripts/functions/eval: Update error message for command -> recipe. * test_driver.pl (compare_output): Allow the answer to be a regex, if surrounded by '/'. * scripts/misc/close_stdout: Use a regex for the answer, since sometimes the error will have a description and sometimes it won't. 2007-09-10 Paul Smith * scripts/variables/special: Add tests for .RECIPEPREFIX variable. 2007-08-15 Paul Smith These test cases were contributed by Icarus Sparry and J. David Bryan for Savannah bugs #3330 and #15919. * scripts/targets/SECONDARY: Add tests for Savannah bugs 3330 and 15919. * scripts/features/parallelism: Add tests for wrong answer/hang combining INTERMEDIATE, order-only prereqs, and parallelism. See Savannah bugs 3330 and 15919. 2007-07-13 Paul Smith Install a timeout so tests can never loop infinitely. Original idea and patch for a single-test version provided by Icarus Sparry * test_driver.pl (_run_command): New function: this is called by other functions to actually run a command. Before we run it, install a SIGALRM handler and set up a timer to go off in the future (default is 5s; this can be overridden by individual tests). (run_command): Call it. (run_command_with_output): Call it. * run_make_tests.pl (run_make_with_options): Override the default timeout if the caller requests it. (run_make_test): Pass any timeout override to run_make_with_options. * scripts/features/parallelism: Increase the timeout for long tests. * scripts/options/dash-l: Ditto. 2006-10-01 Paul Smith * run_make_tests.pl (set_more_defaults): Remove setting of LANG in ENV here. This doesn't always work. * test_driver.pl (toplevel): Set LC_ALL to 'C' in the make environment. Fixes Savannah bug #16698. 2006-09-30 Paul Smith * scripts/variables/automatic: Add back the test for bug #8154. 2006-04-01 Paul D. Smith * scripts/functions/realpath: Don't run tests with multiple initial slashes on Windows: those paths mean something different. 2006-03-19 Paul D. Smith * scripts/features/parallelism: Test that the jobserver is properly managed when we have to re-exec the master instance of make. 2006-03-17 Boris Kolpackov * scripts/features/statipattrules: Add tests for bug #16053. 2006-03-09 Paul Smith * scripts/features/escape: Use "pre:" not "p:" to avoid conflicts with DOS drive letters. Fixes Savannah bug #15947. * test_driver.pl (run_each_test): Set the status properly even when a test fails to execute. Fixes Savannah bug #15942. * scripts/functions/foreach: Use a different environment variable other than PATH to avoid differences with Windows platforms. Fixes Savannah bug #15938. 2006-03-05 Paul D. Smith * run_make_tests.pl (set_more_defaults): Add CYGWIN_NT as a port type W32. Fixed Savannah bug #15937. * scripts/features/default_names: Don't call error() when the test fails. Fixes Savannah bug #15941. 2006-02-17 Paul D. Smith * scripts/features/targetvars: Test a complex construction which guarantees that we have to merge variable lists of different sizes. Tests for Savannah bug #15757. 2006-02-15 Paul D. Smith * scripts/functions/error: Make sure filename/lineno information is related to where the error is expanded, not where it's set. * scripts/functions/warning: Ditto. * scripts/functions/foreach: Check for different error conditions. * scripts/functions/word: Ditto. * scripts/variables/negative: Test some variable reference failure conditions. * scripts/options/warn-undefined-variables: Test the --warn-undefined-variables flag. 2006-02-09 Paul D. Smith * run_make_tests.pl (set_more_defaults): Update valgrind support for newer versions. * test_driver.pl (toplevel): Skip all hidden files/directories (ones beginning with "."). * scripts/functions/andor: Tests for $(and ...) and $(or ...) functions. 2006-02-08 Boris Kolpackov * scripts/features/parallelism: Add a test for bug #15641. 2006-02-06 Paul D. Smith * scripts/options/dash-W: Add a test for bug #15341. 2006-01-03 Paul D. Smith * scripts/variables/automatic: Add a test for bug #8154. * README: Update to reflect the current state of the test suite. 2005-12-12 Paul D. Smith * scripts/features/parallelism, scripts/functions/wildcard, scripts/targets/FORCE, scripts/targets/PHONY, scripts/targets/SILENT: Use the default setting for $delete_command. Fixes bug #15085. * run_make_tests.pl (get_this_pwd) [VMS]: Use -no_ask with delete_file. 2005-12-11 Paul D. Smith * scripts/misc/general4: Test implicit rules with '$' in the prereq list & prereq patterns. * scripts/features/se_implicit: Add in .SECONDEXPANSION settings. 2005-12-09 Boris Kolpackov * scripts/features/patternrules: Add a test for bug #13022. 2005-12-07 Boris Kolpackov * scripts/features/double_colon: Add a test for bug #14334. 2005-11-17 Boris Kolpackov * scripts/functions/flavor: Add a test for the flavor function. 2005-11-14 Boris Kolpackov * scripts/variables/INCLUDE_DIRS: Add a test for the .INCLUDE_DIRS special variable. 2005-10-24 Paul D. Smith * scripts/misc/general4: Test '$$' in prerequisites list. * scripts/features/statipattrules: Rewrite to use run_make_test(). Add various static pattern info. * scripts/features/se_statpat: Enable .SECONDEXPANSION target. * scripts/features/se_explicit: Add tests for handling '$$' in prerequisite lists with and without setting .SECONDEXPANSION. * scripts/features/order_only: Convert to run_make_test(). * run_make_tests.pl (set_more_defaults): If we can't get the value of $(MAKE) from make, then fatal immediately. 2005-08-31 Paul D. Smith * run_make_tests.pl (get_this_pwd): Require the POSIX module (in an eval to trap errors) and if it exists, use POSIX::getcwd to find the working directory. If it doesn't exist, go back to the previous methods. This tries to be more accurate on Windows systems. 2005-08-29 Paul D. Smith * scripts/functions/abspath: Add some text to the error messages to get a better idea of what's wrong. Make warnings instead of errors. * scripts/features/patspecific_vars: Don't use "test", which is UNIX specific. Print the values and let the test script match them. 2005-08-25 Paul Smith * scripts/variables/SHELL: Use a /./ prefix instead of //: the former works better with non-UNIX environments. Fixes Savannah bug #14129. 2005-08-13 Boris Kolpackov * scripts/functions/wildcard: Wrap calls to $(wildcard) with $(sort) so that the resulting order is no longer filesystem- dependent. 2005-08-10 Boris Kolpackov * scripts/features/statipattrules: Add a test for Savannah bug #13881. 2005-08-07 Paul D. Smith * scripts/features/parallelism: Add a test for a bug reported by Michael Matz (matz@suse.de) in which make exits without waiting for all its children in some situations during parallel builds. 2005-07-08 Paul D. Smith * test_driver.pl: Reset the environment to a clean value every time before we invoke make. I'm suspicious that the environment isn't handled the same way in Windows as it is in UNIX, and some variables are leaking out beyond the tests they are intended for. Create an %extraENV hash tests can set to add more env. vars. * tests/scripts/features/export: Change to use %extraENV. * tests/scripts/functions/eval: Ditto. * tests/scripts/functions/origin: Ditto. * tests/scripts/options/dash-e: Ditto. * tests/scripts/variables/SHELL: Ditto. 2005-06-27 Paul D. Smith * scripts/options/dash-W: Use 'echo >>' instead of touch to update files. * scripts/features/reinvoke: Rewrite to be safer on systems with subsecond timestamps. * scripts/features/patternrules: False exits with different error codes on different systems (for example, Linux => 1, Solaris => 255). * scripts/options/dash-W: Set the timestamp to foo.x in the future, to be sure it will be considered updated when it's remade. 2005-06-26 Paul D. Smith * scripts/functions/shell: New test suite for the shell function. 2005-06-25 Paul D. Smith * scripts/features/include: Test include/-include/sinclude with no arguments. Tests fix for Savannah bug #1761. * scripts/misc/general3: Implement comprehensive testing of backslash-newline behavior in command scripts: various types of quoting, fast path / slow path, etc. Tests fix for Savannah bug #1332. * scripts/options/symlinks: Test symlinks to non-existent files. Tests fix for Savannah bug #13280. * scripts/misc/general3: Test semicolons in variable references. Tests fix for Savannah bug #1454. * scripts/variables/MAKE_RESTARTS: New file: test the MAKE_RESTARTS variable. * scripts/options/dash-B: Test re-exec doesn't loop infinitely. Tests fix for Savannah bug #7566. * scripts/options/dash-W: New file: test the -W flag, including re-exec infinite looping. 2005-06-12 Paul D. Smith * scripts/misc/close_stdout: Add a test for Savannah bug #1328. This test only works on systems that have /dev/full (e.g., Linux). 2005-06-09 Paul D. Smith * scripts/functions/foreach: Add a test for Savannah bug #11913. 2005-05-31 Boris Kolpackov * scripts/features/include: Add a test for Savannah bug #13216. * scripts/features/patternrules: Add a test for Savannah bug #13218. 2005-05-13 Paul D. Smith * scripts/features/conditionals: Add tests for the new if... else if... endif syntax. 2005-05-03 Paul D. Smith * scripts/variables/DEFAULT_GOAL: Rename DEFAULT_TARGET to DEFAULT_GOAL. 2005-05-02 Paul D. Smith * scripts/features/parallelism: Add a test for exporting recursive variables containing $(shell) calls. Rewrite this script to use run_make_test() everywhere. 2005-04-07 Paul D. Smith * scripts/targets/SECONDARY: Add a test for Savannah bug #12331. 2005-03-15 Boris Kolpackov * scripts/variables/automatic: Add a test for Savannah bug #12320. 2005-03-10 Boris Kolpackov * scripts/features/patternrules: Add a test for Savannah bug #12267. 2005-03-09 Boris Kolpackov * scripts/variables/DEFAULT_TARGET: Add a test for Savannah bug #12266. 2005-03-04 Boris Kolpackov * scripts/features/patternrules: Add a test for Savannah bug #12202. 2005-03-03 Boris Kolpackov * scripts/features/se_implicit: Add a test for stem termination bug. Add a test for stem triple-expansion bug. * scripts/features/se_statpat: Add a test for stem triple-expansion bug. * scripts/features/statipattrules: Change test #4 to reflect new way empty prerequisite list is handled. 2005-03-01 Boris Kolpackov * scripts/features/statipattrules: Add a test for Savannah bug #12180. 2005-02-28 Paul D. Smith * scripts/options/dash-q: Add a test for Savannah bug # 7144. * scripts/options/symlinks: New file to test checking of symlink timestamps. Can't use filename dash-L because it conflicts with dash-l on case-insensitive filesystems. * scripts/variables/MAKEFILE_LIST, scripts/variables/MFILE_LIST: Rename MAKEFILE_LIST test to MFILE_LIST, for systems that need 8.3 unique filenames. 2005-02-28 Boris Kolpackov * scripts/variables/DEFAULT_TARGET: Test the .DEFAULT_TARGET special variable. 2005-02-27 Boris Kolpackov * scripts/features/se_explicit: Test the second expansion in explicit rules. * scripts/features/se_implicit: Test the second expansion in implicit rules. * scripts/features/se_statpat: Test the second expansion in static pattern rules. * scripts/variables/automatic: Fix to work with the second expansion. * scripts/misc/general4: Add a test for bug #12091. 2005-02-27 Paul D. Smith * scripts/functions/eval: Check that eval of targets within command scripts fails. See Savannah bug # 12124. 2005-02-26 Paul D. Smith * test_driver.pl (compare_output): If a basic comparison of the log and answer doesn't match, try harder: change all backslashes to slashes and all CRLF to LF. This helps on DOS/Windows systems. 2005-02-09 Paul D. Smith * scripts/features/recursion: Test command line variable settings: only one instance of a given variable should be provided. 2004-11-30 Boris Kolpackov * tests/scripts/functions/abspath: New file: test `abspath' built-in function. * tests/scripts/functions/realpath: New file: test `realpath' built-in function. 2004-11-28 Paul D. Smith * scripts/options/dash-C [WINDOWS32]: Add a test for bug #10252; this doesn't really test anything useful in UNIX but... * scripts/variables/SHELL: New file: test proper handling of SHELL according to POSIX rules. Fixes bug #1276. 2004-10-21 Boris Kolpackov * scripts/functions/word: Test $(firstword ) and $(lastword ). 2004-10-05 Boris Kolpackov * scripts/features/patspecific_vars: Test simple/recursive variable expansion. 2004-09-28 Boris Kolpackov * scripts/features/include: Test dontcare flag inheritance when rebuilding makefiles. 2004-09-27 Boris Kolpackov * scripts/features/patspecific_vars: Test exported variables. 2004-09-22 Paul D. Smith * run_make_tests.pl (run_make_test): Don't add newlines to the makestring or answer if they are completely empty. * scripts/features/patternrules: Rename from implicit_prereq_eval. * scripts/test_template: Rework the template. 2004-09-21 Boris Kolpackov * run_make_tests.pl: Change `#!/usr/local/bin/perl' to be `#!/usr/bin/env perl'. * scripts/features/implicit_prereq_eval: Test implicit rule prerequisite evaluation code. 2004-09-21 Paul D. Smith * run_make_tests.pl (run_make_test): Enhance to allow the make string to be undef: in that case it reuses the previous make string. Allows multiple tests on the same makefile. * scripts/variables/flavors: Add some tests for prefix characters interacting with define/endef variables. 2004-09-20 Paul D. Smith * scripts/functions/substitution: Rewrite to use run_make_test() interface, and add test for substitution failures reported by Markus Mauhart . 2004-03-22 Paul D. Smith * test_driver.pl (run_each_test, toplevel, compare_output): Change to track both the testing categories _AND_ the number of individual tests, and report both sets of numbers. 2004-02-21 Paul D. Smith * scripts/functions/origin: Set our own environment variable rather than relying on $HOME. 2004-01-21 Paul D. Smith * scripts/features/conditionals: Test arguments to ifn?def which contain whitespace (such as a function that is evaluated). Bug #7257. 2004-01-07 Paul D. Smith * scripts/features/order_only: Test order-only prerequisites in pattern rules (patch #2349). 2003-11-02 Paul D. Smith * scripts/functions/if: Test if on conditionals with trailing whitespace--bug #5798. * scripts/functions/eval: Test eval in a non-file context--bug #6195. 2003-04-19 Paul D. Smith * scripts/features/patspecific_vars: Test multiple patterns matching the same target--Bug #1405. 2003-04-09 Paul D. Smith * run_make_tests.pl (set_more_defaults): A new $port_type of 'OS/2' for (surprise!) OS/2. Also choose a wait time of 2 seconds for OS/2. 2003-03-28 Paul D. Smith * scripts/targets/SECONDARY: Test the "global" .SECONDARY (with not prerequisites)--Bug #2515. 2003-01-30 Paul D. Smith * scripts/features/targetvars: Test very long target-specific variable definition lines (longer than the default make buffer length). Tests patch # 1022. * scripts/functions/eval: Test very recursive $(eval ...) calls with simple variable expansion (bug #2238). * scripts/functions/word: Test error handling for word and wordlist functions (bug #2407). 2003-01-22 Paul D. Smith * scripts/functions/call: Test recursive argument masking (bug #1744). 2002-10-25 Paul D. Smith * scripts/functions/eval: Test using $(eval ...) inside conditionals (Bug #1516). 2002-10-14 Paul D. Smith * scripts/options/dash-t: Add a test for handling -t on targets with no commands (Bug #1418). 2002-10-13 Paul D. Smith * scripts/features/targetvars: Add a test for exporting target-specific vars (Bug #1391). 2002-10-05 Paul D. Smith * scripts/variables/automatic: Add tests for $$(@), $${@}, $${@D}, and $${@F}. 2002-09-23 Paul D. Smith * scripts/features/escape: Test handling of escaped comment characters in targets and prerequisites. 2002-09-18 Paul D. Smith * scripts/features/export: Test export/unexport of multiple variables in a single command. 2002-09-17 Paul D. Smith * scripts/features/targetvars: Tests for Bug #940: test target-specific and pattern-specific variables in conjunction with double-colon targets. 2002-09-10 Paul D. Smith * test_driver.pl (compare_output): Match the new format for time skew error messages. * scripts/features/export: Created. Add tests for export/unexport capabilities, including exporting/unexporting expanded variables. * scripts/features/conditionals: Add a test for expanded variables in ifdef conditionals. 2002-09-04 Paul D. Smith * scripts/features/reinvoke: Change touch/sleep combos to utouch invocations. * scripts/features/vpathgpath: Ditto. * scripts/features/vpathplus: Ditto. * scripts/options/dash-n: Ditto. * scripts/targets/INTERMEDIATE: Ditto. * scripts/targets/SECONDARY: Ditto. * scripts/options/dash-t: Added a test for the -t bug fixed by Henning Makholm. This test was also contributed by Henning. * scripts/misc/general4: Add a test suite for obscure algorithmic features of make. First test: make sure creation subdirectories as prerequisites of targets works properly. * scripts/misc/version: Remove this bogus test. 2002-08-07 Paul D. Smith * scripts/misc/general3: Add a test for makefiles that don't end in newlines. * scripts/variables/special: Create tests for the special variables (.VARIABLES and .TARGETS). Comment out .TARGETS test for now as it's not yet supported. 2002-08-01 Paul D. Smith * scripts/options/dash-B: Add a test for the new -B option. 2002-07-11 Paul D. Smith * run_make_tests.pl (valid_option): Add support for Valgrind. Use -valgrind option to the test suite. (set_more_defaults): Set up the file descriptor to capture Valgrind output. We have to unset its close-on-exec flag; we hardcode the value for F_SETFD (2) rather than load it; hopefully this will help us avoid breaking the Windows/DOS test suite. 2002-07-10 Paul D. Smith * scripts/variables/automatic: Add some tests for $$@, $$(@D), and $$(@F). * test_driver.pl (utouch): Create a new function that creates a file with a specific timestamp offset. Use of this function will let us avoid lots of annoying sleep() invocations in the tests just to get proper timestamping, which will make the tests run a lot faster. So far it's only used in the automatic test suite. 2002-07-09 Paul D. Smith * scripts/variables/automatic: Create a test for automatic variables. 2002-07-08 Paul D. Smith * scripts/features/order_only: Test new order-only prerequisites. 2002-07-07 Paul D. Smith * scripts/functions/eval: Test new function. * scripts/functions/value: Test new function. * scripts/variables/MAKEFILE_LIST: Test new variable. 2002-04-28 Paul D. Smith * scripts/functions/call: New test: transitive closure implementation using $(call ...) to test variable recursion. 2002-04-21 Paul D. Smith * test_driver.pl (compare_dir_tree): Ignore CVS and RCS directories in the script directories. 2001-05-02 Paul D. Smith * scripts/variables/flavors: Test define/endef scripts where only one of the command lines is quiet. 2000-06-22 Paul D. Smith * scripts/options/dash-q: New file; test the -q option. Includes a test for PR/1780. 2000-06-21 Paul D. Smith * scripts/features/targetvars: Added a test for PR/1709: allowing semicolons in target-specific variable values. 2000-06-19 Paul D. Smith * scripts/functions/addsuffix: Test for an empty final argument. Actually this bug might have happened for any function, but this one was handy. 2000-06-17 Eli Zaretskii * scripts/options/general: If parallel jobs are not supported, expect a warning message from Make. 2000-06-15 Eli Zaretskii * scripts/options/general: Don't try -jN with N != 1 if parallel jobs are not supported. 2000-05-24 Paul D. Smith * scripts/options/general: Test general option processing (PR/1716). 2000-04-11 Paul D. Smith * scripts/functions/strip: Test empty value to strip (PR/1689). 2000-04-08 Eli Zaretskii * scripts/features/reinvoke: Sleep before updating the target files in the first test, to ensure its time stamp really gets newer; otherwise Make might re-exec more than once. 2000-04-07 Eli Zaretskii * scripts/features/double_colon: Don't run the parallel tests if parallel jobs aren't supported. 2000-04-04 Paul D. Smith * scripts/functions/word: wordlist doesn't swap arguments anymore. 2000-03-27 Paul D. Smith * scripts/features/statipattrules: Test that static pattern rules whose prerequisite patterns resolve to empty strings throw an error (instead of dumping core). Fixes PR/1670. * scripts/features/reinvoke: Make more robust by touching "b" first, to ensure it's not newer than "a". Reported by Marco Franzen . * scripts/options/dash-n: Ditto. * scripts/functions/call: Whoops. The fix to PR/1527 caused recursive invocations of $(call ...) to break. I can't come up with any way to get both working at the same time, so I backed out the fix to 1527 and added a test case for recursive calls. This also tests the fix for PR/1610. * scripts/features/double_colon: Test that circular dependencies in double-colon rule sets are detected correctly (PR/1671). 2000-03-26 Paul D. Smith * scripts/targets/INTERMEDIATE: Test that make doesn't remove .INTERMEDIATE files when given on the command line (PR/1669). 2000-03-08 Paul D. Smith * scripts/options/dash-k: Add a test for error detection by multiple targets depending on the same prerequisite with -k. For PR/1634. 2000-02-07 Paul D. Smith * scripts/features/escape: Add a test for backslash-escaped spaces in a target name (PR/1586). 2000-02-04 Paul D. Smith * scripts/features/patspecific_vars: Add a test for pattern-specific target variables inherited from the parent target (PR/1407). 2000-02-02 Paul D. Smith * run_make_tests.pl (set_more_defaults): Hard-code the LANG to C to make sure sorting order, etc. is predictable. Reported by Andreas Jaeger . * run_make_tests.pl (set_more_defaults): Set the $wtime variable depending on the OS. Eli Zaretskii reports this seems to need to be *4* on DOS/Windows, not just 2. Keep it 1 for other systems. * scripts/features/vpathplus (touchfiles): Use the $wtime value instead of hardcoding 2. * scripts/targets/SECONDARY: Ditto. * scripts/targets/INTERMEDIATE: Ditto. 2000-01-27 Paul D. Smith * test_driver.pl (toplevel): Don't try to run test scripts which are really directories. 2000-01-23 Paul D. Smith * scripts/features/include: Remove a check; the fix caused more problems than the error, so I removed it and removed the test for it. 2000-01-11 Paul D. Smith * scripts/functions/call: Add a test for PR/1517 and PR/1527: make sure $(call ...) doesn't eval its arguments and that you can invoke foreach from it without looping forever. 1999-12-15 Paul D. Smith * scripts/targets/INTERMEDIATE: Add a test for PR/1423: make sure .INTERMEDIATE settings on files don't disable them as implicit intermediate possibilities. 1999-12-01 Paul D. Smith * scripts/features/double_colon: Add a test for PR/1476: Try double-colon rules as non-goal targets and during parallel builds to make sure they're handled serially. 1999-11-17 Paul D. Smith * scripts/functions/if: Add a test for PR/1429: put some text after an if-statement to make sure it works. * scripts/features/targetvars: Add a test for PR/1380: handling += in target-specific variable definitions correctly. 1999-10-15 Paul D. Smith * scripts/variables/MAKEFILES: This was really broken: it didn't test anything at all, really. Rewrote it, plus added a test for PR/1394. 1999-10-13 Paul D. Smith * scripts/options/dash-n: Add a test for PR/1379: "-n doesn't behave properly when used with recursive targets". 1999-10-08 Paul D. Smith * scripts/features/targetvars: Add a check for PR/1378: "Target-specific vars don't inherit correctly" 1999-09-29 Paul D. Smith * test_driver.pl (get_osname): Change $fancy_file_names to $short_filenames and reverse the logic. (run_each_test): Change test of non-existent $port_host to use $short_filenames--problem reported by Eli Zaretskii. 1999-09-23 Paul D. Smith * scripts/features/parallelism: Add a check to ensure that the jobserver works when we re-invoke. Also cleaned up the tests a little, reducing the number of rules we use so the test won't need as many "sleep" commands. 1999-09-16 Paul D. Smith * scripts/features/reinvoke: Remove invocations of "touch" in makefiles. See the comments on the touch function rewrite below. Note that UNIX touch behaves the same way if the file already exists: it sets the time to the _local_ time. We don't want this. This is probably a good tip for makefile writers in general, actually... where practical. * scripts/options/dash-l: Ditto. * scripts/options/dash-n: Ditto. * test_driver.pl (run_each_test): In retrospect, I don't like the .lN/.bN/.dN postfix required by DOS. So, for non-DOS systems I changed it back to use .log, .base, and .diff. * run_make_tests.pl (set_more_defaults): Move the check for the make pathname to here from set_defaults (that's too early since it happens before the command line processing). Create a new variable $port_type, calculated from $osname, to specify what kind of system we're running on. We should integrate the VOS stuff here, too. (valid_option): Comment out the workdir/-work stuff so people won't be fooled into thinking it works... someone needs to fix this, though! * scripts/functions/origin: Use $port_type instead of $osname. * scripts/functions/foreach: Ditto. * scripts/features/default_names: Ditto. 1999-09-15 Paul D. Smith * test_driver.pl (touch): Rewrite this function. Previously it used to use utime() to hard-set the time based on the current local clock, or, if the file didn't exist, it merely created it. This mirrors exactly what real UNIX touch does, but it fails badly on networked filesystems where the FS server clock is skewed from the local clock: normally modifying a file causes it to get a mod time based on the _server's_ clock. Hard-setting it based on the _local_ clock causes gratuitous errors and makes the tests unreliable except on local filesystems. The new function will simply modify the file, allowing the filesystem to set the mod time as it sees fit. * scripts/features/parallelism: The second test output could change depending on how fast some scripts completed; use "sleep" to force the order we want. * test_driver.pl (toplevel): A bug in Perl 5.000 to Perl 5.004 means that "%ENV = ();" doesn't do the right thing. This worked in Perl 4 and was fixed in Perl 5.004_01, but use a loop to delete the environment rather than require specific versions. * run_make_tests.pl (set_more_defaults): Don't use Perl 5 s/// modifier "s", so the tests will run with Perl 4. (set_more_defaults): Set $pure_log to empty if there's no -logfile option in PURIFYOPTIONS. (setup_for_test): Don't remove any logs unless $pure_log is set. 1999-09-15 Eli Zaretskii * scripts/features/reinvoke: Put the SHELL definition in the right test makefile. 1999-09-15 Paul D. Smith ChangeLog file for the test suite created. Copyright (C) 1992-2017 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: tests/NEWS ================================================ Changes from 0.4.9 to 3.78 (Sep 6, 1999): Lots of new tests. Renamed to follow the GNU Make scheme. Also added some support for using Purify with make. Rob Tulloh contributed some changes to get the test suite running on NT; I tweaked them a bit (hopefully I didn't break anything!) Note that NT doesn't grok the self-exec funkiness that Unix shells use, so instead I broke that out into a separate shell script "run_make_tests" that invokes perl with the (renamed) script run_make_tests.pl. Eli Zaretski contributed changes to get the test suite running on DOS with DJGPP. I also meddled in these somewhat. If you're on DOS or NT you should run "perl.exe run_make_tests.pl ..." If you're on Unix, you can continue to run "./run_make_tests ..." as before. Changes from 0.4.8 to 0.4.9 (May 14, 1998): Release by Paul D. Smith ; I'm the one to blame for problems in this version :). Add some perl to test_driver.pl to strip out GNU Make clock skew warning messages from the output before comparing it to the known-good output. A new test for escaped :'s in filenames (someone on VMS found this didn't work anymore in 3.77): scripts/features/escape. Changes from 0.4.7 to 0.4.8 (May 14, 1998): Release by Paul D. Smith ; I'm the one to blame for problems in this version :). New tests for features to be included in GNU Make 3.77. Changes from 0.4.6 to 0.4.7 (August 18, 1997): Release by Paul D. Smith ; I'm the one to blame for problems in this version :). Reworked some tests to make sure they all work with both perl4 and perl5. Work around a bug in perl 5.004 which doesn't clean the environment correctly in all cases (fixed in at least 5.004_02). Updated functions/strip to test for newline stripping. Keep a $PURIFYOPTIONS env variable if present. Changes from 0.4.5 to 0.4.6 (April 07, 1997): Release by Paul D. Smith ; I'm the one to blame for problems in this version :). Updated to work with GNU Make 3.76 (and pretests). Added new tests and updated existing ones. Note that the new tests weren't tested with perl 4, however I think they should work. Ignore any tests whose filenames end in "~", so that Emacs backup files aren't run. Changes from 0.4.4 to 0.4.5 (April 29, 1995): Updated to be compatible with perl 5.001 as well as 4.036. Note: the test suite still won't work on 14-char filesystems (sorry, Kaveh), but I will get to it. Also, some tests and stuff still haven't made it in because I haven't had time to write the test scripts for them. But they, too, will get in eventually. Contributions of scripts (i.e., tests that I can just drop in) are particularly welcome and will be incorporated immediately. Changes from 0.4.3 to 0.4.4 (March 1995): Updated for changes in make 3.72.12, and to ignore CVS directories (thanks go to Jim Meyering for the patches for this). Fixed uname call to not make a mess on BSD/OS 2.0 (whose uname -a is very verbose). Let me know if this doesn't work correctly on your system. Changed to display test name while it is running, not just when it finishes. Note: the test suite still won't work on 14-char filesystems (sorry, Kaveh), but I will get to it. Also, some tests and stuff still haven't made it in because I haven't had time to write the test scripts for them. But they, too, will get in eventually. Changes from 0.4 to 0.4.3 (October 1994): Fixed bugs (like dependencies on environment variables). Caught up with changes in make. The load_limit test should now silently ignore a failure due to make not being able to read /dev/kmem. Reorganized tests into subdirs and renamed lots of things so that those poor souls who still have to deal with 14-char filename limits won't hate me any more. Thanks very much to Kaveh R. Ghazi for helping me with the implementation and testing of these changes, and for putting up with all my whining about it... Added a $| = 1 so that systems that don't seem to automatically flush their output for some reason will still print all the output. I'd hate for someone to miss out on the smiley that you're supposed to get when all the tests pass... :-) Changes from 0.3 to 0.4 (August 1993): Lost in the mists of time (and my hurry to get it out before I left my job). Changes from 0.2 to 0.3 (9-30-92): Several tests fixed to match the fact that MAKELEVEL > 0 or -C now imply -w. parallel_execution test fixed to not use double colon rules any more since their behavior has changed. errors_in_commands test fixed to handle different error messages and return codes from rm. Several tests fixed to handle -make_path with a relative path and/or a name other than "make" for make. dash-e-option test fixed to use $PATH instead of $USER (since the latter does not exist on some System V systems). This also removes the dependency on getlogin (which fails under certain weird conditions). test_driver_core changed so that you can give a test name like scripts/errors_in_commands and it will be handled correctly (handy if you have a shell with filename completion). Changes from 0.1 to 0.2 (5-4-92): README corrected to require perl 4.019, not 4.010. -make_path replaces -old. errors_in_commands test updated for change in format introduced in make 3.62.6. test_driver_core now uses a better way of figuring what OS it is running on (thanks to meyering@cs.utexas.edu (Jim Meyering) for suggesting this, as well as discovering the hard way that the old way (testing for /mnt) fails on his machine). Some new tests were added. ------------------------------------------------------------------------------- Copyright (C) 1992-2024 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ================================================ FILE: tests/config-flags.pm.W32 ================================================ # This is a -*-perl-*- script # # Set variables for Windows systems. %CONFIG_FLAGS = ( USE_SYSTEM_GLOB => 'no' ); 1; ================================================ FILE: tests/config-flags.pm.in ================================================ # This is a -*-perl-*- script # # Set variables that were defined by configure, in case we need them # during the tests. %CONFIG_FLAGS = ( AM_LDFLAGS => '@AM_LDFLAGS@', AR => '@AR@', CC => '@CC@', CFLAGS => '@CFLAGS@', CPP => '@CPP@', CPPFLAGS => '@CPPFLAGS@', GUILE_CFLAGS => '@GUILE_CFLAGS@', GUILE_LIBS => '@GUILE_LIBS@', LDFLAGS => '@LDFLAGS@', LIBS => '@LIBS@', USE_SYSTEM_GLOB => '@USE_SYSTEM_GLOB@' ); 1; ================================================ FILE: tests/config_flags_pm.com ================================================ $! $! config_flags_pm.com - Build config-flags.pm on VMS. $! $! Just good enough to run the self tests for now. $! $! Copyright (C) 2014-2024 Free Software Foundation, Inc. $! This file is part of GNU Make. $! $! GNU Make is free software; you can redistribute it and/or modify it under $! the terms of the GNU General Public License as published by the Free Software $! Foundation; either version 3 of the License, or (at your option) any later $! version. $! $! GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY $! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS $! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more $! details. $! $! You should have received a copy of the GNU General Public License along with $! this program. If not, see . $! $! $ open/read cfpm_in config-flags.pm.in $! $ outfile = "sys$disk:[]config-flags.pm" $! $ cflags = "/include=([],[.lib]" $! $ create 'outfile' $ open/append cfpm 'outfile' $! $cfpm_read_loop: $ read cfpm_in/end=cfpm_read_loop_end line_in $ line_in_len = f$length(line_in) $ if f$locate("@", line_in) .lt. line_in_len $ then $ part1 = f$element(0, "@", line_in) $ key = f$element(1, "@", line_in) $ part2 = f$element(2, "@", line_in) $ value = "" $ if key .eqs. "CC" then value = "CC" $ if key .eqs. "CPP" then value = "CPP" $ if key .eqs. "CFLAGS" then value = cflags $ if key .eqs. "GUILE_CFLAGS" then value = cflags $ if key .eqs. "USE_SYSTEM_GLOB" then value = "no" $ write cfpm part1, value, part2 $ goto cfpm_read_loop $ endif $ write cfpm line_in $ goto cfpm_read_loop $cfpm_read_loop_end: $ close cfpm_in $ close cfpm $! ================================================ FILE: tests/guile.supp ================================================ # Guile valgrind suppression file # Created with Guile 1.8.7 # --- Garbage collection { guilegc Memcheck:Cond ... fun:scm_gc_for_newcell } { guilegc Memcheck:Value4 ... fun:scm_gc_for_newcell } { guilegc Memcheck:Value8 ... fun:scm_gc_for_newcell } # -- scm_alloc_struct { guileheap Memcheck:Leak ... fun:scm_alloc_struct } ================================================ FILE: tests/mkshadow ================================================ #!/bin/sh # # Simple script to make a "shadow" test directory, using symbolic links. # Typically you'd put the shadow in /tmp or another local disk # # Copyright (C) 1992-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . case "$1" in "") echo 'Usage: mkshadow '; exit 1 ;; esac dest="$1" if [ ! -d "$dest" ]; then echo "Destination directory '$dest' must exist!" exit 1 fi if [ ! -f run_make_tests ]; then echo "The current directory doesn't appear to contain the test suite!" exit 1 fi suite=`pwd | sed 's%^/tmp_mnt%%'` name=`basename "$suite"` files=`echo *` set -e mkdir "$dest/$name" cd "$dest/$name" ln -s "$suite" .testdir for f in $files; do ln -s .testdir/$f . done rm -rf work echo "Shadow test suite created in '$dest/$name'." exit 0 ================================================ FILE: tests/run_make_tests ================================================ #!/bin/sh exec perl $0.pl ${1+"$@"} ================================================ FILE: tests/run_make_tests.bat ================================================ @echo off rem Copyright (C) 2017-2024 Free Software Foundation, Inc. rem This file is part of GNU Make. rem rem GNU Make is free software; you can redistribute it and/or modify it under rem the terms of the GNU General Public License as published by the Free rem Software Foundation; either version 3 of the License, or (at your option) rem any later version. rem rem GNU Make is distributed in the hope that it will be useful, but WITHOUT rem ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or rem FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for. rem more details. rem rem You should have received a copy of the GNU General Public License along rem with this program. If not, see . setlocal cd "%~dp0" perl -I. .\run_make_tests.pl %* ================================================ FILE: tests/run_make_tests.com ================================================ $! Test_make.com $! $! This is a wrapper for the GNU Make perl test programs on VMS. $! $! Parameter "-help" for description on how to use described below. $! $! Copyright (C) 2014-2024 Free Software Foundation, Inc. $! This file is part of GNU Make. $! $! GNU Make is free software; you can redistribute it and/or modify it under $! the terms of the GNU General Public License as published by the Free Software $! Foundation; either version 3 of the License, or (at your option) any later $! version. $! $! GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY $! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS $! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more $! details. $! $! You should have received a copy of the GNU General Public License along with $! this program. If not, see . $! $! $! Allow more than 8 parameters with using commas as a delimiter. $! $ params = "''p1',''p2',''p3',''p4',''p5',''p6',''p7',''p8'" $! $ test_flags = ",verbose,detail,keep,usage,help,debug," $ test_flags_len = f$length(test_flags) $ verbose_flag = "" $ detail_flag = "" $ keep_flag = "" $ usage_flag = "" $ help_flag = "" $ debug_flag = "" $! $ ignored_options = "profile,make,srcdir,valgrind,memcheck,massif," $ ignored_option_len = f$length(ignored_options) $! $ testname = "" $ make :== $bin:make.exe" $! $ i = 0 $param_loop: $ param = f$element(i, ",", params) $ i = i + 1 $ if param .eqs. "" then goto param_loop $ if param .eqs. "," then goto param_loop_end $ param_len = f$length(param) $ if f$locate("/", param) .lt. param_len $ then $ if testname .nes. "" $ then $ write sys$output "Only the last test name specified will be run!" $ endif $ testname = param $ goto param_loop $ endif $ lc_param = f$edit(param,"LOWERCASE") - "-" $ if f$locate(",''lc_param',", ignored_options) .lt. ignored_option_len $ then $ write sys$output "parameter ''param' is ignored on VMS for now." $ goto param_loop $ endif $ if f$locate(",''lc_param',", test_flags) .lt. test_flags_len $ then $ 'lc_param'_flag = "-" + lc_param $ goto param_loop $ endif $ write sys$output "parameter ''param' is not known to VMS." $ goto param_loop $! $param_loop_end: $! $no_gnv = 1 $no_perl = 1 $! $! Find GNV 2.1.3 + manditory updates $! If properly updated, the GNV$GNU logical name is present. $! Updated GNV utilities have a gnv$ prefix on them. $ gnv_root = f$trnlnm("GNV$GNU", "LNM$SYSTEM_TABLE") $ if gnv_root .nes. "" $ then $ no_gnv = 0 $ ! Check for update ar utility. $ new_ar = "gnv$gnu:[usr.bin]gnv$ar.exe" $ if f$search(new_ar) .nes. "" $ then $ ! See if a new port of ar exists. $ ar :== $'new_ar' $ else $ ! Fall back to legacy GNV AR wrapper. $ old_ar = "gnv$gnu:[bin]ar.exe" $ if f$search(old_ar) .nes. "" $ then $ ar :== $'old_ar' $ else $ no_gnv = 1 $ endif $ endif $ ! Check for updated bash $ if no_gnv .eq. 0 $ then $ new_bash = "gnv$gnu:[bin]gnv$bash.exe" $ if f$search(new_bash) .nes. "" $ then $ bash :== $'new_bash' $ sh :== $'new_bash' $ else $ no_gnv = 1 $ endif $ endif $ ! Check for updated coreutils $ if no_gnv .eq. 0 $ then $ new_cat = "gnv$gnu:[bin]gnv$cat.exe" $ if f$search(new_cat) .nes. "" $ then $ cat :== $'new_cat' $ cp :== $gnv$gnu:[bin]gnv$cp.exe $ echo :== $gnv$gnu:[bin]gnv$echo.exe $ false :== $gnv$gnu:[bin]gnv$false.exe $ true :== $gnv$gnu:[bin]gnv$true.exe $ touch :== $gnv$gnu:[bin]gnv$touch.exe $ mkdir :== $gnv$gnu:[bin]gnv$mkdir.exe $ rm :== $gnv$gnu:[bin]gnv$rm.exe $ sleep :== $gnv$gnu:[bin]gnv$sleep.exe $ else $ no_gnv = 1 $ endif $ endif $ ! Check for updated diff utility. $ if no_gnv .eq. 0 $ then $ new_diff = "gnv$gnu:[usr.bin]gnv$diff.exe" $ if f$search(new_diff) .nes. "" $ then $ ! See if a new port of diff exists. $ diff :== $'new_diff' $ else $ ! Fall back to legacy GNV diff $ old_diff = "gnv$gnu:[bin]diff.exe" $ if f$search(old_diff) .nes. "" $ then $ diff :== $'old_diff' $ else $ no_gnv = 1 $ endif $ endif $ endif $ endif $! $if no_gnv $then $ write sys$output "Could not find an up to date GNV installed!" $ help_flag = 1 $endif $! $! Find perl 5.18.1 or later. $! $! look in perl_root:[000000]perl_setup.com $ perl_root = f$trnlnm("perl_root") $ ! This works with known perl installed from PCSI kits. $ if perl_root .nes. "" $ then $ perl_ver = f$element(1, ".", perl_root) $ if f$locate("-", perl_ver) .lt. f$length(perl_ver) $ then $ no_perl = 0 $ endif $ endif $ if no_perl $ then $! look for sys$common:[perl-*]perl_setup.com $ perl_setup = f$search("sys$common:[perl-*]perl_setup.com") $ if perl_setup .eqs. "" $ then $ if gnv_root .nes. "" $ then $ gnv_device = f$parse(gnv_root,,,"DEVICE") $ perl_templ = "[vms$common.perl-*]perl_setup.com" $ perl_search = f$parse(perl_templ, gnv_device) $ perl_setup = f$search(perl_search) $ endif $ endif $ if perl_setup .nes. "" $ then $ @'perl_setup' $ no_perl = 0 $ endif $ endif $! $ if no_perl $ then $ write sys$output "Could not find an up to date Perl installed!" $ help_flag = "-help" $ endif $! $! $ if help_flag .nes. "" $ then $ type sys$input $DECK This is a test script wrapper for the run_make_tests.pl script. This wrapper makes sure that the DCL symbols and logical names needed to run the perl script are in place. The test wrapper currently requires that the DCL symbols be global symbols. Those symbols will be left behind after the procedure is run. The PERL_ROOT will be set to a compatible perl if such a perl is found and is not the default PERL_ROOT:. This setting will persist after the test. This wrapper should be run with the default set to the base directory of the make source. The HELP parameter will bring up this text and then run the help script for the Perl wrapper. Not all options for the perl script have been implemented, such as valgrind or specifying the make path or source path. Running the wrapper script requires: Perl 5.18 or later. PCSI kits available from https://sourceforge.net/projects/vmsperlkit/files/ GNV 2.1.3 or later. GNV 3.0.1 has not tested with this script. Bash 4.2.47 or later. Coreutils 8.21 or later. https://sourceforge.net/projects/gnv/files/ Read before installing: https://sourceforge.net/p/gnv/wiki/InstallingGNVPackages/ As updates for other GNV components get posted, those updates should be used. $EOD $ endif $! $ if no_gnv .or. no_perl then exit 44 $! $! $ default = f$environment("DEFAULT") $ default_dev = f$element(0, ":", default) + ":" $ this = f$environment("PROCEDURE") $ on error then goto all_error $ set default 'default_dev''f$parse(this,,,"DIRECTORY")' $! $! Need to make sure that the config-flags.pm exists. $ if f$search("config-flags.pm") .eqs. "" $ then $ @config_flags_pm.com $ endif $ define/user bin 'default_dev'[-],gnv$gnu:[bin] $ define/user decc$filename_unix_noversion enable $ define/user decc$filename_unix_report enable $ define/user decc$readdir_dropdotnotype enable $ flags = "" $ if verbose_flag .nes. "" then flags = verbose_flag $ if detail_flag .nes. "" then flags = flags + " " + detail_flag $ if keep_flag .nes. "" then flags = flags + " " + keep_flag $ if usage_flag .nes. "" then flags = flags + " " + usage_flag $ if help_flag .nes. "" then flags = flags + " " + help_flag $ if debug_flag .nes. "" then flags = flags + " " + debug_flag $ flags = f$edit(flags, "TRIM, COMPRESS") $ if testname .nes. "" $ then $ perl run_make_tests.pl "''testname'" 'flags' $ else $ perl run_make_tests.pl 'flags' $ endif $all_error: $ set default 'default' $! ================================================ FILE: tests/run_make_tests.pl ================================================ #!/usr/bin/env perl # -*-perl-*- # Test driver for the Make test suite # Usage: run_make_tests [testname] # [-debug] # [-help] # [-verbose] # [-keep] # [-make ] # (and others) # Copyright (C) 1992-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # Add the working directory to @INC and load the test driver use FindBin; use lib "$FindBin::Bin"; our $testsroot = $FindBin::Bin; require "test_driver.pl"; use File::Spec; use Cwd; $cwdpath = cwd(); ($cwdvol, $cwddir, $_) = File::Spec->splitpath($cwdpath, 1); # Some target systems might not have the POSIX module... $has_POSIX = eval { require "POSIX.pm" }; %FEATURES = (); %DEFVARS = ( AR => undef, CC => undef ); $valgrind = 0; # invoke make with valgrind $valgrind_args = ''; $memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full --suppressions=guile.supp'; $massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup'; $pure_log = undef; $make_path = undef; @make_command = (); $command_string = ''; $all_tests = 0; # Shell commands $sh_name = '/bin/sh'; $is_posix_sh = 1; $CMD_rmfile = 'rm -f'; # rmdir broken in some Perls on VMS. if ($^O eq 'VMS') { require VMS::Filespec; VMS::Filespec->import(); sub vms_rmdir { my $vms_file = vmspath($_[0]); $vms_file = fileify($vms_file); my $ret = unlink(vmsify($vms_file)); return $ret }; *CORE::GLOBAL::rmdir = \&vms_rmdir; $CMD_rmfile = 'delete_file -no_ask'; } %CONFIG_FLAGS = (); # Find the strings that will be generated for various error codes. # We want them from the C locale regardless of our current locale. $ERR_no_such_file = undef; $ERR_no_such_file_code = "2"; $ERR_read_only_file = undef; $ERR_unreadable_file = undef; $ERR_nonexe_file = undef; $ERR_exe_dir = undef; $ERR_command_not_found = undef; #$SIG{INT} = sub { print STDERR "Caught a signal!\n"; die @_; }; sub valid_option { local($option) = @_; if ($option =~ /^-make([-_]?path)?$/i) { $make_path = shift @argv; if (! -f $make_path) { print "$option $make_path: Not found.\n"; exit 1; } return 1; } if ($option =~ /^-all([-_]?tests)?$/i) { $all_tests = 1; return 1; } if ($option =~ /^-(valgrind|memcheck)$/i) { $valgrind = 1; $valgrind_args = $memcheck_args; return 1; } if ($option =~ /^-massif$/i) { $valgrind = 1; $valgrind_args = $massif_args; return 1; } # This doesn't work--it _should_! Someone badly needs to fix this. # # elsif ($option =~ /^-work([-_]?dir)?$/) # { # $workdir = shift @argv; # return 1; # } return 0; } # This is an "all-in-one" function. Arguments are as follows: # # [0] (string): The makefile to be tested. undef means use the last one. # [1] (string): Arguments to pass to make. # [2] (string): Answer we should get back. # [3] (integer): Exit code we expect. A missing code means 0 (success) $makefile = undef; $old_makefile = undef; $mkpath = undef; $make_name = undef; $helptool = undef; sub subst_make_string { my $wd = cwd(); local $_ = shift; $makefile and s/#MAKEFILE#/$makefile/g; s/#MAKEPATH#/$mkpath/g; s/#MAKE#/$make_name/g; s/#PERL#/$perl_name/g; s/#PWD#/$wd/g; s/#HELPER#/$perl_name $helptool/g; return $_; } sub run_make_test { local ($makestring, $options, $answer, $err_code, $timeout) = @_; my @call = caller; # If the user specified a makefile string, create a new makefile to contain # it. If the first value is not defined, use the last one (if there is # one). if (! defined $makestring) { defined $old_makefile or die "run_make_test(undef) invoked before run_make_test('...')\n"; $makefile = $old_makefile; } elsif ($makestring) { if (! defined($makefile)) { $makefile = &get_tmpfile(); } # Make sure it ends in a newline and substitute any special tokens. $makestring && $makestring !~ /\n$/s and $makestring .= "\n"; $makestring = subst_make_string($makestring); # Populate the makefile! open(MAKEFILE, "> $makefile") or die "Failed to open $makefile: $!\n"; print MAKEFILE $makestring; close(MAKEFILE) or die "Failed to write $makefile: $!\n"; } # Do the same processing on $answer as we did on $makestring. if (defined $answer) { $answer && $answer !~ /\n$/s and $answer .= "\n"; $answer = subst_make_string($answer); } run_make_with_options($makefile, $options, &get_logfile(0), $err_code, $timeout, @call); &compare_output($answer, &get_logfile(1)); $old_makefile = $makefile; $makefile = undef; } sub add_options { my $cmd = shift; foreach (@_) { if (ref($cmd)) { push(@$cmd, ref($_) ? @$_ : $_); } else { $cmd .= ' '.(ref($_) ? "@$_" : $_); } } return $cmd; } sub create_command { return !$_[0] || ref($_[0]) ? [@make_command] : join(' ', @make_command); } # The old-fashioned way... # $options can be a scalar (string) or a ref to an array of options # If it's a scalar the entire argument is passed to system/exec etc. as # a single string. If it's a ref then the array is passed to system/exec. # Using a ref should be preferred as it's more portable but all the older # invocations use strings. sub run_make_with_options { my ($filename, $options, $logname, $expected_code, $timeout, @call) = @_; @call = caller unless @call; my $code; my $command = create_command($options); $expected_code = 0 unless defined($expected_code); # Reset to reflect this one test. $test_passed = 1; if ($filename) { $command = add_options($command, '-f', $filename); } if ($options) { if (!ref($options) && $^O eq 'VMS') { # Try to make sure arguments are properly quoted. # This does not handle all cases. # We should convert the tests to use array refs not strings # VMS uses double quotes instead of single quotes. $options =~ s/\'/\"/g; # If the leading quote is inside non-whitespace, then the # quote must be doubled, because it will be enclosed in another # set of quotes. $options =~ s/(\S)(\".*\")/$1\"$2\"/g; # Options must be quoted to preserve case if not already quoted. $options =~ s/(\S+)/\"$1\"/g; # Special fixup for embedded quotes. $options =~ s/(\"\".+)\"(\s+)\"(.+\"\")/$1$2$3/g; $options =~ s/(\A)(?:\"\")(.+)(?:\"\")/$1\"$2\"/g; # Special fixup for misc/general4 test. $options =~ s/""\@echo" "cc""/\@echo cc"/; $options =~ s/"\@echo link"""/\@echo link"/; # Remove shell escapes expected to be removed by bash if ($options !~ /path=pre/) { $options =~ s/\\//g; } # special fixup for options/eval $options =~ s/"--eval=\$\(info" "eval/"--eval=\$\(info eval/; print ("Options fixup = -$options-\n") if $debug; } $command = add_options($command, $options); } my $cmdstr = cmd2str($command); $command_string = "# $call[1]:$call[2]:\n$cmdstr\n"; if ($valgrind) { print VALGRIND "\n\nExecuting: $cmdstr\n"; } { my $old_timeout = $test_timeout; $timeout and $test_timeout = $timeout; # If valgrind is enabled, turn off the timeout check $valgrind and $test_timeout = 0; if (ref($command)) { $code = run_command_with_output($logname, @$command); } else { $code = run_command_with_output($logname, $command); } $test_timeout = $old_timeout; } # Check to see if we have Purify errors. If so, keep the logfile. # For this to work you need to build with the Purify flag -exit-status=yes if ($pure_log && -f $pure_log) { if ($code & 0x7000) { $code &= ~0x7000; # If we have a purify log, save it $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : ""); print("Renaming purify log file to $tn\n") if $debug; rename($pure_log, "$tn") or die "Can't rename $pure_log to $tn: $!\n"; ++$purify_errors; } else { unlink($pure_log); } } if ($code != $expected_code) { print "Error running @make_command (expected $expected_code; got $code)\n$call[1]:$call[2]: $cmdstr\n"; $test_passed = 0; &create_file(get_runfile(), $command_string); # If it's a SIGINT, stop here if ($code & 127) { print STDERR "\nCaught signal ".($code & 127)."!\n"; ($code & 127) == 2 and exit($code); } return 0; } if ($profile & $vos) { system "add_profile @make_command"; } return 1; } sub print_usage { &print_standard_usage ("run_make_tests", "[-make MAKE_PATHNAME] [-memcheck] [-massif]",); } sub print_help { &print_standard_help ( "-make", "\tYou may specify the pathname of the copy of make to run.", "-valgrind", "-memcheck", "\tRun the test suite under valgrind's memcheck tool.", "\tChange the default valgrind args with the VALGRIND_ARGS env var.", "-massif", "\tRun the test suite under valgrind's massif tool.", "\tChange the default valgrind args with the VALGRIND_ARGS env var." ); } sub set_defaults { # $profile = 1; $testee = "GNU Make"; $make_path = "make"; $tmpfilesuffix = "mk"; if ($port_type eq 'UNIX') { $scriptsuffix = '.sh'; } elsif ($port_type eq 'VMS') { $scriptsuffix = '.com'; } else { $scriptsuffix = '.bat'; } $ENV{LC_ALL} = $makeENV{LC_ALL}; $ENV{LANG} = $makeENV{LANG}; $ENV{LANGUAGE} = $makeENV{LANGUAGE}; use locale; my $loc = undef; if ($has_POSIX) { POSIX->import(qw(locale_h)); # Windows has POSIX locale, but only LC_ALL not LC_MESSAGES $loc = POSIX::setlocale(&POSIX::LC_ALL); POSIX::setlocale(&POSIX::LC_ALL, 'C'); } if (open(my $F, '<', 'file.none')) { print "Opened non-existent file! Skipping related tests.\n"; } else { $ERR_no_such_file = "$!"; if ($osname eq 'os390') { $ERR_no_such_file_code = "129"; } } unlink('file.out'); touch('file.out'); chmod(0444, 'file.out'); if (open(my $F, '>', 'file.out')) { print "Opened read-only file! Skipping related tests.\n"; close($F); } else { $ERR_read_only_file = "$!"; } $_ = `./file.out 2>&1`; if ($? == 0) { print "Executed non-executable file! Skipping related tests.\n"; } else { $ERR_nonexe_file = "$!"; } if ($^O =~ /cygwin/i) { # For some reason the execute here gives a different answer than make's print "Skipping directory execution on $^O\n"; } else { $_ = `./. 2>&1`; if ($? == 0) { print "Executed directory! Skipping related tests.\n"; } else { $ERR_exe_dir = "$!"; } } chmod(0000, 'file.out'); if (open(my $F, '<', 'file.out')) { print "Opened unreadable file! Skipping related tests.\n"; close($F); } else { $ERR_unreadable_file = "$!"; } unlink('file.out') or die "Failed to delete file.out: $!\n"; $_ = `/bin/sh -c 'bad-command 2>&1'`; if ($? == 0) { print "Invoked invalid file! Skipping related tests.\n"; } else { s/\r?\n//g; s/bad-command/#CMDNAME#/g; $ERR_command_not_found = $_; } $loc and POSIX::setlocale(&POSIX::LC_ALL, $loc); $ENV{LC_ALL} = $origENV{LC_ALL}; $ENV{LANG} = $origENV{LANG}; $ENV{LANGUAGE} = $origENV{LANGUAGE}; } # This is no longer used: we import config-flags.pm instead # sub parse_status # { # if (open(my $fh, '<', "$_[0]/config.status")) { # while (my $line = <$fh>) { # $line =~ m/^[SD]\["([^\"]+)"\]=" *(.*)"/ and $CONFIG_FLAGS{$1} = $2; # } # return 1; # } # return 0; # } sub find_prog { my $prog = $_[0]; my ($v, $d, $f) = File::Spec->splitpath($prog); # If there's no directory then we need to search the PATH if (! $d) { foreach my $e (File::Spec->path()) { $prog = File::Spec->catfile($e, $f); if (-x $prog) { ($v, $d, $f) = File::Spec->splitpath($prog); last; } } } return ($v, $d, $f); } sub get_config { return exists($CONFIG_FLAGS{$_[0]}) ? $CONFIG_FLAGS{$_[0]} : ''; } sub set_more_defaults { my $string; # Try to find and load config-flags.pm. They may be in the local directory # or in the $srcpath if we're remote. my $d = $cwd; my $cfg = File::Spec->catfile($d, 'config-flags.pm'); if (! -f $cfg) { # Nope, so look in the srcpath my $d = $srcpath; $cfg = File::Spec->catfile($d, 'config-flags.pm'); } -f $cfg or die "Can't locate config-flags.pm in $cwd" . ($cwd eq $srcpath ? '' : " or $srcpath") . "\n"; unshift(@INC, $d); require "config-flags.pm"; # Find the full pathname of Make. For DOS systems this is more # complicated, so we ask make itself. if ($osname eq 'VMS') { $port_type = 'VMS-DCL' unless defined $ENV{"SHELL"}; # On VMS pre-setup make to be found with simply 'make'. $make_path = 'make'; } else { create_file('make.mk', 'all:;$(info $(MAKE))'); my $mk = `$make_path -sf make.mk`; unlink('make.mk'); $mk =~ s/\r?\n$//; $mk or die "FATAL ERROR: Cannot determine the value of \$(MAKE)\n"; $make_path = $mk; } ($mpv, $mpd, $mpf) = File::Spec->splitpath($make_path); # Ask make what shell to use create_file('shell.mk', 'all:;$(info $(SHELL))'); $sh_name = `$make_path -sf shell.mk`; unlink('shell.mk'); $sh_name =~ s/\r?\n$//; if (! $sh_name) { print "Cannot determine shell\n"; $is_posix_sh = 0; } else { my $o = `$sh_name -c ': do nothing' 2>&1`; $is_posix_sh = $? == 0 && $o eq ''; } $string = `$make_path -v`; $string =~ /^(GNU Make [^,\n]*)/ or die "$make_path is not GNU Make. Version:\n$string"; $testee_version = "$1\n"; create_file('null.mk', ''); my $redir = '2>&1'; $redir = '' if os_name eq 'VMS'; $string = `$make_path -f null.mk $redir`; if ($string =~ /(.*): \*\*\* No targets\. Stop\./) { $make_name = $1; } else { $make_name = $mpf; } # prepend pwd if this is a relative path (ie, does not # start with a slash, but contains one). Thanks for the # clue, Roland. if ($mpd && !File::Spec->file_name_is_absolute($make_path) && $cwdvol eq $mpv) { $mkpath = File::Spec->catpath($cwdvol, File::Spec->catdir($cwd, $mpd), $mpf); } else { $mkpath = $make_path; } # Find the helper tool $helptool = File::Spec->catfile($srcpath, 'thelp.pl'); # It's difficult to quote this properly in all the places it's used so # ensure it doesn't need to be quoted. $helptool =~ s,\\,/,g if $port_type eq 'W32'; $helptool =~ s, ,\\ ,g; # Get Purify log info--if any. if (exists $ENV{PURIFYOPTIONS} && $ENV{PURIFYOPTIONS} =~ /.*-logfile=([^ ]+)/) { $pure_log = $1 || ''; $pure_log =~ s/%v/$make_name/; $purify_errors = 0; } $string = `$make_path -j 2 -f null.mk $redir`; if ($string =~ /not supported/) { $parallel_jobs = 0; } else { $parallel_jobs = 1; } unlink('null.mk'); create_file('features.mk', 'all:;$(info $(.FEATURES))'); %FEATURES = map { $_ => 1 } split /\s+/, `$make_path -sf features.mk`; print "$make_path FEATURES: @{[%FEATURES]}\n" if $verbose; unlink('features.mk'); # Find the default values for different built-in variables my $s = "all:;\n"; foreach (keys %DEFVARS) { $s .= "\$(info $_=\$($_))\n"; } create_file('defvars.mk', $s); foreach (split "\n", `$make_path -sf defvars.mk`) { my @e = split /=/, $_, 2; $DEFVARS{$e[0]} = $e[1]; } unlink('defvars.mk'); # Set up for valgrind, if requested. @make_command = ($make_path); if ($valgrind) { my $args = $valgrind_args; open(VALGRIND, "> valgrind.out") or die "Cannot open valgrind.out: $!\n"; # -q --leak-check=yes exists $ENV{VALGRIND_ARGS} and $args = $ENV{VALGRIND_ARGS}; @make_command = ('valgrind', '--log-fd='.fileno(VALGRIND)); push(@make_command, split(' ', $args)); push(@make_command, $make_path); # F_SETFD is 2 fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n"; system("echo Starting on `date` 1>&".fileno(VALGRIND)); print "Enabled valgrind support.\n"; } if ($debug) { print "Port type: $port_type\n"; print "Make command: @make_command\n"; print "Shell path: $sh_name".($is_posix_sh ? ' (POSIX)' : '')."\n"; print "#PWD#: $cwdpath\n"; print "#PERL#: $perl_name\n"; print "#MAKEPATH#: $mkpath\n"; print "#MAKE#: $make_name\n"; } } sub setup_for_test { $makefile = &get_tmpfile; if (-f $makefile) { unlink $makefile; } # Get rid of any Purify logs. if ($pure_log) { ($pure_testname = $testname) =~ tr,/,_,; $pure_testname = "$pure_log.$pure_testname"; system("rm -f $pure_testname*"); print("Purify testfiles are: $pure_testname*\n") if $debug; } } exit !&toplevel; ================================================ FILE: tests/scripts/features/archives ================================================ # -*-mode: perl-*- $description = "Test GNU Make's archive management features."; $details = "\ This only works on systems that support it."; # If this instance of make doesn't support archives, skip it exists $FEATURES{archives} or return -1; # In theory archive support exists on Windows but it doesn't use ar; # someone will need to port this test. $port_type eq 'W32' and return -1; # Create some .o files to work with if ($osname eq 'VMS') { # VMS AR needs real object files at this time. foreach $afile ('a1', 'a2', 'a3') { # Use non-standard extension to prevent implicit rules from recreating # objects when the test tampers with the timestamp. 1 while unlink "$afile.c1"; 1 while unlink "$afile.o"; create_file("$afile.c1", "int $afile(void) {return 1;}\n"); system("cc $afile.c1 /object=$afile.o"); } } else { utouch(-60, qw(a1.o a2.o a3.o)); } # Fallback if configure did not find AR my $ar = get_config('AR') || 'ar'; my $redir = '2>&1'; $redir = '' if $osname eq 'VMS'; # This is the value from src/default.c my $arflags = $osname eq 'aix' ? '-Xany -rv' : '-rv'; my $arvar = "AR=\"$ar\""; # Newer versions of binutils can be built with --enable-deterministic-archives # which forces all timestamps (among other things) to always be 0, defeating # GNU Make's archive support. See if ar supports the U option to disable it. unlink('libxx.a'); $_ = `$ar ${arflags}U libxx.a a1.o $redir`; if ($? == 0) { $arflags = "${arflags}U"; $arvar = "$arvar ARFLAGS=\"$arflags\""; } # Some versions of ar print different things on creation. Find out. unlink('libxx.a'); my $created = `$ar $arflags libxx.a a1.o $redir`; $created =~ s/a1\.o/#OBJECT#/g; # Some versions of ar print different things on add. Find out. my $add = `$ar $arflags libxx.a a2.o $redir`; $add =~ s/a2\.o/#OBJECT#/g; # Some versions of ar print different things on replacement. Find out. my $repl = `$ar $arflags libxx.a a2.o $redir`; $repl =~ s/a2\.o/#OBJECT#/g; unlink('libxx.a'); # Very simple ($_ = $created) =~ s/#OBJECT#/a1.o/g; my $answer = "$ar $arflags libxx.a a1.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a1.o'; } run_make_test('all: libxx.a(a1.o)', $arvar, $answer); # Multiple .o's. Add a new one to the existing library ($_ = $add) =~ s/#OBJECT#/a2.o/g; $answer = "$ar $arflags libxx.a a2.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a2.o'; } run_make_test('all: libxx.a(a1.o a2.o)', $arvar, $answer); # Touch one of the .o's so it's rebuilt if ($port_type eq 'VMS-DCL') { # utouch is not changing what VMS library compare is testing for. # So do a real change by regenerating the file. 1 while unlink('a1.o'); # Later time stamp than last insertion. sleep(2); system('cc a1.c1 /object=a1.o'); # Next insertion will have a later timestamp. sleep(2); } else { utouch(-40, 'a1.o'); } ($_ = $repl) =~ s/#OBJECT#/a1.o/g; $answer = "$ar $arflags libxx.a a1.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a1.o'; } run_make_test(undef, $arvar, $answer); # Use wildcards $answer = "#MAKE#: Nothing to be done for 'all'.\n"; run_make_test('all: libxx.a(*.o)', $arvar, $answer); # Touch one of the .o's so it's rebuilt if ($port_type eq 'VMS-DCL') { # utouch is not changing what VMS library compare is testing for. # So do a real change by regenerating the file. 1 while unlink('a1.o'); # Make timestamp later than last insertion. sleep(2); system('cc a1.c1 /object=a1.o'); } else { utouch(-30, 'a1.o'); } ($_ = $repl) =~ s/#OBJECT#/a1.o/g; $answer = "$ar $arflags libxx.a a1.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a1.o'; } run_make_test(undef, $arvar, $answer); # Use both wildcards and simple names if ($port_type eq 'VMS-DCL') { # utouch is not changing what VMS library compare is testing for. # So do a real change by regenerating the file. 1 while unlink('a2.o'); sleep(2); system('cc a2.c1 /object=a2.o'); } else { utouch(-50, 'a2.o'); } ($_ = $add) =~ s/#OBJECT#/a3.o/g; $_ .= "$ar $arflags libxx.a a2.o\n"; ($_ .= $repl) =~ s/#OBJECT#/a2.o/g; $answer = "$ar $arflags libxx.a a3.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a3.o'; } run_make_test('all: libxx.a(a3.o *.o)', $arvar, $answer); # Check whitespace handling if ($port_type eq 'VMS-DCL') { # utouch is not changing what VMS library compare is testing for. # So do a real change by regenerating the file. 1 while unlink('a2.o'); sleep(2); system('cc a2.c1 /object=a2.o'); } else { utouch(-40, 'a2.o'); } ($_ = $repl) =~ s/#OBJECT#/a2.o/g; $answer = "$ar $arflags libxx.a a2.o\n$_"; if ($port_type eq 'VMS-DCL') { $answer = 'library /replace libxx.a a2.o'; } run_make_test('all: libxx.a( a3.o *.o )', $arvar, $answer); rmfiles(qw(a1.c1 a2.c1 a3.c1 a1.o a2.o a3.o libxx.a)); # Check non-archive targets # See Savannah bug #37878 $mk_string = q! all: foo(bar).baz foo(bar).baz: ; @echo '$@' !; if ($port_type eq 'VMS-DCL') { $mk_string =~ s/echo/write sys\$\$output/; $mk_string =~ s/\'/\"/g; } run_make_test($mk_string, $arvar, "foo(bar).baz\n"); # Check renaming of archive targets. # See Savannah bug #38442 mkdir('artest', 0777); touch('foo.vhd'); $mk_string = q! DIR = artest vpath % $(DIR) default: lib(foo) (%): %.vhd ; @cd $(DIR) && touch $(*F) && $(AR) $(ARFLAGS) $@ $(*F) >/dev/null 2>&1 && rm $(*F) .PHONY: default !; if ($port_type eq 'VMS-DCL') { $mk_string =~ s#= artest#= sys\$\$disk:\[.artest\]#; $mk_string =~ s#lib\(foo\)#lib.tlb\(foo\)#; $mk_string =~ s#; \@cd#; pipe SET DEFAULT#; $mk_string =~ s#touch \$\(\*F\)#touch \$\(\*F\) && library/create/text sys\$\$disk:\$\@#; $mk_string =~ s#library#if f\$\$search(\"\$\@\") \.eqs\. \"\" then library#; # VMS needs special handling for null extension $mk_string =~ s#\@ \$\(\*F\)#\@ \$\(\*F\)\.#; $mk_string =~ s#>/dev/null 2>&1 ##; } run_make_test($mk_string, $arvar, ""); run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); unlink('foo.vhd'); if ($osname eq 'VMS') { remove_directory_tree("$cwdpath/artest"); } else { remove_directory_tree('artest'); } # Check long names for archive members. # See Savannah bug #54395 if ($osname ne 'VMS' && $osname ne 'os390') { my $pre = '1234567890123456'; my $lib = 'libxx.a'; my $cr = $created; $cr =~ s/#OBJECT#/${pre}a/g; my $ad = $add; $ad =~ s/#OBJECT#/${pre}b/g; run_make_test(qq! # Both member names > 16 characters long default: $lib(${pre}a) $lib(${pre}b) (%): % ; \$(AR) \$(ARFLAGS) \$@ \$% $pre%: ; touch \$\@ !, $arvar, "touch ${pre}a\n$ar $arflags $lib ${pre}a\n${cr}touch ${pre}b\n$ar $arflags $lib ${pre}b\n${ad}rm ${pre}a ${pre}b\n"); # Run it again; nothing should happen run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); unlink($lib); } # SV 61436 : Allow redefining archive rules to propagate timestamps # These don't work right on z/OS for some reason: archives not fully supported? if ($osname ne 'os390') { # Find the output when creating an archive from multiple files utouch(-10, 'a.o', 'b.o'); my $create2 = `$ar $arflags mylib.a a.o b.o $redir`; touch('b.o'); my $add2 = `$ar $arflags mylib.a b.o $redir`; unlink('a.o', 'b.o', 'mylib.a'); # Some systems complain when compiling empty files create_file('a.c', 'int i;'); create_file('b.c', 'int j;'); utouch(-20, 'a.c', 'b.c'); my $cc = get_config('CC') || 'cc'; my $vars = "CC=\"$cc\" $arvar"; run_make_test(q! mylib.a: mylib.a(a.o b.o) (%): % ; %.a: ; $(AR) $(ARFLAGS) $@ $? %.o : %.c ; @echo Compile $<; $(COMPILE.c) -o $@ $< !, $vars, "Compile a.c\nCompile b.c\n$ar $arflags mylib.a a.o b.o\n${create2}rm b.o a.o"); run_make_test(undef, $vars, "#MAKE#: 'mylib.a' is up to date."); # Now update one of the source files and it should be compiled and archived sleep(2); touch('b.c'); run_make_test(undef, $vars, "Compile b.c\n$ar $arflags mylib.a b.o\n${add2}rm b.o"); run_make_test(undef, $vars, "#MAKE#: 'mylib.a' is up to date."); unlink('a.c', 'b.c', 'a.o', 'b.o', 'mylib.a'); } # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/comments ================================================ $description = "The following test creates a makefile to test comments\n" ."and comment continuation to the next line using a \n" ."backslash within makefiles."; $details = "To test comments within a makefile, a semi-colon was placed \n" ."after a comment was started. This should not be reported as\n" ."an error since it is within a comment. We then continue the \n" ."comment to the next line using a backslash. To test whether\n" ."the comment really continued, we place an echo command with some\n" ."text on the line which should never execute since it should be \n" ."within a comment\n"; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE <<\EOF; # Test comment vs semicolon parsing and line continuation target: # this ; is just a comment \ @echo This is within a comment. @echo There should be no errors for this makefile. EOF # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile); # Create the answer to what should be produced by this Makefile $answer = "There should be no errors for this makefile.\n"; # COMPARE RESULTS &compare_output($answer,&get_logfile(1)); 1; ================================================ FILE: tests/scripts/features/conditionals ================================================ # -*-perl-*- $description = "Check GNU Make conditionals."; $details = "Attempt various different flavors of GNU Make conditionals."; run_make_test(' arg1 = first arg2 = second arg3 = third arg4 = cc arg5 = second all: ifeq ($(arg1),$(arg2)) @echo arg1 equals arg2 else @echo arg1 NOT equal arg2 endif ifeq \'$(arg2)\' "$(arg5)" @echo arg2 equals arg5 else @echo arg2 NOT equal arg5 endif ifneq \'$(arg3)\' \'$(arg4)\' @echo arg3 NOT equal arg4 else @echo arg3 equal arg4 endif ifndef undefined @echo variable is undefined else @echo variable undefined is defined endif ifdef arg4 @echo arg4 is defined else @echo arg4 is NOT defined endif', '', 'arg1 NOT equal arg2 arg2 equals arg5 arg3 NOT equal arg4 variable is undefined arg4 is defined'); # Test expansion of variables inside ifdef. run_make_test(' foo = 1 FOO = foo F = f DEF = no DEF2 = no ifdef $(FOO) DEF = yes endif ifdef $(F)oo DEF2 = yes endif DEF3 = no FUNC = $1 ifdef $(call FUNC,DEF)3 DEF3 = yes endif all:; @echo DEF=$(DEF) DEF2=$(DEF2) DEF3=$(DEF3)', '', 'DEF=yes DEF2=yes DEF3=yes'); # Test all the different "else if..." constructs run_make_test(' arg1 = first arg2 = second arg3 = third arg4 = cc arg5 = fifth result = ifeq ($(arg1),$(arg2)) result += arg1 equals arg2 else ifeq \'$(arg2)\' "$(arg5)" result += arg2 equals arg5 else ifneq \'$(arg3)\' \'$(arg3)\' result += arg3 NOT equal arg4 else ifndef arg5 result += variable is undefined else ifdef undefined result += arg4 is defined else result += success endif all: ; @echo $(result)', '', 'success'); # Test some random "else if..." construct nesting run_make_test(' arg1 = first arg2 = second arg3 = third arg4 = cc arg5 = second ifeq ($(arg1),$(arg2)) $(info failed 1) else ifeq \'$(arg2)\' "$(arg2)" ifdef undefined $(info failed 2) else $(info success) endif else ifneq \'$(arg3)\' \'$(arg3)\' $(info failed 3) else ifdef arg5 $(info failed 4) else ifdef undefined $(info failed 5) else $(info failed 6) endif .PHONY: all all: ; @:', '', 'success'); # SV 47960 : ensure variable assignments in non-taken legs don't cause problems run_make_test(' ifneq ($(FOO),yes) target: else BAR = bar target: endif @echo one ', '', "one\n"); # SV 64085: Ensure recipe prefixed conditionals are never considered run_make_test(q! blah=1 ifdef blah else else endif all:; !, '', "#MAKE#: 'all' is up to date."); run_make_test(q! blah=1 ifdef blah else endif endif all:; !, '', "#MAKE#: 'all' is up to date."); run_make_test(q! blah=1 ifdef blah else ifdef blah endif all:; !, '', "#MAKE#: 'all' is up to date."); run_make_test(q! blah=1 all:; foo: ifdef blah ifdef blah endif !, '', "#MAKE#: 'all' is up to date."); run_make_test(q! blah=1 all:; foo: ifdef blah endif endif !, '', "#MAKE#: 'all' is up to date."); run_make_test(q! blah=1 all:; foo: ifdef blah else else endif !, '', "#MAKE#: 'all' is up to date."); # SV 64402: parse braces in ifeq/ifneq properly run_make_test(q! ifeq ($(and a,b),) endif ifeq (${and a,b},) endif ifeq (${and $(x),${or $(z),${q}}},) endif ifeq (${and ),(},) endif ifeq ($(and },{),) endif # We can hide the comma in a variable C = , ifeq ((and a$Cb),) endif all:; !, '', "#MAKE#: 'all' is up to date."); # The "," in "$," is a variable name not a comma run_make_test(q! ifeq ($,,) $(info ok) endif all:; !, '', "ok\n#MAKE#: 'all' is up to date."); # Without variable references we don't do anything special with parens run_make_test(q! ifeq ((and a,b),) endif all:; !, '', "#MAKEFILE#:2: extraneous text after 'ifeq' directive\n#MAKE#: 'all' is up to date."); # This tells the test driver that the perl test script executed properly. 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/features/default_names ================================================ # -*-perl-*- $description = "This script tests to make sure that Make looks for default makefiles in the correct order (GNUmakefile,makefile,Makefile)"; # Create a makefile called "GNUmakefile" $makefile = "GNUmakefile"; open(MAKEFILE,"> $makefile"); print MAKEFILE "FIRST: ; \@echo It chose GNUmakefile\n"; close(MAKEFILE); # Create another makefile called "makefile" open(MAKEFILE,"> makefile"); print MAKEFILE "SECOND: ; \@echo It chose makefile\n"; close(MAKEFILE); # DOS/W32/MacOSX platforms are case-insensitive / case-preserving, so # Makefile is the same file as makefile. Just test what we can here. my $case_sensitive = 0; if (! -f 'Makefile') { # Create another makefile called "Makefile" $case_sensitive = 1; open(MAKEFILE,"> Makefile"); print MAKEFILE "THIRD: ; \@echo It chose Makefile\n"; close(MAKEFILE); } run_make_with_options("","",&get_logfile); compare_output("It chose GNUmakefile\n",&get_logfile(1)); unlink($makefile); run_make_with_options("","",&get_logfile); compare_output("It chose makefile\n",&get_logfile(1)); unlink("makefile"); if ($case_sensitive) { run_make_with_options("","",&get_logfile); compare_output("It chose Makefile\n",&get_logfile(1)); unlink("Makefile"); } 1; ================================================ FILE: tests/scripts/features/dircache ================================================ # -*-mode: perl-*- $description = "Test the directory cache behavior."; # The first wildcard should bring the entire directory into the cache Then we # create a new file "behind make's back" then see if the next wildcard detects # it. run_make_test(q! _orig := $(wildcard ./*) $(shell echo > anewfile) _new := $(wildcard ./*) $(info diff=$(filter-out $(_orig),$(_new))) all:;@: !, '', "diff=./anewfile\n"); rmfiles('anewfile'); run_make_test(q! _orig := $(wildcard ./*) $(file >anewfile) _new := $(wildcard ./*) $(info diff=$(filter-out $(_orig),$(_new))) all:;@: !, '', "diff=./anewfile\n"); rmfiles('anewfile'); 1; ================================================ FILE: tests/scripts/features/double_colon ================================================ # -*-perl-*- $description = "Test handling of double-colon rules."; $details = "\ We test these features: - Multiple commands for the same (double-colon) target - Different prerequisites for targets: only out-of-date ones are rebuilt. - Double-colon targets that aren't the goal target. Then we do the same thing for parallel builds: double-colon targets should always be built serially."; # TEST 0: A simple double-colon rule that isn't the goal target. run_make_test(q! all: baz foo:: f1.h ; @echo foo FIRST foo:: f2.h ; @echo foo SECOND bar:: ; @echo aaa; sleep 1; echo aaa done bar:: ; @echo bbb baz:: ; @echo aaa baz:: ; @echo bbb biz:: ; @echo aaa biz:: two ; @echo bbb two: ; @echo two f1.h f2.h: ; @echo $@ d :: ; @echo ok d :: d ; @echo oops !, "all", "aaa\nbbb\n"); # TEST 1: As above, in parallel if ($parallel_jobs) { run_make_test(undef, "-j10 all", "aaa\nbbb\n"); } # TEST 2: A simple double-colon rule that is the goal target run_make_test(undef, "bar", "aaa\naaa done\nbbb\n"); # TEST 3: As above, in parallel if ($parallel_jobs) { run_make_test(undef, "-j10 bar", "aaa\naaa done\nbbb\n"); } # TEST 4: Each double-colon rule is supposed to be run individually &utouch(-5, 'f2.h'); &touch('foo'); run_make_test(undef, "foo", "f1.h\nfoo FIRST\n"); # TEST 5: Again, in parallel. if ($parallel_jobs) { run_make_test(undef, "-j10 foo", "f1.h\nfoo FIRST\n"); } # TEST 6: Each double-colon rule is supposed to be run individually &utouch(-5, 'f1.h'); unlink('f2.h'); &touch('foo'); run_make_test(undef, "foo", "f2.h\nfoo SECOND\n"); # TEST 7: Again, in parallel. if ($parallel_jobs) { run_make_test(undef, "-j10 foo", "f2.h\nfoo SECOND\n"); } # TEST 8: Test circular dependency check; PR/1671 run_make_test(undef, "d", "ok\n$make_name: circular d <- d dependency dropped\noops\n"); # TEST 8: I don't grok why this is different than the above, but it is... # # Hmm... further testing indicates this might be timing-dependent? # #if ($parallel_jobs) { # run_make_test(undef, "-j10 biz", "aaa\ntwo\nbbb\n"); #} unlink('foo','f1.h','f2.h'); # TEST 9: make sure all rules in s double colon family get executed # (Savannah bug #14334). # &touch('one'); &touch('two'); run_make_test(' .RECIPEPREFIX = > .PHONY: all all: result result:: one > @echo $^ >>$@ > @echo $^ result:: two > @echo $^ >>$@ > @echo $^ ', '', 'one two'); unlink('result','one','two'); # TEST 10: SV 33399 : check for proper backslash handling run_make_test(' a\ xb :: ; @echo one a\ xb :: ; @echo two ', '', "one\ntwo\n"); # Test 11: SV 44742 : All double-colon rules should be run in parallel build. run_make_test(' .RECIPEPREFIX = > result :: 01 > @echo update > @touch $@ result :: 02 > @echo update > @touch $@ result :: 03 > @echo update > @touch $@ result :: 04 > @echo update > @touch $@ result :: 05 > @echo update > @touch $@ 01 02 03 04 05: > @touch 01 02 03 04 05 ', '-j10 result', "update\nupdate\nupdate\nupdate\nupdate\n"); unlink('result', '01', '02', '03', '04', '05'); # Test 12: SV 44742 : Double-colon rules with parallelism run_make_test(' root: all ; echo root all:: ; echo all_one all:: 3 ; echo all_two %: ; sleep $* ', '-rs -j2 1 2 root', "all_one\nall_two\nroot\n"); # SV 47995 : Parallel double-colon rules with FORCE run_make_test(' all:: ; @echo one all:: joe ; @echo four joe: FORCE ; touch joe-is-forced FORCE: ', '-j5', "one\ntouch joe-is-forced\nfour\n"); unlink('joe-is-forced'); # sv 60188. # Even though test.x is explicitly mentioned, terminal pattern rules still # apply only if the prerequisite exists. touch('hello.z'); # subtest 1. test.x is explicitly mentioned. run_make_test(q! all: hello.z %.z:: test.x ; touch $@ %.x: ; !, '', "#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.z'); # subtest 2. hello.x is derived from the stem. touch('hello.z'); run_make_test(q! all: hello.z %.z:: %.x; touch $@ %.x: ; touch $@ !, '', "#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.z'); # subtest 3 # hello.x is explicitly mentioned on an unrelated rule and thus is not an # intermediate file. # Terminal pattern rules do not apply anyway and there is no rule to built # 'hello.x'. touch('hello.z'); run_make_test(q! all: hello.z %.z:: %.x; touch $@ %.x: ; unrelated: hello.x !, '', "#MAKE#: *** No rule to make target 'hello.x', needed by 'hello.z'. Stop.\n", 512); # SV 64016. # Test that update_goal_chain moves to the next target while the current # target is being built: hello.x recipe is started and update_goal_chain # begins to update bye.x. run_make_test(q! hello.x::; @#HELPER# -q wait bye.x out $@ bye.x::; @#HELPER# sleep 1 file $@ !, '-j2 hello.x bye.x', "sleep 1\nfile bye.x\nhello.x"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/echoing ================================================ # -*-perl-*- $description = "The following test creates a makefile to test command echoing. It tests that when a command line starts with a '\@', the echoing of that line is suppressed. It also tests the -n option which tells make to ONLY echo the commands and no execution happens. In this case, even the commands with '\@' are printed. Lastly, it tests the -s flag which tells make to prevent all echoing, as if all commands started with a '\@'."; $details = "This test is similar to the 'clean' test except that a '\@' has been placed in front of the delete command line. Four tests are run here. First, make is run normally and the first echo command should be executed. In this case there is no '\@' so we should expect make to display the command AND display the echoed message. Secondly, make is run with the clean target, but since there is a '\@' at the beginning of the command, we expect no output; just the deletion of a file which we check for. Third, we give the clean target again except this time we give make the -n option. We now expect the command to be displayed but not to be executed. In this case we need only to check the output since an error message would be displayed if it actually tried to run the delete command again and the file didn't exist. Lastly, we run the first test again with the -s option and check that make did not echo the echo command before printing the message.\n"; $example = "EXAMPLE_FILE"; touch($example); # TEST #1 # ------- run_make_test(" all: \techo This makefile did not clean the dir... good clean: \t\@$CMD_rmfile $example\n", '', 'echo This makefile did not clean the dir... good This makefile did not clean the dir... good'); # TEST #2 # ------- run_make_test(undef, 'clean', ''); if (-f $example) { $test_passed = 0; unlink($example); } # TEST #3 # ------- run_make_test(undef, '-n clean', "$CMD_rmfile $example\n"); # TEST #4 # ------- run_make_test(undef, '-s', "This makefile did not clean the dir... good\n"); 1; ================================================ FILE: tests/scripts/features/errors ================================================ # -*-perl-*- $description = "Test ignored failures in recipe command lines"; run_make_test(qq! one: \t-exit 1 \texit 0 two: \texit 1 \texit 0 !, "one", "exit 1\n#MAKE#: [#MAKEFILE#:3: one] Error 1 (ignored)\nexit 0\n"); # TEST #1 # ------- run_make_test(undef, " -i two", "exit 1\n#MAKE#: [#MAKEFILE#:6: two] Error 1 (ignored)\nexit 0\n"); # TEST #2 # ------- # Test that error line offset works run_make_test(qq! all: \t\@echo hi \t\@echo there \t\@exit 1 !, '', "hi\nthere\n#MAKE#: *** [#MAKEFILE#:5: all] Error 1", 512); # Windows error look completely different :-/ sub errors_getinfo { my ($cmd, $args, $err) = @_; if ($port_type eq 'W32') { return (2, "process_begin: CreateProcess(NULL, $cmd$args, ...) failed.\nmake (e=2): The system cannot find the file specified."); } if (!$err) { $err = $ERR_no_such_file; } return (127, "#MAKE#: $cmd: $err"); } # TEST #3 # ------- # Try failing due to unknown command my $unk = './foobarbazbozblat'; unlink($unk); my ($ernum, $erstr) = errors_getinfo($unk, " xx yy"); run_make_test(qq! one: ; -$unk xx yy !, 'one', "$unk xx yy\n$erstr\n#MAKE#: [#MAKEFILE#:2: one] Error $ernum (ignored)\n"); # TEST #4 # ------- ($ernum, $erstr) = errors_getinfo($unk, " aa bb"); run_make_test(qq! two: ; $unk aa bb !, 'two -i', "$unk aa bb\n$erstr\n#MAKE#: [#MAKEFILE#:2: two] Error $ernum (ignored)\n"); # TEST #5 # ------- run_make_test(undef, 'two', "$unk aa bb\n$erstr\n#MAKE#: *** [#MAKEFILE#:2: two] Error $ernum\n", 512); # SV #56918 : Test the unknown command as the second recipe line ($ernum, $erstr) = errors_getinfo($unk, " qq rr"); run_make_test(qq! three: \t\@echo one \t$unk qq rr !, 'three', "one\n$unk qq rr\n$erstr\n#MAKE#: *** [#MAKEFILE#:4: three] Error $ernum\n", 512); # Try failing due to non-executable file if ($ERR_nonexe_file) { my $noexe = './barfooblatboz'; touch($noexe); run_make_test(qq! one: ; -$noexe xx yy two: ; $noexe aa bb !, 'one', "$noexe xx yy\n#MAKE#: $noexe: $ERR_nonexe_file\n#MAKE#: [#MAKEFILE#:2: one] Error 127 (ignored)\n"); unlink($noexe); } # Try failing by "running" a directory if ($ERR_exe_dir) { mkdir('sd', 0775) or print "mkdir: sd: $!\n"; ($ernum, $erstr) = errors_getinfo('sd', '', $ERR_exe_dir); run_make_test(q! PATH := . all: ; sd !, '', "sd\n$erstr\n#MAKE#: *** [#MAKEFILE#:3: all] Error $ernum", 512); if ($port_type eq 'W32') { $ernum = 5; $erstr = "process_begin: CreateProcess(NULL, ./sd, ...) failed.\nmake (e=5): Access is denied."; } else { $ernum = 127; $erstr = "#MAKE#: ./sd: $ERR_exe_dir"; } run_make_test(q! all: ; ./sd !, '', "./sd\n$erstr\n#MAKE#: *** [#MAKEFILE#:2: all] Error $ernum", 512); rmdir('sd'); } 1; ================================================ FILE: tests/scripts/features/escape ================================================ # -*-perl-*- $description = "Test various types of escaping in makefiles."; $details = "\ Make sure that escaping of ':' works in target names. Make sure escaping of whitespace works in target names. Make sure that escaping of '#' works. Make sure that backslash before non-special characters are kept."; # TEST 1 run_make_test(q! ifdef NOESC path = pre: endif ifdef ONEESC path = pre\: endif ifdef TWOESC path = pre\\\\: endif $(path)foo : ; @echo "touch ($@)" foo\ bar: ; @echo "touch ($@)" sharp: foo\#bar.ext foo\#bar.ext: ; @echo "foo#bar.ext = ($@)" !, '', 'touch (foo)'); # TEST 2: This one should fail, since the ":" is unquoted. run_make_test(undef, 'NOESC=1', "#MAKEFILE#:12: *** target pattern contains no '%'. Stop.", 512); # TEST 3: This one should work, since we escape the ":". run_make_test(undef, 'ONEESC=1', 'touch (pre:foo)'); # TEST 4: This one should fail, since the escape char is escaped. run_make_test(undef, 'TWOESC=1', "#MAKEFILE#:12: *** target pattern contains no '%'. Stop.", 512); # TEST 5: This one should work run_make_test(undef, ['foo bar'], 'touch (foo bar)'); # TEST 6: Test escaped comments run_make_test(undef, 'sharp', 'foo#bar.ext = (foo#bar.ext)'); # Test escaped colons in prerequisites # Quoting of backslashes in q!! is kind of messy. # Solaris sh does not properly handle backslashes even in '' so just # check the output make prints, not what the shell interprets. run_make_test(q! foo: foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar foo foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar: ; : '$@' !, '', ": 'foo:bar'\n: 'foo\\:bar'\n: 'foo\\\\:bar'\n: 'foo'\n"); # Test backslash before non-special chars: should be kept as-is run_make_test(q! all: ..\foo .DEFAULT: ; : '$@' !, '', ": '..\\foo'\n"); # Test escaped comments in variable assignments run_make_test(q! self = $1 foo := $(call self,#foo#)#foo bar := $(call self,\#bar\#)#bar all:;@echo '$(foo) $(bar)' !, '',"#foo# \\#bar\\#"); # Test escaped comments in variable assignments in a variable run_make_test(q! C = \# self = $1 foo := $(call self,$Cfoo$C)#foo all:;@echo '$(foo)' !, '',"#foo#"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/exec ================================================ # -*-perl-*- use warnings; my $description = "Test that make can execute binaries as well as scripts with" ." various shabangs and without a shbang"; my $details = "The various shells that this test uses are the default" ." /bin/sh, \$SHELL and the perl interpreter that is" ." executing this test program. The shells are used for the value" ." of SHELL inside the test makefile and also as a shbang in the" ." executed script. There is also a test which executes a script" ." that has no shbang."; # Only bother with this on UNIX systems $port_type eq 'UNIX' or return -1; $^O =~ /cygwin/ and return -1; my @shbangs = ('#!/bin/sh', "#!$perl_name"); # The exec in Valgrind's VM doesn't allow starting commands without any shbang $valgrind or push @shbangs, ''; my @shells = ('', 'SHELL=/bin/sh'); # Try whatever shell the user has, as long as it's not a C shell. # The C shell is not usable with make, due to not correctly handling # file descriptors and possibly other issues. my $usersh = $origENV{SHELL}; if ($usersh !~ /csh/) { push @shbangs, ("#!$usersh"); push @shells, ("SHELL=$usersh"); } my $answer = 'hello, world'; # tests [0-11] # Have a makefile with various SHELL= exec a shell program with varios # shbangs or without a shbang at all. my $stem = './exec.cmd'; my $k = 0; for my $shbang (@shbangs) { for my $shell (@shells) { my $cmd = $k ? "$stem.$k" : $stem; ++$k; unlink $cmd; open(CMD,"> $cmd"); print CMD "$shbang\n"; print CMD "printf \"$answer\\n\";\n"; close(CMD); chmod 0700, $cmd; run_make_test("# shbang=$shbang\n# shell=$shell" . q! all:; @$(CMD) !, "$shell CMD=$cmd", "$answer\n"); rmfiles($cmd); } } # tests [12-14] # Exec a binary from a makefile that has SHELL=. for my $shell (@shells) { run_make_test(q! all:; @#PERL# -e 'printf "$(ANSWER)\n"'; !, "$shell ANSWER='$answer'", "$answer\n"); } # test 15 # Use perl as a shell. run_make_test(q! SHELL = #PERL# .SHELLFLAGS = -e all:; @printf "$(ANSWER)\n"; !, "ANSWER='$answer'", "$answer\n"); 1; ================================================ FILE: tests/scripts/features/expand ================================================ # -*-perl-*- $description = "Test variable expansion."; # sv 64124. # Expand a variable whose value exceeds 200 bytes. # 200 is the initial size of variable_buffer. # Value bigger than 200 bytes causes a realloc of variable_buffer. # In this test the variable being expanded is MAKEFLAGS and its value occupies # 12, 600 and 120000 bytes. my $s = "hello_world\n"; my @mult = (1, 50, 10000); for my $m (@mult) { my $answer = $s x $m; $ENV{'MAKEFLAGS'} = " -- hello=$answer"; run_make_test(q! $(info x$(hello)y) all: !, '', "x${answer}y\n#MAKE#: Nothing to be done for 'all'.\n"); } # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/export ================================================ # -*-perl-*- $description = "Check GNU Make export/unexport commands."; $details = ""; # The test driver cleans out our environment for us so we don't have to worry # about that here. &run_make_test(' FOO = foo BAR = bar BOZ = boz export BAZ = baz export BOZ BITZ = bitz BOTZ = botz export BITZ BOTZ unexport BOTZ ifdef EXPORT_ALL export endif ifdef UNEXPORT_ALL unexport endif ifdef EXPORT_ALL_PSEUDO .EXPORT_ALL_VARIABLES: endif .RECIPEPREFIX := > all: > @echo "FOO=$(FOO) BAR=$(BAR) BAZ=$(BAZ) BOZ=$(BOZ) BITZ=$(BITZ) BOTZ=$(BOTZ)" > @echo "FOO=$$FOO BAR=$$BAR BAZ=$$BAZ BOZ=$$BOZ BITZ=$$BITZ BOTZ=$$BOTZ" ', '', "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 1: make sure vars inherited from the parent are exported $ENV{FOO} = 1; &run_make_test(undef, '', "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 2: global export. Explicit unexport takes precedence. run_make_test(undef, "EXPORT_ALL=1" , "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 3: global unexport. Explicit export takes precedence. &run_make_test(undef, "UNEXPORT_ALL=1", "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 4: both: in the above makefile the unexport comes last so that rules. &run_make_test(undef, "EXPORT_ALL=1 UNEXPORT_ALL=1", "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 5: test the pseudo target. &run_make_test(undef, "EXPORT_ALL_PSEUDO=1", "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 6: Test the expansion of variables inside export &run_make_test(' foo = f-ok bar = b-ok FOO = foo F = f BAR = bar B = b export $(FOO) export $(B)ar .RECIPEPREFIX := > all: > @echo foo=$(foo) bar=$(bar) > @echo foo=$$foo bar=$$bar ', "", "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n"); # TEST 7: Test the expansion of variables inside unexport &run_make_test(' foo = f-ok bar = b-ok FOO = foo F = f BAR = bar B = b export foo bar unexport $(FOO) unexport $(B)ar .RECIPEPREFIX := > all: > @echo foo=$(foo) bar=$(bar) > @echo foo=$$foo bar=$$bar ', '', "foo=f-ok bar=b-ok\nfoo= bar=\n"); # TEST 7: Test exporting multiple variables on the same line &run_make_test(' A = a B = b C = c D = d E = e F = f G = g H = h I = i J = j SOME = A B C export F G H I J export D E $(SOME) all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J ', '', "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n"); # TEST 8: Test unexporting multiple variables on the same line @args{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10); %ENV = (%ENV, %args); &run_make_test(' A = a B = b C = c D = d E = e F = f G = g H = h I = i J = j SOME = A B C unexport F G H I J unexport D E $(SOME) all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J ', '', "A= B= C= D= E= F= G= H= I= J=\n"); # TEST 9: Check setting a variable named "export" &run_make_test(' export = 123 export export export export = 456 a: ; @echo "\$$(export)=$(export) / \$$export=$$export" ', '', "\$(export)=456 / \$export=456\n"); # TEST 10: Check "export" as a target &run_make_test(' a: export export: ; @echo "$@" ', '', "export\n"); # Check export and assignment of a variable on the same line $ENV{hello} = 'moon'; run_make_test(q! all: ; @echo hello=$(hello) hello=$$hello export hello=sun !, '', "hello=sun hello=sun\n"); # Check unexport and assignment of a variable on the same line $ENV{hello} = 'moon'; run_make_test(q! all: ; @echo hello=$(hello) hello=$$hello unexport hello=sun !, '', "hello=sun hello=\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/grouped_targets ================================================ # -*-perl-*- $description = "This test is about grouped multiple targets indicated by &:"; $details = "Here we test for requirements like\n" ."- if multiple such targets are updated, the recipe is run once\n" ."- parsing issues related to the &: syntax itself\n"; # Parsing: &: allowed without any targets. run_make_test(q{ .PHONY: all &:; all: ;@printf '' }, '', ""); # Parsing: &: works not preceded by whitespace. run_make_test(q{ foo&:;@echo foo }, 'foo', "foo"); # Ordinary rule runs recipe four times for t1 t2 t3 t4. # Grouped target rule runs recipe once; others are considered updated. run_make_test(q{ .PHONY: t1 t2 t3 t4 g1 g2 g3 g4 t1 t2 t3 t4: ; @echo $@ g1 g2 g3 g4 &: ; @echo $@ }, 't1 t2 t3 t4 g1 g2 g3 g4', "t1\n" ."t2\n" ."t3\n" ."t4\n" ."g1\n" ."#MAKE#: Nothing to be done for 'g2'.\n" ."#MAKE#: Nothing to be done for 'g3'.\n" ."#MAKE#: Nothing to be done for 'g4'."); # Similar to previous test, but targets come from m1 phony # rather than from the command line. We don't see "Nothing to # be done for" messages. Also, note reversed order g4 g3 ... # Thus the auto variable $@ is "g4" when that rule fires. run_make_test(q{ .PHONY: m1 t1 t2 t3 t4 g1 g2 g3 g4 m1: t1 t2 t3 t4 g4 g3 g2 g1 t1 t2 t3 t4: ; @echo $@ g1 g2 g3 g4&: ; @echo $@ }, '', "t1\nt2\nt3\nt4\ng4"); # Set a grouped target recipe for existing targets run_make_test(q{ .PHONY: M a b M: a b a: a b&: ; @echo Y b: }, '', "Y"); # grouped targets require a recipe run_make_test(q{ .PHONY: M a b M: a b a b&: }, '', "#MAKEFILE#:4: *** grouped targets must provide a recipe. Stop.", 512); # Pattern rules use grouped targets anyway so it's a no-op run_make_test(q{ .PHONY: M M: a.q b.q a.% b.%&: ; @echo Y }, '', "Y"); # Double-colon grouped target rules. run_make_test(q{ .PHONY: M a b c d e f g h M: a b a b c&:: ; @echo X c d e&:: ; @echo Y f g h&:: ; @echo Z }, '', "X"); run_make_test(q{ .PHONY: M a b c d e f g h M: c a b c&:: ; @echo X c d e&:: ; @echo Y f g h&:: ; @echo Z }, '', "X\nY"); run_make_test(q{ .PHONY: M a b c d e f g h M: a b c d e a b c&:: ; @echo X c d e&:: ; @echo Y f g h&:: ; @echo Z }, '', "X\nY"); run_make_test(q{ .PHONY: M a b c d e f g h M: d e a b c&:: ; @echo X c d e&:: ; @echo Y f g h&:: ; @echo Z }, '', "Y"); run_make_test(q{ .PHONY: M a b c d e f g h M: f g h a b c&:: ; @echo X c d e&:: ; @echo Y f g h&:: ; @echo Z }, '', "Z"); # sv 60188. # Test that a file explicitly mentioned by the user and made by an implicit # rule is not considered intermediate. touch('hello.z'); touch('hello.q'); # subtest 1 # hello.x is not explicitly mentioned and thus is an intermediate file. run_make_test(q! all: hello.z %.z %.q: %.x ; touch $*.z $*.q %.x: ; !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 2 # test.x is explicitly mentioned and thus is not an intermediate file. run_make_test(q! all: hello.z %.z %.q: %.x test.x ; @echo $*.z $*.q %.x: ; !, '', "hello.z hello.q\n"); # subtest 3 # hello.x is explicitly mentioned on an unrelated rule and thus is not an # intermediate file. run_make_test(q! all: hello.z %.z %.q: %.x; @echo $*.z $*.q %.x: ; unrelated: hello.x !, '', "hello.z hello.q\n"); unlink('hello.z'); unlink('hello.q'); # SV 62809: Missing grouped target peer causes remake regardless of which # target caused the rule to run. touch(qw(gta)); # but not gtb run_make_test(q! gta gtb &: ; touch gta gtb !, 'gta', "touch gta gtb\n"); unlink(qw(gta gtb)); # Ensure both goal targets are built if they depend on a grouped prereq touch(qw(gta)); # but not gtb run_make_test(q! x1 x2: ; touch $@ x1: gta x2: gtb gta gtb &: ; touch gta gtb !, 'x1 x2', "touch gta gtb\ntouch x1\ntouch x2\n"); # Now everything should be up to date run_make_test(undef, 'x1 x2', "#MAKE#: 'x1' is up to date.\n#MAKE#: 'x2' is up to date."); unlink(qw(x1 x2 gta gtb)); # If an also-make file is older than a prerequisite build both utouch(-20, 'gtb'); utouch(-10, 'pre'); touch(qw(gta)); run_make_test(q! gta gtb &: pre ; touch gta gtb !, 'gta', "touch gta gtb\n"); unlink(qw(pre gta gtb)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/implicit_search ================================================ # -*-perl-*- $description = "Test implicit rule search."; $details = ""; # sv 48643 # Each test has a %.c rule ahead of %.f rule. # hello.f exists and hello.c is missing. unlink('hello.c', 'hello.tsk', 'hello.o', 'hello.x'); # Run every test with and without a suffix. my @suffixes = ('', '.o'); # Run every test with single and double colon rules. my @rules = ('', ':'); for my $s (@suffixes) { for my $r (@rules) { touch('hello.f'); # Test that make finds the intended implicit rule based on existence of a # prerequisite in the filesystem. # # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen. run_make_test(" all: hello$s %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'."); # Test that make finds the intended implicit rule based on the explicit # prerequisite of the top goal and despite the existence of a # prerequisite in the filesystem. # # hello.c is an explicit prerequisite of the top target (hello.o or hello). # hello.c ought to exist. # hello.c prerequisite causes '%.o: %.c' rule to be chosen. run_make_test(" hello$s: hello.c %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'. Stop.\n", 512); # Test that make finds the intended implicit rule when the implicit # prerequisite matches a target of an unrelated rule and despite the existence # of a prerequisite of the other rule candidate in the filesystem. # # hello.c matches 'hello.c:' rule. This makes hello.c a target and thus ought # to exist. # hello.c prerequisite causes '%.o: %.c' rule to be chosen. run_make_test(" all: hello$s %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) hello.c:; @#HELPER# fail 1 ", '-r', "fail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512); # Test that make finds the intended implicit rule based on existence of a # prerequisite in the filesystem, even when the prerequisite of another # candidate rule is mentioned explicitly on an unrelated rule. # # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen, even though hello.c # is mentioned explicitly on 'unrelated: hello.c'. # ought-to-exist does not apply to hello.c. run_make_test(" all: hello$s %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) unrelated: hello.c ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'."); # Test that make finds the intended implicit rule based on existence of a # prerequisite in the filesystem. # # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen. # Despite '%.o: %.c hello.c' rule having explicit prerequisite hello.c. # ought-to-exist does not apply to hello.c. run_make_test(" all: hello$s %$s:$r %.c hello.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'."); # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen. # '%.o: %.f hello.f' rule has explicit prerequisite hello.f. # ought-to-exist does not apply to hello.c. run_make_test(" all: hello$s %$s:$r %.c; \$(info hello.c) %$s:$r %.f hello.f; \$(info hello.f) ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'."); # Rule '%: %.f' is chosen, because '%: %.f' requires no intermediates. # '%: %.c', on the other hand, requires intemediate hello.c to be built by the # default rule. run_make_test(" all: hello$s %$s:$r %.c; \$(info \$<) %$s:$r %.f; \$(info \$<) .DEFAULT:; \$(info \$\@) true unrelated: hello.c ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'."); # hello.f is missing. # This time both hello.c and hello.f are missing and both '%: %.c' and '%: %.f' # require an intermediate. # The default rule builds intemerdiate hello.c. # '%: %.c' rule is chosen to build hello. unlink('hello.f'); run_make_test(" all: hello$s %$s:$r %.c; \$(info \$<) %$s:$r %.f; \$(info \$<) .DEFAULT:; \@\$(info \$\@) #HELPER# fail 1 unrelated: hello.c ", '-r', "hello.c\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512); # hello.f is missing. # No rule is found, because hello.c is not mentioned explicitly. run_make_test(" all: hello$s %$s:$r %.c; \$(info \$<) %$s:$r %.f; \$(info \$<) .DEFAULT:; \@\$(info \$\@) #HELPER# fail 1 ", '-r', "hello$s\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello$s] Error 1\n", 512); } } # Almost the same tests as above, but this time an intermediate is built. touch('hello.f'); for my $s (@suffixes) { for my $r (@rules) { my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n"; my $rcode = 512; if ($s or $r) { $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'."; $rcode = 0; } run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', "$result", $rcode); run_make_test(" all: hello.tsk %.tsk: %$s hello$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', $result, $rcode); run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c hello$s; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', $result, $rcode); } } for my $r (@rules) { # Circular dependency hello.o <- hello.tsk is dropped. run_make_test(" all: hello.tsk %.tsk: %.o; \$(info hello.tsk) %.o:$r %.c; \$(info hello.c) %.o:$r %.f %.tsk; \$(info hello.f) ", '-r', "#MAKE#: circular hello.o <- hello.tsk dependency dropped\nhello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'."); } for my $s (@suffixes) { for my $r (@rules) { run_make_test(" all: hello.tsk hello$s: hello.c %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) ", '-r', "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'. Stop.\n", 512); } } for my $s (@suffixes) { for my $r (@rules) { my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n"; if ($s or $r) { $result = "fail 1\n#MAKE#: *** [#MAKEFILE#:6: hello.c] Error 1\n"; } run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) hello.c:; @#HELPER# fail 1 ", '-r', $result, 512); } } for my $s (@suffixes) { for my $r (@rules) { run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f; \$(info hello.f) unrelated: hello$s ", '-r', "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'."); } } for my $s (@suffixes) { for my $r (@rules) { my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n"; my $rcode = 512; if ($s or $r) { $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'."; $rcode = 0; } run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c; \$(info hello.c) %$s:$r %.f hello.f; \$(info hello.f) ", '-r', $result, $rcode); } } # One of the implicit rules has two prerequisites, hello.c and hello.x # hello.c does not qualify as ought to exit. # hello.x can be made from hello.z. # This test exercises the break, which prevents making hello.x as an # intermediate from hello.z during compatibility search. unlink('hello.f'); touch('hello.z'); for my $s (@suffixes) { for my $r (@rules) { run_make_test(" all: hello.tsk %.tsk: %$s; \$(info hello.tsk) %$s:$r %.c %.x; \$(info hello.c) %$s:$r %.f; \$(info hello.f) unrelated: hello$s %.x:$r %.z; \$(info hello.z) ", '-r', "#MAKE#: *** No rule to make target 'hello$s', needed by 'hello.tsk'. Stop.\n", 512); } } # Test that prerequisite 'hello.x' mentioned explicitly on an unrelated rule is # not considered intermediate. touch('hello.tsk'); unlink('hello.x'); run_make_test(" all: hello.tsk %.tsk: %.x; touch hello.tsk %.x: ; unrelated: hello.x ", '-r', "touch hello.tsk\n"); unlink('hello.tsk'); touch ('hello.f'); # Test implicit search of builtin rules. # %: %.c (and other builtin rules) are skipped. # %: %.f is chosen. run_make_test(q! all: hello !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n"); # %.o: %.c (and other builtin rules) are skipped. # %.o: %.f is chosen. run_make_test(q! all: hello.o !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n"); # %: %.c is chosen. # hello.c is an explicit prerequisite of the top target hello. # hello.c ought to exist. # hello.c prerequisite causes '%: %.c' rule to be chosen. run_make_test(q! hello: hello.c !, 'FC="@echo f77" OUTPUT_OPTION=', "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello'. Stop.\n", 512); # %.o: %.c is chosen. # hello.c is an explicit prerequisite of the top target hello.o. # hello.c ought to exist. # hello.c prerequisite causes '%.o: %.c' rule to be chosen. run_make_test(q! hello.o: hello.c !, 'FC="@echo f77" OUTPUT_OPTION=', "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'. Stop.\n", 512); # %: %.c (and other builtin rules) are skipped. # %: %.f is chosen. # ought-to-exist does not apply to hello.c. run_make_test(q! all: hello unrelated: hello.c !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n"); # %.o: %.c (and other builtin rules) are skipped. # %.o: %.f is chosen. # ought-to-exist does not apply to hello.c. run_make_test(q! all: hello.o unrelated: hello.c !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n"); # builtin rule %.o: %.f is removed. # %.o: %.c (and other builtin rules) are skipped, because hello.c is missing. # ought-to-exist does not apply to hello.c. # %.o: %.c is chosen as a compatibility rule, because of hello.c. run_make_test(q! all: hello.o unrelated: hello.c %.o: %.f !, '', "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'. Stop.\n", 512); # sv 17752. # In this test the builtin match-anything rule '%: %.f' is used to build # intermediate hello from hello.f, because hello is mentioned explicitly in # the makefile. run_make_test(q! all: hello.tsk %.tsk: %; $(info $@ from $<) unrelated: hello !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\nhello.tsk from hello\n"); # In this test the builtin match-anything rule %: %.f cannot be used to build # intermediate hello from hello.f, because hello is not mentioned explicitly in # the makefile. run_make_test(q! all: hello.tsk %.tsk: %; $(info $@ from $<) !, 'FC="@echo f77" OUTPUT_OPTION=', "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n", 512); # This is just like the one above, but compatibility rule '%.tsk: % %.x' has 2 # prerequisites, '%' and '%.x'. # '%' expands to 'hello' and matches the explicit 'hello' on the unrelated rule. # '%.x' is an intermediate built from 'hello.xx' by rule '%.x: %.xx' during the # second pass (intermed_ok == 1) of compatibility search. # This test validates that compatibility search performs both intermed_ok == 0 # and intermed_ok == 1 passes. unlink('hello.x'); touch('hello.xx'); run_make_test(q! all: hello.tsk %.tsk: % %.x; $(info $@ from $^) unrelated: hello %.x: %.xx; $(info $@ from $<) !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\nhello.x from hello.xx\nhello.tsk from hello hello.x\n"); unlink('bye.o', 'bye.tsk', 'bye.x'); # sv 21670. # Default recipe is used to build bye.o. run_make_test(q! all: bye.tsk %.tsk: %.o; $(info $@ from $<) .DEFAULT:; $(info bye.o) unrelated: bye.o !, '-r', "bye.o\nbye.tsk from bye.o\n#MAKE#: Nothing to be done for 'all'."); touch('bye.xx'); # This is just like the one above, but compatibility rule '%.tsk: %.o %.x' has 2 # prerequisites, '%.o' and '%.x'. # '%.o' expands to 'bye.o' and matches the explicit 'bye.o' on the unrelated rule. # '%.x' is an intermediate built from 'bye.xx' by rule '%.x: %.xx' during the # second pass (intermed_ok == 1) of compatibility search. # This test validates that compatibility search performs both intermed_ok == 0 # and intermed_ok == 1 passes. run_make_test(q! all: bye.tsk %.tsk: %.o %.x; $(info $@ from $^) .DEFAULT:; $(info bye.o) unrelated: bye.o %.x: %.xx; $(info $@ from $<) !, '-r', "bye.o\nbye.x from bye.xx\nbye.tsk from bye.o bye.x\n#MAKE#: Nothing to be done for 'all'."); unlink('hello.f', 'hello.z', 'hello.xx', 'bye.xx'); # A target specific variable causes the file to be entered to the database as a # prerequisite. Implicit search then treats this file as explicitly mentioned. # Test that implicit search keeps target specific variables of this file intact. # In this series of tests prerequisite 'hello.x' has a target specific variable # and is built as an intermediate. Implicit search treats 'hello.x' as # explicitly mentioned, but 'hello.x' does not qualify as ought-to-exist. unlink('hello.x', 'hello.tsk'); # 'hello.x' is mentioned explicitly on the same implicit rule. run_make_test(q! all: hello.tsk %.tsk: hello.x; $(info $@) %.x:; $(flags) hello.x: flags:=true !, '-r', "true\nhello.tsk\n"); # Similar to the one above, but this time 'hello.x' is derived from the stem. run_make_test(q! all: hello.tsk %.tsk: %.x; $(info $@) %.x:; $(flags) hello.x: flags:=true !, '-r', "true\nhello.tsk\n"); # Similar to the one above, this time 'hello.x' is also mentioned explicitly on # an unrelated rule. run_make_test(q! all: hello.tsk %.tsk: %.x; $(info $@) %.x:; $(flags) hello.x: flags:=true unrelated: hello.x !, '-r', "true\nhello.tsk\n"); # 'hello.x' has a pattern specific variable. run_make_test(q! all: hello.tsk %.tsk: %.x; $(info $@) %.x:; $(flags) %.x: flags:=true !, '-r', "true\nhello.tsk\n"); # 'hello.x' has a target specific variable and a pattern specific variable. run_make_test(q! all: hello.tsk %.tsk: %.x; $(info $@) %.x:; $(flags) hello.x: flags+=good %.x: flags:=true !, '-r', "true good\nhello.tsk\n"); # Intermediate prerequisite 'hello.x' has a target specific variable, a pattern # specific variable, matches on both rules '%.tsk: %.x' and 'big_%.tsk: %.x'. run_make_test(q! all: hello.tsk big_hello.tsk %.tsk: %.x; $(info $@) big_%.tsk: %.x; $(info $@) %.x:; $(flags) hello.x: flags+=good %.x: flags:=true !, '-r', "true good\nhello.tsk\nbig_hello.tsk\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/include ================================================ # -*-mode: perl-*- $description = "Test various forms of the GNU Make 'include' command."; $details = "\ Test include, -include, sinclude and various regressions involving them. Test extra whitespace at the end of the include, multiple -includes and sincludes (should not give an error) and make sure that errors are reported for targets that were also -included."; create_file('incl.mk', "ANOTHER: ; \@echo This is another included makefile\n"); run_make_test(qq!#Extra space at the end of the following file name include incl.mk ! . q! all: ; @echo There should be no errors for this makefile. -include nonexistent.mk -include nonexistent.mk sinclude nonexistent.mk sinclude nonexistent-2.mk -include makeit.mk sinclude makeit.mk error: makeit.mk !, "all", "There should be no errors for this makefile.\n"); run_make_test(undef, "ANOTHER", "This is another included makefile\n"); unlink('incl.mk'); # Try to build the "error" target; this will fail since we don't know # how to create makeit.mk, but we should also get a message (even though # the -include suppressed it during the makefile read phase, we should # see one during the makefile run phase). run_make_test (' -include foo.mk error: foo.mk ; @echo $@ ', '', "#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n", 512 ); # The same as above with an additional include directory. mkdir('hellod', 0777); run_make_test (' -include foo.mk error: foo.mk ; @echo $@ ', '-Ihellod', "#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n", 512 ); rmdir('hellod'); # Make sure that target-specific variables don't impact things. This could # happen because a file record is created when a target-specific variable is # set. run_make_test (' bar.mk: foo := baz -include bar.mk hello: ; @echo hello ', '', "hello\n" ); # Test inheritance of dontcare flag when rebuilding makefiles. # run_make_test(' .PHONY: all all: ; @: -include foo foo: bar; @: ', '', ''); # Make sure that we don't die when the command fails but we dontcare. # (Savannah bug #13216). # run_make_test(' .PHONY: all all:; @: -include foo foo: bar; @: bar:; @exit 1 ', '', ''); # Check include, sinclude, -include with no filenames. # (Savannah bug #1761). run_make_test(' .PHONY: all all:; @: include -include sinclude', '', ''); # Test that the diagnostics is issued even if the target has been # tried before with the dontcare flag (direct dependency case). # run_make_test(' -include foo all: bar foo: baz bar: baz ', '', "#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n", 512); # Test that the diagnostics is issued even if the target has been # tried before with the dontcare flag (indirect dependency case). # run_make_test(' -include foo all: bar foo: baz bar: baz baz: end ', '', "#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n", 512); # Test include of make-able file doesn't show an error (Savannah #102) run_make_test(q! .PHONY: default default:; @echo DONE inc1:; echo > $@ include inc1 include inc2 inc2:; echo > $@ !, '', "echo > inc1\necho > inc2\nDONE\n"); rmfiles('inc1', 'inc2'); # Test include of make-able file doesn't show an error. # Specify an additional include directory. mkdir('hellod', 0777); run_make_test(q! .PHONY: default default:; @echo DONE inc1:; echo > $@ include inc1 include inc2 inc2:; echo > $@ !, '-Ihellod', "echo > inc1\necho > inc2\nDONE\n"); rmfiles('inc1', 'inc2'); # Test include of make-able file doesn't show an error. # inc1 and inc2 are present in the specified include directory. touch('hellod/inc1'); touch('hellod/inc2'); run_make_test(q! .PHONY: default default:; @echo DONE inc1:; echo > $@ include inc1 include inc2 inc2:; echo > $@ !, '-Ihellod', "DONE\n"); rmfiles('inc1', 'inc2', 'hellod/inc1', 'hellod/inc2'); rmdir('hellod'); # No target gets correct error run_make_test("\n", '', '#MAKE#: *** No targets. Stop.', 512); # No target in included file either, still gets correct error. touch('inc1.mk'); run_make_test('include inc1.mk', '', '#MAKE#: *** No targets. Stop.', 512); rmfiles('inc1.mk'); # Include same file multiple times run_make_test(q! default:; @echo DEFAULT include inc1 inc1:; echo > $@ include inc1 !, '', "echo > inc1\nDEFAULT\n"); rmfiles('inc1'); if (defined $ERR_no_such_file) { # Test that the diagnostics is issued even if the target has been # tried before with the dontcare flag (include/-include case). # run_make_test(' include bar -include foo all: foo: baz bar: baz baz: end ', '', "#MAKEFILE#:2: bar: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n", 512); # Test include of non-make-able file does show an error (Savannah #102) run_make_test(q! .PHONY: default default:; @echo DONE inc1:; echo > $@ include inc1 include inc2 !, '', "echo > inc1\n#MAKEFILE#:7: inc2: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512); rmfiles('inc1'); # Included file has a prerequisite that fails to build run_make_test(q! default:; @echo DEFAULT include inc1 inc1: foo; echo > $@ foo:; exit 1 !, '', "exit 1\n#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512); rmfiles('inc1'); # Included file has a prerequisite we don't know how to build run_make_test(q! default:; @echo DEFAULT include inc1 inc1: foo; echo > $@ !, '', "#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512); rmfiles('inc1'); # Check that included double-colon targets with no prerequisites aren't # built. This should fail as hello.mk doesn't exist run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' include hello.mk hello.mk:: ; echo 'FOO=bar' > $@ !, '', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512); # Check that included phony targets aren't built. # This should fail as hello.mk doesn't exist run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' include hello.mk hello.mk: ; echo 'FOO=bar' > $@ .PHONY: hello.mk !, '', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512); } if (defined $ERR_unreadable_file) { # Including files that can't be read should show an error unlink('inc1'); create_file('inc1', 'FOO := foo'); chmod 0000, 'inc1'; run_make_test(q! include inc1 all:;@echo $(FOO) !, '', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512); # Including files that can't be read should show an error, even when there # is a readable file in a subsequent include directory. mkdir('hellod', 0777); touch("hellod/inc1"); run_make_test(q! include inc1 all:;@echo $(FOO) !, '-Ihellod', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512); # Unreadable files that we know how to successfully recreate should work run_make_test(sprintf(q! all:;@echo $(FOO) include inc1 inc1:; @%s $@ && echo FOO := bar > $@ !, $CMD_rmfile), '', "bar"); # Unreadable files that we know how to successfully recreate should work. # Even when there is a readable file in an additional include directory. unlink('inc1'); create_file('inc1', 'FOO := foo'); chmod 0000, 'inc1'; run_make_test(sprintf(q! all:;@echo $(FOO) include inc1 inc1:; @%s $@ && echo FOO := bar > $@ !, $CMD_rmfile), '-Ihellod', "bar"); rmfiles('inc1', 'hellod/inc1'); rmdir('hellod'); } # Check that the order of remaking include files is correct: should remake # them in the same order they were encountered in the makefile. SV 58735 run_make_test(q! -include i1 i2 -include i3 -include i4 %:;@echo $@ all:; !, '', "i1\ni2\ni3\ni4\n#MAKE#: 'all' is up to date.\n"); # Check that included files work if created after the first include failed # https://savannah.gnu.org/bugs/?57676 run_make_test(q! default:; @echo $(hello) -include hello.mk $(shell echo hello=world >hello.mk) include hello.mk !, '', "world\n"); unlink('hello.mk'); # Check that included double-colon targets with no prerequisites aren't built. # This should succeed since hello.mk already exists touch('hello.mk'); run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' include hello.mk hello.mk:: ; echo 'FOO=bar' > $@ !, '', 'FOO='); unlink('hello.mk'); # Check that included double-colon targets with no prerequisites aren't built. # This should succeed due to -include run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' -include hello.mk hello.mk:: ; echo 'FOO=bar' > $@ !, '', 'FOO='); # Check that phony targets aren't built. # This should succeed since hello.mk already exists touch('hello.mk'); run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' include hello.mk hello.mk: ; echo 'FOO=bar' > $@ .PHONY: hello.mk !, '', 'FOO='); unlink('hello.mk'); # Check that included double-colon targets with no prerequisites aren't built. # This should succeed due to -include run_make_test(q! .PHONY: default default:;@echo 'FOO=$(FOO)' -include hello.mk hello.mk: ; echo 'FOO=bar' > $@ .PHONY: hello.mk !, '', 'FOO='); # SV 56301 Verify pattern rules creating optional includes. # -k shouldn't matter when creating include files. run_make_test(q! all:; @echo hello -include inc_a.mk include inc_b.mk %_a.mk %_b.mk:; exit 1 !, '', "exit 1\n#MAKEFILE#:4: failed to remake makefile 'inc_b.mk'", 512); run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:4: failed to remake makefile 'inc_b.mk'", 512); # It seems wrong to me that this gives a different error message, but at # least it doesn't keep going. run_make_test(q! all:; @echo hello include inc_a.mk -include inc_b.mk %_a.mk %_b.mk:; exit 1 !, '', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n", 512); run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n#MAKEFILE#:3: failed to remake makefile 'inc_a.mk'", 512); # Check the default makefiles... this requires us to invoke make with no # arguments. Also check MAKEFILES if ($port_type eq 'W32') { $defaults = "GNUmakefile\nmakefile\nMakefile\nmakefile.mak"; } else { $defaults = "GNUmakefile\nmakefile\nMakefile"; } $ENV{MAKEFILES} = 'foobar barfoo'; run_make_with_options(undef, ['-E', '%:;@echo $@', '-E', 'all:;', '-E', '-include bizbaz', '-E', '-include bazbiz'], get_logfile(0)); $answer = "bizbaz\nbazbiz\nfoobar\nbarfoo\n$defaults\n#MAKE#: 'all' is up to date.\n"; &compare_output(subst_make_string($answer), &get_logfile(1)); # SV 63516 if (exists $FEATURES{'dospaths'}) { run_make_test(q! include C:__foobar %bar: ; @echo $@ all: ; !, '', "C:__foobar\n#MAKE#: 'all' is up to date."); } # sv 63484. # Test that included makefiles are not intermediate. # Here 'test.foo' is mentioned explicitly and cannot be considered # intermediate. utouch(-10, 'test.foo'); utouch(-5, 'test.x'); touch('test'); run_make_test(q! .PHONY: force include test.foo %.foo: force; @echo force $@ %.x: %.foo; touch $@ test: test.x; touch $@ !, '', "force test.foo\n#MAKE#: 'test' is up to date.\n"); unlink('test.foo', 'test.x', 'test'); 1; ================================================ FILE: tests/scripts/features/jobserver ================================================ # -*-perl-*- $description = "Test jobserver."; $details = "These tests are ones that specifically are different when the jobserver feature is available. Most -j tests are the same whether or not jobserver is available, and those appear in the 'parallelism' test suite."; exists $FEATURES{'jobserver'} or return -1; if (!$parallel_jobs) { return -1; } # Shorthand my $np = '--no-print-directory'; my $j1err = "warning: jobserver unavailable: using -j1 (add '+' to parent make rule)"; # Simple test of MAKEFLAGS settings run_make_test(q! SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=,$(MAKEFLAGS)) recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all all:;@echo $@: "/$(SHOW)/" !, "-j2 $np", "recurse: /-j2 --jobserver-auth= $np/\nall: /-j2 --jobserver-auth= $np/\n"); # Setting parallelism with the environment # Command line should take precedence over the environment $ENV{MAKEFLAGS} = "-j2 $np"; run_make_test(q! SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=,$(MAKEFLAGS)) recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all all:;@echo $@: "/$(SHOW)/" !, '', "recurse: /-j2 --jobserver-auth= $np/\nall: /-j2 --jobserver-auth= $np/\n"); # Test override of -jN $ENV{MAKEFLAGS} = "-j9 $np"; run_make_test(q! SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=,$(MAKEFLAGS)) recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j3 -f #MAKEFILE# recurse2 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all all:;@echo $@: "/$(SHOW)/" !, "-j2 $np", "recurse: /-j2 --jobserver-auth= $np/\n#MAKE#[1]: warning: -j3 forced in submake: resetting jobserver mode\nrecurse2: /-j3 --jobserver-auth= $np/\nall: /-j3 --jobserver-auth= $np/\n"); # Test override of -jN with -j run_make_test(q! SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=,$(MAKEFLAGS)) recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j -f #MAKEFILE# recurse2 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all all:;@echo $@: "/$(SHOW)/" !, "-j2 $np", "recurse: /-j2 --jobserver-auth= $np/\n#MAKE#[1]: warning: -j0 forced in submake: resetting jobserver mode\nrecurse2: /-j $np/\nall: /-j $np/\n"); # Don't put --jobserver-auth into a re-exec'd MAKEFLAGS. # We can't test this directly because there's no way a makefile can # show the value of MAKEFLAGS we were re-exec'd with. We can intuit it # by looking for "disabling jobserver mode" warnings; we should only # get one from the original invocation and none from the re-exec. # See Savannah bug #18124 unlink('inc.mk'); run_make_test(q! .RECIPEPREFIX = > -include inc.mk recur: #> @echo 'MAKEFLAGS = $(MAKEFLAGS)' > @rm -f inc.mk > @$(MAKE) -j2 -f #MAKEFILE# all all: #> @echo 'MAKEFLAGS = $(MAKEFLAGS)' > @echo $@ inc.mk: #> @echo 'MAKEFLAGS = $(MAKEFLAGS)' > @echo 'FOO = bar' > $@ !, "$np -j2", "#MAKE#[1]: warning: -j2 forced in submake: resetting jobserver mode\nall\n"); unlink('inc.mk'); # Test recursion which is hidden from make. # See Savannah bug #39934 # Or Red Hat bug https://bugzilla.redhat.com/show_bug.cgi?id=885474 # Environments that don't use a pipe won't close access, so this won't happen. if ($port_type ne 'W32') { create_file('Makefile2', "vpath %.c ../\n", "foo:\n"); run_make_test(q! default: ; @ #MAKEPATH# -f Makefile2 !, "--jobserver-style=pipe -j2 $np", "#MAKE#[1]: $j1err #MAKE#[1]: Nothing to be done for 'foo'."); rmfiles('Makefile2'); } # For Windows and named pipes, we don't need to worry about recursion if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) { create_file('Makefile2', "vpath %.c ../\n", "foo:\n"); run_make_test(q! default: ; @ #MAKEPATH# -f Makefile2 !, "-j2 $np", "#MAKE#[1]: Nothing to be done for 'foo'."); rmfiles('Makefile2'); } # SV 63981: Don't generat warnings if the user specifically disabled -j run_make_test(q! all: ; @$(MAKE) -C . -f #MAKEFILE# recurse -j1 recurse: ; @echo hi !, '-w -j2', "#MAKE#: Entering directory '#PWD#' #MAKE#[1]: Entering directory '#PWD#' hi #MAKE#[1]: Leaving directory '#PWD#' #MAKE#: Leaving directory '#PWD#'"); # Ensure enter/leave directory messages appear before jobserver warnings run_make_test(q! all: ; @$(MAKE) -C . -f #MAKEFILE# recurse -j10 recurse: ; @echo hi !, '-w -j2', "#MAKE#: Entering directory '#PWD#' #MAKE#[1]: Entering directory '#PWD#' #MAKE#[1]: warning: -j10 forced in submake: resetting jobserver mode hi #MAKE#[1]: Leaving directory '#PWD#' #MAKE#: Leaving directory '#PWD#'\n"); # Check for invalid jobserver-style options run_make_test(q! all: a all a: ; @echo $@ !, '--jobserver-style=foo -j8', "#MAKE#: *** unknown jobserver auth style 'foo'. Stop.", 512); # Ensure the jobserver is not disabled even if only later commands are recursive run_make_test(q! .RECIPEPREFIX := > all: > @echo $@ 1 > @echo $@ 2 > @$(MAKE) -f #MAKEFILE# recurse recurse: ; @echo $@ !, "$np -j8", "all 1\nall 2\nrecurse"); if ($port_type ne 'W32') { run_make_test(undef, "$np --jobserver-style=pipe -j8", "all 1\nall 2\nrecurse"); } # And with + instead of $(MAKE) run_make_test(q! .RECIPEPREFIX := > all: > @echo $@ 1 > @echo $@ 2 > @+#MAKEPATH# -f #MAKEFILE# recurse recurse: ; @echo $@ !, "$np -j8", "all 1\nall 2\nrecurse"); if ($port_type ne 'W32') { run_make_test(undef, "$np --jobserver-style=pipe -j8", "all 1\nall 2\nrecurse"); } # We can't reset TMPDIR to something invalid when using valgrind if (exists $FEATURES{'jobserver-fifo'} && !$valgrind) { # sv 62908. # Test that when mkfifo fails, make switches to pipe and succeeds. # Force mkfifo to fail by attempting to create a fifo in a non existent # directory. # run_make_test does not allow matching a multiline pattern, therefore run # the test twice. # First time look for /$ERR_no_such_file/ to ensure mkfifo failed. # Second time look for /Nothing to be done/ to ensure make succeeded. $ENV{TMPDIR} = "nosuchdir"; run_make_test("all:\n", '-j2', "/$ERR_no_such_file/"); $ENV{TMPDIR} = "nosuchdir"; run_make_test(undef, '-j2', "/Nothing to be done/"); # Verify that MAKE_TMPDIR is preferred if provided $ENV{MAKE_TMPDIR} = '.'; $ENV{TMPDIR} = 'nosuchdir'; run_make_test(q! recurse: ; @$(MAKE) -f #MAKEFILE# all all:;@echo "$$MAKEFLAGS" !, "-j2 --no-print-directory", "/--jobserver-auth=fifo:\\./"); # Verify we fall back to -j1 but continue, of the auth is bad. $ENV{MAKEFLAGS} = '-j2 --jobserver-auth=fifo:nosuchfile'; run_make_test(q!all:;@echo hi!, "", "#MAKE#: cannot open jobserver nosuchfile: $ERR_no_such_file\n#MAKE#: $j1err\nhi\n"); } 1; ================================================ FILE: tests/scripts/features/load ================================================ # -*-perl-*- $description = "Test the load operator."; $details = "Test dynamic loading of modules."; # Don't do anything if this system doesn't support "load" exists $FEATURES{'load'} or return -1; my $cc = get_config('CC'); if (! $cc) { $verbose and print "Skipping load test: no CC defined\n"; return -1; } # First build a shared object # Provide both a default and non-default load symbol unlink(qw(testload.c testload.so)); open(my $F, '> testload.c') or die "open: testload.c: $!\n"; print $F <<'EOF' ; #include "gnumake.h" char* getenv (const char*); int plugin_is_GPL_compatible; int testload_gmk_setup (unsigned int, gmk_floc *); int explicit_setup (unsigned int, gmk_floc *); int testload_gmk_setup (unsigned int abi, gmk_floc *pos) { (void)abi; (void)pos; gmk_eval ("TESTLOAD = implicit", 0); if (getenv("TESTAPI_KEEP")) return -1; return 1; } int explicit_setup (unsigned int abi, gmk_floc *pos) { (void)abi; (void)pos; gmk_eval ("TESTLOAD = explicit", 0); if (getenv("TESTAPI_KEEP")) return -1; return 1; } EOF close($F) or die "close: testload.c: $!\n"; # Make sure we can compile my $cppflags = get_config('CPPFLAGS') . ($srcdir ? " -I$srcdir/src" : ''); my $cflags = get_config('CFLAGS') . ' -fPIC'; my $ldflags = get_config('LDFLAGS') . ' -shared'; my $sobuild = "$cc $cppflags $cflags $ldflags -o testload.so testload.c"; my $clog = `$sobuild 2>&1`; if ($? != 0) { $verbose and print "Failed to build testload.so:\n$sobuild\n$clog"; return -1; } # TEST 1 run_make_test(q! PRE := $(.LOADED) load testload.so POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, '--warn-undefined-variables', "pre= post=testload.so implicit\n"); # TEST 2 # Load using an explicit function run_make_test(q! PRE := $(.LOADED) load ./testload.so(explicit_setup) POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, '', "pre= post=testload.so explicit\n"); # TEST 3 # Check multiple loads run_make_test(q! PRE := $(.LOADED) load ./testload.so load testload.so(explicit_setup) POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, '', "pre= post=testload.so implicit\n"); # TEST 4 # Check auto-rebuild of loaded file that's out of date utouch(-10, 'testload.so'); touch('testload.c'); run_make_test(q! PRE := $(.LOADED) load ./testload.so POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild, '', "rebuilding testload.so\npre= post=testload.so implicit\n"); # TEST 5 # Check auto-rebuild of loaded file when it doesn't exist unlink('testload.so'); run_make_test(q! PRE := $(.LOADED) -load ./testload.so(explicit_setup) POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) %.so: %.c ; @echo "rebuilding $@"; !.$sobuild, '', "rebuilding testload.so\npre= post=testload.so explicit\n"); # sv 63044. # Test that the loaded shared object is present in .LOADED when the setup # routine returns -1. $ENV{TESTAPI_KEEP} = 1; run_make_test(q! PRE := $(.LOADED) load testload.so POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, '--warn-undefined-variables', "pre= post=testload.so implicit\n"); # Check that we don't auto-rebuild of loaded file that's out of date # if we return -1 from the setup utouch(-10, 'testload.so'); touch('testload.c'); $ENV{TESTAPI_KEEP} = 1; run_make_test(q! PRE := $(.LOADED) load ./testload.so POST := $(.LOADED) all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild, '', "pre= post=testload.so implicit\n"); # Check using load as a target or variable name run_make_test(q! load: ; @echo $@ -load&: ; @echo $@ !, "", "load\n"); run_make_test(q! load : ; @echo $@ -load &: ; echo $@ !, "", "load\n"); run_make_test(q! load = @echo $@ all: ; $(load) load |: ; echo $@ !, "", "all\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/loadapi ================================================ # -*-perl-*- $description = "Test the shared object load API."; $details = "Verify the different aspects of the shared object API."; # Don't do anything if this system doesn't support "load" exists $FEATURES{load} or return -1; my $cc = get_config('CC'); if (! $cc) { $verbose and print "Skipping load test: no CC defined\n"; return -1; } # First build a shared object # Provide both a default and non-default load symbol unlink(qw(testapi.c testapi.so)); open(my $F, '> testapi.c') or die "open: testapi.c: $!\n"; print $F <<'EOF' ; #include #include #include "gnumake.h" char *getenv (const char*); int plugin_is_GPL_compatible; int testapi_gmk_setup (unsigned int abi, const gmk_floc *floc); static char * test_eval (const char *buf) { gmk_eval (buf, 0); return NULL; } static char * test_expand (const char *val) { return gmk_expand (val); } static char * test_noexpand (const char *val) { char *str = gmk_alloc (strlen (val) + 1); strcpy (str, val); return str; } static char * func_test (const char *funcname, unsigned int argc, char **argv) { char *mem; (void)argc; if (strcmp (funcname, "test-expand") == 0) return test_expand (argv[0]); if (strcmp (funcname, "test-eval") == 0) return test_eval (argv[0]); if (strcmp (funcname, "test-noexpand") == 0) return test_noexpand (argv[0]); mem = gmk_alloc (sizeof ("unknown")); strcpy (mem, "unknown"); return mem; } int testapi_gmk_setup (unsigned int abi, const gmk_floc *floc) { const char *verbose = getenv ("TESTAPI_VERBOSE"); (void)abi; gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT); gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND); gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT); gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0); if (verbose) { printf ("testapi_gmk_setup\n"); if (verbose[0] == '2') printf ("%s:%lu\n", floc->filenm, floc->lineno); } if (getenv ("TESTAPI_KEEP")) return -1; return 1; } int alternative_setup () { gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT); gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND); gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT); gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0); if (getenv ("TESTAPI_VERBOSE")) printf ("alternative_setup\n"); if (getenv ("TESTAPI_KEEP")) return -1; return 1; } void testapi_gmk_unload () { const char *s = getenv ("TESTAPI_VERBOSE"); if (s && *s == '3') printf ("testapi_gmk_unload\n"); } EOF close($F) or die "close: testapi.c: $!\n"; # Make sure we can compile my $cflags = get_config('CFLAGS'); my $cppflags = get_config('CPPFLAGS'); my $ldflags = get_config('LDFLAGS'); my $sobuild = "$cc ".($srcdir? "-I$srcdir/src":'')." $cppflags $cflags -shared -fPIC $ldflags -o testapi.so testapi.c"; my $clog = `$sobuild 2>&1`; if ($? != 0) { $verbose and print "Failed to build testapi.so:\n$sobuild\n$_"; return -1; } # TEST 1 # Check the gmk_expand() function run_make_test(q! EXPAND = expansion all: ; @echo $(test-expand $$(EXPAND)) load testapi.so !, '', "expansion\n"); # TEST 2 # Check the eval operation. Prove that the argument is expanded only once run_make_test(q! load testapi.so TEST = bye ASSIGN = VAR = $(TEST) $(shell echo there) $(test-eval $(value ASSIGN)) TEST = hi all:;@echo '$(VAR)' !, '', "hi there\n"); # TEST 2 # Check the no-expand capability run_make_test(q! load testapi.so TEST = hi all:;@echo '$(test-noexpand $(TEST))' !, '', "\$(TEST)\n"); # During all subsequent tests testapi.so exists. # my @loads = ('', q! load testapi.so load testapi.so -load testapi.so -load testapi.so $(eval load testapi.so) $(eval -load testapi.so) !); for my $extra_loads (@loads) { my $n = 5; if ($extra_loads) { $n = 12; } # sv 63045. # Test that having unloaded a shared object make loads it again, even if the # shared object is not updated. $ENV{TESTAPI_VERBOSE} = 1; run_make_test(" load testapi.so $extra_loads all:; \$(info \$(test-expand hello)) testapi.so: force; \$(info \$@) force:; .PHONY: force ", '', "testapi_gmk_setup\ntestapi.so\ntestapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n"); # sv 63045. # Same as above, but testapi_gmk_setup returned -1. $ENV{TESTAPI_KEEP} = 1; $ENV{TESTAPI_VERBOSE} = 1; run_make_test(" load testapi.so $extra_loads all:; \$(info \$(test-expand hello)) testapi.so: force; \$(info \$@) force:; .PHONY: force ", '', "testapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n"); # sv 63045. # Test that make exits, unless make can successfully update an unloaded shared # object. $ENV{TESTAPI_VERBOSE} = 1; run_make_test(" load testapi.so $extra_loads all:; \$(info \$(test-expand hello)) testapi.so: force; @#HELPER# fail 1 force:; .PHONY: force ", '', "testapi_gmk_setup\nfail 1\n#MAKE#: *** [#MAKEFILE#:$n: testapi.so] Error 1\n", 512); # sv 63045. # Same as above, but testapi_gmk_setup returned -1. $ENV{TESTAPI_KEEP} = 1; $ENV{TESTAPI_VERBOSE} = 1; run_make_test(" load testapi.so $extra_loads all:; \$(info \$(test-expand hello)) testapi.so: force; @#HELPER# fail 1 force:; .PHONY: force ", '', "testapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n"); # sv 63100. # Test that make supplies the correct floc when the shared object is loaded # again. $ENV{TESTAPI_VERBOSE} = 2; run_make_test(" load testapi.so $extra_loads all:; \$(info \$(test-expand hello)) testapi.so: force; \$(info \$@) force:; .PHONY: force ", '', "testapi_gmk_setup\n#MAKEFILE#:2\ntestapi.so\ntestapi_gmk_setup\n#MAKEFILE#:2\nhello\n#MAKE#: 'all' is up to date.\n"); } my @names = ('testapi.so', './testapi.so', '#PWD#/testapi.so'); for my $name (@names) { # Test the make correctly figures out the name of the close function and runs # the close function. $ENV{TESTAPI_VERBOSE} = 3; run_make_test(" load $name all:; \$(info \$(test-expand hello)) ", '', "testapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\ntestapi_gmk_unload\n"); } # Same as above, but the setup function is custom. @names = ('testapi.so(alternative_setup)', './testapi.so(alternative_setup)', '#PWD#/testapi.so(alternative_setup)'); for my $name (@names) { # Test the close function. $ENV{TESTAPI_VERBOSE} = 3; run_make_test(" load $name all:; \$(info \$(test-expand hello)) ", '', "alternative_setup\nhello\n#MAKE#: 'all' is up to date.\ntestapi_gmk_unload\n"); } # Test that makes runs the close function on failure. $ENV{TESTAPI_VERBOSE} = 3; run_make_test(q! load testapi.so all: bad_preqreq; : !, '', "testapi_gmk_setup\n#MAKE#: *** No rule to make target 'bad_preqreq', needed by 'all'. Stop.\ntestapi_gmk_unload\n", 512); # Test that make unloads a shared object, calls the close function, loads # the plugin again, and then calls the close function again on exit. &utouch(-10, 'testapi.so'); $ENV{TESTAPI_VERBOSE} = 3; run_make_test(" load testapi.so all:; \$(info \$(test-expand hello)) testapi.so: testapi.c; $sobuild ", '', "testapi_gmk_setup\ntestapi_gmk_unload\n$sobuild\ntestapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\ntestapi_gmk_unload"); # Test that make unloads a shared object, calls the close function, loads # the plugin again, and then calls the close function again on exit. $ENV{TESTAPI_VERBOSE} = 3; run_make_test(q! load testapi.so all:; $(info $(test-expand hello)) testapi.so: force; $(info $@) force:; .PHONY: force !, '', "testapi_gmk_setup\ntestapi_gmk_unload\ntestapi.so\ntestapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\ntestapi_gmk_unload\n"); unlink(qw(testapi.c testapi.so)) unless $keep; # Test that make does not run the close function, unless the shared object # loaded successfully. unlink('testapi.so'); $ENV{TESTAPI_VERBOSE} = 3; run_make_test(q! load testapi.so all:; : !, '', "#MAKEFILE#:2: testapi.so: cannot open shared object file: $ERR_no_such_file\n#MAKEFILE#:2: *** testapi.so: failed to load. Stop.\n", 512); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/mult_rules ================================================ # -*-perl-*- $description = "\ The following test creates a makefile to test the presence of multiple rules for one target. One file can be the target of several rules if at most one rule has commands; the other rules can only have dependencies."; $details = "\ The makefile created in this test contains two hardcoded rules for foo.o and bar.o. It then gives another multiple target rule with the same names as above but adding more dependencies. Additionally, another variable extradeps is listed as a dependency but is defined to be null. It can however be defined on the make command line as extradeps=extra.h which adds yet another dependency to the targets."; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE < $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "bigoutput littleoutput: test.h\n"; print MAKEFILE "\t\@echo I am \$(subst output,,\$@)\n"; # END of Contents of MAKEFILE close(MAKEFILE); &touch("test.h"); &run_make_with_options($makefile,"bigoutput",&get_logfile); # Create the answer to what should be produced by this Makefile $answer = "I am big\n"; &compare_output($answer,&get_logfile(1)); &run_make_with_options($makefile,"littleoutput",&get_logfile); $answer = "I am little\n"; &compare_output($answer,&get_logfile(1)); unlink "test.h"; 1; ================================================ FILE: tests/scripts/features/order_only ================================================ # -*-perl-*- $description = "Test order-only prerequisites."; $details = "\ Create makefiles with various combinations of normal and order-only prerequisites and ensure they behave properly. Test the \$| variable."; # TEST #0 -- Basics run_make_test(' %r: | baz ; @echo $< $^ $| bar: foo foo:;@: baz:;@:', '', "foo foo baz\n"); # TEST #1 -- First try: the order-only prereqs need to be built. run_make_test(q! foo: bar | baz @echo '$$^ = $^' @echo '$$| = $|' touch $@ .PHONY: baz bar baz: touch $@!, '', "touch bar\ntouch baz\n\$^ = bar\n\$| = baz\ntouch foo\n"); # TEST #2 -- now we do it again: baz is PHONY but foo should _NOT_ be updated run_make_test(undef, '', "touch baz\n"); unlink(qw(foo bar baz)); # TEST #3 -- Make sure the order-only prereq was promoted to normal. run_make_test(q! foo: bar | baz @echo '$$^ = $^' @echo '$$| = $|' touch $@ foo: baz .PHONY: baz bar baz: touch $@!, '', "touch bar\ntouch baz\n\$^ = bar baz\n\$| = \ntouch foo\n"); # TEST #4 -- now we do it again run_make_test(undef, '', "touch baz\n\$^ = bar baz\n\$| = \ntouch foo\n"); unlink(qw(foo bar baz)); # Test empty normal prereqs # TEST #5 -- make sure the parser was correct. run_make_test(q! foo:| baz @echo '$$^ = $^' @echo '$$| = $|' touch $@ .PHONY: baz baz: touch $@!, '', "touch baz\n\$^ = \n\$| = baz\ntouch foo\n"); # TEST #6 -- now we do it again: this time foo won't be built run_make_test(undef, '', "touch baz\n"); unlink(qw(foo baz)); # Test order-only in pattern rules # TEST #7 -- make sure the parser was correct. run_make_test(q! %.w : %.x | baz @echo '$$^ = $^' @echo '$$| = $|' touch $@ all: foo.w .PHONY: baz foo.x baz: touch $@!, '', "touch foo.x\ntouch baz\n\$^ = foo.x\n\$| = baz\ntouch foo.w\n"); # TEST #8 -- now we do it again: this time foo.w won't be built run_make_test(undef, '', "touch baz\n"); unlink(qw(foo.w foo.x baz)); # TEST #9 -- make sure that $< is set correctly in the face of order-only # prerequisites in pattern rules. run_make_test(' %r: | baz ; @echo $< $^ $| bar: foo foo:;@: baz:;@:', '', "foo foo baz\n"); 1; ================================================ FILE: tests/scripts/features/output-sync ================================================ # -*-perl-*- $description = "Test --output-sync (-O) option."; $details = "Test the synchronization of output from parallel jobs."; # If we don't have output sync support, never mind. exists $FEATURES{'output-sync'} or return -1; # Output sync can't be tested without parallelization $parallel_jobs or return -1; # The following subdirectories with Makefiles are used in several # of the following tests. The model is: # foo/Makefile - has a "foo" target that waits for the bar target # bar/Makefile - has a "bar" target that runs immediately # - has a "baz" target that waits for the foo target # # So, you start the two sub-makes in parallel and first the "bar" target is # built, followed by "foo", followed by "baz". The trick is that first each # target prints a "start" statement, then waits (if appropriate), then prints # an end statement. Thus we can tell if the -O flag is working, since # otherwise these statements would be mixed together. @syncfiles = (); sub output_sync_clean { rmfiles('foo/Makefile', 'bar/Makefile', @syncfiles); rmdir('foo'); rmdir('bar'); } # We synchronize the different jobs by having them wait for a sentinel file to # be created, instead of relying on a certain amount of time passing. # Unfortunately in this test we have to sleep after we see the sync file, # since we also want to make the obtaining of the write synchronization lock # reliable. If things are too fast, then sometimes a different job will steal # the output sync lock and the output is mis-ordered from what we expect. sub output_sync_wait { return subst_make_string("#HELPER# \$Q wait ../mksync.$_[0] sleep 1"); } sub output_sync_set { return subst_make_string("#HELPER# \$Q file ../mksync.$_[0]"); } @syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start); $tmout = 30; output_sync_clean(); mkdir('foo', 0777); mkdir('bar', 0777); $set_foo = output_sync_set('foo'); $set_bar = output_sync_set('bar'); $set_foo_start = output_sync_set('foo_start'); $set_bar_start = output_sync_set('bar_start'); $wait_foo = output_sync_wait('foo'); $wait_bar = output_sync_wait('bar'); $wait_foo_start = output_sync_set('foo_start'); $wait_bar_start = output_sync_set('bar_start'); open(MAKEFILE,"> foo/Makefile"); print MAKEFILE < bar/Makefile"); print MAKEFILE <&2) !, '-w -Oline', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n"); # Ensure that output generated while parsing makefiles is synced # when appropriate. run_make_test(q! $(shell echo foo 1>&2) all: ; echo bar !, '-s -w -Otarget', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n#MAKE#: Entering directory '#PWD#'\nbar\n#MAKE#: Leaving directory '#PWD#'\n"); # Test recursion $m1 = get_tmpfile(); $m2 = get_tmpfile(); open(M1, "> $m1"); print M1 <<'EOF'; $(shell echo d1 stderr 1>&2) $(info d1 stdout) all:; @: EOF close(M1); open(M2, "> $m2"); print M2 <<'EOF'; $(shell echo d2 stderr 1>&2) $(info d2 stdout) all:; @: # Force an ordering on the output $(shell sleep 1) EOF close(M2); run_make_test(qq! all: t1 t2 t1: ; \@\$(MAKE) -f $m1 t2: ; \@\$(MAKE) -f $m2 !, "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#[1]: Entering directory '#PWD#'\nd2 stderr\nd2 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n"); rmfiles($m1, $m2); # Ensure that output generated while parsing makefiles is synced # when appropriate. $m1 = get_tmpfile(); open(M1, "> $m1"); print M1 <<'EOF'; $(shell echo d1 stderr 1>&2) $(info d1 stdout) $(error d1 failed) all:; @: EOF close(M1); run_make_test(qq! all: t1 t1: ; -\@\$(MAKE) -f $m1 !, "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n$m1:3: *** d1 failed. Stop.\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#: [#MAKEFILE#:3: t1] Error 2 (ignored)\n"); rmfiles($m1); # Test $(error ...) functions in recipes run_make_test(q! foo: $(OBJS) ; echo $(or $(filter %.o,$^),$(error fail)) !, '-O', "#MAKEFILE#:2: *** fail. Stop.\n", 512); # SV 47365: Make sure exec failure error messages are shown # Needs to be ported to Windows if ($port_type ne 'W32') { run_make_test(q! all:: ; @./foo bar baz !, '-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127\n", 512); } if ($port_type eq 'UNIX') { # POSIX doesn't require sh to set PPID so test this my $cmd = create_command(); add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!); my $fout = 'ppidtest.out'; run_command_with_output($fout, @$cmd); $_ = read_file_into_string($fout); s/\r?\n//g; if (/^[0-9]+$/) { use POSIX (); # SV 63157. # Test that make removes temporary files, even when a signal is received. The # general test_driver postprocessing will ensure the temporary file used to # synchronize output and the jobserver fifo are both removed. sleep is needed # to let make write its "... Terminated" message to the log file. Must use # REGEX because some systems (MacOS) add extra text after Terminated. run_make_test(q! pid:=$(shell echo $$PPID) all:; @#HELPER# -q term $(pid) sleep 10 !, '-O -j2', '/#MAKE#: \*\*\* \[#MAKEFILE#:3: all] Terminated/', POSIX::SIGTERM); } unlink($fout); # SV 63333. Test that make continues to run without output sync when we # cannot create a temporary file. # Create a non-writable temporary directory. # Run the test twice, because run_make_test cannot match a regex against a # multiline input. # If we do this Valgrind fails because it cannot write temp files... the docs # don't describe any way to tell valgrind to use a directory other than TMPDIR. if (!$valgrind) { my $tdir = 'test_tmp_dir'; mkdir($tdir, 0500); $ENV{'TMPDIR'} = $tdir; run_make_test(q! all:; $(info hello, world) !, '-Orecurse', "/suppressing output-sync/"); run_make_test(undef, '-Orecurse', "/#MAKE#: 'all' is up to date./"); rmdir($tdir); } } # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/override ================================================ # -*-perl-*- $description = "Test the override directive on variable assignments."; $details = ""; # TEST 0: Basic override run_make_test(' X = start override recur = $(X) override simple := $(X) X = end all: ; @echo "$(recur) $(simple)" ', 'recur=I simple=J', "end start\n"); # TEST 1: Override with append run_make_test(' X += X1 override X += X2 override Y += Y1 Y += Y2 all: ; @echo "$(X) $(Y)" ', '', "X1 X2 Y1\n"); # TEST 2: Override with append to the command line run_make_test(undef, 'X=C Y=C', "C X2 C Y1\n"); # Test override of define/endef run_make_test(' override define foo @echo First comes the definition. @echo Then comes the override. endef all: ; $(foo) ', 'foo=Hello', "First comes the definition.\nThen comes the override.\n"); 1; ================================================ FILE: tests/scripts/features/parallelism ================================================ # -*-perl-*- $description = "Test parallelism (-j) option."; $details = ""; if (!$parallel_jobs) { return -1; } run_make_test(q! all : def_1 def_2 def_3 def_1 : ; @#HELPER# file ONE wait THREE out TWO def_2 : ; @#HELPER# wait FOUR file THREE def_3 : ; @#HELPER# wait ONE file FOUR!, '-j4', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO"); rmfiles(qw(ONE TWO THREE FOUR)); # Verify -j added to MAKEFLAGS in the makefile run_make_test(q! MAKEFLAGS += -j4 all : def_1 def_2 def_3 def_1 : ; @#HELPER# file ONE wait THREE out TWO def_2 : ; @#HELPER# wait FOUR file THREE def_3 : ; @#HELPER# wait ONE file FOUR!, '', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO"); rmfiles(qw(ONE TWO THREE FOUR)); # Command line should take precedence run_make_test(q! MAKEFLAGS += -j2 all : def_1 def_2 def_3 def_1 : ; @#HELPER# file ONE wait THREE out TWO def_2 : ; @#HELPER# wait FOUR file THREE def_3 : ; @#HELPER# wait ONE file FOUR!, '-j4', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO"); rmfiles(qw(ONE TWO THREE FOUR)); # Test parallelism with included files. Here we sleep/echo while # building the included files, to test that they are being built in # parallel. run_make_test(q! all: 1 2; @#HELPER# out success -include 1.inc 2.inc .RECIPEPREFIX := > 1.inc: > @#HELPER# file ONE.inc wait THREE.inc file TWO.inc > @echo '1: ; @#HELPER# file ONE wait THREE file TWO' > $@ 2.inc: > @#HELPER# wait ONE.inc file THREE.inc > @echo '2: ; @#HELPER# wait ONE file THREE' > $@!, "-j4", "file ONE.inc\nwait ONE.inc\nfile THREE.inc\nwait THREE.inc\nfile TWO.inc\nfile ONE\nwait ONE\nfile THREE\nwait THREE\nfile TWO\nsuccess\n", 0, 7); rmfiles(qw(ONE.inc TWO.inc THREE.inc ONE TWO THREE 1.inc 2.inc)); # Test parallelism with included files--this time recurse first and make # sure the jobserver works. run_make_test(q! recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all all: 1 2; @#HELPER# out success INC = no ifeq ($(INC),yes) -include 1.inc 2.inc endif 1.inc: ; @#HELPER# file ONE.inc wait THREE.inc file TWO.inc; echo '1: ; @#HELPER# file ONE wait THREE file TWO' > $@ 2.inc: ; @#HELPER# wait ONE.inc file THREE.inc; echo '2: ; @#HELPER# wait ONE file THREE' > $@!, "-j4", "file ONE.inc\nwait ONE.inc\nfile THREE.inc\nwait THREE.inc\nfile TWO.inc\nfile ONE\nwait ONE\nfile THREE\nwait THREE\nfile TWO\nsuccess\n", 0, 7); rmfiles(qw(ONE.inc TWO.inc THREE.inc ONE TWO THREE 1.inc 2.inc)); # Grant Taylor reports a problem where tokens can be lost (not written back # to the pipe when they should be): this happened when there is a $(shell ...) # function in an exported recursive variable. I added some code to check # for this situation and print a message if it occurred. This test used # to trigger this code when I added it but no longer does after the fix. run_make_test(q! export HI = $(shell $($@.CMD)) first.CMD = #HELPER# out hi second.CMD = #HELPER# sleep 4 .PHONY: all first second all: first second first second: ; @#HELPER# out $@ sleep 1 out $@!, '-j2', "first\nsleep 1\nfirst\nsecond\nsleep 1\nsecond", 0); # Michael Matz reported a bug where if make is running in # parallel without -k and two jobs die in a row, but not too close to each # other, then make will quit without waiting for the rest of the jobs to die. run_make_test(q! .PHONY: all fail.1 fail.2 fail.3 ok all: fail.1 ok fail.2 fail.3 fail.1: ; @#HELPER# -q sleep 1 out $@ file fail.1 fail 1 fail.2: ; @#HELPER# -q sleep 2 out $@ wait fail.1 file fail.2 fail 1 fail.3: ; @#HELPER# -q sleep 3 out $@ wait fail.2 file fail.3 fail 1 ok: ; @#HELPER# -q sleep 4 wait fail.3 out OK!, '-rR -j5', "fail.1 #MAKE#: *** [#MAKEFILE#:5: fail.1] Error 1 #MAKE#: *** Waiting for unfinished jobs.... fail.2 #MAKE#: *** [#MAKEFILE#:6: fail.2] Error 1 fail.3 #MAKE#: *** [#MAKEFILE#:7: fail.3] Error 1 OK", 512); rmfiles(qw(fail.1 fail.2 fail.3)); # Test for Savannah bug #15641. # run_make_test(' .PHONY: all all:; @: -include foo.d foo.d: comp ; @#HELPER# out $@ comp: mod_a.o mod_b.o; @: mod_a.o mod_b.o: ; @#HELPER# fail 1 ', '-j2', "fail 1\nfail 1\n"); # TEST #9 -- Savannah bugs 3330 and 15919 # In earlier versions of make this will either give the wrong answer, or hang. utouch(-10, 'target'); run_make_test('target: intermed ; #HELPER# file $@ .INTERMEDIATE: intermed intermed: | phony ; #HELPER# file $@ .PHONY: phony phony: ; : phony', '-rR -j', ': phony'); rmfiles('target'); # TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec # See Savannah bug #33873 $ENV{MAKEFLAGS} = '-j4'; run_make_test(q! things = thing1 thing2 all: $(things) thing1:; @#HELPER# wait thing2start file $@start wait thing2end out $@end thing2:; @#HELPER# file $@start wait thing1start file $@end -include inc.mk inc.mk: ; @touch $@ !, '', "file thing2start\nwait thing2start\nfile thing1start\nwait thing1start\nfile thing2end\nwait thing2end\nthing1end\n"); rmfiles(qw(inc.mk thing1start thing1end thing2start thing2end)); # Ensure intermediate/secondary files are not pruned incorrectly. # See Savannah bug #30653 utouch(-15, 'file2'); utouch(-10, 'file4'); utouch(-5, 'file1'); run_make_test(q! .INTERMEDIATE: file3 file4: file3 ; @mv -f $< $@ file3: file2 ; touch $@ file2: file1 ; @touch $@ !, '--no-print-directory -j2', "touch file3"); rmfiles('file1', 'file2', 'file3', 'file4'); # Ensure that the jobserver is preserved across make re-exec. run_make_test(q! all: one two one: ;@ #HELPER# wait TWO file ONE two: ;@ #HELPER# file TWO include fff1.mk fff1.mk: ; touch $@ !, '-j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\n"); rmfiles('fff1.mk', 'ONE', 'TWO'); # Test if a sub-make needs to re-exec and the makefile is built via # sub-make. Reported by Masahiro Yamada run_make_test(q! all: ; @$(MAKE) -f #MAKEFILE# recurse recurse: one two ; @#HELPER# out $@ one: ;@ #HELPER# wait TWO file ONE two: ;@ #HELPER# file TWO mkinclude: ; touch fff1.mk ifeq ($(MAKECMDGOALS),recurse) include fff1.mk fff1.mk: ; @$(MAKE) -f #MAKEFILE# mkinclude endif !, '--no-print-directory -j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\nrecurse\n"); rmfiles('fff1.mk', 'ONE', 'TWO'); # Make sure that all jobserver FDs are closed if we need to re-exec the # master copy. # # First, find the "default" file descriptors we normally use # Then make sure they're still used. # # Right now we don't have a way to run a makefile and capture the output # without checking it, so we can't really write this test. # run_make_test(' # submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output # dependfile: ; @echo FOO=bar > $@ # INCL := true # FOO=foo # ifeq ($(INCL),true) # -include dependfile # endif # fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS)) # recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true', # '-j2 INCL=false fdprint', # 'bar'); # rmfiles(qw(dependfile output)); # # Do it again, this time where the include is done by the non-master make. # run_make_test(undef, '-j2 recurse INCL=false', 'bar'); # rmfiles(qw(dependfile output)); 1; ================================================ FILE: tests/scripts/features/patspecific_vars ================================================ # -*-perl-*- $description = "Test pattern-specific variable settings."; $details = "\ Create a makefile containing various flavors of pattern-specific variable settings, override and non-override, and using various variable expansion rules, semicolon interference, etc."; open(MAKEFILE,"> $makefile"); print MAKEFILE <<'EOF'; all: one.x two.x three.x FOO = foo BAR = bar BAZ = baz one.x: override FOO = one %.x: BAR = two t%.x: BAR = four thr% : override BAZ = three one.x two.x three.x: ; @echo $@: $(FOO) $(BAR) $(BAZ) four.x: baz ; @echo $@: $(FOO) $(BAR) $(BAZ) baz: ; @echo $@: $(FOO) $(BAR) $(BAZ) # test matching multiple patterns a%: AAA = aaa %b: BBB = ccc a%: BBB += ddd %b: AAA ?= xxx %b: AAA += bbb .PHONY: ab ab: ; @echo $(AAA); echo $(BBB) EOF close(MAKEFILE); # TEST #1 -- basics &run_make_with_options($makefile, "", &get_logfile); $answer = "one.x: one two baz\ntwo.x: foo four baz\nthree.x: foo four three\n"; &compare_output($answer,&get_logfile(1)); # TEST #2 -- try the override feature &run_make_with_options($makefile, "BAZ=five", &get_logfile); $answer = "one.x: one two five\ntwo.x: foo four five\nthree.x: foo four three\n"; &compare_output($answer,&get_logfile(1)); # TEST #3 -- make sure patterns are inherited properly &run_make_with_options($makefile, "four.x", &get_logfile); $answer = "baz: foo two baz\nfour.x: foo two baz\n"; &compare_output($answer,&get_logfile(1)); # TEST #4 -- test multiple patterns matching the same target &run_make_with_options($makefile, "ab", &get_logfile); $answer = "aaa bbb\nccc ddd\n"; &compare_output($answer,&get_logfile(1)); # TEST #5 -- test pattern-specific exported variables # run_make_test(' /%: export foo := foo /bar: @echo $(foo) $$foo ', '', 'foo foo'); # TEST #6 -- test expansion of pattern-specific simple variables # run_make_test(' .PHONY: all all: inherit := good $$t all: bar baz b%: pattern := good $$t global := original $$t # normal target # ifdef rec bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit) else bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit) endif bar: ; @echo \'normal: $a;\' # pattern target # ifdef rec %z: a = global: $(global) pattern: $(pattern) inherit: $(inherit) else %z: a := global: $(global) pattern: $(pattern) inherit: $(inherit) endif %z: ; @echo \'pattern: $a;\' global := new $$t ', '', 'normal: global: original $t pattern: inherit: ; pattern: global: original $t pattern: inherit: ;'); # TEST #7 -- test expansion of pattern-specific recursive variables # run_make_test(undef, # reuse previous makefile 'rec=1', 'normal: global: new $t pattern: good $t inherit: good $t; pattern: global: new $t pattern: good $t inherit: good $t;'); # TEST #8: override in pattern-specific variables run_make_test(' a%: override FOO += f1 a%: FOO += f2 ab: ; @echo "$(FOO)" ', '', "f1\n"); run_make_test(undef, 'FOO=C', "C f1\n"); # TEST #9: Test shortest stem selection in pattern-specific variables. run_make_test(' %-mt.x: x := two %.x: x := one all: foo.x foo-mt.x foo.x: ;@echo $x foo-mt.x: ;@echo $x ', '', "one\ntwo"); 1; ================================================ FILE: tests/scripts/features/patternrules ================================================ # -*-perl-*- $description = "Test pattern rules."; $details = ""; use Cwd; $dir = cwd; $dir =~ s,.*/([^/]+)$,../$1,; # TEST #0: Make sure that multiple patterns where the same target # can be built are searched even if the first one fails # to match properly. # run_make_test(q! .PHONY: all all: case.1 case.2 case.3 case.4 # We can't have this, due to "Implicit Rule Search Algorithm" step 5c #xxx: void # 1 - existing file %.1: void ; @exit 1 %.1: #MAKEFILE# ; @exit 0 # 2 - phony %.2: void ; @exit 1 %.2: 2.phony ; @exit 0 .PHONY: 2.phony # 3 - implicit-phony %.3: void ; @exit 1 %.3: 3.implicit-phony ; @exit 0 3.implicit-phony: # 4 - explicitly mentioned file made by an implicit rule %.4: void ; @exit 1 %.4: test.x ; @exit 0 %.x: ; !, '', ''); # TEST #1: make sure files that are built via implicit rules are marked # as targets (Savannah bug #12202). # run_make_test(' TARGETS := foo foo.out .PHONY: all foo.in all: $(TARGETS) %: %.in ; @echo $@ %.out: % ; @echo $@ foo.in: ; @: ', '', "foo\nfoo.out"); # TEST #2: make sure intermediate files that also happened to be # prerequisites are not removed (Savannah bug #12267). # run_make_test(' $(dir)/foo.o: $(dir)/foo.y: ; @echo $@ %.c: %.y ; touch $@ %.o: %.c ; @echo $@ .PHONY: install install: $(dir)/foo.c ', "dir=$dir", "$dir/foo.y\ntouch $dir/foo.c\n$dir/foo.o"); unlink("$dir/foo.c"); # TEST #3: make sure precious flag is set properly for targets # that are built via implicit rules (Savannah bug #13218). # run_make_test(' .DELETE_ON_ERROR: .PRECIOUS: %.bar %.bar:; @touch $@ && exit 1 $(dir)/foo.bar: ', "dir=$dir", "#MAKE#: *** [#MAKEFILE#:6: $dir/foo.bar] Error 1", 512); unlink("$dir/foo.bar"); # TEST #4: make sure targets of a matched implicit pattern rule are # never considered intermediate (Savannah bug #13022). # run_make_test(' .PHONY: all all: foo.c foo.o %.h %.c: %.in ; touch $*.h ; touch $*.c %.o: %.c %.h ; echo $+ >$@ %.o: %.c ; @echo wrong rule foo.in: ; touch $@ ', '', "touch foo.in\ntouch foo.h ; touch foo.c\necho foo.c foo.h >foo.o\nrm foo.h"); unlink('foo.in', 'foo.h', 'foo.c', 'foo.o'); # TEST #5: make sure both prefix and suffix patterns work with multiple # target patterns (Savannah bug #26593). # run_make_test(' all: foo.s1 foo.s2 p1.foo p2.foo p1.% p2.%: %.orig ; @echo $@ %.s1 %.s2: %.orig ; @echo $@ .PHONY: foo.orig ', '', "foo.s1\np1.foo\n"); # TEST 6: Make sure that non-target files are still eligible to be created # as part of implicit rule chaining. Savannah bug #17752. run_make_test(sprintf(q! BIN = xyz COPY = $(BIN).cp SRC = $(BIN).c allbroken: $(COPY) $(BIN) ; @echo ok $(SRC): ; @echo 'main(){}' > $@ %%.cp: %% ; @cp $< $@ %% : %%.c ; @cp $< $@ clean: ; @%s $(SRC) $(COPY) $(BIN) !, $CMD_rmfile), '', "ok\n"); unlink(qw(xyz xyz.cp xyz.c)); # TEST 7: Make sure that all prereqs of all "also_make" targets get created # before any of the things that depend on any of them. Savannah bug #19108. run_make_test(q! final: x ; @echo $@ x: x.t1 x.t2 ; @echo $@ x.t2: dep dep: ; @echo $@ %.t1 %.t2: ; @echo $*.t1 ; echo $*.t2 !, '', "dep\nx.t1\nx.t2\nx\nfinal\n"); # TEST 8: Verify we can remove pattern rules. Savannah bug #18622. my @f = (qw(foo.w foo.ch)); touch(@f); run_make_test(q! CWEAVE := : # Disable builtin rules %.tex : %.w %.tex : %.w %.ch !, 'foo.tex', "#MAKE#: *** No rule to make target 'foo.tex'. Stop.", 512); unlink(@f); # TEST #9: Test shortest stem selection in pattern rules. run_make_test(' %.x: ;@echo one %-mt.x: ;@echo two all: foo.x foo-mt.x ', '', "one\ntwo"); # Test pattern rules building the same targets # See SV 54233. touch('a.c'); # a.lnk isn't listed as removed, because it's not actually created run_make_test(q! all: a.elf a.dbg %.elf %.lnk: %.c ; : $*.elf $*.lnk %.elf %.dbg: %.lnk ; : $*.elf $*.dbg !, '-j2', ": a.elf a.lnk\n: a.elf a.dbg\n"); # SV 60435 : a.lnk is removed, because it is intermediate. run_make_test(q! all: a.elf a.dbg %.elf %.lnk: %.c ; touch $*.elf $*.lnk %.elf %.dbg: %.lnk ; touch $*.elf $*.dbg !, '-j2', "touch a.elf a.lnk\ntouch a.elf a.dbg\nrm a.lnk\n"); unlink('a.elf', 'a.dbg'); # SV 60435 : a.lnk is not intermediate, because it is explicitly mentioned. run_make_test(q! all: a.elf a.dbg %.elf %.lnk: %.c ; touch $*.elf $*.lnk %.elf %.dbg: %.lnk ; touch $*.elf $*.dbg install: a.lnk .PHONY: install !, '-j2', "touch a.elf a.lnk\ntouch a.elf a.dbg\n"); unlink('a.c', 'a.elf', 'a.dbg', 'a.lnk'); # SV 56655: Test patterns matching files containing whitespace touch('some file.yy'); run_make_test(q! %.xx : %.yy ; @echo matched !, '"some file.xx"', "matched\n"); unlink('some file.xx', 'some file.yy'); # sv 60188. # Test that a file explicitly mentioned by the user and made by an implicit # rule is not considered intermediate. touch('hello.z'); unlink('hello.x', 'test.x'); # subtest 1 # hello.x is not explicitly mentioned and thus is an intermediate file. run_make_test(q! all: hello.z %.z: %.x ; touch $@ %.x: ; !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 2 # test.x is explicitly mentioned and thus is not an intermediate file. run_make_test(q! all: hello.z %.z: %.x test.x ; touch $@ %.x: ; !, '', "touch hello.z"); # subtest 3 # hello.x is explicitly mentioned on an unrelated rule and thus is not an # intermediate file. touch('hello.z'); run_make_test(q! all: hello.z %.z: %.x; touch $@ %.x: ; unrelated: hello.x !, '', "touch hello.z"); unlink('hello.z'); # sv 60188. # Test that a file explicitly mentioned by the user and made by an implicit # rule is not considered intermediate, even when the builtin rules are used. touch('hello.x'); touch('test.x'); touch('hello.tsk'); # subtest 1 # hello.o is not explicitly mentioned and thus is an intermediate file. run_make_test(q! all: hello.tsk %.tsk: %.z ; @echo $@ %.z : %.x ; @echo $@ !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 2 # test.z is explicitly mentioned and thus is not an intermediate file. # test.z is built first because until it's built we don't know if we # need to rebuild the intermediate hello.z run_make_test(q! all: hello.tsk %.tsk: %.z test.z ; @echo $@ %.z : %.x ; @echo $@ !, '', "test.z\nhello.z\nhello.tsk\n"); # subtest 3 # hello.o is not explicitly mentioned and thus is an intermediate file. run_make_test(q! all: hello.tsk dep:=%.o %.tsk: $(dep) ; @echo $@ !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 4 # Even when test.z is constructed from 2 variables it is still explicitly # mentioned and thus is not an intermediate file. # test.z is built first because until it's built we don't know if we # need to rebuild the intermediate hello.z run_make_test(q! all: hello.tsk name:=test suf:=.z %.tsk: %.z $(name)$(suf) ; @echo $@ %.z: %.x ; @echo $@ !, '', "test.z\nhello.z\nhello.tsk\n"); unlink('hello.x', 'test.x', 'hello.tsk'); # Test that chained pattern rules with multiple targets remove all intermediate # files. # sv 60435. # subtest 1. # a.1 and a.2 are intermediate and should be removed. run_make_test(q! a.4: %.4: %.1 %.15 ; cat $^ >$@ %.1 %.15: ; touch $*.1 $*.15 !, '', "touch a.1 a.15\ncat a.1 a.15 >a.4\nrm a.15 a.1"); unlink('a.4'); # subtest 2. # a.1 and a.2 are intermediate and should be removed. # a.3 is explicit and should not be removed. run_make_test(q! a.4: %.4: %.1 %.15 a.3 ; cat $^ >$@ %.1 %.15: ; touch $*.1 $*.15 %.3: ; touch $@ !, '', "touch a.3\ntouch a.1 a.15\ncat a.1 a.15 a.3 >a.4\nrm a.15 a.1"); unlink('a.3', 'a.4'); # subtest 3. # a.1 and a.2 are intermediate and should be removed. # a.3 is explicit and should not be removed. run_make_test(q! a.4: %.4: %.1 %.15 a.3 ; cat $^ >$@ %.1 %.15 %.3: ; touch $*.1 $*.15 $*.3 !, '', "touch a.1 a.15 a.3\ncat a.1 a.15 a.3 >a.4\nrm a.15 a.1"); unlink('a.3', 'a.4'); # subtest 4. # a.1 and a.2 are intermediate and should be removed. # a.3 is explicit and should not be removed. run_make_test(q! a.4: %.4: %.1 %.15 a.3 ; cat $^ >$@ %.3 %.1 %.15: ; touch $*.1 $*.15 $*.3 !, '', "touch a.1 a.15 a.3\ncat a.1 a.15 a.3 >a.4\nrm a.15 a.1"); unlink('a.3', 'a.4'); # subtest 5. # a.1 and a.2 are intermediate and should be removed. # a.3 is explicit and should not be removed. run_make_test(q! a.4: %.4: a.3 %.1 %.15 ; cat $^ >$@ %.1 %.15 %.3: ; touch $*.1 $*.15 $*.3 !, '', "touch a.1 a.15 a.3\ncat a.3 a.1 a.15 >a.4\nrm a.15 a.1"); unlink('a.3', 'a.4'); # subtest 6. # a.2 is intermediate and should be removed. # a.1 is mentioned explicitly on an unrelated rule and should not be removed. run_make_test(q! a.3: %.3: %.1 %.2 ; cat $^ >$@ %.1 %.2: ; touch $*.1 $*.2 install: a.1 .PHONY: install !, '', "touch a.1 a.2\ncat a.1 a.2 >a.3\nrm a.2"); unlink('a.1', 'a.3'); # Test removal of intermediate files. # subtest 1. # hello.x is removed, because it is intermediate. run_make_test(q! hello.tsk: %.tsk: %.x; touch $@ %.x: ; touch $@ !, '', "touch hello.x\ntouch hello.tsk\nrm hello.x"); unlink('hello.tsk'); # subtest 2. # Even though hello.x is intermediate, it is not removed, because it is not # created. touch('hello.x'); run_make_test(q! hello.tsk: %.tsk: %.x; touch $@ %.x: ; touch $@ !, '', "touch hello.tsk"); unlink('hello.x', 'hello.tsk'); # subtest 2. # Even though hello.x is intermediate, it is not removed, because it is not # created. run_make_test(q! hello.tsk: %.tsk: %.x; touch $@ %.x: ; : $@ !, '', ": hello.x\ntouch hello.tsk"); unlink('hello.tsk'); # A target explicitly listed as a prerequisite of a pattern rule, is still # considered mentioned and "ought to exist". run_make_test(q! 1.all: 1.q ; touch $@ %.q: 1.r ; touch $@ %.r: ; touch $@ !, '', "touch 1.r\ntouch 1.q\ntouch 1.all\n"); unlink('1.all', '1.q', '1.r'); # SV 63098: Verify that missing also_made in pattern rules gives a warning but # doesn't fail. run_make_test(q! %a %b : ; touch $*a !, 'gta', "touch gta\n#MAKEFILE#:2: warning: pattern recipe did not update peer target 'gtb'\n"); unlink(qw(gta)); # We don't warn if we didn't update the file utouch(-10, qw(gta)); run_make_test(q! %a %b : xyzzy ; $(OP) xyzzy: ; ifdef RUN OP = @echo no endif !, '-rR gta', "#MAKE#: 'gta' is up to date.\n"); run_make_test(undef, '-rR gta RUN=1', "no\n"); unlink(qw(gta)); run_make_test(q! all:; include gta %a %b : ; touch $*a !, '', "touch gta\n#MAKEFILE#:4: warning: pattern recipe did not update peer target 'gtb'\n#MAKE#: 'all' is up to date."); unlink(qw(gta)); run_make_test(q! %.c %.h : %.y; touch $*.c %.o: %.c; touch $@ foo.y: ; touch $@ !, 'foo.o', "touch foo.y\ntouch foo.c\n#MAKEFILE#:2: warning: pattern recipe did not update peer target 'foo.h'\ntouch foo.o\nrm foo.c"); unlink(qw(foo.y foo.c foo.o)); if (0) { # SV 12078: Missing grouped pattern peer causes remake regardless of which # target caused the rule to run. touch(qw(gta)); # but not gtb run_make_test(q! %a %b : ; touch $*a $*b !, 'gta', "touch gta gtb\n"); unlink(qw(gta gtb)); # Ensure both goal targets are built if they depend on a grouped pattern touch(qw(gta)); # but not gtb run_make_test(q! x y: ; touch $@ x: gta y: gtb %a %b : ; touch $*a $*b !, 'x y', "touch gta gtb\ntouch x\ntouch y\n"); # Now everything should be up to date run_make_test(undef, 'x y', "#MAKE#: 'x' is up to date.\n#MAKE#: 'y' is up to date."); unlink(qw(x y gta gtb)); # sv 12078 : make sure we notice when all targets need to be rebuilt # a.1st exists but b.1st doesn't: make sure a.2nd is out of date as well utouch(-20, 'a.1st'); utouch(-10, 'a.2nd', 'b.2nd'); run_make_test(q! 1st := a.1st b.1st 2nd := ${1st:.1st=.2nd} .PHONY: all all: ${2nd} a.% b.% : ; touch a.$* b.$* ${2nd}: %.2nd: %.1st ; cp $< $@ ! , '', "touch a.1st b.1st\ncp a.1st a.2nd\ncp b.1st b.2nd\n"); unlink(qw(a.1st b.1st a.2nd b.2nd)); # Variation: b.1st exists but is newer utouch(-20, 'a.1st'); utouch(-10, 'a.2nd', 'b.2nd'); touch(qw(b.1st)); run_make_test(undef, '', "cp b.1st b.2nd\n"); unlink(qw(a.1st b.1st a.2nd b.2nd)); } # sv 62206. # The following combinations are generated with and without second expansion. # 1. # all: bye.x # %.x: ... # # 2. # all: lib/bye.x # %.x: ... # # 3. # all: lib/bye.x # lib/%.x: ... # # The following combination is not generated, because there is no rule to # build bye.x, no stem substitution takes place, not of interest of this test. # 4. # all: bye.x # lib/%.x: ... my @dir = ('', 'lib/'); # With and without last slash. my @secondexpansion = ('', '.SECONDEXPANSION:'); for my $se (@secondexpansion) { for my $d (@dir) { # The directory of the prerequisite of 'all'. for my $r (@dir) { # The directory of the target in the rule definition. (!$d && $r) && next; # Combination 4. my $dollar = $se ? '$' : ''; # The prerequisite should only have directory if the prerequisite of 'all' has # it and if the prerequisite pattern in the rule definition does not have it. # That is combination 2. my $pdir = $d && !$r ? $d : ''; my $prereqs = "${pdir}bye.1"; # One func, one %. run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(firstword %.1); \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); $prereqs = "${pdir}bye.1 ${pdir}bye.2"; # Multiple funcs, each has one %. run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(firstword %.1) $dollar\$(firstword %.2); \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4"; # Multiple funcs, each has multiple %. run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(wordlist 1, 99, %.1 %.2) $dollar\$(wordlist 1, 99, %.3 %.4); \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4"; # Nested functions. run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1, 99, %.1 %.2)) $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1,99, %.3 %.4)); \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); $prereqs = "${pdir}bye1%2% ${pdir}bye ${pdir}3bye4%5 ${pdir}6bye ${pdir}bye7%8 ${pdir}bye9 ${pdir}bye10% ${pdir}11bye12 13"; # Multiple funcs, each has multiple words, each word has multiple %, sole %, # various corner cases. # Make should substitute the first % and only the first % in each word with the # stem. run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(wordlist 1, 99, %1%2% % 3%4%5 6%) %7%8 %9 $dollar\$(wordlist 1, 99, %10% 11%12) 13; \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); if ($port_type eq 'UNIX') { # Test that make does not use some hardcoded array of a finite size on stack. # Long prerequisite name. This prerequisite name is over 66K long. my $prefix = 'abcdefgh' x 128 x 33; # 33K long. my $suffix = 'stuvwxyz' x 128 x 33; # 33K long. $prereqs = "${pdir}${prefix}bye${suffix}.1 ${pdir}${prefix}bye${suffix}.2"; run_make_test(" $se all: ${d}bye.x $r%.x: $dollar\$(wordlist 1, 99, ${prefix}%${suffix}.1 ${prefix}%${suffix}.2); \$(info \$@ from \$^) .PHONY: $prereqs ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); } } } } # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/quoting ================================================ # -*-perl-*- $description = "The following test creates a makefile to test using \n" . "quotes within makefiles."; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE <<'EOM'; TEXFONTS = NICEFONT DEFINES = -DDEFAULT_TFM_PATH=\".:$(TEXFONTS)\" test: ; @"echo" 'DEFINES = $(DEFINES)' EOM # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile); # Create the answer to what should be produced by this Makefile $answer = 'DEFINES = -DDEFAULT_TFM_PATH=\".:NICEFONT\"' . "\n"; # COMPARE RESULTS &compare_output($answer,&get_logfile(1)); 1; ================================================ FILE: tests/scripts/features/recursion ================================================ # -*-perl-*- $description = "Test recursion."; $details = "DETAILS"; # Test some basic recursion. run_make_test(' .RECIPEPREFIX := | all: | $(MAKE) -f #MAKEFILE# foo foo: | @echo $(MAKE) | @echo MAKELEVEL = $(MAKELEVEL) | $(MAKE) -f #MAKEFILE# last last: | @echo $(MAKE) | @echo MAKELEVEL = $(MAKELEVEL) | @echo THE END ', ('CFLAGS=-O -w' . ($parallel_jobs ? ' -j 2' : '')), ($vos ? "#MAKE#: Entering directory '#PWD#' make 'CFLAGS=-O' -f #MAKEFILE# foo make CFLAGS=-O MAKELEVEL = 0 make 'CFLAGS=-O' -f #MAKEFILE# last make CFLAGS=-O MAKELEVEL = 0 THE END #MAKE#: Leaving directory '#PWD#'" : "#MAKE#: Entering directory '#PWD#' #MAKEPATH# -f #MAKEFILE# foo #MAKE#[1]: Entering directory '#PWD#' #MAKEPATH# MAKELEVEL = 1 #MAKEPATH# -f #MAKEFILE# last #MAKE#[2]: Entering directory '#PWD#' #MAKEPATH# MAKELEVEL = 2 THE END #MAKE#[2]: Leaving directory '#PWD#' #MAKE#[1]: Leaving directory '#PWD#' #MAKE#: Leaving directory '#PWD#'")); # Test command line overrides. run_make_test(' recur: all ; @$(MAKE) --no-print-directory -f #MAKEFILE# a=AA all all: ; @echo "MAKEOVERRIDES = $(MAKEOVERRIDES)" ', 'a=ZZ', 'MAKEOVERRIDES = a=ZZ MAKEOVERRIDES = a=AA '); # SV 46013: Ensure that MAKEOVERRIDES is passed even if set in the makefile run_make_test(q! ifeq ($(MAKELEVEL),0) MAKEOVERRIDES += FOO+=bar endif .PHONY: M R M: ; @$(MAKE) --no-print-directory -f #MAKEFILE# R R: ; @echo '$(FOO)' !, '', 'bar'); 1; ================================================ FILE: tests/scripts/features/reinvoke ================================================ # -*-mode: perl-*- $description = "Test GNU Make's auto-reinvocation feature."; $details = "\ If the makefile or one it includes can be rebuilt then it is, and make is reinvoked. We create a rule to rebuild the makefile from a temp file, then touch the temp file to make it newer than the makefile."; $omkfile = $makefile; &utouch(-600, 'incl.mk'); # For some reason if we don't do this then the test fails for systems # with sub-second timestamps, maybe + NFS? Not sure. &utouch(-1, 'incl-1.mk'); run_make_test(' all: ; @echo running rules. #MAKEFILE# incl.mk: incl-1.mk ; @echo rebuilding $@; echo >> $@ include incl.mk', '', "rebuilding incl.mk\nrunning rules.\n"); # Make sure updating the makefile itself also works &utouch(-600, $omkfile); run_make_test(undef, '', "rebuilding #MAKEFILE#\nrunning rules.\n"); &rmfiles('incl.mk', 'incl-1.mk'); # In this test we create an included file that's out-of-date, but then # the rule doesn't update it. Make shouldn't re-exec. &utouch(-600, 'b','a'); #&utouch(-10, 'a'); &touch('c'); run_make_test(' all: ; @echo hello a : b ; echo >> $@ b : c ; test -f $@ || echo >> $@ c: ; echo >> $@ include $(F)', 'F=a', "test -f b || echo >> b\nhello\n"); # Now try with the file we're not updating being the actual file we're # including: this and the previous one test different parts of the code. run_make_test(undef, 'F=b', "test -f b || echo >> b\nhello\n"); &rmfiles('a','b','c'); # Ensure command line variables are preserved properly across re-exec # Tests for Savannah bug #30723 run_make_test(' ifdef RECURSE -include foo30723 endif recurse: ; @$(MAKE) -f $(MAKEFILE_LIST) RECURSE=1 test test: ; @echo F.O=$(F.O) foo30723: ; @touch $@ ', '--no-print-directory F.O=bar', "F.O=bar\n"); unlink('foo30723'); # If ANY makefile is rebuilt then we should re-exec run_make_test(' all: ; @echo RESTARTS=$(MAKE_RESTARTS) m1.d: ; @echo $@; touch $@ m2.d: m1.d ; @test -f $< || { echo $@; touch $@; } include m1.d -include m2.d ', '', "m1.d\nRESTARTS=1\n"); unlink('m1.d', 'm2.d'); # Same as before but be sure we get error messages for un-created makefiles run_make_test(' all: ; @echo RESTARTS=$(MAKE_RESTARTS) m1.d: ; @echo $@; touch $@ m2.d: m1.d ; @test -f $< || { echo $@; touch $@; } include m1.d m2.d ', '', # This runs afoul of https://savannah.gnu.org/bugs/?61226 0 ? "m1.d\n#MAKEFILE#:8: m2.d: $ERR_no_such_file" : "m1.d\nRESTARTS=1", 0 ? 512 : 0); unlink('m1.d', 'm2.d'); # sv 61226. # This set of four cases tests two aspects of make. # # 1. If a rule has no prerequisites or recipe, and the target of the rule is a # nonexistent file, then make imagines this target to have been updated # whenever its rule is run. # # 2. Make does not re-execute itself in this case of imagined target. # # Test case 1. # Make imagines hello.d was updated by a rule without recipe and without # prereqs. # This should succeed. # Make should not re-execute itself. run_make_test(' hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) hello.d: include hello.d ', '', "RESTARTS=\n#MAKE#: 'hello.o' is up to date."); # Test case 2. # Make imagines hello.d was updated by a rule with a recipe and without # prereqs. # This should succeed. # Make should not re-execute itself. run_make_test(' hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) hello.d:; $(info $@) include hello.d ', '', "hello.d\nRESTARTS=\n#MAKE#: 'hello.o' is up to date."); &touch('hello.td'); # Test case 3. # Make imagines hello.d was updated by a rule without a recipe and with # prereqs. # This should succeed. # Make should not re-execute itself. run_make_test(' hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) hello.d: hello.td include hello.d ', '', "RESTARTS=\n#MAKE#: 'hello.o' is up to date."); # Test case 4. # Same test as three tests above, but the rule has both recipe and prereqs. # Make should report this error. run_make_test(' hello.o: hello.d; $(info $@) hello.d: hello.td; $(info $@) include hello.d ', '', # This runs afoul of https://savannah.gnu.org/bugs/?61226 0 ? "hello.d\n#MAKEFILE#:4: hello.d: $ERR_no_such_file" : "hello.d\nhello.o\n#MAKE#: 'hello.o' is up to date.", 0 ? 512 : 0); unlink('hello.td'); # Test SV 62088 : make sure we don't re-invoke for stdin makefiles. # The test framework doesn't seem to have a good way to do this. create_file('input.mk', "all:;\$(info all)\n"); close(STDIN); open(STDIN, "<", 'input.mk') || die "input.mk: $!\n"; run_make_test('', '-sf -', "all\n"); # This close MUST come at the end of the test!! close(STDIN); unlink('input.mk'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/rule_glob ================================================ # -*-perl-*- $description = "Test globbing in targets and prerequisites."; $details = ""; touch(qw(a.one a.two a.three)); # Test wildcards in regular targets and prerequisites run_make_test(q{ .PHONY: all a.one a.two a.three all: a.one* a.t[a-z0-9]o a.th[!q]ee a.o[Nn][Ee] a.t*: ; @echo $@ }, '', "a.one\na.two\na.three"); # Test wildcards in pattern targets and prerequisites run_make_test(q{ .PHONY: all all: a.four %.four : %.t* ; @echo $@: $(sort $^) }, '', "a.four: a.three a.two"); # Test wildcards in second expansion targets and prerequisites run_make_test(q{ .PHONY: all all: a.four .SECONDEXPANSION: %.four : $$(sort %.t*) ; @echo $@: $(sort $^) }, '', "a.four: a.three a.two"); unlink(qw(a.one a.two a.three)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/se_explicit ================================================ # -*-perl-*- $description = "Test second expansion in ordinary rules."; $details = ""; # TEST #0: Test handing of '$' in prerequisites with and without second # expansion. # If we don't support archives then the prerequisite is different my $prereq = exists $FEATURES{'archives'} ? '$' : '$(PRE)'; run_make_test(q! ifdef SE .SECONDEXPANSION: endif foo$$bar: bar$$baz bar$$biz ; @echo '$@ : $^' PRE = one two bar$$baz: $$(PRE) baraz: $$(PRE) PRE = three four .DEFAULT: ; @echo '$@' !, '', "$prereq\nbar\$biz\nfoo\$bar : bar\$baz bar\$biz"); run_make_test(undef, 'SE=1', "three\nfour\nbariz\nfoo\$bar : baraz bariz"); # TEST #1: automatic variables. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' foo: bar baz foo: biz | buz foo: $$@.1 \ $$<.2 \ $$(addsuffix .3,$$^) \ $$(addsuffix .4,$$+) \ $$|.5 \ $$*.6 !, '', 'bar baz biz buz foo.1 bar.2 bar.3 baz.3 biz.3 bar.4 baz.4 biz.4 buz.5 .6 '); # Test #2: target/pattern -specific variables. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' foo.x: $$a $$b foo.x: a := bar %.x: b := baz !, '', 'bar baz '); # Test #3: order of prerequisites. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' all: foo bar baz # Subtest #1 foo: foo.1; @: foo: foo.2 foo: foo.3 # Subtest #2 bar: bar.2 bar: bar.1; @: bar: bar.3 # Subtest #3 baz: baz.1 baz: baz.2 baz: ; @: !, '', 'foo.1 foo.2 foo.3 bar.1 bar.2 bar.3 baz.1 baz.2 '); # TEST #4: eval in a context where there is no reading_file run_make_test(q! .SECONDEXPANSION: all : $$(eval $$(info test)) !, '', "test\n#MAKE#: Nothing to be done for 'all'.\n"); # TEST #5: (NEGATIVE) catch eval in a prereq list trying to create new # target/prereq relationships. run_make_test(q! .SECONDEXPANSION: proj1.exe : proj1.o $$(eval $$(test)) define test proj1.o : proj1.c proj1.c: proj1.h endef !, '', "#MAKE#: *** prerequisites cannot be defined in recipes. Stop.\n", 512); # Automatic $$+ variable expansion issue. Savannah bug #25780 run_make_test(q! all : foo foo .SECONDEXPANSION: all : $$+ ; @echo '$+' foo : ; !, '', "foo foo foo foo\n"); # Automatic $$+ variable expansion issue. Savannah bug #25780 run_make_test(q! all : bar bar bar : ; q%x : ; .SECONDEXPANSION: a%l: q1x $$+ q2x ; @echo '$+' !, '', "q1x bar bar q2x bar bar\n"); # Allow patsubst shorthand in second expansion context. # Requires the colon to be quoted. Savannah bug #16545 run_make_test(q! .PHONY: foo.bar .SECONDEXPANSION: foo: $$(@\\:%=%.bar); @echo '$^' !, '', "foo.bar\n"); # SV 54549 : Ensure we don't free used variable_sets run_make_test(q! foo: -lcat # Removing second expansion prevents segfault .SECONDEXPANSION: foo: $$@.o ; # Having an empty command here prevents segfault unless, # the environment is empty. `env -i make foo` # MFLAGS=-w or MAKEFLAGS=-w `env MFLAGS=-w make foo` # libcat.a target calls an extra command, `@true \n @touch $@` # odd. %.o: ; @true # Having an empty command prevents segfault. -l%: lib%.a ; @true # Not creating libcat.a here prevents segfault, libcat.a: ; @touch $@ !, '', q!#MAKEFILE#:16: recipe was specified for file '-lcat' at #MAKEFILE#:16, #MAKEFILE#:16: but '-lcat' is now considered the same file as 'libcat.a' #MAKEFILE#:16: recipe for '-lcat' will be ignored in favor of the one for 'libcat.a'!); unlink('libcat.a'); # SV 28456 : Don't reset $$< for default recipes run_make_test(q! .SECONDEXPANSION: .PHONY: biz baz biz: baz ; biz: $$(info $$<) !, '', "baz\n#MAKE#: Nothing to be done for 'biz'.\n"); # sv 60659. Second expansion of automatic variables inside a function in the # prerequisite list. # $$@ expands to the target in the 1st and following rules. # $$<,$$^,$$+,$$|,$$?,$$*,$$% expand to the empty string in the prerequisite # list of the 1st rule. # $$<,$$^,$$+,$$|,$$?,$$*,$$% in the prerequisite list of the 2nd (and # following) rule expand to the values from the 1st rule. # subtest 1. Explicit rules. 1st rule. run_make_test(q! .SECONDEXPANSION: all: 2.x 2.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # subtest 2. Explicit rules. 2nd rule. run_make_test(q! .SECONDEXPANSION: all: 15.x 1.x 15.x: 5.z 6.z 5.z | 7.z 7.z 8.z 1.x: 1.z 2.z 2.z | 3.z 4.z 15.x 1.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=15.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=,%= @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # subtest 3. Grouped targets in explicit rules. 1st rule. run_make_test(q! .SECONDEXPANSION: all: 15.x 15.x 1.x&: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=15.x,<=,^=,+=,|=,?=,*=,%= @=1.x,<=,^=,+=,|=,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # subtest 4. Grouped targets in explicit rules. 2nd rule. run_make_test(q! .SECONDEXPANSION: all: 15.x 1.x 15.x: 5.z 6.z 5.z | 7.z 7.z 8.z 1.x: 1.z 2.z 2.z | 3.z 4.z 15.x 1.x&: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=15.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=,%= @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # Double colon rules. # Because each double colon rule is independent of the other double colon rules # for the same target, each automatic variable in the prerequisite list, other # than $$@, second expands to the empty string in any rule, 1st, 2nd or later. # subtest 5. 1st double colon rule. run_make_test(q! .SECONDEXPANSION: all: 2.x 2.x:: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # subtest 6. 2nd double colon rule. run_make_test(q! .SECONDEXPANSION: all: 15.x 1.x 15.x:: 5.z 6.z 5.z | 7.z 7.z 8.z ; 1.x:: 1.z 2.z 2.z | 3.z 4.z ; 15.x 1.x:: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ; %.z: ; !, '', "@=15.x,<=,^=,+=,|=,?=,*=,%= @=1.x,<=,^=,+=,|=,?=,*=,%= #MAKE#: Nothing to be done for 'all'.\n"); # sv 62324. # Integrity self check. run_make_test(q! .SECONDEXPANSION: all: bye.x bye.x: $$(firstword bye.1; !, '', "#MAKEFILE#:4: *** unterminated call to function 'firstword': missing ')'. Stop.", 512); unlink('hello.tsk', 'test.o', 'bye.tsk', 'hello.o', 'hello.h', 'hello.q', 'bye.c', 'bye.o'); # sv 62706. # Test that makes avoids second expanding prerequisites of the targets which # are not built. # Here, hello.tsk is built and its prerequisites are second expanded. # bye.tsk is not built and its prerequisites are not second expanded. run_make_test(q! .SECONDEXPANSION: hello.tsk: hello.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk: bye.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) bye.o: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Multiple rules per target. run_make_test(q! .SECONDEXPANSION: all: hello.tsk dep1:=hello.o dep2:=hello.h hello.tsk: $$(dep1) hello.tsk: $$(dep2); $(info $@ from $^) hello.o:; $(info $@) hello.h:; $(info $@) !, 'hello.tsk', "hello.h hello.o hello.tsk from hello.h hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Multiple targets per rule. run_make_test(q! .SECONDEXPANSION: hello.tsk bye.tsk: hello.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk: bye.o $$(info second expansion of $$@ prereqs) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) bye.o: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Grouped targets. run_make_test(q! .SECONDEXPANSION: world.tsk: world.o $$(info 1 second expansion of $$@ prereqs) hello.tsk world.tsk &: hello.o $$(info 2 second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk: bye.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) world.o: $$(info second expansion of $$@ prereqs); $(info $@) bye.o: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "2 second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o 2 second expansion of world.tsk prereqs 1 second expansion of world.tsk prereqs second expansion of world.o prereqs world.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Order only. run_make_test(q! .SECONDEXPANSION: hello.tsk:| hello.o $$(info second expansion of $$@ prereqs); $(info $@ from $|) bye.tsk:| bye.o $$(info second expansion of $$@ prereqs); $(info $@ from $|) hello.o:| $$(info second expansion of $$@ prereqs); $(info $@) bye.o:| $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Double colon. 1 rule per target. run_make_test(q! .SECONDEXPANSION: hello.tsk:: hello.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk:: bye.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) hello.o:: $$(info second expansion of $$@ prereqs); $(info $@) bye.o:: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Double colon. 2 rules per targets. run_make_test(q! .SECONDEXPANSION: hello.tsk:: hello.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<) hello.tsk:: hello.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<) bye.tsk:: bye.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<) bye.tsk:: bye.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<) hello.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@) hello.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@) bye.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@) bye.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@) !, 'hello.tsk', "1 second expansion of hello.tsk prereqs 1 second expansion of hello.o prereqs 1 hello.o 2 second expansion of hello.o prereqs 2 hello.o 1 hello.tsk from hello.o 2 second expansion of hello.tsk prereqs 2 hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Test that the prerequisites of 'hello.tsk' are second expanded once. run_make_test(q! .SECONDEXPANSION: all: hello.tsk hello.q hello.tsk: hello.o $$(info second expansion of $$@ prereqs); $(info $@ from $^) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) hello.q: hello.tsk $$(info second expansion of $$@ prereqs); $(info $@ from $^) !, '', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o second expansion of hello.q prereqs hello.q from hello.tsk #MAKE#: Nothing to be done for 'all'.\n"); # sv 62706. # Merge vpath file and local file. # Test that both sets of prerequisites from 'hello.c' rule and from # 'src/hello.c' rule are second expanded. run_make_test(q! .SECONDEXPANSION: vpath hello.c src all: hello.c; $(info $@ from $^) hello.c: $$(info second expansion of hello.c prereqs); $(info 1 $@) src/hello.c: $$(info second expansion of src/hello.c prereqs); $(info 2 $@) !, '', "#MAKEFILE#:5: recipe was specified for file 'hello.c' at #MAKEFILE#:5, #MAKEFILE#:5: but 'hello.c' is now considered the same file as 'src/hello.c' #MAKEFILE#:5: recipe for 'hello.c' will be ignored in favor of the one for 'src/hello.c' second expansion of src/hello.c prereqs second expansion of hello.c prereqs 2 src/hello.c all from src/hello.c #MAKE#: 'all' is up to date.\n"); # sv 62706. # .DEFAULT. run_make_test(q! .SECONDEXPANSION: bye:=bye.c all: hello.o .DEFAULT: $$(info second expansion of prereqs of default recipe @ = $$@) ; $(info default recipe $@) !, '', "default recipe hello.o #MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.1'); # sv 62706. # No side effects from second expansion of unrelated rules. run_make_test(q! .SECONDEXPANSION: hello.tsk:; exit 1 unrelated: $$(shell touch hello.1); !, '', "exit 1 #MAKE#: *** [#MAKEFILE#:3: hello.tsk] Error 1\n", 512); # sv 62706. # Second expansion of intermediate prerequisites. # The rule to build hello.x is explicit. # .SECONDARY marks hello.x as intermediate. # Test that $$(deps) is secondary expanded. run_make_test(q! deps:=hello.h .SECONDEXPANSION: .SECONDARY: hello.x all: hello.x hello.x: $$(deps); $(info $@) hello.h:; $(info $@) !, '', "hello.h\nhello.x\n#MAKE#: Nothing to be done for 'all'.\n"); 1; ================================================ FILE: tests/scripts/features/se_implicit ================================================ # -*-perl-*- $description = "Test second expansion in implicit rules."; $details = ""; use Cwd; $dir = cwd; $dir =~ s,.*/([^/]+)$,../$1,; # Test #1: automatic variables. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' foo.a: bar baz foo.a: biz | buz foo.%: 1.$$@ \ 2.$$< \ $$(addprefix 3.,$$^) \ $$(addprefix 4.,$$+) \ 5.$$| \ 6.$$* ; @: 1.foo.a \ 2.bar \ 3.bar \ 3.baz \ 3.biz \ 4.bar \ 4.baz \ 4.biz \ 5.buz \ 6.a: ; @echo '$@' !, '', '1.foo.a 2.bar 3.bar 3.baz 3.biz 4.bar 4.baz 4.biz 5.buz 6.a bar baz biz buz '); # Test #2: target/pattern -specific variables. # run_make_test(q! .SECONDEXPANSION: foo.x: foo.%: $$(%_a) $$(%_b) bar ; @: foo.x: x_a := bar %.x: x_b := baz bar baz: ; @echo '$@' !, '', "bar\nbaz\n"); # Test #3: order of prerequisites. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' all: foo bar baz # Subtest #1 # %oo: %oo.1; @: foo: foo.2 foo: foo.3 foo.1: ; @echo '$@' # Subtest #2 # bar: bar.2 %ar: %ar.1; @: bar: bar.3 bar.1: ; @echo '$@' # Subtest #3 # baz: baz.1 baz: baz.2 %az: ; @: !, '', 'foo.1 foo.2 foo.3 bar.1 bar.2 bar.3 baz.1 baz.2 '); # Test #4: stem splitting logic. # run_make_test(q! .SECONDEXPANSION: $(dir)/tmp/bar.o: $(dir)/tmp/foo/bar.c: ; @echo '$@' $(dir)/tmp/bar/bar.c: ; @echo '$@' foo.h: ; @echo '$@' %.o: $$(addsuffix /%.c,foo bar) foo.h ; @echo '$@: {$<} $^' !, "dir=$dir", "$dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h "); # Test #5: stem splitting logic and order-only prerequisites. # run_make_test(q! .SECONDEXPANSION: $(dir)/tmp/foo.o: $(dir)/tmp/foo.c $(dir)/tmp/foo.c: ; @echo '$@' bar.h: ; @echo '$@' %.o: %.c|bar.h ; @echo '$@: {$<} {$|} $^' !, "dir=$dir", "$dir/tmp/foo.c bar.h $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c "); # Test #6: lack of implicit prerequisites. # run_make_test(q! .SECONDEXPANSION: foo.o: foo.c foo.c: ; @echo '$@' %.o: ; @echo '$@: {$<} $^' !, '', "foo.c\nfoo.o: {foo.c} foo.c\n"); # Test #7: Test stem from the middle of the name. # run_make_test(q! .SECONDEXPANSION: foobarbaz: foo%baz: % $$*.1 ; @echo '$*' bar bar.1: ; @echo '$@' !, '', "bar\nbar.1\nbar\n"); # Test #8: Make sure stem triple-expansion does not happen. # run_make_test(q! .SECONDEXPANSION: foo$$bar: f%r: % $$*.1 ; @echo '$*' oo$$ba oo$$ba.1: ; @echo '$@' !, '', 'oo$ba oo$ba.1 oo$ba '); # Test #9: Check the value of $^ run_make_test(q! .SECONDEXPANSION: %.so: | $$(extra) ; @echo $^ foo.so: extra := foo.o foo.so: foo.o: !, '', "\n"); # Test #10: Test second expansion with second expansion prerequisites # Ensures pattern_search() recurses with SE prereqs. touch('a'); run_make_test(q! .SECONDEXPANSION: sim_base_rgg := just_a_name sim_base_src := a sim_base_f := a a a sim_%.f: $${sim_$$*_f} ; echo $@ sim_%.src: $${sim_$$*_src} ; echo $@ sim_%: \ $$(if $$(sim_$$*_src),sim_%.src) \ $$(if $$(sim_$$*_f),sim_%.f) \ $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s) ; echo $@ !, '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'. Stop.", 512); unlink('a'); # Ensure that order-only tokens embedded in second expansions are parsed run_make_test(q! .SECONDEXPANSION: PREREQS=p1|p2 P2=p2 all : foo bar f%o: $$(PREREQS) ; @echo '$@' from '$^' and '$|' b%r: p1|$$(P2) ; @echo '$@' from '$^' and '$|' p% : ; : $@ !, "", ": p1\n: p2\nfoo from p1 and p2\nbar from p1 and p2\n"); # SV 28456 : Don't reset $$< for default recipes run_make_test(q! .SECONDEXPANSION: .PHONY: foo bar foo: bar foo: $$(info $$<) %oo: ; !, '', "bar\n#MAKE#: Nothing to be done for 'foo'.\n"); # SV 54161: Expand $$* properly when it contains a path run_make_test(q! .SECONDEXPANSION: %x: $$(info $$*); @echo '$*' !, 'q/ux', "q/u\nq/u\n"); # sv 60188. # Test that a file explicitly mentioned by the user and made by an implicit # rule is not considered intermediate. touch('hello.z'); # subtest 1. # hello.x is derived from the stem and thus is an intermediate file. run_make_test(q! .SECONDEXPANSION: dep:=.x all: hello.z %.z: %$$(dep) ; @echo $@ %.x: ; !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 2. # test.x is explicitly mentioned and thus is not an intermediate file. run_make_test(q! .SECONDEXPANSION: dep:=test.x all: hello.z %.z: %.x $$(dep) ; @echo $@ %.x: ; !, '', "hello.z\n"); # subtest 3. # make is building hello.z and does not second expand the prerequisites of rule # 'unrelated: $$(dep)'. '$$(dep)' stays not expanded and 'hello.x' is never # entered to the database. Make considers 'hello.x' intermediate while building # 'hello.z'. Because 'hello.z' is present and 'hello.x' is missing and # 'hello.x' is intermediate, there is no need to rebuild 'hello.z'. run_make_test(q! .SECONDEXPANSION: dep:=hello.x all: hello.z %.z: %.x; @echo $@ %.x: ; unrelated: $$(dep) !, '', "#MAKE#: Nothing to be done for 'all'.\n"); # subtest 4. # Just like subtest 3. $$(dep) is not second expanded. 'hello.x' is # intermediate. run_make_test(q! .SECONDEXPANSION: dep:=hello.x all: hello.z %.z: %.x; @echo $@ %.x: ; %.q: $$(dep) !, '', "#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.z'); # sv 60188. # Test that a file explicitly mentioned by the user and made by an implicit # rule is not considered intermediate, even when the builtin rules are used. touch('hello.x'); touch('hello.tsk'); # subtest 1. # hello.z is explicitly mentioned and thus is not an intermediate file. run_make_test(q! .SECONDEXPANSION: dep:=hello.z all: hello.tsk %.tsk: $$(dep) ; @echo $@ %.z : %.x ; @echo $@ !, '', "hello.z\nhello.tsk"); # subtest 2. # hello.z is derived from the stem and thus is an intermediate file. run_make_test(q! .SECONDEXPANSION: dep:=.z all: hello.tsk %.tsk: %$$(dep) ; @echo $@ %.z : %.x ; @echo $@ !, '', "#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.x'); unlink('hello.tsk'); # sv 60659. Second expansion of automatic variables inside a function in the # prerequisite list. # $$@ expands to the target in the 1st and following rules. # $$* expands to the stem in the 1st and following rules. # $$<,$$^,$$+,$$|,$$?,$$% expand to the empty string in the prerequisite list # of the 1st rule. # $$<,$$^,$$+,$$|,$$?,$$% in the prerequisite list of the 2nd (and following) # rule expand to the values from the 1st rule. # $$% cannot be used in prerequisites, because in pattern rules % is # substituted for stem. # subtest 1. Pattern rules. 1st rule. run_make_test(q! .SECONDEXPANSION: all: 2.x %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=2 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 2. Pattern rules. 2nd rule. run_make_test(q! .SECONDEXPANSION: all: 2.x 1.x 2.x: 5.z 6.z 5.z | 7.z 7.z 8.z 1.x: 1.z 2.z 2.z | 3.z 4.z %.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=2 @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 3. Static pattern rules. 1st rule. run_make_test(q! .SECONDEXPANSION: all: 2.x 2.x: %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=2 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 4. Static pattern rules. 2nd rule. run_make_test(q! .SECONDEXPANSION: all: 15.x 1.x 15.x: 5.z 6.z 5.z | 7.z 7.z 8.z 1.x: 1.z 2.z 2.z | 3.z 4.z 15.x 1.x: %.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=15.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=15 @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 5. Grouped targets in implicit rules. 1st rule. run_make_test(q! .SECONDEXPANSION: all: 2.x %.x %.xx&: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=2 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 6. Grouped targets in implicit rules. 2nd rule. run_make_test(q! .SECONDEXPANSION: all: 2.x 1.xx 2.x: 5.z 6.z 5.z | 7.z 7.z 8.z 1.xx: 1.z 2.z 2.z | 3.z 4.z %.x %.xx&: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; %.z: ; !, '', "@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=2 @=1.xx,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1 #MAKE#: Nothing to be done for 'all'.\n"); # subtest 7. Double colon rule. run_make_test(q! .SECONDEXPANSION: all: 2.x %.x:: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ; 5.z 6.z: ; !, '', "@=2.x,<=,^=,+=,|=,?=,*=2 #MAKE#: Nothing to be done for 'all'.\n"); # sv 62324. # Integrity self check. run_make_test(q! .SECONDEXPANSION: all: bye.x %.x: $$(firstword %.1; !, '', "#MAKE#: *** unterminated call to function 'firstword': missing ')'. Stop.", 512); # sv 62706. # Test that makes avoids second expanding prerequisites of the rules which are # not tried during implicit search. # Here, make tries rules '%.tsk: %.o' and '%.o' and their prerequisites are # second expanded. # Rules '%.bin: %.x' and '%.x:' are not used in implicit search for 'hello.tsk' # and 'hello.o' and their prerequisites are not expanded. run_make_test(q! .SECONDEXPANSION: %.bin: %.x $$(info second expansion of $$@ prereqs); $(info $@ from $<) %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) %.x: $$(info second expansion of $$@ prereqs); $(info $@) %.o: $$(info second expansion of $$@ prereqs); $(info $@) !, '-R hello.tsk', "second expansion of hello.o prereqs second expansion of hello.tsk prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # No side effects from second expansion of unrelated rules. run_make_test(q! .SECONDEXPANSION: all: hello.tsk %.tsk: %.o; exit 1 hello.o:; %.q: $$(shell touch hello.1); !, '', "exit 1 #MAKE#: *** [#MAKEFILE#:4: hello.tsk] Error 1\n", 512); # sv 62706. # Second expansion of intermediate prerequisites. # The rule to build hello.x is implicit. # Test that $$(deps) is secondary expanded. run_make_test(q! deps:=hello.h .SECONDEXPANSION: all: hello.tsk %.tsk: %.x; $(info $@) %.x: $$(deps); $(info $@) hello.h:; $(info $@) !, '', "hello.h\nhello.x\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/se_statpat ================================================ # -*-perl-*- $description = "Test second expansion in static pattern rules."; $details = ""; # Test #1: automatic variables. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' foo.a foo.b: foo.%: bar.% baz.% foo.a foo.b: foo.%: biz.% | buz.% foo.a foo.b: foo.%: $$@.1 \ $$<.2 \ $$(addsuffix .3,$$^) \ $$(addsuffix .4,$$+) \ $$|.5 \ $$*.6 !, '', 'bar.a baz.a biz.a buz.a foo.a.1 bar.a.2 bar.a.3 baz.a.3 biz.a.3 bar.a.4 baz.a.4 biz.a.4 buz.a.5 a.6 '); # Test #2: target/pattern -specific variables. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' foo.x foo.y: foo.%: $$(%_a) $$($$*_b) foo.x: x_a := bar %.x: x_b := baz !, '', "bar\nbaz\n"); # Test #3: order of prerequisites. # run_make_test(q! .SECONDEXPANSION: .DEFAULT: ; @echo '$@' all: foo.a bar.a baz.a # Subtest #1 foo.a foo.b: foo.%: foo.%.1; @: foo.a foo.b: foo.%: foo.%.2 foo.a foo.b: foo.%: foo.%.3 # Subtest #2 bar.a bar.b: bar.%: bar.%.2 bar.a bar.b: bar.%: bar.%.1; @: bar.a bar.b: bar.%: bar.%.3 # Subtest #3 baz.a baz.b: baz.%: baz.%.1 baz.a baz.b: baz.%: baz.%.2 baz.a baz.b: ; @: !, '', 'foo.a.1 foo.a.2 foo.a.3 bar.a.1 bar.a.2 bar.a.3 baz.a.1 baz.a.2 '); # Test #4: Make sure stem triple-expansion does not happen. # run_make_test(q! .SECONDEXPANSION: foo$$bar: f%r: % $$*.1 ; @echo '$*' oo$$ba oo$$ba.1: ; @echo '$@' !, '', 'oo$ba oo$ba.1 oo$ba '); # sv 62324. # Integrity self check. run_make_test(q! .SECONDEXPANSION: all: bye.x bye.x: %.x: $$(firstword %.1; !, '', "#MAKEFILE#:4: *** unterminated call to function 'firstword': missing ')'. Stop.", 512); #unlink('hello.tsk', 'bye.tsk', 'hello.o', 'hello.q', 'bye.o'); # sv 62706. # Test that makes avoids second expanding prerequisites of the targets which # are not built. # Here, hello.tsk is built and its prerequisites are second expanded. # bye.tsk is not built and its prerequisites are not second expanded. # Static pattern rules. run_make_test(q! .SECONDEXPANSION: hello.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) bye.o: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Order only prereqs. run_make_test(q! .SECONDEXPANSION: hello.tsk: %.tsk:| %.o $$(info second expansion of $$@ prereqs); $(info $@ from $|) bye.tsk: %.tsk:| %.o $$(info second expansion of $$@ prereqs); $(info $@ from $|) hello.o:| $$(info second expansion of $$@ prereqs); $(info $@) bye.o:| $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Double colon. 1 rule per target. run_make_test(q! .SECONDEXPANSION: hello.tsk:: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) bye.tsk:: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<) hello.o:: $$(info second expansion of $$@ prereqs); $(info $@) bye.o:: $$(info second expansion of $$@ prereqs); $(info $@) !, 'hello.tsk', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Double colon. 2 rules per target. run_make_test(q! .SECONDEXPANSION: hello.tsk:: %.tsk: %.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<) hello.tsk:: %.tsk: %.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<) bye.tsk:: %.tsk: %.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<) bye.tsk:: %.tsk: %.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<) hello.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@) hello.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@) bye.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@) bye.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@) !, 'hello.tsk', "1 second expansion of hello.tsk prereqs 1 second expansion of hello.o prereqs 1 hello.o 2 second expansion of hello.o prereqs 2 hello.o 1 hello.tsk from hello.o 2 second expansion of hello.tsk prereqs 2 hello.tsk from hello.o #MAKE#: 'hello.tsk' is up to date.\n"); # sv 62706. # Test that the prerequisites of 'hello.tsk' are second expanded once. run_make_test(q! .SECONDEXPANSION: all: hello.tsk hello.q hello.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $^) hello.o: $$(info second expansion of $$@ prereqs); $(info $@) hello.q: %.q: %.tsk $$(info second expansion of $$@ prereqs); $(info $@ from $^) !, '', "second expansion of hello.tsk prereqs second expansion of hello.o prereqs hello.o hello.tsk from hello.o second expansion of hello.q prereqs hello.q from hello.tsk #MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.1'); # sv 62706. # No side effects from second expansion of unrelated rules. run_make_test(q! .SECONDEXPANSION: all: hello.tsk hello.tsk: %.tsk: %.o; exit 1 hello.o:; bye.tsk: %.tsk: $$(shell touch hello.1); !, '', "exit 1 #MAKE#: *** [#MAKEFILE#:4: hello.tsk] Error 1\n", 512); # sv 62706. # Second expansion of intermediate prerequisites. # The rule to build hello.x is static pattern. # .SECONDARY marks hello.x as intermediate. # Test that $$(deps) is secondary expanded. run_make_test(q! deps:=hello.h .SECONDEXPANSION: .SECONDARY: hello.x all: hello.x hello.x: %.x: $$(deps); $(info $@) hello.h:; $(info $@) !, '', "hello.h\nhello.x\n#MAKE#: Nothing to be done for 'all'.\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/shell_assignment ================================================ # -*-perl-*- $description = "Test BSD-style shell assignments (VAR != VAL) for variables."; $details = ""; # TEST 0: Basic shell assignment (!=). run_make_test(' .POSIX: demo1!=printf \' 1 2 3\n4\n\n5 \n \n 6\n\n\n\n\' demo2 != printf \'7 8\n \' demo3 != printf \'$$(demo2)\' demo4 != printf \' 2 3 \n\' demo5 != printf \' 2 3 \n\n\' all: ; @echo "<$(demo1)> <$(demo2)> <$(demo3)> <$(demo4)> <${demo5}>" ', '', "< 1 2 3 4 5 6 > <7 8 > <7 8 > < 2 3 > < 2 3 >\n"); # TEST 1: Handle '#' the same way as BSD make $hashOctal = "\\043"; if ($osname eq 'os390') { $hashOctal = "\\173"; } run_make_test(' foo1!=echo bar#baz hash != printf \'' . $hashOctal . '\' foo2!= echo "bar$(hash)baz" all: ; @echo "<$(foo1)> <$(hash)> <$(foo2)>" ', '', " <#> \n"); # TEST 2: shell assignment variables (from !=) should be recursive. # Note that variables are re-evaluated later, so the shell can output # a value like $(XYZZY) as part of !=. The $(XYZZY) will be EVALUATED # when the value containing it is evaluated. On the negative side, this # means if you don't want this, you need to escape dollar signs as $$. # On the positive side, it means that shell programs can output macros # that are then evaluated as they are traditionally evaluated.. and that # you can use traditional macro evaluation semantics to implement !=. run_make_test(' XYZZY = fiddle-dee-dee dollar = $$ VAR3 != printf \'%s\' \'$(dollar)(XYZZY)\' all: ; @echo "<$(VAR3)>" ', '', "\n"); # TEST 3: Overrides invoke shell anyway; they just don't store the result # in a way that is visible. run_make_test(' override != echo abc > ,abc ; cat ,abc all: ; @echo "<$(override)>" ; cat ,abc ', 'override=xyz', "\nabc\n"); unlink(',abc'); 1; ================================================ FILE: tests/scripts/features/statipattrules ================================================ # -*-perl-*- $description = "Test handling of static pattern rules."; $details = "\ The makefile created in this test has three targets. The filter command is used to get those target names ending in .o and statically creates a compile command with the target name and the target name with .c. It also does the same thing for another target filtered with .elc and creates a command to emacs a .el file"; &touch('bar.c', 'lose.c'); # TEST #0 # ------- run_make_test(' files = foo.elc bar.o lose.o $(filter %.o,$(files)): %.o: %.c ; @echo CC -c $(CFLAGS) $< -o $@ $(filter %.elc,$(files)): %.elc: %.el ; @echo emacs $< ', '', 'CC -c bar.c -o bar.o'); # TEST #1 # ------- run_make_test(undef, 'lose.o', 'CC -c lose.c -o lose.o'); # TEST #2 # ------- &touch("foo.el"); run_make_test(undef, 'foo.elc', 'emacs foo.el'); # Clean up after the first tests. unlink('foo.el', 'bar.c', 'lose.c'); # TEST #3 -- PR/1670: don't core dump on invalid static pattern rules # ------- run_make_test(' .DEFAULT: ; @echo $@ foo: foo%: % %.x % % % y.% % ; @echo $@ ', '', ".x\ny.\nfoo"); # TEST #4 -- bug #12180: core dump on a stat pattern rule with an empty # prerequisite list. run_make_test(' foo.x bar.x: %.x : ; @echo $@ ', '', 'foo.x'); # TEST #5 -- bug #13881: double colon static pattern rule does not # substitute %. run_make_test(' foo.bar:: %.bar: %.baz foo.baz: ;@: ', '', ''); # TEST #6: make sure the second stem does not overwrite the first # perprerequisite's stem (Savannah bug #16053). # run_make_test(' .RECIPEPREFIX := > all.foo.bar: %.foo.bar: %.one all.foo.bar: %.bar: %.two all.foo.bar: > @echo $* > @echo $^ .DEFAULT:;@: ', '', 'all.foo all.one all.foo.two'); # TEST #7: make sure the second stem does not overwrite the first # perprerequisite's stem when second expansion is enabled # (Savannah bug #16053). # run_make_test(' .RECIPEPREFIX := > .SECONDEXPANSION: all.foo.bar: %.foo.bar: %.one $$*-one all.foo.bar: %.bar: %.two $$*-two all.foo.bar: > @echo $* > @echo $^ .DEFAULT:;@: ', '', 'all.foo all.one all-one all.foo.two all.foo-two'); # Test #8: # sv 60188. # Static pattern rules are considered explicit rules: no prerequisite of # a static pattern rule can ever be considered intermediate. touch('hello.z'); # subtest 1 run_make_test(q! hello.z: %.z: %.x ; @echo $@ %.x: ; !, '', "hello.z\n"); # subtest 2 run_make_test(q! hello.z: %.z: %.x test.x ; @echo $@ %.x: ; !, '', "hello.z\n"); # subtest 3 # 'hello.x' is mentioned explicitly on an unrelated rule. run_make_test(q! hello.z: %.z: %.x ; @echo $@ %.x: ; unrelated: hello.x !, '', "hello.z\n"); unlink('hello.z'); # sv 17374 Ensure double-colon static pattern rules work touch(qw(a.src b.src)); run_make_test(q! all: a.tgt b.tgt a.tgt b.tgt:: %.tgt : %.src ; cp $< $@ !, '', "cp a.src a.tgt\ncp b.src b.tgt\n"); unlink(qw(a.src b.src a.tgt b.tgt)); my @dir = ('', 'lib/'); # With and without last slash. my @secondexpansion = ('', '.SECONDEXPANSION:'); # The following combinations are generated with and without second expansion. # 1. # all: bye.x # bye.x: %.x: ... # # 2. # all: lib/bye.x # lib/bye.x: %.x: ... # # 3. # all: lib/bye.x # lib/bye.x: lib/%.x: ... # # The following combination is not generated, because there is no rule to # build bye.x, no stem substitution takes place, not of interest of this test. # 4. # all: bye.x # bye.x: lib/%.x: ... # for my $se (@secondexpansion) { for my $d (@dir) { # The directory of the prerequisite of 'all'. for my $r (@dir) { # The directory of the prerequisite in the rule definition. (!$d && $r) && next; # Combination 4. my $dollar = $se ? '$' : ''; # The prerequisite should only have directory if the prerequisite of 'all' has # it and if the prerequisite pattern in the rule definition does not have it. # That is combination 2. my $pdir = $d && !$r ? $d : ''; # One func, one %. my $prereqs = "${pdir}bye.1"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(firstword %.1); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # Multiple funcs, each has one %. $prereqs = "${pdir}bye.1 ${pdir}bye.2"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(firstword %.1) $dollar\$(firstword %.2); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # Multiple funcs, each has multiple %. $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %.1 %.2) $dollar\$(wordlist 1, 99, %.3 %.4); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # Multiple funcs, each has multiple %, each prerequisite has multiple %. $prereqs = "${pdir}bye_%_%.1 ${pdir}bye_%_%.2 ${pdir}bye_%_%.3 ${pdir}bye_%_%.4"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %_%_%.1 %_%_%.2) $dollar\$(wordlist 1, 99, %_%_%.3 %_%_%.4); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # Nested functions. $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1, 99, %.1 %.2)) $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1,99, %.3 %.4)); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # Multiple funcs, each has multiple words, each word has multiple %, sole %, # various corner cases. # Make should substitute the first % and only the first % in each word with the # stem. $prereqs = "${pdir}bye1%2% ${pdir}bye 3${pdir}bye4%5 6${pdir}bye ${pdir}bye7%8 ${pdir}bye9 ${pdir}bye10% 11${pdir}bye12 13"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %1%2% % 3%4%5 6%) %7%8 %9 $dollar\$(wordlist 1, 99, %10% 11%12) 13; \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); if ($port_type eq 'UNIX') { # Test that make does not use some hardcoded array of a finite size on stack. # Long prerequisite name. This prerequisite name is over 66K long. my $prefix = 'abcdefgh' x 128 x 33; # 33K long. my $suffix = 'stuvwxyz' x 128 x 33; # 33K long. $prereqs = "${prefix}${pdir}bye${suffix}.1 ${prefix}${pdir}bye${suffix}.2"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, ${prefix}%${suffix}.1 ${prefix}%${suffix}.2); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); } # Empty stem. $prereqs = "${pdir}.1"; run_make_test(" $se .PHONY: $prereqs all: ${d}bye.x ${d}bye.x: $r%bye.x: $dollar\$(firstword %.1); \$(info \$@ from \$^) ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); # A word expands to an empty prerequisite. run_make_test(" $se all: ${d}bye.x ${d}bye.x: $r%.x: $dollar\$(%); \$(info \$@ from \$^) ", '', "${d}bye.x from \n#MAKE#: Nothing to be done for 'all'.\n"); } } } # Escaped %. # The following combinations are generated without second expansion. # 1. # all: the%weird\\_hello_pattern\\.x # the\\%weird\\_hello_pattern\\.x: the\\%weird\\_%_pattern\\.x: ... # # 2. # all: lib/the%weird\\_hello_pattern\\.x # lib/the\\%weird\\_hello_pattern\\.x: lib/the\\%weird\\_%_pattern\\.x: ... # # Other combinations or second expansion are not tested, because escaped % is # not implemented for those. for my $d (@dir) { my $prereqs = "${d}the%weird\\\\_hello_pattern%\\\\.1 ${d}the%weird\\\\_hello_pattern%\\\\.2"; run_make_test(" .PHONY: $prereqs all: ${d}the%weird\\\\_hello_pattern\\\\.x ${d}the\\%weird\\\\_hello_pattern\\\\.x: ${d}the\\%weird\\\\_%_pattern\\\\.x: \$(wordlist 1, 99, ${d}the\\%weird\\\\_%_pattern%\\\\.1 ${d}the\\%weird\\\\_%_pattern%\\\\.2); \$(info \$@ from \$^) ", '', "${d}the%weird\\\\_hello_pattern\\\\.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n"); } 1; ================================================ FILE: tests/scripts/features/suffixrules ================================================ # -*-perl-*- $description = "Test suffix rules."; $details = ""; # TEST #0: Clear all suffixes touch('foo.c'); run_make_test(q! .SUFFIXES: all: foo.o ; @echo $@ $< !, '', "#MAKE#: *** No rule to make target 'foo.o', needed by 'all'. Stop.\n", 512); unlink('foo.c'); # Test #1: Add a simple suffix rule touch('foo.baz'); run_make_test(q! .SUFFIXES: .biz .baz .baz.biz: ; @echo make $@ !, 'foo.biz', "make foo.biz\n"); unlink('foo.baz'); # Test #2: Make sure the defaults still work touch('foo.c'); run_make_test(undef, 'foo.o COMPILE.c=@echo OUTPUT_OPTION=', "foo.c\n"); unlink('foo.c'); # Test #3: Replacing all suffixes touch('foo.baz'); run_make_test(q! .SUFFIXES: .SUFFIXES: .biz .baz .baz.biz: ; @echo make $@ !, 'foo.biz', "make foo.biz\n"); unlink('foo.baz'); # SV 40657: "Suffix rules" with deps are normal rules my $prewarn = 'warning: ignoring prerequisites on suffix rule definition'; touch('foo.bar'); # Verify warnings for single-suffix rules run_make_test(q! .SUFFIXES: .SUFFIXES: .baz .baz: foo.bar ; @echo make $@ from $< $X.POSIX: !, 'X=1 .baz', "#MAKEFILE#:5: $prewarn\nmake .baz from foo.bar\n"); # In POSIX mode we don't get a warning run_make_test(undef, 'X= .baz', "make .baz from foo.bar\n"); # Test double-suffix rules run_make_test(q! .SUFFIXES: .SUFFIXES: .biz .baz $X.POSIX: .baz.biz: foo.bar ; @echo make $@ from $< !, 'X=1 .baz.biz', "#MAKEFILE#:7: $prewarn\nmake .baz.biz from foo.bar\n"); # SV 40657: In POSIX mode we don't get a warning run_make_test(undef, 'X= .baz.biz', "make .baz.biz from foo.bar\n"); unlink('foo.bar'); # SV 40657: In POSIX mode, no pattern rules should be created utouch(-20, 'foo.baz'); run_make_test(undef, 'X= foo.biz', "#MAKE#: *** No rule to make target 'foo.biz'. Stop.\n", 512); # SV 40657: In Non-POSIX mode, a pattern rule is created run_make_test(undef, 'X=1 foo.biz', "#MAKEFILE#:7: $prewarn\nmake foo.biz from foo.baz\n"); # SV 40657: ... but any prerequisites are ignored utouch(-10, 'foo.biz'); touch('foo.bar'); run_make_test(undef, 'X=1 foo.biz', "#MAKEFILE#:7: $prewarn\n#MAKE#: 'foo.biz' is up to date.\n"); unlink('foo.baz', 'foo.biz', 'foo.bar'); touch('hello.c'); unlink('hello.o'); # sv 63821. # Default suffix rule .c.o. run_make_test('all: hello.o', 'COMPILE.c=@echo OUTPUT_OPTION=', 'hello.c'); # User defined rules beat built-in rules. run_make_test(q! all: hello.o .c.o:; $(info $@ user defined .c.o rule) !, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n"); # sv 63821. # The same as above, but suffixes are cleared. run_make_test(q! all: hello.o .SUFFIXES: .c.o:; $(info $@ user defined .c.o rule) !, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512); # sv 63821. # Suffixes are cleared and defined in the makefile. run_make_test(q! all: hello.o .SUFFIXES: .SUFFIXES: .c .o .c.o:; $(info $@ user defined .c.o rule) !, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n"); # sv 63821. # When built-in rules are disabled, but certain suffixes are added to # .SUFFIXES, make should exit with the 'No rule...' error message. run_make_test(q! .SUFFIXES: .c .o all: hello.o !, '-r', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512); # sv 63821. # Same as above, but this time built-in rules are disabled inside the makefile. run_make_test(q! MAKEFLAGS += -r .SUFFIXES: .c .o all: hello.o !, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512); # sv 63821. # Same as above, but this time there is a rule. run_make_test(q! all: hello.o MAKEFLAGS += -r .SUFFIXES: .c .o .c.o:; $(info $@ user defined .c.o rule) !, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.c', 'hello.o'); # sv 65324. # Crash in disable_builtins. run_make_test(q! all:; !, '-r MAKEFLAGS=', "#MAKE#: 'all' is up to date.\n"); # Complete 1; ================================================ FILE: tests/scripts/features/targetvars ================================================ # -*-perl-*- $description = "Test target-specific variable settings."; $details = "\ Create a makefile containing various flavors of target-specific variable values, override and non-override, and using various variable expansion rules, semicolon interference, etc."; run_make_test(' export FOO = foo export BAR = bar one: override FOO = one one two: ; @echo $(FOO) $(BAR) two: BAR = two .RECIPEPREFIX = > three: ; BAR=1000 > @echo $(FOO) $(BAR) # Some things that shouldn not be target vars funk : override funk : override adelic adelic override : ; echo $@ # Test per-target recursive variables four:FOO=x four:VAR$(FOO)=ok four: ; @echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)" five:FOO=x five six : VAR$(FOO)=good five six: ;@echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)" # Test per-target variable inheritance seven: eight seven eight: ; @echo $@: $(FOO) $(BAR) seven: BAR = seven seven: FOO = seven eight: BAR = eight # Test the export keyword with per-target variables nine: ; @echo $(FOO) $(BAR) $$FOO $$BAR nine: FOO = wallace nine-a: export BAZ = baz nine-a: ; @echo $$BAZ # Test = escaping EQ = = ten: one$(EQ)two ten: one $(EQ) two ten one$(EQ)two $(EQ):;@echo $@ .PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two # Test target-specific vars with pattern/suffix rules QVAR = qvar RVAR = = %.q : ; @echo $(QVAR) $(RVAR) foo.q : RVAR += rvar # Target-specific vars with multiple LHS pattern rules %.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR) foo.r : RVAR += rvar foo.t : TVAR := $(QVAR) ', "one two three", "one bar\nfoo two\nBAR=1000\nfoo bar\n"); # TEST #2 run_make_test(undef, "one two FOO=1 BAR=2", "one 2\n1 2\n"); # TEST #3 run_make_test(undef, "four", "x ok ok\n"); # TEST #4 run_make_test(undef, "seven", "eight: seven eight\nseven: seven seven\n"); # TEST #5 run_make_test(undef, "nine", "wallace bar wallace bar\n"); # TEST #5-a run_make_test(undef, "nine-a", "baz\n"); # TEST #6 run_make_test(undef, "ten", "one=two\none bar\n=\nfoo two\nten\n"); # TEST #6 run_make_test(undef, "foo.q bar.q", "qvar = rvar\nqvar =\n"); # TEST #7 run_make_test(undef, "foo.t bar.s", "qvar = qvar\nqvar =\n"); # TEST #8 # For PR/1378: Target-specific vars don't inherit correctly run_make_test(' foo: FOO = foo bar: BAR = bar foo: bar bar: baz baz: ; @echo $(FOO) $(BAR) ', "", "foo bar\n"); # TEST #9 # For PR/1380: Using += assignment in target-specific variables sometimes fails # Also PR/1831 run_make_test(' .PHONY: all one all: FOO += baz all: one; @echo $(FOO) FOO = bar one: FOO += biz one: FOO += boz one: ; @echo $(FOO) ', '', "bar baz biz boz\nbar baz\n"); # Test #10 run_make_test(undef, 'one', "bar biz boz\n"); # Test #11 # PR/1709: Test semicolons in target-specific variable values run_make_test(' foo : FOO = ; ok foo : ; @echo "$(FOO)" ', '', "; ok\n"); # Test #12 # PR/2020: More hassles with += target-specific vars. I _really_ think # I nailed it this time :-/. run_make_test(' .PHONY: a BLAH := foo COMMAND = echo $(BLAH) a: ; @$(COMMAND) a: BLAH := bar a: COMMAND += snafu $(BLAH) ', '', "bar snafu bar\n"); # Test #13 # Test double-colon rules with target-specific variable values run_make_test(' W = bad X = bad foo: W = ok foo:: ; @echo $(W) $(X) $(Y) $(Z) foo:: ; @echo $(W) $(X) $(Y) $(Z) foo: X = ok Y = foo bar: foo bar: Y = bar Z = nopat ifdef PATTERN fo% : Z = pat endif ', 'foo', "ok ok foo nopat\nok ok foo nopat\n"); # Test #14 # Test double-colon rules with target-specific variable values and # inheritance run_make_test(undef, 'bar', "ok ok bar nopat\nok ok bar nopat\n"); # Test #15 # Test double-colon rules with pattern-specific variable values run_make_test(undef, 'foo PATTERN=yes', "ok ok foo pat\nok ok foo pat\n"); # Test #16 # Test target-specific variables with very long command line # (> make default buffer length) run_make_test(' base_metals_fmd_reports.sun5 base_metals_fmd_reports CreateRealPositions CreateMarginFunds deals_changed_since : BUILD_OBJ=$(shell if test -f "build_information.generate" ; then echo "$(OBJ_DIR)/build_information.o"; else echo "no build information"; fi ) deals_changed_since: ; @echo $(BUILD_OBJ) ', '', "no build information\n"); # TEST #17 # Test a merge of set_lists for files, where one list is much longer # than the other. See Savannah bug #15757. mkdir('t1', 0777); touch('t1/rules.mk'); run_make_test(' VPATH = t1 include rules.mk .PHONY: all all: foo.x foo.x : rules.mk ; @echo MYVAR=$(MYVAR) FOOVAR=$(FOOVAR) ALLVAR=$(ALLVAR) all: ALLVAR = xxx foo.x: FOOVAR = bar rules.mk : MYVAR = foo .INTERMEDIATE: foo.x rules.mk ', '-I t1', 'MYVAR= FOOVAR=bar ALLVAR=xxx'); rmfiles('t1/rules.mk'); rmdir('t1'); # TEST #18 # Test appending to a simple variable containing a "$": avoid a # double-expansion. See Savannah bug #15913. run_make_test(' VAR := $$FOO foo: VAR += BAR foo: ; @echo '."'".'$(VAR)'."'".' ', '', '$FOO BAR'); # TEST #19: Override with append variables run_make_test(' a: override FOO += f1 a: FOO += f2 a: ; @echo "$(FOO)" ', '', "f1\n"); run_make_test(undef, 'FOO=C', "C f1\n"); # TEST #19: Conditional variables with command-line settings run_make_test(' a: FOO ?= f1 a: ; @echo "$(FOO)" ', '', "f1\n"); run_make_test(undef, 'FOO=C', "C\n"); # TEST #20: Check for continuation after semicolons run_make_test(q! a: A = 'hello;\ world' a: ; @echo $(A) !, '', "hello; world\n"); # TEST #21: SV-56834 Ensure setting PATH in a target var works properly my $sname = "foobar$scriptsuffix"; mkdir('sd', 0775); create_file("sd/$sname", "exit 0\n"); chmod 0755, "sd/$sname"; run_make_test(qq! all: PATH := sd all: ; $sname >/dev/null !, '', "$sname >/dev/null\n"); # Don't use the general PATH if not found on the target path $ENV{PATH} = "$ENV{PATH}:sd"; my ($ernum, $erstr); if ($port_type eq 'W32') { $ernum = 1; $erstr = "'$sname' is not recognized as an internal or external command,\noperable program or batch file."; } else { $ernum = 127; $erstr = "#MAKE#: $sname: $ERR_no_such_file"; } run_make_test(qq! all: PATH := .. all: ; $sname !, '', "$sname\n$erstr\n#MAKE#: *** [#MAKEFILE#:3: all] Error $ernum", 512); unlink("sd/$sname"); rmdir ('sd'); # SV 59230: Conditional (non-)assignment of target-specific variables should # preserve export settings. $ENV{hello} = 'moon'; run_make_test(q! all:; @echo hello=$$hello dummy: hello?=world !, '', 'hello=moon'); # SV 59230: Assignment of a global variable should not affect export of a # target specific variable. $ENV{hello} = "moon"; run_make_test(q! all:; @echo hello=$$hello hello=sun dummy: hello?=world !, '', 'hello=sun'); # Support target-specific unexport $ENV{hello} = "moon"; run_make_test(q! unexport hello=sun all: base exp base exp: ; @echo hello=$$hello exp: export hello=world !, '', "hello=\nhello=world\n"); $ENV{hello} = "moon"; run_make_test(q! hello=sun all: base exp base exp: ; @echo hello=$$hello exp: unexport hello=world !, '', "hello=sun\nhello=\n"); run_make_test(q! all:; @echo hello=$$hello unexport hello=sun dummy: hello?=world !, '', 'hello='); $ENV{hello} = "moon"; run_make_test(q! all:; @echo hello=$$hello hello=sun dummy: unexport hello=world !, '', 'hello=sun'); run_make_test(q! all: mid mid: base ifeq ($(midexport),export) mid: export hello=mid else ifeq ($(midexport),unexport) mid: unexport hello=mid else mid: hello=mid endif ifeq ($(baseexport),export) base: export hello=base else ifeq ($(baseexport),unexport) base: unexport hello=base else base: hello=base endif all mid base:; @echo $@ make=$(hello) shell=$$hello !, '', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n"); # Test base settings with env var $ENV{hello} = "environ"; run_make_test(undef, '', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n"); $ENV{hello} = "environ"; run_make_test(undef, 'baseexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n"); $ENV{hello} = "environ"; run_make_test(undef, 'baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n"); # Test mid settings with env var $ENV{hello} = "environ"; run_make_test(undef, 'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n"); $ENV{hello} = "environ"; run_make_test(undef, 'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n"); $ENV{hello} = "environ"; run_make_test(undef, 'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make=environ shell=environ\n"); $ENV{hello} = "environ"; run_make_test(undef, 'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make=environ shell=environ\n"); # Test base settings without env var run_make_test(undef, 'baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n"); run_make_test(undef, 'baseexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n"); # Test mid settings with env var run_make_test(undef, 'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make= shell=\n"); run_make_test(undef, 'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make= shell=\n"); run_make_test(undef, 'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n"); run_make_test(undef, 'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n"); # TEST #19: Test define/endef variables as target-specific vars # run_make_test(' # define b # @echo global # endef # a: define b # @echo local # endef # a: ; $(b) # ', # '', "local\n"); 1; ================================================ FILE: tests/scripts/features/temp_stdin ================================================ # -*-mode: perl-*- $description = "Test handling of temporary file created from stdin."; # These tests rely on the test_driver checking for leftover temporary content create_file('input.mk', "world:=1\n"); create_file('bye.mk', "moon:=2\n"); # sv 62118,62145. # Test that makes leaves no temp file when make code is piped to stdin and -v, # -h or an invalid option is specified. my @opts = ('-v', '-h', '--nosuchopt'); my @exit_codes = (0, 0, 512); for my $i (0 .. $#opts) { close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(q! all:; $(info hello world) !, "$opts[$i] -f-", "/uilt for /", $exit_codes[$i]); } # sv 62118,62145. # Test that a stdin temp file is removed. close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(q! all:; $(info world=$(world)) !, '-f-', "world=1\n#MAKE#: 'all' is up to date.\n"); # sv 62118,62145. # Test that a stdin temp file is removed, even when make re-execs. # Also test that make honors TMPDIR to create the temp file. # Ensure touching bye.mk causes re-exec. &utouch(-600, 'bye.mk'); close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(q! include bye.mk all:; $(info hello) $(MAKE_RESTARTS)bye.mk: force; touch $@ force: !, '-R --debug=b -f-', "/Re-executing.+?--temp-stdin=\Q$temppath\E/"); if ($port_type eq 'UNIX') { # POSIX doesn't require sh to set PPID so test this my $cmd = create_command(); add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!); my $fout = 'ppidtest.out'; run_command_with_output($fout, @$cmd); $_ = read_file_into_string($fout); s/\r?\n//g; if (/^[0-9]+$/) { use POSIX (); # sv 63157. # Test that make removes the temporary file which holds make code from stdin, # even when a signal is received. include bye.mk and bye.mk: rule is needed # to cause make to keep the temporary file for re-exec. Without re-exec make # will remove the file before the signal arrives. sleep is needed to let make # write its "... Terminated" message to the log file. Must use REGEX because # some systems (MacOS) add extra text after Terminated. &utouch(-600, 'bye.mk'); close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(q! include bye.mk pid := $(shell echo $$PPID) all:; bye.mk: force; @#HELPER# -q term $(pid) sleep 10 force: !, '-f-', '/#MAKE#: \*\*\* \[#MAKEFILE#:5: bye.mk] Terminated/', POSIX::SIGTERM); } unlink($fout); # sv 62118,62145. # Test that a stdin temp file is removed, when execvp fails to re-exec make. # In order to cause execvp to fail, copy the tested make binary to the temp # directory and take away the 'x' bit. use File::Spec; use File::Copy; my $tmakedir = File::Spec->catfile($cwdpath, 'tmakedir'); mkdir($tmakedir, 0770); my $makecopy = File::Spec->catfile($tmakedir, 'make'); copy("$mkpath", $makecopy); # Set file mode bits, because perl copy won't. chmod 0700, $makecopy; my @make_orig = @make_command; @make_command = ($makecopy); # Ensure touching bye.mk causes re-exec. &utouch(-600, 'bye.mk'); close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(" include bye.mk all:; \$(info hello) \$(MAKE_RESTARTS)bye.mk: force; touch \$@ && chmod u-x $makecopy force: ", "-f-", "touch bye.mk && chmod u-x $makecopy\nmake: $makecopy: $ERR_nonexe_file\n", 32512); @make_command = @make_orig; unlink($makecopy); rmdir($tmakedir); # SV 63333. Test that make exits with an error message if we cannot store a # makefile from stdin to a temporary file. # Create a non-writable temporary directory. # If we do this Valgrind fails because it cannot write temp files... the docs # don't describe any way to tell valgrind to use a directory other than TMPDIR. if (!$valgrind) { my $tdir = 'test_tmp_dir'; mkdir($tdir, 0500); $ENV{'TMPDIR'} = $tdir; close(STDIN); open(STDIN, "<", 'input.mk') || die "$0: cannot open input.mk for reading: $!"; run_make_test(q! all:; $(info hello, world) !, '-f-', '/cannot store makefile from stdin to a temporary file. Stop./', 512); rmdir($tdir); } } # This close MUST come at the end of the test!! close(STDIN); unlink('input.mk', 'bye.mk'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/utf8 ================================================ # -*-perl-*- $description = "Test support for UTF-8."; $details = ""; # Verify that the UTF-8 BOM is ignored. run_make_test("\xEF\xBB\xBFall: ; \@echo \$\@\n", '', "all"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/features/varnesting ================================================ # -*-perl-*- $description = "Test recursive variables"; $details = ""; run_make_test(' x = variable1 variable2 := Hello y = $(subst 1,2,$(x)) z = y a := $($($(z))) all: ; @echo $(a) ', '', "Hello\n"); # This tests resetting the value of a variable while expanding it. # You may only see problems with this if you're using valgrind or # some other memory checker that poisons freed memory. # See Savannah patch #7534 run_make_test(' VARIABLE = $(eval VARIABLE := echo hi)$(VARIABLE) wololo: ; @$(VARIABLE) ', '', "hi\n"); 1; ================================================ FILE: tests/scripts/features/vpath ================================================ # -*-perl-*- $description = "Test vpath for particular classes of filenames."; $details = ""; mkdir('work'); @files_to_touch = ("work${pathsep}main.c","work${pathsep}defs.h", "work${pathsep}kbd.c","work${pathsep}command.h", "work${pathsep}commands.c","work${pathsep}display.c", "work${pathsep}buffer.h","work${pathsep}insert.c", "work${pathsep}command.c"); &touch(@files_to_touch); run_make_test(q! vpath %.c foo vpath %.c work vpath %.h work objects = main.o kbd.o commands.o display.o insert.o edit: $(objects) ; @echo cc -o $@ $^ main.o : main.c defs.h ; @echo cc -c $(firstword $^) kbd.o : kbd.c defs.h command.h ; @echo cc -c kbd.c commands.o : command.c defs.h command.h ; @echo cc -c commands.c display.o : display.c defs.h buffer.h ; @echo cc -c display.c insert.o : insert.c defs.h buffer.h ; @echo cc -c insert.c !, '', "cc -c work${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n" ."cc -c display.c\ncc -c insert.c\n" ."cc -o edit main.o kbd.o commands.o display.o insert.o\n"); unlink(@files_to_touch); # TEST 2: after vpath lookup ensure we don't get incorrect circular dependency # warnings due to change of struct file ptr. Savannah bug #13529. mkdir('vpath-d', 0777); run_make_test(q! vpath %.te vpath-d/ .SECONDARY: default: vpath-d/a vpath-d/b vpath-d/a: fail.te vpath-d/b : fail.te vpath-d/fail.te: !, '', "#MAKE#: Nothing to be done for 'default'.\n"); rmdir('vpath-d'); # Test VPATH vs vpath run_make_test(q! VPATH = work:#PWD# vpath %.c foo vpath %.c work vpath %.c #PWD# vpath %.h work vpath %.c vpath all: ; @echo ALL IS WELL !, '', "ALL IS WELL\n"); # Test interaction of -lfoo and vpath my @dirs_to_make = qw(a1 b1 a2 b2 b3); for my $d (@dirs_to_make) { mkdir($d, 0777); } my @files_to_touch = ("a1${pathsep}lib1.a", "a1${pathsep}libc.a", "b1${pathsep}lib1.so", "a2${pathsep}lib2.a", "b2${pathsep}lib2.so", "lib3.a", "b3${pathsep}lib3.so"); &touch(@files_to_touch); my $answer = "a1${pathsep}lib1.a a1${pathsep}libc.a " . "a2${pathsep}lib2.a lib3.a\n"; if ($port_type eq 'VMS-DCL') { $answer =~ s/ /,/g; } run_make_test(' vpath %.h b3 vpath %.a a1 vpath %.so b1 vpath % a2 b2 vpath % b3 all: -l1 -lc -l2 -l3; @echo $^ ', '', $answer); unlink(@files_to_touch); for my $d (@dirs_to_make) { rmdir($d); } # Check that if we find find files with VPATH, we don't do pattern search mkdir("vpa"); run_make_test(q! VPATH = vpa %.x: ; @echo pattern $@ vpa/foo.x: ; @echo vpath $@ !, 'foo.x', "vpath vpa/foo.x\n"); rmdir("vpa"); 1; ================================================ FILE: tests/scripts/features/vpathgpath ================================================ # -*-perl-*- $description = "Tests VPATH+/GPATH functionality."; $details = ""; mkdir('work'); $VP = "work$pathsep"; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "VPATH = $VP\n"; print MAKEFILE <<'EOMAKE'; GPATH = $(VPATH) .SUFFIXES: .a .b .c .d .PHONY: general rename notarget intermediate %.a: %.b: %.c: %.d: %.a : %.b ; cat $^ > $@ %.b : %.c ; cat $^ > $@ %.c :: %.d ; cat $^ > $@ # General testing info: general: foo.b foo.b: foo.c bar.c EOMAKE close(MAKEFILE); @touchedfiles = (); $off = -500; sub gtouchfiles { foreach (@_) { ($f = $_) =~ s,VP/,$VP,g; &utouch($off, $f); $off += 10; push(@touchedfiles, $f); } } # Run the general-case test >ouchfiles("VP/foo.d", "VP/bar.d", "VP/foo.c", "VP/bar.c", "foo.b", "bar.d"); &run_make_with_options($makefile,"general",&get_logfile()); push(@touchedfiles, "bar.c"); $answer = "$make_name: Nothing to be done for 'general'.\n"; &compare_output($answer,&get_logfile(1)); unlink(@touchedfiles) unless $keep; 1; ================================================ FILE: tests/scripts/features/vpathplus ================================================ # -*-perl-*- $description = "Tests the new VPATH+ functionality added in 3.76."; $details = ""; mkdir('work'); $VP = "work$pathsep"; @touchedfiles = (); $off = -500; sub touchfiles { foreach (@_) { &utouch($off, $_); $off += 10; push(@touchedfiles, $_); } } &touchfiles("$VP/foo.d", "$VP/bar.d", "$VP/foo.c", "$VP/bar.c", "foo.b", "bar.d"); # Run the general-case test run_make_test(qq!VPATH = $VP! . q! .SUFFIXES: .a .b .c .d .PHONY: general rename notarget intermediate %.a: %.b: %.c: %.d: %.a : %.b ; cat $^ > $@ %.b : %.c ; cat $^ > $@ 2>/dev/null || exit 1 %.c :: %.d ; cat $^ > $@ # General testing info: general: foo.b foo.b: foo.c bar.c # Rename testing info: rename: $(VPATH)/foo.c foo.d # Target not made testing info: notarget: notarget.b notarget.c: notarget.d ; -@echo "not creating $@ from $^" # Intermediate files: intermediate: inter.a !, 'general', "cat bar.d > bar.c\ncat ${VP}foo.c bar.c > foo.b 2>/dev/null || exit 1\n"); push(@touchedfiles, "bar.c"); # Test rules that don't make the target correctly &touchfiles("$VP/notarget.c", "notarget.b", "notarget.d"); run_make_test(undef, 'notarget', "not creating notarget.c from notarget.d\ncat notarget.c > notarget.b 2>/dev/null || exit 1\n#MAKE#: *** [#MAKEFILE#:11: notarget.b] Error 1\n", 512); # Test intermediate file handling (part 1) &touchfiles("$VP/inter.d"); my $be = pack("L", 1) eq pack("N", 1); my $intfiles = $be ? "inter.c inter.b" : "inter.b inter.c"; run_make_test(undef, 'intermediate', "cat ${VP}inter.d > inter.c\ncat inter.c > inter.b 2>/dev/null || exit 1\ncat inter.b > inter.a\nrm $intfiles\n"); push(@touchedfiles, "inter.a", "inter.b"); # Test intermediate file handling (part 2) &utouch(-20, "inter.a"); &utouch(-10, "$VP/inter.b"); &touch("$VP/inter.d"); run_make_test(undef, 'intermediate', "cat ${VP}inter.d > inter.c\ncat inter.c > inter.b 2>/dev/null || exit 1\ncat inter.b > inter.a\nrm inter.c\n"); push(@touchedfiles, "$VP/inter.b", "$VP/inter.d"); unlink @touchedfiles unless $keep; 1; ================================================ FILE: tests/scripts/functions/abspath ================================================ # -*-perl-*- $description = "Test the abspath functions."; $details = ""; # Someone needs to rewrite this to be portable for Windows $port_type eq 'W32' and return -1; run_make_test(' ifneq ($(realpath $(abspath .)),$(CURDIR)) $(warning .: abs="$(abspath .)" real="$(realpath $(abspath .))" curdir="$(CURDIR)") endif ifneq ($(realpath $(abspath ./)),$(CURDIR)) $(warning ./: abs="$(abspath ./)" real="$(realpath $(abspath ./))" curdir="$(CURDIR)") endif ifneq ($(realpath $(abspath .///)),$(CURDIR)) $(warning .///: abs="$(abspath .///)" real="$(realpath $(abspath .///))" curdir="$(CURDIR)") endif ifneq ($(abspath /),/) $(warning /: abspath="$(abspath /)") endif ifneq ($(abspath ///),/) $(warning ///: abspath="$(abspath ///)") endif ifneq ($(abspath /.),/) $(warning /.: abspath="$(abspath /.)") endif ifneq ($(abspath ///.),/) $(warning ///.: abspath="$(abspath ///.)") endif ifneq ($(abspath /./),/) $(warning /./: abspath="$(abspath /./)") endif ifneq ($(abspath /.///),/) $(warning /.///: abspath="$(abspath /.///)") endif ifneq ($(abspath /..),/) $(warning /..: abspath="$(abspath /..)") endif ifneq ($(abspath ///..),/) $(warning ///..: abspath="$(abspath ///..)") endif ifneq ($(abspath /../),/) $(warning /../: abspath="$(abspath /../)") endif ifneq ($(abspath /..///),/) $(warning /..///: abspath="$(abspath /..///)") endif ifneq ($(abspath /foo/bar/..),/foo) $(warning /foo/bar/..: abspath="$(abspath /foo/bar/..)") endif ifneq ($(abspath /foo/bar/../../../baz),/baz) $(warning /foo/bar/../../../baz: abspath="$(abspath /foo/bar/../../../baz)") endif ifneq ($(abspath /foo/bar/../ /..),/foo /) $(warning /foo/bar/../ /..: abspath="$(abspath /foo/bar/../ /..)") endif .PHONY: all all: ; @: ', '', ''); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/addprefix ================================================ $description = "The following test creates a makefile to test the addprefix " ."function."; $details = ""; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(addprefix src${pathsep},a.b.z.foo hacks) \n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile $answer = "src${pathsep}a.b.z.foo src${pathsep}hacks\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/addsuffix ================================================ # -*-perl-*- $description = "Test the addsuffix function."; $details = ""; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE <1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(basename src${pathsep}a.b.z.foo.c src${pathsep}hacks src.bar${pathsep}a.b.z.foo.c src.bar${pathsep}hacks hacks) \n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile $answer = "src${pathsep}a.b.z.foo src${pathsep}hacks src.bar${pathsep}a.b.z.foo src.bar${pathsep}hacks hacks\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/call ================================================ # -*-perl-*- $description = "Test the call function.\n"; $details = "Try various uses of call and ensure they all give the correct results.\n"; run_make_test(q! # Simple, just reverse two things # reverse = $2 $1 # A complex 'map' function, using recursive 'call'. # map = $(foreach a,$2,$(call $1,$a)) # Test using a builtin; this is silly as it's simpler to do without call # my-notdir = $(call notdir,$(1)) # Test using non-expanded builtins # my-foreach = $(foreach $(1),$(2),$(3)) my-if = $(if $(1),$(2),$(3)) # Test recursive invocations of call with different arguments # one = $(1) $(2) $(3) two = $(call one,$(1),foo,$(2)) # Test recursion on the user-defined function. As a special case make # won't error due to this. # Implement transitive closure using $(call ...) # DEP_foo = bar baz quux DEP_baz = quux blarp rest = $(wordlist 2,$(words ${1}),${1}) tclose = $(if $1,$(firstword $1)\ $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1)))) all: ; @echo '$(call reverse,bar,foo)'; \ echo '$(call map,origin,MAKE reverse map)'; \ echo '$(call my-notdir,a/b c/d e/f)'; \ echo '$(call my-foreach)'; \ echo '$(call my-foreach,a,,,)'; \ echo '$(call my-if,a,b,c)'; \ echo '$(call two,bar,baz)'; \ echo '$(call tclose,foo)'; !, "", "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n"); # These won't work because call expands all its arguments first, before # passing them on, then marks them as resolved/simple, so they're not # expanded again by the function. # # echo '$(call my-foreach,a,x y z,$$(a)$$(a))'; \ # echo '$(call my-if,,$$(info don't print this),$$(info do print this))' # # $answer = "xx yy zz\ndo print this\n"; # TEST eclipsing of arguments when invoking sub-calls run_make_test(q! all = $1 $2 $3 $4 $5 $6 $7 $8 $9 level1 = $(call all,$1,$2,$3,$4,$5) level2 = $(call level1,$1,$2,$3) level3 = $(call level2,$1,$2,$3,$4,$5) all: @echo $(call all,1,2,3,4,5,6,7,8,9,10,11) @echo $(call level1,1,2,3,4,5,6,7,8) @echo $(call level2,1,2,3,4,5,6,7,8) @echo $(call level3,1,2,3,4,5,6,7,8) !, "", "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n"); # Ensure that variables are defined in global scope even in a $(call ...) delete $ENV{X123}; run_make_test(' tst = $(eval export X123) $(call tst) all: ; @echo "$${X123-not set}" ', '', "\n"); 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/functions/dir ================================================ $description = "The following test creates a makefile to test the dir " ."function."; $details = ""; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(dir src${pathsep}foo.c hacks) \n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile $answer = "src${pathsep} .${pathsep}\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/error ================================================ # -*-Perl-*- $description = "\ The following test creates a makefile to test the error function."; $details = ""; open(MAKEFILE,"> $makefile"); print MAKEFILE 'err = $(error Error found!) ifdef ERROR1 $(error error is $(ERROR1)) endif ifdef ERROR2 $(error error is $(ERROR2)) endif ifdef ERROR3 all: some; @echo $(error error is $(ERROR3)) endif ifdef ERROR4 all: some; @echo error is $(ERROR4) @echo $(error error is $(ERROR4)) endif some: ; @echo Some stuff testvar: ; @: $(err) '; close(MAKEFILE); # Test #1 &run_make_with_options($makefile, "ERROR1=yes", &get_logfile, 512); $answer = "$makefile:4: *** error is yes. Stop.\n"; &compare_output($answer,&get_logfile(1)); # Test #2 &run_make_with_options($makefile, "ERROR2=no", &get_logfile, 512); $answer = "$makefile:8: *** error is no. Stop.\n"; &compare_output($answer,&get_logfile(1)); # Test #3 &run_make_with_options($makefile, "ERROR3=maybe", &get_logfile, 512); $answer = "Some stuff\n$makefile:12: *** error is maybe. Stop.\n"; &compare_output($answer,&get_logfile(1)); # Test #4 &run_make_with_options($makefile, "ERROR4=definitely", &get_logfile, 512); $answer = "Some stuff\n$makefile:17: *** error is definitely. Stop.\n"; &compare_output($answer,&get_logfile(1)); # Test #5 &run_make_with_options($makefile, "testvar", &get_logfile, 512); $answer = "$makefile:22: *** Error found!. Stop.\n"; &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/functions/eval ================================================ # -*-perl-*- $description = "Test the eval function."; $details = "This is a test of the eval function in GNU Make. This function will evaluate inline makefile syntax and incorporate the results into its internal database.\n"; open(MAKEFILE,"> $makefile"); print MAKEFILE <<'EOF'; define Y all:: ; @echo $AA A = B endef X = $(eval $(value Y)) $(eval $(shell echo A = A)) $(eval $(Y)) $(eval A = C) $(eval $(X)) EOF close(MAKEFILE); &run_make_with_options($makefile, "", &get_logfile); # Create the answer to what should be produced by this Makefile $answer = "AA\nBA\n"; &compare_output($answer,&get_logfile(1)); # Test to make sure defining variables when we have extra scope pushed works # as expected. $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile2"); print MAKEFILE <<'EOF'; VARS = A B VARSET = $(1) = $(2) $(foreach v,$(VARS),$(eval $(call VARSET,$v,$v))) all: ; @echo A = $(A) B = $(B) EOF close(MAKEFILE); &run_make_with_options($makefile2, "", &get_logfile); # Create the answer to what should be produced by this Makefile $answer = "A = A B = B\n"; &compare_output($answer,&get_logfile(1)); # Test to make sure eval'ing inside conditionals works properly $makefile3 = &get_tmpfile; open(MAKEFILE,"> $makefile3"); print MAKEFILE <<'EOF'; FOO = foo all:: ; @echo it define Y all:: ; @echo worked endef ifdef BAR $(eval $(Y)) endif EOF close(MAKEFILE); &run_make_with_options($makefile3, "", &get_logfile); $answer = "it\n"; &compare_output($answer,&get_logfile(1)); &run_make_with_options($makefile3, "BAR=1", &get_logfile); $answer = "it\nworked\n"; &compare_output($answer,&get_logfile(1)); # TEST very recursive invocation of eval $makefile3 = &get_tmpfile; open(MAKEFILE,"> $makefile3"); print MAKEFILE <<'EOF'; ..9 := 0 1 2 3 4 5 6 7 8 9 rev=$(eval res:=)$(foreach word,$1,$(eval res:=${word} ${res}))${res} a:=$(call rev,${..9}) all: ; @echo '[$(a)]' EOF close(MAKEFILE); &run_make_with_options($makefile3, "", &get_logfile); $answer = "[ 9 8 7 6 5 4 3 2 1 0 ]\n"; &compare_output($answer,&get_logfile(1)); # TEST eval with no filename context. # The trick here is that because EVAR is taken from the environment, it must # be evaluated before every command is invoked. Make sure that works, when # we have no file context for reading_file (bug # 6195) $makefile4 = &get_tmpfile; open(MAKEFILE,"> $makefile4"); print MAKEFILE <<'EOF'; EVAR = $(eval FOBAR = 1) all: ; @echo "OK" EOF close(MAKEFILE); $ENV{EVAR} = '1'; &run_make_with_options($makefile4, "", &get_logfile); $answer = "OK\n"; &compare_output($answer,&get_logfile(1)); # Clean out previous information to allow new run_make_test() interface. # If we ever convert all the above to run_make_test() we can remove this line. $makefile = undef; # Test handling of backslashes in strings to be evaled. run_make_test(' define FOO all: ; @echo hello \ world endef $(eval $(FOO)) ', '', 'hello world'); run_make_test(' define FOO all: ; @echo '."'".'he\llo'."'".' @echo world endef $(eval $(FOO)) ', '', 'he\llo world'); # We don't allow new target/prerequisite relationships to be defined within a # command script, because these are evaluated after snap_deps() and that # causes lots of problems (like core dumps!) # See Savannah bug # 12124. run_make_test('deps: ; $(eval deps: foo)', '', '#MAKEFILE#:1: *** prerequisites cannot be defined in recipes. Stop.', 512); 1; ================================================ FILE: tests/scripts/functions/file ================================================ # -*-perl-*- $description = 'Test the $(file ...) function.'; # Test > and >> run_make_test(q! define A a b endef B = c d $(file >file.out,$(A)) $(foreach L,$(B),$(file >> file.out,$L)) x:;@echo hi; cat file.out !, '', "hi\na\nb\nc\nd"); unlink('file.out'); # Test >> to a non-existent file run_make_test(q! define A a b endef $(file >> file.out ,$(A)) x:;@cat file.out !, '', "a\nb"); unlink('file.out'); # Test > with no content run_make_test(q! $(file >4touch) .PHONY:x x:;@cat 4touch !, '', ''); # Test >> with no content run_make_test(q! $(file >>4touch) .PHONY:x x:;@cat 4touch !, '', ''); unlink('4touch'); # Test > to a read-only file if (defined $ERR_read_only_file) { touch('file.out'); chmod(0444, 'file.out'); run_make_test(q! define A a b endef $(file > file.out,$(A)) x:;@cat file.out !, '', "#MAKEFILE#:6: *** open: file.out: $ERR_read_only_file. Stop.", 512); unlink('file.out'); } # Use variables for operator and filename run_make_test(q! define A a b endef OP = > FN = file.out $(file $(OP) $(FN),$(A)) x:;@cat file.out !, '', "a\nb"); unlink('file.out'); # Don't add newlines if one already exists run_make_test(q! define A a b endef $(file >file.out,$(A)) x:;@cat file.out !, '', "a\nb"); unlink('file.out'); # Empty text run_make_test(q! $(file >file.out,) $(file >>file.out,) x:;@cat file.out !, '', "\n\n"); unlink('file.out'); # Reading files run_make_test(q! $(file >file.out,A = foo) X1 := $(file >file.out,B = bar) $(eval $(file X1 := x$(file X1 := x$(file X1 := x$(file X1 := x$(file )', '', "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512); run_make_test('$(file >>)', '', "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512); run_make_test('$(file <)', '', "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512); # Bad call run_make_test('$(file foo)', '', "#MAKEFILE#:1: *** file: invalid file operation: foo. Stop.\n", 512); # SV 17448: check whitespace create_file('out1', "1\n"); run_make_test(q! all:;$(info $(file < out1 )) !, '', "1\n#MAKE#: 'all' is up to date."); unlink('out1'); 1; ================================================ FILE: tests/scripts/functions/filter-out ================================================ # -*-perl-*- $description = "Test the filter and filter-out functions."; $details = "The makefile created in this test has two variables. The filter-out function is first used to discard names ending in .o with a single simple pattern. The second filter-out function augments the simple pattern with three literal names, which are also added to the text argument. This tests an internal hash table which is only used if there are multiple literals present in both the pattern and text arguments. The result of both filter-out functions is the same single .elc name.\n"; # Basic test -- filter run_make_test(q! files1 := $(filter %.o, foo.elc bar.o lose.o) files2 := $(filter %.o foo.i, foo.i bar.i lose.i foo.elc bar.o lose.o) all: ; @echo '$(files1) $(files2)' !, '', "bar.o lose.o foo.i bar.o lose.o\n"); # Basic test -- filter-out run_make_test(q! files1 := $(filter-out %.o, foo.elc bar.o lose.o) files2 := $(filter-out foo.i bar.i lose.i %.o, foo.i bar.i lose.i foo.elc bar.o lose.o) all: ; @echo '$(files1) $(files2)' !, '', "foo.elc foo.elc\n"); # Force use of hash (see function.c:func_filter_filterout for params) my $base = 'foo.1 foo.2 foo.3 foo.4 foo.5 foo.6 foo.7 foo.8 foo.9 foo.10'; my $base10 = join(' ', ($base) x 10); my $out3 = join(' ', ('foo.3') x 10); my $out456 = join(' ', ('foo.4 foo.5 foo.6') x 10); run_make_test("words := $base10" . q! files1 := $(filter %.3, $(words)) files2 := $(filter %.4 foo.5 foo.6, $(words)) all: ; @echo '$(files1) $(files2)' !, '', "$out3 $out456\n"); # Escaped patterns run_make_test(q!all:;@echo '$(filter foo\%bar,foo%bar fooXbar)'!, '', "foo%bar\n"); run_make_test(q!all:;@echo '$(filter foo\%\%\\\\\%\%bar,foo%%\\%%bar fooX\\Ybar)'!, '', "foo%%\\%%bar\n"); run_make_test(q! X = $(filter foo\\\\\%bar,foo\%bar foo\Xbar) all:;@echo '$(X)'!, '', "foo\\%bar\n"); 1; ================================================ FILE: tests/scripts/functions/findstring ================================================ $description = "The following test creates a makefile to test the findstring " ."function."; $details = ""; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(findstring port, reporter)\n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile, "", &get_logfile, 0); # Create the answer to what should be produced by this Makefile $answer = "port\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/flavor ================================================ # -*-perl-*- $description = "Test the flavor function."; $details = ""; # Test #1: Test general logic. # run_make_test(' s := s r = r $(info u $(flavor u)) $(info s $(flavor s)) $(info r $(flavor r)) ra += ra rc ?= rc $(info ra $(flavor ra)) $(info rc $(flavor rc)) s += s r += r $(info s $(flavor s)) $(info r $(flavor r)) .PHONY: all all:;@: ', '', 'u undefined s simple r recursive ra recursive rc recursive s simple r recursive'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/foreach ================================================ # -*-perl-*- # $Id$ $description = "Test the foreach function."; $details = "This is a test of the foreach function in gnu make. This function starts with a space separated list of names and a variable. Each name in the list is substituted into the variable and the given text evaluated. The general form of the command is $(foreach var,\$list,\$text). Several types of foreach loops are tested\n"; # TEST 0 # Set an environment variable that we can test in the makefile. $ENV{FOOFOO} = 'foo foo'; run_make_test("space = ' '".' null := auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ < foo = bletch null @ garf av = $(foreach var, $(auto_var), $(origin $(var)) ) override WHITE := BLACK for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) ) fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) ) all: auto for2 auto : ; @echo $(av) for2: ; @echo $(fe)', '-e WHITE=WHITE CFLAGS=', "undefined file default file environment override default file command line override automatic automatic foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o default.o file.o environment.o override.o default.o file.o command.o line.o override.o automatic.o automatic.o"); # TEST 1: Test that foreach variables take precedence over global # variables in a global scope (like inside an eval). Tests bug #11913 run_make_test(' .PHONY: all target all: target x := BAD define mktarget target: x := $(x) target: ; @echo "$(x)" endef x := GLOBAL $(foreach x,FOREACH,$(eval $(value mktarget)))', '', 'FOREACH'); # Allow variable names with trailing space run_make_test(q! $(foreach \ a \ , b c d \ , $(info $a)) all:;@: !, "", "b\nc\nd\n"); # Allow empty variable names. We still expand the body. run_make_test(' x = $(foreach ,1 2 3,a) y := $x all: ; @echo $y', '', "a a a\n"); # Check some error conditions. run_make_test(' x = $(foreach ) y = $x all: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'. Stop.", 512); run_make_test(' x = $(foreach x,y) y := $x all: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (2) to function 'foreach'. Stop.", 512); 1; ================================================ FILE: tests/scripts/functions/guile ================================================ # -*-perl-*- $description = 'Test the $(guile ...) function.'; $details = 'This only works on systems that support it.'; # If this instance of make doesn't support GNU Guile, skip it # This detects if guile is loaded using the "load" directive # $makefile = get_tmpfile(); # open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n"; # print MAKEFILE q! # -load guile # all: ; @echo $(filter guile,$(.LOADED)) # !; # close(MAKEFILE) || die "Failed to write $makefile: $!\n"; # $cmd = subst_make_string("#MAKEPATH# -f $makefile"); # $log = get_logfile(0); # $code = run_command_with_output($log, $cmd); # read_file_into_string ($log) eq "guile\n" and $FEATURES{guile} = 1; # If we don't have Guile support, never mind. exists $FEATURES{guile} or return -1; # Guile and Valgrind/ASAN don't play together at all. exists $FEATURES{sanitize} and return -1; $valgrind and return -1; # Verify simple data type conversions # Currently we don't support vectors: # echo '$(guile (vector 1 2 3))'; \ run_make_test(q! x:;@echo '$(guile #f)'; \ echo '$(guile #t)'; \ echo '$(guile #\c)'; \ echo '$(guile 1234)'; \ echo '$(guile 'foo)'; \ echo '$(guile "bar")'; \ echo '$(guile (cons 'a 'b))'; \ echo '$(guile '(a b (c . d) 1 (2) 3))' !, '', "\n#t\nc\n1234\nfoo\nbar\na b\na b c d 1 2 3"); # Verify guile functions in variables -- SV 43378 run_make_test(q! res := $(guile #f) \ $(guile #t) \ $(guile #\c) \ $(guile 1234) \ $(guile 'foo) \ $(guile "bar") \ $(guile (cons 'a 'b)) \ $(guile '(a b (c . d) 1 (2) 3)) x:;@echo '$(res)' !, '', " #t c 1234 foo bar a b a b c d 1 2 3"); # Verify the gmk-expand function run_make_test(q! VAR = $(guile (gmk-expand "$(shell echo hi)")) x:;@echo '$(VAR)' !, '', "hi"); # Verify the gmk-eval function # Prove that the string is expanded only once (by eval) run_make_test(q! TEST = bye EVAL = VAR = $(TEST) $(shell echo there) $(guile (gmk-eval "$(value EVAL)")) TEST = hi x:;@echo '$(VAR)' !, '', "hi there"); # Verify the gmk-eval function with a list run_make_test(q! $(guile (gmk-eval '(VAR = 1 (2) () 3))) x:;@echo '$(VAR)' !, '', "1 2 3"); # Verify the gmk-var function run_make_test(q! VALUE = hi $(shell echo there) VAR = $(guile (gmk-var "VALUE")) x:;@echo '$(VAR)' !, '', "hi there"); # Verify the gmk-var function with a symbol run_make_test(q! VALUE = hi $(shell echo there) VAR = $(guile (gmk-var 'VALUE)) x:;@echo '$(VAR)' !, '', "hi there"); # Write a Guile program using define and run it run_make_test(q! # Define the "fib" function in Guile define fib ;; A procedure for counting the n:th Fibonacci number ;; See SICP, p. 37 (define (fib n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2)))))) endef $(guile $(fib)) # Now run it x:;@echo $(guile (fib $(FIB))) !, 'FIB=10', "55"); 1; ================================================ FILE: tests/scripts/functions/if ================================================ # -*-perl-*- $description = "Test the if function.\n"; $details = "Try various uses of if and ensure they all give the correct results.\n"; open(MAKEFILE, "> $makefile"); print MAKEFILE < all: > @echo 0_1 $(intcmp $n,$n) > @echo 0_2 $(intcmp $z,$z) > @echo 0_3 $(intcmp -$z,$z) > @echo 0_4 $(intcmp $p,$p) > @echo 0_5 $(intcmp $n,$z) > @echo 0_6 $(intcmp $z,$n) > @echo 1_1 $(intcmp $n,$n,$(shell echo lt)) > @echo 1_2 $(intcmp $n,$z,$(shell echo lt)) > @echo 1_3 $(intcmp $z,$n,$(shell echo lt)) > @echo 2_1 $(intcmp $n,$p,lt,ge) > @echo 2_2 $(intcmp $z,$z,lt,ge) > @echo 2_3 $(intcmp $p,$n,lt,ge) > @echo 3_0 $(intcmp $p,$n,lt,eq,) > @echo 3_1 $(intcmp $z,$p,lt,eq,gt) > @echo 3_2 $(intcmp $p,$z,lt,eq,gt) > @echo 3_3 $(intcmp $p,$p,lt,eq,gt) > @echo 3_4 $(intcmp $p,$q,lt,eq,gt) > @echo 3_5 $(intcmp $q,$p,lt,eq,gt) > @echo 3_6 $(intcmp -$p,-$q,lt,eq,gt) > @echo 3_7 $(intcmp -$q,-$p,lt,eq,gt) > @echo 4_1 $(intcmp -$(huge),$(huge),lt,eq,gt) > @echo 4_2 $(intcmp $(huge),-$(huge),lt,eq,gt) > @echo 4_3 $(intcmp -$(huge),-$(huge),lt,eq,gt) > @echo 4_4 $(intcmp +$(huge),$(huge),lt,eq,gt) ', '', '0_1 -10 0_2 0 0_3 0 0_4 888 0_5 0_6 1_1 1_2 lt 1_3 2_1 lt 2_2 ge 2_3 ge 3_0 3_1 lt 3_2 gt 3_3 eq 3_4 lt 3_5 gt 3_6 gt 3_7 lt 4_1 lt 4_2 gt 4_3 eq 4_4 eq '); # Test error conditions run_make_test(' intcmp-e1: ; @echo $(intcmp 12a,1,foo) intcmp-e2: ; @echo $(intcmp 0,,foo) intcmp-e3: ; @echo $(intcmp -1,) intcmp-e4: ; @echo $(intcmp ,55)', 'intcmp-e1', "#MAKEFILE#:2: *** non-numeric first argument to 'intcmp' function: '12a'. Stop.", 512); run_make_test(undef, 'intcmp-e2', "#MAKEFILE#:3: *** non-numeric second argument to 'intcmp' function: empty value. Stop.", 512); run_make_test(undef, 'intcmp-e3', "#MAKEFILE#:4: *** non-numeric second argument to 'intcmp' function: empty value. Stop.", 512); run_make_test(undef, 'intcmp-e4', "#MAKEFILE#:5: *** non-numeric first argument to 'intcmp' function: empty value. Stop.", 512); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/join ================================================ $description = "The following test creates a makefile to test the join " ."function."; $details = ""; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(join a b c,foo hacks .pl1) \n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile $answer = "afoo bhacks c.pl1\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/let ================================================ # -*-perl-*- # $Id$ $description = "Test the let function."; $details = "This is a test of the let function in gnu make. This function destructures a list of values and binds each value to a variable name in a list of variable names. Superfluous variable names are assigned the empty string and the remaining values are assigned to the last variable name. The binding holds for the duration of the evaluation of the given text and no longer. The general form of the command is $(let \$vars,\$list,\$text). Several types of let assignments are tested\n"; # check for mismatched var and list word counts run_make_test(q! a = bad b = news x = $(let a b,1 2,$a $b) y = $(let a,1 2,$a) z = $(let a b,1,$a $b) all:;@echo 'a=,$a,' 'b=,$b,' 'x=,$x,' 'y=,$y,' 'z=,$z,' !, '', "a=,bad, b=,news, x=,1 2, y=,1 2, z=,1 ,\n"); # check for whitespace run_make_test(q! a = bad b = news x = $(let a b, 1 2 ,+$a+$b+) y = $(let a, 1 2 ,+$a+) z = $(let a b, 1 ,+$a+$b+) all:;@echo 'a=,$a,' 'b=,$b,' 'x=,$x,' 'y=,$y,' 'z=,$z,' !, '', "a=,bad, b=,news, x=,+1+2 +, y=,+1 2 +, z=,+1++,\n"); # Allow empty variable names and empty value list. # We still expand the list and body. run_make_test(' null = v = $(let ,$(info blankvar),abc) x = $(let $(null),$(info side-effect),abc) y = $(let y,,$ydef) z = $(let a b, ,+$a+$b+) all: ; @echo $v/$x/$y/$z', '', "blankvar\nside-effect\nabc/abc/def/+++\n"); # The example macro from the manual. run_make_test(' reverse = $(let first rest,$1,$(if $(rest),$(call reverse,$(rest)) )$(first)) all: ; @echo $(call reverse, \ moe miny meeny eeny \ )', '', "eeny meeny miny moe\n"); # Set an environment variable that we can test in the makefile. $ENV{FOOFOO} = 'foo foo'; # Verify masking: expansion outside the scope of let is unaffected. run_make_test(' auto_var = \ udef \ CC \ FOOFOO \ MAKE \ foo \ CFLAGS \ WHITE \ @ \ < av = $(foreach var, $(auto_var), $(origin $(var)) ) foo = bletch null @ garf override WHITE := BLACK define mktarget target: foo := $(foo) target: ; @echo $(AR)_$(foo)_ endef all: auto target auto: ; @echo $(let $(auto_var),,$(av)) $(av) $(let AR foo,bar foo ,$(eval $(value mktarget)))', '-e WHITE=WHITE CFLAGS=', "automatic automatic automatic automatic automatic automatic automatic automatic automatic undefined default environment override default file command line override automatic automatic ar_foo _ "); # Check some error conditions. run_make_test(' x = $(let ) y = $x all: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'let'. Stop.", 512); run_make_test(' x = $(let x,y) y := $x all: ; @echo $y', '', "#MAKEFILE#:2: *** insufficient number of arguments (2) to function 'let'. Stop.", 512); 1; ================================================ FILE: tests/scripts/functions/notdir ================================================ $description = "The following test creates a makefile to test the notdir " ."function."; $details = ""; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := \$(notdir ${pathsep}src${pathsep}foo.c hacks) \n" ."all: \n" ."\t\@echo \$(string) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile $answer = "foo.c hacks\n"; # COMPARE RESULTS # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/origin ================================================ # -*-perl-*- $description = "Test the origin function."; $details = "This is a test of the origin function in gnu make. This function will report on where a variable was defined per the following list: 'undefined' never defined 'default' default definition 'environment' environment var without -e 'environment override' environment var with -e 'file' defined in makefile 'command line' defined on the command line 'override' defined by override in makefile 'automatic' Automatic variable\n"; # Set an environment variable $ENV{MAKETEST} = 1; run_make_test(' foo := bletch garf auto_var = undefined CC MAKETEST MAKE foo CFLAGS WHITE @ av = $(foreach var, $(auto_var), $(origin $(var)) ) override WHITE := BLACK .RECIPEPREFIX = > all: auto > @echo $(origin undefined) > @echo $(origin CC) > @echo $(origin MAKETEST) > @echo $(origin MAKE) > @echo $(origin foo) > @echo $(origin CFLAGS) > @echo $(origin WHITE) > @echo $(origin @) auto : > @echo $(av)', '-e WHITE=WHITE CFLAGS=', 'undefined default environment override default file command line override automatic undefined default environment override default file command line override automatic'); 1; ================================================ FILE: tests/scripts/functions/realpath ================================================ # -*-perl-*- $description = "Test the realpath functions."; $details = ""; # Check the local directory's realpath run_make_test(' ifneq ($(realpath .),$(CURDIR)) $(warning $(realpath .) != $(CURDIR)) endif ifneq ($(realpath ./),$(CURDIR)) $(warning $(realpath ./) != $(CURDIR)) endif ifneq ($(realpath .///),$(CURDIR)) $(warning $(realpath .///) != $(CURDIR)) endif .PHONY: all all: ; @: ', '', ''); # Find the realpath to the root of the partition create_file('root.mk', 'all:;$(info $(realpath /))'); my $root = `$make_path -sf root.mk`; unlink('root.mk'); $root =~ s/\r?\n//g; my $tst = ' ifneq ($(realpath /.),#ROOT#) $(warning $(realpath /.) != #ROOT#) endif ifneq ($(realpath /./),#ROOT#) $(warning $(realpath /./) != #ROOT#) endif ifneq ($(realpath /.///),#ROOT#) $(warning $(realpath /.///) != #ROOT#) endif ifneq ($(realpath /..),#ROOT#) $(warning $(realpath /..) != #ROOT#) endif ifneq ($(realpath /../),#ROOT#) $(warning $(realpath /../) != #ROOT#) endif ifneq ($(realpath /..///),#ROOT#) $(warning $(realpath /..///) != #ROOT#) endif ifneq ($(realpath . /..),$(CURDIR) #ROOT#) $(warning $(realpath . /..) != $(CURDIR) #ROOT#) endif .PHONY: all all: ; @: '; $tst =~ s/#ROOT#/$root/g; run_make_test($tst, '', ''); # On Windows platforms "//" means something special. So, don't do these tests # there. if ($port_type ne 'W32') { $tst = ' ifneq ($(realpath ///),#ROOT#) $(warning $(realpath ///) != #ROOT#) endif ifneq ($(realpath ///.),#ROOT#) $(warning $(realpath ///.) != #ROOT#) endif ifneq ($(realpath ///..),#ROOT#) $(warning $(realpath ///..) != #ROOT#) endif .PHONY: all all: ; @:'; $tst =~ s/#ROOT#/$root/g; run_make_test($tst, '', ''); } # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/shell ================================================ # -*-perl-*- $description = 'Test the $(shell ...) function.'; $details = ''; # Test standard shell run_make_test('.PHONY: all OUT := $(shell echo hi) all: ; @echo $(OUT) ','','hi'); # Test shells inside rules. run_make_test('.PHONY: all all: ; @echo $(shell echo hi) ','','hi'); # Verify .SHELLSTATUS run_make_test('.PHONY: all PRE := $(.SHELLSTATUS) $(shell exit 0) OK := $(.SHELLSTATUS) $(shell exit 1) BAD := $(.SHELLSTATUS) all: ; @echo PRE=$(PRE) OK=$(OK) BAD=$(BAD) ','','PRE= OK=0 BAD=1'); # Test unescaped comment characters in shells. Savannah bug #20513 run_make_test(q! FOO := $(shell echo '#') foo: ; echo '$(FOO)' !, '', "echo '#'\n#\n"); # Test that exported variables are passed to $(shell ...) $ENV{FOO} = 'baz'; run_make_test(q! OUT = $(shell echo $$FOO) foo: ; @echo '$(OUT)' !, '', 'baz'); $ENV{FOO} = 'baz'; run_make_test(q! FOO = bar OUT = $(shell echo $$FOO) foo: ; @echo '$(OUT)' !, '', 'bar'); run_make_test(q! export FOO = bar OUT = $(shell echo $$FOO) foo: ; @echo '$(OUT)' !, '', 'bar'); # Test shells inside exported environment variables, simply expanded. run_make_test(' export HI := $(shell echo hi) .PHONY: all all: ; @echo $$HI ', '','hi'); # Test shells inside exported environment variables. See SV 10593 run_make_test(' export HI = $(shell echo hi) .PHONY: all all: ; @echo $$HI ', '',"hi"); $ENV{HI} = 'foo'; run_make_test(' HI = $(shell echo hi) .PHONY: all all: ; @echo $$HI ', '',"hi"); $ENV{HI} = 'foo'; run_make_test(' HI = $(shell echo hi) bad := $(HI) .PHONY: all all: ; @echo $$HI $(bad) ', '',"hi hi"); # SV 63016: Exported variable that contains a variable containing $(shell...) run_make_test(' HI = $(shell echo hi) export bad = $(HI) .PHONY: all all:; : $(HI) ', '',": hi"); $ENV{HI} = 'outer'; run_make_test(' export HI = $(shell echo $$HI) .PHONY: all all:; @echo $$HI ', '',"outer"); $ENV{HI} = 'outer'; run_make_test(' export HI = $(shell echo $$HI) .PHONY: all all:; : $(HI) ', '',": outer"); if ($port_type ne 'W32') { # Test shell errors in recipes including offset # This needs to be ported to Windows, or else Windows error messages # need to converted to look like more normal make errors. run_make_test(' .RECIPEPREFIX = > all: >@echo hi >$(shell ./basdfdfsed there) >@echo $(.SHELLSTATUS) ', '', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\nhi\n127\n"); run_make_test(' $(shell ./basdfdfsed where) all: ; @echo $(.SHELLSTATUS) ', '', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\n127\n"); # Test SHELLSTATUS for kill. # This test could be ported to Windows, using taskkill ... ? # Figure out the exit code for SIGINT my $pid = fork(); if (! $pid) { exec('kill -2 $$') or die "exec: Cannot execute sleep\n"; } waitpid($pid, 0); # .SHELLSTATUS for a signal gives 128 + the signal number my $ret = $?; if ($ret > 255) { # Solaris 10 perl 5.8.4 puts signal number + 128 into the high 8 bits. $ret >>= 8; } if ($osname ne 'os390') { $ret |= 128; } run_make_test('.PHONY: all $(shell kill -2 $$$$) STAT := $(.SHELLSTATUS) all: ; @echo STAT=$(STAT) ','',"STAT=$ret\n"); # Test that not-found errors can be redirected if ($ERR_command_not_found) { $_ = $ERR_command_not_found; s/#CMDNAME#/bad-command/g; run_make_test(q! out := $(shell bad-command 2>&1) all: ; @echo '$(.SHELLSTATUS): $(out)' !, '', "127: $_\n"); } # If we're using pipes for jobserver, then we will close them and not # allow them to be available to sub-makes invoked via $(shell ...) if (exists $FEATURES{'jobserver'}) { run_make_test(q! ifeq ($(ELT),) default:; @$(MAKE) -f #MAKEFILE# ELT=1 else ifeq ($(ELT),1) OUTPUT := $(shell $(MAKE) -f #MAKEFILE# ELT=2) $(info $(OUTPUT)) default:;: $(ELT) else default:;: $(ELT) endif !, '--no-print-directory -j2 --jobserver-style=pipe', "#MAKE#[2]: warning: jobserver unavailable: using -j1 (add '+' to parent make rule)\n: 2\n: 1"); } # This crashes if we use vfork and don't reset environ properly run_make_test(q! export PATH = $(shell echo "tests:$$PATH") foo = $(shell echo yes) all:;echo $(foo) !, '', "echo yes\nyes\n"); } # If we're not using pipes for jobserver, then they are available in sub-makes # invoked by $(shell ...) if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) { run_make_test(q! ifeq ($(ELT),) default:; @$(MAKE) -f #MAKEFILE# ELT=1 else ifeq ($(ELT),1) OUTPUT := $(shell $(MAKE) -f #MAKEFILE# ELT=2) $(info $(OUTPUT)) default:;: $(ELT) else default:;: $(ELT) endif !, '--no-print-directory -j2', ": 2\n: 1"); } # sv 65323. Check for bash, because such long variable name causes ksh to # segfault. if (-x '/bin/bash') { # sv 65172. # Buffer overrun in recursively_expand_for_file on a variable with a long # name. my $v = "a1234567890" x 4 x 1000; run_make_test(" SHELL:=/bin/bash export $v=\$(shell echo hello) all:; \@echo \$\$$v ", '', "hello\n"); } 1; ================================================ FILE: tests/scripts/functions/sort ================================================ # -*-perl-*- $description = "The following test creates a makefile to verify the ability of make to sort lists of object. Sort will also remove any duplicate entries. This will also be tested."; $details = "The make file is built with a list of object in a random order and includes some duplicates. Make should sort all of the elements remove all duplicates\n"; run_make_test(' foo := moon_light days foo1:= jazz bar := captured bar2 = boy end, has rise A midnight bar3:= $(foo) s1 := _by s2 := _and_a t1 := $(addsuffix $(s1), $(bar) ) t2 := $(addsuffix $(s2), $(foo1) ) t3 := $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) $(t2) t4 := $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) $(t3) t5 := $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) $(t4) t6 := $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) $(t5) t7 := $(t6) $(t6) $(t6) p1 := $(addprefix $(foo1), $(s2) ) blank:= all: @echo $(sort $(bar2) $(foo) $(addsuffix $(s1), $(bar) ) $(t2) $(bar2) $(bar3)) @echo $(sort $(blank) $(foo) $(bar2) $(t1) $(p1) ) @echo $(sort $(foo) $(bar2) $(t1) $(t4) $(t5) $(t7) $(t6) ) ', '', 'A boy captured_by days end, has jazz_and_a midnight moon_light rise A boy captured_by days end, has jazz_and_a midnight moon_light rise A boy captured_by days end, has jazz_and_a midnight moon_light rise '); # Test with non-space/tab whitespace. Note that you can't see the # original bug except using valgrind. run_make_test("FOO = a b\tc\rd\fe \f \f \f \f \ff all: ; \@echo \$(words \$(sort \$(FOO)))\n", '', "6\n"); 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/functions/strip ================================================ # -*-perl-*- $description = "The following test creates a makefile to verify the ability of make to strip white space from lists of object.\n"; $details = "The make file is built with a list of objects that contain white space These are then run through the strip command to remove it. This is then verified by echoing the result.\n"; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE <<'EOMAKE'; TEST1 := "Is this TERMINAL fun? What makes you believe is this terminal fun? JAPAN is a WONDERFUL planet -- I wonder if we will ever reach their level of COMPARATIVE SHOPPING..." E := TEST2 := $E try this and this $E define TEST3 and these test out some blank lines endef .PHONY: all all: @echo '$(strip $(TEST1) )' @echo '$(strip $(TEST2) )' @echo '$(strip $(TEST3) )' space: ; @echo '$(strip ) $(strip )' EOMAKE # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile); $answer = "\"Is this TERMINAL fun? What makes you believe is this terminal fun? JAPAN is a WONDERFUL planet -- I wonder if we will ever reach their level of COMPARATIVE SHOPPING...\" try this and this and these test out some blank lines "; &compare_output($answer,&get_logfile(1)); &run_make_with_options($makefile,"space",&get_logfile); $answer = " \n"; &compare_output($answer,&get_logfile(1)); 1; ================================================ FILE: tests/scripts/functions/substitution ================================================ # -*-perl-*- $description = "Test the subst and patsubst functions"; $details = ""; # Generic patsubst test: test both the function and variable form. run_make_test(' foo := a.o b.o c.o bar := $(foo:.o=.c) bar2:= $(foo:%.o=%.c) bar3:= $(patsubst %.c,%.o,x.c.c bar.c) all:;@echo $(bar); echo $(bar2); echo $(bar3)', '', 'a.c b.c c.c a.c b.c c.c x.c.o bar.o'); # Patsubst without '%'--shouldn't match because the whole word has to match # in patsubst. Based on a bug report by Markus Mauhart run_make_test('all:;@echo $(patsubst Foo,Repl,FooFoo)', '', 'FooFoo'); # Variable subst where a pattern matches multiple times in a single word. # Based on a bug report by Markus Mauhart run_make_test(' A := fooBARfooBARfoo all:;@echo $(A:fooBARfoo=REPL)', '', 'fooBARREPL'); 1; ================================================ FILE: tests/scripts/functions/suffix ================================================ $description = "The following test creates a makefile to test the suffix\n" ."function. \n"; $details = "The suffix function will return the string following the last _._\n" ."the list provided. It will provide all of the unique suffixes found\n" ."in the list. The long strings are sorted to remove duplicates.\n"; # IF YOU NEED >1 MAKEFILE FOR THIS TEST, USE &get_tmpfile; TO GET # THE NAME OF THE MAKEFILE. THIS INSURES CONSISTENCY AND KEEPS TRACK OF # HOW MANY MAKEFILES EXIST FOR EASY DELETION AT THE END. # EXAMPLE: $makefile2 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "string := word.pl general_test2.pl1 FORCE.pl word.pl3 generic_test.perl /tmp.c/bar foo.baz/bar.c MAKEFILES_variable.c\n" ."string2 := \$(string) \$(string) \$(string) \$(string) \$(string) \$(string) \$(string)\n" ."string3 := \$(string2) \$(string2) \$(string2) \$(string2) \$(string2) \$(string2) \$(string2)\n" ."string4 := \$(string3) \$(string3) \$(string3) \$(string3) \$(string3) \$(string3) \$(string3)\n" ."all: \n" ."\t\@echo \$(suffix \$(string)) \n" ."\t\@echo \$(sort \$(suffix \$(string4))) \n" ."\t\@echo \$(suffix \$(string) a.out) \n" ."\t\@echo \$(sort \$(suffix \$(string3))) \n"; # END of Contents of MAKEFILE close(MAKEFILE); &run_make_with_options($makefile,"",&get_logfile,0); # Create the answer to what should be produced by this Makefile # COMPARE RESULTS $answer = ".pl .pl1 .pl .pl3 .perl .c .c\n" .".c .perl .pl .pl1 .pl3\n" .".pl .pl1 .pl .pl3 .perl .c .c .out\n" .".c .perl .pl .pl1 .pl3\n"; # In this call to compare output, you should use the call &get_logfile(1) # to send the name of the last logfile created. You may also use # the special call &get_logfile(1) which returns the same as &get_logfile(1). &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/functions/value ================================================ # -*-perl-*- $description = "Test the value function."; $details = "This is a test of the value function in GNU Make. This function will evaluate to the value of the named variable with no further expansion performed on it.\n"; open(MAKEFILE,"> $makefile"); print MAKEFILE <<'EOF'; export FOO = foo recurse = FOO = $FOO static := FOO = $(value FOO) all: ; @echo $(recurse) $(value recurse) $(static) $(value static) EOF close(MAKEFILE); &run_make_with_options($makefile, "", &get_logfile); # Create the answer to what should be produced by this Makefile $answer = "FOO = OO FOO = foo FOO = foo FOO = foo\n"; &compare_output($answer,&get_logfile(1)); 1; ================================================ FILE: tests/scripts/functions/warning ================================================ # -*-Perl-*- $description = "\ The following test creates a makefile to test the warning function."; $details = ""; open(MAKEFILE,"> $makefile"); print MAKEFILE <<'EOF'; ifdef WARNING1 $(warning warning is $(WARNING1)) endif ifdef WARNING2 $(warning warning is $(WARNING2)) endif ifdef WARNING3 all: some; @echo hi $(warning warning is $(WARNING3)) endif ifdef WARNING4 all: some; @echo hi @echo there $(warning warning is $(WARNING4)) endif some: ; @echo Some stuff EOF close(MAKEFILE); # Test #1 &run_make_with_options($makefile, "WARNING1=yes", &get_logfile, 0); $answer = "$makefile:2: warning is yes\nSome stuff\n"; &compare_output($answer,&get_logfile(1)); # Test #2 &run_make_with_options($makefile, "WARNING2=no", &get_logfile, 0); $answer = "$makefile:6: warning is no\nSome stuff\n"; &compare_output($answer,&get_logfile(1)); # Test #3 &run_make_with_options($makefile, "WARNING3=maybe", &get_logfile, 0); $answer = "Some stuff\n$makefile:10: warning is maybe\nhi\n"; &compare_output($answer,&get_logfile(1)); # Test #4 &run_make_with_options($makefile, "WARNING4=definitely", &get_logfile, 0); $answer = "Some stuff\n$makefile:15: warning is definitely\nhi\nthere\n"; &compare_output($answer,&get_logfile(1)); # Test linenumber offset run_make_test(q! all: one two $(warning in $@ line 3) @true $(warning in $@ line 5) one two: $(warning in $@ line 8) @true $(warning in $@ line 10) !, '', "#MAKEFILE#:8: in one line 8 #MAKEFILE#:10: in one line 10 #MAKEFILE#:8: in two line 8 #MAKEFILE#:10: in two line 10 #MAKEFILE#:3: in all line 3 #MAKEFILE#:5: in all line 5\n"); # This tells the test driver that the perl test script executed properly. 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/functions/wildcard ================================================ # -*-perl-*- $description = "The following test creates a makefile to test wildcard expansions and the ability to put a command on the same line as the target name separated by a semi-colon."; $details = "\ This test creates 4 files by the names of 1.example, two.example and 3.example. We execute three tests. The first executes the print1 target which tests the '*' wildcard by echoing all filenames by the name of '*.example'. The second test echo's all files which match '?.example' and [a-z0-9].example. Lastly we clean up all of the files using the '*' wildcard as in the first test"; touch("example.1"); touch("example.two"); touch("example.3"); touch("example.for"); touch("example._"); # TEST #1 # ------- run_make_test(qq/ .PHONY: print1 print2 clean print1: ;\@echo \$(wildcard example.*) print2: \t\@echo \$(wildcard example.?) \t\@echo \$(wildcard example.[a-z0-9]) \t\@echo \$(wildcard example.[!A-Za-z_\\!]) clean: \t$CMD_rmfile \$(wildcard example.*) /, 'print1', "example.1 example.3 example._ example.for example.two\n"); # TEST #2 # ------- run_make_test(undef, 'print2', "example.1 example.3 example._\n" ."example.1 example.3\n" ."example.1 example.3\n"); # TEST #3 # ------- $answer = "$CMD_rmfile example.1 example.3 example._ example.for example.two"; if ($vos) { $answer .= " \n"; } else { $answer .= "\n"; } run_make_test(undef, 'clean', $answer); # TEST #4: Verify that failed wildcards don't return the pattern run_make_test(q! all: ; @echo $(wildcard xz--y*.7) !, '', "\n"); # TEST #5: wildcard used to verify file existence touch('xxx.yyy'); run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, '', "file=xxx.yyy\n"); unlink('xxx.yyy'); run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!, '', "file=\n"); # TEST #7: verify that when the input pattern has a trailing slash wildcard # returns only directories. # # Currently this doesn't work with our embedded GLOB so disable it. # ------- if (get_config('USE_SYSTEM_GLOB') eq 'yes') { touch("hellof"); mkdir("hellod", 0770); mkdir("hellod/worldd", 0770); touch("hellod/worldf"); mkdir("hellod/worldd/kend1", 0770); mkdir("hellod/worldd/kend2", 0770); touch("hellod/worldd/kenf1"); touch("hellod/worldd/kenf2"); run_make_test(qq! print3: \t\@echo \$(wildcard hello*) \t\@echo \$(wildcard hello*/) \t\@echo \$(wildcard hellod/world*) \t\@echo \$(wildcard hellod/world*/) \t\@echo \$(wildcard hello* hellod/world*) \t\@echo \$(wildcard hello*/ hellod/world*/) \t\@echo \$(wildcard hellod/*) \t\@echo \$(wildcard hellod/*/) \t\@echo \$(wildcard */world*) \t\@echo \$(wildcard */worldd/) \t\@echo \$(wildcard hellod/*/ken*/) \t\@echo \$(wildcard hellod/*/ken?[12]) \t\@echo \$(wildcard hellod/*/ken?[12]/) !, '', "hellod hellof\n" ."hellod/\n" ."hellod/worldd hellod/worldf\n" ."hellod/worldd/\n" ."hellod hellof hellod/worldd hellod/worldf\n" ."hellod/ hellod/worldd/\n" ."hellod/worldd hellod/worldf\n" ."hellod/worldd/\n" ."hellod/worldd hellod/worldf\n" ."hellod/worldd/\n" ."hellod/worldd/kend1/ hellod/worldd/kend2/\n" ."hellod/worldd/kend1 hellod/worldd/kend2 " ."hellod/worldd/kenf1 hellod/worldd/kenf2\n" ."hellod/worldd/kend1/ hellod/worldd/kend2/\n"); unlink('hellof', 'hellod/worldf', 'hellod/worldd/kenf1', 'hellod/worldd/kenf2'); foreach $d ('hellod/worldd/kend1', 'hellod/worldd/kend2', 'hellod/worldd', 'hellod') { rmdir($d); } } if ($port_type ne 'W32') { # Check wildcard on the root directory run_make_test('print4: ; @echo $(wildcard /)', '', "/\n"); } if ($port_type ne 'W32' && eval { symlink("",""); 1 }) { # TEST #6: check for wildcards matching directories # See SV 53465 my $dir = '__rdir'; my $lnk = '__ldir'; mkdir($dir, 0777); symlink($dir, $lnk); run_make_test(qq!all: ; \@echo \$(wildcard $lnk*/.)!, '', "$lnk/."); unlink($lnk); rmdir($dir); # Test for dangling symlinks # This doesn't work with the built-in glob... needs to be updated! # It also for some obscure reason, will break if we use ASAN!! if (get_config('USE_SYSTEM_GLOB') eq 'yes' && !exists($FEATURES{sanitize})) { symlink($dir, $lnk); run_make_test(qq!all: ; \@echo \$(wildcard $lnk)!, '', "$lnk"); unlink($lnk); } } 1; ================================================ FILE: tests/scripts/functions/word ================================================ # -*-perl-*- $description = "\ Test the word, words, wordlist, firstword, and lastword functions.\n"; $details = "\ Produce a variable with a large number of words in it, determine the number of words, and then read each one back.\n"; run_make_test(' string := word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl string2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string) string3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) string4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) .RECIPEPREFIX = > all: > @echo $(words $(string)) > @echo $(words $(string4)) > @echo $(word 1, $(string)) > @echo $(word 100, $(string)) > @echo $(word 1 , $(string)) > @echo $(word 1000, $(string3)) > @echo $(word 9223372036854775807, $(string2)) > @echo $(wordlist 3, 4, $(string)) > @echo $(wordlist 4, 3, $(string)) > @echo $(wordlist 1 , 6 , $(string)) > @echo $(wordlist 5,7, $(string)) > @echo $(wordlist 100, 110, $(string)) > @echo $(wordlist 7, 10, $(string2)) > @echo $(wordlist 9223372036854775807, 0, $(string2)) ', '', "6\n" ."2058\n" ."word.pl\n" ."\n" ."word.pl\n" ."\n" ."\n" ."FORCE.pl word.pl\n" ."\n" ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n" ."generic_test.perl MAKEFILES_variable.pl\n" ."\n" ."word.pl general_test2.pl FORCE.pl word.pl\n" ."\n" ); # Test error conditions run_make_test('FOO = foo bar biz baz word-e1: ; @echo $(word ,$(FOO)) word-e2: ; @echo $(word abc ,$(FOO)) word-e3: ; @echo $(word 1a,$(FOO)) word-e4: ; @echo $(word 9999999999999999999,$(FOO)) wordlist-e1: ; @echo $(wordlist ,,$(FOO)) wordlist-e2: ; @echo $(wordlist abc ,,$(FOO)) wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))', 'word-e1', "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value. Stop.", 512); run_make_test(undef, 'word-e2', "#MAKEFILE#:4: *** invalid first argument to 'word' function: 'abc '. Stop.", 512); run_make_test(undef, 'word-e3', "#MAKEFILE#:5: *** invalid first argument to 'word' function: '1a'. Stop.", 512); run_make_test(undef, 'word-e4', "#MAKEFILE#:6: *** invalid first argument to 'word' function: '9999999999999999999' out of range. Stop.", 512); run_make_test(undef, 'wordlist-e1', "#MAKEFILE#:8: *** invalid first argument to 'wordlist' function: empty value. Stop.", 512); run_make_test(undef, 'wordlist-e2', "#MAKEFILE#:9: *** invalid first argument to 'wordlist' function: 'abc '. Stop.", 512); run_make_test(undef, 'wordlist-e3', "#MAKEFILE#:10: *** invalid second argument to 'wordlist' function: ' 12a '. Stop.", 512); # Test error conditions again, but this time in a variable reference run_make_test('FOO = foo bar biz baz W = $(word $x,$(FOO)) WL = $(wordlist $s,$e,$(FOO)) word-e: ; @echo $(W) wordlist-e: ; @echo $(WL)', 'word-e x=', "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value. Stop.", 512); run_make_test(undef, 'word-e x=abc', "#MAKEFILE#:3: *** invalid first argument to 'word' function: 'abc'. Stop.", 512); run_make_test(undef, 'word-e x=0', "#MAKEFILE#:3: *** first argument to 'word' function must be greater than 0. Stop.", 512); run_make_test(undef, 'wordlist-e s= e=', "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: empty value. Stop.", 512); run_make_test(undef, 'wordlist-e s=abc e=', "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: 'abc'. Stop.", 512); run_make_test(undef, 'wordlist-e s=4 e=12a', "#MAKEFILE#:4: *** invalid second argument to 'wordlist' function: '12a'. Stop.", 512); run_make_test(undef, 'wordlist-e s=0 e=12', "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: '0'. Stop.", 512); run_make_test(undef, 'wordlist-e s=1 e=-1', "#MAKEFILE#:4: *** invalid second argument to 'wordlist' function: '-1'. Stop.", 512); # TEST #8 -- test $(firstword ) # run_make_test(' void := list := $(void) foo bar baz # a := $(word 1,$(list)) b := $(firstword $(list)) .PHONY: all all: ; @test "$a" = "$b" && echo $a ', '', 'foo'); # TEST #9 -- test $(lastword ) # run_make_test(' void := list := $(void) foo bar baz # a := $(word $(words $(list)),$(list)) b := $(lastword $(list)) .PHONY: all all: ; @test "$a" = "$b" && echo $a ', '', 'baz'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/misc/bs-nl ================================================ # -*-perl-*- $description = "Test backslash-newline handling."; $details = ""; # TEST #1 # ------- # Backslash-newlines in recipes # These are basic backslash-newlines with no tricks run_make_test("fast:;\@echo fa\\\nst\n", '', 'fast'); run_make_test("slow:;\@: no-op; echo sl\\\now\n", '', 'slow'); run_make_test("dquote:;\@echo \"dqu\\\note\"\n", '', 'dquote'); # Single quotes don't behave the same in Windows if ($port_type ne 'W32') { run_make_test("squote:;\@echo 'squ\\\note'\n", '', "squ\\\note"); } # Ensure that a leading prefix character is omitted run_make_test("fast:;\@echo fa\\\n\tst\n", '', 'fast'); run_make_test("slow:;\@: no-op; echo sl\\\n\tow\n", '', 'slow'); run_make_test("dquote:;\@echo \"dqu\\\n\tote\"\n", '', 'dquote'); # Single quotes don't behave the same in Windows if ($port_type ne 'W32') { run_make_test("squote:;\@echo 'squ\\\n\tote'\n", '', "squ\\\note"); } # Ensure that ONLY the leading prefix character is omitted run_make_test("fast:;\@echo fa\\\n\t st\n", '', 'fa st'); run_make_test("slow:;\@: no-op; echo sl\\\n\t\tow\n", '', "sl ow"); run_make_test("dquote:;\@echo \"dqu\\\n\t ote\"\n", '', 'dqu ote'); run_make_test("squote:;\@echo 'squ\\\n\t\t ote'\n", '', "squ\\\n\t ote"); # Backslash-newlines in variable values # Simple run_make_test(q! var = he\ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # Condense trailing space run_make_test(q! var = he \ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # Remove leading space run_make_test(q! var = he\ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # Multiple bs/nl condensed run_make_test(q! var = he\ \ \ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # POSIX: Preserve trailing space run_make_test(q! .POSIX: var = he \ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # POSIX: One space per bs-nl run_make_test(q! .POSIX: var = he\ \ \ llo var:;@echo '|$(var)|'!, '', "|he llo|"); # Savannah #39035: handle whitespace in call run_make_test(q! f = echo $(1) t:; @$(call f,"a \ b"); \ $(call f,"a \ b") !, '', "a b\na b\n"); # Savannah #38945: handle backslash CRLF # We need our own makefile so we can set binmode my $m1 = get_tmpfile(); open(MAKEFILE, "> $m1"); binmode(MAKEFILE); print MAKEFILE "FOO = foo \\\r\n"; close(MAKEFILE); my $m2 = get_tmpfile(); open(MAKEFILE, "> $m2"); print MAKEFILE "include $m1\ndefine BAR\nall: ; \@echo \$(FOO) bar\nendef\n\$(eval \$(BAR))\n"; close(MAKEFILE); run_make_with_options($m2, '', get_logfile()); compare_output("foo bar\n", get_logfile(1)); # Test different types of whitespace, and bsnl inside functions sub xlate { $_ = $_[0]; s/\\r/\r/g; s/\\t/\t/g; s/\\f/\f/g; s/\\n/\n/g; return $_; } run_make_test(xlate(q! $(foreach\r a \t , b\t c \r ,$(info $a \r ) ) all:;@: !), '', "b \r \nc \r \n"); run_make_test(xlate(q! all:;@:$(foreach\r a \t , b\t c \r ,$(info $a \r ) ) !), '', "b \r \nc \r \n"); run_make_test(xlate(q! $(foreach \ \r a \t\ , b\t \ c \r ,$(info \ $a \r ) \ ) all:;@: !), '', "b \r \nc \r \n"); run_make_test(xlate(q! all:;@:$(foreach \ \r a \t\ , b\t \ c \r ,$(info \ $a \r ) \ ) !), '', "b \r \nc \r \n"); run_make_test(xlate(q! define FOO $(foreach \r a \t , b\t c \r ,$(info $a \r ) ) endef $(FOO) all:;@: !), '', "b \r \nc \r \n"); run_make_test(xlate(q! define FOO $(foreach \r a \t , b\t c \r ,$(info $a \r ) ) endef all:;@:$(FOO) !), '', "b \r \nc \r \n"); # Test variables in recipes that expand to multiple lines run_make_test(q! define var echo foo echo bar endef all:;$(var) !, '', "echo foo\nfoo\necho bar\nbar\n"); run_make_test(q! define var echo foo @ echo bar endef all:;$(var) !, '', "echo foo\nfoo\necho bar\nbar\n"); 1; ================================================ FILE: tests/scripts/misc/close_stdout ================================================ # -*-perl-*- $description = "Make sure make exits with an error if stdout is full."; -e '/dev/full' or return -1; # In Strawberry Perl, /dev/full "exists" but does nothing :-/ $port_type eq 'W32' and return -1; run_make_test("\n", '-v > /dev/full', '/^#MAKE#: write error/', 256); 1; ================================================ FILE: tests/scripts/misc/failure ================================================ # -*-perl-*- $description = "Test miscellaneous failures."; # Test that the "did you mean TAB" message is printed properly run_make_test(q! $x. !, '', '#MAKEFILE#:2: *** missing separator. Stop.', 512); run_make_test(q! foo: bar !, '', '#MAKEFILE#:3: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.', 512); run_make_test(q! .RECIPEPREFIX = : foo: bar !, '', '#MAKEFILE#:4: *** missing separator. Stop.', 512); for my $kw ('eq', 'neq') { run_make_test(qq! if$kw(foo,bar) \$(error ouch) endif !, '', '#MAKEFILE#:2: *** missing separator (ifeq/ifneq must be followed by whitespace). Stop.', 512); run_make_test(qq! if$kw \$(error ouch) endif !, '', '#MAKEFILE#:2: *** invalid syntax in conditional. Stop.', 512); run_make_test(qq! if$kw blah \$(error ouch) endif !, '', '#MAKEFILE#:2: *** invalid syntax in conditional. Stop.', 512); } 1; ================================================ FILE: tests/scripts/misc/fopen-fail ================================================ # -*-perl-*- $description = "Make sure make exits with an error if fopen fails."; # For some reason on Cygwin, make exits with no error message after # it recurses for a while. $^O =~ /cygwin/ and return -1; # Recurse infinitely until we run out of open files, and ensure we # fail with a non-zero exit code. Don't bother to test the output # since it's hard to know what it will be, exactly. # See Savannah bug #27374. # Use a longer-than-normal timeout: some systems have more FDs available? # We also set ulimit -n 512 in check-regression in Makefile.am, which see. # See Savannah bug #42390. run_make_test(q! include $(lastword $(MAKEFILE_LIST)) !, '', undef, 512, 300); 1; ================================================ FILE: tests/scripts/misc/general1 ================================================ # -*-perl-*- $description = "The following test creates a makefile to test the simple functionality of make. It mimics the rebuilding of a product with dependencies. It also tests the simple definition of VPATH."; open(MAKEFILE,"> $makefile"); print MAKEFILE < $makefile"); # The contents of the Makefile ... print MAKEFILE < $makefile2"); print MAKEFILE "all:;\@echo FOO = \$(FOO)\nFOO = foo"; close(MAKEFILE); &run_make_with_options($makefile2,"",&get_logfile); $answer = "FOO = foo\n"; &compare_output($answer,&get_logfile(1)); # TEST 3 # Check semicolons in variable references run_make_test(' $(if true,$(info true; true)) all: ; @: ', '', 'true; true'); # TEST 4 # Check that backslashes in command scripts are handled according to POSIX. # Checks Savannah bug # 1332. # Test the fastpath / no quotes run_make_test(' all: @echo foo\ bar @echo foo\ bar @echo foo\ bar @echo foo\ bar @echo foo \ bar @echo foo \ bar @echo foo \ bar @echo foo \ bar ', '', 'foobar foobar foo bar foo bar foo bar foo bar foo bar foo bar'); # Test the fastpath / single quotes # Single quotes don't behave the same in Windows if ($port_type ne 'W32') { run_make_test(q! all: @echo 'foo\ bar' @echo 'foo\ bar' @echo 'foo\ bar' @echo 'foo\ bar' @echo 'foo \ bar' @echo 'foo \ bar' @echo 'foo \ bar' @echo 'foo \ bar' !, '', 'foo\ bar foo\ bar foo\ bar foo\ bar foo \ bar foo \ bar foo \ bar foo \ bar'); } # Test the fastpath / double quotes run_make_test(' all: @echo "foo\ bar" @echo "foo\ bar" @echo "foo\ bar" @echo "foo\ bar" @echo "foo \ bar" @echo "foo \ bar" @echo "foo \ bar" @echo "foo \ bar" ', '', 'foobar foobar foo bar foo bar foo bar foo bar foo bar foo bar'); # Test the slow path / no quotes run_make_test(' all: @echo hi; echo foo\ bar @echo hi; echo foo\ bar @echo hi; echo foo\ bar @echo hi; echo foo\ bar @echo hi; echo foo \ bar @echo hi; echo foo \ bar @echo hi; echo foo \ bar @echo hi; echo foo \ bar ', '', 'hi foobar hi foobar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar'); # Test the slow path / no quotes. This time we put the slow path # determination _after_ the backslash-newline handling. run_make_test(' all: @echo foo\ bar; echo hi @echo foo\ bar; echo hi @echo foo\ bar; echo hi @echo foo\ bar; echo hi @echo foo \ bar; echo hi @echo foo \ bar; echo hi @echo foo \ bar; echo hi @echo foo \ bar; echo hi ', '', 'foobar hi foobar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar hi'); # Test the slow path / single quotes run_make_test(q! all: @echo hi; echo 'foo\ bar' @echo hi; echo 'foo\ bar' @echo hi; echo 'foo\ bar' @echo hi; echo 'foo\ bar' @echo hi; echo 'foo \ bar' @echo hi; echo 'foo \ bar' @echo hi; echo 'foo \ bar' @echo hi; echo 'foo \ bar' !, '', 'hi foo\ bar hi foo\ bar hi foo\ bar hi foo\ bar hi foo \ bar hi foo \ bar hi foo \ bar hi foo \ bar'); # Test the slow path / double quotes run_make_test(' all: @echo hi; echo "foo\ bar" @echo hi; echo "foo\ bar" @echo hi; echo "foo\ bar" @echo hi; echo "foo\ bar" @echo hi; echo "foo \ bar" @echo hi; echo "foo \ bar" @echo hi; echo "foo \ bar" @echo hi; echo "foo \ bar" ', '', 'hi foobar hi foobar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar hi foo bar'); run_make_test('x:;@-exit 1', '', "#MAKE#: [#MAKEFILE#:1: x] Error 1 (ignored)\n"); # Slow path with odd setups if ($port_type ne 'W32') { run_make_test(q! slow: SHELL := echo slow: .SHELLFLAGS := hoho slow:; @foo bar !, '', "hoho foo bar\n"); run_make_test(q! slow: SHELL := echo hi slow: .SHELLFLAGS := ho ho slow:; @foo bar !, '', "hi ho ho foo bar\n"); run_make_test(q! slow: SHELL := echo hi slow: .SHELLFLAGS := 'ho;ho' slow:; @foo bar !, '', "hi ho;ho foo bar\n"); } 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/misc/general4 ================================================ # -*-perl-*- $description = "\ This tests random features of make's algorithms, often somewhat obscure, which have either broken at some point in the past or seem likely to break."; run_make_test(' # Make sure that subdirectories built as prerequisites are actually handled # properly. all: dir/subdir/file.a dir/subdir: ; @echo mkdir -p dir/subdir dir/subdir/file.b: dir/subdir ; @echo touch dir/subdir/file.b dir/subdir/%.a: dir/subdir/%.b ; @echo cp $< $@', '', "mkdir -p dir/subdir\ntouch dir/subdir/file.b\ncp dir/subdir/file.b dir/subdir/file.a\n"); # Test implicit rules &touch('foo.c'); run_make_test('foo: foo.o', 'CC="@echo cc" OUTPUT_OPTION=', 'cc -c foo.c cc foo.o -o foo'); unlink('foo.c'); # Test implicit rules with '$' in the name (see se_implicit) run_make_test(q! %.foo : baz$$bar ; @echo 'done $<' %.foo : bar$$baz ; @echo 'done $<' test.foo: baz$$bar bar$$baz: ; @echo '$@' !, '', "baz\$bar\ndone baz\$bar"); # Test implicit rules with '$' in the name (see se_implicit) # Use the '$' in the pattern. run_make_test(q! %.foo : %$$bar ; @echo 'done $<' test.foo: test$$bar: ; @echo '$@' !, '', "test\$bar\ndone test\$bar"); # Make sure that subdirectories built as prerequisites are actually handled # properly... this time with '$' run_make_test(q! all: dir/subdir/file.$$a dir/subdir: ; @echo mkdir -p '$@' dir/subdir/file.$$b: dir/subdir ; @echo touch '$@' dir/subdir/%.$$a: dir/subdir/%.$$b ; @echo 'cp $< $@' !, '', "mkdir -p dir/subdir\ntouch dir/subdir/file.\$b\ncp dir/subdir/file.\$b dir/subdir/file.\$a\n"); # Test odd whitespace at the beginning of a line run_make_test(" all: \f \\ \f \\ \013 \\ all: ; \@echo hi ", '', "hi\n"); # SV-56834 Ensure setting PATH in the makefile works properly my $sname = "foobar$scriptsuffix"; mkdir('sd', 0775); create_file("sd/$sname", "exit 0\n"); chmod 0755, "sd/$sname"; run_make_test(qq! PATH := sd all: ; $sname >/dev/null !, '', "$sname >/dev/null\n"); # Don't use the general PATH if not found on the target path $ENV{PATH} = "$ENV{PATH}:sd"; my ($ernum, $erstr); if ($port_type eq 'W32') { $ernum = 2; $erstr = "process_begin: CreateProcess(NULL, $sname, ...) failed.\nmake (e=2): The system cannot find the file specified."; } else { $ernum = 127; $erstr = "#MAKE#: $sname: $ERR_no_such_file"; } run_make_test(qq! PATH := .. all: ; $sname !, '', "$sname\n$erstr\n#MAKE#: *** [#MAKEFILE#:3: all] Error $ernum", 512); unlink("sd/$sname"); rmdir('sd'); # Ensure that local programs are not found if "." is not on the PATH create_file($sname, ''); chmod 0755, $sname; if ($port_type eq 'W32') { $ernum = -1; $erstr = ""; } else { $ernum = 127; $erstr = "#MAKE#: $sname: $ERR_no_such_file\n"; } run_make_test(qq! PATH := .. all: ; $sname !, '', "$sname\n$erstr#MAKE#: *** [#MAKEFILE#:3: all] Error $ernum", 512); unlink($sname); if ($port_type eq 'UNIX') { # SV 57674: ensure we use a system default PATH if one is not set delete $ENV{PATH}; run_make_test(q! a: ; @echo hi !, '', "hi\n"); } 1; ================================================ FILE: tests/scripts/misc/utf8 ================================================ # -*-perl-*- $description = "Test utf8 handling."; $details = ""; # Variable names containing UTF8 characters run_make_test(" \xe2\x96\xaa := hello \$(info \$(\xe2\x96\xaa)) all: ", '', "hello\n#MAKE#: Nothing to be done for 'all'."); 1; ================================================ FILE: tests/scripts/options/dash-B ================================================ # -*-perl-*- $description = "Test make -B (always remake) option.\n"; $details = "\ Construct a simple makefile that builds a target. Invoke make once, so it builds everything. Invoke it again and verify that nothing is built. Then invoke it with -B and verify that everything is built again."; &touch('bar.x'); run_make_test(' .SUFFIXES: .PHONY: all all: foo foo: bar.x @echo cp $< $@ @echo "" > $@ ', '', 'cp bar.x foo'); run_make_test(undef, '', "#MAKE#: Nothing to be done for 'all'."); run_make_test(undef, '-B', 'cp bar.x foo'); # Put the timestamp for foo into the future; it should still be remade. # There are clock skew errors printed here but they will be cleared by # the comparison code. utouch(1000, 'foo'); run_make_test(undef, '', "#MAKE#: Nothing to be done for 'all'."); run_make_test(undef, '-B', 'cp bar.x foo'); # Clean up rmfiles('bar.x', 'foo'); # Test -B with the re-exec feature: we don't want to re-exec forever # Savannah bug # 7566 run_make_test(' all: ; @: $(info MAKE_RESTARTS=$(MAKE_RESTARTS)) include foo.x foo.x: ; @touch $@ ', '-B', 'MAKE_RESTARTS= MAKE_RESTARTS=1'); rmfiles('foo.x'); # Test -B with the re-exec feature: we DO want -B in the "normal" part of the # makefile. &touch('blah.x'); run_make_test(' all: blah.x ; @echo $@ $(info MAKE_RESTARTS=$(MAKE_RESTARTS)) include foo.x foo.x: ; @touch $@ blah.x: ; @echo $@ ', '-B', 'MAKE_RESTARTS= MAKE_RESTARTS=1 blah.x all'); rmfiles('foo.x', 'blah.x'); # Test that $? is set properly with -B; all prerequisites will be newer! utouch(-10, 'x.b'); touch('x.a'); run_make_test(q! x.a: x.b ; @echo $? !, '-B', "x.b\n"); unlink(qw(x.a x.b)); 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/options/dash-C ================================================ # -*-perl-*- $description = "Test the -C option to GNU Make."; use File::Spec; # Pre-set $makefile to be in a subdirectory $makefile = 'Makefile'; my $_srcdir = 'src'; mkdir($_srcdir, 0775); my $_incdir = 'inc'; mkdir($_incdir, 0775); my $_mkpath = File::Spec->catfile($_srcdir, $makefile); create_file($_mkpath, "include \$(file)\nall: ;\n"); # TEST #1 # ------- run_make_test('', "-C $_srcdir --no-print-directory", "#MAKE#: 'all' is up to date."); # TEST #2 # ------- # Do it again with trailing "/"; this should work the same run_make_test(undef, "-C $_srcdir/ --no-print-directory", "#MAKE#: 'all' is up to date."); # Test stringing together multiple -C options run_make_test(undef, "-C $_incdir -C .. -C $_srcdir --no-print-directory", "#MAKE#: 'all' is up to date."); # SV 63552 - Ensure -I is considered after -C my $_incfile = 'test'; my $_incpath = File::Spec->catfile($_incdir, $_incfile); create_file($_incpath, '$(info included)'); my $_incopt = File::Spec->catfile('..', $_incdir); run_make_test(undef, "-C src -I $_incopt --no-print-directory file=$_incfile", "included\n#MAKE#: 'all' is up to date."); unlink($_incpath); rmdir($_incdir); unlink($_mkpath); rmdir($_srcdir); 1; ================================================ FILE: tests/scripts/options/dash-I ================================================ # -*-perl-*- $description = "The following test creates a makefile to test the -I option."; $details = "\ This test tests the -I option by including a filename in another directory and giving make that directory name under -I in the command line. Without this option, the make would fail to find the included file. It also checks to make sure that the -I option gets passed to recursive makes."; use File::Spec; # Create a directory and put a makefile in it. # We can't put it in the current directory since that's automatically searched # anyway. my $subdir = 'idir'; mkdir($subdir, 0777); my $included = 'ifile.mk'; my $ipath = File::Spec->catfile($subdir, $included); create_file($ipath, " ANOTHER: \t\@echo This is another included makefile recurse: \t\@\$(MAKE) ANOTHER -f \$(main_makefile)\n"); my $nosuch = "#MAKEFILE#:5: $included: $ERR_no_such_file #MAKE#: *** No rule to make target '$included'. Stop.\n"; # Verify that we get an error if we don't have -I run_make_test(qq! main_makefile := \$(firstword \$(MAKEFILE_LIST)) all: \t\@echo There should be no errors for this makefile include $included !, '', $nosuch, 512); # Check basic -I works run_make_test(undef, "-I $subdir all", "There should be no errors for this makefile\n"); # Check that the included target works run_make_test(undef, "-I $subdir ANOTHER", "This is another included makefile\n"); # Check that -I is passed down through MAKEFLAGS run_make_test(undef, "-I $subdir recurse", "#MAKE#[1]: Entering directory '#PWD#' This is another included makefile #MAKE#[1]: Leaving directory '#PWD#'\n"); # Verify that we get an error if we add -I- to delete previous includes run_make_test(undef, "-I $subdir -I- all", $nosuch, 512); # Make another directory with the same name and make sure the right one is # chosen if -I- stops the path. mkdir('idir2', 0777); my $ipath2 = File::Spec->catfile('idir2', $included); create_file($ipath2, "This is a bad makefile!!\n"); run_make_test(undef, "-I idir2 -I $subdir ANOTHER", "$included:1: *** missing separator. Stop.\n", 512); run_make_test(undef, "-I idir2 -I - -I $subdir ANOTHER", "This is another included makefile\n"); # Check that -I- is passed down through MAKEFLAGS run_make_test(undef, "-I idir2 -I - -I $subdir recurse", "#MAKE#[1]: Entering directory '#PWD#' This is another included makefile #MAKE#[1]: Leaving directory '#PWD#'\n"); unlink($ipath2); rmdir('idir2'); # The only way to check if -I- voids included directories is to see if a file # exists in one and try to include it. We very likely can't add our own files # to the default directories since they're probably write-protected. This # won't work if none of the default directories contain any files :-/ create_file('defaultdirs.mk', "\$(info \$(.INCLUDE_DIRS))\nall:;\@:\n"); my $cmd = subst_make_string("#MAKEPATH# -f defaultdirs.mk"); my @dirs = `$cmd`; my $dirs = $dirs[0]; $dirs =~ s/\r?\n//g; unlink('defaultdirs.mk'); my $fn = undef; foreach my $dn (split ' ', $dirs) { # On Windows the default is "." which is bogus! if ($dn ne '.') { my @files = glob(File::Spec->catfile($dn, "*")); if (@files) { (undef, undef, $fn) = File::Spec->splitpath($files[0]); last; } } } if ($fn) { run_make_test(" all:; include $fn ", '-I-', "#MAKEFILE#:3: $fn: $ERR_no_such_file #MAKE#: *** No rule to make target '$fn'. Stop.\n", 512); } unlink($ipath); rmdir($subdir); 1; ================================================ FILE: tests/scripts/options/dash-W ================================================ # -*-perl-*- $description = "Test make -W (what if) option.\n"; # Basic build run_make_test(' a.x: b.x a.x b.x: ; echo >> $@ ', '', "echo >> b.x\necho >> a.x"); # Run it again: nothing should happen run_make_test(undef, '', "#MAKE#: 'a.x' is up to date."); # Now run it with -W b.x: should rebuild a.x run_make_test(undef, '-W b.x', 'echo >> a.x'); # Put the timestamp for a.x into the future; it should still be remade. # There are clock skew errors printed here but they will be cleared by # the comparison code. utouch(1000, 'a.x'); run_make_test(undef, '', "#MAKE#: 'a.x' is up to date."); run_make_test(undef, '-W b.x', 'echo >> a.x'); # Clean up rmfiles('a.x', 'b.x'); # Test -W with the re-exec feature: we don't want to re-exec forever # Savannah bug # 7566 # First set it up with a normal build run_make_test(' all: baz.x ; @: include foo.x foo.x: bar.x @echo "\$$(info restarts=\$$(MAKE_RESTARTS))" > $@ @echo "touch $@" bar.x: ; echo >> $@ baz.x: bar.x ; @echo "touch $@" ', '', 'echo >> bar.x touch foo.x restarts=1 touch baz.x'); # Now run with -W bar.x # Tweak foo.x's timestamp so the update will change it. # There are clock skew errors printed here but they will be cleared by # the comparison code. &utouch(1000, 'foo.x'); run_make_test(undef, '-W bar.x', "restarts=\ntouch foo.x\nrestarts=1\ntouch baz.x"); rmfiles('foo.x', 'bar.x'); # Test -W on vpath-found files: it should take effect. # Savannah bug # 15341 mkdir('x-dir', 0777); utouch(-20, 'x-dir/x'); touch('y'); run_make_test(' y: x ; @echo cp $< $@ ', '-W x-dir/x VPATH=x-dir', 'cp x-dir/x y'); # Make sure ./ stripping doesn't interfere with the match. run_make_test(' y: x ; @echo cp $< $@ ', '-W ./x-dir/x VPATH=x-dir', 'cp x-dir/x y'); run_make_test(undef, '-W x-dir/x VPATH=./x-dir', 'cp ./x-dir/x y'); unlink(qw(y x-dir/x)); rmdir('x-dir'); 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/options/dash-d ================================================ # -*-perl-*- $description = "Test make -d option.\n"; # sv 60777. # Test that debug output is printed when both -d and --trace are specified. run_make_test('all: ; :', '-d --trace', "/GNU Make/"); 1; ================================================ FILE: tests/scripts/options/dash-e ================================================ # -*-perl-*- $description = "Test the -e (environment overrides) option"; $ENV{GOOGLE} = 'boggle'; run_make_test(q! GOOGLE = bazzle all:; @echo "$(GOOGLE)" !, '-e', "boggle\n"); # Ensure variables set on the command line have the origin correct # See SV 61218 run_make_test(q! $(info FOO [$(origin FOO)]: $(value FOO)) all: ; recurse: ; @$(MAKE) -f #MAKEFILE# !, '-e --no-print-directory FOO=1 recurse', "FOO [command line]: 1\nFOO [command line]: 1\n#MAKE#[1]: 'all' is up to date."); # SV 64803. # Test that the origin of an env variable is 'enviroment override' when -e # is set and the makefile does not modify the variable. # First run the test without -e and then with -e. mkdir('lib', 0777); create_file('lib/makefile', '$(info in submake value=$(hello), origin=$(origin hello)) all:; @echo "value=$(hello), origin=$(origin hello)"'."\n"); # No -e. $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib .PHONY: lib all !, '-s', "value=world, origin=environment\nvalue=world, origin=environment\n". "in submake value=world, origin=environment\nvalue=world, origin=environment"); # -e is specified on the command line. my @opts = ('-e', '--environment-overrides'); for my $opt (@opts) { $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib .PHONY: lib all !, "-s $opt", "value=world, origin=environment override\nvalue=world, origin=environment override\n". "in submake value=world, origin=environment override\nvalue=world, origin=environment override"); } # MAKEFLAGS from env affects top level make. $ENV{hello} = 'world'; $ENV{MAKEFLAGS} = 'e'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib .PHONY: lib all !, "-s", "value=world, origin=environment override\nvalue=world, origin=environment override\n". "in submake value=world, origin=environment override\nvalue=world, origin=environment override"); # -e is passed to submake on the command line. $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -e -C lib .PHONY: lib all !, "-s", "value=world, origin=environment\nvalue=world, origin=environment\n". "in submake value=world, origin=environment override\nvalue=world, origin=environment override"); # MAKEFLAGS is reset for submake. $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib MAKEFLAGS= .PHONY: lib all !, "-se", "value=world, origin=environment override\nvalue=world, origin=environment override\n". "in submake value=world, origin=environment\nvalue=world, origin=environment"); # Some MAKEFLAGS in top make env. # This MAKEFLAGS does not conform to the format that make itself produces for # submake. However, make still parses and honors this MAKEFLAGS. # This test checks that make does not confuse 'e' in 'extramk' with '-e'. $ENV{MAKEFLAGS} = 'r -Iextramk -k bye=moon'; $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib .PHONY: lib all !, "-s", "value=world, origin=environment\nvalue=world, origin=environment\n". "in submake value=world, origin=environment\nvalue=world, origin=environment"); # Some MAKEFLAGS in top make env. # This MAKEFLAGS does not conform to the format that make itself produces for # submake. However, make still parses and honors this MAKEFLAGS. # This test checks that make detects '-e' in this MAKEFLAGS. $ENV{MAKEFLAGS} = 'r -Iextramk -ke bye=moon'; $ENV{hello} = 'world'; run_make_test(q! .RECIPEPREFIX = > $(info value=$(hello), origin=$(origin hello)) all: > @echo "value=$(hello), origin=$(origin hello)" > @$(MAKE) -C lib .PHONY: lib all !, "-s", "value=world, origin=environment override\nvalue=world, origin=environment override\n". "in submake value=world, origin=environment override\nvalue=world, origin=environment override"); 1; ================================================ FILE: tests/scripts/options/dash-f ================================================ # -*-perl-*- $description = "The following test tests that if you specify greater \n" ."than one '-f makefilename' on the command line, \n" ."that make concatenates them. This test creates three \n" ."makefiles and specifies all of them with the -f option \n" ."on the command line. To make sure they were concatenated, \n" ."we then call make with the rules from the concatenated \n" ."makefiles one at a time. Finally, it calls all three \n" ."rules in one call to make and checks that the output\n" ."is in the correct order."; $makefile2 = &get_tmpfile; $makefile3 = &get_tmpfile; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE "all: \n"; print MAKEFILE "\t\@echo This is the output from the original makefile\n"; # END of Contents of MAKEFILE close(MAKEFILE); # Create a second makefile open(MAKEFILE,"> $makefile2"); print MAKEFILE "TWO: \n"; print MAKEFILE "\t\@echo This is the output from makefile 2\n"; close(MAKEFILE); # Create a third makefile open(MAKEFILE,"> $makefile3"); print MAKEFILE "THREE: \n"; print MAKEFILE "\t\@echo This is the output from makefile 3\n"; close(MAKEFILE); # Create the answer to what should be produced by this Makefile $answer = "This is the output from the original makefile\n"; # Run make to catch the default rule &run_make_with_options($makefile,"-f $makefile2 -f $makefile3",&get_logfile,0); &compare_output($answer,&get_logfile(1)); # Run Make again with the rule from the second makefile: TWO $answer = "This is the output from makefile 2\n"; &run_make_with_options($makefile,"-f $makefile2 -f $makefile3 TWO",&get_logfile,0); &compare_output($answer,&get_logfile(1)); # Run Make again with the rule from the third makefile: THREE $answer = "This is the output from makefile 3\n"; &run_make_with_options($makefile, "-f $makefile2 -f $makefile3 THREE", &get_logfile, 0); &compare_output($answer,&get_logfile(1)); # Run Make again with ALL three rules in the order 2 1 3 to make sure # that all rules are executed in the proper order $answer = "This is the output from makefile 2\n"; $answer .= "This is the output from the original makefile\n"; $answer .= "This is the output from makefile 3\n"; &run_make_with_options($makefile, "-f $makefile2 -f $makefile3 TWO all THREE", &get_logfile, 0); &compare_output($answer,&get_logfile(1)); # sv 62118. # Validate all sorts of -f etc. options my $hello = 'hello.mk'; my $bye = 'bye.mk'; my $byesrc = 'bye.mk.src'; create_file($hello, 'all:; $(info hello, world) '); create_file($bye, 'def:; $(info bye, world) bye.mk: bye.mk.src; touch $@ bye.mk.src:; touch $@ '); # These invocations use the empty filename string so that the test framework # doesn't add any -f options on its own. # Incorrect order of options. -R follows -f. # Invocation of make is equivalent to # echo 'all:; $(info hello, world)' | make -f bye.mk -fR - all # There is bye.mk, but there is no 'R'. # make runs the recipes from bye.mk and prints the error about missing 'R'. # Ensure the newly created bye.src.mk is newer than bye.mk. &utouch(-600, $bye); run_make_test('', "-f$bye -fR - all", "#MAKE#: R: No such file or directory touch bye.mk.src touch bye.mk #MAKE#: *** No rule to make target 'R'. Stop. ", 512); my @opts; my $answer; # Test double -f-. @opts = ('-f- -f-', '-f - -f -', '-f- -f -', '-f - -f-', '-f- --file=-', '-f- --file -', '-f - --file=-', '-f - --file -', '-f- --makefile=-', '-f- --makefile -', '-f - --makefile=-', '-f - --makefile -', '--file=- --makefile=-', '--file=- --makefile -', '--file - --makefile=-', '--file - --makefile -'); for my $opt (@opts) { # We shouldn't need this; if the options are wrong then make shouldn't try # to read from stdin. close(STDIN); open(STDIN, "<", $hello) || die "$0: cannot open $hello for reading: $!"; run_make_test('', "-f$bye $opt", "#MAKE#: *** Makefile from standard input specified twice. Stop.\n", 512); } # -f is not followed by filename. @opts = ('-f', '--file', '--makefile'); $answer = "/requires an argument/"; for my $opt (@opts) { run_make_test('', $opt, $answer, 512); } # Test that make correctly parses all possible syntaxes to pipe make code to # the standard input. $answer = "touch bye.mk.src touch bye.mk hello, world #MAKE#: 'all' is up to date.\n"; @opts = ('-f- all', '-f - all', '-Rf- all', '-Rf - all', '--file=- all', '--file - all', '--makefile=- all', '--makefile - all'); for my $opt (@opts) { unlink($byesrc); close(STDIN); open(STDIN, "<", $hello) || die "$0: cannot open $hello for reading: $!"; # Ensure the newly created bye.src.mk is newer than bye.mk. &utouch(-600, $bye); run_make_test('', "-f$bye $opt", $answer); } # This close MUST come at the end of the test!! close(STDIN); unlink($hello, $bye, $byesrc); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/options/dash-k ================================================ # -*-perl-*- $description = "Test the make -k (don't stop on error) option.\n"; $details = "\ The makefile created in this test is a simulation of building a small product. However, the trick to this one is that one of the dependencies of the main target does not exist. Without the -k option, make would fail immediately and not build any part of the target. What we are looking for here, is that make builds the rest of the dependencies even though it knows that at the end it will fail to rebuild the main target."; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE < $makefile2"); print MAKEFILE <<'EOF'; .SUFFIXES: all: exe1 exe2; @echo making $@ exe1 exe2: lib; @echo cp $^ $@ lib: foo.o; @echo cp $^ $@ foo.o: ; exit 1 EOF close(MAKEFILE); &run_make_with_options($makefile2, "-k", &get_logfile, $error_code); $answer = "exit 1 $make_name: *** [$makefile2:9: foo.o] Error 1 $make_name: Target 'all' not remade because of errors.\n"; &compare_output($answer, &get_logfile(1)); # TEST -- make sure we keep the error code if we can't create an included # makefile. if (defined $ERR_no_such_file) { run_make_test('all: ; @echo hi include ifile ifile: no-such-file; exit 1 ', '-k', "#MAKEFILE#:2: ifile: $ERR_no_such_file #MAKE#: *** No rule to make target 'no-such-file', needed by 'ifile'. #MAKEFILE#:2: failed to remake makefile 'ifile'", 512); } 1; ================================================ FILE: tests/scripts/options/dash-l ================================================ # -*-perl-*- # Date: Tue, 11 Aug 1992 09:34:26 -0400 # From: pds@lemming.webo.dg.com (Paul D. Smith) $description = "Test load balancing (-l) option."; $details = "\ This test creates a makefile where all depends on three rules which contain the same body. Each rule checks for the existence of a temporary file; if it exists an error is generated. If it doesn't exist then it is created, the rule sleeps, then deletes the temp file again. Thus if any of the rules are run in parallel the test will fail. When make is called in this test, it is given the -l option with a value of 0.0001. This ensures that the load will be above this number and make will therefore decide that it cannot run more than one job even though -j 4 was also specified on the command line."; # On Windows a very different algorithm is used. $port_type eq 'W32' and return -1; open(MAKEFILE,"> $makefile"); printf MAKEFILE subst_make_string(q! test = #HELPER# noexist test-file file test-file sleep 2 rm test-file all : ONE TWO THREE ONE : ; @$(test) TWO : ; @$(test) THREE : ; @$(test) !); close(MAKEFILE); my $ans = "noexist test-file\nfile test-file\nsleep 2\nrm test-file\n"; $mkoptions = "-l 0.0001"; $mkoptions .= " -j 4" if ($parallel_jobs); # We have to wait longer than the default (5s). &run_make_with_options($makefile, $mkoptions, &get_logfile, 0, 10); $slurp = &read_file_into_string(&get_logfile(1)); if ($slurp =~ /cannot enforce load limit/) { return -1; } &compare_output("$ans$ans$ans", &get_logfile(1)); 1; ================================================ FILE: tests/scripts/options/dash-n ================================================ # -*-perl-*- $description = "Test the -n option.\n"; $details = "Try various uses of -n and ensure they all give the correct results.\n"; touch('orig'); run_make_test(q! final: intermediate ; echo >> $@ intermediate: orig ; echo >> $@ !, '', "echo >> intermediate\necho >> final\n"); # TEST 1 run_make_test(undef, '-Worig -n', "echo >> intermediate\necho >> final\n"); # We consider the actual updated timestamp of targets with all # recursive commands, even with -n. Switching this to the new model # is non-trivial because we use a trick below to change the log content # before we compare it ... $makefile2 = &get_tmpfile; open(MAKEFILE, "> $makefile2"); print MAKEFILE <<'EOF'; .SUFFIXES: BAR = # nothing FOO = +$(BAR) a: b; echo > $@ b: c; $(FOO) EOF close(MAKEFILE); &utouch(-20, 'b'); &utouch(-10, 'a'); &touch('c'); # TEST 2 &run_make_with_options($makefile2, "", &get_logfile); $answer = "$make_name: 'a' is up to date.\n"; &compare_output($answer, &get_logfile(1)); # TEST 3 &run_make_with_options($makefile2, "-n", &get_logfile); $answer = "$make_name: 'a' is up to date.\n"; &compare_output($answer, &get_logfile(1)); # TEST 4 unlink(qw(a b)); &run_make_with_options($makefile2, "-t -n", &get_logfile); open(DASH_N_LOG, ">>" . &get_logfile(1)); print DASH_N_LOG "a exists but should not!\n" if -e 'a'; print DASH_N_LOG "b exists but should not!\n" if -e 'b'; close(DASH_N_LOG); &compare_output("touch b\ntouch a\n", &get_logfile(1)); # Ensure -n continues to be included with recursive/re-execed make # See Savannah bug #38051 $topmake = &get_tmpfile; $submake = &get_tmpfile; open(MAKEFILE, "> $topmake"); print MAKEFILE <<"EOF"; foo: ; \@\$(MAKE) -f "$submake" bar EOF close(MAKEFILE); # The bar target should print what would happen, but not actually run open(MAKEFILE, "> $submake"); print MAKEFILE <<'EOF'; inc: ; touch $@ -include inc bar: ; @echo $(strip $(MAKEFLAGS)) EOF close(MAKEFILE); &run_make_with_options($topmake, '-n --no-print-directory', &get_logfile); $answer = subst_make_string("#MAKEPATH# -f \"$submake\" bar\ntouch inc\necho n --no-print-directory\n"); &compare_output($answer, &get_logfile(1)); # SV 65917: Verify handling of -n with multi-target pattern rules # This is what the makefile below would run utouch(-12, qw(alpha.p)); utouch(-10, qw(alpha.x alpha.y)); utouch(-8, qw(beta.p)); utouch(-6, qw(beta.x beta.y)); utouch(-4, qw(alpha.q)); utouch(-2, qw(beta.q)); # Now make some things out of date touch(qw(alpha.p)); run_make_test(q! .SUFFIXES: .RECIPEPREFIX := > all: alpha.q beta.q alpha.p beta.p: > touch $@ %.x %.y: %.p > touch $*.x $*.y alpha.q: alpha.x alpha.y beta.y > touch $@ beta.q: beta.x beta.y alpha.y > touch $@ !, '-n', "touch alpha.x alpha.y\ntouch alpha.q\ntouch beta.q\n"); # This is what the makefile below would run utouch(-12, qw(quark.p)); utouch(-10, qw(quark.x quark.y)); utouch(-8, qw(meson.p)); utouch(-6, qw(meson.x meson.y)); utouch(-4, qw(quark.q)); utouch(-2, qw(meson.q)); # Now make some things out of date touch(qw(quark.p)); run_make_test(q! .SUFFIXES: .RECIPEPREFIX := > all: quark.q meson.q quark.p meson.p: > touch $@ quark.x quark.y &: quark.p > touch quark.x quark.y meson.x meson.y &: meson.p > touch meson.x meson.y quark.q: quark.x quark.y meson.y > touch $@ meson.q: meson.x meson.y quark.y > touch $@ !, '-n', "touch quark.x quark.y\ntouch quark.q\ntouch meson.q\n"); 1; ================================================ FILE: tests/scripts/options/dash-q ================================================ # -*-perl-*- $description = "Test the -q option.\n"; $details = "Try various uses of -q and ensure they all give the correct results.\n"; # TEST 0 run_make_test(qq! one: two: ; three: ; : four: ; \$(.XY) five: ; \\ \$(.XY) six: ; \\ \$(.XY) \t\$(.XY) seven: ; \\ \$(.XY) \t: foo \t\$(.XY) !, '-q one', ''); # TEST 1 run_make_test(undef, '-q two', ''); # TEST 2 run_make_test(undef, '-q three', '', 256); # TEST 3 run_make_test(undef, '-q four', ''); # TEST 4 run_make_test(undef, '-q five', ''); # TEST 5 run_make_test(undef, '-q six', ''); # TEST 6 run_make_test(undef, '-q seven', '', 256); # TEST 7 : Savannah bug # 7144 run_make_test(' one:: ; @echo one one:: ; @echo two ', '-q', '', 256); # TEST 7 : Savannah bug # 42249 # Make sure we exit with 1 even for prerequisite updates run_make_test(' build-stamp: ; echo $@ build-arch: build-stamp build-x: build-arch build-y: build-x ', '-q build-y', '', 256); # TEST 8 # Make sure we exit with 2 on error even with -q run_make_test(' build-stamp: ; echo $@ build-arch: build-stamp-2 build-x: build-arch build-y: build-x ', '-q build-y', "#MAKE#: *** No rule to make target 'build-stamp-2', needed by 'build-arch'. Stop.\n", 512); # TEST 9 : Savannah bug # 47151 # Make sure we exit with 1 when invoking a recursive make run_make_test(' foo: bar ; echo foo bar: ; @$(MAKE) -f #MAKEFILE# baz baz: ; echo baz ', '-q foo', '', 256); 1; ================================================ FILE: tests/scripts/options/dash-r ================================================ # -*-perl-*- $description = "Test removing default rules and variables"; touch('xxx.c'); # Simple check run_make_test("\n", '-r COMPILE.c=echo xxx.o', "#MAKE#: *** No rule to make target 'xxx.o'. Stop.", 512); # Make sure we can set it from within the makefile too run_make_test(q! COMPILE.c = echo MAKEFLAGS += -r !, 'xxx.o', "#MAKE#: *** No rule to make target 'xxx.o'. Stop.", 512); unlink('xxx.c'); # Simple check for -R run_make_test(q! all:;$(info CC='$(CC)') !, '-sR', "CC=''"); # Make sure we can set -R from within the makefile too run_make_test(q! MAKEFLAGS += -R all:;$(info CC='$(CC)') !, '-s', "CC=''"); # sv 62356. # Setting -R in MAKEFLAGS sets -r. run_make_test(q! MAKEFLAGS := -R .PHONY: hello.c all: hello.o !, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.", 512); my @flavors = ('=', ':=', ':::=', '+='); # sv 64107. # Use $answer to test that -R in the makefile has the same effect as -R on the # command line. my $answer = "at parse time TEX=\nat build time TEX=\n#MAKE#: 'all' is up to date.\n"; # Subtest 1. # First run with -R command line switch. for my $fl (@flavors) { run_make_test(" \$(info at parse time TEX=\$(TEX)) all:; \$(info at build time TEX=\$(TEX)) ", '-R', "$answer"); } # Subtest 2. # Set -R in the makefile. # Also, test that setting -R in MAKEFLAGS takes effect immediately. for my $fl (@flavors) { run_make_test(" \$(info at start time TEX=\$(TEX)) MAKEFLAGS ${fl} -R \$(info at parse time TEX=\$(TEX)) all:; \$(info at build time TEX=\$(TEX)) ", '', "at start time TEX=tex\n$answer"); } # Same as above, but also set TEX conditionally. $answer = "at parse time TEX=hello\nat build time TEX=hello\n#MAKE#: 'all' is up to date.\n"; # Subtest 3. # -R on the command line. for my $fl (@flavors) { run_make_test(" TEX ?= hello \$(info at parse time TEX=\$(TEX)) all:; \$(info at build time TEX=\$(TEX)) ", '-R', "$answer"); } # Subtest 4. # -R in the makefile. for my $fl (@flavors) { run_make_test(" \$(info at start time TEX=\$(TEX)) MAKEFLAGS ${fl} -R TEX ?= hello \$(info at parse time TEX=\$(TEX)) all:; \$(info at build time TEX=\$(TEX)) ", '', "at start time TEX=tex\n$answer"); } 1; ================================================ FILE: tests/scripts/options/dash-s ================================================ # -*-perl-*- $description = "Test the -s (silent) and --no-silent options.\n"; run_make_test(q! all: one two one: ; @echo MAKEFLAGS=$$MAKEFLAGS two: ; echo two !, '', "MAKEFLAGS=\necho two\ntwo"); run_make_test(undef, '-s', "MAKEFLAGS=s\ntwo"); run_make_test(undef, '--silent', "MAKEFLAGS=s\ntwo"); run_make_test(undef, '--quiet', "MAKEFLAGS=s\ntwo"); run_make_test(undef, '--no-silent', "MAKEFLAGS= --no-silent\necho two\ntwo"); run_make_test(undef, '-s --no-silent', "MAKEFLAGS= --no-silent\necho two\ntwo"); run_make_test(undef, '--silent --no-silent', "MAKEFLAGS= --no-silent\necho two\ntwo"); run_make_test(undef, '--quiet --no-silent', "MAKEFLAGS= --no-silent\necho two\ntwo"); run_make_test(undef, '--no-silent -s', "MAKEFLAGS=s\ntwo"); run_make_test(undef, '--no-silent --silent', "MAKEFLAGS=s\ntwo"); run_make_test(undef, '--no-silent --quiet', "MAKEFLAGS=s\ntwo"); 1; ================================================ FILE: tests/scripts/options/dash-t ================================================ # -*-perl-*- $description = "Test the -t option.\n"; $details = "Look out for regressions of prior bugs related to -t.\n"; # That means, nobody has even tried to make the tests below comprehensive # TEST 0 # bug reported by Henning Makholm on 2001-11-03: # make 3.79.1 touches only interm-[ab] but reports final-[a] as # 'up to date' without touching them. # The 'obvious' fix didn't work for double-colon rules, so pay special # attention to them. open(MAKEFILE, "> $makefile"); print MAKEFILE <<'EOMAKE'; final-a: interm-a ; echo >> $@ final-b: interm-b ; echo >> $@ interm-a:: orig1-a ; echo >> $@ interm-a:: orig2-a ; echo >> $@ interm-b:: orig1-b ; echo >> $@ interm-b:: orig2-b ; echo >> $@ EOMAKE close(MAKEFILE); &utouch(-30, 'orig1-a','orig2-b'); &utouch(-20, 'interm-a','interm-b'); &utouch(-10, 'final-a','final-b'); &touch('orig2-a','orig1-b'); &run_make_with_options($makefile, "-t final-a final-b", &get_logfile); $answer = "touch interm-a\ntouch final-a\ntouch interm-b\ntouch final-b\n"; &compare_output($answer, &get_logfile(1)); unlink('orig1-a', 'orig2-a', 'interm-a', 'final-a'); unlink('orig1-b', 'orig2-b', 'interm-b', 'final-b'); # TEST 1 # -t should not touch files with no commands. $makefile2 = &get_tmpfile; open(MAKEFILE, "> $makefile2"); print MAKEFILE <<'EOMAKE'; PHOOEY: xxx xxx: ; @: EOMAKE close(MAKEFILE); &run_make_with_options($makefile2, "-t", &get_logfile); $answer = "touch xxx\n"; &compare_output($answer, &get_logfile(1)); unlink('xxx'); 1; ================================================ FILE: tests/scripts/options/eval ================================================ # -*-perl-*- $description = "Test the --eval option."; $details = "Verify that --eval options take effect, and are passed to sub-makes."; # Verify that --eval is evaluated first run_make_test(q! $(info infile) BAR = bar all: ; @echo all recurse: ; @$(MAKE) -f #MAKEFILE# && echo recurse!, ['--eval=$(info eval)', 'FOO=$(BAR)'], "eval\ninfile\nall"); # Make sure that --eval is handled correctly during recursion run_make_test(undef, ['--no-print-directory', '--eval=$(info eval)', 'recurse'], "eval\ninfile\neval\ninfile\nall\nrecurse"); # Make sure that --eval is not passed in MAKEFLAGS run_make_test(q! all: ; @echo "MAKEFLAGS=$$MAKEFLAGS" !, ['--eval=$(info eval)'], "eval\n".'MAKEFLAGS= --eval=$$(info\ eval)'); # Make sure that --eval is handled correctly during restarting run_make_test(q! all: ; @echo $@ -include gen.mk gen.mk: ; @echo > $@ !, ['--eval=$(info eval)'], "eval\neval\nall"); unlink('gen.mk'); # Check -E run_make_test(q! BAR = bar all: ; @echo all recurse: ; @$(MAKE) -f #MAKEFILE# && echo recurse!, ['-E', '$(info eval)', 'FOO=$(BAR)'], "eval\nall"); 1; ================================================ FILE: tests/scripts/options/general ================================================ # -*-perl-*- $description = "Test generic option processing.\n"; # TEST 0 if (!$parallel_jobs) { $answer = "#MAKE#: Parallel jobs (-j) are not supported on this platform.\n#MAKE#: Resetting to single job (-j1) mode.\n1foo\n"; } else { $answer = "1foo\n"; } run_make_test(q! foo 1foo: ; @echo $@ !, "-j 1foo", $answer); # TEST 1 # This test prints the usage string; I don't really know a good way to # test it. I guess I could invoke make with a known-bad option to see # what the usage looks like, then compare it to what I get here... :( # On UNIX I can invoke it with 2>/dev/null, then just check the error code. if ($port_type ne 'W32') { run_make_test(undef, "-j1foo 2>/dev/null", '', 512); } 1; ================================================ FILE: tests/scripts/options/print-directory ================================================ # -*-perl-*- $description = "Test the -w option to GNU Make."; my $enter = "#MAKE#: Entering directory '#PWD#'"; my $leave = "#MAKE#: Leaving directory '#PWD#'"; # Simple test without -w run_make_test(q! all: ; @echo hi !, "", "hi\n"); my $ans = "$enter\nhi\n$leave\n"; # Simple test with -w run_make_test(undef, "-w", $ans); # Simple test with overriding -w run_make_test(undef, "-w --no-print-directory", "hi\n"); # Simple test with overriding --no-print-directory run_make_test(undef, "--no-print-directory --print-directory", $ans); # Test makefile rebuild to ensure no enter/leave run_make_test(q! include foo all: ;@: foo: ; touch foo !, "", "touch foo\n"); unlink('foo'); $ans = "$enter\ntouch foo\n$leave\n"; # Test makefile rebuild with -w run_make_test(undef, "-w", $ans); unlink('foo'); # Test makefile rebuild with -w overridden run_make_test(undef, "-w --no-print-directory", "touch foo\n"); unlink('foo'); # Test makefile rebuild with --no-print-directory overridden run_make_test(undef, "--no-print-directory --print-directory", $ans); unlink('foo'); my $enter1 = "#MAKE#[1]: Entering directory '#PWD#'"; my $leave1 = "#MAKE#[1]: Leaving directory '#PWD#'"; $ans = "$enter1\nhi\n$leave1\n"; # Test makefile recursion with default enter/leave run_make_test(q! all: ;@$(MAKE) -f #MAKEFILE# recurse recurse: ; @echo hi !, "", $ans); # Disable enter/leave run_make_test(undef, "--no-print-directory", "hi\n"); # Re-enable enter/leave $ans = "$enter\n$ans$leave\n"; run_make_test(undef, "--no-print-directory -w", $ans); # Override enter/leave run_make_test(undef, "-w --no-print-directory", "hi\n"); 1; ================================================ FILE: tests/scripts/options/print-targets ================================================ # -*-perl-*- $description = "Test the --print-targets option to GNU Make."; # Define various things and verify the output run_make_test(q! .PHONY: all all: ;@: # "special" target .BOGUS: ;@: # Check various forms of suffix rule .SUFFIXES: .q .q: ;@: .c.o: ;@: # Not a suffix rule .x.z: ;@: # Verify included files aren't built / don't fail include badfile include goodfile submake: ; $(MAKE) all always: ; +echo always goodfile: ; touch goodfile !, "--print-targets", "submake\n.x.z\nalways\nall\ngoodfile\n"); 1; ================================================ FILE: tests/scripts/options/shuffle ================================================ # -*-perl-*- $description = "Test the --shuffle option."; $details = "Verify that --shuffle has expected effect on target order and argument order."; # # Test --shuffle=random # # TEST 1: Fixed seed should yield the same order from run to run. $makefile = &get_tmpfile; open(MAKEFILE, "> $makefile"); print MAKEFILE <<'EOF'; # More target prerequisites lower collision chance in TEST 2 all: a_ b_ c_ d_ e_ f_ g_ i_ j_ k_ l_ %: ; echo $@ EOF close(MAKEFILE); $log1 = &get_logfile; $log2 = &get_logfile; &run_make_with_options($makefile, "--shuffle=12345", $log1); &run_make_with_options($makefile, "--shuffle=12345", $log2); &compare_output(&read_file_into_string($log1), $log2); # TEST 2: Sequential runs should produce different orders. $log3 = &get_logfile; $log4 = &get_logfile; &run_make_with_options($makefile, "--shuffle", $log3); &run_make_with_options($makefile, "--shuffle", $log4); ++$tests_run; if (&read_file_into_string($log3) ne &read_file_into_string($log4)) { print "ok\n" if $debug; ++$tests_passed; } # # Test --shuffle=reverse # run_make_test(' %: ; @echo $@ all: a b c ', '--shuffle=reverse', "c\nb\na\nall"); run_make_test(' %: ; @echo $@ all: a b c ', '--shuffle=none', "a\nb\nc\nall"); run_make_test(' %: ; @echo $@ all: a b c ', '--shuffle=identity', "a\nb\nc\nall"); # Make sure prerequisites get reverse order and commands don't get affected. run_make_test(' all: foo.o ; @echo $@ %.o : %.c ; @echo cc -c -o $@ $< foo.o : foo.c foo.h bar.h baz.h %.h: ; @echo $@ %.c: ; @echo $@ ', '--shuffle=reverse', "baz.h\nbar.h\nfoo.h\nfoo.c\ncc -c -o foo.o foo.c\nall"); # Make sure pattern prerequisites get reverse order and commands don't get # affected. run_make_test(' all: foo_ ; @echo $@ foo%: arg%1 arg%2 arg%3 arg%4 ; @echo bld $@ $< $(word 3,$^) $(word 2,$^) $(word 4,$^) arg%: ; @echo $@ ', '--shuffle=reverse', "arg_4\narg_3\narg_2\narg_1\nbld foo_ arg_1 arg_3 arg_2 arg_4\nall"); # Check if make can survive circular dependency. run_make_test(' all: a_ b_ ; @echo $@ %_: ; @echo $@ a_: b_ b_: a_ ', '--shuffle=reverse', "#MAKE#: circular a_ <- b_ dependency dropped\na_\nb_\nall"); # Check if order-only dependencies get reordered. run_make_test(' all: a_ ; @echo $@ %_: ; @echo $@ a_: b_ c_ | d_ e_ ', '--shuffle=reverse', "e_\nd_\nc_\nb_\na_\nall"); # Check if goals are reordered. run_make_test(' %_: ; @echo $@ ', '--shuffle=reverse a_ b_ c_', "c_\nb_\na_"); # .NOTPARALLEL should prevent reordering from happening. run_make_test(' %_: ; @echo $@ # disable shuffling .NOTPARALLEL: ', '--shuffle=reverse a_ b_ c_', "a_\nb_\nc_"); # Check if SECONDEXPANSION targets also get reshuffled. run_make_test(' .SECONDEXPANSION: all: $$(var) %_: ; @echo $@ var = a_ b_ c_ ', '--shuffle=reverse', "c_\nb_\na_"); 1; ================================================ FILE: tests/scripts/options/symlinks ================================================ # -*-perl-*- $description = "Test the -L option."; $details = "Verify that symlink handling with and without -L works properly."; # Only run these tests if the system sypports symlinks exists $FEATURES{'check-symlink'} or return -1; use File::Spec; # Set up a symlink sym -> dep # We'll make both dep and targ older than sym &utouch(-10, 'dep'); &utouch(-5, 'targ'); my $dirnm = (File::Spec->splitdir($testpath))[-1]; my $dep = File::Spec->catfile(File::Spec->updir(), $dirnm, 'dep'); symlink($dep, 'sym') or die "Cannot create symlink sym -> $dep\n"; # Without -L, nothing should happen # With -L, it should update targ run_make_test('targ: sym ; @echo make $@ from $<', '', "#MAKE#: 'targ' is up to date."); run_make_test(undef, '-L', "make targ from sym"); # Now update dep; in all cases targ should be out of date. &touch('dep'); run_make_test(undef, '', "make targ from sym"); run_make_test(undef, '-L', "make targ from sym"); # Now update targ; in all cases targ should be up to date. &touch('targ'); run_make_test(undef, '', "#MAKE#: 'targ' is up to date."); run_make_test(undef, '-L', "#MAKE#: 'targ' is up to date."); # Add in a new link between sym and dep. Be sure it's newer than targ. sleep(1); rename('dep', 'dep1'); symlink('dep1', 'dep'); # Without -L, nothing should happen # With -L, it should update targ run_make_test(undef, '', "#MAKE#: 'targ' is up to date."); run_make_test(undef, '-L', "make targ from sym"); rmfiles('targ', 'dep', 'sym', 'dep1'); # Check handling when symlinks point to non-existent files. Without -L we # should get an error: with -L we should use the timestamp of the symlink. symlink("../$dirnm/dep", 'sym'); run_make_test('targ: sym ; @echo make $@ from $<', '', "#MAKE#: *** No rule to make target 'sym', needed by 'targ'. Stop.", 512); run_make_test('targ: sym ; @echo make $@ from $<', '-L', 'make targ from sym'); rmfiles('targ', 'sym'); 1; ================================================ FILE: tests/scripts/options/warn ================================================ # -*-perl-*- $description = "Test the --warn option."; my %warn_test = ( '--warn' => '', '--warn=warn' => '', '--warn=error --warn=warn' => '', '--warn --warn=error' => '=error', '--warn=ignore --warn=error --warn=ignore --warn=invalid-ref,invalid-var,undefined-var' => '=ignore,invalid-ref,invalid-var,undefined-var', '--warn=invalid-ref:ignore --warn=error --warn=invalid-var:warn,,,,,undefined-var:error,,,,,' => '=error,invalid-ref:ignore,invalid-var,undefined-var:error' ); # Verify the deprecated --warn-undefined-variables option run_make_test(q! $(info MF=$(MAKEFLAGS)) all:; @#HELPER# env MAKEFLAGS !, '--warn-undefined-variables', "MF= --warn=undefined-var\nMAKEFLAGS= --warn=undefined-var"); # sv 64115. # Verify that -R along with --warn-undefined-variables do not warn about # internal variables, such as GNUMAKEFLAGS. run_make_test(q! $(info MF=$(MAKEFLAGS)) all:; @#HELPER# env MAKEFLAGS !, '-R --warn-undefined-variables', "MF=rR --warn=undefined-var\nMAKEFLAGS=rR --warn=undefined-var"); # Verify parsing of --warn in various forms. while (my ($f, $r) = each %warn_test) { run_make_test(undef, $f, "MF= --warn$r\nMAKEFLAGS= --warn$r"); } # Verify that values set in MAKEFLAGS take effect while (my ($f, $r) = each %warn_test) { run_make_test(qq! MAKEFLAGS += $f \$(info MF=\$(MAKEFLAGS)) all:; \@#HELPER# env MAKEFLAGS !, '', "MF= --warn$r\nMAKEFLAGS= --warn$r"); } # Verify that make's special variables don't warn even if they're not set run_make_test(q! vars := $(.VARIABLES) $(MAKECMDGOALS) $(MAKE_RESTARTS) $(CURDIR) vars += $(GNUMAKEFLAGS) $(MAKEFLAGS) $(MFLAGS) $(MAKE_COMMAND) $(MAKE) vars += $(MAKEFILE_LIST) $(MAKEOVERRIDES) $(-*-command-variables-*-) vars += $(.RECIPEPREFIX) $(.LOADED) $(.FEATURES) vars += $(SHELL) $(.SHELLFLAGS) $(MAKE_TERMOUT) $(MAKE_TERMERR) vars += $(.DEFAULT) $(.DEFAULT_GOAL) $(-*-eval-flags-*-) $(SUFFIXES) vars += $(VPATH) $(GPATH) all:; !, '--warn=undefined-var', "#MAKE#: 'all' is up to date."); # sv 63609. # Test for buffer overrun in warn_undefined. run_make_test(q! all:; X := $(averyveryveryloooooooooooooooooooooooooooongvariablename) !, '--warn=undefined-var', "#MAKEFILE#:3: warning: reference to undefined variable 'averyveryveryloooooooooooooooooooooooooooongvariablename' #MAKE#: 'all' is up to date.\n" ); # Check undefined variable warnings # With no options or with ignore, nothing should happen run_make_test(' EMPTY = EREF = $(EMPTY) UREF = $(UNDEFINED) SEREF := $(EREF) SUREF := $(UREF) all: ; @echo ref $(EREF) $(UREF)', '', 'ref'); run_make_test(undef, '--warn=undefined-var:ignore', 'ref'); # Check warnings run_make_test(undef, '--warn=undefined-var', "#MAKEFILE#:7: warning: reference to undefined variable 'UNDEFINED' #MAKEFILE#:9: warning: reference to undefined variable 'UNDEFINED' ref"); # Check and errors run_make_test(undef, '--warn=undefined-var:error', "#MAKEFILE#:7: *** reference to undefined variable 'UNDEFINED'. Stop.", 512); # Check invalid variable reference warnings # With no options we still check for invalid references run_make_test(' IREF = $(bad variable) SIREF := $(IREF) define nl endef all: ; @echo ref $(also$(nl)bad) $(IREF) $(SIREF)', '', "#MAKEFILE#:2: warning: invalid variable reference 'bad variable' #MAKEFILE#:10: warning: invalid variable reference 'also\nbad' #MAKEFILE#:2: warning: invalid variable reference 'bad variable' ref"); run_make_test(undef, '--warn=ignore', 'ref'); run_make_test(undef, '--warn=invalid-ref:ignore', 'ref'); # Check and errors run_make_test(undef, '--warn=invalid-ref:error', "#MAKEFILE#:2: *** invalid variable reference 'bad variable'. Stop.", 512); # Check invalid variable name warnings # With no options we still check for invalid references run_make_test(' EMPTY = SPACE = $(EMPTY) $(EMPTY) BAD$(SPACE)VAR = foo define nl endef NL$(nl)VAR = bar define BAD$(SPACE)DEF := foo endef define NL$(nl)DEF := foo endef all: ; @echo ref', '', "#MAKEFILE#:4: warning: invalid variable name 'BAD VAR' #MAKEFILE#:11: warning: invalid variable name 'NL\nVAR' #MAKEFILE#:13: warning: invalid variable name 'BAD DEF' #MAKEFILE#:17: warning: invalid variable name 'NL\nDEF' ref"); run_make_test(undef, '--warn=ignore', 'ref'); run_make_test(undef, '--warn=invalid-var:ignore', 'ref'); # Check errors run_make_test(undef, '--warn=invalid-var:error', "#MAKEFILE#:4: *** invalid variable name 'BAD VAR'. Stop.", 512); # Make sure unknown warnings and actions fail when given on the command line. run_make_test(undef, '--warn=no-such-warn', "#MAKE#: *** unknown warning 'no-such-warn'. Stop.", 512); run_make_test(undef, '--warn=invalid-var:no-such-action', "#MAKE#: *** unknown warning action 'no-such-action'. Stop.", 512); # sv 65739. Circular dependency. run_make_test(q! hello: hello; @: !, '', "#MAKE#: circular hello <- hello dependency dropped\n"); run_make_test(undef, '--warn=error', "#MAKE#: *** circular hello <- hello dependency detected. Stop.\n", 512); run_make_test(undef, '--warn=circular-dep:error', "#MAKE#: *** circular hello <- hello dependency detected. Stop.\n", 512); run_make_test(undef, '--warn=warn', "#MAKE#: circular hello <- hello dependency dropped\n"); run_make_test(undef, '--warn=circular-dep:warn', "#MAKE#: circular hello <- hello dependency dropped\n"); run_make_test(undef, '--warn=ignore', ''); run_make_test(undef, '--warn=circular-dep:ignore', ''); 1; ================================================ FILE: tests/scripts/targets/DEFAULT ================================================ # -*-perl-*- $description = "The following test creates a makefile to override part\n" ."of one Makefile with Another Makefile with the .DEFAULT\n" ."rule."; $details = "This tests the use of the .DEFAULT special target to say that \n" ."to remake any target that cannot be made fram the information\n" ."in the containing makefile, make should look in another makefile\n" ."This test gives this makefile the target bar which is not \n" ."defined here but passes the target bar on to another makefile\n" ."which does have the target bar defined.\n"; create_file('defsub.mk', q! bar: ; @echo Executing rule BAR !); run_make_test(q! foo:; @echo Executing rule FOO .DEFAULT: ; @$(MAKE) -f defsub.mk $@ !, 'bar',"#MAKE#[1]: Entering directory '#PWD#'\n" . "Executing rule BAR\n" . "#MAKE#[1]: Leaving directory '#PWD#'\n"); unlink('defsub.mk'); 1; ================================================ FILE: tests/scripts/targets/DELETE_ON_ERROR ================================================ #! -*-perl-*- $description = "Test the behaviour of the .DELETE_ON_ERROR target."; $details = ""; run_make_test(' .DELETE_ON_ERROR: all: ; exit 1 > $@ ', '', "exit 1 > all\n#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n#MAKE#: *** deleting file 'all'", 512); run_make_test(' .DELETE_ON_ERROR: all: foo.x ; %.x : %.q ; echo > $@ %.q : ; exit 1 > $@ ', '', "exit 1 > foo.q\n#MAKE#: *** [#MAKEFILE#:5: foo.q] Error 1\n#MAKE#: *** deleting file 'foo.q'", 512); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/FORCE ================================================ # -*-perl-*- $description = "The following tests rules without Commands or Dependencies."; # Create a file named "clean". This is the same name as the target clean # and tricks the target into thinking that it is up to date. (Unless you # use the .PHONY target. touch('clean'); run_make_test(qq! .IGNORE : clean: FORCE ; $CMD_rmfile clean FORCE: !, '', "$CMD_rmfile clean"); rmfiles('clean'); 1; ================================================ FILE: tests/scripts/targets/IGNORE ================================================ # -*-perl-*- $description = "Test the behaviour of the .IGNORE target."; $details = ""; # Without any ignore run_make_test(q! all: ; @#HELPER# -q fail 1 !, '', "#MAKE#: *** [#MAKEFILE#:2: all] Error 1", 512); # Global .IGNORE run_make_test(q! .IGNORE: all: ; @#HELPER# -q fail 1 !, '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)"); # Specific .IGNORE run_make_test(q! .IGNORE: all all: ; @#HELPER# -q fail 1 !, '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)"); 1; ================================================ FILE: tests/scripts/targets/INTERMEDIATE ================================================ # -*-perl-*- $description = "Test the behaviour of the .INTERMEDIATE target."; $details = "\ Test the behavior of the .INTERMEDIATE special target. Create a makefile where a file would not normally be considered intermediate, then specify it as .INTERMEDIATE. Build and ensure it's deleted properly. Rebuild to ensure that it's not created if it doesn't exist but doesn't need to be built. Change the original and ensure that the intermediate file and the ultimate target are both rebuilt, and that the intermediate file is again deleted. Try this with implicit rules and explicit rules: both should work.\n"; # TEST #0 &utouch(-20, 'foo.f', 'bar.f'); run_make_test(q! .INTERMEDIATE: foo.e bar.e # Implicit rule test %.d : %.e ; cp $< $@ %.e : %.f ; cp $< $@ foo.d: foo.e # Explicit rule test foo.c: foo.e bar.e; cat $^ > $@ !, 'foo.d', "cp foo.f foo.e\ncp foo.e foo.d\nrm foo.e\n"); # TEST #1 run_make_test(undef, 'foo.d', "#MAKE#: 'foo.d' is up to date.\n"); # TEST #2 &utouch(-10, 'foo.d'); &touch('foo.f'); run_make_test(undef, 'foo.d', "cp foo.f foo.e\ncp foo.e foo.d\nrm foo.e\n"); # TEST #3 run_make_test(undef, 'foo.c', "cp foo.f foo.e\ncp bar.f bar.e\ncat foo.e bar.e > foo.c\nrm foo.e bar.e\n"); # TEST #4 run_make_test(undef, 'foo.c', "#MAKE#: 'foo.c' is up to date.\n"); # TEST #5 &utouch(-10, 'foo.c'); &touch('foo.f'); run_make_test(undef, 'foo.c', "cp foo.f foo.e\ncp bar.f bar.e\ncat foo.e bar.e > foo.c\nrm foo.e bar.e\n"); # TEST #6 -- added for PR/1669: don't remove files mentioned on the cmd line. run_make_test(undef, 'foo.e', "cp foo.f foo.e\n"); unlink('foo.f', 'foo.e', 'foo.d', 'foo.c', 'bar.f', 'bar.e', 'bar.d', 'bar.c'); # TEST #7 -- added for PR/1423 run_make_test(q! all: foo foo.a: ; touch $@ %: %.a ; touch $@ .INTERMEDIATE: foo.a !, '-R', "touch foo.a\ntouch foo\nrm foo.a\n"); unlink('foo'); # sv 60188. # A file made by an implicit rule, but explicitly mentioned by the user, is # still considered intermediate if it's a prereq to .INTERMEDIATE. touch('hello.z'); unlink('test.x'); run_make_test(q! all: hello.z %.z: test.x; touch $@ %.x: ; .INTERMEDIATE: test.x !, '', "#MAKE#: Nothing to be done for 'all'.\n"); unlink('hello.z'); # A target explicitly listed as a prerequisite of a pattern rule, is still # considered mentioned and "ought to exist". run_make_test(q! 1.all: 1.q ; touch $@ %.q: 1.r ; touch $@ %.r: ; touch $@ .INTERMEDIATE: 1.r !, '', "touch 1.r\ntouch 1.q\ntouch 1.all\nrm 1.r\n"); unlink('1.all', '1.q', '1.r'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/NOTINTERMEDIATE ================================================ # -*-perl-*- $description = "Test the behaviour of the .NOTINTERMEDIATE target."; $details = "\ Test the behavior of the .NOTINTERMEDIATE special target.\n"; touch('hello.z'); unlink('hello.x'); # Test 1. A file which matches a .NOTINTERMEDIATE pattern is not intermediate. run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: %.q %.x !, '', "touch hello.z\n"); # Test 2. .NOTINTERMEDIATE: %.q pattern has no effect on hello.x. touch('hello.z'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: %.q !, '', "#MAKE#: 'hello.z' is up to date.\n"); # Test 3. A file which is a prereq of .NOTINTERMEDIATE is not intermediate. run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: %.q hello.x !, '', "touch hello.z\n"); # Test 4. .NOTINTERMEDIATE without prerequisites makes everything # notintermediate. run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: !, '', "touch hello.z\n"); # Test 5. Same file cannot be intermediate and notintermediate. run_make_test(q! .INTERMEDIATE: hello.x .NOTINTERMEDIATE: hello.x !, '', "#MAKE#: *** hello.x cannot be both .NOTINTERMEDIATE and .INTERMEDIATE. Stop.\n", 512); # Test 6. Same file cannot be secondary and notintermediate. run_make_test(q! .SECONDARY: hello.x .NOTINTERMEDIATE: hello.x !, '', "#MAKE#: *** hello.x cannot be both .NOTINTERMEDIATE and .SECONDARY. Stop.\n", 512); # Test 7. All .SECONDARY and all .NOTINTERMEDIATE are mutually exclusive. run_make_test(q! .SECONDARY: .NOTINTERMEDIATE: !, '', "#MAKE#: *** .NOTINTERMEDIATE and .SECONDARY are mutually exclusive. Stop.\n", 512); # Test 8. .INTERMEDIATE file takes priority over a .NOTINTERMEDIATE pattern. unlink('hello.x'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .INTERMEDIATE: hello.x .NOTINTERMEDIATE: %.q %.x !, '', "#MAKE#: 'hello.z' is up to date.\n"); # Test 9. Everything is notintermediate, except hello.x. unlink('hello.x'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .INTERMEDIATE: hello.x .NOTINTERMEDIATE: !, '', "#MAKE#: 'hello.z' is up to date.\n"); # Test 10. Everything is notintermediate, except hello.x. unlink('hello.x'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .SECONDARY: hello.x .NOTINTERMEDIATE: !, '', "#MAKE#: 'hello.z' is up to date.\n"); # Test 11. Everything is secondary, except %.q, hello.x. unlink('hello.x'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: %.q hello.x .SECONDARY: !, '', "touch hello.z\n"); # Test 12. Everything is secondary, except %.q %.x. unlink('hello.x'); run_make_test(q! hello.z: %.z: %.x; touch $@ %.x: ; .NOTINTERMEDIATE: %.q %.x .SECONDARY: !, '', "touch hello.z\n"); unlink('hello.z'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/ONESHELL ================================================ # -*-perl-*- $description = "Test the behaviour of the .ONESHELL target."; $details = ""; my $multi_ok = 0; if ($port_type ne 'W32') { # Some shells (*shakes fist at Solaris*) cannot handle multiple flags in # separate arguments. my $t = `$sh_name -e -c true 2>/dev/null`; $multi_ok = $? == 0; } # Simple run_make_test(q! .ONESHELL: all: a=$$$$ [ 0"$$a" -eq "$$$$" ] || echo fail !, '', 'a=$$ [ 0"$a" -eq "$$" ] || echo fail '); # Simple but use multi-word SHELLFLAGS if ($multi_ok) { run_make_test(q! .ONESHELL: .SHELLFLAGS = -e -c all: a=$$$$ [ 0"$$a" -eq "$$$$" ] || echo fail !, '', 'a=$$ [ 0"$a" -eq "$$" ] || echo fail '); } # Again, but this time with inner prefix chars run_make_test(q! .ONESHELL: all: a=$$$$ @-+ [ 0"$$a" -eq "$$$$" ] || echo fail !, '', 'a=$$ [ 0"$a" -eq "$$" ] || echo fail '); # This time with outer prefix chars run_make_test(q! .ONESHELL: all: @a=$$$$ [ 0"$$a" -eq "$$$$" ] || echo fail !, '', ''); # This time with outer and inner prefix chars run_make_test(q! .ONESHELL: all: @a=$$$$ -@ +[ 0"$$a" -eq "$$$$" ] || echo fail !, '', ''); # Now try using a different interpreter # This doesn't work on Windows right now if ($port_type ne 'W32') { run_make_test(q! .RECIPEPREFIX = > .ONESHELL: SHELL = #PERL# .SHELLFLAGS = -e all: > @$$a=5 > +7; > @y=qw(a b c); >print "a = $$a, y = (@y)\n"; !, '', "a = 12, y = (a b c)\n"); # Simple .SHELLFLAGS, no quotes. # sv 61805. run_make_test(q! .ONESHELL: SHELL = #PERL# .SHELLFLAGS = -e all:; @print "it works\n" !, '', 'it works'); # Pass a quoted string with spaces to oneshell. # sv 61805. run_make_test(q! .ONESHELL: SHELL = #PERL# .SHELLFLAGS = -w -E 'use warnings FATAL => "all";' -E all:; @print "it works\n" !, '', 'it works'); # Empty .SHELLFLAGS. # sv 61805. run_make_test(q! .ONESHELL: SHELL = #PERL# .SHELLFLAGS = all:; @print "it works" !, '', "Can't open perl script \"print \"it works\"\": $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: all] Error $ERR_no_such_file_code", 512); # No .SHELLFLAGS. # sv 61805. run_make_test(q! .ONESHELL: SHELL = #PERL# all:; @print "it works" !, '', "Can't open perl script \"print \"it works\"\": $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:4: all] Error $ERR_no_such_file_code", 512); # Pass a quoted string with spaces to oneshell. # sv 61805. run_make_test(q! .ONESHELL: SHELL = #PERL# .SHELLFLAGS = -w -E 'use warnings FATAL => "all";' -E 'my $$foo = "bar";' -E all:; @print "it works: $$foo\n" !, '', 'it works: bar'); } # This tells the test driver that the perl test script executed properly. 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/targets/PHONY ================================================ # -*-perl-*- $description = "The following tests the use of a PHONY target. It makes\n" ."sure that the rules under a target get executed even if\n" ."a filename of the same name of the target exists in the\n" ."directory.\n"; $details = "This makefile in this test declares the target clean to be a \n" ."PHONY target. We then create a file named \"clean\" in the \n" ."directory. Although this file exists, the rule under the target\n" ."clean should still execute because of it's phony status."; $example = "EXAMPLE_FILE"; touch($example); # Create a file named "clean". This is the same name as the target clean # and tricks the target into thinking that it is up to date. (Unless you # use the .PHONY target. touch('clean'); open(MAKEFILE, "> $makefile"); print MAKEFILE qq! .PHONY : clean all: ; \@echo This makefile did not clean the dir ... good clean: ; $CMD_rmfile $example clean !; close(MAKEFILE); $answer = "$CMD_rmfile $example clean\n"; &run_make_with_options($makefile,"clean",&get_logfile); if (-f $example) { $test_passed = 0; } &compare_output($answer,&get_logfile(1)); # Just in case unlink($example, 'clean'); 1; ================================================ FILE: tests/scripts/targets/POSIX ================================================ # -*-perl-*- $description = "Test the behaviour of the .POSIX target."; $details = ""; # Ensure turning on .POSIX enables the -e flag for the shell run_make_test(q! .POSIX: all: ; @#HELPER# -q fail 1; #HELPER# out hello !, '', "#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512); # But explicit settings must still take precedence run_make_test(q! .POSIX: all: ; @-#HELPER# -q fail 1; #HELPER# out hello .SHELLFLAGS = -c !, '', "hello"); run_make_test(q! .POSIX: all: ; @-#HELPER# -q fail 1; #HELPER# out hello all: .SHELLFLAGS = -c !, '', "hello"); # SV 63667: We shouldn't add -e to sh if errors are ignored run_make_test(q! .POSIX: all: ; @-#HELPER# -q fail 1; #HELPER# out hello !, '', "hello\n"); # SV 64085: Also don't add -e if -i or .IGNORE is used run_make_test(q! .POSIX: all: ; @#HELPER# -q fail 1; #HELPER# out hello !, '-i', "hello\n"); run_make_test(q! .POSIX: .IGNORE: all: ; @#HELPER# -q fail 1; #HELPER# out hello !, '', "hello\n"); run_make_test(q! .POSIX: .IGNORE: all all: ; @#HELPER# -q fail 1; #HELPER# out hello !, '', "hello\n"); # But explicit settings must still take precedence run_make_test(q! .POSIX: all: ; @-#HELPER# -q fail 1; #HELPER# out hello .SHELLFLAGS = -ec !, '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n"); run_make_test(q! .POSIX: all: ; @-#HELPER# -q fail 1; #HELPER# out hello all: .SHELLFLAGS = -ec !, '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n"); # User settings must override .POSIX # In the standard .POSIX must be the first thing in the makefile # but we relax that rule in GNU Make. # Different versions of sh generate different output for -x so check it my $script = subst_make_string('#HELPER# -q fail 1; true'); my $flags = '-xc'; my $out = `$sh_name $flags '$script' 2>&1`; run_make_test(qq! .SHELLFLAGS = $flags .POSIX: all: ; \@$script !, '', $out); # Test the default value of various POSIX-specific variables my %POSIX = (AR => 'ar', ARFLAGS => '-rv', YACC => 'yacc', YFLAGS => '', LEX => 'lex', LFLAGS => '', LDFLAGS => '', CC => 'c99', CFLAGS => '-O1', FC => 'fort77', FFLAGS => '-O1', SCCSFLAGS => '', SCCSGETFLAGS => '-s'); my $make = join('', map { "\t\@echo '$_=\$($_)'\n" } sort keys %POSIX); my $r = join('', map { "$_=$POSIX{$_}\n"} sort keys %POSIX); run_make_test(qq! .POSIX: all: $make !, '', $r); # Make sure that local settings take precedence %ENV = (%ENV, map { $_ => "xx-$_" } keys %POSIX); $r = join('', map { "$_=xx-$_\n"} sort keys %POSIX); run_make_test(undef, '', $r); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/SECONDARY ================================================ #! -*-perl-*- $description = "Test the behaviour of the .SECONDARY target."; $details = "\ Test the behavior of the .SECONDARY special target. Create a makefile where a file would not normally be considered intermediate, then specify it as .SECONDARY. Build and note that it's not automatically deleted. Delete the file. Rebuild to ensure that it's not created if it doesn't exist but doesn't need to be built. Change the original and ensure that the secondary file and the ultimate target are both rebuilt, and that the secondary file is not deleted. Try this with implicit rules and explicit rules: both should work.\n"; open(MAKEFILE,"> $makefile"); print MAKEFILE <<'EOF'; .SECONDARY: foo.e # Implicit rule test %.d : %.e ; cp $< $@ %.e : %.f ; cp $< $@ foo.d: foo.e # Explicit rule test foo.c: foo.e ; cp $< $@ EOF close(MAKEFILE); # TEST #1 &utouch(-20, 'foo.f'); &run_make_with_options($makefile,'foo.d',&get_logfile); $answer = "cp foo.f foo.e\ncp foo.e foo.d\n"; &compare_output($answer, &get_logfile(1)); # TEST #2 unlink('foo.e'); &run_make_with_options($makefile,'foo.d',&get_logfile); $answer = "$make_name: 'foo.d' is up to date.\n"; &compare_output($answer, &get_logfile(1)); # TEST #3 &utouch(-10, 'foo.d'); &touch('foo.f'); &run_make_with_options($makefile,'foo.d',&get_logfile); $answer = "cp foo.f foo.e\ncp foo.e foo.d\n"; &compare_output($answer, &get_logfile(1)); # TEST #4 &run_make_with_options($makefile,'foo.c',&get_logfile); $answer = "cp foo.e foo.c\n"; &compare_output($answer, &get_logfile(1)); # TEST #5 unlink('foo.e'); &run_make_with_options($makefile,'foo.c',&get_logfile); $answer = "$make_name: 'foo.c' is up to date.\n"; &compare_output($answer, &get_logfile(1)); # TEST #6 &utouch(-10, 'foo.c'); &touch('foo.f'); &run_make_with_options($makefile,'foo.c',&get_logfile); $answer = "cp foo.f foo.e\ncp foo.e foo.c\n"; &compare_output($answer, &get_logfile(1)); unlink('foo.f', 'foo.e', 'foo.d', 'foo.c'); # TEST #7 -- test the "global" .SECONDARY, with no targets. $makefile2 = &get_tmpfile; open(MAKEFILE, "> $makefile2"); print MAKEFILE <<'EOF'; .SECONDARY: final: intermediate intermediate: source final intermediate source: ; echo $< > $@ EOF close(MAKEFILE); &utouch(-10, 'source'); touch('final'); &run_make_with_options($makefile2, '', &get_logfile); $answer = "$make_name: 'final' is up to date.\n"; &compare_output($answer, &get_logfile(1)); unlink('source', 'final', 'intermediate'); # TEST #8 -- test the "global" .SECONDARY, with .PHONY. touch('version2'); run_make_test(' .PHONY: version .SECONDARY: version2: version ; @echo GOOD all: version2', 'all', 'GOOD'); unlink('version2'); # TEST #9 -- Savannah bug #15919 # The original fix for this bug caused a new bug, shown here. touch(qw(1.a 2.a)); run_make_test(' %.c : %.b ; cp $< $@ %.b : %.a ; cp $< $@ all : 1.c 2.c 2.a: 1.c', '-rR -j', 'cp 1.a 1.b cp 1.b 1.c cp 2.a 2.b cp 2.b 2.c rm 2.b 1.b'); unlink(qw(1.a 2.a 1.c 2.c)); # TEST #10 -- Savannah bug #15919 touch('test.0'); run_make_test(' .SECONDARY : test.1 test.2 test.3 test : test.4 %.4 : %.int %.3 ; touch $@ %.int : %.3 %.2 ; touch $@ %.3 : | %.2 ; touch $@ %.2 : %.1 ; touch $@ %.1 : %.0 ; touch $@', '-rR -j 2', 'touch test.1 touch test.2 touch test.3 touch test.int touch test.4 rm test.int'); # After a touch of test.0 it should give the same output, except we don't need # to rebuild test.3 (order-only) sleep(1); touch('test.0'); run_make_test(undef, '-rR -j 2', 'touch test.1 touch test.2 touch test.int touch test.4 rm test.int'); # With both test.0 and test.3 updated it should still build everything except # test.3 sleep(1); touch('test.0', 'test.3'); run_make_test(undef, '-rR -j 2', 'touch test.1 touch test.2 touch test.int touch test.4 rm test.int'); unlink(qw(test.0 test.1 test.2 test.3 test.4)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/SILENT ================================================ # -*-perl-*- $description = "Test the special target .SILENT."; run_make_test(q! .PHONY: M a b M: a b .SILENT : b a b: ; echo $@ !, '', "echo a\na\nb"); run_make_test(q! .PHONY: M a b M: a b .SILENT: a b: ; echo $@ !, '', "a\nb"); # SV 54740 : don't inherit .SILENT settings in sub-makes run_make_test(q! .PHONY: M r a b r: a b ; @$(MAKE) -f #MAKEFILE# M V=x a b: ; echo $@ V = $V.SILENT: M: a b !, '--no-print-directory', "a\nb\necho a\na\necho b\nb"); 1; ================================================ FILE: tests/scripts/targets/WAIT ================================================ # -*-perl-*- $description = "Test the behaviour of the .WAIT target."; $details = ""; # Ensure .WAIT doesn't appear in any automatic variables run_make_test(q! all: .WAIT pre1 .WAIT pre2 | .WAIT pre3 ; @echo '<=$< ^=$^ ?=$? +=$+ |=$|' pre1 pre2 pre3:; # This is just here so we don't fail with older versions of make .WAIT: !, '', '<=pre1 ^=pre1 pre2 ?=pre1 pre2 +=pre1 pre2 |=pre3'); run_make_test(q! .SECONDEXPANSION: all: $$(pre) ; @echo '<=$< ^=$^ ?=$? +=$+ |=$|' pre1 pre2 pre3:; pre = .WAIT pre1 .WAIT pre2 | .WAIT pre3 # This is just here so we don't fail with older versions of make .WAIT: !, '', '<=pre1 ^=pre1 pre2 ?=pre1 pre2 +=pre1 pre2 |=pre3'); run_make_test(q! all: pre p% : .WAIT p%1 .WAIT p%2 | .WAIT p%3; @echo '<=$< ^=$^ ?=$? +=$+ |=$|' pre1 pre2 pre3: ; # This is just here so we don't fail with older versions of make .WAIT: !, '', "<=pre1 ^=pre1 pre2 ?=pre1 pre2 +=pre1 pre2 |=pre3\n"); # Unfortunately I don't think we can get away from using sleep here; at least # I can't think of any way to make sure .WAIT works without it. Even with it, # it's not reliable (in that even if .WAIT is not working we MIGHT succeed the # test--it shouldn't ever be the case that we fail the test unexpectedly). # That makes this test suite slow to run :-/. run_make_test(q! all : pre1 .WAIT pre2 pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\npre2\n"); # Ensure .WAIT doesn't add extra a dependency between its targets run_make_test(undef, '-j10 pre2', "pre2\n"); # sv 63856. # .WAIT on the command line. run_make_test(q! pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 pre1 .WAIT pre2', "start-pre1\nend-pre1\npre2\n"); # Multiple consecutive .WAITs. run_make_test(q! all : pre1 .WAIT .WAIT .WAIT pre2 pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\npre2\n"); # First and last prerequsites are .WAIT. run_make_test(q! all : .WAIT pre1 .WAIT pre2 .WAIT pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\npre2\n"); # All prerequisites are .WAITs. run_make_test(q! all : .WAIT .WAIT .WAIT # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "#MAKE#: Nothing to be done for 'all'.\n"); run_make_test(q! all: !, '-j10 .WAIT', "#MAKE#: Nothing to be done for 'all'.\n"); # Wait between the duplicate goals. run_make_test(q! all: hello.tsk .WAIT hello.tsk hello.tsk:; $(info $@) !, '-j10', "hello.tsk\n#MAKE#: Nothing to be done for 'all'.\n"); # Wait between the duplicate command line goals. run_make_test(q! hello.tsk:; $(info $@) !, '-j10 hello.tsk .WAIT hello.tsk', "hello.tsk\n#MAKE#: 'hello.tsk' is up to date.\n#MAKE#: 'hello.tsk' is up to date.\n"); # Ensure .WAIT doesn't wait between all targets run_make_test(q! all : pre1 .WAIT pre2 pre3 pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out start-$@ file TWO wait THREE out end-$@ pre3: ; @#HELPER# -q wait TWO out $@ file THREE # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\nstart-pre2\npre3\nend-pre2\n"); unlink(qw(TWO THREE)); # Ensure .WAIT on the command line doesn't wait between all targets. run_make_test(q! pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out start-$@ file TWO wait THREE out end-$@ pre3: ; @#HELPER# -q wait TWO out $@ file THREE # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 pre1 .WAIT pre2 pre3', "start-pre1\nend-pre1\nstart-pre2\npre3\nend-pre2\n"); unlink(qw(TWO THREE)); # Ensure .WAIT waits for ALL targets on the left before ANY targets on the right run_make_test(q! all : pre1 pre2 .WAIT post1 post2 pre1: ; @#HELPER# -q out start-$@ file PRE1 wait PRE2 sleep 1 out end-$@ pre2: ; @#HELPER# -q wait PRE1 out $@ file PRE2 post1: ; @#HELPER# -q wait POST2 out $@ file POST1 post2: ; @#HELPER# -q file POST2 wait POST1 out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\npre2\nend-pre1\npost1\npost2\n"); unlink(qw(PRE1 PRE2 POST1 POST2)); # Ensure .WAIT on the command line waits for ALL targets on the left before ANY # targets on the right. run_make_test(q! pre1: ; @#HELPER# -q out start-$@ file PRE1 wait PRE2 sleep 1 out end-$@ pre2: ; @#HELPER# -q wait PRE1 out $@ file PRE2 post1: ; @#HELPER# -q wait POST2 out $@ file POST1 post2: ; @#HELPER# -q file POST2 wait POST1 out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 pre1 pre2 .WAIT post1 post2', "start-pre1\npre2\nend-pre1\npost1\npost2\n"); unlink(qw(PRE1 PRE2 POST1 POST2)); # See if .WAIT takes effect between different lists of prereqs # In the current implementation, .WAIT waits only between two prerequisites # in a given target. These same two targets might be run in a different # order if they appear as prerequisites of another target. This is the way # other implementations of .WAIT work. I personally think it's gross and # makes .WAIT just a toy when it comes to ordering, but it's much simpler # to implement than creating an actual edge in the DAG to represent .WAIT # and since that's what users expect, we'll do the same for now. run_make_test(q! all : one two one: pre1 .WAIT pre2 two: pre2 pre1 pre1: ; @#HELPER# -q out start-$@ file PRE1 wait PRE2 out end-$@ pre2: ; @#HELPER# -q wait PRE1 out $@ file PRE2 # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\npre2\nend-pre1\n"); unlink(qw(PRE1 PRE2)); # Check that .WAIT works with pattern rules run_make_test(q! all: pre p% : p%1 .WAIT p%2; pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\npre2\n"); # Check that .WAIT works with secondarily expanded rules run_make_test(q! .SECONDEXPANSION: all: $$(pre) pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ pre3: ; @#HELPER# -q out $@ pre = .WAIT pre1 .WAIT pre2 | .WAIT pre3 # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "start-pre1\nend-pre1\npre2\npre3\n"); # Verify NOTPARALLEL works run_make_test(q! all : pre1 pre2 pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ .NOTPARALLEL: !, '-j10', "start-pre1\nend-pre1\npre2\n"); run_make_test(q! all : p1 .WAIT np1 p1: pre1 pre2 pre1: ; @#HELPER# -q out start-$@ file PRE1 wait PRE2 out end-$@ pre2: ; @#HELPER# -q wait PRE1 out $@ file PRE2 np1: npre1 npre2 npre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ npre2: ; @#HELPER# -q out $@ .NOTPARALLEL: np1 !, '-j10', "start-pre1\npre2\nend-pre1\nstart-npre1\nend-npre1\nnpre2\n"); unlink(qw(PRE1 PRE2)); # Ensure we don't shuffle if .WAIT is set run_make_test(q! all : pre1 .WAIT pre2 pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 --shuffle=reverse', "start-pre1\nend-pre1\npre2\n"); # Ensure we don't shuffle if .WAIT is set on the command line. run_make_test(q! pre1: ; @#HELPER# -q out start-$@ sleep 1 out end-$@ pre2: ; @#HELPER# -q out $@ # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 --shuffle=reverse pre1 .WAIT pre2', "start-pre1\nend-pre1\npre2\n"); # Warn about invalid .WAIT definitions run_make_test(q! .WAIT: foo .WAIT: ; echo oops all:;@: !, '', "#MAKEFILE#:2: .WAIT should not have prerequisites\n#MAKEFILE#:3: .WAIT should not have commands\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # Then run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! all: A B A ::; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B ::; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "A-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); # Subtest 2. # Wait for all double colon targets on the left, before building targets on the # right. run_make_test(q! all: A .WAIT B A ::; @#HELPER# -q out $@-1 out $@-1-done A ::; @#HELPER# -q out $@-2 out $@-2-done A ::; @#HELPER# -q out $@-3 out $@-3-done B ::; @#HELPER# -q out $@-1 out $@-1-done B ::; @#HELPER# -q out $@-2 out $@-2-done B ::; @#HELPER# -q out $@-3 out $@-3-done # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "A-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); # sv 63856. # Wait for all double colon targets on the left, before building targets on the # right. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # Then run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. # The targets are specified on the command line. unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! A ::; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B ::; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 A B', "A-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); # Subtest 2. # sv 63856. # Wait for all double colon targets on the left, before building targets on the # right. The targets are specified on the command line. run_make_test(q! A ::; @#HELPER# -q out $@-1 out $@-1-done A ::; @#HELPER# -q out $@-2 out $@-2-done A ::; @#HELPER# -q out $@-3 out $@-3-done B ::; @#HELPER# -q out $@-1 out $@-1-done B ::; @#HELPER# -q out $@-2 out $@-2-done B ::; @#HELPER# -q out $@-3 out $@-3-done # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 A .WAIT B', "A-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Regular targets which have double colon targets as prerequisites. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # The targets are specified in the makefile. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! all: C .WAIT A B A ::; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B ::; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done C: D E D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: C D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "D\nE\nE-done\nD-done\nA-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Regular targets which have double colon targets as prerequisites. # Subtest 2. # Run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. # The targets are specified in the makefile. # unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! all: C .WAIT A .WAIT B A ::; @#HELPER# -q out $@-1 out $@-1-done A ::; @#HELPER# -q out $@-2 out $@-2-done A ::; @#HELPER# -q out $@-3 out $@-3-done B ::; @#HELPER# -q out $@-1 out $@-1-done B ::; @#HELPER# -q out $@-2 out $@-2-done B ::; @#HELPER# -q out $@-3 out $@-3-done C: D E D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: C D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "D\nE\nE-done\nD-done\nA-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Regular targets which have double colon targets as prerequisites. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # The targets are specified on the command line. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! A ::; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B ::; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done C: D E D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: C D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 C .WAIT A B', "D\nE\nE-done\nD-done\nA-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Regular targets which have double colon targets as prerequisites. # Subtest 2. # Run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. # The targets are specified on the command line. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! A ::; @#HELPER# -q out $@-1 out $@-1-done A ::; @#HELPER# -q out $@-2 out $@-2-done A ::; @#HELPER# -q out $@-3 out $@-3-done B ::; @#HELPER# -q out $@-1 out $@-1-done B ::; @#HELPER# -q out $@-2 out $@-2-done B ::; @#HELPER# -q out $@-3 out $@-3-done C: D E D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: C D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 C .WAIT A .WAIT B', "D\nE\nE-done\nD-done\nA-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); # Wait for all double colon targets on the left, before building targets on the # right. # Double colon targets have reqular targets as prerequisites. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # The targets are specified in the makefile. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! all: A B A :: D; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B :: E; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "D\nE\nE-done\nD-done\nA-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Double colon targets have reqular targets as prerequisites. # Subtest 2. # Run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. # The targets are specified in the makefile. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! all: A .WAIT B A :: D; @#HELPER# -q out $@-1 out $@-1-done A :: ; @#HELPER# -q out $@-2 out $@-2-done A :: ; @#HELPER# -q out $@-3 out $@-3-done B :: E; @#HELPER# -q out $@-1 out $@-1-done B :: ; @#HELPER# -q out $@-2 out $@-2-done B :: ; @#HELPER# -q out $@-3 out $@-3-done D:; @#HELPER# -q out D out D-done E:; @#HELPER# -q out E out E-done .PHONY: D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10', "D\nD-done\nA-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nE\nE-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Double colon targets have reqular targets as prerequisites. # Subtest 1. First run this test without .WAIT and observe and A recipes # interleave with B recipes. # The targets are specified on the command line. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! A :: D; @#HELPER# -q out A-1 file A-1-done wait B-1-done out A-1-done A ::; @#HELPER# -q out A-2 file A-2-done wait B-2-done out A-2-done A ::; @#HELPER# -q out A-3 file A-3-done wait B-3-done out A-3-done B :: E; @#HELPER# -q wait A-1-done out B-1 out B-1-done file B-1-done B ::; @#HELPER# -q wait A-2-done out B-2 out B-2-done file B-2-done B ::; @#HELPER# -q wait A-3-done out B-3 out B-3-done file B-3-done D:; @#HELPER# -q out D file D wait E-done out D-done E:; @#HELPER# -q wait D out E out E-done file E-done .PHONY: D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 A B', "D\nE\nE-done\nD-done\nA-1\nB-1\nB-1-done\nA-1-done\nA-2\nB-2\nB-2-done\nA-2-done\nA-3\nB-3\nB-3-done\nA-3-done\n"); # Wait for all double colon targets on the left, before building targets on the # right. # Double colon targets have reqular targets as prerequisites. # Subtest 2. # Run the same test with .WAIT and observe that all A recipes get started # sequentially before the 1st B recipe gets started and then all B recipes get # started sequentially. # The targets are specified on the command line. unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); run_make_test(q! A :: D; @#HELPER# -q out $@-1 out $@-1-done A :: ; @#HELPER# -q out $@-2 out $@-2-done A :: ; @#HELPER# -q out $@-3 out $@-3-done B :: E; @#HELPER# -q out $@-1 out $@-1-done B :: ; @#HELPER# -q out $@-2 out $@-2-done B :: ; @#HELPER# -q out $@-3 out $@-3-done D:; @#HELPER# -q out D out D-done E:; @#HELPER# -q out E out E-done .PHONY: D E # This is just here so we don't fail with older versions of make .WAIT: !, '-j10 A .WAIT B', "D\nD-done\nA-1\nA-1-done\nA-2\nA-2-done\nA-3\nA-3-done\nE\nE-done\nB-1\nB-1-done\nB-2\nB-2-done\nB-3\nB-3-done\n"); unlink('D', 'D-done', 'E', 'E-done'); unlink('A-1-done', 'A-2-done', 'A-3-done', 'B-1-done', 'B-2-done', 'B-3-done'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/targets/clean ================================================ # -*-perl-*- $description = "The following test creates a makefile to delete a \n" ."file in the directory. It tests to see if make will \n" ."NOT execute the command unless the rule is given in \n" ."the make command line."; $example = "EXAMPLE_FILE"; open(MAKEFILE,"> $makefile"); print MAKEFILE qq! all: ; \@echo This makefile did not clean the dir... good clean: ; $CMD_rmfile $example !; close(MAKEFILE); touch($example); run_make_with_options($makefile,"",&get_logfile,0); $answer = "This makefile did not clean the dir... good\n"; compare_output($answer,&get_logfile(1)) || error("abort"); $answer = "$CMD_rmfile $example\n"; run_make_with_options($makefile,"clean",&get_logfile,0); if (-f $example) { $test_passed = 0; } compare_output($answer,&get_logfile(1)) || error("abort"); 1; ================================================ FILE: tests/scripts/test_template ================================================ # -*-perl-*- $description = ""; $details = ""; # Run a make test. See the documentation of run_make_test() in # run_make_tests.pl, but briefly the first argument is a string with the # contents of a makefile to be tested, the second is a string containing the # arguments to be passed to the make invocation, the third is a string # containing the expected output. The fourth is the expected exit code for # make. If not specified, it's assumed that the make program should succeed # (exit with 0). run_make_test('Your test makefile goes here', 'Arguments to pass to make go here', 'Expected output from the invocation goes here'); # There are various special tokens, options, etc. See the full documentation # in run_make_tests.pl. # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/variables/CURDIR ================================================ # -*-perl-*- $description = "This tests the CURDIR variable."; $details = "Echo CURDIR both with and without -C. Also ensure overrides work."; # TEST #1 # ------- run_make_test(q! all: ; @echo $(CURDIR) !, '', "#PWD#\n"); 1; ================================================ FILE: tests/scripts/variables/DEFAULT_GOAL ================================================ # -*-perl-*- $description = "Test the .DEFAULT_GOAL special variable."; $details = ""; # Test #1: basic logic. # run_make_test(' # Basics. # foo: ; @: ifneq ($(.DEFAULT_GOAL),foo) $(error ) endif # Reset to empty. # .DEFAULT_GOAL := bar: ; @: ifneq ($(.DEFAULT_GOAL),bar) $(error ) endif # Change to a different goal. # .DEFAULT_GOAL := baz baz: ; @echo $@ ', '', 'baz'); # Test #2: unknown goal. # run_make_test(' .DEFAULT_GOAL = foo ', '', "#MAKE#: *** No rule to make target 'foo'. Stop.", 512); # Test #3: more than one goal. # run_make_test(' .DEFAULT_GOAL := foo bar ', '', '#MAKE#: *** .DEFAULT_GOAL contains more than one target. Stop.', 512); # Test #4: Savannah bug #12226. # run_make_test(' define rule foo: ; @echo $$@ endef define make-rule $(eval $(rule)) endef $(call make-rule) ', '', 'foo'); # TEST #5: .DEFAULT_GOAL containing just whitespace (Savannah bug #25697) run_make_test(' N = .DEFAULT_GOAL = $N $N # Just whitespace foo: ; @echo "boo" ', '', "#MAKE#: *** No targets. Stop.\n", 512); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/variables/EXTRA_PREREQS ================================================ # -*-perl-*- $description = "Test the .EXTRA_PREREQS special variable."; $details = ""; # Simple global .EXTRA_PREREQS and automatic variable settings run_make_test(' .EXTRA_PREREQS = tick tack .PHONY: all all: ; @echo ${.EXTRA_PREREQS}/$@/$ $@ !, "", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n"); unlink('x.mk'); # Ensure that we don't add GNUMAKEFLAGS to the environment if it's not there run_make_test(q! all: ; @#HELPER# env GNUMAKEFLAGS !, '', 'GNUMAKEFLAGS='); $ENV{GNUMAKEFLAGS} = '-Itst/bad'; run_make_test(q! all: ; @#HELPER# env GNUMAKEFLAGS !, '', 'GNUMAKEFLAGS='); 1; ================================================ FILE: tests/scripts/variables/INCLUDE_DIRS ================================================ # -*-perl-*- $description = "Test the .INCLUDE_DIRS special variable."; $details = ""; use Cwd; $dir = cwd; $dir =~ s,.*/([^/]+)$,../$1,; if (-d '/usr/include') { # Test #1: The content of .INCLUDE_DIRS depends on the platform for which # make was built. What we know for sure is that it shouldn't be # empty. # run_make_test(' ifeq ($(.INCLUDE_DIRS),) $(warning .INCLUDE_DIRS is empty) endif .PHONY: all all:;@: ', '', ''); } # Test #2: Make sure -I paths end up in .INCLUDE_DIRS. # run_make_test(' ifeq ($(dir),) $(warning dir is empty) endif ifeq ($(filter $(dir),$(.INCLUDE_DIRS)),) $(warning .INCLUDE_DIRS does not contain $(dir): $(.INCLUDE_DIRS)) endif .PHONY: all all:;@: ', "-I$dir dir=$dir", ''); # Find the default .INCLUDE_DIRS create_file('defaultdirs.mk', "\$(info \$(.INCLUDE_DIRS))\nall:;\@:\n"); my $cmd = subst_make_string("#MAKEPATH# -f defaultdirs.mk"); my @dirs = `$cmd`; my $dirs = $dirs[0]; $dirs =~ s/\r?\n//g; unlink('defaultdirs.mk'); run_make_test(" ifneq (\$(.INCLUDE_DIRS),$dirs) \$(warning Mismatched \$(.INCLUDE_DIRS) != $dirs) endif all:;\@: ", '', ''); # Verify that -I- disables content from .INCLUDE_DIRS run_make_test(q/ ifneq ($(.INCLUDE_DIRS),) $(warning Mismatched $(.INCLUDE_DIRS) != ) endif all:;@: /, '-I-', ''); # Prefix -I dirs to the front mkdir('somedir', 0777); my $xdirs = $dirs ? " $dirs" : ''; run_make_test(" ifneq (\$(.INCLUDE_DIRS),somedir$xdirs) \$(warning Mismatched '\$(.INCLUDE_DIRS)' != 'somedir$xdirs') endif all:;\@: ", '-I somedir', ''); # Verify .INCLUDE_DIRS contains files after -I- run_make_test(q/ ifneq ($(.INCLUDE_DIRS),somedir) $(warning Mismatched $(.INCLUDE_DIRS) != somedir) endif all:;@: /, '-I - -I somedir', ''); rmdir('somedir'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/variables/LIBPATTERNS ================================================ # -*-perl-*- $description = "Test .LIBPATTERNS special variable."; $details = ""; # TEST 0: basics touch('mtest_foo.a'); run_make_test(' .LIBPATTERNS = mtest_%.a all: -lfoo ; @echo "build $@ from $<" ', '', "build all from mtest_foo.a\n"); # TEST 1: Handle elements that are not patterns. run_make_test(' .LIBPATTERNS = mtest_foo.a mtest_%.a all: -lfoo ; @echo "build $@ from $<" ', '', "#MAKE#: .LIBPATTERNS element 'mtest_foo.a' is not a pattern build all from mtest_foo.a\n"); # TEST 2: target-specific override # Uncomment this when we add support, see Savannah bug #25703 # run_make_test(' # .LIBPATTERNS = mbad_%.a # all: .LIBPATTERNS += mtest_%.a # all: -lfoo ; @echo "build $@ from $<" # ', # '', "build all from mtest_foo.a\n"); unlink('mtest_foo.a'); 1; ================================================ FILE: tests/scripts/variables/MAKE ================================================ # -*-perl-*- $description = "Test proper behavior of the MAKE variable"; $details = "DETAILS"; run_make_test(q! TMP := $(MAKE) MAKE := $(subst X=$(X),,$(MAKE)) all: @echo $(TMP) $(MAKE) -f #MAKEFILE# foo foo: @echo $(MAKE) !, '', "#MAKEPATH#\n#MAKEPATH# -f #MAKEFILE# foo\n" . "#MAKE#[1]: Entering directory '#PWD#'\n" . "#MAKEPATH#\n#MAKE#[1]: Leaving directory '#PWD#'\n"); rmfiles("foo"); 1; ================================================ FILE: tests/scripts/variables/MAKECMDGOALS ================================================ # -*-perl-*- $description = "Test the MAKECMDGOALS variable."; $details = "\ We construct a makefile with various targets, all of which print out \$(MAKECMDGOALS), then call it different ways."; open(MAKEFILE,"> $makefile"); print MAKEFILE "\ .DEFAULT all: \@echo \$(MAKECMDGOALS) "; close(MAKEFILE); # TEST #1 &run_make_with_options($makefile, "", &get_logfile, 0); $answer = "\n"; &compare_output($answer,&get_logfile(1)); # TEST #2 &run_make_with_options($makefile, "all", &get_logfile, 0); $answer = "all\n"; &compare_output($answer,&get_logfile(1)); # TEST #3 &run_make_with_options($makefile, "foo bar baz yaz", &get_logfile, 0); $answer = "foo bar baz yaz\nfoo bar baz yaz\nfoo bar baz yaz\nfoo bar baz yaz\n"; &compare_output($answer,&get_logfile(1)); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/variables/MAKEFILES ================================================ # -*-perl-*- $description = "Test the MAKEFILES variable."; $makefile2 = &get_tmpfile; $makefile3 = &get_tmpfile; open(MAKEFILE,"> $makefile2"); print MAKEFILE < $makefile3"); print MAKEFILE < all: > @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' > @MSG=Works $(MAKE) -e -f #MAKEFILE# jump jump: > @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' > @$(MAKE) -f #MAKEFILE# print print: > @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' .PHONY: all jump print !, '--no-print-directory', 'all: MAKEFLAGS= --no-print-directory jump Works: MAKEFLAGS=e --no-print-directory print Works: MAKEFLAGS=e --no-print-directory'); # Ensure MAKEFLAGS updates are handled immediately rather than later mkdir('foo', 0777); mkdir('bar', 0777); run_make_test(q! $(info MAKEFLAGS=$(MAKEFLAGS)) $(info INCLUDE_DIRS=$(.INCLUDE_DIRS)) MAKEFLAGS += -Ibar $(info MAKEFLAGS=$(MAKEFLAGS)) $(info INCLUDE_DIRS=$(.INCLUDE_DIRS)) .PHONY: all all: ; @echo 'MAKEFLAGS=$(MAKEFLAGS)' "\$$MAKEFLAGS=$$MAKEFLAGS" !, '-I- -Ifoo', 'MAKEFLAGS= -I- -Ifoo INCLUDE_DIRS=foo MAKEFLAGS= -I- -Ifoo -Ibar INCLUDE_DIRS=foo bar MAKEFLAGS= -I- -Ifoo -Ibar $MAKEFLAGS= -I- -Ifoo -Ibar'); rmdir('foo'); rmdir('bar'); # Test that command line switches are all present in MAKEFLAGS. # sv 62514. my @opts; my @flavors; # Simple flags. @opts = ('i', 'k', 'n', 'q', 'r', 's', 'w', 'd'); exists $FEATURES{'check-symlink'} and push @opts, 'L'; @flavors = ('=', ':=', ':::=', '+=-'); for my $fl (@flavors) { for my $opt (@opts) { run_make_test(" MAKEFLAGS${fl}B all:; \$(info makeflags='\$(MAKEFLAGS)') ", "-$opt", "/makeflags='B$opt'/"); } } # Strawberry Perl's exec()--or something!--appears to replace all /tmp with the # user's %TEMP% value so we can't use that for -I testing. Make a directory. mkdir('localtmp', 0777); # Switches which carry arguments. @opts = (' -Ilocaltmp', ' -Onone', ' --debug=b', ' -l2.5'); for my $fl (@flavors) { for my $opt (@opts) { run_make_test(" MAKEFLAGS${fl}B all:; \$(info makeflags='\$(MAKEFLAGS)') ", "$opt", "/makeflags='B$opt'/"); } } # Long options which take no arguments. # sv 62514. @opts = (' --no-print-directory', ' --warn=undefined-var', ' --trace'); for my $fl (@flavors) { for my $opt (@opts) { run_make_test(" MAKEFLAGS${fl}B all:; \$(info makeflags='\$(MAKEFLAGS)') ", "$opt", "/makeflags='B$opt'/"); } } # Test that make filters out duplicates. # Each option is specified in the makefile, env and on the command line. @opts = (' -Ilocaltmp', ' -Onone', ' --debug=b', ' -l2.5'); for my $fl (@flavors) { for my $opt (@opts) { $ENV{'MAKEFLAGS'} = $opt; run_make_test(" MAKEFLAGS${fl}B $opt all:; \$(info makeflags='\$(MAKEFLAGS)') ", "$opt", "/makeflags='B$opt'/"); } } # Test that make filters out duplicates. # Each option is specified in the makefile, env and on the command line. # decode_switches reallocates when the number of parameters in sl->list exceeds 5. # This test exercises the realloc branch. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2'; run_make_test(" MAKEFLAGS${fl}B -I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2 all:; \$(info makeflags='\$(MAKEFLAGS)') ", '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6', "/makeflags='B -I1 -I2 -I3 -I4 -I5 -I6 -l2.5 -Onone --debug=b'/"); } # A mix of multiple flags from env, the makefile and command line. # Skip -L since it's not available everywhere for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn=undefined-var --trace'; run_make_test(" MAKEFLAGS${fl}iknqrswd -Ilocaltmp -Ilocaltmp -Onone -Onone -l2.5 -l2.5 all:; \$(info makeflags='\$(MAKEFLAGS)') ", '-Onone -l2.5 -l2.5 -Onone -Ilocaltmp -iknqrswd -i -n -s -k -Ilocaltmp', "/makeflags='Bdiknqrsw -Ilocaltmp -l2.5 -Onone --trace --warn=undefined-var'/"); } # Verify MAKEFLAGS are all available to shell function at parse time. for my $fl (@flavors) { my $answer = 'Biknqrs -Ilocaltmp -l2.5 -Onone --no-print-directory --warn=undefined-var'; $ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn=undefined-var'; run_make_test(" MAKEFLAGS${fl}iknqrsw -Ilocaltmp -Ilocaltmp -Onone -Onone -l2.5 -l2.5 --no-print-directory \$(info at parse time '\$(MAKEFLAGS)') XX := \$(shell echo \"\$\$MAKEFLAGS\") all:; \$(info at build time makeflags='\$(XX)') ", '-Onone -l2.5 -l2.5 -Onone -Ilocaltmp -iknqrs -i -n -s -k -Ilocaltmp', "at parse time '$answer' at build time makeflags='$answer'"); } # Verify MAKEFLAGS and command line definitions are all available to shell function at parse time. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn=undefined-var'; my $answer = 'Biknqrs -Ilocaltmp -l2.5 -Onone --no-print-directory --warn=undefined-var -- hello=world'; run_make_test(" MAKEFLAGS${fl}iknqrsw -Ilocaltmp -Ilocaltmp -Onone -Onone -l2.5 -l2.5 --no-print-directory \$(info at parse time '\$(MAKEFLAGS)') XX := \$(shell echo \"\$\$MAKEFLAGS\") all:; \$(info at build time makeflags='\$(XX)') ", '-Onone -l2.5 -l2.5 -Onone -Ilocaltmp -iknqrs -i -n -s -k -Ilocaltmp hello=world', "at parse time '$answer' at build time makeflags='$answer'"); } # Verify that command line arguments are included in MAKEFLAGS run_make_test(q! all: ; @echo $(MAKEFLAGS) !, '-e FOO=bar -r -R', 'erR -- FOO=bar'); # Long arguments mean everything is prefixed with "-" run_make_test(q! all: ; @echo /$(MAKEFLAGS)/ !, '--no-print-directory -e -r -R --trace FOO=bar', "#MAKEFILE#:2: update target 'all' due to: target does not exist echo /erR --trace --no-print-directory -- FOO=bar/ /erR --trace --no-print-directory -- FOO=bar/"); # sv 63347. # Verify that command line arguments are included in MAKEFLAGS # when makefiles are parsed. my $answer = 'erR -- hello:=world FOO=bar'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-e FOO=bar -r -R hello:=world', "$answer $answer #MAKE#: 'all' is up to date.\n"); # sv 63347. # Same as above, with makefile setting the value of the same variables as # defined on the cli. $answer = 'erR -- hello:=world FOO=bar'; run_make_test(q! $(info $(MAKEFLAGS)) FOO=moon hello:=moon $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-e FOO=bar -r -R hello:=world', "$answer $answer $answer #MAKE#: 'all' is up to date.\n"); # sv 63347. # Same as above, with makefile overriding the value of cli definition. $answer = 'erR -- hello:=world FOO=bar'; run_make_test(q! $(info $(MAKEFLAGS)) override FOO=moon override hello:=moon export hello $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-e FOO=bar -r -R hello:=world', "$answer $answer $answer #MAKE#: 'all' is up to date.\n"); # Same as above, and makefile overrides the value of cli definition. # resets MAKEOVERRIDES. $answer = 'rR -- hello:=world FOO=bar'; run_make_test(q! $(info $(MAKEFLAGS)) override FOO=moon override hello:=moon export hello $(info $(MAKEFLAGS)) MAKEOVERRIDES= $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, 'FOO=bar -r -R hello:=world', "$answer $answer rR -- \nrR #MAKE#: 'all' is up to date.\n"); # sv 63347. # MAKEFLAGS set is env and makefile sets MAKEFLAGS and there is a command # line definition. $answer = ' -- bye=moon hello=world'; $ENV{'MAKEFLAGS'} = 'hello=world'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, 'bye=moon', " -- bye=moon hello=world -- bye=moon hello=world #MAKE#: 'all' is up to date.\n"); # sv 63347. # Conditional assignment and MAKEFLAGS. $answer = 'B -- bye=moon hello=world'; $ENV{'MAKEFLAGS'} = 'hello=world'; run_make_test(q! $(info $(MAKEFLAGS)) MAKEFLAGS?=-k $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-B bye=moon', "$answer $answer $answer #MAKE#: 'all' is up to date.\n"); # sv 63347. # MAKEFLAGS set is env and makefile sets MAKEFLAGS and there is a command # line definition. for my $fl (@flavors) { my $answer = ' -- bye=moon hello=world'; $ENV{'MAKEFLAGS'} = 'hello=world'; run_make_test(" \$(info \$(MAKEFLAGS)) MAKEFLAGS${fl}R \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", 'bye=moon', "$answer rR$answer rR$answer #MAKE#: 'all' is up to date.\n"); } # sv 63347. # Test changes introduced by makefiles to MAKEFLAGS. for my $fl (@flavors) { my $answer = 'rR --no-print-directory -- hello:=world FOO=bar'; run_make_test(q! MAKEFLAGS+=--no-print-directory $(info $(MAKEFLAGS)) MAKEFLAGS+=-k $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, 'FOO=bar -r -R hello:=world', "$answer k$answer k$answer #MAKE#: 'all' is up to date.\n"); } # sv 63347. # Test changes introduced by makefiles to MAKEFLAGS. # Same as above, but with -e. for my $fl (@flavors) { my $answer = 'erR -- hello:=world FOO=bar'; run_make_test(q! MAKEFLAGS+=--no-print-directory $(info $(MAKEFLAGS)) MAKEFLAGS+=-k $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-e FOO=bar -r -R hello:=world', "$answer $answer $answer #MAKE#: 'all' is up to date.\n"); } mkdir('bye', 0777); create_file('bye/makefile', 'hello=moon all:; $(info $(hello))'); # sv 63347. # Test that a cli definition takes precedence over a definition set in # submake. run_make_test(q! v:=$(shell $(MAKE) -C bye --no-print-directory) all: ; $(info $(v)) !, 'hello=world', "world #MAKE#[1]: 'all' is up to date.\n#MAKE#: 'all' is up to date."); # Same as above with the shell assignment operator. run_make_test(q! v \!= $(MAKE) -C bye --no-print-directory all: ; $(info $(v)) !, 'hello=world', "world #MAKE#[1]: 'all' is up to date.\n#MAKE#: 'all' is up to date."); unlink('bye/makefile'); rmdir('bye'); # sv 63347 # Invalid command line variable definition. run_make_test(q! all:; $(info $(hello)) !, 'hello=\'$(world\'', "#MAKEFILE#:2: *** unterminated variable reference. Stop.\n", 512); # sv 63347 # An unused invalid command line variable definition is ignored. run_make_test(q! all:; $(info good) !, 'hello=\'$(world\'', "good\n#MAKE#: 'all' is up to date.\n"); # sv 63537 # Certain switches can be flipped on and off. # -k/-S, -w/--no-print-directory and -s/--no-silent. # Test the following aspects of behavior of these switches # 1. A switch can be enabled or disabled in makefile. # 2. A switch can be enabled or disabled in env. # 3. A switch can be enabled or disabled on the command line. # 4. Command line beats makefile. # 5. Env beats makefile. # 6. Command line beats env. # 7. MAKEFLAGS contains each specified switch at parse and build time. # 8. If contradicting switches are specified in multiple origins, MAKEFLAGS # contains the winning switch at parse and build time. # 9. MAKEFLAGS does not contain the beaten switch. @flavors = ('=', ':=', ':::=', '+='); # sv 63537 # -w vs --no-print-directory # -w on the command line. run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-w', "#MAKE#: Entering directory '#PWD#' w w #MAKE#: 'all' is up to date. #MAKE#: Leaving directory '#PWD#'\n"); # -w in the env. $ENV{'MAKEFLAGS'} = '-w'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '', "#MAKE#: Entering directory '#PWD#' w w #MAKE#: 'all' is up to date. #MAKE#: Leaving directory '#PWD#'\n"); # -w in env, --no-print-directory on the command line. $ENV{'MAKEFLAGS'} = '-w'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '--no-print-directory', " --no-print-directory --no-print-directory #MAKE#: 'all' is up to date.\n"); # --no-print-directory in env, -w on the command line. $ENV{'MAKEFLAGS'} = '--no-print-directory'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-w', "#MAKE#: Entering directory '#PWD#' w w #MAKE#: 'all' is up to date. #MAKE#: Leaving directory '#PWD#'\n"); delete $ENV{'MAKEFLAGS'}; # -w in makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-w \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '', "#MAKE#: Entering directory '#PWD#' w w #MAKE#: 'all' is up to date. #MAKE#: Leaving directory '#PWD#'\n"); } # sv 63537 # -w in makefile, --no-print-directory on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-w \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '--no-print-directory', " --no-print-directory --no-print-directory #MAKE#: 'all' is up to date.\n"); } mkdir('lib2', 0777); create_file('lib2/makefile', 'all:; $(info $(MAKEFLAGS))'); # sv 63537 # Default, no -w or --no-print-directory is specified. run_make_test(q! all:; $(MAKE) -C lib2 !, '', "#MAKEPATH# -C lib2 #MAKE#[1]: Entering directory '#PWD#/lib2' #MAKE#[1]: 'all' is up to date. #MAKE#[1]: Leaving directory '#PWD#/lib2'\n"); # sv 63537 # --no-print-directory in makefile, -w on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--no-print-directory \$(info \$(MAKEFLAGS)) all: \t \$(info \$(MAKEFLAGS)) \t \$(MAKE) -C lib2 ", '-w', "#MAKE#: Entering directory '#PWD#' w w #MAKEPATH# -C lib2 #MAKE#[1]: Entering directory '#PWD#/lib2' w #MAKE#[1]: 'all' is up to date. #MAKE#[1]: Leaving directory '#PWD#/lib2' #MAKE#: Leaving directory '#PWD#'\n"); } # sv 63537 # --no-print-directory in makefile, -w in the env. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '-w'; run_make_test(" MAKEFLAGS${fl}--no-print-directory \$(info \$(MAKEFLAGS)) all: \t \$(info \$(MAKEFLAGS)) \t \$(MAKE) -C lib2 ", '', "#MAKE#: Entering directory '#PWD#' w w #MAKEPATH# -C lib2 #MAKE#[1]: Entering directory '#PWD#/lib2' w #MAKE#[1]: 'all' is up to date. #MAKE#[1]: Leaving directory '#PWD#/lib2' #MAKE#: Leaving directory '#PWD#'\n"); } unlink('lib2/makefile'); rmdir('lib2'); # sv 63537 # -k vs -S. # -S in env. $ENV{'MAKEFLAGS'} = '-S'; run_make_test(q! .RECIPEPREFIX := > $(info $(MAKEFLAGS)) all: one two one: > $(info $(MAKEFLAGS)) > #HELPER# -q fail 1 two:; $(info $@) !, '', "S S #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); # -S in env, -k on the command line. $ENV{'MAKEFLAGS'} = '-S'; run_make_test(q! .RECIPEPREFIX := > $(info $(MAKEFLAGS)) all: one two one: > $(info $(MAKEFLAGS)) > #HELPER# -q fail 1 two:; $(info $@) !, '-k', "k k #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); # -k in env. $ENV{'MAKEFLAGS'} = '-k'; run_make_test(q! .RECIPEPREFIX := > $(info $(MAKEFLAGS)) all: one two one: > $(info $(MAKEFLAGS)) > #HELPER# -q fail 1 two:; $(info $@) !, '', "k k #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); # -k in env, -S on the command line. $ENV{'MAKEFLAGS'} = '-k'; run_make_test(q! .RECIPEPREFIX := > $(info $(MAKEFLAGS)) all: one two one: > $(info $(MAKEFLAGS)) > #HELPER# -q fail 1 two:; $(info $@) !, '-S', "S S #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); delete $ENV{'MAKEFLAGS'}; # -k in makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-k \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '', "k k #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); } # sv 63537 # -k in makefile and -S on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-k \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '-S', "S S #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } # sv 63537 # -k in makefile and -S in the env. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '-S'; run_make_test(" MAKEFLAGS${fl}-k \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '', "S S #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } delete $ENV{'MAKEFLAGS'}; # sv 63537 # -S in makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-S \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '', "S S #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } # -S in makefile and -k on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-S \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '-k', "k k #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); } # sv 63537 # -S in makefile and -k in the env. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '-k'; run_make_test(" MAKEFLAGS${fl}-S \$(info \$(MAKEFLAGS)) all: one two one: \t \$(info \$(MAKEFLAGS)) \t #HELPER# -q fail 1 two:; \$(info \$@) ", '', "k k #HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); } # sv 63537 # -s vs --no-silent. # -s in env. $ENV{'MAKEFLAGS'} = '-s'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '', "s\ns"); # -s in env, --no-silent on the command line. $ENV{'MAKEFLAGS'} = '-s'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '--no-silent', " --no-silent --no-silent #MAKE#: 'all' is up to date.\n"); # --no-silent in env. $ENV{'MAKEFLAGS'} = '--no-silent'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '', " --no-silent --no-silent #MAKE#: 'all' is up to date.\n"); # --no-silent in env, -s on the command line. $ENV{'MAKEFLAGS'} = '--no-silent'; run_make_test(q! $(info $(MAKEFLAGS)) all:; $(info $(MAKEFLAGS)) !, '-s', "s\ns"); delete $ENV{'MAKEFLAGS'}; # -s in the makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-s \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '', "s\ns"); } # sv 63537 # -s in makefile and --no-silent on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}-s \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '--no-silent', " --no-silent --no-silent #MAKE#: 'all' is up to date.\n"); } # sv 63537 # -s in makefile and --no-silent in the env. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '--no-silent'; run_make_test(" MAKEFLAGS${fl}-s \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '', " --no-silent --no-silent #MAKE#: 'all' is up to date.\n"); } delete $ENV{'MAKEFLAGS'}; # sv 63537 # --no-silent in makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--no-silent \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '', " --no-silent --no-silent #MAKE#: 'all' is up to date.\n"); } # sv 63537 # --no-silent in makefile and -s on the command line. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--no-silent \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '-s', "s\ns"); } # sv 63537 # --no-silent in makefile and -s in the env. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '-s'; run_make_test(" MAKEFLAGS${fl}--no-silent \$(info \$(MAKEFLAGS)) all:; \$(info \$(MAKEFLAGS)) ", '', "s\ns"); } delete $ENV{'MAKEFLAGS'}; # sv 63537 # Multiple --debug switches from various origins are all combined. # Because run_make_test regex matching facility does not allow to match against # multiple lines, run the test twice. During the first run match the output of # --debug=b, during the second run match the output of --debug=-j. # # --debug=b in makefile. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--debug=b hello:; touch \$@ .PHONY: hello ", '', "/Updating makefiles/"); } # --debug=b in makefile, --debug=j on the command line. # Test for --debug=j output. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--debug=b hello:; touch \$@ .PHONY: hello ", '--debug=j', "/Putting child/"); } # --debug=b in makefile, --debug=j on the command line. # Test for --debug=b output. for my $fl (@flavors) { run_make_test(" MAKEFLAGS${fl}--debug=b hello:; touch \$@ .PHONY: hello ", '--debug=j', "/Updating makefiles/"); } # --debug=j in makefile, --debug=b on the command line. # Test that MAKEFLAGS contains --debug=b. run_make_test(q! MAKEFLAGS=--debug=j $(info makeflags=$(MAKEFLAGS)) hello:; touch $@ .PHONY: hello !, '--debug=b', "/makeflags= --debug=b/"); # --debug=b in makefile, --debug=j in the env. # Test for --debug=j output. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '--debug=j'; run_make_test(" MAKEFLAGS${fl}--debug=b hello:; touch \$@ .PHONY: hello ", '', "/Putting child/"); } # --debug=b in makefile, --debug=j in the env. # Test for --debug=b output. for my $fl (@flavors) { $ENV{'MAKEFLAGS'} = '--debug=j'; run_make_test(" MAKEFLAGS${fl}--debug=b hello:; touch \$@ .PHONY: hello ", '', "/Updating makefiles/"); } unlink('hello'); rmdir('localtmp'); # sv 66037. An infinite loop when MAKEFLAGS is specified on the command line. my @cli= ('-r MAKEFLAGS=-k hello=world', '-r MAKEFLAGS=-k hello=world MAKEFLAGS=-R', '-r MAKEFLAGS="-R -- hello=world MAKEFLAGS=-k"'); for my $c (@cli) { run_make_test(q! $(info hello=$(hello)) all:; !, $c, "hello=world\n#MAKE#: 'all' is up to date.\n"); } run_make_test(q! $(info hello=$(hello)) all:; !, '-r MAKEFLAGS="-R -- hello=world MAKEFLAGS=hello=bye"', "hello=bye\n#MAKE#: 'all' is up to date.\n"); run_make_test(q! $(info hello=$(hello)) all:; !, '-r MAKEFLAGS="-R -- hello=world MAKEFLAGS=-s"', "hello=world\n"); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/scripts/variables/MAKELEVEL ================================================ # -*-perl-*- $description = "The following test creates a makefile to test makelevels in Make. It prints \$(MAKELEVEL) and then prints the environment variable MAKELEVEL"; open(MAKEFILE,"> $makefile"); # The Contents of the MAKEFILE ... print MAKEFILE < $@ bar.x: ; @touch $@ ', '', 'MAKE_RESTARTS= MAKE_RESTARTS=1 MAKE_RESTARTS=2'); rmfiles('foo.x', 'bar.x'); # Test multiple restarts and make sure the variable is cleaned up run_make_test(' .RECIPEPREFIX = > recurse: > @echo recurse MAKE_RESTARTS=$$MAKE_RESTARTS > @$(MAKE) -f #MAKEFILE# all all: ; @echo all MAKE_RESTARTS=$$MAKE_RESTARTS $(info MAKE_RESTARTS=$(MAKE_RESTARTS)) include foo.x foo.x: ; @echo "include bar.x" > $@ bar.x: ; @touch $@ ', '', "MAKE_RESTARTS= MAKE_RESTARTS=1 MAKE_RESTARTS=2 recurse MAKE_RESTARTS= #MAKE#[1]: Entering directory '#PWD#' MAKE_RESTARTS= all MAKE_RESTARTS= #MAKE#[1]: Leaving directory '#PWD#'"); rmfiles('foo.x', 'bar.x'); 1; ================================================ FILE: tests/scripts/variables/MFILE_LIST ================================================ # -*-perl-*- $description = "Test the MAKEFILE_LIST variable."; create_file('incl2', "m2 := \$(MAKEFILE_LIST)\n"); run_make_test(qq! m1 := \$(MAKEFILE_LIST) include incl2 m3 := \$(MAKEFILE_LIST) all: \t\@echo \$(m1) \t\@echo \$(m2) \t\@echo \$(m3) !, '', "#MAKEFILE#\n#MAKEFILE# incl2\n#MAKEFILE# incl2\n"); unlink('incl2'); # SV 50823 -- makefiles containing '$' chars create_file('foo$bar', "m2 := \$(MAKEFILE_LIST)\n"); run_make_test(qq! m1 := \$(MAKEFILE_LIST) include foo\$\$bar m3 := \$(MAKEFILE_LIST) all: \t\@echo '\$(m1)' \t\@echo '\$(m2)' \t\@echo '\$(m3)' \t\@echo '\$(value MAKEFILE_LIST)' !, '', "#MAKEFILE#\n#MAKEFILE# foo\$bar\n#MAKEFILE# foo\$bar\n#MAKEFILE# foo\$bar\n"); unlink('foo$bar'); 1; ================================================ FILE: tests/scripts/variables/SHELL ================================================ # -*-perl-*- $description = "Test proper handling of SHELL."; # If we don't have a POSIX shell available, never mind $is_posix_sh or return -1; # On Windows, shell names might not match if ($port_type eq 'W32') { return -1; } $mshell = $sh_name; # According to POSIX, the value of SHELL in the environment has no impact on # the value in the makefile. $ENV{SHELL} = '/dev/null'; run_make_test('all:;@echo "$(SHELL)"', '', $mshell); # According to POSIX, any value of SHELL set in the makefile should not be # exported to the subshell. A more portable option might be to set SHELL to # be $^X (perl) in the makefile, and set .SHELLFLAGS to -e. $ENV{SHELL} = $mshell; my $altshell = "/./$mshell"; my $altshell2 = "/././$mshell"; if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) { $altshell = "$1$2.$2$3"; $altshell2 = "$1$2.$2.$2$3"; } run_make_test("SHELL := $altshell\n".' all:;@echo "$(SHELL) $$SHELL" ', '', "$altshell $mshell"); # As a GNU Make extension, if make's SHELL variable is explicitly exported, # then we really _DO_ export it. $ENV{SHELL} = $mshell; run_make_test("export SHELL := $altshell\n".' all:;@echo "$(SHELL) $$SHELL" ', '', "$altshell $altshell"); # Test out setting of SHELL, both exported and not, as a target-specific # variable. $ENV{SHELL} = $mshell; run_make_test("all: SHELL := $altshell\n".' all:;@echo "$(SHELL) $$SHELL" ', '', "$altshell $mshell"); $ENV{SHELL} = $mshell; run_make_test(" SHELL := $altshell2 one: two two: export SHELL := $altshell\n".' one two:;@echo "$@: $(SHELL) $$SHELL" ', '', "two: $altshell $altshell\none: $altshell2 $mshell\n"); # Test .SHELLFLAGS # We don't know the output here: on some systems, for example, every line # printed by the shell in -x mode has a trailing space! my $script = 'true; true'; my $flags = '-xc'; my $out = `$sh_name $flags '$script' 2>&1`; run_make_test(qq! .SHELLFLAGS = $flags all: ; \@$script !, '', $out); # Do it again but add spaces to SHELLFLAGS # Some shells (*shakes fist at Solaris*) cannot handle multiple flags in # separate arguments. my $t = `$sh_name -e -c true 2>/dev/null`; my $multi_ok = $? == 0; if ($multi_ok) { $flags = '-x -c'; run_make_test(qq! .SHELLFLAGS = $flags all: ; \@$script !, '', $out); } $script = subst_make_string('true; #HELPER# -q fail 1; true'); $flags = '-xec'; $out = `$sh_name $flags '$script' 2>&1`; run_make_test(qq! .SHELLFLAGS = $flags all: ; \@$script !, '', "${out}#MAKE#: *** [#MAKEFILE#:3: all] Error 1", 512); 1; ================================================ FILE: tests/scripts/variables/WARNINGS ================================================ # -*-perl-*- $description = "Test the .WARNINGS variable."; my %warn_test = ( 'warn' => 'warn', 'error warn' => 'warn', 'error' => 'error', 'ignore error ignore invalid-var,invalid-ref,undefined-var' => 'ignore,invalid-var,invalid-ref,undefined-var', 'invalid-ref:ignore error invalid-var:warn,,,,,undefined-var:error,,,,,' => '=error,invalid-var,invalid-ref:ignore,undefined-var:error' ); # Verify that values set in .WARNINGS don't get passed to sub-makes while (my ($f, $r) = each %warn_test) { run_make_test(qq! .WARNINGS = error \$(info MF=\$(MAKEFLAGS)) all:; \@#HELPER# env MAKEFLAGS !, '', "MF=\nMAKEFLAGS="); } # Verify that make's special variables don't warn even if they're not set run_make_test(q! .WARNINGS = undefined-var vars := $(.VARIABLES) $(MAKECMDGOALS) $(MAKE_RESTARTS) $(CURDIR) vars += $(GNUMAKEFLAGS) $(MAKEFLAGS) $(MFLAGS) $(MAKE_COMMAND) $(MAKE) vars += $(MAKEFILE_LIST) $(MAKEOVERRIDES) $(-*-command-variables-*-) vars += $(.RECIPEPREFIX) $(.LOADED) $(.FEATURES) vars += $(SHELL) $(.SHELLFLAGS) $(MAKE_TERMOUT) $(MAKE_TERMERR) vars += $(.DEFAULT) $(.DEFAULT_GOAL) $(-*-eval-flags-*-) $(SUFFIXES) vars += $(VPATH) $(GPATH) all:; !, '', "#MAKE#: 'all' is up to date."); # sv 63609. # Test for buffer overrun in warn_undefined. run_make_test(q! .WARNINGS = undefined-var all:; X := $(averyveryveryloooooooooooooooooooooooooooongvariablename) !, '', "#MAKEFILE#:4: warning: reference to undefined variable 'averyveryveryloooooooooooooooooooooooooooongvariablename' #MAKE#: 'all' is up to date.\n" ); # Check undefined variable warnings # With no options or with ignore, nothing should happen run_make_test(' .WARNINGS := $(warnval) EMPTY = EREF = $(EMPTY) UREF = $(UNDEFINED) SEREF := $(EREF) SUREF := $(UREF) all: ; @echo ref $(EREF) $(UREF)', '', 'ref'); run_make_test(undef, 'warnval=undefined-var:ignore', 'ref'); # Check warnings run_make_test(undef, 'warnval=undefined-var', "#MAKEFILE#:8: warning: reference to undefined variable 'UNDEFINED' #MAKEFILE#:10: warning: reference to undefined variable 'UNDEFINED' ref"); # Check and errors run_make_test(undef, 'warnval=undefined-var:error', "#MAKEFILE#:8: *** reference to undefined variable 'UNDEFINED'. Stop.", 512); # Check invalid variable reference warnings # With no options we still check for invalid references run_make_test(' .WARNINGS = $(warnval) IREF = $(bad variable) SIREF := $(IREF) define nl endef all: ; @echo ref $(also$(nl)bad) $(IREF) $(SIREF)', '', "#MAKEFILE#:3: warning: invalid variable reference 'bad variable' #MAKEFILE#:11: warning: invalid variable reference 'also\nbad' #MAKEFILE#:3: warning: invalid variable reference 'bad variable' ref"); run_make_test(undef, 'warnval=ignore', 'ref'); run_make_test(undef, 'warnval=invalid-ref:ignore', 'ref'); # Check and errors run_make_test(undef, 'warnval=invalid-ref:error', "#MAKEFILE#:3: *** invalid variable reference 'bad variable'. Stop.", 512); # Check invalid variable name warnings # With no options we still check for invalid references run_make_test(' .WARNINGS = $(warnval) EMPTY = SPACE = $(EMPTY) $(EMPTY) BAD$(SPACE)VAR = foo define nl endef NL$(nl)VAR = bar define BAD$(SPACE)DEF := foo endef define NL$(nl)DEF := foo endef all: ; @echo ref', '', "#MAKEFILE#:5: warning: invalid variable name 'BAD VAR' #MAKEFILE#:12: warning: invalid variable name 'NL\nVAR' #MAKEFILE#:14: warning: invalid variable name 'BAD DEF' #MAKEFILE#:18: warning: invalid variable name 'NL\nDEF' ref"); run_make_test(undef, 'warnval=ignore', 'ref'); run_make_test(undef, 'warnval=invalid-var:ignore', 'ref'); # Check errors run_make_test(undef, 'warnval=invalid-var:error', "#MAKEFILE#:5: *** invalid variable name 'BAD VAR'. Stop.", 512); # Make sure unknown warnings and actions are only noted but not failed on: # this allows makefiles to be portable to older versions where those warnings # didn't exist run_make_test(q! .WARNINGS = no-such-warn all:; !, '',"#MAKEFILE#:2: unknown warning 'no-such-warn': ignored\n#MAKE#: 'all' is up to date."); run_make_test(q! .WARNINGS = invalid-var:no-such-action all:; !, '',"#MAKEFILE#:2: unknown warning action 'no-such-action': ignored\n#MAKE#: 'all' is up to date."); # sv 65739. Circular dependency. run_make_test(q! hello: hello; @: !, '', "#MAKE#: circular hello <- hello dependency dropped\n"); run_make_test(q! .WARNINGS = circular-dep:error hello: hello; @: !, '', "#MAKE#: *** circular hello <- hello dependency detected. Stop.\n", 512); run_make_test(q! .WARNINGS = circular-dep:warn hello: hello; @: !, '', "#MAKE#: circular hello <- hello dependency dropped\n"); run_make_test(q! .WARNINGS = circular-dep:ignore hello: hello; @: !, '', ''); # Validate .WARNINGS set as target-specific variables # This is not supported (yet...?) # run_make_test(q! # ok := $(undef) # ref = $(undef) # all: enabled disabled enabled2 ; # .WARNINGS = undefined-var # enabled enabled2 disabled ref: ; $(info $@:$(ref)) # disabled: .WARNINGS = # disabled: ref # !, # '', "#MAKEFILE#:9: reference to undefined variable 'undef'\nenabled: # ref: # disabled: # #MAKEFILE#:9: reference to undefined variable 'undef'\nenabled2: # #MAKE#: 'all' is up to date."); 1; ================================================ FILE: tests/scripts/variables/append ================================================ # -*-perl-*- use warnings; my $description = "Test appending to variables of various origins."; # sv 64822, sv 36486. # Test various combinations of appends in the presence and absence of command # line definitions, env overrides and makefile overrides. # Test the following statements. # A target or pattern specific definition or append is available at build time # only. # A definition with a makefile override can only be appended to with another # override. # A definition with a makefile override can only be redefined with another # override. # A target or pattern specific definition takes precedence over a global # definition for that target. # A global variable is immune to a target or pattern specific definition or # append. # A target or pattern specific definition is immune to another target or pattern # specific definition or append. # A prerequisite inherits a target or pattern specific value from its target. # "phobos" inherits the value of "hello" from "mars". my @goals = ('phobos', 'mars'); my @specificities = ('', 's: ', '%: '); my @inits = ('', 'hello=file', 'hello:=file', 'override hello=file'); my @global_append = ('', 'hello+=red'); my @blue_override = ('', 'override '); my @yellow_override = ('', 'override '); my @cmdline = ('', 'hello=cmd', 'hello:=cmd hello+=cmd2'); my @env_ovr = ('', '-e'); my @envs = ('', 'env'); for my $goal (@goals) { for my $spec (@specificities) { for my $init (@inits) { for my $ga (@global_append) { for my $bovr (@blue_override) { for my $yovr (@yellow_override) { for my $dashe (@env_ovr) { for my $env (@envs) { for my $cmd (@cmdline) { if ($env) { $ENV{'hello'} = 'env'; } else { delete $ENV{'hello'}; } my $parse_time_answer = ''; my $build_time_answer = ''; # For goal "phobos" target is "", "phobos: " and "phobo%: ". # For goal "mars" target is "", "mars: " and "mar%: ". my $target = ''; if ($spec) { $target = $goal; chop($target); $target .= $spec; } if ($init =~ 'override') { $build_time_answer = 'file'; } elsif ($cmd) { $build_time_answer = $cmd =~ 'cmd2' ? 'cmd cmd2' : 'cmd'; } elsif ($dashe and $env) { $build_time_answer = 'env'; } elsif ($init and !$target and $ga) { $build_time_answer = 'file red'; } elsif ($init) { $build_time_answer = 'file'; } elsif ($env and $ga) { $build_time_answer = 'env red'; } elsif ($env) { $build_time_answer = 'env'; } elsif ($ga) { $build_time_answer = 'red'; } if ($bovr and $yovr) { $build_time_answer .= ' ' if ($build_time_answer); $build_time_answer .= 'blue yellow'; } elsif ($bovr) { $build_time_answer .= ' ' if ($build_time_answer); $build_time_answer .= 'blue'; } elsif ($yovr and !($init =~ 'override') and !$cmd and !($dashe and $env)) { $build_time_answer .= ' ' if ($build_time_answer); $build_time_answer .= 'blue yellow'; } elsif ($yovr) { $build_time_answer .= ' ' if ($build_time_answer); $build_time_answer .= 'yellow'; } elsif ($init =~ 'override') { } elsif ($cmd) { } elsif ($dashe and $env) { } else { $build_time_answer .= ' ' if ($build_time_answer); $build_time_answer .= 'blue yellow'; } if ($cmd and $target) { $parse_time_answer = $cmd =~ 'cmd2' ? 'cmd cmd2' : 'cmd'; } elsif ($env and !$dashe and $target and $ga) { $parse_time_answer = 'env red'; } elsif ($env and $target) { $parse_time_answer = 'env'; } elsif ($target and $ga) { $parse_time_answer = 'red'; } elsif ($target) { $parse_time_answer = ''; } else { $parse_time_answer = $build_time_answer; } my $i = $init ? "$target$init" : ''; # moon and satur% specific settings test that target and pattern # settings specific to one target do not affect another target. my $answer = $goal eq "mars" ? "$parse_time_answer\n$build_time_answer\n" # From parse time and from "phobos" recipe. . "$build_time_answer\n#MAKE#: 'mars' is up to date.\n" : # From "mars" recipe. "$parse_time_answer\n$build_time_answer\n#MAKE#: 'phobos' is up to date.\n"; run_make_test(" # goal = $goal # init = $init # target = $target # ga = $ga # bovr = $bovr # yovr = $yovr # cmd = $cmd # env = $env # dashe = $dashe moon: hello=1 moon: override hello+=2 $i $ga $target${bovr}hello+=blue $target${yovr}hello+=yellow satur%: override hello:=3 satur%: hello+=4 \$(info \$(hello)) phobos:; \$(info \$(hello)) mars: phobos; \$(info \$(hello)) saturn:; \$(info \$(hello)) ", "$dashe $cmd $goal", "$answer"); } } } } } } } } } # Preferably, we would want to run the tests below for all the combinations, # generated by the loop above. However, that causes the test to take a lot of # time. # The fix for sv 64822 went to recursively_expand_for_file. # There are three code paths that lead to recursively_expand_for_file. # - export of a variable to target environment. # - expansion of a substitution reference. # - other expansions of a variable that was appended to. # Test target env, substitution reference in parse and build modes.; # Also test a mix of pattern and target specific definitions and appends. run_make_test(q! al%: hello=file al%: hello+=one all: hello+=two $(info $(hello)) all:; $(info $(hello)) !, "", "\nfile one two\n#MAKE#: 'all' is up to date.\n"); run_make_test(q! hello=file al%: hello+=one all: hello+=two $(info $(hello:X=Y)) all:; $(info $(hello:X=Y)) !, "", "file\nfile one two\n#MAKE#: 'all' is up to date.\n"); run_make_test(q! hello=file al%: hello+=one all: hello+=two export hello $(info $(shell echo $$hello)) all:; $(info $(shell echo $$hello)) !, "", "file\nfile one two\n#MAKE#: 'all' is up to date.\n"); # "phobos" inherits the value of "hello" from "mars". On top of that there are # also "phobos" specific appends. for my $goal (@goals) { my $answer = $goal eq "mars" ? "\nminit mone mtwo pone ptwo\n" # From parse time and from "phobos" recipe. . "minit mone mtwo\n#MAKE#: 'mars' is up to date.\n" : # From "mars" recipe. "\npone ptwo\n#MAKE#: 'phobos' is up to date.\n"; # From parse time and from "phobos" recipe. run_make_test(" mar%: hello=minit mar%: hello+=mone mars: hello+=mtwo phobo%: hello+=pone phobos: hello+=ptwo \$(info \$(hello)) phobos:; \$(info \$(hello)) mars: phobos; \$(info \$(hello)) ", "$goal", "$answer"); } # This test is similar to the one above. The difference is that here there is a # pattern-specific definition of "hello" that matches "phobos". run_make_test(q! mar%: hello:=minit mar%: hello+=mone mars: hello+=mtwo phobo%: hello:=pinit phobo%: hello+=pone phobos: hello+=ptwo $(info $(hello)) phobos:; $(info $(hello)) mars: phobos; $(info $(hello)) !, 'phobos', "\npinit pone ptwo\n#MAKE#: 'phobos' is up to date.\n"); # Test pattern and target specific appends to a global variable that has origin override. # sv 36486. my @ops = ('=', '+=', ':='); @inits = ('', 'override ', 'al%: override '); @specificities = ('', 'all: ', 'al%: '); for my $init (@inits) { for my $spec (@specificities) { for my $op (@ops) { my $build_time_answer = ''; if ($init =~ ':' and $op eq '+=' and !$spec) { # This is the case where global variable obtains value 'one two three' at # parse time and later at build time a pattern or target specific # 'hello+=file' appends 'file'. # e.g. # al%: override hello+=file # hello+=one # hello+=two # hello+=three $build_time_answer = 'one two three file'; } elsif ($init =~ 'override') { $build_time_answer = 'file'; } else { $build_time_answer = 'file one two three'; } my $parse_time_answer = $init =~ ':' ? '' : 'file'; if (!$spec and ($init ne 'override ')) { $parse_time_answer .= ' ' if $parse_time_answer; $parse_time_answer .= 'one two three'; } run_make_test(" ${init}hello${op}file ${spec}hello+=one ${spec}hello+=two ${spec}hello+=three \$(info \$(hello)) all:; \$(info \$(hello)) ", "", "$parse_time_answer\n$build_time_answer\n#MAKE#: 'all' is up to date.\n"); } } } 1; ================================================ FILE: tests/scripts/variables/automatic ================================================ # -*-perl-*- $description = "Test automatic variable setting."; $details = ""; use Cwd; $dir = cwd; $dir =~ s,.*/([^/]+)$,../$1,; open(MAKEFILE, "> $makefile"); print MAKEFILE "dir = $dir\n"; print MAKEFILE <<'EOF'; .SUFFIXES: .SUFFIXES: .x .y .z $(dir)/foo.x : baz.z $(dir)/bar.y baz.z @echo '$$@ = $@, $$(@D) = $(@D), $$(@F) = $(@F)' @echo '$$* = $*, $$(*D) = $(*D), $$(*F) = $(*F)' @echo '$$< = $<, $$( $makefile2"); print MAKEFILE "dir = $dir\n"; print MAKEFILE <<'EOF'; .SECONDEXPANSION: .SUFFIXES: .DEFAULT: ; @echo '$@' $(dir)/foo $(dir)/bar: $@.x $$@.x $$$@.x $$$$@.x $$(@D).x $$(@F).x $(dir)/x.z $(dir)/y.z: $(dir)/%.z : $@.% $$@.% $$$@.% $$$$@.% $$(@D).% $$(@F).% $(dir)/biz: $$(@).x $${@}.x $${@D}.x $${@F}.x EOF close(MAKEFILE); &run_make_with_options($makefile2, "$dir/foo $dir/bar", &get_logfile); $answer = ".x\n$dir/foo.x\nx\n\$@.x\n$dir.x\nfoo.x\n$dir/bar.x\nbar.x\n"; &compare_output($answer, &get_logfile(1)); &run_make_with_options($makefile2, "$dir/x.z $dir/y.z", &get_logfile); $answer = ".x\n$dir/x.z.x\nx\n\$@.x\n$dir.x\nx.z.x\n.y\n$dir/y.z.y\ny\n\$@.y\n$dir.y\ny.z.y\n"; &compare_output($answer, &get_logfile(1)); &run_make_with_options($makefile2, "$dir/biz", &get_logfile); $answer = "$dir/biz.x\n$dir.x\nbiz.x\n"; &compare_output($answer, &get_logfile(1)); # TEST #2 -- test for Savannah bug #12320. # run_make_test(' .SUFFIXES: .b .src mbr.b: mbr.src @echo $* mbr.src: ; @:', '', 'mbr'); # Same as above with second expansion. # run_make_test(' .SECONDEXPANSION: .SUFFIXES: .b .src p:=mbr.src mbr.b: $$p @echo $* mbr.src: ; @:', '', 'mbr'); # Test that $* is set to empty string for unknown suffixes. run_make_test(' mbr.b: mbr.src @echo star=$* mbr.src: ; @:', '', "star=\n"); # TEST #3 -- test for Savannah bug #8154 # Make sure that nonexistent prerequisites are listed in $?, since they are # considered reasons for the target to be rebuilt. # # See also Savannah bugs #16002 and #16051. touch('foo'); run_make_test(' foo: bar ; @echo "\$$? = $?" bar: ;', '', '$? = bar'); unlink('foo'); # TEST #4: ensure prereq ordering is correct when the command target has none # See Savannah bug #21198 run_make_test(' all : A B all : ; @echo $@ -- $^ -- $< all : C D all : E F A B C D E F G H : ; @: ', '', "all -- A B C D E F -- A\n"); 1; ================================================ FILE: tests/scripts/variables/conditional ================================================ # -*-perl-*- $description = "Test various flavors of conditional variable setting."; $details = ""; # Test ?= run_make_test(q! x = bar y = baz foo ?= $(x) biz?=$(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=10 biz=20"); run_make_test(q! foo=1 biz=2 x = bar y = baz foo ?= $(x) biz?=$(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=1 biz=2"); # Test ?:= run_make_test(q! x = bar y = baz foo ?:= $(x) biz?:=$(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=bar biz=baz"); run_make_test(q! foo=1 biz=2 x = bar y = baz foo ?:= $(x)$(info expanded) biz?:=$(y)$(info expanded) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=1 biz=2"); # Test ?::= run_make_test(q! x = bar y = baz foo ?::= $(x) biz?::=$(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=bar biz=baz"); run_make_test(q! foo=1 biz=2 x = bar y = baz foo ?::= $(x)$(info expanded) biz?::=$(y)$(info expanded) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=1 biz=2"); # Test ?:::= run_make_test(q! x = bar y = baz foo ?:::= $(x) biz?:::=$(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=bar biz=baz"); run_make_test(q! foo=1 biz=2 x = bar y = baz foo ?:::= $(x)$(info expanded) biz?:::=$(y)$(info expanded) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) !, '', "foo=1 biz=2"); # Test ?!= run_make_test(q/ x = bar y = baz foo ?!= echo $(x) biz?!=echo $(y) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) /, '', "foo=bar biz=baz"); run_make_test(q/ foo=1 biz=2 x = bar y = baz foo ?!= echo $(x)$(info expanded) biz?!=echo $(y)$(info expanded) x = 10 y = 20 all:;@: $(info foo=$(foo) biz=$(biz)) /, '', "foo=1 biz=2"); 1; ================================================ FILE: tests/scripts/variables/define ================================================ # -*-perl-*- $description = "Test define/endef variable assignments."; $details = ""; # TEST 0: old-style basic define/endef run_make_test(' define multi @echo hi echo there endef all: ; $(multi) ', '', "hi\necho there\nthere\n"); # TEST 1: Various new-style define/endef run_make_test(' FOO = foo define multi = echo hi @echo $(FOO) endef # this is the end define simple := @echo $(FOO) endef define posix ::= @echo $(FOO) endef append = @echo a define append += @echo b endef define cond ?= # this is a conditional @echo first endef define cond ?= @echo second endef FOO = there all: ; $(multi) $(simple) $(posix) $(append) $(cond) ', '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n"); # TEST 1a: Various new-style define/endef, with no spaces run_make_test(q! FOO = foo define multi= echo hi @echo $(FOO) endef # this is the end define simple:= @echo $(FOO) endef define posix::= @echo $(FOO) endef define posixbsd:::= @echo '$(FOO)$$bar' endef append = @echo a define append+= @echo b endef define cond?= # this is a conditional @echo first endef define cond?= @echo second endef FOO = there all: ; $(multi) $(simple) $(posix) $(posixbsd) $(append) $(cond) !, '', "echo hi\nhi\nthere\nfoo\nfoo\nfoo\$bar\na\nb\nfirst\n"); # TEST 2: define in true section of conditional (containing conditional) run_make_test(' FOO = foo NAME = def def = ifdef BOGUS define $(subst e,e,$(NAME)) = ifeq (1,1) FOO = bar endif endef endif $(eval $(def)) all: ; @echo $(FOO) ', 'BOGUS=1', "bar\n"); # TEST 3: define in false section of conditional (containing conditional) run_make_test(undef, '', "foo\n"); # TEST 4: nested define (supported?) run_make_test(' define outer define inner A = B endef endef $(eval $(outer)) outer: ; @echo $(inner) ', '', "A = B\n"); # TEST 5: NEGATIVE: Missing variable name run_make_test(' NAME = define $(NAME) = ouch endef all: ; @echo ouch ', '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512); # TEST 6: NEGATIVE: extra text after define run_make_test(' NAME = define NAME = $(NAME) ouch endef all: ; @echo ok ', '', "#MAKEFILE#:3: extraneous text after 'define' directive\nok\n"); # TEST 7: NEGATIVE: extra text after endef run_make_test(' NAME = define NAME = ouch endef $(NAME) all: ; @echo ok ', '', "#MAKEFILE#:5: extraneous text after 'endef' directive\nok\n"); # TEST 8: NEGATIVE: missing endef run_make_test(' NAME = all: ; @echo ok define NAME = ouch endef$(NAME) ', '', "#MAKEFILE#:4: *** missing 'endef', unterminated 'define'. Stop.\n", 512); # ------------------------- # Make sure that prefix characters apply properly to define/endef values. # # There's a bit of oddness here if you try to use a variable to hold the # prefix character for a define. Even though something like this: # # define foo # echo bar # endef # # all: ; $(V)$(foo) # # (where V=@) can be seen by the user to be obviously different than this: # # define foo # $(V)echo bar # endef # # all: ; $(foo) # # and the user thinks it should behave the same as when the "@" is literal # instead of in a variable, that can't happen because by the time make # expands the variables for the command line and sees it begins with a "@" it # can't know anymore whether the prefix character came before the variable # reference or was included in the first line of the variable reference. # TEST #5 # ------- run_make_test(' define FOO $(V1)echo hello $(V2)echo world endef all: ; @$(FOO) ', '', 'hello world'); # TEST #6 # ------- run_make_test(undef, 'V1=@ V2=@', 'hello world'); # TEST #7 # ------- run_make_test(' define FOO $(V1)echo hello $(V2)echo world endef all: ; $(FOO) ', 'V1=@', 'hello echo world world'); # TEST #8 # ------- run_make_test(undef, 'V2=@', 'echo hello hello world'); # TEST #9 # ------- run_make_test(undef, 'V1=@ V2=@', 'hello world'); # TEST #10 # ------- # Test the basics; a "@" internally to the variable applies to only one line. # A "@" before the variable applies to the entire variable. run_make_test(' define FOO @echo hello echo world endef define BAR echo hello echo world endef all: foo bar foo: ; $(FOO) bar: ; @$(BAR) ', '', 'hello echo world world hello world '); # Ensure that define can be a target when not appearing in a variable # definition context. See SV 59870 run_make_test(q! define = define $(define) : ;@echo $@ %:define all: define foo %.x : define foo:; !, '', "define\n"); 1; ================================================ FILE: tests/scripts/variables/flavors ================================================ # -*-perl-*- $description = "Test various flavors of make variable setting."; $details = ""; # TEST 0: Recursive run_make_test(' ugh = Goodbye foo = $(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Hello\n"); # TEST 1: Simple run_make_test(' bar = Goodbye foo := $(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Goodbye\n"); # TEST 2: Append to recursive run_make_test(' foo = Hello ugh = Goodbye foo += $(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Hello Hello\n"); # TEST 3: Append to simple run_make_test(' foo := Hello ugh = Goodbye bar = ${ugh} foo += $(bar) ugh = Hello all: ; @echo $(foo) ', '', "Hello Goodbye\n"); # TEST 4: Conditional pre-set run_make_test(' foo = Hello ugh = Goodbye bar = ${ugh} foo ?= $(bar) ugh = Hello all: ; @echo $(foo) ', '', "Hello\n"); # TEST 5: Conditional unset run_make_test(' ugh = Goodbye bar = ${ugh} foo ?= $(bar) ugh = Hello all: ; @echo $(foo) ', '', "Hello\n"); # TEST 6: Simple using POSIX syntax run_make_test(' bar = Goodbye foo ::= $(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Goodbye\n"); # TEST 7: POSIX syntax no spaces run_make_test(' bar = Goodbye foo::=$(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Goodbye\n"); # TEST 8: Append to empty run_make_test(q! recur = recur += foo simple := simple += bar recur_empty = foo recur_empty += simple_empty := bar simple_empty += empty_recur = empty_recur += empty_simple := empty_simple += all: ; @: $(info recur=/$(recur)/ simple=/$(simple)/ recure=/$(recur_empty)/ simplee=/$(simple_empty)/ erecur=/$(empty_recur)/ esimple=/$(empty_simple)/) !, '', "recur=/foo/ simple=/bar/ recure=/foo/ simplee=/bar/ erecur=// esimple=//\n"); # TEST 9: Line continuation run_make_test(q! recur = $\ zero $\ one$$\ two$$$\ three simple := $\ four $\ five$$\ six$$$\ seven all: d$\ e$\ p; @: .PHONY: dep dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/) !, '', "recur=/zeroone\$ two\$three/ simple=/fourfive\$ six\$seven/\n"); # TEST 9: Line continuation with POSIX run_make_test(q! .POSIX: recur = $\ zero $\ one$$\ two$$$\ three simple := $\ four $\ five$$\ six$$$\ seven all: d$\ e$\ p; @: .PHONY: dep dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/) !, '', "recur=/zero one\$ two\$three/ simple=/four five\$ six\$seven/\n"); # Test POSIX :::= # This creates a recursive variable, but it expands the RHS first. Any # variable escapes ('$$') are preserved so that this recursive variable can be # expanded again without changing its contents. run_make_test(' bar = Goodbye foo :::= $(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) ', '', "Goodbye"); # POSIX :::= no spaces run_make_test(q! bar = Goodbye foo:::=$(bar) bar = ${ugh} ugh = Hello all: ; @echo $(foo) !, '', "Goodbye"); # Variable escapes ('$$') are preserved. run_make_test(q! bar = Good$$bye foo :::= $(bar) $$what bar = ${ugh} ugh = Hello all: ; @echo '$(foo)' !, '', 'Good$bye $what'); # Append works as expected run_make_test(q! bar = Good$$bye foo :::= $(bar) foo += $$what $(bar) bar = ${ugh} ugh = Hello all: ; @echo '$(foo)' !, '', 'Good$bye $what Hello'); # Target-specific variable run_make_test(q! bar = Good$$bye all: foo :::= $(bar) all: ; @echo '$(foo)' !, '', 'Good$bye'); 1; ================================================ FILE: tests/scripts/variables/negative ================================================ # -*-perl-*- $description = "Run some negative tests (things that should fail)."; my $unterm = '*** unterminated variable reference. Stop.'; # TEST #0 # Check that non-terminated variable references are detected (and # reported using the best filename/lineno info run_make_test(' foo = bar x = $(foo y = $x all: ; @echo $y ', '', "#MAKEFILE#:3: $unterm", 512); # TEST #1 # Bogus variable value passed on the command line. run_make_test(undef, ['x=$(other'], "#MAKEFILE#:4: $unterm", 512); # TEST #2 # Again, but this time while reading the makefile. run_make_test(' foo = bar x = $(foo y = $x z := $y all: ; @echo $y ', '', "#MAKEFILE#:3: $unterm", 512); # TEST #3 # Bogus variable value passed on the command line. run_make_test(undef, ['x=$(other'], "#MAKEFILE#:4: $unterm", 512); my $nosep = '*** missing separator. Stop.'; # Whitespace not allowed in variable names run_make_test('x y =', '', "#MAKEFILE#:1: $nosep", 512); run_make_test('x y=', '', "#MAKEFILE#:1: $nosep", 512); # In theory an empty variable should be ignored, but during parsing it's a # real token and so this fails. I'm not 100% sure if this is right or not. run_make_test('x $X=', '', "#MAKEFILE#:1: $nosep", 512); 1; ================================================ FILE: tests/scripts/variables/private ================================================ # -*-perl-*- $description = "Test 'private' variables."; $details = ""; # 1: Simple verification that private variables are not inherited &run_make_test(' a: F = g a: F = a b: private F = b a b c: ; @echo $@: F=$(F) a: b b: c ', '', "c: F=a\nb: F=b\na: F=a\n"); # 2: Again, but this time we start with "b" so "a"'s variable is not in scope &run_make_test(undef, 'b', "c: F=g\nb: F=b\n"); # 3: Verification with pattern-specific variables &run_make_test(' t.a: F1 = g F2 = g %.a: private F1 = a %.a: F2 = a t.a t.b: ; @echo $@: F1=$(F1) / F2=$(F2) t.a: t.b ', '', "t.b: F1=g / F2=a\nt.a: F1=a / F2=a\n"); # 4: Test private global variables &run_make_test(' a: private F = g G := $(F) a: b: F = b a b: ; @echo $@: F=$(F) / G=$(G) a: b ', '', "b: F=b / G=g\na: F= / G=g\n"); # Exported private global variables run_make_test(' private export F = global $(info $(shell #HELPER# env F)) a: b b: export F=b a b: ; @#HELPER# raw $@ env F ', '', "F=global\nbF=b\naF="); # 5: Multiple conditions on the same variable. Test export. delete $ENV{'_X'}; &run_make_test(' _X = x a: export override private _X = a a: ; @echo _X=$(_X) / _X=$$_X ', '', "_X=a / _X=a"); # 6: Test override. &run_make_test(undef, '_X=c', "_X=a / _X=a\n"); # 7: Ensure keywords still work as targets &run_make_test(' a: export override private foo bar foo bar export override private: ; @echo $@ ', '', "export\noverride\nprivate\nfoo\nbar\n"); # 8: Ensure keywords still work as variables &run_make_test(' private = g a: private = a a: b a b: ; @echo $@=$(private) ', '', "b=a\na=a\n"); # 9: make sure private suppresses inheritance run_make_test(q! DEFS = FOO all: bar1 bar1: private DEFS += 1 bar3: private DEFS += 3 bar1: bar2 bar2: bar3 bar1 bar2 bar3: ; @echo '$@: $(DEFS)' !, '', "bar3: FOO 3\nbar2: FOO\nbar1: FOO 1\n"); # 10: Test append with pattern-specific variables and private run_make_test(q! IA = global PA = global PS = global S = global PS = global SV = global b%: IA += b% b%: private PA += b% b%: private PS = b% bar: all bar: IA += bar bar: private PA += bar bar: private PS = bar a%: IA += a% a%: private PA += a% a%: private PS = a% all: IA += all all: private PA += all all: private PS = all bar all: ; @echo '$@: IA=$(IA)'; echo '$@: PA=$(PA)'; echo '$@: PS=$(PS)' !, '', "all: IA=global b% bar a% all all: PA=global a% all all: PS=all bar: IA=global b% bar bar: PA=global b% bar bar: PS=bar\n"); # SV 61463: Private parent variables should not be exported run_make_test(q! a: private export FOO := a a: b b: ; @#HELPER# env FOO !, '', 'FOO='); run_make_test(q! a: private export FOO := a a: b b: FOO := b b: ; @#HELPER# env FOO !, '', 'FOO='); run_make_test(q! export FOO := g a: private export FOO := a a: b b: b: ; @#HELPER# env FOO !, '', 'FOO=g'); run_make_test(q! export FOO := g a: private export FOO := a a: b b: FOO := b b: ; @#HELPER# env FOO !, '', 'FOO=b'); run_make_test(q! private export FOO := g a: private export FOO := a a: b b: FOO := b b: ; @#HELPER# env FOO !, '', 'FOO='); 1; ================================================ FILE: tests/scripts/variables/special ================================================ # -*-perl-*- $description = "Test special GNU Make variables."; $details = ""; &run_make_test(' X1 := $(sort $(filter FOO BAR,$(.VARIABLES))) FOO := foo X2 := $(sort $(filter FOO BAR,$(.VARIABLES))) BAR := bar all: ; @echo X1 = $(X1); echo X2 = $(X2); echo LAST = $(sort $(filter FOO BAR,$(.VARIABLES))) ', '', "X1 =\nX2 = FOO\nLAST = BAR FOO\n"); # SV 45728: Test that undefining a variable is reflected properly &run_make_test(' FOO := foo BAR := bar $(info one: $(sort $(filter FOO BAR BAZ,$(.VARIABLES)))) undefine BAR BAZ := baz $(info two: $(sort $(filter FOO BAR BAZ,$(.VARIABLES)))) all:;@: ', '', "one: BAR FOO\ntwo: BAZ FOO\n"); # $makefile2 = &get_tmpfile; # open(MAKEFILE, "> $makefile2"); # print MAKEFILE <<'EOF'; # X1 := $(sort $(.TARGETS)) # all: foo # @echo X1 = $(X1) # @echo X2 = $(X2) # @echo LAST = $(sort $(.TARGETS)) # X2 := $(sort $(.TARGETS)) # foo: # EOF # close(MAKEFILE); # # TEST #2 # # ------- # &run_make_with_options($makefile2, "", &get_logfile); # $answer = "X1 =\nX2 = all\nLAST = all foo\n"; # &compare_output($answer, &get_logfile(1)); # Test the .RECIPEPREFIX variable &run_make_test(' define foo : foo-one\ foo-two : foo-three : foo-four endef orig: ; : orig-one : orig-two \ orig-three \ orig-four \ orig-five \\\\ : orig-six $(foo) .RECIPEPREFIX = > test: ; : test-one >: test-two \ test-three \ >test-four \ > test-five \\\\ >: test-six >$(foo) .RECIPEPREFIX = reset: ; : reset-one : reset-two \ reset-three \ reset-four \ reset-five \\\\ : reset-six $(foo) ', 'orig test reset', ': orig-one : orig-two \ orig-three \ orig-four \ orig-five \\\\ : orig-six : foo-one foo-two : foo-three : foo-four : test-one : test-two \ test-three \ test-four \ test-five \\\\ : test-six : foo-one foo-two : foo-three : foo-four : reset-one : reset-two \ reset-three \ reset-four \ reset-five \\\\ : reset-six : foo-one foo-two : foo-three : foo-four'); 1; ### Local Variables: ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) ### End: ================================================ FILE: tests/scripts/variables/undefine ================================================ # -*-perl-*- $description = "Test variable undefine."; $details = ""; # TEST 0: basic undefine functionality run_make_test(' a = a b := b define c c endef $(info $(flavor a) $(flavor b) $(flavor c)) n := b undefine a undefine $n undefine c $(info $(flavor a) $(flavor b) $(flavor c)) all: ;@: ', '', "recursive simple recursive\nundefined undefined undefined"); # TEST 1: override run_make_test(' undefine a override undefine b $(info $(flavor a) $(flavor b)) all: ;@: ', 'a=a b=b', "recursive undefined"); 1; # TEST 2: undefine in eval (make sure we undefine from the global var set) run_make_test(' define undef $(eval undefine $$1) endef a := a $(call undef,a) $(info $(flavor a)) all: ;@: ', '', "undefined"); # TEST 3: Missing variable name run_make_test(' a = undefine $a all: ;@echo ouch ', '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512); # Ensure that define can be a target when not appearing in a variable # definition context. See SV 59870 run_make_test(q! undefine = undefine $(undefine) : ;@echo $@ %:undefine all: undefine foo %.x : undefine foo:; !, '', "undefine\n"); 1; ================================================ FILE: tests/scripts/vms/library ================================================ # -*-mode: perl-*- $description = "Test GNU Make's VMS Library management features."; $details = "\ This only works on VMS systems."; return -1 if $osname ne 'VMS'; # Help library $mk_string = "help : help.hlb(file1.hlp)\n\n" . "file1.hlp :\n" . "\t\@pipe open/write xxx file1.hlp ; write xxx \"1 help\" ; close xxx\n"; my $answer = "library /replace help.hlb file1.hlp"; run_make_test($mk_string, '', $answer); unlink('help.hlb'); unlink('file1.hlp'); #Text library $mk_string = "text : text.tlb(file1.txt)\n\n" . "file1.txt :\n" . "\t\@pipe open/write xxx file1.txt ; write xxx \"text file\" ; close xxx\n"; $answer = "library /replace text.tlb file1.txt"; run_make_test($mk_string, '', $answer); unlink('text.tlb'); unlink('file1.txt'); #Macro library $mk_string = "macro : macro.mlb(file1.mar)\n\n" . "file1.mar :\n" . "\tpipe open/write xxx file1.mar ; " . "write xxx \".macro a b\" ; write xxx \".endm\" ; close xxx\n"; $answer = "library /replace macro.mlb file1.mar"; run_make_test($mk_string, '', $answer); unlink('macro.mlb'); unlink('file1.mar'); $mk_string = "all:imagelib.olb(file2.exe)\n" . "file2.exe : file2.obj file2.opt\n" . "\t\@link /share=\$\@ \$\*,\$\*/opt\n\n" . "file2.opt :\n" . "\t\@pipe open/write xxx file2.opt ; " . "write xxx \"CASE_SENSITIVE=YES\" ; close xxx\n" . "file2.c :\n" . "\t\@pipe open/write xxx file2.c ; write xxx \"file2(){}\" ; close xxx\n"; $answer = "library /replace imagelib.olb file2.exe"; run_make_test($mk_string, '', $answer); unlink('imagelib.olb'); unlink('file2.c'); unlink('file2.obj'); unlink('file2.exe'); unlink('file2.opt'); # This tells the test driver that the perl test script executed properly. 1; ================================================ FILE: tests/test_driver.pl ================================================ #!/usr/bin/perl # -*-perl-*- # # Modification history: # Written 91-12-02 through 92-01-01 by Stephen McGee. # Modified 92-02-11 through 92-02-22 by Chris Arthur to further generalize. # # Copyright (C) 1991-2024 Free Software Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # Test driver routines used by a number of test suites, including # those for SCS, make, roll_dir, and scan_deps (?). # # this routine controls the whole mess; each test suite sets up a few # variables and then calls &toplevel, which does all the real work. # $Id$ use Config; use Cwd; use File::Spec; use File::Temp; $debug = 0; # debug flag $profile = 0; # profiling flag $verbose = 0; # verbose mode flag $detail = 0; # detailed verbosity $keep = 0; # keep temp files around # The number of test categories we've run $categories_run = 0; # The number of test categroies that have passed $categories_passed = 0; # The total number of individual tests that have been run $total_tests_run = 0; # The total number of individual tests that have passed $total_tests_passed = 0; # Set to true if something failed. It could be that tests_run == tests_passed # even with failures, if we don't run tests for some reason. $some_test_failed = 0; # The number of tests in this category that have been run $tests_run = 0; # The number of tests in this category that have passed $tests_passed = 0; # Info on which tests failed @failure_info = (); $port_type = undef; $osname = undef; $vos = undef; $pathsep = undef; $testee = undef; $testee_version = undef; # Yeesh. This whole test environment is such a hack! $test_passed = 1; # Timeout in seconds. If the test takes longer than this we'll fail it. # This is to prevent hung tests. $test_timeout = 60; $diff_name = undef; # Path to Perl $perl_name = $^X; if ($^O ne 'VMS') { $perl_name .= $Config{_exe} unless $perl_name =~ m/$Config{_exe}$/i; } sub which { my $cmd = $_[0]; # Poor man's File::Which my ($v,$d,$f) = File::Spec->splitpath($cmd); if ($d) { # The command has a pathname so don't look for it in PATH. # Use forward-slashes even on Windows, else it fails in recipes. (-f $cmd and -x _) or return undef; $cmd =~ tr,\\,/,; return $cmd; } my @ext; if ($port_type eq 'UNIX' || $port_type eq 'VMS-DCL') { @ext = (''); } else { @ext = index($f, '.') == -1 ? () : (''); push @ext, split /;/, $ENV{PATHEXT}; } foreach my $dir (File::Spec->path()) { foreach my $e (@ext) { my $p = File::Spec->catfile($dir, "$cmd$e"); (-f $p and -x _) or next; # Use forward-slashes even on Windows, else it fails in recipes. $p =~ tr,\\,/,; return $p; } } return undef; } # %makeENV is the cleaned-out environment. Tests must not modify it. my %makeENV = (); sub vms_get_process_logicals { # Sorry for the long note here, but to keep this test running on # VMS, it is needed to be understood. # # Perl on VMS by default maps the %ENV array to the system wide logical # name table. # # This is a very large dynamically changing table. # On Linux, this would be the equivalent of a table that contained # every mount point, temporary pipe, and symbolic link on every # file system. You normally do not have permission to clear or replace it, # and if you did, the results would be catastrophic. # # On VMS, added/changed %ENV items show up in the process logical # name table. So to track changes, a copy of it needs to be captured. my $raw_output = `show log/process/access_mode=supervisor`; my @raw_output_lines = split('\n',$raw_output); my %log_hash; foreach my $line (@raw_output_lines) { if ($line =~ /^\s+"([A-Za-z\$_]+)"\s+=\s+"(.+)"$/) { $log_hash{$1} = $2; } } return \%log_hash } # %origENV is the caller's original environment if ($^O ne 'VMS') { %origENV = %ENV; } else { my $proc_env = vms_get_process_logicals; %origENV = %{$proc_env}; } sub resetENV { # We used to say "%ENV = ();" but this doesn't work in Perl 5.000 # through Perl 5.004. It was fixed in Perl 5.004_01, but we don't # want to require that here, so just delete each one individually. if ($osname ne 'VMS') { foreach $v (keys %ENV) { delete $ENV{$v}; } %ENV = %makeENV; } else { my $proc_env = vms_get_process_logicals(); my %delta = %{$proc_env}; foreach my $v (keys %delta) { if (exists $origENV{$v}) { if ($origENV{$v} ne $delta{$v}) { $ENV{$v} = $origENV{$v}; } } else { delete $ENV{$v}; } } } } # Returns a string-ified version of cmd which is a value provided to exec() # so it can either be a ref of a list or a string. sub cmd2str { my @c; my $cmd = $_[0]; if (!ref($cmd)) { push @c, $cmd; } else { foreach (@$cmd) { if (/[][#;"*?&|<>(){}\$`^~!]/) { s/\'/\'\\'\'/g; push @c, "'$_'"; } else { push @c, $_; } } } if ($testpath eq $cwd) { return join(' ', @c); } return "(cd $testpath && " . join(' ', @c) . ')'; } sub toplevel { %origENV = %ENV unless $^O eq 'VMS'; # Pull in benign variables from the user's environment foreach (# POSIX-specific things 'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH', 'LD_LIBRARY_PATH', # *SAN things 'ASAN_OPTIONS', 'UBSAN_OPTIONS', 'LSAN_OPTIONS', # Purify things 'PURIFYOPTIONS', # Windows-specific things 'Path', 'SystemRoot', 'TEMP', 'TMP', 'USERPROFILE', 'PATHEXT', # z/OS specific things 'LIBPATH', '_BPXK_AUTOCVT', '_TAG_REDIR_IN', '_TAG_REDIR_OUT', # DJGPP-specific things 'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN', 'FNCASE', '387', 'EMU387', 'GROUP' ) { $makeENV{$_} = $ENV{$_} if $ENV{$_}; } # Make sure our compares are not foiled by locale differences $makeENV{LC_ALL} = 'C'; $makeENV{LANG} = 'C'; $makeENV{LANGUAGE} = 'C'; $| = 1; # unbuffered output $debug = 0; # debug flag $profile = 0; # profiling flag $verbose = 0; # verbose mode flag $detail = 0; # detailed verbosity $keep = 0; # keep temp files around $workdir = "work"; # The directory where the test will start running $tempdir = "_tmp"; # A temporary directory $scriptdir = "scripts"; # The directory where we find the test scripts $tmpfilesuffix = "t"; # the suffix used on tmpfiles $default_output_stack_level = 0; # used by attach_default_output, etc. $default_input_stack_level = 0; # used by attach_default_input, etc. &get_osname; # sets $osname, $vos, $pathsep, and $short_filenames # Locate the test directory. It's the one that contains this script. my @sp = File::Spec->splitpath(__FILE__); $srcpath = File::Spec->canonpath(File::Spec->catpath($sp[0], $sp[1], '')); # Locate the top source directory. $toppath = File::Spec->rel2abs(File::Spec->updir(), $srcpath); local $cwd = cwd(); $workpath = "$workdir"; $scriptpath = $srcpath eq $cwd ? $scriptdir : File::Spec->catdir($srcpath, $scriptdir); $perl_name = which($perl_name); # See if we have a diff $diff_name = which('diff'); if (!$diff_name) { print "No diff found; differences will not be shown\n"; } &set_defaults; # suite-defined &parse_command_line (@ARGV); print "OS name = '$osname'\n" if $debug; $temppath = File::Spec->rel2abs($tempdir); if (-d $temppath) { &remove_directory_tree("$temppath/") or &error ("Couldn't wipe out $temppath: $!\n"); } else { mkdir ($temppath, 0777) or error ("Cannot mkdir $temppath: $!\n"); } # This is used by POSIX systems $makeENV{TMPDIR} = $temppath; # These are used on Windows $makeENV{TMP} = $temppath; $makeENV{TEMP} = $temppath; # Replace the environment with the new one resetENV(); &set_more_defaults; # suite-defined &print_banner; if ($osname eq 'VMS' && $scriptpath eq $scriptdir) { # Porting this script to VMS revealed a small bug in opendir() not # handling search lists correctly when the directory only exists in # one of the logical_devices. Need to find the first directory in # the search list, as that is where things will be written to. my @dirs = split('/', $cwdpath); my $logical_device = $ENV{$dirs[1]}; if ($logical_device =~ /([A-Za-z0-9_]+):(:?.+:)+/) { # A search list was found. Grab the first logical device # and use it instead of the search list. $dirs[1]=$1; my $lcl_pwd = join('/', @dirs); $workpath = $lcl_pwd . '/' . $workdir } } print "Finding tests in $scriptpath...\n"; if (-d $workpath) { print "Clearing $workpath...\n"; &remove_directory_tree("$workpath/") or &error ("Couldn't wipe out $workpath: $!\n"); } else { mkdir ($workpath, 0777) or &error ("Cannot mkdir $workpath: $!\n"); } if (!-d $scriptpath) { &error ("Failed to find $scriptpath containing perl test scripts.\n"); } if (@TESTS) { print "Creating dirs in $workpath...\n"; foreach $test (@TESTS) { if ($test =~ /^([^\/]+)\//) { $dir = $1; push (@rmdirs, $dir); -d "$workpath/$dir" or mkdir ("$workpath/$dir", 0777) or &error ("Couldn't mkdir $workpath/$dir: $!\n"); } } } else { print "Searching for tests...\n"; opendir (SCRIPTDIR, $scriptpath) or &error ("Couldn't opendir $scriptpath: $!\n"); @dirs = grep (!/^(\..*|CVS|RCS)$/, readdir (SCRIPTDIR) ); closedir (SCRIPTDIR); print "Creating dirs in $workpath...\n"; foreach my $dir (@dirs) { next if ($dir =~ /^(\..*|CVS|RCS)$/ || ! -d "$scriptpath/$dir"); push (@rmdirs, $dir); # VMS can have overlaid file systems, so directories may repeat. next if -d "$workpath/$dir"; mkdir ("$workpath/$dir", 0777) or &error ("Couldn't mkdir $workpath/$dir: $!\n"); opendir (SCRIPTDIR, "$scriptpath/$dir") or &error ("Couldn't opendir $scriptpath/$dir: $!\n"); @files = grep (!/^(\..*|CVS|RCS|.*~)$/, readdir (SCRIPTDIR) ); closedir (SCRIPTDIR); foreach my $test (@files) { -d $test and next; push (@TESTS, "$dir/$test"); } } } if (@TESTS == 0) { &error ("\nNo tests in $scriptpath, and none were specified.\n"); } print "\n"; run_all_tests(); foreach my $dir (@rmdirs) { rmdir ("$workpath/$dir"); } rmdir ($workpath); rmdir ($temppath); $| = 1; $categories_failed = $categories_run - $categories_passed; $total_tests_failed = $total_tests_run - $total_tests_passed; if ($total_tests_failed) { print "\n$total_tests_failed Test"; print "s" unless $total_tests_failed == 1; print " in $categories_failed Categor"; print ($categories_failed == 1 ? "y" : "ies"); print " Failed :-(\n\n"; my $i = 0; for my $e (@failure_info) { ++$i; print " Failure $i:\n"; print " run: $e->{'run'}\n" if exists($e->{'run'}); print " base: $e->{'base'}\n"; print " diff: $e->{'diff'}\n" if exists($e->{'diff'}); } return 0; } if ($some_test_failed) { # Something failed but no tests were marked failed... probably a syntax # error in a test script print "\nSome tests failed (See output for details) :-(\n\n"; return 0; } print "\n$total_tests_passed Test"; print "s" unless $total_tests_passed == 1; print " in $categories_passed Categor"; print ($categories_passed == 1 ? "y" : "ies"); print " Complete ... No Failures :-)\n\n"; return 1; } sub get_osname { # Set up an initial value. In perl5 we can do it the easy way. $osname = defined($^O) ? $^O : ''; $vos = 0; $pathsep = "/"; # find the type of the port. We do this up front to have a single # point of change if it needs to be tweaked. # # This is probably not specific enough. # if ($osname =~ /MSWin32/i || $osname =~ /Windows/i || $osname =~ /msys/i || $osname =~ /MINGW32/i || $osname =~ /CYGWIN_NT/i) { $port_type = 'W32'; } # Bleah, the osname is so variable on DOS. This kind of bites. # Well, as far as I can tell if we check for some text at the # beginning of the line with either no spaces or a single space, then # a D, then either "OS", "os", or "ev" and a space. That should # match and be pretty specific. elsif ($osname =~ /^([^ ]*|[^ ]* [^ ]*)D(OS|os|ev) /) { $port_type = 'DOS'; } # Check for OS/2 elsif ($osname =~ m%OS/2%) { $port_type = 'OS/2'; } # VMS has a GNV Unix mode or a DCL mode. # The SHELL environment variable should not be defined in VMS-DCL mode. elsif ($osname eq 'VMS' && !defined $ENV{"SHELL"}) { $port_type = 'VMS-DCL'; } # Everything else, right now, is UNIX. Note that we should integrate # the VOS support into this as well and get rid of $vos else { $port_type = 'UNIX'; } if ($osname eq 'VMS') { return; } # Find a path to Perl # See if the filesystem supports long file names with multiple # dots. DOS doesn't. $short_filenames = 0; (open (TOUCHFD, '>', 'fancy.file.name') and close (TOUCHFD)) or $short_filenames = 1; unlink ("fancy.file.name") or $short_filenames = 1; if (! $short_filenames) { # Thanks go to meyering@cs.utexas.edu (Jim Meyering) for suggesting a # better way of doing this. (We used to test for existence of a /mnt # dir, but that apparently fails on an SGI Indigo (whatever that is).) # Because perl on VOS translates /'s to >'s, we need to test for # VOSness rather than testing for Unixness (ie, try > instead of /). mkdir (".ostest", 0777) or &error ("Couldn't create .ostest: $!\n", 1); open (TOUCHFD, "> .ostest>ick") and close (TOUCHFD); chdir (".ostest") or &error ("Couldn't chdir to .ostest: $!\n", 1); } if (! $short_filenames && -f "ick") { $osname = "vos"; $vos = 1; $pathsep = ">"; } elsif ($osname eq '') { # the following is regrettably gnarly, but it seems to be the only way # to not get ugly error messages if uname can't be found. # Hmmm, BSD/OS 2.0's uname -a is excessively verbose. Let's try it # with switches first. eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)"; if ($osname =~ /not found/i) { $osname = "(something posixy with no uname)"; } elsif ($@ ne "" || $?) { eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)"; if ($@ ne "" || $?) { $osname = "(something posixy)"; } } } if (! $short_filenames) { chdir ("..") or &error ("Couldn't chdir to ..: $!\n", 1); unlink (".ostest>ick"); rmdir (".ostest") or &error ("Couldn't rmdir .ostest: $!\n", 1); } } sub parse_command_line { @argv = @_; # use @ARGV if no args were passed in if (@argv == 0) { @argv = @ARGV; } # look at each option; if we don't recognize it, maybe the suite-specific # command line parsing code will... while (@argv) { $option = shift @argv; if ($option =~ /^-usage$/i) { &print_usage; exit 0; } if ($option =~ /^-(h|help)$/i) { &print_help; exit 0; } if ($option =~ /^-debug$/i) { print "\nDEBUG ON\n"; $debug = 1; } elsif ($option =~ /^-profile$/i) { $profile = 1; } elsif ($option =~ /^-verbose$/i) { $verbose = 1; } elsif ($option =~ /^-detail$/i) { $detail = 1; $verbose = 1; } elsif ($option =~ /^-keep$/i) { $keep = 1; } elsif (&valid_option($option)) { # The suite-defined subroutine takes care of the option } elsif ($option =~ /^-/) { print "Invalid option: $option\n"; &print_usage; exit 0; } else { # must be the name of a test $option =~ s/\.pl$//; push(@TESTS,$option); } } } sub max { my $num = shift @_; my $newnum; while (@_) { $newnum = shift @_; if ($newnum > $num) { $num = $newnum; } } return $num; } sub print_centered { my ($width, $string) = @_; if (length ($string)) { my $pad = " " x ( ($width - length ($string) + 1) / 2); print "$pad$string"; } } sub print_banner { # $testee is suite-defined my $info = "Running tests for $testee on $osname"; my $len = &max (length($info), length($testee_version), 77) + 2; my $line = ("-" x $len) . "\n"; &print_centered ($len, $line); &print_centered ($len, $info."\n"); &print_centered ($len, $testee_version); &print_centered ($len, $line); print "\n"; } sub run_all_tests { # Make sure we always run the tests from the current directory unshift(@INC, cwd()); $categories_run = 0; # Make a copy of STDIN so we can reset it open(INCOPY, "<&STDIN"); # Leave enough space in the extensions to append a number, even # though it needs to fit into 8+3 limits. if ($short_filenames) { $logext = 'l'; $diffext = 'd'; $baseext = 'b'; $runext = 'r'; $extext = ''; } else { $logext = 'log'; $diffext = 'diff'; $baseext = 'base'; $runext = 'run'; $extext = $osname eq 'VMS' ? '_' : '.'; } $lasttest = ''; # $testname is published foreach $testname (sort @TESTS) { # Skip duplicates on VMS caused by logical name search lists. next if $testname eq $lasttest; $lasttest = $testname; $suite_passed = 1; # reset by test on failure $num_of_logfiles = 0; $num_of_tmpfiles = 0; $description = ""; $details = ""; $old_makefile = undef; $testname =~ s/^$scriptpath$pathsep//; $testname =~ s/(\.pl|\.perl)$//; $perl_testname = File::Spec->catfile($scriptpath, $testname); -f $perl_testname or die "Invalid test: $testname\n\n"; local $testpath = File::Spec->catdir($workpath, $testname); remove_directory_tree($testpath); mkdir($testpath, 0777) or &error("Couldn't mkdir $testpath: $!\n", 1); setup_for_test(); $output = "........................................................ "; substr($output, 0, length($testname)) = "$testname "; print $output; $tests_run = 0; $tests_passed = 0; # Run the test! chdir($testpath) or error("Can't change to $testpath: $!\n", 1); $code = do $perl_testname; chdir($cwd) or error("Can't change back to $cwd: $!\n", 1); # Reset STDIN from the copy in case it was changed open(STDIN, "<&INCOPY"); ++$categories_run; $total_tests_run += $tests_run; $total_tests_passed += $tests_passed; # How did it go? if (!defined($code)) { # Failed to parse or called die if (length ($@)) { warn "\n*** Test died ($testname): $@\n"; } else { warn "\n*** Couldn't parse $perl_testname\n"; } $status = "FAILED ($tests_passed/$tests_run passed)"; $some_test_failed = 1; } elsif ($code == -1) { # Skipped... not supported $status = "N/A"; --$categories_run; remove_directory_tree($testpath); } elsif ($code != 1) { # Bad result... this shouldn't really happen. Usually means that # the suite forgot to end with "1;". warn "\n*** Test returned $code\n"; $status = "FAILED ($tests_passed/$tests_run passed)"; $some_test_failed = 1; } elsif ($tests_run == 0) { # Nothing was done!! $status = "FAILED (no tests found!)"; $some_test_failed = 1; } elsif ($tests_run > $tests_passed) { # Lose! $status = "FAILED ($tests_passed/$tests_run passed)"; $some_test_failed = 1; } else { # Win! ++$categories_passed; $status = "ok ($tests_passed passed)"; # Clean up if (!$keep) { remove_directory_tree($testpath); } } # If the verbose option has been specified, then a short description # of each test is printed before displaying the results of each test # describing WHAT is being tested. if ($verbose) { if ($detail) { print "\nWHAT IS BEING TESTED\n"; print "--------------------"; } print "\n\n$description\n\n"; } # If the detail option has been specified, then the details of HOW # the test is testing what it says it is testing in the verbose output # will be displayed here before the results of the test are displayed. if ($detail) { print "\nHOW IT IS TESTED\n"; print "----------------"; print "\n\n$details\n\n"; } print "$status\n"; } close(INCOPY); } # Deletes all filenames that are sent to it. sub rmfiles { return (unlink @_); } sub print_standard_usage { my ($plname, @moreusage) = @_; print "usage:\t$plname [testname] [-verbose] [-detail] [-keep]\n"; print "\t\t\t[-profile] [-usage] [-help] [-debug]\n"; foreach (@moreusage) { print "\t\t\t$_\n"; } } sub print_standard_help { my (@morehelp) = @_; my $t = " "; my $line = "Test Driver For $testee"; print "$line\n"; $line = "=" x length ($line); print "$line\n"; print_usage(); print "\ntestname\n" . "${t}You may, if you wish, run only ONE test if you know the name\n" . "${t}of that test and specify this name anywhere on the command\n" . "${t}line. Otherwise ALL existing tests in the scripts directory\n" . "${t}will be run.\n" . "-verbose\n" . "${t}If this option is given, a description of every test is\n" . "${t}displayed before the test is run. (Not all tests may have\n" . "${t}descriptions at this time)\n" . "-detail\n" . "${t}If this option is given, a detailed description of every\n" . "${t}test is displayed before the test is run. (Not all tests\n" . "${t}have descriptions at this time)\n" . "-profile\n" . "${t}If this option is given, then the profile file\n" . "${t}is added to other profiles every time $testee is run.\n" . "${t}This option only works on VOS at this time.\n" . "-keep\n" . "${t}You may give this option if you DO NOT want ANY\n" . "${t}of the files generated by the tests to be deleted. \n" . "${t}Without this option, all files generated by the test will\n" . "${t}be deleted IF THE TEST PASSES.\n" . "-debug\n" . "${t}Use this option if you would like to see all of the system\n" . "${t}calls issued and their return status while running the tests\n" . "${t}This can be helpful if you're having a problem adding a test\n" . "${t}to the suite, or if the test fails!\n"; foreach $line (@morehelp) { my $tline = $line; if (substr ($tline, 0, 1) eq "\t") { substr ($tline, 0, 1) = $t; } print "$tline\n"; } } ####################################################################### ########### Generic Test Driver Subroutines ########### ####################################################################### sub get_caller { my $depth = defined ($_[0]) ? $_[0] : 1; my ($pkg, $filename, $linenum) = caller ($depth + 1); return "$filename: $linenum"; } sub error { my $message = $_[0]; my $caller = &get_caller (1); if (defined ($_[1])) { $caller = &get_caller ($_[1] + 1) . " -> $caller"; } die "$caller: $message"; } sub compare_answer_vms { my ($kgo, $log) = @_; # VMS has extra blank lines in output sometimes. # Ticket #41760 $log =~ s/\n\n+/\n/gm; $log =~ s/\A\n+//g; return 1 if ($kgo eq $log); # VMS adding a "Waiting for unfinished jobs..." # Remove it for now to see what else is going on. $log =~ s/^.+\*\*\* Waiting for unfinished jobs.+$//m; $log =~ s/\n\n/\n/gm; $log =~ s/^\n+//gm; return 1 if ($log eq $kgo); # VMS wants target device to exist or generates an error, # Some test targets look like VMS devices and trip this. $log =~ s/^.+\: no such device or address.*$//gim; $log =~ s/\n\n/\n/gm; $log =~ s/^\n+//gm; return 1 if ($log eq $kgo); # VMS error message has a different case $log =~ s/no such file /No such file /gm; return 1 if ($log eq $kgo); # VMS is putting comas instead of spaces in output $log =~ s/,/ /gm; return 1 if ($log eq $kgo); # VMS Is sometimes adding extra leading spaces to output? { (my $mlog = $log) =~ s/^ +//gm; return 1 if ($mlog eq $kgo); } # VMS port not handling POSIX encoded child status # Translate error case it for now. $log =~ s/0x1035a00a/1/gim; return 1 if ($log =~ /\Q$kgo\E/i); $log =~ s/0x1035a012/2/gim; return 1 if ($log eq $kgo); # Tests are using a UNIX null command, temp hack # until this can be handled by the VMS port. # ticket # 41761 $log =~ s/^.+DCL-W-NOCOMD.*$//gim; $log =~ s/\n\n+/\n/gm; $log =~ s/^\n+//gm; return 1 if ($log eq $kgo); # Tests are using exit 0; # this generates a warning that should stop the make, but does not $log =~ s/^.+NONAME-W-NOMSG.*$//gim; $log =~ s/\n\n+/\n/gm; $log =~ s/^\n+//gm; return 1 if ($log eq $kgo); # VMS is sometimes adding single quotes to output? $log =~ s/\'//gm; return 1 if ($log eq $kgo); # And missing an extra space in output $kgo =~ s/\h\h+/ /gm; return 1 if ($log eq $kgo); # VMS adding ; to end of some lines. $log =~ s/;\n/\n/gm; return 1 if ($log eq $kgo); # VMS adding trailing space to end of some quoted lines. $log =~ s/\h+\n/\n/gm; return 1 if ($log eq $kgo); # And VMS missing leading blank line $kgo =~ s/\A\n//g; return 1 if ($log eq $kgo); # Unix double quotes showing up as single quotes on VMS. $kgo =~ s/\"//g; return 1 if ($log eq $kgo); return 0; } sub convert_answer_zos { my ($log) = @_; # z/OS emits "Error 143" or "SIGTERM" instead of terminated $log =~ s/Error 143/Terminated/igm; $log =~ s/SIGTERM/Terminated/igm; # z/OS error messages have a prefix $log =~ s/EDC5129I No such file or directory\./No such file or directory/igm; $log =~ s/FSUM7351 not found/not found/igm; return $log; } sub compare_answer { my ($kgo, $log) = @_; my ($mkgo, $mlog); # For make, get rid of any time skew error before comparing--too bad this # has to go into the "generic" driver code :-/ $log =~ s/^.*modification time .*in the future.*\n//igm; $log =~ s/^.*clock skew detected.*\n//igm; return 1 if ($log eq $kgo); # Get rid of newline differences, forever $kgo =~ s,\r\n,\n,gs; $log =~ s,\r\n,\n,gs; return 1 if ($log eq $kgo); # Keep the originals in case it's a regex $mkgo = $kgo; $mlog = $log; # z/OS has quirky outputs if ($osname eq 'os390') { $mlog = convert_answer_zos($mlog); return 1 if ($mlog eq $kgo); } # Some versions of Perl on Windows use /c instead of C: $mkgo =~ s,\b([A-Z]):,/\L$1,g; $mlog =~ s,\b([A-Z]):,/\L$1,g; return 1 if ($mlog eq $mkgo); # See if it is a backslash problem (only on W32?) $mkgo =~ tr,\\,/,; $mlog =~ tr,\\,/,; return 1 if ($mlog eq $mkgo); # VMS is a whole thing... return 1 if ($osname eq 'VMS' && compare_answer_vms($kgo, $log)); # See if the answer might be a regex. if ($kgo =~ m,^/(.+)/$,) { # Check the regex against both the original and modified strings return 1 if ($log =~ /$1/); return 1 if ($mlog =~ /$1/); } return 0; } my %old_tempfiles = (); sub compare_output { my ($answer, $logfile) = @_; my ($slurp, $matched, $extra) = ('', 0, 0); ++$tests_run; # Check to see if any temporary files were leftover after the run completes my @tf = (); foreach my $file (glob(File::Spec->catfile($temppath, "*"))) { if (!exists $old_tempfiles{$file}) { push @tf, $file; $old_tempfiles{$file} = 1; } } if (@tf) { open (LOGFILE, '>>', $logfile) or die "Cannot open log file $logfile: $!\n"; print LOGFILE "Leftover temporary files: @tf\n"; close (LOGFILE); $extra = 1; } if (! defined $answer) { print "Ignoring output ........ " if $debug; $matched = 1; } else { print "Comparing output ........ " if $debug; $matched = compare_answer($answer, &read_file_into_string ($logfile)); } my $base = get_basefile(); my $run = get_runfile(); my $diff = get_difffile(); my %e = ('base' => File::Spec->catdir($testpath, $base)); if (! $matched) { &create_file($base, $answer); &create_file($run, $command_string); $e{'run'} = File::Spec->catdir($testpath, $run); } if ($matched && $test_passed && !$extra) { print "ok\n" if $debug; ++$tests_passed; return 1; } if (! $matched) { # Create the difference file if ($diff_name) { run_command_with_output($diff, "$diff_name -c $base $logfile"); } else { create_file($diff, "Log file $logfile differs from base file $base\n"); } $e{'diff'} = File::Spec->catdir($testpath, $diff); } push @failure_info, \%e; return 0; } sub read_file_into_string { my ($filename) = @_; my $oldslash = $/; undef $/; open (RFISFILE, '<', $filename) or return ""; my $slurp = ; close (RFISFILE); $/ = $oldslash; return $slurp; } my @OUTSTACK = (); my @ERRSTACK = (); sub attach_default_output { my ($filename) = @_; if ($vos) { my $code = system "++attach_default_output_hack $filename"; $code == -2 or &error ("ado death\n", 1); return 1; } my $dup = undef; open($dup, '>&', STDOUT) or error("ado: $! duping STDOUT\n", 1); push @OUTSTACK, $dup; $dup = undef; open($dup, '>&', STDERR) or error("ado: $! duping STDERR\n", 1); push @ERRSTACK, $dup; open(STDOUT, '>', $filename) or error("ado: $filename: $!\n", 1); open(STDERR, ">&STDOUT") or error("ado: $filename: $!\n", 1); } # close the current stdout/stderr, and restore the previous ones from # the "stack." sub detach_default_output { if ($vos) { my $code = system "++detach_default_output_hack"; $code == -2 or &error ("ddoh death\n", 1); return 1; } @OUTSTACK or error("default output stack has flown under!\n", 1); close(STDOUT); close(STDERR) unless $osname eq 'VMS'; open (STDOUT, '>&', pop @OUTSTACK) or error("ddo: $! duping STDOUT\n", 1); open (STDERR, '>&', pop @ERRSTACK) or error("ddo: $! duping STDERR\n", 1); } sub _run_with_timeout { my $code; if ($osname eq 'VMS') { #local $SIG{ALRM} = sub { # my $e = $ERRSTACK[0]; # print $e "\nTest timed out after $test_timeout seconds\n"; # die "timeout\n"; #}; #alarm $test_timeout; system(@_); #alarm 0; my $severity = ${^CHILD_ERROR_NATIVE} & 7; $code = 0; if (($severity & 1) == 0) { $code = 512; } # Get the vms status. my $vms_code = ${^CHILD_ERROR_NATIVE}; # Remove the print status bit $vms_code &= ~0x10000000; # Posix code translation. if (($vms_code & 0xFFFFF000) == 0x35a000) { $code = (($vms_code & 0xFFF) >> 3) * 256; } } elsif ($port_type eq 'W32' && $^O ne 'msys') { # Using ActiveState Perl (?) my $pid = system(1, @_); $pid > 0 or die "Cannot execute $_[0]: $!\n"; local $SIG{ALRM} = sub { my $e = $ERRSTACK[0]; print $e "\nTest timed out after $test_timeout seconds\n"; kill -9, $pid; die "timeout\n"; }; alarm $test_timeout; my $r = waitpid($pid, 0); alarm 0; $r == -1 and die "No such pid: $pid\n"; # This shouldn't happen since we wait forever or timeout via SIGALRM $r == 0 and die "No process exited.\n"; $code = $?; } else { my $pid = fork(); if (! $pid) { exec(@_) or die "exec: Cannot execute $_[0]: $!\n"; } local $SIG{ALRM} = sub { my $e = $ERRSTACK[0]; print $e "\nTest timed out after $test_timeout seconds\n"; # Resend the alarm to our process group to kill the children. $SIG{ALRM} = 'IGNORE'; kill -14, $$; die "timeout\n"; }; alarm $test_timeout; my $r = waitpid($pid, 0); alarm 0; $r == -1 and die "No such pid: $pid\n"; # This shouldn't happen since we wait forever or timeout via SIGALRM $r == 0 and die "No process exited.\n"; $code = $?; } return $code; } # This runs a command without any debugging info. sub _run_command { my $orig = $SIG{ALRM}; my $code = eval { _run_with_timeout(@_); }; $SIG{ALRM} = $orig; # Reset then environment so that it's clean for the next test. resetENV(); if ($@) { # The eval failed. If it wasn't SIGALRM then die. $@ eq "timeout\n" or die "Command failed: $@"; $code = 14; } return $code; } # run one command (passed as a list of arg 0 - n), returning 0 on success # and nonzero on failure. sub run_command { print "\nrun_command: @_\n" if $debug; my $code = _run_command(@_); print "run_command returned $code.\n" if $debug; print "vms status = ${^CHILD_ERROR_NATIVE}\n" if $debug and $osname eq 'VMS'; return $code; } # run one command (passed as a list of arg 0 - n, with arg 0 being the # second arg to this routine), returning 0 on success and non-zero on failure. # The first arg to this routine is a filename to connect to the stdout # & stderr of the child process. sub run_command_with_output { my $filename = shift; print "\nrun_command_with_output($filename,$runname): @_\n" if $debug; &attach_default_output ($filename); my $code = eval { _run_command(@_) }; my $err = $@; &detach_default_output; $err and die $err; print "run_command_with_output returned $code.\n" if $debug; print "vms status = ${^CHILD_ERROR_NATIVE}\n" if $debug and $osname eq 'VMS'; return $code; } # performs the equivalent of an "rm -rf" on the first argument. Like # rm, if the path ends in /, leaves the (now empty) directory; otherwise # deletes it, too. sub remove_directory_tree { my ($targetdir) = @_; my ($nuketop) = 1; my $ch = substr ($targetdir, length ($targetdir) - 1); if ($ch eq "/" || $ch eq $pathsep) { $targetdir = substr ($targetdir, 0, length ($targetdir) - 1); $nuketop = 0; } -e $targetdir or return 1; &remove_directory_tree_inner ("RDT00", $targetdir) or return 0; if ($nuketop && !rmdir ($targetdir)) { print "Cannot remove $targetdir: $!\n"; return 0; } return 1; } sub remove_directory_tree_inner { my ($dirhandle, $targetdir) = @_; opendir ($dirhandle, $targetdir) or return 0; my $subdirhandle = $dirhandle; $subdirhandle++; while (my $object = readdir ($dirhandle)) { $object =~ /^(\.\.?|CVS|RCS)$/ and next; $object = "$targetdir$pathsep$object"; lstat ($object); if (-d _ && &remove_directory_tree_inner ($subdirhandle, $object)) { if (!rmdir($object)) { print "Cannot remove $object: $!\n"; return 0; } } else { if ($osname ne 'VMS') { if (!unlink $object) { print "Cannot unlink $object: $!\n"; return 0; } } else { # VMS can have multiple versions of a file. 1 while unlink $object; } } } closedir ($dirhandle); return 1; } # We used to use this behavior for this function: # #sub touch #{ # my (@filenames) = @_; # my $now = time; # # foreach my $file (@filenames) { # utime ($now, $now, $file) # or (open (TOUCHFD, '>>', $file) and close (TOUCHFD)) # or &error ("Couldn't touch $file: $!\n", 1); # } # return 1; #} # # But this behaves badly on networked filesystems where the time is # skewed, because it sets the time of the file based on the _local_ # host. Normally when you modify a file, it's the _remote_ host that # determines the modtime, based on _its_ clock. So, instead, now we open # the file and write something into it to force the remote host to set # the modtime correctly according to its clock. # sub touch { foreach my $file (@_) { (open(T, '>>', $file) and print(T "\n") and close(T)) or &error("Couldn't touch $file: $!\n", 1); } return @_; } # Touch with a time offset. To DTRT, call touch() then use stat() to get the # access/mod time for each file and apply the offset. sub utouch { my $off = shift; &touch(@_); foreach my $f (@_) { my @s = stat($f); utime($s[8]+$off, $s[9]+$off, $f); } return @_; } # open a file, write some stuff to it, and close it. sub create_file { my ($filename, @lines) = @_; open (CF, '>', $filename) or &error ("Couldn't open '$filename': $!\n", 1); foreach $line (@lines) { print CF $line; } close (CF); } # create a directory tree described by an associative array, wherein each # key is a relative pathname (using slashes) and its associated value is # one of: # DIR indicates a directory # FILE:contents indicates a file, which should contain contents +\n # LINK:target indicates a symlink, pointing to $basedir/target # The first argument is the dir under which the structure will be created # (the dir will be made and/or cleaned if necessary); the second argument # is the associative array. sub create_dir_tree { my ($basedir, %dirtree) = @_; &remove_directory_tree ("$basedir"); mkdir ($basedir, 0777) or &error ("Couldn't mkdir $basedir: $!\n", 1); foreach my $path (sort keys (%dirtree)) { if ($dirtree {$path} =~ /^DIR$/) { mkdir ("$basedir/$path", 0777) or &error ("Couldn't mkdir $basedir/$path: $!\n", 1); } elsif ($dirtree {$path} =~ /^FILE:(.*)$/) { &create_file ("$basedir/$path", $1 . "\n"); } elsif ($dirtree {$path} =~ /^LINK:(.*)$/) { symlink ("$basedir/$1", "$basedir/$path") or &error ("Couldn't symlink $basedir/$path -> $basedir/$1: $!\n", 1); } else { &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1); } } if ($just_setup_tree) { die "Tree is setup...\n"; } } # compare a directory tree with an associative array in the format used # by create_dir_tree, above. # The first argument is the dir under which the structure should be found; # the second argument is the associative array. sub compare_dir_tree { my ($basedir, %dirtree) = @_; my $bogus = 0; opendir (DIR, $basedir) or &error ("Couldn't open $basedir: $!\n", 1); my @allfiles = grep (!/^(\.\.?|CVS|RCS)$/, readdir (DIR) ); closedir (DIR); if ($debug) { print "dirtree: (%dirtree)\n$basedir: (@allfiles)\n"; } foreach my $path (sort keys (%dirtree)) { if ($debug) { print "Checking $path ($dirtree{$path}).\n"; } my $found = 0; foreach my $i (0 .. $#allfiles) { if ($allfiles[$i] eq $path) { splice (@allfiles, $i, 1); # delete it if ($debug) { print " Zapped $path; files now (@allfiles).\n"; } lstat ("$basedir/$path"); $found = 1; last; } } if (!$found) { print "compare_dir_tree: $path does not exist.\n"; $bogus = 1; next; } if ($dirtree {$path} =~ /^DIR$/) { if (-d _ && opendir (DIR, "$basedir/$path") ) { my @files = readdir (DIR); closedir (DIR); @files = grep (!/^(\.\.?|CVS|RCS)$/ && ($_ = "$path/$_"), @files); push (@allfiles, @files); if ($debug) { print " Read in $path; new files (@files).\n"; } } else { print "compare_dir_tree: $path is not a dir.\n"; $bogus = 1; } } elsif ($dirtree {$path} =~ /^FILE:(.*)$/) { if (-l _ || !-f _) { print "compare_dir_tree: $path is not a file.\n"; $bogus = 1; next; } if ($1 ne "*") { my $contents = &read_file_into_string ("$basedir/$path"); if ($contents ne "$1\n") { print "compare_dir_tree: $path contains wrong stuff." . " Is:\n$contentsShould be:\n$1\n"; $bogus = 1; } } } elsif ($dirtree {$path} =~ /^LINK:(.*)$/) { my $target = $1; if (!-l _) { print "compare_dir_tree: $path is not a link.\n"; $bogus = 1; next; } my $contents = readlink ("$basedir/$path"); $contents =~ tr/>/\//; my $fulltarget = "$basedir/$target"; $fulltarget =~ tr/>/\//; if (!($contents =~ /$fulltarget$/)) { if ($debug) { $target = $fulltarget; } print "compare_dir_tree: $path should be link to $target, " . "not $contents.\n"; $bogus = 1; } } else { &error ("Bogus dirtree type: \"$dirtree{$path}\"\n", 1); } } if ($debug) { print "leftovers: (@allfiles).\n"; } foreach my $file (@allfiles) { print "compare_dir_tree: $file should not exist.\n"; $bogus = 1; } return !$bogus; } # this subroutine generates the prefix name used to keep tmp filenames, # log filenames, etc., unique. sub get_prefix { my ($num) = @_; return sprintf("t%03d.", $num); } # just like logfile, only a generic tmp filename for use by the test. # they are automatically cleaned up unless -keep was used, or the test fails. # Pass an argument of 1 to return the same filename as the previous call. sub get_tmpfile { my ($no_increment) = @_; $num_of_tmpfiles += !$no_increment; return (&get_prefix ($num_of_tmpfiles) . $tmpfilesuffix); } # This subroutine returns a log filename with a number appended to # the end corresponding to how many logfiles have been created in the # current running test. An optional parameter may be passed (0 or 1). # If a 1 is passed, then it does NOT increment the logfile counter # and returns the name of the latest logfile. If either no parameter # is passed at all or a 0 is passed, then the logfile counter is # incremented and the new name is returned. sub get_logfile { my ($no_increment) = @_; $num_of_logfiles += !$no_increment; return (&get_prefix ($num_of_logfiles) . $logext); } # This subroutine returns a base (answer) filename with a number # appended to the end corresponding to how many logfiles (and thus # base files) have been created in the current running test. # NO PARAMETERS ARE PASSED TO THIS SUBROUTINE. sub get_basefile { return (&get_prefix ($num_of_logfiles) . $baseext); } # This subroutine returns a difference filename with a number appended # to the end corresponding to how many logfiles (and thus diff files) # have been created in the current running test. sub get_difffile { return (&get_prefix ($num_of_logfiles) . $diffext); } # This subroutine returns a command filename with a number appended # to the end corresponding to how many logfiles (and thus command files) # have been created in the current running test. sub get_runfile { return (&get_prefix ($num_of_logfiles) . $runext); } 1; ================================================ FILE: tests/thelp.pl ================================================ #!/usr/bin/env perl # -*-perl-*- # # This script helps us write tests in a portable way, without relying on a lot # of shell features. Since we already have Perl to run the tests, use that. # # The arguments represent a set of steps that will be run one at a time. # Each step consists of an operator and argument. # # It supports the following operators: # out : echo to stdout with a newline # raw : echo to stdout without adding anything # env : echo the value of the env.var. , or "" # file : echo to stdout AND create the file # dir : echo to stdout AND create the directory # rm : echo to stdout AND delete the file/directory # wait : wait for a file named to exist # exist : echo AND fail if a file named doesn't exist # noexist : echo AND fail if a file named exists # tmout : Change the timeout for waiting. Default is 4 seconds. # sleep : Sleep for seconds then echo # term : send SIGTERM to PID # fail : echo to stdout then exit with error code err # # If given -q only the "out", "raw", and "env" commands generate output. # Force flush $| = 1; my $quiet = 0; my $timeout = 10; sub op { my ($op, $nm) = @_; defined $nm or die "Missing value for $op\n"; if ($op eq 'out') { print "$nm\n"; return 1; } if ($op eq 'raw') { print "$nm"; return 1; } if ($op eq 'env') { print "$nm=" unless $quiet; if (exists $ENV{$nm}) { print "$ENV{$nm}\n"; } else { print "\n"; } return 1; } # Show the output before creating the file if ($op eq 'file') { print "file $nm\n" unless $quiet; open(my $fh, '>', $nm) or die "$nm: open: $!\n"; close(my $fh); return 1; } if ($op eq 'exist') { -f "$nm" || die "$nm: file should exist: $!\n"; print "exist $nm\n" unless $quiet; return 1 } if ($op eq 'noexist') { -f "$nm" && die "$nm: file exists\n"; print "noexist $nm\n" unless $quiet; return 1 } # Show the output before creating the directory if ($op eq 'dir') { print "dir $nm\n" unless $quiet; mkdir($nm) or die "$nm: mkdir: $!\n"; return 1; } # Show the output after removing the file if ($op eq 'rm') { if (-f $nm) { unlink($nm) or die "$nm: unlink: $!\n"; } elsif (-d $nm) { rmdir($nm) or die "$nm: rmdir: $!\n"; } else { die "$nm: not file or directory: $!\n"; } print "rm $nm\n" unless $quiet; return 1; } if ($op eq 'tmout') { $timeout = $nm; print "tmout $nm\n" unless $quiet; return 1; } # Show the output after the file exists if ($op eq 'wait') { my $start = time(); my $end = $start + $timeout; while (time() <= $end) { if (-f $nm) { print "wait $nm\n" unless $quiet; return 1; } select(undef, undef, undef, 0.1); } die "wait $nm: timeout after ".(time()-$start-1)." seconds\n"; } # Show the output after sleeping if ($op eq 'sleep') { sleep($nm); print "sleep $nm\n" unless $quiet; return 1; } if ($op eq 'term') { print "term $nm\n" unless $quiet; kill('TERM', $nm); return 1; } if ($op eq 'fail') { print "fail $nm\n" unless $quiet; exit($nm); } die("Invalid command: $op $nm\n"); } if (@ARGV && $ARGV[0] eq '-q') { $quiet = 1; shift; } while (@ARGV) { if (op($ARGV[0], $ARGV[1])) { shift; shift; } } exit(0); ================================================ FILE: vms_export_symbol_test.com ================================================ $! VMS_EXPORT_SYMBOL_TEST.COM $! $! Verify the VMS_EXPORT_SYMBOL.C module $! $! 22-May-2014 J. Malmberg $! $!========================================================================= $! $ cc/names=(as_is)/define=(DEBUG=1,_POSIX_EXIT=1) vms_export_symbol.c $! $ link vms_export_symbol $! $ delete vms_export_symbol.obj;* $! $! Need a foreign command to test. $ vms_export_symbol := $sys$disk:[]vms_export_symbol.exe $ save_export_symbol = vms_export_symbol $! $ vms_export_symbol $ if $severity .ne. 1 $ then $ write sys$output "Test program failed!"; $ endif $! $ if vms_export_symbol .nes. save_export_symbol $ then $ write sys$output "Test failed to restore foreign command!" $ endif $ if f$type(test_export_symbol) .nes. "" $ then $ write sys$output "Test failed to clear exported symbol!" $ endif $ if f$type(test_putenv_symbol) .nes. "" $ then $ write sys$output "Test failed to clear putenv exported symbol!" $ endif $!