OSDN Git Service

TARGET_ARCH is already stripped, do not do it again for nios2
[uclinux-h8/uClibc.git] / Rules.mak
1 # Rules.make for uClibc
2 #
3 # Copyright (C) 2000 by Lineo, inc.
4 # Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 #
6 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 #
8
9 #-----------------------------------------------------------
10 # This file contains rules which are shared between multiple
11 # Makefiles.  All normal configuration options live in the 
12 # file named ".config".  Don't mess with this file unless 
13 # you know what you are doing.
14
15
16 #-----------------------------------------------------------
17 # If you are running a cross compiler, you will want to set 
18 # 'CROSS' to something more interesting ...  Target 
19 # architecture is determined by asking the CC compiler what 
20 # arch it compiles things for, so unless your compiler is 
21 # broken, you should not need to specify TARGET_ARCH.
22 #
23 # Most people will set this stuff on the command line, i.e.
24 #        make CROSS=arm-linux-
25 # will build uClibc for 'arm'.
26
27 ifndef CROSS
28 CROSS=
29 endif
30 CC         = $(CROSS)gcc
31 AR         = $(CROSS)ar
32 LD         = $(CROSS)ld
33 NM         = $(CROSS)nm
34 STRIPTOOL  = $(CROSS)strip
35
36 INSTALL    = install
37 LN         = ln
38 RM         = rm -f
39
40 STRIP_FLAGS ?= -x -R .note -R .comment
41
42 # Select the compiler needed to build binaries for your development system
43 HOSTCC     = gcc
44 BUILD_CFLAGS = -O2 -Wall
45
46
47 #---------------------------------------------------------
48 # Nothing beyond this point should ever be touched by mere
49 # mortals.  Unless you hang out with the gods, you should
50 # probably leave all this stuff alone.
51 MAJOR_VERSION := 0
52 MINOR_VERSION := 9
53 SUBLEVEL      := 28
54 VERSION       := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
55 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
56 LC_ALL := C
57 export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL
58
59 LIBC := libc
60 SHARED_MAJORNAME := $(LIBC).so.$(MAJOR_VERSION)
61 UCLIBC_LDSO := ld-uClibc.so.$(MAJOR_VERSION)
62 NONSHARED_LIBNAME := uclibc_nonshared.a
63 libc := $(top_builddir)lib/$(SHARED_MAJORNAME)
64 interp := $(top_builddir)lib/interp.os
65 ldso := $(top_builddir)lib/$(UCLIBC_LDSO)
66 headers_dep := $(top_builddir)include/bits/sysnum.h
67
68 #LIBS :=$(interp) -L$(top_builddir)lib -lc
69 LIBS := $(interp) -L$(top_builddir)lib $(libc:.$(MAJOR_VERSION)=)
70
71 # Make sure DESTDIR and PREFIX can be used to install
72 # PREFIX is a uClibcism while DESTDIR is a common GNUism
73 ifndef PREFIX
74 PREFIX = $(DESTDIR)
75 endif
76
77 # Pull in the user's uClibc configuration
78 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
79 -include $(top_builddir).config
80 endif
81
82 ifndef CROSS
83 CROSS=$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
84 endif
85
86 # A nifty macro to make testing gcc features easier
87 check_gcc=$(shell \
88         if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
89         then echo "$(1)"; else echo "$(2)"; fi)
90 check_as=$(shell \
91         if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
92         then echo "-Wa,$(1)"; fi)
93
94 # Setup some shortcuts so that silent mode is silent like it should be
95 ifeq ($(findstring s,$(MAKEFLAGS)),)
96 export MAKE_IS_SILENT=n
97 SECHO=@echo
98 SHELL_SET_X=set -x
99 else
100 export MAKE_IS_SILENT=y
101 SECHO=-@false
102 SHELL_SET_X=set +x
103 endif
104
105 # Make certain these contain a final "/", but no "//"s.
106 TARGET_ARCH:=$(shell grep -s '^TARGET_ARCH' $(top_builddir)/.config | sed -e 's/^TARGET_ARCH=//' -e 's/"//g')
107 TARGET_ARCH:=$(strip $(subst ",, $(strip $(TARGET_ARCH))))
108 RUNTIME_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(RUNTIME_PREFIX))))))
109 DEVEL_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(DEVEL_PREFIX))))))
110 KERNEL_SOURCE:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(KERNEL_SOURCE))))))
111 export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_SOURCE
112
113 ARFLAGS:=cr
114
115 OPTIMIZATION:=
116 PICFLAG:=-fPIC
117 PIEFLAG_NAME:=-fPIE
118
119 # Some nice CPU specific optimizations
120 ifeq ($(TARGET_ARCH),i386)
121         OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
122         OPTIMIZATION+=$(call check_gcc,-falign-jumps=0 -falign-loops=0,-malign-jumps=0 -malign-loops=0)
123         CPU_CFLAGS-$(CONFIG_386)+=-march=i386
124         CPU_CFLAGS-$(CONFIG_486)+=-march=i486
125         CPU_CFLAGS-$(CONFIG_ELAN)+=-march=i486
126         CPU_CFLAGS-$(CONFIG_586)+=-march=i586
127         CPU_CFLAGS-$(CONFIG_586MMX)+=$(call check_gcc,-march=pentium-mmx,-march=i586)
128         CPU_CFLAGS-$(CONFIG_686)+=-march=i686
129         CPU_CFLAGS-$(CONFIG_PENTIUMII)+=$(call check_gcc,-march=pentium2,-march=i686)
130         CPU_CFLAGS-$(CONFIG_PENTIUMIII)+=$(call check_gcc,-march=pentium3,-march=i686)
131         CPU_CFLAGS-$(CONFIG_PENTIUM4)+=$(call check_gcc,-march=pentium4,-march=i686)
132         CPU_CFLAGS-$(CONFIG_K6)+=$(call check_gcc,-march=k6,-march=i586)
133         CPU_CFLAGS-$(CONFIG_K7)+=$(call check_gcc,-march=athlon,-march=i686) $(call check_gcc,-falign-functions=4,-malign-functions=4)
134         CPU_CFLAGS-$(CONFIG_CRUSOE)+=-march=i686 $(call check_gcc,-falign-functions=0,-malign-functions=0)
135         CPU_CFLAGS-$(CONFIG_WINCHIPC6)+=$(call check_gcc,-march=winchip-c6,-march=i586)
136         CPU_CFLAGS-$(CONFIG_WINCHIP2)+=$(call check_gcc,-march=winchip2,-march=i586)
137         CPU_CFLAGS-$(CONFIG_CYRIXIII)+=$(call check_gcc,-march=c3,-march=i486) $(call check_gcc,-falign-functions=0,-malign-functions=0)
138         CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
139 endif
140
141 ifeq ($(TARGET_ARCH),sparc)
142         CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
143         CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
144         CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
145         CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
146 endif
147
148 ifeq ($(TARGET_ARCH),arm)
149         OPTIMIZATION+=-fstrict-aliasing
150         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
151         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB
152         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-mlittle-endian
153         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mbig-endian
154         CPU_CFLAGS-$(CONFIG_GENERIC_ARM)+=
155         CPU_CFLAGS-$(CONFIG_ARM610)+=-mtune=arm610 -march=armv3
156         CPU_CFLAGS-$(CONFIG_ARM710)+=-mtune=arm710 -march=armv3
157         CPU_CFLAGS-$(CONFIG_ARM720T)+=-mtune=arm7tdmi -march=armv4
158         CPU_CFLAGS-$(CONFIG_ARM920T)+=-mtune=arm9tdmi -march=armv4
159         CPU_CFLAGS-$(CONFIG_ARM922T)+=-mtune=arm9tdmi -march=armv4
160         CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv5
161         CPU_CFLAGS-$(CONFIG_ARM1136JF_S)+=-mtune=arm1136jf-s -march=armv6
162         CPU_CFLAGS-$(CONFIG_ARM_SA110)+=-mtune=strongarm110 -march=armv4
163         CPU_CFLAGS-$(CONFIG_ARM_SA1100)+=-mtune=strongarm1100 -march=armv4
164         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=$(call check_gcc,-mtune=xscale,-mtune=strongarm110)
165         CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=-march=armv4 -Wa,-mcpu=xscale
166 endif
167
168 ifeq ($(TARGET_ARCH),mips)
169         CPU_CFLAGS-$(CONFIG_MIPS_ISA_1)+=-mips1
170         CPU_CFLAGS-$(CONFIG_MIPS_ISA_2)+=-mips2 -mtune=mips2
171         CPU_CFLAGS-$(CONFIG_MIPS_ISA_3)+=-mips3 -mtune=mips3
172         CPU_CFLAGS-$(CONFIG_MIPS_ISA_4)+=-mips4 -mtune=mips4
173         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS32)+=-mips32 -mtune=mips32
174         CPU_CFLAGS-$(CONFIG_MIPS_ISA_MIPS64)+=-mips64 -mtune=mips32
175 endif
176
177 ifeq ($(TARGET_ARCH),sh)
178         OPTIMIZATION+=-fstrict-aliasing
179         OPTIMIZATION+= $(call check_gcc,-mprefergot,)
180         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
181         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN)+=-EB
182         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN)+=-ml
183         CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
184         CPU_CFLAGS-$(CONFIG_SH2)+=-m2
185         CPU_CFLAGS-$(CONFIG_SH3)+=-m3
186 ifeq ($(UCLIBC_HAS_FLOATS),y)
187         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
188         CPU_CFLAGS-$(CONFIG_SH4)+=-m4
189 else
190         CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
191         CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
192 endif
193 endif
194
195 ifeq ($(TARGET_ARCH),sh64)
196         OPTIMIZATION+=-fstrict-aliasing
197         CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN):=-EL
198         CPU_LDFLAGS-$(ARCH_BIG_ENDIAN):=-EB
199         CPU_CFLAGS-$(ARCH_LITTLE_ENDIAN):=-ml
200         CPU_CFLAGS-$(ARCH_BIG_ENDIAN):=-mb
201         CPU_CFLAGS-$(CONFIG_SH5)+=-m5-32media
202 endif
203
204 ifeq ($(TARGET_ARCH),h8300)
205         CPU_LDFLAGS-$(CONFIG_H8300H)+= -ms8300h
206         CPU_LDFLAGS-$(CONFIG_H8S)   += -ms8300s
207         CPU_CFLAGS-$(CONFIG_H8300H) += -mh -mint32 -fsigned-char
208         CPU_CFLAGS-$(CONFIG_H8S)    += -ms -mint32 -fsigned-char
209 endif
210
211 ifeq ($(TARGET_ARCH),cris)
212         CPU_LDFLAGS-$(CONFIG_CRIS)+=-mcrislinux
213         CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
214         PICFLAG:=-fpic
215         PIEFLAG_NAME:=-fpie
216 endif
217
218 ifeq ($(TARGET_ARCH),powerpc)
219 # PowerPC can hold 8192 entries in its GOT with -fpic which is more than
220 # enough. Therefore use -fpic which will reduce code size and generates
221 # faster code.
222         PICFLAG:=-fpic
223         PIEFLAG_NAME:=-fpie
224 endif
225
226 ifeq ($(TARGET_ARCH),frv)
227         CPU_LDFLAGS-$(CONFIG_FRV)+=-melf32frvfd
228         CPU_CFLAGS-$(CONFIG_FRV)+=-mfdpic
229         # Using -pie causes the program to have an interpreter, which is
230         # forbidden, so we must make do with -shared.  Unfortunately,
231         # -shared by itself would get us global function descriptors
232         # and calls through PLTs, dynamic resolution of symbols, etc,
233         # which would break as well, but -Bsymbolic comes to the rescue.
234         export LDPIEFLAG:=-shared -Bsymbolic
235         UCLIBC_LDSO=ld.so.1
236 endif
237
238 # Keep the check_gcc from being needlessly executed
239 ifndef PIEFLAG
240 ifneq ($(UCLIBC_BUILD_PIE),y)
241 export PIEFLAG:=
242 else
243 export PIEFLAG:=$(call check_gcc,$(PIEFLAG_NAME),$(PICFLAG))
244 endif
245 endif
246 # We need to keep track of both the CC PIE flag (above) as 
247 # well as the LD PIE flag (below) because we can't rely on 
248 # gcc passing -pie if we used -fPIE
249 ifndef LDPIEFLAG
250 ifneq ($(UCLIBC_BUILD_PIE),y)
251 export LDPIEFLAG:=
252 else
253 export LDPIEFLAG:=$(shell $(LD) --help | grep -q pie && echo "-Wl,-pie")
254 endif
255 endif
256
257 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
258 ifndef ASNEEDED
259 ifneq ($(UCLIBC_HAS_SSP),y)
260 export ASNEEDED:=
261 else
262 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 ) )
263 endif
264 endif
265
266 # Use '-Os' optimization if available, else use -O2, allow Config to override
267 OPTIMIZATION+=$(call check_gcc,-Os,-O2)
268 # Use the gcc 3.4 -funit-at-a-time optimization when available
269 OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
270
271 # Add a bunch of extra pedantic annoyingly strict checks
272 XWARNINGS=$(subst ",, $(strip $(WARNINGS))) -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
273 XARCH_CFLAGS=$(subst ",, $(strip $(ARCH_CFLAGS)))
274 CPU_CFLAGS=$(subst ",, $(strip $(CPU_CFLAGS-y)))
275
276 LDADD_LIBFLOAT=
277 ifeq ($(UCLIBC_HAS_SOFT_FLOAT),y)
278 # Add -msoft-float to the CPU_FLAGS since ldso and libdl ignore CFLAGS.
279 # If -msoft-float isn't supported, we want an error anyway.
280 # Hmm... might need to revisit this for arm since it has 2 different
281 # soft float encodings.
282 ifneq ($(TARGET_ARCH),nios2)
283     CPU_CFLAGS += -msoft-float
284 endif
285 ifeq ($(TARGET_ARCH),arm)
286 # No longer needed with current toolchains, but leave it here for now.
287 # If anyone is actually still using gcc 2.95 (say), they can uncomment it.
288 #    LDADD_LIBFLOAT=-lfloat
289 endif
290 endif
291
292 SSP_DISABLE_FLAGS?=$(call check_gcc,-fno-stack-protector,)
293 ifeq ($(UCLIBC_BUILD_SSP),y)
294 SSP_CFLAGS:=$(call check_gcc,-fno-stack-protector-all,)
295 SSP_CFLAGS+=$(call check_gcc,-fstack-protector,)
296 SSP_ALL_CFLAGS?=$(call check_gcc,-fstack-protector-all,)
297 else
298 SSP_CFLAGS:=$(SSP_DISABLE_FLAGS)
299 endif
300
301 # Some nice CFLAGS to work with
302 CFLAGS:=$(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
303         -fno-builtin -nostdinc -D_LIBC -I$(top_builddir)include -I.
304
305 LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared --warn-common --warn-once -z combreloc
306
307 ifeq ($(UCLIBC_BUILD_RELRO),y)
308 LDFLAGS_NOSTRIP+=-z relro
309 endif
310
311 ifeq ($(UCLIBC_BUILD_NOW),y)
312 LDFLAGS_NOSTRIP+=-z now
313 endif
314
315 LDFLAGS:=$(LDFLAGS_NOSTRIP) -z defs
316 ifeq ($(DODEBUG),y)
317     #CFLAGS += -g3
318     CFLAGS += -O0 -g3
319     STRIPTOOL:= true -Since_we_are_debugging
320 else
321     CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS)
322     LDFLAGS += -s
323 endif
324
325 ifeq ($(DOMULTI),y)
326 # we try to compile all sources at once into an object (IMA), but
327 # gcc-3.3.x does not support it
328 # gcc-3.4.x supports it, but does not need and support --combine. though fails on many sources
329 # gcc-4.0.x supports it, supports the --combine flag, but does not need it
330 # gcc-4.1(200506xx) supports it, but needs the --combine flag, else libs are useless
331 GCC_VER?=$(shell $(CC) -dumpversion | cut -d . -f 1)
332 ifeq ($(GCC_VER),3)
333 DOMULTI:=n
334 else
335 CFLAGS+=$(call check_gcc,--combine,)
336 endif
337 else
338 DOMULTI:=n
339 endif
340
341 ifeq ($(UCLIBC_HAS_THREADS),y)
342 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
343         PTNAME := nptl
344 else
345 ifeq ($(LINUXTHREADS_OLD),y)
346         PTNAME := linuxthreads.old
347 else
348         PTNAME := linuxthreads
349 endif
350 endif
351 PTDIR := $(top_builddir)libpthread/$(PTNAME)
352 # set up system dependencies include dirs (NOTE: order matters!)
353 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
354 PTINC:= -I$(PTDIR)                                              \
355         -I$(PTDIR)/compat                                       \
356         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)       \
357         -I$(PTDIR)/sysdeps/$(TARGET_ARCH)                       \
358         -I$(PTDIR)/sysdeps/unix/sysv/linux                      \
359         -I$(PTDIR)/sysdeps/pthread                              \
360         -I$(PTDIR)/sysdeps/pthread/bits                         \
361         -I$(PTDIR)/sysdeps/generic                              \
362         -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH)                 \
363         -I$(top_srcdir)ldso/include                             \
364         -include $(PTDIR)/compat/libc-symbols.h
365 #
366 # Test for TLS if NPTL support was selected.
367 #
368 GCC_HAS_TLS=$(shell \
369         echo "extern __thread int foo;" | $(CC) -o /dev/null -S -xc - 2>&1)
370 ifneq ($(GCC_HAS_TLS),)
371 gcc_tls_test_fail:
372         @echo "####";
373         @echo "#### Your compiler does not support TLS and you are trying to build uClibc";
374         @echo "#### with NPTL support. Upgrade your binutils and gcc to versions which";
375         @echo "#### support TLS for your architecture. Do not contact uClibc maintainers";
376         @echo "#### about this problem.";
377         @echo "####";
378         @echo "#### Exiting...";
379         @echo "####";
380         @exit 1;
381 endif
382 else
383 PTINC := \
384         -I$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH) \
385         -I$(PTDIR)/sysdeps/$(TARGET_ARCH) \
386         -I$(PTDIR)/sysdeps/unix/sysv/linux \
387         -I$(PTDIR)/sysdeps/pthread \
388         -I$(PTDIR) \
389         -I$(top_builddir)libpthread
390 endif
391 CFLAGS+=$(PTINC)
392 else
393         PTNAME := 
394         PTINC  := 
395 endif
396
397 # Sigh, some stupid versions of gcc can't seem to cope with '-iwithprefix include'
398 #CFLAGS+=-iwithprefix include
399 CFLAGS+=-isystem $(shell $(CC) -print-file-name=include)
400
401 ifneq ($(DOASSERTS),y)
402 CFLAGS+=-DNDEBUG
403 endif
404
405 ifneq ($(strip $(C_SYMBOL_PREFIX)),"")
406 CFLAGS+=-D__SYMBOL_PREFIX=1
407 endif
408
409 # moved from ldso/{ldso,libdl}
410 # BEWARE!!! At least mips* will die if -O0 is used!!!
411 ifeq ($(TARGET_ARCH),mips)
412 CFLAGS:=$(CFLAGS:-O0=-O1)
413 endif
414
415 # Keep the check_as from being needlessly executed
416 ifndef ASFLAGS_NOEXEC
417 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
418 export ASFLAGS_NOEXEC := $(call check_as,--noexecstack)
419 else
420 export ASFLAGS_NOEXEC :=
421 endif
422 endif
423 ASFLAGS = $(ASFLAGS_NOEXEC)
424
425 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
426 LIBGCC:=$(shell $(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name)
427 LIBGCC_DIR:=$(dir $(LIBGCC))
428
429 # moved from libpthread/linuxthreads
430 ifeq ($(UCLIBC_CTOR_DTOR),y)
431 SHARED_START_FILES:=$(top_builddir)lib/crti.o $(LIBGCC_DIR)crtbeginS.o
432 SHARED_END_FILES:=$(LIBGCC_DIR)crtendS.o $(top_builddir)lib/crtn.o
433 endif
434
435 ########################################
436 #
437 # uClinux shared lib support
438 #
439
440 ifeq ($(CONFIG_BINFMT_SHARED_FLAT),y)
441   # For the shared version of this, we specify no stack and its library ID
442   FLTFLAGS += -s 0
443   LIBID=1
444   export LIBID FLTFLAGS
445   SHARED_TARGET = lib/libc
446 endif