src/share/tools/MakeDeps/MakeDeps.java

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 435
a61af66fc99e
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

     1 /*
     2  * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 // This program reads an include file database.
    26 // The database should cover each self .c and .h file,
    27 //   but not files in /usr/include
    28 // The database consists of pairs of nonblank words, where the first word is
    29 //   the filename that needs to include the file named by the second word.
    30 // For each .c file, this program generates a fooIncludes.h file that
    31 //  the .c file may include to include all the needed files in the right order.
    32 // It also generates a foo.dep file to include in the makefile.
    33 // Finally it detects cycles, and can work with two files, an old and a new one.
    34 // To incrementally write out only needed files after a small change.
    35 //
    36 // Based on a suggestion by Roland Conybeare, algorithm suggested by Craig
    37 //  Chambers, written by David Ungar, 3/1/89.
    38 //  Added PREFIX, {DEP/INC}_DIR, smaller dep output  10/92  -Urs
    40 // Add something for precompiled headers
    42 // To handle different platforms, I am introducing a platform file.
    43 // The platform file contains lines like:
    44 // os = svr4
    45 //
    46 // Then, when processing the includeDB file, a token such as <os>
    47 // gets replaced by svr4. -- dmu 3/25/97
    49 // Modified to centralize Dependencies to speed up make -- dmu 5/97
    51 public class MakeDeps {
    53     public static void usage() {
    54         System.out.println("usage:");
    55         System.out.println("\tmakeDeps platform-name     platform-file     database-file [MakeDeps args] [platform args]");
    56         System.out.println("\tmakeDeps diffs platform-name old-platform-file old-database-file new-platform-file new-database-file [MakeDeps args] [platform args]");
    57         System.out.println("where platform-name is the name of a platform MakeDeps supports");
    58         System.out.println("(currently \"WinGammaPlatform\" or \"UnixPlatform\")");
    59         System.out.println("MakeDeps options:");
    60         System.out.println("  -firstFile [filename]: Specify the first file in link order (i.e.,");
    61         System.out.println("   to have a well-known function at the start of the output file)");
    62         System.out.println("  -lastFile [filename]: Specify the last file in link order (i.e.,");
    63         System.out.println("   to have a well-known function at the end of the output file)");
    64         System.err.println("WinGammaPlatform platform-specific options:");
    65         System.err.println("  -sourceBase <path to directory (workspace) " +
    66                            "containing source files; no trailing slash>");
    67         System.err.println("  -dspFileName <full pathname to which .dsp file " +
    68                            "will be written; all parent directories must " +
    69                            "already exist>");
    70         System.err.println("  -envVar <environment variable to be inserted " +
    71                            "into .dsp file, substituting for path given in " +
    72                            "-sourceBase. Example: HotSpotWorkSpace>");
    73         System.err.println("  -dllLoc <path to directory in which to put " +
    74                            "jvm.dll and jvm_g.dll; no trailing slash>");
    75         System.err.println("  If any of the above are specified, "+
    76                            "they must all be.");
    77         System.err.println("  Additional, optional arguments, which can be " +
    78                            "specified multiple times:");
    79         System.err.println("    -absoluteInclude <string containing absolute " +
    80                            "path to include directory>");
    81         System.err.println("    -relativeInclude <string containing include " +
    82                            "directory relative to -envVar>");
    83         System.err.println("    -define <preprocessor flag to be #defined " +
    84                            "(note: doesn't yet support " +
    85                            "#define (flag) (value))>");
    86         System.err.println("    -perFileLine <file> <line>");
    87         System.err.println("    -conditionalPerFileLine <file> <line for " +
    88                            "release build> <line for debug build>");
    89         System.err.println("  (NOTE: To work around a bug in nmake, where " +
    90                            "you can't have a '#' character in a quoted " +
    91                            "string, all of the lines outputted have \"#\"" +
    92                            "prepended)");
    93         System.err.println("    -startAt <subdir of sourceBase>");
    94         System.err.println("    -ignoreFile <file which won't be able to be " +
    95                            "found in the sourceBase because it's generated " +
    96                            "later>");
    97         System.err.println("    -additionalFile <file not in database but " +
    98                            "which should show up in .dsp file, like " +
    99                            "includeDB_core>");
   100         System.err.println("    -additionalGeneratedFile <environment variable of " +
   101                            "generated file's location> <relative path to " +
   102                            "directory containing file; no trailing slash> " +
   103                            "<name of file generated later in the build process>");
   104         System.err.println("    -prelink <build> <desc> <cmds>:");
   105         System.err.println(" Generate a set of prelink commands for the given BUILD");
   106         System.err.println(" (\"Debug\" or \"Release\"). The prelink description and commands");
   107         System.err.println(" are both quoted strings.");
   108         System.err.println("    Default includes: \".\"");
   109         System.err.println("    Default defines: WIN32, _WINDOWS, \"HOTSPOT_BUILD_USER=$(USERNAME)\"");
   110     }
   112     public static void main(String[] args) {
   113         try {
   114             if (args.length < 3) {
   115                 usage();
   116                 System.exit(1);
   117             }
   119             int argc = 0;
   120             boolean diffMode = false;
   121             if (args[argc].equals("diffs")) {
   122                 diffMode = true;
   123                 ++argc;
   124             }
   126             String platformName = args[argc++];
   127             Class platformClass = Class.forName(platformName);
   129             String plat1 = null;
   130             String db1 = null;
   131             String plat2 = null;
   132             String db2 = null;
   134             String firstFile = null;
   135             String lastFile = null;
   137             int numOptionalArgs =
   138                 (diffMode ? (args.length - 6) : (args.length - 3));
   139             if (numOptionalArgs < 0) {
   140                 usage();
   141                 System.exit(1);
   142             }
   144             plat1 = args[argc++];
   145             db1   = args[argc++];
   147             if (diffMode) {
   148               plat2 = args[argc++];
   149               db2   = args[argc++];
   150             }
   152             // argc now points at start of optional arguments, if any
   154             try {
   155               boolean gotOne = true;
   156               while (gotOne && (argc < args.length - 1)) {
   157                 gotOne = false;
   158                 String arg = args[argc];
   159                 if (arg.equals("-firstFile")) {
   160                   firstFile = args[argc + 1];
   161                   argc += 2;
   162                   gotOne = true;
   163                 } else if (arg.equals("-lastFile")) {
   164                   lastFile = args[argc + 1];
   165                   argc += 2;
   166                   gotOne = true;
   167                 }
   168               }
   169             }
   170             catch (Exception e) {
   171               e.printStackTrace();
   172               usage();
   173               System.exit(1);
   174             }
   176             Platform platform = (Platform) platformClass.newInstance();
   177             platform.setupFileTemplates();
   178             long t = platform.defaultGrandIncludeThreshold();
   180             String[] platformArgs = null;
   181             int numPlatformArgs = args.length - argc;
   182             if (numPlatformArgs > 0) {
   183                 platformArgs = new String[numPlatformArgs];
   184                 int offset = argc;
   185                 while (argc < args.length) {
   186                   platformArgs[argc - offset] = args[argc];
   187                   ++argc;
   188                 }
   189             }
   191             // If you want to change the threshold, change the default
   192             // "grand include" threshold in Platform.java, or override
   193             // it in the platform-specific file like UnixPlatform.java
   195             Database previous = new Database(platform, t);
   196             Database current = new Database(platform, t);
   198             previous.canBeMissing();
   200             if (firstFile != null) {
   201               previous.setFirstFile(firstFile);
   202               current.setFirstFile(firstFile);
   203             }
   204             if (lastFile != null) {
   205               previous.setLastFile(lastFile);
   206               current.setLastFile(lastFile);
   207             }
   209             if (diffMode) {
   210                 System.out.println("Old database:");
   211                 previous.get(plat1, db1);
   212                 previous.compute();
   213                 System.out.println("New database:");
   214                 current.get(plat2, db2);
   215                 current.compute();
   216                 System.out.println("Deltas:");
   217                 current.putDiffs(previous);
   218             } else {
   219                 System.out.println("New database:");
   220                 current.get(plat1, db1);
   221                 current.compute();
   222                 current.put();
   223             }
   225             if (platformArgs != null) {
   226                 // Allow the platform to write platform-specific files
   227                 platform.writePlatformSpecificFiles(previous, current,
   228                                                     platformArgs);
   229             }
   230         }
   231         catch (Exception e) {
   232             e.printStackTrace();
   233               System.exit(1);
   234         }
   235     }
   236 }

mercurial