xref: /freebsd/contrib/bmake/mk/inc.mk (revision c59c3bf3)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: inc.mk,v 1.9 2024/02/17 17:26:57 sjg Exp $
4#
5#	@(#) Copyright (c) 2008, 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
20.if !empty(LIBOWN)
21INC_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
22.endif
23INCMODE ?= 444
24INC_COPY ?= -C
25INCSDIR ?= ${INCDIR}
26
27STAGE_INCSDIR?= ${STAGE_OBJTOP}${INCSDIR}
28
29# accommodate folk used to freebsd
30INCGROUPS ?= ${INCSGROUPS:UINCS}
31INCGROUPS := ${INCGROUPS:O:u}
32
33.if !target(buildincludes)
34.for group in ${INCGROUPS}
35buildincludes: ${${group}}
36.endfor
37.endif
38buildincludes:
39includes: buildincludes
40
41.if !target(incinstall)
42.for group in ${INCGROUPS}
43.if !empty(${group})
44.if ${group} != "INC"
45${group}_INSTALL_OWN ?= ${INC_INSTALL_OWN}
46${group}DIR ?= ${INCDIR}
47.endif
48# incase we are staging
49STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
50
51.for header in ${${group}:O:u}
52${group}_INSTALL_OWN.${header:T} ?= ${${group}_INSTALL_OWN}
53${group}DIR.${header:T} ?= ${${group}DIR}
54inc_mkdir_list += ${${group}DIR.${header:T}}
55
56.if defined(${group}NAME.${header:T})
57STAGE_AS_SETS += ${group}
58STAGE_AS_${header} = ${${group}NAME.${header:T}}
59stage_as.${group}: ${header}
60
61incinstall: incinstall.${group}.${header:T}
62incinstall.${group}.${header:T}: ${header} inc_mkdirs
63	${INSTALL} ${INC_COPY} ${${group}_INSTALL_OWN.${header:T}} -m ${INCMODE} ${.ALLSRC:Ninc_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${header:T}}
64
65.else
66STAGE_SETS += ${group}
67stage_files.${group}: ${header}
68incinstall.${group}: ${header}
69incinstall: incinstall.${group}
70.endif
71
72.endfor				# header
73
74incinstall.${group}: inc_mkdirs
75	${INSTALL} ${INC_COPY} ${${group}_INSTALL_OWN} -m ${INCMODE} \
76	${.ALLSRC:Ninc_mkdirs:O:u} ${DESTDIR}${${group}DIR}
77
78.endif				# !empty
79.endfor				# group
80
81inc_mkdirs:
82	@for d in ${inc_mkdir_list:O:u}; do \
83		test -d ${DESTDIR}$$d || \
84		${INSTALL} -d ${INC_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
85	done
86
87.endif				# !target(incinstall)
88
89beforeinstall:
90realinstall:	incinstall
91.ORDER: beforeinstall incinstall
92