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.sun;
21  
22  import java.io.File;
23  import java.util.Vector;
24  
25  import com.github.maven_nar.cpptasks.CUtil;
26  import com.github.maven_nar.cpptasks.compiler.LinkType;
27  import com.github.maven_nar.cpptasks.compiler.Linker;
28  import com.github.maven_nar.cpptasks.gcc.AbstractLdLinker;
29  
30  /**
31   * Adapter for Sun (r) Forte(tm) C++ Linker
32   *
33   * @author Curt Arnold
34   */
35  public final class ForteCCLinker extends AbstractLdLinker {
36    private static final String[] discardFiles = new String[] {
37        ".dll", ".so", ".sl"
38    };
39    private static final String[] objFiles = new String[] {
40        ".o", ".a", ".lib"
41    };
42    private static final ForteCCLinker arLinker = new ForteCCLinker("CC", objFiles, discardFiles, "lib", ".a");
43    private static final ForteCCLinker dllLinker = new ForteCCLinker("CC", objFiles, discardFiles, "lib", ".so");
44    private static final ForteCCLinker instance = new ForteCCLinker("CC", objFiles, discardFiles, "", "");
45  
46    public static ForteCCLinker getInstance() {
47      return instance;
48    }
49  
50    private File[] libDirs;
51  
52    private ForteCCLinker(final String command, final String[] extensions, final String[] ignoredExtensions,
53        final String outputPrefix, final String outputSuffix) {
54      super(command, "-V", extensions, ignoredExtensions, outputPrefix, outputSuffix, false, null);
55    }
56  
57    public void addImpliedArgs(final boolean debug, final LinkType linkType, final Vector<String> args) {
58      if (debug) {
59        args.addElement("-g");
60      }
61      if (linkType.isStaticRuntime()) {
62        // FREEHEP changed -static
63        args.addElement("-staticlib=%all");
64      }
65      if (linkType.isSharedLibrary()) {
66        args.addElement("-G");
67      }
68      if (linkType.isStaticLibrary()) {
69        args.addElement("-xar");
70      }
71    }
72  
73    public void addIncremental(final boolean incremental, final Vector<String> args) {
74      /*
75       * if (incremental) { args.addElement("-xidlon"); } else {
76       * args.addElement("-xidloff"); }
77       */
78    }
79  
80    /**
81     * Returns library path.
82     * 
83     */
84    @Override
85    public File[] getLibraryPath() {
86      if (this.libDirs == null) {
87        final File CCloc = CUtil.getExecutableLocation("CC");
88        if (CCloc != null) {
89          final File compilerLib = new File(new File(CCloc, "../lib").getAbsolutePath());
90          if (compilerLib.exists()) {
91            this.libDirs = new File[2];
92            this.libDirs[0] = compilerLib;
93          }
94        }
95        if (this.libDirs == null) {
96          this.libDirs = new File[1];
97        }
98      }
99      this.libDirs[this.libDirs.length - 1] = new File("/usr/lib");
100     return this.libDirs;
101   }
102 
103   @Override
104   public Linker getLinker(final LinkType type) {
105     if (type.isStaticLibrary()) {
106       return arLinker;
107     }
108     if (type.isSharedLibrary()) {
109       return dllLinker;
110     }
111     return instance;
112   }
113 }