KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jk > ant > compilers > CcCompiler


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jk.ant.compilers;
18
19 import java.io.File JavaDoc;
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 /**
27  * Compile using Gcc.
28  *
29  * @author Costin Manolache
30  */

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 JavaDoc[] getTargetFiles( Source src ) {
41         File JavaDoc srcFile = src.getFile();
42         String JavaDoc name=srcFile.getName();
43         
44         return co_mapper.mapFileName( name );
45     }
46     
47     String JavaDoc cc;
48     
49     /** Compile using 'standard' gcc flags. This assume a 'current' gcc on
50      * a 'normal' platform - no need for libtool
51      */

52     public void compileSingleFile(Source sourceObj) throws BuildException {
53     File JavaDoc f=sourceObj.getFile();
54     String JavaDoc 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                 // HP-UX uses -W for some other things
87
cmd.createArgument().setValue("-W");
88             }
89
90             if( cc!= null && cc.indexOf( "gcc" ) >= 0 ) {
91                 //cmd.createArgument().setValue("-Wall");
92
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                 // Non -Wall
101
// cmd.createArgument().setValue("-Wtraditional");
102
// cmd.createArgument().setValue("-Wredundant-decls");
103
cmd.createArgument().setValue("-Wmissing-declarations");
104                 cmd.createArgument().setValue("-Wmissing-prototypes");
105                 // cmd.createArgument().setValue("-Wconversions");
106
cmd.createArgument().setValue("-Wcast-align");
107                 // cmd.createArgument().setValue("-pedantic" );
108
}
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         // bb.in
120
// cmd.createArgument().setValue("-ax" );
121
}
122     }
123
124
125 }
126
127
Popular Tags