0001: /*
0002: *
0003: *
0004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
0005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006: *
0007: * This program is free software; you can redistribute it and/or
0008: * modify it under the terms of the GNU General Public License version
0009: * 2 only, as published by the Free Software Foundation.
0010: *
0011: * This program is distributed in the hope that it will be useful, but
0012: * WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * General Public License version 2 for more details (a copy is
0015: * included at /legal/license.txt).
0016: *
0017: * You should have received a copy of the GNU General Public License
0018: * version 2 along with this work; if not, write to the Free Software
0019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020: * 02110-1301 USA
0021: *
0022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023: * Clara, CA 95054 or visit www.sun.com if you need additional
0024: * information or have any questions.
0025: */
0026:
0027: package makedep;
0028:
0029: import java.io.*;
0030: import java.util.*;
0031: import java.awt.*;
0032: import java.awt.event.*;
0033: import javax.swing.*;
0034: import config.Configurator;
0035:
0036: /**
0037: * Win32IDETool creates a cldc_vm.dsw project file for building
0038: * the VM inside Visual Studio 6.0. To get started:
0039: * <ul>
0040: * <li> Change to the build\win32_i386_ide subdirectory of
0041: * this VM source distribution;
0042: * <li> Type "idetool create" in the Command Prompt.
0043: * </ul>
0044: *
0045: * Output structure:
0046: *
0047: * $(BuildSpace)/cldc_vm.dsw
0048: *
0049: * $(BuildSpace)/javaapi/javaapi.dsp
0050: * jcc.zip
0051: * classes.zip
0052: * NativesTable.cpp
0053: *
0054: * $(BuildSpace)/loopgen/loopgen.dsp
0055: * Debug/loopgen.exe
0056: *
0057: * $(BuildSpace)/loop/loop.dsp
0058: *
0059: * $(BuildSpace)/romgen/romgen.dsp
0060: * $(BuildSpace)/romgen/Release/romgen.exe
0061: *
0062: * $(BuildSpace)/romimage/romimage.dsp
0063: * $(BuildSpace)/romimage/ROMImage.cpp
0064: *
0065: * $(BuildSpace)/cldc_vm/cldc_vm.dsp
0066: * $(BuildSpace)/cldc_vm/Debug/Interpreter_i386.asm
0067: * $(BuildSpace)/cldc_vm/Debug/OopMaps.cpp
0068: * Debug/cldc_vm.exe
0069: * Release/cldc_vm.exe
0070: * Product/cldc_vm.exe
0071: */
0072: public class Win32IDETool extends IDETool {
0073: public static String DEBUG_LOOPGEN = "Debug loop generator";
0074: public static String DEBUG_ROMGEN = "Debug ROM generator";
0075:
0076: public static void main(String args[]) {
0077: Win32IDETool tool = new Win32IDETool();
0078: try {
0079: tool.execute(args);
0080: } catch (Exception e) {
0081: e.printStackTrace();
0082: System.exit(-1);
0083: }
0084: }
0085:
0086: public int parseOneArgument(String args[], int i)
0087: throws ArrayIndexOutOfBoundsException {
0088: return super .parseOneArgument(args, i);
0089: }
0090:
0091: public void execute(String args[]) throws Exception {
0092: parseArguments(args);
0093: initConfigurator(); // in IDETool
0094: setUserSettings(queryUserSettings());
0095:
0096: VC6WorkSpace vc6ws = new VC6WorkSpace(this );
0097:
0098: // (1) API project
0099: VC6JavaAPIProject apiProject = new VC6JavaAPIProject(this );
0100:
0101: // (2) Loop generator project
0102: VC6VMProject loopgenProject = new VC6VMProject(this , "loopgen",
0103: "i386", VC6VMProject.LOOPGEN);
0104: loopgenProject.addDependency(apiProject);
0105:
0106: // (2) Interpreter Loop project
0107: VC6LoopProject loopProject = null;
0108: loopProject = new VC6LoopProject(this );
0109: loopProject.addDependency(loopgenProject);
0110:
0111: VC6VMProject romgenProject = null;
0112: VC6ROMImageProject romimageProject = null;
0113:
0114: if (isRomizing()) {
0115: // (3) ROM generator project
0116: romgenProject = new VC6VMProject(this , "romgen", "i386",
0117: VC6VMProject.ROMGEN);
0118: romgenProject.addDependency(apiProject);
0119: romgenProject.addDependency(loopgenProject);
0120: romgenProject.addDependency(loopProject);
0121:
0122: romimageProject = new VC6ROMImageProject(this );
0123: romimageProject.addDependency(romgenProject);
0124: }
0125:
0126: // (5) Target project
0127: VC6VMProject targetProject = new VC6VMProject(this , "cldc_vm",
0128: "i386", VC6VMProject.TARGET);
0129: targetProject.addDependency(apiProject);
0130: targetProject.addDependency(loopgenProject);
0131:
0132: if (isRomizing()) {
0133: targetProject.addDependency(romimageProject);
0134: }
0135:
0136: vc6ws.addProject(apiProject);
0137: vc6ws.addProject(loopgenProject);
0138: vc6ws.addProject(loopProject);
0139: if (isRomizing()) {
0140: vc6ws.addProject(romgenProject);
0141: vc6ws.addProject(romimageProject);
0142: }
0143: vc6ws.addProject(targetProject);
0144:
0145: vc6ws.write();
0146: System.exit(0);
0147: }
0148:
0149: Vector getBuildOptions() {
0150: Vector v = new Vector();
0151: v.addElement("ROMIZING");
0152: Vector enableFlags = configurator.getFlagNames();
0153: for (int i = 0; i < enableFlags.size(); i++) {
0154: v.addElement((String) enableFlags.elementAt(i));
0155: }
0156:
0157: return v;
0158: }
0159:
0160: Vector getGeneratorOptions() {
0161: Vector v = new Vector();
0162: v.addElement(DEBUG_LOOPGEN);
0163: v.addElement(DEBUG_ROMGEN);
0164:
0165: return v;
0166: }
0167:
0168: Vector getPaths() {
0169: Vector v = new Vector();
0170: v.addElement("javac.exe");
0171: v.addElement("java.exe");
0172: v.addElement("jar.exe");
0173: v.addElement("ml.exe");
0174: v.addElement("preverify.exe");
0175:
0176: return v;
0177: }
0178:
0179: /**
0180: * Read user settings from $BuildSpace/prefs.props, then pop up
0181: * a dialog to ask for user modification
0182: */
0183: Properties queryUserSettings() throws Exception {
0184: Properties props = new Properties();
0185:
0186: // Put default settings
0187: Vector v = getBuildOptions();
0188: for (int i = 0; i < v.size(); i++) {
0189: String name = (String) v.elementAt(i);
0190: if (name.equals("ROMIZING")) {
0191: props.put(v.elementAt(i), "true");
0192: } else {
0193: props.put(v.elementAt(i), "default");
0194: }
0195: }
0196:
0197: props.put(DEBUG_LOOPGEN, "true");
0198: props.put(DEBUG_ROMGEN, "false");
0199:
0200: String workspace = getWorkSpaceArg();
0201: String preverify = workspace + "/build/share/bin/win32_i386/"
0202: + "preverify.exe";
0203: preverify = preverify.replace('/', File.separatorChar);
0204:
0205: props.put("javac.exe", "");
0206: props.put("java.exe", "");
0207: props.put("jar.exe", "");
0208: props.put("ml.exe", "");
0209: props.put("preverify.exe", preverify);
0210:
0211: String prefsFile = getOutputFileFullPath("prefs.props");
0212: try {
0213: // Load from saved values
0214: FileInputStream in = new FileInputStream(prefsFile);
0215: props.load(in);
0216: in.close();
0217: } catch (IOException e) {
0218: // ignore it
0219: }
0220:
0221: Win32IDESettingsDialog dialog = new Win32IDESettingsDialog();
0222:
0223: // The following call blocks until the user has finished with
0224: // dialog.
0225: dialog.getUserInput(props, getBuildOptions(),
0226: getGeneratorOptions(), getPaths());
0227:
0228: try {
0229: FileOutputStream out = new FileOutputStream(prefsFile);
0230: props.store(out, "");
0231: out.close();
0232: } catch (IOException e) {
0233: // ignore it
0234: }
0235:
0236: return props;
0237: }
0238:
0239: public String getExecutablePath(String name) {
0240: Object path = getUserSettings().get(name);
0241: if (path != null && (path instanceof String)) {
0242: String result = getAbsolutePath((String) path);
0243: //System.out.println(name + " = " + result);
0244: return result;
0245: } else {
0246: return name;
0247: }
0248: }
0249:
0250: public boolean isRomizing() {
0251: return isOptionEnabled("ROMIZING");
0252: }
0253: }
0254:
0255: abstract class IDEOutputFile {
0256: private IDETool tool;
0257: private PrintWriter outFile;
0258:
0259: public IDEOutputFile(IDETool tool) {
0260: this .tool = tool;
0261: }
0262:
0263: public IDETool tool() {
0264: return this .tool;
0265: }
0266:
0267: public void putln() {
0268: putln("");
0269: }
0270:
0271: public void putln(String s) {
0272: outFile.println(s);
0273: }
0274:
0275: public void put(String s) {
0276: outFile.print(s);
0277: }
0278:
0279: public void openOutputFile(String fileName) throws Exception {
0280: outFile = tool().openOutputFile(fileName);
0281: }
0282:
0283: public void closeOutputFile() throws Exception {
0284: outFile.close();
0285: }
0286: }
0287:
0288: /**
0289: * Create a workspace for VC6. A workspace contains multiple projects.
0290: */
0291: class VC6WorkSpace extends IDEOutputFile {
0292: private Vector projects;
0293:
0294: public VC6WorkSpace(IDETool tool) {
0295: super (tool);
0296: this .projects = new Vector();
0297: }
0298:
0299: public void addProject(IDEProject proj) {
0300: projects.addElement(proj);
0301: }
0302:
0303: /**
0304: * Write all files associated with this workspace, including the .dsw
0305: * file, .dsp files for all sub-projects, and all generated files.
0306: */
0307: public void write() throws Exception {
0308: writeWorkspaceFile();
0309: writeProjectFiles();
0310: }
0311:
0312: void writeProjectFiles() throws Exception {
0313: for (int i = 0; i < projects.size(); i++) {
0314: IDEProject proj = (IDEProject) projects.elementAt(i);
0315: proj.write();
0316: }
0317: }
0318:
0319: /**
0320: * Write the .dsw file for this workspace
0321: */
0322: void writeWorkspaceFile() throws Exception {
0323: openOutputFile("cldc_vm.dsw");
0324: writeHeader();
0325: writeProjects();
0326: writeFooter();
0327: closeOutputFile();
0328: }
0329:
0330: void writeHeader() {
0331: putln("Microsoft Developer Studio Workspace File, "
0332: + "Format Version 6.00");
0333: putln("# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!");
0334: writeSeparator();
0335: }
0336:
0337: void writeSeparator() {
0338: putln();
0339: putln("####################################################"
0340: + "###########################");
0341: putln();
0342: putln();
0343: }
0344:
0345: void writeProjects() throws Exception {
0346: for (int i = 0; i < projects.size(); i++) {
0347: IDEProject proj = (IDEProject) projects.elementAt(i);
0348: writeProject(proj);
0349: }
0350: }
0351:
0352: void writeProject(IDEProject proj) throws Exception {
0353: put("Project: \"" + proj.getName() + "\"=.\\");
0354: put(proj.getOutputDir() + "\\" + proj.getName() + ".dsp - ");
0355: put("Package Owner=<4>");
0356: putln();
0357: putln();
0358: putln("Package=<5>");
0359: putln("{{{");
0360: putln("}}}");
0361: putln();
0362: putln("Package=<4>");
0363: putln("{{{");
0364:
0365: Vector dependencies = proj.getDependencies();
0366: for (int i = 0; i < dependencies.size(); i++) {
0367: IDEProject other = (IDEProject) dependencies.elementAt(i);
0368: putln(" Begin Project Dependency");
0369: putln(" Project_Dep_Name " + other.getName());
0370: putln(" End Project Dependency");
0371: }
0372: putln("}}}");
0373: writeSeparator();
0374: }
0375:
0376: void writeFooter() {
0377: putln("Global:");
0378: putln();
0379: putln("Package=<5>");
0380: putln("{{{");
0381: putln("}}}");
0382: putln("");
0383: putln("Package=<3>");
0384: putln("{{{");
0385: putln("}}}");
0386: writeSeparator();
0387: }
0388: }
0389:
0390: abstract class IDEProject extends IDEOutputFile {
0391: String name;
0392: String outputDir;
0393:
0394: /**
0395: * Other projects that this project depend on.
0396: */
0397: Vector dependencies;
0398:
0399: public IDEProject(IDETool tool, String name) {
0400: super (tool);
0401: this .name = name;
0402: dependencies = new Vector();
0403: }
0404:
0405: public String getName() {
0406: return name;
0407: }
0408:
0409: void setOutputDir(String dir) {
0410: outputDir = dir;
0411: }
0412:
0413: public String getOutputDir() {
0414: if (outputDir != null) {
0415: return outputDir;
0416: } else {
0417: return name;
0418: }
0419: }
0420:
0421: public abstract void write() throws Exception;
0422:
0423: public void openOutputFile() throws Exception {
0424: tool().makeDirExist(getOutputDir());
0425: openOutputFile(getOutputDir() + File.separator + name + ".dsp");
0426: }
0427:
0428: public String getRelativeSourceFile(String s) {
0429: File file = new File(s);
0430: if (file.isAbsolute()) {
0431: return s;
0432: }
0433: if (tool().isDefaultBuildspace()) {
0434: // IMPL_NOTE: use the right number of ".."'s
0435: return "..\\" + s;
0436: } else {
0437: return tool().getAbsolutePath(s);
0438: }
0439: }
0440:
0441: public void addDependency(IDEProject dependency) {
0442: dependencies.addElement(dependency);
0443: }
0444:
0445: public Vector getDependencies() {
0446: return dependencies;
0447: }
0448: }
0449:
0450: class IDEProjectConfig {
0451: /* E.g.
0452: * "makeproj - Win32 Release" (based on "Win32 (x86) External Target")
0453: */
0454: public String name; /* E.g., "makeproj - Win32 Release" */
0455: public String base; /* E.g., "Win32 (x86) External Target" */
0456: public String outputDir; /* E.g., "Release" */
0457:
0458: public boolean isDebug() {
0459: return (name.indexOf("Debug") >= 0);
0460: }
0461:
0462: public boolean isRelease() {
0463: return (name.indexOf("Release") >= 0);
0464: }
0465:
0466: public boolean isProduct() {
0467: return (name.indexOf("Product") >= 0);
0468: }
0469: }
0470:
0471: abstract class NMakefile extends IDEOutputFile {
0472: String fileName;
0473:
0474: public NMakefile(IDETool tool, String fileName) {
0475: super (tool);
0476: this .fileName = fileName;
0477: }
0478:
0479: /**
0480: * Convenience function for accessing Win32IDETool
0481: */
0482: Win32IDETool win32Tool() {
0483: return (Win32IDETool) tool();
0484: }
0485:
0486: public void write() throws Exception {
0487: openOutputFile(fileName);
0488: writeContents();
0489: closeOutputFile();
0490: }
0491:
0492: public void puttab() {
0493: put("\t");
0494: }
0495:
0496: public void puttabln(String s) {
0497: putln("\t" + s);
0498: }
0499:
0500: abstract void writeContents() throws Exception;
0501: }
0502:
0503: abstract class VC6Project extends IDEProject {
0504: public VC6Project(IDETool tool, String name) {
0505: super (tool, name);
0506: }
0507:
0508: /**
0509: * Convenience function for accessing Win32IDETool
0510: */
0511: Win32IDETool win32Tool() {
0512: return (Win32IDETool) tool();
0513: }
0514:
0515: abstract public String getTargetTypeString();
0516:
0517: abstract public Vector getAvailableConfigs();
0518:
0519: public void addConfig(Vector v, String configName,
0520: String outputDir, String baseName) {
0521: IDEProjectConfig config = new IDEProjectConfig();
0522: config.name = getName() + " - " + configName;
0523: config.base = baseName;
0524: config.outputDir = outputDir;
0525: v.addElement(config);
0526: }
0527:
0528: public String getDefaultConfigName() {
0529: Vector v = getAvailableConfigs();
0530: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(0);
0531: return config.name;
0532: }
0533:
0534: public void writeHeader() {
0535: putln("# Microsoft Developer Studio Project File - "
0536: + "Name=\"" + getName() + "\" - Package Owner=<4>");
0537: putln("# Microsoft Developer Studio Generated Build File, "
0538: + "Format Version 6.00");
0539: putln("# ** DO NOT EDIT **");
0540: putln();
0541: putln("# TARGTYPE " + getTargetTypeString());
0542: putln();
0543: putln("CFG=" + getDefaultConfigName());
0544: }
0545:
0546: void nmakemsg(String s) {
0547: putln("!MESSAGE " + s);
0548: }
0549:
0550: void writeNMakeMessage() {
0551: nmakemsg("This is not a valid makefile. "
0552: + "To build this project using NMAKE,");
0553: nmakemsg("use the Export Makefile command and run");
0554: nmakemsg("");
0555: nmakemsg("NMAKE /f \"" + getName() + ".mak\".");
0556: nmakemsg("");
0557: nmakemsg("You can specify a configuration when running NMAKE");
0558: nmakemsg("by defining the macro CFG on the command line. "
0559: + "For example:");
0560: nmakemsg("");
0561: nmakemsg("NMAKE /f \"" + getName() + ".mak\" CFG=\""
0562: + getDefaultConfigName() + "\"");
0563: nmakemsg("");
0564: nmakemsg("Possible choices for configuration are:");
0565: nmakemsg("");
0566:
0567: Vector v = getAvailableConfigs();
0568: for (int i = 0; i < v.size(); i++) {
0569: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
0570: nmakemsg("\"" + config.name + "\" (based on \""
0571: + config.base + "\")");
0572: }
0573: nmakemsg("");
0574: putln();
0575: }
0576: }
0577:
0578: abstract class VC6NMakeProject extends VC6Project {
0579: abstract public NMakefile getNMakefile(IDETool tool, String fileName);
0580:
0581: abstract public String getTargetFileName();
0582:
0583: public VC6NMakeProject(IDETool tool, String name) {
0584: super (tool, name);
0585: }
0586:
0587: public void write() throws Exception {
0588: openOutputFile();
0589: writeHeader();
0590: writeNMakeMessage();
0591: writeConfigs();
0592: writeTarget();
0593: closeOutputFile();
0594:
0595: String makName = getOutputDir() + File.separator + getName()
0596: + ".mak";
0597: NMakefile nmakefile = getNMakefile(tool(), makName);
0598:
0599: nmakefile.write();
0600: }
0601:
0602: void writeConfigs() {
0603: putln("# Begin Project");
0604: putln("# PROP AllowPerConfigDependencies 0");
0605: putln("# PROP Scc_ProjName \"\"");
0606: putln("# PROP Scc_LocalPath \"\"");
0607:
0608: String ifstr = "!IF";
0609: Vector v = getAvailableConfigs();
0610: for (int i = 0; i < v.size(); i++) {
0611: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
0612: putln();
0613: putln(ifstr + " \"$(CFG)\" == \"" + config.name + "\"");
0614: putln();
0615:
0616: String outdir = config.outputDir;
0617: int debuglib = 0;
0618: if (outdir.equals("Debug")) {
0619: debuglib = 1;
0620: }
0621:
0622: putln("# PROP BASE Use_MFC 0");
0623: putln("# PROP BASE Use_Debug_Libraries " + debuglib);
0624: putln("# PROP BASE Output_Dir \"" + outdir + "\"");
0625: putln("# PROP BASE Intermediate_Dir \"" + outdir + "\"");
0626: putln("# PROP BASE Cmd_Line \"NMAKE /nologo /f \""
0627: + getName() + ".mak\"\"");
0628: putln("# PROP BASE Rebuild_Opt \"/a\"");
0629: putln("# PROP BASE Target_File \"" + getTargetFileName()
0630: + "\"");
0631: putln("# PROP BASE Target_Dir \"\"");
0632: putln("# PROP Use_MFC 0");
0633: putln("# PROP Use_Debug_Libraries " + debuglib);
0634: putln("# PROP Output_Dir \"" + outdir + "\"");
0635: putln("# PROP Intermediate_Dir \"" + outdir + "\"");
0636: putln("# PROP Cmd_Line \"NMAKE /nologo /f \"" + getName()
0637: + ".mak\"\"");
0638: putln("# PROP Rebuild_Opt \"/a\"");
0639: putln("# PROP Target_File \"" + getTargetFileName() + "\"");
0640: putln("# PROP Target_Dir \"\"");
0641:
0642: ifstr = "!ELSEIF";
0643: }
0644:
0645: putln();
0646: putln("!ENDIF");
0647: putln();
0648: }
0649:
0650: void writeTarget() {
0651: putln("# Begin Target");
0652: putln("");
0653:
0654: Vector v = getAvailableConfigs();
0655: for (int i = 0; i < v.size(); i++) {
0656: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
0657: putln("# Name \"" + config.name + "\"");
0658: }
0659:
0660: putln();
0661:
0662: String ifstr = "!IF";
0663: for (int i = 0; i < v.size(); i++) {
0664: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
0665: putln(ifstr + " \"$(CFG)\" == \"" + config.name + "\"");
0666: putln("");
0667:
0668: ifstr = "!ELSEIF";
0669: }
0670:
0671: putln("!ENDIF ");
0672: putln();
0673: putln("# Begin Group \"Source Files\"");
0674: putln();
0675: putln("# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"");
0676: writeSourceFiles(tool().getAPISources());
0677: putln("# End Group");
0678: putln("# Begin Group \"Header Files\"");
0679: putln();
0680: putln("# PROP Default_Filter \"h;hpp;hxx;hm;inl\"");
0681: putln("# End Group");
0682: putln("# Begin Group \"Resource Files\"");
0683: putln();
0684: putln("# PROP Default_Filter "
0685: + "\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"");
0686: putln("# End Group");
0687: putln("# End Target");
0688: putln("# End Project");
0689: }
0690:
0691: void writeSourceFiles(Vector v) {
0692: for (int i = 0; i < v.size(); i++) {
0693: putln("# Begin Source File");
0694: putln();
0695: putln("SOURCE="
0696: + getRelativeSourceFile((String) v.elementAt(i)));
0697: putln("# End Source File");
0698: }
0699: }
0700: }
0701:
0702: class VC6JavaAPIProject extends VC6NMakeProject {
0703: public VC6JavaAPIProject(IDETool tool) {
0704: super (tool, "javaapi");
0705: }
0706:
0707: public String getTargetTypeString() {
0708: return "\"Win32 (x86) External Target\" 0x0106";
0709: }
0710:
0711: public Vector getAvailableConfigs() {
0712: Vector v = new Vector();
0713: String base = "Win32 (x86) External Target";
0714: addConfig(v, "Win32 Release", "Release", base);
0715: return v;
0716: }
0717:
0718: public String getTargetFileName() {
0719: return "NativesTable.cpp";
0720: }
0721:
0722: public NMakefile getNMakefile(IDETool tool, String fileName) {
0723: return new VC6JavaAPINMakefile(tool, fileName, this );
0724: }
0725: }
0726:
0727: class VC6JavaAPINMakefile extends NMakefile {
0728: private IDEProject proj;
0729:
0730: public VC6JavaAPINMakefile(IDETool tool, String fileName,
0731: IDEProject proj) {
0732: super (tool, fileName);
0733: this .proj = proj;
0734: }
0735:
0736: public void writeContents() {
0737: writeHeader();
0738: writeJCC();
0739: writeClassesZip();
0740: writeNativesTable();
0741: writeClean();
0742: }
0743:
0744: void writeHeader() {
0745: putln("# This file is auto-generated. DO NOT EDIT");
0746: putln();
0747: putln("all: NativesTable.cpp");
0748: putln();
0749: putln("JAVAC = " + tool().getExecutablePath("javac.exe"));
0750: putln("JAR = " + tool().getExecutablePath("jar.exe"));
0751: putln("JAVA = " + tool().getExecutablePath("java.exe"));
0752: putln("PREVERIFY = "
0753: + tool().getExecutablePath("preverify.exe"));
0754: putln();
0755: putln();
0756: }
0757:
0758: void writeJCC() {
0759: // JCC_SOURCES
0760: Vector v = tool().getJccSources();
0761: put("JCC_SOURCES =");
0762: for (int i = 0; i < v.size(); i++) {
0763: putln(" \\");
0764: put(" "
0765: + proj.getRelativeSourceFile((String) v
0766: .elementAt(i)));
0767: }
0768: putln();
0769: putln();
0770:
0771: // jcc
0772: putln("jcc:");
0773: puttab();
0774: putln("-@mkdir jcc > NUL 2> NUL");
0775: putln();
0776:
0777: // jcc.jar
0778: putln("jcc.jar: jcc $(JCC_SOURCES)");
0779: puttabln("@echo Creating JCC tool");
0780: puttabln("@\"$(JAVAC)\" -d jcc @<<");
0781: putln("$(JCC_SOURCES)");
0782: putln("<<");
0783: puttabln("@\"$(JAR)\" -cf $@ -C jcc .");
0784: putln();
0785: }
0786:
0787: void writeClassesZip() {
0788: String api_ver;
0789: if (tool().isOptionEnabled("ENABLE_REFLECTION")) {
0790: api_ver = "CLDC 1.1 plus";
0791: } else if (tool().isOptionEnabled("ENABLE_CLDC_11")) {
0792: api_ver = "CLDC 1.1";
0793: } else {
0794: api_ver = "CLDC 1.0";
0795: }
0796:
0797: // API_SOURCES
0798: Vector v = tool().getAPISources();
0799: put("API_SOURCES =");
0800: for (int i = 0; i < v.size(); i++) {
0801: putln(" \\");
0802: put(" "
0803: + proj.getRelativeSourceFile((String) v
0804: .elementAt(i)));
0805: }
0806: putln();
0807: putln();
0808:
0809: // tmpclasses
0810: putln("tmpclasses:");
0811: puttabln("-@mkdir tmpclasses > NUL 2> NUL");
0812: putln();
0813:
0814: // classes
0815: putln("classes:");
0816: puttabln("-@mkdir classes > NUL 2> NUL");
0817: putln();
0818:
0819: putln("classes.zip: tmpclasses classes $(API_SOURCES)");
0820: puttabln("@echo Compiling " + api_ver + " API classes");
0821: puttabln("-@rmdir /Q /S tmpclasses > NUL 2> NUL");
0822: puttabln("-@rmdir /Q /S classes > NUL 2> NUL");
0823: puttabln("-@mkdir tmpclasses > NUL 2> NUL");
0824: puttabln("-@mkdir classes > NUL 2> NUL");
0825: puttabln("@\"$(JAVAC)\" -d tmpclasses @<<");
0826: putln("$(API_SOURCES)");
0827: putln("<<");
0828: puttabln("@echo Preverifying classes");
0829: puttabln("@\"$(PREVERIFY)\" -classpath classes -d classes tmpclasses");
0830: puttabln("@echo Creating $@");
0831: puttabln("@\"$(JAR)\" -cf $@ -C classes .");
0832: putln();
0833: }
0834:
0835: void writeNativesTable() {
0836: putln("NativesTable.cpp: classes.zip jcc.jar");
0837: puttabln("@echo Creating $@");
0838: puttabln("@\"$(JAVA)\" -cp jcc.jar JavaCodeCompact "
0839: + "-writer CLDC_HI_Natives -o $@ classes.zip");
0840: putln();
0841: }
0842:
0843: void writeClean() {
0844: putln("clean:");
0845: puttabln("@echo Cleaning output files");
0846: puttabln("-@rmdir /Q /S jcc > NUL 2> NUL");
0847: puttabln("-@rmdir /Q /S tmpclasses > NUL 2> NUL");
0848: puttabln("-@rmdir /Q /S classes > NUL 2> NUL");
0849: puttabln("-@del /Q jcc.jar > NUL 2> NUL");
0850: puttabln("-@del /Q classes.zip > NUL 2> NUL");
0851: puttabln("-@del /Q NativesTable.cpp > NUL 2> NUL");
0852: }
0853: }
0854:
0855: class VC6ROMImageProject extends VC6NMakeProject {
0856: public VC6ROMImageProject(IDETool tool) {
0857: super (tool, "romimage");
0858: }
0859:
0860: public String getTargetTypeString() {
0861: return "\"Win32 (x86) External Target\" 0x0106";
0862: }
0863:
0864: public Vector getAvailableConfigs() {
0865: Vector v = new Vector();
0866: String base = "Win32 (x86) External Target";
0867: addConfig(v, "Win32 Release", "Release", base);
0868: return v;
0869: }
0870:
0871: public String getTargetFileName() {
0872: return "ROMImage.cpp";
0873: }
0874:
0875: public NMakefile getNMakefile(IDETool tool, String fileName) {
0876: return new VC6ROMImageNMakefile(tool, fileName, this );
0877: }
0878: }
0879:
0880: class VC6ROMImageNMakefile extends NMakefile {
0881: private IDEProject proj;
0882:
0883: public VC6ROMImageNMakefile(IDETool tool, String fileName,
0884: IDEProject proj) {
0885: super (tool, fileName);
0886: this .proj = proj;
0887: }
0888:
0889: public void writeContents() {
0890: writeHeader();
0891: writeROMImageRule();
0892: writeClean();
0893: }
0894:
0895: void writeHeader() {
0896: putln("# This file is auto-generated. DO NOT EDIT");
0897: putln();
0898: putln("all: ROMImage.cpp");
0899: putln();
0900:
0901: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_ROMGEN)) {
0902: putln("ROMGEN = ..\\romgen\\Debug\\romgen.exe");
0903: } else {
0904: putln("ROMGEN = ..\\romgen\\Release\\romgen.exe");
0905: }
0906: putln("CLASSES_ZIP = ..\\javaapi\\classes.zip");
0907: putln();
0908: putln();
0909: }
0910:
0911: void writeROMImageRule() {
0912: String workspace = tool().getWorkSpaceArg();
0913: String romconfig = workspace + File.separator
0914: + "src\\vm\\cldcx_rom.cfg";
0915: romconfig = tool().getAbsolutePath(romconfig);
0916: String rompath = workspace + File.separator + "src\\vm";
0917: rompath = tool().getAbsolutePath(rompath);
0918:
0919: putln("ROMImage.cpp: $(ROMGEN) $(CLASSES_ZIP)");
0920: puttabln("@echo Creating $@");
0921: puttabln("\"$(ROMGEN)\" -cp \"$(CLASSES_ZIP)\" \\");
0922: puttabln(" =HeapCapacity8M \\");
0923: puttabln(" -romconfig \"" + romconfig + "\" \\");
0924: puttabln(" -romincludepath \"" + rompath + "\" \\");
0925: puttabln(" +EnableAllROMOptimizations \\");
0926: puttabln(" -romize \\");
0927: puttabln(" +GenerateROMStructs");
0928: putln();
0929: }
0930:
0931: void writeClean() {
0932: putln("clean:");
0933: puttabln("@echo Cleaning output files");
0934: puttabln("-@del /Q ROMImage.cpp > NUL 2> NUL");
0935: puttabln("-@del /Q ROMLog.txt > NUL 2> NUL");
0936: puttabln("-@del /Q ROMStructs.h > NUL 2> NUL");
0937:
0938: }
0939: }
0940:
0941: class VC6LoopProject extends VC6NMakeProject {
0942: public VC6LoopProject(IDETool tool) {
0943: super (tool, "loop");
0944: }
0945:
0946: public String getTargetTypeString() {
0947: return "\"Win32 (x86) External Target\" 0x0106";
0948: }
0949:
0950: public Vector getAvailableConfigs() {
0951: Vector v = new Vector();
0952: String base = "Win32 (x86) External Target";
0953: addConfig(v, "Win32 Release", "Release", base);
0954: return v;
0955: }
0956:
0957: public String getTargetFileName() {
0958: return "Dummy.cpp";
0959: }
0960:
0961: public NMakefile getNMakefile(IDETool tool, String fileName) {
0962: return new VC6LoopNMakefile(tool, fileName, this );
0963: }
0964: }
0965:
0966: class VC6LoopNMakefile extends NMakefile {
0967: private IDEProject proj;
0968:
0969: public VC6LoopNMakefile(IDETool tool, String fileName,
0970: IDEProject proj) {
0971: super (tool, fileName);
0972: this .proj = proj;
0973: }
0974:
0975: public void writeContents() {
0976: writeHeader();
0977: writeLoopRule();
0978: writeClean();
0979: }
0980:
0981: void writeHeader() {
0982: putln("# This file is auto-generated. DO NOT EDIT");
0983: putln();
0984: putln("all: Dummy.cpp");
0985: putln();
0986:
0987: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_LOOPGEN)) {
0988: putln("LOOPGEN = ..\\loopgen\\Debug\\loopgen.exe");
0989: } else {
0990: putln("LOOPGEN = ..\\loopgen\\Release\\loopgen.exe");
0991: }
0992: putln();
0993: putln();
0994: }
0995:
0996: void writeLoopRule() {
0997: putln("Dummy.cpp: $(LOOPGEN)");
0998: puttabln("@echo Creating Interpreter Loops");
0999:
1000: puttabln("$(LOOPGEN) -generate +GenerateDebugAssembly "
1001: + "-outputdir ..\\cldc_vm\\Debug");
1002: puttabln("$(LOOPGEN) +GenerateOopMaps "
1003: + "-outputdir ..\\cldc_vm\\Debug");
1004:
1005: puttabln("$(LOOPGEN) -generateoptimized "
1006: + "-outputdir ..\\cldc_vm\\Release");
1007: puttabln("$(LOOPGEN) +GenerateOopMaps "
1008: + "-outputdir ..\\cldc_vm\\Release");
1009:
1010: puttabln("$(LOOPGEN) -generateoptimized "
1011: + "-outputdir ..\\cldc_vm\\Product");
1012: puttabln("$(LOOPGEN) +GenerateOopMaps "
1013: + "-outputdir ..\\cldc_vm\\Product");
1014:
1015: if (win32Tool().isRomizing()) {
1016: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_ROMGEN)) {
1017: puttabln("$(LOOPGEN) -generate +GenerateDebugAssembly "
1018: + "-outputdir ..\\romgen\\Debug");
1019: puttabln("$(LOOPGEN) +GenerateOopMaps "
1020: + "-outputdir ..\\romgen\\Debug");
1021: } else {
1022: puttabln("$(LOOPGEN) -generateoptimized "
1023: + "-outputdir ..\\romgen\\Release");
1024: puttabln("$(LOOPGEN) +GenerateOopMaps "
1025: + "-outputdir ..\\romgen\\Release");
1026: }
1027: }
1028:
1029: putln();
1030: }
1031:
1032: void writeClean() {
1033: String junk = " > NUL 2> NUL";
1034: putln("clean:");
1035: puttabln("@echo Cleaning output files");
1036: puttabln("-@del /Q Dummy.cpp" + junk);
1037: puttabln("-@del /Q ..\\cldc_vm\\Debug\\Interpreter_i386.asm"
1038: + junk);
1039: puttabln("-@del /Q ..\\cldc_vm\\Release\\Interpreter_i386.asm"
1040: + junk);
1041: puttabln("-@del /Q ..\\cldc_vm\\Product\\Interpreter_i386.asm"
1042: + junk);
1043: puttabln("-@del /Q ..\\cldc_vm\\Debug\\OopMaps.cpp" + junk);
1044: puttabln("-@del /Q ..\\cldc_vm\\Release\\OopMaps.cpp" + junk);
1045: puttabln("-@del /Q ..\\cldc_vm\\Product\\OopMaps.cpp" + junk);
1046:
1047: if (win32Tool().isRomizing()) {
1048: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_ROMGEN)) {
1049: puttabln("-@del /Q ..\\romgen\\Debug\\Interpreter_i386.asm"
1050: + junk);
1051: puttabln("-@del /Q ..\\romgen\\Debug\\OopMaps.cpp"
1052: + junk);
1053: } else {
1054: puttabln("-@del /Q ..\\romgen\\Release\\Interpreter_i386.asm"
1055: + junk);
1056: puttabln("-@del /Q ..\\romgen\\Release\\OopMaps.cpp"
1057: + junk);
1058: }
1059: }
1060:
1061: }
1062: }
1063:
1064: class VMSourceHandler {
1065: private String arch;
1066: private String os;
1067: private IDETool tool;
1068: private Vector vpaths;
1069: private IDEProject proj;
1070:
1071: public VMSourceHandler(IDETool tool, IDEProject proj, String arch,
1072: String os) {
1073: this .tool = tool;
1074: this .proj = proj;
1075: this .arch = arch;
1076: this .os = os;
1077:
1078: vpaths = new Vector();
1079: addVpath("/src/vm/cpu/" + arch);
1080: addVpath("/src/vm/os/" + os);
1081: addVpath("/src/vm/share/compiler");
1082: addVpath("/src/vm/share/handles");
1083: addVpath("/src/vm/share/interpreter");
1084: addVpath("/src/vm/share/memory");
1085: addVpath("/src/vm/share/natives");
1086: addVpath("/src/vm/share/ROM");
1087: addVpath("/src/vm/share/reflection");
1088: addVpath("/src/vm/share/runtime");
1089: addVpath("/src/vm/share/utilities");
1090: addVpath("/src/vm/share/verifier");
1091: addVpath("/src/vm/share/debugger");
1092: addVpath("/src/vm/share/float");
1093: addVpath("/src/vm/share/isolate");
1094: addVpath("/src/vm/share/dynupdate");
1095: addVpath("/src/vm/share/memoryprofiler");
1096: }
1097:
1098: public String resolveFileForProject(String fileName) {
1099:
1100: for (int i = 0; i < vpaths.size(); i++) {
1101: String s = (String) vpaths.elementAt(i) + File.separator
1102: + fileName;
1103: File f = new File(s);
1104: if (f.exists()) {
1105: return proj.getRelativeSourceFile(s);
1106: }
1107: }
1108:
1109: throw new Error("Source file not found: " + fileName);
1110: }
1111:
1112: public Vector getVpaths() {
1113: return vpaths;
1114: }
1115:
1116: private void addVpath(String vpath) {
1117: String workspace = tool.getWorkSpaceArg();
1118: vpath = workspace + vpath;
1119: vpath = vpath.replace('/', File.separatorChar);
1120: vpaths.addElement(vpath);
1121: }
1122: }
1123:
1124: class VC6VMProject extends VC6Project {
1125: Database database;
1126: VMSourceHandler vmSourceHandler;
1127: int type;
1128:
1129: public final static int LOOPGEN = 1;
1130: public final static int ROMGEN = 2;
1131: public final static int TARGET = 3;
1132:
1133: /**
1134: * @param type must be LOOPGEN, ROMGEN or TARGET
1135: */
1136: public VC6VMProject(IDETool tool, String name, String arch, int type) {
1137: super (tool, name);
1138: vmSourceHandler = new VMSourceHandler(tool, this , arch, "win32");
1139: this .type = type;
1140: }
1141:
1142: public String getTargetTypeString() {
1143: return "\"Win32 (x86) Console Application\" 0x0103";
1144: }
1145:
1146: public Vector getAvailableConfigs() {
1147: Vector v = new Vector();
1148: String base = "Win32 (x86) Console Application";
1149: switch (this .type) {
1150: case TARGET:
1151: addConfig(v, "Win32 Debug", "Debug", base);
1152: addConfig(v, "Win32 Release", "Release", base);
1153: addConfig(v, "Win32 Product", "Product", base);
1154: break;
1155: case LOOPGEN:
1156: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_LOOPGEN)) {
1157: addConfig(v, "Win32 Debug", "Debug", base);
1158: } else {
1159: addConfig(v, "Win32 Release", "Release", base);
1160: }
1161: break;
1162: case ROMGEN:
1163: if (win32Tool().isOptionEnabled(win32Tool().DEBUG_ROMGEN)) {
1164: addConfig(v, "Win32 Debug", "Debug", base);
1165: } else {
1166: addConfig(v, "Win32 Release", "Release", base);
1167: }
1168: break;
1169: }
1170: return v;
1171: }
1172:
1173: void openDatabase() throws Exception {
1174: Platform platform = new WinGammaPlatform();
1175: platform.setupFileTemplates();
1176: long t = platform.defaultGrandIncludeThreshold();
1177:
1178: database = new Database(platform, t);
1179:
1180: tool().makeDirExist(getOutputDir());
1181: tool().makeDirExist(getOutputDir() + File.separator + "incls");
1182: database.setOutputDir(tool().getOutputFileFullPath(
1183: getOutputDir()));
1184:
1185: Properties globalProps = new Properties();
1186: if (tool().isOptionEnabled("ENABLE_JAVA_DEBUGGER")) {
1187: globalProps.put("ENABLE_JAVA_DEBUGGER", "true");
1188: }
1189: if (tool().isOptionEnabled("ENABLE_ROM_JAVA_DEBUGGER")) {
1190: globalProps.put("ENABLE_ROM_JAVA_DEBUGGER", "true");
1191: }
1192: if (tool().isOptionEnabled("ENABLE_ISOLATES")) {
1193: globalProps.put("ENABLE_ISOLATES", "true");
1194: }
1195: if (this .type == TARGET) {
1196: if (tool().isOptionEnabled("ENABLE_MONET")) {
1197: globalProps.put("ENABLE_MONET", "true");
1198: }
1199: }
1200: if (tool().isOptionEnabled("ENABLE_METHOD_TRAPS")) {
1201: globalProps.put("ENABLE_METHOD_TRAPS", "true");
1202: }
1203: if (tool().isOptionEnabled("ENABLE_DYNUPDATE")) {
1204: globalProps.put("ENABLE_DYNUPDATE", "true");
1205: }
1206: globalProps.put("ENABLE_GENERATE_SOURCE_ROM_IMAGE", "true");
1207: globalProps.put("ENABLE_INTERPRETER_GENERATOR", "true");
1208:
1209: database.get(tool().getPlatformArg(), tool().getDatabaseArg(),
1210: globalProps);
1211: database.compute();
1212: }
1213:
1214: public void write() throws Exception {
1215: openDatabase();
1216:
1217: openOutputFile();
1218: writeHeader();
1219: writeNMakeMessage();
1220: writeProjectBlock();
1221: writeSourceFileRules();
1222: writeHeaderFileRules();
1223: writeFooter();
1224: closeOutputFile();
1225: writeIncls();
1226: writeJvmConfig();
1227: }
1228:
1229: public void writeProjectBlock() {
1230: putln("# Begin Project");
1231: putln("# PROP AllowPerConfigDependencies 0");
1232: putln("# PROP Scc_ProjName \"\"");
1233: putln("# PROP Scc_LocalPath \"\"");
1234: putln("CPP=cl.exe");
1235: putln("MTL=midl.exe");
1236: putln("RSC=rc.exe");
1237:
1238: String ifstr = "!IF";
1239: Vector v = getAvailableConfigs();
1240: for (int i = 0; i < v.size(); i++) {
1241: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
1242: putln();
1243: putln(ifstr + " \"$(CFG)\" == \"" + config.name + "\"");
1244: putln();
1245:
1246: String outdir = config.outputDir;
1247: int debuglib = 0;
1248: if (outdir.equals("Debug")) {
1249: debuglib = 1;
1250: }
1251:
1252: putln("# PROP BASE Use_MFC 0");
1253: putln("# PROP BASE Use_Debug_Libraries " + debuglib);
1254: putln("# PROP BASE Output_Dir \"" + outdir + "\"");
1255: putln("# PROP BASE Intermediate_Dir \"" + outdir + "\"");
1256: putln("# PROP BASE Target_Dir \"\"");
1257: putln("# PROP Use_MFC 0");
1258: putln("# PROP Use_Debug_Libraries " + debuglib);
1259: putln("# PROP Output_Dir \"" + outdir + "\"");
1260: putln("# PROP Intermediate_Dir \"" + outdir + "\"");
1261: putln("# PROP Ignore_Export_Lib 0");
1262: putln("# PROP Target_Dir \"\"");
1263:
1264: put("# ADD BASE CPP ");
1265: putBaseCppFlags(config);
1266: putln("/YX /FR /FD /c");
1267:
1268: put("# ADD CPP /I \".\" ");
1269: putIncludePaths();
1270: putCppFlags(config, true);
1271: putln("/c");
1272:
1273: putln("# ADD BASE RSC /l 0x406 /d \"NDEBUG\"");
1274: putln("# ADD RSC /l 0x406 /d \"NDEBUG\"");
1275: putln("BSC32=bscmake.exe");
1276: putln("# ADD BASE BSC32 /nologo");
1277: putln("# ADD BSC32 /nologo");
1278: putln("LINK32=link.exe");
1279:
1280: String linkLine = "LINK32 gdi32.lib user32.lib wsock32.lib "
1281: + "/nologo /subsystem:console /incremental:no "
1282: + "/machine:I386";
1283:
1284: if (outdir.equals("Debug")) {
1285: linkLine += " /debug";
1286: }
1287:
1288: putln("# ADD BASE " + linkLine);
1289: putln("# ADD " + linkLine);
1290:
1291: ifstr = "!ELSEIF";
1292: }
1293: putln();
1294: putln("!ENDIF");
1295: putln();
1296:
1297: putln("# Begin Target");
1298: putln();
1299: for (int i = 0; i < v.size(); i++) {
1300: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
1301: putln("# Name \"" + config.name + "\"");
1302: }
1303: }
1304:
1305: void putBaseCppFlags(IDEProjectConfig config) {
1306: put("/nologo ");
1307:
1308: if (config.isDebug()) {
1309: put("/W3 /Gm /Zi /Od ");
1310: } else if (config.isRelease()) {
1311: put("/W3 /O2 /Zi /Od ");
1312: } else {
1313: put("/W3 /O2 ");
1314: }
1315:
1316: Vector v = getBaseCppDefines(config);
1317: for (int i = 0; i < v.size(); i++) {
1318: put("/D \"" + v.elementAt(i) + "\" ");
1319: }
1320: }
1321:
1322: void putCppFlags(IDEProjectConfig config, boolean usePCH) {
1323: putBaseCppFlags(config);
1324:
1325: Vector v = getCppDefines(config);
1326: for (int i = 0; i < v.size(); i++) {
1327: put("/D \"" + v.elementAt(i) + "\" ");
1328: }
1329: if (usePCH) {
1330: put("/FR /Yu\"incls/_precompiled.incl\" /FD ");
1331: }
1332: }
1333:
1334: Vector getBaseCppDefines(IDEProjectConfig config) {
1335: Vector v = new Vector();
1336: v.addElement("WIN32");
1337:
1338: if (config.isDebug()) {
1339: v.addElement("DEBUG");
1340: v.addElement("AZZERT");
1341: } else if (config.isRelease()) {
1342: v.addElement("NDEBUG");
1343: } else {
1344: v.addElement("PRODUCT");
1345: v.addElement("NDEBUG");
1346: }
1347:
1348: return v;
1349: }
1350:
1351: Vector getCppDefines(IDEProjectConfig config) {
1352: Vector v = new Vector();
1353:
1354: if (this .type == TARGET && win32Tool().isRomizing()) {
1355: v.addElement("ROMIZING");
1356: }
1357: return v;
1358: }
1359:
1360: void putIncludePaths() {
1361: Vector vpaths = vmSourceHandler.getVpaths();
1362: for (int i = 0; i < vpaths.size(); i++) {
1363: String path = (String) vpaths.elementAt(i);
1364: put("/I \"" + getRelativeSourceFile(path) + "\" ");
1365: }
1366: }
1367:
1368: void writeSourceFileRules() throws Exception {
1369: Vector sourceFiles = new Vector();
1370:
1371: for (Iterator iter = database.getAllFiles().iterator(); iter
1372: .hasNext();) {
1373: FileList fl = (FileList) iter.next();
1374: String fileName = fl.getName();
1375: if (isFileIncludedInSources(fileName)) {
1376: fileName = vmSourceHandler
1377: .resolveFileForProject(fileName);
1378: sourceFiles.addElement(fileName);
1379: }
1380: }
1381:
1382: // Add extra source specific to this VM. For example, a
1383: // loopgen VM would add InterpreterSkeleton.cpp
1384: addExtraSources(sourceFiles);
1385:
1386: boolean added_pch = false;
1387: putln("# Begin Group \"Source Files\"");
1388: putln();
1389: putln("# PROP Default_Filter "
1390: + "\"cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90;asm\"");
1391: for (int i = 0; i < sourceFiles.size(); i++) {
1392: String fileName = (String) sourceFiles.elementAt(i);
1393:
1394: putln("# Begin Source File");
1395: putln();
1396: putln("SOURCE=" + fileName);
1397:
1398: if (!mayUsePrecompiledHeader(fileName)) {
1399: putln("# SUBTRACT CPP /YX /Yc /Yu");
1400: } else {
1401: if (!added_pch) {
1402: putln("# ADD CPP /Yc\"incls/_precompiled.incl\"");
1403: added_pch = true;
1404: }
1405: }
1406: putln("# End Source File");
1407: }
1408:
1409: // Write the asm files as well
1410: switch (this .type) {
1411: case TARGET:
1412: case ROMGEN:
1413: writeAsmAndOopMapsFileRules();
1414: break;
1415: }
1416:
1417: putln("# End Group");
1418: }
1419:
1420: void writeAsmAndOopMapsFileRules() throws Exception {
1421: writeAsmAndOopMapsFileRules(true);
1422: writeAsmAndOopMapsFileRules(false);
1423:
1424: createDummyAsmAndOopMapsFiles(true);
1425: createDummyAsmAndOopMapsFiles(false);
1426: }
1427:
1428: void writeAsmAndOopMapsFileRules(boolean isAsm) {
1429: Vector v = getAvailableConfigs();
1430: for (int i = 0; i < v.size(); i++) {
1431: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
1432: String srcName, stem, ext;
1433:
1434: if (isAsm) {
1435: stem = "Interpreter_i386";
1436: ext = ".asm";
1437: } else {
1438: stem = "OopMaps";
1439: ext = ".cpp";
1440: }
1441: srcName = config.outputDir + "\\" + stem + ext;
1442: String mlpath = win32Tool().getExecutablePath("ml.exe");
1443:
1444: putln("# Begin Source File");
1445: putln();
1446: putln("SOURCE=\"" + srcName + "\"");
1447: putln();
1448:
1449: if (v.size() > 1) {
1450: putln("!IF \"$(CFG)\" == \"" + config.name + "\"");
1451: putln();
1452: }
1453:
1454: putln("# PROP Ignore_Default_Tool 1");
1455: putln("# Begin Custom Build - Performing Custom Build Step on "
1456: + "$(InputName).asm");
1457: putln("OutDir=.\\" + config.outputDir);
1458: putln("InputPath=\\\"" + config.outputDir + "\\" + stem
1459: + ext + "\"");
1460: putln("InputName=" + stem);
1461:
1462: putln();
1463: putln("\"$(OutDir)\\$(InputName).obj\" : $(SOURCE) "
1464: + "\"$(INTDIR)\" \"$(OUTDIR)\"");
1465: if (isAsm) {
1466: putln(" \"" + mlpath
1467: + "\" /nologo /c /coff /Zi /FR "
1468: + "/Fo\"$(OutDir)\\$(InputName).obj\" "
1469: + srcName);
1470: } else {
1471: put(" \"cl.exe\" /c /I . ");
1472: putIncludePaths();
1473: putCppFlags(config, false);
1474: putln(" /Fo\"$(OutDir)\\$(InputName).obj\" " + srcName);
1475: }
1476: putln("# End Custom Build");
1477: putln();
1478:
1479: if (v.size() > 1) {
1480: // We need to write the Exclude_From_Build only if there
1481: // are more than one config in this project.
1482: for (int j = 0; j < v.size(); j++) {
1483: if (i == j) {
1484: continue;
1485: }
1486: IDEProjectConfig other = (IDEProjectConfig) v
1487: .elementAt(j);
1488: putln("!ELSEIF \"$(CFG)\" == \"" + other.name
1489: + "\"");
1490: putln();
1491: putln("# PROP Exclude_From_Build 1");
1492: putln();
1493: }
1494: putln("!ENDIF");
1495: putln();
1496: }
1497: putln("# End Source File");
1498: putln();
1499: }
1500: }
1501:
1502: void createDummyAsmAndOopMapsFiles(boolean isAsm) throws Exception {
1503: Vector v = getAvailableConfigs();
1504: for (int i = 0; i < v.size(); i++) {
1505: IDEProjectConfig config = (IDEProjectConfig) v.elementAt(i);
1506:
1507: String dirName = getOutputDir() + "\\" + config.outputDir;
1508: File f = new File(dirName);
1509: if (!f.exists()) {
1510: f.mkdir();
1511: }
1512:
1513: if (isAsm) {
1514: String asmName = dirName + "\\Interpreter_i386.asm";
1515: PrintWriter writer = tool().openOutputFile(asmName);
1516: writer.println("\t;Dummy file.");
1517: writer
1518: .println("\t;Will be overwritten during compilation.");
1519: writer.println("\t;This file is auto-generated.");
1520: writer.println("\t;Do not edit.");
1521: writer.close();
1522: } else {
1523: String asmName = dirName + "\\OopMaps.cpp";
1524: PrintWriter writer = tool().openOutputFile(asmName);
1525: writer.println("// Dummy file.");
1526: writer
1527: .println("// Will be overwritten during compilation.");
1528: writer.println("// This file is auto-generated.");
1529: writer.println("// Do not edit.");
1530: writer.close();
1531: }
1532: }
1533: }
1534:
1535: void writeHeaderFileRules() {
1536: Vector headerFiles = new Vector();
1537:
1538: for (Iterator iter = database.getAllFiles().iterator(); iter
1539: .hasNext();) {
1540: FileList fl = (FileList) iter.next();
1541: String fileName = fl.getName();
1542: if (isFileIncludedInHeaders(fileName)) {
1543: fileName = vmSourceHandler
1544: .resolveFileForProject(fileName);
1545: headerFiles.addElement(fileName);
1546: }
1547: }
1548:
1549: putln("# Begin Group \"Header Files\"");
1550: putln();
1551: putln("# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"");
1552: for (int i = 0; i < headerFiles.size(); i++) {
1553: String fileName = (String) headerFiles.elementAt(i);
1554:
1555: putln("# Begin Source File");
1556: putln();
1557: putln("SOURCE=" + fileName);
1558: putln("# End Source File");
1559: }
1560: putln("# End Group");
1561:
1562: putln("# Begin Group \"Config Files\"");
1563: putln();
1564: putln("# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"");
1565: putln("# Begin Source File");
1566: putln();
1567: putln("SOURCE=jvmconfig.h");
1568: putln("# End Source File");
1569: putln("# End Group");
1570: }
1571:
1572: void writeFooter() {
1573: putln("# Begin Group \"Resource Files\"");
1574: putln();
1575: putln("# PROP Default_Filter "
1576: + "\"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"");
1577: putln("# End Group");
1578: putln("# End Target");
1579: putln("# End Project");
1580: }
1581:
1582: void writeIncls() throws Exception {
1583: database.put();
1584: }
1585:
1586: /* override this to implement file filtering */
1587: public boolean isFileIncludedInSources(String fileName) {
1588: fileName = fileName.toLowerCase();
1589: if (!fileName.endsWith(".cpp") && !fileName.endsWith(".c")) {
1590: return false;
1591: }
1592:
1593: if (fileName.equals("nativestable.cpp")) { // this file is generated
1594: return false;
1595: }
1596:
1597: if (fileName.equals("romimage.cpp")) { // this file is generated
1598: return false;
1599: }
1600:
1601: return true;
1602: }
1603:
1604: /* override this to implement file filtering */
1605: public boolean isFileIncludedInHeaders(String fileName) {
1606: fileName = fileName.toLowerCase();
1607: if (!fileName.endsWith(".hpp") && !fileName.endsWith(".h")) {
1608: return false;
1609: }
1610:
1611: return true;
1612: }
1613:
1614: /* override this to implement file filtering */
1615: public boolean mayUsePrecompiledHeader(String fileName) {
1616: fileName = fileName.toLowerCase();
1617: if (fileName.endsWith("romimage.cpp")) {
1618: return false;
1619: }
1620: if (fileName.endsWith("romskeleton.cpp")) {
1621: return false;
1622: }
1623: if (fileName.endsWith("nativestable.cpp")) {
1624: return false;
1625: }
1626: if (fileName.endsWith("os_win32.cpp")) {
1627: return false;
1628: }
1629:
1630: return true;
1631: }
1632:
1633: /**
1634: * Override this to include extra files. You must add a pathname
1635: * that's accessible from this project. E.g., "./NativesTable.cpp"
1636: */
1637: public void addExtraSources(Vector lst) {
1638: lst.addElement("../javaapi/NativesTable.cpp");
1639: VMSourceHandler h = this .vmSourceHandler;
1640:
1641: switch (this .type) {
1642: case TARGET:
1643: if (!win32Tool().isRomizing()) {
1644: lst.addElement(h
1645: .resolveFileForProject("ROMSkeleton.cpp"));
1646: } else {
1647: lst.addElement("..\\romimage\\ROMImage.cpp");
1648: }
1649: break;
1650: case LOOPGEN:
1651: lst.addElement(h
1652: .resolveFileForProject("InterpreterSkeleton.cpp"));
1653: lst.addElement(h.resolveFileForProject("ROMSkeleton.cpp"));
1654: lst.addElement(h
1655: .resolveFileForProject("OopMapsSkeleton.cpp"));
1656: break;
1657: case ROMGEN:
1658: lst.addElement(h.resolveFileForProject("ROMSkeleton.cpp"));
1659: break;
1660: }
1661: }
1662:
1663: /**
1664: * Write the jvmconfig.h file for this project
1665: */
1666: void writeJvmConfig() throws Exception {
1667: /*
1668: * If user has chosen non-default value for the ENABLE_XXX flags,
1669: * pass these values to tool.configurator, which creates jvmconfig.h.
1670: */
1671:
1672: Hashtable env = new Hashtable();
1673: Properties userSettings = tool().getUserSettings();
1674: for (Enumeration keys = userSettings.keys(); keys
1675: .hasMoreElements();) {
1676: String key = (String) keys.nextElement();
1677: if (key.startsWith("ENABLE")) {
1678: String value = (String) userSettings.get(key);
1679: if (key.equals("ENABLE_MONET") && this .type != TARGET) {
1680: // ENABLE_MONET must be set to false for loopgen and romgen
1681: value = "false";
1682: }
1683: if (value.equals("true") || value.equals("false")) {
1684: env.put(key, value);
1685: env.put(key + "__BY", "idetool");
1686: }
1687: }
1688: }
1689:
1690: switch (this .type) {
1691: case ROMGEN:
1692: case LOOPGEN:
1693: // the generators must have INTERPRETER and ROM generators
1694: env.put("ENABLE_INTERPRETER_GENERATOR", "true");
1695: env.put("ENABLE_INTERPRETER_GENERATOR__BY", "idetool");
1696: env.put("ENABLE_ROM_GENERATOR", "true");
1697: env.put("ENABLE_ROM_GENERATOR__BY", "idetool");
1698: }
1699:
1700: String filename = getOutputDir() + File.separator
1701: + "jvmconfig.h";
1702: String fullpath = tool().getOutputFileFullPath(filename);
1703: Vector extra = new Vector();
1704: extra.addElement("USE_UNICODE_FOR_FILENAMES=1");
1705:
1706: // Append product-specific definitions
1707: {
1708: String productName = tool().configurator.getProductName();
1709: if (productName != null) {
1710: extra.addElement("JVM_NAME=\"" + productName + "\"");
1711: }
1712: String releaseVersion = tool().configurator
1713: .getReleaseVersion();
1714: if (releaseVersion != null) {
1715: extra.addElement("JVM_RELEASE_VERSION=\""
1716: + releaseVersion + "\"");
1717: }
1718: }
1719:
1720: win32Tool().configurator.write(fullpath, env, extra);
1721: }
1722: }
1723:
1724: class Win32IDESettingsDialog extends JFrame implements ActionListener {
1725: boolean okPressed;
1726: Object lock = new Object();
1727: Hashtable widgets;
1728: Properties props;
1729: Vector buildOptions, generatorOptions, paths;
1730:
1731: public void getUserInput(Properties props, Vector buildOptions,
1732: Vector generatorOptions, Vector paths) throws Exception {
1733: this .props = props;
1734: this .buildOptions = buildOptions;
1735: this .generatorOptions = generatorOptions;
1736: this .paths = paths;
1737:
1738: searchPaths();
1739: createUI();
1740: waitUI();
1741: updateProperties();
1742: }
1743:
1744: private void searchPaths() throws Exception {
1745: Vector v = getSystemPaths();
1746:
1747: for (int n = 0; n < paths.size(); n++) {
1748: String name = (String) paths.elementAt(n);
1749: String path = (String) props.get(name);
1750:
1751: if (path != null && !path.equals("")) {
1752: // we already have a default value
1753: continue;
1754: }
1755: path = "- please enter full path of " + name;
1756: for (int i = 0; i < v.size(); i++) {
1757: String p = (String) v.elementAt(i);
1758: String s = p + File.separator + name;
1759: File f = new File(s);
1760: if (f.exists()) {
1761: path = s;
1762: break;
1763: }
1764: }
1765:
1766: props.put(name, path);
1767: }
1768: }
1769:
1770: private Vector getSystemPaths() throws Exception {
1771: Vector v = new Vector();
1772:
1773: Process proc = Runtime.getRuntime().exec("cmd.exe /c path");
1774: InputStream in = proc.getInputStream();
1775: InputStreamReader inr = new InputStreamReader(in);
1776: BufferedReader reader = new BufferedReader(inr);
1777: String data = reader.readLine();
1778: reader.close();
1779:
1780: if (!data.toLowerCase().startsWith("path=")) {
1781: return v;
1782: } else {
1783: data = data.substring(5);
1784: }
1785:
1786: StringTokenizer st = new StringTokenizer(data,
1787: File.pathSeparator);
1788: while (st.hasMoreTokens()) {
1789: String path = st.nextToken();
1790: v.addElement(path);
1791: }
1792: return v;
1793: }
1794:
1795: private void addOne(JPanel panel, GridBagLayout gridbag,
1796: GridBagConstraints c, JComponent comp, boolean indent) {
1797: c.fill = GridBagConstraints.BOTH;
1798: c.weightx = 1.0;
1799: if (indent) {
1800: c.insets = new Insets(0, 20, 0, 0);
1801: } else {
1802: c.insets = new Insets(5, 0, 0, 0);
1803: }
1804: c.gridwidth = GridBagConstraints.REMAINDER;
1805: gridbag.setConstraints(comp, c);
1806: panel.add(comp);
1807: }
1808:
1809: private void addTwo(JPanel panel, GridBagLayout gridbag,
1810: GridBagConstraints c, JComponent one, JComponent two,
1811: boolean indent) {
1812: c.fill = GridBagConstraints.BOTH;
1813: c.weightx = 1.0;
1814: c.ipadx = 2;
1815: c.gridwidth = 1;
1816: if (indent) {
1817: c.insets = new Insets(0, 20, 0, 0);
1818: } else {
1819: c.insets = new Insets(5, 0, 0, 0);
1820: }
1821: gridbag.setConstraints(one, c);
1822: panel.add(one);
1823:
1824: c.insets = new Insets(0, 0, 0, 0);
1825: c.gridwidth = GridBagConstraints.REMAINDER;
1826: gridbag.setConstraints(two, c);
1827: panel.add(two);
1828: }
1829:
1830: class MyScrollablePanel extends JPanel implements Scrollable {
1831: JPanel otherPanel;
1832:
1833: MyScrollablePanel(JPanel otherPanel) {
1834: this .otherPanel = otherPanel;
1835: }
1836:
1837: public Dimension getPreferredSize() {
1838: Dimension d = super .getPreferredSize();
1839: return d;
1840: }
1841:
1842: public Dimension getPreferredScrollableViewportSize() {
1843: Dimension d1 = super .getPreferredSize();
1844: Dimension d2 = otherPanel.getPreferredSize();
1845: return new Dimension((int) (d1.getWidth()), (int) (d2
1846: .getHeight()));
1847: }
1848:
1849: public boolean getScrollableTracksViewportWidth() {
1850: return false;
1851: }
1852:
1853: public boolean getScrollableTracksViewportHeight() {
1854: return false;
1855: }
1856:
1857: public int getScrollableUnitIncrement(Rectangle visibleRect,
1858: int orientation, int direction) {
1859: return 10;
1860: }
1861:
1862: public int getScrollableBlockIncrement(Rectangle visibleRect,
1863: int orientation, int direction) {
1864: return 50;
1865: }
1866: }
1867:
1868: private void createUI() {
1869: widgets = new Hashtable();
1870:
1871: JPanel rightPanel = new JPanel();
1872: JPanel leftPanel = new MyScrollablePanel(rightPanel);
1873:
1874: GridBagLayout gridbag = new GridBagLayout();
1875: GridBagConstraints c = new GridBagConstraints();
1876:
1877: leftPanel.setLayout(gridbag);
1878: rightPanel.setLayout(new GridLayout(0, 1));
1879:
1880: // Build options
1881: addOne(leftPanel, gridbag, c, new JLabel("Build Options:"),
1882: false);
1883: String items3[] = { "true", "false", "default", };
1884: String items2[] = { "true", "false", };
1885:
1886: for (Enumeration e = buildOptions.elements(); e
1887: .hasMoreElements();) {
1888: String name = (String) e.nextElement();
1889: String value = (String) props.get(name);
1890:
1891: JLabel label = new JLabel(name);
1892: JComboBox box;
1893:
1894: if (name.startsWith("ENABLE")) {
1895: box = new JComboBox(items3);
1896: } else {
1897: box = new JComboBox(items2);
1898: }
1899:
1900: if (value.equals("true")) {
1901: box.setSelectedIndex(0);
1902: } else if (value.equals("false")) {
1903: box.setSelectedIndex(1);
1904: } else {
1905: box.setSelectedIndex(2);
1906: }
1907:
1908: addTwo(leftPanel, gridbag, c, label, box, true);
1909: widgets.put(name, box);
1910: }
1911:
1912: // Generator options
1913: addOne(leftPanel, gridbag, c, new JLabel("Generator Options:"),
1914: false);
1915: for (Enumeration e = generatorOptions.elements(); e
1916: .hasMoreElements();) {
1917: String name = (String) e.nextElement();
1918: boolean defValue = ((String) props.get(name))
1919: .equals("true");
1920:
1921: JCheckBox box = new JCheckBox(name);
1922: if (defValue) {
1923: box.setSelected(true);
1924: }
1925: addOne(leftPanel, gridbag, c, box, true);
1926: widgets.put(name, box);
1927: }
1928:
1929: // Paths
1930: rightPanel.add(new JLabel("Tool Paths:"));
1931: for (Enumeration e = paths.elements(); e.hasMoreElements();) {
1932: String name = (String) e.nextElement();
1933: String path = (String) props.get(name);
1934:
1935: JLabel label = new JLabel(name);
1936: JTextField textField = new JTextField();
1937: textField.setColumns(30);
1938: textField.setText(path);
1939: rightPanel.add(label);
1940: rightPanel.add(textField);
1941: widgets.put(name, textField);
1942: }
1943:
1944: JButton ok = new JButton(" OK ");
1945: ok.setActionCommand("ok");
1946: ok.addActionListener(this );
1947:
1948: JButton cancel = new JButton("Cancel");
1949: cancel.setActionCommand("cancel");
1950: cancel.addActionListener(this );
1951:
1952: JPanel buttons = new JPanel();
1953: buttons.setLayout(new FlowLayout());
1954: buttons.add(ok);
1955: buttons.add(cancel);
1956:
1957: JPanel rightOuterPanel = new JPanel();
1958: rightOuterPanel.setLayout(new BorderLayout());
1959: rightOuterPanel.add(rightPanel, BorderLayout.NORTH);
1960:
1961: JScrollPane leftPane = new JScrollPane(leftPanel,
1962: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
1963: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
1964:
1965: JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
1966: leftPane, rightOuterPanel);
1967: getContentPane().add(split);
1968: getContentPane().add(buttons, BorderLayout.SOUTH);
1969:
1970: getRootPane().setDefaultButton(ok);
1971:
1972: this .pack();
1973: this .setLocation(200, 200);
1974: }
1975:
1976: private void waitUI() throws Exception {
1977: this .addWindowListener(new WindowAdapter() {
1978: public void windowClosing(WindowEvent e) {
1979: setVisible(false);
1980: synchronized (lock) {
1981: lock.notifyAll();
1982: }
1983: }
1984: });
1985:
1986: okPressed = false;
1987: this .setVisible(true);
1988: synchronized (lock) {
1989: lock.wait();
1990: }
1991:
1992: if (!okPressed) {
1993: System.out.println("IDE creation cancelled");
1994: System.exit(1);
1995: }
1996: }
1997:
1998: private void updateProperties() {
1999: for (Enumeration e = widgets.keys(); e.hasMoreElements();) {
2000: String name = (String) e.nextElement();
2001: JComponent comp = (JComponent) widgets.get(name);
2002:
2003: if (comp instanceof JCheckBox) {
2004: boolean sel = ((JCheckBox) comp).isSelected();
2005: if (sel) {
2006: props.put(name, "true");
2007: } else {
2008: props.put(name, "false");
2009: }
2010: } else if (comp instanceof JComboBox) {
2011: JComboBox box = (JComboBox) comp;
2012: String value = (String) box.getSelectedItem();
2013: props.put(name, value);
2014: } else if (comp instanceof JTextField) {
2015: String value = ((JTextField) comp).getText();
2016: props.put(name, value);
2017: }
2018: }
2019: }
2020:
2021: public void actionPerformed(java.awt.event.ActionEvent e) {
2022: if (e.getActionCommand().equals("ok")) {
2023: okPressed = true;
2024: }
2025: setVisible(false);
2026: synchronized (lock) {
2027: lock.notifyAll();
2028: }
2029: }
2030: }
2031:
2032: // IMPL_NOTE: add default debug command line args for ROM generator
2033: // IMPL_NOTE: disable optimization for float
|