OSDN Git Service

ctype: remove some trivial macros from ctype.h;
[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 # check for proper make version
9 ifneq ($(findstring x3.7,x$(MAKE_VERSION)),)
10 $(error Your make is too old $(MAKE_VERSION). Go get at least 3.80)
11 endif
12
13 #-----------------------------------------------------------
14 # This file contains rules which are shared between multiple
15 # Makefiles.  All normal configuration options live in the
16 # file named ".config".  Don't mess with this file unless
17 # you know what you are doing.
18
19
20 #-----------------------------------------------------------
21 # If you are running a cross compiler, you will want to set
22 # 'CROSS' to something more interesting ...  Target
23 # architecture is determined by asking the CC compiler what
24 # arch it compiles things for, so unless your compiler is
25 # broken, you should not need to specify TARGET_ARCH.
26 #
27 # Most people will set this stuff on the command line, i.e.
28 #        make CROSS=arm-linux-
29 # will build uClibc for 'arm'.
30
31 ifndef CROSS
32 CROSS=
33 endif
34 CC         = $(CROSS)gcc
35 AR         = $(CROSS)ar
36 LD         = $(CROSS)ld
37 NM         = $(CROSS)nm
38 STRIPTOOL  = $(CROSS)strip
39
40 INSTALL    = install
41 LN         = ln
42 RM         = rm -f
43 TAR        = tar
44 SED        = sed
45 AWK        = awk
46
47 STRIP_FLAGS ?= -x -R .note -R .comment
48
49 ## unused? if yes, remove after 0.9.31
50 ## UNIFDEF := $(top_builddir)extra/scripts/unifdef -UUCLIBC_INTERNAL
51
52 # Select the compiler needed to build binaries for your development system
53 HOSTCC     = gcc
54 BUILD_CFLAGS = -O2 -Wall
55 export ARCH := $(shell uname -m | $(SED) -e s/i.86/i386/ \
56                                   -e s/sun.*/sparc/ -e s/sparc.*/sparc/ \
57                                   -e s/arm.*/arm/ -e s/sa110/arm/ \
58                                   -e s/sh.*/sh/ \
59                                   -e s/s390x/s390/ -e s/parisc.*/hppa/ \
60                                   -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
61                                   -e s/xtensa.*/xtensa/ )
62
63
64 #---------------------------------------------------------
65 # Nothing beyond this point should ever be touched by mere
66 # mortals.  Unless you hang out with the gods, you should
67 # probably leave all this stuff alone.
68
69 # Pull in the user's uClibc configuration
70 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
71 -include $(top_builddir).config
72 endif
73
74 # Make certain these contain a final "/", but no "//"s.
75 TARGET_ARCH:=$(shell grep -s '^TARGET_ARCH' $(top_builddir)/.config | $(SED) -e 's/^TARGET_ARCH=//' -e 's/"//g')
76 TARGET_ARCH:=$(strip $(subst ",, $(strip $(TARGET_ARCH))))
77 TARGET_SUBARCH:=$(shell grep -s '^TARGET_SUBARCH' $(top_builddir)/.config | $(SED) -e 's/^TARGET_SUBARCH=//' -e 's/"//g')
78 TARGET_SUBARCH:=$(strip $(subst ",, $(strip $(TARGET_SUBARCH))))
79 RUNTIME_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(RUNTIME_PREFIX))))))
80 DEVEL_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(DEVEL_PREFIX))))))
81 KERNEL_HEADERS:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(KERNEL_HEADERS))))))
82 export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS
83
84
85 # Now config hard core
86 MAJOR_VERSION := 0
87 MINOR_VERSION := 9
88 SUBLEVEL      := 30
89 EXTRAVERSION  :=-svn
90 VERSION       := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
91 ifneq ($(EXTRAVERSION),)
92 VERSION       := $(VERSION)$(EXTRAVERSION)
93 endif
94 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
95 LC_ALL := C
96 export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL
97
98 LIBC := libc
99 SHARED_MAJORNAME := $(LIBC).so.$(MAJOR_VERSION)
100 ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 mips64 powerpc64 s390x sparc64 x86_64 ),)
101 UCLIBC_LDSO_NAME := ld64-uClibc
102 ARCH_NATIVE_BIT := 64
103 else
104 UCLIBC_LDSO_NAME := ld-uClibc
105 ARCH_NATIVE_BIT := 32
106 endif
107 UCLIBC_LDSO := $(UCLIBC_LDSO_NAME).so.$(MAJOR_VERSION)
108 NONSHARED_LIBNAME := uclibc_nonshared.a
109 libc := $(top_builddir)lib/$(SHARED_MAJORNAME)
110 libc.depend := $(top_builddir)lib/$(SHARED_MAJORNAME:.$(MAJOR_VERSION)=)
111 interp := $(top_builddir)lib/interp.os
112 ldso := $(top_builddir)lib/$(UCLIBC_LDSO)
113 headers_dep := $(top_builddir)include/bits/sysnum.h
114 sub_headers := $(headers_dep)
115
116 #LIBS :=$(interp) -L$(top_builddir)lib -lc
117 LIBS := $(interp) -L$(top_builddir)lib $(libc:.$(MAJOR_VERSION)=)
118
119 # Make sure DESTDIR and PREFIX can be used to install
120 # PREFIX is a uClibcism while DESTDIR is a common GNUism
121 ifndef PREFIX
122 PREFIX = $(DESTDIR)
123 endif
124
125 ifneq ($(HAVE_SHARED),y)
126 libc :=
127 interp :=
128 ldso :=
129 endif
130
131 comma:=,
132 space:= #
133
134 ifndef CROSS
135 CROSS=$(strip $(subst ",, $(CROSS_COMPILER_PREFIX)))
136 endif
137
138 # A nifty macro to make testing gcc features easier
139 check_gcc=$(shell \
140         if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
141         then echo "$(1)"; else echo "$(2)"; fi)
142 check_as=$(shell \
143         if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
144         then echo "-Wa,$(1)"; fi)
145 check_ld=$(shell \
146         if $(LD) $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1; \
147         then echo "$(1)"; fi)
148
149 ARFLAGS:=cr
150
151 # Flags in OPTIMIZATION are used only for non-debug builds
152 OPTIMIZATION:=
153 # Use '-Os' optimization if available, else use -O2, allow Config to override
154 OPTIMIZATION+=$(call check_gcc,-Os,-O2)
155 # Use the gcc 3.4 -funit-at-a-time optimization when available
156 OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
157
158 GCC_MAJOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 1)
159 #GCC_MINOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 2)
160
161 ifeq ($(GCC_MAJOR_VER),4)
162 # shrinks code, results are from 4.0.2
163 # 0.36%
164 OPTIMIZATION+=$(call check_gcc,-fno-tree-loop-optimize,)
165 # 0.34%
166 OPTIMIZATION+=$(call check_gcc,-fno-tree-dominator-opts,)
167 # 0.1%
168 OPTIMIZATION+=$(call check_gcc,-fno-strength-reduce,)
169 endif
170
171 CPU_CFLAGS-$(UCLIBC_FORMAT_SHARED_FLAT) += -mid-shared-library
172 CPU_CFLAGS-$(UCLIBC_FORMAT_FLAT_SEP_DATA) += -msep-data
173
174 PICFLAG-y := -fPIC
175 PICFLAG-$(UCLIBC_FORMAT_FDPIC_ELF) := -mfdpic
176 PICFLAG := $(PICFLAG-y)
177 PIEFLAG_NAME:=-fPIE
178
179 # Some nice CPU specific optimizations
180 ifeq ($(TARGET_ARCH),i386)
181         OPTIMIZATION+=$(call check_gcc,-fomit-frame-pointer,)
182
183 ifeq ($(CONFIG_386)$(CONFIG_486)$(CONFIG_586)$(CONFIG_586MMX),y)
184         # Non-SSE capable processor.
185         # NB: this may make SSE insns segfault!
186         # -O1 -march=pentium3, -Os -msse etc are known to be affected.
187         # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13685
188         # -m32 is needed if host is 64-bit
189         OPTIMIZATION+=$(call check_gcc,-m32 -mpreferred-stack-boundary=2,)
190 else
191         OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=4,)
192 endif
193
194         # Choice of alignment (please document why!)
195         #  -falign-labels: in-line labels
196         #  (reachable by normal code flow, aligning will insert nops
197         #  which will be executed - may even make things slower)
198         #  -falign-jumps: reachable only by a jump
199         # Generic: no alignment at all (smallest code)
200         GCC_FALIGN=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,-malign-jumps=1 -malign-loops=1)
201 ifeq ($(CONFIG_K7),y)
202         # Align functions to four bytes, use default for jumps and loops (why?)
203         GCC_FALIGN=$(call check_gcc,-falign-functions=4 -falign-labels=1,-malign-functions=4)
204 endif
205 ifeq ($(CONFIG_CRUSOE),y)
206         # Use compiler's default for functions, jumps and loops (why?)
207         GCC_FALIGN=$(call check_gcc,-falign-functions=0 -falign-labels=1,-malign-functions=0)
208 endif
209 ifeq ($(CONFIG_CYRIXIII),y)
210         # Use compiler's default for functions, jumps and loops (why?)
211         GCC_FALIGN=$(call check_gcc,-falign-functions=0 -falign-labels=1,-malign-functions=0)
212 endif
213         OPTIMIZATION+=$(GCC_FALIGN)
214
215         # Putting each function and data object into its own section
216         # allows for kbytes of less text if users link against static uclibc
217         # using ld --gc-sections.
218         # ld 2.18 can't do that (yet?) for shared libraries, so we itself
219         # do not use --gc-sections at shared lib link time.
220         # However, in combination with sections being sorted by alignment
221         # it does result in much reduced padding:
222         #   text    data     bss     dec     hex
223         # 235319    1472    5992  242783   3b45f old.so
224         # 234104    1472    5980  241556   3af94 new.so
225         # Without -ffunction-sections, all functions will get aligned
226         # to 4 byte boundary by as/ld. This is arguably a bug in as.
227         # It specifies 4 byte align for .text even if not told to do so:
228         # Idx Name          Size      VMA       LMA       File off  Algn
229         #   0 .text         xxxxxxxx  00000000  00000000  xxxxxxxx  2**2 <===!
230         CPU_CFLAGS-y  += $(call check_gcc,-ffunction-sections -fdata-sections,)
231 ifneq ($(call check_ld,--sort-common,),)
232         CPU_LDFLAGS-y += -Wl,--sort-common
233 endif
234 ifneq ($(call check_ld,--sort-section alignment),)
235         CPU_LDFLAGS-y += -Wl,--sort-section,alignment
236 endif
237
238         CPU_LDFLAGS-y+=-m32
239         CPU_CFLAGS-y+=-m32
240         CPU_CFLAGS-$(CONFIG_386)+=-march=i386
241         CPU_CFLAGS-$(CONFIG_486)+=-march=i486
242         CPU_CFLAGS-$(CONFIG_ELAN)+=-march=i486
243         CPU_CFLAGS-$(CONFIG_586)+=-march=i586
244         CPU_CFLAGS-$(CONFIG_586MMX)+=$(call check_gcc,-march=pentium-mmx,-march=i586)
245         CPU_CFLAGS-$(CONFIG_686)+=-march=i686
246         CPU_CFLAGS-$(CONFIG_PENTIUMII)+=$(call check_gcc,-march=pentium2,-march=i686)
247         CPU_CFLAGS-$(CONFIG_PENTIUMIII)+=$(call check_gcc,-march=pentium3,-march=i686)
248         CPU_CFLAGS-$(CONFIG_PENTIUM4)+=$(call check_gcc,-march=pentium4,-march=i686)
249         CPU_CFLAGS-$(CONFIG_K6)+=$(call check_gcc,-march=k6,-march=i586)
250         CPU_CFLAGS-$(CONFIG_K7)+=$(call check_gcc,-march=athlon,-march=i686)
251         CPU_CFLAGS-$(CONFIG_CRUSOE)+=-march=i686
252         CPU_CFLAGS-$(CONFIG_WINCHIPC6)+=$(call check_gcc,-march=winchip-c6,-march=i586)
253         CPU_CFLAGS-$(CONFIG_WINCHIP2)+=$(call check_gcc,-march=winchip2,-march=i586)
254         CPU_CFLAGS-$(CONFIG_CYRIXIII)+=$(call check_gcc,-march=c3,-march=i486)
255         CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
256 endif
257
258 ifeq ($(TARGET_ARCH),sparc)
259         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
260         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
261         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
262         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
263 endif
264
265 ifeq ($(TARGET_ARCH),arm)
266         OPTIMIZATION+=-fstrict-aliasing
267         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
268         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
269         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
270         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
271         CPU_CFLAGS-$(CONFIG_GENERIC_ARM)+=
272         CPU_CFLAGS-$(CONFIG_ARM610)+=-mtune=arm610 -march=armv3
273         CPU_CFLAGS-$(CONFIG_ARM710)+=-mtune=arm710 -march=armv3
274         CPU_CFLAGS-$(CONFIG_ARM7TDMI)+=-mtune=arm7tdmi -march=armv4t
275         CPU_CFLAGS-$(CONFIG_ARM720T)+=-mtune=arm7tdmi -march=armv4t
276         CPU_CFLAGS-$(CONFIG_ARM920T)+=-mtune=arm9tdmi -march=armv4t
277         CPU_CFLAGS-$(CONFIG_ARM922T)+=-mtune=arm9tdmi -march=armv4t
278         CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv5t
279         CPU_CFLAGS-$(CONFIG_ARM10T)+=-mtune=arm10tdmi -march=armv5t
280         CPU_CFLAGS-$(CONFIG_ARM1136JF_S)+=-mtune=arm1136jf-s -march=armv6
281         CPU_CFLAGS-$(CONFIG_ARM1176JZ_S)+=-mtune=arm1176jz-s -march=armv6
282         CPU_CFLAGS-$(CONFIG_ARM1176JZF_S)+=-mtune=arm1176jzf-s -march=armv6
283         CPU_CFLAGS-$(CONFIG_ARM_SA110)+=-mtune=strongarm110 -march=armv4
284         CPU_CFLAGS-$(CONFIG_ARM_SA1100)+=-mtune=strongarm1100 -march=armv4
285         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=$(call check_gcc,-mtune=xscale,-mtune=strongarm110)
286         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=-march=armv5te -Wa,-mcpu=xscale
287         CPU_CFLAGS-$(CONFIG_ARM_IWMMXT)+=-march=iwmmxt -Wa,-mcpu=iwmmxt -mabi=iwmmxt
288         CPU_CFLAGS-$(CONFIG_ARM_CORTEX_M3)+=-mcpu=cortex-m3 -mthumb
289         CPU_CFLAGS-$(CONFIG_ARM_CORTEX_M1)+=-mcpu=cortex-m1 -mthumb
290 endif
291
292 ifeq ($(TARGET_ARCH),mips)
293         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
294         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
295         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
296         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
297         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
298         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
299         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
300         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32R2)+=-march=mips32r2 -mtune=mips32r2
301         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
302         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
303                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
304                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
305         endif
306         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
307                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
308                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
309         endif
310         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
311         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
312         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
313 endif
314
315 ifeq ($(TARGET_ARCH),nios)
316         CPU_LDFLAGS-y+=-Wl,-m32
317         CPU_CFLAGS-y+=-Wl,-m32
318 endif
319
320 ifeq ($(TARGET_ARCH),sh)
321         OPTIMIZATION+=-fstrict-aliasing
322         OPTIMIZATION+= $(call check_gcc,-mprefergot,)
323         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
324         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
325         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
326         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
327         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
328         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
329 ifeq ($(UCLIBC_HAS_FLOATS),y)
330         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
331         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
332 else
333         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
334         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
335 endif
336 endif
337
338 ifeq ($(TARGET_ARCH),sh64)
339         OPTIMIZATION+=-fstrict-aliasing
340         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-Wl,-EL
341         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-Wl,-EB
342         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
343         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
344         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
345 endif
346
347 ifeq ($(TARGET_ARCH),h8300)
348         SYMBOL_PREFIX=_
349         CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
350         CPU_LDFLAGS-$(CONFIG_H8S)   += -Wl,-ms8300s
351         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
352         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
353 endif
354
355 ifeq ($(TARGET_ARCH),cris)
356         CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
357         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
358         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
359         PICFLAG:=-fpic
360         PIEFLAG_NAME:=-fpie
361 endif
362
363 ifeq ($(TARGET_ARCH),m68k)
364         # -fPIC is only supported for 68020 and above.  It is not supported
365         # for 68000, 68010, or Coldfire.
366         PICFLAG:=-fpic
367         PIEFLAG_NAME:=-fpie
368 endif
369
370 ifeq ($(TARGET_ARCH),powerpc)
371 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
372 # enough. Therefore use -fpic which will reduce code size and generates
373 # faster code.
374         PICFLAG:=-fpic
375         PIEFLAG_NAME:=-fpie
376         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)
377         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
378         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES"
379
380 endif
381
382 ifeq ($(TARGET_ARCH),bfin)
383         SYMBOL_PREFIX=_
384 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
385         CPU_CFLAGS-y:=-mfdpic
386         CPU_LDFLAGS-y += -Wl,-melf32bfinfd
387         PICFLAG:=-fpic
388         PIEFLAG_NAME:=-fpie
389 endif
390 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
391         PICFLAG := -mleaf-id-shared-library
392 endif
393 endif
394
395 ifeq ($(TARGET_ARCH),frv)
396         CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
397         # Using -pie causes the program to have an interpreter, which is
398         # forbidden, so we must make do with -shared.  Unfortunately,
399         # -shared by itself would get us global function descriptors
400         # and calls through PLTs, dynamic resolution of symbols, etc,
401         # which would break as well, but -Bsymbolic comes to the rescue.
402         export LDPIEFLAG:=-Wl,-shared -Wl,-Bsymbolic
403         UCLIBC_LDSO=ld.so.1
404 endif
405
406 ifeq ($(strip $(TARGET_ARCH)),avr32)
407        CPU_CFLAGS-$(CONFIG_AVR32_AP7)  += -march=ap
408        CPU_CFLAGS-$(CONFIG_LINKRELAX)  += -mrelax
409        CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
410 endif
411
412 ifeq ($(TARGET_ARCH),i960)
413       SYMBOL_PREFIX=_
414 endif
415
416 ifeq ($(TARGET_ARCH),microblaze)
417       SYMBOL_PREFIX=_
418 endif
419
420 ifeq ($(TARGET_ARCH),v850)
421       SYMBOL_PREFIX=_
422 endif
423
424 # Keep the check_gcc from being needlessly executed
425 ifndef PIEFLAG
426 ifneq ($(UCLIBC_BUILD_PIE),y)
427 export PIEFLAG:=
428 else
429 export PIEFLAG:=$(call check_gcc,$(PIEFLAG_NAME),$(PICFLAG))
430 endif
431 endif
432 # We need to keep track of both the CC PIE flag (above) as
433 # well as the LD PIE flag (below) because we can't rely on
434 # gcc passing -pie if we used -fPIE
435 ifndef LDPIEFLAG
436 ifneq ($(UCLIBC_BUILD_PIE),y)
437 export LDPIEFLAG:=
438 else
439 export LDPIEFLAG:=$(shell $(LD) --help 2>/dev/null | grep -q -- -pie && echo "-Wl,-pie")
440 endif
441 endif
442
443 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
444 ifndef ASNEEDED
445 export ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
446 endif
447
448 # Add a bunch of extra pedantic annoyingly strict checks
449 XWARNINGS=$(subst ",, $(strip $(WARNINGS))) -Wstrict-prototypes -fno-strict-aliasing
450 ifeq ($(EXTRA_WARNINGS),y)
451 XWARNINGS+=-Wnested-externs -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wformat=2
452 XWARNINGS+=-Wmissing-prototypes -Wmissing-declarations
453 XWARNINGS+=-Wnonnull -Wundef
454 # works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
455 #XWARNINGS+=-Wdeclaration-after-statement
456 endif
457 XARCH_CFLAGS=$(subst ",, $(strip $(ARCH_CFLAGS)))
458 CPU_CFLAGS=$(subst ",, $(strip $(CPU_CFLAGS-y)))
459
460 SSP_DISABLE_FLAGS ?= $(call check_gcc,-fno-stack-protector,)
461 ifeq ($(UCLIBC_BUILD_SSP),y)
462 SSP_CFLAGS := $(call check_gcc,-fno-stack-protector-all,)
463 SSP_CFLAGS += $(call check_gcc,-fstack-protector,)
464 SSP_ALL_CFLAGS ?= $(call check_gcc,-fstack-protector-all,)
465 else
466 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
467 endif
468
469 NOSTDLIB_CFLAGS:=$(call check_gcc,-nostdlib,)
470 # Some nice CFLAGS to work with
471 # Why -funsigned-char: I hunted a bug related to incorrect
472 # sign extension of 'char' type for 10 hours straight. Not fun.
473 CFLAGS := -include $(top_builddir)include/libc-symbols.h \
474         $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
475         -funsigned-char -fno-builtin -nostdinc -I$(top_builddir)include -I. \
476         -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)
477
478 # Make sure that we can be built with non-C99 compilers, too.
479 # Use __\1__ instead.
480 CFLAGS += $(call check_gcc,-fno-asm,)
481 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
482 CFLAGS += $(subst ",, $(UCLIBC_EXTRA_CFLAGS))
483 endif
484
485 LDADD_LIBFLOAT=
486 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
487 # If -msoft-float isn't supported, we want an error anyway.
488 # Hmm... might need to revisit this for arm since it has 2 different
489 # soft float encodings.
490 ifneq ($(TARGET_ARCH),nios)
491 ifneq ($(TARGET_ARCH),nios2)
492 ifneq ($(TARGET_ARCH),sh)
493 CFLAGS += -msoft-float
494 endif
495 endif
496 endif
497 ifeq ($(TARGET_ARCH),arm)
498 # No longer needed with current toolchains, but leave it here for now.
499 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
500 #    LDADD_LIBFLOAT=-lfloat
501 endif
502 endif
503
504 # Please let us see private headers' parts
505 CFLAGS += -DUCLIBC_INTERNAL
506
507 # We need this to be checked within libc-symbols.h
508 ifneq ($(HAVE_SHARED),y)
509 CFLAGS += -DSTATIC
510 endif
511
512 CFLAGS += $(call check_gcc,-std=gnu99,)
513
514 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -Wl,-shared \
515         -Wl,--warn-common -Wl,--warn-once -Wl,-z,combreloc
516 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
517 #LDFLAGS_NOSTRIP+=$(call check_ld,--gc-sections)
518
519 ifeq ($(UCLIBC_BUILD_RELRO),y)
520 LDFLAGS_NOSTRIP+=-Wl,-z,relro
521 endif
522
523 ifeq ($(UCLIBC_BUILD_NOW),y)
524 LDFLAGS_NOSTRIP+=-Wl,-z,now
525 endif
526
527 ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
528 # Be sure that binutils support it
529 LDFLAGS_GNUHASH:=$(call check_ld,--hash-style=gnu)
530 ifeq ($(LDFLAGS_GNUHASH),)
531 $(error Your binutils don't support --hash-style option, while you want to use it)
532 else
533 LDFLAGS_NOSTRIP += -Wl,$(LDFLAGS_GNUHASH)
534 endif
535 endif
536
537 LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
538 ifeq ($(DODEBUG),y)
539 CFLAGS += -O0 -g3
540 else
541 CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS)
542 endif
543 ifeq ($(DOSTRIP),y)
544 LDFLAGS += -Wl,-s
545 else
546 STRIPTOOL := true -Stripping_disabled
547 endif
548
549 ifeq ($(DOMULTI),y)
550 # we try to compile all sources at once into an object (IMA), but
551 # gcc-3.3.x does not support it
552 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
553 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
554 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
555 ifeq ($(GCC_MAJOR_VER),3)
556 DOMULTI:=n
557 else
558 CFLAGS+=$(call check_gcc,--combine,)
559 endif
560 else
561 DOMULTI:=n
562 endif
563
564 ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
565 LDFLAGS += $(subst ",, $(UCLIBC_EXTRA_LDFLAGS))
566 endif
567
568 ifeq ($(UCLIBC_HAS_THREADS),y)
569 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
570         PTNAME := nptl
571 else
572 ifeq ($(LINUXTHREADS_OLD),y)
573         PTNAME := linuxthreads.old
574 else
575         PTNAME := linuxthreads
576 endif
577 endif
578 PTDIR := $(top_builddir)libpthread/$(PTNAME)
579 # set up system dependencies include dirs (NOTE: order matters!)
580 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
581 PTINC:= -I$(PTDIR)                                              \
582         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)       \
583         -I$(PTDIR)/sysdeps/$(TARGET_ARCH)                       \
584         -I$(PTDIR)/sysdeps/unix/sysv/linux                      \
585         -I$(PTDIR)/sysdeps/pthread                              \
586         -I$(PTDIR)/sysdeps/pthread/bits                         \
587         -I$(PTDIR)/sysdeps/generic                              \
588         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH)                 \
589         -I$(top_srcdir)ldso/include
590 #
591 # Test for TLS if NPTL support was selected.
592 #
593 GCC_HAS_TLS=$(shell \
594         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
595 ifneq ($(GCC_HAS_TLS),)
596 gcc_tls_test_fail:
597         @echo "####";
598         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
599         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
600         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
601         @echo "#### about this problem.";
602         @echo "####";
603         @echo "#### Exiting...";
604         @echo "####";
605         @exit 1;
606 endif
607 else
608 PTINC := \
609         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
610         -I$(PTDIR)/sysdeps/$(TARGET_ARCH) \
611         -I$(PTDIR)/sysdeps/unix/sysv/linux \
612         -I$(PTDIR)/sysdeps/pthread \
613         -I$(PTDIR) \
614         -I$(top_builddir)libpthread
615 endif
616 CFLAGS+=$(PTINC)
617 else
618         PTNAME :=
619         PTINC  :=
620 endif
621 CFLAGS += -I$(KERNEL_HEADERS)
622
623 #CFLAGS += -iwithprefix include-fixed -iwithprefix include
624 CC_IPREFIX:=$(shell $(CC) --print-file-name=include)
625 CFLAGS += -I$(dir $(CC_IPREFIX))/include-fixed -I$(CC_IPREFIX)
626
627 ifneq ($(DOASSERTS),y)
628 CFLAGS+=-DNDEBUG
629 endif
630
631 ifeq ($(SYMBOL_PREFIX),_)
632 CFLAGS+=-D__UCLIBC_UNDERSCORES__
633 endif
634
635 # Keep the check_as from being needlessly executed
636 ifndef ASFLAGS_NOEXEC
637 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
638 export ASFLAGS_NOEXEC := $(call check_as,--noexecstack)
639 else
640 export ASFLAGS_NOEXEC :=
641 endif
642 endif
643 ASFLAGS = $(ASFLAGS_NOEXEC)
644
645 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
646 LIBGCC:=$(shell $(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name)
647 LIBGCC_DIR:=$(dir $(LIBGCC))
648
649 # moved from libpthread/linuxthreads
650 ifeq ($(UCLIBC_CTOR_DTOR),y)
651 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
652 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
653 endif
654
655 LOCAL_INSTALL_PATH := install_dir