Index: trunk/src/kmk/default.c
===================================================================
--- trunk/src/kmk/default.c	(revision 2591)
+++ trunk/src/kmk/default.c	(revision 3140)
@@ -1,6 +1,4 @@
 /* Data base of default implicit rules for GNU Make.
-Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-2010 Free Software Foundation, Inc.
+Copyright (C) 1988-2016 Free Software Foundation, Inc.
 This file is part of GNU Make.
 
@@ -17,5 +15,8 @@
 this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "make.h"
+#include "makeint.h"
+
+#include <assert.h>
+
 #include "filedef.h"
 #include "variable.h"
@@ -33,13 +34,15 @@
 
 /* This is the default list of suffixes for suffix rules.
-   `.s' must come last, so that a `.o' file will be made from
-   a `.c' or `.p' or ... file rather than from a .s file.  */
+   '.s' must come last, so that a '.o' file will be made from
+   a '.c' or '.p' or ... file rather than from a .s file.  */
 
 static char default_suffixes[]
 #ifndef CONFIG_NO_DEFAULT_SUFFIXES
 #ifdef VMS
-  = ".exe .olb .ln .obj .c .cxx .cc .pas .p .for .f .r .y .l .mar \
-.s .ss .i .ii .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
-.w .ch .cweb .web .com .sh .elc .el";
+  /* VMS should include all UNIX/POSIX + some VMS extensions */
+  = ".out .exe .a .olb .hlb .tlb .mlb .ln .o .obj .c .cxx .cc .cpp .pas .p \
+.for .f .r .y .l .ym .yl .mar .s .ss .i .ii .mod .sym .def .h .info .dvi \
+.tex .texinfo .texi .txinfo .mem .hlp .brn .rnh .rno .rnt .rnx .w .ch .cweb \
+.web .com .sh .elc .el";
 #elif defined(__EMX__)
   = ".out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S \
@@ -58,22 +61,38 @@
   {
 #ifndef CONFIG_NO_DEFAULT_PATTERN_RULES
+#ifdef VMS
     { "(%)", "%",
-	"$(AR) $(ARFLAGS) $@ $<" },
-
+        "@if f$$search(\"$@\") .eqs. \"\" then $(LIBRARY)/CREATE/"
+         "$(or "
+          "$(patsubst %,TEXT,$(filter %.tlb %.TLB,$@)),"
+          "$(patsubst %,HELP,$(filter %.hlb %.HLB,$@)),"
+          "$(patsubst %,MACRO,$(filter %.mlb %.MLB,$@)),"
+          "$(and "
+           "$(patsubst %,SHARE,$(filter %.olb %.OLB,$@)),"
+           "$(patsubst %,SHARE,$(filter %.exe %.EXE,$<))),"
+          "OBJECT)"
+         " $@\n"
+        "$(AR) $(ARFLAGS) $@ $<" },
+
+#else
+    { "(%)", "%",
+        "$(AR) $(ARFLAGS) $@ $<" },
+#endif
     /* The X.out rules are only in BSD's default set because
-       BSD Make has no null-suffix rules, so `foo.out' and
-       `foo' are the same thing.  */
+       BSD Make has no null-suffix rules, so 'foo.out' and
+       'foo' are the same thing.  */
 #ifdef VMS
     { "%.exe", "%",
-        "copy $< $@" },
-#else
+        "$(CP) $< $@" },
+
+#endif
     { "%.out", "%",
-	"@rm -f $@ \n cp $< $@" },
-#endif
+        "@rm -f $@ \n cp $< $@" },
+
     /* Syntax is "ctangle foo.w foo.ch foo.c".  */
     { "%.c", "%.w %.ch",
-	"$(CTANGLE) $^ $@" },
+        "$(CTANGLE) $^ $@" },
     { "%.tex", "%.w %.ch",
-	"$(CWEAVE) $^ $@" },
+        "$(CWEAVE) $^ $@" },
 #endif /* !CONFIG_NO_DEFAULT_PATTERN_RULES */
     { 0, 0, 0 }
@@ -84,30 +103,32 @@
 #ifndef CONFIG_NO_DEFAULT_TERMINAL_RULES
 #ifdef VMS
+
     /* RCS.  */
     { "%", "%$$5lv", /* Multinet style */
-        "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
+        "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" },
     { "%", "[.$$rcs]%$$5lv", /* Multinet style */
-        "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
+        "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" },
     { "%", "%_v", /* Normal style */
-        "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
+        "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" },
     { "%", "[.rcs]%_v", /* Normal style */
-        "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
+        "if f$$search(\"$@\") .nes. \"\" then +$(CHECKOUT,v)" },
 
     /* SCCS.  */
