--- apt-0.6.46.4.orig/apt-pkg/contrib/md5.h
+++ apt-0.6.46.4/apt-pkg/contrib/md5.h
@@ -29,7 +29,11 @@
 
 #include <string>
 #include <algorithm>
+#ifdef __INTERIX
+#include <inttypes.h>
+#else
 #include <stdint.h>
+#endif
 
 using std::string;
 using std::min;
--- apt-0.6.46.4.orig/apt-pkg/contrib/sha256.cc
+++ apt-0.6.46.4/apt-pkg/contrib/sha256.cc
@@ -33,7 +33,11 @@
 #include <apt-pkg/strutl.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef __INTERIX
+#include <inttypes.h>
+#else
 #include <stdint.h>
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 #include <arpa/inet.h>
--- apt-0.6.46.4.orig/buildlib/apti18n.h.in
+++ apt-0.6.46.4/buildlib/apti18n.h.in
@@ -18,6 +18,8 @@
 #else
 // apt will not use any gettext
 # define setlocale(a, b)
+# define textdomain(a)
+# define bindtextdomain(a, b)
 # define _(x) x
 # define N_(x) x
 #endif
--- apt-0.6.46.4.orig/buildlib/environment.mak.in
+++ apt-0.6.46.4/buildlib/environment.mak.in
@@ -13,7 +13,13 @@
 LIBSTDCPP_VER = @LIBSTDCPP_VER@
 
 # Linker stuff
-PICFLAGS+= -fPIC -DPIC
+HOST_OS = @host_os@
+ifneq (,$(findstring interix,$(HOST_OS)))
+    # don't add -fPIC for interix
+    PICFLAGS+= -DPIC
+else
+    PICFLAGS+= -fPIC -DPIC
+endif
 LFLAGS+= @LDFLAGS@
 LEFLAGS+= 
 SOCKETLIBS:= @SOCKETLIBS@
@@ -66,7 +72,13 @@
    SONAME_MAGIC=-Wl,-soname -Wl,
    LFLAGS_SO=
 else
-   # Do not know how to create shared libraries here.
-   ONLYSTATICLIBS = yes
+   ifneq (,$(findstring interix,$(HOST_OS)))
+      # interix has shared libs, but ld only supports -h, not -soname
+      SONAME_MAGIC=-Wl,-h,
+      LFLAGS_SO=-Wl,--image-base,`expr $${RANDOM-$$$$} % 4096 / 2 \* 262144 + 1342177280` 
+   else
+      # Do not know how to create shared libraries here.
+      ONLYSTATICLIBS = yes
+   endif
 endif
 	
--- apt-0.6.46.4.orig/buildlib/inttypes.h.in
+++ apt-0.6.46.4/buildlib/inttypes.h.in
@@ -4,6 +4,13 @@
 
 #include <config.h>
 
+#undef int32_t
+#undef uint32_t
+#undef int16_t
+#undef uint16_t
+#undef int8_t
+#undef uint8_t
+
 /* Generate the fixed bit size types */
 #if SIZEOF_INT == 4
   typedef int int32_t;
--- apt-0.6.46.4.orig/buildlib/ostable
+++ apt-0.6.46.4/buildlib/ostable
@@ -11,6 +11,7 @@
 [^-]*-kfreebsd.*-gnu   kfreebsd
 [^-]*-knetbsd.*-gnu   knetbsd
 [^-]*-gnu[^-]*   hurd
+[^-]*-interix[^-]*   interix
 
 # These are samples. 
 hp-hpux[^-]*	    hp-ux
--- apt-0.6.46.4.orig/cmdline/apt-get.cc
+++ apt-0.6.46.4/cmdline/apt-get.cc
@@ -48,7 +48,13 @@
 
 #include <set>
 #include <locale.h>
+#ifdef __INTERIX
+extern "C" {
+#endif
 #include <langinfo.h>
+#ifdef __INTERIX
+}
+#endif
 #include <fstream>
 #include <termios.h>
 #include <sys/ioctl.h>
