automake conditional compilation technicality

automake conditional compilation technicality

Post by Ian Macdona » Thu, 30 Dec 1999 04:00:00



Hi,

I'm currently developing a C program and doing my best to bring the
power of GNU automake to bear on the build process. I'm now at the
stage where I can use automake fairly effectively, and consulting the
manual usually clears up any confusion I may have.

However, with this particular project, I've run into a problem that I
can't quite work out how to solve in an elegant fashion.

The problem is with a couple of source files that need to be compiled
only under certain circumstances.

I currently have a Makefile.am consisting of the following:

bin_PROGRAMS = qrcs
qrcs_SOURCES = qrcs.c qrcs.h
EXTRA_qrcs_SOURCES = ext2fs.c ext2fs.h
man_MANS = qrcs.1
EXTRA_DIST = $(man_MANS) qrcs.spec qrcs.lsm

The automake manual recommends assigning source files that are only
conditionally part of the build process to EXTRA_qrcs_SOURCES instead
of qrcs_SOURCES, so that is what I have done.

The problem comes in not knowing how to inform the build process when
it should build the EXTRA_qrcs_SOURCES files.

My configure.in checks for the existence of linux/ext2_fs.h and, if it
is found, defines HAVE_LINUX_EXT2_FS_H. That's the easy part.

When this symbol is defined, I want to compile the ext2fs.o object and
link it to the main one, qrcs.o, to form the qrcs binary.

I have solved the problem temporarily by removing the
EXTRA_qrcs_SOURCES line and adding ext2fs.c and ext2fs.h to
qrcs_SOURCES.

Of course, to make this work on non-Linux systems, I've had to edit
ext2fs.c and employ the kludge of enclosing the whole file in an
#ifdef HAVE_LINUX_EXT2_FS_H clause, which then produces a compile time
warning about ANSI C forbidding empty source files, which in turn
requires its own kludge to circumvent.

What I thus need is a way of informing the build process to build and
link EXTRA_qrcs_SOURCES only when the header file in question has been
found, but I can't work out what to put in Makefile.am to achieve
this.

The automake manual doesn't seem to provide the solution either, even
though the subject of conditional compilation *is* touched upon. Maybe
I'm barking up the wrong tree altogether.

Anyway, any help you can offer would be much appreciated.

Ian
--
Ian Macdonald              | Q: What do you call 15 blondes in a circle?
Red Hat Certified Engineer | A: A dope ring.  Q: Why do blondes put    
http://www.caliban.org/    | their hair in ponytails? A: To cover up the
Linux 2.2.13 on an i686    | valve stem.                                
                           |                                            

 
 
 

automake conditional compilation technicality

Post by Ken Pizzi » Wed, 05 Jan 2000 04:00:00



Quote:>The problem is with a couple of source files that need to be compiled
>only under certain circumstances.

>I currently have a Makefile.am consisting of the following:

>bin_PROGRAMS = qrcs
>qrcs_SOURCES = qrcs.c qrcs.h
>EXTRA_qrcs_SOURCES = ext2fs.c ext2fs.h
>man_MANS = qrcs.1
>EXTRA_DIST = $(man_MANS) qrcs.spec qrcs.lsm

>The automake manual recommends assigning source files that are only
>conditionally part of the build process to EXTRA_qrcs_SOURCES instead
>of qrcs_SOURCES, so that is what I have done.

>The problem comes in not knowing how to inform the build process when
>it should build the EXTRA_qrcs_SOURCES files.

>My configure.in checks for the existence of linux/ext2_fs.h and, if it
>is found, defines HAVE_LINUX_EXT2_FS_H. That's the easy part.

The configure.in should also conditionally set a configuration
variable, say EXT2_FS, to ext2fs.o and have your Makefile.am say:

                --Ken Pizzini

 
 
 

automake conditional compilation technicality

Post by Ian Macdona » Thu, 06 Jan 2000 04:00:00


On 4 Jan 2000 17:45:00 GMT, Ken Pizzini



>>I currently have a Makefile.am consisting of the following:

>>bin_PROGRAMS = qrcs
>>qrcs_SOURCES = qrcs.c qrcs.h
>>EXTRA_qrcs_SOURCES = ext2fs.c ext2fs.h
>>man_MANS = qrcs.1
>>EXTRA_DIST = $(man_MANS) qrcs.spec qrcs.lsm

>>The automake manual recommends assigning source files that are only
>>conditionally part of the build process to EXTRA_qrcs_SOURCES instead
>>of qrcs_SOURCES, so that is what I have done.

