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