summaryrefslogtreecommitdiff
path: root/mk/pkgtasks/directories.mk
blob: de1d42cf099162a56f8d991a4ef620d1b77e9075 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# $NetBSD: directories.mk,v 1.3 2017/08/10 05:37:44 jlam Exp $
#
# Copyright (c) 2017 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Generate the data file for the directories package task.

# MAKE_DIRS
# OWN_DIRS
# REQD_DIRS
#	List of directories that should be created and destroyed when
#	the package is installed and removed.
#
#	OWN_DIRS is for directories owned by the package and the user
#	is prompted to remove the directory if it isn't empty.  The
#	directories are created or removed only if PKG_CONFIG is "yes".
#
#	MAKE_DIRS is for directories used by the package and the user
#	is never prompted to remove non-empty directories.  The
#	directories are created or removed only if PKG_CONFIG is "yes".
#
#	REQD_DIRS is for directories used by the package that must
#	always be created (PKG_CONFIG is ignored), and the user is
#	never prompted to remove non-empty directories.  All
#	directories listed in REQD_DIRS should be under ${PREFIX}.
#	The use-case for REQD_DIRS is very specialized, and most
#	packages should be using either OWN_DIRS or MAKE_DIRS instead.
#
#	If the directory pathname is a relative path, then it is taken
#	to be relative to ${PREFIX}.
#
# MAKE_DIRS_PERMS
# OWN_DIRS_PERMS
# REQD_DIRS_PERMS
#	List of sublists representing directories with ownership and
#	explicit modes that should be created and destroyed when the
#	package is installed and removed.  The sublists are of the
#	form:
#
#		<directory> <owner> <group> <mode>
#
#	These variables have the same usage as the similarly-named
#	variables that don't end in "_PERMS".
#
_PKG_VARS.pkgtasks+=	MAKE_DIRS MAKE_DIRS_PERMS \
			OWN_DIRS OWN_DIRS_PERMS \
			REQD_DIRS REQD_DIRS_PERMS
MAKE_DIRS?=		# empty
MAKE_DIRS_PERMS?=	# empty
OWN_DIRS?=		# empty
OWN_DIRS_PERMS?=	# empty
REQD_DIRS?=		# empty
REQD_DIRS_PERMS?=	# empty

# Trigger pkgtasks dependency if needed.
_PKGTASKS_DATAVARS.directories=		\
	MAKE_DIRS MAKE_DIRS_PERMS	\
	OWN_DIRS OWN_DIRS_PERMS		\
	REQD_DIRS REQD_DIRS_PERMS
.for _var_ in ${_PKGTASKS_DATAVARS.directories}
.  if !empty(${_var_})
USE_PKGTASKS=		yes
.  endif
.endfor

# Strip leading "${PREFIX}/" from the directory pathnames.
_MAKE_DIRS=		${MAKE_DIRS:S|^${PREFIX}/||g}
_MAKE_DIRS_PERMS=	${MAKE_DIRS_PERMS:S|^${PREFIX}/||g}
_OWN_DIRS=		${OWN_DIRS:S|^${PREFIX}/||g}
_OWN_DIRS_PERMS=	${OWN_DIRS_PERMS:S|^${PREFIX}/||g}
_REQD_DIRS=		${REQD_DIRS:S|^${PREFIX}/||g}
_REQD_DIRS_PERMS=	${REQD_DIRS_PERMS:S|^${PREFIX}/||g}

# ASSERT: The variables have the right number of words and that no
#	directory is listed in more than one variable.
#
# _ALL_DIRS.directories
#	List of directories named in MAKE_DIRS, OWN_DIRS, REQD_DIRS,
#	MAKE_DIRS_PERMS, OWN_DIRS_PERMS, and REQD_DIRS_PERMS.  This
#	variable is used in pkgsrc/mk/pkgtasks/files.mk.
#
_ALL_DIRS.directories=	# empty
.for _var_ in MAKE_DIRS OWN_DIRS REQD_DIRS
.  for d in ${${_var_}}
_DIRS.${d}+=		${_var_}
_ALL_DIRS.directories+=	${d}
.  endfor
.endfor
.for _var_ in MAKE_DIRS_PERMS OWN_DIRS_PERMS REQD_DIRS_PERMS
.  if empty(${_var_}) || empty(${_var_}:C/.*/4/:M*:S/4 4 4 4//gW)
# ${_var_} has a multiple of 4 words.
.    for d o g m in ${${_var_}}
_DIRS.${d}+=		${_var_}
_ALL_DIRS.directories+=	${d}
.    endfor
.  else
PKG_FAIL_REASON+=	${_var_:Q}" must have a multiple of 4 words."
.  endif
.endfor
.for d in ${_ALL_DIRS.directories:O:u}
.  if ${_DIRS.${d}:[#]} != 1
PKG_FAIL_REASON+=	${d:Q}" is listed more than once: "${_DIRS.${d}:Q}
.  endif
.endfor

_PKGTASKS_DATA.directories=	${_PKGTASKS_DIR}/directories
_PKGTASKS_DATAFILES+=		${_PKGTASKS_DATA.directories}

${_PKGTASKS_DATA.directories}:
	${RUN}${MKDIR} ${.TARGET:H:Q}
	${RUN}exec > ${.TARGET:Q}.tmp
	${RUN}set -- args ${_MAKE_DIRS}; shift;				\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; shift;					\
		${ECHO} "# DIR: $$dir m" >> ${.TARGET:Q}.tmp;		\
	done
	${RUN}set -- args ${_MAKE_DIRS_PERMS}; shift;			\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; shift 4; \
		${ECHO} "# DIR: $$dir m $$mode $$owner $$group"		\
			>> ${.TARGET:Q}.tmp;				\
	done
	${RUN}set -- args ${_OWN_DIRS}; shift;				\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; shift;					\
		${ECHO} "# DIR: $$dir mo" >> ${.TARGET:Q}.tmp;		\
	done
	${RUN}set -- args ${_OWN_DIRS_PERMS}; shift;			\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; shift 4; \
		${ECHO} "# DIR: $$dir mo $$mode $$owner $$group"	\
			>> ${.TARGET:Q}.tmp;				\
	done
	${RUN}set -- args ${_REQD_DIRS}; shift;				\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; shift;					\
		${ECHO} "# DIR: $$dir fm" >> ${.TARGET:Q}.tmp;		\
	done
	${RUN}set -- args ${_REQD_DIRS_PERMS}; shift;			\
	while ${TEST} "$$#" -gt 0; do					\
		dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; shift 4; \
		${ECHO} "# DIR: $$dir fm $$mode $$owner $$group"	\
			>> ${.TARGET:Q}.tmp;				\
	done
	${RUN}${MV} ${.TARGET:Q}.tmp ${.TARGET:Q}