setlogcons, from Jan Kaszka.
[oweals/busybox.git] / Rules.mak
index c1a61e30c3d7b5810336f327f28c59c7ff99209d..a70ef8cc5e8b47188dc8cd4256fbf3fc9aeb63c8 100644 (file)
--- a/Rules.mak
+++ b/Rules.mak
@@ -14,8 +14,8 @@ endif
 PROG      := busybox
 MAJOR_VERSION   :=1
 MINOR_VERSION   :=1
-SUBLEVEL_VERSION:=0
-EXTRAVERSION    :=-pre1
+SUBLEVEL_VERSION:=1
+EXTRAVERSION    :=
 VERSION   :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
 BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
 
@@ -39,15 +39,7 @@ LD             = $(CROSS)ld
 NM             = $(CROSS)nm
 STRIP          = $(CROSS)strip
 CPP            = $(CC) -E
-# MAKEFILES      = $(top_builddir)/.config
-RM             = rm
-RM_F           = $(RM) -f
-LN             = ln
-LN_S           = $(LN) -s
-MKDIR          = mkdir
-MKDIR_P        = $(MKDIR) -p
-MV             = mv
-CP             = cp
+SED           ?= sed
 
 
 # What OS are you compiling busybox for?  This allows you to include
@@ -81,7 +73,8 @@ CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
 #GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
 
 WARNINGS=-Wall -Wstrict-prototypes -Wshadow
-CFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
+CFLAGS+=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
+
 ARFLAGS=cru
 
 
@@ -114,17 +107,16 @@ check_gcc=$(shell \
                then echo "$(1)"; else echo "$(2)"; fi \
        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
-else
-export MAKE_IS_SILENT=y
-SECHO=-@false
-endif
+# A not very robust macro to check for available ld flags
+check_ld=$(shell \
+       if [ "x$(1)" != "x" ]; then \
+               $(LD) --help | grep -q "\$(1)" && echo "-Wl,$(1)" ; \
+       fi)
 
 CFLAGS+=$(call check_gcc,-funsigned-char,)
 
+CFLAGS+=$(call check_gcc,-mmax-stack-frame=256,)
+
 #--------------------------------------------------------
 # Arch specific compiler optimization stuff should go here.
 # Unless you want to override the defaults, do not set anything
@@ -133,17 +125,46 @@ CFLAGS+=$(call check_gcc,-funsigned-char,)
 # use '-Os' optimization if available, else use -O2
 OPTIMIZATION:=$(call check_gcc,-Os,-O2)
 
+ifeq ($(CONFIG_BUILD_AT_ONCE),y)
+# gcc 2.95 exits with 0 for "unrecognized option"
+ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 3 ] ; echo $$?)),0)
+       CFLAGS_COMBINE:=$(call check_gcc,--combine,)
+endif
+OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25795
+#PROG_CFLAGS+=$(call check_gcc,-fwhole-program,)
+endif # CONFIG_BUILD_AT_ONCE
+
+LIB_LDFLAGS:=$(call check_ld,--enable-new-dtags,)
+#LIB_LDFLAGS+=$(call check_ld,--reduce-memory-overheads,)
+#LIB_LDFLAGS+=$(call check_ld,--as-needed,)
+#LIB_LDFLAGS+=$(call check_ld,--warn-shared-textrel,)
+
+
 # Some nice architecture specific optimizations
 ifeq ($(strip $(TARGET_ARCH)),arm)
        OPTIMIZATION+=-fstrict-aliasing
 endif
 ifeq ($(strip $(TARGET_ARCH)),i386)
        OPTIMIZATION+=$(call check_gcc,-march=i386,)
+# gcc-4.0 and older seem to benefit from these
+#ifneq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
        OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
