diff -Nur scratchbox-1.0.1-orig/Makefile scratchbox-1.0.1/Makefile
--- scratchbox-1.0.1-orig/Makefile	2005-01-27 12:37:04.000000000 +0200
+++ scratchbox-1.0.1/Makefile	2005-06-17 14:22:15.000000000 +0300
@@ -5,6 +5,7 @@
 
 VERSION		= $(shell head -n1 /scratchbox/etc/scratchbox-version)
 ARCH		= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
+ARCH		= $(shell uname -m)
 
 BUILD_TARGETS	= base utils host-gcc tools doc_tools debian_tools post-install docs
 PACKAGE_TARGETS	= tarball deb rpm
@@ -28,7 +29,7 @@
 tools: host-gcc utils
 	make -C meta/scratchbox install
 
-doc_tools: host-gcc utils
+doc_tools: utils
 	make -C meta/doc_tools install
 
 debian_tools: host-gcc utils
@@ -66,7 +67,7 @@
 clean:
 	find . -type d -maxdepth 2 -mindepth 2 ! -name CVS -exec make -C {} clean \;
 	fakeroot debian/rules clean
-	rm -rf rpm/$(ARCH)
+	rm -rf rpm/$(UNAMEM)
 	for PACKAGE in $(PACKAGE_LIST); do \
 		rm -f rpm/$$PACKAGE.spec; \
 	done
diff -Nur scratchbox-1.0.1-orig/build scratchbox-1.0.1/build
--- scratchbox-1.0.1-orig/build	2005-01-13 19:44:45.000000000 +0200
+++ scratchbox-1.0.1/build	2005-06-17 14:22:15.000000000 +0300
@@ -190,7 +190,7 @@
 	if [ "$SB_BUILD_OPT_BUILD_HOST_COMP" = "yes" ] ; then
 		if [ "$SB_BUILD_OPT_CLEAN_COMPILERS" = "yes" ] ; then
 			log "Cleaning host-gcc source tree and installation"
-			make -C compilers/host_gcc $SB_BUILD_OPT_MAKEOPTS clean-installation
+			make -C compilers/host_gcc $SB_BUILD_OPT_MAKEOPTS clean
 		fi
 		log "Building host-gcc"
 		$TIME make $SB_BUILD_OPT_MAKEOPTS host-gcc
diff -Nur scratchbox-1.0.1-orig/compilers/host_gcc/Makefile scratchbox-1.0.1/compilers/host_gcc/Makefile
--- scratchbox-1.0.1-orig/compilers/host_gcc/Makefile	2005-06-02 12:12:21.000000000 +0300
+++ scratchbox-1.0.1/compilers/host_gcc/Makefile	2005-06-17 14:58:51.000000000 +0300
@@ -3,13 +3,13 @@
 CATEGORIES = compilers
 
 GCCNAME    = gcc-3.3
-GCCVERSION = 3.3.5
+GCCVERSION = 3.3.6
 GCCPATCH   = 5
 GCCSRC     = $(WORKDIR)/$(GCCNAME)-$(GCCVERSION)
 
 BINNAME    = binutils
 BINVERSION = 2.15
-BINPATCH   = 5
+BINPATCH   = 6
 BINSRC     = $(WORKDIR)/$(BINNAME)-$(BINVERSION)
 
 DISTFILES  = $(GCCNAME)_$(GCCVERSION).orig.tar.gz \
@@ -19,10 +19,10 @@
              $(BINNAME)_$(BINVERSION)-$(BINPATCH).diff.gz \
              $(BINNAME)_$(BINVERSION)-$(BINPATCH).dsc
 
-PATCHFILES = gcc.patch binutils.patch
+PATCHFILES = gcc-x86_64.patch binutils.patch
 
 LIBDEPS =
-#DEPENDS = tools/scratchbox-base
+DEPENDS = tools/scratchbox-base
 
 DESCRIPTION = host-gcc
 
@@ -33,6 +33,7 @@
 CATEGORY_DIR = $(SBOX_DIR)/compilers/host-gcc
 
 ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
+UNAMEM = $(shell uname -m)
 
 ALIEN_DIR = $(SBOX_DIR)/tools/alien_bin
 
@@ -80,9 +81,9 @@
 
 	cp -ar $(GCCSRC)/debian/{gcc,g++,cpp}-3.3$(prefix)/lib $(prefix)/
 
-	mv $(prefix)/lib/gcc-lib/i486-linux/$(GCCVERSION)/cc1      $(ALIEN_DIR)/
-	mv $(prefix)/lib/gcc-lib/i486-linux/$(GCCVERSION)/cc1plus  $(ALIEN_DIR)/
-	mv $(prefix)/lib/gcc-lib/i486-linux/$(GCCVERSION)/collect2 $(ALIEN_DIR)/
+	mv $(prefix)/lib/gcc-lib/x86_64-linux/$(GCCVERSION)/cc1      $(ALIEN_DIR)/
+	mv $(prefix)/lib/gcc-lib/x86_64-linux/$(GCCVERSION)/cc1plus  $(ALIEN_DIR)/
+	mv $(prefix)/lib/gcc-lib/x86_64-linux/$(GCCVERSION)/collect2 $(ALIEN_DIR)/
 
 	ln -sf gcc $(ALIEN_DIR)/cc
 	ln -sf gcc $(ALIEN_DIR)/host-gcc
@@ -98,11 +99,11 @@
 
 	for i in cc1 cc1plus collect2 ; do \
 		ln -sf $(SBOX_DIR)/tools/bin/sb_tool_wrapper \
-			$(prefix)/lib/gcc-lib/i486-linux/$(GCCVERSION)/$$i ; \
+			$(prefix)/lib/gcc-lib/x86_64-linux/$(GCCVERSION)/$$i ; \
 	done
 
 	cp files/host-gcc.specs $(prefix)/
-	echo > $(prefix)/compiler-name "host-gcc:$(prefix):$(ARCH):linux:glibc:$(ARCH)"
+	echo > $(prefix)/compiler-name "host-gcc:$(prefix):$(UNAMEM):linux:glibc:$(UNAMEM)"
 
 	$(MAKECOOKIE)
 
@@ -117,4 +118,3 @@
 	done
 
 	$(MAKECOOKIE)
-
diff -Nur scratchbox-1.0.1-orig/compilers/host_gcc/checksums scratchbox-1.0.1/compilers/host_gcc/checksums
--- scratchbox-1.0.1-orig/compilers/host_gcc/checksums	2005-01-12 13:48:17.000000000 +0200
+++ scratchbox-1.0.1/compilers/host_gcc/checksums	2005-06-17 15:02:13.000000000 +0300
@@ -1,8 +1,8 @@
-caff4d599d959027cc4919ffe354dba6  download/gcc-3.3_3.3.5.orig.tar.gz
-eb05b307a1c84283627d42b7fc8a1982  download/gcc-3.3_3.3.5-5.diff.gz
-88ce9f36da68b70a79ba46a417302094  download/gcc-3.3_3.3.5-5.dsc
+539984e4dde9141639c4ca6b90097d73  download/gcc-3.3_3.3.6.orig.tar.gz
+5ba4df5fd6929861329ae734b4fc110f  download/gcc-3.3_3.3.6-5.diff.gz
+e4c359f4685a94e2fda02e845b688565  download/gcc-3.3_3.3.6-5.dsc
 ea140e23ae50a61a79902aa67da5214e  download/binutils_2.15.orig.tar.gz
-055e74792e7118ddf33ae6b04d640818  download/binutils_2.15-5.diff.gz
-b20cf60b07384592ed5fa71314c6d2d9  download/binutils_2.15-5.dsc
-21951b7f45c64627b421cd5b8019b140  download/gcc.patch
+d7d3502acef87b3210e2db9739723972  download/binutils_2.15-6.diff.gz
+e25d40c0a57ad00fcaf947ea72ed6412  download/binutils_2.15-6.dsc
+1e0874bc6c8184f9c29f64ee3a87499c  download/gcc-x86_64.patch
 401b86903d331a330144f90b5c0aaacd  download/binutils.patch
