LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Makefile conditional does not work (http://www.linuxquestions.org/questions/linux-software-2/makefile-conditional-does-not-work-785572/)

x_terminat_or_3 01-29-2010 06:12 AM

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.

Valery Reznic 01-30-2010 12:49 AM

Replace REQUIRED_USER to USERID

x_terminat_or_3 01-30-2010 02:20 AM

Dang! Thank you very much.

Don't suppose you know how to get make to warn about using uninitialised variables?

Valery Reznic 01-30-2010 05:03 AM

Quote:

Originally Posted by x_terminat_or_3 (Post 3845763)
Dang! Thank you very much.

Don't suppose you know how to get make to warn about using uninitialised variables?

--warn-undefined-variables

x_terminat_or_3 01-30-2010 05:06 AM

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 ;)

Valery Reznic 01-30-2010 05:32 AM

Quote:

Originally Posted by x_terminat_or_3 (Post 3845915)
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.

x_terminat_or_3 01-30-2010 05:33 AM

:)

Thanks


All times are GMT -5. The time now is 01:43 AM.