<Config>
   <Tool Header="RLST7" Desc="ST7/STM8 Linker" InputInFile="no" ExitFail="0" SourceFilter="*.rapp" TargetFilter="ST7" ConfigPath="ST7\RLST7.config" MsgFilter="^\*\*\*{SPECERROR} : {SPECMESSAGE}$" Help="Doc\ST7\RLSTM8">
       <![CDATA[script
         {
         var inputfiles = Tools.GetPropertyValue("RLST7", "General", "InputFiles");
         inputfiles = inputfiles.replace(/\.obj/g, ".obj_"); // Replace "obj" extensions with "obj_"
         Tools.SetPropertyValue("RLST7", "Output", "objt", inputfiles);

         var outputfilename = Tools.GetPropertyValue("ApplicationBuild", "Build", "OutputFile");
         outputfilename = outputfilename.replace(/\\/g, "\\\\");     // Replace "\" with "\\"
         var arelocfile = outputfilename + ".areloc";

         //if areloc file still exist and the value of the option is not null this means than an error occured,
         //we should ask for a rebuilt
          var areloc = Tools.GetPropertyValue("Target", "ToolSetST7", "ArelocInfo");
         if( (areloc != "") && objFSO.FileExists( arelocfile ) )
              {
              //to not loop
               Project.SavePropertyValue("Target", "ToolSetST7", "ArelocInfo", "");

              Project.Command(33081);
              }
         }
      ]]>
      <![CDATA[ $(Target.ToolSetST7.Areloc) "$(RkitBin)\RLSTM8.EXE" $(Target.ProcessorST7.IsSTM8) $(RLST7.Output.objt) TO("$(Build.OutputFile)") "LIBPATH($(Directories.LibDir))" SCINAME($(Target.ProcessorST7.SCIName)) GENERATEDEPFILE CODESIZE($(Target.ProcessorST7.CodeSize)) CODESTART($(Target.ProcessorST7.CodeStart)) RAMSIZE($(Target.ProcessorST7.RamSize)) DATASTART($(Target.ProcessorST7.RamStart)) STACKSIZE($(RLST7.More.StackSize)) $(RLST7.Output.Debug) $(RLST7.Output.RmUn) $(RLST7.Map.Print) $(RLST7.Map.XRef) XML("$(ApplicationDir)\$(ApplicationName).$(Config).xml") XMLRIDE("$(ApplicationDir)\$(ApplicationName)-globals.$(Config).xml") $(RLST7.More.More) LSTACC("$(Build.OutputFile).areloc")]]>
      <![CDATA[script
         {
         var oldinfo = Project.GetPropertyValue("Target", "ToolSetST7", "ArelocInfo");

         //objShell.popup("Write OldArelocInfo:" + oldinfo );
         Project.SetPropertyValue("Target", "ToolSetST7", "OldArelocInfo", oldinfo);

         Project.SavePropertyValue("Target", "ToolSetST7", "ArelocInfo", "");
         Project.SetPropertyValue("Target", "ToolSetST7", "ArelocInfo", "");
         }
      ]]>
      <![CDATA[ "$(RkitBin)\RLSTM8.EXE" $(Target.ProcessorST7.IsSTM8) $(CmdInput) TO("$(Build.OutputFile)") "LIBPATH($(Directories.LibDir))" SCINAME($(Target.ProcessorST7.SCIName)) GENERATEDEPFILE CODESIZE($(Target.ProcessorST7.CodeSize)) CODESTART($(Target.ProcessorST7.CodeStart)) RAMSIZE($(Target.ProcessorST7.RamSize)) DATASTART($(Target.ProcessorST7.RamStart)) STACKSIZE($(RLST7.More.StackSize)) $(RLST7.Output.Debug) $(RLST7.Output.RmUn) $(RLST7.Map.Print) $(RLST7.Map.XRef) XML("$(ApplicationDir)\$(ApplicationName).$(Config).xml") XMLRIDE("$(ApplicationDir)\$(ApplicationName)-globals.$(Config).xml") $(RLST7.More.More) ]]>
      <![CDATA[ $(RLST7.Output.GenHex) "$(RkitBin)\OHST7.EXE" "$(Build.OutputFile)" HEX ]]>
      <![CDATA[ $(RLST7.Output.GenBin) "$(RkitBin)\OHST7.EXE" "$(Build.OutputFile)" BIN ]]>
      <![CDATA[script
         {
         var outputfilename =  Project.GetPropertyValue("ApplicationBuild", "Build", "OutputFile");

         outputfilename = outputfilename.replace(/\\/g, "\\\\");     // Replace "\" with "\\"
         var arelocfile = outputfilename + ".areloc";

         var arelocinfo = "";   // Will contain the list of areloc statements


         if( objFSO.FileExists( arelocfile ) && objFSO.FileExists( outputfilename ))
            {
            var filehandle = objFSO.OpenTextFile( arelocfile );
            var linebuf;           // Buffer for reading lines

            while( !filehandle.AtEndOfStream )
               {
               linebuf = filehandle.ReadLine();
               arelocinfo = arelocinfo + linebuf + " ";
               }
            filehandle.Close();
            objFSO.DeleteFile(arelocfile);
            }

         // If autorelocation is devalidated, delete the areloc file
         var areloc  = Project.GetPropertyValue("Target", "ToolSetST7", "Areloc");
         var oldinfo = Project.GetPropertyValue("Target", "ToolSetST7", "OldArelocInfo");

         if(areloc == "REM")
            {
            arelocinfo = "";       // Clear the autoreloc information
            }
         // Change and save the value so that the option is kept
         //objShell.popup("Write ArelocInfo:" + arelocinfo );
         Project.SetPropertyValue("Target", "ToolSetST7", "ArelocInfo", arelocinfo);
         Project.SavePropertyValue("Target", "ToolSetST7", "ArelocInfo", arelocinfo);

         // Ask the project to rebuild again the application
         if(areloc != "REM")
            {
            // If the stored value has been changed, enforce a new rebuilt
            if(oldinfo != arelocinfo)
                {
                // Ask the project to rebuild again the application
                Project.Command(33081);
                }
            }
        }
      ]]>

   </Tool>
   <Defs>
      <Set Header="RLST7" Desc="Linker options" Comment="Defines the ST7/STM8 linker options.">
         <Section Header="General" Hidden="1">
            <Property Header="InputFiles" Type="PT_STRING" Value=""/>
            <Property Header="OutExt" Type="PT_STRING" Value=".aof"/>
            <Property Header="ListExt" Type="PT_STRING" Value=".map"/>
         </Section>
         <Section Header="Output" Desc="Linker output" Comment="Defines the linker output options.">
            <Property Header="objt" Desc="obj_ list" Type="PT_STRING" Default="" Hidden="1" Comment="List of obj files with a trailing underscore."/>
            <Property Header="RmUn" Desc="Remove uncalled segments" Type="PT_CHOICE" Default="REMOVEUNCALLED" Comment="Remove uncalled segments from the produced file. Absolute segments are always preserved.">
               <Enum Header="Yes" Value="REMOVEUNCALLED"/>
               <Enum Header="No" Value=""/>
            </Property>
            <Property Header="GenBin" Desc="Generate a binary file" Type="PT_CHOICE" Default="" Comment="Produces a binary file (with '.bin' file extension) in addition to the AOF file.">
               <Enum Header="Yes" Value=""/>
               <Enum Header="No" Value="rem"/>
            </Property>
            <Property Header="GenHex" Desc="Generate an hex file" Type="PT_CHOICE" Default="" Comment="Produces an HEX file (with '.hex' file extension) in addition to the AOF file.">
               <Enum Header="Yes" Value=""/>
               <Enum Header="No" Value="rem"/>
            </Property>
            <Property Header="Debug" Desc="Generate debug information" Type="PT_CHOICE" Default="" Comment="Includes debug information in the AOF output file.">
               <Enum Header="Yes" Value=""/>
               <Enum Header="No" Value=" NODL NODP NODS"/>
            </Property>
         </Section>
         <Section Header="Memory" Hidden="1" Desc="Memory map" Comment="Describes the memory map for the ST7/STM8 linker.">
            <Property Header="RamStart" Desc="RAM start" Type="PT_STRING" Comment="Defines the RAM start address.\nYou should not modify this option unless explicitly required."/>
            <Property Header="RamSize" Desc="RAM size" Type="PT_STRING" Comment="Defines the RAM size.\nYou should not modify this option unless explicitly required."/>
            <Property Header="RomStart" Desc="ROM start" Type="PT_STRING" Comment="Defines the ROM start address.\nYou should not modify this option unless explicitly required."/>
            <Property Header="RomSize" Desc="ROM size" Type="PT_STRING" Comment="Defines the ROM size.\nYou should not modify this option unless explicitly required."/>
         </Section>
         <Section Header="Map" Desc="Map file" Comment="Defines the ST7/STM8 linker map file options.">
            <Property Header="Print" Desc="Generate map file" Type="PT_CHOICE" Default="" Comment="Generates a map file.">
               <Enum Header="Yes" Value=""/>
               <Enum Header="No" Value="NOPRINT"/>
            </Property>
            <Property Header="XRef" Desc="Generate cross references" Type="PT_CHOICE" Default="IX" Comment="Generates cross-reference information in the linker output file.">
               <Enum Header="Yes" Value="IX"/>
               <Enum Header="No" Value=""/>
            </Property>
         </Section>
         <Section Header="More" Desc="Additional options" Comment="Specifies additional options for the ST7/STM8 linker.">
            <Property Header="StackSize" Desc="Stack size" Type="PT_STRING" Comment="Defines the stack size. You can enter this value in decimal (e.g.: 64) or hexadecimal (e.g.: 0x40 or 040H)."/>
            <Property Header="More" Desc="More options" Type="PT_STRING" Comment="Specifies additional options to be added on the ST7/STM8 linker command line." Pattern=" %s "/>
         </Section>
      </Set>
   </Defs>
</Config>
