xref: /dragonfly/contrib/bmake/mk/scripts.mk (revision 631c21f2)
1# $Id: scripts.mk,v 1.4 2020/08/19 17:51:53 sjg Exp $
2#
3#	@(#) Copyright (c) 2006, 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
18SCRIPTSGROUPS ?= SCRIPTS
19SCRIPTSGROUPS := ${SCRIPTSGROUPS:O:u}
20
21SCRIPTSDIR?=	${BINDIR}
22SCRIPTSOWN?=	${BINOWN}
23SCRIPTSGRP?=	${BINGRP}
24SCRIPTSMODE?=	${BINMODE}
25
26SCRIPTS_INSTALL_OWN?= -o ${SCRIPTSOWN} -g ${SCRIPTSGRP}
27SCRIPTS_COPY ?= -C
28
29# how we get script name from src
30SCRIPTSNAME_MOD?=T:R
31
32.if !target(buildfiles)
33.for group in ${SCRIPTSGROUPS}
34buildfiles: ${${group}}
35.endfor
36.endif
37buildfiles:
38realbuild: buildfiles
39
40.for group in ${SCRIPTSGROUPS}
41.if !empty(${group}) && defined(${group}DIR)
42.if ${group} != "SCRIPTS"
43${group}_INSTALL_OWN ?= ${SCRIPTS_INSTALL_OWN}
44.endif
45# incase we are staging
46STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
47
48.for script in ${${group}:O:u}
49${group}_INSTALL_OWN.${script:T} ?= ${${group}_INSTALL_OWN}
50${group}DIR.${script:T} ?= ${${group}DIR_${script:T}:U${${group}DIR}}
51script_mkdir_list += ${${group}DIR.${script:T}}
52
53${group}NAME.${script} ?= ${${group}NAME_${script:T}:U${script:${SCRIPTSNAME_MOD}}}
54.if ${${group}NAME.${script}:T} != ${script:T}
55STAGE_AS_SETS += ${group}
56STAGE_AS_${script} = ${${group}NAME.${script:T}}
57stage_as.${group}: ${script}
58
59installscripts: installscripts.${group}.${script:T}
60installscripts.${group}.${script:T}: ${script} script_mkdirs
61	${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN.${script:T}} \
62	-m ${SCRIPTSMODE} ${.ALLSRC:Nscript_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${script:T}}
63
64.else
65STAGE_SETS += ${group}
66stage_files.${group}: ${script}
67installscripts.${group}: ${script}
68installscripts: installscripts.${group}
69.endif
70
71.endfor				# script
72
73installscripts.${group}: script_mkdirs
74	${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN} -m ${SCRIPTSMODE} \
75	${.ALLSRC:Nscript_mkdirs:O:u} ${DESTDIR}${${group}DIR}
76
77.endif				# !empty
78.endfor				# group
79
80script_mkdirs:
81	@for d in ${script_mkdir_list:O:u}; do \
82		test -d ${DESTDIR}$$d || \
83		${INSTALL} -d ${SCRIPTS_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
84	done
85
86
87beforeinstall:
88installscripts:
89realinstall:	installscripts
90.ORDER: beforeinstall installscripts
91
92