1# SPDX-License-Identifier: BSD-2-Clause 2# 3# $Id: scripts.mk,v 1.5 2024/02/17 17:26:57 sjg Exp $ 4# 5# @(#) Copyright (c) 2006, Simon J. Gerraty 6# 7# This file is provided in the hope that it will 8# be of use. There is absolutely NO WARRANTY. 9# Permission to copy, redistribute or otherwise 10# use this file is hereby granted provided that 11# the above copyright notice and this notice are 12# left intact. 13# 14# Please send copies of changes and bug-fixes to: 15# sjg@crufty.net 16# 17 18.include <init.mk> 19 20SCRIPTSGROUPS ?= SCRIPTS 21SCRIPTSGROUPS := ${SCRIPTSGROUPS:O:u} 22 23SCRIPTSDIR?= ${BINDIR} 24SCRIPTSOWN?= ${BINOWN} 25SCRIPTSGRP?= ${BINGRP} 26SCRIPTSMODE?= ${BINMODE} 27 28SCRIPTS_INSTALL_OWN?= -o ${SCRIPTSOWN} -g ${SCRIPTSGRP} 29SCRIPTS_COPY ?= -C 30 31# how we get script name from src 32SCRIPTSNAME_MOD?=T:R 33 34.if !target(buildfiles) 35.for group in ${SCRIPTSGROUPS} 36buildfiles: ${${group}} 37.endfor 38.endif 39buildfiles: 40realbuild: buildfiles 41 42.for group in ${SCRIPTSGROUPS} 43.if !empty(${group}) && defined(${group}DIR) 44.if ${group} != "SCRIPTS" 45${group}_INSTALL_OWN ?= ${SCRIPTS_INSTALL_OWN} 46.endif 47# incase we are staging 48STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR} 49 50.for script in ${${group}:O:u} 51${group}_INSTALL_OWN.${script:T} ?= ${${group}_INSTALL_OWN} 52${group}DIR.${script:T} ?= ${${group}DIR_${script:T}:U${${group}DIR}} 53script_mkdir_list += ${${group}DIR.${script:T}} 54 55${group}NAME.${script} ?= ${${group}NAME_${script:T}:U${script:${SCRIPTSNAME_MOD}}} 56.if ${${group}NAME.${script}:T} != ${script:T} 57STAGE_AS_SETS += ${group} 58STAGE_AS_${script} = ${${group}NAME.${script:T}} 59stage_as.${group}: ${script} 60 61installscripts: installscripts.${group}.${script:T} 62installscripts.${group}.${script:T}: ${script} script_mkdirs 63 ${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN.${script:T}} \ 64 -m ${SCRIPTSMODE} ${.ALLSRC:Nscript_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${script:T}} 65 66.else 67STAGE_SETS += ${group} 68stage_files.${group}: ${script} 69installscripts.${group}: ${script} 70installscripts: installscripts.${group} 71.endif 72 73.endfor # script 74 75installscripts.${group}: script_mkdirs 76 ${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN} -m ${SCRIPTSMODE} \ 77 ${.ALLSRC:Nscript_mkdirs:O:u} ${DESTDIR}${${group}DIR} 78 79.endif # !empty 80.endfor # group 81 82script_mkdirs: 83 @for d in ${script_mkdir_list:O:u}; do \ 84 test -d ${DESTDIR}$$d || \ 85 ${INSTALL} -d ${SCRIPTS_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \ 86 done 87 88 89beforeinstall: 90installscripts: 91realinstall: installscripts 92.ORDER: beforeinstall installscripts 93 94