abstract
project Lace_shared
is
   -- Scenario Variables
   --

   type Os_Type is
      ("Windows_NT", "Linux", "MacOSX");
   lace_OS : Os_Type := external ("Lace_OS", "Linux");

   type Restrictions_Type is
      ("xgc", "ravenscar");
   lace_Restrictions : Restrictions_Type := external ("Lace_Restrictions", "xgc");

   type Build_Mode_Type is
      ("debug", "fast", "small");
   lace_Build_Mode : Build_Mode_Type := external ("Lace_Build_Mode", "debug");


   -- Declare various options.
   --

   Binder_Options := ();

   Style_Options  := ("-gnatyk",      --  Check casings: a:attribute, k:keywords, n:package Standard identifiers, p:pragma, r:identifier references.
                      "-gnatybfhi",   --  Check b:no blanks at end of lines, f:no ff/vtabs, h: no htabs, i:if-then layout, u:no unnecessary blank lines.
                      "-gnatyO",      --  Check that overriding subprograms are explicitly marked as such.
                      "-gnatye",      --  Check that labels on end statements (ending subprograms), and on exit statements (exiting named loops), are present.
                      "-gnatyx");     --  Check x:no extra parens.

   Compiler_Options :=   ("-gnat2022",
                          "-gnatwa",
                          "-fno-strict-aliasing")
                        & Style_Options;

   Fast_Options := ("-O3",
                    "-gnatn",
                    -- "-gnatp",       -- TODO: This breaks opengl code. Investigate more.
                    "-funroll-loops",
                    "-ftracer",
                    "-g");             -- TODO: Temporary for profiling. Make a new build mode for profiling.

   Small_Options := ("-Os",
                     "-gnatp",
                     "-fno-inline",
                     "-march=i386",
                     "-ffunction-sections",
                     "-falign-jumps=0",
                     "-falign-loops=0",
                     "-falign-functions=0",
                     "-mpreferred-stack-boundary=2");


   -- Modify options to cater for the build mode.
   --

   case lace_Build_Mode
   is
      when "debug" =>
         Binder_Options   := Binder_Options   & "-Es";
         Compiler_Options := Compiler_Options & "-O0"
                                              & "-gnata"
                                              & "-gnato"
                                              & "-gnateE"                -- Extra debug info in 'constraint_Error' messages.
                                              & "-fstack-check"
                                              & "-g";
         case lace_OS
         is
            when "Linux"  =>
               Compiler_Options := Compiler_Options & "-gnatVa";

            when "Windows_NT"  =>
               Compiler_Options := Compiler_Options & "-fno-inline"
                                                    & "-gnatVcdeimoprst";
--                                                  & "-gnatVf"             -- (2016) turned off floating point validity check, seems to give
                                                                            -- false positives on a scalar product for collision detection
            when "MacOSX" =>
               null;
         end case;

      when "fast" =>
         case lace_OS
         is
            when "Linux"  =>
               Compiler_Options := Compiler_Options & Fast_Options
                                                    & "-fomit-frame-pointer";
            when "Windows_NT"  =>
               Compiler_Options := Compiler_Options & Fast_Options
                                                    & "-fipa-cp-clone"
                                                    & "-fgcse-after-reload"
                                                    & "-ftree-vectorize"
                                                    & "-mfpmath=sse"
                                                    & "-msse3";
            when "MacOSX" =>
               null;
         end case;

      when "small" =>
         case lace_OS
         is
            when "Linux"  =>
               Compiler_Options := Compiler_Options & Small_Options
                                                    & "-fdata-sections";
            when "Windows_NT"  =>
               Compiler_Options := Compiler_Options & Small_Options;

            when "MacOSX" =>
               null;
         end case;
   end case;


   -- Modify options to cater for the operating system.
   --

   case lace_OS
   is
      when "MacOSX" =>
         Compiler_Options := Compiler_Options & "-gnatf"
                                              & "-gnatE"
                                              & "-gnatVcfimorst"
                                              & "-gnatyhiknp";
      when "Linux" =>
         Binder_Options   := Binder_Options   & "-static";

      when "Windows_NT" =>
         null;
   end case;


   -- Define the packages.
   --

   package Ide is
      case lace_OS
      is
         when "Linux"      => for Default_Switches ("adacontrol") use ("-Ftgnat_short");
         when "Windows_NT" => for Default_Switches ("adacontrol") use ("-F", "gnat_short");
         when "MacOSX"     => for Default_Switches ("adacontrol") use ();
      end case;
   end Ide;


   package Builder is
      for Default_Switches ("ada") use ("-C", "-j0");

      case lace_Build_Mode
      is
         when "debug" => for Global_Configuration_Pragmas use "debug.pra";
                         for Default_Switches ("ada") use ("-C", "-j0", "-gnat2022");     -- TODO: Create and use a Builder_Options variable ?
         when "fast"  => for Global_Configuration_Pragmas use "debug.pra";                -- TODO: Without this, openGL fails. Investigate.
                         for Default_Switches ("ada") use ("-C", "-j0", "-gnat2022");
         when "small" => null;
      end case;
   end Builder;


   package Compiler is
      for Default_Switches ("ada") use Compiler_Options;
   end Compiler;


   package Binder is
      for Default_Switches ("ada") use Binder_Options;
   end Binder;

end Lace_shared;
