1 16 17 package org.apache.jk.ant.compilers; 18 19 import java.io.File ; 20 21 import org.apache.jk.ant.Source; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.types.Commandline; 24 25 30 public class GcjCompiler extends CcCompiler { 31 32 public GcjCompiler() { 33 super(); 34 co_mapper.setFrom("*.java"); 35 co_mapper.setTo("*.o"); 36 } 37 38 public String [] getTargetFiles( Source src ) { 39 File srcFile = src.getFile(); 40 String name=srcFile.getName(); 41 if( name.endsWith( ".java" ) ) { 42 return co_mapper.mapFileName( name ); 43 } else { 44 return new String [] 45 { name + ".o" }; 46 } 47 } 48 49 50 52 public void compileSingleFile(Source sourceObj) throws BuildException { 53 File f=sourceObj.getFile(); 54 String source=f.toString(); 55 Commandline cmd = new Commandline(); 56 57 cmd.setExecutable( "gcj" ); 58 59 cmd.createArgument().setValue("-c" ); 60 61 if( optG ) { 62 cmd.createArgument().setValue("-ggdb3" ); 64 } 67 addOptimize( cmd ); 68 addExtraFlags( cmd ); 69 cmd.createArgument().setValue("-fPIC" ); 70 addIncludes( cmd ); 71 String targetDir=sourceObj.getPackage(); 72 try { 73 File f1=new File ( buildDir, targetDir ); 74 f1.mkdirs(); 75 cmd.createArgument().setValue( "-o" ); 76 String targetO[]=getTargetFiles( sourceObj ); 77 if( targetO==null ) { 78 log("no target for " + sourceObj.getFile() ); 79 return; 80 } 81 File ff=new File ( f1, targetO[0]); 82 cmd.createArgument().setValue( ff.toString() ); 83 } catch( Exception ex ) { 84 ex.printStackTrace(); 85 } 86 87 if( ! source.endsWith(".java") ) { 88 cmd.createArgument().setValue("-R" ); 89 cmd.createArgument().setValue( targetDir + "/" + f.getName() ); 90 } else { 92 } 94 cmd.createArgument().setValue( source ); 95 project.log( "Compiling " + source); 96 97 if( debug > 0 ) 98 project.log( "Command: " + cmd ); 99 int result=execute( cmd ); 100 if( result!=0 ) { 101 displayError( result, source, cmd ); 102 } 103 closeStreamHandler(); 104 } 105 106 protected void addIncludes(Commandline cmd) { 107 String [] includeList = ( includes==null ) ? 108 new String [] {} : includes.getIncludePatterns(project); 109 for( int i=0; i<includeList.length; i++ ) { 110 cmd.createArgument().setValue("-I" + includeList[i] ); 111 } 112 } 113 114 115 } 116 117 | Popular Tags |