Reputation: 2887
I've some commands in my gnu make file which is returning true or false
Commands like
apps := $(shell zmr build app)
...more code
service := $(shell zmr build service)
...
target := $(shell zmr build target)
Now I want to enhance those command to return also boolean for true of false
apps,isValid := $(shell zmr build app)
...
service,isValid := $(shell zmr build service)
...
target,isValid := $(shell zmr build target)
and when if isValie
equal to false use exit in the make?
I try to read about the functions like https://www.gnu.org/software/make/manual/html_node/Conditional-Functions.html#Conditional-Functions
or https://www.gnu.org/software/make/manual/html_node/Eval-Function.html#Eval-Function
but not sure if this is right way...any example how to handle it properly will really help me , Im a bit lost with the options
I've tried the following answer without success, any idea how I can make it work inside makefile
?
update -
I want to use a function in my GNU MAKE which get true
or false
from command
, if get false
it will exit
the make process (i..e not proceed with the next command, if true proceed with the process) how it can be done simply and strait forward
Upvotes: 3
Views: 676
Reputation: 15493
Hmmm, as a matter of style, I would strive not to use $(shell …)
and use recipes wherever possible.
Having said that, it is possible to do what you ask. I will just assume the last word is the status.
output := $(shell zmr build app && echo t || echo f)
Here t
is appended to the output of zmr
if the command succeeded.
Otherwise f
is appended.
Now we just strip off the last word to separate the status from the command output.
retcode := $(lastword ${output})
apps := $(words 2,$(words ${output}),x ${output})
$(if $(filter f,${retcode}),$(error apps failed))
Upvotes: 2
Reputation: 4487
Your needs is already quite too advanced to be managed only in a make file.
You may consider using a tool like autoconf (See. https://www.gnu.org/software/autoconf/autoconf.html) which will allow you to perfectly reach your needs, with a result more legible.
Let me know if you need help for that.
Upvotes: 1
Reputation: 6994
I've some commands in my gnu make file which is returning true or false
apps := $(shell zmr build app)
Now I want to enhance those command to return also boolean for true of false
apps,isValid := $(shell zmr build app)
when if
isValid
equal to false use exit in the make
Assuming your zmr build ...
commands outputs true
or false
, you can exit make
with
ifeq (${apps,isValid},false)
$(error app not valid)
endif
make
does not know about datatypes so true
and false
are just strings for it.
I do not know the semantic of your zmr build
but it sounds like it would do some expensive things... The $(shell ...)
operation is usually only intended for short running commands without side effects. It might be better to put the isValid
stuff into a target
apps,isValid:
zmr build app
make
will fail automatically when this command fails.
Upvotes: 2