Patch from Berhnard Fischer to keep duplicate objects out of the library.
[oweals/busybox.git] / Makefile
index 5e636362977b7bc7d0675ac4bffcd5e65f63f29a..c8b6d79d2719185729c1d3e3493978cd000c6531 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,19 +2,7 @@
 #
 # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
 #
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# Licensed under GPLv2, see the file LICENSE in this tarball for details.
 #
 
 #--------------------------------------------------------------
@@ -37,7 +25,7 @@ endif
 export srctree=$(top_srcdir)
 vpath %/Config.in $(srctree)
 
-include $(top_builddir)/Rules.mak
+include $(top_srcdir)/Rules.mak
 
 DIRS:=applets archival archival/libunarchive coreutils console-tools \
        debianutils editors findutils init miscutils modutils networking \
@@ -115,14 +103,14 @@ all: busybox busybox.links doc
 all_tree:      $(ALL_MAKEFILES)
 
 $(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
-       d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
+       [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
 
 # In this section, we need .config
 -include $(top_builddir)/.config.cmd
 include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
 -include $(top_builddir)/.depend
 
-busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
+busybox: $(ALL_MAKEFILES) .depend $(libraries-y)
        $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
        $(STRIPCMD) $@
 
@@ -153,6 +141,12 @@ check: busybox
        bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
        $(top_srcdir)/testsuite/runtest
 
+sizes:
+       -rm -f busybox
+       $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
+               -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
+       nm --size-sort busybox
+
 # Documentation Targets
 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
 
@@ -186,24 +180,14 @@ docs/busybox.net/BusyBox.html: docs/busybox.pod
        -@ rm -f pod2htm*
 
 # The nifty new buildsystem stuff
-scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
-       $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
-
-scripts/split-include: $(top_srcdir)/scripts/split-include.c
+scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
        $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
 
 depend dep: .depend
-.depend: scripts/mkdep include/config.h include/bbconfigopts.h
-       rm -f .depend .hdepend;
-       mkdir -p include/config;
-       scripts/mkdep -I include -- \
-         `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
-       scripts/mkdep -I include -- \
-         `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
-
-include/config/MARKER: depend scripts/split-include
-       scripts/split-include include/config.h include/config
-       @ touch include/config/MARKER
+.depend: scripts/bb_mkdep include/config.h include/bb_config.h
+       @rm -f .depend
+       @mkdir -p include/config
+       scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@
 
 include/config.h: .config
        @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
@@ -212,14 +196,15 @@ include/config.h: .config
        @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
 
 include/bb_config.h: include/config.h
-       echo "#ifndef AUTOCONF_INCLUDED" > $@
-       sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
+       @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
+       @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
            -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
                < $< >> $@
-       echo "#endif" >> $@
+       @echo "#endif" >> $@
 
 include/bbconfigopts.h: .config
-       scripts/config/mkconfigs >include/bbconfigopts.h
+       @[ -d $(@D) ] || mkdir -v $(@D)
+       $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
 
 finished2:
        $(SECHO)
@@ -233,16 +218,13 @@ all: menuconfig
 # configuration
 # ---------------------------------------------------------------------------
 
-$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
-       d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
-
-scripts/config/conf: scripts/config/Makefile Rules.mak
+scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
        $(MAKE) -C scripts/config conf
        -@if [ ! -f .config ] ; then \
                cp $(CONFIG_DEFCONFIG) .config; \
        fi
 
-scripts/config/mconf: scripts/config/Makefile Rules.mak
+scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
        $(MAKE) -C scripts/config ncurses conf mconf
        -@if [ ! -f .config ] ; then \
                cp $(CONFIG_DEFCONFIG) .config; \
@@ -262,10 +244,7 @@ randconfig: scripts/config/conf
 
 allyesconfig: scripts/config/conf
        @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
-       sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
-       sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
-       sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
-       sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
+       sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
        @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
 
 allnoconfig: scripts/config/conf
@@ -275,23 +254,23 @@ defconfig: scripts/config/conf
        @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
 
 clean:
+       - $(MAKE) -C scripts/config $@
        - rm -f docs/busybox.dvi docs/busybox.ps \
            docs/busybox.pod docs/busybox.net/busybox.html \
            docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
            docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
            docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
-           .config.old .hdepend busybox
+           .config.old busybox testsuite/links/*
        - rm -rf _install
        - find . -name .\*.flags -exec rm -f {} \;
        - find . -name \*.o -exec rm -f {} \;
        - find . -name \*.a -exec rm -f {} \;
 
 distclean: clean
-       - rm -f scripts/split-include scripts/mkdep
-       - rm -rf include/config include/config.h include/bb_config.h
+       - rm -f scripts/bb_mkdep
+       - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
        - find . -name .depend -exec rm -f {} \;
        rm -f .config .config.old .config.cmd
-       - $(MAKE) -C scripts/config clean
 
 release: distclean #doc
        cd ..; \
@@ -299,7 +278,7 @@ release: distclean #doc
        cp -a busybox $(PROG)-$(VERSION); \
        \
        find $(PROG)-$(VERSION)/ -type d \
-               -name CVS \
+               -name .svn \
                -print \
                -exec rm -rf {} \; ; \
        \