Changeset 3140 for trunk/src/kmk/file.c


Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/file.c

    r2788 r3140  
    11/* Target file management for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
    2018
    2119#include <assert.h>
    2220
     21#include "filedef.h"
    2322#include "dep.h"
    24 #include "filedef.h"
    2523#include "job.h"
    2624#include "commands.h"
     
    6361#ifndef CONFIG_WITH_STRCACHE2
    6462  return_ISTRING_COMPARE (((struct file const *) x)->hname,
    65                           ((struct file const *) y)->hname);
     63                          ((struct file const *) y)->hname);
    6664#else  /* CONFIG_WITH_STRCACHE2 */
    6765  return ((struct file const *) x)->hname
     
    7068}
    7169
    72 #ifndef FILE_BUCKETS
    73 #define FILE_BUCKETS    1007
    74 #endif
    7570static struct hash_table files;
    7671
     
    9388  struct file *f;
    9489  struct file file_key;
    95 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
     90#ifdef VMS
     91  int want_vmsify;
     92#ifndef WANT_CASE_SENSITIVE_TARGETS
    9693  char *lname;
     94#endif
    9795#endif
    9896
     
    103101     on the command line.  */
    104102#ifdef VMS
     103   want_vmsify = (strpbrk (name, "]>:^") != NULL);
    105104# ifndef WANT_CASE_SENSITIVE_TARGETS
    106105  if (*name != '.')
     
    118117  while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
    119118      name += 2;
     119  while (name[0] == '<' && name[1] == '>' && name[2] != '\0')
     120      name += 2;
    120121#endif
    121122  while (name[0] == '.'
    122123#ifdef HAVE_DOS_PATHS
    123         && (name[1] == '/' || name[1] == '\\')
     124        && (name[1] == '/' || name[1] == '\\')
    124125#else
    125         && name[1] == '/'
    126 #endif
    127         && name[2] != '\0')
     126        && name[1] == '/'
     127#endif
     128        && name[2] != '\0')
    128129    {
    129130      name += 2;
    130131      while (*name == '/'
    131132#ifdef HAVE_DOS_PATHS
    132              || *name == '\\'
    133 #endif
    134              )
    135         /* Skip following slashes: ".//foo" is "foo", not "/foo".  */
    136         ++name;
     133             || *name == '\\'
     134#endif
     135             )
     136        /* Skip following slashes: ".//foo" is "foo", not "/foo".  */
     137        ++name;
    137138    }
    138139
    139140  if (*name == '\0')
    140     /* It was all slashes after a dot.  */
     141    {
     142      /* It was all slashes after a dot.  */
     143#if defined(_AMIGA)
     144      name = "";
     145#else
     146      name = "./";
     147#endif
    141148#if defined(VMS)
    142     name = "[]";
    143 #elif defined(_AMIGA)
    144     name = "";
    145 #else
    146     name = "./";
    147 #endif
    148 
     149      /* TODO - This section is probably not needed. */
     150      if (want_vmsify)
     151        name = "[]";
     152#endif
     153    }
    149154#ifndef CONFIG_WITH_STRCACHE2
    150155  file_key.hname = name;
     
    209214
    210215  assert (*name != '\0');
    211   assert (strcache_iscached (name));
     216  assert (! verify_flag || strcache_iscached (name));
    212217
    213218#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
     
    237242  f = *file_slot;
    238243  if (! HASH_VACANT (f) && !f->double_colon)
    239     return f;
     244    {
     245      f->builtin = 0;
     246      return f;
     247    }
    240248
    241249#ifndef CONFIG_WITH_ALLOC_CACHES
     
    245253#endif
    246254  new->name = new->hname = name;
    247   new->update_status = -1;
     255  new->update_status = us_none;
    248256
    249257  if (HASH_VACANT (f))
     
    271279
    272280/* Rehash FILE to NAME.  This is not as simple as resetting
    273    the `hname' member, since it must be put in a new hash bucket,
     281   the 'hname' member, since it must be put in a new hash bucket,
    274282   and possibly merged with an existing file called NAME.  */
    275283
     
    289297
    290298  /* If it's already that name, we're done.  */
     299  from_file->builtin = 0;
    291300  file_key.hname = to_hname;
    292301  if (! file_hash_cmp (from_file, &file_key))
     
    341350      else if (from_file->cmds != to_file->cmds)
    342351        {
     352          size_t l = strlen (from_file->name);
    343353          /* We have two sets of commands.  We will go with the
    344354             one given in the rule explicitly mentioning this name,
     
    346356          if (to_file->cmds->fileinfo.filenm != 0)
    347357            error (&from_file->cmds->fileinfo,
    348                    _("Recipe was specified for file `%s' at %s:%lu,"),
     358                   l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH,
     359                   _("Recipe was specified for file '%s' at %s:%lu,"),
    349360                   from_file->name, to_file->cmds->fileinfo.filenm,
    350361                   to_file->cmds->fileinfo.lineno);
    351362          else
    352             error (&from_file->cmds->fileinfo,
    353                    _("Recipe for file `%s' was found by implicit rule search,"),
     363            error (&from_file->cmds->fileinfo, l,
     364                   _("Recipe for file '%s' was found by implicit rule search,"),
    354365                   from_file->name);
    355           error (&from_file->cmds->fileinfo,
    356                  _("but `%s' is now considered the same file as `%s'."),
     366          l += strlen (to_hname);
     367          error (&from_file->cmds->fileinfo, l,
     368                 _("but '%s' is now considered the same file as '%s'."),
    357369                 from_file->name, to_hname);
    358           error (&from_file->cmds->fileinfo,
    359                  _("Recipe for `%s' will be ignored in favor of the one for `%s'."),
     370          error (&from_file->cmds->fileinfo, l,
     371                 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
    360372                 to_hname, from_file->name);
    361373        }
     
    367379    {
    368380      if (to_file->multi_head)
    369         fatal (NILF, _("can't rename/merge multi target '%s' with multi target '%s'"),
    370                from_file->name, to_hname);
     381        OSS (fatal, NILF, _("can't rename/merge multi target '%s' with multi target '%s'"),
     382             from_file->name, to_hname);
    371383
    372384      to_file->multi_maybe = from_file->multi_maybe;
     
    411423
    412424  if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
    413     fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
    414            from_file->name, to_hname);
     425    OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"),
     426         from_file->name, to_hname);
    415427  if (!to_file->double_colon  && from_file->double_colon)
    416428    {
    417429      if (to_file->is_target)
    418         fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
    419                from_file->name, to_hname);
     430        OSS (fatal, NILF,
     431             _("can't rename double-colon '%s' to single-colon '%s'"),
     432             from_file->name, to_hname);
    420433      else
    421434        to_file->double_colon = from_file->double_colon;
     
    436449  MERGE (cmd_target);
    437450  MERGE (phony);
     451  MERGE (loaded);
    438452  MERGE (ignore_vpath);
    439453#undef MERGE
    440454
     455  to_file->builtin = 0;
    441456  from_file->renamed = to_file;
    442457}
    443458
    444459/* Rename FILE to NAME.  This is not as simple as resetting
    445    the `name' member, since it must be put in a new hash bucket,
     460   the 'name' member, since it must be put in a new hash bucket,
    446461   and possibly merged with an existing file called NAME.  */
    447462
     
    498513    if (! HASH_VACANT (*file_slot))
    499514      {
    500         struct file *f = *file_slot;
     515        struct file *f = *file_slot;
    501516        /* Is this file eligible for automatic deletion?
    502517           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
    503518           given on the command line, and it's either a -include makefile or
    504519           it's not precious.  */
    505         if (f->intermediate && (f->dontcare || !f->precious)
    506             && !f->secondary && !f->cmd_target)
    507           {
    508             int status;
    509             if (f->update_status == -1)
    510               /* If nothing would have created this file yet,
    511                  don't print an "rm" command for it.  */
    512               continue;
    513             if (just_print_flag)
    514               status = 0;
    515             else
    516               {
    517                 status = unlink (f->name);
    518                 if (status < 0 && errno == ENOENT)
    519                   continue;
    520               }
    521             if (!f->dontcare)
    522               {
    523                 if (sig)
    524                   error (NILF, _("*** Deleting intermediate file `%s'"), f->name);
    525                 else
    526                   {
    527                     if (! doneany)
    528                       DB (DB_BASIC, (_("Removing intermediate files...\n")));
    529                     if (!silent_flag)
    530                       {
    531                         if (! doneany)
    532                           {
    533                             fputs ("rm ", stdout);
    534                             doneany = 1;
    535                           }
    536                         else
    537                           putchar (' ');
    538                         fputs (f->name, stdout);
    539                         fflush (stdout);
    540                       }
    541                   }
    542                 if (status < 0)
    543                   perror_with_name ("unlink: ", f->name);
    544               }
    545           }
     520        if (f->intermediate && (f->dontcare || !f->precious)
     521            && !f->secondary && !f->cmd_target)
     522          {
     523            int status;
     524            if (f->update_status == us_none)
     525              /* If nothing would have created this file yet,
     526                 don't print an "rm" command for it.  */
     527              continue;
     528            if (just_print_flag)
     529              status = 0;
     530            else
     531              {
     532                status = unlink (f->name);
     533                if (status < 0 && errno == ENOENT)
     534                  continue;
     535              }
     536            if (!f->dontcare)
     537              {
     538                if (sig)
     539                  OS (error, NILF,
     540                      _("*** Deleting intermediate file '%s'"), f->name);
     541                else
     542                  {
     543                    if (! doneany)
     544                      DB (DB_BASIC, (_("Removing intermediate files...\n")));
     545                    if (!silent_flag)
     546                      {
     547                        if (! doneany)
     548                          {
     549                            fputs ("rm ", stdout);
     550                            doneany = 1;
     551                          }
     552                        else
     553                          putchar (' ');
     554                        fputs (f->name, stdout);
     555                        fflush (stdout);
     556                      }
     557                  }
     558                if (status < 0)
     559                  perror_with_name ("unlink: ", f->name);
     560              }
     561          }
    546562      }
    547563
     
    560576split_prereqs (char *p)
    561577{
    562   struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0);
     578  struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL,
     579                                    PARSEFS_NONE);
    563580
    564581  if (*p)
     
    569586
    570587      ++p;
    571       ood = PARSE_FILE_SEQ (&p, struct dep, '\0', NULL, 0);
     588      ood = PARSE_SIMPLE_SEQ (&p, struct dep);
    572589
    573590      if (! new)
     
    728745      if (d->staticpattern)
    729746        {
    730           char *o;
    731           d->name = o = variable_expand ("");
     747          char *o = variable_expand ("");
    732748          o = subst_expand (o, name, "%", "$*", 1, 2, 0);
    733749          *o = '\0';
     
    802818}
    803819
    804 /* For each dependency of each file, make the `struct dep' point
    805    at the appropriate `struct file' (which may have to be created).
     820/* For each dependency of each file, make the 'struct dep' point
     821   at the appropriate 'struct file' (which may have to be created).
    806822
    807823   Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
     
    911927    for (d = f->deps; d != 0; d = d->next)
    912928      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    913         f2->precious = 1;
     929        f2->precious = 1;
    914930
    915931  for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
    916932    for (d = f->deps; d != 0; d = d->next)
    917933      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    918         f2->low_resolution_time = 1;
     934        f2->low_resolution_time = 1;
    919935
    920936  for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
    921937    for (d = f->deps; d != 0; d = d->next)
    922938      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    923         {
    924           /* Mark this file as phony nonexistent target.  */
    925           f2->phony = 1;
     939        {
     940          /* Mark this file as phony nonexistent target.  */
     941          f2->phony = 1;
    926942          f2->is_target = 1;
    927           f2->last_mtime = NONEXISTENT_MTIME;
    928           f2->mtime_before_update = NONEXISTENT_MTIME;
    929         }
     943          f2->last_mtime = NONEXISTENT_MTIME;
     944          f2->mtime_before_update = NONEXISTENT_MTIME;
     945        }
    930946
    931947  for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
     
    959975    {
    960976      if (f->deps == 0)
    961         ignore_errors_flag = 1;
     977        ignore_errors_flag = 1;
    962978      else
    963         for (d = f->deps; d != 0; d = d->next)
    964           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    965             f2->command_flags |= COMMANDS_NOERROR;
     979        for (d = f->deps; d != 0; d = d->next)
     980          for (f2 = d->file; f2 != 0; f2 = f2->prev)
     981            f2->command_flags |= COMMANDS_NOERROR;
    966982    }
    967983
     
    970986    {
    971987      if (f->deps == 0)
    972         silent_flag = 1;
     988        silent_flag = 1;
    973989      else
    974         for (d = f->deps; d != 0; d = d->next)
    975           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    976             f2->command_flags |= COMMANDS_SILENT;
     990        for (d = f->deps; d != 0; d = d->next)
     991          for (f2 = d->file; f2 != 0; f2 = f2->prev)
     992            f2->command_flags |= COMMANDS_SILENT;
    977993    }
    978994
     
    10051021
    10061022
    1007 /* Set the `command_state' member of FILE and all its `also_make's.  */
     1023/* Set the 'command_state' member of FILE and all its 'also_make's.  */
    10081024
    10091025void
     
    10281044
    10291045FILE_TIMESTAMP
    1030 file_timestamp_cons (const char *fname, time_t s, int ns)
     1046file_timestamp_cons (const char *fname, time_t stamp, long int ns)
    10311047{
    10321048  int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
     1049  FILE_TIMESTAMP s = stamp;
    10331050  FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
    10341051  FILE_TIMESTAMP ts = product + offset;
    10351052
    10361053  if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
    1037         && product <= ts && ts <= ORDINARY_MTIME_MAX))
     1054        && product <= ts && ts <= ORDINARY_MTIME_MAX))
    10381055    {
    10391056      char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
     1057      const char *f = fname ? fname : _("Current time");
    10401058      ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
    10411059      file_timestamp_sprintf (buf, ts);
    1042       error (NILF, _("%s: Timestamp out of range; substituting %s"),
    1043              fname ? fname : _("Current time"), buf);
     1060      OSS (error, NILF,
     1061           _("%s: Timestamp out of range; substituting %s"), f, buf);
    10441062    }
    10451063
     
    10661084    if (clock_gettime (CLOCK_REALTIME, &timespec) == 0)
    10671085      {
    1068         r = 1;
    1069         s = timespec.tv_sec;
    1070         ns = timespec.tv_nsec;
    1071         goto got_time;
     1086        r = 1;
     1087        s = timespec.tv_sec;
     1088        ns = timespec.tv_nsec;
     1089        goto got_time;
    10721090      }
    10731091  }
     
    10781096    if (gettimeofday (&timeval, 0) == 0)
    10791097      {
    1080         r = 1000;
    1081         s = timeval.tv_sec;
    1082         ns = timeval.tv_usec * 1000;
    1083         goto got_time;
     1098        r = 1000;
     1099        s = timeval.tv_sec;
     1100        ns = timeval.tv_usec * 1000;
     1101        goto got_time;
    10841102      }
    10851103  }
     
    11081126  if (tm)
    11091127    sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
    1110              tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
    1111              tm->tm_hour, tm->tm_min, tm->tm_sec);
     1128             tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
     1129             tm->tm_hour, tm->tm_min, tm->tm_sec);
    11121130  else if (t < 0)
    11131131    sprintf (p, "%ld", (long) t);
     
    11611179  const struct file *f = item;
    11621180
     1181  /* If we're not using builtin targets, don't show them.
     1182
     1183     Ideally we'd be able to delete them altogether but currently there's no
     1184     facility to ever delete a file once it's been added.  */
     1185  if (no_builtin_rules_flag && f->builtin)
     1186    return;
     1187
    11631188  putchar ('\n');
     1189
     1190  if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
     1191    {
     1192      fputs (".RECIPEPREFIX = ", stdout);
     1193      cmd_prefix = f->cmds->recipe_prefix;
     1194      if (cmd_prefix != RECIPEPREFIX_DEFAULT)
     1195        putchar (cmd_prefix);
     1196      putchar ('\n');
     1197    }
     1198
     1199  if (f->variables != 0)
     1200    print_target_variables (f);
     1201
    11641202  if (!f->is_target)
    11651203    puts (_("# Not a target:"));
     
    12281266    }
    12291267#endif
    1230 
     1268  if (f->builtin)
     1269    puts (_("#  Builtin rule"));
    12311270  puts (f->tried_implicit
    12321271        ? _("#  Implicit rule search has been done.")
    12331272        : _("#  Implicit rule search has not been done."));
    12341273  if (f->stem != 0)
    1235     printf (_("#  Implicit/static pattern stem: `%s'\n"), f->stem);
     1274    printf (_("#  Implicit/static pattern stem: '%s'\n"), f->stem);
    12361275  if (f->intermediate)
    12371276    puts (_("#  File is an intermediate prerequisite."));
     
    12411280      fputs (_("#  Also makes:"), stdout);
    12421281      for (d = f->also_make; d != 0; d = d->next)
    1243         printf (" %s", dep_name (d));
     1282        printf (" %s", dep_name (d));
    12441283      putchar ('\n');
    12451284    }
     
    12691308    case cs_finished:
    12701309      switch (f->update_status)
    1271         {
    1272         case -1:
    1273           break;
    1274         case 0:
    1275           puts (_("#  Successfully updated."));
    1276           break;
    1277         case 1:
    1278           assert (question_flag);
    1279           puts (_("#  Needs to be updated (-q is set)."));
    1280           break;
    1281         case 2:
    1282           puts (_("#  Failed to be updated."));
    1283           break;
    1284         default:
    1285           puts (_("#  Invalid value in `update_status' member!"));
    1286           fflush (stdout);
    1287           fflush (stderr);
    1288           abort ();
    1289         }
     1310        {
     1311        case us_none:
     1312          break;
     1313        case us_success:
     1314          puts (_("#  Successfully updated."));
     1315          break;
     1316        case us_question:
     1317          assert (question_flag);
     1318          puts (_("#  Needs to be updated (-q is set)."));
     1319          break;
     1320        case us_failed:
     1321          puts (_("#  Failed to be updated."));
     1322          break;
     1323        }
    12901324      break;
    12911325    default:
    1292       puts (_("#  Invalid value in `command_state' member!"));
     1326      puts (_("#  Invalid value in 'command_state' member!"));
    12931327      fflush (stdout);
    12941328      fflush (stderr);
     
    13311365
    13321366#define VERIFY_CACHED(_p,_n) \
    1333     do{\
    1334         if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
    1335           error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \
     1367    do{                                                                       \
     1368        if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n))               \
     1369          error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n),  \
     1370                 _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \
    13361371    }while(0)
    13371372
Note: See TracChangeset for help on using the changeset viewer.