Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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