Recent

Author Topic: [Solved] Compile auxilliary units via Makefile  (Read 613 times)

Wesbat

  • New Member
  • *
  • Posts: 37
    • engrams.dev
[Solved] Compile auxilliary units via Makefile
« on: January 12, 2025, 05:37:55 am »
Hi there.

I'm trying to understand how to write a Makefile.fpc to compile a program.

I'm using the GO32V2 version of the compiler, but this process should apply to any, right? (Please correct me if I'm wrong)

This is my test program:
Code: Pascal  [Select][+][-]
  1. program MyProg;
  2.  
  3. uses
  4.   graph,
  5.   myunit;
  6.  
  7. BEGIN
  8.   sayhi;
  9. END.
  10.  

and my test unit:
Code: Pascal  [Select][+][-]
  1. unit myunit;
  2.  
  3. interface
  4.  
  5. procedure sayhi;
  6.  
  7. implementation
  8.  
  9. procedure sayhi;
  10. begin
  11.   WriteLn('hello world');
  12. end;
  13.  
  14. end.
  15.  

and my Makefile.fpc:
Code: Pascal  [Select][+][-]
  1. [require]
  2. unitdir=c:\pp\units\go32v2\graph
  3.  
  4. [target]
  5. units=myunit
  6. programs=myprog
  7.  

I run "fpcmake" to generate the GNU Makefile, after which I run "make":

Linking .\Myprog .exe
myprog.pp(9,1) Warning: Object myunit.o not found, Linking nay fail !
myprog.pp(9,1) Error: Can't open object file: myunit.o
myprog.pp(9,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

However if I open myunit.pp with the fp.exe IDE and compile it (producing the myunit.o object) first, then obviously make finds it and succeeds.

I thought the [target] units directive in Makefile.fpc would compile myunit.o from what I read in the documentation, but this does not seem to be the case.

Any hints will be much appreciated :)
« Last Edit: January 14, 2025, 08:35:46 am by Wesbat »

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Compile auxilliary units via Makefile
« Reply #1 on: January 12, 2025, 08:00:36 am »
I am missing entries for [default], [install] and maybe [package] (because you have multiple files).
You are correct to assume that it should work anywhere if the format is correct and complete.
See programmers guide, appendix E. for a thorough explanation.

The way fpcmake works means you can't just skip entries that you assume you don't need. Usually you need at least all but one ([require]) sections.
« Last Edit: January 12, 2025, 08:03:10 am by Thaddy »
But I am sure they don't want the Trumps back...

Wesbat

  • New Member
  • *
  • Posts: 37
    • engrams.dev
Re: Compile auxilliary units via Makefile
« Reply #2 on: January 13, 2025, 08:17:22 am »
Roger that Thaddy. Thank you for your answer, it prompted me to re-read the documentation.

I discovered that by listing "myunit" in the programs list, it gets compiled and linking succeeds. I realize this is not an idiomatic solution, so I will keep trying different configurations to find the proper way.

Code: Pascal  [Select][+][-]
  1. ...
  2. [target]
  3. programs=myunit myprog
  4. ...

 

TinyPortal © 2005-2018