[Top][All Lists]

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

Re: Fwd: How to include macro headers

From: Eric Blake
Subject: Re: Fwd: How to include macro headers
Date: Wed, 25 Jun 2014 06:55:17 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 06/25/2014 12:15 AM, Praveen kumar R wrote:
> I apologize for my poor description of the issue.
> To start of with I have a file, which includes the build time
> macro definitions,
> B_REFSW_OS  = linuxuser
> BCHP_CHIP  = 7429
> BCHP_VER  = B0

Ah, so these are Makefile snippets, to be included during 'make' (and
not .m4 files during autoconf or .h files during the compiler run by
make).  See what a difference it makes when you give us details we can
work with?

> which are used in my source file to make switches,see below code snippet
> if (NEXUS_PLATFORM  == 97428) {
> {
> }
> else
> {
> }

Wait, this looks like C code.  Are you trying to turn your makefile
macros into C .h macros?

> I am trying to include this inc file in the automake file so that the build
> variables are available for the sources at the compile time.

But this is the autoconf list, not the automake list.  Are you sure you
are asking in the right location?

> This is an existing inc file which is used in the normal makefile, as I am
> porting this component to autotools I needed to do the same.
> I tried this in my Makefile,am
> include

Yes, that is how you would include a makefile snippet.  But including a
makefile snippet does not impact the C code that the compiler sees.

If you are using just make variables, then you could do this in your


        -DB_REFSW_OS=$(B_REFSW_OS) \

(expanded to mention all variable names you want to turn into
preprocessor macros), but that feels like a lot of duplication.  Are you
sure you even need make variables?

> this is not working and I am getting compile time errors, like
>  NEXUS_PLATFORM undefined, because there is check in the source before
> using it like
> can I use the existing inc file as is ? or do I need to port this as to
> suit for autotools environment.

If you want to propagate a make-time macro into your C files, the
general way to do that via autoconf is to use AC_DEFINE (or
AC_DEFINE_UNQUOTED), to stick the definition into your config.h file.
This is completely independent of make variables.  Stick this in your (and NOT your

AC_DEFINE([B_REFSW_OS], [linuxuser], [some doc comment])
AC_DEFINE([NEXUS_PLATFORM], [97428], [whatever this variable does...])

and so forth.  If you don't want to hard-code those values, but instead
let the user configure them, then add appropriate configure tests,
collect the value into a shell variable, such as:

bchp_chip=`some command to determine appropriate value`
AC_DEFINE_UNQUOTED([BCHP_CHIP], [$bchp_chip], [whatever this does])

then in your .c files, just #include <config.h> (first, before any other
headers), and the macros will already be defined.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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