Subversion Repositories DevTools

Rev

Rev 5137 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4950 dpurdie 1
###############################################################################
2
# File:     TOOLSET/AVR32_GNU.rul[e]
3
# Contents: AVR32_GNU rules
4
#
5
###############################################################################
6
 
7
###############################################################################
8
#..     Remove "undef" warnings
9
#
10
cc_includes	 +=
11
cc_defines	 +=
12
cxx_includes +=
13
cxx_defines	 +=
14
as_includes	 +=
15
as_defines	 +=
16
 
17
GCC_MACHINE	= $(shell $(GCC_CC) -dumpmachine)
18
GCC_VERSION	= $(shell $(GCC_CC) -dumpversion)
19
 
20
###############################################################################
21
#..     Toolset defaults
22
#           mkdepend is a lot faster that gcc
23
#
24
USE_GCCDEPEND	= 0
25
 
26
###############################################################################
27
#..     Parse user options
28
#       Global options already parsed
29
#       These options extend the global options
30
#
31
ifdef OPTIONS
32
 
33
ifneq "$(findstring metrics,$(OPTIONS))" ""	    # Build source metrixs
34
USE_METRICS	= 1
35
endif
36
 
37
ifneq "$(findstring profile,$(OPTIONS))" ""
38
USE_PROFILE	= 1
39
endif
40
 
41
ifneq "$(findstring ccdepend,$(OPTIONS))" ""	# Build depends using gcc
42
USE_GCCDEPEND	= 1
43
endif
44
ifneq "$(findstring gccdepend,$(OPTIONS))" ""
45
USE_GCCDEPEND	= 1
46
endif
47
ifneq "$(findstring mkdepend,$(OPTIONS))" ""
48
USE_GCCDEPEND	= 0
49
endif
50
 
51
ifneq "$(findstring wall,$(OPTIONS))" ""	    # Enable all warnings
52
USE_WALL	= 1
53
endif
54
 
55
endif	#OPTIONS
56
 
57
###############################################################################
58
#..     C and C++ Compiler warning filter
59
#
60
cc_filter_name  := warnings.avr32
61
cc_filter	:= "$(notdir $(wildcard $(GBE_ROOT)/$(cc_filter_name)))"
62
 
63
ifeq ($(strip $(cc_filter)),"$(cc_filter_name)")
64
    cc_filter      := $(GBE_ROOT)/$(cc_filter_name)
65
else
66
    cc_filter  :=
67
endif
68
 
69
ifdef cc_filter
70
cc_redirect_stderr = 1
71
cc_error_filter = $(awk) -f $(cc_filter)
72
endif
73
 
74
###############################################################################
75
#..     C Compiler definition
76
#
77
 
78
	# Standard defines
79
	#
80
	#..
81
ifdef GCC_DEFINES
82
gcc_defines	+= $(GCC_DEFINES)
83
endif
84
 
85
ifeq "$(DEBUG)" "1"
86
gcc_defines	+= -DDEBUG
87
else
88
gcc_defines	+=
89
endif
90
 
91
gcc_defines	+= -D__SOURCE__=\"$(notdir $<)\"
92
 
5137 dpurdie 93
gcc_conly_flags =
4950 dpurdie 94
#
95
#   Target specific flags
96
#
97
gcc_flags	+= -ffunction-sections
98
gcc_flags   += -masm-addr-pseudos 
99
gcc_flags   += -mno-cond-exec-before-reload 
100
gcc_flags   += -mrelax 
5137 dpurdie 101
gcc_conly_flags   += -std=gnu99 
4950 dpurdie 102
gcc_flags   += -mpart=$(AVR32_PART)
103
 
104
# Standard flags
105
#
106
#  -Wall implies:
107
#       -Wimplicit, -Wreturn-type, -Wunused, -Wswitch
108
#       -Wformat, -Wchar-subscripts, -Wparentheses
109
#       -Wmissing-braces
110
#..
111
gcc_flags	+= -c
112
gcc_flags	+= -Wall
5137 dpurdie 113
gcc_conly_flags	+= -Werror-implicit-function-declaration 
114
gcc_conly_flags	+= -Wmissing-prototypes 
4950 dpurdie 115
gcc_flags	+= -Wpointer-arith 
5137 dpurdie 116
gcc_conly_flags	+= -Wstrict-prototypes
4950 dpurdie 117
ifdef USE_WALL
118
#gcc_flags	+= -Wuninitialized		# only makes sense with `-O'
119
gcc_flags	+= -Wwrite-strings
120
gcc_flags	+= -Wcast-qual
121
gcc_flags	+= -Wbad-function-cast
122
gcc_flags	+= -Wmissing-declarations
123
gcc_flags	+= -Wnested-externs
124
gcc_flags	+= -Wtraditional
125
gcc_flags	+= -Wconversion
126
gcc_flags	+= -Wcomment
127
gcc_flags	+= -Wcast-align
128
#gcc_flags	+= -Winline
129
gcc_flags	+= -Wshadow
130
gcc_flags	+= -Wredundant-decls
131
#gcc_flags	+= -Wid-clash-31
132
endif
133
 
134
ifdef GCC_CFLAGS
135
gcc_flags	+= $(GCC_CFLAGS)
136
endif
137
 
138
ifdef FORCE_C_COMPILE
139
endif
140
 
141
ifdef FORCE_CC_COMPILE
142
endif
143
 
144
ifdef USE_OPTIMISE				# default for production
145
gcc_flags	+= -O1
146
else
147
endif
148
 
149
ifdef USE_DEBUGINFO				# default for debug
150
gcc_flags	+= -g3 -ggdb
151
else
152
gcc_flags	+= -g3 -ggdb
153
endif
154
 
155
ifeq "$(DEBUG)" "1"				# debug/prod specific
156
ifdef GCC_CFLAGSD
157
gcc_flags	+= $(GCC_CFLAGSD)
158
endif
159
else
160
ifdef GCC_CFLAGSP
161
gcc_flags	+= $(GCC_CFLAGSP)
162
endif
163
endif
164
 
165
ifdef USE_STRICT_ANSI			# default NO
166
gcc_flags	+= -ansi
167
endif
168
 
169
ifdef USE_PROFILE				# default NO
170
gcc_flags	+= -pg
171
endif
172
 
173
ifdef LEAVETMP					# default NO
174
gcc_flags	+= -save-temps
175
endif
176
 
177
ifdef WARNINGS_AS_ERRORS
178
gcc_flags	+= -Werror
179
endif
180
 
181
	# Standard includes
182
	#
183
	#..
184
gcc_includes	+=
185
 
186
ifdef GCC_INCLUDES
187
gcc_includes	+= $(GCC_INCLUDES)
188
endif
189
 
190
	# Command
191
	#
192
	#..
193
cc		    = $(CC_PRE) $(GCC_CC)
194
cc_init		=
195
cc_o_switch	= -o $@
196
cc_source	= $<
197
cc_flags	= \
198
		$(patsubst %,%,$(CFLAGS)) \
5137 dpurdie 199
		$(patsubst %,%,$(gcc_flags)$(gcc_conly_flags)) \
4950 dpurdie 200
		$(patsubst %,%,$(gcc_defines)) \
201
		$(patsubst %,-D%,$(cc_defines)) \
202
		$(patsubst %,-I %,$(INCDIRS)) \
203
		$(patsubst %,-I %,$(cc_includes)) \
204
		$(patsubst %,-I %,$(gcc_includes))
205
cc_term		=
206
 
207
define cc_pre
6177 dpurdie 208
	@echo '[$<] compiling..'
4950 dpurdie 209
endef
210
 
211
ifdef USE_METRICS
212
define cc_post
213
	$(cc) -E $(cc_flags) $(cc_source) | mcstrip | cyclo -c > $(basename $@).met
214
endef
215
else
216
define cc_post
217
endef
218
endif
219
 
220
###############################################################################
221
#..     C/C++ dependencies
222
#
223
 
224
	# Additional defines
225
	#
226
	#..
227
gcc_depend	+=
228
 
229
ifeq ($(USE_GCCDEPEND),0)
230
	# Build GCC predefs and default include paths
231
	#..
232
 
233
gcc_depend	+= -D__GNUC__=$(word 1,$(subst .,$(space),$(GCC_VERSION)))
234
gcc_depend	+= -D__GNUC_MINOR__=$(word 2,$(subst .,$(space),$(GCC_VERSION)))
235
gcc_depend	+= -D__STDC__ -D__STDC_HOSTED__
236
 
237
# Definitions set by the GCC compiler
238
# See them with the command: /opt/avr32-gnu-toolchain-linux_x86/bin/avr32-gcc -dM -E - < /dev/null | sort
239
#
240
gcc_depend	+= -D__avr32__ -D__AVR32__ -D__ELF__
241
 
242
gcc_depend	+= -Y $(GBE_AVR32_GNU)/lib/gcc/$(GCC_MACHINE)/$(GCC_VERSION)/include
243
gcc_depend	+= -Y $(GBE_AVR32_GNU)/$(GCC_MACHINE)/include
244
gcc_depend	+= -Y $(GBE_AVR32_GNU)/include
245
endif
246
 
247
ifdef GCC_DEPEND
248
gcc_depend	+= $(GCC_DEPEND)
249
endif
250
 
251
	# Command
252
	#
253
	#..
254
ifeq ($(USE_GCCDEPEND),0)
255
ccdep		= $(XX_PRE) $(GBE_BIN)/mkdepend
256
ccdep_init	=
257
ccdep_o_switch	= -f -
258
ccdep_flags	= -MM -b -We -p '$$(OBJDIR)/' -o ".$(o)"
259
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
260
else
261
ccdep		= -$(XX_PRE) $(GCC_CC)
262
ccdep_init	=
263
ccdep_o_switch	=
264
ccdep_flags	= -E -MM -MG
265
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
266
endif
267
 
268
ccdep_flags	+= \
269
		$(patsubst %,%,$(CFLAGS)) \
270
		$(patsubst %,%,$(gcc_depend)) \
271
		$(patsubst %,%,$(gcc_defines)) \
272
		$(patsubst %,-D%,$(cc_defines)) \
273
		$(patsubst %,-I %,$(INCDIRS)) \
274
		$(patsubst %,-I %,$(cc_includes))
275
 
276
ifeq ($(USE_GCCDEPEND),0)
277
ccdep_flags	+= \
278
		$(patsubst %,-Y %,$(gcc_includes))
279
endif
280
 
281
	#
282
	#   Parse the depend output:
283
	#
284
	#   s/^.*/\(.*\.${o}\:\)/$(OBJDIR)/\1/g
285
	#        replace all object rules which contain / seperated
286
	#        subdirs with a stripped prefixed object name.
287
	#
288
	#        eg. subdir/dir/object.o:        $(OBJDIR)/object.o
289
	#
290
	#   s/^\([^/].*\.${o}\:\)/$(OBJDIR)/\1/g
291
	#        prefix all object rules without subdirs.
292
	#
293
	#        eg. object.o:                   $(OBJDIR)/object.o
294
	#..
295
 
296
ccdep_pre	= 
297
 
298
ccdep_sed	= \
299
	-sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
300
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
301
		$(subst /,/,$@).tmp > $@ 2> $(OBJDIR)/depend.err;
302
ifdef SHNAMES
303
ccdep_sedsh	= \
304
	sed  -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
305
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
306
		$(subst /,/,$@).tmp >> $@ 2>> $(OBJDIR)/depend.err;
307
ccdep_sed	+= \
308
		$(foreach shname,$(SHNAMES),$(ccdep_sedsh))
309
endif
310
 
311
ifndef LEAVETMP
312
define ccdep_post
313
	@$(ccdep_sed)
314
	@rm $(subst /,/,$@).tmp
315
endef
316
else
317
define ccdep_post
318
	@$(ccdep_sed)
319
endef
320
endif
321
 
322
#..     C++ Compiler definition
323
#
324
ifdef USE_CHECKER
325
cxx		= @checkergcc
326
else
327
cxx		= $(CC_PRE) $(GCC_CC)
328
endif
329
cxx_init	=
330
cxx_o_switch	= -o $@
331
cxx_source	= $<
332
cxx_flags	= \
333
		$(patsubst %,%,$(CXXFLAGS)) \
334
		$(patsubst %,%,$(gcc_flags)) \
335
		$(patsubst %,%,$(gcc_defines)) \
336
		$(patsubst %,-d%,$(cxx_defines)) \
337
		$(patsubst %,-I %,$(INCDIRS)) \
338
		$(patsubst %,-I %,$(cxx_includes)) \
339
		$(patsubst %,-I %,$(gcc_includes))
340
 
341
define cxx_pre
6177 dpurdie 342
	@echo '[$<] compiling..'
4950 dpurdie 343
endef
344
 
345
define cxx_post
346
endef
347
 
348
###############################################################################
349
#..     Archiver definition
350
#
351
 
352
#..     Archiver
353
#
354
ar		= $(XX_PRE) $(GCC_AR)
355
ar_o_switch	=
356
ar_flags	= -scr $@ \
357
		$(patsubst %,%,$^)
358
 
359
define ar_pre
6177 dpurdie 360
	@echo '[$@] Create archive..'
4950 dpurdie 361
endef
362
 
363
define ar_post
364
endef
365
 
366
#..     Archive Merge
367
#
368
armerge		= $(XX_PRE) $(GBE_TOOLS)/armerge
369
armerge_init	=
370
armerge_flags	= -d $(MLIBDIR) -t unix -a $(GCC_AR)
371
armerge_o_switch= $@ $^
372
 
373
armerge_pre	= -$(rm) -f $@
374
armerge_post	=
375
 
376
###############################################################################
377
#..     Linker definition
378
#
379
 
380
#..     Linker
381
#
382
ld		    = $(CC_PRE) $(GCC_CC)
383
ld_init		=
384
ld_o_switch	= -o $@
385
 
386
ld_flags	+= -Xlinker -Map '$(basename $@).map'
387
 
388
ifeq "$(DEBUG)" "1"
389
ld_flags	+= -g
390
endif
391
ifdef USE_PROFILE
392
ld_flags	+= -pg
393
endif
394
 
395
ld_flags	+= \
396
		$(patsubst %,%,$(LDFLAGS)) \
397
		$(patsubst %,%,$(GCC_LDFLAGS)) \
398
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
399
		$(patsubst %,-Xlinker -rpath-link %,$(wildcard $(LIBDIRS))) \
400
		$($(notdir $(basename $@))_ld)
401
 
402
define ld_pre
6177 dpurdie 403
	@echo '[$@] Linking..'; \
4950 dpurdie 404
	$(touch) $(basename $@).map
405
endef
406
 
407
define ld_post
408
endef
409
 
410
define LDDEPEND
411
	$(AA_PRE)export GCC_LIB; \
412
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
413
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
414
endef
415
 
416
###############################################################################
417
#   ELF2BIN
418
#       $1 - Full name of the output
419
#       $2 - Full name of elf file
420
define ELF2BIN
421
    $(echo) "[$1] Elf to Binary Conversion.."
422
    $(GCC_OBJCOPY) -O binary $2 $1 || rm -f $1 $2
423
endef
424