🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3797

automake conditional compilation technicality

#3797
From: Ian Macdonald
Date: Wed, 29 Dec 1999 00:00
62 lines
3362 bytes
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.                                
                           |                                            
Technical Details
Message-ID: <slrn86k3jo.h30.ian@caliban.xs4all.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109f73,70579a91ac9a2bf6,start
X-Google-Attributes: gid109f73,public
X-Google-Thread: fc89c,70579a91ac9a2bf6,start
X-Google-Attributes: gidfc89c,public
From: ian@caliban.org (Ian Macdonald)
Subject: automake conditional compilation technicality
Date: 1999/12/29
Message-ID: <slrn86k3jo.h30.ian@caliban.xs4all.nl>
X-Deja-AN: 566097157
Sender: ianmacd@node10084.a2000.nl
Mail-Copies-To: never
X-Trace: news1.xs4all.nl 946475123 23373 24.132.0.132 (29 Dec 1999 13:45:23 GMT)
Organization: The Mighty Caliban
X-OS: Linux 2.2.13
User-Agent: slrn/0.9.6.2 (Linux)
NNTP-Posting-Date: 29 Dec 1999 13:45:23 GMT
Newsgroups: comp.unix.programmer,gnu.utils.help
X-Complaints-To: abuse@xs4all.nl