VirtualBox

Changeset 3138 in kBuild for vendor/gnumake/current/file.c


Ignore:
Timestamp:
Mar 12, 2018 7:32:29 PM (7 years ago)
Author:
bird
Message:

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/file.c

    r2596 r3138  
    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"
     
    5755{
    5856  return_ISTRING_COMPARE (((struct file const *) x)->hname,
    59                           ((struct file const *) y)->hname);
    60 }
    61 
    62 #ifndef FILE_BUCKETS
    63 #define FILE_BUCKETS    1007
    64 #endif
     57                          ((struct file const *) y)->hname);
     58}
     59
    6560static struct hash_table files;
    6661
     
    7873  struct file *f;
    7974  struct file file_key;
    80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
     75#ifdef VMS
     76  int want_vmsify;
     77#ifndef WANT_CASE_SENSITIVE_TARGETS
    8178  char *lname;
     79#endif
    8280#endif
    8381
     
    8886     on the command line.  */
    8987#ifdef VMS
     88   want_vmsify = (strpbrk (name, "]>:^") != NULL);
    9089# ifndef WANT_CASE_SENSITIVE_TARGETS
    9190  if (*name != '.')
     
    103102  while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
    104103      name += 2;
     104  while (name[0] == '<' && name[1] == '>' && name[2] != '\0')
     105      name += 2;
    105106#endif
    106107  while (name[0] == '.'
    107108#ifdef HAVE_DOS_PATHS
    108         && (name[1] == '/' || name[1] == '\\')
     109        && (name[1] == '/' || name[1] == '\\')
    109110#else
    110         && name[1] == '/'
     111        && name[1] == '/'
    111112#endif
    112         && name[2] != '\0')
     113        && name[2] != '\0')
    113114    {
    114115      name += 2;
    115116      while (*name == '/'
    116117#ifdef HAVE_DOS_PATHS
    117              || *name == '\\'
     118             || *name == '\\'
    118119#endif
    119              )
    120         /* Skip following slashes: ".//foo" is "foo", not "/foo".  */
    121         ++name;
     120             )
     121        /* Skip following slashes: ".//foo" is "foo", not "/foo".  */
     122        ++name;
    122123    }
    123124
    124125  if (*name == '\0')
    125     /* It was all slashes after a dot.  */
     126    {
     127      /* It was all slashes after a dot.  */
     128#if defined(_AMIGA)
     129      name = "";
     130#else
     131      name = "./";
     132#endif
    126133#if defined(VMS)
    127     name = "[]";
    128 #elif defined(_AMIGA)
    129     name = "";
    130 #else
    131     name = "./";
     134      /* TODO - This section is probably not needed. */
     135      if (want_vmsify)
     136        name = "[]";
    132137#endif
    133 
     138    }
    134139  file_key.hname = name;
    135140  f = hash_find_item (&files, &file_key);
     
    156161
    157162  assert (*name != '\0');
    158   assert (strcache_iscached (name));
     163  assert (! verify_flag || strcache_iscached (name));
    159164
    160165#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
     
    180185  f = *file_slot;
    181186  if (! HASH_VACANT (f) && !f->double_colon)
    182     return f;
     187    {
     188      f->builtin = 0;
     189      return f;
     190    }
    183191
    184192  new = xcalloc (sizeof (struct file));
    185193  new->name = new->hname = name;
    186   new->update_status = -1;
     194  new->update_status = us_none;
    187195
    188196  if (HASH_VACANT (f))
     
    204212
    205213/* Rehash FILE to NAME.  This is not as simple as resetting
    206    the `hname' member, since it must be put in a new hash bucket,
     214   the 'hname' member, since it must be put in a new hash bucket,
    207215   and possibly merged with an existing file called NAME.  */
    208216
     
    217225
    218226  /* If it's already that name, we're done.  */
     227  from_file->builtin = 0;
    219228  file_key.hname = to_hname;
    220229  if (! file_hash_cmp (from_file, &file_key))
     
    261270      else if (from_file->cmds != to_file->cmds)
    262271        {
     272          size_t l = strlen (from_file->name);
    263273          /* We have two sets of commands.  We will go with the
    264274             one given in the rule explicitly mentioning this name,
     
    266276          if (to_file->cmds->fileinfo.filenm != 0)
    267277            error (&from_file->cmds->fileinfo,
    268                    _("Recipe was specified for file `%s' at %s:%lu,"),
     278                   l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH,
     279                   _("Recipe was specified for file '%s' at %s:%lu,"),
    269280                   from_file->name, to_file->cmds->fileinfo.filenm,
    270281                   to_file->cmds->fileinfo.lineno);
    271282          else
    272             error (&from_file->cmds->fileinfo,
    273                    _("Recipe for file `%s' was found by implicit rule search,"),
     283            error (&from_file->cmds->fileinfo, l,
     284                   _("Recipe for file '%s' was found by implicit rule search,"),
    274285                   from_file->name);
    275           error (&from_file->cmds->fileinfo,
    276                  _("but `%s' is now considered the same file as `%s'."),
     286          l += strlen (to_hname);
     287          error (&from_file->cmds->fileinfo, l,
     288                 _("but '%s' is now considered the same file as '%s'."),
    277289                 from_file->name, to_hname);
    278           error (&from_file->cmds->fileinfo,
    279                  _("Recipe for `%s' will be ignored in favor of the one for `%s'."),
     290          error (&from_file->cmds->fileinfo, l,
     291                 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
    280292                 to_hname, from_file->name);
    281293        }
     
    297309
    298310  if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
    299     fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
    300            from_file->name, to_hname);
     311    OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"),
     312         from_file->name, to_hname);
    301313  if (!to_file->double_colon  && from_file->double_colon)
    302314    {
    303315      if (to_file->is_target)
    304         fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
    305                from_file->name, to_hname);
     316        OSS (fatal, NILF,
     317             _("can't rename double-colon '%s' to single-colon '%s'"),
     318             from_file->name, to_hname);
    306319      else
    307320        to_file->double_colon = from_file->double_colon;
     
    322335  MERGE (cmd_target);
    323336  MERGE (phony);
     337  MERGE (loaded);
    324338  MERGE (ignore_vpath);
    325339#undef MERGE
    326340
     341  to_file->builtin = 0;
    327342  from_file->renamed = to_file;
    328343}
    329344
    330345/* Rename FILE to NAME.  This is not as simple as resetting
    331    the `name' member, since it must be put in a new hash bucket,
     346   the 'name' member, since it must be put in a new hash bucket,
    332347   and possibly merged with an existing file called NAME.  */
    333348
     
    368383    if (! HASH_VACANT (*file_slot))
    369384      {
    370         struct file *f = *file_slot;
     385        struct file *f = *file_slot;
    371386        /* Is this file eligible for automatic deletion?
    372387           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
    373388           given on the command line, and it's either a -include makefile or
    374389           it's not precious.  */
    375         if (f->intermediate && (f->dontcare || !f->precious)
    376             && !f->secondary && !f->cmd_target)
    377           {
    378             int status;
    379             if (f->update_status == -1)
    380               /* If nothing would have created this file yet,
    381                  don't print an "rm" command for it.  */
    382               continue;
    383             if (just_print_flag)
    384               status = 0;
    385             else
    386               {
    387                 status = unlink (f->name);
    388                 if (status < 0 && errno == ENOENT)
    389                   continue;
    390               }
    391             if (!f->dontcare)
    392               {
    393                 if (sig)
    394                   error (NILF, _("*** Deleting intermediate file `%s'"), f->name);
    395                 else
    396                   {
    397                     if (! doneany)
    398                       DB (DB_BASIC, (_("Removing intermediate files...\n")));
    399                     if (!silent_flag)
    400                       {
    401                         if (! doneany)
    402                           {
    403                             fputs ("rm ", stdout);
    404                             doneany = 1;
    405                           }
    406                         else
    407                           putchar (' ');
    408                         fputs (f->name, stdout);
    409                         fflush (stdout);
    410                       }
    411                   }
    412                 if (status < 0)
    413                   perror_with_name ("unlink: ", f->name);
    414               }
    415           }
     390        if (f->intermediate && (f->dontcare || !f->precious)
     391            && !f->secondary && !f->cmd_target)
     392          {
     393            int status;
     394            if (f->update_status == us_none)
     395              /* If nothing would have created this file yet,
     396                 don't print an "rm" command for it.  */
     397              continue;
     398            if (just_print_flag)
     399              status = 0;
     400            else
     401              {
     402                status = unlink (f->name);
     403                if (status < 0 && errno == ENOENT)
     404                  continue;
     405              }
     406            if (!f->dontcare)
     407              {
     408                if (sig)
     409                  OS (error, NILF,
     410                      _("*** Deleting intermediate file '%s'"), f->name);
     411                else
     412                  {
     413                    if (! doneany)
     414                      DB (DB_BASIC, (_("Removing intermediate files...\n")));
     415                    if (!silent_flag)
     416                      {
     417                        if (! doneany)
     418                          {
     419                            fputs ("rm ", stdout);
     420                            doneany = 1;
     421                          }
     422                        else
     423                          putchar (' ');
     424                        fputs (f->name, stdout);
     425                        fflush (stdout);
     426                      }
     427                  }
     428                if (status < 0)
     429                  perror_with_name ("unlink: ", f->name);
     430              }
     431          }
    416432      }
    417433
     
    430446split_prereqs (char *p)
    431447{
    432   struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0);
     448  struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL,
     449                                    PARSEFS_NONE);
    433450
    434451  if (*p)
     
    439456
    440457      ++p;
    441       ood = PARSE_FILE_SEQ (&p, struct dep, '\0', NULL, 0);
     458      ood = PARSE_SIMPLE_SEQ (&p, struct dep);
    442459
    443460      if (! new)
     
    579596      if (d->staticpattern)
    580597        {
    581           char *o;
    582           d->name = o = variable_expand ("");
     598          char *o = variable_expand ("");
    583599          o = subst_expand (o, name, "%", "$*", 1, 2, 0);
    584600          *o = '\0';
    585601          free (name);
    586           d->name = name = xstrdup (d->name);
     602          d->name = name = xstrdup (variable_buffer);
    587603          d->staticpattern = 0;
    588604        }
     
    641657}
    642658
    643 /* For each dependency of each file, make the `struct dep' point
    644    at the appropriate `struct file' (which may have to be created).
     659/* For each dependency of each file, make the 'struct dep' point
     660   at the appropriate 'struct file' (which may have to be created).
    645661
    646662   Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
     
    697713    for (d = f->deps; d != 0; d = d->next)
    698714      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    699         f2->precious = 1;
     715        f2->precious = 1;
    700716
    701717  for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
    702718    for (d = f->deps; d != 0; d = d->next)
    703719      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    704         f2->low_resolution_time = 1;
     720        f2->low_resolution_time = 1;
    705721
    706722  for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
    707723    for (d = f->deps; d != 0; d = d->next)
    708724      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    709         {
    710           /* Mark this file as phony nonexistent target.  */
    711           f2->phony = 1;
     725        {
     726          /* Mark this file as phony nonexistent target.  */
     727          f2->phony = 1;
    712728          f2->is_target = 1;
    713           f2->last_mtime = NONEXISTENT_MTIME;
    714           f2->mtime_before_update = NONEXISTENT_MTIME;
    715         }
     729          f2->last_mtime = NONEXISTENT_MTIME;
     730          f2->mtime_before_update = NONEXISTENT_MTIME;
     731        }
    716732
    717733  for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
     
    745761    {
    746762      if (f->deps == 0)
    747         ignore_errors_flag = 1;
     763        ignore_errors_flag = 1;
    748764      else
    749         for (d = f->deps; d != 0; d = d->next)
    750           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    751             f2->command_flags |= COMMANDS_NOERROR;
     765        for (d = f->deps; d != 0; d = d->next)
     766          for (f2 = d->file; f2 != 0; f2 = f2->prev)
     767            f2->command_flags |= COMMANDS_NOERROR;
    752768    }
    753769
     
    756772    {
    757773      if (f->deps == 0)
    758         silent_flag = 1;
     774        silent_flag = 1;
    759775      else
    760         for (d = f->deps; d != 0; d = d->next)
    761           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    762             f2->command_flags |= COMMANDS_SILENT;
     776        for (d = f->deps; d != 0; d = d->next)
     777          for (f2 = d->file; f2 != 0; f2 = f2->prev)
     778            f2->command_flags |= COMMANDS_SILENT;
    763779    }
    764780
     
    777793
    778794
    779 /* Set the `command_state' member of FILE and all its `also_make's.  */
     795/* Set the 'command_state' member of FILE and all its 'also_make's.  */
    780796
    781797void
     
    794810
    795811FILE_TIMESTAMP
    796 file_timestamp_cons (const char *fname, time_t s, int ns)
     812file_timestamp_cons (const char *fname, time_t stamp, long int ns)
    797813{
    798814  int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
     815  FILE_TIMESTAMP s = stamp;
    799816  FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
    800817  FILE_TIMESTAMP ts = product + offset;
    801818
    802819  if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
    803         && product <= ts && ts <= ORDINARY_MTIME_MAX))
     820        && product <= ts && ts <= ORDINARY_MTIME_MAX))
    804821    {
    805822      char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
     823      const char *f = fname ? fname : _("Current time");
    806824      ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
    807825      file_timestamp_sprintf (buf, ts);
    808       error (NILF, _("%s: Timestamp out of range; substituting %s"),
    809              fname ? fname : _("Current time"), buf);
     826      OSS (error, NILF,
     827           _("%s: Timestamp out of range; substituting %s"), f, buf);
    810828    }
    811829
     
    832850    if (clock_gettime (CLOCK_REALTIME, &timespec) == 0)
    833851      {
    834         r = 1;
    835         s = timespec.tv_sec;
    836         ns = timespec.tv_nsec;
    837         goto got_time;
     852        r = 1;
     853        s = timespec.tv_sec;
     854        ns = timespec.tv_nsec;
     855        goto got_time;
    838856      }
    839857  }
     
    844862    if (gettimeofday (&timeval, 0) == 0)
    845863      {
    846         r = 1000;
    847         s = timeval.tv_sec;
    848         ns = timeval.tv_usec * 1000;
    849         goto got_time;
     864        r = 1000;
     865        s = timeval.tv_sec;
     866        ns = timeval.tv_usec * 1000;
     867        goto got_time;
    850868      }
    851869  }
     
    874892  if (tm)
    875893    sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
    876              tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
    877              tm->tm_hour, tm->tm_min, tm->tm_sec);
     894             tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
     895             tm->tm_hour, tm->tm_min, tm->tm_sec);
    878896  else if (t < 0)
    879897    sprintf (p, "%ld", (long) t);
     
    927945  const struct file *f = item;
    928946
     947  /* If we're not using builtin targets, don't show them.
     948
     949     Ideally we'd be able to delete them altogether but currently there's no
     950     facility to ever delete a file once it's been added.  */
     951  if (no_builtin_rules_flag && f->builtin)
     952    return;
     953
    929954  putchar ('\n');
     955
     956  if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
     957    {
     958      fputs (".RECIPEPREFIX = ", stdout);
     959      cmd_prefix = f->cmds->recipe_prefix;
     960      if (cmd_prefix != RECIPEPREFIX_DEFAULT)
     961        putchar (cmd_prefix);
     962      putchar ('\n');
     963    }
     964
     965  if (f->variables != 0)
     966    print_target_variables (f);
     967
    930968  if (!f->is_target)
    931969    puts (_("# Not a target:"));
     
    941979  if (f->dontcare)
    942980    puts (_("#  A default, MAKEFILES, or -include/sinclude makefile."));
     981  if (f->builtin)
     982    puts (_("#  Builtin rule"));
    943983  puts (f->tried_implicit
    944984        ? _("#  Implicit rule search has been done.")
    945985        : _("#  Implicit rule search has not been done."));
    946986  if (f->stem != 0)
    947     printf (_("#  Implicit/static pattern stem: `%s'\n"), f->stem);
     987    printf (_("#  Implicit/static pattern stem: '%s'\n"), f->stem);
    948988  if (f->intermediate)
    949989    puts (_("#  File is an intermediate prerequisite."));
     
    953993      fputs (_("#  Also makes:"), stdout);
    954994      for (d = f->also_make; d != 0; d = d->next)
    955         printf (" %s", dep_name (d));
     995        printf (" %s", dep_name (d));
    956996      putchar ('\n');
    957997    }
     
    9811021    case cs_finished:
    9821022      switch (f->update_status)
    983         {
    984         case -1:
    985           break;
    986         case 0:
    987           puts (_("#  Successfully updated."));
    988           break;
    989         case 1:
    990           assert (question_flag);
    991           puts (_("#  Needs to be updated (-q is set)."));
    992           break;
    993         case 2:
    994           puts (_("#  Failed to be updated."));
    995           break;
    996         default:
    997           puts (_("#  Invalid value in `update_status' member!"));
    998           fflush (stdout);
    999           fflush (stderr);
    1000           abort ();
    1001         }
     1023        {
     1024        case us_none:
     1025          break;
     1026        case us_success:
     1027          puts (_("#  Successfully updated."));
     1028          break;
     1029        case us_question:
     1030          assert (question_flag);
     1031          puts (_("#  Needs to be updated (-q is set)."));
     1032          break;
     1033        case us_failed:
     1034          puts (_("#  Failed to be updated."));
     1035          break;
     1036        }
    10021037      break;
    10031038    default:
    1004       puts (_("#  Invalid value in `command_state' member!"));
     1039      puts (_("#  Invalid value in 'command_state' member!"));
    10051040      fflush (stdout);
    10061041      fflush (stderr);
     
    10331068
    10341069#define VERIFY_CACHED(_p,_n) \
    1035     do{\
    1036         if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
    1037           error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \
     1070    do{                                                                       \
     1071        if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n))               \
     1072          error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n),  \
     1073                 _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \
    10381074    }while(0)
    10391075
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette