1 16 17 package org.apache.jk.ant.compilers; 18 19 import java.io.File ; 20 import java.io.FileWriter ; 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.util.Enumeration ; 24 import java.util.Vector ; 25 26 import org.apache.jk.ant.JkData; 27 import org.apache.jk.ant.SoTask; 28 import org.apache.jk.ant.Source; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.types.Commandline; 31 import org.apache.tools.ant.util.GlobPatternMapper; 32 33 38 public class MwldLinker extends LinkerAdapter { 39 GlobPatternMapper lo_mapper=new GlobPatternMapper(); 40 41 public MwldLinker() { 42 super(); 43 lo_mapper.setFrom("*.c"); 44 lo_mapper.setTo("*.o"); 45 } 46 47 public void setSoTask(SoTask so ) { 48 this.so=so; 49 so.setExtension(".nlm"); 50 so.duplicateTo( this ); 51 project.setProperty("netware", "true"); 52 53 Enumeration e=altSoFiles.elements(); 54 while (e.hasMoreElements()) 55 { 56 JkData data = (JkData) e.nextElement(); 57 String altSo = data.getValue(); 58 if (altSo == null) 59 continue; 60 else 61 { 62 so.setTarget(altSo); setTarget(altSo); break; 65 } 66 } 67 } 68 69 public void execute() throws BuildException { 70 findSourceFiles(); 71 link(this.srcList); 72 } 73 74 76 public boolean link(Vector srcList) throws BuildException { 77 Commandline cmd = new Commandline(); 78 File linkOpt = new File (buildDir, "link.opt"); 79 File linkDef = new File (buildDir, "link.def"); 80 boolean useLibC = false; 81 82 String libtool=project.getProperty("build.compiler.ld"); 83 if(libtool==null) libtool="mwldnlm"; 84 85 cmd.setExecutable( libtool ); 86 87 project.log( "Linking " + buildDir + "/" + soFile + ".nlm"); 89 90 PrintWriter linkOptPw = null; 92 PrintWriter linkDefPw = null; 93 try 94 { 95 String libBase = project.getProperty("build.compiler.base"); 96 if (libBase == null) libBase = "\\tools\\mw\\5.3"; 97 linkOptPw = new PrintWriter (new FileWriter (linkOpt)); 98 linkDefPw = new PrintWriter (new FileWriter (linkDef)); 99 100 linkOptPw.println("-warnings off"); 102 linkOptPw.println("-zerobss"); 103 linkOptPw.println("-o " + soFile + ".nlm"); 104 linkOptPw.println("-map " + soFile + ".map"); 105 linkOptPw.println("-nodefaults"); 106 107 if (optG) 109 { 110 linkOptPw.println("-g"); 111 linkOptPw.println("-sym internal"); 112 linkOptPw.println("-sym codeview4"); 113 linkOptPw.println("-osym " + soFile + ".NCV"); 114 } 115 116 Enumeration opts = linkOpts.elements(); 118 while( opts.hasMoreElements() ) { 119 JkData opt = (JkData) opts.nextElement(); 120 String option = opt.getValue(); 121 if( option == null ) continue; 122 123 linkOptPw.println( option ); 124 option = option.toLowerCase(); 125 126 if (option.indexOf("libc") > 0) 128 useLibC = true; 129 } 130 131 if (useLibC) 133 linkOptPw.println("-llibcpre.o"); 134 else 135 linkOptPw.println(libBase + "\\lib\\nwpre.obj"); 136 137 for( int i=0; i<srcList.size(); i++ ) { 139 Source source=(Source)srcList.elementAt(i); 140 File srcF = source.getFile(); 141 String name=srcF.getName(); 142 String targetNA[]=lo_mapper.mapFileName( name ); 143 if( targetNA!=null ) 144 linkOptPw.println( targetNA[0] ); 145 } 146 linkOptPw.println("-commandfile link.def"); 147 148 Enumeration mods = modules.elements(); 150 while( mods.hasMoreElements() ) { 151 JkData mod = (JkData) mods.nextElement(); 152 String name = mod.getValue(); 153 if( name==null ) continue; 154 linkDefPw.println("module " + name); 155 } 156 157 Enumeration imps = imports.elements(); 159 while( imps.hasMoreElements() ) { 160 JkData imp = (JkData) imps.nextElement(); 161 String name = imp.getValue(); 162 if( name==null ) continue; 163 if (imp.isFile()) 164 linkDefPw.println("Import @" + name); 165 else 166 linkDefPw.println("Import " + name); 167 } 168 169 Enumeration exps = exports.elements(); 171 while( exps.hasMoreElements() ) { 172 JkData exp = (JkData) exps.nextElement(); 173 String name = exp.getValue(); 174 if( name==null ) continue; 175 if (exp.isFile()) 176 linkDefPw.println("Export @" + name); 177 else 178 linkDefPw.println("Export " + name); 179 } 180 } 181 catch (IOException ioe) 182 { 183 log("Caught IOException"); 184 } 185 finally 186 { 187 if (linkOptPw != null) 188 { 189 linkOptPw.close(); 190 } 191 192 if (linkDefPw != null) 193 { 194 linkDefPw.close(); 195 } 196 } 197 198 199 cmd.createArgument().setValue( "@link.opt" ); 200 int result=execute( cmd ); 201 if( result!=0 ) { 202 log("Link failed " + result ); 203 log("Command:" + cmd.toString()); 204 log("Output:" ); 205 if( outputstream!=null ) 206 log( outputstream.toString()); 207 log("StdErr:" ); 208 if( errorstream!=null ) 209 log( errorstream.toString()); 210 211 throw new BuildException("Link failed " + soFile); 212 } 213 if (null == project.getProperty("save.optionFiles")) 214 { 215 linkOpt.delete(); 216 linkDef.delete(); 217 } 218 closeStreamHandler(); 219 return true; 220 } 221 } 222 223 | Popular Tags |