[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: run checks that may abort before build?: "info make if; info make er
From: |
gnu_make0 |
Subject: |
Re: run checks that may abort before build?: "info make if; info make error" |
Date: |
Tue, 06 Jun 2017 16:42:47 -0500 |
On Tue 6/6/17 17:24 -0400 address@hidden wrote:
> On Tue, 2017-06-06 at 16:07 -0500, address@hidden wrote:
> > Works:
> >
> > SHELL = /bin/bash
> > STARTUP_CHECK_NOP := $(shell set -x;: Checking for FINALDESTDIR:;[[ -d
> > $(FINALDESTDIR) ]] || kill 0)
> >
> > Is there a cleaner way? The STARTUP_CHECK_NOP macro is liable to
> > confuse a maintainer since it's value is never used.
>
> It's helpful if you describe in words what you want to do.
In this case, as you saw I was testing for a dir. ( that only root could have
made )
Guess, I was fishing for some general approach, that would use the shell,
but not the one I showed.
> If you're trying to fail immediately if a directory doesn't exist, you
> can do something like this:
>
> $(if $(wildcard $(FINALDESTDIR)/.),,$(error $(FINALDESTDIR) does not exist))
>
> This also uses only make constructs so is slightly more portable.
Thanks! I will use that and plan to look at the "info make if".
--
Tom
--
$ cat makefile
FINALDESTDIR := /tmp/asdf
$(if $(wildcard $(FINALDESTDIR)/.),,$(error $(FINALDESTDIR) does not exist))
$ make
makefile:3: *** /tmp/asdf does not exist. Stop.
$ mkdir /tmp/asdf
$ make
make: *** No targets. Stop.
$ : All good.
--snip
$ info make if
Next: Foreach Function, Prev: File Name Functions, Up: Functions
8.4 Functions for Conditionals
==============================
There are three functions that provide conditional expansion. A key
aspect of these functions is that not all of the arguments are expanded
initially. Only those arguments which need to be expanded, will be
expanded.
'$(if CONDITION,THEN-PART[,ELSE-PART])'
The 'if' function provides support for conditional expansion in a
functional context (as opposed to the GNU 'make' makefile
conditionals such as 'ifeq' (*note Syntax of Conditionals:
Conditional Syntax.).
The first argument, CONDITION, first has all preceding and trailing
whitespace stripped, then is expanded. If it expands to any
non-empty string, then the condition is considered to be true. If
it expands to an empty string, the condition is considered to be
false.
If the condition is true then the second argument, THEN-PART, is
evaluated and this is used as the result of the evaluation of the
entire 'if' function.
If the condition is false then the third argument, ELSE-PART, is
evaluated and this is the result of the 'if' function. If there is
no third argument, the 'if' function evaluates to nothing (the
empty string).
Note that only one of the THEN-PART or the ELSE-PART will be
evaluated, never both. Thus, either can contain side-effects (such
as 'shell' function calls, etc.)
'$(or CONDITION1[,CONDITION2[,CONDITION3...]])'
The 'or' function provides a "short-circuiting" OR operation. Each
argument is expanded, in order. If an argument expands to a
non-empty string the processing stops and the result of the
expansion is that string. If, after all arguments are expanded,
all of them are false (empty), then the result of the expansion is
the empty string.
--SNIP