Subversion Repositories DevTools

Rev

Rev 4949 | Rev 5330 | Go to most recent revision | 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
 
5115 dpurdie 172
ifdef USE_STRICT_ANSI			# default NO
227 dpurdie 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
 
4928 dpurdie 184
ifdef WARNINGS_AS_ERRORS
185
gcc_flags	+= -Werror
186
endif
187
 
5115 dpurdie 188
ifdef GEN_PIC
189
gcc_flags	+= -fPIC
190
endif
191
 
227 dpurdie 192
SHCFLAGS	+= -fpic
193
SHCXXFLAGS	+= -fpic
194
 
195
	# Standard includes
196
	#
197
	#..
198
gcc_includes	+=
199
 
200
ifdef GCC_INCLUDES
201
gcc_includes	+= $(GCC_INCLUDES)
202
endif
203
 
204
	# Command
205
	#
206
	#..
207
ifdef USE_CHECKER
208
cc		= @checkergcc
209
else
210
cc		= $(CC_PRE) $(GCC_CC)
211
endif
212
cc_init		=
213
cc_o_switch	= -o $@
214
cc_source	= $<
215
cc_flags	= \
216
		$(patsubst %,%,$(CFLAGS)) \
217
		$(patsubst %,%,$(gcc_flags)) \
218
		$(patsubst %,%,$(gcc_defines)) \
219
		$(patsubst %,-D%,$(cc_defines)) \
220
		$(patsubst %,-I %,$(INCDIRS)) \
221
		$(patsubst %,-I %,$(cc_includes)) \
222
		$(patsubst %,-I %,$(gcc_includes))
223
cc_term		=
224
 
225
define cc_pre
226
	@echo [$<] compiling..
227
endef
228
 
229
ifdef USE_METRICS
230
define cc_post
231
	$(cc) -E $(cc_flags) $(cc_source) | mcstrip | cyclo -c > $(basename $@).met
232
endef
233
else
234
define cc_post
235
endef
236
endif
237
 
238
###############################################################################
239
#..     C/C++ dependencies
240
#
241
 
242
	# Additional defines
243
	#
244
	#..
245
gcc_depend	+=
246
 
247
ifeq ($(USE_GCCDEPEND),0)
248
	# Build GCC predefs and default include paths
249
	#..
250
GCC_MACHINE	=$(shell $(GCC_CC) -dumpmachine)
251
GCC_VERSION	=$(shell $(GCC_CC) -dumpversion)
252
 
253
gcc_depend	+= -D__GNUC__=$(word 1,$(subst .,$(space),$(GCC_VERSION)))
254
gcc_depend	+= -D__GNUC_MINOR__=$(word 2,$(subst .,$(space),$(GCC_VERSION)))
255
gcc_depend	+= -D__STDC__ -D__STDC_HOSTED__
256
 
257
ifdef GCC_TARGET
258
ifneq "$(findstring Linux,$(GCC_TARGET))" ""
259
gcc_depend	+= -Dunix -D__unix -D__unix__
260
gcc_depend	+= -Dlinux -D__linux -D__linux__
261
endif
262
ifneq "$(findstring i386,$(GCC_TARGET))" ""
263
gcc_depend	+= -Di386 -D__i386 -D__i386__
264
endif
265
ifneq "$(findstring armv4,$(GCC_TARGET))" ""
266
gcc_depend	+= -Darm -D__arm -D__arm__
267
gcc_depend	+= -D__ARM_ARCH__=4
268
endif
269
ifneq "$(findstring armv9,$(GCC_TARGET))" ""
270
gcc_depend	+= -Darm -D__arm -D__arm__
271
gcc_depend	+= -D__ARM_ARCH__=9
272
endif
273
 
274
endif
275
 
276
gcc_depend	+= -Y $(GCC_ROOT)/lib/gcc-lib/$(GCC_MACHINE)/$(GCC_VERSION)/include
277
gcc_depend	+= -Y $(GCC_ROOT)/include
278
endif
279
 
280
ifdef GCC_DEPEND
281
gcc_depend	+= $(GCC_DEPEND)
282
endif
283
 
284
	# Command
285
	#
286
	#..
287
ifeq ($(USE_GCCDEPEND),0)
367 dpurdie 288
ccdep		= $(XX_PRE) $(GBE_BIN)/mkdepend
227 dpurdie 289
ccdep_init	=
290
ccdep_o_switch	= -f -
291
ccdep_flags	= -MM -b -We -p '$$(OBJDIR)/' -o ".$(o)"
4538 dpurdie 292
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
227 dpurdie 293
else
294
ccdep		= -$(XX_PRE) $(GCC_CC)
295
ccdep_init	=
296
ccdep_o_switch	=
297
ccdep_flags	= -E -MM -MG
298
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $(subst /,/,$@).tmp 2> $(OBJDIR)/depend.err
299
endif
300
 
301
ccdep_flags	+= \
302
		$(patsubst %,%,$(CFLAGS)) \
303
		$(patsubst %,%,$(gcc_depend)) \
304
		$(patsubst %,%,$(gcc_defines)) \
305
		$(patsubst %,-D%,$(cc_defines)) \
306
		$(patsubst %,-I %,$(INCDIRS)) \
307
		$(patsubst %,-I %,$(cc_includes))
308
 
309
ifeq ($(USE_GCCDEPEND),0)
310
ccdep_flags	+= \
311
		$(patsubst %,-Y %,$(gcc_includes))
312
endif
313
 
314
	#
315
	#   Parse the depend output:
316
	#
317
	#   s/^.*/\(.*\.${o}\:\)/$(OBJDIR)/\1/g
318
	#        replace all object rules which contain / seperated
319
	#        subdirs with a stripped prefixed object name.
320
	#
321
	#        eg. subdir/dir/object.o:        $(OBJDIR)/object.o
322
	#
323
	#   s/^\([^/].*\.${o}\:\)/$(OBJDIR)/\1/g
324
	#        prefix all object rules without subdirs.
325
	#
326
	#        eg. object.o:                   $(OBJDIR)/object.o
327
	#..
328
 
329
ccdep_pre	=
330
 
331
ccdep_sed	= \
332
	-sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
333
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
334
		$(subst /,/,$@).tmp > $@ 2> $(OBJDIR)/depend.err;
335
ifdef SHNAMES
336
ccdep_sedsh	= \
337
	sed  -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
338
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
339
		$(subst /,/,$@).tmp >> $@ 2>> $(OBJDIR)/depend.err;
340
ccdep_sed	+= \
341
		$(foreach shname,$(SHNAMES),$(ccdep_sedsh))
342
endif
343
 
344
ifndef LEAVETMP
345
define ccdep_post
346
	@$(ccdep_sed)
347
	@rm $(subst /,/,$@).tmp
348
endef
349
else
350
define ccdep_post
351
	@$(ccdep_sed)
352
endef
353
endif
354
 
355
#..     C++ Compiler definition
356
#
357
ifdef USE_CHECKER
358
cxx		= @checkergcc
359
else
360
cxx		= $(CC_PRE) $(GCC_CC)
361
endif
362
cxx_init	=
363
cxx_o_switch	= -o $@
364
cxx_source	= $<
365
cxx_flags	= \
366
		$(patsubst %,%,$(CXXFLAGS)) \
367
		$(patsubst %,%,$(gcc_flags)) \
368
		$(patsubst %,%,$(gcc_defines)) \
369
		$(patsubst %,-d%,$(cxx_defines)) \
370
		$(patsubst %,-I %,$(INCDIRS)) \
371
		$(patsubst %,-I %,$(cxx_includes)) \
372
		$(patsubst %,-I %,$(gcc_includes))
373
 
374
define cxx_pre
375
	@echo [$<] compiling..
376
endef
377
 
378
define cxx_post
379
endef
380
 
381
###############################################################################
382
#..     Assembler definition
383
#
384
 
385
#..     Assembler (GCC)
386
#
387
as		= $(CC_PRE) $(GCC_CC)
388
as_init		=
389
as_i_switch	= -I$(space)
390
as_o_switch	=
391
as_object	= -o $@
392
as_source	= $<
393
 
394
gas_flags	= -Wall -x assembler-with-cpp -c
395
ifeq "$(DEBUG)" "1"
396
gas_flags	+= -g -DDEBUG
397
endif
398
ifdef DLVL
399
gas_flags	+= -DDLVL=$(DLVL)
400
endif
401
ifdef ALVL
402
gas_flags	+= -DALVL=$(ALVL)
403
endif
404
as_defines	:= $(addprefix -D,$(as_defines))
405
as_defines	+= $(gas_flags)
406
 
407
as_flags	= \
251 dpurdie 408
		$(ASFLAGS) \
409
		$(as_defines) \
227 dpurdie 410
		$(patsubst %,$(as_i_switch)%,$(INCDIRS)) \
411
		$(patsubst %,$(as_i_switch)%,$(as_includes)) \
