Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
###############################################################################
2
# File:     TOOLSET/gcc.rul[e]
3
# Contents: GCC 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
 
18
###############################################################################
19
#..     Toolset defaults
383 dpurdie 20
#           mkdepend is a lot faster that gcc
227 dpurdie 21
#
383 dpurdie 22
USE_GCCDEPEND	= 0
227 dpurdie 23
 
24
###############################################################################
25
#..     Parse user options
26
#       Global options already parsed
27
#       These options extend the global options
28
#
29
ifdef OPTIONS
30
 
31
ifneq "$(findstring purify,$(OPTIONS))" ""	# Enable purify
32
CC_PRE		+= purify
33
else
34
ifneq "$(findstring purecov,$(OPTIONS))" ""	# Enable pure coverage
35
CC_PRE		+= purecov
36
endif
37
endif
38
 
39
ifneq "$(findstring metrics,$(OPTIONS))" ""	# Build source metrixs
40
USE_METRICS	= 1
41
endif
42
 
43
ifneq "$(findstring checker,$(OPTIONS))" ""
44
USE_CHECKER	= 1
45
endif
46
 
47
ifneq "$(findstring profile,$(OPTIONS))" ""
48
USE_PROFILE	= 1
49
endif
50
 
51
ifneq "$(findstring ccdepend,$(OPTIONS))" ""	# Build depends using gcc
52
USE_GCCDEPEND	= 1
53
endif
54
ifneq "$(findstring gccdepend,$(OPTIONS))" ""
55
USE_GCCDEPEND	= 1
56
endif
57
ifneq "$(findstring mkdepend,$(OPTIONS))" ""
58
USE_GCCDEPEND	= 0
59
endif
60
 
61
ifneq "$(findstring wall,$(OPTIONS))" ""	# Enable all warnings
62
USE_WALL	= 1
63
endif
64
 
65
endif	#OPTIONS
66
 
67
###############################################################################
377 dpurdie 68
#..     C and C++ Compiler warning filter
69
#
70
cc_filter_name  := warnings.gcc
71
cc_filter	:= "$(notdir $(wildcard $(GBE_ROOT)/$(cc_filter_name)))"
72
 
73
ifeq ($(strip $(cc_filter)),"$(cc_filter_name)")
74
    cc_filter      := $(GBE_ROOT)/$(cc_filter_name)
75
else
76
    cc_filter  :=
77
endif
78
 
79
ifdef cc_filter
80
cc_redirect_stderr = 1
81
cc_error_filter = $(awk) -f $(cc_filter)
82
endif
83
 
84
###############################################################################
227 dpurdie 85
#..     C Compiler definition
86
#
87
 
88
	# Standard defines
89
	#
90
	#..
91
ifdef GCC_DEFINES
92
gcc_defines	+= $(GCC_DEFINES)
93
endif
94
 
95
gcc_defines	+= -D_REENTRANT
96
 
97
ifeq "$(DEBUG)" "1"
373 dpurdie 98
gcc_defines	+= -DDEBUG
227 dpurdie 99
else
100
gcc_defines	+=
101
endif
102
 
103
ifdef ALVL
104
gcc_defines	+= -DALVL=$(ALVL)
105
endif
106
 
107
ifdef DLVL
108
gcc_defines	+= -DDLVL=$(DLVL)
109
endif
110
 
111
gcc_defines	+= -D__SOURCE__=\"$(notdir $<)\"
112
 
113
	# Standard flags
114
	#
115
	#  -Wall implies:
116
	#       -Wimplicit, -Wreturn-type, -Wunused, -Wswitch
117
	#       -Wformat, -Wchar-subscripts, -Wparentheses
118
	#       -Wmissing-braces
119
	#..
120
gcc_flags	+= -c
121
gcc_flags	+= -Wall
122
ifdef USE_WALL
123
#gcc_flags	+= -Wuninitialized		# only makes sense with `-O'
124
gcc_flags	+= -Wwrite-strings
125
gcc_flags	+= -Wcast-qual
126
gcc_flags	+= -Wbad-function-cast
127
gcc_flags	+= -Wpointer-arith
128
gcc_flags	+= -Wstrict-prototypes
129
gcc_flags	+= -Wmissing-prototypes
130
gcc_flags	+= -Wmissing-declarations
131
gcc_flags	+= -Wnested-externs
132
gcc_flags	+= -Wtraditional
133
gcc_flags	+= -Wconversion
134
gcc_flags	+= -Wcomment
135
gcc_flags	+= -Wcast-align
136
#gcc_flags	+= -Winline
137
gcc_flags	+= -Wshadow
138
gcc_flags	+= -Wredundant-decls
4309 dpurdie 139
#gcc_flags	+= -Wid-clash-31
227 dpurdie 140
endif
141
 
