blob: ecbfcec5eda6a4a5e9e6847e86862cdb4f5705b1 [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
37srctree=$(top_srcdir)
38vpath %/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 \
Eric Anderseneac20452003-07-29 07:45:05 +000045 sysklogd util-linux 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)
50CFLAGS += -I/usr/include/selinux
51LIBRARIES += -lsecure
52endif
53
Eric Andersen7daa0762004-10-08 07:46:08 +000054CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
55CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
56
57ALL_DIRS:= $(DIRS) scripts/config
58ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
59
60ifeq ($(KBUILD_SRC),)
61
62ifdef O
63 ifeq ("$(origin O)", "command line")
64 KBUILD_OUTPUT := $(O)
65 endif
66endif
67
68# That's our default target when none is given on the command line
69.PHONY: _all
70_all:
71
72ifneq ($(KBUILD_OUTPUT),)
73# Invoke a second make in the output directory, passing relevant variables
74# check that the output directory actually exists
75saved-output := $(KBUILD_OUTPUT)
76KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
77$(if $(wildcard $(KBUILD_OUTPUT)),, \
78 $(error output directory "$(saved-output)" does not exist))
79
80.PHONY: $(MAKECMDGOALS)
81
82$(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
83 $(MAKE) -C $(KBUILD_OUTPUT) \
84 top_srcdir=$(CURDIR) \
85 top_builddir=$(KBUILD_OUTPUT) \
86 TOPDIR=$(KBUILD_OUTPUT) \
87 KBUILD_SRC=$(CURDIR) \
88 -f $(CURDIR)/Makefile $@
89
90$(KBUILD_OUTPUT)/Rules.mak:
91 @echo > $@
92 @echo top_srcdir=$(CURDIR) >> $@
93 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
94 @echo include $(top_srcdir)/Rules.mak >> $@
95
96$(KBUILD_OUTPUT)/Makefile:
97 @echo > $@
98 @echo top_srcdir=$(CURDIR) >> $@
99 @echo top_builddir=$(KBUILD_OUTPUT) >> $@
100 @echo KBUILD_SRC='$$(top_srcdir)' >> $@
101 @echo include '$$(KBUILD_SRC)'/Makefile >> $@
102
103# Leave processing to above invocation of make
104skip-makefile := 1
105endif # ifneq ($(KBUILD_OUTPUT),)
106endif # ifeq ($(KBUILD_SRC),)
107
108ifeq ($(skip-makefile),)
109
110_all: all
Glenn L McGrath6376b582003-09-24 15:48:29 +0000111
Eric Andersen068b6b02002-12-13 22:53:28 +0000112ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersen00814662001-04-26 23:29:10 +0000113
Eric Andersend4fcb802003-07-15 00:28:26 +0000114all: busybox busybox.links doc
Erik Andersen0a704e82000-05-03 03:19:06 +0000115
Eric Andersen7daa0762004-10-08 07:46:08 +0000116all_tree: $(ALL_MAKEFILES)
Eric Andersen3cd27602001-10-24 07:58:02 +0000117
Eric Andersen7daa0762004-10-08 07:46:08 +0000118$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
119 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
120
121# In this section, we need .config
122-include $(top_builddir)/.config.cmd
123include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
124-include $(top_builddir)/.depend
125
126busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
Glenn L McGrathd72e34c2003-09-20 00:59:35 +0000127 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
Eric Andersen85208e22002-04-12 12:05:57 +0000128 $(STRIPCMD) $@
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000129
Eric Andersen7daa0762004-10-08 07:46:08 +0000130busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000131 - $(SHELL) $^ >$@
132
Eric Andersen63024862004-10-13 17:45:57 +0000133install: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000134 $(SHELL) $< $(PREFIX)
Eric Andersen13879102004-08-26 23:13:00 +0000135ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
136 @echo
137 @echo
138 @echo --------------------------------------------------
139 @echo You will probably need to make your busybox binary
140 @echo setuid root to ensure all configured applets will
141 @echo work properly.
142 @echo --------------------------------------------------
143 @echo
144endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000145
Glenn L McGrath87470de2003-08-29 12:20:31 +0000146uninstall: busybox.links
147 rm -f $(PREFIX)/bin/busybox
148 for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
Eric Andersen1f30a412002-04-13 13:39:48 +0000149
Peter Kjellerstedt88da3ef2004-11-02 09:05:22 +0000150install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000151 $(SHELL) $< $(PREFIX) --hardlinks
152
Eric Andersen7daa0762004-10-08 07:46:08 +0000153check: busybox
154 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
155 $(top_srcdir)/testsuite/runtest
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000156
157# Documentation Targets
Eric Andersenf7300882004-04-06 15:26:25 +0000158doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
John Beppu94e50542001-04-05 19:42:03 +0000159
Eric Andersen7daa0762004-10-08 07:46:08 +0000160docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
161 -mkdir -p docs
162 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
163 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
164 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000165
Eric Andersen67536ff2000-07-06 22:53:22 +0000166docs/BusyBox.txt: docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000167 @echo
168 @echo BusyBox Documentation
169 @echo
Eric Andersen29be79c2000-12-01 22:57:44 +0000170 -mkdir -p docs
Eric Andersen19f86202001-02-17 00:42:47 +0000171 -pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000172
Eric Andersen67536ff2000-07-06 22:53:22 +0000173docs/BusyBox.1: docs/busybox.pod
Eric Andersen09a34e52000-12-01 19:40:18 +0000174 - mkdir -p docs
Eric Andersen29be79c2000-12-01 22:57:44 +0000175 - pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000176 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000177
Eric Andersen2423b122001-12-08 01:56:15 +0000178docs/BusyBox.html: docs/busybox.net/BusyBox.html
Eric Andersen1cf81662001-02-17 15:55:15 +0000179 - mkdir -p docs
Eric Andersene2f6e122000-12-01 19:55:04 +0000180 -@ rm -f docs/BusyBox.html
Eric Andersen7daa0762004-10-08 07:46:08 +0000181 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000182
Eric Andersen2423b122001-12-08 01:56:15 +0000183docs/busybox.net/BusyBox.html: docs/busybox.pod
184 -@ mkdir -p docs/busybox.net
Eric Andersen19f86202001-02-17 00:42:47 +0000185 - pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000186 docs/busybox.net/BusyBox.html
Eric Andersen36763742001-04-24 21:46:07 +0000187 -@ rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000188
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000189# The nifty new buildsystem stuff
Eric Andersen7daa0762004-10-08 07:46:08 +0000190scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
191 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Eric Andersen67536ff2000-07-06 22:53:22 +0000192
Eric Andersen7daa0762004-10-08 07:46:08 +0000193scripts/split-include: $(top_srcdir)/scripts/split-include.c
194 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000195
Eric Andersenc9f20d92002-12-05 08:41:41 +0000196.depend: scripts/mkdep
Eric Andersen85208e22002-04-12 12:05:57 +0000197 rm -f .depend .hdepend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000198 mkdir -p include/config;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000199 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000200 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000201 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000202 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000203
Eric Andersenaaab46b2003-01-11 18:02:51 +0000204depend dep: include/config.h .depend
Eric Andersen85208e22002-04-12 12:05:57 +0000205
Eric Andersenc9f20d92002-12-05 08:41:41 +0000206include/config/MARKER: depend scripts/split-include
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000207 scripts/split-include include/config.h include/config
208 @ touch include/config/MARKER
209
Eric Andersenc9f20d92002-12-05 08:41:41 +0000210include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000211 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000212 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000213 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000214 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000215
Eric Andersenc9f20d92002-12-05 08:41:41 +0000216finished2:
217 @echo
218 @echo Finished installing...
219 @echo
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
Eric Andersen7daa0762004-10-08 07:46:08 +0000228$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
229 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
230
231scripts/config/conf: scripts/config/Makefile 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
237scripts/config/mconf: scripts/config/Makefile 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)
Eric Andersen8ee69432004-04-06 11:46:56 +0000257 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
258 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
Eric Andersenb07ae7b2004-04-06 11:51:45 +0000259 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
260 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
Eric Andersen8ee69432004-04-06 11:46:56 +0000261 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000262
263allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000264 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000265
266defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000267 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000268
Eric Andersencc8ed391999-10-05 16:24:54 +0000269clean:
Eric Andersenf7300882004-04-06 15:26:25 +0000270 - rm -f docs/busybox.dvi docs/busybox.ps \
271 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000272 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
273 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
274 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
275 .config.old .hdepend busybox
276 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000277 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000278 - find . -name \*.o -exec rm -f {} \;
279 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000280
281distclean: clean
Eric Andersena9953432003-01-27 22:11:59 +0000282 - rm -f scripts/split-include scripts/mkdep
283 - rm -rf include/config include/config.h
284 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000285 rm -f .config .config.old .config.cmd
Eric Andersena9953432003-01-27 22:11:59 +0000286 - $(MAKE) -C scripts/config clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000287
Eric Andersenc9f20d92002-12-05 08:41:41 +0000288release: distclean #doc
Erik Andersenfac10d72000-02-07 05:29:42 +0000289 cd ..; \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000290 rm -rf $(PROG)-$(VERSION); \
291 cp -a busybox $(PROG)-$(VERSION); \
Erik Andersenfac10d72000-02-07 05:29:42 +0000292 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000293 find $(PROG)-$(VERSION)/ -type d \
Erik Andersenfac10d72000-02-07 05:29:42 +0000294 -name CVS \
295 -print \
Eric Andersen53b55ac2001-03-16 07:43:53 +0000296 -exec rm -rf {} \; ; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000297 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000298 find $(PROG)-$(VERSION)/ -type f \
Eric Andersenb0b732b2000-07-06 23:17:16 +0000299 -name .\#* \
300 -print \
Eric Andersen53b55ac2001-03-16 07:43:53 +0000301 -exec rm -f {} \; ; \
Eric Andersenb0b732b2000-07-06 23:17:16 +0000302 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000303 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000304
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000305tags:
306 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000307
Eric Andersenc9f20d92002-12-05 08:41:41 +0000308
Eric Andersen068b6b02002-12-13 22:53:28 +0000309endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000310
Eric Andersen7daa0762004-10-08 07:46:08 +0000311endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000312
Eric Andersen7daa0762004-10-08 07:46:08 +0000313.PHONY: dummy subdirs release distclean clean config oldconfig \
314 menuconfig tags check test depend buildtree
Eric Andersen85208e22002-04-12 12:05:57 +0000315