3 * Copyright 2001-2005 The Ant-Contrib project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package net
.sf
.antcontrib
.cpptasks
.compiler
;
21 import net
.sf
.antcontrib
.cpptasks
.AssemblerDef
;
22 import net
.sf
.antcontrib
.cpptasks
.CCTask
;
23 import net
.sf
.antcontrib
.cpptasks
.ProcessorDef
;
24 import net
.sf
.antcontrib
.cpptasks
.TargetDef
;
26 * An abstract assembler implementation.
29 public abstract class AbstractAssembler
extends AbstractProcessor
30 implements Assembler
{
31 private String outputSuffix
;
32 protected AbstractAssembler(String
[] sourceExtensions
,
33 String
[] headerExtensions
, String outputSuffix
) {
34 super(sourceExtensions
, headerExtensions
);
35 this.outputSuffix
= outputSuffix
;
37 abstract protected AssemblerConfiguration
createConfiguration(CCTask task
,
38 LinkType linkType
, ProcessorDef
[] baseConfigs
,
39 AssemblerDef specificConfig
, TargetDef targetPlatform
);
40 public ProcessorConfiguration
createConfiguration(CCTask task
,
41 LinkType linkType
, ProcessorDef
[] baseConfigs
,
42 ProcessorDef specificConfig
, TargetDef targetPlatform
) {
43 if (specificConfig
== null) {
44 throw new NullPointerException("specificConfig");
46 return createConfiguration(task
, linkType
, baseConfigs
,
47 (AssemblerDef
) specificConfig
, targetPlatform
);
49 public String
getOutputFileName(String inputFile
) {
50 if (bid(inputFile
) > 1) {
51 String baseName
= getBaseOutputName(inputFile
);
52 return baseName
+ outputSuffix
;
56 protected String
getBaseOutputName(String inputFile
) {
57 int lastSlash
= inputFile
.lastIndexOf('/');
58 int lastReverse
= inputFile
.lastIndexOf('\\');
59 int lastSep
= inputFile
.lastIndexOf(File
.separatorChar
);
60 if (lastReverse
> lastSlash
) {
61 lastSlash
= lastReverse
;
63 if (lastSep
> lastSlash
) {
66 int lastPeriod
= inputFile
.lastIndexOf('.');
68 lastPeriod
= inputFile
.length();
70 return inputFile
.substring(lastSlash
+ 1, lastPeriod
);