Sign in Join

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

Mailing lists / fpc-pascal / 2009-05

Using platform specific include files like FPC does

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

How do I use platform specific include files like FPC does, but in my own projects?

for example: In tiOPF we have a tiUtils.pas unit. We try and limit IFDEFs to only that unit. Often we have a single tiXXX() method which contains a {IFDEF FPC} or {IFDEF UNIX} and {IFDEF WINDOWS}. I would like to try and remove such ifdefs and use include files to support Windows, Linux and MacOSX.

Any thoughts on how I can accomplish this like FPC does?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

How do I use platform specific include files like FPC does, but in my own projects?

FPC has actually several schemes.

The most common two are:

1 {$ifdef'ed} inclusion of includefiles.
2 having make set the includedir to a target version.

The first is dead simple, the second depends on your makefile system.

Note that afaik the main reason FPC does this is because too many ifdefs make the source unreadable. It is not because of a grudge against ifdefs.

Tomas Hajny
to Marco van de Voort
Marco van de Voort wrote 15 lines
In our previous episode, Graeme Geldenhuys said: > How do I use platform specific include files like FPC does, but in my > own projects? FPC has actually several schemes. The most common two are: 1 {$ifdef'ed} inclusion of includefiles. 2 having make set the includedir to a target version. The first is dead simple, the second depends on your makefile system. Note that afaik the main reason FPC does this is because too many ifdefs make the source unreadable. It is not because of a grudge against ifdefs.

Well, additional advantages of not having IFDEFs in the code (second scenario) include higher consistency of implementation across the platforms and no need for changes in the common source when adding support for new platforms.

Tomas

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Graeme Geldenhuys said: FPC has actually several schemes. The…

2009/5/21 Marco van de Voort :

2 having make set the includedir to a target version. The first is dead simple, the second depends on your makefile system.

Ah, so that's the secret. :-) Thanks, I'll try this one. I'm pretty sure I can use some of the built-in path macros in Lazarus IDE to accomplish this.

Note that afaik the main reason FPC does this is because too many ifdefs make the source unreadable. It is not because of a grudge against ifdefs.

An the same reason I want to get rid of IFDEFs. The obfuscate the code.

Thanks for the tip. :)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Marco van de Voort
to Tomas Hajny: Well, additional advantages of not having IFDEFs in the code (second scenario) include…

In our previous episode, Tomas Hajny said:

Well, additional advantages of not having IFDEFs in the code (second scenario) include higher consistency of implementation across the platforms and no need for changes in the common source when adding support for new platforms.

That is one side. On the other side it often encourages bringing abstractions of one platform to others.

Marco van de Voort
to Graeme Geldenhuys: 2009/5/21 Marco van de Voort : Ah, so that's the secret. :-) Thanks, I'll try this one.…

In our previous episode, Graeme Geldenhuys said:

Ah, so that's the secret. :-) Thanks, I'll try this one. I'm pretty sure I can use some of the built-in path macros in Lazarus IDE to accomplish this.

Afaik lazarus already does this in de lcl/ dir.

> Note that afaik the main reason FPC does this is because too many ifdefs > make the source unreadable. It is not because of a grudge against ifdefs. An the same reason I want to get rid of IFDEFs. The obfuscate the code.

(I meant more that we only do it for the heaviest ifdefed files)