LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-29-2010, 06:12 AM   #1
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
Makefile conditional does not work


Hi there

I'm trying to write a make file to deploy software in a production setup.

The first thing I'm trying to do is detect if the user running the make is root.

From the documentation scattered about, I came up with this:

Code:
USERID=$(shell id -u)

all:
        $(info User Id is $(USERID))
        ifeq ($(REQUIRED_USER),0)
                $(info Running as root... OK)
        else
                $(error You must be root to execute this command)
        endif
When I run this as root, I get the following output:

Quote:
$ > make
User Id is 0
Running as root... OK
Makefile:6: *** You must be root to execute this command. Stop.
When I run this as another user:

Quote:
$ > make
User Id is 496
Running as root... OK
Makefile:6: *** You must be root to execute this command. Stop.
As you can see, in both situations, make executes both branches of the conditional.

How to do this the correct way?

Thanks for your help.
 
Old 01-30-2010, 12:49 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
Replace REQUIRED_USER to USERID
 
1 members found this post helpful.
Old 01-30-2010, 02:20 AM   #3
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Original Poster
Rep: Reputation: 38
Dang! Thank you very much.

Don't suppose you know how to get make to warn about using uninitialised variables?
 
Old 01-30-2010, 05:03 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
Quote:
Originally Posted by x_terminat_or_3 View Post
Dang! Thank you very much.

Don't suppose you know how to get make to warn about using uninitialised variables?
--warn-undefined-variables
 
1 members found this post helpful.
Old 01-30-2010, 05:06 AM   #5
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Original Poster
Rep: Reputation: 38
Ugh! Don't know what's gotten into me for not doing make --help myself...

You have permission to slap me on the head with a newspaper for making silly mistakes like that
 
Old 01-30-2010, 05:32 AM   #6
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
Quote:
Originally Posted by x_terminat_or_3 View Post
Ugh! Don't know what's gotten into me for not doing make --help myself...

You have permission to slap me on the head with a newspaper for making silly mistakes like that
Take it easy. Everyone make oversights.
 
Old 01-30-2010, 05:33 AM   #7
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Original Poster
Rep: Reputation: 38


Thanks
 
  


Reply

Tags
creating, debugging, files, gnu, make, makefile


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
conditional syntax problem in kernel makefile heliks Linux - Kernel 0 11-03-2009 02:29 AM
Makefile in freebsd will work in redhat9.0 linux yogeshk@redim.net Programming 2 12-29-2006 04:02 AM
Makefile in freebsd will work in redhat9.0 linux yogeshk@redim.net LQ Suggestions & Feedback 1 12-29-2006 03:45 AM
editing a c program and a makefile to work with newer kernel scorpion_gr Linux - Software 9 12-16-2006 04:19 AM


All times are GMT -5. The time now is 04:38 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration