001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package makedep;
028:
029: /** Defines what must be specified for each platform. This class must
030: have a no-arg constructor. */
031:
032: import java.io.*;
033:
034: public abstract class Platform {
035: // The next three must be instantiated in subclasses' constructors
036:
037: /** An incl file is produced per .c file and contains all the
038: includes it needs */
039: protected FileName inclFileTemplate;
040:
041: /** A GI (grand-include) file has any file used more than N times
042: for precompiled headers */
043: protected FileName giFileTemplate;
044:
045: /** A GD (grand-dependencies) file that tells Unix make all the
046: .o's needed for linking and the include dependencies */
047: protected FileName gdFileTemplate;
048:
049: // Accessors
050: public FileName getInclFileTemplate() {
051: return inclFileTemplate;
052: }
053:
054: public FileName getGIFileTemplate() {
055: return giFileTemplate;
056: }
057:
058: public FileName getGDFileTemplate() {
059: return gdFileTemplate;
060: }
061:
062: // an incl file is the file included by each.c file that includes
063: // all needed header files
064:
065: public void setupFileTemplates() {
066: String inclsDir = "incls" + fileSeparator();
067: inclFileTemplate = new FileName(this , inclsDir, "_", "",
068: ".incl", "", "");
069: giFileTemplate = new FileName(this , inclsDir, "",
070: "_precompiled", ".incl", "", "");
071: gdFileTemplate = new FileName(this , "", "", "Dependencies", "",
072: "", "");
073: }
074:
075: public abstract String[] outerSuffixes();
076:
077: public abstract String fileSeparator();
078:
079: /** empty file name -> no grand include file */
080: public boolean haveGrandInclude() {
081: return usePrecompiledHeader
082: && (giFileTemplate.nameOfList().length() > 0);
083: }
084:
085: public boolean writeDeps() {
086: return (gdFileTemplate.nameOfList().length() > 0);
087: }
088:
089: /** <p> A gi file is the grand-include file. It includes in one
090: file any file that is included more than a certain number of
091: times. </p>
092:
093: <p> It is used for precompiled header files. </p>
094:
095: <p> It has a source name, that is the file that this program
096: generates, and a compiled name; that is the file that is
097: included by other files. </p>
098:
099: <p> Some platforms have this program actually explicitly
100: include the preprocessed gi file-- see includeGIInEachIncl().
101: </p>
102:
103: <p> Also, some platforms need a pragma in the GI file. </p> */
104: public boolean includeGIInEachIncl() {
105: return false;
106: }
107:
108: /** For some platforms, e.g. Solaris, include the grand-include
109: dependencies in the makefile. For others, e.g. Windows, do
110: not. */
111: public boolean includeGIDependencies() {
112: return false;
113: }
114:
115: /** Default implementation does nothing */
116: public void writeGIPragma(PrintWriter out) {
117: }
118:
119: /** A line with a filename and the noGrandInclude string means
120: that this file cannot use the precompiled header. */
121: public String noGrandInclude() {
122: return "no_precompiled_headers";
123: }
124:
125: /** A line with a filename and the
126: generatePlatformDependentInclude means that an include file
127: for the header file must be generated. Does not effect the
128: dependency computation. */
129: public String generatePlatformDependentInclude() {
130: return "generate_platform_dependent_include";
131: }
132:
133: /** Prefix and suffix strings for emitting Makefile rules */
134: public abstract String objFileSuffix();
135:
136: public abstract String asmFileSuffix();
137:
138: public abstract String dependentPrefix();
139:
140: // Exit routines:
141:
142: /** Abort means an internal error */
143: public void abort() {
144: throw new RuntimeException("Internal error");
145: }
146:
147: /** fatalError is used by clients to stop the system */
148: public void fatalError(String msg) {
149: System.err.println(msg);
150: System.exit(1);
151: }
152:
153: /** Default implementation performs case-sensitive comparison */
154: public boolean fileNameStringEquality(String s1, String s2) {
155: return s1.equals(s2);
156: }
157:
158: public void fileNamePortabilityCheck(String name) {
159: // Empty for now
160: }
161:
162: public void fileNamePortabilityCheck(String name,
163: String matchingName) {
164: if (!name.equals(matchingName)) {
165: fatalError("Error: file " + name + " also appears as "
166: + matchingName + ". Case must be consistent for "
167: + "portability.");
168: }
169: }
170:
171: /** max is 31 on mac, so warn */
172: public int fileNameLengthLimit() {
173: return 40;
174: }
175:
176: public int defaultGrandIncludeThreshold() {
177: return 30;
178: }
179:
180: /** Not very general, but this is a way to get platform-specific
181: files to be written. Default implementation does nothing. */
182: public void writePlatformSpecificFiles(Database previousDB,
183: Database currentDB, String[] args)
184: throws IllegalArgumentException, IOException {
185: }
186:
187: /* A platform may use this to process the name of a file. E.g., Symbian
188: * strips leading DOS drive names */
189: public String translateFileName(String name) {
190: return name;
191: }
192:
193: boolean usePrecompiledHeader = true;
194:
195: public void setUsePrecompiledHeader(boolean value) {
196: usePrecompiledHeader = value;
197: }
198:
199: boolean getUsePrecompiledHeader() {
200: return usePrecompiledHeader;
201: }
202: }
|