Subversion Repositories DevTools

Rev

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