Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-01

Use environment variables in configuration file?

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to hinst
hinst wrote 9 lines
I want to use an environment variable in FPC configuration file; is this not possible? I created sample project which demonstrates the problem. I have one main source file and one unit which is located in subdirectory. I try to compile my program with this bash script:   It looks like FPC does not substitute $mvar with meow. It does not compile my program. However if I change options variable to this: options="@cfg.txt -Mobjfpc pro.pas -Fu$mvar" Then my program gets compiled successfully.

Obviously, since the bash interpreter takes care of substitution, FPC never sees $mvar.

Show quoted text 12 lines
It means that:   If I put -Fu$mvar in config file then it does not work   If I put -Fu$mvar in bash script then it does work   Which is strange because in standard config file fpc.cfg I can find not only built-in variables like $FPCVERSION but also environment variables like $LOCAL_APPDATA   Examples: -FuD:\Lazarus\fpc\$FPCVERSION/units/$fpctarget/httpd22 -Fu$LOCAL_APPDATA\FreePascal\fppkg/units/$FPCTARGET/* This I do not understand. How come that FPC when reading config file understands $LOCAL_APPDATA, but does not substitute variable I specified $mvar

Because there are several standard "placeholders" that FPC understands in the config file. These placeholders start with $.
They are not environment variables, despite the notation with $.

Michael.

Michael Van Canneyt
to Michael Van Canneyt
Michael Van Canneyt wrote 39 lines
On Wed, 29 Jan 2014, hinst wrote: > I want to use an environment variable in FPC configuration file; is this > not possible? > I created sample project which demonstrates the problem. I have one main > source file and one unit which is located > in subdirectory. > I try to compile my program with this bash script: >   > It looks like FPC does not substitute $mvar with meow. It does not compile > my program. > However if I change options variable to this: > options="@cfg.txt -Mobjfpc pro.pas -Fu$mvar" > Then my program gets compiled successfully. Obviously, since the bash interpreter takes care of substitution, FPC never sees $mvar. > It means that: >   If I put -Fu$mvar in config file then it does not work >   If I put -Fu$mvar in bash script then it does work >   > Which is strange because in standard config file fpc.cfg I can find not > only built-in variables like $FPCVERSION but > also environment variables like $LOCAL_APPDATA >   > Examples: > -FuD:\Lazarus\fpc\$FPCVERSION/units/$fpctarget/httpd22 > -Fu$LOCAL_APPDATA\FreePascal\fppkg/units/$FPCTARGET/* > This I do not understand. How come that FPC when reading config file > understands $LOCAL_APPDATA, but does not > substitute variable I specified $mvar Because there are several standard "placeholders" that FPC understands in the config file. These placeholders start with $. They are not environment variables, despite the notation with $.

See globals.pas

          ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);
          ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);
          ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);
          ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);
          ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);
          ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);
          ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE);

Is the standard list on Windows.

And looking a bit further, I just see that you CAN do environment variables, if you enclose them in $$, so $mvar$ would do the trick.

Michael.

hinst
to Michael Van Canneyt

29.01.2014, 14:36, "Michael Van Canneyt" :

Show quoted text 51 lines
On Wed, 29 Jan 2014, Michael Van Canneyt wrote: >  On Wed, 29 Jan 2014, hinst wrote: >>  I want to use an environment variable in FPC configuration file; is this >>  not possible? >>  I created sample project which demonstrates the problem. I have one main >>  source file and one unit which is located >>  in subdirectory. >>  I try to compile my program with this bash script: >> >>  It looks like FPC does not substitute $mvar with meow. It does not compile >>  my program. >>  However if I change options variable to this: >>  options="@cfg.txt -Mobjfpc pro.pas -Fu$mvar" >>  Then my program gets compiled successfully. >  Obviously, since the bash interpreter takes care of substitution, FPC never >  sees $mvar. >>  It means that: >>    If I put -Fu$mvar in config file then it does not work >>    If I put -Fu$mvar in bash script then it does work >> >>  Which is strange because in standard config file fpc.cfg I can find not >>  only built-in variables like $FPCVERSION but >>  also environment variables like $LOCAL_APPDATA >> >>  Examples: >>  -FuD:\Lazarus\fpc\$FPCVERSION/units/$fpctarget/httpd22 >>  -Fu$LOCAL_APPDATA\FreePascal\fppkg/units/$FPCTARGET/* >>  This I do not understand. How come that FPC when reading config file >>  understands $LOCAL_APPDATA, but does not >>  substitute variable I specified $mvar >  Because there are several standard "placeholders" that FPC understands in the >  config file. These placeholders start with $. >  They are not environment variables, despite the notation with $. See globals.pas           ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);           ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);           ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);           ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);           ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);           ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);           ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE); Is the standard list on Windows. And looking a bit further, I just see that you CAN do environment variables, if you enclose them in $$, so $mvar$ would do the trick. Michael.

Thanks! it worked

Michael Van Canneyt
to hinst
hinst wrote 19 lines
> > See globals.pas > >           ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA); >           ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA); >           ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA); >           ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL); >           ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES); >           ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON); >           ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE); > > Is the standard list on Windows. > > And looking a bit further, I just see that you CAN do environment variables, > if you enclose them in $$, so $mvar$ would do the trick. > > Michael. Thanks! it worked

And I have updated the documentation :)

Michael.