412
		$(as_object)
413
 
414
define as_pre
415
	@echo [$<] compiling..
416
endef
417
 
418
define as_post
419
endef
420
 
421
 
422
###############################################################################
423
#..     Archiver definition
424
#
425
 
426
#..     Archiver
427
#
428
ar		= $(XX_PRE) $(GCC_AR)
429
ar_o_switch	=
4034 dpurdie 430
ar_flags	= -scr $@ \
227 dpurdie 431
		$(patsubst %,%,$^)
432
 
433
define ar_pre
4034 dpurdie 434
	@echo [$@] Create archive..
227 dpurdie 435
endef
436
 
437
define ar_post
438
endef
439
 
440
#..     Archive Merge
441
#
442
armerge		= $(XX_PRE) $(GBE_TOOLS)/armerge
443
armerge_init	=
261 dpurdie 444
armerge_flags	= -d $(MLIBDIR) -t unix -a $(GCC_AR)
227 dpurdie 445
armerge_o_switch= $@ $^
446
 
447
armerge_pre	= -$(rm) -f $@
448
armerge_post	=
449
 
450
###############################################################################
451
#..     Linker definition
452
#
453
 
454
#..     Linked (shared library support)
455
#
456
#       The following are detailed within the context of TARGET definition:
457
#
458
#       SHNAME  Defines the shared library name (eg lib.so.1.1)
459
#       SHBASE  Defines the base library name (eg lib.so)
460
#
461
shld		= $(CC_PRE) $(GCC_CC)
462
shld_o_switch	= -o $@
463
 
464
shld_flags	+= -shared -fPIC
4034 dpurdie 465
shld_flags	+= -Wl,-z,defs,--warn-unresolved-symbols
227 dpurdie 466
shld_flags	+= -Xlinker -h'$(SHNAME)'
467
shld_flags	+= -Xlinker -Map '$(LIBDIR)/$(SHBASE).map'
468
 
469
ifeq "$(DEBUG)" "1"
470
shld_flags	+= -g
471
endif
472
shld_flags	+= \
473
		$(patsubst %,%,$(LDFLAGS)) \
4728 dpurdie 474
		$(patsubst %,%,$(GCC_LDFLAGS)) \
4518 dpurdie 475
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
227 dpurdie 476
		$($(notdir $(SHBASE))_shld)
477
 
478
define shld_pre
479
	@echo [$@] Linking shared library..; \
480
	$(touch) $(LIBDIR)/$(SHBASE).map
481
endef
482
 
483
define shld_post
484
endef
485
 
486
define SHLDDEPEND
341 dpurdie 487
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 488
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 489
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 490
endef
491
 
492
 
493
#..     Linker
494
#
495
ifdef USE_CHECKER
496
ld		= @checkergcc
497
else
498
ld		= $(CC_PRE) $(GCC_CC)
499
endif
500
ld_init		=
501
ld_o_switch	= -o $@
502
 
503
ld_flags	+= -Xlinker -Map '$(basename $@).map'
504
 
505
ifeq "$(DEBUG)" "1"
506
ld_flags	+= -g
507
endif
508
ifdef USE_PROFILE
509
ld_flags	+= -pg
510
endif
511
 
512
ld_flags	+= \
513
		$(patsubst %,%,$(LDFLAGS)) \
4728 dpurdie 514
		$(patsubst %,%,$(GCC_LDFLAGS)) \
4518 dpurdie 515
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
516
		$(patsubst %,-Xlinker -rpath-link %,$(wildcard $(LIBDIRS))) \
227 dpurdie 517
		$($(notdir $(basename $@))_ld)
518
 
519
define ld_pre
520
	@echo [$@] Linking..; \
521
	$(touch) $(basename $@).map
522
endef
523
 
524
define ld_post
525
endef
526
 
527
define LDDEPEND
341 dpurdie 528
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 529
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 530
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 531
endef
532
 
373 dpurdie 533
 
227 dpurdie 534
#
373 dpurdie 535
#   LDSTRIP
4949 dpurdie 536
#       $1 - Full name of the output
373 dpurdie 537
#       $2 - Full name of debug file
538
define LDSTRIP
539
    $(GCC_OBJCOPY) --only-keep-debug $1 $2 || rm -f $1 $2
540
    $(GCC_OBJCOPY) --strip-debug $1 || rm -f $1 $2
541
    $(GCC_OBJCOPY) --add-gnu-debuglink=$2 $1 || rm -f $1 $2
542
 
543
endef