Scenario
I was running into some trouble trying to assign values from a command into a variable in a makefile. Using backtick notation seems to work fine, but as soon as I use the more modern $(pwd) notation, the value of the variable returns nothing.
$ cat Makefile
FOO=moo
BAR=$(pwd)
BAZ=`pwd`
all: foo bar baz
foo:
@echo foo:$(FOO)';'
bar:
@echo bar:$(BAR)';'
baz:
@echo baz:$(BAZ)';'
$ make all
foo:moo;
bar:;
baz:/home/mazunki;
As you can see, FOO and BAZ work as expected. But not BAR.
Problem
Let's look at my problem now, by adding some more examples. I'm skipping the echoing, as you get the idea.
$ cat Makefile
SHELL=/bin/env bash
FOO=dog
BAR=$(pwd)
BAZ=`pwd`
QUZ=`$(FOO)`/cat
ZOT=`\`FOO\``/owl
BIM=`$(BAZ)`/rat
BAM=`\`BAZ\``/pig
BUM=`BUM`/fox
all: foo bar baz quz zot bim bam bum
# targets for all the things
$ make
foo:dog;
bar:;
baz:/home/mazunki;
bash: dog: command not found
quz:/cat;
bash: FOO: command not found
zot:/owl;
bim:pwd/rat;
bash: BAZ: command not found
bam:/pig;
bash: BAZ: command not found
bum:/fox;
I really had hopes for BIM. But sadly, it only return the command which I wanted to run instead. I tried adding another layer of $() and/or `` to it, but the result is an empty output instead.
My desired output is what I'd get from running echo -n $(pwd)/rat in Bash. None of my tested examples allow me to do this. I want to be able to do this, as some of the commands I use for my preface variables are based on initial settings, as such:
# User settings
ROOT=`pwd`
SRCPATH=$(ROOT)/src/
OBJPATH=$(ROOT)/objects/
# Scripting
SRCFILES=`find $(SRCPATH) -name '*.ext' -printf '%p '`
OBJFILES=`find $(SRCPATH) -name '*.ext' -printf '$(OBJPATH)/%p ' | sed 's/^$(SRCPATH)/^$(OBJPATH)//g; s/.ext;/.obj;/g; s/;$//g'`
It might look kind of a convoluted scenario, but I'm doing this for two main reasons: I want it to be highly configurable, without having to edit the commands themselves, and also because I want to learn how to make Makefiles properly.