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.openwatcom;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.Vector;
25
26 import com.github.maven_nar.cpptasks.CUtil;
27 import com.github.maven_nar.cpptasks.TargetMatcher;
28 import com.github.maven_nar.cpptasks.VersionInfo;
29 import com.github.maven_nar.cpptasks.compiler.CommandLineLinker;
30 import com.github.maven_nar.cpptasks.compiler.LinkType;
31 import com.github.maven_nar.cpptasks.platforms.WindowsPlatform;
32 import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
33
34 /**
35 * Adapter for the OpenWatcom linker.
36 *
37 * @author Curt Arnold
38 */
39 public abstract class OpenWatcomLinker extends CommandLineLinker {
40 /**
41 * Constructor.
42 *
43 * @param command
44 * String command string (wcl386 or wfl386)
45 * @param outputSuffix
46 * String output suffix
47 */
48 protected OpenWatcomLinker(final String command, final String outputSuffix) {
49 super(command, "-r", new String[] {
50 ".obj", ".lib", ".res"
51 }, new String[] {
52 ".map", ".pdb", ".lnk"
53 }, outputSuffix, false, null);
54 }
55
56 /**
57 * Add specified base address to linker options.
58 *
59 * @param base
60 * long base address
61 * @param args
62 * Vector command options
63 */
64 protected final void addBase(final long base, final Vector<String> args) {
65 }
66
67 /**
68 * Adds non-default entry point.
69 *
70 * @param entry
71 * entry point name
72 * @param args
73 * command line parameters
74 */
75 protected final void addEntry(final String entry, final Vector<String> args) {
76 }
77
78 /**
79 * Adds fixed option.
80 *
81 * @param fixed
82 * if executable is fixed
83 * @param args
84 * command line parameters
85 */
86 protected final void addFixed(final Boolean fixed, final Vector<String> args) {
87 }
88
89 /**
90 * Adds other command line parameters.
91 *
92 * @param debug
93 * boolean is debug
94 * @param linkType
95 * LinkType link type
96 * @param args
97 * Vector command line arguments
98 */
99 protected final void addImpliedArgs(final boolean debug, final LinkType linkType, final Vector<String> args) {
100 if (linkType.isExecutable()) {
101 if (linkType.isSubsystemConsole()) {
102 args.addElement("/bc");
103 } else {
104 if (linkType.isSubsystemGUI()) {
105 args.addElement("/bg");
106 }
107 }
108 }
109 if (linkType.isSharedLibrary()) {
110 args.addElement("/bd");
111 }
112 }
113
114 /**
115 * Add command line switch to force incremental linking.
116 *
117 * @param incremental
118 * boolean do incremental linking
119 * @param args
120 * Vector command line arguments
121 */
122 protected final void addIncremental(final boolean incremental, final Vector<String> args) {
123 }
124
125 /**
126 * Add command line switch to force map generation.
127 *
128 * @param map
129 * boolean build map
130 * @param args
131 * Vector command line arguments
132 */
133 protected final void addMap(final boolean map, final Vector<String> args) {
134 if (map) {
135 args.addElement("/fm");
136 }
137 }
138
139 /**
140 * Add command line switch for stack reservation.
141 *
142 * @param stack
143 * int stack size.
144 * @param args
145 * Vector command line arguments.
146 */
147 protected final void addStack(final int stack, final Vector<String> args) {
148 if (stack >= 0) {
149 final String stackStr = Integer.toString(stack);
150 args.addElement("/k" + stackStr);
151 }
152 }
153
154 /**
155 * Adds source or object files to the bidded fileset to
156 * support version information.
157 *
158 * @param versionInfo
159 * version information
160 * @param linkType
161 * link type
162 * @param isDebug
163 * true if debug build
164 * @param outputFile
165 * name of generated executable
166 * @param objDir
167 * directory for generated files
168 * @param matcher
169 * bidded fileset
170 * @throws IOException
171 * if unable to write version resource
172 */
173 @Override
174 public final void addVersionFiles(final VersionInfo versionInfo, final LinkType linkType, final File outputFile,
175 final boolean isDebug, final File objDir, final TargetMatcher matcher) throws IOException {
176 WindowsPlatform.addVersionFiles(versionInfo, linkType, outputFile, isDebug, objDir, matcher);
177 }
178
179 /**
180 * Get command file switch.
181 *
182 * @param commandFile
183 * String command file name
184 * @return String command line option
185 */
186 @Override
187 public final String getCommandFileSwitch(final String commandFile) {
188 return "@" + commandFile;
189 }
190
191 /**
192 * Get search path for libraries.
193 *
194 * @return File[] library path
195 */
196 @Override
197 public final File[] getLibraryPath() {
198 return CUtil.getPathFromEnvironment("LIB", ";");
199 }
200
201 /**
202 * Get file selectors for libraries.
203 *
204 * @param libnames
205 * String[]
206 * @param libType
207 * LibraryTypeEnum
208 * @return String[]
209 */
210 @Override
211 public final String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
212 return OpenWatcomProcessor.getLibraryPatterns(libnames, libType);
213 }
214
215 /**
216 * Get maximum command line length.
217 *
218 * @return int command line length
219 */
220 @Override
221 public final int getMaximumCommandLength() {
222 return 1024;
223 }
224
225 /**
226 * Get output file switch.
227 *
228 * @param outFile
229 * Output file name
230 * @return String[] command line switches
231 */
232 @Override
233 public final String[] getOutputFileSwitch(final String outFile) {
234 return OpenWatcomProcessor.getOutputFileSwitch(outFile);
235 }
236
237 /**
238 * Gets file name sensitivity of processors.
239 *
240 * @return boolean true if case sensitive.
241 */
242 @Override
243 public final boolean isCaseSensitive() {
244 return OpenWatcomProcessor.isCaseSensitive();
245 }
246
247 }