Optionally compiling feature [Archive] - C Board

PDA

View Full Version : Optionally compiling feature


JasonLikesJava
11-06-2002, 12:51 PM
I want to write Makefile.am and/or configure.in to only compile certains files if a certain argument is given to the configure script.

I'd suppose I should append certain files to the SOURCES variable if the argument is given. I was able to detect if a certain argument was given using AC_ARG_ENABLE in configure.in although I don't know how to change Makefile.am to change which sources are to be compiled given the condition in configure.in.

Thanks

starX
11-06-2002, 02:56 PM
While I can't say for certain, I think I remember reading somewhere in the GNU make handbook that you can only create conditionals based on the internal variables of the makefile itself. My advice would be to have your configuration script write the makefile, using conditionals in the script to write certain variables to the makefile if certain conditions are met within the makefile itself. Given the general structure of makefiles, this might be a bit of hand-coding on your part, but I don't think it would be that difficult.

starX
www.axisoftime.com

JasonLikesJava
11-08-2002, 11:53 AM
I haven't done much work with creating Makefiles and build scripts, so how exactly would I do that?

I've come up with something like this so far but it doesn't work:

#configure.in
AM_CONDITIONAL(FEATURE, test "$enable_feature" = "yes")

#Makefile.am
COMMONSOURCES = a.cpp b.cpp
if FEATURE
FEATURESOURCES = feature.cpp
else
FEATURESOURCES =
endif

SOURCES = "$(COMMONSOURCES) $(FEATURESOURCES)"

The part in configure.in seems to work and enable_feature is set to yes or no according to arguments given.

starX
11-09-2002, 08:29 PM
Like I said before, the GNU Make manual says that makefile variables only pertain to the variable status with the cvurrent makefile, but if you build a shell script to check for the file...



#!/bin/bash

#
# Echo you're generic makefile stuff here
#

# Now we need to know if the files are *.cpp files, or the normal c files

if ls *.cpp
then
echo "COMPILER = g++" >> makefile
else
echo "COMPILER = gcc" >> makefile
fi

# Other makefile stuff



Yes, I fully realize that this is a trivial example, and I'm not 100% sure that this will work, but it should be a good start.

If you want real configuration power, look up GNU autoconf.

starX
www.axisoftime.com