LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2011, 10:58 AM   #1
endfx
Member
 
Registered: May 2003
Location: Canada
Distribution: Debian
Posts: 105

Rep: Reputation: 15
Makefiles and shell conditionals


Hello,

I have the following target in a makefile:

Code:
all:
    if [ condition ]; then echo "HELLO"; fi
This seems to work when using older version of make but doesn't seem to work for newer versions. Eg make version 3.81-3 is fine with the above but 3.81-7 is not fine with the above.

The problem appears to be the "if" statement. It doesn't get executed by the shell. If I remove the if statement then it works (i.e. HELLO is printed)

Does anybody know why newer make doesn't work with the above.

Please note, this worked before. It is not a question of if I have a tab in the right spot, it is a question of why newer make does not pass the 'if' statement on to the shell.
 
Old 03-16-2011, 11:07 AM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by endfx View Post
I have the following target in a makefile:

Code:
all:
    if [ condition ]; then echo "HELLO"; fi
Just a stupid question: are you using the same shell as before? As you probably know, the if-syntax is very shell specific, though. What kind of error message do you get?

Quote:
Originally Posted by endfx View Post
This seems to work when using older version of make but doesn't seem to work for newer versions. Eg make version 3.81-3 is fine with the above but 3.81-7 is not fine with the above.
Here's what I would probably do: after checking the shell, I would test the version 3.81-4, 3.81-5 and 3.81-6 and check if you discovered a regression in the code. Then I would possibly post the question on the GNU make mailing list (or check the bug report system of GNU make).

But posting your error message here could already help us to give you more hints ...

I hope that helps,
Andi
 
Old 03-16-2011, 11:34 AM   #3
endfx
Member
 
Registered: May 2003
Location: Canada
Distribution: Debian
Posts: 105

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ForzaItalia2006 View Post
Just a stupid question: are you using the same shell as before? As you probably know, the if-syntax is very shell specific, though. What kind of error message do you get?
I'm not using the same shell version. Bash 3.2-0 is the old working one and 4.1-2 is the new non working version.
When I copy and paste the "if ..." code from the makefile directly into a shell, it works. So I assumed the problem was not with the shell, though I could still be wrong about this.


Quote:
Originally Posted by ForzaItalia2006 View Post
Here's what I would probably do: after checking the shell, I would test the version 3.81-4, 3.81-5 and 3.81-6 and check if you discovered a regression in the code. Then I would possibly post the question on the GNU make mailing list (or check the bug report system of GNU make).

But posting your error message here could already help us to give you more hints ...

I hope that helps,
Andi
I'm not getting an error, it's just printing out the command:

Code:
make all
if [ condition ]; then echo "HELLO"; fi
and continues on.

Good idea about trying the different versions. I tried the older (working) make on my newer system and it doesn't work, so it looks like it's something other than make. Frustrating ...

Thanks for your reply

Last edited by endfx; 03-16-2011 at 11:51 AM.
 
Old 03-16-2011, 12:06 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
What distro are you using?

My default shell when running under Ubuntu is bash; however that is not the shell that is used when executing a Makefile. I believe dash is used. To force a particular shell to be used within the Makefile, indicate your preference using the SHELL variable.

For example:
Code:
SHELL = /bin/bash

all:
        @ echo $(SHELL)
Try this Makefile with and without the SHELL environment variable.
 
Old 03-16-2011, 12:41 PM   #5
endfx
Member
 
Registered: May 2003
Location: Canada
Distribution: Debian
Posts: 105

Original Poster
Rep: Reputation: 15
Thanks dwhitney67! That was it.
It was using dash. When I switched it to bash the makefile started working.

I forgot ubuntu points /bin/sh at dash. I change /bin/sh to point to bash on my systems because dash screws up a lot of shell scripts. Heh, I still remember the controversy when Ubuntu made this switch.

Thanks again!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem with BASH conditionals - passing condition as variable smaddox Programming 8 09-18-2009 11:21 AM
configure (automake) conditionals kev000 Programming 0 07-15-2007 12:25 PM
MAKEFILEs shinpadsmt Linux - Newbie 3 02-21-2004 02:52 AM
Makefiles and shell variables Snabber Linux - Software 1 08-05-2003 11:23 PM
bash scripting - conditionals dguy Linux - Newbie 4 01-19-2002 08:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration