Solved

Makefile with condition

Posted on 2004-09-30
11
4,016 Views
Last Modified: 2013-12-26
have a small problem in this makefile
     CC=gcc
                1.o: 1.cpp
     #ifeq ($(kw),y
     $(CC) -o  2.o 2.cpp
     #ifeq ($(kw),n)
     $(CC) -o  1.o 1.cpp
     #endif
     
when I invoke the make file like
make kw=y or
make kw=n or
make
all of these lines will compile the both file
so what I suppose to change to make it for example
make kw=y to compiler file 2.cpp
make kw=n  to compiler file 1.cpp
make by default n
TK

0
Comment
Question by:albusaidi
  • 6
  • 5
11 Comments
 
LVL 1

Expert Comment

by:gseidman
Comment Utility
You don't seem to really understand what's going on in a Makefile to begin
with, actually. First off, you are compiling executables but are giving the
resulting files a .o extension, which implies that they are object files.
Second, it looks like you have two separate executable targets and you want
to be able to compile one at a time. Third, these appear to be C++ source
files, but you are trying to compile them with a C compiler. If this is a
correct understanding of the problem, you want

CXX=g++
exe1: 1.cpp
      $(CXX) -o exe1 1.cpp

exe2: 2.cpp
      $(CXX) -o exe2 2.cpp

You can then run

make exe1

to build the first program and

make exe2

to build the second program.

0
 

Author Comment

by:albusaidi
Comment Utility

actually this is not my problem , I make this small example and I don't care it is for C or C++ ( nothing except printf) ... My point only I have amakefile and I need to ignore some time some lines and some time I need it ... I need to make it as option ... how can I make it.

I couldn't pring the original example because it is long and difficult .

TK.
0
 

Author Comment

by:albusaidi
Comment Utility

that mean I wnat to use condition ... because these lines can be in diffrent line ... any time I want to ignore any line I only make a condition ..
How can I do that ...
T.K again
0
 
LVL 1

Expert Comment

by:gseidman
Comment Utility

foo:
ifeq ($(kw), y)
      line1
else
      line2
endif
0
 

Author Comment

by:albusaidi
Comment Utility
I tried Your code but still all the time the compiler execute both lines even if the condtion True or false.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:gseidman
Comment Utility
Post exactly what you put in the Makefile and what you typed on the commandline.
0
 

Author Comment

by:albusaidi
Comment Utility
foo:
      #ifeq ($(kw),y)
      $(CC) -o  1.o 1.cpp
      #else
      $(CC) -o  2.o 2.cpp
      #endif
make kw=y
OR
foo:
      i#feq ("$(kw)","y")
      $(CC) -o  1.o 1.cpp
      #else
      $(CC) -o  2.o 2.cpp
      #endif
make kw=y
0
 
LVL 1

Accepted Solution

by:
gseidman earned 50 total points
Comment Utility
The problem is that you are putting in a # which is the comment character. You are commenting out the conditionals. That's not what I had in my example.
0
 

Author Comment

by:albusaidi
Comment Utility
myt compiler is not except this (cygwin)
alway I get this message
$ make kw=y
ifeq ("y","y")
Syntax error: word unexpected (expecting ")")
make: *** [foo] Error 2

0
 

Author Comment

by:albusaidi
Comment Utility
I got the way .. TK for every body

CC=gcc
foo:      
ifeq ('$(kw)','y')        // here we use '
      $(CC) -o  1.o 1.cpp // must be space
else
      $(CC) -o  2.o 2.cpp // must be space
endif

maybe it seem is easy but I spend more than 3 days on this example ... TK
0
 
LVL 1

Expert Comment

by:gseidman
Comment Utility
Please remember to assign points.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now