1# This is completely unsupported.
2#
3# Uasge: make -f scripts/Makefile.IMA
4#
5# Fix COMBINED_COMPILE upstream (in the Kbuild) and propagate
6# the changes back
7srctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
8objtree		:= $(CURDIR)
9src		:= $(srctree)
10obj		:= $(objtree)
11
12# Make generated files
13DUMMY := $(shell $(Q)$(srctree)/scripts/gen_build_files.sh $(srctree) $(objtree) >&2)
14
15# Look for make include files relative to root of src
16MAKEFLAGS += --include-dir=$(srctree)
17
18default: busybox
19
20include .config
21
22# Cross compiling and selecting different set of gcc/bin-utils
23ifeq ($(CROSS_COMPILE),)
24CROSS_COMPILE := $(subst ",,$(CONFIG_CROSS_COMPILER_PREFIX))
25endif
26
27ifneq ($(CROSS_COMPILE),)
28SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1)
29else
30SUBARCH := $(shell uname -m)
31endif
32SUBARCH := $(shell echo $(SUBARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
33                                         -e s/arm.*/arm/ -e s/sa110/arm/ \
34                                         -e s/s390x/s390/ -e s/parisc64/parisc/ \
35                                         -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
36ARCH ?= $(SUBARCH)
37
38ifndef HOSTCC
39HOSTCC = cc
40endif
41AS              = $(CROSS_COMPILE)as
42CC              = $(CROSS_COMPILE)gcc
43LD              = $(CC) -nostdlib
44CPP             = $(CC) -E
45AR              = $(CROSS_COMPILE)ar
46NM              = $(CROSS_COMPILE)nm
47STRIP           = $(CROSS_COMPILE)strip
48OBJCOPY         = $(CROSS_COMPILE)objcopy
49OBJDUMP         = $(CROSS_COMPILE)objdump
50
51CFLAGS   := $(CFLAGS)
52
53# We need some generic definitions
54include $(srctree)/scripts/Kbuild.include
55
56include Makefile.flags
57
58-include $(srctree)/arch/$(ARCH)/Makefile
59ifdef CONFIG_FEATURE_COMPRESS_USAGE
60usage_stuff = include/usage_compressed.h
61endif
62
63ifndef BB_VER
64BB_VER:=""
65endif
66
67WHOLE_PROGRAM:=$(call cc-option,-fwhole-program,)
68
69# pull in the config stuff
70lib-all-y := applets/applets.o
71lib-y:=
72include procps/Kbuild
73lib-all-y += $(patsubst %,procps/%,$(sort $(lib-y)))
74lib-y:=
75include networking/Kbuild
76lib-all-y += $(patsubst %,networking/%,$(sort $(lib-y)))
77lib-y:=
78include networking/udhcp/Kbuild
79lib-all-y += $(patsubst %,networking/udhcp/%,$(sort $(lib-y)))
80lib-y:=
81include networking/libiproute/Kbuild
82lib-all-y += $(patsubst %,networking/libiproute/%,$(sort $(lib-y)))
83lib-y:=
84include loginutils/Kbuild
85lib-all-y += $(patsubst %,loginutils/%,$(sort $(lib-y)))
86lib-y:=
87include archival/Kbuild
88lib-all-y += $(patsubst %,archival/%,$(sort $(lib-y)))
89lib-y:=
90include archival/libarchive/Kbuild
91lib-all-y += $(patsubst %,archival/libarchive/%,$(sort $(lib-y)))
92lib-y:=
93include applets/Kbuild
94lib-all-y += $(patsubst %,applets/%,$(sort $(lib-y)))
95lib-y:=
96include e2fsprogs/Kbuild
97lib-all-y += $(patsubst %,e2fsprogs/%,$(sort $(lib-y)))
98lib-y:=
99#include e2fsprogs/old_e2fsprogs/Kbuild
100#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/%,$(sort $(lib-y)))
101#lib-y:=
102#include e2fsprogs/old_e2fsprogs/ext2fs/Kbuild
103#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/ext2fs/%,$(sort $(lib-y)))
104#lib-y:=
105#include e2fsprogs/old_e2fsprogs/blkid/Kbuild
106#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/blkid/%,$(sort $(lib-y)))
107#lib-y:=
108#include e2fsprogs/old_e2fsprogs/uuid/Kbuild
109#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/uuid/%,$(sort $(lib-y)))
110#lib-y:=
111#include e2fsprogs/old_e2fsprogs/e2p/Kbuild
112#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/e2p/%,$(sort $(lib-y)))
113#lib-y:=
114include debianutils/Kbuild
115lib-all-y += $(patsubst %,debianutils/%,$(sort $(lib-y)))
116lib-y:=
117include klibc-utils/Kbuild
118lib-all-y += $(patsubst %,klibc-utils/%,$(sort $(lib-y)))
119lib-y:=
120include runit/Kbuild
121lib-all-y += $(patsubst %,runit/%,$(sort $(lib-y)))
122lib-y:=
123include modutils/Kbuild
124lib-all-y += $(patsubst %,modutils/%,$(sort $(lib-y)))
125lib-y:=
126include miscutils/Kbuild
127lib-all-y += $(patsubst %,miscutils/%,$(sort $(lib-y)))
128lib-y:=
129include mailutils/Kbuild
130lib-all-y += $(patsubst %,mailutils/%,$(sort $(lib-y)))
131lib-y:=
132include coreutils/libcoreutils/Kbuild
133lib-all-y += $(patsubst %,coreutils/libcoreutils/%,$(sort $(lib-y)))
134lib-y:=
135include coreutils/Kbuild
136lib-all-y += $(patsubst %,coreutils/%,$(sort $(lib-y)))
137lib-y:=
138include sysklogd/Kbuild
139lib-all-y += $(patsubst %,sysklogd/%,$(sort $(lib-y)))
140lib-y:=
141include shell/Kbuild
142lib-all-y += $(patsubst %,shell/%,$(sort $(lib-y)))
143lib-y:=
144include console-tools/Kbuild
145lib-all-y += $(patsubst %,console-tools/%,$(sort $(lib-y)))
146lib-y:=
147include findutils/Kbuild
148lib-all-y += $(patsubst %,findutils/%,$(sort $(lib-y)))
149lib-y:=
150include util-linux/Kbuild
151lib-all-y += $(patsubst %,util-linux/%,$(sort $(lib-y)))
152lib-y:=
153include util-linux/volume_id/Kbuild
154lib-all-y += $(patsubst %,util-linux/volume_id/%,$(sort $(lib-y)))
155lib-y:=
156include init/Kbuild
157lib-all-y += $(patsubst %,init/%,$(sort $(lib-y)))
158lib-y:=
159include libpwdgrp/Kbuild
160lib-all-y += $(patsubst %,libpwdgrp/%,$(sort $(lib-y)))
161lib-y:=
162include editors/Kbuild
163lib-all-y += $(patsubst %,editors/%,$(sort $(lib-y)))
164lib-y:=
165include printutils/Kbuild
166lib-all-y += $(patsubst %,printutils/%,$(sort $(lib-y)))
167lib-y:=
168include selinux/Kbuild
169lib-all-y += $(patsubst %,selinux/%,$(sort $(lib-y)))
170lib-y:=
171include scripts/Kbuild
172lib-all-y += $(patsubst %,scripts/%,$(sort $(lib-y)))
173lib-y:=
174include libbb/Kbuild
175lib-all-y += $(patsubst %,libbb/%,$(sort $(lib-y)))
176lib-y:=
177
178comma:=,
179busybox_unstripped.o: $(usage_stuff) include/applet_tables.h include/NUM_APPLETS.h include/autoconf.h
180	$(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) \
181		$(patsubst %,-Wl$(comma)%,$(LDFLAGS) $(EXTRA_LDFLAGS)) \
182		-DGCC_COMBINE=1 \
183		--combine $(WHOLE_PROGRAM) \
184		-funit-at-a-time -Wno-error -std=gnu99  \
185		-c -o busybox_unstripped.o \
186		$(lib-all-y:.o=.c)
187
188busybox: busybox_unstripped.o
189	$(srctree)/scripts/trylink \
190		busybox_unstripped \
191		"$(CC) $(CFLAGS_busybox)" \
192		"$(CFLAGS)" \
193		"$(LDFLAGS)" \
194		"busybox_unstripped.o" \
195		"" \
196		"crypt m"
197	cp -f $(@)_unstripped $@
198	-$(STRIP) -s -R .note -R .comment -R .version $@
199
200# If .config is newer than include/autoconf.h, someone tinkered
201# with it and forgot to run make oldconfig.
202include/autoconf.h: .config
203	$(MAKE) -f $(srctree)/Makefile silentoldconfig
204
205# Override rules for host compile
206applets/usage: include/autoconf.h
207	$(HOSTCC) -Wall -O2 -I$(srctree)/include -o applets/usage applets/usage.c
208
209applets/applet_tables: include/autoconf.h
210	$(HOSTCC) -Wall -O2 -I$(srctree)/include -o applets/applet_tables applets/applet_tables.c
211