# -*- 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
PortGroup           github 1.0

github.setup        bcpierce00 unison 2.52.0 v
revision            0
categories          net
maintainers         nomaintainer
license             GPL-3
description         Unison File Synchronizer
long_description    Unison is a file-synchronization tool for Unix and \
                    Windows. It allows two replicas of a collection of \
                    files and directories to be stored on different \
                    hosts (or different disks on the same host), \
                    modified separately, and then brought up to date by \
                    propagating the changes in each replica to the other.
homepage            http://www.cis.upenn.edu/~bcpierce/unison/

checksums           rmd160  034d7024768d856d7366e39805b00e0719e272d3 \
                    sha256  a11389971212915328fe69101c92737b17664595c4318ebcb8da367e5ba63540 \
                    size    1354200
github.tarball_from archive

universal_variant   no

depends_build       port:ocaml

installs_libs       no

use_parallel_build  no

patchfiles-append   patch-Makefile.OCaml.diff \
                    patch-target.diff \
                    patch-Makefile.diff \
                    patch-check-cltool.diff

post-patch {
    reinplace "s|__MACPORTS_PREFIX__|${prefix}|g" ${worksrcpath}/src/uimac/MyController.m
    set deployment_version [join [split ${macosx_deployment_target} .] ""]0
    reinplace "s|__MACPORTS_DEPLOYMENT_VERSION__|${deployment_version}|g" ${worksrcpath}/src/uimac/English.lproj/MainMenu.xib
}

# see https://trac.macports.org/ticket/57234
if {[vercmp ${xcodeversion} 10.0] >= 0} {
    build.env-append    XCODEFLAGS=-UseNewBuildSystem=NO
}

build.env-append    CC=${configure.cc}
destroot.env-append PREFIX=${prefix}

build.args          UISTYLE=text THREADS=true
destroot.args       UISTYLE=text THREADS=true

# ocamlopt not supported on powerpc. Notice, that OCaml 5
# drops support for all 32-bit platforms in its native compiler.
# So once OCaml is updated, i386 should be added here.
if {${configure.build_arch} in [list ppc ppc64]} {
    build.args-append \
                    NATIVE=false
    destroot.args-append \
                    NATIVE=false
}

use_configure       no

variant gtk description {Build GTK front-end} conflicts aqua {
    depends_lib-append      port:lablgtk2

    build.args-replace      UISTYLE=text \
                            UISTYLE=gtk2

    destroot.args-replace   UISTYLE=text \
                            UISTYLE=gtk2
}

# see https://trac.macports.org/ticket/56785
if {${os.major} >= 17} {
variant aqua description {Build Aqua front-end} conflicts gtk {
    build.args-replace      UISTYLE=text \
                            UISTYLE=mac14

    destroot.args-replace   UISTYLE=text \
                            UISTYLE=mac14

    use_xcode               yes

    destroot {
        copy ${worksrcpath}/src/uimac/build/Default/Unison.app ${destroot}${applications_dir}

        # Don't use cltool. It finds Unison using Launch Services. If the user
        # has multiple copies of Unison installed, Launch Services could return
        # any of them, not necessarily the one installed by MacPorts.
        xinstall ${filespath}/unison.in ${destroot}${prefix}/bin/unison
        reinplace "s|@APPLICATIONS_DIR@|${applications_dir}|g" ${destroot}${prefix}/bin/unison
    }
}
}

if {![variant_isset gtk] && !([variant_exists aqua] && [variant_isset aqua])} {
    default_variants    +gtk
}

notes "
Unison has always suggested using the same version across machines accessing\
the same files. If you want to keep the previous version, you can reactivate\
the previous version; see:

https://trac.macports.org/wiki/howto/InstallingOlderPort
"
