Makefile:how to force exit and show usage msg?

  • Follow


I'm not finding how to do this.
I want to force exit with a usage message if user doesn't enter correct
build parameters.
Also, I can't get my usage msg to show up in all cases where I want it
to.  My usage msg is forced into a file, that I want to cat when it
should be shown.

Running in linux, gmake.

Example makefile:
#=======================================
USAGE:force
@$(ECHO) " usage text put in file for output on demand">usage
# force usage file to be recreated every time
force: ;

ifndef platform
platform=linux
else
ifneq "$(platform)" "linux"
showhelp::help
#	exit # How can I force exit here?
else
PLATFORM_CODE=LX
endif
endif

ifndef build
build=internal
endif
ifdef build
ifneq "$(build)" "beta"
ifneq "$(build)" "patch"
ifneq "$(build)" "release"
ifneq "$(build)" "internal"
showhelp::help
#	exit  # How can I force exit here?
endif
endif
endif
endif
endif

include $(platform).env

help:
@cat usage

# other non pertinent stuff not included in example...
#================ end of example =====

What I find when I run this with the command
make platform=foo
is it tells me that foo.env cannot be found.  It should cat the usage
file and then exit.

help is not a file in my current directory.

if I run make -n platform=foo then I can see that the usage file is NOT
being created.
But, when I run make -n platform=linux, or make -n, it is created!  I
don't understand why the difference.

I want to create the usage msg every time, because I expect that there
may be other makefiles that also create their own usage messages.

Thanks,
Dave

ps. I'm posting from googleGroups2 beta, and the makefile indentation
and tabs are not showing up in my msg preview window, sorry about that
if they don't show up.

0
Reply kaatzd 9/3/2004 6:57:47 PM

kaatzd@hotmail.com <kaatzd@hotmail.com> wrote:
> I'm not finding how to do this.
> I want to force exit with a usage message if user doesn't enter correct
> build parameters.
> Also, I can't get my usage msg to show up in all cases where I want it
> to.  My usage msg is forced into a file, that I want to cat when it
> should be shown.

> Running in linux, gmake.

> Example makefile:
> #=======================================
> USAGE:force
> @$(ECHO) " usage text put in file for output on demand">usage
> # force usage file to be recreated every time
> force: ;

> ifndef platform
> platform=linux
> else
> ifneq "$(platform)" "linux"
> showhelp::help
> #	exit # How can I force exit here?
> else
> PLATFORM_CODE=LX
> endif
> endif

> ifndef build
> build=internal
> endif
> ifdef build
> ifneq "$(build)" "beta"
> ifneq "$(build)" "patch"
> ifneq "$(build)" "release"
> ifneq "$(build)" "internal"
> showhelp::help
> #	exit  # How can I force exit here?
> endif
> endif
> endif
> endif
> endif

> include $(platform).env

> help:
> @cat usage

> # other non pertinent stuff not included in example...
> #================ end of example =====

> What I find when I run this with the command
> make platform=foo
> is it tells me that foo.env cannot be found.  It should cat the usage
> file and then exit.

You can't have any commands before the first target. Something like
this should work:

ifneq ($(shell ls $(platform).env 2>/dev/null),)
    include $(platform).env
    PLATFORM := $(platform)
endif

..PHONY: create_usage_file help

all: create_usage_file
ifndef PLATFORM
    @$(MAKE) help
    @exit 2
endif
    @echo $(platform)
    @echo "Success: Platform is defined and .env file exists"

create_usage_file:
    @echo "Usage info written into a file" > usage

help:
    @cat usage

This checks if the file of the form $platform.env exists and if yes
it includes it and sets another variable that's checked later. The
'usage' file gets created always (unless you use a different target
than the default target) and if PLATFORM hasn't been defined the
usage file is displayed and make then exits. I don't know if that's
what you're looking for, if not please try to explain what what you
need to do differently.
                                    Regards, Jens
-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de
0
Reply Jens 9/3/2004 10:18:48 PM


1 Replies
1502 Views

(page loaded in 0.106 seconds)

Similiar Articles:













7/20/2012 1:05:22 PM


Reply: