[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: for loop in makefile
From: |
Paul D. Smith |
Subject: |
Re: for loop in makefile |
Date: |
11 Jul 2002 00:53:40 -0400 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
%% address@hidden (Wayne Throop) writes:
wt> : address@hidden (Ed Wong)
wt> : I need to have a simple loop in makefile to unzip and rename all the
wt> : nc*.gz files in current directory. The following is how I do it in
wt> : shell script and I need to put it in makefile. Anyone know how to do
wt> : it? Thanks in advance.
wt> :
wt> : for file in `ls nc*.gz`
wt> : do
wt> : base=`echo $file | awk -F. '{ print $1 }'`
wt> : $unzip $file
wt> : mv -f $base $base.txt
wt> : done
wt> One straightforward way is
wt> $(foreach f,$(basename $(wildcard nc*.gz)),gunzip $f.gz; mv -f $f
$f.txt;)
Lots of folks suggested straight translations of various forms, but you
might also consider actually _using_ the capabilities of make, rather
than just writing shell scripts (or the make equivalent).
For example, you can write an implicit (pattern) rule which knows how to
perform the above translation on one file, then use $(wildcard ...) for
example to find all the .gz files:
%.txt : %.gz
$(unzip) $<
mv -f $* $@
all: $(patsubst %.gz,%.txt,$(wildcard nc*.gz))
Done! This is how you'd use _make_ to do it.
PS. Note I didn't test this so the details might be slightly incorrect.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist