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.CCTask;
26  import com.github.maven_nar.cpptasks.CUtil;
27  import com.github.maven_nar.cpptasks.VersionInfo;
28  import com.github.maven_nar.cpptasks.compiler.CommandLineLinker;
29  import com.github.maven_nar.cpptasks.compiler.LinkType;
30  import com.github.maven_nar.cpptasks.compiler.Linker;
31  import com.github.maven_nar.cpptasks.types.LibrarySet;
32  import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
33  
34  /**
35   * Adapter for the Sun C89 Linker
36   *
37   * @author Hiram Chirino (cojonudo14@hotmail.com)
38   */
39  public final class C89Linker extends CommandLineLinker {
40    private static final C89Linker dllLinker = new C89Linker("lib", ".so");
41    private static final C89Linker instance = new C89Linker("", "");
42  
43    public static C89Linker getInstance() {
44      return instance;
45    }
46  
47    private final String outputPrefix;
48  
49    private C89Linker(final String outputPrefix, final String outputSuffix) {
50      super("ld", "/bogus", new String[] {
51          ".o", ".a", ".lib", ".x"
52      }, new String[] {}, outputSuffix, false, null);
53      this.outputPrefix = outputPrefix;
54    }
55  
56    protected void addBase(final long base, final Vector<String> args) {
57    }
58  
59    protected void addEntry(final String entry, final Vector<String> args) {
60    }
61  
62    protected void addFixed(final Boolean fixed, final Vector<String> args) {
63    }
64  
65    protected void addImpliedArgs(final boolean debug, final LinkType linkType, final Vector<String> args) {
66      if (linkType.isSharedLibrary()) {
67        args.addElement("-G");
68      }
69    }
70  
71    protected void addIncremental(final boolean incremental, final Vector<String> args) {
72    }
73  
74    @Override
75    public String[] addLibrarySets(final CCTask task, final LibrarySet[] libsets, final Vector<String> preargs,
76        final Vector<String> midargs, final Vector<String> endargs) {
77      super.addLibrarySets(task, libsets, preargs, midargs, endargs);
78      final StringBuffer buf = new StringBuffer("-l");
79      for (final LibrarySet set : libsets) {
80        final File libdir = set.getDir(null);
81        final String[] libs = set.getLibs();
82        if (libdir != null) {
83          endargs.addElement("-L");
84          endargs.addElement(libdir.getAbsolutePath());
85        }
86        for (final String lib : libs) {
87          //
88          // reset the buffer to just "-l"
89          //
90          buf.setLength(2);
91          //
92          // add the library name
93          buf.append(lib);
94          //
95          // add the argument to the list
96          endargs.addElement(buf.toString());
97        }
98      }
99      return null;
100   }
101 
102   protected void addMap(final boolean map, final Vector<String> args) {
103   }
104 
105   protected void addStack(final int stack, final Vector<String> args) {
106   }
107 
108   @Override
109   public String getCommandFileSwitch(final String commandFile) {
110     return "@" + commandFile;
111   }
112 
113   @Override
114   public File[] getLibraryPath() {
115     return CUtil.getPathFromEnvironment("LIB", ";");
116   }
117 
118   @Override
119   public String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
120     return C89Processor.getLibraryPatterns(libnames, libType);
121   }
122 
123   @Override
124   public Linker getLinker(final LinkType linkType) {
125     if (linkType.isSharedLibrary()) {
126       return dllLinker;
127     }
128     /*
129      * if(linkType.isStaticLibrary()) { return
130      * OS390Librarian.getInstance(); }
131      */
132     return instance;
133   }
134 
135   @Override
136   public int getMaximumCommandLength() {
137     return Integer.MAX_VALUE;
138   }
139 
140   @Override
141   public String[] getOutputFileNames(final String baseName, final VersionInfo versionInfo) {
142     final String[] baseNames = super.getOutputFileNames(baseName, versionInfo);
143     if (this.outputPrefix.length() > 0) {
144       for (int i = 0; i < baseNames.length; i++) {
145         baseNames[i] = this.outputPrefix + baseNames[i];
146       }
147     }
148     return baseNames;
149   }
150 
151   @Override
152   public String[] getOutputFileSwitch(final String outputFile) {
153     return new String[] {
154         "-o", outputFile
155     };
156   }
157 
158   @Override
159   public boolean isCaseSensitive() {
160     return C89Processor.isCaseSensitive();
161   }
162 }