diff -Nur scratchbox-1.0.1-orig/compilers/host_gcc/files/gcc-x86_64.patch scratchbox-1.0.1/compilers/host_gcc/files/gcc-x86_64.patch
--- scratchbox-1.0.1-orig/compilers/host_gcc/files/gcc-x86_64.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/compilers/host_gcc/files/gcc-x86_64.patch	2005-06-17 14:19:37.000000000 +0300
@@ -0,0 +1,401 @@
+--- main.d/gcc-3.3-3.3.6/debian/rules.defs	2005-06-02 23:33:02.000000000 +0300
++++ main.d/gcc-3.3-3.3.6/debian/rules.defs	2005-06-02 23:34:31.000000000 +0300
+@@ -121,358 +121,35 @@
+ # multiarch --------------------
+ with_multiarch := no
+ 
+-# C --------------------
+-enabled_languages := c
+-# Build all packages needed for C development
+-ifeq ($(with_base_only),yes)
+-  with_cdev := no
+-else
+-  ifeq ($(with_dev),yes)
+-    with_cdev := yes
+-  else
+-    with_cdev := no
+-  endif
+-endif
+-
+-# C++ --------------------
+-ifeq ($(with_base_only),yes)
+-  with_cxx := no
+-else
+-  with_cxx := yes
+-endif
+-no_cxx_archs := avr
+-ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(no_cxx_archs)))
+-  with_cxx := disabled for architecture $(DEB_TARGET_ARCH)
+-endif
+-ifeq (c++, $(findstring c++,$(WITHOUT_LANG)))
+-  with_cxx := disabled by environment
+-endif
+-# Build all packages needed for C++ development
+-ifeq ($(with_cxx)-$(with_dev),yes-yes)
+-  with_cxxdev := yes
+-else
+-  with_cxxdev := no
+-endif
+-
+-ifeq ($(with_cxx),yes)
+-  enabled_languages += c++
+-endif
+-
+-ifeq ($(with_cxx),yes)
+-  with_libcxx := yes
+-else
+-  with_libcxx := no
+-endif
+-
+-# debugging versions of libstdc++
+-ifeq ($(with_cxxdev),yes)
+-  with_debug := yes
+-else
+-  with_debug := no
+-endif
+-#debug_no_archs := powerpc
+-#ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(debug_no_archs)))
+-#    with_debug := disabled for architecure $(DEB_TARGET_ARCH)
+-#endif
+-
+-# Java --------------------
+-# java converted for V3 C++ ABI for some archs
+-ifeq ($(with_base_only),yes)
+-  with_java := no
+-else
+-  with_java := yes
+-endif
+-
+-java_no_archs := hurd-i386 mips mipsel freebsd-i386
+-ifneq ($(DEB_TARGET_ARCH),i386)
+-  ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(java_no_archs)))
+-    with_java := disabled for architecure $(DEB_TARGET_ARCH)
+-  endif
+-endif
+-ifdef DEB_CROSS
+-  with_java := disabled for cross compiler package
+-endif
+-ifeq (java, $(findstring java,$(WITHOUT_LANG)))
+-  with_java := disabled by environment
+-endif
+-ifneq ($(with_cxx),yes)
+-  with_java := disabled, because C++ disabled: $(with_cxx)
+-endif
+-
+-# Build all packages needed for Java development (gcj, libgcj-dev)
+-ifeq ($(with_java)-$(with_dev),yes-yes)
+-  with_javadev := yes
+-else
+-  with_javadev := no
+-endif
+-ifeq ($(with_java),yes)
+-  with_libgcj := yes
+-else
+-  with_libgcj := no
+-endif
+-
+-ifeq ($(with_java),yes)
+-  enabled_languages += java
+-endif
+-
+-# fastjar -------------------
+-ifeq ($(with_common_pkgs),yes)
+-  ifdef DEB_CROSS
+-    with_fastjar := disabled for cross compiler package
+-  else
+-  with_fastjar := yes
+-  endif
+-else
+-  with_fastjar := no
+-endif
+-
+-with_fastjar := built from gcc-3.4 source
+-
+-# libffi -------------------
+-ifeq ($(with_common_libs),yes)
+-  with_libffi := yes
+-  no_ffi_archs := hurd-i386 freebsd-i386
+-  ifneq ($(with_java),yes)
+-    ifneq ($(DEB_TARGET_ARCH),i386)
+-    ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(no_ffi_archs)))
+-      with_libffi := disabled for architecure $(DEB_TARGET_ARCH)
+-    endif
+-    endif
+-  endif
+-  ifdef DEB_CROSS
+-    with_libffi := disabled for cross compiler package
+-  endif
+-endif
+-
+-# Fortran --------------------
+-ifeq ($(with_base_only),yes)
+-  with_fortran := no
+-else
+-  with_fortran := yes
+-endif
+-
+-ifdef DEB_CROSS
+-  with_fortran := disabled for cross compiler package
+-endif
+-ifeq (f77, $(findstring f77,$(WITHOUT_LANG)))
+-  with_fortran := disabled by environment
+-endif
+-
+-# Build all packages needed for Fortran development
+-ifeq ($(with_fortran)-$(with_dev),yes-yes)
+-  with_fdev := yes
+-else
+-  with_fdev := no
+-endif
+-
+-ifeq ($(with_common_libs)-$(with_fortran),yes-yes)
+-  with_libg2c := yes
+-else
+-  with_libg2c := no
+-  # ABI changes, keep the package for mipsel
+-  ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),mipsel))
+-    with_libg2c := yes
+-  endif
+-endif
+-
+-ifeq ($(with_fortran),yes)
+-  enabled_languages += f77
+-endif
+-
+-# protoize --------------------
+-ifeq ($(with_common_pkgs),yes)
+-  with_proto := yes
+-  ifdef DEB_CROSS
+-    with_proto := disabled for cross compiler package
+-  endif
+-else
+-  with_proto := no
+-endif
+-#ifeq ($(with_proto),yes)
+-#  enabled_languages += proto
+-#endif
+-
+-# fixincludes --------------------
+-ifeq ($(with_common_pkgs),yes)
+-  with_fixincl := yes
+-  ifdef DEB_CROSS
+-    with_fixincl := disabled for cross compiler package
+-  endif
+-else
+-  with_fixincl := no
+-endif
+-
+-# Pascal --------------------
+-with_pascal := yes
+-ifneq ($(with_dev),yes)
+-  with_pascal := no
+-endif
+-
+-#pascal_no_archs := netbsd-i386 arm
+-ifneq ($(DEB_TARGET_ARCH),i386)
+-  ifeq ($(DEB_TARGET_ARCH),$(findstring $(DEB_TARGET_ARCH),$(pascal_no_archs)))
+-    with_pascal := disabled for architecture $(DEB_TARGET_ARCH)
+-  endif
+-endif
+-with_gpidump := yes
+-#ifeq ($(DEB_TARGET_ARCH),$(findstring $(DEB_TARGET_ARCH),s390 powerpc))
+-#  with_gpidump := disabled for architecture $(DEB_TARGET_ARCH)
+-#endif
+-pascal_version := 20030830
+-ifdef DEB_CROSS
+-  with_pascal := disabled for cross compiler package
+-endif
+-ifeq (pascal, $(findstring pascal,$(WITHOUT_LANG)))
+-  with_pascal := disabled by environment
+-endif
+-ifeq ($(with_pascal),yes)
+-  enabled_languages += pascal
+-endif
+-
+-# ObjC --------------------
+-ifeq ($(with_base_only),yes)
+-  with_objc := no
+-else
+-  with_objc := yes
+-endif
+-# the ObjC runtime with garbage collection enabled needs the Boehm GC
+-with_objc_gc := yes
+-
+-# disable ObjC garbage collection library (needs libgc)
+-libgc_no_archs := avr freebsd-i386
+-ifneq ($(DEB_TARGET_ARCH),i386)
+-  ifeq ($(DEB_TARGET_ARCH),$(findstring $(DEB_TARGET_ARCH),$(libgc_no_archs)))
+-    with_objc_gc := disabled for architecture $(DEB_TARGET_ARCH)
+-  endif
+-endif
+-ifdef DEB_CROSS
+-  with_objc := disabled for cross compiler package
+-endif
+-ifeq (objc, $(findstring objc,$(WITHOUT_LANG)))
+-  with_objc := disabled by environment
+-endif
+-
+-ifneq ($(with_objc),yes)
+-  with_objc_gc := $(with_objc)
+-endif
+-
+-# Build all packages needed for Objective-C development
+-ifeq ($(with_objc)-$(with_dev),yes-yes)
+-  with_objcdev := yes
+-else
+-  with_objcdev := no
+-endif
+-ifeq ($(with_common_libs)-$(with_objc),yes-yes)
+-  with_libobjc := yes
+-else
+-  with_libobjc := no
+-endif
+-
+-ifeq ($(with_objc),yes)
+-  enabled_languages += objc
+-endif
+-
+-# Ada --------------------
+-with_ada := yes
+-ifneq ($(with_dev),yes)
+-  with_ada := no
+-endif
+-
+-with_libgnat := yes
+-ada_no_archs := arm hurd-i386 m68k freebsd-i386 netbsd-i386
+-ifneq ($(DEB_TARGET_ARCH),i386)
+-  ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(ada_no_archs)))
+-    with_ada := disabled for architecure $(DEB_TARGET_ARCH)
+-  endif
+-endif
+-ifeq (ada, $(findstring ada,$(WITHOUT_LANG)))
+-  with_ada := disabled by environment
+-endif
++enabled_languages := c c++
++with_cdev := yes
++with_cxx := yes
++with_cxxdev := yes
++with_libcxx := yes
++with_debug := no
++with_cxa_atexit := no
++with_java := no
++with_javadev := no
++with_libgcj := no
++with_fastjar := no
++with_libffi := no
++with_fortran := no
++with_fdev := no
++with_libg2c := no
++with_proto := no
++with_fixincl := no
++with_pascal := no
++with_gpidump := no
++with_objc := no
++with_objc_gc := no
++with_objcdev := no
++with_ada := no
+ with_libgnat := no
+-ifdef DEB_CROSS
+-  with_ada := disabled for cross compiler package
+-endif
+-
+-# needed for 3.4 on alpha
+-ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),xxxxx))
+-  with_ada_bootstrap_workaround := yes
+-endif
+-
+-ifeq ($(with_ada),yes)
+-  enabled_languages += ada
+-else
+-  with_libgnat := $(with_ada)
+-  with_libgnat := disabled
+-endif
+-
+-# treelang --------------------
+-ifeq ($(with_base_only),yes)
+-  with_treelang := no
+-else
+-  ifeq ($(with_dev),yes)
+-    with_treelang := yes
+-  else
+-    with_treelang := no
+-  endif
+-endif
+-tl_no_archs := powerpc
+-ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(tl_no_archs)))
+-    with_treelang := disabled for architecure $(DEB_TARGET_ARCH)
+-endif
+-ifdef DEB_CROSS
+-  with_treelang := disabled for cross compiler package
+-endif
+-ifeq (treelang, $(findstring treelang,$(WITHOUT_LANG)))
+-  with_treelang := disabled by environment
+-endif
+-
+-ifeq ($(with_treelang),yes)
+-  enabled_languages += treelang
+-endif
+-
+-# Shared libgcc --------------------
+-with_shared_libgcc := yes
+-
+-#ifeq ($(with_common_libs),yes)
+-#  with_libgcc := yes
+-#else
+-ifdef DEB_CROSS
+-  with_libgcc := yes
+-else
+-  libgcc_archs := hppa m68k netbsd-i386
+-  ifeq ($(DEB_TARGET_ARCH),i386)
+-    with_libgcc := no
+-    with_shared_libgcc := no
+-  else
+-    ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(libgcc_archs)))
+-      with_libgcc := yes
+-    else
+-      with_libgcc := no
+-      with_shared_libgcc := no
+-    endif
+-  endif
+-endif
+-#endif
+-
+-# run testsuite --------------------
+-with_check := yes
+-# If you don't want to run the gcc testsuite, set `with_check' to `no'
+-#with_check := disabled by hand
+-ifeq ($(with_base_only),yes)
+-  with_check := no
+-endif
+-ifdef DEB_CROSS
+-  with_check := disabled for cross compiler package
+-endif
+-check_no_archs := hurd-i386 m68k
+-ifneq ($(DEB_TARGET_ARCH),i386)
+-  ifeq ($(DEB_TARGET_ARCH), $(findstring $(DEB_TARGET_ARCH),$(check_no_archs)))
+-    with_check :=disabled for $(DEB_TARGET_ARCH)
+-  endif
+-endif
+-ifneq ($(WITHOUT_CHECK),)
+-  with_check := disabled by environment
+-endif
++with_ada_bootstrap_workaround := no
++with_treelang := no
++with_libgcc := no
++with_shared_libgcc := no
++with_check := no
+ 
+ # powerpc nof libraries --------------------
+ with_libnof := no
+--- /main.d/gcc-3.3-3.3.6/debian/rules2	2005-06-02 23:33:02.000000000 +0300
++++ main.d/gcc-3.3-3.3.6/debian/rules2	2005-06-02 23:36:06.000000000 +0300
+@@ -981,6 +981,9 @@
+ 	ln -s $(libdir) $(d)/lib64
+ 	mkdir -p $(d)/usr/$(libdir)
+ 	ln -s $(libdir) $(d)/usr/lib64
++	# hack to make things compile, stupid PF hack
++	mkdir -p $(d)/$(PF)/lib
++	ln -s $(libdir) $(d)/$(PF)/lib64				
+ endif
+ 
+ 	: # Install everything
diff -Nur scratchbox-1.0.1-orig/compilers/host_gcc/files/host-gcc.specs scratchbox-1.0.1/compilers/host_gcc/files/host-gcc.specs
--- scratchbox-1.0.1-orig/compilers/host_gcc/files/host-gcc.specs	2005-01-12 09:16:45.000000000 +0200
+++ scratchbox-1.0.1/compilers/host_gcc/files/host-gcc.specs	2005-06-17 14:19:34.000000000 +0300
@@ -1,7 +1,7 @@
 %rename cpp old_cpp
 
 *cpp:
--isystem /host_usr/include -isystem /scratchbox/host_shared/include -isystem /scratchbox/host_shared/include/c++/3.3 -isystem /scratchbox/host_shared/include/c++/3.3/i486-linux %(old_cpp)
+-isystem /host_usr/include -isystem /scratchbox/host_shared/include -isystem /scratchbox/host_shared/include/c++/3.3 -isystem /scratchbox/host_shared/include/c++/3.3/x86_64-linux %(old_cpp)
 
 %rename link old_link
 
Binary files scratchbox-1.0.1-orig/debian/buildinfo.gz and scratchbox-1.0.1/debian/buildinfo.gz differ
diff -Nur scratchbox-1.0.1-orig/debian_tools/apt/Makefile scratchbox-1.0.1/debian_tools/apt/Makefile
--- scratchbox-1.0.1-orig/debian_tools/apt/Makefile	2005-01-31 22:52:49.000000000 +0200
+++ scratchbox-1.0.1/debian_tools/apt/Makefile	2005-06-17 15:08:29.000000000 +0300
@@ -3,7 +3,7 @@
 CATEGORIES = debian_tools
 DISTFILES = $(GARNAME)_$(GARVERSION).tar.gz
 
-PATCHFILES = sb.patch
+PATCHFILES =
 
 LIBDEPS =
 DEPENDS = debian_tools/dpkg
@@ -26,6 +26,10 @@
 
 include ../category.mk
 
+pre-patch:
+	patch -d $(WORKSRC) -p2 < files/sb.patch
+	$(MAKECOOKIE)
+
 build-apt:
 	$(MAKE) $(BUILD_ARGS) -C $(WORKSRC)/apt-pkg all 
 	$(MAKE) $(BUILD_ARGS) -C $(WORKSRC)/apt-inst all
diff -Nur scratchbox-1.0.1-orig/debian_tools/apt/checksums scratchbox-1.0.1/debian_tools/apt/checksums
--- scratchbox-1.0.1-orig/debian_tools/apt/checksums	2005-01-31 22:52:49.000000000 +0200
+++ scratchbox-1.0.1/debian_tools/apt/checksums	2005-06-17 15:08:34.000000000 +0300
@@ -1,2 +1 @@
 9fe62202d4f40b63463138a7e09018b4  download/apt_0.5.28.1.tar.gz
-95d7bba3a8500beaf7ab32d31138556b  download/sb.patch
diff -Nur scratchbox-1.0.1-orig/debian_tools/dpkg/Makefile scratchbox-1.0.1/debian_tools/dpkg/Makefile
--- scratchbox-1.0.1-orig/debian_tools/dpkg/Makefile	2005-01-31 12:12:53.000000000 +0200
+++ scratchbox-1.0.1/debian_tools/dpkg/Makefile	2005-06-17 14:24:06.000000000 +0300
@@ -2,7 +2,7 @@
 GARVERSION = 1.10.26
 CATEGORIES = debian_tools
 DISTFILES = $(GARNAME)_$(GARVERSION).tar.gz
-PATCHFILES = dpkg-sbox.patch
+PATCHFILES = 
 
 LIBDEPS =
 # DEPENDS = tools/perl
@@ -36,3 +36,6 @@
 
 	$(MAKECOOKIE)
 
+pre-patch:
+	patch -d $(WORKSRC) -p2 < files/dpkg-sbox.patch
+	$(MAKECOOKIE)
diff -Nur scratchbox-1.0.1-orig/debian_tools/dpkg/checksums scratchbox-1.0.1/debian_tools/dpkg/checksums
--- scratchbox-1.0.1-orig/debian_tools/dpkg/checksums	2005-01-31 22:19:42.000000000 +0200
+++ scratchbox-1.0.1/debian_tools/dpkg/checksums	2005-06-17 14:24:06.000000000 +0300
@@ -1,2 +1 @@
 76c7987cbaef738ebc8c101d5a46c3d6  download/dpkg_1.10.26.tar.gz
