Merge "Allow BROKEN_RUN to skip all tests built by certain version(s) of toolchain"
diff --git a/build/core/init.mk b/build/core/init.mk
index d33dd0f..ef96806 100644
--- a/build/core/init.mk
+++ b/build/core/init.mk
@@ -212,9 +212,9 @@
         HOST_ARCH := $(PROCESSOR_ARCHITECTURE)
         ifeq ($(HOST_ARCH),AMD64)
             HOST_ARCH := x86
-            ifneq ("",$(shell echo "%ProgramFiles(x86)%"))
-                HOST_ARCH64 := x86_64
-            endif
+        endif
+        ifneq ("",$(shell echo "%ProgramW6432%"))
+            HOST_ARCH64 := x86_64
         endif
     else # HOST_OS_BASE != windows
         UNAME := $(shell uname -m)
diff --git a/build/tools/build-gcc.sh b/build/tools/build-gcc.sh
index 1a4d335..65ba81b 100755
--- a/build/tools/build-gcc.sh
+++ b/build/tools/build-gcc.sh
@@ -356,6 +356,7 @@
 run rm -rf $TOOLCHAIN_PATH/$ABI_CONFIGURE_TARGET/lib/libiberty.a
 run rm -rf $TOOLCHAIN_PATH/$ABI_CONFIGURE_TARGET/lib/*/libiberty.a
 run rm -rf $TOOLCHAIN_PATH/$ABI_CONFIGURE_TARGET/lib/*/*/libiberty.a
+find $TOOLCHAIN_PATH -name "*.la" -exec rm -f {} \;
 
 # Remove libstdc++ for now (will add it differently later)
 # We had to build it to get libsupc++ which we keep.
diff --git a/build/tools/build-host-awk.sh b/build/tools/build-host-awk.sh
index 0fe10a1..84890b7 100755
--- a/build/tools/build-host-awk.sh
+++ b/build/tools/build-host-awk.sh
@@ -58,6 +58,9 @@
 if [ "$MINGW" = "yes" ]; then
   BUILD_MINGW=yes
 fi
