Recent

Author Topic: fpcmkcfg and replacable parameters  (Read 427 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
fpcmkcfg and replacable parameters
« on: October 30, 2024, 11:25:56 am »
The FPC config file made by fpcmkcfg (in 3.2.4 RC1 and others) has version specific information in it, unnecessarily I believe.

As I need to swap compilers around from time to time and expect to so until a new FPC release is made, I need my config to work with various versions of FPC. But a typical line in the fpc.cfg (from fpcmkcfg) looks like -

Code: Bash  [Select][+][-]
  1. -Fu/home/dbannon/bin/FPC/fpc-3.2.4/units/$fpctarget
  2.  
  3. # but should, IMHO be like this -
  4.  
  5. -Fu/home/dbannon/bin/FPC/fpc-$fpcversion/units/$fpctarget

The macro, $fpcversion is listed by fpcmkcfg and seems to have been working for some time. But I cannot find a way to use it, a user error (?) any suggestions please ?  Its not particularly difficult to edit the file with sed but it seems silly that it is necessary.

Incidentally, my command line looks like this -

Code: Bash  [Select][+][-]
  1. $> fpcmkcfg -d basepath="$HOME"/bin/FPC/fpc-3.2.4 > ~/.fpc.cfg

Davo
 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: fpcmkcfg and replacable parameters
« Reply #1 on: October 30, 2024, 11:36:38 am »
The issue you are facing is due to the fact that the terminal gives special meaning to a dollar sign. So the option needs to be escaped.

I am not entirely sure if this also works on/for the command-line but it does work inside a script.
Code: [Select]
fpcmkcfg -d "basepath=/somewhere/somehow/\$fpcversion"
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8000
Re: fpcmkcfg and replacable parameters
« Reply #2 on: October 30, 2024, 11:54:37 am »
I'm pretty sure that a hardcoded version is an error, my (Linux) systems all have $fpcversion.

The one thing I'd add to what TRon's said is that if you're having problems with quoting you might find it easier to write your setup script using Perl rather than shell, since by and large that will give you far more control.

I've wrestled with this sort of thing in the past (I think it was in the context of writing scripts to control a SCSI-connected tape changer) and while it worked in the end I concluded 90% of the way through that shell was quite simply the wrong tool for the job.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11930
  • FPC developer.
Re: fpcmkcfg and replacable parameters
« Reply #3 on: October 30, 2024, 11:58:33 am »
The issue you are facing is due to the fact that the terminal gives special meaning to a dollar sign. So the option needs to be escaped.

I am not entirely sure if this also works on/for the command-line but it does work inside a script.
Code: [Select]
fpcmkcfg -d "basepath=/somewhere/somehow/\$fpcversion"

(btw: afaik the FPC installer script that calls this, specifies bash in the shebang, so if that kind of escaping is for other shells...)

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: fpcmkcfg and replacable parameters
« Reply #4 on: October 30, 2024, 12:01:37 pm »
(btw: afaik the FPC installer script that calls this, specifies bash in the shebang, so if that kind of escaping is for other shells...)
True, but I am/was more or less guessing that dbannon uses bash.

@MarkMLI:
fpcmkcfg used to contain several 'default' templates (not sure if that is still the case) and you can at least provide a (custom) default template if you happen to have one.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fpcmkcfg and replacable parameters
« Reply #5 on: October 30, 2024, 12:53:13 pm »
Thanks folks but I think I am not communicating here, the problem I mention can be replicated with pure command line entries.  No scripts, no passed envvars, no use of a $ in any command.

Code: Bash  [Select][+][-]
  1. dbannon@dell:~$ fpcmkcfg -d basepath=/home/dbannon/bin/FPC/fpc-3.2.4 | grep Fu
  2. ...
  3. -Fu/home/dbannon/bin/FPC/fpc-3.2.4/units/$fpctarget
  4. -Fu/home/dbannon/bin/FPC/fpc-3.2.4/units/$fpctarget/*
  5. ...

(Removed most lines for brevity, they all contain the "3.2.4" version number)

Are other people not seeing this ?  Thats interesting ...

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: fpcmkcfg and replacable parameters
« Reply #6 on: October 30, 2024, 12:57:20 pm »
Sorry dbannon but in that case I either am daft or still not fully grasp what you meant.

Quote
$fpcmkcfg -d basepath=/home/dbannon/bin/FPC/fpc-3.2.4
The basepath option is provided including the 3.2.4 numbers so it will store that literally in the generated configuration file.

apologies for any miscommunication in advance.


edit
Code: Bash  [Select][+][-]
  1. $fpcmkcfg -d "basepath=/somewhere/somehow/\$fpcversion" | grep Fu
  2. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel
  3. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/*
  4. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/rtl
  5. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget
  6. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/*
  7. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/rtl
  8. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/httpd13/
  9. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/httpd20
  10. -Fu/somewhere/somehow/$fpcversion/units/$fpctarget/httpd22
  11. -Fu~/.fppkg/lib/fpc/$fpcversion/units/$FPCTARGET/*
  12.  

vs
Code: Bash  [Select][+][-]
  1. fpcmkcfg -d "basepath=/somewhere/somehow/fpc-3.2.4" | grep Fu
  2. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/$fpcsubarch-$fpcmemorymodel
  3. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/*
  4. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/$fpcsubarch-$fpcmemorymodel/rtl
  5. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget
  6. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/*
  7. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/rtl
  8. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/httpd13/
  9. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/httpd20
  10. -Fu/somewhere/somehow/fpc-3.2.4/units/$fpctarget/httpd22
  11. -Fu~/.fppkg/lib/fpc/$fpcversion/units/$FPCTARGET/*
  12.  

« Last Edit: October 30, 2024, 01:09:18 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8000
Re: fpcmkcfg and replacable parameters
« Reply #7 on: October 30, 2024, 12:58:20 pm »
I've seen embedded numbers like that once, years ago, and I think it was associated with a target which was "work in progress".

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fpcmkcfg and replacable parameters
« Reply #8 on: October 30, 2024, 01:15:28 pm »
No, you are all correct and I should have read TRon's post more carefully.

Yep, putting in a variable, already containing the true path, works eexactly as I expected it too !
Code: Bash  [Select][+][-]
  1. $> export fpcversion="fpc-3.2.4"
  2. $> fpcmkcfg -d basepath=/home/dbannon/bin/FPC/\$fpcversion | grep Fu
  3. ...
  4. -Fu/home/dbannon/bin/FPC/$fpcversion/units/$fpctarget
  5. -Fu/home/dbannon/bin/FPC/$fpcversion/units/$fpctarget/*

Sorry for the noise !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: fpcmkcfg and replacable parameters
« Reply #9 on: October 30, 2024, 01:21:43 pm »
Yep, putting in a variable, already containing the true path, works eexactly as I expected it too !

Well, actually... if the aim is to have a environment variable substituted (at compile time) inside fpc.cfg (from my own config file):
Code: Bash  [Select][+][-]
  1. -d "basepath=\$fpc_root_directory\$/\$fpcversion"
  2.  
Note the envar enclosed between dollar signs

If the aim is to replace when/while creating the cfg file then $name_of_envar (just like $HOME) should be enough., e.g.
Code: Bash  [Select][+][-]
  1. -d "basepath=/somewhere/$name_of_envar/somehow"
  2.  

combined:
Code: Bash  [Select][+][-]
  1. -d "basepath=/\$somewhere\$/$some_envar/somehow/\$fpcversion"
  2.  
- $somewhere$ will be replaced at compile time with envar somewhere (if it exist, else empty)
- some_envar is replaced at creation time when making the config file
- $fpcversion will be replaced by the compiler's version number at compile time
« Last Edit: October 30, 2024, 01:40:25 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

 

TinyPortal © 2005-2018