blob: d205bb1b6b35a5a3d0bc2f577fdceac422c663e5 [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 \
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
125busybox: $(ALL_MAKEFILES) .depend include/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
Eric Andersen53310252000-07-04 19:42:23 +0000166 @echo
167 @echo BusyBox Documentation
168 @echo
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
Mike Frysingere9903cf2005-06-11 00:13:58 +0000203depend dep: .depend
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
Eric Andersenc9f20d92002-12-05 08:41:41 +0000215finished2:
216 @echo
217 @echo Finished installing...
218 @echo
Eric Andersen19f86202001-02-17 00:42:47 +0000219
Eric Andersen068b6b02002-12-13 22:53:28 +0000220else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000221
222all: menuconfig
223
Eric Andersenc9f20d92002-12-05 08:41:41 +0000224# configuration
225# ---------------------------------------------------------------------------
226
Eric Andersen7daa0762004-10-08 07:46:08 +0000227$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
228 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
229
230scripts/config/conf: scripts/config/Makefile Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000231 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000232 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000233 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000234 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000235
236scripts/config/mconf: scripts/config/Makefile Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000237 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000238 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000239 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000240 fi
241
242menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000243 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000244
245config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000246 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000247
248oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000249 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000250
251randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000252 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000253
254allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000255 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Eric Andersen8ee69432004-04-06 11:46:56 +0000256 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
257 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
Eric Andersenb07ae7b2004-04-06 11:51:45 +0000258 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
259 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
Eric Andersen8ee69432004-04-06 11:46:56 +0000260 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000261
262allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000263 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000264
265defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000266 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000267
Eric Andersencc8ed391999-10-05 16:24:54 +0000268clean:
Eric Andersenf7300882004-04-06 15:26:25 +0000269 - rm -f docs/busybox.dvi docs/busybox.ps \
270 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000271 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
272 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
273 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
274 .config.old .hdepend busybox
275 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000276 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000277 - find . -name \*.o -exec rm -f {} \;
278 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000279
280distclean: clean
Eric Andersena9953432003-01-27 22:11:59 +0000281 - rm -f scripts/split-include scripts/mkdep
282 - rm -rf include/config include/config.h
283 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000284 rm -f .config .config.old .config.cmd
Eric Andersena9953432003-01-27 22:11:59 +0000285 - $(MAKE) -C scripts/config clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000286
Eric Andersenc9f20d92002-12-05 08:41:41 +0000287release: distclean #doc
Erik Andersenfac10d72000-02-07 05:29:42 +0000288 cd ..; \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000289 rm -rf $(PROG)-$(VERSION); \
290 cp -a busybox $(PROG)-$(VERSION); \
Erik Andersenfac10d72000-02-07 05:29:42 +0000291 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000292 find $(PROG)-$(VERSION)/ -type d \
Erik Andersenfac10d72000-02-07 05:29:42 +0000293 -name CVS \
294 -print \
Eric Andersen53b55ac2001-03-16 07:43:53 +0000295 -exec rm -rf {} \; ; \
Erik Andersenfac10d72000-02-07 05:29:42 +0000296 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000297 find $(PROG)-$(VERSION)/ -type f \
Eric Andersenb0b732b2000-07-06 23:17:16 +0000298 -name .\#* \
299 -print \
Eric Andersen53b55ac2001-03-16 07:43:53 +0000300 -exec rm -f {} \; ; \
Eric Andersenb0b732b2000-07-06 23:17:16 +0000301 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000302 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000303
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000304tags:
305 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000306
Eric Andersenc9f20d92002-12-05 08:41:41 +0000307
Eric Andersen068b6b02002-12-13 22:53:28 +0000308endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000309
Eric Andersen7daa0762004-10-08 07:46:08 +0000310endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000311
Eric Andersen7daa0762004-10-08 07:46:08 +0000312.PHONY: dummy subdirs release distclean clean config oldconfig \
313 menuconfig tags check test depend buildtree
Eric Andersen85208e22002-04-12 12:05:57 +0000314