forked from linusyang/android-busybox-ndk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
117 lines (99 loc) · 4.26 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
# Makefile for android-busybox-ndk
# fetches upstream busybox from git, applies patches, builds it
# Point to your android-ndk installation
ANDROID_NDK=$(PWD)/../ndk
# Pick your target ARCH (arm,mips,x86)
ARCH=arm
# Config to use
#CONFIG_FILE="./android_ndk_stericson-like"
CONFIG_FILE="./android_ndk_config-w-patches" # contains more
# Following options should not be changed unless you know better
BB_DIR="busybox-git.$(ARCH)"
SYSROOT=$(ANDROID_NDK)/platforms/android-9/arch-$(ARCH)
#
# ARM SETUP
#
ifeq ($(ARCH),arm)
GCC_PREFIX="$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-"
EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv5te -msoft-float -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers"
EXTRA_LDFLAGS="-static -Xlinker -z -Xlinker muldefs -nostdlib ${SYSROOT}/usr/lib/crtbegin_static.o ${SYSROOT}/usr/lib/crtend_android.o -L${SYSROOT}/usr/lib"
EXTRA_LDLIBS="m c gcc"
endif
#
# MIPS SETUP
# NOTE: MIPS_SIM_NABI32 is a 64bit ABI; Android uses MIPS_SIM_ABI32
#
ifeq ($(ARCH),mips)
GCC_PREFIX="$(ANDROID_NDK)/toolchains/mipsel-linux-android-4.4.3/prebuilt/linux-x86/bin/mipsel-linux-android-"
EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -fpic -fno-short-enums -fgcse-after-reload -frename-registers -U_MIPS_SIM -D_MIPS_SIM=_MIPS_SIM_ABI32"
EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o"
endif
#
# X86 SETUP
#
ifeq ($(ARCH),x86)
GCC_PREFIX="$(ANDROID_NDK)/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-"
EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -fpic -fno-short-enums -fgcse-after-reload -frename-registers -Dhtons=__swap16 -Dhtonl=__swap32 -Dntohs=__swap16 -Dntohl=__swap32 -D_XOPEN_SOURCE -D_POSIX_C_SOURCE"
EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o"
endif
all: busybox-git config patches build
busybox-git:
if test -d $(BB_DIR); then \
echo "'$(BB_DIR)' already exists"; \
else \
echo "Fetching fresh busybox source"; \
git clone git://git.busybox.net/busybox $(BB_DIR); \
cd $(BB_DIR); \
git checkout remotes/origin/1_21_stable; \
cd ..; \
echo "Last tested revision: 1.21.1"; \
fi
config:
if test ! -f $(CONFIG_FILE); then \
echo "Error: config file '$(CONFIG_FILE)' does not exist!" \
exit 1; \
fi
patches:
if test -f $(BB_DIR)/android-busybox-ndk-patched; then \
echo "Busybox already patched"; \
else \
echo "Applying patches"; \
for i in patches/*.patch; do \
patch -d $(BB_DIR) --forward -p1 < $$i; \
done; \
touch "$(BB_DIR)/android-busybox-ndk-patched"; \
fi
@echo "EXPORT CONFIG_FILE=$(CONFIG_FILE)"
@echo "EXPORT GCC_PREFIX=$(GCC_PREFIX)"
@echo "EXPORT SYSROOT=$(SYSROOT)"
@echo "EXPORT EXTRA_CFLAGS=$(EXTRA_CFLAGS)"
@echo "EXPORT EXTRA_LDFLAGS=$(EXTRA_LDFLAGS)"
@echo "EXPORT EXTRA_LDLIBS=$(EXTRA_LDLIBS)"
cat $(CONFIG_FILE) | \
sed 's:\(CONFIG_CROSS_COMPILER_PREFIX=\).*:\1$(GCC_PREFIX):' | \
sed 's:\(CONFIG_SYSROOT=\).*:\1\"$(SYSROOT)\":' | \
sed 's:\(CONFIG_EXTRA_CFLAGS=\).*:\1$(EXTRA_CFLAGS):' | \
sed 's:\(CONFIG_EXTRA_LDFLAGS=\).*:\1$(EXTRA_LDFLAGS):' | \
sed 's:\(CONFIG_EXTRA_LDLIBS=\).*:\1$(EXTRA_LDLIBS):' \
> $(BB_DIR)/.config
build-check:
if test ! -d $(ANDROID_NDK); then \
echo "Error: edit 'Makefile' and point 'ANDROID_NDK=' to your android ndk installation\n(currently: $(ANDROID_NDK))"; exit 1; \
fi
if test ! -d $(SYSROOT); then \
echo "Error: can not find 'android' platform in '$(SYSROOT)', did you install it?"; exit 1; \
fi
if test ! -f $(GCC_PREFIX)gcc; then \
echo "Error: can not find crosscompiler with prefix $(GCC_PREFIX), did you install it?"; exit 1; \
fi
build: build-check
make -C $(BB_DIR)
echo "Busybox binary at '$(BB_DIR)/busybox'"
clean:
make -C $(BB_DIR) clean
# undo patches
cd $(BB_DIR) && git checkout . && git clean -f -d
dist-clean: distclean
distclean:
rm -Rf $(BB_DIR)
.PHONY: busybox-git patches