--- apt-0.6.46.4.orig/cmdline/makefile
+++ apt-0.6.46.4/cmdline/makefile
@@ -7,42 +7,42 @@
 
 # The apt-cache program
 PROGRAM=apt-cache
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-cache.cc
 include $(PROGRAM_H)
 
 # The apt-get program
 PROGRAM=apt-get
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-get.cc acqprogress.cc
 include $(PROGRAM_H)
 
 # The apt-config program
 PROGRAM=apt-config
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-config.cc
 include $(PROGRAM_H)
 
 # The apt-cdrom program
 PROGRAM=apt-cdrom
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-cdrom.cc 
 include $(PROGRAM_H)
 
 # The apt-sortpkgs program
 PROGRAM=apt-sortpkgs
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-sortpkgs.cc
 include $(PROGRAM_H)
 
 # The apt-extracttemplates program
 PROGRAM=apt-extracttemplates
-SLIBS = -lapt-pkg -lapt-inst
+SLIBS = -lapt-pkg -lapt-inst $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = apt-extracttemplates.cc 
 include $(PROGRAM_H)
--- apt-0.6.46.4.orig/configure.in
+++ apt-0.6.46.4/configure.in
@@ -163,13 +163,13 @@
 AC_SUBST(NEED_SOCKLEN_T_DEFINE)
 
 dnl HP-UX needs -d_XOPEN_SOURCE_EXTENDED for h_errno
-AC_MSG_CHECKING(for h_errno)
-AC_EGREP_HEADER(h_errno, netdb.h, [AC_MSG_RESULT(normal)],
-   [CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED"
-    AC_EGREP_HEADER(h_errno, netdb.h, 
-       [AC_MSG_RESULT(needs _XOPEN_SOURCE_EXTENDED)],
-       [AC_MSG_ERROR("not found.")])
-   ])
+dnl AC_MSG_CHECKING(for h_errno)
+dnl AC_EGREP_HEADER(h_errno, netdb.h, [AC_MSG_RESULT(normal)],
+dnl    [CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED"
+dnl     AC_EGREP_HEADER(h_errno, netdb.h, 
+dnl        [AC_MSG_RESULT(needs _XOPEN_SOURCE_EXTENDED)],
+dnl        [AC_MSG_ERROR("not found.")])
+dnl    ])
 
 dnl Check for debiandoc
 AC_PATH_PROG(DEBIANDOC_HTML,debiandoc2html)