+if [ "$TRY64" = "yes" ]; then
+  BUILD_TRY64=yes
+fi
 
 log "Configuring the build"
 mkdir -p $BUILD_DIR && rm -rf $BUILD_DIR/*
@@ -69,8 +72,9 @@
     -C "$AWK_SRCDIR" \
     -j $NUM_JOBS \
     BUILD_DIR="$BUILD_DIR" \
-    MINGW="$BUILD_MINGW"
-fail_panic "Failed to build the sed-$AWK_VERSION executable!"
+    MINGW="$BUILD_MINGW" \
+    TRY64="$BUILD_TRY64"
+fail_panic "Failed to build the awk-$AWK_VERSION executable!"
 
 log "Copying executable to prebuilt location"
 run mkdir -p $(dirname "$OUT") && cp "$BUILD_DIR/$(get_host_exec_name ndk-awk)" "$OUT"
diff --git a/build/tools/build-host-toolbox.sh b/build/tools/build-host-toolbox.sh
index 7646fb2..ed719f6 100755
--- a/build/tools/build-host-toolbox.sh
+++ b/build/tools/build-host-toolbox.sh
@@ -86,17 +86,16 @@
 BUILD_WINDOWS_SOURCES=yes
 
 if [ "$BUILD_WINDOWS_SOURCES" ]; then
+    ORIGINAL_HOST_TAG=$HOST_TAG
+    MINGW=yes
+    handle_mingw
+    prepare_mingw_toolchain $BUILD_DIR
 
-    SUBDIR=$(get_prebuilt_install_prefix windows)/bin
+    SUBDIR=$(get_prebuilt_install_prefix $HOST_TAG)/bin
     DSTDIR=$NDK_DIR/$SUBDIR
     mkdir -p "$DSTDIR"
     fail_panic "Could not create destination directory: $DSTDIR"
 
-    MINGW=yes
-    prepare_mingw_toolchain $BUILD_DIR
-
-    ORIGINAL_HOST_TAG=$HOST_TAG
-
     # Build echo.exe
     HOST_TAG=$ORIGINAL_HOST_TAG
     builder_begin_host "$BUILD_DIR" "$MAKEFILE"
@@ -116,8 +115,8 @@
     builder_end
 
     if [ "$PACKAGE_DIR" ]; then
-        ARCHIVE=toolbox-windows.tar.bz2
-        log "Packaging : $ARCHIVE"
+        ARCHIVE=toolbox-$HOST_TAG.tar.bz2
+        dump "Packaging : $ARCHIVE"
         pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR/echo.exe" "$SUBDIR/cmp.exe"
         fail_panic "Could not package toolbox binaires"
     fi
diff --git a/build/tools/package-release.sh b/build/tools/package-release.sh
index 5899506..b6f196c 100755
--- a/build/tools/package-release.sh
+++ b/build/tools/package-release.sh
@@ -256,11 +256,15 @@
 {
     local PREBUILT=${1}.tar.bz2
     local PREBUILT64=${1}_64.tar.bz2
+    local PREBUILT64_ALT=${1}-x86_64.tar.bz2
     local DDIR="${2:-$DSTDIR}"
     echo "Unpacking $PREBUILT"
     if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then
         unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DDIR"
         fail_panic "Could not unpack prebuilt $PREBUILT. Aborting."
+        if [ ! -f "$PREBUILT_DIR/$PREBUILT64" ] ; then
+            PREBUILT64=$PREBUILT64_ALT
+        fi
         if [ -f "$PREBUILT_DIR/$PREBUILT64" ] ; then
             echo "Unpacking $PREBUILT64"
             unpack_archive "$PREBUILT_DIR/$PREBUILT64" "$DDIR"
diff --git a/build/tools/prebuilt-common.sh b/build/tools/prebuilt-common.sh
index d363508..d7b5dfa 100644
--- a/build/tools/prebuilt-common.sh
+++ b/build/tools/prebuilt-common.sh
@@ -562,7 +562,8 @@
                 ;;
         esac
         if [ "$TRY64" = "yes" ]; then
-            ABI_CONFIGURE_HOST=amd64-mingw32msvc
+            ABI_CONFIGURE_HOST=x86_64-pc-mingw32msvc
+            HOST_TAG=windows-x86_64
         else
             # NOTE: The canadian-cross build of Binutils 2.19 will fail if you
             #        use i586-pc-mingw32msvc here. Binutils 2.21 will work ok
@@ -570,9 +571,9 @@
             #       Use i586-pc-mingw32msvc here because wrappers are generated
             #        using this name
             ABI_CONFIGURE_HOST=i586-pc-mingw32msvc
+            HOST_TAG=windows
         fi
         HOST_OS=windows
-        HOST_TAG=windows
         HOST_EXE=.exe
     fi
 }
@@ -600,8 +601,7 @@
     # so we just add more prefixes to the list to check.
     if [ "$HOST_ARCH" = "x86_64" -a "$TRY64" = "yes" ]; then
         BINPREFIX=x86_64-pc-mingw32msvc-
-        BINPREFIXLST="x86_64-pc-mingw32msvc- amd64-mingw32msvc-
-          x86_64-w64-mingw32-"
+        BINPREFIXLST="x86_64-pc-mingw32msvc- x86_64-w64-mingw32- amd64-mingw32msvc-"
         DEBIAN_NAME=mingw64
     else
         # we are trying 32 bit anyway, so forcing it to avoid build issues
@@ -654,16 +654,19 @@
     $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=$BINPREFIX --dst-prefix="$DST_PREFIX" "$MINGW_WRAP_DIR"
     # generate wrappers for BUILD toolchain
     # this is required for mingw build to avoid tools canadian cross configuration issues
-    LEGACY_TOOLCHAIN_DIR="$ANDROID_NDK_ROOT/../prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6"
-    $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-linux-gnu- \
-            --dst-prefix="$LEGACY_TOOLCHAIN_DIR/bin/x86_64-linux-" "$MINGW_WRAP_DIR"
-    $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-pc-linux-gnu- \
-            --dst-prefix="$LEGACY_TOOLCHAIN_DIR/bin/x86_64-linux-" "$MINGW_WRAP_DIR"
+    # 32-bit BUILD toolchain
     LEGACY_TOOLCHAIN_DIR="$ANDROID_NDK_ROOT/../prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6"
     $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-linux-gnu- \
             --dst-prefix="$LEGACY_TOOLCHAIN_DIR/bin/i686-linux-" "$MINGW_WRAP_DIR"
     $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-pc-linux-gnu- \
             --dst-prefix="$LEGACY_TOOLCHAIN_DIR/bin/i686-linux-" "$MINGW_WRAP_DIR"
+    # 64-bit BUILD toolchain.  libbfd is still built in 32-bit.  Use gcc-sdk instead
+    # of x86_64-linux-glibc2.7-4.6 which is a 64-bit-only tol
+    LEGACY_TOOLCHAIN_DIR="$ANDROID_NDK_ROOT/../prebuilts/tools/gcc-sdk"
+    $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-linux-gnu- \
+            --dst-prefix="$LEGACY_TOOLCHAIN_DIR/" "$MINGW_WRAP_DIR"
+    $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-pc-linux-gnu- \
+            --dst-prefix="$LEGACY_TOOLCHAIN_DIR/" "$MINGW_WRAP_DIR"
     fail_panic "Could not create mingw wrapper toolchain in $MINGW_WRAP_DIR"
 
     export PATH=$MINGW_WRAP_DIR:$PATH
@@ -960,7 +963,11 @@
 {
     local RET=$HOST_TAG
     if [ "$MINGW" = "yes" ]; then
-        RET=windows
+        if [ "$TRY64" = "no" ]; then
+            RET=windows
+        else
+            RET=windows-x86_64
+        fi
     fi
     case $RET in
         linux-x86_64)
diff --git a/ndk-build.cmd b/ndk-build.cmd
index 262cecf..45dd31c 100644
--- a/ndk-build.cmd
+++ b/ndk-build.cmd
@@ -1,7 +1,7 @@
 @echo off
 rem This is a Windows cmd.exe script used to invoke the NDK-specific GNU Make executable
 set NDK_ROOT=%~dp0
-set NDK_MAKE=%NDK_ROOT%/prebuilt/windows/bin/make.exe
+set NDK_MAKE=%NDK_ROOT%\prebuilt\windows-x86_64\bin\make.exe
 
 rem Check if %NDK_ROOT% contains space
 goto :L
@@ -14,4 +14,8 @@
 call :FOO %NDK_ROOT%
 if ERRORLEVEL 1 exit /b 1
 
-%NDK_ROOT%\prebuilt\windows\bin\make.exe -f %NDK_ROOT%build/core/build-local.mk SHELL=cmd %*
+rem Check if 64-bit make exists and Windows is also 64-bit
+if "%ProgramW6432%"=="" set NDK_MAKE=%NDK_ROOT%\prebuilt\windows\bin\make.exe
+if not exist %NDK_MAKE% set NDK_MAKE=%NDK_ROOT%\prebuilt\windows\bin\make.exe
+
+%NDK_MAKE% -f %NDK_ROOT%build/core/build-local.mk SHELL=cmd %*
diff --git a/sources/host-tools/make-3.81/ar.c b/sources/host-tools/make-3.81/ar.c
index 4d9f1bb..80cd8d8 100644
--- a/sources/host-tools/make-3.81/ar.c
+++ b/sources/host-tools/make-3.81/ar.c
@@ -25,7 +25,7 @@
 #include <fnmatch.h>
 
 /* Defined in arscan.c.  */
