From 7f0f6c771e501f923d10cec3faf51f379fce40e7 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 30 Jul 2020 19:16:35 +0200 Subject: ghdldrv: factorize part of --gen-makefile Fix #1403 --- src/ghdldrv/ghdlcomp.adb | 47 ++------------------------------------ src/ghdldrv/ghdldrv.adb | 44 ++--------------------------------- src/ghdldrv/ghdllocal.adb | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/ghdldrv/ghdllocal.ads | 4 ++++ 4 files changed, 66 insertions(+), 87 deletions(-) diff --git a/src/ghdldrv/ghdlcomp.adb b/src/ghdldrv/ghdlcomp.adb index c58360aee..96a854d28 100644 --- a/src/ghdldrv/ghdlcomp.adb +++ b/src/ghdldrv/ghdlcomp.adb @@ -34,7 +34,6 @@ with Vhdl.Utils; with Vhdl.Configuration; with Errorout; use Errorout; with Libraries; -with Version; package body Ghdlcomp is @@ -842,7 +841,6 @@ package body Ghdlcomp is is pragma Unreferenced (Cmd); use Simple_IO; - use Ada.Command_Line; use Name_Table; HT : constant Character := ASCII.HT; @@ -861,52 +859,11 @@ package body Ghdlcomp is Setup_Libraries (True); Files_List := Build_Dependence (Prim_Id, Sec_Id); - Put_Line ("# Makefile automatically generated by ghdl"); - Put ("# Version: GHDL "); - Put (Version.Ghdl_Ver); - Put (' '); - Put (Version.Ghdl_Release); - Put (" - "); - if Version_String /= null then - Put (Version_String.all); - end if; - New_Line; - Put_Line ("# Command used to generate this makefile:"); - Put ("# "); - Put (Command_Name); - for I in 1 .. Argument_Count loop - Put (' '); - Put (Argument (I)); - end loop; - New_Line; + Ghdllocal.Gen_Makefile_Disp_Header; New_Line; - Put ("GHDL="); - Put_Line (Command_Name); - - -- Extract options for command line. - Put ("GHDLFLAGS="); - for I in 2 .. Argument_Count loop - declare - Arg : constant String := Argument (I); - begin - if Arg (1) = '-' then - if (Arg'Length > 10 and then Arg (1 .. 10) = "--workdir=") - or else (Arg'Length > 7 and then Arg (1 .. 7) = "--ieee=") - or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") - or else (Arg'Length > 7 and then Arg (1 .. 7) = "--work=") - or else (Arg'Length > 2 and then Arg (1 .. 2) = "-P") - or else (Arg'Length > 2 and then Arg (1 .. 2) = "-f") - or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") - then - Put (" "); - Put (Arg); - end if; - end if; - end; - end loop; - New_Line; + Ghdllocal.Gen_Makefile_Disp_Variables; Put ("GHDLRUNFLAGS="); for I in Next_Arg .. Args'Last loop diff --git a/src/ghdldrv/ghdldrv.adb b/src/ghdldrv/ghdldrv.adb index bac182572..eda267479 100644 --- a/src/ghdldrv/ghdldrv.adb +++ b/src/ghdldrv/ghdldrv.adb @@ -36,7 +36,6 @@ with Options; use Options; with Ghdlmain; use Ghdlmain; with Ghdllocal; use Ghdllocal; with Errorout; -with Version; package body Ghdldrv is -- Argument table for the tools. @@ -1834,52 +1833,13 @@ package body Ghdldrv is Setup_Libraries (True); Files_List := Build_Dependence (Primary_Id, Secondary_Id); - Put_Line ("# Makefile automatically generated by ghdl"); - Put ("# Version: GHDL "); - Put (Version.Ghdl_Ver); - Put (' '); - Put (Version.Ghdl_Release); - Put (" - "); - if Version_String /= null then - Put (Version_String.all); - end if; - New_Line; - Put_Line ("# Command used to generate this makefile:"); - Put ("# "); - Put (Command_Name); - for I in 1 .. Argument_Count loop - Put (' '); - Put (Argument (I)); - end loop; - New_Line; + Ghdllocal.Gen_Makefile_Disp_Header; New_Line; -- Omit variables. if not Only_Depends then - Put ("GHDL="); - Put_Line (Command_Name); - - -- Extract options for command line. - Put ("GHDLFLAGS="); - for I in 2 .. Argument_Count loop - declare - Arg : constant String := Argument (I); - begin - if Arg (1) = '-' then - if (Arg'Length > 10 and then Arg (1 .. 10) = "--workdir=") - or else (Arg'Length > 7 and then Arg (1 .. 7) = "--ieee=") - or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") - or else (Arg'Length > 7 and then Arg (1 .. 7) = "--work=") - or else (Arg'Length > 2 and then Arg (1 .. 2) = "-P") - then - Put (" "); - Put (Arg); - end if; - end if; - end; - end loop; - New_Line; + Ghdllocal.Gen_Makefile_Disp_Variables; New_Line; diff --git a/src/ghdldrv/ghdllocal.adb b/src/ghdldrv/ghdllocal.adb index b2df3769f..bf9176b16 100644 --- a/src/ghdldrv/ghdllocal.adb +++ b/src/ghdldrv/ghdllocal.adb @@ -27,6 +27,8 @@ with Default_Paths; with Errorout; with Files_Map; with Libraries; +with Version; + with Vhdl.Sem_Lib; with Vhdl.Std_Package; with Vhdl.Scanner; @@ -1789,6 +1791,62 @@ package body Ghdllocal is end loop; end Perform_Action; + -- Used by --gen-makefile + procedure Gen_Makefile_Disp_Header + is + use Ada.Command_Line; + begin + Put_Line ("# Makefile automatically generated by ghdl"); + Put ("# Version: GHDL "); + Put (Version.Ghdl_Ver); + Put (' '); + Put (Version.Ghdl_Release); + Put (" - "); + if Version_String /= null then + Put (Version_String.all); + end if; + New_Line; + Put_Line ("# Command used to generate this makefile:"); + Put ("# "); + Put (Command_Name); + for I in 1 .. Argument_Count loop + Put (' '); + Put (Argument (I)); + end loop; + New_Line; + end Gen_Makefile_Disp_Header; + + procedure Gen_Makefile_Disp_Variables + is + use Ada.Command_Line; + begin + Put ("GHDL="); + Put_Line (Command_Name); + + -- Extract options for command line. + Put ("GHDLFLAGS="); + for I in 2 .. Argument_Count loop + declare + Arg : constant String := Argument (I); + begin + if Arg (1) = '-' then + if (Arg'Length > 10 and then Arg (1 .. 10) = "--workdir=") + or else (Arg'Length > 7 and then Arg (1 .. 7) = "--ieee=") + or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") + or else (Arg'Length > 7 and then Arg (1 .. 7) = "--work=") + or else (Arg'Length > 2 and then Arg (1 .. 2) = "-P") + or else (Arg'Length > 2 and then Arg (1 .. 2) = "-f") + or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") + then + Put (" "); + Put (Arg); + end if; + end if; + end; + end loop; + New_Line; + end Gen_Makefile_Disp_Variables; + procedure Register_Commands is begin Register_Command (new Command_Import); diff --git a/src/ghdldrv/ghdllocal.ads b/src/ghdldrv/ghdllocal.ads index 230ddd7f5..0b195dee5 100644 --- a/src/ghdldrv/ghdllocal.ads +++ b/src/ghdldrv/ghdllocal.ads @@ -160,5 +160,9 @@ package Ghdllocal is -- option). procedure Expect_Filenames (Args : Argument_List); + -- Used by --gen-makefile + procedure Gen_Makefile_Disp_Header; + procedure Gen_Makefile_Disp_Variables; + procedure Register_Commands; end Ghdllocal; -- cgit v1.2.3