Solved

Makefile use of ifdef

Posted on 2012-04-03
5
1,236 Views
Last Modified: 2012-04-11
Is it possible for a makefile to be aware of what is defined in the source code?  For example, in a header file I have:
#define T5

I'd like the makefile to recognize the definition and build differently based on that:
ifdef T5
CH_Manager: $(OBJ)
      $(CC) $(CCOPT) $(CFLAGS) -o $(OUTDIR)CH_Manager_T5 $^
endif

This doesn't work.  
I'd like to change the name of the resulting executable based on what's defined. Is it possible?  If not is there another way to do it?

Thanks.
0
Comment
Question by:JohnSantaFe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 37803889
You can use 'ifdef' in your makefile to set a definition for the source code, that to me seems the better way round:

ifdef T5
CH_Manager: $(OBJ)
      $(CC) $(CCOPT) $(CFLAGS) -DT5 -o $(OUTDIR)CH_Manager_T5 $^
endif
0
 

Author Comment

by:JohnSantaFe
ID: 37803964
Yea, I understand that.  The disadvantage is you don't get the highlighting in the IDE (Eclipse) that shows you what is being defined and what is not.  I find that very useful.
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 300 total points
ID: 37804818
The traditional (unix) approach to this, is to have a configure script that is run before building the source code, and serves to customize the build for the specific platform and/or user preferences.

See eg. autoconf (http://www.gnu.org/software/autoconf/) for a tool that facilitates the generation of such configure scripts.

The configure script would generate a config.h file, which your IDE can read, and provide the highlighting you desire.
0
 
LVL 34

Assisted Solution

by:sarabande
sarabande earned 100 total points
ID: 37805326
you could make a new target in the makefile

T5:  $(EXE)
      sometool  $(EXE) -T5

Open in new window


it is assumed that $(EXE) is the target which makes the executable. sometool would check whether the executable has the option defined - for example by reading the configuration or simply by starting the executable with a special option - and if so would copy or rename the executable.

Sara
0
 

Author Comment

by:JohnSantaFe
ID: 37834420
I appreciate the ideas.  It looks like the 'right' way to do this is with autoconf, I was hoping for something a little simpler.
Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question