#
# cygport build script for unison*
# by Andrew E. Schulman, 2015-06-05
#

# This script works for any of the Cygwin unison* packages:
# unison2.27, unison2.32, unison2.40, unison2.45, unison2.48, unison2.49.
# Just set the NAME, VERSION, and RELEASE.

#NAME=unison2.48
#VERSION=2.48.3
#RELEASE=2
NAME=unison2.49
VERSION=2.49.543
RELEASE=1

# Packaging

SUMMARY="Synchronize collections of files on different hosts (text interface)"
DESCRIPTION="Unison is a file synchronizer 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."
CATEGORY="Utils"
HOMEPAGE="http://www.cis.upenn.edu/~bcpierce/unison/"

# Sources

SRC_URI="
	http://www.cis.upenn.edu/~bcpierce/unison/download/releases/unison-${PV}/unison-${PV}.tar.gz
	http://www.cis.upenn.edu/~bcpierce/unison/download/releases/unison-${PV}/unison-${PV}-manual.html
"
#SRC_DIR=unison-${PV}
SRC_DIR=src

# Build

if [[ $NAME == "*-gtk" ]] ; then
	# GTK UI
	DEPEND="ocaml ocaml-lablgtk2 libgtk2.0-devel libpango1.0-devel"
	UISTYLE=gtk2
else
	# Console UI
	DEPEND=ocaml
	UISTYLE=text
fi

src_compile ()
{
	# Maintainer mode:
	# Substitute Unison version information into generic Cygwin patch files
	PUV=${PN#unison}	# Unison version # (e.g. 2.45)
	PUP=$(expr ${PUV%.*} '*' 1000 '+' ${PUV#*.})	# Package priority (e.g. 2045 for version 2.45)

	cd "$S"
	set -v
	sed -i \
		-e "s:@PN@:${PN}:g" \
		-e "s:@PV@:${PV}:g" \
		-e "s:@PR@:${PR}:g" \
		-e "s:@P@:${P}:g" \
		-e "s:@PVR@:${PVR}:g" \
		-e "s:@PF@:${PF}:g" \
		-e "s:@PUV@:${PUV}:g" \
		-e "s:@PUP@:${PUP}:g" \
		CYGWIN-PATCHES/*
	set +v

	cd "$B"
	lndirs
	unset NAME CFLAGS
	make OSARCH=Cygwin UISTYLE=$UISTYLE
}

src_install ()
{
	cd "${B}"

	newbin unison.exe unison-${PN#unison}.exe

	dodoc \
		CONTRIB \
		INSTALL \
		INSTALL.gtk2 \
		INSTALL.win32 \
		INSTALL.win32-cygwin-gnuc \
		INSTALL.win32-msvc \
		ROADMAP.txt
	newdoc unison-${PV}-manual.html unison-manual.html

	dosym ../Cygwin/${PN}.README /usr/share/doc/${PN}/README.Cygwin
}
