OSDN Git Service

ldd: Add ARC support
[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 ifeq ($(GCC_MAJOR_VER),4)
284 # shrinks code, results are from 4.0.2
285 # 0.36%
286 $(eval $(call check-gcc-var,-fno-tree-loop-optimize))
287 OPTIMIZATION += $(CFLAG_-fno-tree-loop-optimize)
288 # 0.34%
289 $(eval $(call check-gcc-var,-fno-tree-dominator-opts))
290 OPTIMIZATION += $(CFLAG_-fno-tree-dominator-opts)
291 # 0.1%
292 $(eval $(call check-gcc-var,-fno-strength-reduce))
293 OPTIMIZATION += $(CFLAG_-fno-strength-reduce)
294 endif
295
296
297 # CPU_CFLAGS-y contain options which are not warnings,
298 # not include or library paths, and not optimizations.
299
300 # Why -funsigned-char: I hunted a bug related to incorrect
301 # sign extension of 'char' type for 10 hours straight. Not fun.
302 CPU_CFLAGS-y := -funsigned-char -fno-builtin
303
304 $(eval $(call check-gcc-var,-fno-asm))
305 CPU_CFLAGS-y += $(CFLAG_-fno-asm)
306
307 LDADD_LIBFLOAT=
308 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
309 # If -msoft-float isn't supported, we want an error anyway.
310 # Hmm... might need to revisit this for arm since it has 2 different
311 # soft float encodings.
312 ifneq ($(TARGET_ARCH),nios)
313 ifneq ($(TARGET_ARCH),nios2)
314 ifneq ($(TARGET_ARCH),sh)
315 ifneq ($(TARGET_ARCH),c6x)
316 CPU_CFLAGS-y += -msoft-float
317 endif
318 endif
319 endif
320 endif
321 ifeq ($(TARGET_ARCH),arm)
322 # No longer needed with current toolchains, but leave it here for now.
323 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
324 #    LDADD_LIBFLOAT=-lfloat
325 endif
326 endif
327
328 $(eval $(call check-gcc-var,-std=gnu99))
329 CPU_CFLAGS-y += $(CFLAG_-std=gnu99)
330
331 CPU_CFLAGS-$(UCLIBC_FORMAT_SHARED_FLAT) += -mid-shared-library
332 CPU_CFLAGS-$(UCLIBC_FORMAT_FLAT_SEP_DATA) += -msep-data
333
334 CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN) += -Wl,-EL
335 CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)    += -Wl,-EB
336
337 PICFLAG-y := -fPIC
338 PICFLAG-$(UCLIBC_FORMAT_FDPIC_ELF) := -mfdpic
339 PICFLAG-$(UCLIBC_FORMAT_DSBT_ELF)  := -mdsbt -fpic
340 PICFLAG := $(PICFLAG-y)
341 PIEFLAG_NAME:=-fPIE
342
343 # Some nice CPU specific optimizations
344 ifeq ($(TARGET_ARCH),i386)
345 $(eval $(call check-gcc-var,-fomit-frame-pointer))
346         OPTIMIZATION += $(CFLAG_-fomit-frame-pointer)
347
348 ifeq ($(CONFIG_386)$(CONFIG_486)$(CONFIG_586),y)
349         # TODO: Change this to a gcc version check.  This bug
350         # should be fixed with at least gcc-4.3.
351         # Non-SSE capable processor.
352         # NB: this may make SSE insns segfault!
353         # -O1 -march=pentium3, -Os -msse etc are known to be affected.
354         # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13685
355         # -m32 is needed if host is 64-bit
356         OPTIMIZATION+=$(call check_gcc,-m32 -mpreferred-stack-boundary=2,)
357 else
358 $(eval $(call check-gcc-var,-mpreferred-stack-boundary=4))
359         OPTIMIZATION += $(CFLAG_-mpreferred-stack-boundary=4)
360 endif
361
362         # Choice of alignment (please document why!)
363         #  -falign-labels: in-line labels
364         #  (reachable by normal code flow, aligning will insert nops
365         #  which will be executed - may even make things slower)
366         #  -falign-jumps: reachable only by a jump
367         # Generic: no alignment at all (smallest code)
368         GCC_FALIGN=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,-malign-jumps=1 -malign-loops=1)
369         OPTIMIZATION+=$(GCC_FALIGN)
370
371         # Putting each function and data object into its own section
372         # allows for kbytes of less text if users link against static uclibc
373         # using ld --gc-sections.
374         # ld 2.18 can't do that (yet?) for shared libraries, so we itself
375         # do not use --gc-sections at shared lib link time.
376         # However, in combination with sections being sorted by alignment
377         # it does result in much reduced padding:
378         #   text    data     bss     dec     hex
379         # 235319    1472    5992  242783   3b45f old.so
380         # 234104    1472    5980  241556   3af94 new.so
381         # Without -ffunction-sections, all functions will get aligned
382         # to 4 byte boundary by as/ld. This is arguably a bug in as.
383         # It specifies 4 byte align for .text even if not told to do so:
384         # Idx Name          Size      VMA       LMA       File off  Algn
385         #   0 .text         xxxxxxxx  00000000  00000000  xxxxxxxx  2**2 <===!
386         CPU_CFLAGS-y  += $(CFLAG_-ffunction-sections) $(CFLAG_-fdata-sections)
387         CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-common)
388 $(eval $(call check-ld-var,--sort-section=alignment))
389         CPU_LDFLAGS-y += $(CFLAG_-Wl--sort-section=alignment)
390
391         CPU_LDFLAGS-y+=-m32
392         CPU_CFLAGS-y+=-m32
393 endif
394
395 ifeq ($(TARGET_ARCH),sparc)
396         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
397         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
398         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
399         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
400 endif
401
402 ifeq ($(TARGET_ARCH),arm)
403         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
404         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
405         CPU_CFLAGS-$(COMPILE_IN_THUMB_MODE)+=-mthumb
406 endif
407
408 ifeq ($(TARGET_ARCH),metag)
409         SYMBOL_PREFIX=_
410         CPU_CFLAGS-$(CONFIG_META_1_2)+=
411         CPU_CFLAGS-$(CONFIG_META_2_1)+=-Wa,-mcpu=metac21
412 endif
413
414 ifeq ($(TARGET_ARCH),mips)
415         OPTIMIZATION+=-mno-split-addresses
416         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
417         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
418         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
419         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
420         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
421         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32R2)+=-march=mips32r2 -mtune=mips32r2
422         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
423         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
424                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
425                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
426         endif
427         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
428                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
429                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
430         endif
431         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
432         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
433         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
434 endif
435
436 ifeq ($(TARGET_ARCH),nios)
437         OPTIMIZATION+=-funaligned-struct-hack
438         CPU_LDFLAGS-y+=-Wl,-m32
439         CPU_CFLAGS-y+=-Wl,-m32
440 endif
441
442 ifeq ($(TARGET_ARCH),sh)
443 $(eval $(call check-gcc-var,-mprefergot))
444         OPTIMIZATION += $(CFLAG_-mprefergot)
445         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
446         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
447         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
448         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
449 ifeq ($(UCLIBC_HAS_FPU),y)
450         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
451         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
452 else
453         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
454         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
455 endif
456 endif
457
458 ifeq ($(TARGET_ARCH),sh64)
459         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
460         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
461         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
462 endif
463
464 ifeq ($(TARGET_ARCH),h8300)
465         SYMBOL_PREFIX=_
466         CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
467         CPU_LDFLAGS-$(CONFIG_H8S)   += -Wl,-ms8300s
468         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
469         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
470 endif
471
472 ifeq ($(TARGET_ARCH),i960)
473         OPTIMIZATION+=-mh -mint32 #-fsigned-char
474 endif
475
476 ifeq ($(TARGET_ARCH),e1)
477         OPTIMIZATION+=-mgnu-param
478 endif
479
480 ifeq ($(TARGET_ARCH),cris)
481         CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
482         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
483         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
484         PICFLAG:=-fpic
485         PIEFLAG_NAME:=-fpie
486 endif
487
488 ifeq ($(TARGET_ARCH),m68k)
489         # -fPIC is only supported for 68020 and above.  It is not supported
490         # for 68000, 68010, or Coldfire.
491         PICFLAG:=-fpic
492         PIEFLAG_NAME:=-fpie
493 endif
494
495 ifeq ($(TARGET_ARCH),powerpc)
496 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
497 # enough. Therefore use -fpic which will reduce code size and generates
498 # faster code.
499         PICFLAG:=-fpic
500         PIEFLAG_NAME:=-fpie
501         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)
502         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
503         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES"
504
505 endif
506
507 ifeq ($(TARGET_ARCH),bfin)
508         SYMBOL_PREFIX=_
509 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
510         CPU_CFLAGS-y:=-mfdpic
511         CPU_LDFLAGS-y += -Wl,-melf32bfinfd
512         PICFLAG:=-fpic
513         PIEFLAG_NAME:=-fpie
514 endif
515 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
516         PICFLAG := -mleaf-id-shared-library
517 endif
518 endif
519
520 ifeq ($(TARGET_ARCH),frv)
521         CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
522         # Using -pie causes the program to have an interpreter, which is
523         # forbidden, so we must make do with -shared.  Unfortunately,
524         # -shared by itself would get us global function descriptors
525         # and calls through PLTs, dynamic resolution of symbols, etc,
526         # which would break as well, but -Bsymbolic comes to the rescue.
527         export LDPIEFLAG:=-shared -Wl,-Bsymbolic
528         UCLIBC_LDSO=ld.so.1
529 endif
530
531 ifeq ($(strip $(TARGET_ARCH)),avr32)
532        CPU_CFLAGS-$(CONFIG_AVR32_AP7)  += -march=ap
533        CPU_CFLAGS-$(CONFIG_LINKRELAX)  += -mrelax
534        CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
535 endif
536
537 ifeq ($(TARGET_ARCH),i960)
538       SYMBOL_PREFIX=_
539 endif
540
541 ifeq ($(TARGET_ARCH),v850)
542       SYMBOL_PREFIX=_
543 endif
544
545 ifeq ($(TARGET_ARCH),c6x)
546         PIEFLAG:=
547         CPU_CFLAGS-$(CONFIG_TMS320C64X) += -march=c64x
548         CPU_CFLAGS-$(CONFIG_TMS320C64XPLUS) += -march=c64x+
549         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
550         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
551         CPU_LDFLAGS-y += $(CPU_CFLAGS)
552 endif
553
554 $(eval $(call check-gcc-var,$(PIEFLAG_NAME)))
555 PIEFLAG := $(CFLAG_$(PIEFLAG_NAME))
556 ifeq ($(PIEFLAG),)
557 PIEFLAG := $(PICFLAG)
558 endif
559 # We need to keep track of both the CC PIE flag (above) as
560 # well as the LD PIE flag (below) because we can't rely on
561 # gcc passing -pie if we used -fPIE. We need to directly use -pie
562 # instead of -Wl,-pie as gcc picks up the wrong startfile/endfile
563 $(eval $(call cache-output-var,LDPIEFLAG,$(CC) -Wl$(comma)--help 2>/dev/null | grep -q -- -pie && echo "-pie"))
564
565 # Check for --as-needed support in linker
566 ifndef LD_FLAG_ASNEEDED
567 _LD_FLAG_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -- --as-needed)
568 ifneq ($(_LD_FLAG_ASNEEDED),)
569 export LD_FLAG_ASNEEDED:=--as-needed
570 endif
571 endif
572 ifndef LD_FLAG_NO_ASNEEDED
573 ifdef LD_FLAG_ASNEEDED
574 export LD_FLAG_NO_ASNEEDED:=--no-as-needed
575 endif
576 endif
577 ifndef CC_FLAG_ASNEEDED
578 ifdef LD_FLAG_ASNEEDED
579 export CC_FLAG_ASNEEDED:=-Wl,$(LD_FLAG_ASNEEDED)
580 endif
581 endif
582 ifndef CC_FLAG_NO_ASNEEDED
583 ifdef LD_FLAG_NO_ASNEEDED
584 export CC_FLAG_NO_ASNEEDED:=-Wl,$(LD_FLAG_NO_ASNEEDED)
585 endif
586 endif
587 link.asneeded = $(if $(findstring yy,$(CC_FLAG_ASNEEDED)$(CC_FLAG_NO_ASNEEDED)),$(CC_FLAG_ASNEEDED) $(1) $(CC_FLAG_NO_ASNEEDED))
588
589 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
590 ifndef ASNEEDED
591 export ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
592
593 # Only used in installed libc.so linker script
594 ifeq ($(UCLIBC_HAS_BACKTRACE),y)
595 ifeq ($(HARDWIRED_ABSPATH),y)
596 UBACKTRACE_FULL_NAME := $(subst //,/,$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO))
597 else
598 UBACKTRACE_FULL_NAME := $(UBACKTRACE_DSO)
599 endif
600 export UBACKTRACE_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && \
601         echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_FULL_NAME) ) )" || \
602         echo "GROUP ( $(UBACKTRACE_FULL_NAME) )")
603 else
604 export UBACKTRACE_ASNEEDED:=""
605 endif
606 endif
607
608 # Add a bunch of extra pedantic annoyingly strict checks
609 WARNING_FLAGS = -Wstrict-prototypes -Wstrict-aliasing
610 ifeq ($(EXTRA_WARNINGS),y)
611 WARNING_FLAGS += \
612         -Wformat=2 \
613         -Wmissing-noreturn \
614         -Wmissing-format-attribute \
615         -Wmissing-prototypes \
616         -Wmissing-declarations \
617         -Wnested-externs \
618         -Wnonnull \
619         -Wold-style-declaration \
620         -Wold-style-definition \
621         -Wshadow \
622         -Wundef
623 # Works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
624 WARNING_FLAGS-gcc-4 += -Wdeclaration-after-statement
625 endif
626 WARNING_FLAGS += $(WARNING_FLAGS-gcc-$(GCC_MAJOR_VER))
627 $(foreach w,$(WARNING_FLAGS),$(eval $(call check-gcc-var,$(w))))
628 XWARNINGS = $(call qstrip,$(WARNINGS)) $(foreach w,$(WARNING_FLAGS),$(CFLAG_$(w)))
629
630 CPU_CFLAGS=$(call qstrip,$(CPU_CFLAGS-y))
631
632 # Save the tested flag in a single variable and force it to be
633 # evaluated just once.  Then use that computed value.
634 $(eval $(call check-gcc-var,-fno-stack-protector))
635 SSP_DISABLE_FLAGS ?= $(CFLAG_-fno-stack-protector)
636 ifeq ($(UCLIBC_BUILD_SSP),y)
637 $(eval $(call check-gcc-var,-fno-stack-protector-all))
638 $(eval $(call check-gcc-var,-fstack-protector))
639 $(eval $(call check-gcc-var,-fstack-protector-all))
640 SSP_CFLAGS := $(CFLAG_-fno-stack-protector-all)
641 SSP_CFLAGS += $(CFLAG_-fstack-protector)
642 SSP_ALL_CFLAGS ?= $(CFLAG_-fstack-protector-all)
643 else
644 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
645 endif
646
647 # Collect all CFLAGS components
648 CFLAGS := $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
649         -nostdinc -I$(top_builddir)include \
650         -I$(top_srcdir)include -include libc-symbols.h \
651         -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH) \
652         -I$(top_srcdir)libc/sysdeps/linux \
653         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) \
654         -I$(top_srcdir)ldso/include -I.
655 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
656 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
657 endif
658
659 # We need this to be checked within libc-symbols.h
660 ifneq ($(HAVE_SHARED),y)
661 CFLAGS += -DSTATIC
662 endif
663
664 $(eval $(call check-ld-var,--warn-once))
665 $(eval $(call check-ld-var,--sort-common))
666 $(eval $(call check-ld-var,--discard-all))
667 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared \
668         -Wl,--warn-common $(CFLAG_-Wl--warn-once) -Wl,-z,combreloc
669 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
670 #$(eval $(call check-ld-var,--gc-sections))
671 #LDFLAGS_NOSTRIP += $(LDFLAG_--gc-sections)
672
673 $(eval $(call check-gcc-var,-fdata-sections))
674 $(eval $(call check-gcc-var,-ffunction-sections))
675
676 ifeq ($(UCLIBC_BUILD_RELRO),y)
677 LDFLAGS_NOSTRIP+=-Wl,-z,relro
678 endif
679
680 ifeq ($(UCLIBC_BUILD_NOW),y)
681 LDFLAGS_NOSTRIP+=-Wl,-z,now
682 endif
683
684 ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
685 # Be sure that binutils support it
686 $(eval $(call check-ld-var,--hash-style=gnu))
687 ifeq ($(LDFLAG_--hash-style=gnu),)
688 ifneq ($(filter-out $(clean_targets) CLEAN_% install_headers headers-y,$(MAKECMDGOALS)),)
689 $(error Your binutils do not support --hash-style option, while you want to use it)
690 endif
691 else
692 LDFLAGS_NOSTRIP += $(CFLAG_-Wl--hash-style=gnu)
693 endif
694 endif
695
696 LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
697 ifeq ($(DODEBUG),y)
698 CFLAGS += -O0 -g3 -DDEBUG
699 else
700 CFLAGS += $(OPTIMIZATION)
701 endif
702 ifeq ($(DOSTRIP),y)
703 LDFLAGS += -Wl,-s
704 else
705 STRIPTOOL := true -Stripping_disabled
706 endif
707 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
708 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
709 endif
710
711 ifeq ($(DOMULTI),y)
712 # we try to compile all sources at once into an object (IMA), but
713 # gcc-3.3.x does not support it
714 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
715 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
716 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
717 ifeq ($(GCC_MAJOR_VER),3)
718 DOMULTI:=n
719 else
720 $(eval $(call check-gcc-var,--combine))
721 CFLAGS += $(CFLAG_--combine)
722 endif
723 else
724 DOMULTI:=n
725 endif
726
727 ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
728 LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
729 endif
730
731 ifeq ($(UCLIBC_HAS_THREADS),y)
732 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
733         PTNAME := nptl
734         CFLAGS += -DHAVE_FORCED_UNWIND
735 else
736 ifeq ($(LINUXTHREADS_OLD),y)
737         PTNAME := linuxthreads.old
738 else
739         PTNAME := linuxthreads
740 endif
741 endif
742 PTDIR := libpthread/$(PTNAME)
743 # set up system dependencies include dirs (NOTE: order matters!)
744 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
745 PTINC:= -I$(top_builddir)$(PTDIR)                                       \
746         -I$(top_srcdir)$(PTDIR)                                         \
747         $(if $(TARGET_SUBARCH),-I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/$(TARGET_SUBARCH)) \
748         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)  \
749         -I$(top_builddir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                \
750         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                  \
751         -I$(top_builddir)$(PTDIR)/sysdeps/unix/sysv/linux               \
752         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux                 \
753         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread                         \
754         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread/bits                    \
755         -I$(top_srcdir)$(PTDIR)/sysdeps/generic
756 #
757 # Test for TLS if NPTL support was selected.
758 #
759 GCC_HAS_TLS=$(shell \
760         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
761 ifneq ($(GCC_HAS_TLS),)
762 gcc_tls_test_fail:
763         @echo "####";
764         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
765         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
766         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
767         @echo "#### about this problem.";
768         @echo "####";
769         @echo "#### Exiting...";
770         @echo "####";
771         @exit 1;
772 endif
773 else
774 PTINC := \
775         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
776         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
777         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux \
778         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread \
779         -I$(top_srcdir)$(PTDIR) \
780         -I$(top_srcdir)libpthread
781 endif
782 CFLAGS+=$(PTINC)
783 else
784         PTNAME :=
785         PTINC  :=
786 endif
787 CFLAGS += -I$(top_srcdir)libc/sysdeps/linux/common
788
789 #CFLAGS += -iwithprefix include-fixed -iwithprefix include
790 $(eval $(call cache-output-var,CC_IPREFIX,$(CC) -print-file-name=include))
791 CC_INC := -isystem $(dir $(CC_IPREFIX))include-fixed -isystem $(CC_IPREFIX)
792 CFLAGS += $(CC_INC)
793
794 CFLAGS += -I$(KERNEL_HEADERS)
795
796 ifneq ($(DOASSERTS),y)
797 CFLAGS+=-DNDEBUG
798 endif
799
800 ifeq ($(SYMBOL_PREFIX),_)
801 CFLAGS+=-D__UCLIBC_UNDERSCORES__
802 endif
803
804 # Keep the check_as from being needlessly executed
805 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
806 $(eval $(call check-as-var,--noexecstack))
807 endif
808 ASFLAGS = $(ASFLAG_--noexecstack)
809
810 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
811 $(eval $(call cache-output-var,LIBGCC,$(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name))
812 $(eval $(call cache-output-var,LIBGCC_EH,$(CC) $(LIBGCC_CFLAGS) -print-file-name=libgcc_eh.a))
813 # with -O0 we (e.g. lockf) might end up with references to
814 # _Unwind_Resume, so pull in gcc_eh in this case..
815 LIBGCC_DIR:=$(dir $(LIBGCC))
816 LIBGCC += $(if $(DODEBUG),$(LIBGCC_EH))
817
818 # moved from libpthread/linuxthreads
819 ifeq ($(UCLIBC_CTOR_DTOR),y)
820 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
821 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
822 endif
823
824 LOCAL_INSTALL_PATH := $(if $(O),$(O)/)install_dir
825
826 PTHREAD_GENERATE_MANGLE ?= -n "s/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*\$$/\#define \1 \2/p"