logo
Tags down

shadow

my makefile's target-specific variable doesn't affect recursively expanded variables


By : user3851600
Date : October 16 2020, 11:12 AM
it should still fix some issue , The Make manual says this about target-specific variables
code :


Share : facebook icon twitter icon

Bug in GNU make: target-specific variables are not expanded in implicit rules?


By : Darkelflemurian
Date : March 29 2020, 07:55 AM
Any of those help As Beta has pointed out, this indeed isn't a bug in make since the limitation is described in the documentation (I guess I must have missed that particular part -- sorry).
In any case, I was actually able to work around this issue by doing something even simpler. Since all I need is to assign a variable based on the goal, I found that I can use the $(MAKECMDGOALS) variable in order to expand the build directory properly. Eliminating the $(CONFIG) variable and rewriting the Makefile as the following does exactly what I need:
code :
all:
        @echo specify configuration 'debug' or 'release'

OBJS := foo.o bar.o

BUILDDIR := .build/$(MAKECMDGOALS)

TARGET := $(addprefix $(BUILDDIR)/,$(OBJS))

debug: $(TARGET)
release: $(TARGET)

clean:
        rm -rf .build

$(BUILDDIR)/%.o: %.c
        @echo [$(BUILDDIR)/$*.o] should be [$@]
        @mkdir -p $(dir $@)
        $(CC) -c $< -o $@
$ make debug
[.build/debug/foo.o] should be [.build/debug/foo.o]
cc -c foo.c -o .build/debug/foo.o
[.build/debug/bar.o] should be [.build/debug/bar.o]
cc -c bar.c -o .build/debug/bar.o
$ make release
[.build/release/foo.o] should be [.build/release/foo.o]
cc -c foo.c -o .build/release/foo.o
[.build/release/bar.o] should be [.build/release/bar.o]
cc -c bar.c -o .build/release/bar.o
$ make debug
make: Nothing to be done for `debug'.
$ make release
make: Nothing to be done for `release'.

Define a recursively expanded variable using a variable whose name is computed from a simply expanded variable


By : Jeong Ah Leum
Date : March 29 2020, 07:55 AM
I wish this help you The short answer is there's no good solution for the question you are asking. It's not possible to stop expansion of a variable partway through and defer it until later. Not only that, but because you use the variable in a prerequisite list even if you could get the value of the $(c)_dependencies_src variable to contain just the variable references you wanted, in the very next line they would be completely expanded as part of the prerequisites list so it wouldn't gain you anything.
There's only one way to postpone the expansion of prerequisites and that's to use the secondary expansion feature. You would have to do something like:
code :
$(c)_src              := $(src)
$(c)_dependencies     := $(dependencies)

.SECONDEXPANSION
$(c) : $($(c)_src) $$(foreach dep, $$($$@_dependencies), $$($$(dep)_src))
        @echo $^
targets :=

### Bar
targets += bar
bar_c            := bar
bar_src          := bar_a.txt
bar_dependencies :=

### Foo
targets += foo
foo_c            := foo
foo_src          := foo_a.txt foo_b.txt
foo_dependencies := bar hoge

### Hoge
targets += hoge
hoge_c            := hoge
hoge_src          := hoge_a.txt
hoge_dependencies := bar

# Now build all the rules
include rules.mk
define make_c
$1 : $($1_src) $(foreach dep, $($1_dependencies), $($(dep)_src))
        @echo $$^
endif

$(foreach T,$(targets),$(eval $(call make_c,$T)))
targets := $(patsubst %_c,%,$(filter %_c,$(.VARIABLES)))

Obtaining Target-Specific Variables in included Makefiles


By : Seree Leo Khamplean
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can't do this. Target-specific variables are only set in the context of the recipe for the target. So, they have no value when the included makefile is parsed; that's not in the context of any particular rule.
Without knowing what the blah blah blah actually does in your makefile it's difficult to suggest alternatives. However, assuming you can't simplify this and it must be a set of make directives inside an ifdef, then you can use recursive make to do this:
code :
all: client server

client: APPS += client_app
server: APPS += server_app

client server:
        $(MAKE) APPS=$(APPS) $@.$(TARGET)

include ../Makefile.include

Not all variables recursively expanded in Makefile


