Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAKEFLAGS drops leading "-" in 4.3 release #2

Open
chrisdonlan opened this issue Oct 6, 2020 · 5 comments
Open

MAKEFLAGS drops leading "-" in 4.3 release #2

chrisdonlan opened this issue Oct 6, 2020 · 5 comments

Comments

@chrisdonlan
Copy link

GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Minimal example of the issue:

# foo/makefile
echo-makeflags:
  @echo $(MAKEFLAGS)

Command line:

$: make -B echo-makeflags
B

When passing to submake, I have the following problem: suppose there are no makeflags?

# bar/makefile

relay-%:
ifdef $(MAKEFLAGS)
   some-command-relay-technique $* -$(MAKEFLAGS)
else
   some-command-relay-technique $*
endif

# fix

ifdef MAKEFLAGS
RELAYFLAGS+=-$(MAKEFLAGS)
endif

# but now RELAYFLAGS is introduced
@chrisdonlan
Copy link
Author

@madscientist is it ok if I look into this, or is it intended behavior?

@madscientist
Copy link
Contributor

This is how it's supposed to work, and has always worked since the dawn of time. When considering stuff like this it's always best to check the docs first; they are not always accurate but usually they are: https://www.gnu.org/software/make/manual/html_node/Options_002fRecursion.html

@madscientist
Copy link
Contributor

madscientist commented Oct 7, 2020

Just to be clear, it's wrong to include $(MAKEFLAGS) explicitly in any invocation of a sub-make. That's not how MAKEFLAGS is supposed to be used. From the POSIX standard for make we see:

Before the makefile(s) are read, all of the make utility command line options (except -f and -p) and make utility command line macro definitions (except any for the MAKEFLAGS macro), not already included in the MAKEFLAGS macro, shall be added to the MAKEFLAGS macro, quoted in an implementation-defined manner such that when MAKEFLAGS is read by another instance of the make command, the original macro's value is recovered. Other implementation-defined options and macros may also be added to the MAKEFLAGS macro. If this modifies the value of the MAKEFLAGS macro, or, if the MAKEFLAGS macro is modified at any subsequent time, the MAKEFLAGS environment variable shall be modified to match the new value of the MAKEFLAGS macro. The result of setting MAKEFLAGS in the Makefile is unspecified.

In short, when used to pass values to a recursive invocation of make the value of MAKEFLAGS is set by make itself to some format that is implementation-defined (not standardized) and passed through the environment to the sub-make. It's not intended to be used or interpreted by makefiles themselves. GNU make does specifically define some values which makes it possible for makefiles to query the contents of MAKEFLAGS reliably but that variable is still not intended to be used on the command line when invoking a sub-make. The value will be passed through the environment to the sub-make so this is not needed.

@chrisdonlan
Copy link
Author

@madscientist then this might be an XY problem. posted a stack question here: relay make to remote box

@chrisdonlan
Copy link
Author

@madscientist and thanks for the advice. Learning is a pell mell experience these days, has been a long time since I've looked at docs patiently, but make has earned that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants