* Handle case of empty static pattern rule prerequisites.
authorPaul Smith <psmith@gnu.org>
Mon, 27 Mar 2000 20:53:50 +0000 (20:53 +0000)
committerPaul Smith <psmith@gnu.org>
Mon, 27 Mar 2000 20:53:50 +0000 (20:53 +0000)
* Fix linenumbers in error messages for rule definitions.

ChangeLog
NEWS
file.c
read.c
tests/ChangeLog
tests/scripts/features/statipattrules

index f4e1592..529ef50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2000-03-27  Paul D. Smith  <psmith@gnu.org>
 
+       * read.c (record_files): Check if expanding a static pattern
+       rule's prerequisite pattern leaves an empty string as the
+       prerequisite, and issue an error if so.  Fixes PR/1670.
+       (read_makefile): Store the starting linenumber for a rule in
+       TGTS_STARTED.
+       (record_waiting_files): Use the TGTS_STARTED value for the file
+       location passed to record_file() instead of the current
+       linenumber, so error messages list the line where the target was
+       defined instead of the line after the end of the rule definition.
+
        * remake.c (start_updating, finish_updating, is_updating): Fix
        PR/1671; circular dependencies in double-colon rules are not
        diagnosed.  These macros set the updating flag in the root
@@ -28,8 +38,8 @@
 
 2000-03-23  Paul Eggert  <eggert@twinsun.com>
 
-       * filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Don't use
-       st_mtim.tv_sec; this doesn't work on Unixware.
+       * filedef.h (FILE_TIMESTAMP_STAT_MODTIME): Use st_mtime instead of
+       st_mtim.tv_sec; the latter doesn't work on Unixware.
 
 2000-03-18  Paul D. Smith  <psmith@gnu.org>
 
diff --git a/NEWS b/NEWS
index 9fe1e02..0079ffe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,6 @@
 GNU make NEWS                                               -*-indented-text-*-
   History of user-visible changes.
-  25 Jan 2000
+  27 Mar 2000
 
 Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
 See the end for copying conditions.
@@ -36,12 +36,6 @@ Version 3.79
   current makefile is run serially regardless of the value of -j.
   However, submakes are still eligible for parallel execution.
 
-* The $(call ...) function doesn't expand its arguments automatically
-  anymore.  This allows you to put builtin functions like "if" and
-  "foreach", which also have special expansion rules, in a $(call ...)
-  function and have it work properly.  This was suggested by Damien
-  GIBOU <damien.gibou@st.com>.
-
 * The --debug option has changed: it now allows optional flags
   controlling the amount and type of debugging output.  By default only
   a minimal amount information is generated, displaying the names of
diff --git a/file.c b/file.c
index c64db0b..10ae1b8 100644 (file)
--- a/file.c
+++ b/file.c
@@ -58,8 +58,7 @@ lookup_file (name)
   register char *lname, *ln;
 #endif
 
-  if (*name == '\0')
-    abort ();
+  assert (*name != '\0');
 
   /* This is also done in parse_file_seq, so this is redundant
      for names read from makefiles.  It is here for names passed
diff --git a/read.c b/read.c
index c5434f7..9f35753 100644 (file)
--- a/read.c
+++ b/read.c
@@ -287,7 +287,7 @@ read_makefile (filename, flags)
   unsigned int commands_len = 200;
   char *commands;
   unsigned int commands_idx = 0;
-  unsigned int cmds_started;
+  unsigned int cmds_started, tgts_started;
   char *p;
   char *p2;
   int len, reading_target;
@@ -313,9 +313,13 @@ read_makefile (filename, flags)
     {                                                                        \
       if (filenames != 0)                                                    \
         {                                                                     \
+         int lineno = fileinfo.lineno;                                       \
+         struct floc fi;                                                     \
+         fi.filenm = fileinfo.filenm;                                        \
+         fi.lineno = tgts_started;                                           \
          record_files (filenames, pattern, pattern_percent, deps,            \
                         cmds_started, commands, commands_idx, two_colon,      \
-                        &fileinfo, !(flags & RM_NO_DEFAULT_GOAL));           \
+                        &fi, !(flags & RM_NO_DEFAULT_GOAL));                  \
           using_filename |= commands_idx > 0;                                 \
         }                                                                     \
       filenames = 0;                                                         \
@@ -327,7 +331,7 @@ read_makefile (filename, flags)
   fileinfo.lineno = 1;
 
   pattern_percent = 0;
-  cmds_started = fileinfo.lineno;
+/*  cmds_started = fileinfo.lineno; */
 
   if (ISDB (DB_VERBOSE))
     {
@@ -755,6 +759,7 @@ read_makefile (filename, flags)
          /* Record the previous rule.  */
 
          record_waiting_files ();
+          tgts_started = fileinfo.lineno;
 
          /* Search the line for an unquoted ; that is not after an
              unquoted #.  */
@@ -1540,7 +1545,7 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
       char *implicit_percent;
 
       nextf = filenames->next;
-      free ((char *) filenames);
+      free (filenames);
 
       implicit_percent = find_percent (name);
       implicit |= implicit_percent != 0;
@@ -1608,6 +1613,12 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
                    continue;
                  o = patsubst_expand (buffer, name, pattern, d->name,
                                       pattern_percent, percent);
+                  /* If the name expanded to the empty string, that's
+                     illegal.  */
+                  if (o == buffer)
+                    fatal (flocp,
+                           _("target `%s' leaves prerequisite pattern empty"),
+                           name);
                  free (d->name);
                  d->name = savestring (buffer, o - buffer);
                }
@@ -1627,7 +1638,8 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
          /* If CMDS == F->CMDS, this target was listed in this rule
             more than once.  Just give a warning since this is harmless.  */
          if (cmds != 0 && cmds == f->cmds)
