1#	$NetBSD: bsd.links.mk,v 1.33 2009/03/01 09:42:41 isaki Exp $
2
3.include <bsd.init.mk>
4
5##### Basic targets
6install:	linksinstall
7
8##### Default values
9LINKS?=
10SYMLINKS?=
11LINKSOWN?=	${BINOWN}
12LINKSGRP?=	${BINGRP}
13LINKSMODE?=	${NONBINMODE}
14
15__linkinstall: .USE
16	${_MKSHMSG_INSTALL} ${.TARGET}; \
17	${_MKSHECHO} "${INSTALL_LINK} \
18	    -o ${LINKSOWN_${.ALLSRC:T}:U${LINKSOWN}} \
19	    -g ${LINKSGRP_${.ALLSRC:T}:U${LINKSGRP}} \
20	    -m ${LINKSMODE_${.ALLSRC:T}:U${LINKSMODE}} \
21	    ${.ALLSRC} ${.TARGET}" && \
22	${INSTALL_LINK} \
23	    -o ${LINKSOWN_${.ALLSRC:T}:U${LINKSOWN}} \
24	    -g ${LINKSGRP_${.ALLSRC:T}:U${LINKSGRP}} \
25	    -m ${LINKSMODE_${.ALLSRC:T}:U${LINKSMODE}} \
26	    ${.ALLSRC} ${.TARGET}
27
28##### Install rules
29.PHONY:		linksinstall
30linksinstall::	realinstall
31.if !empty(SYMLINKS)
32	@(set ${SYMLINKS}; \
33	 while test $$# -ge 2; do \
34		l=$$1; shift; \
35		t=${DESTDIR}$$1; shift; \
36		if  ttarg=`${TOOL_STAT} -qf '%Y' $$t` && \
37		    [ "$$l" = "$$ttarg" ]; then \
38			continue ; \
39		fi ; \
40		${_MKSHMSG_INSTALL} $$t; \
41		${_MKSHECHO} ${INSTALL_SYMLINK} $$l $$t; \
42		${INSTALL_SYMLINK} $$l $$t; \
43	 done; )
44.endif
45
46.for _src _dst in ${LINKS}
47_l:=${DESTDIR}${_src}
48_t:=${DESTDIR}${_dst}
49
50# Handle case conflicts carefully, when _dst occurs
51# more than once after case flattening
52.if ${MKUPDATE} == "no" || ${LINKS:tl:M${_dst:tl:Q}:[\#]} > 1
53${_t}!		${_l} __linkinstall
54.else
55${_t}:		${_l} __linkinstall
56.endif
57
58linksinstall::	${_t}
59.PRECIOUS:	${_t}
60.endfor
61
62configinstall:		configlinksinstall
63.PHONY:			configlinksinstall
64configlinksinstall::	configfilesinstall
65.if !empty(CONFIGSYMLINKS)
66	@(set ${CONFIGSYMLINKS}; \
67	 while test $$# -ge 2; do \
68		l=$$1; shift; \
69		t=${DESTDIR}$$1; shift; \
70		if  ttarg=`${TOOL_STAT} -qf '%Y' $$t` && \
71		    [ "$$l" = "$$ttarg" ]; then \
72			continue ; \
73		fi ; \
74		${_MKSHMSG_INSTALL} $$t; \
75		${_MKSHECHO} ${INSTALL_SYMLINK} $$l $$t; \
76		${INSTALL_SYMLINK} $$l $$t; \
77	 done; )
78.endif
79
80.for _src _dst in ${CONFIGLINKS}
81_l:=${DESTDIR}${_src}
82_t:=${DESTDIR}${_dst}
83
84# Handle case conflicts carefully, when _dst occurs
85# more than once after case flattening
86.if ${MKUPDATE} == "no" || ${CONFIGLINKS:tl:M${_dst:tl:Q}:[\#]} > 1
87${_t}!		${_l} __linkinstall
88.else
89${_t}:		${_l} __linkinstall
90.endif
91
92configlinksinstall::	${_t}
93.PRECIOUS:	${_t}
94.endfor
95
96.include <bsd.sys.mk>
97