blob: 76550d267340533272855805ae8ab8c8c14fd281 [file] [log] [blame]
Denis Vlasenko27e15012008-09-28 17:19:02 +00001#!/bin/sh
2
Denys Vlasenkoff0e8752010-05-10 04:16:43 +02003# If not specified in environment...
4if ! test "$LIBC"; then
5 # Select which libc to build against
6 LIBC="glibc"
7 LIBC="uclibc"
8fi
Denis Vlasenko62e0dc22008-11-09 16:08:31 +00009# x86 32-bit:
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020010#CROSS_COMPILER_PREFIX="i486-linux-uclibc-"
Denis Vlasenko62e0dc22008-11-09 16:08:31 +000011# My system has strange prefix for x86 64-bit uclibc:
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020012#CROSS_COMPILER_PREFIX="x86_64-pc-linux-gnu-"
Denis Vlasenko27e15012008-09-28 17:19:02 +000013
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020014if test $# -lt 2 || ! test -d "$1" || test -e "$2"; then
15 echo "Usage: $0 SRC_DIR TMP_DIR"
16 echo
17 echo "SRC_DIR will be copied to TMP_DIR directory."
18 echo "Then a random build will be performed."
19 echo
20 echo "Useful variables:"
21 echo "\$LIBC, \$CROSS_COMPILER_PREFIX, \$MAKEOPTS"
22 exit 1
23fi
Denis Vlasenko27e15012008-09-28 17:19:02 +000024
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020025cp -dpr -- "$1" "$2" || { echo "copy error"; exit 1; }
26cd -- "$2" || { echo "cd $dir error"; exit 1; }
Denis Vlasenko27e15012008-09-28 17:19:02 +000027
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020028# Generate random config
29make randconfig >/dev/null || { echo "randconfig error"; exit 1; }
Denis Vlasenko27e15012008-09-28 17:19:02 +000030
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020031# Tweak resulting config
Denis Vlasenko27e15012008-09-28 17:19:02 +000032cat .config \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020033| grep -v CONFIG_DEBUG_PESSIMIZE \
Denis Vlasenko27e15012008-09-28 17:19:02 +000034| grep -v CONFIG_WERROR \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020035| grep -v CONFIG_CROSS_COMPILER_PREFIX \
Denys Vlasenko2315c882010-01-24 23:33:06 +010036| grep -v CONFIG_SELINUX \
37| grep -v CONFIG_EFENCE \
38| grep -v CONFIG_DMALLOC \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020039\
40| grep -v CONFIG_RFKILL \
41>.config.new
Denis Vlasenko27e15012008-09-28 17:19:02 +000042mv .config.new .config
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020043echo '# CONFIG_DEBUG_PESSIMIZE is not set' >>.config
44echo '# CONFIG_WERROR is not set' >>.config
45echo "CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILER_PREFIX}\"" >>.config
Denys Vlasenko3e5fa432010-07-06 02:26:35 +020046echo '# CONFIG_SELINUX is not set' >>.config
47echo '# CONFIG_EFENCE is not set' >>.config
48echo '# CONFIG_DMALLOC is not set' >>.config
49echo '# CONFIG_RFKILL is not set' >>.config
Denis Vlasenko27e15012008-09-28 17:19:02 +000050
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020051# If glibc, don't build static
52if test x"$LIBC" = x"glibc"; then
53 cat .config \
54 | grep -v CONFIG_STATIC \
Denys Vlasenko9c9a7422017-12-31 20:31:05 +010055 | grep -v CONFIG_FEATURE_LIBBUSYBOX_STATIC \
Denys Vlasenko015db582016-06-19 18:15:33 +020056 \
57 | grep -v CONFIG_FEATURE_2_4_MODULES \
58 | grep -v CONFIG_FEATURE_USE_BSS_TAIL \
59 | grep -v CONFIG_DEBUG_SANITIZE \
Denys Vlasenko5f5119b2018-06-26 16:01:05 +020060 | grep -v CONFIG_FEATURE_MOUNT_NFS \
Denys Vlasenko18532662018-06-26 16:08:22 +020061 | grep -v CONFIG_FEATURE_INETD_RPC \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020062 >.config.new
63 mv .config.new .config
64 echo '# CONFIG_STATIC is not set' >>.config
Denys Vlasenko9c9a7422017-12-31 20:31:05 +010065 echo '# CONFIG_FEATURE_LIBBUSYBOX_STATIC is not set' >>.config
Denys Vlasenko015db582016-06-19 18:15:33 +020066 # newer glibc (at least 2.23) no longer supply query_module() ABI.
67 # People who target 2.4 kernels would likely use older glibc (and older bbox).
68 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
69 echo '# CONFIG_FEATURE_USE_BSS_TAIL is not set' >>.config
70 echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
Denys Vlasenko5f5119b2018-06-26 16:01:05 +020071 # 2018: current glibc versions no longer include rpc/rpc.h
72 echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
Denys Vlasenko18532662018-06-26 16:08:22 +020073 echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020074fi
Denis Vlasenko27e15012008-09-28 17:19:02 +000075
Denys Vlasenko3e5fa432010-07-06 02:26:35 +020076# If uclibc, build static, and remove some things
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020077# likely to not work on uclibc.
78if test x"$LIBC" = x"uclibc"; then
79 cat .config \
80 | grep -v CONFIG_STATIC \
81 | grep -v CONFIG_BUILD_LIBBUSYBOX \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020082 | grep -v CONFIG_PIE \
Denys Vlasenko3e5fa432010-07-06 02:26:35 +020083 \
84 | grep -v CONFIG_FEATURE_2_4_MODULES \
Denys Vlasenko69c8c692015-10-11 16:27:55 +020085 | grep -v CONFIG_FEATURE_SYNC_FANCY \
86 | grep -v CONFIG_FEATURE_TOUCH_NODEREF \
Denys Vlasenko015db582016-06-19 18:15:33 +020087 | grep -v CONFIG_NANDWRITE \
88 | grep -v CONFIG_NANDDUMP \
89 | grep -v CONFIG_BLKDISCARD \
90 | grep -v CONFIG_NSENTER \
91 | grep -v CONFIG_UNSHARE \
Denys Vlasenko7fdb7642017-07-03 02:33:08 +020092 | grep -v CONFIG_FALLOCATE \
93 | grep -v CONFIG_UDHCPC6 \
Denys Vlasenko762440b2018-06-26 17:22:35 +020094 | grep -v CONFIG_NSLOOKUP \
Denys Vlasenko7fdb7642017-07-03 02:33:08 +020095 | grep -v CONFIG_ASH_INTERNAL_GLOB \
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020096 >.config.new
97 mv .config.new .config
98 echo 'CONFIG_STATIC=y' >>.config
Denys Vlasenko3e5fa432010-07-06 02:26:35 +020099 echo '# CONFIG_BUILD_LIBBUSYBOX is not set' >>.config
100 echo '# CONFIG_PIE is not set' >>.config
101 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
Denys Vlasenko69c8c692015-10-11 16:27:55 +0200102 echo '# CONFIG_FEATURE_SYNC_FANCY is not set' >>.config
Denys Vlasenko198b02f2013-12-31 23:22:36 +0100103 echo '# CONFIG_FEATURE_TOUCH_NODEREF is not set' >>.config
Denys Vlasenko015db582016-06-19 18:15:33 +0200104 # My uclibc installation does not support some needed APIs...
105 echo '# CONFIG_NANDWRITE is not set' >>.config
106 echo '# CONFIG_NANDDUMP is not set' >>.config
107 echo '# CONFIG_BLKDISCARD is not set' >>.config
108 echo '# CONFIG_NSENTER is not set' >>.config
109 echo '# CONFIG_UNSHARE is not set' >>.config
Denys Vlasenko7fdb7642017-07-03 02:33:08 +0200110 echo '# CONFIG_FALLOCATE is not set' >>.config
111 echo '# CONFIG_UDHCPC6 is not set' >>.config
Denys Vlasenko762440b2018-06-26 17:22:35 +0200112 echo '# CONFIG_NSLOOKUP is not set' >>.config
Denys Vlasenko7fdb7642017-07-03 02:33:08 +0200113 echo 'CONFIG_ASH_INTERNAL_GLOB=y' >>.config
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200114fi
115
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200116# If musl
117if test x"$LIBC" = x"musl"; then
118 cat .config \
119 | grep -v CONFIG_STATIC \
Denys Vlasenko7c443d12020-06-24 00:27:37 +0200120 | grep -v CONFIG_DEBUG_SANITIZE \
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200121 | grep -v CONFIG_LFS \
122 | grep -v CONFIG_EXTRA_COMPAT \
123 | grep -v CONFIG_FEATURE_2_4_MODULES \
124 | grep -v CONFIG_FEATURE_VI_REGEX_SEARCH \
125 | grep -v CONFIG_FEATURE_MOUNT_NFS \
126 | grep -v CONFIG_FEATURE_INETD_RPC \
127 >.config.new
128 mv .config.new .config
129 echo 'CONFIG_STATIC=y' >>.config
Denys Vlasenko7c443d12020-06-24 00:27:37 +0200130 # "error: cannot specify -static with -fsanitize=address":
131 echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200132 # with LFS off, uoff_t will have wrong width:
133 echo 'CONFIG_LFS=y' >>.config
134 echo '# CONFIG_EXTRA_COMPAT is not set' >>.config
135 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
136 echo '# CONFIG_FEATURE_VI_REGEX_SEARCH is not set' >>.config
137 echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
138 echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
139fi
140
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200141# If STATIC, remove some things.
Denis Vlasenko27e15012008-09-28 17:19:02 +0000142# PAM with static linking is probably pointless
143# (but I need to try - now I don't have libpam.a on my system, only libpam.so)
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200144if grep -q "^CONFIG_STATIC=y" .config; then
145 cat .config \
146 | grep -v CONFIG_PAM \
147 >.config.new
148 mv .config.new .config
Denys Vlasenko3e5fa432010-07-06 02:26:35 +0200149 echo '# CONFIG_PAM is not set' >>.config
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200150fi
Denis Vlasenko27e15012008-09-28 17:19:02 +0000151
Denis Vlasenko27e15012008-09-28 17:19:02 +0000152# Regenerate .config with default answers for yanked-off options
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200153# (most of default answers are "no").
154{ yes "" | make oldconfig >/dev/null; } || { echo "oldconfig error"; exit 1; }
Denis Vlasenko27e15012008-09-28 17:19:02 +0000155
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200156# Build!
157nice -n 10 make $MAKEOPTS 2>&1 | tee make.log
Denys Vlasenkobb0bf282016-06-19 21:54:04 +0200158grep 'Rerun make' make.log \
159&& nice -n 10 make $MAKEOPTS 2>&1 | tee -a make.log
Denis Vlasenko27e15012008-09-28 17:19:02 +0000160
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200161# Return exitcode 1 if busybox executable does not exist
162test -x busybox