blob: 338e3a4af617458cddcd9a142e33bee261baae6d [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#
Eric Andersenc4996011999-10-20 22:08:37 +00005# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18#
19
Eric Andersenc9f20d92002-12-05 08:41:41 +000020#--------------------------------------------------------------
21# You shouldn't need to mess with anything beyond this point...
22#--------------------------------------------------------------
23noconfig_targets := menuconfig config oldconfig randconfig \
24 defconfig allyesconfig allnoconfig clean distclean \
Eric Andersenbcf27242005-02-13 22:15:59 +000025 release tags
Eric Andersen7daa0762004-10-08 07:46:08 +000026
27ifndef TOPDIR
28TOPDIR=$(CURDIR)/
29endif
30ifndef top_srcdir
31top_srcdir=$(CURDIR)
32endif
33ifndef top_builddir
34top_builddir=$(CURDIR)
35endif
36
Mike Frysinger9d6e0832005-07-31 22:50:17 +000037export srctree=$(top_srcdir)
Eric Andersen7daa0762004-10-08 07:46:08 +000038vpath %/Config.in $(srctree)
39
40include $(top_builddir)/Rules.mak
Eric Andersenc9f20d92002-12-05 08:41:41 +000041
Glenn L McGrath3238ea12003-02-15 10:53:40 +000042DIRS:=applets archival archival/libunarchive coreutils console-tools \
43 debianutils editors findutils init miscutils modutils networking \
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000044 networking/libiproute networking/udhcp procps loginutils shell \
Mike Frysingerd89e6292005-04-24 05:07:59 +000045 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
Eric Andersenab050f52001-01-27 06:01:43 +000046
Eric Andersen7daa0762004-10-08 07:46:08 +000047SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
48
Eric Andersen9e480452003-07-03 10:07:04 +000049ifeq ($(strip $(CONFIG_SELINUX)),y)
Rob Landley60158cb2005-05-03 06:25:50 +000050LIBRARIES += -lselinux
Eric Andersen9e480452003-07-03 10:07:04 +000051endif
52
Eric Andersen7daa0762004-10-08 07:46:08 +000053CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
54CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
55
56ALL_DIRS:= $(DIRS) scripts/config
57ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
58
59ifeq ($(KBUILD_SRC),)
60
61ifdef O
62 ifeq ("$(origin O)", "command line")
63 KBUILD_OUTPUT := $(O)
64 endif
65endif
66
67# That's our default target when none is given on the command line
68.PHONY: _all
69_all:
70
71ifneq ($(KBUILD_OUTPUT),)
72# Invoke a second make in the output directory, passing relevant variables
73# check that the output directory actually exists
74saved-output := $(KBUILD_OUTPUT)
75KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
76$(if $(wildcard $(KBUILD_OUTPUT)),, \
77 $(error output directory "$(saved-output)" does not exist))
78
79.PHONY: $(MAKECMDGOALS)
80
81$(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
82 $(MAKE) -C $(KBUILD_OUTPUT) \
83 top_srcdir=$(CURDIR) \
84 top_builddir=$(KBUILD_OUTPUT) \
85 TOPDIR=$(KBUILD_OUTPUT) \
86 KBUILD_SRC=$(CURDIR) \
87 -f $(CURDIR)/Makefile $@
88
89$(KBUILD_OUTPUT)/Rules.mak:
90 @echo > $@
91 @echo top_srcdir=$(CURDIR) >> $@
92 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
93 @echo include $(top_srcdir)/Rules.mak >> $@
94
95$(KBUILD_OUTPUT)/Makefile:
96 @echo > $@
97 @echo top_srcdir=$(CURDIR) >> $@
98 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
99 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
100 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
101
102# Leave processing to above invocation of make
103skip-makefile := 1
104endif # ifneq ($(KBUILD_OUTPUT),)
105endif # ifeq ($(KBUILD_SRC),)
106
107ifeq ($(skip-makefile),)
108
109_all: all
Glenn L McGrath6376b582003-09-24 15:48:29 +0000110
Eric Andersen068b6b02002-12-13 22:53:28 +0000111ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersen00814662001-04-26 23:29:10 +0000112
Eric Andersend4fcb802003-07-15 00:28:26 +0000113all: busybox busybox.links doc
Erik Andersen0a704e82000-05-03 03:19:06 +0000114
Eric Andersen7daa0762004-10-08 07:46:08 +0000115all_tree: $(ALL_MAKEFILES)
Eric Andersen3cd27602001-10-24 07:58:02 +0000116
Eric Andersen7daa0762004-10-08 07:46:08 +0000117$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
118 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
119
120# In this section, we need .config
121-include $(top_builddir)/.config.cmd
122include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
123-include $(top_builddir)/.depend
124
Rob Landley193c8c72005-07-27 06:55:36 +0000125busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
Glenn L McGrathd72e34c2003-09-20 00:59:35 +0000126 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
Eric Andersen85208e22002-04-12 12:05:57 +0000127 $(STRIPCMD) $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000128
Eric Andersen7daa0762004-10-08 07:46:08 +0000129busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000130 - $(SHELL) $^ >$@
131
Eric Andersen63024862004-10-13 17:45:57 +0000132install: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000133 $(SHELL) $< $(PREFIX)
Eric Andersen13879102004-08-26 23:13:00 +0000134ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
135 @echo
136 @echo
137 @echo --------------------------------------------------
138 @echo You will probably need to make your busybox binary
139 @echo setuid root to ensure all configured applets will
140 @echo work properly.
141 @echo --------------------------------------------------
142 @echo
143endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000144
Glenn L McGrath87470de2003-08-29 12:20:31 +0000145uninstall: busybox.links
146 rm -f $(PREFIX)/bin/busybox
147 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
Eric Andersen1f30a412002-04-13 13:39:48 +0000148
Peter Kjellerstedt88da3ef2004-11-02 09:05:22 +0000149install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000150 $(SHELL) $< $(PREFIX) --hardlinks
151
Eric Andersen7daa0762004-10-08 07:46:08 +0000152check: busybox
153 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
154 $(top_srcdir)/testsuite/runtest
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000155
156# Documentation Targets
Eric Andersenf7300882004-04-06 15:26:25 +0000157doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
John Beppu94e50542001-04-05 19:42:03 +0000158
Eric Andersen7daa0762004-10-08 07:46:08 +0000159docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
160 -mkdir -p docs
161 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
162 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
163 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000164
Eric Andersen67536ff2000-07-06 22:53:22 +0000165docs/BusyBox.txt: docs/busybox.pod
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000166 $(SECHO)
167 $(SECHO) BusyBox Documentation
168 $(SECHO)
Eric Andersen29be79c2000-12-01 22:57:44 +0000169 -mkdir -p docs
Eric Andersen19f86202001-02-17 00:42:47 +0000170 -pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000171
Eric Andersen67536ff2000-07-06 22:53:22 +0000172docs/BusyBox.1: docs/busybox.pod
Eric Andersen09a34e52000-12-01 19:40:18 +0000173 - mkdir -p docs
Eric Andersen29be79c2000-12-01 22:57:44 +0000174 - pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000175 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000176
Eric Andersen2423b122001-12-08 01:56:15 +0000177docs/BusyBox.html: docs/busybox.net/BusyBox.html
Eric Andersen1cf81662001-02-17 15:55:15 +0000178 - mkdir -p docs
Eric Andersene2f6e122000-12-01 19:55:04 +0000179 -@ rm -f docs/BusyBox.html
Eric Andersen7daa0762004-10-08 07:46:08 +0000180 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000181
Eric Andersen2423b122001-12-08 01:56:15 +0000182docs/busybox.net/BusyBox.html: docs/busybox.pod
183 -@ mkdir -p docs/busybox.net
Eric Andersen19f86202001-02-17 00:42:47 +0000184 - pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000185 docs/busybox.net/BusyBox.html
Eric Andersen36763742001-04-24 21:46:07 +0000186 -@ rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000187
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000188# The nifty new buildsystem stuff
Eric Andersen7daa0762004-10-08 07:46:08 +0000189scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
190 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Eric Andersen67536ff2000-07-06 22:53:22 +0000191
Eric Andersen7daa0762004-10-08 07:46:08 +0000192scripts/split-include: $(top_srcdir)/scripts/split-include.c
193 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000194
Mike Frysingere9903cf2005-06-11 00:13:58 +0000195.depend: scripts/mkdep include/config.h
Eric Andersen85208e22002-04-12 12:05:57 +0000196 rm -f .depend .hdepend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000197 mkdir -p include/config;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000198 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000199 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000200 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000201 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000202
Paul Fox79c142d2005-08-01 16:04:40 +0000203depend dep: .depend include/bbconfigopts.h
Eric Andersen85208e22002-04-12 12:05:57 +0000204
Eric Andersenc9f20d92002-12-05 08:41:41 +0000205include/config/MARKER: depend scripts/split-include
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000206 scripts/split-include include/config.h include/config
207 @ touch include/config/MARKER
208
Eric Andersenc9f20d92002-12-05 08:41:41 +0000209include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000210 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000211 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000212 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000213 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000214
Rob Landley193c8c72005-07-27 06:55:36 +0000215include/bb_config.h: include/config.h
216 echo "#ifndef AUTOCONF_INCLUDED" > $@
Rob Landleyef8f4232005-07-28 19:36:33 +0000217 sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
218 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
219 < $< >> $@
Rob Landley193c8c72005-07-27 06:55:36 +0000220 echo "#endif" >> $@
221
Paul Fox79c142d2005-08-01 16:04:40 +0000222include/bbconfigopts.h: .config
223 scripts/config/mkconfigs >include/bbconfigopts.h
Paul Fox79c142d2005-08-01 16:04:40 +0000224
Eric Andersenc9f20d92002-12-05 08:41:41 +0000225finished2:
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000226 $(SECHO)
227 $(SECHO) Finished installing...
228 $(SECHO)
Eric Andersen19f86202001-02-17 00:42:47 +0000229
Eric Andersen068b6b02002-12-13 22:53:28 +0000230else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000231
232all: menuconfig
233
Eric Andersenc9f20d92002-12-05 08:41:41 +0000234# configuration
235# ---------------------------------------------------------------------------
236
Eric Andersen7daa0762004-10-08 07:46:08 +0000237$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
238 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
239
240scripts/config/conf: scripts/config/Makefile Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000241 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000242 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000243 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000244 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000245
246scripts/config/mconf: scripts/config/Makefile Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000247 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000248 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000249 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000250 fi
251
252menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000253 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000254
255config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000256 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000257
258oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000259 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000260
261randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000262 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000263
264allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000265 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Eric Andersen8ee69432004-04-06 11:46:56 +0000266 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
267 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
Eric Andersenb07ae7b2004-04-06 11:51:45 +0000268 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
269 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
Eric Andersen8ee69432004-04-06 11:46:56 +0000270 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000271
272allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000273 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000274
275defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000276 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000277
Eric Andersencc8ed391999-10-05 16:24:54 +0000278clean:
Eric Andersenf7300882004-04-06 15:26:25 +0000279 - rm -f docs/busybox.dvi docs/busybox.ps \
280 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000281 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
282 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
283 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
284 .config.old .hdepend busybox
285 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000286 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000287 - find . -name \*.o -exec rm -f {} \;
288 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000289
290distclean: clean
Eric Andersena9953432003-01-27 22:11:59 +0000291 - rm -f scripts/split-include scripts/mkdep
Rob Landley193c8c72005-07-27 06:55:36 +0000292 - rm -rf include/config include/config.h include/bb_config.h
Eric Andersena9953432003-01-27 22:11:59 +0000293 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000294 rm -f .config .config.old .config.cmd
Eric Andersena9953432003-01-27 22:11:59 +0000295 - $(MAKE) -C scripts/config clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000296
Eric Andersenc9f20d92002-12-05 08:41:41 +0000297release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000298 cd ..; \
299 rm -rf $(PROG)-$(VERSION); \
300 cp -a busybox $(PROG)-$(VERSION); \
301 \
302 find $(PROG)-$(VERSION)/ -type d \
303 -name CVS \
304 -print \
305 -exec rm -rf {} \; ; \
306 \
307 find $(PROG)-$(VERSION)/ -type f \
308 -name .\#* \
309 -print \
310 -exec rm -f {} \; ; \
311 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000312 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000313
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000314tags:
315 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000316
Eric Andersenc9f20d92002-12-05 08:41:41 +0000317
Eric Andersen068b6b02002-12-13 22:53:28 +0000318endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000319
Eric Andersen7daa0762004-10-08 07:46:08 +0000320endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000321
Eric Andersen7daa0762004-10-08 07:46:08 +0000322.PHONY: dummy subdirs release distclean clean config oldconfig \
323 menuconfig tags check test depend buildtree