blob: fffc52466ce57013128c2c9e03dd56f28fcf9903 [file] [log] [blame]
Eric Andersenc4996011999-10-20 22:08:37 +00001# Makefile for busybox
2#
Eric Andersenc7bda1c2004-03-15 08:29:22 +00003# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Erik Andersen9ffdaa62000-02-11 21:55:04 +00004#
Rob Landleya7e14db2005-09-11 01:16:47 +00005# Licensed under GPLv2, see the file LICENSE in this tarball for details.
Eric Andersenc4996011999-10-20 22:08:37 +00006#
7
Eric Andersenc9f20d92002-12-05 08:41:41 +00008#--------------------------------------------------------------
9# You shouldn't need to mess with anything beyond this point...
10#--------------------------------------------------------------
11noconfig_targets := menuconfig config oldconfig randconfig \
Bernhard Reutner-Fischerbe5c1032005-10-08 11:08:28 +000012 defconfig allyesconfig allnoconfig allbareconfig \
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +000013 clean distclean \
Eric Andersenbcf27242005-02-13 22:15:59 +000014 release tags
Eric Andersen7daa0762004-10-08 07:46:08 +000015
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +000016# make-3.79.1 didn't support MAKEFILE_LIST
17# for building out-of-tree, users of make-3.79 still have to pass top_srcdir=
18# to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
19ifndef MAKEFILE_LIST
20MAKEFILE_LIST=.
21endif
Bernhard Reutner-Fischer1c943eb2005-09-26 16:01:43 +000022# the toplevel sourcedir
Eric Andersen7daa0762004-10-08 07:46:08 +000023ifndef top_srcdir
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000024top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
Eric Andersen7daa0762004-10-08 07:46:08 +000025endif
Bernhard Reutner-Fischer1c943eb2005-09-26 16:01:43 +000026# toplevel directory of the object-tree
Eric Andersen7daa0762004-10-08 07:46:08 +000027ifndef top_builddir
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000028top_builddir:=$(CURDIR)
Eric Andersen7daa0762004-10-08 07:46:08 +000029endif
30
Mike Frysinger9d6e0832005-07-31 22:50:17 +000031export srctree=$(top_srcdir)
Eric Andersen7daa0762004-10-08 07:46:08 +000032vpath %/Config.in $(srctree)
33
Glenn L McGrath3238ea12003-02-15 10:53:40 +000034DIRS:=applets archival archival/libunarchive coreutils console-tools \
35 debianutils editors findutils init miscutils modutils networking \
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000036 networking/libiproute networking/udhcp procps loginutils shell \
Mike Frysingerd89e6292005-04-24 05:07:59 +000037 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
Eric Andersenab050f52001-01-27 06:01:43 +000038
Eric Andersen7daa0762004-10-08 07:46:08 +000039SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
40
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +000041# That's our default target when none is given on the command line
42.PHONY: _all
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +000043
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000044_all: all
Eric Andersen7daa0762004-10-08 07:46:08 +000045
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000046# see if we are in verbose mode
47ifdef VERBOSE
48 CHECK_VERBOSE := -v
49 PACKAGE_BE_VERBOSE := $(VERBOSE)
50endif
51ifdef V
52 CHECK_VERBOSE := -v
53 PACKAGE_BE_VERBOSE := $(V)
54endif
Eric Andersen7daa0762004-10-08 07:46:08 +000055
56ifdef O
57 ifeq ("$(origin O)", "command line")
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000058 PACKAGE_OUTPUTDIR := $(shell cd $(O) && pwd)
59 top_builddir := $(PACKAGE_OUTPUTDIR)
Eric Andersen7daa0762004-10-08 07:46:08 +000060 endif
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +000061else
62# If no alternate output-dir was specified, we build in cwd
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000063 PACKAGE_OUTPUTDIR := $(top_builddir)
Eric Andersen7daa0762004-10-08 07:46:08 +000064endif
65
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000066#######################################################################
67# Try to workaround bugs in make
68
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +000069# make-3.79.1 didn't understand order-only prerequisites ('|').
70# Just treat them as normal prerequisites. Note that this will lead to
71# spurious rebuilds.
72ifeq ($(MAKE_VERSION),3.79.1)
73|: ;
74endif
75
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000076# Workaround for bugs in make-3.80
77# eval is broken if it is in a conditional
78
79#$ cat 3.80-eval-in-cond.mak
80#all:: ; @echo it
81#define Y
82# all:: ; @echo worked
83#endef
84#ifdef BAR
85#$(eval $(Y))
86#endif
87#$ make -f 3.80-eval-in-cond.mak
88#it
89#$ make -f 3.80-eval-in-cond.mak BAR=set
90#3.80-eval-in-cond.mak:5: *** missing `endif'. Stop.
91
92# This was fixed in December 2003.
93define check_gcc
94$(eval $(1)+=$(if $(2),$(if $(shell $(CC) $(2) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 && echo y),$(2),$(if $(3),$(3))),$(if $(3),$(3))))
95endef
96
97define check_ld
98$(eval $(1)+=$(if $(2),$(if $(shell $(LD) $(2) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && echo y),$(shell echo \-Wl,$(2)),$(if $(3),$(3))),$(if $(3),$(3))))
99endef
100
101#######################################################################
102
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +0000103-include $(top_srcdir)/Rules.mak
Bernhard Reutner-Fischer8c7a7e62005-10-13 10:40:18 +0000104
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000105# Handle building out of tree
106ifneq ($(top_builddir),$(top_srcdir))
107all_tree := $(patsubst %,$(top_builddir)/%,$(DIRS) scripts scripts/config include include/config)
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000108$(all_tree):
109 @mkdir -p "$@"
110
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000111saved-output := $(PACKAGE_OUTPUTDIR)
112
113$(if $(wildcard $(PACKAGE_OUTPUTDIR)),, \
Eric Andersen7daa0762004-10-08 07:46:08 +0000114 $(error output directory "$(saved-output)" does not exist))
115
Bernhard Reutner-Fischer9b6b8942006-03-02 17:38:15 +0000116.PHONY: $(filter $(noconfig_targets),$(MAKECMDGOALS))
Eric Andersen7daa0762004-10-08 07:46:08 +0000117
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000118$(PACKAGE_OUTPUTDIR)/Rules.mak:
Eric Andersen7daa0762004-10-08 07:46:08 +0000119 @echo > $@
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000120 @echo top_srcdir=$(top_srcdir) >> $@
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000121 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
122 @echo include $$\(top_srcdir\)/Rules.mak >> $@
Eric Andersen7daa0762004-10-08 07:46:08 +0000123
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000124$(PACKAGE_OUTPUTDIR)/Makefile:
Eric Andersen7daa0762004-10-08 07:46:08 +0000125 @echo > $@
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000126 @echo top_srcdir=$(top_srcdir) >> $@
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000127 @echo top_builddir=$(PACKAGE_OUTPUTDIR) >> $@
128 @echo PACKAGE_SOURCEDIR='$$(top_srcdir)' >> $@
129 @echo include '$$(PACKAGE_SOURCEDIR)'/Makefile >> $@
Eric Andersen7daa0762004-10-08 07:46:08 +0000130
Eric Andersen7daa0762004-10-08 07:46:08 +0000131
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000132buildtree := $(all_tree) $(PACKAGE_OUTPUTDIR)/Rules.mak $(PACKAGE_OUTPUTDIR)/Makefile
Eric Andersen7daa0762004-10-08 07:46:08 +0000133
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000134# We only need a copy of the Makefile for the config targets and reuse
135# the rest from the source directory, i.e. we do not cp ALL_MAKEFILES.
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000136scripts/config/Makefile: $(top_srcdir)/scripts/config/Makefile | $(buildtree)
137 @cp $(top_srcdir)/scripts/config/Makefile $@
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000138
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000139else
140all_tree := include/config
141$(all_tree):
142 @mkdir -p "$@"
143buildtree := $(all_tree)
144endif # ifneq ($(PACKAGE_OUTPUTDIR),$(top_srcdir))
Glenn L McGrath6376b582003-09-24 15:48:29 +0000145
Rob Landleyd24eaac2005-09-26 15:49:41 +0000146help:
147 @echo 'Cleaning:'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000148 @echo ' clean - delete temporary files created by build'
149 @echo ' distclean - delete all non-source files (including .config)'
Rob Landleyd24eaac2005-09-26 15:49:41 +0000150 @echo
151 @echo 'Build:'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000152 @echo ' all - Executable and documentation'
153 @echo ' busybox - the swiss-army executable'
154 @echo ' doc - docs/BusyBox.{txt,html,1}'
Rob Landleyd24eaac2005-09-26 15:49:41 +0000155 @echo
156 @echo 'Configuration:'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000157 @echo ' allnoconfig - disable all symbols in .config'
Rob Landley1ab4c3d2006-02-08 18:50:17 +0000158 @echo ' allyesconfig - enable all symbols in .config (see defconfig)'
159 @echo ' allbareconfig - enable all applets without any sub-features'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000160 @echo ' config - text based configurator (of last resort)'
Rob Landley1ab4c3d2006-02-08 18:50:17 +0000161 @echo ' defconfig - set .config to largest generic configuration'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000162 @echo ' menuconfig - interactive curses-based configurator'
163 @echo ' oldconfig - resolve any unresolved symbols in .config'
Rob Landleyd24eaac2005-09-26 15:49:41 +0000164 @echo
165 @echo 'Installation:'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000166 @echo ' install - install busybox into $prefix'
Rob Landleyd24eaac2005-09-26 15:49:41 +0000167 @echo ' uninstall'
168 @echo
169 @echo 'Development:'
"Vladimir N. Oleynik"b7576992006-01-23 11:39:05 +0000170 @echo ' check - run the test suite for all applets'
171 @echo ' randconfig - generate a random configuration'
172 @echo ' release - create a distribution tarball'
173 @echo ' sizes - show size of all enabled busybox symbols'
Rob Landleyd24eaac2005-09-26 15:49:41 +0000174 @echo
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000175 @echo 'Make flags:'
176 @echo ' V=<number> - print verbose make output (default: unset)'
177 @echo ' 0 print CC invocations'
178 @echo ' 1'
179 @echo ' 2 also print when make enters a directory'
180 @echo ' 3 also verbosely print shell invocations'
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000181
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000182ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000183# Default target if none was requested explicitly
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000184all: defconfig menuconfig ;
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000185
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000186ifneq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000187# warn if no configuration exists and we are asked to build a non-config target
188.config:
189 @echo ""
190 @echo "No $(top_builddir)/$@ found!"
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000191 @echo "Please refer to 'make help', section Configuration."
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000192 @echo ""
193 @exit 1
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000194else
195# Avoid implicit rule to kick in by using an empty command
196.config: $(buildtree) ;
197endif
198endif # ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
199
Bernhard Reutner-Fischer4d635252005-10-07 10:53:15 +0000200
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000201# configuration
202# ---------------------------------------------------------------------------
203
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000204CONFIG_CONFIG_IN = $(top_srcdir)/Config.in
205
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000206scripts/config/conf: scripts/config/Makefile
Mike Frysingerb38673f2006-02-02 01:41:53 +0000207 $(Q)$(MAKE) -C scripts/config conf
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000208
209scripts/config/mconf: scripts/config/Makefile
Mike Frysingerb38673f2006-02-02 01:41:53 +0000210 $(Q)$(MAKE) -C scripts/config ncurses conf mconf
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000211
212menuconfig: scripts/config/mconf
213 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
214
215config: scripts/config/conf
216 @./scripts/config/conf $(CONFIG_CONFIG_IN)
217
218oldconfig: scripts/config/conf
219 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
220
221randconfig: scripts/config/conf
222 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
223
224allyesconfig: scripts/config/conf
225 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000226 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER)=.*/# \1 is not set/" .config
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000227 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
228
229allnoconfig: scripts/config/conf
230 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
231
Rob Landley1ab4c3d2006-02-08 18:50:17 +0000232# defconfig is allyesconfig minus any features that are specialized enough
233# or cause enough behavior change that the user really should switch them on
234# manually if that's what they want. Sort of "maximum sane config".
Rob Landleya167ec52006-01-31 02:42:50 +0000235
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000236defconfig: scripts/config/conf
Rob Landleya167ec52006-01-31 02:42:50 +0000237 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000238 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG.*|STATIC|SELINUX|BUILD_(AT_ONCE|LIBBUSYBOX)|FEATURE_(DEVFS|FULL_LIBBUSYBOX|SHARED_BUSYBOX|MTAB_SUPPORT|CLEAN_UP|UDHCP_DEBUG)|INSTALL_NO_USR))=.*/# \1 is not set/" .config
Rob Landleya167ec52006-01-31 02:42:50 +0000239 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
240
Bernhard Reutner-Fischerbe5c1032005-10-08 11:08:28 +0000241allbareconfig: scripts/config/conf
242 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000243 @$(SED) -i -r -e "s/^(USING_CROSS_COMPILER|CONFIG_(DEBUG|STATIC|SELINUX|DEVFSD|NC_GAPING_SECURITY_HOLE|BUILD_AT_ONCE)).*/# \1 is not set/" .config
244 @$(SED) -i -e "/FEATURE/s/=.*//;/^[^#]/s/.*FEATURE.*/# \0 is not set/;" .config
Bernhard Reutner-Fischerbe5c1032005-10-08 11:08:28 +0000245 @echo "CONFIG_FEATURE_BUFFERS_GO_ON_STACK=y" >> .config
246 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Bernhard Reutner-Fischera9d89132005-10-07 18:45:03 +0000247
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000248ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersen00814662001-04-26 23:29:10 +0000249
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000250# Load all Config.in
Eric Andersen7daa0762004-10-08 07:46:08 +0000251-include $(top_builddir)/.config.cmd
Eric Andersen7daa0762004-10-08 07:46:08 +0000252
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000253endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Bernhard Reutner-Fischer5c071bc2005-10-05 07:40:46 +0000254
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000255# convert $(DIRS) to upper case. Use sed instead of tr since we're already
256# depending on it.
257DIRS_UPPER:=$(shell echo $(DIRS) | $(SED) 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
258
Bernhard Reutner-Fischere3ec99d2006-03-02 18:23:13 +0000259# First populate the variables ..._OBJ-y et al
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000260$(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-y:=))
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000261
262include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
263
264# Then we need the dependencies for ..._OBJ
265define dir_pattern.o
266ifeq ($(os),.os)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000267$(if $($(1)_OBJ.os),$($(1)_OBJ.os:.os=.o): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
268endif
269$(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
270$(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000271endef
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +0000272
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000273# The actual directory patterns for .o*
274$(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
275
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +0000276define file_lists
277$($(1)$(2)) $($(1)$(2).o) $($(1)$(2).os)
278endef
279bin-obj-y:=$(subst .os,.o,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_OBJ)))
280bin-mobj-y:=$(subst .osm,.om,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_MOBJ)))
281
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000282ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
283# Finally pull in the dependencies (headers and other includes) of the
284# individual object files
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000285-include $(top_builddir)/.depend
286
Bernhard Reutner-Fischerc8e278f2006-03-02 18:13:05 +0000287$(top_builddir)/applets/applets.o: $(top_builddir)/.config
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000288# Everything is set.
289
290all: busybox busybox.links doc ;
291
292# Two modes of operation: legacy and IMA
293# Legacy mode builds each object through an individual invocation of CC
294# IMA compiles all sources at once (aka IPO aka IPA etc.)
295
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000296ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000297# We are not building .o
298bin-obj-y:=
299bin-mobj-y:=
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000300# Which parts of the internal libs are requested?
301# Per default we only want what was actually selected.
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000302# -a denotes all while -y denotes the selected ones.
303ifeq ($(strip $(CONFIG_FEATURE_FULL_LIBBUSYBOX)),y)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000304LIBRARY_DEFINE:=$(LIBRARY_DEFINE-a)
305LIBRARY_SRC :=$(LIBRARY_SRC-a)
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000306else # CONFIG_FEATURE_FULL_LIBBUSYBOX
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000307LIBRARY_DEFINE:=$(LIBRARY_DEFINE-y)
308LIBRARY_SRC :=$(LIBRARY_SRC-y)
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000309endif # CONFIG_FEATURE_FULL_LIBBUSYBOX
310APPLET_SRC:=$(APPLET_SRC-y)
311APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000312else # CONFIG_BUILD_AT_ONCE
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000313# no --combine, build archives out of the individual .o
314# This was the old way the binary was built.
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000315libbusybox-obj:=$(archival_libunarchive_OBJ$(os)) \
316 $(networking_libiproute_OBJ$(os)) \
317 $(libpwdgrp_MOBJ$(os)) \
318 $(coreutils_libcoreutils_OBJ$(os)) \
319 $(libbb_OBJ$(os)) $(libbb_MOBJ$(os))
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000320
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000321ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000322# linking against libbusybox, so don't build the .o already contained in the .so
323bin-obj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.os=.o),$(bin-obj-y))
324bin-mobj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.osm=.om),$(bin-mobj-y))
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000325endif # CONFIG_FEATURE_SHARED_BUSYBOX
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000326endif # CONFIG_BUILD_AT_ONCE
327
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000328# build an .a to keep .hash et al small
Bernhard Reutner-Fischercfc5d862006-03-02 09:44:32 +0000329ifneq ($(bin-obj-y)$(bin-mobj-y),)
330 applets.a:=$(bin-obj-y) $(bin-mobj-y)
331endif
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000332ifdef applets.a
333applets.a: $(applets.a)
Bernhard Reutner-Fischer7ad83b42006-03-03 14:19:15 +0000334 $(Q)-rm -f $(@)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000335 $(do_ar)
Bernhard Reutner-Fischer7ad83b42006-03-03 14:19:15 +0000336
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000337bin-obj.a=applets.a
338endif
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000339
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000340ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
341LD_LIBBUSYBOX:=libbusybox.so
342LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)
343DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
344 $(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
345 $(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
346
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000347endif # CONFIG_BUILD_LIBBUSYBOX
348
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000349ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
350ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000351# --combine but not linking against libbusybox, so compile lib*.c
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000352BUSYBOX_SRC := $(LIBRARY_SRC)
353BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
354endif # !CONFIG_FEATURE_SHARED_BUSYBOX
355$(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
356else # CONFIG_BUILD_AT_ONCE
357$(LIBBUSYBOX_SONAME): $(libbusybox-obj)
358endif # CONFIG_BUILD_AT_ONCE
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000359
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000360
361ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
362LDBUSYBOX:=-L$(top_builddir) -lbusybox
363endif
364
365ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000366$(LIBBUSYBOX_SONAME):
367ifndef MAJOR_VERSION
368 $(error MAJOR_VERSION needed for $@ is not defined)
369endif
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000370 $(do_link) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(CFLAGS_COMBINE) \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000371 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
Bernhard Reutner-Fischer08a1b502006-01-27 15:45:56 +0000372 -Wl,-z,combreloc $(LIB_LDFLAGS) \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000373 -o $(@) \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000374 -Wl,--start-group \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000375 $(LIBRARY_DEFINE) $(^) \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000376 -Wl,--end-group
377 @rm -f $(DO_INSTALL_LIBS)
378 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
Mike Frysingerb38673f2006-02-02 01:41:53 +0000379 $(do_strip)
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000380
381endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
382
Bernhard Reutner-Fischercfc5d862006-03-02 09:44:32 +0000383busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(bin-obj.a)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000384 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
385 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
386 $(CFLAGS-$(@)) \
387 -o $@ -Wl,--start-group \
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000388 $(APPLETS_DEFINE) $(APPLET_SRC) \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000389 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
390 $(bin-obj.a) \
Bernhard Reutner-Fischer08c5a172006-01-25 15:58:04 +0000391 $(LDBUSYBOX) $(LIBRARIES) \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000392 -Wl,--end-group
Bernhard Reutner-Fischercfc5d862006-03-02 09:44:32 +0000393
394busybox: busybox_unstripped
395 $(Q)cp busybox_unstripped busybox
Mike Frysingerb38673f2006-02-02 01:41:53 +0000396 $(do_strip)
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000397
Rob Landleya930bd32005-12-16 06:12:46 +0000398busybox.links: $(top_srcdir)/applets/busybox.mkll include/bb_config.h $(top_srcdir)/include/applets.h
Mike Frysingerb38673f2006-02-02 01:41:53 +0000399 $(Q)-$(SHELL) $^ >$@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000400
Eric Andersen63024862004-10-13 17:45:57 +0000401install: $(top_srcdir)/applets/install.sh busybox busybox.links
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000402 $(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000403 $(SHELL) $< $(PREFIX) $(INSTALL_OPTS)
Eric Andersen13879102004-08-26 23:13:00 +0000404ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
405 @echo
406 @echo
407 @echo --------------------------------------------------
408 @echo You will probably need to make your busybox binary
409 @echo setuid root to ensure all configured applets will
410 @echo work properly.
411 @echo --------------------------------------------------
412 @echo
413endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000414
Glenn L McGrath87470de2003-08-29 12:20:31 +0000415uninstall: busybox.links
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000416 rm -f $(PREFIX)/bin/busybox
417 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000418ifneq ($(strip $(DO_INSTALL_LIBS)),n)
419 for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000420 rm -f $(PREFIX)$$i; \
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +0000421 done
422endif
Eric Andersen1f30a412002-04-13 13:39:48 +0000423
Mike Frysingerce0cf1d2005-09-24 05:47:52 +0000424check test: busybox
Eric Andersen7daa0762004-10-08 07:46:08 +0000425 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +0000426 $(top_srcdir)/testsuite/runtest $(CHECK_VERBOSE)
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000427
Bernhard Reutner-Fischercfc5d862006-03-02 09:44:32 +0000428sizes: busybox_unstripped
429 $(NM) --size-sort $(<)
Rob Landley16890752005-09-02 00:41:53 +0000430
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000431# Documentation Targets
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000432doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
John Beppu94e50542001-04-05 19:42:03 +0000433
Mike Frysingerf37529d2006-02-05 22:15:39 +0000434docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod $(top_srcdir)/docs/autodocifier.pl
Mike Frysingerb38673f2006-02-02 01:41:53 +0000435 $(disp_doc)
436 $(Q)-mkdir -p docs
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000437 $(Q)-( cat $(top_srcdir)/docs/busybox_header.pod ; \
438 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h ; \
439 cat $(top_srcdir)/docs/busybox_footer.pod ; ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000440
Eric Andersen67536ff2000-07-06 22:53:22 +0000441docs/BusyBox.txt: docs/busybox.pod
Mike Frysingerb38673f2006-02-02 01:41:53 +0000442 $(disp_doc)
443 $(Q)-mkdir -p docs
444 $(Q)-pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000445
Eric Andersen67536ff2000-07-06 22:53:22 +0000446docs/BusyBox.1: docs/busybox.pod
Mike Frysingerb38673f2006-02-02 01:41:53 +0000447 $(disp_doc)
448 $(Q)-mkdir -p docs
449 $(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000450 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000451
Eric Andersen2423b122001-12-08 01:56:15 +0000452docs/BusyBox.html: docs/busybox.net/BusyBox.html
Mike Frysingerb38673f2006-02-02 01:41:53 +0000453 $(disp_doc)
454 $(Q)-mkdir -p docs
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000455 $(Q)-rm -f docs/BusyBox.html
Mike Frysingerb38673f2006-02-02 01:41:53 +0000456 $(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000457
Eric Andersen2423b122001-12-08 01:56:15 +0000458docs/busybox.net/BusyBox.html: docs/busybox.pod
Mike Frysingerb38673f2006-02-02 01:41:53 +0000459 $(Q)-mkdir -p docs/busybox.net
460 $(Q)-pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000461 docs/busybox.net/BusyBox.html
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000462 $(Q)-rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000463
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000464# The nifty new dependency stuff
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000465scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000466 $(do_link.h)
Erik Andersen1d1d9502000-04-21 01:26:49 +0000467
"Vladimir N. Oleynik"6732af22006-02-15 12:29:37 +0000468DEP_INCLUDES := include/bb_config.h
"Vladimir N. Oleynik"cef737f2005-09-21 07:49:34 +0000469
"Vladimir N. Oleynik"cef737f2005-09-21 07:49:34 +0000470ifeq ($(strip $(CONFIG_BBCONFIG)),y)
471DEP_INCLUDES += include/bbconfigopts.h
472
473include/bbconfigopts.h: .config
Mike Frysingerb38673f2006-02-02 01:41:53 +0000474 $(disp_gen)
475 $(Q)$(top_srcdir)/scripts/config/mkconfigs > $@
"Vladimir N. Oleynik"cef737f2005-09-21 07:49:34 +0000476endif
477
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000478depend dep: $(top_builddir)/.depend ;
479$(top_builddir)/.depend: $(buildtree) scripts/bb_mkdep $(DEP_INCLUDES)
Mike Frysingerb38673f2006-02-02 01:41:53 +0000480 $(disp_gen)
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000481 $(Q)rm -f .depend
482 $(Q)scripts/bb_mkdep $(MKDEP_ARGS) \
483 -I $(top_srcdir)/include $(top_srcdir) > $@.tmp
Mike Frysingerb38673f2006-02-02 01:41:53 +0000484 $(Q)mv $@.tmp $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000485
"Vladimir N. Oleynik"6732af22006-02-15 12:29:37 +0000486include/bb_config.h: .config
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000487 $(disp_gen)
Eric Andersen7daa0762004-10-08 07:46:08 +0000488 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000489
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000490endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
491
Eric Andersencc8ed391999-10-05 16:24:54 +0000492clean:
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000493 - rm -f docs/busybox.dvi docs/busybox.ps \
Eric Andersenf7300882004-04-06 15:26:25 +0000494 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000495 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
496 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
"Vladimir N. Oleynik"9394b232006-01-23 11:24:58 +0000497 docs/busybox.net/BusyBox.html busybox.links \
Bernhard Reutner-Fischera5972112006-03-06 14:19:15 +0000498 libbusybox.so* \
Mike Frysinger33b45a02006-03-05 16:25:19 +0000499 .config.old busybox busybox_unstripped
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000500 - rm -r -f _install testsuite/links
501 - find . -name .\*.flags -exec rm -f {} \;
502 - find . -name \*.o -exec rm -f {} \;
503 - find . -name \*.om -exec rm -f {} \;
504 - find . -name \*.os -exec rm -f {} \;
Mike Frysinger56ee7792006-03-05 18:04:23 +0000505 - find . -name \*.osm -exec rm -f {} \;
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000506 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000507
508distclean: clean
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000509 - $(MAKE) -C scripts/config clean
510 - rm -f scripts/bb_mkdep
511 - rm -r -f include/config $(DEP_INCLUDES)
512 - find . -name .depend'*' -exec rm -f {} \;
513 rm -f .config .config.old .config.cmd
Eric Andersencc8ed391999-10-05 16:24:54 +0000514
Eric Andersenc9f20d92002-12-05 08:41:41 +0000515release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000516 cd ..; \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000517 rm -r -f $(PROG)-$(VERSION); \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000518 cp -a busybox $(PROG)-$(VERSION); \
519 \
520 find $(PROG)-$(VERSION)/ -type d \
Eric Andersen4306bb12005-08-17 00:03:23 +0000521 -name .svn \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000522 -print \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000523 -exec rm -r -f {} \; ; \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000524 \
525 find $(PROG)-$(VERSION)/ -type f \
526 -name .\#* \
527 -print \
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000528 -exec rm -f {} \; ; \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000529 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000530 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000531
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000532tags:
533 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000534
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +0000535# keep these in sync with noconfig_targets above!
536.PHONY: dummy subdirs check test depend dep buildtree \
537 menuconfig config oldconfig randconfig \
538 defconfig allyesconfig allnoconfig allbareconfig \
539 clean distclean \
540 release tags