# -*- 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.54.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  7b36d0dfd8bdb51e179de881c656a57cf02fa20c \
                    sha256  0f14154611a2dfebb8c229be85ceda29a750eace4fb75d06e0d43fe5b58a6e87 \
                    size    1141341
github.tarball_from archive

universal_variant   no

depends_build       port:ocaml

installs_libs       no

use_parallel_build  no

patchfiles-append   patch-target.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.target        tui
destroot.target     install

# 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.env-append    NATIVE=false
    destroot.env-append NATIVE=false
}

use_configure       no

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

    build.target        tui gui
}

# see https://trac.macports.org/ticket/56785
if {${os.major} >= 17} {
variant aqua description {Build Aqua front-end} conflicts gtk {
    build.target        macui

    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
"
