blob: c96c7373bafb7e5ddbf22ad8b531c37ea3da4dc0 [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
Mike Frysinger9d6e0832005-07-31 22:50:17 +000037export srctree=$(top_srcdir)
Eric Andersen7daa0762004-10-08 07:46:08 +000038vpath %/Config.in $(srctree)
39
Rob Landleye1d96332005-08-24 00:41:52 +000040include $(top_srcdir)/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
Rob Landleye1d96332005-08-24 00:41:52 +0000118 [ -d $(@D) ] || mkdir -p $(@D); cp $< $@
Eric Andersen7daa0762004-10-08 07:46:08 +0000119
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
Rob Landley193c8c72005-07-27 06:55:36 +0000125busybox: $(ALL_MAKEFILES) .depend include/bb_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
Rob Landleyd9f71652005-08-28 08:24:21 +0000156sizes:
Rob Landleyac692b22005-09-01 02:40:21 +0000157 -rm -f busybox
158 $(MAKE) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \
159 -f $(top_srcdir)/Makefile STRIPCMD=/bin/true
Rob Landleyd9f71652005-08-28 08:24:21 +0000160 nm --size-sort busybox
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000161# Documentation Targets
Eric Andersenf7300882004-04-06 15:26:25 +0000162doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
John Beppu94e50542001-04-05 19:42:03 +0000163
Eric Andersen7daa0762004-10-08 07:46:08 +0000164docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
165 -mkdir -p docs
166 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
167 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
168 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
Eric Andersen53310252000-07-04 19:42:23 +0000169
Eric Andersen67536ff2000-07-06 22:53:22 +0000170docs/BusyBox.txt: docs/busybox.pod
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000171 $(SECHO)
172 $(SECHO) BusyBox Documentation
173 $(SECHO)
Eric Andersen29be79c2000-12-01 22:57:44 +0000174 -mkdir -p docs
Eric Andersen19f86202001-02-17 00:42:47 +0000175 -pod2text $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000176
Eric Andersen67536ff2000-07-06 22:53:22 +0000177docs/BusyBox.1: docs/busybox.pod
Eric Andersen09a34e52000-12-01 19:40:18 +0000178 - mkdir -p docs
Eric Andersen29be79c2000-12-01 22:57:44 +0000179 - pod2man --center=BusyBox --release="version $(VERSION)" \
Eric Andersen19f86202001-02-17 00:42:47 +0000180 $< > $@
Eric Andersen53310252000-07-04 19:42:23 +0000181
Eric Andersen2423b122001-12-08 01:56:15 +0000182docs/BusyBox.html: docs/busybox.net/BusyBox.html
Eric Andersen1cf81662001-02-17 15:55:15 +0000183 - mkdir -p docs
Eric Andersene2f6e122000-12-01 19:55:04 +0000184 -@ rm -f docs/BusyBox.html
Eric Andersen7daa0762004-10-08 07:46:08 +0000185 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
Eric Andersen53310252000-07-04 19:42:23 +0000186
Eric Andersen2423b122001-12-08 01:56:15 +0000187docs/busybox.net/BusyBox.html: docs/busybox.pod
188 -@ mkdir -p docs/busybox.net
Eric Andersen19f86202001-02-17 00:42:47 +0000189 - pod2html --noindex $< > \
Eric Andersen2423b122001-12-08 01:56:15 +0000190 docs/busybox.net/BusyBox.html
Eric Andersen36763742001-04-24 21:46:07 +0000191 -@ rm -f pod2htm*
Erik Andersen0a704e82000-05-03 03:19:06 +0000192
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000193# The nifty new buildsystem stuff
Eric Andersen7daa0762004-10-08 07:46:08 +0000194scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
195 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Eric Andersen67536ff2000-07-06 22:53:22 +0000196
Eric Andersen7daa0762004-10-08 07:46:08 +0000197scripts/split-include: $(top_srcdir)/scripts/split-include.c
198 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
Erik Andersen1d1d9502000-04-21 01:26:49 +0000199
Mike Frysingerf1dbd4a2005-08-01 20:49:32 +0000200depend dep: .depend
201.depend: scripts/mkdep include/config.h include/bbconfigopts.h
Eric Andersen85208e22002-04-12 12:05:57 +0000202 rm -f .depend .hdepend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000203 mkdir -p include/config;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000204 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000205 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000206 scripts/mkdep -I include -- \
Eric Andersen7daa0762004-10-08 07:46:08 +0000207 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000208
Eric Andersenc9f20d92002-12-05 08:41:41 +0000209include/config/MARKER: depend scripts/split-include
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000210 scripts/split-include include/config.h include/config
211 @ touch include/config/MARKER
212
Eric Andersenc9f20d92002-12-05 08:41:41 +0000213include/config.h: .config
Eric Andersen7daa0762004-10-08 07:46:08 +0000214 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000215 $(MAKE) -C scripts/config conf; \
Eric Andersen3cd27602001-10-24 07:58:02 +0000216 fi;
Eric Andersen7daa0762004-10-08 07:46:08 +0000217 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersen85208e22002-04-12 12:05:57 +0000218
Rob Landley193c8c72005-07-27 06:55:36 +0000219include/bb_config.h: include/config.h
Rob Landley157e8072005-08-02 10:02:23 +0000220 echo -e "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H" > $@
Rob Landleyef8f4232005-07-28 19:36:33 +0000221 sed -e 's/#undef CONFIG_\(.*\)/#define ENABLE_\1 0/' \
222 -e 's/#define CONFIG_\(.*\)/#define CONFIG_\1\n#define ENABLE_\1/' \
223 < $< >> $@
Rob Landley193c8c72005-07-27 06:55:36 +0000224 echo "#endif" >> $@
225
Paul Fox79c142d2005-08-01 16:04:40 +0000226include/bbconfigopts.h: .config
Rob Landleye1d96332005-08-24 00:41:52 +0000227 @[ -d $(@D) ] || mkdir -v $(@D)
228 $(top_srcdir)/scripts/config/mkconfigs >include/bbconfigopts.h
Paul Fox79c142d2005-08-01 16:04:40 +0000229
Eric Andersenc9f20d92002-12-05 08:41:41 +0000230finished2:
Mike Frysingerc99e2c52005-07-28 22:14:35 +0000231 $(SECHO)
232 $(SECHO) Finished installing...
233 $(SECHO)
Eric Andersen19f86202001-02-17 00:42:47 +0000234
Eric Andersen068b6b02002-12-13 22:53:28 +0000235else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000236
237all: menuconfig
238
Eric Andersenc9f20d92002-12-05 08:41:41 +0000239# configuration
240# ---------------------------------------------------------------------------
241
Rob Landleye1d96332005-08-24 00:41:52 +0000242scripts/config/conf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000243 $(MAKE) -C scripts/config conf
Eric Andersen068b6b02002-12-13 22:53:28 +0000244 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000245 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersen068b6b02002-12-13 22:53:28 +0000246 fi
Eric Andersen7daa0762004-10-08 07:46:08 +0000247
Rob Landleye1d96332005-08-24 00:41:52 +0000248scripts/config/mconf: scripts/config/Makefile $(top_srcdir)/Rules.mak
Glenn L McGrathb19c73d2003-08-29 13:25:55 +0000249 $(MAKE) -C scripts/config ncurses conf mconf
Eric Andersenc9f20d92002-12-05 08:41:41 +0000250 -@if [ ! -f .config ] ; then \
Glenn L McGrath6376b582003-09-24 15:48:29 +0000251 cp $(CONFIG_DEFCONFIG) .config; \
Eric Andersenc9f20d92002-12-05 08:41:41 +0000252 fi
253
254menuconfig: scripts/config/mconf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000255 @./scripts/config/mconf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000256
257config: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000258 @./scripts/config/conf $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000259
260oldconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000261 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000262
263randconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000264 @./scripts/config/conf -r $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000265
266allyesconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000267 @./scripts/config/conf -y $(CONFIG_CONFIG_IN)
Eric Andersen8ee69432004-04-06 11:46:56 +0000268 sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
269 sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
Eric Andersenb07ae7b2004-04-06 11:51:45 +0000270 sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
271 sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
Eric Andersen8ee69432004-04-06 11:46:56 +0000272 @./scripts/config/conf -o $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000273
274allnoconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000275 @./scripts/config/conf -n $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000276
277defconfig: scripts/config/conf
Glenn L McGrath6376b582003-09-24 15:48:29 +0000278 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000279
Eric Andersencc8ed391999-10-05 16:24:54 +0000280clean:
Eric Andersenf7300882004-04-06 15:26:25 +0000281 - rm -f docs/busybox.dvi docs/busybox.ps \
282 docs/busybox.pod docs/busybox.net/busybox.html \
Eric Andersen24e098a2003-08-22 20:53:38 +0000283 docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
284 docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
285 docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
286 .config.old .hdepend busybox
287 - rm -rf _install
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000288 - find . -name .\*.flags -exec rm -f {} \;
Eric Andersen87715172002-07-31 03:45:05 +0000289 - find . -name \*.o -exec rm -f {} \;
290 - find . -name \*.a -exec rm -f {} \;
Eric Andersencc8ed391999-10-05 16:24:54 +0000291
292distclean: clean
Eric Andersena9953432003-01-27 22:11:59 +0000293 - rm -f scripts/split-include scripts/mkdep
Mike Frysingerf9bd87b2005-08-11 21:59:52 +0000294 - rm -rf include/config include/config.h include/bb_config.h include/bbconfigopts.h
Eric Andersena9953432003-01-27 22:11:59 +0000295 - find . -name .depend -exec rm -f {} \;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000296 rm -f .config .config.old .config.cmd
Eric Andersena9953432003-01-27 22:11:59 +0000297 - $(MAKE) -C scripts/config clean
Eric Andersencc8ed391999-10-05 16:24:54 +0000298
Eric Andersenc9f20d92002-12-05 08:41:41 +0000299release: distclean #doc
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000300 cd ..; \
301 rm -rf $(PROG)-$(VERSION); \
302 cp -a busybox $(PROG)-$(VERSION); \
303 \
304 find $(PROG)-$(VERSION)/ -type d \
Eric Andersen4306bb12005-08-17 00:03:23 +0000305 -name .svn \
Mike Frysingerfcafa4b2005-08-01 20:48:00 +0000306 -print \
307 -exec rm -rf {} \; ; \
308 \
309 find $(PROG)-$(VERSION)/ -type f \
310 -name .\#* \
311 -print \
312 -exec rm -f {} \; ; \
313 \
Glenn L McGrath0874a612003-11-17 10:26:43 +0000314 tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000315
Mark Whitleydd23b8b2000-07-10 23:00:47 +0000316tags:
317 ctags -R .
Matt Kraai4e05da82001-11-19 19:47:56 +0000318
Eric Andersenc9f20d92002-12-05 08:41:41 +0000319
Eric Andersen068b6b02002-12-13 22:53:28 +0000320endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000321
Eric Andersen7daa0762004-10-08 07:46:08 +0000322endif # ifeq ($(skip-makefile),)
Eric Andersenc9f20d92002-12-05 08:41:41 +0000323
Eric Andersen7daa0762004-10-08 07:46:08 +0000324.PHONY: dummy subdirs release distclean clean config oldconfig \
325 menuconfig tags check test depend buildtree