This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
120 lines (95 loc) · 3.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Build an Autoconf package
#
# Makefile targets:
#
# all/install build and install the package
# clean clean build products and intermediates
#
# Variables to override:
#
# MIX_COMPILE_PATH path to the build's ebin directory
#
# CC C compiler
# CROSSCOMPILE crosscompiler prefix, if any
# CFLAGS compiler flags for compiling all C files
# LDFLAGS linker flags for linking all binaries
BUSYBOX_VERSION = 1.31.1
TOP := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
SRC_TOP = $(TOP)/busybox-$(BUSYBOX_VERSION)
PREFIX = $(MIX_COMPILE_PATH)/../priv
BUILD = $(MIX_COMPILE_PATH)/../obj
GNU_TARGET_NAME = $(notdir $(CROSSCOMPILE))
GNU_HOST_NAME =
MAKE_ENV = KCONFIG_NOTIMESTAMP=1
MAKE_OPTS = CONFIG_PREFIX="$(PREFIX)"
PATCH_DIRS = $(TOP)/patches/common
ifneq ($(CROSSCOMPILE),)
MAKE_OPTS += CROSS_COMPILE="$(CROSSCOMPILE)-"
endif
ifeq ($(shell uname -s),Darwin)
# Fixes to build on OSX
MAKE = $(shell which gmake)
ifeq ($(MAKE),)
$(error gmake required to build. Install by running "brew install homebrew/core/make")
endif
SED = $(shell which gsed)
ifeq ($(SED),)
$(error gsed required to build. Install by running "brew install gnu-sed")
endif
MAKE_OPTS += SED=$(SED)
PATCH_DIRS += $(TOP)/patches/Darwin
ifeq ($(CROSSCOMPILE),)
$(warning Native OS compilation is not supported on OSX. Skipping compilation.)
# Do a fake install so that we can run some tests
TARGETS = fake_install
endif
endif
TARGETS ?= install
calling_from_make:
mix compile
all: $(TARGETS)
install: $(BUILD) $(PREFIX) $(BUILD)/.config $(TOP)/make_menuconfig
$(MAKE_ENV) $(MAKE) $(MAKE_OPTS) -C $(BUILD)
$(MAKE_ENV) $(MAKE) $(MAKE_OPTS) -C $(BUILD) install
$(TOP)/make_menuconfig: Makefile
# Simple script for running "make menuconfig"
printf "#!/bin/sh\n$(MAKE_ENV) $(MAKE) $(MAKE_OPTS) -C $(BUILD) menuconfig\ncp $(BUILD)/.config $(TOP)/busybox.config" > $(TOP)/make_menuconfig
fake_install: $(PREFIX)
# Fake some scripts to aide regression testing on platforms that can't
# compile Busybox
mkdir -p $(PREFIX)/bin $(PREFIX)/sbin $(PREFIX)/usr/bin $(PREFIX)/usr/sbin
printf "#!/bin/sh\nprintf \"BusyBox v$(BUSYBOX_VERSION) () multi-call binary.\\\n\"\n" > $(PREFIX)/bin/busybox
printf "#!/bin/sh\nexit 1\n" > $(PREFIX)/bin/false
printf "#!/bin/sh\nexit 1\n" > $(PREFIX)/sbin/udhcpc
printf "#!/bin/sh\nexit 1\n" > $(PREFIX)/sbin/udhcpd
printf '#!/bin/sh\n/usr/bin/touch "$$1"\n' > $(PREFIX)/usr/bin/touch
chmod +x $(PREFIX)/bin/busybox $(PREFIX)/bin/false \
$(PREFIX)/sbin/udhcpc $(PREFIX)/sbin/udhcpd \
$(PREFIX)/usr/bin/touch
# Initialize the build directory, but use our .config (use make oldconfig to fixup symbols)
$(BUILD)/.config: $(SRC_TOP)/.patched $(TOP)/busybox.config
$(MAKE_ENV) $(MAKE) -C $(BUILD) KBUILD_SRC=$(SRC_TOP) $(MAKE_OPTS) -f $(SRC_TOP)/Makefile defconfig
cp $(TOP)/busybox.config $(BUILD)/.config
yes | $(MAKE_ENV) $(MAKE) $(MAKE_OPTS) -C $(BUILD) oldconfig
$(PREFIX) $(BUILD):
mkdir -p $@
$(TOP)/busybox-$(BUSYBOX_VERSION).tar.bz2:
curl -L https://www.busybox.net/downloads/busybox-$(BUSYBOX_VERSION).tar.bz2 > $@
$(SRC_TOP)/.extracted: $(TOP)/busybox-$(BUSYBOX_VERSION).tar.bz2
sha256sum -c busybox.hash
tar xf $<
touch $(SRC_TOP)/.extracted
$(SRC_TOP)/.patched: $(SRC_TOP)/.extracted
cd $(SRC_TOP); \
for patchdir in $(PATCH_DIRS); do \
for patch in $$(ls $$patchdir); do \
patch -p1 < "$$patchdir/$$patch"; \
done; \
done
touch $(SRC_TOP)/.patched
clean:
if [ -n "$(MIX_COMPILE_PATH)" ]; then $(RM) -r $(BUILD); fi
$(RM) -r $(SRC_TOP)
distclean: clean
$(RM) $(TOP)/busybox-$(BUSYBOX_VERSION).tar.bz2
.PHONY: all clean distclean calling_from_make fake_install install