-e2bd834c1986f1007d1591dbcd9b544e  download/dpkg-sbox.patch
diff -Nur scratchbox-1.0.1-orig/doc_tools/html2text/Makefile scratchbox-1.0.1/doc_tools/html2text/Makefile
--- scratchbox-1.0.1-orig/doc_tools/html2text/Makefile	2004-11-10 19:03:53.000000000 +0200
+++ scratchbox-1.0.1/doc_tools/html2text/Makefile	2005-06-17 14:24:26.000000000 +0300
@@ -1,7 +1,7 @@
 GARNAME = html2text
 GARVERSION = 1.3.2a
 CATEGORIES = doc_tools
-DEB_PATCH = $(GARNAME)_$(GARVERSION)-1.diff.gz
+DEB_PATCH = $(GARNAME)_$(GARVERSION)-2.diff.gz
 DISTFILES = $(GARNAME)_$(GARVERSION).orig.tar.gz $(DEB_PATCH)
 NOEXTRACT = $(DEB_PATCH)
 
diff -Nur scratchbox-1.0.1-orig/doc_tools/html2text/checksums scratchbox-1.0.1/doc_tools/html2text/checksums
--- scratchbox-1.0.1-orig/doc_tools/html2text/checksums	2004-06-01 19:39:20.000000000 +0300
+++ scratchbox-1.0.1/doc_tools/html2text/checksums	2005-06-17 14:24:26.000000000 +0300
@@ -1,2 +1,2 @@
 6097fe07b948e142315749e6620c9cfc  download/html2text_1.3.2a.orig.tar.gz
-ad0aa49f2086eb4f5284c9d580f9f4c6  download/html2text_1.3.2a-1.diff.gz
+fb83aa9279dc7bf4b1d0ab4a4472fbe0  download/html2text_1.3.2a-2.diff.gz
Binary files scratchbox-1.0.1-orig/doc_tools/html2text/files/html2text_1.3.2a-2.diff.gz and scratchbox-1.0.1/doc_tools/html2text/files/html2text_1.3.2a-2.diff.gz differ
diff -Nur scratchbox-1.0.1-orig/meta/scratchbox/Makefile scratchbox-1.0.1/meta/scratchbox/Makefile
--- scratchbox-1.0.1-orig/meta/scratchbox/Makefile	2005-01-27 20:38:14.000000000 +0200
+++ scratchbox-1.0.1/meta/scratchbox/Makefile	2005-06-17 14:25:52.000000000 +0300
@@ -5,7 +5,6 @@
 # HAS TO BE THE FIRST ONE
 DEPENDS  = tools/scratchbox-base
 DEPENDS += tools/glibc
-
 DEPENDS += tools/scratchbox-utils
 DEPENDS += tools/dialog
 DEPENDS += tools/coreutils
diff -Nur scratchbox-1.0.1-orig/tools/bash/Makefile scratchbox-1.0.1/tools/bash/Makefile
--- scratchbox-1.0.1-orig/tools/bash/Makefile	2005-02-07 11:19:29.000000000 +0200
+++ scratchbox-1.0.1/tools/bash/Makefile	2005-06-17 14:25:59.000000000 +0300
@@ -31,9 +31,10 @@
 	zcat $(WORKDIR)/$(GARNAME)_$(GARVERSION)-$(PATCHLEVEL).diff.gz | patch -d $(WORKSRC) -p1
 
 	cd $(WORKSRC); \
-	for i in debian/patches/bash205b-00?.dpatch; do \
+	for i in debian/patches/bash205b-0*.dpatch; do \
 		sh $$i -patch; \
 	done
+
 	$(MAKECOOKIE)
 
 post-install:
diff -Nur scratchbox-1.0.1-orig/tools/distcc/Makefile scratchbox-1.0.1/tools/distcc/Makefile
--- scratchbox-1.0.1-orig/tools/distcc/Makefile	2005-01-31 12:12:53.000000000 +0200
+++ scratchbox-1.0.1/tools/distcc/Makefile	2005-06-17 14:26:30.000000000 +0300
@@ -1,5 +1,6 @@
 GARNAME = distcc
-GARVERSION = 2.18.1
+GARVERSION = 2.18.3
+#GARVERSION = 2.18.1
 CATEGORIES = tools
 DISTFILES = $(GARNAME)_$(GARVERSION).orig.tar.gz
 
diff -Nur scratchbox-1.0.1-orig/tools/distcc/checksums scratchbox-1.0.1/tools/distcc/checksums
--- scratchbox-1.0.1-orig/tools/distcc/checksums	2005-01-31 12:12:53.000000000 +0200
+++ scratchbox-1.0.1/tools/distcc/checksums	2005-06-17 14:26:30.000000000 +0300
@@ -1,3 +1 @@
-357734b226f27eb4a85ef38f762c150e  download/distcc_2.14.orig.tar.gz
-0c088d6a85457afbb483f774ec45e669  download/distcc_2.18.1.orig.tar.gz
-9a76f22977625abb2477a0be50e0a43e  download/distcc_2.18.1-5.diff.gz
+e53f4d3244de004c9370f8e3df18682f  download/distcc_2.18.3.orig.tar.gz
Binary files scratchbox-1.0.1-orig/tools/distcc/files/distcc_2.18.3.orig.tar.gz and scratchbox-1.0.1/tools/distcc/files/distcc_2.18.3.orig.tar.gz differ
diff -Nur scratchbox-1.0.1-orig/tools/openssh/Makefile scratchbox-1.0.1/tools/openssh/Makefile
--- scratchbox-1.0.1-orig/tools/openssh/Makefile	2005-01-31 12:12:54.000000000 +0200
+++ scratchbox-1.0.1/tools/openssh/Makefile	2005-06-17 14:32:02.000000000 +0300
@@ -15,15 +15,21 @@
  # FIXME: blurb goes here
 endef
 
+FORCE_LIBS = LIBS=-lresolv
+
 CONFIGURE_ARGS = --with-ldflags="-L. -Lopenbsd-compat/ $(LDFLAGS)" --prefix=$(prefix) --sbindir=$(sbindir)
 BUILD_ARGS = LDFLAGS="-L. -Lopenbsd-compat/ $(LDFLAGS)" CC="$(CC)" LD="$(CC)"
 
-CONFIGURE_SCRIPTS = $(WORKSRC)/configure
+CONFIGURE_SCRIPTS = openssh
 BUILD_SCRIPTS = $(WORKSRC)/Makefile
 INSTALL_SCRIPTS = openssh
 
 include ../category.mk
 
+configure-openssh:
+	cd $(WORKSRC) && $(FORCE_LIBS) ./configure $(CONFIGURE_ARGS)
+	$(MAKECOOKIE)
+
 install-openssh:
 	install -d $(bindir)
 	cd $(WORKSRC) && install -m 0755 ssh scp ssh-add ssh-agent ssh-keygen ssh-keyscan $(bindir)/
Binary files scratchbox-1.0.1-orig/tools/openssh/files/openssh_3.8.1p1.orig.tar.gz and scratchbox-1.0.1/tools/openssh/files/openssh_3.8.1p1.orig.tar.gz differ
diff -Nur scratchbox-1.0.1-orig/tools/qemu/Makefile scratchbox-1.0.1/tools/qemu/Makefile
--- scratchbox-1.0.1-orig/tools/qemu/Makefile	2005-01-27 16:48:45.000000000 +0200
+++ scratchbox-1.0.1/tools/qemu/Makefile	2005-06-17 14:32:56.000000000 +0300
@@ -1,5 +1,5 @@
 GARNAME = qemu
-GARVERSION = 0.6.1
+GARVERSION = 0.7.0
 CATEGORIES = tools
 DISTFILES = $(GARNAME)-$(GARVERSION).tar.gz
 
@@ -21,7 +21,7 @@
 # /scratchbox/tools/lib/libsb.a.  (I'm not sure if that works, though.)
 
 CONFIGURE_ARGS = --prefix=$(prefix) --interp-prefix=/ --target-list="arm-user ppc-user sparc-user i386-user" --static --disable-sdl
-BUILD_ARGS = LDFLAGS="-static" CC="$(CC)"
+BUILD_ARGS = LDFLAGS="-static" CC="gcc-3.4"
 
 CONFIGURE_SCRIPTS = $(WORKSRC)/configure
 BUILD_SCRIPTS = $(WORKSRC)/Makefile
@@ -31,6 +31,21 @@
 
 pre-patch:
 	patch -p1 -d $(WORKSRC) < files/env.patch
