author | Wuzzy <Wuzzy@disroot.org> |
Mon, 27 May 2024 19:59:44 +0200 | |
changeset 2270 | 22a964a1fe85 |
parent 2018 | 0a12cd51adf3 |
permissions | -rw-r--r-- |
2018 | 1 |
#summary Explanation of Pas2C and how to build it |
214 | 2 |
#labels Phase-Implementation |
2012 | 3 |
==Introduction== |
4 |
Pas2C is an alternative way to build the engine. It is disabled by default. |
|
5 |
||
6 |
Pas2C is intended to be used when building the engine natively (e.g. with !FreePascal) fails for some reason. However, Pas2C does have some limitations and you should try to first build Hedgewars normally before attempting a Pas2C build. |
|
7 |
||
2018 | 8 |
Pas2C is our hand-written Pascal-to-C-compiler. It works by converting all Pascal code to C, and then compiling the C code with a C compiler. Pas2C itself is written in Haskell. Yes, we're a little crazy. :-) |
2012 | 9 |
|
10 |
==Limitations== |
|
11 |
||
12 |
The Pas2C build currently doesn't support the video recorder. A warning will be printed if you try to build a Pas2C build with video recorder support anyway. |
|
13 |
||
14 |
== Building == |
|
15 |
===Caveats=== |
|
16 |
Note! In version 1.0.0, if your `LOCALE` is set to `C`, building will fail with an error like this: |
|
17 |
||
2014 | 18 |
{{{ |
2012 | 19 |
Preprocessing 'uSound.pas'... pas2c: /builddir/build/BUILD/hedgewars-src-1.0.0/hedgewars/uSound.pas: hGetContents: invalid argument (invalid byte sequence) |
2014 | 20 |
}}} |
2012 | 21 |
|
2015 | 22 |
This is because Wuzzy accidentally added Unicode characters in the Pascal source code, something which Pas2C doesn't like. |
2012 | 23 |
|
24 |
If you have this problem, run this shell script in the root of the source directory before building: |
|
25 |
||
2014 | 26 |
{{{ |
2012 | 27 |
for file in hedgewars/uSound.pas hedgewars/uStats.pas; do |
28 |
iconv -f utf-8 -t ascii//TRANSLIT $file -o $file.tmp; |
|
29 |
mv $file.tmp $file; |
|
30 |
done |
|
2014 | 31 |
}}} |
2012 | 32 |
|
33 |
This will be fixed in the next version. |
|
34 |
||
35 |
===Automatic=== |
|
330 | 36 |
|
543 | 37 |
Configure with `cmake -DBUILD_ENGINE_C=1` and then run `make`. |
330 | 38 |
|
2012 | 39 |
===Manual run=== |
330 | 40 |
|
217
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
41 |
Run from the `tools` folder |
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
42 |
{{{ |
330 | 43 |
ghc -e pas2C \"hwengine\"" pas2c.hs |
217
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
44 |
}}} |
214 | 45 |
|
217
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
46 |
You can replace "hwengine" with any other module. |
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
47 |
|
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
48 |
Every pas file will be converted to a .c/.h version in the `hedgewars` folder. In case no output is produced something has gone wrong. |
78f6f4e9f358
Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents:
214
diff
changeset
|
49 |
|
330 | 50 |
Use `clang` to compile, `gcc` compatibility is not yet achieved. We are curious to hear about `icc` and `msvc` (not that we expect anything...) |
51 |
||
52 |
==Development== |
|
2012 | 53 |
There are some special files that you need to know: |
330 | 54 |
|
2012 | 55 |
* `project_files/hwc/rtl/fpcrtl.h` - contains definitions of external functions defined inside custom pascal units (e.g. `SDLh.pas`); |
56 |
* `hedgewars/pas2cSystem.pas` - contains definitions of external functions defined outside our own pascal units (e.g. png and gl units, bundled with !FreePascal); |
|
57 |
* `hedgewars/pas2cRedo.pas` - contains definitions of internal fpc units (provided by the `rtl`) which get a `fpcrtl_` prefix. |
|
330 | 58 |
|
2012 | 59 |
If you need to hide portions of code from Pas2C just wrap it with `${IFNDEF PAS2C}...{$ENDIF}`. |
60 |
||
61 |
To ensure compability with Pas2C, you also must obey the rules stated here: [PascalSyntax] |