4

I try the following makefile:

MAKEFLAGS += s
MAKEFLAGS += r

configure:

Then, when I run make, I get the following errors, as if it wants to compile 'configure', per some default implicit-rule:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13

If I run:

make -r

I do not get the above errors, Instead, I get:

make: Nothing to be done for 'configure'.

I got the idea to define MAKEFLAGS from here:

The 'MAKEFLAGS' variable can also be useful if you want to have certain options, such as '-k' (*note Summary of Options: Options Summary.), set each time you run 'make'. You simply put a value for 'MAKEFLAGS' in your environment. You can also set 'MAKEFLAGS' in a makefile, to specify additional flags that should also be in effect for that makefile. (Note that you cannot use 'MFLAGS' this way. That variable is set only for compatibility; 'make' does not interpret a value you set for it in any way.)

When 'make' interprets the value of '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 '-C', '-f', '-h', '-o', '-W', and their long-named versions are ignored; and there is no error for an invalid option).

1 Answers1

5

You don't say, but probably you're using a too-old version of GNU make. The ability to remove built-in rules by adding -r to MAKEFLAGS inside a makefile was added in GNU make 4.0, released in early October 2013.

It's important to remember that when you look at the manual on the GNU website you're looking at the documentation for the latest version of GNU make. It's better to read the documentation which comes with your distribution, as that will be the correct version of the manual associated with the version of GNU make that you're using.

ETA:

You have to use real flags in MAKEFLAGS. You can't just use the single letter versions. The only time single-letter options are allowed is in the first word of the variable value (I would have removed that too if it weren't required by the standard). You've written:

MAKEFLAGS += s
MAKEFLAGS += r

which gives a value for MAKEFLAGS (if you run make with no other options) of s r. Make will add a dash to the first word, but not any other words, so this is interpreted as -s r and the r is not the -r option. Also, if you happened to run make with an option, say make -k then MAKEFLAGS would be k s r and make would interpret that as -k s r, and then the -s flag would not be set either.

In short, just prepend your options with dashes always when you want to modify MAKEFLAGS:

MAKEFLAGS += -s
MAKEFLAGS += -r
MadScientist
  • 92,819
  • 9
  • 109
  • 136