OSDN Git Service

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