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:
021: import org.apache.jk.ant.Source;
022: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.types.Commandline;
024:
025: /**
026: * Compile using Gcj. This is ( even more ) experimental.
027: *
028: * @author Costin Manolache
029: */
030: public class GcjCompiler extends CcCompiler {
031:
032: public GcjCompiler() {
033: super ();
034: co_mapper.setFrom("*.java");
035: co_mapper.setTo("*.o");
036: }
037:
038: public String[] getTargetFiles(Source src) {
039: File srcFile = src.getFile();
040: String name = srcFile.getName();
041: if (name.endsWith(".java")) {
042: return co_mapper.mapFileName(name);
043: } else {
044: return new String[] { name + ".o" };
045: }
046: }
047:
048: /** Compile using libtool.
049: */
050: public void compileSingleFile(Source sourceObj)
051: throws BuildException {
052: File f = sourceObj.getFile();
053: String source = f.toString();
054: Commandline cmd = new Commandline();
055:
056: cmd.setExecutable("gcj");
057:
058: cmd.createArgument().setValue("-c");
059:
060: if (optG) {
061: // cmd.createArgument().setValue("-g" );
062: cmd.createArgument().setValue("-ggdb3");
063: // cmd.createArgument().setValue("-save-temps" );
064: // cmd.createArgument().setValue("-Wall");
065: }
066: addOptimize(cmd);
067: addExtraFlags(cmd);
068: cmd.createArgument().setValue("-fPIC");
069: addIncludes(cmd);
070: String targetDir = sourceObj.getPackage();
071: try {
072: File f1 = new File(buildDir, targetDir);
073: f1.mkdirs();
074: cmd.createArgument().setValue("-o");
075: String targetO[] = getTargetFiles(sourceObj);
076: if (targetO == null) {
077: log("no target for " + sourceObj.getFile());
078: return;
079: }
080: File ff = new File(f1, targetO[0]);
081: cmd.createArgument().setValue(ff.toString());
082: } catch (Exception ex) {
083: ex.printStackTrace();
084: }
085:
086: if (!source.endsWith(".java")) {
087: cmd.createArgument().setValue("-R");
088: cmd.createArgument()
089: .setValue(targetDir + "/" + f.getName());
090: //System.out.println("XXX resource " + targetDir + "/" + f.getName() );
091: } else {
092: // cmd.createArgument().setValue("-fno-bounds-check" );
093: }
094: cmd.createArgument().setValue(source);
095: project.log("Compiling " + source);
096:
097: if (debug > 0)
098: project.log("Command: " + cmd);
099: int result = execute(cmd);
100: if (result != 0) {
101: displayError(result, source, cmd);
102: }
103: closeStreamHandler();
104: }
105:
106: protected void addIncludes(Commandline cmd) {
107: String[] includeList = (includes == null) ? new String[] {}
108: : includes.getIncludePatterns(project);
109: for (int i = 0; i < includeList.length; i++) {
110: cmd.createArgument().setValue("-I" + includeList[i]);
111: }
112: }
113:
114: }
|