vendor/bmake: upgrade from 20210206 to 20210314
[dragonfly.git] / contrib / bmake / mk / files.mk
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
18 FILES_INSTALL_OWN ?= -o ${SHAREOWN} -g ${SHAREGRP}
19 FILESMODE ?= ${SHAREMODE}
20 FILES_COPY ?= -C
21
22 FILESGROUPS ?= FILES
23 FILESGROUPS := ${FILESGROUPS:O:u}
24
25 .if !target(buildfiles)
26 .for group in ${FILESGROUPS}
27 buildfiles: ${${group}}
28 .endfor
29 .endif
30 buildfiles:
31 realbuild: 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
41 STAGE_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}
46 file_mkdir_list += ${${group}DIR.${file:T}}
47
48 .if defined(${group}NAME.${file:T})
49 STAGE_AS_SETS += ${group}
50 STAGE_AS_${file} = ${${group}NAME.${file:T}}
51 stage_as.${group}: ${file}
52
53 installfiles: installfiles.${group}.${file:T}
54 installfiles.${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
59 STAGE_SETS += ${group}
60 stage_files.${group}: ${file}
61 installfiles.${group}: ${file}
62 installfiles: installfiles.${group}
63 .endif
64
65 .endfor                         # file
66
67 installfiles.${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
74 file_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
80 beforeinstall:
81 installfiles:
82 realinstall:    installfiles
83 .ORDER: beforeinstall installfiles