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 LibtoolLinker extends LinkerAdapter { 36 SoTask so; 37 GlobPatternMapper lo_mapper=new GlobPatternMapper(); 38 public LibtoolLinker() { 39 so=this; 40 lo_mapper.setFrom("*.c"); 41 lo_mapper.setTo("*.lo"); 42 } 43 44 46 public boolean link(Vector srcList) throws BuildException { 47 so.duplicateTo( this ); 48 Commandline cmd = new Commandline(); 49 50 String libtool=project.getProperty("build.native.libtool"); 51 if(libtool==null) libtool="libtool"; 52 53 cmd.setExecutable( libtool ); 54 55 cmd.createArgument().setValue("--mode=link"); 56 57 String cc=project.getProperty("build.native.cc"); 58 if(cc==null) cc="cc"; 59 60 cmd.createArgument().setValue( cc ); 61 62 cmd.createArgument().setValue("-module"); 63 cmd.createArgument().setValue("-avoid-version"); 64 cmd.createArgument().setValue("-rpath"); 65 cmd.createArgument().setValue( buildDir.getAbsolutePath()); 66 67 cmd.createArgument().setValue( "-o" ); 68 cmd.createArgument().setValue( soFile + ".la" ); 69 70 if( profile ) 71 cmd.createArgument().setValue("-pg" ); 72 73 Enumeration opts = linkOpts.elements(); 75 while( opts.hasMoreElements() ) { 76 JkData opt = (JkData) opts.nextElement(); 77 String option = opt.getValue(); 78 if( option == null ) continue; 79 80 cmd.createArgument().setValue( option ); 81 } 82 83 project.log( "Linking " + buildDir + "/" + soFile + ".so"); 85 86 if( libs!=null ) { 87 String libsA[]=libs.list(); 88 for( int i=0; i< libsA.length; i++ ) { 89 cmd.createArgument().setValue( "-l" + libsA[i] ); 90 project.log("XXX -l" + libsA[i] ); 92 } 93 } 94 95 for( int i=0; i<srcList.size(); i++ ) { 96 Source sourceObj=(Source)srcList.elementAt(i); 97 98 File ff=new File ( buildDir, sourceObj.getTargetFile(lo_mapper)); 99 cmd.createArgument().setValue( ff.toString() ); 100 } 101 102 int result=execute( cmd ); 103 if( result!=0 ) { 104 log("Link failed " + result ); 105 log("Command:" + cmd.toString()); 106 log("Output:" ); 107 if( outputstream!=null ) 108 log( outputstream.toString()); 109 log("StdErr:" ); 110 if( errorstream!=null ) 111 log( errorstream.toString()); 112 113 throw new BuildException("Link failed " + soFile); 114 } 115 closeStreamHandler(); 116 117 executeLibtoolInstall(); 118 return true; 119 } 120 121 123 private void executeLibtoolInstall() throws BuildException { 124 Commandline cmd = new Commandline(); 125 126 String libtool=project.getProperty("build.native.libtool"); 127 if(libtool==null) libtool="libtool"; 128 129 cmd.setExecutable( libtool ); 130 131 cmd.createArgument().setValue("--mode=install"); 132 133 cmd.createArgument().setValue( "cp" ); 134 135 File laFile=new File ( buildDir, soFile + ".la" ); 136 cmd.createArgument().setValue( laFile.getAbsolutePath()); 137 138 File soFileF=new File ( buildDir, soFile + ".so" ); 139 cmd.createArgument().setValue( soFileF.getAbsolutePath()); 140 141 int result=execute( cmd ); 142 if( result!=0 ) { 143 log("Link/install failed " + result ); 144 log("Command:" + cmd.toString()); 145 log("Output:" ); 146 if( outputstream!=null ) 147 log( outputstream.toString()); 148 log("StdErr:" ); 149 if( errorstream!=null ) 150 log( errorstream.toString()); 151 152 throw new BuildException("Link failed " + soFile); 153 } 154 closeStreamHandler(); 155 } 156 } 157 158 | Popular Tags |