--- apt-0.6.46.4.orig/debian/changelog
+++ apt-0.6.46.4/debian/changelog
@@ -1,3 +1,10 @@
+apt (0.6.46.4-0.1+interix.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * patches for interix-i386
+
+ -- Martin Koeppe <mkoeppe@gmx.de>  Sat, 31 Mar 2007 14:54:23 +0200
+
 apt (0.6.46.4-0.1) unstable; urgency=emergency
 
   * NMU
--- apt-0.6.46.4.orig/debian/control
+++ apt-0.6.46.4/debian/control
@@ -4,7 +4,7 @@
 Maintainer: APT Development Team <deity@lists.debian.org>
 Uploaders: Jason Gunthorpe <jgg@debian.org>, Adam Heath <doogie@debian.org>, Matt Zimmerman <mdz@debian.org>, Michael Vogt <mvo@debian.org>
 Standards-Version: 3.6.2.2
-Build-Depends: debhelper (>= 5.0), libdb4.4-dev, gettext (>= 0.12)
+Build-Depends: debhelper (>= 5.0), libdb4.5-dev, gettext (>= 0.12)
 Build-Depends-Indep: debiandoc-sgml, docbook-utils (>= 0.6.12-1)
 
 Package: apt
--- apt-0.6.46.4.orig/debian/rules
+++ apt-0.6.46.4/debian/rules
@@ -33,6 +33,15 @@
   export CXXFLAGS = -O2 -g -Wall
 endif
 
+
+ifeq ($(DEB_HOST_ARCH_OS),interix)
+  CC = gcc-3.4
+  CXX = g++-3.4
+  CPPFLAGS = -D_ALL_SOURCE
+  confflags += CC="$(CC)" CXX="$(CXX)" CPPFLAGS="$(CPPFLAGS)"
+endif
+
+
 # Default rule
 build:
 
@@ -114,7 +123,7 @@
 
 build/build-stamp: build/configure-stamp
 	# Add here commands to compile the package.
-	$(MAKE) binary
+	$(MAKE) NOISY=1 binary
 	touch $@
 
 build/build-doc-stamp: build/configure-stamp
--- apt-0.6.46.4.orig/ftparchive/cachedb.cc
+++ apt-0.6.46.4/ftparchive/cachedb.cc
@@ -25,6 +25,10 @@
 #include <apt-pkg/configuration.h>
     
 #include <netinet/in.h>       // htonl, etc
+#ifdef __INTERIX
+#include <arpa/inet.h>       // htonl, etc
+#include "memrchr.h"
+#endif
 									/*}}}*/
 
 // CacheDB::ReadyDB - Ready the DB2					/*{{{*/
--- apt-0.6.46.4.orig/ftparchive/makefile
+++ apt-0.6.46.4/ftparchive/makefile
@@ -8,10 +8,10 @@
 # The apt-ftparchive program
 ifdef BDBLIB
 PROGRAM=apt-ftparchive
-SLIBS = -lapt-pkg -lapt-inst $(BDBLIB)
+SLIBS = -lapt-pkg -lapt-inst $(BDBLIB) $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile apt-inst/makefile
 SOURCE = apt-ftparchive.cc cachedb.cc writer.cc contents.cc override.cc \
-         multicompress.cc
+         multicompress.cc memrchr.cc
 include $(PROGRAM_H)
 else
 PROGRAM=apt-ftparchive
--- apt-0.6.46.4.orig/ftparchive/memrchr.cc
+++ apt-0.6.46.4/ftparchive/memrchr.cc
@@ -0,0 +1,194 @@
+/* memrchr -- find the last occurrence of a byte in a memory block
+
+   Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2005,
+   2006, 2007 Free Software Foundation, Inc.
+
+   Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
+   with help from Dan Sahlin (dan@sics.se) and
+   commentary by Jim Blandy (jimb@ai.mit.edu);
+   adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+   and implemented by Roland McGrath (roland@ai.mit.edu).
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+extern "C" {
+
+#if defined _LIBC
+# include <memcopy.h>
+#else
+# include <config.h>
+# define reg_char char
+#endif
+
+#include <string.h>
+#include <limits.h>
+
+#undef __memrchr
+#undef memrchr
+
+#ifndef weak_alias
+# define __memrchr memrchr
+#endif
+
+/* Search no more than N bytes of S for C.  */
+void *
+__memrchr (void const *s, int c_in, size_t n)
+{
+  const unsigned char *char_ptr;
+  const unsigned long int *longword_ptr;
+  unsigned long int longword, magic_bits, charmask;
+  unsigned reg_char c;
+  int i;
+
+  c = (unsigned char) c_in;
+
+  /* Handle the last few characters by reading one character at a time.
+     Do this until CHAR_PTR is aligned on a longword boundary.  */
+  for (char_ptr = (const unsigned char *) s + n;
+       n > 0 && (size_t) char_ptr % sizeof longword != 0;
+       --n)
+    if (*--char_ptr == c)
+      return (void *) char_ptr;
+
+  /* All these elucidatory comments refer to 4-byte longwords,
+     but the theory applies equally well to any size longwords.  */
+
+  longword_ptr = (const unsigned long int *) char_ptr;
+
+  /* Bits 31, 24, 16, and 8 of this number are zero.  Call these bits
+     the "holes."  Note that there is a hole just to the left of
+     each byte, with an extra at the end:
+
+     bits:  01111110 11111110 11111110 11111111
+     bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
+
+     The 1-bits make sure that carries propagate to the next 0-bit.
+     The 0-bits provide holes for carries to fall into.  */
+
+  /* Set MAGIC_BITS to be this pattern of 1 and 0 bits.
+     Set CHARMASK to be a longword, each of whose bytes is C.  */
+
+  magic_bits = 0xfefefefe;
+  charmask = c | (c << 8);
+  charmask |= charmask << 16;
+#if 0xffffffffU < ULONG_MAX
+  magic_bits |= magic_bits << 32;
+  charmask |= charmask << 32;
+  if (8 < sizeof longword)
+    for (i = 64; i < sizeof longword * 8; i *= 2)
+      {
+	magic_bits |= magic_bits << i;
+	charmask |= charmask << i;
+      }
+#endif
+  magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1);
+
+  /* Instead of the traditional loop which tests each character,
+     we will test a longword at a time.  The tricky part is testing
+     if *any of the four* bytes in the longword in question are zero.  */
+  while (n >= sizeof longword)
+    {
+      /* We tentatively exit the loop if adding MAGIC_BITS to
+	 LONGWORD fails to change any of the hole bits of LONGWORD.
+
+	 1) Is this safe?  Will it catch all the zero bytes?
+	 Suppose there is a byte with all zeros.  Any carry bits
+	 propagating from its left will fall into the hole at its
+	 least significant bit and stop.  Since there will be no
+	 carry from its most significant bit, the LSB of the
+	 byte to the left will be unchanged, and the zero will be
+	 detected.
+
+	 2) Is this worthwhile?  Will it ignore everything except
+	 zero bytes?  Suppose every byte of LONGWORD has a bit set
+	 somewhere.  There will be a carry into bit 8.  If bit 8
+	 is set, this will carry into bit 16.  If bit 8 is clear,
+	 one of bits 9-15 must be set, so there will be a carry
+	 into bit 16.  Similarly, there will be a carry into bit
+	 24.  If one of bits 24-30 is set, there will be a carry
+	 into bit 31, so all of the hole bits will be changed.
+
+	 The one misfire occurs when bits 24-30 are clear and bit
+	 31 is set; in this case, the hole at bit 31 is not
+	 changed.  If we had access to the processor carry flag,
+	 we could close this loophole by putting the fourth hole
+	 at bit 32!
+
+	 So it ignores everything except 128's, when they're aligned
+	 properly.
+
+	 3) But wait!  Aren't we looking for C, not zero?
+	 Good point.  So what we do is XOR LONGWORD with a longword,
+	 each of whose bytes is C.  This turns each byte that is C
+	 into a zero.  */
+
+      longword = *--longword_ptr ^ charmask;
+
+      /* Add MAGIC_BITS to LONGWORD.  */
+      if ((((longword + magic_bits)
+
+	    /* Set those bits that were unchanged by the addition.  */
+	    ^ ~longword)
+
+	   /* Look at only the hole bits.  If any of the hole bits
+	      are unchanged, most likely one of the bytes was a
+	      zero.  */
+	   & ~magic_bits) != 0)
+	{
+	  /* Which of the bytes was C?  If none of them were, it was
+	     a misfire; continue the search.  */
+
+	  const unsigned char *cp = (const unsigned char *) longword_ptr;
+
+	  if (8 < sizeof longword)
+	    for (i = sizeof longword - 1; 8 <= i; i--)
+	      if (cp[i] == c)
+		return (void *) &cp[i];
+	  if (7 < sizeof longword && cp[7] == c)
+	    return (void *) &cp[7];
+	  if (6 < sizeof longword && cp[6] == c)
+	    return (void *) &cp[6];
+	  if (5 < sizeof longword && cp[5] == c)
+	    return (void *) &cp[5];
+	  if (4 < sizeof longword && cp[4] == c)
+	    return (void *) &cp[4];
+	  if (cp[3] == c)
+	    return (void *) &cp[3];
+	  if (cp[2] == c)
+	    return (void *) &cp[2];
+	  if (cp[1] == c)
+	    return (void *) &cp[1];
+	  if (cp[0] == c)
+	    return (void *) cp;
+	}
+
+      n -= sizeof longword;
+    }
+
+  char_ptr = (const unsigned char *) longword_ptr;
+
+  while (n-- > 0)
+    {
+      if (*--char_ptr == c)
+	return (void *) char_ptr;
+    }
+
+  return 0;
+}
+#ifdef weak_alias
+weak_alias (__memrchr, memrchr)
+#endif
+
+}
--- apt-0.6.46.4.orig/ftparchive/memrchr.h
+++ apt-0.6.46.4/ftparchive/memrchr.h
@@ -0,0 +1,14 @@
+#ifndef _MEMRCHR_H_
+#define _MEMRCHR_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void * memrchr (void const *s, int c_in, size_t n);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- apt-0.6.46.4.orig/methods/connect.cc
+++ apt-0.6.46.4/methods/connect.cc
@@ -96,7 +96,11 @@
 
    // Check the socket for an error condition
    unsigned int Err;
