aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile145
1 files changed, 111 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 29897ef4e..3e2b3ef18 100644
--- a/Makefile
+++ b/Makefile
@@ -22,37 +22,112 @@
22#-------------------------------------------------------------- 22#--------------------------------------------------------------
23noconfig_targets := menuconfig config oldconfig randconfig \ 23noconfig_targets := menuconfig config oldconfig randconfig \
24 defconfig allyesconfig allnoconfig clean distclean \ 24 defconfig allyesconfig allnoconfig clean distclean \
25 release tags 25 release tags
26TOPDIR=./ 26
27include Rules.mak 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
28 41
29DIRS:=applets archival archival/libunarchive coreutils console-tools \ 42DIRS:=applets archival archival/libunarchive coreutils console-tools \
30 debianutils editors findutils init miscutils modutils networking \ 43 debianutils editors findutils init miscutils modutils networking \
31 networking/libiproute networking/udhcp procps loginutils shell \ 44 networking/libiproute networking/udhcp procps loginutils shell \
32 sysklogd util-linux libpwdgrp coreutils/libcoreutils libbb 45 sysklogd util-linux libpwdgrp coreutils/libcoreutils libbb
33 46
47SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
48
34ifeq ($(strip $(CONFIG_SELINUX)),y) 49ifeq ($(strip $(CONFIG_SELINUX)),y)
35CFLAGS += -I/usr/include/selinux 50CFLAGS += -I/usr/include/selinux
36LIBRARIES += -lsecure 51LIBRARIES += -lsecure
37endif 52endif
38 53
39CONFIG_CONFIG_IN = sysdeps/$(TARGET_OS)/Config.in 54CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
40CONFIG_DEFCONFIG = sysdeps/$(TARGET_OS)/defconfig 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
41 111
42ifeq ($(strip $(HAVE_DOT_CONFIG)),y) 112ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
43 113
44all: busybox busybox.links doc 114all: busybox busybox.links doc
45 115
116all_tree: $(ALL_MAKEFILES)
117
118$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
119 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
120
46# In this section, we need .config 121# In this section, we need .config
47-include .config.cmd 122-include $(top_builddir)/.config.cmd
48include $(patsubst %,%/Makefile.in, $(DIRS)) 123include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
49-include $(TOPDIR).depend 124-include $(top_builddir)/.depend
50 125
51busybox: .depend include/config.h $(libraries-y) 126busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
52 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group 127 $(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
53 $(STRIPCMD) $@ 128 $(STRIPCMD) $@
54 129
55busybox.links: applets/busybox.mkll include/config.h 130busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
56 - $(SHELL) $^ >$@ 131 - $(SHELL) $^ >$@
57 132
58install: applets/install.sh busybox busybox.links 133install: applets/install.sh busybox busybox.links
@@ -75,14 +150,18 @@ uninstall: busybox.links
75install-hardlinks: applets/install.sh busybox busybox.links 150install-hardlinks: applets/install.sh busybox busybox.links
76 $(SHELL) $< $(PREFIX) --hardlinks 151 $(SHELL) $< $(PREFIX) --hardlinks
77 152
153check: busybox
154 bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
155 $(top_srcdir)/testsuite/runtest
78 156
79# Documentation Targets 157# Documentation Targets
80doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html 158doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
81 159
82docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod 160docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
83 - ( cat docs/busybox_header.pod; \ 161 -mkdir -p docs
84 docs/autodocifier.pl include/usage.h; \ 162 - ( cat $(top_srcdir)/docs/busybox_header.pod; \
85 cat docs/busybox_footer.pod ) > docs/busybox.pod 163 $(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
164 cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
86 165
87docs/BusyBox.txt: docs/busybox.pod 166docs/BusyBox.txt: docs/busybox.pod
88 @echo 167 @echo
@@ -99,7 +178,7 @@ docs/BusyBox.1: docs/busybox.pod
99docs/BusyBox.html: docs/busybox.net/BusyBox.html 178docs/BusyBox.html: docs/busybox.net/BusyBox.html
100 - mkdir -p docs 179 - mkdir -p docs
101 -@ rm -f docs/BusyBox.html 180 -@ rm -f docs/BusyBox.html
102 -@ ln -s busybox.net/BusyBox.html docs/BusyBox.html 181 -@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
103 182
104docs/busybox.net/BusyBox.html: docs/busybox.pod 183docs/busybox.net/BusyBox.html: docs/busybox.pod
105 -@ mkdir -p docs/busybox.net 184 -@ mkdir -p docs/busybox.net
@@ -108,20 +187,19 @@ docs/busybox.net/BusyBox.html: docs/busybox.pod
108 -@ rm -f pod2htm* 187 -@ rm -f pod2htm*
109 188
110# The nifty new buildsystem stuff 189# The nifty new buildsystem stuff
111scripts/mkdep: scripts/mkdep.c 190scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
112 $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c 191 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
113 192
114scripts/split-include: scripts/split-include.c 193scripts/split-include: $(top_srcdir)/scripts/split-include.c
115 $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c 194 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
116 195
117.depend: scripts/mkdep 196.depend: scripts/mkdep
118 rm -f .depend .hdepend; 197 rm -f .depend .hdepend;
119 mkdir -p include/config; 198 mkdir -p include/config;
120 $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
121 scripts/mkdep -I include -- \ 199 scripts/mkdep -I include -- \
122 `find -name \*.c -print | sed -e "s,^./,,"` >> .depend; 200 `find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
123 scripts/mkdep -I include -- \ 201 scripts/mkdep -I include -- \
124 `find -name \*.h -print | sed -e "s,^./,,"` >> .hdepend; 202 `find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
125 203
126depend dep: include/config.h .depend 204depend dep: include/config.h .depend
127 205
@@ -130,13 +208,10 @@ include/config/MARKER: depend scripts/split-include
130 @ touch include/config/MARKER 208 @ touch include/config/MARKER
131 209
132include/config.h: .config 210include/config.h: .config
133 @if [ ! -x ./scripts/config/conf ] ; then \ 211 @if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
134 $(MAKE) -C scripts/config conf; \ 212 $(MAKE) -C scripts/config conf; \
135 fi; 213 fi;
136 @./scripts/config/conf -o $(CONFIG_CONFIG_IN) 214 @$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
137
138%.o: %.c
139 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
140 215
141finished2: 216finished2:
142 @echo 217 @echo
@@ -150,12 +225,16 @@ all: menuconfig
150# configuration 225# configuration
151# --------------------------------------------------------------------------- 226# ---------------------------------------------------------------------------
152 227
153scripts/config/conf: 228$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
229 d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
230
231scripts/config/conf: scripts/config/Makefile Rules.mak
154 $(MAKE) -C scripts/config conf 232 $(MAKE) -C scripts/config conf
155 -@if [ ! -f .config ] ; then \ 233 -@if [ ! -f .config ] ; then \
156 cp $(CONFIG_DEFCONFIG) .config; \ 234 cp $(CONFIG_DEFCONFIG) .config; \
157 fi 235 fi
158scripts/config/mconf: 236
237scripts/config/mconf: scripts/config/Makefile Rules.mak
159 $(MAKE) -C scripts/config ncurses conf mconf 238 $(MAKE) -C scripts/config ncurses conf mconf
160 -@if [ ! -f .config ] ; then \ 239 -@if [ ! -f .config ] ; then \
161 cp $(CONFIG_DEFCONFIG) .config; \ 240 cp $(CONFIG_DEFCONFIG) .config; \
@@ -187,9 +266,6 @@ allnoconfig: scripts/config/conf
187defconfig: scripts/config/conf 266defconfig: scripts/config/conf
188 @./scripts/config/conf -d $(CONFIG_CONFIG_IN) 267 @./scripts/config/conf -d $(CONFIG_CONFIG_IN)
189 268
190check: busybox
191 cd testsuite && ./runtest
192
193clean: 269clean:
194 - rm -f docs/busybox.dvi docs/busybox.ps \ 270 - rm -f docs/busybox.dvi docs/busybox.ps \
195 docs/busybox.pod docs/busybox.net/busybox.html \ 271 docs/busybox.pod docs/busybox.net/busybox.html \
@@ -232,7 +308,8 @@ tags:
232 308
233endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y) 309endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
234 310
235.PHONY: dummy subdirs release distclean clean config oldconfig \ 311endif # ifeq ($(skip-makefile),)
236 menuconfig tags check test depend
237 312
313.PHONY: dummy subdirs release distclean clean config oldconfig \
314 menuconfig tags check test depend buildtree
238 315