From a9e8c5c4b08ca673aef48cc10b45abc70c1033e0 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 23 Jul 2018 16:11:03 +0000 Subject: [PATCH] Add the initial DIRS infrastructure for creating directories with the necessary owner, group, mode and flags. Approved by: bapt (mentor) Differential Revision: https://reviews.freebsd.org/D16405 --- share/mk/bsd.README | 13 +++++++++++++ share/mk/bsd.dirs.mk | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 share/mk/bsd.dirs.mk diff --git a/share/mk/bsd.README b/share/mk/bsd.README index 471a146eb659..36a61e1d196e 100644 --- a/share/mk/bsd.README +++ b/share/mk/bsd.README @@ -22,6 +22,7 @@ bsd.confs.mk - install of configuration files bsd.cpu.mk - sets CPU/arch-related variables (included from sys.mk) bsd.crunchgen.mk - building crunched binaries using crunchgen(1) bsd.dep.mk - handle Makefile dependencies +bsd.dirs.mk - handle directory creation bsd.doc.mk - building troff system documents bsd.endian.mk - TARGET_ENDIAN=1234(little) or 4321 (big) for target bsd.files.mk - install of general purpose files @@ -292,6 +293,18 @@ CLEANDIRS Additional files (CLEANFILES) and directories (CLEANDIRS) to CLEANFILES remove during clean and cleandir targets. "rm -rf" and "rm -f" are used, respectively. +DIRS A list of variables referring to directories. For example: + + DIRS+= FOO + FOO= /usr/share/foo + + Owner, Group, Mode and Flags are handled by FOO_OWN, + FOO_GRP, FOO_MODE and FOO_FLAGS, respectively. + + This allows FILESDIR to be set to FOO, and the directory + will be created before the files are installed and the + dependencies will be set correctly. + DPADD Additional dependencies for the program. Usually used for libraries. For example, to depend on the compatibility and utility libraries use: diff --git a/share/mk/bsd.dirs.mk b/share/mk/bsd.dirs.mk new file mode 100644 index 000000000000..c75d646269ef --- /dev/null +++ b/share/mk/bsd.dirs.mk @@ -0,0 +1,42 @@ +# $FreeBSD$ +# +# Directory permissions management. + +.if !target(____) +____: +# List of directory variable names to install. Each variable name's value +# must be a full path. If non-default permissions are desired, _MODE, +# _OWN, and _GRP may be specified. +DIRS?= + +. for dir in ${DIRS:O:u} +. if defined(${dir}) && !empty(${dir}) +# Set default permissions for a directory +${dir}_MODE?= 0755 +${dir}_OWN?= root +${dir}_GRP?= wheel +. if defined(${dir}_FLAGS) && !empty(${dir}_FLAGS) +${dir}_FLAG= -f ${${dir}_FLAGS} +. endif + +. if defined(NO_ROOT) +. if !defined(${dir}TAGS) || ! ${${dir}TAGS:Mpackage=*} +${dir}TAGS+= package=${${dir}PACKAGE:Uruntime} +. endif +${dir}TAG_ARGS= -T ${${dir}TAGS:[*]:S/ /,/g} +. endif + +installdirs: installdirs-${dir} + +installdirs-${dir}: ${DESTDIR}${${dir}} + +${DESTDIR}${${dir}}: + @${ECHO} installing DIRS ${dir} + ${INSTALL} ${${dir}TAG_ARGS} -d -m ${${dir}_MODE} -o ${${dir}_OWN} \ + -g ${${dir}_GRP} ${${dir}_FLAG} ${DESTDIR}${${dir}} +. endif + +realinstall: installdirs-${dir} +. endfor + +.endif