xref: /freebsd/share/mk/bsd.files.mk (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1# $FreeBSD$
2
3.if !target(__<bsd.init.mk>__)
4.error bsd.files.mk cannot be included directly.
5.endif
6
7.if !target(__<bsd.files.mk>__)
8.if target(__<bsd.dirs.mk>__)
9.error bsd.dirs.mk must be included after bsd.files.mk.
10.endif
11
12__<bsd.files.mk>__:
13
14FILESGROUPS?=	FILES
15
16.for group in ${FILESGROUPS}
17# Add in foo.yes and remove duplicates from all the groups
18${${group}}:= ${${group}} ${${group}.yes}
19${${group}}:= ${${group}:O:u}
20buildfiles: ${${group}}
21.endfor
22
23.if !defined(_SKIP_BUILD)
24all: buildfiles
25.endif
26
27.for group in ${FILESGROUPS}
28.if defined(${group}) && !empty(${group})
29installfiles: installfiles-${group}
30
31${group}OWN?=	${SHAREOWN}
32${group}GRP?=	${SHAREGRP}
33.if ${MK_INSTALL_AS_USER} == "yes"
34${group}OWN=	${SHAREOWN}
35${group}GRP=	${SHAREGRP}
36.endif
37${group}MODE?=	${SHAREMODE}
38${group}DIR?=	BINDIR
39STAGE_SETS+=	${group:C,[/*],_,g}
40
41.if ${group} == "FILES"
42FILESPACKAGE?=	${PACKAGE:Uutilities}
43.endif
44
45.if defined(NO_ROOT)
46.if !defined(${group}TAGS) || ! ${${group}TAGS:Mpackage=*}
47${group}TAGS+=		package=${${group}PACKAGE:Uutilities}
48.endif
49${group}TAG_ARGS=	-T ${${group}TAGS:[*]:S/ /,/g}
50.endif
51
52
53.if ${${group}DIR:S/^\///} == ${${group}DIR}
54# ${group}DIR specifies a variable that specifies a path
55DIRS+=	${${group}DIR}
56${group}DIRTAGS=	${group}TAGS
57_${group}DIR=	${${group}DIR}
58.else
59# ${group}DIR specifies a path
60DIRS+=	${group}DIR
61${group}DIRTAGS=	${${group}TAGS}
62_${group}DIR=	${group}DIR
63.endif
64
65STAGE_DIR.${group:C,[/*],_,g}= ${STAGE_OBJTOP}${${_${group}DIR}}
66
67.for file in ${${group}}
68${group}OWN_${file}?=	${${group}OWN}
69${group}GRP_${file}?=	${${group}GRP}
70.if ${MK_INSTALL_AS_USER} == "yes"
71${group}OWN_${file}=	${SHAREOWN}
72${group}GRP_${file}=	${SHAREGRP}
73.endif # ${MK_INSTALL_AS_USER} == "yes"
74${group}MODE_${file}?=	${${group}MODE}
75
76# Determine the directory for the current file.  Default to the parent group
77# DIR, then check to see how to pass that variable on below.
78${group}DIR_${file}?=	${${group}DIR}
79.if ${${group}DIR_${file}:S/^\///} == ${${group}DIR_${file}}
80# DIR specifies a variable that specifies a path
81_${group}DIR_${file}=	${${group}DIR_${file}}
82.else
83# DIR directly specifies a path
84_${group}DIR_${file}=	${group}DIR_${file}
85.endif
86${group}PREFIX_${file}=	${DESTDIR}${${_${group}DIR_${file}}}
87
88# Append DIR to DIRS if not already in place -- DIRS is already filtered, so
89# this is primarily to ease inspection.
90.for d in ${DIRS}
91_DIRS+=	${${d}}
92.endfor
93.if ${DIRS:M${_${group}DIR_${file}}} == ""
94.if ${_DIRS:M${${_${group}DIR_${file}}}} == ""
95DIRS+=	${_${group}DIR_${file}}
96.else
97_${group}DIR_${file}=	${group}DIR
98.endif
99.endif
100
101.if defined(${group}NAME)
102${group}NAME_${file}?=	${${group}NAME}
103.else
104${group}NAME_${file}?=	${file:T}
105.endif # defined(${group}NAME)
106STAGE_AS_${file}= ${${group}NAME_${file}}
107# we cannot use file safely as a set name
108# since we cannot? apply :T
109# but we can use the ${group}DIR_${file}
110# as a set - meta.stage.mk will :O:u for us
111# we need to expand ${group}DIR_${file} and replace
112# all '/' and '*' with '_' to make a safe target name.
113STAGE_AS_SETS+=	${${_${group}DIR_${file}}:C,[/*],_,g}
114STAGE_DIR.${${_${group}DIR_${file}}:C,[/*],_,g}= ${STAGE_OBJTOP}${${_${group}DIR_${file}}}
115stage_as.${${_${group}DIR_${file}}:C,[/*],_,g}: ${file}
116
117installfiles-${group}: _${group}INS_${file}
118_${group}INS_${file}: ${file} installdirs-${_${group}DIR_${file}}
119	${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN_${file}} \
120	    -g ${${group}GRP_${file}} -m ${${group}MODE_${file}} \
121	    ${.ALLSRC:Ninstalldirs-*} ${${group}PREFIX_${file}}/${${group}NAME_${file}}
122.endfor # file in ${${group}}
123
124.endif # defined(${group}) && !empty(${group})
125.endfor # .for group in ${FILESGROUPS}
126
127realinstall: installfiles
128.ORDER: beforeinstall installfiles
129
130.if ${MK_STAGING} != "no"
131.if ${FILESGROUPS:@g@${$g}@} != ""
132.if !empty(STAGE_SETS)
133buildfiles: stage_files
134STAGE_TARGETS+= stage_files
135stage_files:
136.if !empty(STAGE_AS_SETS)
137buildfiles: stage_as
138STAGE_TARGETS+= stage_as
139stage_as:
140.endif
141.endif
142.endif
143.endif
144
145.include <bsd.dirs.mk>
146
147.endif # !target(__<bsd.files.mk>__)
148