>>The problem comes in not knowing how to inform the build process when
>>it should build the EXTRA_qrcs_SOURCES files.

>>My configure.in checks for the existence of linux/ext2_fs.h and, if it
>>is found, defines HAVE_LINUX_EXT2_FS_H. That's the easy part.

>The configure.in should also conditionally set a configuration
>variable, say EXT2_FS, to ext2fs.o and have your Makefile.am say:


So when would you use the EXTRA_qrcs_SOURCES macro then?

The automake manual recommends the usage of EXTRA_$(package)_SOURCES
for files that are to be built conditionally. Is it just a question of
using this in the same way you describe using EXT2_FS?

Obviously, what you describe would work, but is that the way automake
intends you to use the EXTRA_$(package)_SOURCES construct, or is there
a better way?

Ian
--
Ian Macdonald              | A chap down in Oklahoma Had a* that    
Red Hat Certified Engineer | could sing La Paloma,  But the sweetness of
http://www.veryComputer.com/;  | pitch  Couldn't put off the hitch Of      
Linux 2.2.13 on an i686    | impotence, size and aroma.                
                           |                                            

 
 
 

automake conditional compilation technicality

Post by Ken Pizzi » Sat, 08 Jan 2000 04:00:00



>>>The problem comes in not knowing how to inform the build process when
>>>it should build the EXTRA_qrcs_SOURCES files.

>>>My configure.in checks for the existence of linux/ext2_fs.h and, if it
>>>is found, defines HAVE_LINUX_EXT2_FS_H. That's the easy part.

>>The configure.in should also conditionally set a configuration
>>variable, say EXT2_FS, to ext2fs.o and have your Makefile.am say:

>So when would you use the EXTRA_qrcs_SOURCES macro then?

When you include any files which are not always built.  To quote
from the relevant section of the automake manual (which is
perhaps less than clear on the subject):
:    Automake must know all the source files that could possibly go into a
: program, even if not all the files are built in every circumstance.
: Any files which are only conditionally built should be listed in the
: appropriate `EXTRA_' variable.  For instance, if `hello-linux.c' were
: conditionally included in `hello', the `Makefile.am' would contain:
:
:      EXTRA_hello_SOURCES = hello-linux.c
:
:    Similarly, sometimes it is useful to determine the programs that are
: to be built at configure time.  For instance, GNU `cpio' only builds
: `mt' and `rmt' under special circumstances.
:
:    In this case, you must notify Automake of all the programs that can
: possibly be built, but at the same time cause the generated
: `Makefile.in' to use the programs specified by `configure'.  This is
: done by having `configure' substitute values into each `_PROGRAMS'
: definition, while listing all optionally built programs in
: `EXTRA_PROGRAMS'.

Now that last paragraph talks about "_PROGRAMS", but it
also applies to "_SOURCES": you tell automake itself about the
optionally-compiled sources with the EXTRA_qrcs_SOURCES macro,
and you tell the configure script that you want the EXT2_FS
configuration variable interpolated into the expansion of the

on the qrcs_SOURCES line.

                --Ken Pizzini

 
 
 

1. : Driver/Module Compilation Using GNU Automake/Autoconf

Hi,

Does anyone know how to write the GNU automake (Makefile.am) script to just
compile a source code (C programs) as a linux driver/module? Here is the
scenario:

I have created several files, i.e. file1.c, file2.c, file.h. These files
when
et compiled will produce a Linux driver for some I/O devices. So far, I have
the configure.in made from issuing the "autoscan". I also have created the
Makefile.am which consists of the following lines:

   bin_PROGRAMS = file
   file_SOURCES = file1.c file2.c file.h

I also have executed "aclocal; automake; autoconf" to generate the
configuration files, Makefile.in, and Makefile.  When I typed "make", it
compiled file1.c, file2.c, and created the "file" program. What I want is to
create a driver/module "file.o" for Linux kernel. Does anyone have any idea
what I should include in the Makefile.am to tell the GNU automake and
autoconf
just to compile and create a driver/module for Linux kernel?

--
Robert Young,

2. Heavy Linux FDISK problems

3. Automating Linux Driver/Module Compilation Using GNU Automake/Autoconf

4. Shortening multiple large filenames to their first characters

5. Conditional compilation

6. Rewrite

7. Conditional compilation in C?

8. Is my ethernet card fine if I can ping it's IP address?

9. Sys V/BSD "ps" newbie g++ preprocessor conditional compilation?

10. conditional compilation

11. make & conditional compilation

12. make: conditional compilation/linking?

13. Assembler and Conditional Compilation (C Preprocessor)