Recent

Author Topic: Unit path: "-Fu" and "$UNITPATH"  (Read 6300 times)

qq9ebg9acvzx

  • New Member
  • *
  • Posts: 21
Unit path: "-Fu" and "$UNITPATH"
« on: April 25, 2017, 01:03:20 am »
Quote from: FPC's documentation
1.3.38 $UNITPATH : Specify unit path.
This option serves to specify the unit path, where the compiler looks for unit files. {$UNITPATH
XXX} will add XXX to the unit path. XXX can contain one or more paths, separated by semi-colons
or colons.

...This directive is equivalent to the -Fu command line switch.
In practice, it does not work that way. It works only when I specify the option "-Fu/usr/local/include/folder" in command line.

Am I missing something? I'm using "instantfpc" if it matters.

Thank you!

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #1 on: April 25, 2017, 01:52:17 am »
Am I missing something? I'm using "instantfpc" if it matters.

Never heard of $UNITPATH. Seems like that would hardwire a path in your code - sounds like a bad idea. I would stick to -Fu.

qq9ebg9acvzx

  • New Member
  • *
  • Posts: 21
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #2 on: April 25, 2017, 02:27:55 am »
Am I missing something? I'm using "instantfpc" if it matters.

Never heard of $UNITPATH. Seems like that would hardwire a path in your code - sounds like a bad idea. I would stick to -Fu.
It is true, but in my case I believe it would be better if the "$UNITPATH" directive worked within the code for the following reasons:
  • I want to call the code as a single script file, which gets compiled automatically and run by "instantfpc".
  • Giving multiple command line options to "instantfpc" is a bit problematic in BASH script header, or I don't know how to do it properly. That is one of the reasons I want to set needed compiler flags within the code.

Thank you!

sky_khan

  • Guest
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #3 on: April 25, 2017, 02:31:26 am »
There is this remark at its documentation
Quote
Note that this switch does not propagate to other units, i.e. it’s scope is limited to the current unit.

So it is not global directive, you should give this directive in every unit where you use these secondary units.

qq9ebg9acvzx

  • New Member
  • *
  • Posts: 21
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #4 on: April 25, 2017, 03:13:04 am »
There is this remark at its documentation
Quote
Note that this switch does not propagate to other units, i.e. it’s scope is limited to the current unit.

So it is not global directive, you should give this directive in every unit where you use these secondary units.
This is a single file program, all other units I am using is already compiled units (total of 2). And this directive is listed under "Global directives" in the documentation.

What should I do to get it working?

Thank you!

sky_khan

  • Guest
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #5 on: April 25, 2017, 03:32:07 am »
I tried. It does not work with instantfpc. I dont know why.

But this works.
Code: Pascal  [Select][+][-]
  1. uses
  2.    inner1 in '.\internal\inner1.pas';
  3.  
 

qq9ebg9acvzx

  • New Member
  • *
  • Posts: 21
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #6 on: April 25, 2017, 04:24:02 am »
I tried. It does not work with instantfpc. I dont know why.

But this works.
Code: Pascal  [Select][+][-]
  1. uses
  2.    inner1 in '.\internal\inner1.pas';
  3.  

This works if you include a ".pas", non compiled unit file. The unit file I have to include is a ".ppu" unit file, and this method does not work.

Thank you!

sky_khan

  • Guest
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #7 on: April 25, 2017, 05:33:53 am »
Well, I looked instantfpc. Because it copies your main file except first line into a cache folder and actual compiling is done there, it can not find relative unit paths. I didnt examine in depth but I could not get it work with absolute paths either. I think instantfpc's purpose is running single file simple scripts only. So either you can add your unit path to global fpc.cfg configuration or you can modify instantfpc code. Other than these I'm out of ideas.

sky_khan

  • Guest
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #8 on: April 25, 2017, 06:28:58 am »
Ehhhm, how about this ?

first,
DISCLAIMER: I am not responsible of any damage arising in any way out of the use of this script

/bin/runpas:
Code: Bash  [Select][+][-]
  1. #!/bin/sh
  2. pas=`basename $1`
  3. exe=${pas%\.*}
  4. mkdir -p /tmp/runpas;
  5. mkdir -p /tmp/runpas/bin;
  6. mkdir -p /tmp/runpas/units;
  7. sed '1d' $pas>tmp_runpas_$pas
  8. fpc -FE/tmp/runpas/bin -FU/tmp/runpas/units tmp_runpas_$pas>/tmp/runpas/runpas.log 2>/tmp/runpas/runpas.err
  9. rm tmp_runpas_$pas
  10. /tmp/runpas/bin/tmp_runpas_$exe
  11.  

this copies and compiles main file in-place (except first line). It uses executable output path and unit output path parameters of fpc to redirect those files to temporary folder instead of moving main source file. So
$UNITPATH should keep working.


qq9ebg9acvzx

  • New Member
  • *
  • Posts: 21
Re: Unit path: "-Fu" and "$UNITPATH"
« Reply #9 on: April 25, 2017, 02:09:24 pm »
Ehhhm, how about this ?

first,
DISCLAIMER: I am not responsible of any damage arising in any way out of the use of this script

/bin/runpas:
Code: Bash  [Select][+][-]
  1. #!/bin/sh
  2. pas=`basename $1`
  3. exe=${pas%\.*}
  4. mkdir -p /tmp/runpas;
  5. mkdir -p /tmp/runpas/bin;
  6. mkdir -p /tmp/runpas/units;
  7. sed '1d' $pas>tmp_runpas_$pas
  8. fpc -FE/tmp/runpas/bin -FU/tmp/runpas/units tmp_runpas_$pas>/tmp/runpas/runpas.log 2>/tmp/runpas/runpas.err
  9. rm tmp_runpas_$pas
  10. /tmp/runpas/bin/tmp_runpas_$exe
  11.  

this copies and compiles main file in-place (except first line). It uses executable output path and unit output path parameters of fpc to redirect those files to temporary folder instead of moving main source file. So
$UNITPATH should keep working.
OK, this gave me an idea to create a script that would act as interpreter instead of running "instantfpc" as interpreter directly.

Then I made this script:
Code: Bash  [Select][+][-]
  1. #! /bin/bash
  2. INSTANTFPCOPTIONS='-Mobjfpc -O3 -Sih -viewnh -Fu/usr/include/*;/usr/local/include/* -XMmain -Xs -XS -XX';
  3.  
  4. export INSTANTFPCOPTIONS;
  5.  
  6. instantfpc "$@"
  7.  


Then I just need to specify that script as interpreter: "#! /usr/local/bin/myscript.sh" instead of "#! /usr/bin/instantfpc".

And then just run the script normally: "./instantfpc_script.sh"


If you want a more portable alternative but be limited in number of options, you can specify a one line argument to the interpreter, as far as I know BASH allows only 1 option; like this:
Code: Bash  [Select][+][-]
  1. #! /usr/bin/instantfpc -Fu/usr/include/*;/usr/local/include/*
  2.  


This solution is OK for now, but it would be better if the "$UNITPATH" directive worked. If you know of a better alternative, please let me know.

Thank you very much for your help and time, people!
« Last Edit: April 27, 2017, 06:59:11 pm by qq9ebg9acvzx »

 

TinyPortal © 2005-2018