xref: /dflybsd-src/contrib/bmake/mk/manifest.mk (revision a34d5fb143d34c0e1d2580296c500e2c8a5bc5dc)
1*a34d5fb1SAntonio Huete Jimenez# $Id: manifest.mk,v 1.3 2020/08/19 17:51:53 sjg Exp $
26a91b982SJohn Marino#
36a91b982SJohn Marino#	@(#) Copyright (c) 2014, Simon J. Gerraty
46a91b982SJohn Marino#
56a91b982SJohn Marino#	This file is provided in the hope that it will
66a91b982SJohn Marino#	be of use.  There is absolutely NO WARRANTY.
76a91b982SJohn Marino#	Permission to copy, redistribute or otherwise
86a91b982SJohn Marino#	use this file is hereby granted provided that
96a91b982SJohn Marino#	the above copyright notice and this notice are
106a91b982SJohn Marino#	left intact.
116a91b982SJohn Marino#
126a91b982SJohn Marino#	Please send copies of changes and bug-fixes to:
136a91b982SJohn Marino#	sjg@crufty.net
146a91b982SJohn Marino#
156a91b982SJohn Marino
166a91b982SJohn Marino# generate mtree style manifest supported by makefs in FreeBSD
176a91b982SJohn Marino
186a91b982SJohn Marino# input looks like
196a91b982SJohn Marino# MANIFEST= my.mtree
206a91b982SJohn Marino# for each MANIFEST we have a list of dirs
216a91b982SJohn Marino# ${MANIFEST}.DIRS += bin sbin usr/bin ...
226a91b982SJohn Marino# for each dir we have a ${MANIFEST}.SRCS.$dir
236a91b982SJohn Marino# that provides the absolute path to the contents
246a91b982SJohn Marino# ${MANIFEST}.SRCS.bin += ${OBJTOP}/bin/sh/sh
256a91b982SJohn Marino# ${MANIFEST}.SYMLINKS is a list of src target pairs
266a91b982SJohn Marino# for each file/dir there are a number of attributes
276a91b982SJohn Marino# UID GID MODE FLAGS
286a91b982SJohn Marino# which can be set per dir, per file or we use defaults
296a91b982SJohn Marino# eg.
306a91b982SJohn Marino# MODE.sbin = 550
316a91b982SJohn Marino# MODE.usr/sbin = 550
326a91b982SJohn Marino# MODE.dirs = 555
336a91b982SJohn Marino# means that sbin and usr/sbin get 550 all other dirs get 555
346a91b982SJohn Marino# MODE.usr/bin/passwd = 4555
356a91b982SJohn Marino# MODE.usr/bin.files = 555
366a91b982SJohn Marino# MODE.usr/sbin.files = 500
376a91b982SJohn Marino# means passwd gets 4555 other files in usr/bin get 555 and
386a91b982SJohn Marino# files in usr/sbin get 500
396a91b982SJohn Marino# STORE defaults to basename of src and target directory
406a91b982SJohn Marino# but we can use
416a91b982SJohn Marino# ${MANIFEST}.SRCS.sbin += ${OBJTOP}/bin/sh-static/sh-static
426a91b982SJohn Marino# STORE.sbin/sh-static = sbin/sh
436a91b982SJohn Marino#
446a91b982SJohn Marino# the above is a little overkill but means we can easily adapt to
456a91b982SJohn Marino# different formats
466a91b982SJohn Marino
476a91b982SJohn MarinoUID.dirs ?= 0
486a91b982SJohn MarinoGID.dirs ?= 0
496a91b982SJohn MarinoMODE.dirs ?= 775
506a91b982SJohn MarinoFLAGS.dirs ?=
516a91b982SJohn Marino
526a91b982SJohn MarinoUID.files ?= 0
536a91b982SJohn MarinoGID.files ?= 0
546a91b982SJohn MarinoMODE.files ?= 555
556a91b982SJohn Marino
566a91b982SJohn Marino# a is attribute name d is dirname
576a91b982SJohn MarinoM_DIR_ATTR = L:@a@$${$$a.$$d:U$${$$a.dirs}}@
586a91b982SJohn Marino# as above and s is set to the name we store f as
596a91b982SJohn MarinoM_FILE_ATTR = L:@a@$${$$a.$$s:U$${$$a.$$d.files:U$${$$a.files}}}@
606a91b982SJohn Marino
616a91b982SJohn Marino# this produces the body of the manifest
626a91b982SJohn Marino# there should typically be a header prefixed
636a91b982SJohn Marino_GEN_MTREE_MANIFEST_USE: .USE
646a91b982SJohn Marino	@(${${.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}}';@} \
656a91b982SJohn Marino	${${.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}}';@}@} \
666a91b982SJohn Marino	set ${${.TARGET}.SYMLINKS}; while test $$# -ge 2; do echo "$$2 type=link link=$$1"; shift 2; done) > ${.TARGET}
67