# $Id: Portfile,v 1.27 2006/04/22 20:04:15 mww Exp $

PortSystem 1.0
name			rpm
version			4.4.5
platforms		darwin
categories		sysutils archivers
maintainers		n3npq@mac.com
description		The RPM package management system.
long_description	\
	The RPM Package Manager (RPM) is a powerful command line driven \
	package management system capable of installing, uninstalling, \
	verifying, querying, and updating software packages. Each software \
	package consists of an archive of files along with information about \
	the package like its version, a description, etc.

master_sites		http://wraptastic.org/pub/rpm-4.4.x/
distfiles		rpm-${version}.tar.gz
checksums		md5 d5f434789c0c56d05d77be6f4262a561

depends_lib		lib:libhistory.5:readline lib:libiconv.2:libiconv \
			lib:libintl.3:gettext lib:libsqlite3.0:sqlite3

depends_build		port:expat port:neon \
			port:python24 port:popt \
			port:readline port:beecrypt \
			port:libiconv port:gettext
depends_run		port:gzip

			###you do *not* want these installed, instead use "/usr":
			#lib:libssl:openssl lib:libbz2:bzip2 path:perl:perl5.8
			###zlib should be replaced with the internal rpm version:
			#lib:libz:zlib
			###"expat" is for libneon, and "readline" is for rpm lua
			
			#"doxygen" is required for building the rpm API docs, default is --without
			#bin:doxygen:doxygen

worksrcdir	rpm-${version}

configure.args		--disable-nls --without-javaglue --without-included-gettext \
			--with-libintl-prefix=${prefix} --with-libiconv-prefix=${prefix} \
			--mandir=${prefix}/share/man --infodir=${prefix}/share/info \
			--with-python=2.4

configure.env           __PYTHON="${prefix}/bin/python"

build.type	gnu


variant darwin {
	patchfiles-append \
		patch-file-src-Makefile.in \
		patch-lib-rpmds \
		patch-macros.in

	post-patch {
		file delete -force ${worksrcpath}/beecrypt
		file delete -force ${worksrcpath}/neon
		file delete -force ${worksrcpath}/sqlite
		file delete -force ${worksrcpath}/elfutils
	}

#	use_autoconf	yes
#	use_automake	yes

	pre-configure {
		xinstall -d -m 755 ${workpath}/librt
		system "ln -sf /usr/lib/libSystem.B.dylib \
				${workpath}/librt/librt.dylib"

	#	system "touch ${worksrcpath}/aclocal.m4"
	#	system "touch ${worksrcpath}/config.h.in"
	}

	post-configure {
	#	system "find ${worksrcpath} -name Makefile.in | xargs touch"
	#	system "find ${worksrcpath} -name Makefile | xargs touch"
	}

	configure.args-append --disable-optimized --disable-aio \
			      --with-python=auto --with-lua --with-glob \
		              --enable-broken-chown --disable-rpath

	# requires doxygen:
	#configure.args-append --with-apidocs

	configure.args-append   \
		LDFLAGS="-L${prefix}/lib -L${workpath}/librt" \
		CFLAGS="-I/Library/Frameworks/Python.framework/Versions/2.4/include -I${prefix}/include" CPPFLAGS="-I${prefix}/include -I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4"

	post-destroot {
		# Delete overlapping files.
		file delete ${destroot}${prefix}/include/popt.h 
		system "rm -f ${destroot}${prefix}/share/man/man3/popt.3*"
		system "rm -rf ${destroot}${prefix}/lib/libpopt.*"
		system "rm -rf ${destroot}/System"
		system "rm -rf ${destroot}/Library"
		system "rm -f ${destroot}/usr/local/man/man3/RPM.3pm"

		# MacOSX specific changes
		reinplace "s;%{_usrsrc}/redhat;%{_usrsrc}/apple;" ${destroot}${prefix}/lib/rpm/macros

		# where the RPM database lives
		destroot.keepdirs "${destroot}${prefix}/var/lib/rpm"
		destroot.keepdirs-append "${destroot}${prefix}/src/apple/BUILD"
		destroot.keepdirs-append "${destroot}${prefix}/src/apple/RPMS"
		destroot.keepdirs-append "${destroot}${prefix}/src/apple/SOURCES"
		destroot.keepdirs-append "${destroot}${prefix}/src/apple/SPECS"
		destroot.keepdirs-append "${destroot}${prefix}/src/apple/SRPMS"
	}
}
