1/****************************************************************************
2**
3** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
4** Contact: http://www.qt.io/licensing
5**
6** This file is part of Qbs.
7**
8** Commercial License Usage
9** Licensees holding valid commercial Qt licenses may use this file in
10** accordance with the commercial license agreement provided with the
11** Software or, alternatively, in accordance with the terms contained in
12** a written agreement between you and The Qt Company. For licensing terms and
13** conditions see http://www.qt.io/terms-conditions. For further information
14** use the contact form at http://www.qt.io/contact-us.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 or version 3 as published by the Free
19** Software Foundation and appearing in the file LICENSE.LGPLv21 and
20** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
21** following information to ensure the GNU Lesser General Public License
22** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
23** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, The Qt Company gives you certain additional
26** rights.  These rights are described in The Qt Company LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29****************************************************************************/
30
31import qbs.File
32import qbs.FileInfo
33import qbs.Probes
34import "cpp.js" as Cpp
35import "sdcc.js" as SDCC
36
37CppModule {
38    condition: qbs.toolchain && qbs.toolchain.contains("sdcc")
39
40    Probes.BinaryProbe {
41        id: compilerPathProbe
42        condition: !toolchainInstallPath && !_skipAllChecks
43        names: ["sdcc"]
44    }
45
46    Probes.SdccProbe {
47        id: sdccProbe
48        condition: !_skipAllChecks
49        compilerFilePath: compilerPath
50        enableDefinesByLanguage: enableCompilerDefinesByLanguage
51        preferredArchitecture: qbs.architecture
52    }
53
54    qbs.architecture: sdccProbe.found ? sdccProbe.architecture : original
55    qbs.targetPlatform: "none"
56
57    compilerVersionMajor: sdccProbe.versionMajor
58    compilerVersionMinor: sdccProbe.versionMinor
59    compilerVersionPatch: sdccProbe.versionPatch
60    endianness: sdccProbe.endianness
61
62    compilerDefinesByLanguage: sdccProbe.compilerDefinesByLanguage
63    compilerIncludePaths: sdccProbe.includePaths
64
65    toolchainInstallPath: compilerPathProbe.found ? compilerPathProbe.path : undefined
66
67    /* Work-around for QtCreator which expects these properties to exist. */
68    property string cCompilerName: compilerName
69    property string cxxCompilerName: compilerName
70
71    property string linkerMode: "automatic"
72
73    compilerName: "sdcc" + compilerExtension
74    compilerPath: FileInfo.joinPaths(toolchainInstallPath, compilerName)
75
76    assemblerName: toolchainDetails.assemblerName + compilerExtension
77    assemblerPath: FileInfo.joinPaths(toolchainInstallPath, assemblerName)
78
79    linkerName: toolchainDetails.linkerName + compilerExtension
80    linkerPath: FileInfo.joinPaths(toolchainInstallPath, linkerName)
81
82    property string archiverName: "sdar" + compilerExtension
83    property string archiverPath: FileInfo.joinPaths(toolchainInstallPath, archiverName)
84
85    runtimeLibrary: "static"
86
87    staticLibrarySuffix: ".lib"
88    executableSuffix: ".ihx"
89    objectSuffix: ".rel"
90
91    imageFormat: "ihx"
92
93    enableExceptions: false
94    enableRtti: false
95
96    defineFlag: "-D"
97    includeFlag: "-I"
98    systemIncludeFlag: "-isystem"
99    preincludeFlag: "-include"
100    libraryDependencyFlag: "-l"
101    libraryPathFlag: "-L"
102    linkerScriptFlag: "-f"
103
104    toolchainDetails: SDCC.toolchainDetails(qbs)
105
106    knownArchitectures: ["hcs8", "mcs51", "stm8"]
107
108    Rule {
109        id: assembler
110        inputs: ["asm"]
111        outputFileTags: SDCC.extraCompilerOutputTags().concat(
112                            Cpp.assemblerOutputTags(generateAssemblerListingFiles))
113        outputArtifacts: SDCC.extraCompilerOutputArtifacts(input).concat(
114                             Cpp.assemblerOutputArtifacts(input))
115        prepare: SDCC.prepareAssembler.apply(SDCC, arguments)
116    }
117
118    FileTagger {
119        patterns: ["*.s", "*.a51", "*.asm"]
120        fileTags: ["asm"]
121    }
122
123    Rule {
124        id: compiler
125        inputs: ["cpp", "c"]
126        auxiliaryInputs: ["hpp"]
127        outputFileTags: SDCC.extraCompilerOutputTags().concat(
128                            Cpp.compilerOutputTags(generateCompilerListingFiles))
129        outputArtifacts: SDCC.extraCompilerOutputArtifacts(input).concat(
130                             Cpp.compilerOutputArtifacts(input))
131        prepare: SDCC.prepareCompiler.apply(SDCC, arguments)
132    }
133
134    Rule {
135        id: applicationLinker
136        multiplex: true
137        inputs: ["obj", "linkerscript"]
138        inputsFromDependencies: ["staticlibrary"]
139        outputFileTags: SDCC.extraApplicationLinkerOutputTags().concat(
140                            Cpp.applicationLinkerOutputTags(generateLinkerMapFile))
141        outputArtifacts: SDCC.extraApplicationLinkerOutputArtifacts(product).concat(
142                             Cpp.applicationLinkerOutputArtifacts(product))
143        prepare: SDCC.prepareLinker.apply(SDCC, arguments)
144    }
145
146    Rule {
147        id: staticLibraryLinker
148        multiplex: true
149        inputs: ["obj"]
150        inputsFromDependencies: ["staticlibrary"]
151        outputFileTags: Cpp.staticLibraryLinkerOutputTags()
152        outputArtifacts: Cpp.staticLibraryLinkerOutputArtifacts(product)
153        prepare: SDCC.prepareArchiver.apply(SDCC, arguments)
154    }
155}
156