OSDN Git Service

force ourselves to write proper code and develop testscases
[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
55
56 #---------------------------------------------------------
57 # Nothing beyond this point should ever be touched by mere
58 # mortals.  Unless you hang out with the gods, you should
59 # probably leave all this stuff alone.
60
61 # Pull in the user's uClibc configuration
62 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
63 -include $(top_builddir).config
64 endif
65
66 # Make certain these contain a final "/", but no "//"s.
67 TARGET_ARCH:=$(shell grep -s '^TARGET_ARCH' $(top_builddir)/.config | sed -e 's/^TARGET_ARCH=//' -e 's/"//g')
68 TARGET_ARCH:=$(strip $(subst ",, $(strip $(TARGET_ARCH))))
69 TARGET_SUBARCH:=$(shell grep -s '^TARGET_SUBARCH' $(top_builddir)/.config | sed -e 's/^TARGET_SUBARCH=//' -e 's/"//g')
70 TARGET_SUBARCH:=$(strip $(subst ",, $(strip $(TARGET_SUBARCH))))
71 RUNTIME_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(RUNTIME_PREFIX))))))
72 DEVEL_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(DEVEL_PREFIX))))))
73 KERNEL_HEADERS:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(KERNEL_HEADERS))))))
74 export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS
75
76
77 # Now config hard core
78 MAJOR_VERSION := 0
79 MINOR_VERSION := 9
80 SUBLEVEL      := 29
81 EXTRAVERSION  :=
82 VERSION       := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
83 ifneq ($(EXTRAVERSION),)
84 VERSION       := $(VERSION)$(EXTRAVERSION)
85 endif
86 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
87 LC_ALL := C
88 export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL
89
90 LIBC := libc
91 SHARED_MAJORNAME := $(LIBC).so.$(MAJOR_VERSION)
92 ifneq ($(findstring  $(TARGET_ARCH) , hppa64 ia64 mips64 powerpc64 s390x sh64 sparc64 x86_64 ),)
93 UCLIBC_LDSO_NAME := ld64-uClibc
94 else
95 UCLIBC_LDSO_NAME := ld-uClibc
96 endif
97 UCLIBC_LDSO := $(UCLIBC_LDSO_NAME).so.$(MAJOR_VERSION)
98 NONSHARED_LIBNAME := uclibc_nonshared.a
99 libc := $(top_builddir)lib/$(SHARED_MAJORNAME)
100 interp := $(top_builddir)lib/interp.os
101 ldso := $(top_builddir)lib/$(UCLIBC_LDSO)
102 headers_dep := $(top_builddir)include/bits/sysnum.h
103 sub_headers := $(headers_dep)
104
105 #LIBS :=$(interp) -L$(top_builddir)lib -lc
106 LIBS := $(interp) -L$(top_builddir)lib $(libc:.$(MAJOR_VERSION)=)
107
108 # Make sure DESTDIR and PREFIX can be used to install
109 # PREFIX is a uClibcism while DESTDIR is a common GNUism
110 ifndef PREFIX
111 PREFIX = $(DESTDIR)
112 endif
113
114 ifneq ($(HAVE_SHARED),y)
115 libc :=
116 interp :=
117 ldso :=
118 endif
119
120 ifndef CROSS
121 CROSS=$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
122 endif
123
124 # A nifty macro to make testing gcc features easier
125 check_gcc=$(shell \
126         if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
127         then echo "$(1)"; else echo "$(2)"; fi)
128 check_as=$(shell \
129         if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
130         then echo "-Wa,$(1)"; fi)
131 check_ld=$(shell \
132         if $(LD) $(1) -o /dev/null -b binary /dev/null > /dev/null 2>&1; \
133         then echo "$(1)"; fi)
134
135 ARFLAGS:=cr
136
137 OPTIMIZATION:=
138 # Use '-Os' optimization if available, else use -O2, allow Config to override
139 OPTIMIZATION+=$(call check_gcc,-Os,-O2)
140 # Use the gcc 3.4 -funit-at-a-time optimization when available
141 OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
142
143 GCC_MAJOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 1)
144 #GCC_MINOR_VER?=$(shell $(CC) -dumpversion | cut -d . -f 2)
145
146 ifeq ($(GCC_MAJOR_VER),4)
147 # shrinks code, results are from 4.0.2
148 # 0.36%
149 OPTIMIZATION+=$(call check_gcc,-fno-tree-loop-optimize,)
150 # 0.34%
151 OPTIMIZATION+=$(call check_gcc,-fno-tree-dominator-opts,)
152 # 0.1%
153 OPTIMIZATION+=$(call check_gcc,-fno-strength-reduce,)
154 endif
155
156 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
157         PICFLAG:=-mfdpic
158 else
159         PICFLAG:=-fPIC
160 endif
161 PIEFLAG_NAME:=-fPIE
162
163 # Some nice CPU specific optimizations
164 ifeq ($(TARGET_ARCH),i386)
165         OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
166         OPTIMIZATION+=$(call check_gcc,-falign-jumps=0 -falign-loops=0,-malign-jumps=0 -malign-loops=0)
167         CPU_CFLAGS-$(CONFIG_386)+=-march=i386
168         CPU_CFLAGS-$(CONFIG_486)+=-march=i486
169         CPU_CFLAGS-$(CONFIG_ELAN)+=-march=i486
170         CPU_CFLAGS-$(CONFIG_586)+=-march=i586
171         CPU_CFLAGS-$(CONFIG_586MMX)+=$(call check_gcc,-march=pentium-mmx,-march=i586)
172         CPU_CFLAGS-$(CONFIG_686)+=-march=i686
173         CPU_CFLAGS-$(CONFIG_PENTIUMII)+=$(call check_gcc,-march=pentium2,-march=i686)
174         CPU_CFLAGS-$(CONFIG_PENTIUMIII)+=$(call check_gcc,-march=pentium3,-march=i686)
175         CPU_CFLAGS-$(CONFIG_PENTIUM4)+=$(call check_gcc,-march=pentium4,-march=i686)
176         CPU_CFLAGS-$(CONFIG_K6)+=$(call check_gcc,-march=k6,-march=i586)
177         CPU_CFLAGS-$(CONFIG_K7)+=$(call check_gcc,-march=athlon,-march=i686) $(call check_gcc,-falign-functions=4,-malign-functions=4)
178         CPU_CFLAGS-$(CONFIG_CRUSOE)+=-march=i686 $(call check_gcc,-falign-functions=0,-malign-functions=0)
179         CPU_CFLAGS-$(CONFIG_WINCHIPC6)+=$(call check_gcc,-march=winchip-c6,-march=i586)
180         CPU_CFLAGS-$(CONFIG_WINCHIP2)+=$(call check_gcc,-march=winchip2,-march=i586)
181         CPU_CFLAGS-$(CONFIG_CYRIXIII)+=$(call check_gcc,-march=c3,-march=i486) $(call check_gcc,-falign-functions=0,-malign-functions=0)
182         CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
183 endif
184
185 ifeq ($(TARGET_ARCH),sparc)
186         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
187         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
188         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
189         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
190 endif
191
192 ifeq ($(TARGET_ARCH),arm)
193         OPTIMIZATION+=-fstrict-aliasing
194         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
195         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB
196         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
197         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
198         CPU_CFLAGS-$(CONFIG_GENERIC_ARM)+=
199         CPU_CFLAGS-$(CONFIG_ARM610)+=-mtune=arm610 -march=armv3
200         CPU_CFLAGS-$(CONFIG_ARM710)+=-mtune=arm710 -march=armv3
201         CPU_CFLAGS-$(CONFIG_ARM7TDMI)+=-mtune=arm7tdmi -march=armv4t
202         CPU_CFLAGS-$(CONFIG_ARM720T)+=-mtune=arm7tdmi -march=armv4t
203         CPU_CFLAGS-$(CONFIG_ARM920T)+=-mtune=arm9tdmi -march=armv4t
204         CPU_CFLAGS-$(CONFIG_ARM922T)+=-mtune=arm9tdmi -march=armv4t
205         CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv5t
206         CPU_CFLAGS-$(CONFIG_ARM10T)+=-mtune=arm10tdmi -march=armv5t
207         CPU_CFLAGS-$(CONFIG_ARM1136JF_S)+=-mtune=arm1136jf-s -march=armv6
208         CPU_CFLAGS-$(CONFIG_ARM1176JZ_S)+=-mtune=arm1176jz-s -march=armv6
209         CPU_CFLAGS-$(CONFIG_ARM1176JZF_S)+=-mtune=arm1176jzf-s -march=armv6
210         CPU_CFLAGS-$(CONFIG_ARM_SA110)+=-mtune=strongarm110 -march=armv4
211         CPU_CFLAGS-$(CONFIG_ARM_SA1100)+=-mtune=strongarm1100 -march=armv4
212         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=$(call check_gcc,-mtune=xscale,-mtune=strongarm110)
213         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=-march=armv5te -Wa,-mcpu=xscale
214         CPU_CFLAGS-$(CONFIG_ARM_IWMMXT)+=-march=iwmmxt -Wa,-mcpu=iwmmxt -mabi=iwmmxt
215 endif
216
217 ifeq ($(TARGET_ARCH),mips)
218         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
219         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB
220         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
221         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
222         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
223         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
224         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
225         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
226         ifeq ($(strip $(ARCH_BIG_ENDIAN)),y)
227                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-melf64btsmip
228                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-melf32btsmip
229         endif
230         ifeq ($(strip $(ARCH_LITTLE_ENDIAN)),y)
231                 CPU_LDFLAGS-$(CONFIG_MIPS_N64_ABI)+=-melf64ltsmip
232                 CPU_LDFLAGS-$(CONFIG_MIPS_O32_ABI)+=-melf32ltsmip
233         endif
234         CPU_CFLAGS-$(CONFIG_MIPS_N64_ABI)+=-mabi=64
235         CPU_CFLAGS-$(CONFIG_MIPS_O32_ABI)+=-mabi=32
236         CPU_CFLAGS-$(CONFIG_MIPS_N32_ABI)+=-mabi=n32
237 endif
238
239 ifeq ($(TARGET_ARCH),nios)
240         CPU_LDFLAGS-y+=-m32
241         CPU_CFLAGS-y+=-m32
242 endif
243
244 ifeq ($(TARGET_ARCH),sh)
245         OPTIMIZATION+=-fstrict-aliasing
246         OPTIMIZATION+= $(call check_gcc,-mprefergot,)
247         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
248         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB
249         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
250         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
251         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
252         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
253 ifeq ($(UCLIBC_HAS_FLOATS),y)
254         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
255         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
256 else
257         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
258         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
259 endif
260 endif
261
262 ifeq ($(TARGET_ARCH),sh64)
263         OPTIMIZATION+=-fstrict-aliasing
264         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-EL
265         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-EB
266         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
267         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
268         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
269 endif
270
271 ifeq ($(TARGET_ARCH),h8300)
272         CPU_LDFLAGS-$(CONFIG_H8300H)+= -ms8300h
273         CPU_LDFLAGS-$(CONFIG_H8S)   += -ms8300s
274         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32
275         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32
276 endif
277
278 ifeq ($(TARGET_ARCH),cris)
279         CPU_LDFLAGS-$(CONFIG_CRIS)+=-mcrislinux
280         CPU_LDFLAGS-$(CONFIG_CRISV32)+=-mcrislinux
281         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
282         PICFLAG:=-fpic
283         PIEFLAG_NAME:=-fpie
284 endif
285
286 ifeq ($(TARGET_ARCH),m68k)
287         # -fPIC is only supported for 68020 and above.  It is not supported
288         # for 68000, 68010, or Coldfire.
289         PICFLAG:=-fpic
290         PIEFLAG_NAME:=-fpie
291 endif
292
293 ifeq ($(TARGET_ARCH),powerpc)
294 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
295 # enough. Therefore use -fpic which will reduce code size and generates
296 # faster code.
297         PICFLAG:=-fpic
298         PIEFLAG_NAME:=-fpie
299         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)
300         CPU_CFLAGS-$(PPC_HAS_REL16)+= -DHAVE_ASM_PPC_REL16
301         CPU_CFLAGS-$(CONFIG_E500) += "-D__NO_MATH_INLINES -D__NO_LONG_DOUBLE_MATH"
302
303 endif
304
305 ifeq ($(TARGET_ARCH),frv)
306         CPU_LDFLAGS-$(CONFIG_FRV)+=-melf32frvfd
307         # Using -pie causes the program to have an interpreter, which is
308         # forbidden, so we must make do with -shared.  Unfortunately,
309         # -shared by itself would get us global function descriptors
310         # and calls through PLTs, dynamic resolution of symbols, etc,
311         # which would break as well, but -Bsymbolic comes to the rescue.
312         export LDPIEFLAG:=-shared -Bsymbolic
313         UCLIBC_LDSO=ld.so.1
314 endif
315
316 # Keep the check_gcc from being needlessly executed
317 ifndef PIEFLAG
318 ifneq ($(UCLIBC_BUILD_PIE),y)
319 export PIEFLAG:=
320 else
321 export PIEFLAG:=$(call check_gcc,$(PIEFLAG_NAME),$(PICFLAG))
322 endif
323 endif
324 # We need to keep track of both the CC PIE flag (above) as
325 # well as the LD PIE flag (below) because we can't rely on
326 # gcc passing -pie if we used -fPIE
327 ifndef LDPIEFLAG
328 ifneq ($(UCLIBC_BUILD_PIE),y)
329 export LDPIEFLAG:=
330 else
331 export LDPIEFLAG:=$(shell $(LD) --help 2>/dev/null | grep -q -- -pie && echo "-Wl,-pie")
332 endif
333 endif
334
335 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
336 ifndef ASNEEDED
337 ifneq ($(UCLIBC_HAS_SSP),y)
338 export ASNEEDED:=
339 else
340 export ASNEEDED:=$(shell (LD_TMP=$(mktemp LD_XXXXXX) ; echo "GROUP ( AS_NEEDED ( /usr/lib/libc.so ) )" > $LD_TMP && if $(LD) -T $LD_TMP -o /dev/null > /dev/null 2>&1; then echo "AS_NEEDED ( $(UCLIBC_LDSO) )"; else echo "$(UCLIBC_LDSO)"; fi; rm -f $LD_TMP ) )
341 endif
342 endif
343
344 # Add a bunch of extra pedantic annoyingly strict checks
345 XWARNINGS=$(subst ",, $(strip $(WARNINGS))) -Wstrict-prototypes -fno-strict-aliasing
346 ifeq ($(EXTRA_WARNINGS),y)
347 XWARNINGS+=-Wnested-externs -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wformat=2
348 XWARNINGS+=-Wmissing-prototypes -Wmissing-declarations
349 XWARNINGS+=-Wnonnull -Wundef
350 # works only w/ gcc-3.4 and up, can't be checked for gcc-3.x w/ check_gcc()
351 #XWARNINGS+=-Wdeclaration-after-statement
352 endif
353 XARCH_CFLAGS=$(subst ",, $(strip $(ARCH_CFLAGS)))
354 CPU_CFLAGS=$(subst ",, $(strip $(CPU_CFLAGS-y)))
355
356 SSP_DISABLE_FLAGS ?= $(call check_gcc,-fno-stack-protector,)
357 ifeq ($(UCLIBC_BUILD_SSP),y)
358 SSP_CFLAGS := $(call check_gcc,-fno-stack-protector-all,)
359 SSP_CFLAGS += $(call check_gcc,-fstack-protector,)
360 SSP_ALL_CFLAGS ?= $(call check_gcc,-fstack-protector-all,)
361 else
362 SSP_CFLAGS := $(SSP_DISABLE_FLAGS)
363 endif
364
365 # Some nice CFLAGS to work with
366 CFLAGS := -include $(top_builddir)include/libc-symbols.h \
367         $(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
368         -fno-builtin -nostdinc -I$(top_builddir)include -I.
369
370 ifneq ($(strip $(UCLIBC_EXTRA_CFLAGS)),"")
371 CFLAGS += $(subst ",, $(UCLIBC_EXTRA_CFLAGS))
372 endif
373
374 LDADD_LIBFLOAT=
375 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
376 # If -msoft-float isn't supported, we want an error anyway.
377 # Hmm... might need to revisit this for arm since it has 2 different
378 # soft float encodings.
379 ifneq ($(TARGET_ARCH),nios)
380 ifneq ($(TARGET_ARCH),nios2)
381 CFLAGS += -msoft-float
382 endif
383 endif
384 ifeq ($(TARGET_ARCH),arm)
385 # No longer needed with current toolchains, but leave it here for now.
386 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
387 #    LDADD_LIBFLOAT=-lfloat
388 endif
389 endif
390
391 # We need this to be checked within libc-symbols.h
392 ifneq ($(HAVE_SHARED),y)
393 CFLAGS += -DSTATIC
394 endif
395
396 CFLAGS += $(call check_gcc,-std=gnu99,)
397
398 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared --warn-common --warn-once -z combreloc
399 # binutils-2.16.1 warns about ignored sections, 2.16.91.0.3 and newer are ok
400 #LDFLAGS_NOSTRIP+=$(call check_ld,--gc-sections)
401
402 ifeq ($(UCLIBC_BUILD_RELRO),y)
403 LDFLAGS_NOSTRIP+=-z relro
404 endif
405
406 ifeq ($(UCLIBC_BUILD_NOW),y)
407 LDFLAGS_NOSTRIP+=-z now
408 endif
409
410 LDFLAGS:=$(LDFLAGS_NOSTRIP) -z defs
411 ifeq ($(DODEBUG),y)
412 #CFLAGS += -g3
413 CFLAGS += -O0 -g3
414 else
415 CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS)
416 endif
417 ifeq ($(DOSTRIP),y)
418 LDFLAGS += -s
419 else
420 STRIPTOOL := true -Stripping_disabled
421 endif
422
423 ifeq ($(DOMULTI),y)
424 # we try to compile all sources at once into an object (IMA), but
425 # gcc-3.3.x does not support it
426 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
427 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
428 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
429 ifeq ($(GCC_MAJOR_VER),3)
430 DOMULTI:=n
431 else
432 CFLAGS+=$(call check_gcc,--combine,)
433 endif
434 else
435 DOMULTI:=n
436 endif
437
438 ifeq ($(UCLIBC_HAS_THREADS),y)
439 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
440         PTNAME := nptl
441 else
442 ifeq ($(LINUXTHREADS_OLD),y)
443         PTNAME := linuxthreads.old
444 else
445         PTNAME := linuxthreads
446 endif
447 endif
448 PTDIR := $(top_builddir)libpthread/$(PTNAME)
449 # set up system dependencies include dirs (NOTE: order matters!)
450 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
451 PTINC:= -I$(PTDIR)                                              \
452         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)       \
453         -I$(PTDIR)/sysdeps/$(TARGET_ARCH)                       \
454         -I$(PTDIR)/sysdeps/unix/sysv/linux                      \
455         -I$(PTDIR)/sysdeps/pthread                              \
456         -I$(PTDIR)/sysdeps/pthread/bits                         \
457         -I$(PTDIR)/sysdeps/generic                              \
458         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH)                 \
459         -I$(top_srcdir)ldso/include
460 #
461 # Test for TLS if NPTL support was selected.
462 #
463 GCC_HAS_TLS=$(shell \
464         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
465 ifneq ($(GCC_HAS_TLS),)
466 gcc_tls_test_fail:
467         @echo "####";
468         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
469         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
470         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
471         @echo "#### about this problem.";
472         @echo "####";
473         @echo "#### Exiting...";
474         @echo "####";
475         @exit 1;
476 endif
477 else
478 PTINC := \
479         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
480         -I$(PTDIR)/sysdeps/$(TARGET_ARCH) \
481         -I$(PTDIR)/sysdeps/unix/sysv/linux \
482         -I$(PTDIR)/sysdeps/pthread \
483         -I$(PTDIR) \
484         -I$(top_builddir)libpthread
485 endif
486 CFLAGS+=$(PTINC)
487 else
488         PTNAME :=
489         PTINC  :=
490 endif
491 CFLAGS += -I$(KERNEL_HEADERS)
492
493 # Sigh, some stupid versions of gcc can't seem to cope with '-iwithprefix include'
494 #CFLAGS+=-iwithprefix include
495 CFLAGS+=-isystem $(shell $(CC) -print-file-name=include)
496
497 ifneq ($(DOASSERTS),y)
498 CFLAGS+=-DNDEBUG
499 endif
500
501 # Keep the check_as from being needlessly executed
502 ifndef ASFLAGS_NOEXEC
503 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
504 export ASFLAGS_NOEXEC := $(call check_as,--noexecstack)
505 else
506 export ASFLAGS_NOEXEC :=
507 endif
508 endif
509 ASFLAGS = $(ASFLAGS_NOEXEC)
510
511 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
512 LIBGCC:=$(shell $(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name)
513 LIBGCC_DIR:=$(dir $(LIBGCC))
514
515 # moved from libpthread/linuxthreads
516 ifeq ($(UCLIBC_CTOR_DTOR),y)
517 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
518 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
519 endif