Index: trunk/dports/sysutils/dpkg/Portfile
===================================================================
--- trunk/dports/sysutils/dpkg/Portfile	(revision 979)
+++ trunk/dports/sysutils/dpkg/Portfile	(revision 979)
@@ -0,0 +1,39 @@
+PortSystem 1.0
+name			dpkg
+version			1.9.21
+categories		archivers
+maintainers		landonf@opendarwin.org
+description		Debian package maintenance system
+
+master_sites		http://ftp.debian.org/debian/pool/main/d/dpkg/
+checksums		md5 fbd279854e724103fec3358c76d47c69
+distname		${portname}_${portversion}
+worksrcdir		${portname}-${portversion}
+
+configure.args		--with-included-gettext --without-sgml-doc
+
+post-patch {
+	system "ln -s ${worksrcpath}/intl/libgnuintl.h ${worksrcpath}/intl/libintl.h"
+	# dpkg-shlibs
+	reinplace s|/etc/dpkg/|${prefix}/etc/dpkg/| ${worksrcpath}/scripts/dpkg-shlibdeps.pl
+	# dpkg-source
+	reinplace s|/etc/dpkg/|${prefix}/etc/dpkg/| ${worksrcpath}/scripts/dpkg-source.1
+
+	# update-alternatives
+	reinplace s|/etc/alternatives|${prefix}/etc/alternatives|g ${worksrcpath}/scripts/update-alternatives.pl
+	reinplace s|/etc|${prefix}/etc|g ${worksrcpath}/scripts/update-alternatives.8
+
+	# update-rc.d
+	reinplace s|/etc/|${prefix}/etc/|g ${worksrcpath}/scripts/update-rc.d.pl
+	reinplace s|/etc/|${prefix}/etc/|g ${worksrcpath}/scripts/update-rc.d.8
+}
+
+variant darwin {
+	pre-install { file mkdir ${prefix}/share/doc/dpkg }
+	patchfiles-append patch-dpkg-deb_Makefile.in patch-optlib_Makefile.in \
+			  patch-split_Makefile.in patch-utils_Makefile.in \
+			  patch-utils_start-stop-daemon.c patch-configure \
+			  patch-main_Makefile.in patch-dselect_Makefile.in
+}
+
+include			contents
Index: trunk/dports/sysutils/dpkg/contents
===================================================================
--- trunk/dports/sysutils/dpkg/contents	(revision 979)
+++ trunk/dports/sysutils/dpkg/contents	(revision 979)
@@ -0,0 +1,163 @@
+contents {
+bin/822-date
+bin/dpkg
+bin/dpkg-architecture
+bin/dpkg-buildpackage
+bin/dpkg-checkbuilddeps
+bin/dpkg-deb
+bin/dpkg-distaddfile
+bin/dpkg-genchanges
+bin/dpkg-gencontrol
+bin/dpkg-name
+bin/dpkg-parsechangelog
+bin/dpkg-scanpackages
+bin/dpkg-scansources
+bin/dpkg-shlibdeps
+bin/dpkg-source
+bin/dpkg-split
+bin/dselect
+bin/md5sum
+etc/alternatives/README
+etc/alternatives
+etc/dpkg/origins/debian
+etc/dpkg/origins
+etc/dpkg
+lib/db/alternatives
+lib/db/info
+lib/db/methods/disk
+lib/db/methods/floppy
+lib/db/methods/mnt
+lib/db/updates
+lib/db/methods
+lib/dpkg/controllib.pl
+lib/dpkg/enoent
+lib/dpkg/methods/disk/desc.cdrom
+lib/dpkg/methods/disk/desc.harddisk
+lib/dpkg/methods/disk/desc.mounted
+lib/dpkg/methods/disk/desc.nfs
+lib/dpkg/methods/disk/install
+lib/dpkg/methods/disk/names
+lib/dpkg/methods/disk/setup
+lib/dpkg/methods/disk/update
+lib/dpkg/methods/disk
+lib/dpkg/methods/floppy/desc.floppy
+lib/dpkg/methods/floppy/install
+lib/dpkg/methods/floppy/names
+lib/dpkg/methods/floppy/setup
+lib/dpkg/methods/floppy/update
+lib/dpkg/methods/floppy
+lib/dpkg/methods
+lib/dpkg/mksplit
+lib/dpkg/parsechangelog/debian
+lib/dpkg/parsechangelog
+lib/dpkg
+man/fr/man1/dpkg-deb.1
+man/fr/man1/dpkg-name.1
+man/fr/man1/dpkg-source.1
+man/fr/man1
+man/fr/man5/deb-control.5
+man/fr/man5
+man/fr/man8/cleanup-info.8
+man/fr/man8/dpkg-divert.8
+man/fr/man8/dpkg-scanpackages.8
+man/fr/man8/dpkg-scansources.8
+man/fr/man8/dpkg.8
+man/fr/man8/install-info.8
+man/fr/man8/start-stop-daemon.8
+man/fr/man8/update-alternatives.8
+man/fr/man8/update-rc.d.8
+man/fr/man8
+man/fr
+man/ja/man1/822-date.1
+man/ja/man1/dpkg-checkbuilddeps.1
+man/ja/man1/dpkg-deb.1
+man/ja/man1/dpkg-name.1
+man/ja/man1/md5sum.1
+man/ja/man5/deb-control.5
+man/ja/man5/deb-old.5
+man/ja/man5/deb.5
+man/ja/man5
+man/ja/man8/cleanup-info.8
+man/ja/man8/dpkg-divert.8
+man/ja/man8/dpkg-scanpackages.8
+man/ja/man8/dpkg-scansources.8
+man/ja/man8/dpkg.8
+man/ja/man8/dselect.8
+man/ja/man8/install-info.8
+man/ja/man8/start-stop-daemon.8
+man/ja/man8/update-alternatives.8
+man/ja/man8/update-rc.d.8
+man/ja/man8
+man/ja/man1
+man/ja
+man/man1/822-date.1
+man/man1/dpkg-architecture.1
+man/man1/dpkg-buildpackage.1
+man/man1/dpkg-checkbuilddeps.1
+man/man1/dpkg-deb.1
+man/man1/dpkg-distaddfile.1
+man/man1/dpkg-genchanges.1
+man/man1/dpkg-gencontrol.1
+man/man1/dpkg-name.1
+man/man1/dpkg-parsechangelog.1
+man/man1/dpkg-shlibdeps.1
+man/man1/dpkg-source.1
+man/man1/md5sum.1
+man/man5/deb-control.5
+man/man5/deb-old.5
+man/man5/deb.5
+man/man8/cleanup-info.8
+man/man8/dpkg-divert.8
+man/man8/dpkg-scanpackages.8
+man/man8/dpkg-scansources.8
+man/man8/dpkg-split.8
+man/man8/dpkg-statoverride.8
+man/man8/dpkg.8
+man/man8/dselect.8
+man/man8/install-info.8
+man/man8/start-stop-daemon.8
+man/man8/update-alternatives.8
+man/man8/update-rc.d.8
+man/man8
+man/sv/man1/822-date.1
+man/sv/man1/md5sum.1
+man/sv/man1
+man/sv/man5/deb-control.5
+man/sv/man5/deb-old.5
+man/sv/man5/deb.5
+man/sv/man5
+man/sv/man8/dpkg-split.8
+man/sv/man8/dpkg.8
+man/sv/man8/dselect.8
+man/sv/man8/start-stop-daemon.8
+man/sv/man8
+man/sv
+sbin/cleanup-info
+sbin/dpkg-divert
+sbin/dpkg-statoverride
+sbin/install-info
+sbin/start-stop-daemon
+sbin/update-alternatives
+sbin/update-rc.d
+share/doc/dpkg/ChangeLog
+share/doc/dpkg/ChangeLog.manuals
+share/doc/dpkg/copyright
+share/doc/dpkg/THANKS
+share/doc/dpkg/TODO
+share/doc/dpkg
+share/locale/ca/LC_MESSAGES/dpkg.mo
+share/locale/cs/LC_MESSAGES/dpkg.mo
+share/locale/da/LC_MESSAGES/dpkg.mo
+share/locale/de/LC_MESSAGES/dpkg.mo
+share/locale/en/LC_MESSAGES/dpkg.mo
+share/locale/es/LC_MESSAGES/dpkg.mo
+share/locale/fr/LC_MESSAGES/dpkg.mo
+share/locale/gl/LC_MESSAGES/dpkg.mo
+share/locale/it/LC_MESSAGES/dpkg.mo
+share/locale/ja/LC_MESSAGES/dpkg.mo
+share/locale/nl/LC_MESSAGES/dpkg.mo
+share/locale/pl/LC_MESSAGES/dpkg.mo
+share/locale/pt_BR/LC_MESSAGES/dpkg.mo
+share/locale/ru/LC_MESSAGES/dpkg.mo
+share/locale/sv/LC_MESSAGES/dpkg.mo
+}
Index: trunk/dports/sysutils/dpkg/files/patch-configure
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-configure	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-configure	(revision 979)
@@ -0,0 +1,21 @@
+--- configure	Thu May 16 10:45:11 2002
++++ configure	Sat Oct  5 22:35:43 2002
+@@ -4409,12 +4409,12 @@
+ LIBS="$ac_save_LIBS"
+ 
+ fi
+-if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+-  echo "$ac_t""yes" 1>&6
+-  SSD_LIBS="-lkvm $SSD_LIBS"
+-else
+-  echo "$ac_t""no" 1>&6
+-fi
++#if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
++#  echo "$ac_t""yes" 1>&6
++#  SSD_LIBS="-lkvm $SSD_LIBS"
++#else
++#  echo "$ac_t""no" 1>&6
++#fi
+ 
+ 
+ 
Index: trunk/dports/sysutils/dpkg/files/patch-dpkg-deb_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-dpkg-deb_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-dpkg-deb_Makefile.in	(revision 979)
@@ -0,0 +1,9 @@
+--- dpkg-deb/Makefile.in	Sat Oct  5 08:11:36 2002
++++ dpkg-deb/Makefile.in	Fri Dec  8 17:51:21 2000
+@@ -41,5 +41,5 @@
+ 	$(INSTALL_DATA) $(srcdir)/dpkg-deb.1 $(DESTDIR)$(man1dir)
+ 
+ dpkg-deb: $(OBJECTS) ../lib/libdpkg.a
+-	$(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) $(ZLIB_LIBS) -ldpkg
++	$(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) $(ZLIB_LIBS) -ldpkg ../optlib/libopt.a
+ 
Index: trunk/dports/sysutils/dpkg/files/patch-dselect_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-dselect_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-dselect_Makefile.in	(revision 979)
@@ -0,0 +1,11 @@
+--- dselect/Makefile.in	Sat Oct  5 22:39:41 2002
++++ dselect/Makefile.in	Sat Oct  5 22:48:46 2002
+@@ -47,7 +47,7 @@
+ 	done
+ 
+ dselect: $(OBJECTS) ../lib/libdpkg.a
+-	$(CXX) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg -lncurses
++	$(CXX) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg -lncurses ../optlib/libopt.a
+ 
+ basecmds.o: helpmsgs.h
+ curkeys.o: curkeys.h
Index: trunk/dports/sysutils/dpkg/files/patch-main_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-main_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-main_Makefile.in	(revision 979)
@@ -0,0 +1,11 @@
+--- main/Makefile.in	Tue Apr 24 04:02:50 2001
++++ main/Makefile.in	Sat Oct  5 22:40:09 2002
+@@ -48,7 +48,7 @@
+ 	done
+ 
+ dpkg: $(OBJECTS) ../lib/libdpkg.a
+-	$(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg
++	$(CC) $(LDFLAGS) -L../lib -o $@ $(OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg ../optlib/libopt.a
+ 
+ enquiry.o: archtable.h
+ 
Index: trunk/dports/sysutils/dpkg/files/patch-optlib_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-optlib_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-optlib_Makefile.in	(revision 979)
@@ -0,0 +1,10 @@
+--- optlib/Makefile.in	Sun Mar  4 06:39:06 2001
++++ optlib/Makefile.in	Sat Oct  5 07:56:15 2002
+@@ -14,6 +14,7 @@
+ 	
+ libopt.a: $(OBJECTS)
+ 	$(AR) r $@ $^
++	$(RANLIB) $@
+ 
+ .PHONY: install
+ install:: all
Index: trunk/dports/sysutils/dpkg/files/patch-split_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-split_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-split_Makefile.in	(revision 979)
@@ -0,0 +1,11 @@
+--- split/Makefile.in	Tue Jan 11 11:41:55 2000
++++ split/Makefile.in	Sat Oct  5 08:24:10 2002
+@@ -41,7 +41,7 @@
+ 	$(INSTALL_DATA) $(srcdir)/dpkg-split.8 $(DESTDIR)/$(man8dir)
+ 
+ dpkg-split: $(SPLIT_OBJECTS) 
+-	$(CC) $(LDFLAGS) -L../lib -o $@ $(SPLIT_OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg
++	$(CC) $(LDFLAGS) -L../lib -o $@ $(SPLIT_OBJECTS) $(LIBS) $(NLS_LIBS) -ldpkg ../optlib/libopt.a
+ 
+ split.o: split.c
+ 	$(CC) $(ALL_CFLAGS) -DMKSPLITSCRIPT=\"$(dpkglibdir)/mksplit\" -c $<
Index: trunk/dports/sysutils/dpkg/files/patch-utils_Makefile.in
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-utils_Makefile.in	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-utils_Makefile.in	(revision 979)
@@ -0,0 +1,11 @@
+--- utils/Makefile.in	Tue Apr 24 04:05:58 2001
++++ utils/Makefile.in	Sat Oct  5 22:24:13 2002
+@@ -67,7 +67,7 @@
+ 	$(INSTALL_DATA) $(srcdir)/$(MD5_MANPAGES) $(DESTDIR)/$(man1dir)
+ 
+ start-stop-daemon: $(SSD_OBJECTS) ../lib/libdpkg.a
+-	$(CC) $(LDFLAGS) -o $@ $^ $(SSD_LIBS)
++	$(CC) $(LDFLAGS) -o $@ $^ $(SSD_LIBS) ../optlib/libopt.a
+ 
+ md5sum: $(MD5_OBJECTS) ../lib/libdpkg.a
+ 	$(CC) $(LDFLAGS) -o $@ $^ $(NLS_LIBS)
Index: trunk/dports/sysutils/dpkg/files/patch-utils_start-stop-daemon.c
===================================================================
--- trunk/dports/sysutils/dpkg/files/patch-utils_start-stop-daemon.c	(revision 979)
+++ trunk/dports/sysutils/dpkg/files/patch-utils_start-stop-daemon.c	(revision 979)
@@ -0,0 +1,132 @@
+--- utils/start-stop-daemon.c	Sun May 13 15:01:28 2001
++++ utils/start-stop-daemon.c	Sat Oct  5 22:22:21 2002
+@@ -30,6 +30,8 @@
+ #  define OSsunos
+ #elif defined(OPENBSD)
+ #  define OSOpenBSD
++#elif defined(__APPLE__)
++#  define OSDarwin
+ #else
+ #  error Unknown architecture - cannot build start-stop-daemon
+ #endif
+@@ -41,7 +43,7 @@
+ #  include <ps.h>
+ #endif
+ 
+-#if defined(OSOpenBSD)
++#if defined(OSOpenBSD) || defined(OSDarwin)
+ #include <sys/param.h>
+ #include <sys/user.h>
+ #include <sys/proc.h>
+@@ -653,11 +655,12 @@
+ {
+ #if defined(OSLinux)
+ 	if (execname && !pid_is_exec(pid, &exec_stat))
++		return;
+ #elif defined(OSHURD)
+     /* I will try this to see if it works */
+ 	if (execname && !pid_is_cmd(pid, execname))
+-#endif
+ 		return;
++#endif
+ 	if (userspec && !pid_is_user(pid, user_id))
+ 		return;
+ 	if (cmdname && !pid_is_cmd(pid, cmdname))
+@@ -787,7 +790,7 @@
+ }
+  
+ int
+-pid_is_user(pid_t pid, int uid)
++pid_is_user(pid_t pid, uid_t uid)
+ {
+ 	kvm_t *kd;
+ 	int nentries;   /* Value not used */
+@@ -828,7 +831,6 @@
+ 	return (strcmp(name, pidexec) == 0) ? 1 : 0;
+ }
+ 
+-
+ static void
+ do_procinit(void)
+ {
+@@ -836,6 +838,80 @@
+ }
+ 
+ #endif /* OSOpenBSD */
++
++#if defined(OSDarwin)
++int
++pid_is_user(pid_t pid, uid_t uid)
++{
++	int mib[4];
++	size_t size;
++	struct kinfo_proc ki;
++
++	size = sizeof(ki);
++	mib[0] = CTL_KERN;
++	mib[1] = KERN_PROC;
++	mib[2] = KERN_PROC_PID;
++	mib[3] = pid;
++	if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
++		errx(1, "%s", "Failure calling sysctl");
++	return (uid == ki.kp_eproc.e_pcred.p_ruid);
++}
++
++static int
++pid_is_cmd(pid_t pid, const char *name)
++{
++	int mib[4];
++	size_t size;
++	struct kinfo_proc ki;
++
++	size = sizeof(ki);
++	mib[0] = CTL_KERN;
++	mib[1] = KERN_PROC;
++	mib[2] = KERN_PROC_PID;
++	mib[3] = pid;
++	if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
++		errx(1, "%s", "Failure calling sysctl");
++	return (!strncmp(name, ki.kp_proc.p_comm, MAXCOMLEN));
++}
++
++static void
++do_procinit(void)
++{
++	int mib[3];
++	size_t size;
++	int nprocs, ret, i;
++	struct kinfo_proc *procs = NULL, *newprocs;
++	
++	mib[0] = CTL_KERN;
++	mib[1] = KERN_PROC;
++	mib[2] = KERN_PROC_ALL;
++	ret = sysctl(mib, 3, NULL, &size, NULL, 0);
++	/* Allocate enough memory for entire process table */
++	do {
++		size += size / 10;
++		newprocs = realloc(procs, size);
++		if (newprocs == NULL) {
++			if (procs)
++				free(procs);
++			errx(1, "%s", "Could not reallocate memory");
++		}
++		procs = newprocs;
++		ret = sysctl(mib, 3, procs, &size, NULL, 0);
++	} while (ret >= 0 && errno == ENOMEM);
++
++	if (ret < 0)
++		errx(1, "%s", "Failure calling sysctl");
++
++	/* Verify size of proc structure */
++	if (size % sizeof(struct kinfo_proc) != 0)
++		errx(1, "%s", "proc size mismatch, userland out of sync with kernel");
++	nprocs = size / sizeof(struct kinfo_proc);
++	for (i = 0; i < nprocs; i++) {
++		check(procs[i].kp_proc.p_pid);
++	}
++}
++#endif
++
+ 
+ 
+ static void
