From 957a51a4dad2c82e0ced61ac5813f87ab6752dd7 Mon Sep 17 00:00:00 2001
From: Narek Galstyan <narekg@berkeley.edu>
Date: Sun, 19 Apr 2026 22:07:03 -0400
Subject: [PATCH 1/3] Fix lcov duplicate directory error for non-vpath builds

Fixes `make coverage-html` target on lcov v2 (default on latest Debian).

Commit c3d9a66024a9 added -d $(srcdir) to the lcov commands to support
vpath builds, but did so unconditionally. For non-vpath (in-tree)
builds, $(srcdir) is ".", resulting in "-d . -d ." which causes lcov to
fail with a duplicate file error.
lcov: ERROR: (usage) duplicate file ./src/pl/plpgsql/src/pl_gram.gcno i
both . and .
    (use "lcov --ignore-errors usage ..." to bypass this error)
Message summary:
  1 error message:
    usage: 1
The fix used the same pattern used in commit 5f340cb30ce2 for the
genhtml --prefix option: only add -d $(srcdir) when vpath_build is yes.
---
 src/Makefile.global.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index cef1ad7f87d..dbd5f9d3c40 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1061,12 +1061,12 @@ LCOVFLAGS = -q --no-external
 all_gcno_files = $(shell find . -name '*.gcno' -print)
 
 lcov_base.info: $(all_gcno_files)
-	$(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
+	$(LCOV) $(LCOVFLAGS) -c -i -d . $(if $(filter yes,$(vpath_build)),-d $(srcdir)) -o $@
 
 all_gcda_files = $(shell find . -name '*.gcda' -print)
 
 lcov_test.info: $(all_gcda_files)
-	$(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
+	$(LCOV) $(LCOVFLAGS) -c -d . $(if $(filter yes,$(vpath_build)),-d $(srcdir)) -o $@
 
 
 # hook for clean-up
-- 
2.50.1 (Apple Git-155)

