# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mongodb
pkgver=2.4.4
pkgrel=2
pkgdesc="High-performance, schema-free document-oriented database"
url="http://www.mongodb.org"
arch="x86"
license="AGPLv3 and zlib and ASL 2.0"
depends=""
depends_dev="boost-dev python-dev pcre-dev readline-dev libpcap-dev
	snappy-dev v8-dev openssl-dev"
makedepends="scons $depends_dev"
install=""
subpackages="$pkgname-dev $pkgname-libs $pkgname-server"
source="http://fastdl.mongodb.org/src/mongodb-src-r$pkgver.tar.gz
	mongodb-2.2-r1-fix-scons.patch
	mongodb-2.4.4-fix-sharedclient.patch
	mongodb-2.2.4-use-system-version.patch
	uclibc-libc-version.patch

	mongodb.confd
	mongodb.initd
	mongodb.logrotate
	mongos.confd
	mongos.initd
	"

_builddir="$srcdir"/mongodb-src-r$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
#	sed -i -e '/Werror/d' SConstruct || return 1
}

build() {
	cd "$_builddir"
	export SCONSFLAGS="$MAKEFLAGS"
	scons \
		--cc="$CC" \
		--cxx="$CXX" \
		--full \
		--nostrip \
		--prefix="$pkgdir"/usr \
		--sharedclient \
		--ssl \
		--use-system-all \
		--usev8 \
		. \
		|| return 1
}

package() {
	cd "$_builddir"
	export SCONSFLAGS="$MAKEFLAGS"
	scons install . \
		--cc="$CC" \
		--cxx="$CXX" \
		--full \
		--nostrip \
		--prefix="$pkgdir"/usr \
		--sharedclient \
		--ssl \
		--use-system-all \
		--usev8 \
		|| return 1
	rm "$pkgdir"/usr/lib/*.a || return 1

	for i in $source; do
		local _mode _dir
		case $i in
		*.initd) _mode=755; _dir="$pkgdir"/etc/init.d ;;
		*.confd) _mode=644; _dir="$pkgdir"/etc/conf.d ;;
		*.logrotate) _mode=644; _dir="$pkgdir"/etc/logrotate.d ;;
		*) continue;;
		esac
		install -D -m $_mode "$srcdir"/$i "$_dir"/${i%.*} || return 1
	done
}

libs() {
	pkgdesc="MongoDB shared libraries"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/
}

server() {
	pkgdesc="MongoDB server, sharding server"
	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/etc
	mv "$pkgdir"/usr/bin/mongod \
		"$pkgdir"/usr/bin/mongos \
		"$subpkgdir"/usr/bin/ || return 1
	mv "$pkgdir"/etc/* "$subpkgdir"/etc/ || return 1
}

md5sums="6674d22591c52dc7009b84800e9295b5  mongodb-src-r2.4.4.tar.gz
624887501b5a8b99ecf7f6043a4873d4  mongodb-2.2-r1-fix-scons.patch
48dd5de6ddd588ede2909009e1372b19  mongodb-2.4.4-fix-sharedclient.patch
a5933e42383e887adcb35986c4e359a8  mongodb-2.2.4-use-system-version.patch
fc38e47db518165b6663ba45af17a4ea  uclibc-libc-version.patch
7d2f94bed7bfacd32fcd52dfd931f077  mongodb.confd
7bfbe9bd5da9254ab4981c7c3b8ac2bc  mongodb.initd
49df78833de4cb6e2b9b1ab9da52c3ac  mongodb.logrotate
33b23ee722f6e5d15eb6d9c2723a346f  mongos.confd
e2e7904c561364545a48077ba4e84dc3  mongos.initd"
sha256sums="ea3db3e730290d030853f7a22cbbc5edfbe33dd538ec67d551a7e88f6d4db240  mongodb-src-r2.4.4.tar.gz
cd136dea1ee03cfe8009cfe1e787478115f1f73209f3a770794c36813d1374df  mongodb-2.2-r1-fix-scons.patch
30ab8a6eb6f410b58df478276037ec1b694f72d3772311130b6258123c906cc5  mongodb-2.4.4-fix-sharedclient.patch
a70eebd1cef135d2940dda2705012f5bfab68580f54d62d4d56995e27a725d51  mongodb-2.2.4-use-system-version.patch
01f5974e74554c6b2456984f387ab8e753cbdd5dd6a401e51ee1b1876cc11b74  uclibc-libc-version.patch
a4ca29c577428c02cd0b0a8b46756df5f53a05519c9d13c270533cf99b9b819d  mongodb.confd
ee590071ade60cffdd28ce5bd1e685bcfb49878fb88a21adea0cf30867587ade  mongodb.initd
76994c32d999def5c925bd7be3f96687b3406f1d67b89aa6a4df8053025b1e01  mongodb.logrotate
2afd582564623da0e928ca667d37bef467334c82d08b49301f1f6c16ba177767  mongos.confd
0b7dafba846962f473c406e09d80923e07cf03bb8ba727b3e0408fbef28b23da  mongos.initd"
sha512sums="f72aee0a9c979756741902eb87775d154de45660596ec4507274a7719d376869510f192cf7777840821cb491cfe009beced8891e3f243c761ee758ab023a457d  mongodb-src-r2.4.4.tar.gz
741c4438b1f2060023ddb053317021f680a33d535299350f8775f602fd0221e7f96be0ca2694861611dfe449cb09fea4f3075018a6fc9f3c32ee978c075f3e97  mongodb-2.2-r1-fix-scons.patch
4f3e3e57ff38b5173fac972dbafa68119afccda505a8ca77326e78b715cf81401fa36bcd04297a52782b877c0c58cccee21938e6d780d30fbcf23cdf14ada5dd  mongodb-2.4.4-fix-sharedclient.patch
bb91d6eb5ec9d1c44b0a95d6831b3cf75401c62f15649f01cecf0ef3b976658f3508220dab887155e8bda0bc28b868cb069d985e51d386b1633124acb445d781  mongodb-2.2.4-use-system-version.patch
59993b64edef35490d3fd765850046f8757d10f6eb7fe2e5a9488cb020cffcc0ca690ca2a1807fe66ffb40b0a2d583ba240f09982c9d9c0ca1cab7fbedc37eb6  uclibc-libc-version.patch
9bcd870742c31bf25f34188ddc3c414de1103e9860dea9f54eee276b89bc2cf1226abab1749c5cda6a6fb0880e541373754e5e83d63cc7189d4b9c274fd555c3  mongodb.confd
c0634af4653a3b3ca1a72671460e8ea11cce99b84a48782c5cdcc27453d7ead1e89a61d0ce225febda68913dd04e972b4d6a911060b1e5c4ecfbfc1e991e7b12  mongodb.initd
8c089b1a11f494e4148fb4646265964c925bf937633a65e395ee1361d42facf837871dd493a9a2e0f480ae0e0829dbd3ed60794c5334e2716332e131fc5c2c51  mongodb.logrotate
61d8734cef644187eeadc821c89e63a3fbf61860fe2db6e74557b1c6760fe83ba7549cb04f9e3aacea4d8e7e4d81a3b1bc0d5e29715eca33c4761adb17ea9ab7  mongos.confd
28b54e19efd977721549b95e23d34b070c1af0648d5ae60e2457c86a3c18e5cbb6a56fa147d13a38ac540cf9315ac8f74cddaa3c7baafc56c8c6e5596ebef0c0  mongos.initd"