mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.6k stars 1.63k forks source link

Free Pascal support #1018

Open J5lx opened 7 years ago

J5lx commented 7 years ago

As the title suggests, I'm currently interested in Free Pascal support in Meson and I'm also considering to hack on this myself if I can wrap my head around Python and the way existing fpc build systems do things. However, while thinking about it I've come across a few things where I'm not quite sure how to handle them. Essentially it all boils down to the fact that there seem to be quite a lot of closely-related-yet-slightly-incompatible Pascal/Delphi languages, often using the same set of file extensions, and the Free Pascal compiler alone can apparently handle several of these variants. At the same time though, I have never really seen any variants other than Free Pascal actually being used. So currently I'm wondering:

  1. Should I add one generic language for all of these variants or one just for Free Pascal?
  2. How should it be called (e.g. in project())? pascal? freepascal? fpc? delphi? etc.

Personally I lean towards one fpc-specific language, since most of those variants seem to be slightly incompatible, but I'm worried that that would make other variants "second-class citizens" as most of them seem to use the same file extensions. It'd be nice to have some additional input on this.

jpakkane commented 7 years ago

For example C and C++ have many different standard versions, which are switchable with compiler flags. Maybe something similar could be done here? Other questions that come to mind:

J5lx commented 7 years ago

Switching between the dialects is possible using the -M compiler flag, but since we're talking about dialects rather than standards here I doubt that this would achieve the same level of portability as with C/C++. Plus, that compiler flag seems to be specific to fpc. Regarding the other questions:

All in all, I really lean towards an fpc-specific language, but that last point regarding the popularity of the different dialects is something that worries me, and I was hoping that someone else might have a better overview of the situation. If that's not the case I'd be happy to just work on fpc support, but I'd still like to have an okay for that, since this is not my own project.

nirbheek commented 7 years ago

In that case, I think it's fine to begin with just FreePascal support (call it 'freepascal' instead of just 'pascal'). If people ask about support for other dialects we can look into it at that time. No need to do premature featurization. :)

J5lx commented 7 years ago

Thanks, I'll have a look at it.

nirbheek commented 7 years ago

Do you think you can get this ready for the next release? :)

J5lx commented 7 years ago

Of course that depends on when you want to do the next release, but I wouldn't bet on it. The Free Pascal Compiler does lots of things in lots of non-standard ways, and I don't have a lot of time right now.

nirbheek commented 7 years ago

Probably in January or February 2017, I think since December is usually a time of holidays for most people.

J5lx commented 7 years ago

Okay, so I finally got to work on this again, but now I'm completely stuck. As I mentioned before, fpc does lots of things in lots of very weird, non-standard ways. The problem right now is the linking stage: The fpc command line can only be used to compile a source file, not for linking stuff only. However, fpc has the ability to generate, at compile-time, a linker script and a script for calling the linker accordingly. Those are always named "link.res" and "ppas.(sh|bat)", located in the same directory as the object files, and they are supposed to be called from within the same directory as the original compilation process. See https://git.io/vMC9S for an example; exepath in the code is the name of the directory with the object files.

So how would one handle this situation in Meson? After all, the fact that these generated scripts have to be used means that the name of the "linker" depends on the target. Plus, linker arguments (including additional object files to be included in the executable) have to be passed during compilation (of the main source file containing the actual program, i.e. what would be main() in C). Thoughts?

jpakkane commented 7 years ago

The only way is to have custom code in ninjabackend.py. Find the place where it branches based on what languages the target contains, add a check for Pascal and then write your own method to handle the idiosyncrasies of fpc.

tazdij commented 6 years ago

Since there is no response, and the issue remains open. Does this mean FreePascal is still not supported?

J5lx commented 6 years ago

I did some more work on this since then, but I didn’t manage to get it done and meanwhile I went on to work on other things where I don’t need fpc. Right now I’m rather busy but maybe in a few weeks at most I can at least try to unearth the work I did (should still be lying around somewhere) and see how useful it still is in regard to current meson versions / master.

tazdij commented 6 years ago

Hey thanks for the update. I have a few projects in FreePascal (Because it is awesome) and I want to build them as curated apps for ElementaryOS which uses a Meson build process in the "Cloud". I have been having some trouble putting together a process to make this work.

I am almost considering building it as a .so and then writing a thin C app to wrap it >.< but this is a nasty workaround.