Subversion Repositories DevTools

Rev

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