From ef21e4f17e104a34e7db89215db567cddd48832d Mon Sep 17 00:00:00 2001
From: Pier Angelo Vendrame <pierov@torproject.org>
Date: Wed, 1 Mar 2023 10:19:50 +0100
Subject: [PATCH] Sort the object list passed to ar in the Makefile.

This makes builds reproducible.
---
 Makefile | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index c31e3d7..f350ecb 100644
--- a/Makefile
+++ b/Makefile
@@ -488,13 +488,13 @@ $(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBW
 %.a:
 	@mkdir -p "$(@D)"
 	# On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
-	$(AR) crs $@ $(wordlist 1, 199, $^)
-	$(AR) crs $@ $(wordlist 200, 399, $^)
-	$(AR) crs $@ $(wordlist 400, 599, $^)
-	$(AR) crs $@ $(wordlist 600, 799, $^)
+	$(AR) crs $@ $(wordlist 1, 199, $(sort $^))
+	$(AR) crs $@ $(wordlist 200, 399, $(sort $^))
+	$(AR) crs $@ $(wordlist 400, 599, $(sort $^))
+	$(AR) crs $@ $(wordlist 600, 799, $(sort $^))
 	# This might eventually overflow again, but at least it'll do so in a loud way instead of
 	# silently dropping the tail.
-	$(AR) crs $@ $(wordlist 800, 100000, $^)
+	$(AR) crs $@ $(wordlist 800, 100000, $(sort $^))
 
 $(MUSL_PRINTSCAN_OBJS): CFLAGS += \
 	    -D__wasilibc_printscan_no_long_double \
-- 
2.39.2