142
ifdef GCC_CFLAGS
143
gcc_flags	+= $(GCC_CFLAGS)
144
endif
145
 
146
ifdef FORCE_C_COMPILE
147
endif
148
 
149
ifdef FORCE_CC_COMPILE
150
endif
151
 
152
ifdef USE_OPTIMISE				# default for production
153
else
154
endif
155
 
156
ifdef USE_DEBUGINFO				# default for debug
373 dpurdie 157
gcc_flags	+= -g3 -ggdb
227 dpurdie 158
else
373 dpurdie 159
gcc_flags	+= -g3 -ggdb
227 dpurdie 160
endif
161
 
162
ifeq "$(DEBUG)" "1"				# debug/prod specific
163
ifdef GCC_CFLAGSD
4034 dpurdie 164
gcc_flags	+= $(GCC_CFLAGSD)
227 dpurdie 165
endif
166
else
167
ifdef GCC_CFLAGSP
4034 dpurdie 168
gcc_flags	+= $(GCC_CFLAGSP)
227 dpurdie 169
endif
170
endif
171
 
172
ifdef USE_STRICT_ANSI				# default NO
173
gcc_flags	+= -ansi
174
endif
175
 
176
ifdef USE_PROFILE				# default NO
177
gcc_flags	+= -pg
178
endif
179
 
180
ifdef LEAVETMP					# default NO
181
gcc_flags	+= -save-temps
182
endif
183
 
184
SHCFLAGS	+= -fpic
185
SHCXXFLAGS	+= -fpic
186
 
187
	# Standard includes
188
	#
189
	#..
190
gcc_includes	+=
191
 
192
ifdef GCC_INCLUDES
193
gcc_includes	+= $(GCC_INCLUDES)
194
endif
195
 
196
	# Command
197
	#
198
	#..
199
ifdef USE_CHECKER
200
cc		= @checkergcc
201
else
202
cc		= $(CC_PRE) $(GCC_CC)
203
endif
204
cc_init		=
205
cc_o_switch	= -o $@
206
cc_source	= $<
207
cc_flags	= \
208
		$(patsubst %,%,$(CFLAGS)) \
209
		$(patsubst %,%,$(gcc_flags)) \
210
		$(patsubst %,%,$(gcc_defines)) \
211
		$(patsubst %,-D%,$(cc_defines)) \
212
		$(patsubst %,-I %,$(INCDIRS)) \
213
		$(patsubst %,-I %,$(cc_includes)) \
214
		$(patsubst %,-I %,$(gcc_includes))
215
cc_term		=
216
 
217
define cc_pre
218
	@echo [$<] compiling..
219
endef
220
 
221
ifdef USE_METRICS
222
define cc_post
223
	$(cc) -E $(cc_flags) $(cc_source) | mcstrip | cyclo -c > $(basename $@).met
224
endef
225
else
226
define cc_post
227
endef
228
endif
229
 
230
###############################################################################
231
#..     C/C++ dependencies
232
#
233
 
234
	# Additional defines
235
	#
236
	#..
237
gcc_depend	+=
238
 
239
ifeq ($(USE_GCCDEPEND),0)
240
	# Build GCC predefs and default include paths
241
	#..
242
GCC_MACHINE	=$(shell $(GCC_CC) -dumpmachine)
243
GCC_VERSION	=$(shell $(GCC_CC) -dumpversion)
244
 
245
gcc_depend	+= -D__GNUC__=$(word 1,$(subst .,$(space),$(GCC_VERSION)))
246
gcc_depend	+= -D__GNUC_MINOR__=$(word 2,$(subst .,$(space),$(GCC_VERSION)))
247
gcc_depend	+= -D__STDC__ -D__STDC_HOSTED__
248
 
249
ifdef GCC_TARGET
250
ifneq "$(findstring Linux,$(GCC_TARGET))" ""
251
gcc_depend	+= -Dunix -D__unix -D__unix__
252
gcc_depend	+= -Dlinux -D__linux -D__linux__
253
endif
254
ifneq "$(findstring i386,$(GCC_TARGET))" ""
255
gcc_depend	+= -Di386 -D__i386 -D__i386__
256
endif
257
ifneq "$(findstring armv4,$(GCC_TARGET))" ""
258
gcc_depend	+= -Darm -D__arm -D__arm__
259
gcc_depend	+= -D__ARM_ARCH__=4
260
endif
261
ifneq "$(findstring armv9,$(GCC_TARGET))" ""
262
gcc_depend	+= -Darm -D__arm -D__arm__
263
gcc_depend	+= -D__ARM_ARCH__=9
264
endif
265
 
266
endif
267
 
