You're trying to use an automatic variable in a scope where it doesn't have the value you want. make -p is how I'd debug such:
martind@swiftboat:~/tmp/benjamin-cama-2017-08-03$ cat Makefile SUBDIR = $(@D) $(SUBDIR)/target-%: martind@swiftboat:~/tmp/benjamin-cama-2017-08-03$ make -n -p 2>&1 | grep target- | grep -v FEATURES /target-%: martind@swiftboat:~/tmp/benjamin-cama-2017-08-03$ The documentation, specifically https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html, speaks directly to this case: "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." -----Original Message----- From: Bug-make [mailto:bug-make-bounces+martin.dorey=hds....@gnu.org] On Behalf Of Benjamin Cama Sent: Thursday, August 03, 2017 08:37 To: Edward Welbourne Cc: bug-make@gnu.org Subject: Targets directory name concatenation strangeness OK, new subject as this specific behavior gets stranger. Le jeudi 03 août 2017 à 17:27 +0200, Benjamin Cama a écrit : > Le jeudi 03 août 2017 à 15:06 +0000, Edward Welbourne a écrit : > > Benjamin Cama (3 August 2017 17:00) > > > Well, I tried: > > > > > > SUBDIR = $(dir $@) > > > $(SUBDIR)/target-%: > > > … > > > > > > But it doesn't work. But without a slash (which is already present at > > > the end of $(SUBDIR)), it actually works!: > > > > > > SUBDIR = $(dir $@) > > > $(SUBDIR)target-%: > > > … > > > > > > Is this a bug? > > > > No: thing/target-suffix and thing//target-suffix are different names. > > They may be functionally equivalent, but make just sees different > > strings, one with a doubled-slash, the other with just one slash. > > Well, the thing is that passing target names to make with any number of > slashes normalize it to one, so I tended to think that the definition > followed the same normalization. Thanks for the explanation, then. Still, when I try to concatenate the slashless directory name and the file name with a slash in between, it does not work!: SUBDIR = $(@D) $(SUBDIR)/target-%: echo $(SUBDIR) does not work: $ make foo/target-1234 make: *** No rule to make target 'foo/target-1234'. Arrêt. Without the slash, it works: $ make foo/target-1234 echo foo foo This looks very strange to me. -- Benjamin Cama - Tél : 258 _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.gnu.org%2Fmailman%2Flistinfo%2Fbug-make&data=01%7C01%7Cmartin.dorey%40hds.com%7C6f15570d18bf401e55ec08d4da8588aa%7C18791e1761594f52a8d4de814ca8284a%7C0&sdata=Rq8TZAAnciZ2lN87viZ%2Byqu1j3rA6LmSRnxtZaSId7g%3D&reserved=0 _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make