-extern long int ar_scan PARAMS ((char *archive, long int (*function) (), long int arg));
+extern long int ar_scan PARAMS ((char *archive, long int (*function) (), intptr_t arg));
 extern int ar_name_equal PARAMS ((char *name, char *mem, int truncated));
 #ifndef VMS
 extern int ar_member_touch PARAMS ((char *arname, char *memname));
@@ -107,7 +107,7 @@
       (void) f_mtime (arfile, 0);
   }
 
-  val = ar_scan (arname, ar_member_date_1, (long int) memname);
+  val = ar_scan (arname, ar_member_date_1, (intptr_t) memname);
 
   if (!arname_used)
     free (arname);
@@ -284,7 +284,7 @@
   state.size = size;
   state.chain = 0;
   state.n = 0;
-  (void) ar_scan (arname, ar_glob_match, (long int) &state);
+  (void) ar_scan (arname, ar_glob_match, (intptr_t) &state);
 
   if (state.chain == 0)
     return 0;
diff --git a/sources/host-tools/make-3.81/arscan.c b/sources/host-tools/make-3.81/arscan.c
index dbc4afd..6db6e2b 100644
--- a/sources/host-tools/make-3.81/arscan.c
+++ b/sources/host-tools/make-3.81/arscan.c
@@ -134,7 +134,7 @@
    Returns 0 if have scanned successfully.  */
 
 long int