+#ifndef __INTERIX
    unsigned int Len = sizeof(Err);
+#else
+   int Len = sizeof(Err);
+#endif
    if (getsockopt(Fd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
       return _error->Errno("getsockopt",_("Failed"));
    
--- apt-0.6.46.4.orig/methods/ftp.cc
+++ apt-0.6.46.4/methods/ftp.cc
@@ -697,7 +697,11 @@
       if (WaitFd(DataFd,true,TimeOut) == false)
 	 return _error->Error(_("Could not connect data socket, connection timed out"));
       unsigned int Err;
+#ifndef __INTERIX
       unsigned int Len = sizeof(Err);
+#else
+      int Len = sizeof(Err);
+#endif
       if (getsockopt(DataFd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
 	 return _error->Errno("getsockopt",_("Failed"));
       if (Err != 0)
@@ -742,7 +746,11 @@
    
    // Determine the name to send to the remote
    struct sockaddr_storage Addr;
+#ifndef __INTERIX
    socklen_t AddrLen = sizeof(Addr);
+#else
+   int AddrLen = sizeof(Addr);
+#endif
    if (getsockname(DataListenFd,(sockaddr *)&Addr,&AddrLen) < 0)
       return _error->Errno("getsockname",_("Could not determine the socket's name"));
 
@@ -819,7 +827,11 @@
       
    // Accept the connection
    struct sockaddr_in Addr;
+#ifndef __INTERIX
    socklen_t Len = sizeof(Addr);
+#else
+   int Len = sizeof(Addr);
+#endif
    DataFd = accept(DataListenFd,(struct sockaddr *)&Addr,&Len);
    if (DataFd < 0)
       return _error->Errno("accept",_("Unable to accept connection"));
--- apt-0.6.46.4.orig/methods/ftp.h
+++ apt-0.6.46.4/methods/ftp.h
@@ -26,11 +26,19 @@
    
    // Generic Peer Address
    struct sockaddr_storage PeerAddr;
+#ifndef __INTERIX
    socklen_t PeerAddrLen;
+#else
+   int PeerAddrLen;
+#endif
    
    // Generic Server Address (us)
    struct sockaddr_storage ServerAddr;
+#ifndef __INTERIX
    socklen_t ServerAddrLen;
+#else
+   int ServerAddrLen;
+#endif
    
    // Private helper functions
    bool ReadLine(string &Text);      
--- apt-0.6.46.4.orig/methods/makefile
+++ apt-0.6.46.4/methods/makefile
@@ -12,63 +12,63 @@
 
 # The file method
 PROGRAM=file
-SLIBS = -lapt-pkg 
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = file.cc
 include $(PROGRAM_H)
 
 # The copy method
 PROGRAM=copy
-SLIBS = -lapt-pkg 
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = copy.cc
 include $(PROGRAM_H)
 
 # The gzip method
 PROGRAM=gzip
-SLIBS = -lapt-pkg 
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = gzip.cc
 include $(PROGRAM_H)
 
 # The gpgv method
 PROGRAM=gpgv
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = gpgv.cc
 include $(PROGRAM_H)
 
 # The cdrom method
 PROGRAM=cdrom
-SLIBS = -lapt-pkg 
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = cdrom.cc
 include $(PROGRAM_H)
 
 # The http method
 PROGRAM=http
-SLIBS = -lapt-pkg $(SOCKETLIBS)
+SLIBS = -lapt-pkg $(SOCKETLIBS) $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = http.cc rfc2553emu.cc connect.cc
 include $(PROGRAM_H)
 
 # The ftp method
 PROGRAM=ftp
-SLIBS = -lapt-pkg $(SOCKETLIBS)
+SLIBS = -lapt-pkg $(SOCKETLIBS) $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = ftp.cc rfc2553emu.cc connect.cc
 include $(PROGRAM_H)
 
 # The rred method
 PROGRAM=rred
-SLIBS = -lapt-pkg $(SOCKETLIBS)
+SLIBS = -lapt-pkg $(SOCKETLIBS) $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = rred.cc
 include $(PROGRAM_H)
 
 # The rsh method
 PROGRAM=rsh
-SLIBS = -lapt-pkg
+SLIBS = -lapt-pkg $(INTLLIBS)
 LIB_MAKES = apt-pkg/makefile
 SOURCE = rsh.cc
 include $(PROGRAM_H)

