help-make
[Top][All Lists]
Advanced

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

Re: help on simple makefile


From: John Calcote
Subject: Re: help on simple makefile
Date: Wed, 5 Apr 2017 15:49:16 -0600

Jarod,

You're trying to use make as a procedural language processor. Make is
a declarative language. With procedural languages, you describe tasks
that need to be done and the process for executing those tasks. With
declarative languages, you describe the relationships between input
objects and output objects and let make decide what needs to be done
and when to do it.

--------------
RDIR=.
RFILES:=$(wildcard $(RDIR)/*.txt)
SCRIPT=~/Desktop/python_script.py
OUTDIR=RESHAPE2
OUTFILES=$(patsubst %.txt,$(OUTDIR)/%.xls,$(RFILES))

.PHONY: clean all

all: $(OUTDIR) $(OUTFILES)

$(OUTDIR)/%.xls: %.txt
        $(SCRIPT) -i  $< -o $@

$(OUTDIR):
        test -d $@ || mkdir $@

clean:
        rm -rf $(OUTDIR)
--------------

Here, instead of writing a shell script to iterate files in $(RFILES),
we're telling make that there are a desired set of files in
$(OUTFILES) that end in .xls, and the way these can be made is by
running $(SCRIPT) on a corresponding .txt file in the parent directory
of the target output file.

The $(OUTDIR) rule just exists to ensure that the output directory
exists before make begins to try to locate any of the desired output
files.

Make also has built into it the ability to determine if a .txt file is
newer (based on date/time stamp) than it's corresponding .xls file and
re-execute $(SCRIPT) on just that file. With this Makefile, you could
prove this to yourself by running 'touch' against one of your .txt
files, then running make again. Make will only rebuild the xls file
that comes from that txt file because it can see that all the other
.xls files are already "up to date" (newer than their corresponding
.txt files).

There are a lot of other fancier things you can do with GNU make (or
even just generic make). This Makefile could easily be enhanced by
using more complex features of GNU make.

John

On Wed, Apr 5, 2017 at 2:39 PM, address@hidden <address@hidden> wrote:
> Hi there!! i have  some files .txt and I want to trasform all using a python 
> script to another output on new directory:
>
> SCRIPT=~/Desktop/python_script.py
> RDIR=.
> RFILES:=$(wildcard $(RDIR)/*.txt)
> .PHONY: clean all
>
>
> prepare:
>     mkdir RESHAPE2 ;\
>     for d in $(RFILES);\
>         do \
>         echo $(SCRIPT) -i  $$d -o RESHAPE2/%.xls  ;done
>
> mitico: $(RFILES)
>     @ echo $^|sed 's/.txt/.xls/g'
> listfiles:
>     (ls -ltr RESHAPE2/)
>
>
> clean:
>     rm -rf RESHAPE2/*.xls
>
>
>
> Could you please help me on translate on working  example.
>
> What I want to obtain is  execute the python script on file present on my 
> folder and output on RESHAPE2.
> thanks in advance for any help
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make



reply via email to

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