OSDN Git Service

- fix generation of sysnum.h for parallel builds, second take.
[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 OPTIMIZATION:=
142 # Use '-Os' optimization if available, else use -O2, allow Config to override
143 OPTIMIZATION+=$(call check_gcc,-Os,-O2)
144 # Use the gcc 3.4 -funit-at-a-time optimization when available
145 OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
146
147 GCC_MAJOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 1)
148 #GCC_MINOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 2)
149
150 ifeq ($(GCC_MAJOR_VER),4)
151 # shrinks code, results are from 4.0.2
152 # 0.36%
153 OPTIMIZATION+=$(call check_gcc,-fno-tree-loop-optimize,)
154 # 0.34%
155 OPTIMIZATION+=$(call check_gcc,-fno-tree-dominator-opts,)
156 # 0.1%
157 OPTIMIZATION+=$(call check_gcc,-fno-strength-reduce,)
158 endif
159
160 CPU_CFLAGS-$(UCLIBC_FORMAT_SHARED_FLAT) += -mid-shared-library
161 CPU_CFLAGS-$(UCLIBC_FORMAT_FLAT_SEP_DATA) += -msep-data
162
163 PICFLAG-y := -fPIC
164 PICFLAG-$(UCLIBC_FORMAT_FDPIC_ELF) := -mfdpic
165 PICFLAG := $(PICFLAG-y)
166 PIEFLAG_NAME:=-fPIE
167
168 # Some nice CPU specific optimizations
169 ifeq ($(TARGET_ARCH),i386)
170         OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
171         OPTIMIZATION+=$(call check_gcc,-falign-jumps=0 -falign-loops=0,-malign-jumps=0 -malign-loops=0)
172         CPU_LDFLAGS-y+=-m32
173         CPU_CFLAGS-y+=-m32
174         CPU_CFLAGS-$(CONFIG_386)+=-march=i386
175         CPU_CFLAGS-$(CONFIG_486)+=-march=i486
176         CPU_CFLAGS-$(CONFIG_ELAN)+=-march=i486
177         CPU_CFLAGS-$(CONFIG_586)+=-march=i586
178         CPU_CFLAGS-$(CONFIG_586MMX)+=$(call check_gcc,-march=pentium-mmx,-march=i586)
179         CPU_CFLAGS-$(CONFIG_686)+=-march=i686
180         CPU_CFLAGS-$(CONFIG_PENTIUMII)+=$(call check_gcc,-march=pentium2,-march=i686)
181         CPU_CFLAGS-$(CONFIG_PENTIUMIII)+=$(call check_gcc,-march=pentium3,-march=i686)
182         CPU_CFLAGS-$(CONFIG_PENTIUM4)+=$(call check_gcc,-march=pentium4,-march=i686)
183         CPU_CFLAGS-$(CONFIG_K6)+=$(call check_gcc,-march=k6,-march=i586)
184         CPU_CFLAGS-$(CONFIG_K7)+=$(call check_gcc,-march=athlon,-march=i686) $(call check_gcc,-falign-functions=4,-malign-functions=4)
185         CPU_CFLAGS-$(CONFIG_CRUSOE)+=-march=i686 $(call check_gcc,-falign-functions=0,-malign-functions=0)
186         CPU_CFLAGS-$(CONFIG_WINCHIPC6)+=$(call check_gcc,-march=winchip-c6,-march=i586)
187         CPU_CFLAGS-$(CONFIG_WINCHIP2)+=$(call check_gcc,-march=winchip2,-march=i586)
188         CPU_CFLAGS-$(CONFIG_CYRIXIII)+=$(call check_gcc,-march=c3,-march=i486) $(call check_gcc,-falign-functions=0,-malign-functions=0)
189         CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
190 endif
191
192 ifeq ($(TARGET_ARCH),sparc)
193         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
194         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
195         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
196         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
197 endif
198
199 ifeq ($(TARGET_ARCH),arm)
200         OPTIMIZATION+=-fstrict-aliasing
201         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
202         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
203         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
204         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
205         CPU_CFLAGS-$(CONFIG_GENERIC_ARM)+=
206         CPU_CFLAGS-$(CONFIG_ARM610)+=-mtune=arm610 -march=armv3
207         CPU_CFLAGS-$(CONFIG_ARM710)+=-mtune=arm710 -march=armv3
208         CPU_CFLAGS-$(CONFIG_ARM7TDMI)+=-mtune=arm7tdmi -march=armv4t
209         CPU_CFLAGS-$(CONFIG_ARM720T)+=-mtune=arm7tdmi -march=armv4t
210         CPU_CFLAGS-$(CONFIG_ARM920T)+=-mtune=arm9tdmi -march=armv4t
211         CPU_CFLAGS-$(CONFIG_ARM922T)+=-mtune=arm9tdmi -march=armv4t
212         CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv5t
213         CPU_CFLAGS-$(CONFIG_ARM10T)+=-mtune=arm10tdmi -march=armv5t
214         CPU_CFLAGS-$(CONFIG_ARM1136JF_S)+=-mtune=arm1136jf-s -march=armv6
215         CPU_CFLAGS-$(CONFIG_ARM1176JZ_S)+=-mtune=arm1176jz-s -march=armv6
216         CPU_CFLAGS-$(CONFIG_ARM1176JZF_S)+=-mtune=arm1176jzf-s -march=armv6
217         CPU_CFLAGS-$(CONFIG_ARM_SA110)+=-mtune=strongarm110 -march=armv4
218         CPU_CFLAGS-$(CONFIG_ARM_SA1100)+=-mtune=strongarm1100 -march=armv4
219         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=$(call check_gcc,-mtune=xscale,-mtune=strongarm110)
220         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=-march=armv5te -Wa,-mcpu=xscale
221         CPU_CFLAGS-$(CONFIG_ARM_IWMMXT)+=-march=iwmmxt -Wa,-mcpu=iwmmxt -mabi=iwmmxt
222         CPU_CFLAGS-$(CONFIG_ARM_CORTEX_M3)+=-mcpu=cortex-m3 -mthumb
223         CPU_CFLAGS-$(CONFIG_ARM_CORTEX_M1)+=-mcpu=cortex-m1 -mthumb
224 endif
225
226 ifeq ($(TARGET_ARCH),mips)
227         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
228         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
229         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
230         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
231         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
232         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
233         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
234         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
235         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
236                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64btsmip
237                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32btsmip
238         endif
239         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
240                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-Wl,-melf64ltsmip
241                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-Wl,-melf32ltsmip
242         endif
243         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
244         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
245         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
246 endif
247
248 ifeq ($(TARGET_ARCH),nios)
249         CPU_LDFLAGS-y+=-Wl,-m32
250         CPU_CFLAGS-y+=-Wl,-m32
251 endif
252
253 ifeq ($(TARGET_ARCH),sh)
254         OPTIMIZATION+=-fstrict-aliasing
255         OPTIMIZATION+= $(call check_gcc,-mprefergot,)
256         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-Wl,-EL
257         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-Wl,-EB
258         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
259         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
260         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
261         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
262 ifeq ($(UCLIBC_HAS_FLOATS),y)
263         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
264         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
265 else
266         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
267         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
268 endif
269 endif
270
271 ifeq ($(TARGET_ARCH),sh64)
272         OPTIMIZATION+=-fstrict-aliasing
273         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-Wl,-EL
274         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-Wl,-EB
275         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
276         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
277         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
278 endif
279
280 ifeq ($(TARGET_ARCH),h8300)
281         SYMBOL_PREFIX=_
282         CPU_LDFLAGS-$(CONFIG_H8300H)+= -Wl,-ms8300h
283         CPU_LDFLAGS-$(CONFIG_H8S)   += -Wl,-ms8300s
284         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
285         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
286 endif
287
288 ifeq ($(TARGET_ARCH),cris)
289         CPU_LDFLAGS-$(CONFIG_CRIS)+=-Wl,-mcrislinux
290         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-Wl,-mcrislinux
291         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
292         PICFLAG:=-fpic
293         PIEFLAG_NAME:=-fpie
294 endif
295
296 ifeq ($(TARGET_ARCH),m68k)
297         # -fPIC is only supported for 68020 and above.  It is not supported
298         # for 68000, 68010, or Coldfire.
299         PICFLAG:=-fpic
300         PIEFLAG_NAME:=-fpie
301 endif
302
303 ifeq ($(TARGET_ARCH),powerpc)
304 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
305 # enough. Therefore use -fpic which will reduce code size and generates
306 # faster code.
307         PICFLAG:=-fpic
308         PIEFLAG_NAME:=-fpie
309         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)
310         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
311         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES -D__NO_LONG_DOUBLE_MATH"
312
313 endif
314
315 ifeq ($(TARGET_ARCH),bfin)
316         SYMBOL_PREFIX=_
317 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
318         CPU_CFLAGS-y:=-mfdpic
319         CPU_LDFLAGS-y += -Wl,-melf32bfinfd
320         PICFLAG:=-fpic
321         PIEFLAG_NAME:=-fpie
322 endif
323 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
324         PICFLAG := -mleaf-id-shared-library
325 endif
326 endif
327
328 ifeq ($(TARGET_ARCH),frv)
329         CPU_LDFLAGS-$(CONFIG_FRV)+=-Wl,-melf32frvfd
330         # Using -pie causes the program to have an interpreter, which is
331         # forbidden, so we must make do with -shared.  Unfortunately,
332         # -shared by itself would get us global function descriptors
333         # and calls through PLTs, dynamic resolution of symbols, etc,
334         # which would break as well, but -Bsymbolic comes to the rescue.
335         export LDPIEFLAG:=-Wl,-shared -Wl,-Bsymbolic
336         UCLIBC_LDSO=ld.so.1
337 endif
338
339 ifeq ($(strip $(TARGET_ARCH)),avr32)
340        CPU_CFLAGS-$(CONFIG_AVR32_AP7)  += -march=ap
341        CPU_CFLAGS-$(CONFIG_LINKRELAX)  += -mrelax
342        CPU_LDFLAGS-$(CONFIG_LINKRELAX) += --relax
343 endif
344
345 ifeq ($(TARGET_ARCH),i960)
346       SYMBOL_PREFIX=_
347 endif
348
349 ifeq ($(TARGET_ARCH),microblaze)
350       SYMBOL_PREFIX=_
351 endif
352
353 ifeq ($(TARGET_ARCH),v850)
354       SYMBOL_PREFIX=_
355 endif
356
357 # Keep the check_gcc from being needlessly executed
358 ifndef PIEFLAG
359 ifneq ($(UCLIBC_BUILD_PIE),y)
360 export PIEFLAG:=
361 else
362 export PIEFLAG:=$(call check_gcc,$(PIEFLAG_NAME),$(PICFLAG))
363 endif
364 endif
365 # We need to keep track of both the CC PIE flag (above) as
366 # well as the LD PIE flag (below) because we can't rely on
367 # gcc passing -pie if we used -fPIE
368 ifndef LDPIEFLAG
369 ifneq ($(UCLIBC_BUILD_PIE),y)
370 export LDPIEFLAG:=
371 else
372 export LDPIEFLAG:=$(shell $(LD) --help 2>/dev/null | grep -q -- -pie && echo "-Wl,-pie")
373 endif
374 endif
375
376 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
377 ifndef ASNEEDED
378 export ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
379 endif
380
381 # Add a bunch of extra pedantic annoyingly strict checks
382 XWARNINGS=$(subst ",, $(strip $(WARNINGS))) -Wstrict-prototypes -fno-strict-aliasing
383 ifeq ($(EXTRA_WARNINGS),y)
384 XWARNINGS+=-Wnested-externs -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wformat=2
385 XWARNINGS+=-Wmissing-prototypes -Wmissing-declarations
386 XWARNINGS+=-Wnonnull -Wundef
387 # works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
388 #XWARNINGS+=-Wdeclaration-after-statement
389 endif
390 XARCH_CFLAGS=$(subst ",, $(strip $(ARCH_CFLAGS)))
391 CPU_CFLAGS=$(subst ",, $(strip $(CPU_CFLAGS-y)))
392
393 SSP_DISABLE_FLAGS ?= $(call check_gcc,-fno-stack-protector,)
394 ifeq ($(UCLIBC_BUILD_SSP),y)
395 SSP_CFLAGS := $(call check_gcc,-fno-stack-protector-all,)
396 SSP_CFLAGS += $(call check_gcc,-fstack-protector,)
397 SSP_ALL_CFLAGS ?= $(call check_gcc,-fstack-protector-all,)
398 else
399 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
400 endif
401
402 NOSTDLIB_CFLAGS:=$(call check_gcc,-nostdlib,)
403 # Some nice CFLAGS to work with
404 CFLAGS := -include $(top_builddir)include/libc-symbols.h \
405         $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
406         -fno-builtin -nostdinc -I$(top_builddir)include -I. \
407         -I$(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)
408
409 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
410 CFLAGS += $(subst ",, $(UCLIBC_EXTRA_CFLAGS))
411 endif
412
413 LDADD_LIBFLOAT=
414 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
415 # If -msoft-float isn't supported, we want an error anyway.
416 # Hmm... might need to revisit this for arm since it has 2 different
417 # soft float encodings.
418 ifneq ($(TARGET_ARCH),nios)
419 ifneq ($(TARGET_ARCH),nios2)
420 CFLAGS += -msoft-float
421 endif
422 endif
423 ifeq ($(TARGET_ARCH),arm)
424 # No longer needed with current toolchains, but leave it here for now.
425 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
426 #    LDADD_LIBFLOAT=-lfloat
427 endif
428 endif
429
430 # We need this to be checked within libc-symbols.h
431 ifneq ($(HAVE_SHARED),y)
432 CFLAGS += -DSTATIC
433 endif
434
435 CFLAGS += $(call check_gcc,-std=gnu99,)
436
437 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -Wl,-shared \
438         -Wl,--warn-common -Wl,--warn-once -Wl,-z,combreloc
439 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
440 #LDFLAGS_NOSTRIP+=$(call check_ld,--gc-sections)
441
442 ifeq ($(UCLIBC_BUILD_RELRO),y)
443 LDFLAGS_NOSTRIP+=-Wl,-z,relro
444 endif
445
446 ifeq ($(UCLIBC_BUILD_NOW),y)
447 LDFLAGS_NOSTRIP+=-Wl,-z,now
448 endif
449
450 ifeq ($(LDSO_GNU_HASH_SUPPORT),y)
451 # Be sure that binutils support it
452 LDFLAGS_GNUHASH:=$(call check_ld,--hash-style=gnu)
453 ifeq ($(LDFLAGS_GNUHASH),)
454 $(error Your binutils don't support --hash-style option, while you want to use it)
455 else
456 LDFLAGS_NOSTRIP += -Wl,$(LDFLAGS_GNUHASH)
457 endif
458 endif
459
460 LDFLAGS:=$(LDFLAGS_NOSTRIP) -Wl,-z,defs
461 ifeq ($(DODEBUG),y)
462 #CFLAGS += -g3
463 CFLAGS += -O0 -g3
464 else
465 CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS)
466 endif
467 ifeq ($(DOSTRIP),y)
468 LDFLAGS += -Wl,-s
469 else
470 STRIPTOOL := true -Stripping_disabled
471 endif
472
473 ifeq ($(DOMULTI),y)
474 # we try to compile all sources at once into an object (IMA), but
475 # gcc-3.3.x does not support it
476 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
477 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
478 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
479 ifeq ($(GCC_MAJOR_VER),3)
480 DOMULTI:=n
481 else
482 CFLAGS+=$(call check_gcc,--combine,)
483 endif
484 else
485 DOMULTI:=n
486 endif
487
488 ifneq ($(strip $(UCLIBC_EXTRA_LDFLAGS)),"")
489 LDFLAGS += $(subst ",, $(UCLIBC_EXTRA_LDFLAGS))
490 endif
491
492 ifeq ($(UCLIBC_HAS_THREADS),y)
493 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
494         PTNAME := nptl
495 else
496 ifeq ($(LINUXTHREADS_OLD),y)
497         PTNAME := linuxthreads.old
498 else
499         PTNAME := linuxthreads
500 endif
501 endif
502 PTDIR := $(top_builddir)libpthread/$(PTNAME)
503 # set up system dependencies include dirs (NOTE: order matters!)
504 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
505 PTINC:= -I$(PTDIR)                                              \
506         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)       \
507         -I$(PTDIR)/sysdeps/$(TARGET_ARCH)                       \
508         -I$(PTDIR)/sysdeps/unix/sysv/linux                      \
509         -I$(PTDIR)/sysdeps/pthread                              \
510         -I$(PTDIR)/sysdeps/pthread/bits                         \
511         -I$(PTDIR)/sysdeps/generic                              \
512         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH)                 \
513         -I$(top_srcdir)ldso/include
514 #
515 # Test for TLS if NPTL support was selected.
516 #
517 GCC_HAS_TLS=$(shell \
518         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
519 ifneq ($(GCC_HAS_TLS),)
520 gcc_tls_test_fail:
521         @echo "####";
522         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
523         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
524         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
525         @echo "#### about this problem.";
526         @echo "####";
527         @echo "#### Exiting...";
528         @echo "####";
529         @exit 1;
530 endif
531 else
532 PTINC := \
533         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
534         -I$(PTDIR)/sysdeps/$(TARGET_ARCH) \
535         -I$(PTDIR)/sysdeps/unix/sysv/linux \
536         -I$(PTDIR)/sysdeps/pthread \
537         -I$(PTDIR) \
538         -I$(top_builddir)libpthread
539 endif
540 CFLAGS+=$(PTINC)
541 else
542         PTNAME :=
543         PTINC  :=
544 endif
545 CFLAGS += -I$(KERNEL_HEADERS)
546
547 CFLAGS += -iwithprefix include-fixed -iwithprefix include
548
549 ifneq ($(DOASSERTS),y)
550 CFLAGS+=-DNDEBUG
551 endif
552
553 ifeq ($(SYMBOL_PREFIX),_)
554 CFLAGS+=-D__UCLIBC_UNDERSCORES__
555 endif
556
557 # Keep the check_as from being needlessly executed
558 ifndef ASFLAGS_NOEXEC
559 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
560 export ASFLAGS_NOEXEC := $(call check_as,--noexecstack)
561 else
562 export ASFLAGS_NOEXEC :=
563 endif
564 endif
565 ASFLAGS = $(ASFLAGS_NOEXEC)
566
567 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
568 LIBGCC:=$(shell $(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name)
569 LIBGCC_DIR:=$(dir $(LIBGCC))
570
571 # moved from libpthread/linuxthreads
572 ifeq ($(UCLIBC_CTOR_DTOR),y)
573 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
574 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
575 endif