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: import org.apache.tools.ant.util.GlobPatternMapper;
025:
026: /**
027: * Compile using Gcc.
028: *
029: * @author Costin Manolache
030: */
031: public class CcCompiler extends CompilerAdapter {
032: GlobPatternMapper co_mapper = new GlobPatternMapper();
033:
034: public CcCompiler() {
035: super ();
036: co_mapper.setFrom("*.c");
037: co_mapper.setTo("*.o");
038: }
039:
040: public String[] getTargetFiles(Source src) {
041: File srcFile = src.getFile();
042: String name = srcFile.getName();
043:
044: return co_mapper.mapFileName(name);
045: }
046:
047: String cc;
048:
049: /** Compile using 'standard' gcc flags. This assume a 'current' gcc on
050: * a 'normal' platform - no need for libtool
051: */
052: public void compileSingleFile(Source sourceObj)
053: throws BuildException {
054: File f = sourceObj.getFile();
055: String source = f.toString();
056: Commandline cmd = new Commandline();
057:
058: cc = project.getProperty("build.native.cc");
059: if (cc == null)
060: cc = "cc";
061:
062: cmd.setExecutable(cc);
063:
064: cmd.createArgument().setValue("-c");
065:
066: addIncludes(cmd);
067: addExtraFlags(cmd);
068: addDebug(cmd);
069: addDefines(cmd);
070: addOptimize(cmd);
071: addProfile(cmd);
072:
073: cmd.createArgument().setValue(source);
074:
075: project.log("Compiling " + source);
076:
077: int result = execute(cmd);
078: displayError(result, source, cmd);
079: closeStreamHandler();
080: }
081:
082: protected void addDebug(Commandline cmd) {
083: if (optG) {
084: cmd.createArgument().setValue("-g");
085: }
086:
087: if (optWgcc) {
088: if (!"HP-UX"
089: .equalsIgnoreCase(System.getProperty("os.name"))) {
090: // HP-UX uses -W for some other things
091: cmd.createArgument().setValue("-W");
092: }
093:
094: if (cc != null && cc.indexOf("gcc") >= 0) {
095: //cmd.createArgument().setValue("-Wall");
096: cmd.createArgument().setValue("-Wimplicit");
097: cmd.createArgument().setValue("-Wreturn-type");
098: cmd.createArgument().setValue("-Wcomment");
099: cmd.createArgument().setValue("-Wformat");
100: cmd.createArgument().setValue("-Wchar-subscripts");
101: cmd.createArgument().setValue("-O");
102: cmd.createArgument().setValue("-Wuninitialized");
103:
104: // Non -Wall
105: // cmd.createArgument().setValue("-Wtraditional");
106: // cmd.createArgument().setValue("-Wredundant-decls");
107: cmd.createArgument().setValue("-Wmissing-declarations");
108: cmd.createArgument().setValue("-Wmissing-prototypes");
109: // cmd.createArgument().setValue("-Wconversions");
110: cmd.createArgument().setValue("-Wcast-align");
111: // cmd.createArgument().setValue("-pedantic" );
112: }
113: }
114: }
115:
116: protected void addOptimize(Commandline cmd) {
117: if (optimize)
118: cmd.createArgument().setValue("-O3");
119: }
120:
121: protected void addProfile(Commandline cmd) {
122: if (profile) {
123: cmd.createArgument().setValue("-pg");
124: // bb.in
125: // cmd.createArgument().setValue("-ax" );
126: }
127: }
128:
129: }
|