List Info

Thread: make: target-depending prerequisites?




make: target-depending prerequisites?
country flaguser name
United States
2008-05-22 05:29:27
Hi,

I am trying to make the prerequisites of a target depend on
the current 
target by taking into account the current value of %.
In the example below, I have a main (tex) file, with
dependencies on a 
number of included files. These dependencies are indicated
in variables 
with the name of the main file, with '_depend' appended to
them. My 
strategy is then to create a variable DEPEND, depending on
%.pdf, which 
contains the name of the variable that contains these
dependencies, and 
use this variable in the prerequisites.
Unfortunately, this does not seem to work: $($(DEPEND)) does
contain the 
right dependency, yet it does not seem to be present in the

prerequisites. As a result, 'touching' the dependency does
not trigger a 
rebuild when I run make for the second time.
What might I be going wrong and/or is what I want to do even
possible?

Many thanks!
Yves


<-- Makefile -->

texfiles = main.tex

main_depend = section1.tex

all_pdf = $(texfiles:.tex=.pdf)

all: $(all_pdf)

%.pdf: DEPEND = $(:.pdf=)_depend
%.pdf: %.tex $($(DEPEND))
	echo "Extra dependencies:" $($(DEPEND))
	echo "All prerequisites:" $^
	touch $
	touch $($(DEPEND))


<-- end Makefile --->


Re: make: target-depending prerequisites?
country flaguser name
Sweden
2008-05-23 01:13:07
Yves <grazhopper+nggmail.com> wrote:
> My strategy is then to create a variable DEPEND

Do you really need the variables DEPEND and main_depend?

> Unfortunately, this does not seem to work:

My guess is that your problem is the order that make expands
variables and
evaluates rules. As you are now using your rules to expand
variables those
variables will not be expanded until after the rules have
been evaluated.

A more simple and working approach would be:

-8<-----------------------------
texfiles = main.tex

all_pdf = $(texfiles:%.tex=%.pdf)

all: $(all_pdf)

main.pdf: section1.tex

%.pdf: %.tex 
	echo "All prerequisites:" $^
	touch $
-8<-----------------------------

But maybe you have some other reason to have your variable
main_depend not
shown in your example?

regards Henrik
-- 
The address in the header is only to prevent spam. My real
address is:
hc3(at)poolhem.se Examples of addresses which go to
spammers:
rootlocalhost postmasterlocalhost


Re: make: target-depending prerequisites?
country flaguser name
United States
2008-05-23 02:50:41
> 
> But maybe you have some other reason to have your
variable main_depend not
> shown in your example?

The main reason for trying to do what I am trying to do is
the situation 
where I have multiple main-documents, each with its own
dependencies. If 
one of the depending files is updated, I only want the
relevant 
main-documents to be recompiled, and not all of them.

The following solution does the job, however, this means
duplication of 
the commands inside the main1.pdf and main2.pdf block. My
intent was 
thus to try to avoid this and parametrize into a single
%.pdf block.

-8<-----------------------------------------
texfiles = main1.tex main2.tex

main1_depend = section1.tex section3.tex
main2_depend = section2.tex section1.tex

all_pdf = $(texfiles:.tex=.pdf)

all: $(all_pdf)

main1.pdf: main1.tex $(main1_depend)
	echo "All prerequisites:" $^
	touch $

main2.pdf: main2.tex $(main2_depend)
	echo "All prerequisites:" $^
	touch $
-8<-----------------------------------------

Maybe there exist better solutions to achieve the desired
effect?

Best regards,
Yves

Re: make: target-depending prerequisites?
country flaguser name
Sweden
2008-05-24 19:41:35
Yves <grazhopper+nggmail.com> wrote:

>> But maybe you have some other reason to have your
variable main_depend not
>> shown in your example?
> 
> The main reason for trying to do what I am trying to do
is the situation 
> where I have multiple main-documents, each with its own
dependencies.

Again, do you really need those variables?

> If one of the depending files is updated, I only want
the relevant 
> main-documents to be recompiled, and not all of them.

Thats what make is good for.
 
> The following solution does the job, however, this
means duplication of 
> the commands inside the main1.pdf and main2.pdf block.
My intent was 
> thus to try to avoid this and parametrize into a single
%.pdf block.
> 
> -8<-----------------------------------------
> texfiles = main1.tex main2.tex
> 
> main1_depend = section1.tex section3.tex
> main2_depend = section2.tex section1.tex
> 
> all_pdf = $(texfiles:.tex=.pdf)
> 
> all: $(all_pdf)
> 
> main1.pdf: main1.tex $(main1_depend)
> 	echo "All prerequisites:" $^
> 	touch $
> 
> main2.pdf: main2.tex $(main2_depend)
> 	echo "All prerequisites:" $^
> 	touch $
> -8<-----------------------------------------
> 
> Maybe there exist better solutions to achieve the
desired effect?

I think it would be a cleaner solution if you skipped those
variables
and instead wrote something like this:

-8<-----------------------------------------
texfiles = main1.tex main2.tex

all_pdf = $(texfiles:.tex=.pdf)

all: $(all_pdf)

main1.pdf: section1.tex section3.tex

main2.pdf: section2.tex section1.tex

$(all_pdf): main%.pdf: main%.tex
	echo "All prerequisites:" $^
	touch $
-8<-----------------------------------------

regards Henrik
-- 
The address in the header is only to prevent spam. My real
address is:
hc3(at)poolhem.se Examples of addresses which go to
spammers:
rootlocalhost postmasterlocalhost


Re: make: target-depending prerequisites?
country flaguser name
United States
2008-05-26 07:59:22
> 
> I think it would be a cleaner solution if you skipped
those variables
> and instead wrote something like this:
> 
> -8<-----------------------------------------
> texfiles = main1.tex main2.tex
> 
> all_pdf = $(texfiles:.tex=.pdf)
> 
> all: $(all_pdf)
> 
> main1.pdf: section1.tex section3.tex
> 
> main2.pdf: section2.tex section1.tex
> 
> $(all_pdf): main%.pdf: main%.tex
> 	echo "All prerequisites:" $^
> 	touch $
> -8<-----------------------------------------

This is exactly what I was looking for. Thanks!

Yves

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )