KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Enumeration JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import org.apache.jk.ant.Source;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.types.Commandline;
26
27 /**
28  * Compile using libtool.
29  *
30  * It extends SoTask so we can debug it or use it independently of <so>.
31  * For normal use you should use the generic task, and system-specific
32  * properties to choose the right compiler plugin ( like we select
33  * jikes ).
34  *
35  * @author Costin Manolache
36  */

37 public class LibtoolCompiler extends CcCompiler {
38
39     public LibtoolCompiler() {
40     super();
41     };
42
43     public void compile(Vector JavaDoc sourceFiles ) throws BuildException {
44         compileList=findCompileList(sourceFiles);
45         
46         log("Compiling " + compileList.size() + " out of " + sourceFiles.size());
47     Enumeration JavaDoc en=compileList.elements();
48     while( en.hasMoreElements() ) {
49         Source source=(Source)en.nextElement();
50         compileSingleFile(source);
51     }
52     }
53     
54
55     /** Compile using libtool.
56      */

57     public void compileSingleFile(Source sourceObj) throws BuildException {
58     File JavaDoc f=sourceObj.getFile();
59     String JavaDoc source=f.toString();
60     Commandline cmd = new Commandline();
61
62     String JavaDoc libtool=project.getProperty("build.native.libtool");
63     if(libtool==null) libtool="libtool";
64
65     cmd.setExecutable( libtool );
66     
67     cmd.createArgument().setValue("--mode=compile");
68
69     String JavaDoc cc=project.getProperty("build.native.cc");
70     if(cc==null) cc="cc";
71
72     cmd.createArgument().setValue( cc );
73
74     cmd.createArgument().setValue( "-c" );
75     
76     cmd.createArgument().setValue( "-o" );
77     
78     File JavaDoc ff=new File JavaDoc( buildDir, sourceObj.getTargetFile(co_mapper));
79     cmd.createArgument().setValue( ff.toString() );
80     try {
81         String JavaDoc targetDir=sourceObj.getPackage();
82         File JavaDoc f1=new File JavaDoc( buildDir, targetDir );
83         f1.mkdirs();
84         // System.out.println("mkdir " + f1 );
85
} catch( Exception JavaDoc ex ) {
86         ex.printStackTrace();
87     }
88
89     addIncludes(cmd);
90     addExtraFlags( cmd );
91     addDebug(cmd);
92     addDefines( cmd );
93     addOptimize( cmd );
94     addProfile( cmd );
95
96     project.log( "Compiling " + source);
97     cmd.createArgument().setValue( source );
98
99         if( debug > 0 ) project.log(cmd.toString());
100     int result=execute( cmd );
101         displayError( result, source, cmd );
102     closeStreamHandler();
103     }
104 }
105
106
Popular Tags