pas2CTutorial.wiki
changeset 2012 f0d921e412b0
parent 543 0b430064fc8d
child 2013 3bccb65d8cac
equal deleted inserted replaced
2011:1c2ca44d7b46 2012:f0d921e412b0
     1 #labels Phase-Implementation
     1 #labels Phase-Implementation
     2 ==Automatic==
     2 ==Introduction==
       
     3 Pas2C is an alternative way to build the engine. It is disabled by default.
       
     4 
       
     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.
       
     6 
       
     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.
       
     8 
       
     9 ==Limitations==
       
    10 
       
    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.
       
    12 
       
    13 == Building ==
       
    14 ===Caveats===
       
    15 Note! In version 1.0.0, if your `LOCALE` is set to `C`, building will fail with an error like this:
       
    16 
       
    17 ```
       
    18 Preprocessing 'uSound.pas'... pas2c: /builddir/build/BUILD/hedgewars-src-1.0.0/hedgewars/uSound.pas: hGetContents: invalid argument (invalid byte sequence)
       
    19 ```
       
    20 
       
    21 This is because Wuzzy accidentally added unicode characters in the Pascal source code, something which Pas2C doesn't like.
       
    22 
       
    23 If you have this problem, run this shell script in the root of the source directory before building:
       
    24 
       
    25 ```
       
    26 for file in hedgewars/uSound.pas hedgewars/uStats.pas; do
       
    27     iconv -f utf-8 -t ascii//TRANSLIT $file -o $file.tmp;
       
    28     mv $file.tmp $file;
       
    29 done
       
    30 ```
       
    31 
       
    32 This will be fixed in the next version.
       
    33 
       
    34 ===Automatic===
     3 
    35 
     4 Configure with `cmake -DBUILD_ENGINE_C=1` and then run `make`.
    36 Configure with `cmake -DBUILD_ENGINE_C=1` and then run `make`.
     5 
    37 
     6 ==Manual run==
    38 ===Manual run===
     7 
    39 
     8 Run from the `tools` folder
    40 Run from the `tools` folder
     9 {{{
    41 {{{
    10 ghc -e pas2C \"hwengine\"" pas2c.hs
    42 ghc -e pas2C \"hwengine\"" pas2c.hs
    11 }}}
    43 }}}
    15 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.
    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.
    16 
    48 
    17 Use `clang` to compile, `gcc` compatibility is not yet achieved. We are curious to hear about `icc` and `msvc` (not that we expect anything...)
    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...)
    18 
    50 
    19 ==Development==
    51 ==Development==
    20 There are some special file that you need to know
    52 There are some special files that you need to know:
    21 
    53 
    22   * project_files/hwc/rtl/fpcrtl.h - contains definitions of external functions defined inside custom pascal units (eg SDLh.pas);
    54   * `project_files/hwc/rtl/fpcrtl.h` - contains definitions of external functions defined inside custom pascal units (e.g. `SDLh.pas`);
    23   * hedgewars/pas2cSystem.pas - contains definitions of external functions defined outside our own pascal units (eg png and gl units, bundled with freepascal);
    55   * `hedgewars/pas2cSystem.pas` - contains definitions of external functions defined outside our own pascal units (e.g. png and gl units, bundled with !FreePascal);
    24   * hedgewars/pas2cRedo.pas - contains definitions of internal fpc units (provided by the 'rtl') which get a fpcrtl_ prefix.
    56   * `hedgewars/pas2cRedo.pas` - contains definitions of internal fpc units (provided by the `rtl`) which get a `fpcrtl_` prefix.
    25 
    57 
    26 If you need to hide portions of code from pas2c just wrap it with `${IFNDEF PAS2C}...{$ENDIF}`
    58 If you need to hide portions of code from Pas2C just wrap it with `${IFNDEF PAS2C}...{$ENDIF}`.
       
    59 
       
    60 To ensure compability with Pas2C, you also must obey the rules stated here: [PascalSyntax]