xref: /freebsd/contrib/bmake/mk/files.mk (revision a91a246563dffa876a52f53a98de4af9fa364c52)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: files.mk,v 1.8 2024/02/17 17:26:57 sjg Exp $
4#
5#	@(#) Copyright (c) 2017, 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.include <init.mk>
19
20FILES_INSTALL_OWN ?= -o ${SHAREOWN} -g ${SHAREGRP}
21FILESMODE ?= ${SHAREMODE}
22FILES_COPY ?= -C
23
24FILESGROUPS ?= FILES
25FILESGROUPS := ${FILESGROUPS:O:u}
26
27.if !target(buildfiles)
28.for group in ${FILESGROUPS}
29buildfiles: ${${group}}
30.endfor
31.endif
32buildfiles:
33realbuild: buildfiles
34
35# there is no default FILESDIR so
36# ignore group if ${group}DIR is not defined
37.for group in ${FILESGROUPS}
38.if !empty(${group}) && defined(${group}DIR)
39.if ${group} != "FILES"
40${group}_INSTALL_OWN ?= ${FILES_INSTALL_OWN}
41.endif
42# incase we are staging
43STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
44
45.for file in ${${group}:O:u}
46${group}_INSTALL_OWN.${file:T} ?= ${${group}_INSTALL_OWN}
47${group}DIR.${file:T} ?= ${${group}DIR}
48file_mkdir_list += ${${group}DIR.${file:T}}
49
50.if defined(${group}NAME.${file:T})
51STAGE_AS_SETS += ${group}
52STAGE_AS_${file} = ${${group}NAME.${file:T}}
53stage_as.${group}: ${file}
54
55installfiles: installfiles.${group}.${file:T}
56installfiles.${group}.${file:T}: ${file} file_mkdirs
57	${INSTALL} ${FILES_COPY} ${${group}_INSTALL_OWN.${file:T}} \
58	-m ${FILESMODE} ${.ALLSRC:Nfile_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${file:T}}
59
60.else
61STAGE_SETS += ${group}
62stage_files.${group}: ${file}
63installfiles.${group}: ${file}
64installfiles: installfiles.${group}
65.endif
66
67.endfor				# file
68
69installfiles.${group}: file_mkdirs
70	${INSTALL} ${FILES_COPY} ${${group}_INSTALL_OWN} -m ${FILESMODE} \
71	${.ALLSRC:Nfile_mkdirs:O:u} ${DESTDIR}${${group}DIR}
72
73.endif				# !empty
74.endfor				# group
75
76file_mkdirs:
77	@for d in ${file_mkdir_list:O:u}; do \
78		test -d ${DESTDIR}$$d || \
79		${INSTALL} -d ${FILES_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
80	done
81
82beforeinstall:
83installfiles:
84realinstall:	installfiles
85.ORDER: beforeinstall installfiles
86