From 0f722396846277387c88606addbaa8160f3eee9e Mon Sep 17 00:00:00 2001
From: Maksim Melnikov <m.melnikov@postgrespro.ru>
Date: Fri, 27 Mar 2026 13:33:09 +0300
Subject: [PATCH v2] Fix race with LLVM compilation and bison code generation.

In case when source file is compiled with LLVM and include header file
that should be generated by bison, compile error can occur, example:

cubescan.c:9:10: fatal error: 'cubeparse.h' file not found
    9 | #include "cubeparse.h"

The reason is race, that exist between LLVM compilation and bison code
generation and compilation can occur first. Ideally LLVM compilation
target should depend on .o files targets.
---
 contrib/cube/Makefile | 4 ++++
 contrib/seg/Makefile  | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile
index dfb0d806e4b..d84ad3fc3e9 100644
--- a/contrib/cube/Makefile
+++ b/contrib/cube/Makefile
@@ -35,6 +35,10 @@ endif
 cubeparse.h: cubeparse.c
 	touch $@
 
+ifeq ($(with_llvm), yes)
+cubescan.bc: cubescan.o
+endif
+
 cubeparse.c: BISONFLAGS += -d
 
 # Force these dependencies to be known even without dependency info built:
diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile
index b408f4049cb..dde996ca5c5 100644
--- a/contrib/seg/Makefile
+++ b/contrib/seg/Makefile
@@ -34,6 +34,10 @@ endif
 segparse.h: segparse.c
 	touch $@
 
+ifeq ($(with_llvm), yes)
+segscan.bc: segscan.o
+endif
+
 segparse.c: BISONFLAGS += -d
 
 # Force these dependencies to be known even without dependency info built:
-- 
2.43.0

