1 18 19 package org.apache.tools.ant.taskdefs.compilers; 20 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.Commandline; 25 import org.apache.tools.ant.types.Path; 26 27 33 public class Gcj extends DefaultCompilerAdapter { 34 35 40 public boolean execute() throws BuildException { 41 Commandline cmd; 42 attributes.log("Using gcj compiler", Project.MSG_VERBOSE); 43 cmd = setupGCJCommand(); 44 45 int firstFileName = cmd.size(); 46 logAndAddFilesToCompile(cmd); 47 48 return 49 executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; 50 } 51 52 56 protected Commandline setupGCJCommand() { 57 Commandline cmd = new Commandline(); 58 Path classpath = new Path(project); 59 60 Path p = getBootClassPath(); 63 if (p.size() > 0) { 64 classpath.append(p); 65 } 66 67 classpath.addExtdirs(extdirs); 70 71 classpath.append(getCompileClasspath()); 72 73 if (compileSourcepath != null) { 76 classpath.append(compileSourcepath); 77 } else { 78 classpath.append(src); 79 } 80 81 String exec = getJavac().getExecutable(); 82 cmd.setExecutable(exec == null ? "gcj" : exec); 83 84 if (destDir != null) { 85 cmd.createArgument().setValue("-d"); 86 cmd.createArgument().setFile(destDir); 87 88 if (!destDir.exists() && !destDir.mkdirs()) { 89 throw new BuildException("Can't make output directories. " 90 + "Maybe permission is wrong. "); 91 } 92 } 93 94 cmd.createArgument().setValue("-classpath"); 95 cmd.createArgument().setPath(classpath); 96 97 if (encoding != null) { 98 cmd.createArgument().setValue("--encoding=" + encoding); 99 } 100 if (debug) { 101 cmd.createArgument().setValue("-g1"); 102 } 103 if (optimize) { 104 cmd.createArgument().setValue("-O"); 105 } 106 107 111 if (!isNativeBuild()) { 112 cmd.createArgument().setValue("-C"); 113 } 114 115 addCurrentCompilerArgs(cmd); 116 117 return cmd; 118 } 119 120 126 public boolean isNativeBuild() { 127 boolean nativeBuild = false; 128 String [] additionalArguments = getJavac().getCurrentCompilerArgs(); 129 int argsLength = 0; 130 while (!nativeBuild && argsLength < additionalArguments.length) { 131 int conflictLength = 0; 132 while (!nativeBuild 133 && conflictLength < CONFLICT_WITH_DASH_C.length) { 134 nativeBuild = (additionalArguments[argsLength].startsWith 135 (CONFLICT_WITH_DASH_C[conflictLength])); 136 conflictLength++; 137 } 138 argsLength++; 139 } 140 return nativeBuild; 141 } 142 143 private static final String [] CONFLICT_WITH_DASH_C = { 144 "-o" , "--main=", "-D", "-fjni", "-L" 145 }; 146 147 } 148 | Popular Tags |