Subversion Repositories DevTools

Rev

Go to most recent revision | Details | 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
# Version   Who      Date       Description
6
#           APY      06/02/00   Created (original from DGJPP)
7
#                    25/06/00   __SOURCE__
8
#                               updated gcc_depend
9
#           GH       13/11/00   Initial GCC release
10
#           APY      18/05/04   Updated mkdepend interface
11
#                               Cross Target support
12
#                               General cleanup, removed xargs usage
13
###############################################################################
14
 
15
###############################################################################
16
#..     Remove "undef" warnings
17
#
18
cc_includes	+=
19
cc_defines	+=
20
cxx_includes	+=
21
cxx_defines	+=
22
as_includes	+=
23
as_defines	+=
24
 
25
 
26
###############################################################################
27
#..     Toolset defaults
383 dpurdie 28
#           mkdepend is a lot faster that gcc
227 dpurdie 29
#
383 dpurdie 30
USE_GCCDEPEND	= 0
227 dpurdie 31
 
32
###############################################################################
33
#..     Parse user options
34
#       Global options already parsed
35
#       These options extend the global options
36
#
37
ifdef OPTIONS
38
 
39
ifneq "$(findstring purify,$(OPTIONS))" ""	# Enable purify
40
CC_PRE		+= purify
41
else
42
ifneq "$(findstring purecov,$(OPTIONS))" ""	# Enable pure coverage
43
CC_PRE		+= purecov
44
endif
45
endif
46
 
47
ifneq "$(findstring metrics,$(OPTIONS))" ""	# Build source metrixs
48
USE_METRICS	= 1
49
endif
50
 
51
ifneq "$(findstring checker,$(OPTIONS))" ""
52
USE_CHECKER	= 1
53
endif
54
 
55
ifneq "$(findstring profile,$(OPTIONS))" ""
56
USE_PROFILE	= 1
57
endif
58
 
59
ifneq "$(findstring ccdepend,$(OPTIONS))" ""	# Build depends using gcc
60
USE_GCCDEPEND	= 1
61
endif
62
ifneq "$(findstring gccdepend,$(OPTIONS))" ""
63
USE_GCCDEPEND	= 1
64
endif
65
ifneq "$(findstring mkdepend,$(OPTIONS))" ""
66
USE_GCCDEPEND	= 0
67
endif
68
 
69
ifneq "$(findstring wall,$(OPTIONS))" ""	# Enable all warnings
70
USE_WALL	= 1
71
endif
72
 
73
endif	#OPTIONS
74
 
75
###############################################################################
377 dpurdie 76
#..     C and C++ Compiler warning filter
77
#
78
cc_filter_name  := warnings.gcc
79
cc_filter	:= "$(notdir $(wildcard $(GBE_ROOT)/$(cc_filter_name)))"
80
 
81
ifeq ($(strip $(cc_filter)),"$(cc_filter_name)")
82
    cc_filter      := $(GBE_ROOT)/$(cc_filter_name)
83
else
84
    cc_filter  :=
85
endif
86
 
87
ifdef cc_filter
88
cc_redirect_stderr = 1
89
cc_error_filter = $(awk) -f $(cc_filter)
90
endif
91
 
92
###############################################################################
227 dpurdie 93
#..     C Compiler definition
94
#
95
 
96
	# Standard defines
97
	#
98
	#..
99
ifdef GCC_DEFINES
100
gcc_defines	+= $(GCC_DEFINES)
101
endif
102
 
103
gcc_defines	+= -D_REENTRANT
104
 
105
ifeq "$(DEBUG)" "1"
373 dpurdie 106
gcc_defines	+= -DDEBUG
227 dpurdie 107
else
108
gcc_defines	+=
109
endif
110
 
111
ifdef ALVL
112
gcc_defines	+= -DALVL=$(ALVL)
113
endif
114
 
115
ifdef DLVL
116
gcc_defines	+= -DDLVL=$(DLVL)
117
endif
118
 
119
gcc_defines	+= -D__SOURCE__=\"$(notdir $<)\"
120
 
121
	# Standard flags
122
	#
123
	#  -Wall implies:
124
	#       -Wimplicit, -Wreturn-type, -Wunused, -Wswitch
125
	#       -Wformat, -Wchar-subscripts, -Wparentheses
126
	#       -Wmissing-braces
127
	#..
128
gcc_flags	+= -c
129
gcc_flags	+= -Wall
130
ifdef USE_WALL
131
#gcc_flags	+= -Wuninitialized		# only makes sense with `-O'
132
gcc_flags	+= -Wwrite-strings
133
gcc_flags	+= -Wcast-qual
134
gcc_flags	+= -Wbad-function-cast
135
gcc_flags	+= -Wpointer-arith
136
gcc_flags	+= -Wstrict-prototypes
137
gcc_flags	+= -Wmissing-prototypes
138
gcc_flags	+= -Wmissing-declarations
139
gcc_flags	+= -Wnested-externs
140
gcc_flags	+= -Wtraditional
141
gcc_flags	+= -Wconversion
142
gcc_flags	+= -Wcomment
143
gcc_flags	+= -Wcast-align
144
#gcc_flags	+= -Winline
145
gcc_flags	+= -Wshadow
146
gcc_flags	+= -Wredundant-decls
4309 dpurdie 147
#gcc_flags	+= -Wid-clash-31
227 dpurdie 148
endif
149
 
150
ifdef GCC_CFLAGS
151
gcc_flags	+= $(GCC_CFLAGS)
152
endif
153
 
154
ifdef FORCE_C_COMPILE
155
endif
156
 
157
ifdef FORCE_CC_COMPILE
158
endif
159
 
160
ifdef USE_OPTIMISE				# default for production
161
else
162
endif
163
 
164
ifdef USE_DEBUGINFO				# default for debug
373 dpurdie 165
gcc_flags	+= -g3 -ggdb
227 dpurdie 166
else
373 dpurdie 167
gcc_flags	+= -g3 -ggdb
227 dpurdie 168
endif
169
 
170
ifeq "$(DEBUG)" "1"				# debug/prod specific
171
ifdef GCC_CFLAGSD
4034 dpurdie 172
gcc_flags	+= $(GCC_CFLAGSD)
227 dpurdie 173
endif
174
else
175
ifdef GCC_CFLAGSP
4034 dpurdie 176
gcc_flags	+= $(GCC_CFLAGSP)
227 dpurdie 177
endif
178
endif
179
 
180
ifdef USE_STRICT_ANSI				# default NO
181
gcc_flags	+= -ansi
182
endif
183
 
184
ifdef USE_PROFILE				# default NO
185
gcc_flags	+= -pg
186
endif
187
 
188
ifdef LEAVETMP					# default NO
189
gcc_flags	+= -save-temps
190
endif
191
 
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)"
292
ccdep_source	= $(filter %.c %.cc %.cpp, $+) > $@ 2> $(OBJDIR)/depend.err
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
ifneq ($(USE_GCCDEPEND),0)
332
ccdep_sed	= \
333
	-sed -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
334
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/\1/g' \
335
		$(subst /,/,$@).tmp > $@ 2> $(OBJDIR)/depend.err;
336
ifdef SHNAMES
337
ccdep_sedsh	= \
338
	sed  -e 's/^.*\/\(.*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
339
	     -e 's/^\([^/]*\.${o}\:\)/\$$\(OBJDIR\)\/$(shname)\/\1/g' \
340
		$(subst /,/,$@).tmp >> $@ 2>> $(OBJDIR)/depend.err;
341
ccdep_sed	+= \
342
		$(foreach shname,$(SHNAMES),$(ccdep_sedsh))
343
endif
344
 
345
ifndef LEAVETMP
346
define ccdep_post
347
	@$(ccdep_sed)
348
	@rm $(subst /,/,$@).tmp
349
endef
350
else
351
define ccdep_post
352
	@$(ccdep_sed)
353
endef
354
endif
355
else
356
ccdep_post	=
357
endif
358
 
359
#..     C++ Compiler definition
360
#
361
ifdef USE_CHECKER
362
cxx		= @checkergcc
363
else
364
cxx		= $(CC_PRE) $(GCC_CC)
365
endif
366
cxx_init	=
367
cxx_o_switch	= -o $@
368
cxx_source	= $<
369
cxx_flags	= \
370
		$(patsubst %,%,$(CXXFLAGS)) \
371
		$(patsubst %,%,$(gcc_flags)) \
372
		$(patsubst %,%,$(gcc_defines)) \
373
		$(patsubst %,-d%,$(cxx_defines)) \
374
		$(patsubst %,-I %,$(INCDIRS)) \
375
		$(patsubst %,-I %,$(cxx_includes)) \
376
		$(patsubst %,-I %,$(gcc_includes))
377
 
378
define cxx_pre
379
	@echo [$<] compiling..
380
endef
381
 
382
define cxx_post
383
endef
384
 
385
###############################################################################
386
#..     Assembler definition
387
#
388
 
389
#..     Assembler (GCC)
390
#
391
as		= $(CC_PRE) $(GCC_CC)
392
as_init		=
393
as_i_switch	= -I$(space)
394
as_o_switch	=
395
as_object	= -o $@
396
as_source	= $<
397
 
398
gas_flags	= -Wall -x assembler-with-cpp -c
399
ifeq "$(DEBUG)" "1"
400
gas_flags	+= -g -DDEBUG
401
endif
402
ifdef DLVL
403
gas_flags	+= -DDLVL=$(DLVL)
404
endif
405
ifdef ALVL
406
gas_flags	+= -DALVL=$(ALVL)
407
endif
408
as_defines	:= $(addprefix -D,$(as_defines))
409
as_defines	+= $(gas_flags)
410
 
