aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile122
1 files changed, 33 insertions, 89 deletions
diff --git a/Makefile b/Makefile
index fffc52466..7fcdd45e5 100644
--- a/Makefile
+++ b/Makefile
@@ -13,15 +13,16 @@ noconfig_targets := menuconfig config oldconfig randconfig \
13 clean distclean \ 13 clean distclean \
14 release tags 14 release tags
15 15
16# make-3.79.1 didn't support MAKEFILE_LIST
17# for building out-of-tree, users of make-3.79 still have to pass top_srcdir=
18# to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
19ifndef MAKEFILE_LIST
20MAKEFILE_LIST=.
21endif
22# the toplevel sourcedir 16# the toplevel sourcedir
23ifndef top_srcdir 17ifndef top_srcdir
18# make-3.79.1 didn't support MAKEFILE_LIST
19# for building out-of-tree, users of make-3.79.1 still have to pass top_srcdir=
20# to make: make -f /srcs/busybox/Makefile top_srcdir=/srcs/busybox
21ifdef MAKEFILE_LIST
24top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd) 22top_srcdir:=$(shell cd $(dir $(firstword $(MAKEFILE_LIST))) && pwd)
23else
24top_srcdir:=$(CURDIR)
25endif
25endif 26endif
26# toplevel directory of the object-tree 27# toplevel directory of the object-tree
27ifndef top_builddir 28ifndef top_builddir
@@ -63,44 +64,22 @@ else
63 PACKAGE_OUTPUTDIR := $(top_builddir) 64 PACKAGE_OUTPUTDIR := $(top_builddir)
64endif 65endif
65 66
66#######################################################################
67# Try to workaround bugs in make
68
69# make-3.79.1 didn't understand order-only prerequisites ('|').
70# Just treat them as normal prerequisites. Note that this will lead to
71# spurious rebuilds.
72ifeq ($(MAKE_VERSION),3.79.1)
73|: ;
74endif
75
76# Workaround for bugs in make-3.80
77# eval is broken if it is in a conditional
78
79#$ cat 3.80-eval-in-cond.mak
80#all:: ; @echo it
81#define Y
82# all:: ; @echo worked
83#endef
84#ifdef BAR
85#$(eval $(Y))
86#endif
87#$ make -f 3.80-eval-in-cond.mak
88#it
89#$ make -f 3.80-eval-in-cond.mak BAR=set
90#3.80-eval-in-cond.mak:5: *** missing `endif'. Stop.
91
92# This was fixed in December 2003.
93define check_gcc 67define check_gcc
94$(eval $(1)+=$(if $(2),$(if $(shell $(CC) $(2) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 && echo y),$(2),$(if $(3),$(3))),$(if $(3),$(3)))) 68$(if $(2),$(if $(shell $(CC) $(2) -S -o /dev/null -xc /dev/null > /dev/null 2>&1 && echo y),$(2),$(if $(3),$(3))),$(if $(3),$(3)))
95endef 69endef
96 70
97define check_ld 71define check_ld
98$(eval $(1)+=$(if $(2),$(if $(shell $(LD) $(2) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && echo y),$(shell echo \-Wl,$(2)),$(if $(3),$(3))),$(if $(3),$(3)))) 72$(if $(2),$(if $(shell $(LD) $(2) -o /dev/null -b binary /dev/null > /dev/null 2>&1 && echo y),$(shell echo \-Wl,$(2)),$(if $(3),$(3))),$(if $(3),$(3)))
99endef 73endef
100 74
101####################################################################### 75#######################################################################
76# make-3.79.1 doesn't support order-only prerequisites..
77ifeq ($(MAKE_VERSION),3.79.1)
78|: $(^) ;
79endif
80#######################################################################
81
102 82
103-include $(top_srcdir)/Rules.mak
104 83
105# Handle building out of tree 84# Handle building out of tree
106ifneq ($(top_builddir),$(top_srcdir)) 85ifneq ($(top_builddir),$(top_srcdir))
@@ -179,6 +158,8 @@ help:
179 @echo ' 2 also print when make enters a directory' 158 @echo ' 2 also print when make enters a directory'
180 @echo ' 3 also verbosely print shell invocations' 159 @echo ' 3 also verbosely print shell invocations'
181 160
161-include $(top_srcdir)/Rules.mak
162
182ifneq ($(strip $(HAVE_DOT_CONFIG)),y) 163ifneq ($(strip $(HAVE_DOT_CONFIG)),y)
183# Default target if none was requested explicitly 164# Default target if none was requested explicitly
184all: defconfig menuconfig ; 165all: defconfig menuconfig ;
@@ -252,33 +233,8 @@ ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
252 233
253endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y) 234endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
254 235
255# convert $(DIRS) to upper case. Use sed instead of tr since we're already
256# depending on it.
257DIRS_UPPER:=$(shell echo $(DIRS) | $(SED) 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
258
259# First populate the variables ..._OBJ-y et al
260$(foreach d,$(DIRS_UPPER),$(eval $(notdir $(d))-y:=))
261
262include $(patsubst %,%/Makefile.in,$(SRC_DIRS)) 236include $(patsubst %,%/Makefile.in,$(SRC_DIRS))
263 237
264# Then we need the dependencies for ..._OBJ
265define dir_pattern.o
266ifeq ($(os),.os)
267$(if $($(1)_OBJ.os),$($(1)_OBJ.os:.os=.o): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
268endif
269$(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
270$(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
271endef
272
273# The actual directory patterns for .o*
274$(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
275
276define file_lists
277$($(1)$(2)) $($(1)$(2).o) $($(1)$(2).os)
278endef
279bin-obj-y:=$(subst .os,.o,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_OBJ)))
280bin-mobj-y:=$(subst .osm,.om,$(foreach d,$(DIRS),$(call file_lists,$(subst /,_,$(d)),_MOBJ)))
281
282ifeq ($(strip $(HAVE_DOT_CONFIG)),y) 238ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
283# Finally pull in the dependencies (headers and other includes) of the 239# Finally pull in the dependencies (headers and other includes) of the
284# individual object files 240# individual object files
@@ -294,9 +250,7 @@ all: busybox busybox.links doc ;
294# IMA compiles all sources at once (aka IPO aka IPA etc.) 250# IMA compiles all sources at once (aka IPO aka IPA etc.)
295 251
296ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y) 252ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
297# We are not building .o 253libraries-y:=
298bin-obj-y:=
299bin-mobj-y:=
300# Which parts of the internal libs are requested? 254# Which parts of the internal libs are requested?
301# Per default we only want what was actually selected. 255# Per default we only want what was actually selected.
302# -a denotes all while -y denotes the selected ones. 256# -a denotes all while -y denotes the selected ones.
@@ -312,30 +266,17 @@ APPLETS_DEFINE:=$(APPLETS_DEFINE-y)
312else # CONFIG_BUILD_AT_ONCE 266else # CONFIG_BUILD_AT_ONCE
313# no --combine, build archives out of the individual .o 267# no --combine, build archives out of the individual .o
314# This was the old way the binary was built. 268# This was the old way the binary was built.
315libbusybox-obj:=$(archival_libunarchive_OBJ$(os)) \ 269libbusybox-obj:=archival/libunarchive/libunarchive.a \
316 $(networking_libiproute_OBJ$(os)) \ 270 networking/libiproute/libiproute.a \
317 $(libpwdgrp_MOBJ$(os)) \ 271 libpwdgrp/libpwdgrp.a coreutils/libcoreutils/libcoreutils.a \
318 $(coreutils_libcoreutils_OBJ$(os)) \ 272 libbb/libbb.a
319 $(libbb_OBJ$(os)) $(libbb_MOBJ$(os)) 273libbusybox-obj:=$(patsubst %,$(top_builddir)/%,$(libbusybox-obj))
320
321ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y) 274ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
322# linking against libbusybox, so don't build the .o already contained in the .so 275# linking against libbusybox, so don't build the .a already contained in the .so
323bin-obj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.os=.o),$(bin-obj-y)) 276libraries-y:=$(filter-out $(libbusybox-obj),$(libraries-y))
324bin-mobj-y:=$(filter-out $(libbusybox-obj) $(libbusybox-obj:.osm=.om),$(bin-mobj-y))
325endif # CONFIG_FEATURE_SHARED_BUSYBOX 277endif # CONFIG_FEATURE_SHARED_BUSYBOX
326endif # CONFIG_BUILD_AT_ONCE
327
328# build an .a to keep .hash et al small
329ifneq ($(bin-obj-y)$(bin-mobj-y),)
330 applets.a:=$(bin-obj-y) $(bin-mobj-y)
331endif
332ifdef applets.a
333applets.a: $(applets.a)
334 $(Q)-rm -f $(@)
335 $(do_ar)
336 278
337bin-obj.a=applets.a 279endif # CONFIG_BUILD_AT_ONCE
338endif
339 280
340ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y) 281ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
341LD_LIBBUSYBOX:=libbusybox.so 282LD_LIBBUSYBOX:=libbusybox.so
@@ -355,6 +296,8 @@ endif # !CONFIG_FEATURE_SHARED_BUSYBOX
355$(LIBBUSYBOX_SONAME): $(LIBRARY_SRC) 296$(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
356else # CONFIG_BUILD_AT_ONCE 297else # CONFIG_BUILD_AT_ONCE
357$(LIBBUSYBOX_SONAME): $(libbusybox-obj) 298$(LIBBUSYBOX_SONAME): $(libbusybox-obj)
299AR_INTRO:=-Wl,--whole-archive
300AR_EXTRO:=-Wl,--no-whole-archive
358endif # CONFIG_BUILD_AT_ONCE 301endif # CONFIG_BUILD_AT_ONCE
359 302
360 303
@@ -367,12 +310,12 @@ $(LIBBUSYBOX_SONAME):
367ifndef MAJOR_VERSION 310ifndef MAJOR_VERSION
368 $(error MAJOR_VERSION needed for $@ is not defined) 311 $(error MAJOR_VERSION needed for $@ is not defined)
369endif 312endif
370 $(do_link) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(CFLAGS_COMBINE) \ 313 $(do_link) $(LIB_CFLAGS) $(CFLAGS_COMBINE) \
371 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \ 314 -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
372 -Wl,-z,combreloc $(LIB_LDFLAGS) \ 315 -Wl,-z,combreloc $(LIB_LDFLAGS) \
373 -o $(@) \ 316 -o $(@) \
374 -Wl,--start-group \ 317 -Wl,--start-group \
375 $(LIBRARY_DEFINE) $(^) \ 318 $(LIBRARY_DEFINE) $(AR_INTRO) $(^) $(AR_EXTRO) \
376 -Wl,--end-group 319 -Wl,--end-group
377 @rm -f $(DO_INSTALL_LIBS) 320 @rm -f $(DO_INSTALL_LIBS)
378 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done 321 @for i in $(DO_INSTALL_LIBS); do ln -s $(@) $$i ; done
@@ -380,14 +323,14 @@ endif
380 323
381endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y) 324endif # ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
382 325
383busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(bin-obj.a) 326busybox_unstripped: $(top_builddir)/.depend $(LIBBUSYBOX_SONAME) $(BUSYBOX_SRC) $(APPLET_SRC) $(libraries-y)
384 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \ 327 $(do_link) $(PROG_CFLAGS) $(PROG_LDFLAGS) $(CFLAGS_COMBINE) \
385 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \ 328 $(foreach f,$(^:.o=.c),$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
386 $(CFLAGS-$(@)) \ 329 $(CFLAGS-$(@)) \
387 -o $@ -Wl,--start-group \ 330 -o $@ -Wl,--start-group \
388 $(APPLETS_DEFINE) $(APPLET_SRC) \ 331 $(APPLETS_DEFINE) $(APPLET_SRC) \
389 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \ 332 $(BUSYBOX_DEFINE) $(BUSYBOX_SRC) \
390 $(bin-obj.a) \ 333 $(libraries-y) \
391 $(LDBUSYBOX) $(LIBRARIES) \ 334 $(LDBUSYBOX) $(LIBRARIES) \
392 -Wl,--end-group 335 -Wl,--end-group
393 336
@@ -538,3 +481,4 @@ tags:
538 defconfig allyesconfig allnoconfig allbareconfig \ 481 defconfig allyesconfig allnoconfig allbareconfig \
539 clean distclean \ 482 clean distclean \
540 release tags 483 release tags
484