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  package com.github.maven_nar.cpptasks.compaq;
21  
22  import java.io.File;
23  import java.util.Vector;
24  
25  import org.apache.tools.ant.types.Environment;
26  
27  import com.github.maven_nar.cpptasks.CUtil;
28  import com.github.maven_nar.cpptasks.OptimizationEnum;
29  import com.github.maven_nar.cpptasks.compiler.CommandLineFortranCompiler;
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.compiler.Processor;
33  
34  /**
35   * Adapter for the Compaq(r) Visual Fortran compiler.
36   *
37   * @author Curt Arnold
38   */
39  public class CompaqVisualFortranCompiler extends CommandLineFortranCompiler {
40    private static final CompaqVisualFortranCompiler[] instance = new CompaqVisualFortranCompiler[] {
41      new CompaqVisualFortranCompiler(false, null)
42    };
43  
44    public static CompaqVisualFortranCompiler getInstance() {
45      return instance[0];
46    }
47  
48    private CompaqVisualFortranCompiler(final boolean newEnvironment, final Environment env) {
49      super("DF", null, new String[] {
50          ".f90", ".for", ".f"
51      }, new String[] {
52          ".i", ".i90", ".fpp", ".inc", ".bak", ".exe"
53      }, ".obj", false, null, newEnvironment, env);
54    }
55  
56    @Override
57    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
58        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
59      args.addElement("/nologo");
60      args.addElement("/compile_only");
61      if (debug) {
62        args.addElement("/debug:full");
63        args.addElement("/define:_DEBUG");
64      } else {
65        args.addElement("/debug:none");
66        args.addElement("/define:NDEBUG");
67      }
68      if (multithreaded) {
69        args.addElement("/threads");
70        args.addElement("/define:_MT");
71      } else {
72        args.addElement("/nothreads");
73      }
74      final boolean staticRuntime = linkType.isStaticRuntime();
75      if (staticRuntime) {
76        args.addElement("/libs:static");
77      } else {
78        args.addElement("/libs:dll");
79      }
80      if (linkType.isSharedLibrary()) {
81        args.addElement("/dll");
82        args.addElement("/define:_DLL");
83      }
84    }
85  
86    @Override
87    public void addWarningSwitch(final Vector<String> args, final int level) {
88      switch (level) {
89        case 0:
90          args.addElement("/nowarn");
91          break;
92        case 1:
93          break;
94        case 2:
95          break;
96        case 3:
97          args.addElement("/warn:usage");
98          break;
99        case 4:
100         args.addElement("/warn:all");
101         break;
102       case 5:
103         args.addElement("/warn:errors");
104         break;
105     }
106   }
107 
108   @Override
109   public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
110     if (newEnvironment || env != null) {
111       return new CompaqVisualFortranCompiler(newEnvironment, env);
112     }
113     return this;
114   }
115 
116   @Override
117   protected void getDefineSwitch(final StringBuffer buf, final String define, final String value) {
118     buf.append("/define:");
119     buf.append(define);
120     if (value != null && value.length() > 0) {
121       buf.append('=');
122       buf.append(value);
123     }
124   }
125 
126   @Override
127   protected File[] getEnvironmentIncludePath() {
128     return CUtil.getPathFromEnvironment("INCLUDE", ";");
129   }
130 
131   @Override
132   protected String getIncludeDirSwitch(final String includeDir) {
133     // BEGINFREEHEP quotes seem to confuse the compiler
134     // if (includeDir.indexOf(' ') >= 0) {
135     // buf.append('"');
136     // buf.append(includeDir);
137     // buf.append('"');
138     // } else {
139     // }
140     // ENDFREEHEP
141     return "/include:" + includeDir;
142   }
143 
144   @Override
145   public Linker getLinker(final LinkType type) {
146     return CompaqVisualFortranLinker.getInstance().getLinker(type);
147   }
148 
149   @Override
150   public int getMaximumCommandLength() {
151     return 1024;
152   }
153 
154   @Override
155   protected void getUndefineSwitch(final StringBuffer buf, final String define) {
156     buf.append("/undefine:");
157     buf.append(define);
158   }
159 }