blob: 9655972982b1658823e4fdf63e7c1c411fef51d5 [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) \
"Vladimir N. Oleynik"4a5d95d2005-09-19 16:18:46 +000073 TOPDIR=$(KBUILD_OUTPUT) \
Eric Andersen7daa0762004-10-08 07:46:08 +000074 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
"Vladimir N. Oleynik"4a5d95d2005-09-19 16:18:46 +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
Mike Frysinger016d6282005-09-24 06:15:23 +0000113%.o: .depend
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000114busybox: $(ALL_MAKEFILES) .depend $(libraries-y)
Glenn L McGrathd72e34c2003-09-20 00:59:35 +0000115 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
Eric Andersen85208e22002-04-12 12:05:57 +0000116 $(STRIPCMD) $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000117
Eric Andersen7daa0762004-10-08 07:46:08 +0000118busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000119 - $(SHELL) $^ >$@
120
Eric Andersen63024862004-10-13 17:45:57 +0000121install: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000122 $(SHELL) $< $(PREFIX)
Eric Andersen13879102004-08-26 23:13:00 +0000123ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
124 @echo
125 @echo
126 @echo --------------------------------------------------
127 @echo You will probably need to make your busybox binary
128 @echo setuid root to ensure all configured applets will
129 @echo work properly.
130 @echo --------------------------------------------------
131 @echo
132endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000133
Glenn L McGrath87470de2003-08-29 12:20:31 +0000134uninstall: busybox.links
135 rm -f $(PREFIX)/bin/busybox
136 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
Eric Andersen1f30a412002-04-13 13:39:48 +0000137
Peter Kjellerstedt88da3ef2004-11-02 09:05:22 +0000138install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000139 $(SHELL) $< $(PREFIX) --hardlinks
140
Mike Frysingerce0cf1d2005-09-24 05:47:52 +0000141check test: busybox
Eric Andersen7daa0762004-10-08 07:46:08 +0000142 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
143 $(top_srcdir)/testsuite/runtest
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000144
Rob Landleyd9f71652005-08-28 08:24:21 +0000145sizes:
Rob Landleyac692b22005-09-01 02:40:21 +0000146 -rm -f busybox
147 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
148 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
Rob Landleyd9f71652005-08-28 08:24:21 +0000149 nm --size-sort busybox
Rob Landley16890752005-09-02 00:41:53 +0000150
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000151# Documentation Targets
Eric Andersenf7300882004-04-06 15:26:25 +0000152doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
John Beppu94e50542001-04-05 19:42:03 +0000153
Eric Andersen7daa0762004-10-08 07:46:08 +0000154docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
155 -mkdir -p docs
156 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
157 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
158 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000159
Eric Andersen67536ff2000-07-06 22:53:22 +0000160docs/BusyBox.txt: docs/busybox.pod
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000161 $(SECHO)
162 $(SECHO) BusyBox Documentation
163 $(SECHO)
Eric Andersen29be79c2000-12-01 22:57:44 +0000164 -mkdir -p docs
Eric Andersen19f86202001-02-17 00:42:47 +0000165 -pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000166
Eric Andersen67536ff2000-07-06 22:53:22 +0000167docs/BusyBox.1: docs/busybox.pod
Eric Andersen09a34e52000-12-01 19:40:18 +0000168 - mkdir -p docs
Eric Andersen29be79c2000-12-01 22:57:44 +0000169 - pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000170 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000171
Eric Andersen2423b122001-12-08 01:56:15 +0000172docs/BusyBox.html: docs/busybox.net/BusyBox.html
Eric Andersen1cf81662001-02-17 15:55:15 +0000173 - mkdir -p docs
Eric Andersene2f6e122000-12-01 19:55:04 +0000174 -@ rm -f docs/BusyBox.html
Eric Andersen7daa0762004-10-08 07:46:08 +0000175 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000176
Eric Andersen2423b122001-12-08 01:56:15 +0000177docs/busybox.net/BusyBox.html: docs/busybox.pod
178 -@ mkdir -p docs/busybox.net
Eric Andersen19f86202001-02-17 00:42:47 +0000179 - pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000180 docs/busybox.net/BusyBox.html
Eric Andersen36763742001-04-24 21:46:07 +0000181 -@ rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000182
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000183# The nifty new buildsystem stuff
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000184scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
Eric Andersen7daa0762004-10-08 07:46:08 +0000185 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000186
Mike Frysingerf1dbd4a2005-08-01 20:49:32 +0000187depend dep: .depend
"Vladimir N. Oleynik"cef737f2005-09-21 07:49:34 +0000188
189DEP_INCLUDES=include/config.h include/bb_config.h
190ifeq ($(strip $(CONFIG_BBCONFIG)),y)
191DEP_INCLUDES += include/bbconfigopts.h
192
193include/bbconfigopts.h: .config
194 scripts/config/mkconfigs > $@
195endif
196
197.depend: scripts/bb_mkdep $(DEP_INCLUDES)
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000198 @rm -f .depend
199 @mkdir -p include/config
Mike Frysinger016d6282005-09-24 06:15:23 +0000200 scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@.tmp
201 mv $@.tmp $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000202
Eric Andersenc9f20d92002-12-05 08:41:41 +0000203include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000204 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000205 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000206 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000207 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000208
Rob Landley193c8c72005-07-27 06:55:36 +0000209include/bb_config.h: include/config.h
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000210 @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
211 @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
Rob Landleyef8f4232005-07-28 19:36:33 +0000212 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
213 < $< >> $@
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000214 @echo "#endif" >> $@
Rob Landley193c8c72005-07-27 06:55:36 +0000215
Eric Andersenc9f20d92002-12-05 08:41:41 +0000216finished2:
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000217 $(SECHO)
218 $(SECHO) Finished installing...
219 $(SECHO)
Eric Andersen19f86202001-02-17 00:42:47 +0000220
Eric Andersen068b6b02002-12-13 22:53:28 +0000221else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000222
223all: menuconfig
224
Eric Andersenc9f20d92002-12-05 08:41:41 +0000225# configuration
226# ---------------------------------------------------------------------------
227
Rob Landleye1d96332005-08-24 00:41:52 +0000228scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000229 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000230 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000231 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000232 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000233
Rob Landleye1d96332005-08-24 00:41:52 +0000234scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000235 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000236 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000237 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000238 fi
239
240menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000241 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000242
243config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000244 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000245
246oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000247 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000248
249randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000250 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000251
252allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000253 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Rob Landleya7e14db2005-09-11 01:16:47 +0000254 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 +0000255 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000256
257allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000258 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000259
260defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000261 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000262
Eric Andersencc8ed391999-10-05 16:24:54 +0000263clean:
Rob Landleya7e14db2005-09-11 01:16:47 +0000264 - $(MAKE) -C scripts/config $@
Eric Andersenf7300882004-04-06 15:26:25 +0000265 - rm -f docs/busybox.dvi docs/busybox.ps \
266 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000267 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
268 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
269 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
Rob Landley90252bb2005-09-20 14:09:57 +0000270 .config.old busybox
271 - rm -rf _install testsuite/links
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000272 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000273 - find . -name \*.o -exec rm -f {} \;
274 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000275
276distclean: clean
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000277 - rm -f scripts/bb_mkdep
Mike Frysingerf9bd87b2005-08-11 21:59:52 +0000278 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
Eric Andersena9953432003-01-27 22:11:59 +0000279 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000280 rm -f .config .config.old .config.cmd
Eric Andersencc8ed391999-10-05 16:24:54 +0000281
Eric Andersenc9f20d92002-12-05 08:41:41 +0000282release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000283 cd ..; \
284 rm -rf $(PROG)-$(VERSION); \
285 cp -a busybox $(PROG)-$(VERSION); \
286 \
287 find $(PROG)-$(VERSION)/ -type d \
Eric Andersen4306bb12005-08-17 00:03:23 +0000288 -name .svn \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000289 -print \
290 -exec rm -rf {} \; ; \
291 \
292 find $(PROG)-$(VERSION)/ -type f \
293 -name .\#* \
294 -print \
295 -exec rm -f {} \; ; \
296 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000297 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000298
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000299tags:
300 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000301
Eric Andersenc9f20d92002-12-05 08:41:41 +0000302
Eric Andersen068b6b02002-12-13 22:53:28 +0000303endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000304
Eric Andersen7daa0762004-10-08 07:46:08 +0000305endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000306
Eric Andersen7daa0762004-10-08 07:46:08 +0000307.PHONY: dummy subdirs release distclean clean config oldconfig \
308 menuconfig tags check test depend buildtree