Penguin
Note: You are viewing an old revision of this page. View the current version.

Everyone has to generate configuration files, and basically they're the same across multiple machines, normally with different IP addresses.

m4(1) is the GNU macro processor. You may recognise it from such tools as autoconf(1) and sendmail(8). Here are some cool things you can do with it.

config.m4

divert(-1) define(conf_INTIF,`10.7.0.254') define(conf_INTNET,`10.7.0.0') define(conf_INTBCAST,`10.7.0.255') divert(0)dnl

Makefile

As always with makefiles, you can do lots of magic here. See MakefileHowto for a lot of useful information.

FILES=interfaces all: $(FILES) DESTDIR ?= ./etc

interfaces: interfaces.m4

%:%.m4

m4 < $< > $@

install

cp -f interfaces $(DESTDIR)/network/

The magic is all in the m4 section: that rule says to build any file % from a %.m4, pipe the .m4 file into the m4 command (confused yet?) and then divert the output into the eventual file.

Basically, what this does is lets you define files like this:

interfaces.m4

include(`config.m4')dnl

  1. /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
  2. The loopback interface

auto lo iface lo inet loopback

  1. Internal network connection: eth0

auto eth0 iface eth0 inet static

address conf_INTIF netmask conf_INTMASK broadcast conf_INTBCAST

And then the m4 processor will go through the config.m4 file you have included (the dnl means 'do not linefeed'), and generate a file like this:

interfaces (automatically generated by m4 with a simple 'make')

  1. /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
  2. The loopback interface

auto lo iface lo inet loopback

  1. Internal network connection: eth0

auto eth0 iface eth0 inet static

address 10.7.0.254 netmask 255.255.255.0 broadcast 10.7.0.255