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.util.Vector;
23  
24  import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
25  
26  /**
27   * A add-in class for Sun C89 compilers and linkers
28   *
29   * @author Hiram Chirino (cojonudo14@hotmail.com)
30   */
31  public class C89Processor {
32    private static int addLibraryPatterns(final String[] libnames, final StringBuffer buf, final String prefix,
33        final String extension, final String[] patterns, final int offset) {
34      for (int i = 0; i < libnames.length; i++) {
35        buf.setLength(0);
36        buf.append(prefix);
37        buf.append(libnames[i]);
38        buf.append(extension);
39        patterns[offset + i] = buf.toString();
40      }
41      return offset + libnames.length;
42    }
43  
44    public static void addWarningSwitch(final Vector<String> args, final int level) {
45      switch (level) {
46      /*
47       * case 0: args.addElement("/W0"); break;
48       * 
49       * case 1: args.addElement("/W1"); break;
50       * 
51       * case 2: break;
52       * 
53       * case 3: args.addElement("/W3"); break;
54       * 
55       * case 4: args.addElement("/W4"); break;
56       */
57      }
58    }
59  
60    public static String getCommandFileSwitch(final String cmdFile) {
61      final StringBuffer buf = new StringBuffer("@");
62      if (cmdFile.indexOf(' ') >= 0) {
63        buf.append('\"');
64        buf.append(cmdFile);
65        buf.append('\"');
66      } else {
67        buf.append(cmdFile);
68      }
69      return buf.toString();
70    }
71  
72    public static void getDefineSwitch(final StringBuffer buf, final String define, final String value) {
73      buf.setLength(0);
74      buf.append("-D");
75      buf.append(define);
76      if (value != null && value.length() > 0) {
77        buf.append('=');
78        buf.append(value);
79      }
80    }
81  
82    public static String getIncludeDirSwitch(final String includeDir) {
83      return "-I" + includeDir;
84    }
85  
86    public static String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
87      final StringBuffer buf = new StringBuffer();
88      int patternCount = libnames.length * 2;
89      if (libType != null) {
90        patternCount = libnames.length;
91      }
92      final String[] patterns = new String[patternCount];
93      int offset = 0;
94      if (libType == null || "static".equals(libType.getValue())) {
95        offset = addLibraryPatterns(libnames, buf, "lib", ".a", patterns, 0);
96      }
97      if (libType == null || !"static".equals(libType.getValue())) {
98        offset = addLibraryPatterns(libnames, buf, "lib", ".so", patterns, offset);
99      }
100     return patterns;
101   }
102 
103   public static String[] getOutputFileSwitch(final String outPath) {
104     final StringBuffer buf = new StringBuffer("-o ");
105     if (outPath.indexOf(' ') >= 0) {
106       buf.append('\"');
107       buf.append(outPath);
108       buf.append('\"');
109     } else {
110       buf.append(outPath);
111     }
112     final String[] retval = new String[] {
113       buf.toString()
114     };
115     return retval;
116   }
117 
118   public static void getUndefineSwitch(final StringBuffer buf, final String define) {
119     buf.setLength(0);
120     buf.append("-U");
121     buf.append(define);
122   }
123 
124   public static boolean isCaseSensitive() {
125     return true;
126   }
127 
128   private C89Processor() {
129   }
130 }