Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/tools/ProjectCreator/WinGammaPlatformVC10.java
32285 views
/*1* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import java.io.File;25import java.io.FileNotFoundException;26import java.io.IOException;27import java.io.PrintWriter;28import java.io.UnsupportedEncodingException;29import java.nio.file.FileSystems;30import java.util.Iterator;31import java.util.LinkedList;32import java.util.UUID;33import java.util.Vector;3435public class WinGammaPlatformVC10 extends WinGammaPlatformVC7 {363738LinkedList <String>filters = new LinkedList<String>();39LinkedList <String[]>filterDeps = new LinkedList<String[]>();4041@Override42protected String getProjectExt() {43return ".vcxproj";44}4546@Override47public void writeProjectFile(String projectFileName, String projectName,48Vector<BuildConfig> allConfigs) throws IOException {49System.out.println();50System.out.println(" Writing .vcxproj file: " + projectFileName);5152String projDir = Util.normalize(new File(projectFileName).getParent());5354printWriter = new PrintWriter(projectFileName, "UTF-8");55printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");56startTag("Project",57"DefaultTargets", "Build",58"ToolsVersion", "4.0",59"xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");60startTag("ItemGroup",61"Label", "ProjectConfigurations");62for (BuildConfig cfg : allConfigs) {63startTag("ProjectConfiguration",64"Include", cfg.get("Name"));65tagData("Configuration", cfg.get("Id"));66tagData("Platform", cfg.get("PlatformName"));67endTag();68}69endTag();7071startTag("PropertyGroup", "Label", "Globals");72tagData("ProjectGuid", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}");73tag("SccProjectName");74tag("SccLocalPath");75endTag();7677tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");7879for (BuildConfig cfg : allConfigs) {80startTag(cfg, "PropertyGroup", "Label", "Configuration");81tagData("ConfigurationType", "DynamicLibrary");82tagData("UseOfMfc", "false");83endTag();84}8586tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");87startTag("ImportGroup", "Label", "ExtensionSettings");88endTag();89for (BuildConfig cfg : allConfigs) {90startTag(cfg, "ImportGroup", "Label", "PropertySheets");91tag("Import",92"Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props",93"Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')",94"Label", "LocalAppDataPlatform");95endTag();96}9798tag("PropertyGroup", "Label", "UserMacros");99100startTag("PropertyGroup");101tagData("_ProjectFileVersion", "10.0.30319.1");102for (BuildConfig cfg : allConfigs) {103tagData(cfg, "OutDir", cfg.get("OutputDir") + Util.sep);104tagData(cfg, "IntDir", cfg.get("OutputDir") + Util.sep);105tagData(cfg, "LinkIncremental", "false");106}107for (BuildConfig cfg : allConfigs) {108tagData(cfg, "CodeAnalysisRuleSet", "AllRules.ruleset");109tag(cfg, "CodeAnalysisRules");110tag(cfg, "CodeAnalysisRuleAssemblies");111}112endTag();113114for (BuildConfig cfg : allConfigs) {115startTag(cfg, "ItemDefinitionGroup");116startTag("ClCompile");117tagV(cfg.getV("CompilerFlags"));118endTag();119120startTag("Link");121tagV(cfg.getV("LinkerFlags"));122endTag();123124startTag("PreLinkEvent");125tagData("Message", BuildConfig.getFieldString(null, "PrelinkDescription"));126tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace("\t", "\r\n")));127endTag();128129endTag();130}131132writeFiles(allConfigs, projDir);133134tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");135startTag("ImportGroup", "Label", "ExtensionTargets");136endTag();137138endTag();139printWriter.close();140System.out.println(" Done writing .vcxproj file.");141142writeFilterFile(projectFileName, projectName, allConfigs, projDir);143writeUserFile(projectFileName, allConfigs);144}145146147private void writeUserFile(String projectFileName, Vector<BuildConfig> allConfigs) throws FileNotFoundException, UnsupportedEncodingException {148String userFileName = projectFileName + ".user";149if (new File(userFileName).exists()) {150return;151}152System.out.print(" Writing .vcxproj.user file: " + userFileName);153printWriter = new PrintWriter(userFileName, "UTF-8");154155printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");156startTag("Project",157"ToolsVersion", "4.0",158"xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");159160for (BuildConfig cfg : allConfigs) {161startTag(cfg, "PropertyGroup");162tagData("LocalDebuggerCommand", cfg.get("JdkTargetRoot") + "\\bin\\java.exe");163tagData("LocalDebuggerCommandArguments", "-XXaltjvm=$(TargetDir) -Dsun.java.launcher=gamma");164tagData("LocalDebuggerEnvironment", "JAVA_HOME=" + cfg.get("JdkTargetRoot"));165endTag();166}167168endTag();169printWriter.close();170System.out.println(" Done.");171}172173public void addFilter(String rPath) {174filters.add(rPath);175}176177public void addFilterDependency(String fileLoc, String filter) {178filterDeps.add(new String[] {fileLoc, filter});179}180181private void writeFilterFile(String projectFileName, String projectName,182Vector<BuildConfig> allConfigs, String base) throws FileNotFoundException, UnsupportedEncodingException {183String filterFileName = projectFileName + ".filters";184System.out.print(" Writing .vcxproj.filters file: " + filterFileName);185printWriter = new PrintWriter(filterFileName, "UTF-8");186187printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");188startTag("Project",189"ToolsVersion", "4.0",190"xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");191192startTag("ItemGroup");193for (String filter : filters) {194startTag("Filter", "Include",filter);195UUID uuid = UUID.randomUUID();196tagData("UniqueIdentifier", "{" + uuid.toString() + "}");197endTag();198}199startTag("Filter", "Include", "Resource Files");200UUID uuid = UUID.randomUUID();201tagData("UniqueIdentifier", "{" + uuid.toString() + "}");202tagData("Extensions", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe");203endTag();204endTag();205206//TODO - do I need to split cpp and hpp files?207208// then all files209startTag("ItemGroup");210for (String[] dep : filterDeps) {211String tagName = getFileTagFromSuffix(dep[0]);212213startTag(tagName, "Include", dep[0]);214tagData("Filter", dep[1]);215endTag();216}217endTag();218219endTag();220printWriter.close();221System.out.println(" Done.");222}223224public String getFileTagFromSuffix(String fileName) {225if (fileName.endsWith(".cpp")) {226return"ClCompile";227} else if (fileName.endsWith(".c")) {228return "ClCompile";229} else if (fileName.endsWith(".hpp")) {230return"ClInclude";231} else if (fileName.endsWith(".h")) {232return "ClInclude";233} else {234return"None";235}236}237238void writeFiles(Vector<BuildConfig> allConfigs, String projDir) {239// This code assummes there are no config specific includes.240startTag("ItemGroup");241242String sourceBase = BuildConfig.getFieldString(null, "SourceBase");243244// Use first config for all global absolute includes.245BuildConfig baseConfig = allConfigs.firstElement();246Vector<String> rv = new Vector<String>();247248// Then use first config for all relative includes249Vector<String> ri = new Vector<String>();250baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude");251for (String f : ri) {252rv.add(sourceBase + Util.sep + f);253}254255baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude");256257handleIncludes(rv, allConfigs);258259endTag();260}261262// Will visit file tree for each include263private void handleIncludes(Vector<String> includes, Vector<BuildConfig> allConfigs) {264for (String path : includes) {265FileTreeCreatorVC10 ftc = new FileTreeCreatorVC10(FileSystems.getDefault().getPath(path) , allConfigs, this);266try {267ftc.writeFileTree();268} catch (IOException e) {269e.printStackTrace();270}271}272}273274String buildCond(BuildConfig cfg) {275return "'$(Configuration)|$(Platform)'=='"+cfg.get("Name")+"'";276}277278void tagV(Vector<String> v) {279Iterator<String> i = v.iterator();280while(i.hasNext()) {281String name = i.next();282String data = i.next();283tagData(name, data);284}285}286287void tagData(BuildConfig cfg, String name, String data) {288tagData(name, data, "Condition", buildCond(cfg));289}290291void tag(BuildConfig cfg, String name, String... attrs) {292String[] ss = new String[attrs.length + 2];293ss[0] = "Condition";294ss[1] = buildCond(cfg);295System.arraycopy(attrs, 0, ss, 2, attrs.length);296297tag(name, ss);298}299300void startTag(BuildConfig cfg, String name, String... attrs) {301String[] ss = new String[attrs.length + 2];302ss[0] = "Condition";303ss[1] = buildCond(cfg);304System.arraycopy(attrs, 0, ss, 2, attrs.length);305306startTag(name, ss);307}308309}310311class CompilerInterfaceVC10 extends CompilerInterface {312313@Override314Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir) {315Vector rv = new Vector();316317addAttr(rv, "AdditionalIncludeDirectories", Util.join(";", includes));318addAttr(rv, "PreprocessorDefinitions",319Util.join(";", defines).replace("\\\"", "\""));320addAttr(rv, "PrecompiledHeaderFile", "precompiled.hpp");321addAttr(rv, "PrecompiledHeaderOutputFile", outDir+Util.sep+"vm.pch");322addAttr(rv, "AssemblerListingLocation", outDir);323addAttr(rv, "ObjectFileName", outDir+Util.sep);324addAttr(rv, "ProgramDataBaseFileName", outDir+Util.sep+"jvm.pdb");325// Set /nologo option326addAttr(rv, "SuppressStartupBanner", "true");327// Surpass the default /Tc or /Tp.328addAttr(rv, "CompileAs", "Default");329// Set /W3 option.330addAttr(rv, "WarningLevel", "Level3");331// Set /WX option,332addAttr(rv, "TreatWarningAsError", "true");333// Set /GS option334addAttr(rv, "BufferSecurityCheck", "false");335// Set /Zi option.336addAttr(rv, "DebugInformationFormat", "ProgramDatabase");337// Set /Yu option.338addAttr(rv, "PrecompiledHeader", "Use");339// Set /EHsc- option340addAttr(rv, "ExceptionHandling", "");341342addAttr(rv, "MultiProcessorCompilation", "true");343344return rv;345}346347@Override348Vector getDebugCompilerFlags(String opt) {349Vector rv = new Vector();350351// Set /On option352addAttr(rv, "Optimization", opt);353// Set /FR option.354addAttr(rv, "BrowseInformation", "true");355addAttr(rv, "BrowseInformationFile", "$(IntDir)");356// Set /MD option.357addAttr(rv, "RuntimeLibrary", "MultiThreadedDLL");358// Set /Oy- option359addAttr(rv, "OmitFramePointers", "false");360361return rv;362}363364@Override365Vector getProductCompilerFlags() {366Vector rv = new Vector();367368// Set /O2 option.369addAttr(rv, "Optimization", "MaxSpeed");370// Set /Oy- option371addAttr(rv, "OmitFramePointers", "false");372// Set /Ob option. 1 is expandOnlyInline373addAttr(rv, "InlineFunctionExpansion", "OnlyExplicitInline");374// Set /GF option.375addAttr(rv, "StringPooling", "true");376// Set /MD option. 2 is rtMultiThreadedDLL377addAttr(rv, "RuntimeLibrary", "MultiThreadedDLL");378// Set /Gy option379addAttr(rv, "FunctionLevelLinking", "true");380381return rv;382}383384@Override385Vector getBaseLinkerFlags(String outDir, String outDll, String platformName) {386Vector rv = new Vector();387388addAttr(rv, "AdditionalOptions",389"/export:JNI_GetDefaultJavaVMInitArgs " +390"/export:JNI_CreateJavaVM " +391"/export:JVM_FindClassFromBootLoader "+392"/export:JNI_GetCreatedJavaVMs "+393"/export:jio_snprintf /export:jio_printf "+394"/export:jio_fprintf /export:jio_vfprintf "+395"/export:jio_vsnprintf "+396"/export:JVM_GetVersionInfo "+397"/export:JVM_GetThreadStateNames "+398"/export:JVM_GetThreadStateValues "+399"/export:JVM_InitAgentProperties");400addAttr(rv, "AdditionalDependencies", "kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;Wsock32.lib;winmm.lib;psapi.lib;version.lib");401addAttr(rv, "OutputFile", outDll);402addAttr(rv, "SuppressStartupBanner", "true");403addAttr(rv, "ModuleDefinitionFile", outDir+Util.sep+"vm.def");404addAttr(rv, "ProgramDatabaseFile", outDir+Util.sep+"jvm.pdb");405addAttr(rv, "SubSystem", "Windows");406addAttr(rv, "BaseAddress", "0x8000000");407addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib");408409if(platformName.equals("Win32")) {410addAttr(rv, "TargetMachine", "MachineX86");411} else {412addAttr(rv, "TargetMachine", "MachineX64");413}414415// We always want the /DEBUG option to get full symbol information in the pdb files416addAttr(rv, "GenerateDebugInformation", "true");417418return rv;419}420421@Override422Vector getDebugLinkerFlags() {423Vector rv = new Vector();424425// Empty now that /DEBUG option is used by all configs426427return rv;428}429430@Override431Vector getProductLinkerFlags() {432Vector rv = new Vector();433434// Set /OPT:REF option.435addAttr(rv, "OptimizeReferences", "true");436// Set /OPT:ICF option.437addAttr(rv, "EnableCOMDATFolding", "true");438439return rv;440}441442@Override443void getAdditionalNonKernelLinkerFlags(Vector rv) {444extAttr(rv, "AdditionalOptions", " /export:AsyncGetCallTrace");445}446447@Override448String getOptFlag() {449return "MaxSpeed";450}451452@Override453String getNoOptFlag() {454return "Disabled";455}456457@Override458String makeCfgName(String flavourBuild, String platform) {459return flavourBuild + "|" + platform;460}461462}463464465