hotspot/src/share/tools/MakeDeps/Database.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 759 b1a375646eb5
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
public class Database {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  private MacroDefinitions macros;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // allFiles is kept in lexicographically sorted order. See get().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  private FileList allFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // files that have implicit dependency on platform files
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // e.g. os.hpp: os_<os_family>.hpp os_<os_arch>.hpp but only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // recorded if the platform file was seen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  private FileList platformFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  private FileList outerFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  private FileList indivIncludes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private FileList grandInclude; // the results for the grand include file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private long threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private int nOuterFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private int nPrecompiledFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private boolean missingOk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  private Platform plat;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  /** These allow you to specify files not in the include database
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    which are prepended and appended to the file list, allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    you to have well-known functions at the start and end of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    text segment (allows us to find out in a portable fashion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    whether the current PC is in VM code or not upon a crash) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private String firstFile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private String lastFile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  public Database(Platform plat, long t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    this.plat = plat;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    macros          = new MacroDefinitions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    allFiles        = new FileList("allFiles", plat);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    platformFiles   = new FileList("platformFiles", plat);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    outerFiles      = new FileList("outerFiles", plat);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    indivIncludes   = new FileList("IndivIncludes", plat);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    grandInclude    = new FileList(plat.getGIFileTemplate().nameOfList(), plat);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    threshold = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    nOuterFiles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    nPrecompiledFiles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    missingOk = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    firstFile = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    lastFile = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  public FileList getAllFiles() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return allFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  public Iterator getMacros() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return macros.getMacros();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public void canBeMissing() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    missingOk = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  public boolean hfileIsInGrandInclude(FileList hfile, FileList cfile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return ((hfile.getCount() >= threshold) && (cfile.getUseGrandInclude()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  /** These allow you to specify files not in the include database
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    which are prepended and appended to the file list, allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    you to have well-known functions at the start and end of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    text segment (allows us to find out in a portable fashion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    whether the current PC is in VM code or not upon a crash) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public void setFirstFile(String fileName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    firstFile = fileName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public void setLastFile(String fileName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    lastFile = fileName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  public void get(String platFileName, String dbFileName)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    throws FileFormatException, IOException, FileNotFoundException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      macros.readFrom(platFileName, missingOk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      BufferedReader reader = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        reader = new BufferedReader(new FileReader(dbFileName));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      } catch (FileNotFoundException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        if (missingOk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
          throw(e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      System.out.println("\treading database: " + dbFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      String line;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      int lineNo = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        line = reader.readLine();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        lineNo++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        if (line != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
          StreamTokenizer tokenizer =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
            new StreamTokenizer(new StringReader(line));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
          tokenizer.slashSlashComments(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
          tokenizer.wordChars('_', '_');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
          tokenizer.wordChars('<', '>');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
          // NOTE: if we didn't have to do this line by line,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
          // we could trivially recognize C-style comments as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
          // well.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
          // tokenizer.slashStarComments(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
          int numTok = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          int res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
          String unexpandedIncluder = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
          String unexpandedIncludee = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
          do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
            res = tokenizer.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
            if (res != StreamTokenizer.TT_EOF) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
              if (numTok == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                unexpandedIncluder = tokenizer.sval;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
              } else if (numTok == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
                unexpandedIncludee = tokenizer.sval;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                throw new FileFormatException(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                    "invalid line: \"" + line +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                    "\". Error position: line " + lineNo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
              numTok++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
          } while (res != StreamTokenizer.TT_EOF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
          if ((numTok != 0) && (numTok != 2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
            throw new FileFormatException(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
                "invalid line: \"" + line +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
                "\". Error position: line " + lineNo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          if (numTok == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
            // Non-empty line
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
            String includer = macros.expand(unexpandedIncluder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
            String includee = macros.expand(unexpandedIncludee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
            if (includee.equals(plat.generatePlatformDependentInclude())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
              MacroDefinitions localExpander = macros.copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
              MacroDefinitions localExpander2 = macros.copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
              localExpander.setAllMacroBodiesTo("pd");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
              localExpander2.setAllMacroBodiesTo("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
              // unexpanded_includer e.g. thread_<os_arch>.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
              // thread_solaris_i486.hpp -> _thread_pd.hpp.incl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
              FileName pdName =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                plat.getInclFileTemplate().copyStem(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                    localExpander.expand(unexpandedIncluder)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
              // derive generic name from platform specific name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
              // e.g. os_<arch_os>.hpp => os.hpp. We enforce the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
              // restriction (imperfectly) noted in includeDB_core
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
              // that platform specific files will have an underscore
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
              // preceding the macro invocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
              // First expand macro as null string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
              String newIncluder_temp =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                localExpander2.expand(unexpandedIncluder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
              // Now find "_." and remove the underscore.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
              String newIncluder = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
              int len = newIncluder_temp.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
              int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
              for ( int i = 0; i < len - 1 ; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                if (newIncluder_temp.charAt(i) == '_' && newIncluder_temp.charAt(i+1) == '.') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                  count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                  newIncluder += newIncluder_temp.charAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
              newIncluder += newIncluder_temp.charAt(len-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
              if (count != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
                throw new FileFormatException(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                    "Unexpected filename format for platform dependent file.\nline: \"" + line +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                    "\".\nError position: line " + lineNo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
              FileList p = allFiles.listForFile(includer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
              p.setPlatformDependentInclude(pdName.dirPreStemSuff());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
              // Add an implicit dependency on platform
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
              // specific file for the generic file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
              p = platformFiles.listForFile(newIncluder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
              // if this list is empty then this is 1st
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
              // occurance of a platform dependent file and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
              // we need a new version of the include file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
              // Otherwise we just append to the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
              // file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
              PrintWriter pdFile =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                new PrintWriter(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                    new FileWriter(pdName.dirPreStemSuff(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                      !p.isEmpty())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
                    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
              pdFile.println("# include \"" + includer + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
              pdFile.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
              // Add the platform specific file to the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
              // for this generic file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
              FileList q = allFiles.listForFile(includer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
              p.addIfAbsent(q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
              FileList p = allFiles.listForFile(includer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
              if (isOuterFile(includer))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
                outerFiles.addIfAbsent(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
              if (includee.equals(plat.noGrandInclude())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
                p.setUseGrandInclude(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
                FileList q = allFiles.listForFile(includee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
                p.addIfAbsent(q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      } while (line != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      reader.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      // Keep allFiles in well-known order so we can easily determine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      // whether the known files are the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      allFiles.sortByName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      // Add first and last files differently to prevent a mistake
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      // in ordering in the include databases from breaking the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      // error reporting in the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      if (firstFile != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        FileList p = allFiles.listForFile(firstFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        allFiles.setFirstFile(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        outerFiles.setFirstFile(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      if (lastFile != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        FileList p = allFiles.listForFile(lastFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
        allFiles.setLastFile(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
        outerFiles.setLastFile(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  public void compute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    System.out.println("\tcomputing closures\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    // build both indiv and grand results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    for (Iterator iter = outerFiles.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      indivIncludes.add(((FileList) iter.next()).doCFile());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      ++nOuterFiles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    if (!plat.haveGrandInclude())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      return; // nothing in grand include
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    // count how many times each include is included & add em to grand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    for (Iterator iter = indivIncludes.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      FileList indivInclude = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      if (!indivInclude.getUseGrandInclude()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
        continue; // do not bump count if my files cannot be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
        // in grand include
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      indivInclude.doFiles(grandInclude); // put em on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      // grand_include list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      for (Iterator incListIter = indivInclude.iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
          incListIter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        ((FileList) incListIter.next()).incrementCount();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Not sure this is necessary in Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  public void verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    for (Iterator iter = indivIncludes.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      if (iter.next() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
        plat.abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  public void put() throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    writeIndividualIncludes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    if (plat.haveGrandInclude())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      writeGrandInclude();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    writeGrandUnixMakefile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  private void writeIndividualIncludes() throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    System.out.println("\twriting individual include files\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    for (Iterator iter = indivIncludes.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      FileList list = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      System.out.println("\tcreating " + list.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      list.putInclFile(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  private void writeGrandInclude() throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    System.out.println("\twriting grand include file\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    PrintWriter inclFile =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      new PrintWriter(new FileWriter(plat.getGIFileTemplate().dirPreStemSuff()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    plat.writeGIPragma(inclFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    for (Iterator iter = grandInclude.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      FileList list = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      if (list.getCount() >= threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
        inclFile.println("# include \"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
            plat.getGIFileTemplate().getInvDir() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
            list.getName() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
            "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
        nPrecompiledFiles += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    inclFile.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    inclFile.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  private void writeGrandUnixMakefile() throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    if (!plat.writeDeps())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    System.out.println("\twriting dependencies file\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    PrintWriter gd =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      new PrintWriter(new FileWriter(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
            plat.getGDFileTemplate().dirPreStemSuff())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
          );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    gd.println("# generated by makeDeps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    // HACK ALERT. The compilation of ad_<arch> files is very slow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // We want to start compiling them as early as possible. The compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    // order on unix is dependant on the order we emit files here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    // By sorting the output before emitting it, we expect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    // that ad_<arch> will be compiled early.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    boolean shouldSortObjFiles = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    if (shouldSortObjFiles) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      ArrayList sortList = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      // We need to preserve the ordering of the first and last items
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      // in outerFiles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      int size = outerFiles.size() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      String firstName = removeSuffixFrom(((FileList)outerFiles.get(0)).getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      String lastName = removeSuffixFrom(((FileList)outerFiles.get(size)).getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      for (int i=1; i<size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
        FileList anOuterFile = (FileList)outerFiles.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        String stemName = removeSuffixFrom(anOuterFile.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        sortList.add(stemName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      Collections.sort(sortList);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      // write Obj_Files = ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      gd.println("Obj_Files = \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      gd.println(firstName + plat.objFileSuffix() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      for (Iterator iter = sortList.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        gd.println(iter.next() + plat.objFileSuffix() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      gd.println(lastName + plat.objFileSuffix() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      // write Obj_Files = ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      gd.println("Obj_Files = \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      for (Iterator iter = outerFiles.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
        FileList anOuterFile = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
        String stemName = removeSuffixFrom(anOuterFile.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
        gd.println(stemName + plat.objFileSuffix() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    if (nPrecompiledFiles > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      // write Precompiled_Files = ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      gd.println("Precompiled_Files = \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      for (Iterator iter = grandInclude.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
        FileList list = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        gd.println(list.getName() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    gd.println("DTraced_Files = \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    for (Iterator iter = outerFiles.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      FileList anOuterFile = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      if (anOuterFile.hasListForFile("dtrace.hpp")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
        String stemName = removeSuffixFrom(anOuterFile.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
        gd.println(stemName + plat.objFileSuffix() + " \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      // write each dependency
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      for (Iterator iter = indivIncludes.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
        FileList anII = (FileList) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
        String stemName = removeSuffixFrom(anII.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
        String inclFileName =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
          plat.getInclFileTemplate().copyStem(anII.getName()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
          preStemSuff();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
        gd.println(stemName + plat.objFileSuffix() + " " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
            stemName + plat.asmFileSuffix() + ": \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        printDependentOn(gd, anII.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
        // this gets the include file that includes all that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        // this file needs (first level) since nested includes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        // are skipped to avoid cycles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        printDependentOn(gd, inclFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        if ( plat.haveGrandInclude() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
          printDependentOn(gd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
              plat.getGIFileTemplate().preStemSuff());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
        for (Iterator iiIter = anII.iterator(); iiIter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
          FileList hfile = (FileList) iiIter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
          if (!hfileIsInGrandInclude(hfile, anII) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
              plat.writeDependenciesOnHFilesFromGI()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
                printDependentOn(gd, hfile.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
          if (platformFiles.hasListForFile(hfile.getName())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
            FileList p =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
              platformFiles.listForFile(hfile.getName());;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
            for (Iterator hiIter = p.iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
                hiIter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
              FileList hi2 = (FileList) hiIter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
              if (!hfileIsInGrandInclude(hi2, p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
                printDependentOn(gd, hi2.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
        if (plat.includeGIDependencies()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
            && nPrecompiledFiles > 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
            && anII.getUseGrandInclude()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
          gd.println("    $(Precompiled_Files) \\");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
        gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
        gd.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    gd.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  public void putDiffs(Database previous) throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    System.out.println("\tupdating output files\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    if (!indivIncludes.compareLists(previous.indivIncludes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
        || !grandInclude.compareLists(previous.grandInclude)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      System.out.println("The order of .c or .s has changed, or " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
          "the grand include file has changed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      put();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    Iterator curIter = indivIncludes.iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    Iterator prevIter = previous.indivIncludes.iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
      while (curIter.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
        FileList newCFileList = (FileList) curIter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
        FileList prevCFileList = (FileList) prevIter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
        if (!newCFileList.compareLists(prevCFileList)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          System.out.println("\tupdating " + newCFileList.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
          newCFileList.putInclFile(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      throw new InternalError("assertion failure: cur and prev " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
          "database lists changed unexpectedly.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    writeGrandUnixMakefile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  private void printDependentOn(PrintWriter gd, String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    gd.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    gd.print(plat.dependentPrefix() + name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  private boolean isOuterFile(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    int len = s.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    String[] suffixes = plat.outerSuffixes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    for (int i = 0; i < suffixes.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      String suffix = suffixes[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      int suffLen = suffix.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      if ((len >= suffLen) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
          (plat.fileNameStringEquality(s.substring(len - suffLen),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
                                       suffix))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  private String removeSuffixFrom(String s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    int idx = s.lastIndexOf('.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    if (idx <= 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      plat.abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    return s.substring(0, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
}