From f1c8f60b885d45105d7c9b9529ac13a692a7b615 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= <des@FreeBSD.org>
Date: Sat, 12 Apr 2014 12:44:09 +0000
Subject: [PATCH] Introduce RANLIBFLAGS to mirror ARFLAGS and add -D to both. 
 This sets all timestamps in static libraries to 0 so that consecutive builds
 from the same source, even on different machines, produce identical
 libraries.

MFC after:	3 weeks
---
 gnu/lib/libgcc/Makefile | 4 ++--
 share/mk/bsd.lib.mk     | 6 +++---
 share/mk/sys.mk         | 5 ++++-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/gnu/lib/libgcc/Makefile b/gnu/lib/libgcc/Makefile
index d186e7ef5921..d3befcbb89a8 100644
--- a/gnu/lib/libgcc/Makefile
+++ b/gnu/lib/libgcc/Makefile
@@ -352,7 +352,7 @@ libgcc_eh.a:	${EH_OBJS_T}
 	@${ECHO} building static gcc_eh library
 	@rm -f ${.TARGET}
 	@${AR} ${ARFLAGS} ${.TARGET} `lorder ${EH_OBJS_T} | tsort -q`
-	${RANLIB} ${.TARGET}
+	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
 
 all:	libgcc_eh.a
 
@@ -361,7 +361,7 @@ libgcc_eh_p.a:	${EH_OBJS_P}
 	@${ECHO} building profiled gcc_eh library
 	@rm -f ${.TARGET}
 	@${AR} ${ARFLAGS} ${.TARGET} `lorder ${EH_OBJS_P} | tsort -q`
-	${RANLIB} ${.TARGET}
+	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
 all:	libgcc_eh_p.a
 .endif
 
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index bb3db64c5763..f3f0d45487e1 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -172,7 +172,7 @@ lib${LIB}.a: ${OBJS} ${STATICOBJS}
 .else
 	@${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
 .endif
-	${RANLIB} ${.TARGET}
+	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
 .endif
 
 .if !defined(INTERNALLIB)
@@ -189,7 +189,7 @@ lib${LIB}_p.a: ${POBJS}
 .else
 	@${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
 .endif
-	${RANLIB} ${.TARGET}
+	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
 .endif
 
 .if defined(SHLIB_NAME) || \
@@ -246,7 +246,7 @@ lib${LIB}_pic.a: ${SOBJS}
 	@${ECHO} building special pic ${LIB} library
 	@rm -f ${.TARGET}
 	@${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD}
-	${RANLIB} ${.TARGET}
+	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
 .endif
 
 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
diff --git a/share/mk/sys.mk b/share/mk/sys.mk
index bb5b03520620..23a4040e831e 100644
--- a/share/mk/sys.mk
+++ b/share/mk/sys.mk
@@ -39,9 +39,12 @@ AR		?=	ar
 .if defined(%POSIX)
 ARFLAGS		?=	-rv
 .else
-ARFLAGS		?=	cru
+ARFLAGS		?=	-crD
 .endif
 RANLIB		?=	ranlib
+.if !defined(%POSIX)
+RANLIBFLAGS	?=	-D
+.endif
 
 AS		?=	as
 AFLAGS		?=