1 16 17 package org.apache.jk.ant.compilers; 18 19 import java.io.File ; 20 import java.util.Enumeration ; 21 import java.util.Vector ; 22 23 import org.apache.jk.ant.JkData; 24 import org.apache.jk.ant.SoTask; 25 import org.apache.jk.ant.Source; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.types.Commandline; 28 import org.apache.tools.ant.util.GlobPatternMapper; 29 30 35 public class GcjLinker extends LinkerAdapter { 36 SoTask so; 37 protected static GlobPatternMapper co_mapper=new GlobPatternMapper(); 38 static { 39 co_mapper.setFrom("*.java"); 40 co_mapper.setTo("*.o"); 41 } 42 public GcjLinker() { 43 so=this; 44 } 45 46 public String [] getTargetFiles( Source src ) { 47 File srcFile = src.getFile(); 48 String name=srcFile.getName(); 49 if( name.endsWith( ".java" ) ) 50 return co_mapper.mapFileName( name ); 51 else 52 return new String [] 53 { name + ".o" }; 54 } 55 56 57 58 public void setSoTask(SoTask so ) { 59 this.so=so; 60 so.duplicateTo( this ); 61 } 62 63 public void execute() throws BuildException { 64 findSourceFiles(); 65 link(this.srcList); 66 } 67 68 70 public boolean link(Vector srcList) throws BuildException { 71 link( srcList, true ); 73 return true; 74 } 75 public boolean link(Vector srcList, boolean shared) throws BuildException { 76 Commandline cmd = new Commandline(); 77 78 cmd.setExecutable( "gcj" ); 79 80 if( shared ) 81 cmd.createArgument().setValue( "--shared" ); 82 cmd.createArgument().setValue( "-o" ); 83 if( shared ) 84 cmd.createArgument().setValue( soFile + ".so" ); 85 else 86 cmd.createArgument().setValue( soFile + ".a" ); 87 88 project.log( "Linking " + buildDir + "/" + soFile + ".so"); 89 90 Enumeration opts = linkOpts.elements(); 92 while( opts.hasMoreElements() ) { 93 JkData opt = (JkData) opts.nextElement(); 94 String option = opt.getValue(); 95 if( option == null ) continue; 96 97 cmd.createArgument().setValue( option ); 98 } 99 100 for( int i=0; i<srcList.size(); i++ ) { 101 Source source=(Source)srcList.elementAt(i); 102 File f1=new File (buildDir, source.getPackage()); 103 File srcF=new File (f1, getTargetFiles(source)[0]); 104 cmd.createArgument().setValue( srcF.toString() ); 105 } 106 107 int result=execute( cmd ); 108 if( result!=0 ) { 109 log("Link failed " + result ); 110 log("Command:" + cmd.toString()); 111 log("Output:" ); 112 if( outputstream!=null ) 113 log( outputstream.toString()); 114 log("StdErr:" ); 115 if( errorstream!=null ) 116 log( errorstream.toString()); 117 118 throw new BuildException("Link failed " + soFile); 119 } 120 closeStreamHandler(); 121 122 return true; 123 } 124 } 125 126 | Popular Tags |