Home > Archive > Unix Programming > February 2007 > suffixes rule
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| auditory 2007-02-07, 4:10 am |
| i like to generate .out file from .txt file using make(GNU Make 3.81)
to do this, i tried:
#makefile
all: out.out
%.out: %.txt
cp $< $@
out.out: in.txt
#end of makefile
given in.txt, i just got:
make: Nothing to be done for `all'.
Alternative i tried,
#makefile
..SUFFIXES: .txt .out
..txt.out:
cp $< $@
all: out1.out
out1.out: in.txt
#end of makefile
i got the just same result as above.
What am I doing wrong?
| |
| Jens Thoms Toerring 2007-02-07, 8:05 am |
| auditory <pkyoung@gmail.com> wrote:
> i like to generate .out file from .txt file using make(GNU Make 3.81)
> to do this, i tried:
> all: out.out
> %.out: %.txt
> cp $< $@
Here you tell make how to create a .out file from a .txt file that
has the same name, e.g. how to make "xxx.out" from "xxx.txt".
> out.out: in.txt
And here you tell make that out.out needs to be made if it either
does not exist or if it's older than in.txt. But what you don't
tell make is how to do that. The only other rule there is just
says how to make "in.out" from "in.txt" or "out.out" from "out.txt"
but there's nothing that tells make how to create "out.out" from
"in.out", so it has no reason to use the other rule. If you change
this second rule to
out.out: in.out
cp $< $@
then make will check if there's a file "in.out" and, if this is
not the case, use the other rule to create it and, if this is done,
copy "in.out" to "out.out".
Of course, you could make things simpler by using a single rule
out.out: in.txt
cp $< $@
The use of rules where the target and the dependencies are des-
cribed via a '%' (or by suffix rules) only make sense if they have
a common name, i.e. if you would create "out.out" from "out.txt"
or "in.out" from "in.txt".
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
| |
| auditory 2007-02-07, 7:06 pm |
|
> The use of rules where the target and the dependencies are des-
> cribed via a '%' (or by suffix rules) only make sense if they have
> a common name, i.e. if you would create "out.out" from "out.txt"
> or "in.out" from "in.txt".
> Regards, Jens
Thank you, Jens.
Then is there no way to do this?
(when target and the dependency has no common name)
What actually i'd like to is as followings:
(cp replaced by some script)
#makefile
%.out: %.txt
cp $< $@
out1.out: ../dir1/in.txt
out2.out: ../dir2/in.txt
out3.out: ../dir3/in.txt
out4.out: ../dir4/in.txt
# and so on...
#end of makefile
At this point, what i can think of is:
to copy first all in.txt files into current directory with
proper name (out1.txt, out2.txt, etc)
| |
| Jens Thoms Toerring 2007-02-08, 4:11 am |
| auditory <pkyoung@gmail.com> wrote:
> What actually i'd like to is as followings:
> (cp replaced by some script)
> #makefile
> %.out: %.txt
> cp $< $@
> out1.out: ../dir1/in.txt
> out2.out: ../dir2/in.txt
> out3.out: ../dir3/in.txt
> out4.out: ../dir4/in.txt
> # and so on...
> #end of makefile
> At this point, what i can think of is:
> to copy first all in.txt files into current directory with
> proper name (out1.txt, out2.txt, etc)
Here's a solution I came up with. Probably not very elegant and,
if you're lucky, someone else has some better ideas...
---8<---------------------------------------------------------------------
TARGETS := $(patsubst ../dir%/in.txt,out%.out,$(wildcard ../dir*/in.txt))
..PHONY: all $(TARGETS)
all: $(TARGETS)
$(TARGETS):
@if [ $(patsubst out%.out,../dir%/in.txt,$@) -nt $@ ]; then \
echo "cp $(patsubst out%.out,../dir%/in.txt,$@) $@"; \
cp $(patsubst out%.out,../dir%/in.txt,$@) $@; \
fi
---8<---------------------------------------------------------------------
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
| |
| Henry Townsend 2007-02-08, 10:05 pm |
| auditory wrote:
> What actually i'd like to is as followings:
> (cp replaced by some script)
>
> #makefile
> %.out: %.txt
> cp $< $@
>
> out1.out: ../dir1/in.txt
> out2.out: ../dir2/in.txt
> out3.out: ../dir3/in.txt
> out4.out: ../dir4/in.txt
> # and so on...
This sounds like what vpath was intended for. Look up the vpath function
in the GNU make online manual.
|
|
|
|
|