Package-Name: portage
Gentoo-Package: sys-apps/portage
Requires: python
Compile-Requires: portage-snapshot portage-baselayout portage-sandbox
Homepage: http://www.gentoo.org/
Source: gentoo:///distfiles/portage-(\d+(.\d+)+).tar.bz2 $1
Repack:
	tar xjvfp "$(SOURCE)"
Compile:
	rm -rf "$(PREFIX)"/{lib,man,etc}
	mkdir "$(PREFIX)"/lib{,/portage}
	cp -av bin pym "$(PREFIX)"/lib/portage/
	mkdir -p "$(PREFIX)"/share{,/man{,/man{1,5}}}
	cp -av man/*.1 "$(PREFIX)"/share/man/man1/
	cp -av man/*.5 "$(PREFIX)"/share/man/man5/
	gcc -O2 $(GCC_OPT_FLAGS) src/tbz2tool.c -o bin/tbz2tool
	mkdir "$(PREFIX)"/etc
	cp -av cnf/{dispatch-conf.conf,etc-update.conf,make.globals} "$(PREFIX)"/etc/
	cp -p cnf/make.conf "$(PREFIX)"/etc/make.conf.example
	mkdir "$(PREFIX)"/etc/portage/profile
	rm -f "$(PREFIX)"/etc/portage/profile/package.provided
	echo >>"$(PREFIX)"/etc/portage/profile/package.provided "sys-apps/portage-$(VERSION)"
	echo >>"$(PREFIX)"/etc/portage/profile/package.provided "app-misc/pax-utils-0.1.13"  # not really, but let's pretend
	set -e; for package in sys-apps/baselayout:portage-baselayout \
	                       sys-apps/sandbox:portage-sandbox \
	                       app-shells/bash:bash \
	                       sys-devel/binutils:binutils \
	                       sys-devel/bison:bison \
	                       sys-devel/bzip2:bzip2 \
	                       sys-apps/coreutils:coreutils \
	                       sys-devel/flex:flex \
	                       sys-apps/gawk:gawk \
	                       sys-devel/gcc:gcc \
	                       sys-libs/glibc:glibc \
	                       dev-lang/perl:perl \
	                       dev-lang/python:python \
	                       sys-apps/sed:sed \
	; do \
	    gentoo_name=`echo "$$package" | cut -d: -f1`; \
	    local_name=`echo "$$package" | cut -d: -f2`; \
	    local_version=`cat "$(PREFIX)"/../$$local_name/.version`; \
	    if test -z "$$local_version"; then echo >&2 "Can't get version for $$local_name"; exit 1; fi; \
	    echo >>"$(PREFIX)"/etc/portage/profile/package.provided $${gentoo_name}-$${local_version}; \
	done
Install:
	# Install directly to the filesystem, as portage would, rather than
	# symlinking like we usually do
	rm -rf /usr/lib/portage
	mv "$(PREFIX)"/lib/portage /usr/lib/
	rmdir "$(PREFIX)"/lib
	cp -af "$(PREFIX)"/share/man /usr/share/
	ln -fs ../lib/portage/bin/{ebuild,emerge,portageq,repoman,tbz2tool,xpak} /usr/bin/
	ln -fs ../lib/portage/bin/{archive-conf,dispatch-conf,emaint,emerge-webrsync,env-update,etc-update,fixpackages,quickpkg,regenworld} /usr/sbin/
	ln -fs env-update /usr/sbin/update-env
	ln -fs etc-update /usr/sbin/update-etc
	mv "$(PREFIX)"/etc/{dispatch-conf.conf,etc-update.conf,make.conf.example,make.globals} /etc/
	if test ! -e /etc/make.conf; then cp -p /etc/make.conf.example /etc/make.conf; fi
	cp -af "$(PREFIX)"/etc/portage /etc/
	rm -rf "$(PREFIX)"/etc
	chmod -R go-rwx /etc/{dispatch-conf.conf,etc-update.conf,make.conf,make.conf.example,make.globals,portage}
	# Install portage-sandbox
	cp -af "$(PREFIX)"/../portage-sandbox/usr/bin/sandbox /usr/bin/
	cp -af "$(PREFIX)"/../portage-sandbox/usr/lib/libsandbox.* /usr/lib/
	/sbin/ldconfig
	rm -rf /usr/share/sandbox
	cp -af "$(PREFIX)"/../portage-sandbox/usr/share/sandbox /usr/share/
	# Copy over the safe parts of baselayout
	cp -af "$(PREFIX)"/../portage-baselayout/root/bin/rc-status /bin/
	set -e; for d in conf.d env.d modules.autoload.d; do \
	    mkdir -pv /etc/"$$d"; \
	    set -e; for i in "$(PREFIX)"/../portage-baselayout/root/etc/"$$d"/*; do \
	        f=`basename "$$i"`; \
	        if test ! -f /etc/"$$d"/"$$f"; then \
	            cp -pv "$$i" /etc/"$$d"/"$$f"; \
	        fi; \
	    done; \
	done
	cp -af "$(PREFIX)"/../portage-baselayout/root/etc/runlevels /etc/
	if test ! -f /etc/rc.conf; then cp -pv "$(PREFIX)"/../portage-baselayout/root/etc/rc.conf /etc/; fi
	if test ! -f /etc/sysctl.conf; then cp -pv "$(PREFIX)"/../portage-baselayout/root/etc/sysctl.conf /etc/; fi
	cp -a "$(PREFIX)"/../portage-baselayout/root/etc/{init.d,modules.d} /etc/
	chmod -R go-rwx /etc/{conf.d,env.d,init.d,modules.autoload.d,modules.d,rc.conf,runlevels,sysctl.conf}
	# Install the portage tree
	umask 022; tar Cxjvfp /usr "$(PREFIX)"/../portage-snapshot/portage.tar.bz2
	# Set up a user and group ID for portage
	set -e; if ! grep -q '^portage:' /etc/passwd; then \
	    export i=20 j=1; \
	    while grep -q '^[^:]*:[^:]*:'$$i: /etc/passwd; do \
	        i=$$[i+1]; \
	    done; \
	    if grep -q '^portage:' /etc/group; then \
	        j=`grep '^portage:' /etc/group | cut -d: -f3`; \
	    else \
	        j=$$i; \
	        while grep -q '^[^:]*:[^:]*:'$$j: /etc/group; do \
	            j=$$[j+1]; \
	        done; \
	        echo >>/etc/group "portage::$$j:"; \
	    fi; \
	    echo >>/etc/passwd "portage:x:$$i:$$j:portage:/:/bin/false"; \
	fi
	# Set up the make.profile link, if not already present
	test -e /etc/make.profile || ln -s /usr/portage/profiles/default-linux/x86 /etc/make.profile

-/etc/conf.d/
-/etc/dispatch-conf.conf
-/etc/env.d/
-/etc/etc-update.conf
-/etc/make.conf
-/etc/make.profile
-/etc/modules.autoload.d/
-/etc/portage/
-/etc/rc.conf
-/etc/runlevels/
/bin/rc-status
/etc/conf.d/
/etc/dispatch-conf.conf
/etc/env.d/
/etc/etc-update.conf
/etc/init.d/
/etc/make.conf
/etc/make.conf.example
/etc/make.globals
/etc/make.profile
/etc/modules.autoload.d/
/etc/modules.d/
/etc/portage/
/etc/rc.conf
/etc/runlevels/
/pkg/portage/
/usr/bin/ebuild
/usr/bin/emerge
/usr/bin/portageq
/usr/bin/repoman
/usr/bin/sandbox
/usr/bin/tbz2tool
/usr/bin/xpak
/usr/lib/libsandbox.*
/usr/lib/portage/
/usr/portage/
/usr/sbin/archive-conf
/usr/sbin/dispatch-conf
/usr/sbin/emaint
/usr/sbin/emerge-webrsync
/usr/sbin/env-update
/usr/sbin/etc-update
/usr/sbin/fixpackages
/usr/sbin/quickpkg
/usr/sbin/regenworld
/usr/sbin/update-env
/usr/sbin/update-etc
/usr/share/man/
/usr/share/sandbox/
