blob: a6356b70b693da208f051f558142401359a16ef4 [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 \
12 defconfig allyesconfig allnoconfig clean distclean \
Eric Andersenbcf27242005-02-13 22:15:59 +000013 release tags
Eric Andersen7daa0762004-10-08 07:46:08 +000014
15ifndef TOPDIR
16TOPDIR=$(CURDIR)/
17endif
18ifndef top_srcdir
19top_srcdir=$(CURDIR)
20endif
21ifndef top_builddir
22top_builddir=$(CURDIR)
23endif
24
Mike Frysinger9d6e0832005-07-31 22:50:17 +000025export srctree=$(top_srcdir)
Eric Andersen7daa0762004-10-08 07:46:08 +000026vpath %/Config.in $(srctree)
27
Rob Landleye1d96332005-08-24 00:41:52 +000028include $(top_srcdir)/Rules.mak
Eric Andersenc9f20d92002-12-05 08:41:41 +000029
Glenn L McGrath3238ea12003-02-15 10:53:40 +000030DIRS:=applets archival archival/libunarchive coreutils console-tools \
31 debianutils editors findutils init miscutils modutils networking \
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000032 networking/libiproute networking/udhcp procps loginutils shell \
Mike Frysingerd89e6292005-04-24 05:07:59 +000033 sysklogd util-linux e2fsprogs libpwdgrp coreutils/libcoreutils libbb
Eric Andersenab050f52001-01-27 06:01:43 +000034
Eric Andersen7daa0762004-10-08 07:46:08 +000035SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
36
Eric Andersen9e480452003-07-03 10:07:04 +000037ifeq ($(strip $(CONFIG_SELINUX)),y)
Rob Landley60158cb2005-05-03 06:25:50 +000038LIBRARIES += -lselinux
Eric Andersen9e480452003-07-03 10:07:04 +000039endif
40
Eric Andersen7daa0762004-10-08 07:46:08 +000041CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
42CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
43
44ALL_DIRS:= $(DIRS) scripts/config
45ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
46
47ifeq ($(KBUILD_SRC),)
48
49ifdef O
50 ifeq ("$(origin O)", "command line")
51 KBUILD_OUTPUT := $(O)
52 endif
53endif
54
55# That's our default target when none is given on the command line
56.PHONY: _all
57_all:
58
59ifneq ($(KBUILD_OUTPUT),)
60# Invoke a second make in the output directory, passing relevant variables
61# check that the output directory actually exists
62saved-output := $(KBUILD_OUTPUT)
63KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
64$(if $(wildcard $(KBUILD_OUTPUT)),, \
65 $(error output directory "$(saved-output)" does not exist))
66
67.PHONY: $(MAKECMDGOALS)
68
69$(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
70 $(MAKE) -C $(KBUILD_OUTPUT) \
71 top_srcdir=$(CURDIR) \
72 top_builddir=$(KBUILD_OUTPUT) \
73 TOPDIR=$(KBUILD_OUTPUT) \
74 KBUILD_SRC=$(CURDIR) \
75 -f $(CURDIR)/Makefile $@
76
77$(KBUILD_OUTPUT)/Rules.mak:
78 @echo > $@
79 @echo top_srcdir=$(CURDIR) >> $@
80 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
81 @echo include $(top_srcdir)/Rules.mak >> $@
82
83$(KBUILD_OUTPUT)/Makefile:
84 @echo > $@
85 @echo top_srcdir=$(CURDIR) >> $@
86 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
87 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
88 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
89
90# Leave processing to above invocation of make
91skip-makefile := 1
92endif # ifneq ($(KBUILD_OUTPUT),)
93endif # ifeq ($(KBUILD_SRC),)
94
95ifeq ($(skip-makefile),)
96
97_all: all
Glenn L McGrath6376b582003-09-24 15:48:29 +000098
Eric Andersen068b6b02002-12-13 22:53:28 +000099ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersen00814662001-04-26 23:29:10 +0000100
Eric Andersend4fcb802003-07-15 00:28:26 +0000101all: busybox busybox.links doc
Erik Andersen0a704e82000-05-03 03:19:06 +0000102
Eric Andersen7daa0762004-10-08 07:46:08 +0000103all_tree: $(ALL_MAKEFILES)
Eric Andersen3cd27602001-10-24 07:58:02 +0000104
Eric Andersen7daa0762004-10-08 07:46:08 +0000105$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
Rob Landleye1d96332005-08-24 00:41:52 +0000106 [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
Eric Andersen7daa0762004-10-08 07:46:08 +0000107
108# In this section, we need .config
109-include $(top_builddir)/.config.cmd
110include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
111-include $(top_builddir)/.depend
112
Rob Landley193c8c72005-07-27 06:55:36 +0000113busybox: $(ALL_MAKEFILES) .depend include/bb_config.h $(libraries-y)
Glenn L McGrathd72e34c2003-09-20 00:59:35 +0000114 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
Eric Andersen85208e22002-04-12 12:05:57 +0000115 $(STRIPCMD) $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000116
Eric Andersen7daa0762004-10-08 07:46:08 +0000117busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000118 - $(SHELL) $^ >$@
119
Eric Andersen63024862004-10-13 17:45:57 +0000120install: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000121 $(SHELL) $< $(PREFIX)
Eric Andersen13879102004-08-26 23:13:00 +0000122ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
123 @echo
124 @echo
125 @echo --------------------------------------------------
126 @echo You will probably need to make your busybox binary
127 @echo setuid root to ensure all configured applets will
128 @echo work properly.
129 @echo --------------------------------------------------
130 @echo
131endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000132
Glenn L McGrath87470de2003-08-29 12:20:31 +0000133uninstall: busybox.links
134 rm -f $(PREFIX)/bin/busybox
135 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
Eric Andersen1f30a412002-04-13 13:39:48 +0000136
Peter Kjellerstedt88da3ef2004-11-02 09:05:22 +0000137install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000138 $(SHELL) $< $(PREFIX) --hardlinks
139
Eric Andersen7daa0762004-10-08 07:46:08 +0000140check: busybox
141 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
142 $(top_srcdir)/testsuite/runtest
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000143
Rob Landleyd9f71652005-08-28 08:24:21 +0000144sizes:
Rob Landleyac692b22005-09-01 02:40:21 +0000145 -rm -f busybox
146 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
147 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
Rob Landleyd9f71652005-08-28 08:24:21 +0000148 nm --size-sort busybox
Rob Landley16890752005-09-02 00:41:53 +0000149
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000150# Documentation Targets
Eric Andersenf7300882004-04-06 15:26:25 +0000151doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
John Beppu94e50542001-04-05 19:42:03 +0000152
Eric Andersen7daa0762004-10-08 07:46:08 +0000153docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
154 -mkdir -p docs
155 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
156 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
157 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000158
Eric Andersen67536ff2000-07-06 22:53:22 +0000159docs/BusyBox.txt: docs/busybox.pod
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000160 $(SECHO)
161 $(SECHO) BusyBox Documentation
162 $(SECHO)
Eric Andersen29be79c2000-12-01 22:57:44 +0000163 -mkdir -p docs
Eric Andersen19f86202001-02-17 00:42:47 +0000164 -pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000165
Eric Andersen67536ff2000-07-06 22:53:22 +0000166docs/BusyBox.1: docs/busybox.pod
Eric Andersen09a34e52000-12-01 19:40:18 +0000167 - mkdir -p docs
Eric Andersen29be79c2000-12-01 22:57:44 +0000168 - pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000169 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000170
Eric Andersen2423b122001-12-08 01:56:15 +0000171docs/BusyBox.html: docs/busybox.net/BusyBox.html
Eric Andersen1cf81662001-02-17 15:55:15 +0000172 - mkdir -p docs
Eric Andersene2f6e122000-12-01 19:55:04 +0000173 -@ rm -f docs/BusyBox.html
Eric Andersen7daa0762004-10-08 07:46:08 +0000174 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000175
Eric Andersen2423b122001-12-08 01:56:15 +0000176docs/busybox.net/BusyBox.html: docs/busybox.pod
177 -@ mkdir -p docs/busybox.net
Eric Andersen19f86202001-02-17 00:42:47 +0000178 - pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000179 docs/busybox.net/BusyBox.html
Eric Andersen36763742001-04-24 21:46:07 +0000180 -@ rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000181
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000182# The nifty new buildsystem stuff
Eric Andersen7daa0762004-10-08 07:46:08 +0000183scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
184 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Eric Andersen67536ff2000-07-06 22:53:22 +0000185
Eric Andersen7daa0762004-10-08 07:46:08 +0000186scripts/split-include: $(top_srcdir)/scripts/split-include.c
187 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000188
Mike Frysingerf1dbd4a2005-08-01 20:49:32 +0000189depend dep: .depend
190.depend: scripts/mkdep include/config.h include/bbconfigopts.h
Eric Andersen85208e22002-04-12 12:05:57 +0000191 rm -f .depend .hdepend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000192 mkdir -p include/config;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000193 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000194 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000195 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000196 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000197
Eric Andersenc9f20d92002-12-05 08:41:41 +0000198include/config/MARKER: depend scripts/split-include
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000199 scripts/split-include include/config.h include/config
200 @ touch include/config/MARKER
201
Eric Andersenc9f20d92002-12-05 08:41:41 +0000202include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000203 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000204 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000205 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000206 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000207
Rob Landley193c8c72005-07-27 06:55:36 +0000208include/bb_config.h: include/config.h
Rob Landley157e8072005-08-02 10:02:23 +0000209 echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
Rob Landleyef8f4232005-07-28 19:36:33 +0000210 sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
211 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
212 < $< >> $@
Rob Landley193c8c72005-07-27 06:55:36 +0000213 echo "#endif" >> $@
214
Paul Fox79c142d2005-08-01 16:04:40 +0000215include/bbconfigopts.h: .config
Rob Landleye1d96332005-08-24 00:41:52 +0000216 @[ -d $(@D) ] || mkdir -v $(@D)
217 $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
Paul Fox79c142d2005-08-01 16:04:40 +0000218
Eric Andersenc9f20d92002-12-05 08:41:41 +0000219finished2:
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000220 $(SECHO)
221 $(SECHO) Finished installing...
222 $(SECHO)
Eric Andersen19f86202001-02-17 00:42:47 +0000223
Eric Andersen068b6b02002-12-13 22:53:28 +0000224else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000225
226all: menuconfig
227
Eric Andersenc9f20d92002-12-05 08:41:41 +0000228# configuration
229# ---------------------------------------------------------------------------
230
Rob Landleye1d96332005-08-24 00:41:52 +0000231scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000232 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000233 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000234 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000235 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000236
Rob Landleye1d96332005-08-24 00:41:52 +0000237scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000238 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000239 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000240 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000241 fi
242
243menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000244 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000245
246config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000247 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000248
249oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000250 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000251
252randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000253 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000254
255allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000256 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Rob Landleya7e14db2005-09-11 01:16:47 +0000257 sed -i -r -e "s/^(CONFIG_DEBUG|USING_CROSS_COMPILER|CONFIG_STATIC|CONFIG_SELINUX).*/# \1 is not set/" .config
Eric Andersen8ee69432004-04-06 11:46:56 +0000258 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000259
260allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000261 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000262
263defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000264 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000265
Eric Andersencc8ed391999-10-05 16:24:54 +0000266clean:
Rob Landleya7e14db2005-09-11 01:16:47 +0000267 - $(MAKE) -C scripts/config $@
Eric Andersenf7300882004-04-06 15:26:25 +0000268 - rm -f docs/busybox.dvi docs/busybox.ps \
269 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000270 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
271 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
272 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
Rob Landley16890752005-09-02 00:41:53 +0000273 .config.old .hdepend busybox testsuite/links/*
Eric Andersen24e098a2003-08-22 20:53:38 +0000274 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000275 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000276 - find . -name \*.o -exec rm -f {} \;
277 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000278
279distclean: clean
Eric Andersena9953432003-01-27 22:11:59 +0000280 - rm -f scripts/split-include scripts/mkdep
Mike Frysingerf9bd87b2005-08-11 21:59:52 +0000281 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
Eric Andersena9953432003-01-27 22:11:59 +0000282 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000283 rm -f .config .config.old .config.cmd
Eric Andersencc8ed391999-10-05 16:24:54 +0000284
Eric Andersenc9f20d92002-12-05 08:41:41 +0000285release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000286 cd ..; \
287 rm -rf $(PROG)-$(VERSION); \
288 cp -a busybox $(PROG)-$(VERSION); \
289 \
290 find $(PROG)-$(VERSION)/ -type d \
Eric Andersen4306bb12005-08-17 00:03:23 +0000291 -name .svn \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000292 -print \
293 -exec rm -rf {} \; ; \
294 \
295 find $(PROG)-$(VERSION)/ -type f \
296 -name .\#* \
297 -print \
298 -exec rm -f {} \; ; \
299 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000300 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000301
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000302tags:
303 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000304
Eric Andersenc9f20d92002-12-05 08:41:41 +0000305
Eric Andersen068b6b02002-12-13 22:53:28 +0000306endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000307
Eric Andersen7daa0762004-10-08 07:46:08 +0000308endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000309
Eric Andersen7daa0762004-10-08 07:46:08 +0000310.PHONY: dummy subdirs release distclean clean config oldconfig \
311 menuconfig tags check test depend buildtree