xref: /freebsd/contrib/bmake/mk/manifest.mk (revision d485c77f203fb0f4cdc08dea5ff81631b51d8809)
1# $Id: manifest.mk,v 1.3 2020/08/19 17:51:53 sjg Exp $
2#
3#	@(#) Copyright (c) 2014, Simon J. Gerraty
4#
5#	This file is provided in the hope that it will
6#	be of use.  There is absolutely NO WARRANTY.
7#	Permission to copy, redistribute or otherwise
8#	use this file is hereby granted provided that
9#	the above copyright notice and this notice are
10#	left intact.
11#
12#	Please send copies of changes and bug-fixes to:
13#	sjg@crufty.net
14#
15
16# generate mtree style manifest supported by makefs in FreeBSD
17
18# input looks like
19# MANIFEST= my.mtree
20# for each MANIFEST we have a list of dirs
21# ${MANIFEST}.DIRS += bin sbin usr/bin ...
22# for each dir we have a ${MANIFEST}.SRCS.$dir
23# that provides the absolute path to the contents
24# ${MANIFEST}.SRCS.bin += ${OBJTOP}/bin/sh/sh
25# ${MANIFEST}.SYMLINKS is a list of src target pairs
26# for each file/dir there are a number of attributes
27# UID GID MODE FLAGS
28# which can be set per dir, per file or we use defaults
29# eg.
30# MODE.sbin = 550
31# MODE.usr/sbin = 550
32# MODE.dirs = 555
33# means that sbin and usr/sbin get 550 all other dirs get 555
34# MODE.usr/bin/passwd = 4555
35# MODE.usr/bin.files = 555
36# MODE.usr/sbin.files = 500
37# means passwd gets 4555 other files in usr/bin get 555 and
38# files in usr/sbin get 500
39# STORE defaults to basename of src and target directory
40# but we can use
41# ${MANIFEST}.SRCS.sbin += ${OBJTOP}/bin/sh-static/sh-static
42# STORE.sbin/sh-static = sbin/sh
43#
44# the above is a little overkill but means we can easily adapt to
45# different formats
46
47UID.dirs ?= 0
48GID.dirs ?= 0
49MODE.dirs ?= 775
50FLAGS.dirs ?=
51
52UID.files ?= 0
53GID.files ?= 0
54MODE.files ?= 555
55
56# a is attribute name d is dirname
57M_DIR_ATTR = L:@a@$${$$a.$$d:U$${$$a.dirs}}@
58# as above and s is set to the name we store f as
59M_FILE_ATTR = L:@a@$${$$a.$$s:U$${$$a.$$d.files:U$${$$a.files}}}@
60
61# this produces the body of the manifest
62# there should typically be a header prefixed
63_GEN_MTREE_MANIFEST_USE: .USE
64	@(${${.TARGET}.DIRS:O:u:@d@echo '$d type=dir uid=${UID:${M_DIR_ATTR}} gid=${GID:${M_DIR_ATTR}} mode=${MODE:${M_DIR_ATTR}} ${FLAGS:${M_DIR_ATTR}}';@} \
65	${${.TARGET}.DIRS:O:u:@d@${${.TARGET}.SRCS.$d:O:u:@f@echo '${s::=${STORE.$d/${f:T}:U$d/${f:T}}}$s contents="$f" type=file uid=${UID:${M_FILE_ATTR}} gid=${GID:${M_FILE_ATTR}} mode=${MODE:${M_FILE_ATTR}} ${FLAGS:${M_FILE_ATTR}}';@}@} \
66	set ${${.TARGET}.SYMLINKS}; while test $$# -ge 2; do echo "$$2 type=link link=$$1"; shift 2; done) > ${.TARGET}
67