OSDN Git Service

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