<?xml version="1.0" encoding="UTF-8"?>
<Config>
   <Tool Header="LD" Desc="LD Linker" Separator=";" ExitFail="0" SourceFilter="*.rapp" TargetFilter="ARM" ConfigPath="ARM\LD.config" MsgFilter="{SPECFILE}:{SPECLINE}: {SPECERROR}:{SPECMESSAGE}">
      <!-- do some local correction according to target STM3 specificities -->
      <![CDATA[script
         {
         var processor = Tools.GetPropertyValue("Target", "ProcessorARM", "Processor");
         //STM3
         if(processor.substr(0,4) == "STM3")
            {
            Tools.SetPropertyValue("Target", "ProcessorARM", "Thumb", "-mthumb");
            Tools.SetPropertyValue("Target", "ProcessorARM", "Interwork", "");
            }
         }
      ]]>
      <!-- make .ld files -->
      <![CDATA[script
         {
         var  ld = Tools.GetPropertyValue("", "Build", "OutputFile") + ".ld";
         ld = ld.replace(/\\/g, "\\\\");     // Replace "\" with "\\"

         var inputfiles = Tools.GetPropertyValue("LD", "General", "InputFiles");

         GNUFilesLinkerManager(ld);
         }
      ]]>
      <!-- make map file option -->
      <![CDATA[script
         {
         var mapoption = Tools.GetPropertyValue("LD", "Linker", "MAPFILE");
         mapoption = mapoption.replace(/!/g, "\"");
         //mapoption = mapoption.replace(".elf", ".map");
         Tools.SetPropertyValue("LD", "Linker", "MAPFILE", mapoption)
         }
      ]]>
      <!-- make sure output file and map file directories exist before linking -->
      <![CDATA[script
         {
         var outdir  = objFSO.GetParentFolderName(Tools.GetPropertyValue("", "Build",  "OutputFile"));
         var listdir = objFSO.GetParentFolderName(Tools.GetPropertyValue("", "Build", "ListingFile"));
         if(!objFSO.FolderExists(outdir))
            objFSO.CreateFolder(outdir);
         if(!objFSO.FolderExists(listdir))
            objFSO.CreateFolder(listdir);
         }
      ]]>
      <!-- do link -->
      <![CDATA["$(Target.Tools.Execute)" $(Target.ProcessorARM.Target) $(Target.ProcessorARM.Thumb) $(Target.ProcessorARM.Interwork) -Wl,-T -Xlinker "$(Build.OutputFile).ld" -u _start $(LD.Linker.GC_SECTIONS) -nostartfiles $(LD.Linker.MAPFILE) $(LD.Linker.WARNONCE) $(LD.More.More)]]>
      <!-- do .hex file -->
      <![CDATA[script
         {
         hexfile = Tools.GetPropertyValue("", "Build", "OutputFile");
         hexfile = hexfile.replace(".elf",".hex");
         Tools.SetPropertyValue("LD","General","HexFile", hexfile);
         }
      ]]>
      <![CDATA["$(RKitInst)arm-gcc\bin\arm-none-eabi-objcopy.exe" "$(Build.OutputFile)" --target=ihex "$(LD.General.HexFile)"]]>
      <!-- arm-elf-size.exe to have code size info-->
      <![CDATA["$(RKitBin)\rexrdr.exe" "$(Build.OutputFile).sizetmp" 0 "$(RKitInst)arm-gcc\bin\arm-none-eabi-size.exe" "$(Build.OutputFile)"]]>
      <!-- make xml file -->
      <![CDATA[script
         {
         var filename      =  Tools.GetPropertyValue("", "Build", "OutputFile");
         filename = filename.replace(/\\/g, "\\\\");     // Replace "\" with "\\"
         filename = filename.replace(".elf", "");
         GNULDOutputManager( filename + ".elf.sizetmp", filename + ".depxml");
         
         var dbi	= Project.GetSelectedDBI();
         
         Tools.SetPropertyValue("LD", "General", "DBIFile", dbi);
		     Project.WriteIniValue("Application","ApplicationPath",Tools.GetPropertyValue("", "Build", "OutputFile"), dbi);                                           		
		     Project.WriteIniValue("Application","Target",Tools.GetPropertyValue("", "Target", "TargetFamily"), dbi);                                           				 
         }
      ]]>
      <!-- Create xml files from Dwarf debug information -->
      <![CDATA["$(RKitBin)\dwf2xml.exe" "$(LD.General.DBIFile)" "$(ApplicationDir)\$(ApplicationName)-globals.$(Config).xml" "$(ApplicationDir)\$(ApplicationName).$(Config).xml"]]>
   </Tool>
   <Defs>
      <Set Header="LD" Desc="LD Linker" Comment="Specifies the LD linker settings">
         <Section Header="General" Hidden="1">
            <Property Header="OutExt" Type="PT_STRING" Value=".elf" />
            <Property Header="ListExt" Type="PT_STRING" Value=".map" />
            <Property Header="InputFiles" Type="PT_STRING" Value="" />
            <Property Header="DefaultLibDir" Type="PT_STRING" Value="" />
            <Property Header="HexFile" Type="PT_STRING" Value="" />
            <Property Header="DBIFile" Type="PT_STRING" Value="" />
         </Section>
         <Section Header="Linker" Desc="General" Comment="General linker options.">
            <Property Header="MAPFILE" Major="1" Desc="Generate MAP file" Type="PT_CHOICE" Default="Yes" Comment="Generate a linker MAP file (-Map)">
               <Enum Header="Yes" Value="-Wl,-Map -Xlinker !$(Build.ListingFile)!" />
               <Enum Header="No" Value="" />
            </Property>
            <Property Header="WARNONCE" Major="1" Desc="Warn undefined symbols" Type="PT_CHOICE" Default="No" Comment="Warn for each undefined symbol (--warn-once)">
               <Enum Header="Yes" Value="-Wl,--warn-once" />
               <Enum Header="No" Value="" />
            </Property>
            <Property Header="GC_SECTIONS" Major="1" Desc="Remove unused sections" Type="PT_CHOICE" Default="-Wl,-static -Wl,--gc-sections" Comment="Remove the unused sections from the application, unless they are forced to be kept (see '-u' gcc command-line option and 'KEEP()' directive in the linker script)">
               <Enum Header="Yes" Value="-Wl,-static -Wl,--gc-sections" />
               <Enum Header="No" Value="" />
            </Property>
         </Section>
         <Section Header="Startup" Desc="Startup" Comment="Defines startup options.">
            <Property Header="DEFAULTSTARTUP" Major="1" Desc="Use Default Startup" Type="PT_CHOICE" Default="Yes" Comment="Use the default startup code.">
               <Enum Header="Yes" Value="Yes" />
               <Enum Header="No" Value="No" />
               <![CDATA[
                  var sc= Project.GetPropertyValue("LD","Startup", "DEFAULTSTARTUP");
                  if (sc == "Yes")
                    {
                    Project.EnableProperty("LD","Startup", "File", 0);
                    Project.SetPropertyValue("LD", "Startup", "File", Project.GetPropertyValue("LD", "Startup", "DefaultFile"));
                    }
                  else
                    Project.EnableProperty("LD","Startup", "File", 1);
               ]]>
            </Property>
            <Property Header="File" Major="1" Desc="Startup File" Type="PT_PATH" Default="ctr0.o" Pattern="*.o" Comment="Selects a specific startup file."/>
            <Property Header="DefaultFile" Desc="Default Startup File" Type="PT_STRING" Default="ctr0.o" Hidden="1" />
         </Section>
         <Section Header="Scripts" Desc="Scripts" Comment="Specifies linker script file options.">
            <Property Header="SCRIPTFILES" Major="1" Desc="Use Default Script File" Type="PT_CHOICE" Default="Yes" Comment="Defines whether the default linker script file should be used.">
               <Enum Header="Yes" Value="Yes" />
               <Enum Header="No" Value="No" />
               <![CDATA[
               var st= Project.GetPropertyValue("LD","Scripts", "SCRIPTFILES");
               if (st == "Yes")
                  Project.EnableProperty("LD","Scripts", "File", 0);
               else
                  Project.EnableProperty("LD","Scripts", "File", 1);

               if (st == "Yes")
                  Project.HideProperty("LD","Scripts", "StarterKitLimit", 0);
               else
                  Project.HideProperty("LD","Scripts", "StarterKitLimit", 1);
               ]]>
            </Property>
            <Property Header="File" Major="1" Desc="Script File" Type="PT_PATH" Default="ctr0.ld" Pattern="*.ld" Comment="Selects a specific linker script file."/>
            <Property Header="StarterKitLimit" Major="1" Desc="Starter Kit limitation" Type="PT_CHOICE" Default="Yes" Comment="Informs you whether the linker is size-limited (32K)">
               <Enum Header="Yes" Value="Yes" />
               <Enum Header="No" Value="No" />
            </Property>
         </Section>
         <Section Header="LIB" Desc="Libraries">
            <Property Header="STLIB" Major="1" Desc="ST library" Type="PT_CHOICE" Default="1" Comment="Specifies whether the ST library should be used in your project.">
               <Enum Header="Yes" Value="1" />
               <Enum Header="No" Value="0" />
            </Property>
            <Property Header="UART0PUTC" Major="1" Desc="UART0 Putchar" Type="PT_CHOICE" Default="1" Comment="Specifies whether the project should include a putchar that emits characters on the UART0 peripheral.">
               <Enum Header="Yes" Value="1" />
               <Enum Header="No" Value="0" />
            </Property>
            <Property Header="SMALLP" Major="1" Desc="Small printf" Type="PT_CHOICE" Default="1" Comment="Defines whether the simplified version of printf should be used.">
               <Enum Header="Yes" Value="1" />
               <Enum Header="No" Value="0" />
            </Property>
            <Property Header="NOFLOATP" Major="1" Desc="Small no-float printf" Type="PT_CHOICE" Default="0" Comment="Specifies whether the simplified printf without float support should be used.">
               <Enum Header="Yes" Value="1" />
               <Enum Header="No" Value="0" />
            </Property>
         </Section>
         <Section Header="More" Major="1" Desc="More" Comment="Additional linker options.">
            <Property Header="More" Desc="More" Type="PT_EDITLIST" Pattern=" %s" Comment="Specifies additional options to be added on the linker command line."/>
         </Section>
      </Set>
   </Defs>
</Config>
