Merge cherrypicks of [1816840] into ndk-release-r23.

Change-Id: I49056c5ecc099d5a4342d5f54b17793c1c7798d5
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..b22a816
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,99 @@
+# Copyright 2021 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+project(make)
+cmake_minimum_required(VERSION 3.18.1)
+
+add_executable(make
+  # make_SRCS
+  src/ar.c
+  src/arscan.c
+  src/commands.c
+  src/default.c
+  src/dir.c
+  src/expand.c
+  src/file.c
+  src/function.c
+  src/getopt.c
+  src/getopt1.c
+  src/guile.c
+  src/hash.c
+  src/implicit.c
+  src/job.c
+  src/load.c
+  src/loadapi.c
+  src/main.c
+  src/misc.c
+  src/output.c
+  src/read.c
+  src/remake.c
+  src/rule.c
+  src/signame.c
+  src/strcache.c
+  src/variable.c
+  src/version.c
+  src/vpath.c
+
+  # USE_CUSTOMS
+  src/remote-stub.c
+)
+
+target_compile_definitions(make PRIVATE -DHAVE_CONFIG_H)
+target_include_directories(make PRIVATE lib src)
+
+if(UNIX)
+  if(CMAKE_SYSTEM_NAME STREQUAL Linux)
+    target_include_directories(make PRIVATE soong/linux_glibc)
+    target_sources(make PRIVATE lib/getloadavg.c)
+    target_link_libraries(make PRIVATE -ldl)
+  elseif(APPLE)
+    target_include_directories(make PRIVATE soong/darwin)
+  endif()
+  target_compile_definitions(make PRIVATE
+    -DLOCALEDIR=NULL
+    -DINCLUDEDIR=0
+    -DLIBDIR=0
+  )
+  target_sources(make PRIVATE
+    src/posixos.c
+    lib/concat-filename.c
+    lib/exitfail.c
+    lib/fnmatch.c
+    lib/findprog-in.c
+    lib/glob.c
+    lib/xalloc-die.c
+    lib/xconcat-filename.c
+  )
+endif()
+
+if(WIN32)
+  target_include_directories(make PRIVATE
+    soong/windows
+    src/w32/include
+  )
+  target_compile_definitions(make PRIVATE -DWINDOWS32)
+  target_sources(make PRIVATE
+    src/w32/pathstuff.c
+    src/w32/w32os.c
+    src/w32/compat/posixfcn.c
+    src/w32/subproc/misc.c
+    src/w32/subproc/sub_proc.c
+    src/w32/subproc/w32err.c
+    lib/fnmatch.c
+    lib/glob.c
+    lib/getloadavg.c
+  )
+endif()
+
+install(TARGETS make)
diff --git a/soong/darwin/config.h b/soong/darwin/config.h
index 4bb01ba..675db66 100644
--- a/soong/darwin/config.h
+++ b/soong/darwin/config.h
@@ -1,6 +1,13 @@
 /* src/config.h.  Generated from config.h.in by configure.  */
 /* src/config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* ANDROID: The "CPU and C ABI indicator" section is generated by gnulib's
+   host-cpu-c-abi module and is incompatible with macOS universal builds, where
+   a single clang invocation preprocesses source files twice, once for each
+   architecture. The compiler already defines __x86_64__ or __arm64__ to 1, so
+   stop doing it here. (For Linux, Clang only defines __aarch64__, but Darwin
+   Clang defines __arm64__ too.) */
+
 /* CPU and C ABI indicator */
 #ifndef __i386__
 /* #undef __i386__ */
@@ -9,7 +16,7 @@
 /* #undef __x86_64_x32__ */
 #endif
 #ifndef __x86_64__
-#define __x86_64__ 1
+/* #undef __x86_64__ */
 #endif
 #ifndef __alpha__
 /* #undef __alpha__ */
