OSDN Git Service

e63736205fad3f7303cac1ea5469989c645de9cf
[uclinux-h8/uClibc.git] / Rules.mak
1 # Rules.make for uClibc
2 #
3 # Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
4 #
5 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 #
7
8 # make nano-doc
9 # FOO = bar  -- recursively expanded variable. Value is remebered verbatim.
10 #               If it contains references to other variables, these references
11 #               are expanded whenever this variable is _substituted_.
12 # FOO := bar -- simply expanded variable. Right hand is expanded when
13 #               the variable is _defined_. Therefore faster than =.
14 # FOO ?= bar -- set a value only if it is not already set
15 #               (behaves as =, not :=).
16 # FOO += bar -- append; if FOO is not defined, acts like = (not :=).
17
18
19 # check for proper make version
20 ifneq ($(findstring x3.7,x$(MAKE_VERSION)),)
21 $(error Your make is too old $(MAKE_VERSION). Go get at least 3.80)
22 endif
23
24 #-----------------------------------------------------------
25 # This file contains rules which are shared between multiple
26 # Makefiles.  All normal configuration options live in the
27 # file named ".config".  Don't mess with this file unless
28 # you know what you are doing.
29
30 clean_targets := clean realclean distclean \
31         objclean-y headers_clean-y CLEAN_utils
32 noconfig_targets := menuconfig config nconfig \
33         oldaskconfig silentoldconfig oldconfig allnoconfig allyesconfig \
34         alldefconfig randconfig defconfig savedefconfig listnewconfig \
35         olddefconfig \
36         xconfig gconfig update-po-config mconf qconf gconf nconf conf \
37         release dist tags help
38
39
40 #-----------------------------------------------------------
41 # If you are running a cross compiler, you will want to set
42 # 'CROSS_COMPILE' to something more interesting ...  Target
43 # architecture is determined by asking the CC compiler what
44 # arch it compiles things for, so unless your compiler is
45 # broken, you should not need to specify TARGET_ARCH.
46 #
47 # Most people will set this stuff on the command line, i.e.
48 #        make CROSS_COMPILE=arm-linux-
49 # will build uClibc for 'arm'.
50 # CROSS is still supported for backward compatibily only
51
52 CROSS_COMPILE ?= $(CROSS)
53
54 CC         = $(CROSS_COMPILE)gcc
55 AR         = $(CROSS_COMPILE)ar
56 LD         = $(CROSS_COMPILE)ld
57 NM         = $(CROSS_COMPILE)nm
58 OBJDUMP    = $(CROSS_COMPILE)objdump
59 STRIPTOOL  = $(CROSS_COMPILE)strip
60
61 INSTALL    = install
62 LN         = ln
63 RM         = rm -f
64 TAR        = tar
65 SED        = sed
66 AWK        = awk
67
68 STRIP_FLAGS ?= -x -R .note -R .comment
69
70 ## unused? if yes, remove after 0.9.31
71 ## UNIFDEF := $(top_builddir)extra/scripts/unifdef
72
73 # Select the compiler needed to build binaries for your development system
74 HOSTCC     = gcc
75 BUILD_CFLAGS = -Os
76
77 #---------------------------------------------------------
78 # Nothing beyond this point should ever be touched by mere
79 # mortals.  Unless you hang out with the gods, you should
80 # probably leave all this stuff alone.
81
82 # strip quotes
83 qstrip = $(strip $(subst ",,$(1)))
84 #"))
85
86 # kconfig stuff
87 KCONFIG_CONFIG ?= $(top_builddir).config
88 KCONFIG_CONFIG := $(abspath $(KCONFIG_CONFIG))
89 export KCONFIG_CONFIG
90 KCONFIG_AUTOCONFIG := $(dir $(KCONFIG_CONFIG))include/config/auto.conf
91 export KCONFIG_AUTOCONFIG
92 KCONFIG_TRISTATE := $(dir $(KCONFIG_CONFIG))include/config/tristate.conf
93 export KCONFIG_TRISTATE
94 srctree := $(abspath $(top_srcdir))
95 export srctree
96 KCONFIG_AUTOHEADER := $(dir $(KCONFIG_CONFIG))include/generated/autoconf.h
97 export KCONFIG_AUTOHEADER
98 Kconfig := $(abspath $(top_srcdir)extra/Configs/Config.in)
99
100 # Pull in the user's uClibc configuration
101 ifeq ($(filter $(noconfig_targets) clean CLEAN_%,$(MAKECMDGOALS)),)
102 -include $(KCONFIG_CONFIG)
103 endif
104
105 TARGET_ARCH:=$(call qstrip,$(TARGET_ARCH))
106 ifeq ($(TARGET_ARCH),)
107 ARCH ?= $(shell uname -m | $(SED) -e s/i.86/i386/ \
108                                   -e s/sun.*/sparc/ -e s/sparc.*/sparc/ \
109                                   -e s/arm.*/arm/ -e s/sa110/arm/ \
110                                   -e s/sh.*/sh/ \
111                                   -e s/s390x/s390/ -e s/parisc.*/hppa/ \
112                                   -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
113                                   -e s/xtensa.*/xtensa/ )
114 else
115 ARCH = $(TARGET_ARCH)
116 endif
117 export ARCH
118
119 # Make certain these contain a final "/", but no "//"s.
120 scrub_path = $(strip $(subst //,/, $(subst ,/, $(call qstrip,$(1)))))
121 TARGET_SUBARCH := $(call qstrip,$(TARGET_SUBARCH))
122 RUNTIME_PREFIX := $(call scrub_path,$(RUNTIME_PREFIX))
123 DEVEL_PREFIX   := $(call scrub_path,$(DEVEL_PREFIX))
124 MULTILIB_DIR   := $(call scrub_path,$(MULTILIB_DIR))
125 KERNEL_HEADERS := $(call scrub_path,$(KERNEL_HEADERS))
126 export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR
127
128
129 # Now config hard core
130 MAJOR_VERSION := 0
131 MINOR_VERSION := 9
132 SUBLEVEL      := 34
133 EXTRAVERSION  :=-git
134 VERSION       := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
135 ABI_VERSION   := $(MAJOR_VERSION)
136 ifneq ($(EXTRAVERSION),)
137 VERSION       := $(VERSION)$(EXTRAVERSION)
138 endif
139 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
140 LC_ALL := C
141 export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION ABI_VERSION LC_ALL
142
143 LIBC := libc
144 SHARED_LIBNAME := $(LIBC).so.$(ABI_VERSION)
145 UBACKTRACE_DSO := libubacktrace.so.$(ABI_VERSION)
146
147 UCLIBC_LDSO_NAME := ld-uClibc
148 ARCH_NATIVE_BIT := 32
149 ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 powerpc64 s390x sparc64 x86_64 ),)
150 UCLIBC_LDSO_NAME := ld64-uClibc
151 ARCH_NATIVE_BIT := 64
152 else
153 ifeq ($(CONFIG_MIPS_N64_ABI),y)
154 UCLIBC_LDSO_NAME := ld64-uClibc
155 ARCH_NATIVE_BIT := 64
156 endif
157 endif
158
159 UCLIBC_LDSO := $(UCLIBC_LDSO_NAME).so.$(ABI_VERSION)
160 NONSHARED_LIBNAME := uclibc_nonshared.a
161 libc := $(top_builddir)lib/$(SHARED_LIBNAME)
162 libc.depend := $(top_builddir)lib/$(SHARED_LIBNAME:.$(ABI_VERSION)=)
163 ifneq ($(ARCH_HAS_NO_SHARED),y)
164 libdl.depend := $(top_builddir)lib/libdl.so
165 endif
166 ifneq ($(HAS_NO_THREADS),y)
167 libpthread.depend := $(top_builddir)lib/libpthread.so
168 endif
169 interp := $(top_builddir)lib/interp.os
170 ldso := $(top_builddir)lib/$(UCLIBC_LDSO)
171 headers_dep := $(top_builddir)include/bits/sysnum.h
172 sub_headers := $(headers_dep)
173
174 #LIBS :=$(interp) -L$(top_builddir)lib -lc
175 LIBS := $(interp) -L$(top_builddir)lib $(libc:.$(ABI_VERSION)=)
176
177 # Make sure DESTDIR and PREFIX can be used to install
178 # PREFIX is a uClibcism while DESTDIR is a common GNUism
179 ifndef PREFIX
180 PREFIX = $(DESTDIR)
181 endif
182
183 ifneq ($(HAVE_SHARED),y)
184 libc :=
185 interp :=
186 ldso :=
187 endif
188
189 comma:=,
190 space:= #
191
192 ifeq ($(CROSS_COMPILE),)
193 CROSS_COMPILE=$(call qstrip,$(CROSS_COMPILER_PREFIX))
194 endif
195
196 # A nifty macro to make testing gcc features easier
197 check_gcc=$(shell \
198         if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
199         then echo "$(1)"; else echo "$(2)"; fi)
200 check_as=$(shell \
201         if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
202         then echo "-Wa,$(1)"; fi)
203 # FIXME: filter -fuse-ld=% and pass that, too!!
204 check_ld=$(shell \
205         if $(CC) -Wl,$(1) $(CFLAG_-nostdlib) -o /dev/null -Wl,-b,binary /dev/null > /dev/null 2>&1; \
206         then echo "$(1)"; fi)
207
208 # Use variable indirection here so that we can have variable
209 # names with fun chars in them like equal signs
210 define check-tool-var
211 ifeq ($(filter $(clean_targets) CLEAN_%,$(MAKECMDGOALS)),)
212 _v = $(2)_$(3)
213 ifndef $$(_v)
214 $$(_v) := $$(call $(1),$(subst %, ,$(3)))
215 export $$(_v)
216 endif
217 endif
218 endef
219
220 # Usage: check-gcc-var,<flag>
221 # Check the C compiler to see if it supports <flag>.
222 # Export the variable CFLAG_<flag> if it does.
223 define check-gcc-var
224 $(call check-tool-var,check_gcc,CFLAG,$(1))
225 endef
226 # Usage: check-as-var,<flag>
227 # Check the assembler to see if it supports <flag>.  Export the
228 # variable ASFLAG_<flag> if it does (for invoking the assembler),
229 # as well CFLAG_-Wa<flag> (for invoking the compiler driver).
230 define check-as-var
231 $(call check-tool-var,check_as,ASFLAG,$(1))
232 _v = CFLAG_-Wa$(1)
233 export $$(_v) = $$(if $$(ASFLAG_$(1)),-Wa$$(comma)$$(ASFLAG_$(1)))
234 endef
235 # Usage: check-ld-var,<flag>
236 # Check the linker to see if it supports <flag>.  Export the
237 # variable LDFLAG_<flag> if it does (for invoking the linker),
238 # as well CFLAG_-Wl<flag> (for invoking the compiler driver).
239 define check-ld-var
240 $(call check-tool-var,check_ld,LDFLAG,$(1))
241 _v = CFLAG_-Wl$(1)
242 export $$(_v) = $$(if $$(LDFLAG_$(1)),-Wl$$(comma)$$(LDFLAG_$(1)))
243 endef
244 # Usage: cache-output-var,<variable>,<shell command>
245 # Execute <shell command> and cache the output in <variable>.
246 define cache-output-var
247 ifndef $(1)
248 $(1) := $$(shell $(2))
249 export $(1)
250 endif
251 endef
252
253
254 ARFLAGS:=cr
255
256 # Note: The check for -nostdlib has to be before all calls to check_ld
257 $(eval $(call check-gcc-var,-nostdlib))
258
259 # Flags in OPTIMIZATION are used only for non-debug builds
260
261 OPTIMIZATION:=
262 # Use '-Os' optimization if available, else use -O2, allow Config to override
263 $(eval $(call check-gcc-var,-Os))
264 ifneq ($(CFLAG_-Os),)
265 OPTIMIZATION += $(CFLAG_-Os)
266 else
267 $(eval $(call check-gcc-var,-O2))
268 OPTIMIZATION += $(CFLAG_-O2)
269 endif
270 # Use the gcc 3.4 -funit-at-a-time optimization when available
271 $(eval $(call check-gcc-var,-funit-at-a-time))
272 OPTIMIZATION += $(CFLAG_-funit-at-a-time)
273 # shrinks code by about 0.1%
274 $(eval $(call check-gcc-var,-fmerge-all-constants))
275 $(eval $(call check-gcc-var,-fstrict-aliasing))
276 OPTIMIZATION += $(CFLAG_-fmerge-all-constants) $(CFLAG_-fstrict-aliasing)
277
278 $(eval $(call cache-output-var,GCC_VER,$(CC) -dumpversion))
279 GCC_VER := $(subst ., ,$(GCC_VER))
280 GCC_MAJOR_VER ?= $(word 1,$(GCC_VER))
281 #GCC_MINOR_VER ?= $(word 2,$(GCC_VER))
282
283 ifneq ($(TARGET_ARCH),arc)
284 ifeq ($(GCC_MAJOR_VER),4)
285 # shrinks code, results are from 4.0.2
286 # 0.36%
287 $(eval $(call check-gcc-var,-fno-tree-loop-optimize))
288 OPTIMIZATION += $(CFLAG_-fno-tree-loop-optimize)
289 # 0.34%
290 $(eval $(call check-gcc-var,-fno-tree-dominator-opts))
291 OPTIMIZATION += $(CFLAG_-fno-tree-dominator-opts)
292 # 0.1%
293 $(eval $(call check-gcc-var,-fno-strength-reduce))
294 OPTIMIZATION += $(CFLAG_-fno-strength-reduce)
295 endif
296 endif
297
298 # CPU_CFLAGS-y contain options which are not warnings,
299 # not include or library paths, and not optimizations.
300
301 # Why -funsigned-char: I hunted a bug related to incorrect
302 # sign extension of 'char' type for 10 hours straight. Not fun.
303 CPU_CFLAGS-y := -funsigned-char -fno-builtin
304
305 $(eval $(call check-gcc-var,-fno-asm))
306 CPU_CFLAGS-y += $(CFLAG_-fno-asm)
307
308 LDADD_LIBFLOAT=
309 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
310 # If -msoft-float isn't supported, we want an error anyway.
311 # Hmm... might need to revisit this for arm since it has 2 different
312 # soft float encodings.
313 ifneq ($(TARGET_ARCH),nios)
314 ifneq ($(TARGET_ARCH),nios2)
315 ifneq ($(TARGET_ARCH),sh)
316 ifneq ($(TARGET_ARCH),c6x)
317 CPU_CFLAGS-y += -msoft-float
318 endif
319 endif
320 endif
321 endif
322 ifeq ($(TARGET_ARCH),arm)
323 # No longer needed with current toolchains, but leave it here for now.
324 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
325 #    LDADD_LIBFLOAT=-lfloat
326 endif
327 endif
328
329 $(eval $(call check-gcc-var,-std=gnu99))
330 CPU_CFLAGS-y += $(CFLAG_-std=gnu99)
331
332 CPU_CFLAGS-$(UCLIBC_FORMAT_SHARED_FLAT) += -mid-shared-library
333 CPU_CFLAGS-$(UCLIBC_FORMAT_FLAT_SEP_DATA) += -msep-data
334
335 CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN) += -Wl,-EL
336 CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)    += -Wl,-EB
337
338 PICFLAG-y := -fPIC
339 PICFLAG-$(UCLIBC_FORMAT_FDPIC_ELF) := -mfdpic
340 PICFLAG-$(UCLIBC_FORMAT_DSBT_ELF)  := -mdsbt -fpic
341 PICFLAG := $(PICFLAG-y)
342 PIEFLAG_NAME:=-fPIE
343
344 # Some nice CPU specific optimizations
345 ifeq ($(TARGET_ARCH),i386)
346 $(eval $(call check-gcc-var,-fomit-frame-pointer))
347         OPTIMIZATION += $(CFLAG_-fomit-frame-pointer)
348
349 ifeq ($(CONFIG_386)$(CONFIG_486)$(CONFIG_586),y)
350         # TODO: Change this to a gcc version check.  This bug
351         # should be fixed with at least gcc-4.3.
352         # Non-SSE capable processor.
353         # NB: this may make SSE insns segfault!
354         # -O1 -march=pentium3, -Os -msse etc are known to be affected.
355         # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13685
356         # -m32 is needed if host is 64-bit
357         OPTIMIZATION+=$(call check_gcc,-m32 -mpreferred-stack-boundary=2,)
358 else
359 $(eval $(call check-gcc-var,-mpreferred-stack-boundary=4))
360         OPTIMIZATION += $(CFLAG_-mpreferred-stack-boundary=4)
361 endif
362
363         # Choice of alignment (please document why!)
364         #  -falign-labels: in-line labels
365         #  (reachable by normal code flow, aligning will insert nops
366         #  which will be executed - may even make things slower)
367         #  -falign-jumps: reachable only by a jump
368         # Generic: no alignment at all (smallest code)
369         GCC_FALIGN=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,-malign-jumps=1 -malign-loops=1)
370         OPTIMIZATION+=$(GCC_FALIGN)
371
372         # Putting each function and data object into its own section
373         # allows for kbytes of less text if users link against static uclibc
374         # using ld --gc-sections.
375         # ld 2.18 can't do that (yet?) for shared libraries, so we itself
376         # do not use --gc-sections at shared lib link time.
377         # However, in combination with sections being sorted by alignment
378         # it does result in much reduced padding:
379         #   text    data     bss     dec     hex
380         # 235319    1472    5992  242783   3b45f old.so
381         # 234104    1472    5980  241556   3af94 new.so
382         # Without -ffunction-sections, all functions will get aligned
383         # to 4 byte boundary by as/ld. This is arguably a bug in as.
384         # It specifies 4 byte align for .text even if not told to do so:
385         # Idx Name          Size      VMA       LMA       File off  Algn
386         #   0 .text         xxxxxxxx  00000000  00000000  xxxxxxxx  2**2 <===!
387         CPU_CFLAGS-y  += $(CFLAG_-ffunction-sections) $(CFLAG_-fdata-sections)
388         CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-common)
389 $(eval $(call check-ld-var,--sort-section=alignment))
390         CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-section=alignment)
391
392         CPU_LDFLAGS-y+=-m32
393         CPU_CFLAGS-y+=-m32
394 endif
395
396 ifeq ($(TARGET_ARCH),sparc)
397         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
398         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
399         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
400         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
401 endif
402
403 ifeq ($(TARGET_ARCH),arm)
404         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
405         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
406         CPU_CFLAGS-$(COMPILE_IN_THUMB_MODE)+=-mthumb
407 endif
408
409 ifeq ($(TARGET_ARCH),metag)
410         SYMBOL_PREFIX=_
411         CPU_CFLAGS-$(CONFIG_META_1_2)+=
412         CPU_CFLAGS-$(CONFIG_META_2_1)+=-Wa,-mcpu=metac21
413 endif
414
415 ifeq ($(TARGET_ARCH),mips)
416         OPTIMIZATION+=-mno-split-addresses
417         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
418         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
419         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
420         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
421         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
422         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32R2)+=-march=mips32r2 -mtune=mips32r2
423         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
424         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64R2)+=-mips64r2 -mtune=mips64r2
425         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
426                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
427                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
428         endif
429         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
430                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
431                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
432         endif
433         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
434         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
435         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
436 endif
437
438 ifeq ($(TARGET_ARCH),nios)
439         OPTIMIZATION+=-funaligned-struct-hack
440         CPU_LDFLAGS-y+=-Wl,-m32
441         CPU_CFLAGS-y+=-Wl,-m32
442 endif
443
444 ifeq ($(TARGET_ARCH),sh)
445 $(eval $(call check-gcc-var,-mprefergot))
446         OPTIMIZATION += $(CFLAG_-mprefergot)
447         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
448         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
449         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
450         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
451 ifeq ($(UCLIBC_HAS_FPU),y)
452         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
453         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
454 else
455         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
456         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
457 endif
458 endif
459
460 ifeq ($(TARGET_ARCH),sh64)
461         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
462         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
463         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
464 endif
465
466 ifeq ($(TARGET_ARCH),h8300)
467         SYMBOL_PREFIX=_
468         CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
469         CPU_LDFLAGS-$(CONFIG_H8S)   += -Wl,-ms8300s
470         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
471         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
472 endif
473
474 ifeq ($(TARGET_ARCH),i960)
475         OPTIMIZATION+=-mh -mint32 #-fsigned-char
476 endif
477
478 ifeq ($(TARGET_ARCH),e1)
479         OPTIMIZATION+=-mgnu-param
480 endif
481
482 ifeq ($(TARGET_ARCH),cris)
483         CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
484         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
485         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
486         PICFLAG:=-fpic
487         PIEFLAG_NAME:=-fpie
488 endif
489
490 ifeq ($(TARGET_ARCH),m68k)
491         # -fPIC is only supported for 68020 and above.  It is not supported
492         # for 68000, 68010, or Coldfire.
493         PICFLAG:=-fpic
494         PIEFLAG_NAME:=-fpie
495 endif
496
497 ifeq ($(TARGET_ARCH),powerpc)
498 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
499 # enough. Therefore use -fpic which will reduce code size and generates
500 # faster code.
501         PICFLAG:=-fpic
502         PIEFLAG_NAME:=-fpie
503         PPC_HAS_REL16:=$(shell echo -e "\t.text\n\taddis 11,30,_GLOBAL_OFFSET_TABLE_-.@ha" | $(CC) -c -x assembler -o /dev/null -  2> /dev/null && echo -n y || echo -n n)
504         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
505         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES"
506
507 endif
508
509 ifeq ($(TARGET_ARCH),bfin)
510         SYMBOL_PREFIX=_
511 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
512         CPU_CFLAGS-y:=-mfdpic
513         CPU_LDFLAGS-y += -Wl,-melf32bfinfd
514         PICFLAG:=-fpic
515         PIEFLAG_NAME:=-fpie
516 endif
517 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
518         PICFLAG := -mleaf-id-shared-library
519 endif
520 endif
521
522 ifeq ($(TARGET_ARCH),frv)
523         CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
524         # Using -pie causes the program to have an interpreter, which is
525         # forbidden, so we must make do with -shared.  Unfortunately,
526         # -shared by itself would get us global function descriptors
527         # and calls through PLTs, dynamic resolution of symbols, etc,
528         # which would break as well, but -Bsymbolic comes to the rescue.
529         export LDPIEFLAG:=-shared -Wl,-Bsymbolic
530         UCLIBC_LDSO=ld.so.1
531 endif
532
533 ifeq ($(strip $(TARGET_ARCH)),avr32)
534        CPU_CFLAGS-$(CONFIG_AVR32_AP7)  += -march=ap
535        CPU_CFLAGS-$(CONFIG_LINKRELAX)  += -mrelax
536        CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
537 endif
538
539 ifeq ($(TARGET_ARCH),i960)
540       SYMBOL_PREFIX=_
541 endif
542
543 ifeq ($(TARGET_ARCH),v850)
544       SYMBOL_PREFIX=_
545 endif
546
547 ifeq ($(TARGET_ARCH),c6x)
548         PIEFLAG:=
549         CPU_CFLAGS-$(CONFIG_TMS320C64X) += -march=c64x
550         CPU_CFLAGS-$(CONFIG_TMS320C64XPLUS) += -march=c64x+
551         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
552         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
553         CPU_LDFLAGS-y += $(CPU_CFLAGS)
554 endif
555
556 ifeq ($(TARGET_ARCH),arc)
557         CPU_CFLAGS-y += -mlock -mswape
558         CPU_CFLAGS-$(CONFIG_ARC_CPU_700) += -mA7
559         CPU_LDFLAGS-y += $(CPU_CFLAGS) -marclinux
560 endif
561
562 $(eval $(call check-gcc-var,$(PIEFLAG_NAME)))
563 PIEFLAG := $(CFLAG_$(PIEFLAG_NAME))
564 ifeq ($(PIEFLAG),)
565 PIEFLAG := $(PICFLAG)
566 endif
567 # We need to keep track of both the CC PIE flag (above) as
568 # well as the LD PIE flag (below) because we can't rely on
569 # gcc passing -pie if we used -fPIE. We need to directly use -pie
570 # instead of -Wl,-pie as gcc picks up the wrong startfile/endfile
571 $(eval $(call cache-output-var,LDPIEFLAG,$(CC) -Wl$(comma)--help 2>/dev/null | grep -q -- -pie && echo "-pie"))
572
573 # Check for --as-needed support in linker
574 ifndef LD_FLAG_ASNEEDED
575 _LD_FLAG_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -- --as-needed)
576 ifneq ($(_LD_FLAG_ASNEEDED),)
577 export LD_FLAG_ASNEEDED:=--as-needed
578 endif
579 endif
580 ifndef LD_FLAG_NO_ASNEEDED
581 ifdef LD_FLAG_ASNEEDED
582 export LD_FLAG_NO_ASNEEDED:=--no-as-needed
583 endif
584 endif
585 ifndef CC_FLAG_ASNEEDED
586 ifdef LD_FLAG_ASNEEDED
587 export CC_FLAG_ASNEEDED:=-Wl,$(LD_FLAG_ASNEEDED)
588 endif
589 endif
590 ifndef CC_FLAG_NO_ASNEEDED
591 ifdef LD_FLAG_NO_ASNEEDED
592 export CC_FLAG_NO_ASNEEDED:=-Wl,$(LD_FLAG_NO_ASNEEDED)
593 endif
594 endif
595 link.asneeded = $(if $(findstring yy,$(CC_FLAG_ASNEEDED)$(CC_FLAG_NO_ASNEEDED)),$(CC_FLAG_ASNEEDED) $(1) $(CC_FLAG_NO_ASNEEDED))
596
597 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
598 ifndef ASNEEDED
599 export ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
600
601 # Only used in installed libc.so linker script
602 ifeq ($(UCLIBC_HAS_BACKTRACE),y)
603 ifeq ($(HARDWIRED_ABSPATH),y)
604 UBACKTRACE_FULL_NAME := $(subst //,/,$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO))
605 else
606 UBACKTRACE_FULL_NAME := $(UBACKTRACE_DSO)
607 endif
608 export UBACKTRACE_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && \
609         echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_FULL_NAME) ) )" || \
610         echo "GROUP ( $(UBACKTRACE_FULL_NAME) )")
611 else
612 export UBACKTRACE_ASNEEDED:=""
613 endif
614 endif
615
616 # Add a bunch of extra pedantic annoyingly strict checks
617 WARNING_FLAGS = -Wstrict-prototypes -Wstrict-aliasing
618 ifeq ($(EXTRA_WARNINGS),y)
619 WARNING_FLAGS += \
620         -Wformat=2 \
621         -Wmissing-noreturn \
622         -Wmissing-format-attribute \
623         -Wmissing-prototypes \
624         -Wmissing-declarations \
625         -Wnested-externs \
626         -Wnonnull \
627         -Wold-style-declaration \
628         -Wold-style-definition \
629         -Wshadow \
630         -Wundef
631 # Works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
632 WARNING_FLAGS-gcc-4 += -Wdeclaration-after-statement
633 endif
634 WARNING_FLAGS += $(WARNING_FLAGS-gcc-$(GCC_MAJOR_VER))
635 $(foreach w,$(WARNING_FLAGS),$(eval $(call check-gcc-var,$(w))))
636 XWARNINGS = $(call qstrip,$(WARNINGS)) $(foreach w,$(WARNING_FLAGS),$(CFLAG_$(w)))
637
638 CPU_CFLAGS=$(call qstrip,$(CPU_CFLAGS-y))
639
640 # Save the tested flag in a single variable and force it to be
641 # evaluated just once.  Then use that computed value.
642 $(eval $(call check-gcc-var,-fno-stack-protector))
643 SSP_DISABLE_FLAGS ?= $(CFLAG_-fno-stack-protector)
644 ifeq ($(UCLIBC_BUILD_SSP),y)
645 $(eval $(call check-gcc-var,-fno-stack-protector-all))
646 $(eval $(call check-gcc-var,-fstack-protector))
647 $(eval $(call check-gcc-var,-fstack-protector-all))
648 SSP_CFLAGS := $(CFLAG_-fno-stack-protector-all)
649 SSP_CFLAGS += $(CFLAG_-fstack-protector)
650 SSP_ALL_CFLAGS ?= $(CFLAG_-fstack-protector-all)
651 else
652 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
653 endif
654
655 # Collect all CFLAGS components
656 CFLAGS := $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
657         -nostdinc -I$(top_builddir)include \
658         -I$(top_srcdir)include -include libc-symbols.h \
659         -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH) \
660         -I$(top_srcdir)libc/sysdeps/linux \
661         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) \
662         -I$(top_srcdir)ldso/include -I.
663 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
664 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
665 endif
666
667 # We need this to be checked within libc-symbols.h
668 ifneq ($(HAVE_SHARED),y)
669 CFLAGS += -DSTATIC
670 endif
671
672 $(eval $(call check-ld-var,--warn-once))
673 $(eval $(call check-ld-var,--sort-common))
674 $(eval $(call check-ld-var,--discard-all))
675 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared \
676         -Wl,--warn-common $(CFLAG_-Wl--warn-once) -Wl,-z,combreloc
677 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
678 #$(eval $(call check-ld-var,--gc-sections))
679 #LDFLAGS_NOSTRIP += $(LDFLAG_--gc-sections)
680
681 $(eval $(call check-gcc-var,-fdata-sections))
682 $(eval $(call check-gcc-var,-ffunction-sections))
683
684 ifeq ($(UCLIBC_BUILD_RELRO),y)
685 LDFLAGS_NOSTRIP+=-Wl,-z,relro
686 endif
687
688 ifeq ($(UCLIBC_BUILD_NOW),y)
689 LDFLAGS_NOSTRIP+=-Wl,-z,now
690 endif
691
692 ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
693 # Be sure that binutils support it
694 $(eval $(call check-ld-var,--hash-style=gnu))
695 ifeq ($(LDFLAG_--hash-style=gnu),)
696 ifneq ($(filter-out $(clean_targets) CLEAN_% install_headers headers-y,$(MAKECMDGOALS)),)
697 $(error Your binutils do not support --hash-style option, while you want to use it)
698 endif
699 else
700 LDFLAGS_NOSTRIP += $(CFLAG_-Wl--hash-style=gnu)
701 endif
702 endif
703
704 LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
705 ifeq ($(DODEBUG),y)
706 CFLAGS += -O0 -g3 -DDEBUG
707 else
708 CFLAGS += $(OPTIMIZATION)
709 endif
710 ifeq ($(DOSTRIP),y)
711 LDFLAGS += -Wl,-s
712 else
713 STRIPTOOL := true -Stripping_disabled
714 endif
715 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
716 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
717 endif
718
719 ifeq ($(DOMULTI),y)
720 # we try to compile all sources at once into an object (IMA), but
721 # gcc-3.3.x does not support it
722 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
723 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
724 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
725 ifeq ($(GCC_MAJOR_VER),3)
726 DOMULTI:=n
727 else
728 $(eval $(call check-gcc-var,--combine))
729 CFLAGS += $(CFLAG_--combine)
730 endif
731 else
732 DOMULTI:=n
733 endif
734
735 ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
736 LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
737 endif
738
739 ifeq ($(UCLIBC_HAS_THREADS),y)
740 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
741         PTNAME := nptl
742         CFLAGS += -DHAVE_FORCED_UNWIND
743 else
744 ifeq ($(LINUXTHREADS_OLD),y)
745         PTNAME := linuxthreads.old
746 else
747         PTNAME := linuxthreads
748 endif
749 endif
750 PTDIR := libpthread/$(PTNAME)
751 # set up system dependencies include dirs (NOTE: order matters!)
752 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
753 PTINC:= -I$(top_builddir)$(PTDIR)                                       \
754         -I$(top_srcdir)$(PTDIR)                                         \
755         $(if $(TARGET_SUBARCH),-I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/$(TARGET_SUBARCH)) \
756         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)  \
757         -I$(top_builddir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                \
758         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                  \
759         -I$(top_builddir)$(PTDIR)/sysdeps/unix/sysv/linux               \
760         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux                 \
761         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread                         \
762         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread/bits                    \
763         -I$(top_srcdir)$(PTDIR)/sysdeps/generic
764 #
765 # Test for TLS if NPTL support was selected.
766 #
767 GCC_HAS_TLS=$(shell \
768         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
769 ifneq ($(GCC_HAS_TLS),)
770 gcc_tls_test_fail:
771         @echo "####";
772         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
773         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
774         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
775         @echo "#### about this problem.";
776         @echo "####";
777         @echo "#### Exiting...";
778         @echo "####";
779         @exit 1;
780 endif
781 else
782 PTINC := \
783         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
784         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
785         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux \
786         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread \
787         -I$(top_srcdir)$(PTDIR) \
788         -I$(top_srcdir)libpthread
789 endif
790 CFLAGS+=$(PTINC)
791 else
792         PTNAME :=
793         PTINC  :=
794 endif
795 CFLAGS += -I$(top_srcdir)libc/sysdeps/linux/common
796
797 #CFLAGS += -iwithprefix include-fixed -iwithprefix include
798 $(eval $(call cache-output-var,CC_IPREFIX,$(CC) -print-file-name=include))
799 CC_INC := -isystem $(dir $(CC_IPREFIX))include-fixed -isystem $(CC_IPREFIX)
800 CFLAGS += $(CC_INC)
801
802 CFLAGS += -I$(KERNEL_HEADERS)
803
804 ifneq ($(DOASSERTS),y)
805 CFLAGS+=-DNDEBUG
806 endif
807
808 ifeq ($(SYMBOL_PREFIX),_)
809 CFLAGS+=-D__UCLIBC_UNDERSCORES__
810 endif
811
812 # Keep the check_as from being needlessly executed
813 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
814 $(eval $(call check-as-var,--noexecstack))
815 endif
816 ASFLAGS = $(ASFLAG_--noexecstack)
817
818 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
819 $(eval $(call cache-output-var,LIBGCC,$(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name))
820 $(eval $(call cache-output-var,LIBGCC_EH,$(CC) $(LIBGCC_CFLAGS) -print-file-name=libgcc_eh.a))
821 # with -O0 we (e.g. lockf) might end up with references to
822 # _Unwind_Resume, so pull in gcc_eh in this case..
823 LIBGCC_DIR:=$(dir $(LIBGCC))
824 LIBGCC += $(if $(DODEBUG),$(LIBGCC_EH))
825
826 # moved from libpthread/linuxthreads
827 ifeq ($(UCLIBC_CTOR_DTOR),y)
828 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
829 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
830 endif
831
832 LOCAL_INSTALL_PATH := $(if $(O),$(O)/)install_dir
833
834 PTHREAD_GENERATE_MANGLE ?= -n "s/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*\$$/\#define \1 \2/p"