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