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:: 2010-09-16#$
15# $Rev: 25944 $
16# $Author: hatamoto_minoru $
17#----------------------------------------------------------------------------
18
19# CTRSDK_RVCT_VER ����`����Ă��Ȃ���΁ASDK �̓��쌟�؍� RVCT version ��ݒ�
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# �Ή����Ă��� RVCT �� version
45SUOPPORT_RVCT_VER[] = RVCT40  \
46                      ARMCC41
47
48# SDK �̓��쌟�؍� RVCT version ���C���X�g�[������Ă���΂�����g�p
49# �C���X�g�[������Ă��Ȃ���΁A�Ή����Ă��� RVCT �� version �̒�����
50# ���[�U���C���X�g�[�����Ă��� RVCT �̒�����ŐV�̃o�[�W�������g�p����
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    # �ȉ��̌x����}��
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    # �ȉ��̒��߂�}��
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    # �ȉ��̌x�����G���[�Ƃ��Ĉ���
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    # �ȉ��̒��߂��x���Ƃ��Ĉ���
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                          $`(uniq_diag_flags $(CCFLAGS_WARNING)) \
156                          $`(if $(and $(not $(FEEDBACK_1ST_STAGE)), $(not $(FEEDBACK_2ND_STAGE))), --split_sections) \
157                          $`(if $(and $(USE_GNU_EXTENTIONS), $(not $(equal $(config.buildtype), Debug))), --gnu)
158
159
160    CFLAGS              = --c99
161    CXXFLAGS            = --cpp
162    CSCANFLAGS          = -M --no_depend_system_headers
163    # omake bugzilla #654 --ignore_missing_headers --phony_targets
164
165    #------------------------------------------------------------------------
166    # Demote the following linker warnings to suppresses:
167    #
168    #   L6314W: No section matches pattern
169    #   L6329W: Pattern * only matches removed unused sections
170
171    LDFLAGS_WARNING     = --diag_suppress L6314W,L6329W
172    ASFLAGS             = --cpreproc
173    ARFLAGS             = -rcuT
174    RANLIB              = echo ranlib
175    INCLUDES_OPT        = -I
176    YACC                = echo yacc
177    LEX                 = echo lex
178
179    # .map �t�@�C����R�[���O���t�t�@�C���������邽�߂̃I�v�V����
180    # �t�B�[�h�o�b�N�t�@�C���������ɂ͂����͕s�v
181    LDFLAGS_INFO        = $`(if $(and $(defined MAPFILE), $(MAPFILE)),\
182                             --list=$(MAPFILE) \
183                             --verbose --map --callgraph --callgraph_output=text --symbols --xref --unmangled \
184                             $"--info=architecture,exceptions,inline,inputs,libraries,merge,sizes,stack,summarysizes,summarystack,tailreorder,totals,unused,unusedsymbols,veneerpools,veneers,veneercallers,visibility")
185
186    LDFLAGS             = $`(if $(FEEDBACK_1ST_STAGE),\
187                             --feedback=$@.tmp --feedback_image=none, \
188                             $(LDFLAGS_INFO)) \
189                          --datacompressor off \
190                          --debug \
191                          --no_eager_load_debug \
192                          --entry=$`(ENTRYPOINT) \
193                          --no_exceptions \
194                          --exceptions_tables=nocreate \
195                          --largeregions \
196                          --merge \
197                          --pad 0xFF \
198                          --remove \
199                          --scanlib \
200                          $`(if $(not $(EXCLUSION_SCATTER)), --scatter $`(LDSCRIPT)) \
201                          --startup=$`(ENTRYPOINT) \
202                          --strict \
203                          --userlibpath=$`(LIBDIR) \
204                          --vfemode=force \
205                          --diag_style=$(RVCT_DIAG_STYLE) \
206                          $`(LDFLAGS_WARNING)
207
208    LDRESP              = --via
209    CCOUT               = -o
210    LDOUT               = -o
211    ASOUT               = -o
212
213    new() =
214        return $(this)
215
216    getLDFlagsDebug(config) =
217        switch($(config.buildtype))
218        case $"Debug"
219            return --bestdebug
220        case $"Development"
221            return --bestdebug
222        case $"Release"
223            return --no_bestdebug --inline --tailreorder
224        return
225
226    getCCFlagsCPU(config) =
227        flags =
228            switch($(config.processor))
229            case MPCore
230                value --cpu MPCore
231            case ARM946ES
232                value --cpu ARM946E-S
233            case ARM7TDMI
234                value --cpu ARM7TDMI
235
236        switch($(config.effort))
237        case fast
238            return $(flags) --arm
239        case small
240            return $(flags) --thumb
241
242    getASFlagsCPU(config) =
243        flags =
244            switch($(config.processor))
245            case MPCore
246                value --cpu MPCore
247            case ARM946ES
248                value --cpu ARM946E-S
249            case ARM7TDMI
250                value --cpu ARM7TDMI
251
252        return $(flags) --arm
253
254    getCCFlagsLtcg(config) =
255        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
256            return $(EMPTY)  #--ltcg
257        else
258            return $(EMPTY)
259
260    getLDFlagsLtcg(config) =
261        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
262            return $(EMPTY)  #--ltcg
263        else
264            return $(EMPTY)
265
266    getMacroFlags(config) =
267        flags = -DNN_COMPILER_RVCT -DNN_COMPILER_RVCT_VERSION_MAJOR=4 -DNN_COMPILER_RVCT_VERSION_MINOR=0
268        flags += $(config.getMacroFlags)
269        flags += $(Compiler::getMacroFlags $(config))
270
271        switch($(config.effort))
272        case fast
273            flags += -DNN_COMPILER_OPTION_ARM
274            export
275
276        return $(flags)
277
278uniq_diag_flags(flags) =
279    #println($'input: '"$(flags)")
280    flags = $(gsub $(flags), $' +', $' ')
281    numbers_map = $(Map)
282    lex($(open-in-string $(flags)))
283    default
284        # empty
285    case $'\(A?[[:digit:]]+W?\)' g
286        if $(numbers_map.mem $0)
287            count = $(add $(numbers_map.find $0), 1)
288            export
289        else
290            count = 1
291            export
292        numbers_map = $(numbers_map.add $0, $(count))
293        export
294
295    outstr =
296    lex($(open-in-string $(flags)))
297    case $'\(A?[[:digit:]]+W?\)\(,| |$\)' g
298        count = $(numbers_map.find $1)
299        if $(gt $(count), 1)
300            if $(equal $2,$" ")
301                outstr += $2
302                export
303            #println("deleted $1")
304            export
305        else
306            outstr += $(0)
307            #println("skipped $1")
308            export
309        numbers_map = $(numbers_map.add $1, $(sub $(count), 1))
310        export
311    default
312        outstr += $0
313        export
314
315    flags_tmp = $(split $' ', $(concat $(EMPTY), $(outstr)))
316    flags =
317    foreach(flag, $(flags_tmp))
318        flags += $(flag)
319        export
320    #println("$(flags)")
321    flags = $(gsub $(flags), $', ', $' ')
322    #flags = $(gsub $(flags)$"  ", $'--diag_(suppress|error|warning)  +', $(EMPTY))
323    # '--diag_warning   --diag_suppress'�Ƃ������ɋ�̃I�v�V�����������
324    # �G���[�ɂȂ�̂ŏ�������B
325    flags = $(gsub $(flags), $'(--diag_(suppress|error|warning)[[:space:]]*)+--', $'--')
326    flags = $(gsub $(flags), $'--diag_(suppress|error|warning)[[:space:]]*$', $(EMPTY))
327    #println($'output: '"$(flags)")
328    return $(flags)
329
330