1#!/usr/bin/env omake
2#----------------------------------------------------------------------------
3# Project: Horizon
4# File:    commondefs.cctype.RVCT.om
5#
6# Copyright 2007-2009 Nintendo. All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law. They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14# $Date:: 2011-02-10#$
15# $Rev: 34344 $
16# $Author: yasuda_kei $
17#----------------------------------------------------------------------------
18
19# If CTRSDK_RVCT_VER is not defined, set the RVCT version for which SDK operations have been verified
20if $(defined CTRSDK_RVCT_VER)
21    export
22else
23    if $(defined-env CTRSDK_RVCT_VER)
24        CTRSDK_RVCT_VER = $(getenv CTRSDK_RVCT_VER)
25        export
26    else
27        CTRSDK_RVCT_VER = 40
28        export
29    export
30
31if $(equal $(CTRSDK_RVCT_VER),40)
32    RVCT_ENV_PREFIX = RVCT40
33    export
34else
35    if $(equal $(CTRSDK_RVCT_VER),41)
36        RVCT_ENV_PREFIX = ARMCC41
37        export
38    else
39        RVCT_ENV_PREFIX = ARMCC$(CTRSDK_RVCT_VER)
40        export
41    export
42
43
44# Version of RVCT supported
45SUOPPORT_RVCT_VER[] = RVCT40  \
46                      ARMCC41
47
48# If a RVCT version for which SDK operations have been verified has been installed, it is used
49# If not installed, the most recent supported version of the RVCT installed by the user is used
50#
51if $(defined-env $(RVCT_ENV_PREFIX)BIN)
52    RVCT_BINDIR = $(getenv $"$(RVCT_ENV_PREFIX)BIN")$(DIRSEP)
53    export
54else
55    foreach(rvct_version, $(SUOPPORT_RVCT_VER))
56        if $(defined-env $(rvct_version)BIN)
57            RVCT_BINDIR     = $(getenv $"$(rvct_version)BIN")$(DIRSEP)
58            RVCT_ENV_PREFIX = $(rvct_version)
59            break()
60            export
61        RVCT_BINDIR =
62        export
63    export
64
65RVCT_DIAG_STYLE         = arm
66if $(defined-env HORIZON_RVCT_DIAG_STYLE)
67    RVCT_DIAG_STYLE     = $(getenv HORIZON_RVCT_DIAG_STYLE)
68    export
69
70CompilerRVCT. =
71    extends $(Compiler)
72    class CompilerRVCT
73
74    CC                  = $"$(RVCT_BINDIR)armcc.exe"
75    CXX                 = $"$(RVCT_BINDIR)armcc.exe"
76    CPP                 = $"$(RVCT_BINDIR)armcc.exe" -E
77    AR                  = $"$(RVCT_BINDIR)armar.exe"
78    LD                  = $"$(RVCT_BINDIR)armlink.exe"
79    AS                  = $"$(RVCT_BINDIR)armasm.exe"
80
81    STRIP               = $"$(RVCT_BINDIR)fromelf.exe" --strip debug,comment,symbols --elf
82    DISAS               = $"$(RVCT_BINDIR)fromelf.exe" --32x1 -cd
83
84    CCFLAGS_MACRO       =
85
86    #------------------------------------------------------------------------
87    # The following warnings are suppressed
88    #
89    #    186: pointless comparison of unsigned integer with zero
90    #    340: value copied to temporary, reference to temporary used
91    #    401: destructor for base class "<class name>" is not virtual
92    #   1256: "<type name>" would have been promoted to "int" when passed
93    #   1297: Header file not guarded against multiple inclusion
94    #   1568: nonstandard reinterpret_cast
95    #   1764: SWP instructions are deprecated in architecture ARMv6 and above
96    #   1786: This instruction using SP is deprecated
97    #   1788: Explicit use of PC in this instruction is deprecated
98    #   2523: use of inline assembler is deprecated
99
100    #------------------------------------------------------------------------
101    # The following comments are suppressed
102    #
103    #     96: a translation unit must contain at least one declaration
104    #   1794: Error encountered parsing expansion routine
105    #   1801: Optimization: Function expanded (xxx)
106    #   2442: Could not inline: Cannot remove function from expression
107
108    #------------------------------------------------------------------------
109    # The following warnings are handled as errors
110    #
111    #     68: integer conversion resulted in a change of sign
112    #     88: assignment in condition
113    #    174: expression has no effect
114    #    188: enumerated type mixed with another type
115    #    223: function "<foo>" declared implicitly
116    #   3017: <foo> may be used before being set
117
118    #------------------------------------------------------------------------
119    # The following comments are handled as warnings
120    #
121    #    177: variable "xxx" was declared but never referenced
122    #    193: zero used for undefined preprocessing identifier "xxx"
123    #    228: trailing comma is nonstandard
124    #    550: variable "xxx" was set but never used
125    #    826: parameter "<parameter>" was never referenced
126    #   1301: padding inserted in <struct>
127
128    CCFLAGS_WARNING     = --diag_suppress 186,340,401,1256,1297 	\
129                          --diag_suppress 1568,1764,1786,1788,2523	\
130                          --diag_suppress 96,1794,1801,2442,3017	\
131                          --diag_error 68,88,174,188,223 	    	\
132                          --diag_warning 177,193,228,550,826,1301 	\
133                          --diag_suppress=optimizations
134
135    CCFLAGS_DEV_OPT     = -O0 --retain=calls
136
137    CCFLAGS             = --multibyte_chars \
138                          --apcs /interwork \
139                          --data_reorder \
140                          --debug \
141                          --debug_info=line_inlining_extensions \
142                          --no_debug_macros \
143                          --diag_style=$(RVCT_DIAG_STYLE) \
144                          --dwarf3 \
145                          --no_exceptions \
146                          --force_new_nothrow \
147                          --fpmode=fast \
148                          --littleend \
149                          --remarks \
150                          --remove_unneeded_entities \
151                          --no_rtti \
152                          --signed_chars \
153                          --vfe \
154                          --wchar16 \
155                          $`(if $(equal $(CTRSDK_RVCT_VER), 41), -Ono_change_regsort) \
156                          $`(uniq_diag_flags $(CCFLAGS_WARNING)) \
157                          $`(if $(and $(not $(FEEDBACK_1ST_STAGE)), $(not $(FEEDBACK_2ND_STAGE))), --split_sections) \
158                          $`(if $(and $(USE_GNU_EXTENTIONS), $(not $(equal $(config.buildtype), Debug))), --gnu)
159
160
161    CFLAGS              = --c99
162    CXXFLAGS            = --cpp
163    CSCANFLAGS          = -M --no_depend_system_headers
164    # omake bugzilla #654 --ignore_missing_headers --phony_targets
165
166    #------------------------------------------------------------------------
167    # Demote the following linker warnings to suppresses:
168    #
169    #   L6314W: No section matches pattern
170    #   L6329W: Pattern * only matches removed unused sections
171
172    LDFLAGS_WARNING     = --diag_suppress L6314W,L6329W
173    ASFLAGS             = --cpreproc
174    ARFLAGS             = -rcuT
175    RANLIB              = echo ranlib
176    INCLUDES_OPT        = -I
177    YACC                = echo yacc
178    LEX                 = echo lex
179
180    # Option to generate .map files or call graph files
181    # These are unnecessary when generating a feedback file
182    LDFLAGS_INFO        = $`(if $(and $(defined MAPFILE), $(MAPFILE)),\
183                             --list=$(MAPFILE) \
184                             --verbose --map --callgraph --callgraph_output=text --symbols --xref --unmangled \
185                             $"--info=architecture,exceptions,inline,inputs,libraries,merge,sizes,stack,summarysizes,summarystack,tailreorder,totals,unused,unusedsymbols,veneerpools,veneers,veneercallers,visibility")
186
187    LDFLAGS             = $`(if $(FEEDBACK_1ST_STAGE),\
188                             --feedback=$@.tmp --feedback_image=none, \
189                             $(LDFLAGS_INFO)) \
190                          --datacompressor off \
191                          --debug \
192                          --no_eager_load_debug \
193                          --entry=$`(ENTRYPOINT) \
194                          --no_exceptions \
195                          --exceptions_tables=nocreate \
196                          --keep=nnMain \
197                          --largeregions \
198                          --merge \
199                          --pad 0xFF \
200                          --remove \
201                          --scanlib \
202                          $`(if $(not $(EXCLUSION_SCATTER)), --scatter $`(LDSCRIPT)) \
203                          --startup=$`(ENTRYPOINT) \
204                          --strict \
205                          --userlibpath=$`(LIBDIR) \
206                          --vfemode=force \
207                          --diag_style=$(RVCT_DIAG_STYLE) \
208                          $`(LDFLAGS_WARNING)
209
210    LDRESP              = --via
211    CCOUT               = -o
212    LDOUT               = -o
213    ASOUT               = -o
214
215    new() =
216        return $(this)
217
218    getLDFlagsDebug(config) =
219        switch($(config.buildtype))
220        case $"Debug"
221            return --bestdebug
222        case $"Development"
223            return --bestdebug
224        case $"Release"
225            return --no_bestdebug --inline --tailreorder
226        return
227
228    getCCFlagsCPU(config) =
229        flags =
230            switch($(config.processor))
231            case MPCore
232                value --cpu MPCore
233            case ARM946ES
234                value --cpu ARM946E-S
235            case ARM7TDMI
236                value --cpu ARM7TDMI
237
238        switch($(config.effort))
239        case fast
240            return $(flags) --arm
241        case small
242            return $(flags) --thumb
243
244    getASFlagsCPU(config) =
245        flags =
246            switch($(config.processor))
247            case MPCore
248                value --cpu MPCore
249            case ARM946ES
250                value --cpu ARM946E-S
251            case ARM7TDMI
252                value --cpu ARM7TDMI
253
254        return $(flags) --arm
255
256    getCCFlagsLtcg(config) =
257        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
258            return $(EMPTY)  #--ltcg
259        else
260            return $(EMPTY)
261
262    getLDFlagsLtcg(config) =
263        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
264            return $(EMPTY)  #--ltcg
265        else
266            return $(EMPTY)
267
268    getMacroFlags(config) =
269        flags = -DNN_COMPILER_RVCT -DNN_COMPILER_RVCT_VERSION_MAJOR=4 -DNN_COMPILER_RVCT_VERSION_MINOR=0
270        flags += $(config.getMacroFlags)
271        flags += $(Compiler::getMacroFlags $(config))
272
273        switch($(config.effort))
274        case fast
275            flags += -DNN_COMPILER_OPTION_ARM
276            export
277
278        return $(flags)
279
280uniq_diag_flags(flags) =
281    #println($'input: '"$(flags)")
282    flags = $(gsub $(flags), $' +', $' ')
283    numbers_map = $(Map)
284    lex($(open-in-string $(flags)))
285    default
286        # empty
287    case $'\(A?[[:digit:]]+W?\)' g
288        if $(numbers_map.mem $0)
289            count = $(add $(numbers_map.find $0), 1)
290            export
291        else
292            count = 1
293            export
294        numbers_map = $(numbers_map.add $0, $(count))
295        export
296
297    outstr =
298    lex($(open-in-string $(flags)))
299    case $'\(A?[[:digit:]]+W?\)\(,| |$\)' g
300        count = $(numbers_map.find $1)
301        if $(gt $(count), 1)
302            if $(equal $2,$" ")
303                outstr += $2
304                export
305            #println("deleted $1")
306            export
307        else
308            outstr += $(0)
309            #println("skipped $1")
310            export
311        numbers_map = $(numbers_map.add $1, $(sub $(count), 1))
312        export
313    default
314        outstr += $0
315        export
316
317    flags_tmp = $(split $' ', $(concat $(EMPTY), $(outstr)))
318    flags =
319    foreach(flag, $(flags_tmp))
320        flags += $(flag)
321        export
322    #println("$(flags)")
323    flags = $(gsub $(flags), $', ', $' ')
324    #flags = $(gsub $(flags)$"  ", $'--diag_(suppress|error|warning)  +', $(EMPTY))
325    # If there is an empty option such as '--diag_warning   --diag_suppress', an error occurs, so it is removed
326    #
327    flags = $(gsub $(flags), $'(--diag_(suppress|error|warning)[[:space:]]*)+--', $'--')
328    flags = $(gsub $(flags), $'--diag_(suppress|error|warning)[[:space:]]*$', $(EMPTY))
329    #println($'output: '"$(flags)")
330    return $(flags)
331
332