OSDN Git Service

Fix bug 430 and reduce ldso size with 1KB :). Not sure if I need to use fstat64,...
[uclinux-h8/uclibc-ng.git] / Rules.mak
index edc9241..c79b36c 100644 (file)
--- a/Rules.mak
+++ b/Rules.mak
 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 
-#--------------------------------------------------------
-# This file contains rules which are shared between multiple Makefiles.
-# All normal configuration options live in the file named ".config".
-# Don't mess with this file unless you know what you are doing.
-
-
-#--------------------------------------------------------
-# If you are running a cross compiler, you will want to set 'CROSS'
-# to something more interesting...  Target architecture is determined
-# by asking the CC compiler what arch it compiles things for, so unless
-# your compiler is broken, you should not need to specify TARGET_ARCH
+#-----------------------------------------------------------
+# This file contains rules which are shared between multiple
+# Makefiles.  All normal configuration options live in the 
+# file named ".config".  Don't mess with this file unless 
+# you know what you are doing.
+
+
+#-----------------------------------------------------------
+# If you are running a cross compiler, you will want to set 
+# 'CROSS' to something more interesting ...  Target 
+# architecture is determined by asking the CC compiler what 
+# arch it compiles things for, so unless your compiler is 
+# broken, you should not need to specify TARGET_ARCH.
 #
 # Most people will set this stuff on the command line, i.e.
 #        make CROSS=arm-linux-
 ifndef CROSS
 CROSS=
 endif
-CC= $(CROSS)gcc
-AR= $(CROSS)ar
-LD= $(CROSS)ld
-NM= $(CROSS)nm
-STRIPTOOL= $(CROSS)strip
+CC         = $(CROSS)gcc
+AR         = $(CROSS)ar
+LD         = $(CROSS)ld
+NM         = $(CROSS)nm
+RANLIB     = $(CROSS)ranlib
+STRIPTOOL  = $(CROSS)strip
 
-INSTALL= install
-LN= ln
-RM= rm -f
+INSTALL    = install
+LN         = ln
+RM         = rm -f
 
 # Select the compiler needed to build binaries for your development system
-HOSTCC=gcc
-HOSTCFLAGS=-O2 -Wall
-
-
-#--------------------------------------------------------
-# Nothing beyond this point should ever be touched by mere mortals.
-# Unless you hang out with the gods, you should probably leave all
-# this stuff alone.
-MAJOR_VERSION:=0
-MINOR_VERSION:=9
-SUBLEVEL:=26
-VERSION:=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
+HOSTCC     = gcc
+HOSTCFLAGS = -O2 -Wall
+
+
+#---------------------------------------------------------
+# Nothing beyond this point should ever be touched by mere
+# mortals.  Unless you hang out with the gods, you should
+# probably leave all this stuff alone.
+MAJOR_VERSION := 0
+MINOR_VERSION := 9
+SUBLEVEL      := 28
+VERSION       := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
 # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
-LC_ALL:= C
+LC_ALL := C
 export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL
 
 SHARED_FULLNAME:=libuClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
@@ -70,30 +73,52 @@ UCLIBC_LDSO:=ld-uClibc.so.$(MAJOR_VERSION)
 LIBNAME:=libc.a
 LIBC:=$(TOPDIR)libc/$(LIBNAME)
 
+# Make sure DESTDIR and PREFIX can be used to install
+# PREFIX is a uClibcism while DESTDIR is a common GNUism
+ifndef PREFIX
+PREFIX = $(DESTDIR)
+endif
+
 # Pull in the user's uClibc configuration
 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
 -include $(TOPDIR).config
 endif
 
+ifndef CROSS
+CROSS=$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
+endif
+
 # A nifty macro to make testing gcc features easier
-check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
+check_gcc=$(shell \
+       if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
        then echo "$(1)"; else echo "$(2)"; fi)
