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

Re: wanted: m4 macros to generate mutliple similar config files



On Wed, Dec 13, 2000 at 02:31:54PM +0100, Andreas Schuldei wrote:

> Let me make this more precise:
> input is a list of IPs, privat networks and hostnames.
> the number of output files are the same as the number of hosts/IPs.
> But because this is about the possible connections between the hosts, each
> single config file describes the connection of one host with all others.

What you probably want, then, is something like this:

#!/usr/bin/make

HOSTS:=a b c d e
TARGETS:=$(foreach host,$(HOSTS),base.$(host))

all: $(TARGETS)

base.%: template.m4
	m4 -DHOST=$* $< > $@

This will run template.m4 through m4 for each thing in HOSTS, each time
substituting a new value for HOST.  The output files will be named
base.$(host).  So in your template.m4, just use the token HOST wherever you
want the substitution to be.

I haven't tested the above code, but it should be sufficient to show the basic
idea.  It's not really necessary to use make for this simple case, but once the
procedures for regenerating the configuration files get more complex, it's a
must.  Best to use make in the first place.

-- 
 - mdz



Reply to: