# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                pascal-p5
version             1.4
revision            0
categories          lang
license             GPL-2
maintainers         {@kamischi web.de:karl-michael.schindler} openmaintainer

description         P5, Zuerich type ISO 7185 Pascal compiler
long_description    This is the 5th version of the Pascal-P compiler from Zuerich. \
                    It is modified to be ISO 7185 Pascal compliant, both in \
                    the implementation language, and in the language it processes.
homepage            https://www.standardpascal.org/p5.html

fetch.type          git
git.url             https://git.code.sf.net/p/pascalp5/code
git.branch          f730c1

depends_build       port:fpc

supported_archs     x86_64 arm64 ppc

installs_libs       no
use_configure       no
universal_variant   no

# Directives in fpc start with "$" instead of "#"
# Also convert !, && and || to NOT, AND and OR
post-patch {
    reinplace  "s|^#if !defined(WRDSIZ16) && !defined(WRDSIZ32) && !defined(WRDSIZ64)|\{\$if (NOT defined(WRDSIZ16)) AND (NOT defined(WRDSIZ32)) AND (NOT defined(WRDSIZ64))\}| \
                             g" ${worksrcpath}/source/pint.pas ${worksrcpath}/source/pcom.pas
    reinplace  "s|^#|$|g"       ${worksrcpath}/source/pint.pas ${worksrcpath}/source/pcom.pas
    reinplace  "s|^$.*|\{&\}|g" ${worksrcpath}/source/pint.pas ${worksrcpath}/source/pcom.pas
    reinplace  "s/||/OR/g"      ${worksrcpath}/source/pint.pas
}

# patching the Makefile is more involved.
build {
    file mkdir ${worksrcpath}/build
    system  -W ${worksrcpath} " \
            fpc -Miso -ap -FEbuild source/pcom.pas && \
            fpc -Miso -ap -FEbuild source/pint.pas "
}

destroot {
    xinstall -m 755 -d                        ${destroot}${prefix}/bin/
    xinstall -m 755 ${worksrcpath}/build/pint ${destroot}${prefix}/bin/
    xinstall -m 755 ${worksrcpath}/build/pcom ${destroot}${prefix}/bin/
    xinstall -m 755 ${filespath}/p5           ${destroot}${prefix}/bin/
}

notes "\
p5 is a shell script, which calls the compiler pcom and the interpreter pint.\
The compiler pcom creates an intermediate file NAME.p5, which is run by\
the interpreter pint.\
"
