LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 11: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, 12:07 PM   #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, 12:34 PM   #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 12:51 PM.
 
Old 03-16-2011, 01:06 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,535

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, 01: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:21 PM
configure (automake) conditionals kev000 Programming 0 07-15-2007 01:25 PM
MAKEFILEs shinpadsmt Linux - Newbie 3 02-21-2004 03:52 AM
Makefiles and shell variables Snabber Linux - Software 1 08-06-2003 12:23 AM
bash scripting - conditionals dguy Linux - Newbie 4 01-19-2002 09:00 AM

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

All times are GMT -5. The time now is 10:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration