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
Solved

Makefile with condition

Posted on 2004-09-30
11
4,032 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
ID: 12201271
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
ID: 12201386

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
ID: 12201407

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 1

Expert Comment

by:gseidman
ID: 12201432

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

Author Comment

by:albusaidi
ID: 12202049
I tried Your code but still all the time the compiler execute both lines even if the condtion True or false.
0
 
LVL 1

Expert Comment

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

Author Comment

by:albusaidi
ID: 12202165
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
ID: 12202397
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
ID: 12202420
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
ID: 12211101
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
ID: 12211528
Please remember to assign points.
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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 111
dog bark java program 15 109
string initialization in java 11 115
format the code in java 6 101
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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