001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.jk.ant.compilers;
018:
019: import java.io.File;
020: import java.util.Enumeration;
021: import java.util.Vector;
022:
023: import org.apache.jk.ant.Source;
024: import org.apache.tools.ant.BuildException;
025: import org.apache.tools.ant.types.Commandline;
026:
027: /**
028: * Compile using libtool.
029: *
030: * It extends SoTask so we can debug it or use it independently of <so>.
031: * For normal use you should use the generic task, and system-specific
032: * properties to choose the right compiler plugin ( like we select
033: * jikes ).
034: *
035: * @author Costin Manolache
036: */
037: public class LibtoolCompiler extends CcCompiler {
038:
039: public LibtoolCompiler() {
040: super ();
041: };
042:
043: public void compile(Vector sourceFiles) throws BuildException {
044: compileList = findCompileList(sourceFiles);
045:
046: log("Compiling " + compileList.size() + " out of "
047: + sourceFiles.size());
048: Enumeration en = compileList.elements();
049: while (en.hasMoreElements()) {
050: Source source = (Source) en.nextElement();
051: compileSingleFile(source);
052: }
053: }
054:
055: /** Compile using libtool.
056: */
057: public void compileSingleFile(Source sourceObj)
058: throws BuildException {
059: File f = sourceObj.getFile();
060: String source = f.toString();
061: Commandline cmd = new Commandline();
062:
063: String libtool = project.getProperty("build.native.libtool");
064: if (libtool == null)
065: libtool = "libtool";
066:
067: cmd.setExecutable(libtool);
068:
069: cmd.createArgument().setValue("--mode=compile");
070:
071: String cc = project.getProperty("build.native.cc");
072: if (cc == null)
073: cc = "cc";
074:
075: cmd.createArgument().setValue(cc);
076:
077: cmd.createArgument().setValue("-c");
078:
079: cmd.createArgument().setValue("-o");
080:
081: File ff = new File(buildDir, sourceObj.getTargetFile(co_mapper));
082: cmd.createArgument().setValue(ff.toString());
083: try {
084: String targetDir = sourceObj.getPackage();
085: File f1 = new File(buildDir, targetDir);
086: f1.mkdirs();
087: // System.out.println("mkdir " + f1 );
088: } catch (Exception ex) {
089: ex.printStackTrace();
090: }
091:
092: addIncludes(cmd);
093: addExtraFlags(cmd);
094: addDebug(cmd);
095: addDefines(cmd);
096: addOptimize(cmd);
097: addProfile(cmd);
098:
099: project.log("Compiling " + source);
100: cmd.createArgument().setValue(source);
101:
102: if (debug > 0)
103: project.log(cmd.toString());
104: int result = execute(cmd);
105: displayError(result, source, cmd);
106: closeStreamHandler();
107: }
108: }
|