Subject: toolchain/16885: Linked files are added to METALOG when program isn't rebuilt
To: None <gnats-bugs@gnats.netbsd.org>
From: None <david@l8s.co.uk>
List: netbsd-bugs
Date: 05/18/2002 18:19:37
>Number:         16885
>Category:       toolchain
>Synopsis:       Linked files are added to METALOG when program isn't rebuilt
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 18 10:19:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     David Laight
>Release:        NetBSD 1.5ZC
>Organization:
None
>Environment:
System: NetBSD snowdrop 1.5ZC NetBSD 1.5ZC (GENERIC) #10: Thu May 16 12:50:04 BST 2002 dsl@snowdrop:/oldroot/usr/bsd-current/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	When a program that has multiple names is installed, the hard links
	are regenerated on every build.
	For UNPRIVED builds this adds records to the METALOG file during
	UPDATE builds - even though the entry for the program itself isn't
	in the METALOG file.
	This is doubly annoying because the entries for the links are
	incorrect :-(
>How-To-Repeat:
	rerun 'build.sh -d -u -U -D $DESTDIR -O $OBJDIR' and note that
	entries for commands with synonyms are added to METALOG even
	though the programs aren't rebuild.
	(eg usr/bin/at has links atq, atrm and batch)
>Fix:
	Change bsd.links.mk so that ${INSTALL_LINK} is only executed when the
	file inode numbers are different.

	I've also changed the SYMLINKS copy to save exec'ing awk for
	every symlink.
	The subshells are no longer needed as there is no requirement
	to redirect the output.  I also don't understand rev 1.12!

Index: bsd.links.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.links.mk,v
retrieving revision 1.19
diff -u -r1.19 bsd.links.mk
--- bsd.links.mk	2002/04/30 14:29:01	1.19
+++ bsd.links.mk	2002/05/18 17:10:34
@@ -11,30 +11,30 @@
 ##### Install rules
 linksinstall::	realinstall
 .if !empty(SYMLINKS)
-	@(set ${SYMLINKS}; \
-	 while test $$# -ge 2; do \
-		l=$$1; shift; \
-		t=${DESTDIR}$$1; shift; \
-		if [ -h $$t ]; then \
-			cur=`ls -ld $$t | awk '{print $$NF}'` ; \
-			if [ "$$cur" = "$$l" ]; then \
-				continue ; \
-			fi; \
-		fi; \
-		echo "$$t -> $$l"; \
-		rm -rf $$t; ${INSTALL_SYMLINK} $$l $$t; \
-	 done; )
+	@ l=; for t in ${SYMLINKS}; do \
+		[ -z "$$l" ] && { l=$$t; continue; }; \
+		t=${DESTDIR}$$t; \
+		lt=; \
+		[ -h "$$t" ] && { set -- `ls -lnd $$t`; eval lt=\$${$$#}; }; \
+		[ "$${lt}" != "$$l" ] && { \
+			echo "$$t -> $$l"; \
+			rm -rf $$t; ${INSTALL_SYMLINK} $$l $$t; \
+		}; \
+		l=; \
+	 done;
 .endif
 .if !empty(LINKS)
-	@(set ${LINKS}; \
-	 echo ".include <bsd.own.mk>"; \
-	 while test $$# -ge 2; do \
-		l=${DESTDIR}$$1; shift; \
-		t=${DESTDIR}$$1; shift; \
-		echo "realall: $$t"; \
-		echo "$$t!"; \
-		echo "	@echo \"$$t -> $$l\""; \
-		echo "	@rm -f $$t; ${INSTALL_LINK} $$l $$t"; \
-	 done; \
-	) | ${MAKE} -f- all
+	@ l=; for t in ${LINKS}; do \
+		t=${DESTDIR}$$t; \
+		[ -z "$$l" ] && { l=$$t; continue; }; \
+		[ -f "$$t" ] && { set -- `ls -lind $$t`; ti=$$1; } || ti=; \
+		[ -f "$$l" ] && { set -- `ls -lind $$l`; li=$$1; } || li=; \
+		[ -n "$$li" -a "$$ti" != "$$li" ] && { \
+			echo "$$t -> $$l"; \
+			rm -f $$t; ${INSTALL_LINK} $$l $$t; \
+		}; \
+		l=; \
+	 done;
 .endif
>Release-Note:
>Audit-Trail:
>Unformatted: