3

I would like to use m4 for doing some type-saving stuffs, so the loop will be definitely needed. When I read m4 doc, in chapter 6 there is 6.4 and 6.5 for iteration. But it looks like that foreach is not a builtin macro (Composite?), how could I use it? In the example, they invoke m4 with -I examples option, and include('foreach.m4'), but this file seems not exist with error as:

cannot open `foreach.m4': No such file or directory

Any help is appreciated!

Li

Li Dong
  • 1,088
  • 2
  • 16
  • 27
  • Doesn't `M4` explicitly provide `foreach`, or need users to write their own? – Li Dong Nov 22 '12 at 08:32
  • No, it doesn't: the manual provides a composite (read: example of theoretical behavior and how you would call it) `foreach`, but does not _actually_ provide a `foreach` construct. – Alexej Magura Jan 24 '17 at 20:22

1 Answers1

2

You must use a full path as the argument to -I (or a relative path, but you must specify the directory). Note that the examples directory is not always installed along with m4 (the m4-1.4.1 rpm distributed with RedHat does not include the examples directory.) The simplest thing to do would be to unpack an m4 tarball and use it. (eg, unpack the tarball in /tmp and run m4 -I/tmp/m4-1.4.11/examples)

Also note that -I is a non-standard option for m4, so make sure you are actually using a version of m4 that supports that argument. (eg, gnu-m4)

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • Thanks William! I would like to know what is the rationals behind this? – Li Dong Nov 24 '12 at 17:05
  • 1
    I'm not really sure why not, but as far as I know, `m4` just doesn't look in any default directories other than `.` Since `-I` is non-standard, it wouldn't hurt anything to patch submit a patch to gnu-m4 that provides that functionality. – William Pursell Nov 24 '12 at 17:08