Prechádzať zdrojové kódy

* Replace environment variables placed between dollar signs in fpc.cfg
with the value of the environment variable.

git-svn-id: trunk@16945 -

joost 14 rokov pred
rodič
commit
db6bc3bd00
1 zmenil súbory, kde vykonal 27 pridanie a 0 odobranie
  1. 27 0
      compiler/globals.pas

+ 27 - 0
compiler/globals.pas

@@ -719,6 +719,10 @@ implementation
 ****************************************************************************}
 
      procedure DefaultReplacements(var s:ansistring);
+       var
+         envstr: string;
+         envvalue: pchar;
+         i: integer;
        begin
          { Replace some macros }
          Replace(s,'$FPCVERSION',version_string);
@@ -730,6 +734,29 @@ implementation
            Replace(s,'$FPCTARGET',target_os_string)
          else
            Replace(s,'$FPCTARGET',target_full_string);
+         { Replace environment variables between dollar signs }
+         i := pos('$',s);
+         while i>0 do
+          begin
+            envstr:=copy(s,i+1,length(s)-i);
+            i:=pos('$',envstr);
+            if i>0 then
+             begin
+               envstr := copy(envstr,1,i-1);
+               envvalue := GetEnvPChar(envstr);
+               if assigned(envvalue) then
+                 begin
+                 Replace(s,'$'+envstr+'$',envvalue);
+                 // Look if there is another env.var in the string
+                 i:=pos('$',s);
+                 end
+               else
+                 // if the env.var is not set, do not replace the env.variable
+                 // and stop looking for more env.var within the string
+                 i := 0;
+              FreeEnvPChar(envvalue);
+             end;
+          end;
        end;