From ea157f883d54974f5924d78592813b5f1f082bd5 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 v1 1/2] 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 header 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..b4f3d32450b 100644
--- a/contrib/cube/Makefile
+++ b/contrib/cube/Makefile
@@ -35,6 +35,10 @@ endif
 cubeparse.h: cubeparse.c
 	touch $@
 
+ifeq ($(with_llvm), yes)
+cubescan.c: cubeparse.h
+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..b98ca73bc64 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: segparse.h
+endif
+
 segparse.c: BISONFLAGS += -d
 
 # Force these dependencies to be known even without dependency info built:
-- 
2.43.0