By : Matt
Date : March 29 2020, 07:55 AM
hop of those help? Variables for a recipe are all expanded when the recipe begins to execute:
code :
#forcing `bash` to prevent `make` from using its builtin shell
$ strace -t -e execve -f make -d SHELL=/bin/bash test >output 2>&1
$ cat output # with irrelevant bits elided
17:20:48 execve("/usr/bin/make", ["make", "-d", "SHELL=/bin/bash", "test"], [/* 52 vars */]) = 0
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 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.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
 Considering target file 'Makefile'.
 <lots of lines omitted>
 No need to remake target 'Makefile'.
Updating goal targets....

# prepare the recipe
Considering target file 'test'.
 File 'test' does not exist.
 Finished prerequisites of target file 'test'.
Must remake target 'test'.

# expand $(DATE) the first time
strace: Process 32729 attached
[pid 32729] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "date"], [/* 52 vars */]) = 0
[pid 32729] 17:20:48 execve("/bin/date", ["date"], [/* 52 vars */]) = 0
[pid 32729] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32729, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---

# expand $(FILE) the first time
strace: Process 32730 attached
[pid 32730] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "mktemp"], [/* 52 vars */]) = 0
[pid 32730] 17:20:48 execve("/bin/mktemp", ["mktemp"], [/* 52 vars */]) = 0
[pid 32730] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32730, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---

# expand $(DATE) the second time
strace: Process 32731 attached
[pid 32731] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "date"], [/* 52 vars */]) = 0
[pid 32731] 17:20:48 execve("/bin/date", ["date"], [/* 52 vars */]) = 0
[pid 32731] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32731, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---

# expand $(FILE) the second time
strace: Process 32732 attached
[pid 32732] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "mktemp"], [/* 52 vars */]) = 0
[pid 32732] 17:20:48 execve("/bin/mktemp", ["mktemp"], [/* 52 vars */]) = 0
[pid 32732] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32732, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---

# begin executing the recipe
strace: Process 32733 attached
Putting child 0x5629c95cb0c0 (test) PID 32733 on the chain.
Live child 0x5629c95cb0c0 (test) PID 32733 
[pid 32733] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "echo Tue Jun 26 17:20:48 PDT 201"...], [/* 56 vars */]) = 0
Tue Jun 26 17:20:48 PDT 2018
[pid 32733] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32733, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Reaping winning child 0x5629c95cb0c0 PID 32733 
strace: Process 32734 attached
Live child 0x5629c95cb0c0 (test) PID 32734 
[pid 32734] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "echo /tmp/tmp.nWxcC4KeVf"], [/* 56 vars */]) = 0
/tmp/tmp.nWxcC4KeVf
[pid 32734] 17:20:48 +++ exited with 0 +++
17:20:48 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32734, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Reaping winning child 0x5629c95cb0c0 PID 32734 

# significant time doesn't pass until here
sleep 3
strace: Process 32735 attached
Live child 0x5629c95cb0c0 (test) PID 32735 
[pid 32735] 17:20:48 execve("/bin/bash", ["/bin/bash", "-c", "sleep 3"], [/* 56 vars */]) = 0
[pid 32735] 17:20:48 execve("/bin/sleep", ["sleep", "3"], [/* 56 vars */]) = 0
[pid 32735] 17:20:51 +++ exited with 0 +++
17:20:51 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32735, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Reaping winning child 0x5629c95cb0c0 PID 32735 
strace: Process 32736 attached
Live child 0x5629c95cb0c0 (test) PID 32736 
[pid 32736] 17:20:51 execve("/bin/bash", ["/bin/bash", "-c", "echo Tue Jun 26 17:20:48 PDT 201"...], [/* 56 vars */]) = 0
Tue Jun 26 17:20:48 PDT 2018
[pid 32736] 17:20:51 +++ exited with 0 +++
17:20:51 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32736, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Reaping winning child 0x5629c95cb0c0 PID 32736 
strace: Process 32737 attached
Live child 0x5629c95cb0c0 (test) PID 32737 
[pid 32737] 17:20:51 execve("/bin/bash", ["/bin/bash", "-c", "echo /tmp/tmp.QgNem5ezr0"], [/* 56 vars */]) = 0
/tmp/tmp.QgNem5ezr0
[pid 32737] 17:20:51 +++ exited with 0 +++
17:20:51 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32737, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Reaping winning child 0x5629c95cb0c0 PID 32737 
Removing child 0x5629c95cb0c0 PID 32737 from chain.
Successfully remade target file 'test'.
17:20:51 +++ exited with 0 +++

Partially expanding recursively expanded variables


By : audijenz
Date : March 29 2020, 07:55 AM
it helps some times Consider the following makefile example: , Well, you could do this:
code :
simplevar := $(varname)
val = $($(simplevar)-value)
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © bighow.org