OSDN Git Service

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