OSDN Git Service

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