268
gcc_depend	+= -Y $(GCC_ROOT)/lib/gcc-lib/$(GCC_MACHINE)/$(GCC_VERSION)/include
269
gcc_depend	+= -Y $(GCC_ROOT)/include
270
endif
271
 
272
ifdef GCC_DEPEND
273
gcc_depend	+= $(GCC_DEPEND)
274
endif
275
 
276
	# Command
277
	#
278
	#..
279
ifeq ($(USE_GCCDEPEND),0)
367 dpurdie 280
ccdep		= $(XX_PRE) $(GBE_BIN)/mkdepend
227 dpurdie 281
ccdep_init	=
282
ccdep_o_switch	= -f -
283
ccdep_flags	= -MM -b -We -p '$$(OBJDIR)/' -o ".$(o)"
4538 dpurdie 284
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
227 dpurdie 285
else
286
ccdep		= -$(XX_PRE) $(GCC_CC)
287
ccdep_init	=
288
ccdep_o_switch	=
289
ccdep_flags	= -E -MM -MG
290
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
291
endif
292
 
293
ccdep_flags	+= \
294
		$(patsubst %,%,$(CFLAGS)) \
295
		$(patsubst %,%,$(gcc_depend)) \
296
		$(patsubst %,%,$(gcc_defines)) \
297
		$(patsubst %,-D%,$(cc_defines)) \
298
		$(patsubst %,-I %,$(INCDIRS)) \
299
		$(patsubst %,-I %,$(cc_includes))
300
 
301
ifeq ($(USE_GCCDEPEND),0)
302
ccdep_flags	+= \
303
		$(patsubst %,-Y %,$(gcc_includes))
304
endif
305
 
306
	#
307
	#   Parse the depend output:
308
	#
309
	#   s/^.*/\(.*\.${o}\:\)/$(OBJDIR)/\1/g
310
	#        replace all object rules which contain / seperated
311
	#        subdirs with a stripped prefixed object name.
312
	#
313
	#        eg. subdir/dir/object.o:        $(OBJDIR)/object.o
314
	#
315
	#   s/^\([^/].*\.${o}\:\)/$(OBJDIR)/\1/g
316
	#        prefix all object rules without subdirs.
317
	#
318
	#        eg. object.o:                   $(OBJDIR)/object.o
319
	#..
320
 
321
ccdep_pre	=
322
 
323
ccdep_sed	= \
324
	-sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
325
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
326
		$(subst /,/,$@).tmp > $@ 2> $(OBJDIR)/depend.err;
327
ifdef SHNAMES
328
ccdep_sedsh	= \
329
	sed  -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
330
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
331
		$(subst /,/,$@).tmp >> $@ 2>> $(OBJDIR)/depend.err;
332
ccdep_sed	+= \
333
		$(foreach shname,$(SHNAMES),$(ccdep_sedsh))
334
endif
335
 
336
ifndef LEAVETMP
337
define ccdep_post
338
	@$(ccdep_sed)
339
	@rm $(subst /,/,$@).tmp
340
endef
341
else
342
define ccdep_post
343
	@$(ccdep_sed)
344
endef
345
endif
346
 
347
#..     C++ Compiler definition
348
#
349
ifdef USE_CHECKER
350
cxx		= @checkergcc
351
else
352
cxx		= $(CC_PRE) $(GCC_CC)
353
endif
354
cxx_init	=
355
cxx_o_switch	= -o $@
356
cxx_source	= $<
357
cxx_flags	= \
358
		$(patsubst %,%,$(CXXFLAGS)) \
359
		$(patsubst %,%,$(gcc_flags)) \
360
		$(patsubst %,%,$(gcc_defines)) \
361
		$(patsubst %,-d%,$(cxx_defines)) \
362
		$(patsubst %,-I %,$(INCDIRS)) \
363
		$(patsubst %,-I %,$(cxx_includes)) \
364
		$(patsubst %,-I %,$(gcc_includes))
365
 
366
define cxx_pre
367
	@echo [$<] compiling..
368
endef
369
 
370
define cxx_post
371
endef
372
 
373
###############################################################################
374
#..     Assembler definition
375
#
376
 
377
#..     Assembler (GCC)
378
#
379
as		= $(CC_PRE) $(GCC_CC)
380
as_init		=
381
as_i_switch	= -I$(space)
382
as_o_switch	=
383
as_object	= -o $@
384
as_source	= $<
385
 
386
gas_flags	= -Wall -x assembler-with-cpp -c
387
ifeq "$(DEBUG)" "1"
388
gas_flags	+= -g -DDEBUG
389
endif
390
ifdef DLVL
391
gas_flags	+= -DDLVL=$(DLVL)
392
endif
393
ifdef ALVL
394
gas_flags	+= -DALVL=$(ALVL)
395
endif
396
as_defines	:= $(addprefix -D,$(as_defines))
397
as_defines	+= $(gas_flags)
398
 
