Solved

Makefile use of ifdef

Posted on 2012-04-03
5
1,217 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

730 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