pas2CTutorial.wiki
author Wuzzy
Fri, 11 Oct 2019 21:02:10 +0100
changeset 2014 d61dd7380023
parent 2013 3bccb65d8cac
child 2015 9bcfc5661a37
permissions -rw-r--r--
pas2CTutorial: fix syntax
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
214
2c30f10b37a9 how to run pas2C
vittorio.giovara@gmail.com
parents:
diff changeset
     1
#labels Phase-Implementation
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     2
==Introduction==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     3
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
     4
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     5
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
     6
2013
3bccb65d8cac pas2CTutorial: so crazy
Wuzzy
parents: 2012
diff changeset
     7
Pas2C is our hand-written Pascal-to-C-compiler. It works by converting all Pascal code to C, and then compiling the C code. Yes, we're a little crazy. :-)
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     8
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
     9
==Limitations==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    10
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    11
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
    12
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    13
== Building ==
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    14
===Caveats===
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    15
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
    16
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    17
{{{
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    18
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
    19
}}}
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    20
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    21
This is because Wuzzy accidentally added unicode characters in the Pascal source code, something which Pas2C doesn't like.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    22
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    23
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
    24
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    25
{{{
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    26
for file in hedgewars/uSound.pas hedgewars/uStats.pas; do
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    27
    iconv -f utf-8 -t ascii//TRANSLIT $file -o $file.tmp;
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    28
    mv $file.tmp $file;
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    29
done
2014
d61dd7380023 pas2CTutorial: fix syntax
Wuzzy
parents: 2013
diff changeset
    30
}}}
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    31
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    32
This will be fixed in the next version.
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    33
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    34
===Automatic===
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    35
543
0b430064fc8d Update variable name.
vittorio.giovara@gmail.com
parents: 330
diff changeset
    36
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
    37
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    38
===Manual run===
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    39
217
78f6f4e9f358 Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents: 214
diff changeset
    40
Run from the `tools` folder
78f6f4e9f358 Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents: 214
diff changeset
    41
{{{
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    42
ghc -e pas2C \"hwengine\"" pas2c.hs
217
78f6f4e9f358 Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents: 214
diff changeset
    43
}}}
214
2c30f10b37a9 how to run pas2C
vittorio.giovara@gmail.com
parents:
diff changeset
    44
217
78f6f4e9f358 Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents: 214
diff changeset
    45
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
    46
78f6f4e9f358 Edited wiki page pas2CTutorial through web user interface.
vittorio.giovara@gmail.com
parents: 214
diff changeset
    47
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
    48
330
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    49
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
    50
74f23d3af091 Updated with all the new stuff
vittorio.giovara@gmail.com
parents: 245
diff changeset
    51
==Development==
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    52
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
    53
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    54
  * `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
    55
  * `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
    56
  * `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
    57
2012
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    58
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
    59
f0d921e412b0 pas2CTutorial: Write a lot more about Pas2C
Wuzzy
parents: 543
diff changeset
    60
To ensure compability with Pas2C, you also must obey the rules stated here: [PascalSyntax]