View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  /*
21   * FREEHEP
22   */
23  package com.github.maven_nar.cpptasks.sun;
24  
25  import java.io.File;
26  import java.util.Vector;
27  
28  import com.github.maven_nar.cpptasks.CUtil;
29  import com.github.maven_nar.cpptasks.OptimizationEnum;
30  import com.github.maven_nar.cpptasks.compiler.LinkType;
31  import com.github.maven_nar.cpptasks.compiler.Linker;
32  import com.github.maven_nar.cpptasks.gcc.GccCompatibleCCompiler;
33  
34  /**
35   * Adapter for the Sun (r) Forte (tm) F77 compiler
36   *
37   * @author Mark Donszelmann
38   */
39  public final class ForteF77Compiler extends GccCompatibleCCompiler {
40    private static final ForteF77Compiler instance = new ForteF77Compiler("f77");
41  
42    /**
43     * Gets singleton instance of this class
44     */
45    public static ForteF77Compiler getInstance() {
46      return instance;
47    }
48  
49    private String identifier;
50    private File[] includePath;
51  
52    /**
53     * Private constructor. Use ForteF77Compiler.getInstance() to get singleton
54     * instance of this class.
55     */
56    private ForteF77Compiler(final String command) {
57      super(command, "-V", false, null, false, null);
58    }
59  
60    @Override
61    public void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
62        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
63      args.addElement("-c");
64      if (debug) {
65        args.addElement("-g");
66      }
67      if (optimization != null) {
68        if (optimization.isSpeed()) {
69          args.addElement("-xO2");
70        }
71      }
72      if (multithreaded) {
73        args.addElement("-mt");
74      }
75      if (linkType.isSharedLibrary()) {
76        args.addElement("-KPIC");
77      }
78  
79    }
80  
81    @Override
82    public void addWarningSwitch(final Vector<String> args, final int level) {
83      switch (level) {
84        case 0:
85          args.addElement("-w");
86          break;
87        case 1:
88        case 2:
89          args.addElement("+w");
90          break;
91        case 3:
92        case 4:
93        case 5:
94          args.addElement("+w2");
95          break;
96      }
97    }
98  
99    @Override
100   public File[] getEnvironmentIncludePath() {
101     if (this.includePath == null) {
102       final File f77Loc = CUtil.getExecutableLocation("f77");
103       if (f77Loc != null) {
104         final File compilerIncludeDir = new File(new File(f77Loc, "../include").getAbsolutePath());
105         if (compilerIncludeDir.exists()) {
106           this.includePath = new File[2];
107           this.includePath[0] = compilerIncludeDir;
108         }
109       }
110       if (this.includePath == null) {
111         this.includePath = new File[1];
112       }
113       this.includePath[this.includePath.length - 1] = new File("/usr/include");
114     }
115     return this.includePath;
116   }
117 
118   @Override
119   public Linker getLinker(final LinkType linkType) {
120     return ForteCCLinker.getInstance().getLinker(linkType);
121   }
122 
123   @Override
124   public int getMaximumCommandLength() {
125     return Integer.MAX_VALUE;
126   }
127 }