-	/* ain't no SCCS on vms */
+        /* ain't no SCCS on vms */
+
 #else
     /* RCS.  */
     { "%", "%,v",
-	"$(CHECKOUT,v)" },
+        "$(CHECKOUT,v)" },
     { "%", "RCS/%,v",
-	"$(CHECKOUT,v)" },
+        "$(CHECKOUT,v)" },
     { "%", "RCS/%",
-	"$(CHECKOUT,v)" },
+        "$(CHECKOUT,v)" },
 
     /* SCCS.  */
     { "%", "s.%",
-	"$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
+        "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
     { "%", "SCCS/s.%",
-	"$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
+        "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
 #endif /* !VMS */
 #endif /* !CONFIG_NO_DEFAULT_TERMINAL_RULES */
@@ -115,12 +136,49 @@
   };
 
-static char *default_suffix_rules[] =
+static const char *default_suffix_rules[] =
   {
 #ifndef CONFIG_NO_DEFAULT_SUFFIX_RULES
 #ifdef VMS
+    ".o",
+    "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".obj",
+    "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".s",
+    "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".S",
+    "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".c",
+    "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".cc",
+    "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".C",
+    "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".cpp",
+    "$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".f",
+    "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".m",
+    "$(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".p",
+    "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".F",
+    "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".r",
+    "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
+    ".mod",
+    "$(COMPILE.mod) -o $@ -e $@ $^",
+
+    ".def.sym",
+    "$(COMPILE.def) -o $@ $<",
+
+    ".sh",
+    "copy $< >$@",
+
     ".obj.exe",
     "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@",
     ".mar.exe",
     "$(COMPILE.mar) $^ \n $(LINK.obj) $(subst .mar,.obj,$^) $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@",
+    ".s.o",
+    "$(COMPILE.s) -o $@ $<",
     ".s.exe",
     "$(COMPILE.s) $^ \n $(LINK.obj) $(subst .s,.obj,$^) $(LOADLIBES) $(LDLIBS) $(CRT0) /exe=$@",
@@ -157,4 +215,6 @@
     ".c.obj",
     "$(COMPILE.c) /obj=$@ $<",
+    ".c.o",
+    "$(COMPILE.c) /obj=$@ $<",
     ".cc.ii",
     "$(COMPILE.cc)/prep /list=$@ $<",
@@ -165,9 +225,17 @@
     ".cc.obj",
     "$(COMPILE.cc) /obj=$@ $<",
+    ".cc.o",
+    "$(COMPILE.cc) /obj=$@ $<",
     ".cxx.obj",
+    "$(COMPILE.cxx) /obj=$@ $<",
+    ".cxx.o",
     "$(COMPILE.cxx) /obj=$@ $<",
     ".for.obj",
     "$(COMPILE.for) /obj=$@ $<",
+    ".for.o",
+    "$(COMPILE.for) /obj=$@ $<",
     ".pas.obj",
+    "$(COMPILE.pas) /obj=$@ $<",
+    ".pas.o",
     "$(COMPILE.pas) /obj=$@ $<",
 
@@ -182,4 +250,25 @@
     ".tex.dvi",
     "$(TEX) $<",
+
+    ".cpp.o",
+    "$(COMPILE.cpp) $(OUTPUT_OPTION) $<",
+    ".f.o",
+    "$(COMPILE.f) $(OUTPUT_OPTION) $<",
+    ".m.o",
+    "$(COMPILE.m) $(OUTPUT_OPTION) $<",
+    ".p.o",
+    "$(COMPILE.p) $(OUTPUT_OPTION) $<",
+    ".r.o",
+    "$(COMPILE.r) $(OUTPUT_OPTION) $<",
+    ".mod.o",
+    "$(COMPILE.mod) -o $@ $<",
+
+    ".c.ln",
+    "$(LINT.c) -C$* $<",
+    ".y.ln",
+    "$(YACC.y) $< \n rename y_tab.c $@",
+
+    ".l.ln",
+    "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
 
 #else /* ! VMS */
@@ -302,5 +391,5 @@
 
     ".w.c",
-    "$(CTANGLE) $< - $@",	/* The `-' says there is no `.ch' file.  */
+    "$(CTANGLE) $< - $@",       /* The '-' says there is no '.ch' file.  */
 
     ".web.p",
@@ -308,5 +397,5 @@
 
     ".w.tex",
-    "$(CWEAVE) $< - $@",	/* The `-' says there is no `.ch' file.  */
+    "$(CWEAVE) $< - $@",        /* The '-' says there is no '.ch' file.  */
 
     ".web.tex",
@@ -331,5 +420,6 @@
     "ARCH", "VAX",
 #endif
-    "AR", "library/obj",
+    "AR", "library",
+    "LIBRARY", "library",
     "ARFLAGS", "/replace",
     "AS", "macro",
@@ -341,6 +431,5 @@
 #endif
     "CD", "builtin_cd",
-    "MAKE", "make",
-    "ECHO", "write sys$$output \"",
+    "ECHO", "builtin_echo",
 #ifdef GCC_IS_NATIVE
     "C++", "gcc/plus",
@@ -349,5 +438,12 @@
     "C++", "cxx",
     "CXX", "cxx",
+#ifndef __ia64
     "CXXLD", "cxxlink",
+    "CXXLINK", "cxxlink",
+#else
+    /* CXXLINK is not used on VMS/IA64 */
+    "CXXLD", "link",
+    "CXXLINK", "link",
+#endif
 #endif
     "CO", "co",
@@ -385,4 +481,5 @@
 #endif
 
+    "LINK.o", "$(LD) $(LDFLAGS)",
     "LINK.obj", "$(LD) $(LDFLAGS)",
 #ifndef GCC_IS_NATIVE
@@ -391,15 +488,40 @@
 #endif
     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
+    "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
+    "COMPILE.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
+    "LINK.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
+    "COMPILE.C", "$(COMPILE.cc)",
+    "COMPILE.cpp", "$(COMPILE.cc)",
+    "LINK.C", "$(LINK.cc)",
+    "LINK.cpp", "$(LINK.cc)",
     "YACC.y", "$(YACC) $(YFLAGS)",
     "LEX.l", "$(LEX) $(LFLAGS)",
+    "YACC.m", "$(YACC) $(YFLAGS)",
+    "LEX.m", "$(LEX) $(LFLAGS) -t",
     "COMPILE.for", "$(FC) $(FFLAGS) $(TARGET_ARCH)",
+    "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
+    "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
+    "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
+    "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
+    "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
+    "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     "COMPILE.pas", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
+    "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
+    "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
+    "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
+    "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     "COMPILE.mar", "$(MACRO) $(MACROFLAGS)",
     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
+    "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
+    "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
+    "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
+    "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
+    "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
 
     "MV", "rename/new_version",
     "CP", "copy",
+    ".LIBPATTERNS", "%.olb lib%.a",
 
 #else /* !VMS */
@@ -411,5 +533,5 @@
     "CC", "gcc",
 # ifdef __MSDOS__
-    "CXX", "gpp",	/* g++ is an invalid name on MSDOS */
+    "CXX", "gpp",       /* g++ is an invalid name on MSDOS */
 # else
     "CXX", "gcc",
@@ -429,5 +551,5 @@
 
     "CPP", "$(CC) -E",
-#ifdef	CRAY
+#ifdef  CRAY
     "CF77PPFLAGS", "-P",
     "CF77PP", "/lib/cpp",
@@ -435,9 +557,9 @@
     "CF", "cf77",
     "FC", "$(CF)",
-#else	/* Not CRAY.  */
-#ifdef	_IBMR2
+#else   /* Not CRAY.  */
+#ifdef  _IBMR2
     "FC", "xlf",
 #else
-#ifdef	__convex__
+#ifdef  __convex__
     "FC", "fc",
 #else
@@ -449,5 +571,5 @@
     "F77", "$(FC)",
     "F77FLAGS", "$(FFLAGS)",
-#endif	/* Cray.  */
+#endif  /* Cray.  */
     "GET", SCCS_GET,
     "LD", "ld",
@@ -459,18 +581,18 @@
     "LINT", "lint",
     "M2C", "m2c",
-#ifdef	pyr
+#ifdef  pyr
     "PC", "pascal",
 #else
-#ifdef	CRAY
+#ifdef  CRAY
     "PC", "PASCAL",
     "SEGLDR", "segldr",
 #else
     "PC", "pc",
-#endif	/* CRAY.  */
-#endif	/* pyr.  */
+#endif  /* CRAY.  */
+#endif  /* pyr.  */
 #ifdef GCC_IS_NATIVE
     "YACC", "bison -y",
 #else
-    "YACC", "yacc",	/* Or "bison -y"  */
+    "YACC", "yacc",     /* Or "bison -y"  */
 #endif
     "MAKEINFO", "makeinfo",
@@ -490,8 +612,19 @@
     "LINK.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
+#ifndef HAVE_CASE_INSENSITIVE_FS
+    /* On case-insensitive filesystems, treat *.C files as *.c files,
+       to avoid erroneously compiling C sources as C++, which will
+       probably fail.  */
     "COMPILE.C", "$(COMPILE.cc)",
+#else
+    "COMPILE.C", "$(COMPILE.c)",
+#endif
     "COMPILE.cpp", "$(COMPILE.cc)",
     "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
+#ifndef HAVE_CASE_INSENSITIVE_FS
     "LINK.C", "$(LINK.cc)",
+#else
+    "LINK.C", "$(LINK.c)",
+#endif
     "LINK.cpp", "$(LINK.cc)",
     "YACC.y", "$(YACC) $(YFLAGS)",
@@ -518,24 +651,28 @@
     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
 
-#ifndef	NO_MINUS_C_MINUS_O
+#ifndef NO_MINUS_C_MINUS_O
     "OUTPUT_OPTION", "-o $@",
 #endif
 
-#ifdef	SCCS_GET_MINUS_G
+#ifdef  SCCS_GET_MINUS_G
     "SCCS_OUTPUT_OPTION", "-G$@",
 #endif
 
-#ifdef _AMIGA
+#if defined(_AMIGA)
     ".LIBPATTERNS", "%.lib",
-#else
-#ifdef __MSDOS__
+#elif defined(__MSDOS__)
     ".LIBPATTERNS", "lib%.a $(DJDIR)/lib/lib%.a",
+#elif defined(__APPLE__)
+    ".LIBPATTERNS", "lib%.dylib lib%.a",
+#elif defined(__CYGWIN__) || defined(WINDOWS32)
+    ".LIBPATTERNS", "lib%.dll.a %.dll.a lib%.a %.lib lib%.dll %.dll",
 #else
     ".LIBPATTERNS", "lib%.so lib%.a",
-#endif
 #endif
 
 #endif /* !VMS */
 #endif /* !CONFIG_NO_DEFAULT_VARIABLES */
+    /* Make this assignment to avoid undefined variable warnings.  */
+    "GNUMAKEFLAGS", "",
     0, 0
   };
@@ -548,4 +685,5 @@
 {
   suffix_file = enter_file (strcache_add (".SUFFIXES"));
+  suffix_file->builtin = 1;
 
   if (no_builtin_rules_flag)
@@ -553,8 +691,11 @@
   else
     {
-      char *p = default_suffixes;
-      suffix_file->deps = enter_prereqs(PARSE_FILE_SEQ (&p, struct dep, '\0',
-                                                        NULL, 0),
-                                        NULL);
+      struct dep *d;
+      const char *p = default_suffixes;
+      suffix_file->deps = enter_prereqs (PARSE_SIMPLE_SEQ ((char **)&p, struct dep),
+                                         NULL);
+      for (d = suffix_file->deps; d; d = d->next)
+        d->file->builtin = 1;
+
       define_variable_cname ("SUFFIXES", default_suffixes, o_default, 0);
     }
@@ -569,5 +710,5 @@
 install_default_suffix_rules (void)
 {
-  char **s;
+  const char **s;
 
   if (no_builtin_rules_flag)
@@ -577,19 +718,19 @@
     {
       struct file *f = enter_file (strcache_add (s[0]));
-      /* Don't clobber cmds given in a makefile if there were any.  */
-      if (f->cmds == 0)
-	{
+      /* This function should run before any makefile is parsed.  */
+      assert (f->cmds == 0);
 #ifndef CONFIG_WITH_ALLOC_CACHES
-	  f->cmds = xmalloc (sizeof (struct commands));
-#else
-	  f->cmds = alloccache_alloc (&commands_cache);
-#endif
-	  f->cmds->fileinfo.filenm = 0;
-	  f->cmds->commands = s[1];
-	  f->cmds->command_lines = 0;
+      f->cmds = xmalloc (sizeof (struct commands));
+#else
+      f->cmds = alloccache_alloc (&commands_cache);
+#endif
+      f->cmds->fileinfo.filenm = 0;
+      f->cmds->commands = xstrdup (s[1]);
+      f->cmds->command_lines = 0;
+      f->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
 #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
-          f->cmds->refs = 1000;
-#endif
-	}
+      f->cmds->refs = 1000;
+#endif
+      f->builtin = 1;
     }
 }
@@ -624,2 +765,11 @@
     define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
 }
+
+void
+undefine_default_variables (void)
+{
+  const char **s;
+
+  for (s = default_variables; *s != 0; s += 2)
+    undefine_variable_global (s[0], strlen (s[0]), o_default);
+}
