Optionally compiling feature

This is a discussion on Optionally compiling feature within the Linux Programming forums, part of the Platform Specific Boards category; I want to write Makefile.am and/or configure.in to only compile certains files if a certain argument is given to the ...

  1. #1
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175

    Optionally compiling feature

    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
    Last edited by JasonLikesJava; 11-06-2002 at 01:49 PM.
    OS: Linux Mandrake 9.0
    Compiler: gcc-3.2
    Languages: C, C++, Java

    If you go flying back through time and you see somebody else flying forward into the future, it's probably best to avoid eye contact.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    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

  3. #3
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    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.
    Last edited by JasonLikesJava; 11-08-2002 at 01:10 PM.
    OS: Linux Mandrake 9.0
    Compiler: gcc-3.2
    Languages: C, C++, Java

    If you go flying back through time and you see somebody else flying forward into the future, it's probably best to avoid eye contact.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    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...

    Code:
    #!/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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem compiling files that store functions
    By tiachopvutru in forum C++ Programming
    Replies: 10
    Last Post: 05-30-2008, 06:42 PM
  2. Edit and continue feature
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 04-27-2008, 07:15 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 02:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21