pas2CTutorial.wiki
author Wuzzy
Wed, 21 Jun 2023 12:50:32 +0000
changeset 2242 031a5b86e533
parent 2018 0a12cd51adf3
permissions -rw-r--r--
LuaLibraryAnimate: Say what happens after animation ends
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2018
0a12cd51adf3 pas2CTutorial: Haskell
Wuzzy
parents: 2015
diff changeset
     1
#summary Explanation of Pas2C and how to build it
214
2c30f10b37a9 how to run pas2C
vittorio.giovara@gmail.com
parents:
diff changeset
     2
#labels Phase-Implementation
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     3
==Introduction==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     4
Pas2C is an alternative way to build the engine. It is disabled by default.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     5
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     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.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     7
2018
0a12cd51adf3 pas2CTutorial: Haskell
Wuzzy
parents: 2015
diff changeset
     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
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     9
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    10
==Limitations==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    11
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    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.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    13
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    14
== Building ==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    15
===Caveats===
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    16
Note! In version 1.0.0, if your `LOCALE` is set to `C`, building will fail with an error like this:
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    17
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    18
{{{
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    19
Preprocessing 'uSound.pas'... pas2c: /builddir/build/BUILD/hedgewars-src-1.0.0/hedgewars/uSound.pas: hGetContents: invalid argument (invalid byte sequence)
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    20
}}}
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    21
2015
9bcfc5661a37 pas2CTutorial: typo
Wuzzy
parents: 2014
diff changeset
    22
This is because Wuzzy accidentally added Unicode characters in the Pascal source code, something which Pas2C doesn't like.
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    23
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    24
If you have this problem, run this shell script in the root of the source directory before building:
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    25
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    26
{{{
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    27
for file in hedgewars/uSound.pas hedgewars/uStats.pas; do
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    28
    iconv -f utf-8 -t ascii//TRANSLIT $file -o $file.tmp;
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    29
    mv $file.tmp $file;
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    30
done
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    31
}}}
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    32
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    33
This will be fixed in the next version.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    34
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    35
===Automatic===
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    36
543
0b430064fc8d Update variable name.
vittorio.giovara@gmail.com
parents: 330
diff changeset
    37
Configure with `cmake -DBUILD_ENGINE_C=1` and then run `make`.
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    38
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    39
===Manual run===
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    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
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    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
2c30f10b37a9 how to run pas2C
vittorio.giovara@gmail.com
parents:
diff changeset
    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
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    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...)
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    51
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    52
==Development==
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    53
There are some special files that you need to know:
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    54
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    55
  * `project_files/hwc/rtl/fpcrtl.h` - contains definitions of external functions defined inside custom pascal units (e.g. `SDLh.pas`);
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    56
  * `hedgewars/pas2cSystem.pas` - contains definitions of external functions defined outside our own pascal units (e.g. png and gl units, bundled with !FreePascal);
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    57
  * `hedgewars/pas2cRedo.pas` - contains definitions of internal fpc units (provided by the `rtl`) which get a `fpcrtl_` prefix.
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    58
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    59
If you need to hide portions of code from Pas2C just wrap it with `${IFNDEF PAS2C}...{$ENDIF}`.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    60
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    61
To ensure compability with Pas2C, you also must obey the rules stated here: [PascalSyntax]