[Top][All Lists]

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

Re: Having Trouble with m4 Input (m4 version 1.4.13)

From: Eric Blake
Subject: Re: Having Trouble with m4 Input (m4 version 1.4.13)
Date: Fri, 03 Sep 2010 10:05:31 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100806 Fedora/3.1.2-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.2

On 09/03/2010 09:56 AM, Tom Browder wrote:
I am trying to use m4 (version 1.4.13) to generate a C header file and
am approaching it cautiously because my experience with m4 has not
been comforting.

You may want to consider upgrading to 1.4.15, although I don't think that will impact your usage issue.

My initial m4 input file has these lines:

define(`hashdef', `#define')dnl
define(`Min', include(`conf/MINOR'))
hashdef __PROGVER_MINOR__ Min

When I execute "m4<m4 input file>" I get:

#define __PROGVER_MINOR__ Min

Notice 'Min is not expanded.

Is the '#' stopping it?

Correct. And that's because, by default, # is the m4 comment character, and once hashdef is expanded, you have turned the rest of the line into an m4 comment.

 If so, how can I get the line I want.

By either disabling m4 comments:


or by using proper quoting (so that hashdef no longer expands to a comment character, but a quoted string that happens to contain #):

define(`hashdef', ``#'define')dnl

Also, to be robust to non-GNU m4, you should probably also double-quote define, or use other tricks to ensure that you don't inadvertently end up expanding the define built-in with zero arguments (GNU m4 explicitly documents that the define built-in when invoked with zero arguments expands to it's own name, as if it hadn't been a macro, but POSIX leaves that bit unspecified):

define(`hashdef', ``#define'')dnl

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]