# Contributor: Borys Zhukov <mp5@mp5.im>
# Maintainer: Borys Zhukov <mp5@mp5.im>
setvar pkgname = 'ocaml'
setvar pkgver = '4.04.2'
setvar pkgrel = '1'
setvar pkgdesc = ""Main implementation of the Caml programming language""
setvar url = ""http://ocaml.org/""
setvar arch = ""all !x86 !armhf !s390x""
setvar license = ""LGPLv2""
setvar makedepends = ""ncurses-dev zlib-dev gdbm-dev""
setvar depends = ""ncurses-dev""
setvar options = ""textrels""
setvar subpackages = ""$pkgname-doc""
setvar source = ""http://caml.inria.fr/pub/distrib/ocaml-${pkgver%.*}/$pkgname-$pkgver.tar.gz
	010_all_execstacks.patch
	020_all_configure.patch
	050_all_objinfoldflags.patch
	fix-mcontext-fields.patch
	fix-segfault-in-ppc64le.patch
	""
setvar builddir = ""$srcdir/$pkgname-$pkgver""

proc build {
	cd $builddir

	#strip out -fomit-frame-pointer due to -pg
	local _cflags="$CFLAGS"
	setvar CFLAGS = ""-fPIC""
	for i in $_cflags {
		case (i) {
		-fomit-frame-pointer {}
		* { setvar CFLAGS = ""$CFLAGS $i""}
		}
	}

	./configure -cc ${CC:-gcc} \
		--bindir /usr/bin \
		--libdir /usr/lib/ocaml \
		--mandir /usr/share/man
	make -j1 world.opt
}

proc check {
       cd $builddir
       # there seem to be some spurious failures, ignore until fixed
       make test || true
       cd testsuite
       make report || true
}

proc package {
	cd $builddir
	make BINDIR="$pkgdir"/usr/bin LIBDIR="$pkgdir"/usr/lib/ocaml MANDIR="$pkgdir"/usr/share/man install

	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
	install -Dm644 Changes "$pkgdir"/usr/share/doc/$pkgname/Changes

	find "$pkgdir"/usr/lib/ocaml -name '*'.ml -delete
}
setvar sha512sums = ""c02e9353e8e62154ca683027c005154a7f280034d1ec9184ee52286d4a41852ba70f4ec976c01e07720f3c75e949da049eafc553e7a35ebaa65136e29ab248f5  ocaml-4.04.2.tar.gz
71ac807fb1173863b9dcf8e5fb4e651e0155d6cd0e4b327f5457b83fc09e1b5fbe34150c5d8ccd24f0faff1a8419f5ed8310aa60af1f38c2766ccc37dc6c3835  010_all_execstacks.patch
286758402517a1345556d374b0c3fc49eb93f1ec2bb9ccd2ffe1cc043f59d93b154f68eb9ff410020a15d3d8f148b27f249b7f97954b0e8a080cdd32d6014b4a  020_all_configure.patch
61d9cae6c8be7c16ed4aa6fafc533e2879caadbbe0e023775c1d735c0e54e66e94b9ffab8dc0b0b12c19ccf5c389e05f62af822014d202ae54c52943a0639753  050_all_objinfoldflags.patch
75c67e143a4a05b334bdebbad48ded1e04d383d8ea9b747df2633a5af96b1115b502510faf57753c71bbac38fbc9d9746b167861a63b2fd295901db0d22ea317  fix-mcontext-fields.patch
87e1c7dff0d550aa9855ec5c22226f7d6d3411256eef250bf985c1ef42089610ca6c3dd483c51c4edf656ebfc1728580b933c02f3043159ec01411e6f54e5a88  fix-segfault-in-ppc64le.patch""