blob: c8b6d79d2719185729c1d3e3493978cd000c6531 [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
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000113busybox: $(ALL_MAKEFILES) .depend $(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
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000183scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
Eric Andersen7daa0762004-10-08 07:46:08 +0000184 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000185
Mike Frysingerf1dbd4a2005-08-01 20:49:32 +0000186depend dep: .depend
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000187.depend: scripts/bb_mkdep include/config.h include/bb_config.h
188 @rm -f .depend
189 @mkdir -p include/config
190 scripts/bb_mkdep -c include/config.h -c include/bb_config.h > $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000191
Eric Andersenc9f20d92002-12-05 08:41:41 +0000192include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000193 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000194 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000195 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000196 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000197
Rob Landley193c8c72005-07-27 06:55:36 +0000198include/bb_config.h: include/config.h
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000199 @echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
200 @sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
Rob Landleyef8f4232005-07-28 19:36:33 +0000201 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
202 < $< >> $@
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000203 @echo "#endif" >> $@
Rob Landley193c8c72005-07-27 06:55:36 +0000204
Paul Fox79c142d2005-08-01 16:04:40 +0000205include/bbconfigopts.h: .config
Rob Landleye1d96332005-08-24 00:41:52 +0000206 @[ -d $(@D) ] || mkdir -v $(@D)
207 $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
Paul Fox79c142d2005-08-01 16:04:40 +0000208
Eric Andersenc9f20d92002-12-05 08:41:41 +0000209finished2:
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000210 $(SECHO)
211 $(SECHO) Finished installing...
212 $(SECHO)
Eric Andersen19f86202001-02-17 00:42:47 +0000213
Eric Andersen068b6b02002-12-13 22:53:28 +0000214else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000215
216all: menuconfig
217
Eric Andersenc9f20d92002-12-05 08:41:41 +0000218# configuration
219# ---------------------------------------------------------------------------
220
Rob Landleye1d96332005-08-24 00:41:52 +0000221scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000222 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000223 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000224 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000225 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000226
Rob Landleye1d96332005-08-24 00:41:52 +0000227scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000228 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000229 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000230 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000231 fi
232
233menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000234 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000235
236config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000237 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000238
239oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000240 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000241
242randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000243 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000244
245allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000246 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Rob Landleya7e14db2005-09-11 01:16:47 +0000247 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 +0000248 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000249
250allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000251 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000252
253defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000254 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000255
Eric Andersencc8ed391999-10-05 16:24:54 +0000256clean:
Rob Landleya7e14db2005-09-11 01:16:47 +0000257 - $(MAKE) -C scripts/config $@
Eric Andersenf7300882004-04-06 15:26:25 +0000258 - rm -f docs/busybox.dvi docs/busybox.ps \
259 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000260 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
261 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
262 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000263 .config.old busybox testsuite/links/*
Eric Andersen24e098a2003-08-22 20:53:38 +0000264 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000265 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000266 - find . -name \*.o -exec rm -f {} \;
267 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000268
269distclean: clean
"Vladimir N. Oleynik"5e60dc42005-09-12 12:33:27 +0000270 - rm -f scripts/bb_mkdep
Mike Frysingerf9bd87b2005-08-11 21:59:52 +0000271 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
Eric Andersena9953432003-01-27 22:11:59 +0000272 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000273 rm -f .config .config.old .config.cmd
Eric Andersencc8ed391999-10-05 16:24:54 +0000274
Eric Andersenc9f20d92002-12-05 08:41:41 +0000275release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000276 cd ..; \
277 rm -rf $(PROG)-$(VERSION); \
278 cp -a busybox $(PROG)-$(VERSION); \
279 \
280 find $(PROG)-$(VERSION)/ -type d \
Eric Andersen4306bb12005-08-17 00:03:23 +0000281 -name .svn \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000282 -print \
283 -exec rm -rf {} \; ; \
284 \
285 find $(PROG)-$(VERSION)/ -type f \
286 -name .\#* \
287 -print \
288 -exec rm -f {} \; ; \
289 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000290 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000291
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000292tags:
293 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000294
Eric Andersenc9f20d92002-12-05 08:41:41 +0000295
Eric Andersen068b6b02002-12-13 22:53:28 +0000296endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000297
Eric Andersen7daa0762004-10-08 07:46:08 +0000298endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000299
Eric Andersen7daa0762004-10-08 07:46:08 +0000300.PHONY: dummy subdirs release distclean clean config oldconfig \
301 menuconfig tags check test depend buildtree