On Wed, 15 Sep 2010, Christopher Howard wrote:
> I was of the understand that make doesn't preserve variable assignments
> across commands, which means you couldn't do something like this:
>
> VAR=`ls`
> echo $VAR
>
> If I'm wrong, write me a Makefile that proves it.
There's more than one way to skin that cat. Here, for instance, is a
pseudo-recursive ls written in make:
DIR ?= '.'
TARGETS := $(shell ls $(DIR))
default:
@echo
@echo "Listing files in $(DIR):"
@echo
@echo $(TARGETS)
for tgt in $(TARGETS) ; do \
( test -d $(DIR)/$$tgt && $(MAKE) DIR=$(DIR)/$$tgt ) \
; done
This relies on calling itself recursively and overwriting variable defs on
the command line.
> And how do you write functions in a Makefile?
Those are just rules, basically, but you can also use 'define' to create
macros as well.
--Arthur Corliss
Live Free or Die
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Sep 15 16:24:27 2010
This archive was generated by hypermail 2.1.8 : Wed Sep 15 2010 - 16:24:27 AKDT