[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: conditional prerequisite
From: |
Boris Kolpackov |
Subject: |
Re: conditional prerequisite |
Date: |
Thu, 5 Aug 2004 18:18:08 +0000 (UTC) |
User-agent: |
nn/6.6.5+RFC1522 |
address@hidden writes:
> Suppose, I have a dependency that extracts compilable information
> from a data source, and another rule that retrieves the data source
> e.g. from the web:
>
> info.h: info.txt
> sed -f info.sed info.txt > info.h
>
> info.txt:
> wget http://blabla/info.txt
>
> Now of course I want info.h to be made if info.txt exists and
> is newer.
> But it is also possible that info.txt is not available but info.h
> is still there. In this case I want it to be done and not try to
> retrieve info.txt (so I might actually leave out the second rule).
You can do something along these lines:
info.h: info.txt
sed -f info.sed info.txt > info.h
.PHONY: FORCE
info.txt.tmp: FORCE
wget -N -O $@ http://blabla/info.txt || echo >$@
info.txt: info.txt.tmp
if [ ( -s $< ) -a ( $< -nt $@ ) ]; then cp $< $@; fi
First, we unconditionally (FORCE) execute wget to obtain `info.txt'
if it is newer (-N). Note `|| echo >$@' part - we want empty file
if wget fails.
Second, if `info.txt.tmp' is not empty (-s $<) and newer than
`info.txt' ($< -nt $@) we copy it to `info.txt'. Note that make
will check timestamp of `info.txt' after executing the rule and
if it hasn't changed will not rebuild `info.h' (unless `info.h'
does not exist).
-boris