-	patch -p1 -d $(WORKSRC) < files/syscall.patch
+	patch -p0 -d $(WORKSRC) < files/ipc.patch
+	#patch -p0 -d $(WORKSRC) < files/proc-hack.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-arm-sigfpe.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-evil-dlclose.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-jobsignals.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-sigaction.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-sigaltstackhack.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-sigsilent.patch
+	patch -p0 -d $(WORKSRC) < files/qemu-socketcall.patch
+	patch -p0 -d $(WORKSRC) < files/qemu-solinger-setsockopt.patch
+	#patch -p0 -d $(WORKSRC) < files/qemu-syscalls.patch
+	patch -p0 -d $(WORKSRC) < files/socketopt.patch
+	#patch -p1 -d $(WORKSRC) < files/sysctl.patch
+	patch -p0 -d $(WORKSRC) < files/truncate64.patch
+	patch -p2 -d $(WORKSRC) < files/tcpip-sockopt.patch
+	patch -p0 -d $(WORKSRC) < files/x86_64-fcntl.patch
 	$(MAKECOOKIE)
 
diff -Nur scratchbox-1.0.1-orig/tools/qemu/checksums scratchbox-1.0.1/tools/qemu/checksums
--- scratchbox-1.0.1-orig/tools/qemu/checksums	2004-11-15 10:31:40.000000000 +0200
+++ scratchbox-1.0.1/tools/qemu/checksums	2005-06-17 14:32:56.000000000 +0300
@@ -1 +1 @@
-f1b5e103321832d2786dd4110f6c8ae4  download/qemu-0.6.1.tar.gz
+234e9ace03b00259bb57dc5a9c633056  download/qemu-0.7.0.tar.gz
diff -Nur scratchbox-1.0.1-orig/tools/qemu/files/env.patch scratchbox-1.0.1/tools/qemu/files/env.patch
--- scratchbox-1.0.1-orig/tools/qemu/files/env.patch	2004-11-15 10:28:51.000000000 +0200
+++ scratchbox-1.0.1/tools/qemu/files/env.patch	2005-06-17 14:32:55.000000000 +0300
@@ -1,6 +1,6 @@
---- qemu-0.6.0.orig/linux-user/main.c	2004-08-10 18:21:54.000000000 +0300
-+++ qemu-0.6.0/linux-user/main.c	2004-08-10 18:21:55.000000000 +0300
-@@ -895,6 +895,76 @@
+--- qemu-0.5.4/linux-user/main.c.orig	2004-04-27 00:17:28.000000000 +0300
++++ qemu-0.5.4/linux-user/main.c	2004-04-27 11:02:20.000000000 +0300
+@@ -812,6 +812,76 @@
  }
  #endif
  
