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 import org.apache.tools.ant.util.GlobPatternMapper; 25 26 31 public class CcCompiler extends CompilerAdapter { 32 GlobPatternMapper co_mapper=new GlobPatternMapper(); 33 34 public CcCompiler() { 35 super(); 36 co_mapper.setFrom("*.c"); 37 co_mapper.setTo("*.o"); 38 } 39 40 public String [] getTargetFiles( Source src ) { 41 File srcFile = src.getFile(); 42 String name=srcFile.getName(); 43 44 return co_mapper.mapFileName( name ); 45 } 46 47 String cc; 48 49 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 cc=project.getProperty("build.native.cc"); 58 if(cc==null) cc="cc"; 59 60 cmd.setExecutable( cc ); 61 62 cmd.createArgument().setValue( "-c" ); 63 64 addIncludes(cmd); 65 addExtraFlags( cmd ); 66 addDebug(cmd); 67 addDefines( cmd ); 68 addOptimize( cmd ); 69 addProfile( cmd ); 70 71 cmd.createArgument().setValue( source ); 72 73 project.log( "Compiling " + source); 74 75 int result=execute( cmd ); 76 displayError( result, source, cmd ); 77 closeStreamHandler(); 78 } 79 protected void addDebug(Commandline cmd) { 80 if( optG ) { 81 cmd.createArgument().setValue("-g" ); 82 } 83 84 if( optWgcc ) { 85 if( ! "HP-UX".equalsIgnoreCase( System.getProperty( "os.name" )) ) { 86 cmd.createArgument().setValue("-W"); 88 } 89 90 if( cc!= null && cc.indexOf( "gcc" ) >= 0 ) { 91 cmd.createArgument().setValue("-Wimplicit"); 93 cmd.createArgument().setValue("-Wreturn-type"); 94 cmd.createArgument().setValue("-Wcomment"); 95 cmd.createArgument().setValue("-Wformat"); 96 cmd.createArgument().setValue("-Wchar-subscripts"); 97 cmd.createArgument().setValue("-O"); 98 cmd.createArgument().setValue("-Wuninitialized"); 99 100 cmd.createArgument().setValue("-Wmissing-declarations"); 104 cmd.createArgument().setValue("-Wmissing-prototypes"); 105 cmd.createArgument().setValue("-Wcast-align"); 107 } 109 } 110 } 111 protected void addOptimize( Commandline cmd ) { 112 if( optimize ) 113 cmd.createArgument().setValue("-O3" ); 114 } 115 116 protected void addProfile( Commandline cmd ) { 117 if( profile ) { 118 cmd.createArgument().setValue("-pg" ); 119 } 122 } 123 124 125 } 126 127 | Popular Tags |