Evaluation of shell functions in recipes
hello! please keep our CC:s because we are not subscribed. i have found a bug in our (flashrom.org) makefile which may be a bug in make or its documentation. attached is a small test case makefile. the related documentation is http://www.gnu.org/s/hello/manual/make/Shell-Function.html and http://www.gnu.org/s/hello/manual/make/Reading-Makefiles.html the problem is that the shell function runs before any other commands (i.e. immediate). the documentation of the shell function states: "The commands run by calls to the shell function are run when the function calls are expanded." and from the "reading makefiles" section i would say that this should be deferred i.e. the commands of the recipe should be evaluated sequently. instead the shell functions are run first: - 2 is written to the test file - 4 is written to the test file (overwriting 2) after that the normal execution starts. this leads to the output (among other things) of "1 4 4 3 4". the expected output is "1 2 3 4" could someone please explain if the observed behavior is "right" and if we just read the docs wrong, or if they *are* wrong. thanks! -- Kind regards/Mit freundlichen Grüßen, Stefan Tauner makefile Description: Binary data ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
goals starting with a period followed by a slash
Hi, I was trying to avoid a recipe becoming the default goal by adding a . in front of its name. This worked as long as the target is just a name and not a complete path. This is because the code - ever since the initial commit in 1992 - checks for slashes in the target and ignores the dot/period if it finds one. read.c:1329 ff.: /* See if this target's name does not start with a '.', unless it contains a slash. */ if (*name == '.' && strchr (name, '/') == 0 #ifdef HAVE_DOS_PATHS && strchr (name, '\\') == 0 #endif ) continue; I don't know why it behaves differently with slashes in the goal and would love to hear a rationale for that (and it being mentioned in the documentation ;) The current documentation reads as follows (emphasis mine): > By default, the goal is the first target in the makefile (*not > counting targets that start with a period*). Also, I think there is a bug related to this that truncates the target name in the front. Suppose the following makefile: ./tmp/dot: touch $@ useless: touch $@ According to the documentation simply running "make" should execute the "useless" recipe and create a file named "useless" in the CWD. However, since the check above sees the dot goal as a legitimate target it tries to execute it... however something with the target name is wrong. The actual output shows that the first slash is slashed (pun intended) from the target name (make -d and -p confirms that too): $ make touch tmp/dot touch: cannot touch 'tmp/dot': No such file or directory make: *** [makefile:2: tmp/dot] Error 1 I have not tried to determine the exact cause of this or do further tests. KR -- Dipl.-Ing. Stefan Tauner Research and Development Embedded Systems Department University of Applied Sciences Technikum Wien Hoechstaedtplatz 6, 1200 Vienna, Austria T: +43 1 333 40 77-316 E: stefan.tau...@technikum-wien.at I: embsys.technikum-wien.at I: www.technikum-wien.at ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make
Re: goals starting with a period followed by a slash
On Thu, 02 Feb 2017 11:36:18 -0500 Paul Smith wrote: > On Thu, 2017-02-02 at 16:53 +0100, Stefan Tauner wrote: > > I don't know why it behaves differently with slashes in the goal and > > would love to hear a rationale for that (and it being mentioned in > > the documentation ;) > > The current documentation reads as follows (emphasis mine): > > > By default, the goal is the first target in the makefile (*not > > > counting targets that start with a period*). > > The documentation is wrong (or rather, incomplete). It's intended to > state that special targets are not considered as default targets. > > The POSIX spec defines special targets as "targets with names > consisting of a leading followed by one or more uppercase > letters". > > In GNU make we extend the characters that may appear in special > targets to include underscores, I think. > > But we don't allow slashes in special targets, so any target that > contains a slash is not a special target, and will be used as the > default target. Makes sense, thank you very much. My original objective was to disable the assignment of a default goal in a makefile that gets included by other makefiles, which provides a number of useful stuff including some recipes. I now simply resort to unsetting .DEFAULT_GOAL (with ":=") at the end of the included makefile and this seems to do the trick just fine. KR -- Dipl.-Ing. Stefan Tauner Research and Development Embedded Systems Department University of Applied Sciences Technikum Wien Hoechstaedtplatz 6, 1200 Vienna, Austria T: +43 1 333 40 77-316 E: stefan.tau...@technikum-wien.at I: embsys.technikum-wien.at I: www.technikum-wien.at ___ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make