From c0975bc8a3e2ba9058a2236d01c79aaec3dc4169 Mon Sep 17 00:00:00 2001
From: Tristan Gingold <tgingold@free.fr>
Date: Mon, 13 Mar 2023 07:36:25 +0100
Subject: ghdldrv: only put direct dependences in gen-makefile

---
 src/ghdldrv/ghdldrv.adb   |  4 ++--
 src/ghdldrv/ghdllocal.adb | 16 ++++++++++------
 src/ghdldrv/ghdllocal.ads |  6 ++++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/ghdldrv/ghdldrv.adb b/src/ghdldrv/ghdldrv.adb
index 4a36f95c7..dcc9ec168 100644
--- a/src/ghdldrv/ghdldrv.adb
+++ b/src/ghdldrv/ghdldrv.adb
@@ -1663,7 +1663,7 @@ package body Ghdldrv is
                   Dep_It : List_Iterator;
                   Dep_File : Iir;
                begin
-                  Dep_List := Build_File_Dependences (File);
+                  Dep_List := Build_File_Direct_Dependences (File);
                   Dep_It := List_Iterate (Dep_List);
                   while Is_Valid (Dep_It) loop
                      Put ("    ");
@@ -2005,7 +2005,7 @@ package body Ghdldrv is
          if Is_Makeable_File (File) then
             Put (Get_Object_Filename (File));
             Put (": ");
-            Dep_List := Build_File_Dependences (File);
+            Dep_List := Build_File_Direct_Dependences (File);
             Dep_It := List_Iterate (Dep_List);
             while Is_Valid (Dep_It) loop
                Dep_File := Get_Element (Dep_It);
diff --git a/src/ghdldrv/ghdllocal.adb b/src/ghdldrv/ghdllocal.adb
index ecc36db39..4d6498a86 100644
--- a/src/ghdldrv/ghdllocal.adb
+++ b/src/ghdldrv/ghdllocal.adb
@@ -1533,7 +1533,8 @@ package body Ghdllocal is
    end Check_No_Elab_Flag;
 
    --  Append all the file on which FILE depends.
-   procedure Append_File_Dependences (File : Iir_Design_File; List : Iir_List)
+   procedure Append_File_Dependences
+     (File : Iir_Design_File; List : Iir_List; Recurse : Boolean)
    is
       Unit : Iir;
       List_It : List_Iterator;
@@ -1556,7 +1557,10 @@ package body Ghdllocal is
                      if not Get_Elab_Flag (Dep_Unit_File) then
                         --  Add if not already in the list.
                         Set_Elab_Flag (Dep_Unit_File, True);
-                        Append_File_Dependences (Dep_Unit_File, List);
+                        if Recurse then
+                           Append_File_Dependences
+                             (Dep_Unit_File, List, Recurse);
+                        end if;
                         Append_Element (List, Dep_Unit_File);
                      end if;
                   when Iir_Kind_Foreign_Module =>
@@ -1582,19 +1586,19 @@ package body Ghdllocal is
       end loop;
    end Clear_Elab_Flag;
 
-   function Build_File_Dependences (File : Iir) return Iir_List
+   function Build_File_Direct_Dependences (File : Iir) return Iir_List
    is
       Res : Iir_List;
    begin
       Res := Create_Iir_List;
       Set_Elab_Flag (File, True);
-      Append_File_Dependences (File, Res);
+      Append_File_Dependences (File, Res, False);
 
       Clear_Elab_Flag (Res);
       Set_Elab_Flag (File, False);
 
       return Res;
-   end Build_File_Dependences;
+   end Build_File_Direct_Dependences;
 
    function Build_Dependence (Lib : Name_Id; Prim : Name_Id; Sec : Name_Id)
                              return Iir_List
@@ -1696,7 +1700,7 @@ package body Ghdllocal is
          File := Get_Design_File (Unit);
          if not Get_Elab_Flag (File) then
             Set_Elab_Flag (File, True);
-            Append_File_Dependences (File, Files_List);
+            Append_File_Dependences (File, Files_List, True);
             Append_Element (Files_List, File);
          end if;
       end loop;
diff --git a/src/ghdldrv/ghdllocal.ads b/src/ghdldrv/ghdllocal.ads
index 953002923..de56721b8 100644
--- a/src/ghdldrv/ghdllocal.ads
+++ b/src/ghdldrv/ghdllocal.ads
@@ -131,11 +131,13 @@ package Ghdllocal is
    procedure Load_All_Libraries_And_Files;
 
    --  Return an ordered list of design_files to build LIB.PRIM.SEC.
+   --  Use Elab_Flag.
    function Build_Dependence (Lib : Name_Id; Prim : Name_Id; Sec : Name_Id)
                              return Iir_List;
 
-   --  Return a list of design_file on which FILE depends.
-   function Build_File_Dependences (File : Iir) return Iir_List;
+   --  Return a list of design_file on which FILE directly depends.
+   --  Use Elab_Flag.
+   function Build_File_Direct_Dependences (File : Iir) return Iir_List;
 
    --  Return True iff file FILE has been modified (the file time stamp does
    --  no correspond to what was recorded in the library).
-- 
cgit v1.2.3