diff --git a/soong/windows/NOTE.txt b/soong/windows/NOTE.txt
new file mode 100644
index 0000000..b5b7049
--- /dev/null
+++ b/soong/windows/NOTE.txt
@@ -0,0 +1,16 @@
+This directory was generated by imitating these lines in build_w32.bat:
+
+    if exist src\config.h.W32.template call :ConfigSCM
+    copy src\config.h.W32 %OUTDIR%\src\config.h
+
+    copy lib\glob.in.h %OUTDIR%\lib\glob.h
+    copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h
+
+config.h.W32.template has strings like:
+
+    %PACKAGE%
+    %PACKAGE_VERSION%
+    %VERSION%
+
+These need to be replaced with their real values. See the other config.h files
+for examples.
diff --git a/soong/windows/config.h b/soong/windows/config.h
new file mode 100644
index 0000000..aa548cc
--- /dev/null
+++ b/soong/windows/config.h
@@ -0,0 +1,558 @@
+/* config.h.W32 -- hand-massaged config.h file for Windows builds       -*-C-*-
+
+Copyright (C) 1996-2020 Free Software Foundation, Inc.
+This file is part of GNU Make.
+
+GNU Make 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 3 of the License, or (at your option) any later
+version.
+
+GNU Make 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Suppress some Visual C++ warnings.
+   Maybe after the code cleanup for ISO C we can remove some/all of these.  */
+#if _MSC_VER > 1000
+# pragma warning(disable:4100) /* unreferenced formal parameter */
+# pragma warning(disable:4102) /* unreferenced label */
+# pragma warning(disable:4127) /* conditional expression is constant */
+# pragma warning(disable:4131) /* uses old-style declarator */
+# pragma warning(disable:4702) /* unreachable code */
+# define _CRT_SECURE_NO_WARNINGS  /* function or variable may be unsafe */
+# define _CRT_NONSTDC_NO_WARNINGS /* functions w/o a leading underscore */
+#endif
+
+/* Define to 1 if the 'closedir' function returns void instead of 'int'. */
+/* #undef CLOSEDIR_VOID */
+
+/* Define to one of '_getb67', 'GETB67', 'getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for 'alloca.c' support on those systems.
+   */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define to 1 if using 'alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define to 1 if using 'getloadavg.c'. */
+#define C_GETLOADAVG 1
+
+/* Define to 1 for DGUX with <sys/dg_sys_info.h>. */
+/* #undef DGUX */
+
+/* Define to 1 if translation of program messages to the user's native
+   language is requested. */
+/* #undef ENABLE_NLS */
+
+/* Use high resolution file timestamps if nonzero. */
+#define FILE_TIMESTAMP_HI_RES 0
+
+/* Define to 1 if the 'getloadavg' function needs to be run setuid or setgid.
+   */
+/* #undef GETLOADAVG_PRIVILEGED */
+
+/* Define to 1 if you have 'alloca', as a function or macro. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+/* #undef HAVE_ALLOCA_H */
+
+/* Define to 1 if you have the 'atexit' function. */
+#define HAVE_ATEXIT 1
+
+/* Use case insensitive file names */
+/* #undef HAVE_CASE_INSENSITIVE_FS */
+
+/* Define to 1 if you have the clock_gettime function. */
+/* #undef HAVE_CLOCK_GETTIME */
+
+/* Embed GNU Guile support.  Windows build sets this on the
+   compilation command line.  */
+/* #undef HAVE_GUILE */
+
+/* Define if the GNU dcgettext() function is already present or preinstalled.
+   */
+/* #undef HAVE_DCGETTEXT */
+
+/* Define to 1 if you have the declaration of 'bsd_signal', and to 0 if you
+   don't. */
+#define HAVE_DECL_BSD_SIGNAL 0
+
+/* Define to 1 if you have the declaration of 'sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL_SYS_SIGLIST 0
+
+/* Define to 1 if you have the declaration of '_sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL__SYS_SIGLIST 0
+
+/* Define to 1 if you have the declaration of '__sys_siglist', and to 0 if you
+   don't. */
+#define HAVE_DECL___SYS_SIGLIST 0
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines 'DIR'.
+   */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <direct.h> header file, and it defines getcwd()
+   and chdir().
+   */
+#if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TINYC__)) && !defined(__INTERIX)
+# define HAVE_DIRECT_H 1
+#endif
+
+/* Use platform specific coding */
+#define HAVE_DOS_PATHS 1
+
+/* Define to 1 if you have the 'dup2' function. */
+#define HAVE_DUP2 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the 'fdopen' function. */
+#ifdef __MINGW32__
+#define HAVE_FDOPEN 1
+#endif
+
+/* Define to 1 if you have the 'fileno' function. */
+#define HAVE_FILENO 1
+
+/* Define to 1 if you have the 'getcwd' function.  */
+#define HAVE_GETCWD 1
+
+/* Define to 1 if you have the 'getgroups' function. */
+/* #undef HAVE_GETGROUPS */
+
+/* Define to 1 if you have the 'gethostbyname' function. */
+/* #undef HAVE_GETHOSTBYNAME */
+
+/* Define to 1 if you have the 'gethostname' function. */
+/* #undef HAVE_GETHOSTNAME */
+
+/* Define to 1 if you have the 'getloadavg' function. */
+/* #undef HAVE_GETLOADAVG */
+
+/* Define to 1 if you have the 'getrlimit' function. */
+/* #undef HAVE_GETRLIMIT */
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+/* #undef HAVE_GETTEXT */
+
+/* Define to 1 if you have a standard gettimeofday function */
+#ifdef __MINGW32__
+#define HAVE_GETTIMEOFDAY 1
+#endif
+
+/* Define if you have the iconv() function. */
+/* #undef HAVE_ICONV */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_INTTYPES_H 1
+#endif
+
+/* Define to 1 if you have the 'dgc' library (-ldgc). */
+/* #undef HAVE_LIBDGC */
+
+/* Define to 1 if you have the 'kstat' library (-lkstat). */
+/* #undef HAVE_LIBKSTAT */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+/*#define HAVE_LOCALE_H 1*/
+
+/* Define to 1 if you have the 'lstat' function. */
+/* #undef HAVE_LSTAT */
+
+/* Define to 1 if you have the <mach/mach.h> header file. */
+/* #undef HAVE_MACH_MACH_H */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the 'mkstemp' function. */
+/* #undef HAVE_MKSTEMP */
+
+/* Define to 1 if you have the 'mktemp' function. */
+#define HAVE_MKTEMP 1
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines 'DIR'. */
+/* #undef HAVE_NDIR_H */
+
+/* Define to 1 if you have the <nlist.h> header file. */
+/* #undef HAVE_NLIST_H */
+
+/* Define to 1 if you have the 'pipe' function. */
+/* #undef HAVE_PIPE */
+
+/* Define to 1 if you have the 'pstat_getdynamic' function. */
+/* #undef HAVE_PSTAT_GETDYNAMIC */
+
+/* Define to 1 if you have the 'readlink' function. */
+/* #undef HAVE_READLINK */
+
+/* Define to 1 if you have the 'realpath' function. */
+/* #undef HAVE_REALPATH */
+
+/* Define to 1 if <signal.h> defines the SA_RESTART constant. */
+/* #undef HAVE_SA_RESTART */
+
+/* Define to 1 if you have the 'setegid' function. */
+/* #undef HAVE_SETEGID */
+
+/* Define to 1 if you have the 'seteuid' function. */
+/* #undef HAVE_SETEUID */
+
+/* Define to 1 if you have the 'setlinebuf' function. */
+/* #undef HAVE_SETLINEBUF */
+
+/* Define to 1 if you have the 'setlocale' function. */
+/*#define HAVE_SETLOCALE 1*/
+
+/* Define to 1 if you have the 'setregid' function. */
+/* #undef HAVE_SETREGID */
+
+/* Define to 1 if you have the 'setreuid' function. */
+/* #undef HAVE_SETREUID */
+
+/* Define to 1 if you have the 'setrlimit' function. */
+/* #undef HAVE_SETRLIMIT */
+
+/* Define to 1 if you have the 'setvbuf' function. */
+#define HAVE_SETVBUF 1
+
+/* Define to 1 if you have the 'sigaction' function. */
+/* #undef HAVE_SIGACTION */
+
+/* Define to 1 if you have the 'sigsetmask' function. */
+/* #undef HAVE_SIGSETMASK */
+
+/* Define to 1 if you have the 'socket' function. */
+/* #undef HAVE_SOCKET */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_STDINT_H 1
+#endif
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the 'strcasecmp' function. */
+#if defined(__MINGW32__) || defined(__TINYC__)
+#define HAVE_STRCASECMP 1
+#endif
+
+/* Define to 1 if you have the 'strcmpi' function. */
+#define HAVE_STRCMPI 1
+
+/* Define to 1 if you have the 'strcoll' function and it is properly defined.
+   */
+#define HAVE_STRCOLL 1
+
+/* Define to 1 if you have the 'strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the 'stricmp' function. */
+#define HAVE_STRICMP 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_STRINGS_H 1
+#endif
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the 'strncasecmp' function. */
+#if defined(__MINGW32__) || defined(__TINYC__)
+#define HAVE_STRNCASECMP 1
+#endif
+
+/* Define to 1 if you have the 'strncmpi' function. */
+/* #undef HAVE_STRNCMPI */
+
+/* Define to 1 if you have the 'strndup' function. */
+/* #undef HAVE_STRNDUP */
+
+/* Define to 1 if you have the 'strnicmp' function. */
+#ifdef __MINGW32__
+#define HAVE_STRNICMP 1
+#endif
+
+/* Define to 1 if you have the 'strsignal' function. */
+/* #undef HAVE_STRSIGNAL */
+
+/* Define to 1 if `d_type' is a member of `struct dirent'. */
+/* SV 57152: MinGW64 version of dirent doesn't support d_type. */
+#ifndef __MINGW64__
+# define HAVE_STRUCT_DIRENT_D_TYPE 1
+#endif
+
+/* Define to 1 if you have the `isatty' function. */
+#define HAVE_ISATTY 1
+
+/* Define to 1 if you have the `ttyname' function. */
+#define HAVE_TTYNAME 1
+char *ttyname (int);
+
+/* Define to 1 if you have the `umask' function. */
+#if defined(__MINGW32__) || defined(__TINYC__)
+# define HAVE_UMASK 1
+#endif
+
+/* Define to 1 if 'n_un.n_name' is a member of 'struct nlist'. */
+/* #undef HAVE_STRUCT_NLIST_N_UN_N_NAME */
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines 'DIR'.
+   */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines 'DIR'.
+   */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_SYS_PARAM_H 1
+#endif
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+/* #undef HAVE_SYS_RESOURCE_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+#define HAVE_SYS_TIMEB_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_SYS_TIME_H 1
+#endif
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+/* #undef HAVE_SYS_WAIT_H */
+
+/* Define to 1 if you have the \'union wait' type in <sys/wait.h>. */
+/* #undef HAVE_UNION_WAIT */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#ifdef __MINGW32__
+#define HAVE_UNISTD_H 1
+#endif
+
+/* Define to 1 if you have the 'wait3' function. */
+/* #undef HAVE_WAIT3 */
+
+/* Define to 1 if you have the 'waitpid' function. */
+/* #undef HAVE_WAITPID */
+
+/* Build host information. */
+#define MAKE_HOST "Windows32"
+
+/* Define to 1 to enable job server support in GNU make. */
+#define MAKE_JOBSERVER 1
+
+/* Define to 1 to enable 'load' support in GNU make. */
+#define MAKE_LOAD 1
+
+/* Define to 1 to enable symbolic link timestamp checking. */
+/* #undef MAKE_SYMLINKS */
+
+/* Define to 1 if your 'struct nlist' has an 'n_un' member. Obsolete, depend
+   on 'HAVE_STRUCT_NLIST_N_UN_N_NAME */
+/* #undef NLIST_NAME_UNION */
+
+/* Define to 1 if struct nlist.n_name is a pointer rather than an array. */
+/* #undef NLIST_STRUCT */
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+/* #undef NO_MINUS_C_MINUS_O */
+
+/* Name of this package (needed by automake) */
+#define PACKAGE "make"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-make@gnu.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "GNU make"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://www.gnu.org/software/make/"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.3"
+
+/* Define to the character that separates directories in PATH. */
+#define PATH_SEPARATOR_CHAR ';'
+
+/* Define as the return type of signal handlers ('int' or 'void'). */
+#define RETSIGTYPE void
+
+/* Define to the name of the SCCS 'get' command. */
+#define SCCS_GET "echo no sccs get"
+
+/* Define this if the SCCS 'get' command understands the '-G<file>' option. */
+/* #undef SCCS_GET_MINUS_G */
+
+/* Define to 1 if the 'setvbuf' function takes the buffering type as its
+   second argument and the buffer pointer as the third, as on System V before
+   release 3. */
+/* #undef SETVBUF_REVERSED */
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run time.
+        STACK_DIRECTION > 0 => grows toward higher addresses
+        STACK_DIRECTION < 0 => grows toward lower addresses
+        STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if the 'S_IS*' macros in <sys/stat.h> do not work properly. */
+/* #undef STAT_MACROS_BROKEN */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define if struct stat contains a nanoseconds field */
+/* #undef ST_MTIM_NSEC */
+
+/* Define to 1 on System V Release 4. */
+/* #undef SVR4 */
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#ifdef __MINGW32__
+#define TIME_WITH_SYS_TIME 1
+#endif
+
+/* Define to 1 for Encore UMAX. */
+/* #undef UMAX */
+
+/* Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h> instead of
+   <sys/cpustats.h>. */
+/* #undef UMAX4_3 */
+
+/* Version number of package */
+#define VERSION "4.3"
+
+/* Define if using the dmalloc debugging malloc package */
+/* #undef WITH_DMALLOC */
+
+/* Define to 1 if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+/* # undef _ALL_SOURCE */
+#endif
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+/* #  undef WORDS_BIGENDIAN */
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+   this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for 'stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define to empty if 'const' does not conform to ANSI C. */
+/* #undef const */
+
+#ifdef __MINGW32__
+# undef __USE_MINGW_ANSI_STDIO
+# define __USE_MINGW_ANSI_STDIO 1
+#endif
+
+#include <sys/types.h>
+
+/* Define to 'int' if <sys/types.h> doesn't define. */
+#define gid_t int
+
+/* Define to 'int' if <sys/types.h> does not define. */
+/* GCC 4.x reportedly defines pid_t.  */
+#ifndef _PID_T_
+#ifdef _WIN64
+#define pid_t __int64
+#else
+#define pid_t int
+#endif
+#endif
+
+/* Define to `int' if <sys/types.h> does not define. */
+#define ssize_t int
+
+/* Define to 'int' if <sys/types.h> doesn't define. */
+#define uid_t int
+
+/* Define uintmax_t if not defined in <stdint.h> or <inttypes.h>. */
+#if !HAVE_STDINT_H && !HAVE_INTTYPES_H
+#define uintmax_t unsigned long
+#endif
+
+/* Define if you have <sys/wait.h> that is POSIX.1 compatible.  */
+/* #undef HAVE_SYS_WAIT_H */
+
+/* Define to the installation directory for locales.  */
+#define LOCALEDIR ""
+
+/*
+ * Refer to README.W32 for info on the following settings
+ */
+
+
+/*
+ * If you have a shell that does not grok 'sh -c quoted-command-line'
+ * correctly, you need this setting; it is the default for tcc.
+ * Please see below for specific shell support.
+ */
+#if defined(__TINYC__)
+#define BATCH_MODE_ONLY_SHELL 1
+#else
+/*#define BATCH_MODE_ONLY_SHELL 1 */
+#endif
+
+/*
+ * Define if you have the Cygnus "Cygwin" GNU Windows32 tool set.
+ * Do NOT define BATCH_MODE_ONLY_SHELL if you define HAVE_CYGWIN_SHELL
+ */
+/*#define HAVE_CYGWIN_SHELL 1 */
+
+/*
+ * Define if you have the MKS tool set or shell. Do NOT define
+ * BATCH_MODE_ONLY_SHELL if you define HAVE_MKS_SHELL
+ */
+/*#define HAVE_MKS_SHELL 1 */
+
+/*
+ * Enforce the mutual exclusivity restriction.
+ */
+#ifdef HAVE_MKS_SHELL
+#undef BATCH_MODE_ONLY_SHELL
+#endif
+
+#ifdef HAVE_CYGWIN_SHELL
+#undef BATCH_MODE_ONLY_SHELL
+#endif
diff --git a/soong/windows/fnmatch.h b/soong/windows/fnmatch.h
new file mode 100644
index 0000000..a788c8e
--- /dev/null
+++ b/soong/windows/fnmatch.h
@@ -0,0 +1,85 @@
+/* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999 Free Software
+Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with this library; see the file COPYING.LIB.  If not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA.  */
+
+#ifndef	_FNMATCH_H
+#define	_FNMATCH_H	1
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
+# if !defined __GLIBC__
+#  undef	__P
+#  define __P(protos)	protos
+# endif
+#else /* Not C++ or ANSI C.  */
+# undef	__P
+# define __P(protos)	()
+/* We can get away without defining `const' here only because in this file
+   it is used only inside the prototype for `fnmatch', which is elided in
+   non-ANSI C where `const' is problematical.  */
+#endif /* C++ or ANSI C.  */
+
+#ifndef const
+# if (defined __STDC__ && __STDC__) || defined __cplusplus || defined WINDOWS32
+#  define __const	const
+# else
+#  define __const
+# endif
+#endif
+
+/* We #undef these before defining them because some losing systems
+   (HP-UX A.08.07 for example) define these in <unistd.h>.  */
+#undef	FNM_PATHNAME
+#undef	FNM_NOESCAPE
+#undef	FNM_PERIOD
+
+/* Bits set in the FLAGS argument to `fnmatch'.  */
+#define	FNM_PATHNAME	(1 << 0) /* No wildcard can ever match `/'.  */
+#define	FNM_NOESCAPE	(1 << 1) /* Backslashes don't quote special chars.  */
+#define	FNM_PERIOD	(1 << 2) /* Leading `.' is matched only explicitly.  */
+
+#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE
+# define FNM_FILE_NAME	 FNM_PATHNAME	/* Preferred GNU name.  */
+# define FNM_LEADING_DIR (1 << 3)	/* Ignore `/...' after a match.  */
+# define FNM_CASEFOLD	 (1 << 4)	/* Compare without regard to case.  */
+#endif
+
+/* Value returned by `fnmatch' if STRING does not match PATTERN.  */
+#define	FNM_NOMATCH	1
+
+/* This value is returned if the implementation does not support
+   `fnmatch'.  Since this is not the case here it will never be
+   returned but the conformance test suites still require the symbol
+   to be defined.  */
+#ifdef _XOPEN_SOURCE
+# define FNM_NOSYS	(-1)
+#endif
+
+/* Match NAME against the filename pattern PATTERN,
+   returning zero if it matches, FNM_NOMATCH if not.  */
+extern int fnmatch __P ((__const char *__pattern, __const char *__name,
+			 int __flags));
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif /* fnmatch.h */
diff --git a/soong/windows/glob.h b/soong/windows/glob.h
new file mode 100644
index 0000000..0992de3
--- /dev/null
+++ b/soong/windows/glob.h
@@ -0,0 +1,210 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997, 1998 Free Software Foundation,
+Inc.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with this library; see the file COPYING.LIB.  If not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA.  */
+
+#ifndef	_GLOB_H
+#define	_GLOB_H	1
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#undef	__ptr_t
+#if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
+# if !defined __GLIBC__
+#  undef __P
+#  undef __PMT
+#  define __P(protos)	protos
+#  define __PMT(protos)	protos
+#  if !defined __GNUC__ || __GNUC__ < 2
+#   undef __const
+#   define __const const
+#  endif
+# endif
+# define __ptr_t	void *
+#else /* Not C++ or ANSI C.  */
+# undef	__P
+# undef __PMT
+# define __P(protos)	()
+# define __PMT(protos)	()
+# undef	__const
+# define __const
+# define __ptr_t	char *
+#endif /* C++ or ANSI C.  */
+
+/* We need `size_t' for the following definitions.  */
+#ifndef __size_t
+# if defined __FreeBSD__
+#  define __size_t size_t
+# else
+#  if defined __GNUC__ && __GNUC__ >= 2
+typedef __SIZE_TYPE__ __size_t;
+#  else
+/* This is a guess.  */
+/*hb
+ *	Conflicts with DECCs already defined type __size_t.
+ *	Defining an own type with a name beginning with '__' is no good.
+ *	Anyway if DECC is used and __SIZE_T is defined then __size_t is
+ *	already defined (and I hope it's exactly the one we need here).
+ */
+#   if !(defined __DECC && defined __SIZE_T)
+typedef unsigned long int __size_t;
+#   endif
+#  endif
+# endif
+#else
+/* The GNU CC stddef.h version defines __size_t as empty.  We need a real
+   definition.  */
+# undef __size_t
+# define __size_t size_t
+#endif
+
+/* Bits set in the FLAGS argument to `glob'.  */
+#define	GLOB_ERR	(1 << 0)/* Return on read errors.  */
+#define	GLOB_MARK	(1 << 1)/* Append a slash to each name.  */
+#define	GLOB_NOSORT	(1 << 2)/* Don't sort the names.  */
+#define	GLOB_DOOFFS	(1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
+#define	GLOB_NOCHECK	(1 << 4)/* If nothing matches, return the pattern.  */
+#define	GLOB_APPEND	(1 << 5)/* Append to results of a previous call.  */
+#define	GLOB_NOESCAPE	(1 << 6)/* Backslashes don't quote metacharacters.  */
+#define	GLOB_PERIOD	(1 << 7)/* Leading `.' can be matched by metachars.  */
+
+#if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
+     || defined _GNU_SOURCE)
+# define GLOB_MAGCHAR	 (1 << 8)/* Set in gl_flags if any metachars seen.  */
+# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
+# define GLOB_BRACE	 (1 << 10)/* Expand "{a,b}" to "a" "b".  */
+# define GLOB_NOMAGIC	 (1 << 11)/* If no magic chars, return the pattern.  */
+# define GLOB_TILDE	 (1 << 12)/* Expand ~user and ~ to home directories. */
+# define GLOB_ONLYDIR	 (1 << 13)/* Match only directories.  */
+# define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
+				      if the user name is not available.  */
+# define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
+			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
+			 GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE|     \
+			 GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
+#else
+# define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
+			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
+			 GLOB_PERIOD)
+#endif
+
+/* Error returns from `glob'.  */
+#define	GLOB_NOSPACE	1	/* Ran out of memory.  */
+#define	GLOB_ABORTED	2	/* Read error.  */
+#define	GLOB_NOMATCH	3	/* No matches found.  */
+#define GLOB_NOSYS	4	/* Not implemented.  */
+#ifdef _GNU_SOURCE
+/* Previous versions of this file defined GLOB_ABEND instead of
+   GLOB_ABORTED.  Provide a compatibility definition here.  */
+# define GLOB_ABEND GLOB_ABORTED
+#endif
+
+/* Structure describing a globbing run.  */
+#if !defined _AMIGA && !defined VMS /* Buggy compiler.   */
+struct stat;
+#endif
+typedef struct
+  {
+    __size_t gl_pathc;		/* Count of paths matched by the pattern.  */
+    char **gl_pathv;		/* List of matched pathnames.  */
+    __size_t gl_offs;		/* Slots to reserve in `gl_pathv'.  */
+    int gl_flags;		/* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
+
+    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+       are used instead of the normal file access functions.  */
+    void (*gl_closedir) __PMT ((void *));
+    struct dirent *(*gl_readdir) __PMT ((void *));
+    __ptr_t (*gl_opendir) __PMT ((__const char *));
+    int (*gl_lstat) __PMT ((__const char *, struct stat *));
+#if defined(VMS) && defined(__DECC) && !defined(_POSIX_C_SOURCE)
+    int (*gl_stat) __PMT ((__const char *, struct stat *, ...));
+#else
+    int (*gl_stat) __PMT ((__const char *, struct stat *));
+#endif
+  } glob_t;
+
+#ifdef _LARGEFILE64_SOURCE
+struct stat64;
+typedef struct
+  {
+    __size_t gl_pathc;
+    char **gl_pathv;
+    __size_t gl_offs;
+    int gl_flags;
+
+    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+       are used instead of the normal file access functions.  */
+    void (*gl_closedir) __PMT ((void *));
+    struct dirent64 *(*gl_readdir) __PMT ((void *));
+    __ptr_t (*gl_opendir) __PMT ((__const char *));
+    int (*gl_lstat) __PMT ((__const char *, struct stat64 *));
+    int (*gl_stat) __PMT ((__const char *, struct stat64 *));
+  } glob64_t;
+#endif
+
+#if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2
+# define glob glob64
+# define globfree globfree64
+#else
+# ifdef _LARGEFILE64_SOURCE
+extern int glob64 __P ((__const char *__pattern, int __flags,
+			int (*__errfunc) (__const char *, int),
+			glob64_t *__pglob));
+
+extern void globfree64 __P ((glob64_t *__pglob));
+# endif
+#endif
+
+/* Do glob searching for PATTERN, placing results in PGLOB.
+   The bits defined above may be set in FLAGS.
+   If a directory cannot be opened or read and ERRFUNC is not nil,
+   it is called with the pathname that caused the error, and the
+   `errno' value from the failing call; if it returns non-zero
+   `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
+   If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
+   Otherwise, `glob' returns zero.  */
+#if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2
+extern int glob __P ((__const char *__pattern, int __flags,
+		      int (*__errfunc) (__const char *, int),
+		      glob_t *__pglob));
+
+/* Free storage allocated in PGLOB by a previous `glob' call.  */
+extern void globfree __P ((glob_t *__pglob));
+#else
+extern int glob __P ((__const char *__pattern, int __flags,
+		      int (*__errfunc) (__const char *, int),
+		      glob_t *__pglob)) __asm__ ("glob64");
+
+extern void globfree __P ((glob_t *__pglob)) __asm__ ("globfree64");
+#endif
+
+
+#ifdef _GNU_SOURCE
+/* Return nonzero if PATTERN contains any metacharacters.
+   Metacharacters can be quoted with backslashes if QUOTE is nonzero.
+
+   This function is not part of the interface specified by POSIX.2
+   but several programs want to use it.  */
+extern int glob_pattern_p __P ((__const char *__pattern, int __quote));
+#endif
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif /* glob.h  */