411
as_flags	= \
251 dpurdie 412
		$(ASFLAGS) \
413
		$(as_defines) \
227 dpurdie 414
		$(patsubst %,$(as_i_switch)%,$(INCDIRS)) \
415
		$(patsubst %,$(as_i_switch)%,$(as_includes)) \
416
		$(as_object)
417
 
418
define as_pre
419
	@echo [$<] compiling..
420
endef
421
 
422
define as_post
423
endef
424
 
425
 
426
###############################################################################
427
#..     Archiver definition
428
#
429
 
430
#..     Archiver
431
#
432
ar		= $(XX_PRE) $(GCC_AR)
433
ar_o_switch	=
4034 dpurdie 434
ar_flags	= -scr $@ \
227 dpurdie 435
		$(patsubst %,%,$^)
436
 
437
define ar_pre
4034 dpurdie 438
	@echo [$@] Create archive..
227 dpurdie 439
endef
440
 
441
define ar_post
442
endef
443
 
444
#..     Archive Merge
445
#
446
armerge		= $(XX_PRE) $(GBE_TOOLS)/armerge
447
armerge_init	=
261 dpurdie 448
armerge_flags	= -d $(MLIBDIR) -t unix -a $(GCC_AR)
227 dpurdie 449
armerge_o_switch= $@ $^
450
 
451
armerge_pre	= -$(rm) -f $@
452
armerge_post	=
453
 
454
###############################################################################
455
#..     Linker definition
456
#
457
 
458
#..     Linked (shared library support)
459
#
460
#       The following are detailed within the context of TARGET definition:
461
#
462
#       SHNAME  Defines the shared library name (eg lib.so.1.1)
463
#       SHBASE  Defines the base library name (eg lib.so)
464
#
465
shld		= $(CC_PRE) $(GCC_CC)
466
shld_o_switch	= -o $@
467
 
468
shld_flags	+= -shared -fPIC
4034 dpurdie 469
shld_flags	+= -Wl,-z,defs,--warn-unresolved-symbols
227 dpurdie 470
shld_flags	+= -Xlinker -h'$(SHNAME)'
471
shld_flags	+= -Xlinker -Map '$(LIBDIR)/$(SHBASE).map'
472
 
473
ifeq "$(DEBUG)" "1"
474
shld_flags	+= -g
475
endif
476
shld_flags	+= \
477
		$(patsubst %,%,$(LDFLAGS)) \
4518 dpurdie 478
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
227 dpurdie 479
		$($(notdir $(SHBASE))_shld)
480
 
481
define shld_pre
482
	@echo [$@] Linking shared library..; \
483
	$(touch) $(LIBDIR)/$(SHBASE).map
484
endef
485
 
486
define shld_post
487
endef
488
 
489
define SHLDDEPEND
341 dpurdie 490
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 491
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 492
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 493
endef
494
 
495
 
496
#..     Linker
497
#
498
ifdef USE_CHECKER
499
ld		= @checkergcc
500
else
501
ld		= $(CC_PRE) $(GCC_CC)
502
endif
503
ld_init		=
504
ld_o_switch	= -o $@
505
 
506
ld_flags	+= -Xlinker -Map '$(basename $@).map'
507
 
508
ifeq "$(DEBUG)" "1"
509
ld_flags	+= -g
510
endif
511
ifdef USE_PROFILE
512
ld_flags	+= -pg
513
endif
514
 
515
ld_flags	+= \
516
		$(patsubst %,%,$(LDFLAGS)) \
4518 dpurdie 517
		$(patsubst %,-L%,$(wildcard $(LIBDIRS))) \
518
		$(patsubst %,-Xlinker -rpath-link %,$(wildcard $(LIBDIRS))) \
227 dpurdie 519
		$($(notdir $(basename $@))_ld)
520
 
521
define ld_pre
522
	@echo [$@] Linking..; \
523
	$(touch) $(basename $@).map
524
endef
525
 
526
define ld_post
527
endef
528
 
529
define LDDEPEND
341 dpurdie 530
	$(AA_PRE)export GCC_LIB; \
4518 dpurdie 531
		GCC_LIB="$(subst $(space),;,$(wildcard $(LIBDIRS)))"; \
335 dpurdie 532
	$(cmdfile) -wo$@ "@(vlibgcc,$(GCC_CC))$($(DPLIST))"
227 dpurdie 533
endef
534
 
373 dpurdie 535
 
227 dpurdie 536
#
373 dpurdie 537
#   LDSTRIP
538
#       $1 - Full name of the ouput
539
#       $2 - Full name of debug file
540
define LDSTRIP
541
    $(GCC_OBJCOPY) --only-keep-debug $1 $2 || rm -f $1 $2
542
    $(GCC_OBJCOPY) --strip-debug $1 || rm -f $1 $2
543
    $(GCC_OBJCOPY) --add-gnu-debuglink=$2 $1 || rm -f $1 $2
544
 
545
endef