Skip to content

Commit 0ef442e

Browse files
Makefile: dedup archives in $(LIBS) so link recipes don't repeat them
A handful of link recipes listed archive files twice: once explicitly via $(filter %.a,$^) and again implicitly through $(LIBS), which expanded to $(filter-out %.o,$(GITLIBS)) $(EXTLIBS). On macOS the linker warned about the duplicates: ld: warning: ignoring duplicate libraries: 'libgit.a', 'target/release/libgitcore.a' Redefine $(LIBS) to list archive prerequisites from $^ first, then the rest of the library list with those archives filtered out so each appears only once. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
1 parent 9ac3f19 commit 0ef442e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,9 @@ endif
25032503
#
25042504
# where we use it as a dependency. Since we also pull object files
25052505
# from the dependency list, that would make each entry appear twice.
2506-
LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
2506+
# Archives from $^ come first, then the rest with those archives
2507+
# filtered out so each appears only once.
2508+
LIBS = $(filter %.a,$^) $(filter-out $(filter %.a,$^),$(filter-out %.o,$(GITLIBS)) $(EXTLIBS))
25072509

25082510
BASIC_CFLAGS += $(COMPAT_CFLAGS)
25092511
LIB_OBJS += $(COMPAT_OBJS)
@@ -3392,7 +3394,7 @@ perf: all
33923394
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
33933395

33943396
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
3395-
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
3397+
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
33963398

33973399
check-sha1:: t/helper/test-tool$X
33983400
t/helper/test-sha1.sh
@@ -4015,13 +4017,13 @@ fuzz-all: $(FUZZ_PROGRAMS)
40154017
$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
40164018
$(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
40174019
-Wl,--allow-multiple-definition \
4018-
$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
4020+
$(filter %.o,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
40194021

40204022
$(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
40214023
$(GITLIBS) GIT-LDFLAGS
40224024
$(call mkdir_p_parent_template)
40234025
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
4024-
$(filter %.o,$^) $(filter %.a,$^) $(LIBS)
4026+
$(filter %.o,$^) $(LIBS)
40254027

40264028
GIT-TEST-SUITES: FORCE
40274029
@FLAGS='$(CLAR_TEST_SUITES)'; \

0 commit comments

Comments
 (0)