@@ -54,7 +54,7 @@
 +	while (1) {
 +		entry = NULL;
 +
-+		/* Find first SBOX_ENV-entry. */
++		/* Find first SBRSH_ENV-entry. */
 +		for (p = environ; *p; p++) {
 +			entry = *p;
 +			if (strncmp(entry, ENV_RENAME_PREFIX, prelen) == 0) {
@@ -77,7 +77,7 @@
  void usage(void)
  {
      printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2004 Fabrice Bellard\n"
-@@ -1002,6 +1072,8 @@
+@@ -919,6 +989,8 @@
          usage();
      filename = argv[optind];
  
diff -Nur scratchbox-1.0.1-orig/tools/qemu/files/sysctl.patch scratchbox-1.0.1/tools/qemu/files/sysctl.patch
--- scratchbox-1.0.1-orig/tools/qemu/files/sysctl.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/qemu/files/sysctl.patch	2005-06-17 14:32:56.000000000 +0300
@@ -0,0 +1,46 @@
+--- qemu-0.7.0/linux-user/syscall.c.orig	2004-04-27 00:17:28.000000000 +0300
++++ qemu-0.7.0/linux-user/syscall.c	2004-04-27 11:02:20.000000000 +0300
+@@ -51,6 +51,7 @@
+ #include <netinet/ip.h>
+ #include <netinet/tcp.h>
+ #include <sys/un.h>
++#include <sys/sysctl.h>
+ 
+ #define termios host_termios
+ #define winsize host_winsize
+@@ -2572,9 +2573,32 @@
+         ret = get_errno(fdatasync(arg1));
+         break;
+     case TARGET_NR__sysctl:
+-        /* We don't implement this, but ENODIR is always a safe
+-           return value. */
+-        return -ENOTDIR;
++        {
++            struct __sysctl_args *args = (struct __sysctl_args *) arg1;
++            int *name, nlen, *oldlenp;
++	     size_t oldlen, newlen;
++            void *oldval, *newval;
++
++            name = (int *) tswapl((long) args->name);
++            nlen = tswapl(args->nlen);
++            oldval = (void *) tswapl((long) args->oldval);
++            oldlenp = (int *) tswapl((long) args->oldlenp);
++            oldlen = tswapl(*oldlenp);
++            newval = (void *) tswapl((long) args->newval);
++            newlen = tswapl(args->newlen);
++
++            if (nlen == 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION) {
++                ret = get_errno(
++            		sysctl(name, nlen, oldval, &oldlen, newval, newlen));
++                if (!is_error(ret)) {
++                    *oldlenp = tswapl(oldlen);
++                }
++            } else {
++                gemu_log("qemu: Unsupported sysctl name\n");
++                ret = -ENOSYS;
++            }
++        }
++        break;
+     case TARGET_NR_sched_setparam:
+         {
+             struct sched_param *target_schp = (void *)arg2;
diff -Nur scratchbox-1.0.1-orig/tools/qemu/files/x86_64-fcntl.patch scratchbox-1.0.1/tools/qemu/files/x86_64-fcntl.patch
--- scratchbox-1.0.1-orig/tools/qemu/files/x86_64-fcntl.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/qemu/files/x86_64-fcntl.patch	2005-06-17 14:32:56.000000000 +0300
@@ -0,0 +1,20 @@
+--- linux-user/syscall.c	2005-06-04 02:06:33.000000000 +0300
++++ linux-user/syscall.c	2005-06-04 02:08:17.000000000 +0300
+@@ -3143,6 +3143,9 @@
+ #if TARGET_LONG_BITS == 32
+     case TARGET_NR_fcntl64:
+     {
++        ret = get_errno(do_fcntl(arg1, arg2, arg3));
++
++	/* This caused adduser not to work in my box
+ 	struct flock64 fl;
+ 	struct target_flock64 *target_fl = (void *)arg3;
+ 
+@@ -3171,6 +3174,7 @@
+             ret = get_errno(do_fcntl(arg1, arg2, arg3));
+             break;
+         }
++	*/
+ 	break;
+     }
+ #endif
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-base/Makefile scratchbox-1.0.1/tools/scratchbox-base/Makefile
--- scratchbox-1.0.1-orig/tools/scratchbox-base/Makefile	2005-02-15 10:46:55.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-base/Makefile	2005-06-17 14:32:59.000000000 +0300
@@ -3,6 +3,8 @@
 CATEGORIES = tools
 DISTFILES = $(GARNAME)-$(GARVERSION).tar.gz
 
+PATCHFILES = register_misc_runner-x86_64.patch
+
 LIBDEPS =
 DEPENDS =
 
@@ -45,7 +47,6 @@
 	822-date >> $(SBOX_DIR)/etc/scratchbox-version
 
 	env SBOX_DIR=$(SBOX_DIR) /bin/sh files/copy_libs.sh
-
 	$(MAKECOOKIE)
 
 CVSTAG = BASE_$(GARVERSION)
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-base/checksums scratchbox-1.0.1/tools/scratchbox-base/checksums
--- scratchbox-1.0.1-orig/tools/scratchbox-base/checksums	2005-02-15 14:08:18.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-base/checksums	2005-06-17 14:32:59.000000000 +0300
@@ -1 +1,2 @@
 b053c3750205778dd95ab38424371273  download/scratchbox-base-72.tar.gz
+311337a4a8965bd9d6feaeecd98b0dec  download/register_misc_runner-x86_64.patch
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-base/files/register_misc_runner-x86_64.patch scratchbox-1.0.1/tools/scratchbox-base/files/register_misc_runner-x86_64.patch
--- scratchbox-1.0.1-orig/tools/scratchbox-base/files/register_misc_runner-x86_64.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-base/files/register_misc_runner-x86_64.patch	2005-06-17 14:32:59.000000000 +0300
@@ -0,0 +1,10 @@
+--- main.d/scratchbox-base-72/sb_base/sbin/register_misc_runner	2005-01-18 11:42:09.000000000 +0200
++++ main.d/scratchbox-base-72/sb_base/sbin/register_misc_runner	2005-06-01 14:07:05.000000000 +0300
+@@ -77,4 +77,6 @@
+ register arm     little '\x28'
+ register powerpc big    '\x14'
+ register sparc   big    '\x02'
+-register i386    little '\x03'
++if echo $NATIVE | grep -v x86_64 >/dev/null ; then
++	register i386    little '\x03'
++fi
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-utils/Makefile scratchbox-1.0.1/tools/scratchbox-utils/Makefile
--- scratchbox-1.0.1-orig/tools/scratchbox-utils/Makefile	2005-02-15 09:25:11.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-utils/Makefile	2005-06-17 15:19:48.000000000 +0300
@@ -3,6 +3,8 @@
 CATEGORIES = tools
 DISTFILES = $(GARNAME)-$(GARVERSION).tar.gz
 
+PATCHFILES = libsb-x86_64.patch ldd-x86_64.patch correct-automake-execv.patch
+
 LIBDEPS =
 DEPENDS = tools/scratchbox-base
 
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-utils/checksums scratchbox-1.0.1/tools/scratchbox-utils/checksums
--- scratchbox-1.0.1-orig/tools/scratchbox-utils/checksums	2005-02-15 14:08:18.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-utils/checksums	2005-06-17 14:33:00.000000000 +0300
@@ -1 +1,4 @@
 2b4a5f39e5e6b87dd45424a94bafd3a1  download/scratchbox-utils-84.tar.gz
+be0d6d539071de81dd392a065c286ad7  download/libsb-x86_64.patch
+13f98f8b034edfe98e10d9d14ac66833  download/ldd-x86_64.patch
+9848e0b3b37a95d747988220d4d2d2f9  download/correct-automake-execv.patch
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-utils/files/correct-automake-execv.patch scratchbox-1.0.1/tools/scratchbox-utils/files/correct-automake-execv.patch
--- scratchbox-1.0.1-orig/tools/scratchbox-utils/files/correct-automake-execv.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-utils/files/correct-automake-execv.patch	2005-06-17 14:33:02.000000000 +0300
@@ -0,0 +1,20 @@
+--- main.d/scratchbox-utils-84/sb_automake_wrapper.c	2004-10-21 14:27:21.000000000 +0300
++++ main.d/scratchbox-utils-84/sb_automake_wrapper.c	2005-06-04 02:53:10.000000000 +0300
+@@ -29,7 +29,7 @@
+ {
+     char *name = basename(argv[0]);
+     char *env = getenv("SBOX_DEFAULT_AUTOMAKE");
+-    char prog[PATH_MAX], *new_arg[argc], *ver;
++    char prog[PATH_MAX], *new_arg[argc+1], *ver;
+     int i;
+ 
+     if ((ver = get_version(name))) {
+@@ -49,6 +49,8 @@
+     for (i = 1; i < argc; i++)
+         new_arg[i] = argv[i];
+     
++    new_arg[argc] = NULL;
++    
+     execv(prog, new_arg);
+ 
+     return 0;
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-utils/files/ldd-x86_64.patch scratchbox-1.0.1/tools/scratchbox-utils/files/ldd-x86_64.patch
--- scratchbox-1.0.1-orig/tools/scratchbox-utils/files/ldd-x86_64.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-utils/files/ldd-x86_64.patch	2005-06-17 14:33:02.000000000 +0300
@@ -0,0 +1,587 @@
+--- main.d/scratchbox-utils-84/ldd.c	2005-06-07 10:44:08.000000000 +0300
++++ main.d/scratchbox-utils-84/ldd.c	2005-06-07 10:43:28.000000000 +0300
+@@ -96,6 +96,11 @@
+ #define ELFCLASSM    ELFCLASS32
+ #endif
+ 
++/* This is just for getting ldd to compile */
++#if defined(__x86_64__)
++#define MATCH_MACHINE(x) (x == EM_X86_64)
++#define ELFCLASSM      ELFCLASS64
++#endif
+ 
+ #ifndef MATCH_MACHINE
+ #warning "You really should add a MATCH_MACHINE() macro for your architecture"
+@@ -119,6 +124,7 @@
+ char *interp_dir = NULL;
+ int byteswap;
+ static int interpreter_already_found=0;
++char *error_string = NULL;
+ 
+ static inline uint32_t byteswap32_to_host(uint32_t value)
+ {
+@@ -129,7 +135,14 @@
+ 	}
+ }
+ 
+-
++static inline uint64_t byteswap64_to_host(uint64_t value)
++{
++	if (byteswap==1) {
++		return(bswap_64(value));
++	} else {
++		return(value);
++	}
++}
+ 
+ static Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
+ {
+@@ -144,6 +157,19 @@
+ 	return NULL;
+ }
+ 
++static Elf64_Shdr * elf_find_section_type64(int key, Elf64_Ehdr *ehdr)
++{
++	int j;
++	Elf64_Shdr *shdr;
++	shdr = (Elf64_Shdr *)(ehdr->e_shoff + (char *)ehdr);
++	for (j = ehdr->e_shnum; --j>=0; ++shdr) {
++		if (key==(int)byteswap32_to_host(shdr->sh_type)) {
++			return shdr;
++		}
++	}
++	return NULL;
++}
++
+ static Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
+ {
+ 	int j;
+@@ -156,6 +182,18 @@
+ 	return NULL;
+ }
+ 
++static Elf64_Phdr * elf_find_phdr_type64(int type, Elf64_Ehdr *ehdr)
++{
++	int j;
++	Elf64_Phdr *phdr = (Elf64_Phdr *)(ehdr->e_phoff + (char *)ehdr);
++	for (j = ehdr->e_phnum; --j>=0; ++phdr) {
++		if (type==(int)byteswap32_to_host(phdr->p_type)) {
++			return phdr;
++		}
++	}
++	return NULL;
++}
++
+ /* Returns value if return_val==1, ptr otherwise */ 
+ static void * elf_find_dynamic(int const key, Elf32_Dyn *dynp, 
+ 	Elf32_Ehdr *ehdr, int return_val)
+@@ -173,6 +211,22 @@
+ 	return NULL;
+ }
+ 
++static void * elf_find_dynamic64(int const key, Elf64_Dyn *dynp, 
++	Elf64_Ehdr *ehdr, int return_val)
++{
++	Elf64_Phdr *pt_text = elf_find_phdr_type64(PT_LOAD, ehdr);
++	unsigned tx_reloc = byteswap64_to_host(pt_text->p_vaddr) - byteswap64_to_host(pt_text->p_offset);
++	for (; DT_NULL!=byteswap64_to_host(dynp->d_tag); ++dynp) {
++		if (key == (int)byteswap64_to_host(dynp->d_tag)) {
++			if (return_val == 1)
++				return (void *)(intptr_t)byteswap64_to_host(dynp->d_un.d_val);
++			else
++				return (void *)(byteswap64_to_host(dynp->d_un.d_ptr) - tx_reloc + (char *)ehdr );
++		}
++	}
++	return NULL;
++}
++
+ static int check_elf_header(Elf32_Ehdr *const ehdr)
+ {
+ 	if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||  
+@@ -210,6 +264,44 @@
+ 	return 0;
+ }
+ 
++
++static int check_elf_header64(Elf64_Ehdr *const ehdr)
++{
++	if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||  
++			ehdr->e_ident[EI_CLASS] != ELFCLASS64 ||
++			ehdr->e_ident[EI_VERSION] != EV_CURRENT) 
++	{
++		return 1;
++	}
++
++	/* Check if the target endianness matches the host's endianness */
++	byteswap = 0;
++#if __BYTE_ORDER == __LITTLE_ENDIAN
++	if (ehdr->e_ident[5] == ELFDATA2MSB) {
++		/* Ick -- we will have to byte-swap everything */
++		byteswap = 1;
++	}
++#elif __BYTE_ORDER == __BIG_ENDIAN
++	if (ehdr->e_ident[5] == ELFDATA2LSB) {
++		/* Ick -- we will have to byte-swap everything */
++		byteswap = 1;
++	}
++#else
++#error Unknown host byte order!
++#endif
++	
++	/* Be vary lazy, and only byteswap the stuff we use */
++	if (byteswap==1) {
++		ehdr->e_type=bswap_16(ehdr->e_type);
++		ehdr->e_phoff=bswap_64(ehdr->e_phoff);
++		ehdr->e_shoff=bswap_64(ehdr->e_shoff);
++		ehdr->e_phnum=bswap_16(ehdr->e_phnum);
++		ehdr->e_shnum=bswap_16(ehdr->e_shnum);
++	}
++
++	return 0;
++}
++
+ /* This function's behavior must exactly match that 
+  * in uClibc/ldso/ldso/readelflib1.c */
+ static void search_for_named_library(char *name, char *result, const char *path_list)
+@@ -329,6 +421,81 @@
+ 	}
+ }
+ 
++static void locate_library_file64(Elf64_Ehdr* ehdr, Elf64_Dyn* dynamic, int is_suid, struct library *lib)
++{
++	char *buf;
++	char *path;
++	struct stat filestat;
++	
++	/* If this is a fully resolved name, our job is easy */
++	if (stat (lib->name, &filestat) == 0) {
++		lib->path = lib->name;
++		return;
++	}
++
++	/* We need some elbow room here.  Make some room...*/
++	buf = malloc(1024);
++	if (!buf) {
++		fprintf(stderr, "Out of memory!\n");
++		exit(EXIT_FAILURE);
++	}
++
++	/* This function must match the behavior of _dl_load_shared_library
++	 * in readelflib1.c or things won't work out as expected... */
++
++	/* The ABI specifies that RPATH is searched first, so do that now.  */
++	path = (char *)elf_find_dynamic64(DT_RPATH, dynamic, ehdr, 0);
++	if (path) {
++		search_for_named_library(lib->name, buf, path);
++		if (*buf != '\0') {
++			lib->path = buf;
++			return;
++		}
++	}
++
++	/* Next check LD_{ELF_}LIBRARY_PATH if specified and allowed.
++	 * Since this app doesn't actually run an executable I will skip
++	 * the suid check, and just use LD_{ELF_}LIBRARY_PATH if set */
++	if (is_suid==1)
++		path = NULL;
++	else
++		path = getenv("LD_LIBRARY_PATH");
++	if (path) {
++		search_for_named_library(lib->name, buf, path);
++		if (*buf != '\0') {
++			lib->path = buf;
++			return;
++		}
++	}
++
++#ifdef USE_CACHE
++	/* FIXME -- add code to check the Cache here */ 
++#endif
++
++
++	/* Next look for libraries wherever the shared library 
++	 * loader was installed -- this is usually where we
++	 * should find things... */
++	if (interp_dir) {
++		search_for_named_library(lib->name, buf, interp_dir);
++		if (*buf != '\0') {
++			lib->path = buf;
++			return;
++		}
++	}
++
++	/* Lastly, search the standard list of paths for the library.
++	   This list must exactly match the list in uClibc/ldso/ldso/readelflib1.c */
++	path =	"/usr/X11R6/lib:/usr/lib:/lib";
++	search_for_named_library(lib->name, buf, path);
++	if (*buf != '\0') {
++		lib->path = buf;
++	} else { 
++		free(buf);
++		lib->path = not_found;
++	}
++}
++
+ static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
+ {
+ 	char *tmp, *tmp1, *tmp2;
+@@ -390,6 +557,66 @@
+ }
+ 
+ 
++static int add_library64(Elf64_Ehdr* ehdr, Elf64_Dyn* dynamic, int is_setuid, char *s)
++{
++	char *tmp, *tmp1, *tmp2;
++	struct library *cur, *newlib=lib_list;
++
++	if (!s || !strlen(s))
++		return 1;
++
++	tmp = s; 
++	while (*tmp) {
++		if (*tmp == '/')
++			s = tmp + 1;
++		tmp++;
++	}
++
++	/* We add libc.so.0 elsewhere */
++	if (interpreter_already_found && (tmp=strrchr(interp, '/')) != NULL)
++	{
++		int len = strlen(interp_dir);
++		if (strcmp(s, interp+1+len)==0)
++			return 1;
++	}
++
++	for (cur = lib_list; cur; cur=cur->next) {
++		/* Check if this library is already in the list */
++		tmp1 = tmp2 = cur->name; 
++		while (*tmp1) {
++			if (*tmp1 == '/')
++				tmp2 = tmp1 + 1;
++			tmp1++;
++		}
++		if(strcmp(tmp2, s)==0) {
++			//printf("find_elf_interpreter is skipping '%s' (already in list)\n", cur->name);
++			return 0;
++		}
++	}
++
++	/* Ok, this lib needs to be added to the list */
++	newlib = malloc(sizeof(struct library));
++	if (!newlib)
++		return 1;
++	newlib->name = malloc(strlen(s)+1);
++	strcpy(newlib->name, s);
++	newlib->resolved = 0;
++	newlib->path = NULL;
++	newlib->next = NULL;
++
++	/* Now try and locate where this library might be living... */
++	locate_library_file64(ehdr, dynamic, is_setuid, newlib);
++
++	//printf("add_library is adding '%s' to '%s'\n", newlib->name, newlib->path);
++	if (!lib_list) {
++		lib_list = newlib;
++	} else {
++		for (cur = lib_list;  cur->next; cur=cur->next); /* nothing */
++		cur->next = newlib;
++	}
++	return 0;
++}
++
+ static void find_needed_libraries(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_setuid)
+ {
+ 	Elf32_Dyn  *dyns;
+@@ -400,8 +627,20 @@
+ 					(char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
+ 		}
+ 	}
++}  
++
++static void find_needed_libraries64(Elf64_Ehdr* ehdr, Elf64_Dyn* dynamic, char *strtab, int is_setuid)
++{
++	Elf64_Dyn  *dyns;
++
++	for (dyns=dynamic; byteswap64_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
++		if (DT_NEEDED == byteswap64_to_host(dyns->d_tag)) {
++			add_library64(ehdr, dynamic, is_setuid, 
++					(char*)strtab + byteswap64_to_host(dyns->d_un.d_val));
++		}
++	}
+ }
+-    
++
+ static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
+ {
+ 	Elf32_Phdr *phdr;
+@@ -464,6 +703,69 @@
+ 	return NULL;
+ }
+ 
++
++static struct library * find_elf_interpreter64(Elf64_Ehdr* ehdr)
++{
++	Elf64_Phdr *phdr;
++
++	if (interpreter_already_found==1)
++		return NULL;
++	phdr = elf_find_phdr_type64(PT_INTERP, ehdr);
++	if (phdr) {
++		struct library *cur, *newlib=NULL;
++		char *s = (char*)ehdr + byteswap64_to_host(phdr->p_offset);
++	
++		char *tmp, *tmp1;
++		interp = strdup(s);
++		interp_dir = strdup(s);
++		tmp = strrchr(interp_dir, '/');
++		if (*tmp)
++			*tmp = '\0';
++		else {
++			free(interp_dir);
++			interp_dir = interp;
++		}
++		tmp1 = tmp = s;
++		while (*tmp) {
++			if (*tmp == '/')
++				tmp1 = tmp + 1;
++			tmp++;
++		}
++		for (cur = lib_list; cur; cur=cur->next) {
++			/* Check if this library is already in the list */
++			if(strcmp(cur->name, tmp1)==0) {
++				//printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name);
++				newlib = cur;
++				free(newlib->name);
++				free(newlib->path);
++				return NULL;
++			}
++		}
++		if (newlib == NULL)
++			newlib = malloc(sizeof(struct library));
++		if (!newlib)
++			return NULL;
++		newlib->name = malloc(strlen(s)+1);
++		strcpy(newlib->name, s);
++		newlib->path = newlib->name;
++		newlib->resolved = 1;
++		newlib->next = NULL;
++	
++#if 0
++		//printf("find_elf_interpreter is adding '%s' to '%s'\n", newlib->name, newlib->path);
++		if (!lib_list) {
++			lib_list = newlib;
++		} else {
++			for (cur = lib_list;  cur->next; cur=cur->next); /* nothing */
++			cur->next = newlib;
++		}
++#endif
++		interpreter_already_found=1;
++		return newlib;
++	}
++	return NULL;
++}
++
+ /* map the .so, and locate interesting pieces */
+ int find_dependancies(char* filename)
+ {
+@@ -475,7 +777,7 @@
+ 	Elf32_Shdr *dynsec = NULL;
+ 	Elf32_Dyn *dynamic = NULL;
+ 	struct library *interp;
+-
++	
+ 	if (filename == not_found)
+ 		return 0;
+ 
+@@ -499,18 +801,20 @@
+ 		goto foo;
+ 
+ 	/* mmap the file to make reading stuff from it effortless */
+-	ehdr = (Elf32_Ehdr *)mmap(0, statbuf.st_size, 
++    ehdr = (Elf32_Ehdr *) mmap(0, statbuf.st_size, 
+ 			PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
+ 
+ foo:
+ 	/* Check if this looks like a legit ELF file */
+ 	if (check_elf_header(ehdr)) {
+-		fprintf(stderr, "%s: not an ELF file.\n", filename);
++		error_string = strdup("%s: not an ELF file.\n");
++		/*fprintf(stderr, "%s: not an ELF file.\n", filename);*/
+ 		return -1;
+ 	}
+ 	/* Check if this is the right kind of ELF file */
+ 	if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
+-		fprintf(stderr, "%s: not a dynamic executable\n", filename);
++		error_string = strdup("%s: not a dynamic executable\n");
++		/*fprintf(stderr, "%s: not a dynamic executable\n", filename);*/
+ 		return -1;
+ 	}
+ 	if (ehdr->e_type == ET_EXEC) {
+@@ -575,6 +879,121 @@
+ }
+ 
+ 
++/* map the .so, and locate interesting pieces */
++int find_dependancies64(char* filename)
++{
++	int is_suid = 0;
++	FILE *thefile;
++	struct stat statbuf;
++	char *dynstr=NULL;
++	Elf64_Ehdr *ehdr = NULL;
++	Elf64_Shdr *dynsec = NULL;
++	Elf64_Dyn *dynamic = NULL;
++	struct library *interp;
++
++	if (filename == not_found)
++		return 0;
++
++	if (!filename) {
++		fprintf(stderr, "No filename specified.\n");
++		return -1;
++	}
++	if (!(thefile = fopen(filename, "r"))) {
++		perror(filename);
++		return -1;
++	}
++	if (fstat(fileno(thefile), &statbuf) < 0) {
++		perror(filename);
++		return -1;
++	}
++
++	if ((size_t)statbuf.st_size < sizeof(Elf64_Ehdr))
++		goto foo;
++
++	if (!S_ISREG(statbuf.st_mode))
++		goto foo;
++
++	/* mmap the file to make reading stuff from it effortless */
++    ehdr = (Elf64_Ehdr *) mmap(0, statbuf.st_size, 
++			PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
++
++foo:
++	/* Check if this looks like a legit ELF file */
++	if (check_elf_header64(ehdr)) {
++		if (error_string)
++			fprintf(stderr, error_string, filename);
++		else
++			fprintf(stderr, "%s: not an ELF file.\n", filename);	
++		return -1;
++	}
++	/* Check if this is the right kind of ELF file */
++	if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
++		if (error_string)
++			fprintf(stderr, error_string, filename);
++		else
++			fprintf(stderr, "%s: not a dynamic executable\n", filename);
++		return -1;
++	}
++	if (ehdr->e_type == ET_EXEC) {
++		if (statbuf.st_mode & S_ISUID)
++			is_suid = 1;
++		if ((statbuf.st_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
++			is_suid = 1;
++#if 0
++		/* FIXME */
++		if (is_suid)
++			fprintf(stderr, "%s: is setuid\n", filename);
++#endif
++	}
++
++	interpreter_already_found=0;
++	interp = find_elf_interpreter64(ehdr);
++			
++#if 1
++	if (interp && ehdr->e_type == ET_EXEC && ehdr->e_ident[EI_CLASS] == ELFCLASSM && 
++			ehdr->e_ident[EI_DATA] == ELFDATAM
++		&& ehdr->e_ident[EI_VERSION] == EV_CURRENT && MATCH_MACHINE(ehdr->e_machine)) 
++	{
++		struct stat statbuf;
++		if (stat(interp->path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
++			pid_t pid;
++			int status;
++			static const char * const environment[] = {
++				"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
++				"SHELL=/bin/sh",
++				"LD_TRACE_LOADED_OBJECTS=1",
++				NULL
++			};
++
++			if ((pid = fork()) == 0) {
++				/* Cool, it looks like we should be able to actually 
++				 * run this puppy.  Do so now... */
++				execle(filename, filename, NULL, environment);
++				_exit(0xdead);
++			}
++
++			/* Wait till it returns */
++			waitpid(pid, &status, 0);
++			if (WIFEXITED(status) && WEXITSTATUS(status)==0) {
++				return 1;
++			}
++
++			/* If the exec failed, we fall through to trying to find
++			 * all the needed libraries ourselves by rummaging about
++			 * in the ELF headers... */
++		}
++	}
++#endif
++
++	dynsec = elf_find_section_type64(SHT_DYNAMIC, ehdr);
++	if (dynsec) {
++		dynamic = (Elf64_Dyn*)(byteswap64_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
++		dynstr = (char *)elf_find_dynamic64(DT_STRTAB, dynamic, ehdr, 0);
++		find_needed_libraries64(ehdr, dynamic, dynstr, is_suid);
++	}
++	
++	return 0;
++}
+ 
+ int main( int argc, char** argv)
+ {
+@@ -582,6 +1001,7 @@
+ 	int got_em_all=1;
+ 	char *filename = NULL;
+ 	struct library *cur;
++	int bin64 = 0;
+ 
+ 	if (argc < 2) {
+ 		fprintf(stderr, "ldd: missing file arguments\n");
+@@ -617,8 +1037,13 @@
+ 		}
+ 
+ 		if (find_dependancies(filename)!=0)
+-			continue;
+-
++		{
++		    if (find_dependancies64(filename)!=0)
++			    continue;
++		    else
++				bin64 = 1;
++		}
++		
+ 		while(got_em_all) {
+ 			got_em_all=0;
+ 			/* Keep walking the list till everybody is resolved */
+@@ -626,7 +1051,10 @@
+ 				if (cur->resolved == 0 && cur->path) {
+ 					got_em_all=1;
+ 					//printf("checking sub-depends for '%s\n", cur->path);
+-					find_dependancies(cur->path);
++					if (bin64)
++						find_dependancies64(cur->path);
++					else
++					    find_dependancies(cur->path);
+ 					cur->resolved = 1;
+ 				}
+ 			}
+@@ -654,6 +1082,9 @@
+ 		lib_list=NULL;
+ 	}
+ 
++	if (error_string)
++		free(error_string);
++	
+ 	return 0;
+ }
+ 
diff -Nur scratchbox-1.0.1-orig/tools/scratchbox-utils/files/libsb-x86_64.patch scratchbox-1.0.1/tools/scratchbox-utils/files/libsb-x86_64.patch
--- scratchbox-1.0.1-orig/tools/scratchbox-utils/files/libsb-x86_64.patch	1970-01-01 02:00:00.000000000 +0200
+++ scratchbox-1.0.1/tools/scratchbox-utils/files/libsb-x86_64.patch	2005-06-17 14:33:02.000000000 +0300
@@ -0,0 +1,85 @@
+--- main.d/scratchbox-utils-84/libsb.c	2005-02-15 09:49:54.000000000 +0200
++++ main.d/scratchbox-utils-84/libsb.c	2005-06-01 01:25:00.000000000 +0300
+@@ -140,10 +140,18 @@
+ #endif
+ 
+ /* TODO: should we drop class testing? */
++#if defined(__x86_64__)
++#define elf_class   ELFCLASS64
++#elif
+ #define elf_class   ELFCLASS32
++#endif
+ 
+ /* TODO: how can this be made portable? */
++#if defined(__x86_64__)
++#define elf_machine EM_X86_64
++#elif
+ #define elf_machine EM_386
++#endif
+ 
+ /*
+  * Returns binary type that best describes the ELF binary.
+@@ -155,8 +163,13 @@
+ 	struct stat status;
+ 	char *region;
+ 	unsigned int reloc0, ph_base, ph_frag;
++#if defined(__x86_64__)
++ 	Elf64_Ehdr *ehdr;
++	Elf64_Phdr *phdr;
++#elif
+ 	Elf32_Ehdr *ehdr;
+ 	Elf32_Phdr *phdr;
++#endif
+ 
+ 	retval = BIN_NONE;
+ 
+@@ -179,8 +192,12 @@
+ 	if (!region) {
+ 		goto _out_close;
+ 	}
+-
++  
++#if defined(__x86_64__)
++	ehdr = (Elf64_Ehdr *) region;
++#elif
+ 	ehdr = (Elf32_Ehdr *) region;
++#endif
+ 
+ 	if (strncmp((char *) ehdr, ELFMAG, SELFMAG) != 0) {
+ 		goto _out_munmap;
+@@ -202,7 +219,11 @@
+ 	ph_base = ehdr->e_phoff & PAGE_MASK;
+ 	ph_frag = ehdr->e_phoff - ph_base;
+ 
++#if defined(__x86_64__)
++	phdr = (Elf64_Phdr *) (region + ph_base + ph_frag);
++#elif
+ 	phdr = (Elf32_Phdr *) (region + ph_base + ph_frag);
++#endif
+ 
+ 	for (j = phnum; --j >= 0; ++phdr) {
+ 		if (PT_LOAD == phdr->p_type && ~0 == reloc0) {
+@@ -215,7 +236,11 @@
+ 	for (j = phnum; --j >= 0; ++phdr) {
+ 		int szDyn;
+ 		unsigned int pt_base, pt_frag;
++#if defined(__x86_64__)
++		Elf64_Dyn *dp_rpath, *dp_strsz, *dp_strtab, *dp;
++#elif
+ 		Elf32_Dyn *dp_rpath, *dp_strsz, *dp_strtab, *dp;
++#endif
+ 
+ 		if (PT_DYNAMIC != phdr->p_type) {
+ 			continue;
+@@ -231,7 +256,11 @@
+ 		dp_strsz = NULL;
+ 		dp_strtab = NULL;
+ 
++#if defined(__x86_64__)
++		dp = (Elf64_Dyn *) ((char *) region + pt_base + pt_frag);
++#elif
+ 		dp = (Elf32_Dyn *) ((char *) region + pt_base + pt_frag);
++#endif
+ 
+ 		for (; 0 <= (szDyn -= sizeof (*dp)); ++dp) {
+ 			if (DT_RPATH == dp->d_tag) {
