Add scripts, patches, and Makefiles

This commit is contained in:
topjohnwu 2017-07-29 18:52:59 +08:00
parent c0de43aabf
commit a707fede86
6 changed files with 512 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
busybox
libs
obj
patch

19
busybox.mk Normal file
View File

@ -0,0 +1,19 @@
LOCAL_PATH := $(call my-dir)
VERSION = 1
PATCHLEVEL = 27
SUBLEVEL = 1
EXTRAVERSION = -topjohnwu
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
include $(CLEAR_VARS)
LOCAL_MODULE := busybox
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(LOCAL_PATH)/Android_src.mk
LOCAL_LDFLAGS := -static
LOCAL_CFLAGS := -w -DBB_VER=\"$(BB_VER)\" -DBB_BT=AUTOCONF_TIMESTAMP
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
include $(BUILD_EXECUTABLE)

3
jni/Android.mk Normal file
View File

@ -0,0 +1,3 @@
# Dummy file, actually calls the external busybox makefile
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/../busybox/Android.mk

3
jni/Application.mk Normal file
View File

@ -0,0 +1,3 @@
# APP_ABI := x86 x86_64 armeabi-v7a arm64-v8a
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-21

302
ndk_build.patch Normal file
View File

@ -0,0 +1,302 @@
Author: topjohnwu <topjohnwu@gmail.com>
Date: Sat Jul 29 00:41:40 2017 +0800
Apply patches for ndk-build to work properly
diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src
index 942e755b9..3b2df892c 100644
--- a/archival/libarchive/Kbuild.src
+++ b/archival/libarchive/Kbuild.src
@@ -27,16 +27,7 @@ COMMON_FILES:= \
find_list_entry.o \
init_handle.o
-DPKG_FILES:= \
- unpack_ar_archive.o \
- filter_accept_list_reassign.o \
- unsafe_prefix.o \
- get_header_ar.o \
- get_header_tar.o \
- get_header_tar_gz.o \
- get_header_tar_bz2.o \
- get_header_tar_lzma.o \
- get_header_tar_xz.o \
+DPKG_FILES:=
INSERT
diff --git a/coreutils/nl.c b/coreutils/nl.c
index 5c64923bb..dc468a90b 100644
--- a/coreutils/nl.c
+++ b/coreutils/nl.c
@@ -35,26 +35,6 @@
#include "libbb.h"
-void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename)
-{
- FILE *fp = fopen_or_warn_stdin(filename);
- unsigned N = ns->start;
- char *line;
-
- while ((line = xmalloc_fgetline(fp)) != NULL) {
- if (ns->all
- || (ns->nonempty && line[0])
- ) {
- printf("%*u%s%s\n", ns->width, N, ns->sep, line);
- N += ns->inc;
- } else if (ns->empty_str)
- fputs(ns->empty_str, stdout);
- free(line);
- }
-
- fclose(fp);
-}
-
int nl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nl_main(int argc UNUSED_PARAM, char **argv)
{
diff --git a/include/libbb.h b/include/libbb.h
index 57b74a0c4..e378e0512 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -10,6 +10,7 @@
#ifndef LIBBB_H
#define LIBBB_H 1
+#include "autoconf.h"
#include "platform.h"
#include <ctype.h>
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 80f4cc060..ab4cbb504 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -7,10 +7,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
+#include "libbb.h"
#if ENABLE_LONG_OPTS || ENABLE_FEATURE_GETOPT_LONG
# include <getopt.h>
#endif
-#include "libbb.h"
/* Documentation
diff --git a/libbb/semctl.c b/libbb/semctl.c
index 5ddd07f3c..84ab1c92e 100644
--- a/libbb/semctl.c
+++ b/libbb/semctl.c
@@ -24,7 +24,7 @@
#include <sys/syscall.h> /* For __NR_xxx definitions */
#include <stdarg.h>
-#include <linux/sem.h>
+#include <sys/sem.h>
#include "libbb.h"
#ifndef __NR_semctl
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
index d7d691772..412546c5d 100644
--- a/networking/ether-wake.c
+++ b/networking/ether-wake.c
@@ -88,6 +88,7 @@
#include <netpacket/packet.h>
#include <netinet/ether.h>
#include <linux/if.h>
+#include <net/ethernet.h>
/* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to
* work as non-root, but we need SOCK_PACKET to specify the Ethernet
@@ -131,7 +132,7 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
eap = ether_aton_r(hostid, eaddr);
if (eap) {
bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap));
-#if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
+#if !defined(__BIONIC__) && !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
} else if (ether_hostton(hostid, eaddr) == 0) {
bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr));
#endif
diff --git a/networking/libiproute/ip_common.h b/networking/libiproute/ip_common.h
index 40171bed9..055520208 100644
--- a/networking/libiproute/ip_common.h
+++ b/networking/libiproute/ip_common.h
@@ -6,6 +6,7 @@
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
+#include <linux/if_ether.h>
#if !defined IFA_RTA
#include <linux/if_addr.h>
#endif
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c
index 4c32ae574..a3f443aee 100644
--- a/networking/libiproute/ll_proto.c
+++ b/networking/libiproute/ll_proto.c
@@ -13,6 +13,7 @@
#include "utils.h"
#include <netinet/if_ether.h>
+#include <linux/if_ether.h>
/* Please conditionalize exotic protocols on CONFIG_something */
diff --git a/networking/tls.h b/networking/tls.h
index d487f3810..8399070ec 100644
--- a/networking/tls.h
+++ b/networking/tls.h
@@ -26,7 +26,7 @@
#undef USE_SEED
/* pstm: multiprecision numbers */
#undef DISABLE_PSTM
-#if defined(__GNUC__) && defined(__i386__)
+#if defined(__GNUC__) && defined(__i386__) && !defined(__ANDROID__)
/* PSTM_X86 works correctly. +25 bytes. */
# define PSTM_32BIT
# define PSTM_X86
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 6817861ef..fb6712d2a 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -299,12 +299,15 @@
#define TRACEROUTE_SO_DEBUG 0
+#include "libbb.h"
+
#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
+#include <net/ethernet.h>
#if ENABLE_FEATURE_IPV6
# include <netinet/ip6.h>
# include <netinet/icmp6.h>
@@ -313,7 +316,6 @@
# endif
#endif
-#include "libbb.h"
#include "inet_common.h"
#ifndef IPPROTO_ICMP
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h
index b8f96b029..0c98a206d 100644
--- a/networking/udhcp/dhcpd.h
+++ b/networking/udhcp/dhcpd.h
@@ -5,6 +5,8 @@
#ifndef UDHCP_DHCPD_H
#define UDHCP_DHCPD_H 1
+#include <net/ethernet.h>
+
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
/* Defaults you may want to tweak */
diff --git a/networking/zcip.c b/networking/zcip.c
index 06220346c..98c4b66e9 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -61,6 +61,7 @@
#include <net/if.h>
#include <net/if_arp.h>
#include <linux/sockios.h>
+#include <net/ethernet.h>
#include "struct-etherarp.h"
#include <syslog.h>
diff --git a/shell/glob.h b/shell/glob.h
index e8e65786d..cf22bb095 100644
--- a/shell/glob.h
+++ b/shell/glob.h
@@ -47,11 +47,6 @@
#include <sys/cdefs.h>
//#include <sys/_types.h>
-#ifndef _SIZE_T_DECLARED
-typedef __size_t size_t;
-#define _SIZE_T_DECLARED
-#endif
-
struct stat;
typedef struct {
size_t gl_pathc; /* Count of total paths so far. */
@@ -74,7 +69,6 @@ typedef struct {
int (*gl_stat)(const char *, struct stat *);
} glob_t;
-#if __POSIX_VISIBLE >= 199209
/* Believed to have been introduced in 1003.2-1992 */
#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
@@ -89,9 +83,7 @@ typedef struct {
#define GLOB_ABORTED (-2) /* Unignored error. */
#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */
#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */
-#endif /* __POSIX_VISIBLE >= 199209 */
-#if __BSD_VISIBLE
#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
@@ -103,7 +95,6 @@ typedef struct {
/* source compatibility, these are the old names */
#define GLOB_MAXPATH GLOB_LIMIT
#define GLOB_ABEND GLOB_ABORTED
-#endif /* __BSD_VISIBLE */
__BEGIN_DECLS
int glob(const char *, int, int (*)(const char *, int), glob_t *);
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index 79d54854b..9aa7089f8 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -121,10 +121,10 @@
//usage: " esac\n"
//usage: "done\n"
+#include "libbb.h"
#if ENABLE_FEATURE_GETOPT_LONG
# include <getopt.h>
#endif
-#include "libbb.h"
/* NON_OPT is the code that is returned when a non-option is found in '+'
mode */
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c
index 2b4f3b094..bd33882b2 100644
--- a/util-linux/ipcrm.c
+++ b/util-linux/ipcrm.c
@@ -33,9 +33,9 @@
/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
#include <sys/ipc.h>
-#include <linux/shm.h>
-#include <linux/msg.h>
-#include <linux/sem.h>
+#include <sys/shm.h>
+#include <sys/msg.h>
+#include <sys/sem.h>
#if (defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)) || \
defined(__ANDROID__)
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c
index 121f661f0..3bd0bd3b5 100644
--- a/util-linux/ipcs.c
+++ b/util-linux/ipcs.c
@@ -40,9 +40,9 @@
/* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
#include <sys/types.h>
#include <sys/ipc.h>
-#include <linux/sem.h>
-#include <linux/msg.h>
-#include <linux/shm.h>
+#include <sys/sem.h>
+#include <sys/msg.h>
+#include <sys/shm.h>
#include "libbb.h"

181
ndk_busybox_kitchen.sh Executable file
View File

@ -0,0 +1,181 @@
#!/usr/bin/env bash
##################################################
#
# NDK Busybox Kitchen
# by @topjohnwu
#
##################################################
BBPATH=busybox
PATCHPATH=patch
COMMIT=false
CLEAN=false
UPDATE=false
GENERATE=false
BRANCH=1_27_stable
CONFIG=$PATCHPATH/osm0sis-full-64.config
usage() {
echo "NDK BusyBox Kitchen - Auto Generate Files for ndk-build BusyBox"
echo ""
echo "Download BusyBox and apply patches for NDK, fetch the correct config,"
echo "then finally generate all header files and Android.mk for NDK building"
echo "Once all tasks are finished, simply call \"ndk-build\" to build busybox"
echo ""
echo "$0 [OPTIONS] [ACTION] [BRANCH]"
echo ""
echo "Options:"
echo " -h Show this help message"
echo " -c <file> Use provided file as config instead of default"
echo " --commit Commit all the changes to branch \"android-ndk\""
echo ""
echo "Actions:"
echo " --cleanup Remove everything and start from scratch"
echo " --update Update current repos from upstream"
echo " --generate Generate proper headers and Android.mk"
echo ""
echo "For the first two actions, the busybox repo will be checked-out to [BRANCH]"
echo "If [BRANCH] is not specified, the default branch is \"$BRANCH\""
echo ""
exit
}
progress() {
echo -e "\n\033[44m${1}\033[0m\n"
}
parse_kbuild() {
for KBUILD in `find . -type f -name Kbuild`; do
DIR=${KBUILD#./}
DIR=${DIR%/*}
cat $KBUILD | grep '^[^#].*\.o\b' | while read LINE; do
FILE_LIST=${LINE#*+=}
CONFIG=`echo ${LINE%+=*} | grep -o '$(.*)' | cut -d\( -f2 | cut -d\) -f1`
eval [ -z \"$CONFIG\" -o \"\$$CONFIG\" = \"1\" ] && INCL=true || INCL=false
if $INCL; then
for FILE in `echo $FILE_LIST | grep -o '\b[a-zA-Z0-9_\-]*\.o\b'`; do
echo $DIR/$FILE | sed 's/.o$/.c \\/g'
done
fi
done
done
}
# Commandline parsing
until [ $# -eq 0 ]; do
if [ $1 = "-h" ]; then usage;
elif [ $1 = "-c" ]; then shift; CONFIG=$1;
elif [ $1 = "--commit" ]; then COMMIT=true;
elif [ $1 = "--clean" ]; then CLEAN=true;
elif [ $1 = "--update" ]; then UPDATE=true;
elif [ $1 = "--generate" ]; then GENERATE=true;
else BRANCH=$1; fi
shift
done
$CLEAN || $UPDATE || $GENERATE || usage
# Wiping out current folders
$CLEAN && rm -rf $BBPATH $PATCHPATH 2>/dev/null
if [ ! -d $BBPATH ]; then
progress "Downloading BusyBox source"
git clone git://busybox.net/busybox.git $BBPATH
UPDATE=true
fi
if [ ! -d $PATCHPATH ]; then
progress "Downloading patches from osm0sis/android-busybox-ndk"
git clone https://github.com/osm0sis/android-busybox-ndk.git $PATCHPATH
UPDATE=true
fi
if $UPDATE; then
progress "Updating sources from git"
# Patches
cd $PATCHPATH
git reset --hard && git clean -dfx
git pull
# BusyBox
cd ../$BBPATH
git reset --hard && git clean -dfx
git fetch
git checkout $BRANCH
git pull
if $COMMIT; then
# New branch
git branch -D android-ndk 2>/dev/null
git checkout -b android-ndk
fi
# Run patches from osm0sis's repo
progress "Applying patches from osm0sis/android-busybox-ndk"
for p in `head -n1 ../$PATCHPATH/osm0sis-full-64.config | grep -o 'patches .*$' | cut -c9- | sed -e 's/,//g' -e 's/*//g'`; do
for k in ../$PATCHPATH/patches/$p*.patch; do
# Exclude some patches
echo $k | grep -E "000|001|002|012-a|012-c" >/dev/null 2>&1 && continue
echo -e "\033[44mPatching with ${k##*/}\033[0m"
patch -p1 -i $k
done
done
if $COMMIT; then
# A commit for osm0sis patches
sleep 1
git add .
git commit -m "Apply patches from osm0sis/android-busybox-ndk"
fi
progress "Applying patches for ndk-build to work properly"
patch -p1 -i ../ndk_build.patch
if $COMMIT; then
# A commit for ndk-build patches
sleep 1
git add .
git commit -m "Apply patches for ndk-build to work properly"
fi
find . \( -type f -name "*.orig" -o -name "*.reg" \) -exec rm -f {} \;
cd ../
GENERATE=true
fi
if $GENERATE; then
# Copy config and make config
progress "Generating configuration files"
cp $CONFIG $BBPATH/.config
cd $BBPATH
yes n | make oldconfig 2>/dev/null
# Generate headers
gcc applets/applet_tables.c -o applets/applet_tables
applets/applet_tables include/applet_tables.h include/NUM_APPLETS.h
gcc applets/usage.c -o applets/usage -Iinclude
applets/usage_compressed include/usage_compressed.h applets
scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
scripts/generate_BUFSIZ.sh include/common_bufsiz.h
progress "Generating Android_src.mk based on configs"
# Load config into shell variables
eval `grep -o 'CONFIG[_A-Z0-9]* 1' include/autoconf.h | sed 's/ 1/=1/g'`
# Process Kbuild files
echo "LOCAL_SRC_FILES := \\" > Android_src.mk
parse_kbuild | sort -u >> Android_src.mk
cp ../busybox.mk Android.mk 2>/dev/null
if $COMMIT; then
git add -f include
git add *.mk
git commit -m "Add generated files for ndk-build"
fi
fi