[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
determining prerequisite & dependent targets
From: |
gk |
Subject: |
determining prerequisite & dependent targets |
Date: |
Sun, 22 Jun 2003 12:53:04 -0700 |
I need to be able to determine the list of prerequisites, or dependent
targets, for any given target.
In my system, a single makefile approach is used, which includes many
makefiles. All targets (excluding phony targets) have an absolute path.
I have been using the following rules which work pretty well but I am not
happy with this approach because it depends on parsing the output of make
-p. If that output formatting ever changes, these rules will break.
I would like to know if there is a better way or how difficult would it be
to add such a query feature to make, via command line options or any other
tricks for accessing makes internal database directly.
Thanks.
# Makefile
.PHONY: FORCE
$(CURDIR)/foo1: $(CURDIR)/foo2
$(CURDIR)/foo1: $(CURDIR)/foo3
$(CURDIR)/foo2: $(CURDIR)/foo3
$(CURDIR)/foo%:
@echo $@
# echo the prerequisites of target /%
reqs./%: FORCE
@$(MAKE) -p /$* 2>/dev/null|sed -n -e 's%^/$(patsubst .,\.,$*):
\(.*\)%\1%p' -e '\%^/$(patsubst .,\.,$*):.*%q'
# echo the dependents of target /%
deps./%: FORCE
@$(MAKE) -p /$* 2>/dev/null|sed -n 's%^\(/.*\):.* /$(patsubst
.,\.,$*)\b.*%\1%p'
#eof
address@hidden junk]$ make reqs.$(pwd -P)/foo1
/usr/local/apache/htdocs/common/test/junk/foo2
/usr/local/apache/htdocs/common/test/junk/foo3
address@hidden junk]$ make reqs.$(pwd -P)/foo2
/usr/local/apache/htdocs/common/test/junk/foo3
address@hidden junk]$ make reqs.$(pwd -P)/foo3
address@hidden junk]$ make deps.$(pwd -P)/foo1
address@hidden junk]$ make deps.$(pwd -P)/foo2
/usr/local/apache/htdocs/common/test/junk/foo1
address@hidden junk]$ make deps.$(pwd -P)/foo3
/usr/local/apache/htdocs/common/test/junk/foo1
/usr/local/apache/htdocs/common/test/junk/foo2
address@hidden junk]$
- Greg Keraunen
http://www.xmake.org
- determining prerequisite & dependent targets,
gk <=