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