[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Newbie and not very techie - using GNU make for non-C-development ta

From: James Lawrence
Subject: RE: Newbie and not very techie - using GNU make for non-C-development tasks
Date: Mon, 07 Jul 2014 08:14:45 -0400

You've defined a rule on how to make out/%.txt but you haven't told it which
files in out/ that you want to make.

Try this:

        INPUTS:=$(wildcard in/*)
        TARGETS:=$(addprefix out/,$(notdir $(INPUTS)))

        $(info INPUTS are [$(INPUTS)])
        $(info TARGETS are [$(TARGETS)])

        out/%.txt: in/%.txt
                cat $< > $@

        .PHONY: all
        all: $(TARGETS)

        .PHONY: clean
                rm $(TARGETS)

I've added the intermediate variables and $(info ) calls just to illustrate
what is happening.

        1) The INPUTS variable gets the value of all the files in the input
        2) The TARGETS variable then converts the input names to the target
output names
        3) These values are printed by the next 2 lines. I surround the
value with [] so you can easily tell when a value is null.
        4) Then comes your pattern rule that defines how to change an input
to an output
        5) Then the 'all' rule which depends on $(TARGETS). Since TARGETS is
set to the names of all the files you expect to create, this will trigger
the Pattern rule

Note, I've added a clean rule to delete all the TARGETS in case you ever
decide you really want to clean them out and recreate all of them. This
might happen when you script that manipulates in to out changes.

I've also made both 'all' and 'clean' PHONY rules. It is complicated, but
you want to do it. To see why, create a file named 'all' in the current
directory without the phony rule.


-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of John
Sent: Monday, July 07, 2014 7:30 AM
To: address@hidden
Cc: address@hidden
Subject: Re: Newbie and not very techie - using GNU make for
non-C-development tasks

John Christopher wrote:
> I have the following Makefile:
> $ cat Makefile
> out/%.txt: in/%.txt
>         foo $<   >   $@
> This does not work as expected (I get an error message I do not

Paul Smith <address@hidden> replied:
> You may not understand it, but WE would probably understand it.
> If you told us what it was.

Right. Sorry.

$ ls in
file01.txt file02.txt file03.txt
$ ls out
$ cat Makefile
out/%.txt: in/%.txt
        sed 's/happy/glad/g' $< > $@
$ make
make: *** No targets. Stop.
$ ls out
$ vi Makefile         (changed % to *)
$ cat Makefile
out/*.txt: in/*.txt
        sed 's/happy/glad/g' $< > $@
$ make
sed 's/happy/glad/g' in/file01.txt > out/*.txt
$ ls out

Hope that's more clear. Thanks again for your help.

Help-make mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]