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