On Tue, Aug 03, 2004 at 12:31:14PM +0200, Hyams Iftach wrote:
> The formed solution:
>
> LIST = $(wildcard *CDU*)
> LIST1 = $(subst CDU,CDU_1,$(LIST))
> LIST2 = $(subst CDU,CDU_2,$(LIST))
>
> all: $(LIST1) $(LIST2)
>
> $(LIST1): $(LIST)
> sed -e "s/CDU/CDU_1/g" $(subst CDU_1,CDU,$@) > $@
SED_1 = sed -e "s/CDU/CDU_1/g"
SED_2 = sed -e "s/CDU/CDU_2/g"
Or simpler:
set -x; \
for file in $(LIST); do \
$(SED_1) $$file >`echo $$file | $(SED_1)` \
done
But also see my next comment.
>
> $(LIST2): $(LIST)
> sed -e "s/CDU/CDU_2/g" $(subst CDU_2,CDU,$@) > $@
>
>
> Now the problem is the processing of the newly created
> files upon next execution. If something in the original
> changes - I don't care to remove all outputs and reprocess,
> otherwise, skip.
So what you get here is basically a glorified shell script. It would
have been much simpler to write it as a simple shell script and be done
with that.
However make can give you more than that: conditional execution and a
different sort of error notification. With a properly written makefile
it should be safe and relatively cheap to re-run make after you
corrected a small problem.
Some problems I can think of:
* some of the files in *CDU* will actually be directories
* some of the files in *CDU* will actually be dandling links
* re-running the script, or verifying that all has been done
The problems I could think of with the schema I proposed in my previous
mail were:
Problem 1:
how to create the original list of files. Maybe you have some
external way of doing it? E.g: feeding that list to a certain file
beforehand?
Let's try something:
LIST_ALL := $(wildcard *CDU*)
LIST := $(filter_out _1 _2,$(LIST_ALL)
# even a simple subst will do. patsubst will work just as well,
# naturally:
LIST1 := $(subst CDU,CDU_1,$(LIST)
LIST2 := $(subst CDU,CDU_2,$(LIST)
all: $(LIST1) $(LIST2)
# the following reduces duplication in rules. This will allow you to use
# $(NUM) as _1 or _2 in automatic targets, because per-target variables
# are inherited with dependencies
phoney1: $(LIST1)
phoney2: $(LIST2)
phoney1: NUM:=_1
phoney2: NUM:=_2
(that can also be done in a simple pipe in a shell script , of course)
Problem 2:
An pattern rule can only include one % . This means that automatic rules
cannot be used here (unless someone here has a better idea.
The following command is slightly better than the loop I used above as
it uses $? to remake only targets that need remaking:
# note: '=' and not ':=', as I use $(NUM) and $? which are target-specific
SED_N = sed -e 's/CDU/CDU$(NUM)/g'
COMMAND = \
set -x;\
for file in $?; do \
$(SED_N) <$$file >`echo $$file | $(SED_N)`; \
done
$(LIST2): $(LIST)
$(COMMAND)
$(LIST1): $(LIST)
$(COMMAND)
Thus if you add/update just one file and re-run make (or if make had an
error along the way and you re-run it after fixing the problem) you'll
only create the files need creating.
'set -x' is used to emulate make's error handling: stop as soon as
anything goes wrong. The operator should then fix the problem and re-run
'make'. Thus remaking should have a minimal overhead.
--
Tzafrir Cohen +---------------------------+
http://www.technion.ac.il/~tzafrir/ |vim is a mutt's best friend|
mailto:[EMAIL PROTECTED] +---------------------------+
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]