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