use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.
the class PlatformImplementation method writePlatformSpecificFiles.
/* (non-Javadoc)
* @see com.ibm.uma.platform.IPlatform#writePlatformSpecificFiles(com.ibm.uma.Artifact)
*/
public void writePlatformSpecificFiles(Artifact artifact) throws UMAException {
writeExportFile(artifact);
if (!artifact.flagSet("requiresPrimitiveTable") && !artifact.flagSet("dumpMasterPrimitiveTable")) {
return;
}
String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetName() + "exp.c";
Vector<Export> exports = artifact.getExportedFunctions();
FileAssistant fa = new FileAssistant(filename);
StringBuffer buffer = fa.getStringBuffer();
buffer.append(configuration.getcCopyrightNotice());
buffer.append("#include \"j9comp.h\"\n#include \"j9static.h\"\n\n");
buffer.append("#if !defined(J9VM_SHARED_LIBRARIES_SUPPORTED) || defined(J9VM_OPT_BUNDLE_CORE_MODULES)\n");
if (artifact.flagSet("requiresPrimitiveTable")) {
if (artifact.flagSet("dumpGenericProtosForPrimTable")) {
for (Export export : exports) {
buffer.append("extern void VMCALL " + export.getExport() + "(void);\n");
}
} else {
// "We ask the the module to give us a header file name to include with the public prototypes"
String[] prototypeHeaderFileNames = artifact.getData("prototypeHeaderFileNames");
if (prototypeHeaderFileNames != null) {
for (String fnm : prototypeHeaderFileNames) {
buffer.append("#include \"" + fnm + "\"\n");
}
}
if (artifact.flagSet("extraPrototypesForExportFile")) {
String[] extraProtos = artifact.getData("extraPrototypesForExportFile");
for (String proto : extraProtos) {
buffer.append("extern void VMCALL " + proto + "(void);\n");
}
}
}
buffer.append("\nEsDefinePrimitiveTable(" + artifact.getTargetName().toUpperCase() + "PrimitiveTable)\n");
for (Export export : exports) {
String strippedExportName = stripExportName(export.getExport());
buffer.append("\tEsPrimitiveTableEntry(\"" + strippedExportName + "\"," + strippedExportName + ")\n");
}
buffer.append("EsEndPrimitiveTable\n");
}
if (artifact.flagSet("dumpMasterPrimitiveTable")) {
buffer.append("\n");
Vector<Library> libs = artifact.getStaticLinkLibraries();
if (artifact.getType() == Artifact.TYPE_BUNDLE) {
libs.addAll(artifact.getLibraries());
}
Vector<Artifact> artifacts = new Vector<Artifact>();
for (Library lib : libs) {
switch(lib.getType()) {
case Library.TYPE_BUILD:
Artifact artifact2 = UMA.getUma().getArtifact(lib.getName());
if (artifact2 != null && artifact2.evaluate()) {
artifacts.add(artifact2);
}
break;
}
}
for (Artifact oa : artifacts) {
if (oa.evaluate() && oa.flagSet("requiresPrimitiveTable")) {
buffer.append("extern EsPrimitiveTable " + oa.getTargetName().toUpperCase() + "PrimitiveTable;\n");
}
}
buffer.append("\nEsDefinePrimitiveTable(J9LinkedNatives)\n");
for (Artifact oa : artifacts) {
if (oa.evaluate() && oa.flagSet("requiresPrimitiveTable")) {
String startComment = "";
String endComment = "";
if (!oa.flagSet("isRequired") && !oa.flagSet("isRequiredFor" + artifact.getTargetNameWithScope())) {
startComment = "/* ";
endComment = " */";
}
buffer.append("\t" + startComment + "EsPrimitiveTableEntry(\"" + getTargetNameWithRelease(oa) + "\", " + oa.getTargetName().toUpperCase() + "PrimitiveTable)" + endComment + "\n");
}
}
buffer.append("EsEndPrimitiveTable\n");
}
buffer.append("\n#endif\n");
fa.writeToDisk();
}
use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.
the class PlatformUnix method writeExportFile.
@Override
protected void writeExportFile(Artifact artifact) throws UMAException {
if (!(artifact.getType() == Artifact.TYPE_BUNDLE) && !(artifact.getType() == Artifact.TYPE_SHARED))
return;
if (!isType("linux") && !isType("aix"))
return;
String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".exp";
FileAssistant fa = new FileAssistant(filename);
StringBuffer buffer = fa.getStringBuffer();
Vector<Export> exports = artifact.getExportedFunctions();
if (isType("linux")) {
buffer.append(" {\n");
/*
* The linker doesn't like .exp files that has no exports after the 'global:' label.
*
* This can happen when someone is creating a new shared library, but has yet to define any exports for it.
*/
if (exports.size() > 0)
buffer.append("\tglobal :");
}
for (Export export : exports) {
if (!export.evaluate())
continue;
if (isType("aix")) {
buffer.append(stripExportName(export.getExport()) + "\n");
} else if (isType("linux")) {
buffer.append("\n\t\t" + stripExportName(export.getExport()) + ";");
}
}
if (isType("linux")) {
buffer.append("\n\tlocal : *;\n};\n");
}
fa.writeToDisk();
}
use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.
the class PlatformWindows method writeSharedLibResourceFile.
// TODO: move to template file
void writeSharedLibResourceFile(Artifact artifact) throws UMAException {
if (artifact.getType() != Artifact.TYPE_SHARED && artifact.getType() != Artifact.TYPE_BUNDLE)
return;
GregorianCalendar calendar = new GregorianCalendar();
String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".rc";
FileAssistant fa = new FileAssistant(filename);
StringBuffer buffer = fa.getStringBuffer();
String productName = replaceMacro("rc_productName");
if (productName == null) {
productName = DEFAULT_RC_PRODUCT_NAME;
}
int buildIdLow = Integer.parseInt(getBuildId()) & 0xffff;
int buildIdHigh = Integer.parseInt(getBuildId()) >> 16;
buffer.append("\n" + "#include <windows.h>\n");
writeResourceFileDefines(buffer);
buffer.append("#include \"j9cfg.h\"\n" + "#include \"j9version.h\"\n" + "\n" + "VS_VERSION_INFO VERSIONINFO\n" + " FILEVERSION " + getMajorVersion() + "," + getMinorVersion() + "," + buildIdHigh + "," + buildIdLow + "\n" + " PRODUCTVERSION " + getMajorVersion() + "," + getMinorVersion() + "," + buildIdHigh + "," + buildIdLow + "\n" + " FILEFLAGSMASK 0x3fL\n" + " FILEFLAGS 0x0L\n" + " FILEOS VOS_NT_WINDOWS32\n" + " FILETYPE VFT_DLL\n" + " FILESUBTYPE 0x0L\n" + "BEGIN\n" + " BLOCK \"StringFileInfo\"\n" + " BEGIN\n" + " BLOCK \"040904b0\"\n" + " BEGIN\n" + " VALUE \"CompanyName\", \"International Business Machines Corporation\\0\"\n" + " VALUE \"FileDescription\", \"J9 Virtual Machine Runtime\\0\"\n" + " VALUE \"FileVersion\", \"R" + getMajorVersion() + "." + getMinorVersion() + " (\" EsBuildVersionString \")\\0\"\n" + " VALUE \"InternalName\", \"" + getTargetNameWithRelease(artifact) + "\\0\"\n" + " VALUE \"LegalCopyright\", \" Copyright (c) 1991, " + calendar.get(Calendar.YEAR) + " IBM Corp. and others\\0\"\n" + " VALUE \"OriginalFilename\", \"" + getTargetNameWithRelease(artifact) + ".dll\\0\"\n" + " VALUE \"ProductName\", \"" + productName + "\\0\"\n" + " VALUE \"ProductVersion\", \"R" + getMajorVersion() + "." + getMinorVersion() + "\\0\"\n" + " END\n" + " END\n" + " BLOCK \"VarFileInfo\"\n" + " BEGIN\n" + " VALUE \"Translation\", 0x0409, 1200\n" + " END\n" + "END\n");
fa.writeToDisk();
}
use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.
the class UMA method writeDirectoryMakefile.
// This function takes a module and creates a makefile for the directory,
// then recursively calls this function on all sub-modules.
void writeDirectoryMakefile(Module module) throws UMAException {
if (!module.evaluate())
return;
String modulePath = new File(module.getModulePath()).getParent();
Logger.getLogger().println(Logger.InformationL2Log, "Producing makefile(s) for " + modulePath);
for (Artifact artifact : module.getArtifacts()) {
writeMakefileForArtifact(artifact);
}
if (module.requiresDispatchMakefile()) {
// There needs to be a dispatch makefile
String makefileName = modulePath + File.separator + "makefile";
StringBuffer buffer = new StringBuffer();
FileAssistant fa = new FileAssistant(makefileName, buffer);
buffer.append(configuration.getMakefileCopyrightNotice());
String pathToRoot = determinePathToRoot(module);
Vector<String> targets = new Vector<String>();
Vector<String> specialTargets = new Vector<String>();
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
if (artifact.getType() == Artifact.TYPE_TARGET) {
if (artifact.includeInAllTarget()) {
/*
* The separation of targets into targets and specialTargets
* is being done to allow the 'TARGET' type artifacts to be built first.
* This is a weak way of saying that the whole system is dependent on
* these targets without having to add the dependency to each and every
* artifact.
*
* This only works when not using -j on gmake and because
* gmake will do the targets in the order they are on the dependency line.
*
*/
specialTargets.add(artifact.getMakefileName());
}
} else {
if (artifact.includeInAllTarget()) {
targets.add(artifact.getMakefileName());
}
}
}
buffer.append(UMA_PATH_TO_ROOT + "=" + pathToRoot + "\n");
buffer.append(OMR_DIR + "?=" + pathToRoot + "omr\n");
StringBuffer targetsInTreeBuffer = new StringBuffer();
LineWrapMakefileDirective lwmd = new LineWrapMakefileDirective(targetsInTreeBuffer);
targetsInTreeBuffer.append(UMA_TARGETS_IN_TREE + "=");
for (String target : specialTargets) {
lwmd.addItem(target);
}
for (String target : targets) {
lwmd.addItem(target);
}
buffer.append(targetsInTreeBuffer.toString());
buffer.append("\n\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_MKCONSTANTS_PATH_FROM_ROOT + "\n");
buffer.append("include " + UMA_PATH_TO_ROOT_VAR + UMA_MACROS_PATH_FROM_ROOT + "\n\n");
buffer.append(phasePrefix + "all: " + UMA_TARGETS_IN_TREE_VAR + "\n\n");
buffer.append("clean: $(addprefix clean_," + UMA_TARGETS_IN_TREE_VAR + ")\n\n");
buffer.append("ddrgen: $(addprefix ddrgen_," + UMA_TARGETS_IN_TREE_VAR + ")\n\n");
buffer.append("static: UMA_STATIC_BUILD=1\n" + " export UMA_STATIC_BUILD\n\n" + "static:\n" + " $(MAKE) -f makefile\n\n\n");
for (int phase = 0; phase < configuration.numberOfPhases(); phase++) {
Vector<String> phaseTargets = new Vector<String>();
Vector<String> specialPhaseTargets = new Vector<String>();
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
if (!artifact.isInPhase(phase))
continue;
if (artifact.getType() == Artifact.TYPE_TARGET) {
/*
* The separation of targets into phaseTargets and specialPhaseTargets
* is being done to allow the 'TARGET' type artifacts to be built first.
* This is a weak way of saying that the whole system is dependent on
* these targets without having to add the dependency to each and every
* artifact.
*
* This only works when not using -j on gmake and because
* gmake will do the targets in the order they are on the dependency line.
*
*/
specialPhaseTargets.add(artifact.getMakefileName());
} else {
phaseTargets.add(artifact.getMakefileName());
}
}
buffer.append(phasePrefix + "phase_" + configuration.phaseName(phase) + ":");
StringBuffer targetsInPhaseBuffer = new StringBuffer();
lwmd = new LineWrapMakefileDirective(targetsInPhaseBuffer);
for (String target : specialPhaseTargets) {
lwmd.addItem(target);
}
for (String target : phaseTargets) {
lwmd.addItem(target);
}
buffer.append(targetsInPhaseBuffer.toString() + "\n");
}
buffer.append("\n");
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
switch(artifact.getType()) {
case Artifact.TYPE_SUBDIR:
// to glue the tree together.
break;
case Artifact.TYPE_TARGET:
buffer.append("clean_" + artifact.getMakefileName() + ":\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_CLEAN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
buffer.append("ddrgen_" + artifact.getMakefileName() + ":\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_DDRGEN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
buffer.append(artifact.getMakefileName() + ":");
for (Dependency dependency : artifact.getDependendies()) {
if (!dependency.evaluate())
continue;
buffer.append(" " + dependency.getDependency());
}
buffer.append("\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_ALL)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
break;
default:
buffer.append("clean_" + artifact.getMakefileName() + ":\n\t$(" + artifact.getMakefileName() + "_build) clean\n\n");
buffer.append("ddrgen_" + artifact.getMakefileName() + ":\n\t$(" + artifact.getMakefileName() + "_build) ddrgen\n\n");
buffer.append(artifact.getMakefileName() + ": $(" + artifact.getMakefileName() + "_dependencies)\n\t$(" + artifact.getMakefileName() + "_build)\n\n");
break;
}
}
if (module.isTopLevel()) {
platform.writeTopLevelTargets(buffer);
}
buffer.append(".PHONY: all clean ddrgen");
StringBuffer phonyTargetsBuffer = new StringBuffer();
lwmd = new LineWrapMakefileDirective(phonyTargetsBuffer);
for (String phonyTarget : specialTargets) {
lwmd.addItem(phonyTarget);
lwmd.addItem(" clean_" + phonyTarget);
}
for (String phonyTarget : targets) {
lwmd.addItem(phonyTarget);
lwmd.addItem(" clean_" + phonyTarget);
}
buffer.append(phonyTargetsBuffer.toString() + "\n");
fa.writeToDisk();
}
for (Artifact artifact : module.getArtifacts()) {
if (artifact.getType() == Artifact.TYPE_SUBDIR) {
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
writeDirectoryMakefile(subdirArtifact.getSubdirModule());
}
}
}
use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.
the class UMA method writeTargetInformationMacrosFile.
void writeTargetInformationMacrosFile() throws UMAException {
/*
* Buffer for information about which libraries are static vs. shared
* and their locations on disk and references on the target and link lines.
*/
StringBuffer libLocations = new StringBuffer();
/*
* Buffer for target rules.
*/
StringBuffer targetRules = new StringBuffer();
/*
* A couple of hashtable to gather information an artifacts build dependencies.
*/
Hashtable<String, LinkedHashSet<String>> buildDependencies = new Hashtable<String, LinkedHashSet<String>>();
Hashtable<String, LinkedHashSet<String>> staticBuildDependencies = new Hashtable<String, LinkedHashSet<String>>();
for (Module module : modules) {
if (!module.evaluate())
continue;
// determine build dependencies
for (Artifact artifact : module.getArtifacts()) {
if (!artifact.evaluate())
continue;
switch(artifact.getType()) {
// Fall Through
case Artifact.TYPE_BUNDLE:
case Artifact.TYPE_SHARED:
libLocations.append(artifact.getTargetNameWithScope() + "_alllib=" + artifact.getTargetName() + "\n");
libLocations.append(artifact.getTargetNameWithScope() + "_sharedlib=" + artifact.getTargetName() + "\n");
platform.addLibraryLocationInformation(artifact, libLocations);
expandLibraryDependencies(artifact, libLocations);
break;
case Artifact.TYPE_STATIC:
libLocations.append(artifact.getTargetNameWithScope() + "_alllib=" + artifact.getTargetName() + "\n");
libLocations.append(artifact.getTargetNameWithScope() + "_staticlib=" + artifact.getTargetName() + "\n");
platform.addLibraryLocationInformation(artifact, libLocations);
expandLibraryDependencies(artifact, libLocations);
break;
case Artifact.TYPE_EXECUTABLE:
break;
}
switch(artifact.getType()) {
// Fall Through
case Artifact.TYPE_BUNDLE:
// Fall Through
case Artifact.TYPE_SHARED:
// Fall Through
case Artifact.TYPE_STATIC:
case // Fall Through
Artifact.TYPE_EXECUTABLE:
targetRules.append(artifact.getMakefileName() + "_build" + "=+$(MAKE) $(UMA_WINDOWS_PARRALLEL_HACK) -C " + UMA_PATH_TO_ROOT_VAR + artifact.getContainingModule().getFullName() + " -f " + artifact.getMakefileFileName() + "\n");
break;
}
addDependencies(artifact.getLibraries(), buildDependencies, artifact);
addDependencies(artifact.getStaticLinkLibraries(), staticBuildDependencies, artifact);
}
}
/*
* Write uma macros helper makefile. This file contains several variable definitions that allow
* easy reference to information about the artifacts. e.g.,
*/
File makelibDirectory = new File(UMA.getUma().getRootDirectory() + UMA_MAKELIB_DIR);
makelibDirectory.mkdir();
FileAssistant fa = new FileAssistant(UMA.getUma().getRootDirectory() + UMA_MACROS_PATH_FROM_ROOT);
StringBuffer buffer = fa.getStringBuffer();
buffer.append("# UMA Macro Helper Definition Makefile\n");
buffer.append(configuration.getMakefileCopyrightNotice());
buffer.append(libLocations.toString() + "\n\n\n");
for (String target : buildDependencies.keySet()) {
buffer.append("\n");
for (String dependency : buildDependencies.get(target)) {
buffer.append(target + "_dependencies+=$(findstring " + dependency + "," + UMA_TARGETS_IN_TREE_VAR + ")\n");
}
buffer.append("\n");
}
buffer.append("\n\nifdef UMA_STATIC_BUILD\n\n");
for (String target : staticBuildDependencies.keySet()) {
buffer.append("\n");
for (String dependency : staticBuildDependencies.get(target)) {
buffer.append(target + "_dependencies+=$(findstring " + dependency + "," + UMA_TARGETS_IN_TREE_VAR + ")\n");
}
buffer.append("\n");
}
buffer.append("\n\nendif\n\n");
buffer.append(targetRules.toString());
fa.writeToDisk();
}
Aggregations