# -*- 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.51.2 v
revision            2
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/
platforms           darwin

checksums           rmd160  24050d73c3d38389816828dd8ce77b4de7c80639 \
                    sha256  8e071e862fef675ea034f0c3e4b881d392be0889db4f04ad894cc5a931891e3d \
                    size    1400793

# from ocaml port
supported_archs     i386 x86_64
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

# see https://github.com/bcpierce00/unison/commit/2e7ea9481c6c3ff2ec513c39f73cfe15c0763c06
patchfiles-append   patch-lablgtk.diff

post-patch {
    reinplace "s|__MACPORTS_PREFIX__|${prefix}|g" ${worksrcpath}/src/uimac14/MyController.m
    set deployment_version [join [split ${macosx_deployment_target} .] ""]0
    reinplace "s|__MACPORTS_DEPLOYMENT_VERSION__|${deployment_version}|g" ${worksrcpath}/src/uimac14/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

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

    destroot {
        copy ${worksrcpath}/src/uimac14/build/Default/Unison.app ${destroot}${applications_dir}
        ln -s ${applications_dir}/Unison.app/Contents/MacOS/cltool ${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\
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
"