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 25 import org.apache.jk.ant.Def; 26 import org.apache.jk.ant.SoTask; 27 import org.apache.jk.ant.Source; 28 import org.apache.tools.ant.BuildException; 29 import org.apache.tools.ant.types.Commandline; 30 31 41 public class MwccCompiler extends CcCompiler { 42 43 public MwccCompiler() { 44 super(); 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 54 56 public void compileSingleFile(Source sourceObj) throws BuildException { 57 File f=sourceObj.getFile(); 58 String source=f.toString(); 59 String [] includeList = ( includes==null ) ? 60 new String [] {} : includes.getIncludePatterns(project); 61 62 Commandline cmd = new Commandline(); 63 64 String cc=project.getProperty("build.compiler.cc"); 65 if(cc==null) cc="mwccnlm"; 66 67 cmd.setExecutable( cc ); 68 addCCArgs( cmd, source, includeList ); 69 70 int result=execute( cmd ); 71 if( result!=0 ) { 72 log("Compile failed " + result + " " + source ); 73 log("Output:" ); 74 if( outputstream!=null ) 75 log( outputstream.toString()); 76 log("StdErr:" ); 77 if( errorstream!=null ) 78 log( errorstream.toString()); 79 80 throw new BuildException("Compile failed " + source); 81 } 82 if (null == project.getProperty("save.optionFiles")) 83 { 84 File ccOpt = new File (buildDir, "cc.opt"); 85 ccOpt.delete(); 86 } 87 closeStreamHandler(); 88 89 } 90 91 93 private void addCCArgs(Commandline cmd, String source, String includeList[]) { 94 String extra_cflags=project.getProperty("build.native.extra_cflags"); 95 String localCflags=cflags; 96 File ccOpt = new File (buildDir, "cc.opt"); 97 boolean useLibC = false; 98 99 PrintWriter ccpw = null; 101 try 102 { 103 ccpw = new PrintWriter (new FileWriter (ccOpt)); 104 105 for( int i=0; i<includeList.length; i++ ) { 106 ccpw.print("-I"); 107 ccpw.println(includeList[i] ); 108 } 109 110 if( defines.size() > 0 ) { 111 Enumeration defs=defines.elements(); 112 while( defs.hasMoreElements() ) { 113 Def d=(Def)defs.nextElement(); 114 String name=d.getName(); 115 String val=d.getValue(); 116 if( name==null ) continue; 117 118 String arg="-D" + name; 119 if( val!=null ) 120 arg+= "=" + val; 121 ccpw.println(arg); 122 123 if (name.equals("__NOVELL_LIBC__")) 125 useLibC = true; 126 } 127 } 128 129 if( localCflags==null ) { 131 localCflags=new String ("-nosyspath -c -w nocmdline -bool on"); 132 if (useLibC) 133 localCflags += " -align 4"; 134 else 135 localCflags += " -align 1"; 136 137 if( extra_cflags!=null ) 138 localCflags+=" " + extra_cflags; 139 } 140 141 if (optG) 142 localCflags += " -g"; 143 144 ccpw.println(localCflags); 146 } 147 catch (IOException ioe) 148 { 149 log("Caught IOException"); 150 } 151 finally 152 { 153 if (ccpw != null) 154 { 155 ccpw.close(); 156 } 157 } 158 159 project.log( "Compiling " + source); 160 cmd.createArgument().setValue( source ); 161 cmd.createArgument().setValue( "@cc.opt" ); 162 } 163 } 164 165 | Popular Tags |