OSDN Git Service

libc: Fix sync_file_range.c for MIPS64 N32 ABI
[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         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
425                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
426                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
427         endif
428         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
429                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
430                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
431         endif
432         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
433         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
434         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
435 endif
436
437 ifeq ($(TARGET_ARCH),nios)
438         OPTIMIZATION+=-funaligned-struct-hack
439         CPU_LDFLAGS-y+=-Wl,-m32
440         CPU_CFLAGS-y+=-Wl,-m32
441 endif
442
443 ifeq ($(TARGET_ARCH),sh)
444 $(eval $(call check-gcc-var,-mprefergot))
445         OPTIMIZATION += $(CFLAG_-mprefergot)
446         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
447         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
448         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
449         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
450 ifeq ($(UCLIBC_HAS_FPU),y)
451         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
452         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
453 else
454         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
455         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
456 endif
457 endif
458
459 ifeq ($(TARGET_ARCH),sh64)
460         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
461         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
462         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
463 endif
464
465 ifeq ($(TARGET_ARCH),h8300)
466         SYMBOL_PREFIX=_
467         CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
468         CPU_LDFLAGS-$(CONFIG_H8S)   += -Wl,-ms8300s
469         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
470         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
471 endif
472
473 ifeq ($(TARGET_ARCH),i960)
474         OPTIMIZATION+=-mh -mint32 #-fsigned-char
475 endif
476
477 ifeq ($(TARGET_ARCH),e1)
478         OPTIMIZATION+=-mgnu-param
479 endif
480
481 ifeq ($(TARGET_ARCH),cris)
482         CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
483         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
484         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
485         PICFLAG:=-fpic
486         PIEFLAG_NAME:=-fpie
487 endif
488
489 ifeq ($(TARGET_ARCH),m68k)
490         # -fPIC is only supported for 68020 and above.  It is not supported
491         # for 68000, 68010, or Coldfire.
492         PICFLAG:=-fpic
493         PIEFLAG_NAME:=-fpie
494 endif
495
496 ifeq ($(TARGET_ARCH),powerpc)
497 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
498 # enough. Therefore use -fpic which will reduce code size and generates
499 # faster code.
500         PICFLAG:=-fpic
501         PIEFLAG_NAME:=-fpie
502         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)
503         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
504         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES"
505
506 endif
507
508 ifeq ($(TARGET_ARCH),bfin)
509         SYMBOL_PREFIX=_
510 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
511         CPU_CFLAGS-y:=-mfdpic
512         CPU_LDFLAGS-y += -Wl,-melf32bfinfd
513         PICFLAG:=-fpic
514         PIEFLAG_NAME:=-fpie
515 endif
516 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
517         PICFLAG := -mleaf-id-shared-library
518 endif
519 endif
520
521 ifeq ($(TARGET_ARCH),frv)
522         CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
523         # Using -pie causes the program to have an interpreter, which is
524         # forbidden, so we must make do with -shared.  Unfortunately,
525         # -shared by itself would get us global function descriptors
526         # and calls through PLTs, dynamic resolution of symbols, etc,
527         # which would break as well, but -Bsymbolic comes to the rescue.
528         export LDPIEFLAG:=-shared -Wl,-Bsymbolic
529         UCLIBC_LDSO=ld.so.1
530 endif
531
532 ifeq ($(strip $(TARGET_ARCH)),avr32)
533        CPU_CFLAGS-$(CONFIG_AVR32_AP7)  += -march=ap
534        CPU_CFLAGS-$(CONFIG_LINKRELAX)  += -mrelax
535        CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
536 endif
537
538 ifeq ($(TARGET_ARCH),i960)
539       SYMBOL_PREFIX=_
540 endif
541
542 ifeq ($(TARGET_ARCH),v850)
543       SYMBOL_PREFIX=_
544 endif
545
546 ifeq ($(TARGET_ARCH),c6x)
547         PIEFLAG:=
548         CPU_CFLAGS-$(CONFIG_TMS320C64X) += -march=c64x
549         CPU_CFLAGS-$(CONFIG_TMS320C64XPLUS) += -march=c64x+
550         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
551         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
552         CPU_LDFLAGS-y += $(CPU_CFLAGS)
553 endif
554
555 ifeq ($(TARGET_ARCH),arc)
556         CPU_CFLAGS-y += -mlock -mswape
557         CPU_CFLAGS-$(CONFIG_ARC_CPU_700) += -mA7
558         CPU_LDFLAGS-y += $(CPU_CFLAGS) -marclinux
559 endif
560
561 $(eval $(call check-gcc-var,$(PIEFLAG_NAME)))
562 PIEFLAG := $(CFLAG_$(PIEFLAG_NAME))
563 ifeq ($(PIEFLAG),)
564 PIEFLAG := $(PICFLAG)
565 endif
566 # We need to keep track of both the CC PIE flag (above) as
567 # well as the LD PIE flag (below) because we can't rely on
568 # gcc passing -pie if we used -fPIE. We need to directly use -pie
569 # instead of -Wl,-pie as gcc picks up the wrong startfile/endfile
570 $(eval $(call cache-output-var,LDPIEFLAG,$(CC) -Wl$(comma)--help 2>/dev/null | grep -q -- -pie && echo "-pie"))
571
572 # Check for --as-needed support in linker
573 ifndef LD_FLAG_ASNEEDED
574 _LD_FLAG_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -- --as-needed)
575 ifneq ($(_LD_FLAG_ASNEEDED),)
576 export LD_FLAG_ASNEEDED:=--as-needed
577 endif
578 endif
579 ifndef LD_FLAG_NO_ASNEEDED
580 ifdef LD_FLAG_ASNEEDED
581 export LD_FLAG_NO_ASNEEDED:=--no-as-needed
582 endif
583 endif
584 ifndef CC_FLAG_ASNEEDED
585 ifdef LD_FLAG_ASNEEDED
586 export CC_FLAG_ASNEEDED:=-Wl,$(LD_FLAG_ASNEEDED)
587 endif
588 endif
589 ifndef CC_FLAG_NO_ASNEEDED
590 ifdef LD_FLAG_NO_ASNEEDED
591 export CC_FLAG_NO_ASNEEDED:=-Wl,$(LD_FLAG_NO_ASNEEDED)
592 endif
593 endif
594 link.asneeded = $(if $(findstring yy,$(CC_FLAG_ASNEEDED)$(CC_FLAG_NO_ASNEEDED)),$(CC_FLAG_ASNEEDED) $(1) $(CC_FLAG_NO_ASNEEDED))
595
596 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
597 ifndef ASNEEDED
598 export ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
599
600 # Only used in installed libc.so linker script
601 ifeq ($(UCLIBC_HAS_BACKTRACE),y)
602 ifeq ($(HARDWIRED_ABSPATH),y)
603 UBACKTRACE_FULL_NAME := $(subst //,/,$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO))
604 else
605 UBACKTRACE_FULL_NAME := $(UBACKTRACE_DSO)
606 endif
607 export UBACKTRACE_ASNEEDED:=$(shell $(CC) -Wl,--help 2>/dev/null | grep -q -- --as-needed && \
608         echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_FULL_NAME) ) )" || \
609         echo "GROUP ( $(UBACKTRACE_FULL_NAME) )")
610 else
611 export UBACKTRACE_ASNEEDED:=""
612 endif
613 endif
614
615 # Add a bunch of extra pedantic annoyingly strict checks
616 WARNING_FLAGS = -Wstrict-prototypes -Wstrict-aliasing
617 ifeq ($(EXTRA_WARNINGS),y)
618 WARNING_FLAGS += \
619         -Wformat=2 \
620         -Wmissing-noreturn \
621         -Wmissing-format-attribute \
622         -Wmissing-prototypes \
623         -Wmissing-declarations \
624         -Wnested-externs \
625         -Wnonnull \
626         -Wold-style-declaration \
627         -Wold-style-definition \
628         -Wshadow \
629         -Wundef
630 # Works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
631 WARNING_FLAGS-gcc-4 += -Wdeclaration-after-statement
632 endif
633 WARNING_FLAGS += $(WARNING_FLAGS-gcc-$(GCC_MAJOR_VER))
634 $(foreach w,$(WARNING_FLAGS),$(eval $(call check-gcc-var,$(w))))
635 XWARNINGS = $(call qstrip,$(WARNINGS)) $(foreach w,$(WARNING_FLAGS),$(CFLAG_$(w)))
636
637 CPU_CFLAGS=$(call qstrip,$(CPU_CFLAGS-y))
638
639 # Save the tested flag in a single variable and force it to be
640 # evaluated just once.  Then use that computed value.
641 $(eval $(call check-gcc-var,-fno-stack-protector))
642 SSP_DISABLE_FLAGS ?= $(CFLAG_-fno-stack-protector)
643 ifeq ($(UCLIBC_BUILD_SSP),y)
644 $(eval $(call check-gcc-var,-fno-stack-protector-all))
645 $(eval $(call check-gcc-var,-fstack-protector))
646 $(eval $(call check-gcc-var,-fstack-protector-all))
647 SSP_CFLAGS := $(CFLAG_-fno-stack-protector-all)
648 SSP_CFLAGS += $(CFLAG_-fstack-protector)
649 SSP_ALL_CFLAGS ?= $(CFLAG_-fstack-protector-all)
650 else
651 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
652 endif
653
654 # Collect all CFLAGS components
655 CFLAGS := $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
656         -nostdinc -I$(top_builddir)include \
657         -I$(top_srcdir)include -include libc-symbols.h \
658         -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH) \
659         -I$(top_srcdir)libc/sysdeps/linux \
660         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) \
661         -I$(top_srcdir)ldso/include -I.
662 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
663 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
664 endif
665
666 # We need this to be checked within libc-symbols.h
667 ifneq ($(HAVE_SHARED),y)
668 CFLAGS += -DSTATIC
669 endif
670
671 $(eval $(call check-ld-var,--warn-once))
672 $(eval $(call check-ld-var,--sort-common))
673 $(eval $(call check-ld-var,--discard-all))
674 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared \
675         -Wl,--warn-common $(CFLAG_-Wl--warn-once) -Wl,-z,combreloc
676 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
677 #$(eval $(call check-ld-var,--gc-sections))
678 #LDFLAGS_NOSTRIP += $(LDFLAG_--gc-sections)
679
680 $(eval $(call check-gcc-var,-fdata-sections))
681 $(eval $(call check-gcc-var,-ffunction-sections))
682
683 ifeq ($(UCLIBC_BUILD_RELRO),y)
684 LDFLAGS_NOSTRIP+=-Wl,-z,relro
685 endif
686
687 ifeq ($(UCLIBC_BUILD_NOW),y)
688 LDFLAGS_NOSTRIP+=-Wl,-z,now
689 endif
690
691 ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
692 # Be sure that binutils support it
693 $(eval $(call check-ld-var,--hash-style=gnu))
694 ifeq ($(LDFLAG_--hash-style=gnu),)
695 ifneq ($(filter-out $(clean_targets) CLEAN_% install_headers headers-y,$(MAKECMDGOALS)),)
696 $(error Your binutils do not support --hash-style option, while you want to use it)
697 endif
698 else
699 LDFLAGS_NOSTRIP += $(CFLAG_-Wl--hash-style=gnu)
700 endif
701 endif
702
703 LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
704 ifeq ($(DODEBUG),y)
705 CFLAGS += -O0 -g3 -DDEBUG
706 else
707 CFLAGS += $(OPTIMIZATION)
708 endif
709 ifeq ($(DOSTRIP),y)
710 LDFLAGS += -Wl,-s
711 else
712 STRIPTOOL := true -Stripping_disabled
713 endif
714 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
715 CFLAGS += $(call qstrip,$(UCLIBC_EXTRA_CFLAGS))
716 endif
717
718 ifeq ($(DOMULTI),y)
719 # we try to compile all sources at once into an object (IMA), but
720 # gcc-3.3.x does not support it
721 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
722 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
723 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
724 ifeq ($(GCC_MAJOR_VER),3)
725 DOMULTI:=n
726 else
727 $(eval $(call check-gcc-var,--combine))
728 CFLAGS += $(CFLAG_--combine)
729 endif
730 else
731 DOMULTI:=n
732 endif
733
734 ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
735 LDFLAGS += $(call qstrip,$(UCLIBC_EXTRA_LDFLAGS))
736 endif
737
738 ifeq ($(UCLIBC_HAS_THREADS),y)
739 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
740         PTNAME := nptl
741         CFLAGS += -DHAVE_FORCED_UNWIND
742 else
743 ifeq ($(LINUXTHREADS_OLD),y)
744         PTNAME := linuxthreads.old
745 else
746         PTNAME := linuxthreads
747 endif
748 endif
749 PTDIR := libpthread/$(PTNAME)
750 # set up system dependencies include dirs (NOTE: order matters!)
751 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
752 PTINC:= -I$(top_builddir)$(PTDIR)                                       \
753         -I$(top_srcdir)$(PTDIR)                                         \
754         $(if $(TARGET_SUBARCH),-I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/$(TARGET_SUBARCH)) \
755         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)  \
756         -I$(top_builddir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                \
757         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH)                  \
758         -I$(top_builddir)$(PTDIR)/sysdeps/unix/sysv/linux               \
759         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux                 \
760         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread                         \
761         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread/bits                    \
762         -I$(top_srcdir)$(PTDIR)/sysdeps/generic
763 #
764 # Test for TLS if NPTL support was selected.
765 #
766 GCC_HAS_TLS=$(shell \
767         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
768 ifneq ($(GCC_HAS_TLS),)
769 gcc_tls_test_fail:
770         @echo "####";
771         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
772         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
773         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
774         @echo "#### about this problem.";
775         @echo "####";
776         @echo "#### Exiting...";
777         @echo "####";
778         @exit 1;
779 endif
780 else
781 PTINC := \
782         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
783         -I$(top_srcdir)$(PTDIR)/sysdeps/$(TARGET_ARCH) \
784         -I$(top_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux \
785         -I$(top_srcdir)$(PTDIR)/sysdeps/pthread \
786         -I$(top_srcdir)$(PTDIR) \
787         -I$(top_srcdir)libpthread
788 endif
789 CFLAGS+=$(PTINC)
790 else
791         PTNAME :=
792         PTINC  :=
793 endif
794 CFLAGS += -I$(top_srcdir)libc/sysdeps/linux/common
795
796 #CFLAGS += -iwithprefix include-fixed -iwithprefix include
797 $(eval $(call cache-output-var,CC_IPREFIX,$(CC) -print-file-name=include))
798 CC_INC := -isystem $(dir $(CC_IPREFIX))include-fixed -isystem $(CC_IPREFIX)
799 CFLAGS += $(CC_INC)
800
801 CFLAGS += -I$(KERNEL_HEADERS)
802
803 ifneq ($(DOASSERTS),y)
804 CFLAGS+=-DNDEBUG
805 endif
806
807 ifeq ($(SYMBOL_PREFIX),_)
808 CFLAGS+=-D__UCLIBC_UNDERSCORES__
809 endif
810
811 # Keep the check_as from being needlessly executed
812 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
813 $(eval $(call check-as-var,--noexecstack))
814 endif
815 ASFLAGS = $(ASFLAG_--noexecstack)
816
817 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
818 $(eval $(call cache-output-var,LIBGCC,$(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name))
819 $(eval $(call cache-output-var,LIBGCC_EH,$(CC) $(LIBGCC_CFLAGS) -print-file-name=libgcc_eh.a))
820 # with -O0 we (e.g. lockf) might end up with references to
821 # _Unwind_Resume, so pull in gcc_eh in this case..
822 LIBGCC_DIR:=$(dir $(LIBGCC))
823 LIBGCC += $(if $(DODEBUG),$(LIBGCC_EH))
824
825 # moved from libpthread/linuxthreads
826 ifeq ($(UCLIBC_CTOR_DTOR),y)
827 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
828 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
829 endif
830
831 LOCAL_INSTALL_PATH := $(if $(O),$(O)/)install_dir
832
833 PTHREAD_GENERATE_MANGLE ?= -n "s/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*\$$/\#define \1 \2/p"