1 11 import java.io.BufferedWriter ; 12 import java.io.File ; 13 import java.io.FileWriter ; 14 import java.io.IOException ; 15 import java.io.Writer ; 16 import java.util.ArrayList ; 17 18 public class GenerateBuildScript { 19 20 private static final String LINE_SEPARATOR = System.getProperty("line.separator"); 21 private static final String HEADER= 22 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + LINE_SEPARATOR + 23 "<project name=\"export-executable\" default=\"build_executable\">" +LINE_SEPARATOR + 24 " <target name=\"build_executable\">" + LINE_SEPARATOR + 25 " <echo message=\"compiling resources -> .o\"/>" + LINE_SEPARATOR; 26 27 private static final String FOOTER = 28 " <echo message=\"compiling sources -> .o\"/>" + LINE_SEPARATOR + 29 " <apply failonerror=\"true\" executable=\"${gcc-path}/bin/gcj.exe\" dest=\"${work}\" parallel=\"false\">" + LINE_SEPARATOR + 30 " <arg value=\"--verbose\"/>" + LINE_SEPARATOR + 31 " <arg value=\"--classpath=${work}\"/>" + LINE_SEPARATOR + 32 " <arg value=\"-O2\"/>" + LINE_SEPARATOR + 33 " <arg value=\"-c\"/>" + LINE_SEPARATOR + 34 " <arg value=\"-fassume-compiled\"/>" + LINE_SEPARATOR + 35 " <arg value=\"-march=pentium4\"/>" + LINE_SEPARATOR + 36 " <arg value=\"-mfpmath=sse\"/>" + LINE_SEPARATOR + 37 " <srcfile/>" + LINE_SEPARATOR + 38 " <arg value=\"-o\"/>" + LINE_SEPARATOR + 39 " <targetfile/>" + LINE_SEPARATOR + 40 " <fileset dir=\"${work}\" includes=\"**/*.java\"/>" + LINE_SEPARATOR + 41 " <mapper type=\"glob\" from=\"*.java\" to=\"*.o\"/>" + LINE_SEPARATOR + 42 " </apply>" + LINE_SEPARATOR + LINE_SEPARATOR + 43 " <echo message=\"linking .o -> ${binaryname}\"/>" + LINE_SEPARATOR + 44 " <apply failonerror=\"true\" executable=\"${gcc-path}/bin/gcj.exe\" parallel=\"true\">" + LINE_SEPARATOR + 45 " <arg value=\"--verbose\"/>" + LINE_SEPARATOR + 46 " <arg line =\"-o ${dest}${binaryname}.exe\"/>" + LINE_SEPARATOR + 47 " <arg value=\"-fassume-compiled\"/>" + LINE_SEPARATOR + 48 " <arg value=\"-march=pentium4\"/>" + LINE_SEPARATOR + 49 " <arg value=\"-mfpmath=sse\"/>" + LINE_SEPARATOR + 50 " <arg line=\"--main=org.eclipse.jdt.internal.compiler.batch.Main\"/>" + LINE_SEPARATOR + 51 " <fileset dir=\"${work}\" includes=\"**/*.o\"/>" + LINE_SEPARATOR + 52 " </apply>" + LINE_SEPARATOR + 53 " </target>" + LINE_SEPARATOR + 54 "</project>" + LINE_SEPARATOR; 55 56 private static void collectAllPropertiesFiles(File root, ArrayList collector) { 57 File [] files = root.listFiles(); 58 for (int i = 0; i < files.length; i++) { 59 if (files[i].isDirectory()) { 60 collectAllPropertiesFiles(files[i], collector); 61 } else if (files[i].getName().endsWith(".rsc") || files[i].getName().endsWith(".properties")) { String newElement = files[i].getAbsolutePath(); 63 newElement = newElement.replace('\\', '/'); 64 collector.add(newElement); 65 } 66 } 67 } 68 69 private static void dumpAllProperties(Writer writer, File sourceDir, ArrayList collector) throws IOException { 70 for (int i = 0, max = collector.size(); i < max; i++) { 71 String absolutePath = (String ) collector.get(i); 72 String fileName = absolutePath.substring(sourceDir.getAbsolutePath().length() + 1); 73 writer.write(" <exec dir=\"${work}\" executable=\"${gcc-path}/bin/gcj.exe\">" + LINE_SEPARATOR); 74 writer.write(" <arg line=\"--resource "); 75 writer.write(fileName + " " + fileName + " -c -o " + getObjectName(fileName) + "\"/>" + LINE_SEPARATOR); 76 writer.write(" </exec>" + LINE_SEPARATOR); 77 } 78 } 79 80 private static String getObjectName(String fileName) { 81 return fileName.substring(0, fileName.lastIndexOf('.')) + ".o"; 82 } 83 84 public static void main(String [] args) { 85 if (args.length != 2) { 86 return; 87 } 88 try { 89 BufferedWriter writer = new BufferedWriter (new FileWriter (new File (args[0]))); 90 writer.write(HEADER); 91 File sourceDir = new File (args[1]); 92 if (sourceDir.exists()) { 93 ArrayList collector = new ArrayList (); 94 collectAllPropertiesFiles(sourceDir, collector); 95 dumpAllProperties(writer, sourceDir, collector); 96 } 97 writer.write(FOOTER); 98 writer.flush(); 99 writer.close(); 100 } catch (IOException e) { 101 e.printStackTrace(); 102 } 103 } 104 } 105 | Popular Tags |