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