xref: /freebsd/contrib/bmake/mk/links.mk (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
1# $Id: links.mk,v 1.6 2014/09/29 17:14:40 sjg Exp $
2#
3#	@(#) Copyright (c) 2005, 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# some platforms need something special
17LN?= ln
18ECHO?= echo
19
20LINKS?=
21SYMLINKS?=
22
23__SYMLINK_SCRIPT= \
24		${ECHO} "$$t -> $$l"; \
25		case `'ls' -l $$t 2> /dev/null` in \
26		*"> $$l") ;; \
27		*) \
28			mkdir -p `dirname $$t`; \
29			rm -f $$t; \
30			${LN} -s $$l $$t;; \
31		esac
32
33
34__LINK_SCRIPT= \
35		${ECHO} "$$t -> $$l"; \
36		mkdir -p `dirname $$t`; \
37		rm -f $$t; \
38		${LN} $$l $$t
39
40_SYMLINKS_SCRIPT= \
41	while test $$\# -ge 2; do \
42		l=$$1; shift; \
43		t=${DESTDIR}$$1; shift; \
44		${__SYMLINK_SCRIPT}; \
45	done; :;
46
47_LINKS_SCRIPT= \
48	while test $$\# -ge 2; do \
49		l=${DESTDIR}$$1; shift; \
50		t=${DESTDIR}$$1; shift; \
51		${__LINK_SCRIPT}; \
52	done; :;
53
54_SYMLINKS_USE:	.USE
55	@set ${$@_SYMLINKS:U${SYMLINKS}}; ${_SYMLINKS_SCRIPT}
56
57_LINKS_USE:	.USE
58	@set ${$@_LINKS:U${LINKS}}; ${_LINKS_SCRIPT}
59
60
61# sometimes we want to ensure DESTDIR is ignored
62_BUILD_SYMLINKS_SCRIPT= \
63	while test $$\# -ge 2; do \
64		l=$$1; shift; \
65		t=$$1; shift; \
66		${__SYMLINK_SCRIPT}; \
67	done; :;
68
69_BUILD_LINKS_SCRIPT= \
70	while test $$\# -ge 2; do \
71		l=$$1; shift; \
72		t=$$1; shift; \
73		${__LINK_SCRIPT}; \
74	done; :;
75
76_BUILD_SYMLINKS_USE:	.USE
77	@set ${$@_SYMLINKS:U${SYMLINKS}}; ${_BUILD_SYMLINKS_SCRIPT}
78
79_BUILD_LINKS_USE:	.USE
80	@set ${$@_LINKS:U${LINKS}}; ${_BUILD_LINKS_SCRIPT}
81