-       OPTIMIZATION+=$(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,\
+       OPTIMIZATION+=$(call check_gcc,-falign-functions=1 -falign-jumps=1 -falign-loops=1,\
                -malign-functions=0 -malign-jumps=0 -malign-loops=0)
+#endif # gcc-4.0 and older
+
+# gcc-4.1 and beyond seem to benefit from these
+ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
+       # turn off flags which hurt -Os
+       OPTIMIZATION+=$(call check_gcc,-fno-tree-loop-optimize,)
+       OPTIMIZATION+=$(call check_gcc,-fno-tree-dominator-opts,)
+       OPTIMIZATION+=$(call check_gcc,-fno-strength-reduce,)
+
+       OPTIMIZATION+=$(call check_gcc,-fno-branch-count-reg,)
+endif # gcc-4.1 and beyond
 endif
-OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
+OPTIMIZATIONS:=$(OPTIMIZATION) $(call check_gcc,-fomit-frame-pointer,)
 
 #
 #--------------------------------------------------------
@@ -169,19 +190,31 @@ else
 endif
 ifeq ($(strip $(CONFIG_DEBUG)),y)
     CFLAGS  +=$(WARNINGS) -g -D_GNU_SOURCE
-    LDFLAGS +=-Wl,-warn-common
-    STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
+    LDFLAGS += $(call check_ld,--warn-common,)
 else
     CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
-    LDFLAGS += -Wl,-warn-common
-    STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
+    LDFLAGS += $(call check_ld,--warn-common,)
+    LDFLAGS += $(call check_ld,--sort-common,)
 endif
+STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
 ifeq ($(strip $(CONFIG_STATIC)),y)
-    LDFLAGS += --static
+    PROG_CFLAGS += $(call check_gcc,-static,)
 endif
+CFLAGS_SHARED += $(call check_gcc,-shared,)
+LIB_CFLAGS+=$(CFLAGS_SHARED)
+
+ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
+    CFLAGS_PIC:= $(call check_gcc,-fPIC,)
+    LIB_CFLAGS+=$(CFLAGS_PIC)
+endif
+
 
 ifeq ($(strip $(CONFIG_SELINUX)),y)
-    LIBRARIES += -lselinux
+    SELINUX_INC ?= /usr/include
+    SELINUX_LIB ?= /usr/lib
+    CFLAGS      := -I$(SELINUX_INC) $(CFLAGS)
+    LDFLAGS     := -L$(SELINUX_LIB) $(LDFLAGS)
+    LIBRARIES   += -lselinux
 endif
 
 ifeq ($(strip $(PREFIX)),)
@@ -217,4 +250,59 @@ ifeq ($(strip $(CONFIG_INSTALL_APPLET_DONT)),y)
 INSTALL_OPTS=
 endif
 
+#------------------------------------------------------------
+# Make the output nice and tight
+MAKEFLAGS += --no-print-directory
+export MAKE_IS_SILENT=n
+ifneq ($(findstring s,$(MAKEFLAGS)),)
+export MAKE_IS_SILENT=y
+SECHO := @-false
+DISP  := sil
+Q     := @
+else
+ifneq ($(V)$(VERBOSE),)
+SECHO := @-false
+DISP  := ver
+Q     := 
+else
+SECHO := @echo
+DISP  := pur
+Q     := @
+endif
+endif
+
+show_objs = $(subst $(top_builddir)/,,$(subst ../,,$@))
+pur_disp_compile.c = echo "  "CC $(show_objs)
+pur_disp_compile.h = echo "  "HOSTCC $(show_objs)
+pur_disp_strip     = echo "  "STRIP $(show_objs)
+pur_disp_link      = echo "  "LINK $(show_objs)
+pur_disp_ar        = echo "  "AR $(ARFLAGS) $(show_objs)
+sil_disp_compile.c = true
+sil_disp_compile.h = true
+sil_disp_strip     = true
+sil_disp_link      = true
+sil_disp_ar        = true
+ver_disp_compile.c = echo $(cmd_compile.c)
+ver_disp_compile.h = echo $(cmd_compile.h)
+ver_disp_strip     = echo $(cmd_strip)
+ver_disp_link      = echo $(cmd_link)
+ver_disp_ar        = echo $(cmd_ar)
+disp_compile.c     = $($(DISP)_disp_compile.c)
+disp_compile.h     = $($(DISP)_disp_compile.h)
+disp_strip         = $($(DISP)_disp_strip)
+disp_link          = $($(DISP)_disp_link)
+disp_ar            = $($(DISP)_disp_ar)
+disp_gen           = $(SECHO) "  "GEN $@ ; true
+disp_doc           = $(SECHO) "  "DOC $(subst docs/,,$@) ; true
+cmd_compile.c      = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+cmd_compile.h      = $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
+cmd_strip          = $(STRIPCMD) $@
+cmd_link           = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS)
+cmd_ar             = $(AR) $(ARFLAGS) $@ $^
+compile.c          = @$(disp_compile.c) ; $(cmd_compile.c)
+compile.h          = @$(disp_compile.h) ; $(cmd_compile.h)
+do_strip           = @$(disp_strip)     ; $(cmd_strip)
+do_link            = @$(disp_link)      ; $(cmd_link)
+do_ar              = @$(disp_ar)        ; $(cmd_ar)
+
 .PHONY: dummy