399
as_flags	= \
251 dpurdie 400
		$(ASFLAGS) \
401
		$(as_defines) \
227 dpurdie 402
		$(patsubst %,$(as_i_switch)%,$(INCDIRS)) \
403
		$(patsubst %,$(as_i_switch)%,$(as_includes)) \
404
		$(as_object)
405
 
406
define as_pre
407
	@echo [$<] compiling..
408
endef
409
 
410
define as_post
411
endef
412
 
413
 
414
###############################################################################
415
#..     Archiver definition
416
#
417
 
418
#..     Archiver
419
#
420
ar		= $(XX_PRE) $(GCC_AR)
421
ar_o_switch	=
4034 dpurdie 422
ar_flags	= -scr $@ \
227 dpurdie 423
		$(patsubst %,%,$^)
424
 
425
define ar_pre
4034 dpurdie 426
	@echo [$@] Create archive..
227 dpurdie 427
endef
428
 
429
define ar_post
430
endef
431
 
432
#..     Archive Merge
433
#
434
armerge		= $(XX_PRE) $(GBE_TOOLS)/armerge
435
armerge_init	=
261 dpurdie 436
armerge_flags	= -d $(MLIBDIR) -t unix -a $(GCC_AR)
227 dpurdie 437
armerge_o_switch= $@ $^
438
 
439
armerge_pre	= -$(rm) -f $@
440
armerge_post	=
441
 
442
###############################################################################
443
#..     Linker definition
444
#
445
 
446
#..     Linked (shared library support)
447
#
448
#       The following are detailed within the context of TARGET definition:
449
#
450
#       SHNAME  Defines the shared library name (eg lib.so.1.1)
451
#       SHBASE  Defines the base library name (eg lib.so)
452
#
453
shld		= $(CC_PRE) $(GCC_CC)
454
shld_o_switch	= -o $@
455
 
456
shld_flags	+= -shared -fPIC
4034 dpurdie 457
shld_flags	+= -Wl,-z,defs,--warn-unresolved-symbols
227 dpurdie 458
shld_flags	+= -Xlinker -h'$(SHNAME)'
459
shld_flags	+= -Xlinker -Map '$(LIBDIR)/$(SHBASE).map'
460
 
461
ifeq "$(DEBUG)" "1"
462
shld_flags	+= -g
463
endif
464
shld_flags	+= \
465
		$(patsubst %,%,$(LDFLAGS)) \
4712 alewis 466
		$(patsubst %,%,$(GCC_LDFLAGS)) \
4518 dpurdie 467
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
227 dpurdie 468
		$($(notdir $(SHBASE))_shld)
469
 
470
define shld_pre
471
	@echo [$@] Linking shared library..; \
472
	$(touch) $(LIBDIR)/$(SHBASE).map
473
endef
474
 
475
define shld_post
476
endef
477
 
478
define SHLDDEPEND
341 dpurdie 479
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 480
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 481
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 482
endef
483
 
484
 
485
#..     Linker
486
#
487
ifdef USE_CHECKER
488
ld		= @checkergcc
489
else
490
ld		= $(CC_PRE) $(GCC_CC)
491
endif
492
ld_init		=
493
ld_o_switch	= -o $@
494
 
495
ld_flags	+= -Xlinker -Map '$(basename $@).map'
496
 
497
ifeq "$(DEBUG)" "1"
498
ld_flags	+= -g
499
endif
500
ifdef USE_PROFILE
501
ld_flags	+= -pg
502
endif
503
 
504
ld_flags	+= \
505
		$(patsubst %,%,$(LDFLAGS)) \
4712 alewis 506
		$(patsubst %,%,$(GCC_LDFLAGS)) \
4518 dpurdie 507
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
508
		$(patsubst %,-Xlinker -rpath-link %,$(wildcard $(LIBDIRS))) \
227 dpurdie 509
		$($(notdir $(basename $@))_ld)
510
 
511
define ld_pre
512
	@echo [$@] Linking..; \
513
	$(touch) $(basename $@).map
514
endef
515
 
516
define ld_post
517
endef
518
 
519
define LDDEPEND
341 dpurdie 520
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 521
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 522
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 523
endef
524
 
373 dpurdie 525
 
227 dpurdie 526
#
373 dpurdie 527
#   LDSTRIP
528
#       $1 - Full name of the ouput
529
#       $2 - Full name of debug file
530
define LDSTRIP
531
    $(GCC_OBJCOPY) --only-keep-debug $1 $2 || rm -f $1 $2
532
    $(GCC_OBJCOPY) --strip-debug $1 || rm -f $1 $2
533
    $(GCC_OBJCOPY) --add-gnu-debuglink=$2 $1 || rm -f $1 $2
534
 
535
endef