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