+check_as=$(shell \
+       if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \
+       then echo "-Wa,$(1)"; fi)
+
+# Setup some shortcuts so that silent mode is silent like it should be
+ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS))
+export MAKE_IS_SILENT=n
+SECHO=@echo
+SHELL_SET_X=set -x
+else
+export MAKE_IS_SILENT=y
+SECHO=-@false
+SHELL_SET_X=set +x
+endif
 
 # Make certain these contain a final "/", but no "//"s.
-TARGET_ARCH:=$(strip $(subst ",, $(strip $(TARGET_ARCH))))
+TARGET_ARCH:=$(shell grep -s ^TARGET_ARCH $(TOPDIR)/.config | sed -e 's/^TARGET_ARCH=//' -e 's/"//g')
 RUNTIME_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(RUNTIME_PREFIX))))))
 DEVEL_PREFIX:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(DEVEL_PREFIX))))))
-export RUNTIME_PREFIX DEVEL_PREFIX
+KERNEL_SOURCE:=$(strip $(subst //,/, $(subst ,/, $(subst ",, $(strip $(KERNEL_SOURCE))))))
+export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_SOURCE
 
-ARFLAGS:=r
+ARFLAGS:=cr
 
 OPTIMIZATION:=
 PICFLAG:=-fPIC
-
-PIEFLAG:=$(call check_gcc,-fPIE,)
-ifeq ($(strip $(PIEFLAG)),-fPIE)
-LDPIEFLAG:=$(shell $(LD) --help | grep -q pie && echo "-Wl,-pie")
-endif
+PIEFLAG_NAME:=-fPIE
 
 # Some nice CPU specific optimizations
 ifeq ($(strip $(TARGET_ARCH)),i386)
@@ -117,6 +142,13 @@ ifeq ($(strip $(TARGET_ARCH)),i386)
        CPU_CFLAGS-$(CONFIG_NEHEMIAH)+=$(call check_gcc,-march=c3-2,-march=i686)
 endif
 
+ifeq ($(strip $(TARGET_ARCH)),sparc)
+       CPU_CFLAGS-$(CONFIG_SPARC_V7)+=-mcpu=v7
+       CPU_CFLAGS-$(CONFIG_SPARC_V8)+=-mcpu=v8
+       CPU_CFLAGS-$(CONFIG_SPARC_V9)+=-mcpu=v9
+       CPU_CFLAGS-$(CONFIG_SPARC_V9B)+=$(call check_gcc,-mcpu=v9b,-mcpu=ultrasparc)
+endif
+
 ifeq ($(strip $(TARGET_ARCH)),arm)
        OPTIMIZATION+=-fstrict-aliasing
        CPU_LDFLAGS-$(ARCH_LITTLE_ENDIAN)+=-EL
@@ -129,7 +161,8 @@ ifeq ($(strip $(TARGET_ARCH)),arm)
        CPU_CFLAGS-$(CONFIG_ARM720T)+=-mtune=arm7tdmi -march=armv4
        CPU_CFLAGS-$(CONFIG_ARM920T)+=-mtune=arm9tdmi -march=armv4
        CPU_CFLAGS-$(CONFIG_ARM922T)+=-mtune=arm9tdmi -march=armv4
-       CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv4
+       CPU_CFLAGS-$(CONFIG_ARM926T)+=-mtune=arm9tdmi -march=armv5
+       CPU_CFLAGS-$(CONFIG_ARM1136JF_S)+=-mtune=arm1136jf-s -march=armv6
        CPU_CFLAGS-$(CONFIG_ARM_SA110)+=-mtune=strongarm110 -march=armv4
        CPU_CFLAGS-$(CONFIG_ARM_SA1100)+=-mtune=strongarm1100 -march=armv4
        CPU_CFLAGS-$(CONFIG_ARM_XSCALE)+=$(call check_gcc,-mtune=xscale,-mtune=strongarm110)
@@ -154,7 +187,13 @@ ifeq ($(strip $(TARGET_ARCH)),sh)
        CPU_CFLAGS-$(ARCH_BIG_ENDIAN)+=-mb
        CPU_CFLAGS-$(CONFIG_SH2)+=-m2
        CPU_CFLAGS-$(CONFIG_SH3)+=-m3
+ifeq ($(strip $(UCLIBC_HAS_FLOATS)),y)
+       CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a
        CPU_CFLAGS-$(CONFIG_SH4)+=-m4
+else
+       CPU_CFLAGS-$(CONFIG_SH2A)+=-m2a-nofpu
+       CPU_CFLAGS-$(CONFIG_SH4)+=-m4-nofpu
+endif
 endif
 
 ifeq ($(strip $(TARGET_ARCH)),sh64)
@@ -177,7 +216,7 @@ ifeq ($(strip $(TARGET_ARCH)),cris)
        CPU_LDFLAGS-$(CONFIG_CRIS)+=-mcrislinux
        CPU_CFLAGS-$(CONFIG_CRIS)+=-mlinux
        PICFLAG:=-fpic
-       PIEFLAG:=$(call check_gcc,-fpie,)
+       PIEFLAG_NAME:=-fpie
 endif
 
 ifeq ($(strip $(TARGET_ARCH)),powerpc)
@@ -185,28 +224,45 @@ ifeq ($(strip $(TARGET_ARCH)),powerpc)
 # enough. Therefore use -fpic which will reduce code size and generates
 # faster code.
        PICFLAG:=-fpic
-       PIEFLAG:=$(call check_gcc,-fpie,)
+       PIEFLAG_NAME:=-fpie
 endif
 
 ifeq ($(strip $(TARGET_ARCH)),frv)
        CPU_LDFLAGS-$(CONFIG_FRV)+=-melf32frvfd
        CPU_CFLAGS-$(CONFIG_FRV)+=-mfdpic
-       PICFLAG=-fPIC -DPIC
        # Using -pie causes the program to have an interpreter, which is
        # forbidden, so we must make do with -shared.  Unfortunately,
        # -shared by itself would get us global function descriptors
        # and calls through PLTs, dynamic resolution of symbols, etc,
        # which would break as well, but -Bsymbolic comes to the rescue.
-       LDPIEFLAG=-shared -Bsymbolic
+       export LDPIEFLAG:=-shared -Bsymbolic
        UCLIBC_LDSO=ld.so.1
 endif
 
+# Keep the check_gcc from being needlessly executed
+ifndef PIEFLAG
+ifneq ($(UCLIBC_BUILD_PIE),y)
+export PIEFLAG:=
+else
+export PIEFLAG:=$(call check_gcc,$(PIEFLAG_NAME),$(PICFLAG))
+endif
+endif
+# We need to keep track of both the CC PIE flag (above) as 
+# well as the LD PIE flag (below) because we can't rely on 
+# gcc passing -pie if we used -fPIE
+ifndef LDPIEFLAG
+ifneq ($(UCLIBC_BUILD_PIE),y)
+export LDPIEFLAG:=
+else
+export LDPIEFLAG:=$(shell $(LD) --help | grep -q pie && echo "-Wl,-pie")
+endif
+endif
+
 # Use '-Os' optimization if available, else use -O2, allow Config to override
 OPTIMIZATION+=$(call check_gcc,-Os,-O2)
 # Use the gcc 3.4 -funit-at-a-time optimization when available
 OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
 
-
 # Add a bunch of extra pedantic annoyingly strict checks
 XWARNINGS=$(subst ",, $(strip $(WARNINGS))) -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
 XARCH_CFLAGS=$(subst ",, $(strip $(ARCH_CFLAGS)))
@@ -226,32 +282,28 @@ ifeq ($(strip $(TARGET_ARCH)),arm)
 endif
 endif
 
-ifneq ($(UCLIBC_BUILD_PIE),y)
-PIEFLAG=
-LDPIEFLAG=
-endif
-
-SSP_DISABLE_FLAGS=$(call check_gcc,-fno-stack-protector,)
+SSP_DISABLE_FLAGS:=$(call check_gcc,-fno-stack-protector,)
 ifeq ($(UCLIBC_BUILD_SSP),y)
-SSP_CFLAGS=$(call check_gcc,-fno-stack-protector-all,)
+SSP_CFLAGS:=$(call check_gcc,-fno-stack-protector-all,)
 SSP_CFLAGS+=$(call check_gcc,-fstack-protector,)
-SSP_ALL_CFLAGS=$(call check_gcc,-fstack-protector-all,)
+SSP_ALL_CFLAGS:=$(call check_gcc,-fstack-protector-all,)
 else
-SSP_CFLAGS=$(SSP_DISABLE_FLAGS)
+SSP_CFLAGS:=$(SSP_DISABLE_FLAGS)
 endif
 
 # Some nice CFLAGS to work with
-CFLAGS=$(XWARNINGS) $(OPTIMIZATION) $(XARCH_CFLAGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
+CFLAGS:=$(XWARNINGS) $(CPU_CFLAGS) $(SSP_CFLAGS) \
        -fno-builtin -nostdinc -D_LIBC -I$(TOPDIR)include -I.
+LDFLAGS_NOSTRIP:=$(CPU_LDFLAGS-y) -shared --warn-common --warn-once -z combreloc -z defs
 
 ifeq ($(DODEBUG),y)
     #CFLAGS += -g3
-    CFLAGS = $(XWARNINGS) -O0 -g3 $(CPU_CFLAGS) $(SSP_CFLAGS) \
-       -fno-builtin -nostdinc -D_LIBC -I$(TOPDIR)include -I.
-    LDFLAGS:= $(CPU_LDFLAGS-y) -shared --warn-common --warn-once -z combreloc
+    CFLAGS += -O0 -g3
+    LDFLAGS := $(LDFLAGS_NOSTRIP)
     STRIPTOOL:= true -Since_we_are_debugging
 else
-    LDFLAGS := $(CPU_LDFLAGS-y) -s -shared --warn-common --warn-once -z combreloc
+    CFLAGS += $(OPTIMIZATION) $(XARCH_CFLAGS)
+    LDFLAGS := $(LDFLAGS_NOSTRIP) -s
 endif
 
 ifeq ($(UCLIBC_BUILD_RELRO),y)
@@ -270,26 +322,21 @@ ifneq ($(DOASSERTS),y)
     CFLAGS += -DNDEBUG
 endif
 
-ifeq ($(HAVE_SHARED),y)
-    ifeq ($(BUILD_UCLIBC_LDSO),y)
-       LDSO:=$(TOPDIR)lib/$(UCLIBC_LDSO)
-       DYNAMIC_LINKER:=$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)
-    else
-       LDSO:=$(SYSTEM_LDSO)
-       DYNAMIC_LINKER:=/lib/$(strip $(subst ",, $(notdir $(SYSTEM_LDSO))))
-   endif
-endif
-
 CFLAGS_NOPIC:=$(CFLAGS)
 ifeq ($(DOPIC),y)
     CFLAGS += $(PICFLAG)
 endif
 
+# Keep the check_as from being needlessly executed
 ASFLAGS = $(CFLAGS)
+ifndef ASFLAGS_NOEXEC
 ifeq ($(UCLIBC_BUILD_NOEXECSTACK),y)
-check_as_noexecstack=$(shell if $(LD) --help | grep -q "z noexecstack"; then echo "-Wa,--noexecstack"; fi)
-ASFLAGS += $(check_as_noexecstack)
+export ASFLAGS_NOEXEC := $(call check_as,--noexecstack)
+else
+export ASFLAGS_NOEXEC :=
 endif
+endif
+ASFLAGS += $(ASFLAGS_NOEXEC)
 
 LIBGCC_CFLAGS ?= $(CFLAGS) $(CPU_CFLAGS-y)
 LIBGCC:=$(shell $(CC) $(LIBGCC_CFLAGS) -print-libgcc-file-name)
@@ -309,4 +356,3 @@ ifeq ($(CONFIG_BINFMT_SHARED_FLAT),y)
 endif
 
 TARGET_ARCH:=$(strip $(subst ",, $(strip $(TARGET_ARCH))))
-