# -*- 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                jam
version             2.6.1
revision            0
categories          devel
license             Permissive
maintainers         nomaintainer

# Attempts to install the same executable.
conflicts           ftjam

description         a software build tool like make
long_description    Jam is a software build tool (like make) from \
                    Perforce. It is very powerful tool and it is \
                    used for various projects. It is particularly \
                    adapted for C/C++ development, multiplatform \
                    projects or builds spread on several processors. \
                    Mac OS X developer tools actually include a \
                    customized version of it.
homepage            https://www.perforce.com/documentation/jam-documentation
master_sites        https://swarm.workshop.perforce.com/projects/perforce_software-jam/download/main/

use_tar             yes
dist_subdir         ${name}/${version}

checksums           rmd160  210c15fc72d1bc21c07b72ca0152c5c11570909d \
                    sha256  ace6b227c1a9985934fd13c9c0ae4f7ff44171c6ded8b83bb3da75e6efdcb3a7 \
                    size    665600
platforms           darwin

universal_variant   yes

patchfiles          patch-Makefile.diff \
                    patch-make1.c.diff \
                    patch-scan.h.diff \
                    patch-jam.c.diff \
                    patch-mkjambase.c.diff

post-patch {
    # fix up reminder of Makefile, depending on variants
    set EXTRA ""
    set CFLAGS "-O3"
    if {[variant_isset debug]} {
        set CFLAGS "-O0"
        set EXTRA "-sDEBUG=1"
    } elseif {[variant_isset mw]} {
        set CFLAGS "-opt all"
        set EXTRA "-sCC=mwccppc"
    }
    reinplace "s|@CFLAGS@|${CFLAGS}|g" ${worksrcpath}/Makefile
    reinplace "s|@EXTRA@|${EXTRA}|g" ${worksrcpath}/Makefile

    # fix up Jamfile to always install to the same directory, no
    # matter if debug or regular build
    reinplace "s@/g@@g" ${worksrcpath}/Jamfile
}

# Jam doesn't have a configure script
use_configure       no

pre-build {
    build.cmd-append    CC="${configure.cc}" \
                        CFLAGS=\"[get_canonical_archflags]\"
}

# Installation.
destroot {
    # retrieve directory name where files are installed
    # (there is only 1 with the name "bin*")
    set bindir [exec find ${worksrcpath} -name "bin*"]

    # install binaries
    xinstall -d -m 755 ${destroot}${prefix}/bin
    xinstall -m 755 ${bindir}/jam ${destroot}${prefix}/bin
    xinstall -m 755 ${bindir}/mkjambase ${destroot}${prefix}/bin

    # install library
    xinstall -d -m 755 ${destroot}${prefix}/lib
    xinstall -m 644 ${bindir}/libjam.a ${destroot}${prefix}/lib

    # install documents
    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        Jam.html Jambase.html Jamfile.html README RELNOTES \
        ${destroot}${prefix}/share/doc/${name}
}

variant mw conflicts debug description {Use Metrowerks compiler} {}

variant debug conflicts mw description {Build with debug options but no optimization} {}

livecheck.type      regex
livecheck.url       https://swarm.workshop.perforce.com/projects/perforce_software-jam/files/main
livecheck.regex     /files/main/${name}-(\[0-9.\]+)\.tar