# -*- 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

if {${os.platform} eq "darwin" && ${os.major} < 14} {
    default_variants    +qt4
}
if {![variant_isset qt4]} {
    PortGroup           qmake5 1.0
} else {
    PortGroup           qt4    1.0
}

name                    xxdiff
version                 4.0.1
revision                0
categories              devel
license                 GPL-2+
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description             xxdiff is a graphical merging tool
long_description        xxdiff is a graphical browser for viewing the \
                        differences between two or three files, or between \
                        two directories, and can be used to produce a \
                        merged version.
homepage                https://furius.ca/xxdiff/

depends_build-append    port:bison \
                        port:flex

master_sites            sourceforge:project/xxdiff/xxdiff/${version}/
use_bzip2               yes

checksums               rmd160  1bd4a5bde100026e562d540f230c609f9b3c06cc \
                        sha256  bf58ddda9d7a887f4f5cae20070ed5f2e0d65f575af20860738c6e2742c3a000 \
                        size    1981869

# add upstream support for Qt 5
# MacPorts uses newser bison; respect MacPorts compiler flags
# macOS hack no longer seems to work
#     see ports/macosx/README.macosx
patchfiles-append       patch-qt5.diff \
                        patch-xxdiff.pro.diff \
                        patch-no_hack.diff

configure.dir           ${worksrcpath}/src
build.dir               ${configure.dir}

# from README.build: "You will need GNU make."
build.type              gnu

configure.cmd           ${build.cmd}
configure.pre_args      -f Makefile.bootstrap
configure.args          QMAKE=${qt_qmake_cmd} all

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

if {![variant_isset qt4]} {
    qt5.spec_cmd          QMAKESPEC=
} else {
    configure.args-append QMAKESPEC=${qt_qmake_spec}
}

destroot {
    # see adm/release_bin

    xinstall -m 0755 ${worksrcpath}/bin/xxdiff.app/Contents/MacOS/xxdiff ${destroot}${prefix}/bin

    copy             ${worksrcpath}/bin/xxdiff.app ${destroot}${applications_dir}
    delete           ${destroot}${applications_dir}/xxdiff.app/Contents/MacOS/xxdiff

    set     script  [open "${destroot}${applications_dir}/xxdiff.app/Contents/MacOS/xxdiff" w 0755]
    puts  ${script} "#!/bin/sh"
    puts  ${script} ""
    puts  ${script} "${prefix}/bin/xxdiff --prompt-for-files \"\$@\""
    close ${script}

    xinstall -m 0644 ${worksrcpath}/src/xxdiff.1   ${destroot}${prefix}/share/man/man1

    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
    foreach fl {README CHANGES} {
        xinstall -m 0644 ${worksrcpath}/${fl} ${destroot}${prefix}/share/doc/${name}
    }
    system -W ${destroot}${prefix}/share/doc/${name} "${worksrcpath}/bin/xxdiff.app/Contents/MacOS/xxdiff --help-html > xxdiff-doc.html"
}

variant qt4 description {build using Qt4} {}