-ar_scan (char *archive, long int (*function) PARAMS ((void)), long int arg)
+ar_scan (char *archive, long int (*function) PARAMS ((void)), intptr_t arg)
 {
   char *p;
 
@@ -301,7 +301,7 @@
    Returns 0 if have scanned successfully.  */
 
 long int
-ar_scan (char *archive, long int (*function)(), long int arg)
+ar_scan (char *archive, long int (*function)(), intptr_t arg)
 {
 #ifdef AIAMAG
   FL_HDR fl_header;
@@ -757,7 +757,7 @@
 int
 ar_member_touch (char *arname, char *memname)
 {
-  long int pos = ar_scan (arname, ar_member_pos, (long int) memname);
+  long int pos = ar_scan (arname, ar_member_pos, (intptr_t) memname);
   int fd;
   struct ar_hdr ar_hdr;
   int i;
@@ -815,7 +815,7 @@
 
 #ifdef TEST
 
-long int
+intptr_t
 describe_member (int desc, char *name, int truncated,
 		 long int hdrpos, long int datapos, long int size,
                  long int date, int uid, int gid, int mode)
diff --git a/sources/host-tools/make-3.81/function.c b/sources/host-tools/make-3.81/function.c
index c62f7ab..cf77878 100644
--- a/sources/host-tools/make-3.81/function.c
+++ b/sources/host-tools/make-3.81/function.c
@@ -1481,13 +1481,13 @@
     process_register(hProcess);
 
     /* set the pid for returning to caller */
-    *pid_p = (int) hProcess;
+    *pid_p = (intptr_t) hProcess;
 
   /* set up to read data from child */
-  pipedes[0] = _open_osfhandle((long) hChildOutRd, O_RDONLY);
+  pipedes[0] = _open_osfhandle((intptr_t) hChildOutRd, O_RDONLY);
 
   /* this will be closed almost right away */
-  pipedes[1] = _open_osfhandle((long) hChildOutWr, O_APPEND);
+  pipedes[1] = _open_osfhandle((intptr_t) hChildOutWr, O_APPEND);
   } else {
     /* reap/cleanup the failed process */
 	process_cleanup(hProcess);
diff --git a/sources/host-tools/make-3.81/job.c b/sources/host-tools/make-3.81/job.c
index a81cd81..dcc73c2 100644
--- a/sources/host-tools/make-3.81/job.c
+++ b/sources/host-tools/make-3.81/job.c
@@ -235,7 +235,7 @@
  * The macro which references this function is defined in make.h.
  */
 int
-w32_kill(int pid, int sig)
+w32_kill(intptr_t pid, int sig)
 {
   return ((process_kill((HANDLE)pid, sig) == TRUE) ? 0 : -1);
 }
@@ -303,7 +303,7 @@
           const unsigned final_size = path_size + size + 1;
           char *const path = (char *) xmalloc (final_size);
           memcpy (path, temp_path, final_size);
-          *fd = _open_osfhandle ((long)h, 0);
+          *fd = _open_osfhandle ((intptr_t)h, 0);
           if (unixy)
             {
               char *p;
@@ -515,8 +515,8 @@
 	{
 	  any_remote |= c->remote;
 	  any_local |= ! c->remote;
-	  DB (DB_JOBS, (_("Live child 0x%08lx (%s) PID %ld %s\n"),
-                        (unsigned long int) c, c->file->name,
+	  DB (DB_JOBS, (_("Live child %p (%s) PID %ld %s\n"),
+                        c, c->file->name,
                         (long) c->pid, c->remote ? _(" (remote)") : ""));
 #ifdef VMS
 	  break;
@@ -638,8 +638,8 @@
                              e, map_windows32_error_to_string(e));
                   }
                 else
-                  DB (DB_VERBOSE, ("Main thread handle = 0x%08lx\n",
-                                   (unsigned long)main_thread));
+                  DB (DB_VERBOSE, ("Main thread handle = %p\n",
+                                   main_thread));
               }
 
             /* wait for anything to finish */
@@ -695,9 +695,9 @@
         continue;
 
       DB (DB_JOBS, (child_failed
-                    ? _("Reaping losing child 0x%08lx PID %ld %s\n")
+                    ? _("Reaping losing child %p PID %ld %s\n")
                     : _("Reaping winning child 0x%08lx PID %ld %s\n"),
-                    (unsigned long int) c, (long) c->pid,
+                    c, (long) c->pid,
                     c->remote ? _(" (remote)") : ""));
 
       if (c->sh_batch_file) {
@@ -799,8 +799,8 @@
            update_status to its also_make files.  */
         notice_finished_file (c->file);
 
-      DB (DB_JOBS, (_("Removing child 0x%08lx PID %ld%s from chain.\n"),
-                    (unsigned long int) c, (long) c->pid,
+      DB (DB_JOBS, (_("Removing child %p PID %ld%s from chain.\n"),
+                    c, (long) c->pid,
                     c->remote ? _(" (remote)") : ""));
 
       /* Block fatal signals while frobnicating the list, so that
@@ -844,8 +844,8 @@
 free_child (struct child *child)
 {
   if (!jobserver_tokens)
-    fatal (NILF, "INTERNAL: Freeing child 0x%08lx (%s) but no tokens left!\n",
-           (unsigned long int) child, child->file->name);
+    fatal (NILF, "INTERNAL: Freeing child %p (%s) but no tokens left!\n",
+           child, child->file->name);
 
   /* If we're using the jobserver and this child is not the only outstanding
      job, put a token back into the pipe for it.  */
@@ -861,8 +861,8 @@
       if (r != 1)
 	pfatal_with_name (_("write jobserver"));
 
-      DB (DB_JOBS, (_("Released token for child 0x%08lx (%s).\n"),
-                    (unsigned long int) child, child->file->name));
+      DB (DB_JOBS, (_("Released token for child %p (%s).\n"),
+                    child, child->file->name));
     }
 
   --jobserver_tokens;
@@ -1375,7 +1375,7 @@
       hPID = process_easy(argv, child->environment);
 
       if (hPID != INVALID_HANDLE_VALUE)
-        child->pid = (int) hPID;
+        child->pid = (intptr_t) hPID;
       else {
         int i;
         unblock_sigs();
@@ -1452,8 +1452,8 @@
     {
     case cs_running:
       c->next = children;
-      DB (DB_JOBS, (_("Putting child 0x%08lx (%s) PID %ld%s on the chain.\n"),
-                    (unsigned long int) c, c->file->name,
+      DB (DB_JOBS, (_("Putting child %p (%s) PID %ld%s on the chain.\n"),
+                    c, c->file->name,
                     (long) c->pid, c->remote ? _(" (remote)") : ""));
       children = c;
       /* One more job slot is in use.  */
@@ -2043,8 +2043,8 @@
           break;
       else
           fprintf(stderr,
-                  _("make reaped child pid %ld, still waiting for pid %ld\n"),
-                  (DWORD)hWaitPID, (DWORD)hPID);
+                  _("make reaped child pid %lld, still waiting for pid %lld\n"),
+                  (intptr_t)hWaitPID, (intptr_t)hPID);
     }
 
   /* return child's exit code as our exit code */
diff --git a/sources/host-tools/make-3.81/job.h b/sources/host-tools/make-3.81/job.h
index 436b979..90c57d0 100644
--- a/sources/host-tools/make-3.81/job.h
+++ b/sources/host-tools/make-3.81/job.h
@@ -49,7 +49,7 @@
     unsigned int command_line;	/* Index into above.  */
     char *command_ptr;		/* Ptr into command_lines[command_line].  */
 
-    pid_t pid;			/* Child process's ID number.  */
+    intptr_t pid;		/* Child process's ID number.  */
 #ifdef VMS
     int efn;			/* Completion event flag number */
     int cstatus;		/* Completion status */
diff --git a/sources/host-tools/make-3.81/main.c b/sources/host-tools/make-3.81/main.c
index 483babf..8f262e0 100644
--- a/sources/host-tools/make-3.81/main.c
+++ b/sources/host-tools/make-3.81/main.c
@@ -667,16 +667,16 @@
   if (! ISDB (DB_VERBOSE))
     {
       sprintf(errmsg,
-              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"),
-              prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress);
+              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = %p)\n"),
+              prg, exrec->ExceptionCode, exrec->ExceptionAddress);
       fprintf(stderr, errmsg);
       exit(255);
     }
 
   sprintf(errmsg,
-          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"),
+          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %p\n"),
           prg, exrec->ExceptionCode, exrec->ExceptionFlags,
-          (DWORD)exrec->ExceptionAddress);
+          exrec->ExceptionAddress);
 
   if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
       && exrec->NumberParameters >= 2)
diff --git a/sources/host-tools/make-3.81/make.h b/sources/host-tools/make-3.81/make.h
index 994f4f2..e1acb67 100644
--- a/sources/host-tools/make-3.81/make.h
+++ b/sources/host-tools/make-3.81/make.h
@@ -367,7 +367,7 @@
 # define kill(pid,sig) w32_kill(pid,sig)
 
 extern void sync_Path_environment(void);
-extern int kill(int pid, int sig);
+extern int kill(intptr_t pid, int sig);
 extern char *end_of_token_w32(char *s, char stopchar);
 extern int find_and_set_default_shell(char *token);
 
diff --git a/sources/host-tools/make-3.81/w32/subproc/sub_proc.c b/sources/host-tools/make-3.81/w32/subproc/sub_proc.c
index 8ba9ac3..9c41277 100644
--- a/sources/host-tools/make-3.81/w32/subproc/sub_proc.c
+++ b/sources/host-tools/make-3.81/w32/subproc/sub_proc.c
@@ -30,9 +30,9 @@
 static char *make_command_line(char *shell_name, char *exec_path, char **argv);
 
 typedef struct sub_process_t {
-	int sv_stdin[2];
-	int sv_stdout[2];
-	int sv_stderr[2];
+	intptr_t sv_stdin[2];
+	intptr_t sv_stdout[2];
+	intptr_t sv_stderr[2];
 	int using_pipes;
 	char *inp;
 	DWORD incnt;
@@ -40,7 +40,7 @@
 	volatile DWORD outcnt;
 	char * volatile errp;
 	volatile DWORD errcnt;
-	int pid;
+	intptr_t pid;
 	int exit_code;
 	int signal;
 	long last_err;
@@ -309,12 +309,12 @@
 		pproc->lerrno = E_SCALL;
 		return((HANDLE)pproc);
 	}
-	pproc->sv_stdin[0]  = (int) stdin_pipes[0];
-	pproc->sv_stdin[1]  = (int) stdin_pipes[1];
-	pproc->sv_stdout[0] = (int) stdout_pipes[0];
-	pproc->sv_stdout[1] = (int) stdout_pipes[1];
-	pproc->sv_stderr[0] = (int) stderr_pipes[0];
-	pproc->sv_stderr[1] = (int) stderr_pipes[1];
+	pproc->sv_stdin[0]  = (intptr_t) stdin_pipes[0];
+	pproc->sv_stdin[1]  = (intptr_t) stdin_pipes[1];
+	pproc->sv_stdout[0] = (intptr_t) stdout_pipes[0];
+	pproc->sv_stdout[1] = (intptr_t) stdout_pipes[1];
+	pproc->sv_stderr[0] = (intptr_t) stderr_pipes[0];
+	pproc->sv_stderr[1] = (intptr_t) stderr_pipes[1];
 
 	pproc->using_pipes = 1;
 
@@ -336,9 +336,9 @@
 	 * Just pass the provided file handles to the 'child side' of the
 	 * pipe, bypassing pipes altogether.
 	 */
-	pproc->sv_stdin[1]  = (int) stdinh;
-	pproc->sv_stdout[1] = (int) stdouth;
-	pproc->sv_stderr[1] = (int) stderrh;
+	pproc->sv_stdin[1]  = (intptr_t) stdinh;
+	pproc->sv_stdout[1] = (intptr_t) stdouth;
+	pproc->sv_stderr[1] = (intptr_t) stderrh;
 
 	pproc->last_err = pproc->lerrno = 0;
 
@@ -358,35 +358,35 @@
 	ext = fname + strlen(fname);
 
 	strcpy(ext, ".exe");
-	if ((exec_handle = (HANDLE)OpenFile(fname, file_info,
+	if ((exec_handle = (HANDLE)(intptr_t)OpenFile(fname, file_info,
 			OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR) {
 		free(fname);
 		return(exec_handle);
 	}
 
 	strcpy(ext, ".cmd");
-	if ((exec_handle = (HANDLE)OpenFile(fname, file_info,
+	if ((exec_handle = (HANDLE)(intptr_t)OpenFile(fname, file_info,
 			OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR) {
 		free(fname);
 		return(exec_handle);
 	}
 
 	strcpy(ext, ".bat");
-	if ((exec_handle = (HANDLE)OpenFile(fname, file_info,
+	if ((exec_handle = (HANDLE)(intptr_t)OpenFile(fname, file_info,
 			OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR) {
 		free(fname);
 		return(exec_handle);
 	}
 
 	/* should .com come before this case? */
-	if ((exec_handle = (HANDLE)OpenFile(exec_path, file_info,
+	if ((exec_handle = (HANDLE)(intptr_t)OpenFile(exec_path, file_info,
 			OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR) {
 		free(fname);
 		return(exec_handle);
 	}
 
 	strcpy(ext, ".com");
-	if ((exec_handle = (HANDLE)OpenFile(fname, file_info,
+	if ((exec_handle = (HANDLE)(intptr_t)OpenFile(fname, file_info,
 			OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR) {
 		free(fname);
 		return(exec_handle);
@@ -562,7 +562,7 @@
 		}
 	}
 
-	pproc->pid = (int)procInfo.hProcess;
+	pproc->pid = (intptr_t)procInfo.hProcess;
 	/* Close the thread handle -- we'll just watch the process */
 	CloseHandle(procInfo.hThread);
 
diff --git a/sources/host-tools/nawk-20071023/GNUmakefile b/sources/host-tools/nawk-20071023/GNUmakefile
index 4bef795..8c976aa 100644
--- a/sources/host-tools/nawk-20071023/GNUmakefile
+++ b/sources/host-tools/nawk-20071023/GNUmakefile
@@ -11,6 +11,7 @@
 BISON   := bison
 
 MINGW := $(strip $(WIN32))
+TRY64 := $(strip $(TRY64))
 
 ifeq ($(V),1)
 hide :=
@@ -30,7 +31,11 @@
 EXE :=
 
 ifdef MINGW
+ifdef TRY64
+CC      := x86_64-pc-mingw32msvc-gcc
+else
 CC      := i586-pc-mingw32msvc-gcc
+endif
 EXE     := .exe
 endif
 
diff --git a/sources/host-tools/nawk-20071023/parse.c b/sources/host-tools/nawk-20071023/parse.c
index 8304ded..4aca2d4 100644
--- a/sources/host-tools/nawk-20071023/parse.c
+++ b/sources/host-tools/nawk-20071023/parse.c
@@ -265,12 +265,12 @@
 	return -1;
 }
 
-int ptoi(void *p)	/* convert pointer to integer */
+intptr_t ptoi(void *p)	/* convert pointer to integer */
 {
-	return (int) (long) p;	/* swearing that p fits, of course */
+	return (intptr_t) p;
 }
 
-Node *itonp(int i)	/* and vice versa */
+Node *itonp(intptr_t i)	/* and vice versa */
 {
-	return (Node *) (long) i;
+	return (Node *) i;
 }
diff --git a/sources/host-tools/nawk-20071023/proto.h b/sources/host-tools/nawk-20071023/proto.h
index c5221ee..d97caa6 100644
--- a/sources/host-tools/nawk-20071023/proto.h
+++ b/sources/host-tools/nawk-20071023/proto.h
@@ -25,6 +25,8 @@
 /* To avoid conflicts with <stdio.h> getline declaration on Linux */
 #define getline awk_getline
 
+#include <stdint.h>
+
 extern	int	yywrap(void);
 extern	void	setfname(Cell *);
 extern	int	constnode(Node *);
@@ -93,8 +95,8 @@
 extern	int	isarg(const char *);
 extern	char	*tokname(int);
 extern	Cell	*(*proctab[])(Node **, int);
-extern	int	ptoi(void *);
-extern	Node	*itonp(int);
+extern	intptr_t ptoi(void *);
+extern	Node	*itonp(intptr_t);
 
 extern	void	syminit(void);
 extern	void	arginit(int, char **);
@@ -194,5 +196,12 @@
 extern	Cell	*sub(Node **, int);
 extern	Cell	*gsub(Node **, int);
 
+#if !defined(_WIN32)
+/* In mingw, the following are defined with dllimport attributes.
+  Redefining here will only get warning reads:
+
+  ... redeclared without dllimport attribute: previous dllimport ignored
+ */
 extern	FILE	*popen(const char *, const char *);
 extern	int	pclose(FILE *);
+#endif
\ No newline at end of file
diff --git a/sources/host-tools/sed-4.2.1/lib/regcomp.c b/sources/host-tools/sed-4.2.1/lib/regcomp.c
index a4e3f2d..7f25394 100644
--- a/sources/host-tools/sed-4.2.1/lib/regcomp.c
+++ b/sources/host-tools/sed-4.2.1/lib/regcomp.c
@@ -2563,7 +2563,7 @@
     old_tree = NULL;
 
   if (elem->token.type == SUBEXP)
-    postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
+    postorder (elem, mark_opt_subexp, (void *) (intptr_t) elem->token.opr.idx);
 
   tree = create_tree (dfa, elem, NULL,
 		      (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT));
@@ -3775,7 +3775,8 @@
 static reg_errcode_t
 mark_opt_subexp (void *extra, bin_tree_t *node)
 {
-  Idx idx = (Idx) (long) extra;
+  Idx idx = (Idx) (intptr_t) extra;
+  assert(sizeof(void*) >= sizeof(Idx));
   if (node->token.type == SUBEXP && node->token.opr.idx == idx)
     node->token.opt_subexp = 1;