-           error (flocp, _("target `%s' given more than once in the same rule."),
+           error (flocp,
+                   _("target `%s' given more than once in the same rule."),
                    f->name);
 
          /* Check for two single-colon entries both with commands.
@@ -1636,7 +1648,8 @@ record_files (filenames, pattern, pattern_percent, deps, cmds_started,
          else if (cmds != 0 && f->cmds != 0 && f->is_target)
            {
              error (&cmds->fileinfo,
-                     _("warning: overriding commands for target `%s'"), f->name);
+                     _("warning: overriding commands for target `%s'"),
+                     f->name);
              error (&f->cmds->fileinfo,
                      _("warning: ignoring old commands for target `%s'"),
                      f->name);
index 55e56f8..ad01213 100644 (file)
@@ -1,5 +1,9 @@
 2000-03-27  Paul D. Smith  <psmith@gnu.org>
 
+       * scripts/features/statipattrules: Test that static pattern rules
+       whose prerequisite patterns resolve to empty strings throw an
+       error (instead of dumping core).  Fixes PR/1670.
+
        * scripts/features/reinvoke: Make more robust by touching "b"
        first, to ensure it's not newer than "a".
        Reported by Marco Franzen <Marco.Franzen@Thyron.com>.
@@ -7,7 +11,8 @@
        * scripts/functions/call: Whoops.  The fix to PR/1527 caused
        recursive invocations of $(call ...) to break.  I can't come up
        with any way to get both working at the same time, so I backed out
-       the fix to 1527 and added a test case for recursive calls.
+       the fix to 1527 and added a test case for recursive calls.  This
+       also tests the fix for PR/1610.
 
        * scripts/features/double_colon: Test that circular dependencies
        in double-colon rule sets are detected correctly (PR/1671).
index bf2eae7..29a7c08 100644 (file)
@@ -1,66 +1,67 @@
-$description = "The following test creates a makefile to test static \n"
-              ."pattern rules.  Static pattern rules are rules which \n"
-              ."specify multiple targets and construct the dependency \n"
-              ."names for each target based on the target name. ";
-
-$details = "The makefile created in this test has three targets.  The \n"
-          ."filter command is used to get those target names ending in \n"
-          .".o and statically creates a compile command with the target\n"
-          ."name and the target name with .c.  It also does the same thing\n"
-          ."for another target filtered with .elc and creates a command\n"
-          ."to emacs a .el file";
+#                                                                    -*-perl-*-
+$description = "Test handling of static pattern rules.";
 
-open(MAKEFILE,"> $makefile");
-
-# The Contents of the MAKEFILE ...
+$details = "\
+The makefile created in this test has three targets.  The
+filter command is used to get those target names ending in
+.o and statically creates a compile command with the target
+name and the target name with .c.  It also does the same thing
+for another target filtered with .elc and creates a command
+to emacs a .el file";
 
-print MAKEFILE "files = foo.elc bar.o lose.o   \n\n" 
-              ."\$(filter %.o,\$(files)): %.o: %.c\n"
-              ."\t\@echo CC -c \$(CFLAGS) \$< -o \$@ \n"
-              ."\$(filter %.elc,\$(files)): %.elc: %.el \n"
-              ."\t\@echo emacs \$< \n";
+open(MAKEFILE,"> $makefile");
+print MAKEFILE <<'EOF';
+files = foo.elc bar.o lose.o
 
-# END of Contents of MAKEFILE
+$(filter %.o,$(files)): %.o: %.c ; @echo CC -c $(CFLAGS) $< -o $@
 
+$(filter %.elc,$(files)): %.elc: %.el ; @echo emacs $<
+EOF
 close(MAKEFILE);
 
-&touch("bar.c","lose.c");
+
+&touch('bar.c', 'lose.c');
 
 #   TEST #1
 #   -------
 
-&run_make_with_options($makefile,
-                       "",
-                       &get_logfile,
-                       0);
-
-# Create the answer to what should be produced by this Makefile
+&run_make_with_options($makefile, '', &get_logfile);
 $answer = "CC -c bar.c -o bar.o\n";
-&compare_output($answer,&get_logfile(1));
+&compare_output($answer, &get_logfile(1));
 
 
 #  TEST #2
 #  -------
-&run_make_with_options($makefile,"lose.o",&get_logfile);
 
+&run_make_with_options($makefile, 'lose.o', &get_logfile);
 $answer = "CC -c lose.c -o lose.o\n";
-
-&compare_output($answer,&get_logfile(1));  
+&compare_output($answer, &get_logfile(1));
 
 
 #   TEST #3
 #   -------
 &touch("foo.el");
 
-&run_make_with_options($makefile,"foo.elc",&get_logfile);
-
+&run_make_with_options($makefile, 'foo.elc', &get_logfile);
 $answer = "emacs foo.el\n";
+&compare_output($answer, &get_logfile(1));
+
+
+unlink('foo.el', 'bar.c', 'lose.c');
 
-&compare_output($answer,&get_logfile(1));  
 
+# TEST #4 -- PR/1670: don't core dump on invalid static pattern rules
+# -------
+
+$makefile2 = &get_tmpfile;
+open(MAKEFILE, "> $makefile2");
+print MAKEFILE "foo: foo%: % ; \@echo $@\n";
+close(MAKEFILE);
 
+&run_make_with_options($makefile2, '', &get_logfile, 512);
+$answer = "$makefile2:1: *** target `foo' leaves prerequisite pattern empty.  Stop.\n";
+&compare_output($answer, &get_logfile(1));
 
-unlink("foo.el","bar.c","lose.c");
 
 1;