Reputation: 462
Is it possible to render a makefile?
I have a difficult makefile with inclusions, and I need to debug it.
When I type make -f test.mk
and press Tab key, it shows all available targets, including those ones which were declared dynamically.
That means, make can render makefiles very quickly, so I'm asking if it is possible to save the rendered file somewhere.
define define_target
$(eval _target_name := $(1))
$(info Defining a target: $(_target_name))
$(_target_name):
@echo $(_target_name) triggererd.
endef
$(eval $(call define_target,test))
$(eval $(call define_target,echo))
all: test
all: echo
all:
@echo Done!
peter@peterpc:~/test$ make # Double Tab pressed here to trigger autocompletion
all echo test # All targets except the "all" were defined dynamically!
peter@peterpc:~/test$ make all
Defining a target: test
Defining a target: echo
test triggererd.
echo triggererd.
Done!
test:
@echo test triggered.
echo:
@echo echo triggered.
all: test
all: echo
all:
@echo Done!
Upvotes: 0
Views: 446
Reputation: 100966
The tab completion facility isn't directly provided by make. Someone has created a bash script that will do that for you... this comes as part of the bash_completion package. What this completion does is invoke make
with the -p
, -n
, and -q
options then parse the output to find the names of targets.
So, in short, you can "render" the makefile (for some definition of that) by running make -npq
and looking at the output. Be aware that this is not going to look like the output of a preprocessor, where it shows your exact makefile with expanded variables, etc. but otherwise identical. This will be a dump of make's internal data structures after all parsing is complete (although printed in a generally makefile-like format).
Upvotes: 2