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.hp;
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 aCCLinker extends AbstractLdLinker {
36    private static final String[] discardFiles = new String[0];
37    private static final String[] objFiles = new String[] {
38        ".o", ".a", ".lib", ".dll", ".so", ".sl"
39    };
40    private static final aCCLinker arLinker = new aCCLinker("aCC", objFiles, discardFiles, "", ".a");
41    private static final aCCLinker dllLinker = new aCCLinker("aCC", objFiles, discardFiles, "lib", ".sl");
42    private static final aCCLinker instance = new aCCLinker("aCC", objFiles, discardFiles, "", "");
43  
44    public static aCCLinker getInstance() {
45      return instance;
46    }
47  
48    private File[] libDirs;
49  
50    private aCCLinker(final String command, final String[] extensions, final String[] ignoredExtensions,
51        final String outputPrefix, final String outputSuffix) {
52      super(command, "-help", extensions, ignoredExtensions, outputPrefix, outputSuffix, false, null);
53    }
54  
55    public void addImpliedArgs(final boolean debug, final LinkType linkType, final Vector<String> args) {
56      if (debug) {
57        args.addElement("-g");
58      }
59      /*
60       * if(linkType.isStaticRuntime()) { args.addElement("-static"); }
61       */
62      if (linkType.isSharedLibrary()) {
63        args.addElement("-b");
64      }
65      /*
66       * if (linkType.isStaticLibrary()) { args.addElement("-Wl,-noshared"); }
67       */
68    }
69  
70    public void addIncremental(final boolean incremental, final Vector<String> args) {
71      /*
72       * if (incremental) { args.addElement("-xidlon"); } else {
73       * args.addElement("-xidloff"); }
74       */
75    }
76  
77    /**
78     * Returns library path.
79     * 
80     */
81    @Override
82    public File[] getLibraryPath() {
83      if (this.libDirs == null) {
84        final File CCloc = CUtil.getExecutableLocation("aCC");
85        if (CCloc != null) {
86          final File compilerLib = new File(new File(CCloc, "../lib").getAbsolutePath());
87          if (compilerLib.exists()) {
88            this.libDirs = new File[2];
89            this.libDirs[0] = compilerLib;
90          }
91        }
92        if (this.libDirs == null) {
93          this.libDirs = new File[1];
94        }
95      }
96      this.libDirs[this.libDirs.length - 1] = new File("/usr/lib");
97      return this.libDirs;
98    }
99  
100   @Override
101   public Linker getLinker(final LinkType type) {
102     if (type.isStaticLibrary()) {
103       return arLinker;
104     }
105     if (type.isSharedLibrary()) {
106       return dllLinker;
107     }
108     return instance;
109   }
110 }