summaryrefslogtreecommitdiff
path: root/t/ensure-dir-exists.sh
blob: 552aa1a6fc07541d6f48caaeb6a9df4aafe8e3ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /bin/sh
# Copyright (C) 2012-2015 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test Automake-provided internal macro 'am.cmd.ensure-dir-exists'.

am_create_testdir=empty
. test-init.sh

# Filter out Automake comments.
grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \
  || fatal_ "fetching makefile fragment headers-vars.am"

cat > Makefile << 'END'
include ./defn.mk

files = x/1 x/2 x/3

all: $(files)
.PHONY: all

sanity-check:
	$(warning $(call am.cmd.ensure-dir-exists,x))
	$(if $(filter $(call am.cmd.ensure-dir-exists,x),:MKDIR_P:),, \
             $(error am.cmd.ensure-dir-exists does not contain $$(MKDIR_P)))
.PHONY: sanity-check

$(files):
	$(call am.cmd.ensure-dir-exists,x)
	echo dummy > $@
END

# Sanity check.
$MAKE sanity-check MKDIR_P=:MKDIR_P:

# Basic usage.
$MAKE MKDIR_P='mkdir -p'
test -f x/1
test -f x/2
test -f x/3

# Mkdir is not called uselessly.
rm -rf x
mkdir x
$MAKE MKDIR_P=false

# Mkdir is  not called too many times.
rm -rf x
$MAKE MKDIR_P=mkdir
test -f x/1
test -f x/2
test -f x/3

: