Discussion:
How to include macro headers
Praveen kumar R
2014-06-24 13:06:11 UTC
Permalink
Hi All,
I have a generic inc file where all the build macros are present.
These macros are used in the source c files to make switches, how can I
include this inc file in autoconf.
I tried using "include" directive in my am file and it does not have any
effect.

Thanks,
Praveen
Ralf Corsepius
2014-06-24 14:56:11 UTC
Permalink
Post by Praveen kumar R
Hi All,
I have a generic inc file where all the build macros are present.
These macros are used in the source c files to make switches, how can I
include this inc file in autoconf.
I tried using "include" directive in my am file and it does not have any
effect.
Try adding such files to *_SOURCES.

Ralf
Eric Blake
2014-06-24 15:18:56 UTC
Permalink
Post by Praveen kumar R
Hi All,
I have a generic inc file where all the build macros are present.
These macros are used in the source c files to make switches, how can I
include this inc file in autoconf.
I tried using "include" directive in my am file and it does not have any
effect.
Thanks for the report. However, it is lacking on enough details for me
to even figure out what you are asking (are you trying to write an .m4
file to be included at autoconf time, a .h to be included at make time,
or a macro that gets included into the config.h that is incrementally
built up during configure to affect later configure tests?). Can you
post an actual minimal code sample of what you have tried, with more
details of what you are hoping to accomplish, rather than just vague
descriptions?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Praveen kumar R
2014-06-25 06:15:21 UTC
Permalink
---------- Forwarded message ----------
From: Praveen kumar R <***@gmail.com>
Date: Tue, Jun 24, 2014 at 9:49 PM
Subject: Re: How to include macro headers
To: Eric Blake <***@redhat.com>


I apologize for my poor description of the issue.
To start of with I have a file platform.inc, which includes the build time
macro definitions,
B_REFSW_OS = linuxuser
NEXUS_PLATFORM = 97428
NEXUS_MODE =
BCHP_CHIP = 7429
BCHP_VER = B0

which are used in my source file to make switches,see below code snippet

if (NEXUS_PLATFORM == 97428) {
{
}
else
{
}

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.
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 platform.inc

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
ifndef NEXUS_PLATFORM: ERROR


can I use the existing inc file as is ? or do I need to port this as to
suit for autotools environment.

Thanks,
Praveen R
Post by Eric Blake
Post by Praveen kumar R
Hi All,
I have a generic inc file where all the build macros are present.
These macros are used in the source c files to make switches, how can I
include this inc file in autoconf.
I tried using "include" directive in my am file and it does not have any
effect.
Thanks for the report. However, it is lacking on enough details for me
to even figure out what you are asking (are you trying to write an .m4
file to be included at autoconf time, a .h to be included at make time,
or a macro that gets included into the config.h that is incrementally
built up during configure to affect later configure tests?). Can you
post an actual minimal code sample of what you have tried, with more
details of what you are hoping to accomplish, rather than just vague
descriptions?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Eric Blake
2014-06-25 12:55:17 UTC
Permalink
Post by Praveen kumar R
I apologize for my poor description of the issue.
To start of with I have a file platform.inc, which includes the build time
macro definitions,
B_REFSW_OS = linuxuser
NEXUS_PLATFORM = 97428
NEXUS_MODE =
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?
Post by Praveen kumar R
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?
Post by Praveen kumar R
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?
Post by Praveen kumar R
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 platform.inc
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
Makefile.am:

include platform.inc

NULL =
AM_CFLAGS = \
-DB_REFSW_OS=$(B_REFSW_OS) \
-DNEXUS_PLATFORM=$(NEXUS_PLATFORM) \
$(NULL)

(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?
Post by Praveen kumar R
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
ifndef NEXUS_PLATFORM: ERROR
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
configure.ac (and NOT your Makefile.am):

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 http://libvirt.org
Praveen kumar R
2014-06-25 17:45:31 UTC
Permalink
Eric, That helps...I appreciate.

I have more software components which depends on the platform.inc, doing
the same would take some effort.
Is there any way that I could rewrite the paltform.inc so that I can reuse
it for all other components which use autoconf ?

-Praveen
Post by Eric Blake
Post by Praveen kumar R
I apologize for my poor description of the issue.
To start of with I have a file platform.inc, which includes the build
time
Post by Praveen kumar R
macro definitions,
B_REFSW_OS = linuxuser
NEXUS_PLATFORM = 97428
NEXUS_MODE =
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?
Post by Praveen kumar R
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?
Post by Praveen kumar R
I am trying to include this inc file in the automake file so that the
build
Post by Praveen kumar R
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?
Post by Praveen kumar R
This is an existing inc file which is used in the normal makefile, as I
am
Post by Praveen kumar R
porting this component to autotools I needed to do the same.
I tried this in my Makefile,am
include platform.inc
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
include platform.inc
NULL =
AM_CFLAGS = \
-DB_REFSW_OS=$(B_REFSW_OS) \
-DNEXUS_PLATFORM=$(NEXUS_PLATFORM) \
$(NULL)
(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?
Post by Praveen kumar R
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
ifndef NEXUS_PLATFORM: ERROR
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
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,
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 http://libvirt.org
Loading...