makefile ifeq not working


 
Thread Tools Search this Thread
Top Forums Programming makefile ifeq not working
# 1  
Old 09-02-2009
makefile ifeq not working

If I have a makefile that looks like this:

Code:
regress = NO

echo_set_regress: regress = YES
echo_set_regress: echo_regress
    @echo $(regress)

echo_regress:
    @echo $(regress)
ifeq ($(regress), NO)
    @echo "regress == NO"
else
    @echo "regress == YES"
endif

When I run make echo_regress I get this output:

NO
regress == NO

When I run make_set_regress, I get this output:

YES
regress == NO
YES

Notice that the ifeq check doesn't seem to work at all as I'm still getting regress == NO output. What am I doing wrong? Any help appreciated.
# 2  
Old 09-02-2009
Makefiles do not work that way, they are not shell scripts. They are a list of what files you need to build what files. if you tell it b comes from a, c comes from b, and d comes from c, give it a, then ask for d, it will execute the given instructions in the order needed to produce the target. You can specify them in any order.

Targets you build do not affect variables. These control structures you're trying are more like #ifdef's in C, if you know how those work.

A statement like
Code:
a:b
        echo "creating file a"
        cp b a

...specifies files and only files. It specifies that to create file a, you must have file b. You cannot use it to assign a variable -- and that's probably a good thing since that would botch horribly if make tried to do things in parallel. The lines below it, which must begin in tabs, are shell statements that specify how to create file a. They are executed individually and in order when make tries to build target 'a'.

Remember, you can specify these relationships in any order, and the makefile will decide what statements it needs to do in order to create a from b, c from a, d from c, and so forth. This means it must read and parse the entire file before doing anything, it is not a shell script. It won't even have started building by the time it reaches @echo "regress == YES" because it parses the entire file before deciding what targets to build in what order, and statements in them cannot affect the make environment anyway since they are executed in a shell.

Last edited by Corona688; 09-02-2009 at 07:43 PM..
# 3  
Old 09-03-2009
Actually, you can specify a variable for a specific target.

GNU `make'

What I'm trying to figure out is why the variable that is set for the specific target is echoed correctly, but doesn't seem to be tested correctly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

4. Red Hat

Nslookup working but ping not working at windows client

Hi Team we have created a DNS server at RHEL6.2 environment in 10.20.203.x/24 network. Everything is going well on linux client as nslookup, ping by host etc in entire subnet. We are getting problem in windows client as nslookup working as well but not ping. all the firewall is disabled and... (5 Replies)
Discussion started by: boby.kumar
5 Replies

5. Shell Programming and Scripting

Source command returns error when it strikes conditional statement "ifeq"

Hello All, I am running source command on my project configuration file app.cfg which has conditional statements with make file systax E.g ifeq ($(APP_CMP_DIR),trunk). When I source this file it throws error: syntax error near unexpected token... (1 Reply)
Discussion started by: anand.shah
1 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. UNIX for Advanced & Expert Users

AND && in ifeq in makefile

Hi, Can anybody help mw how to use 2 conditinal directives in makefile (with AND=&&), so far none of my tries succedded. Getting this warning like below. I thought that C's && will work, but alas, played with (), spaces and etc.. and I have only GNU Make 3.80 ifeq ($(VAR1),15) &&... (4 Replies)
Discussion started by: trento17
4 Replies

8. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

9. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

10. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies
Login or Register to Ask a Question