blob: 8d0d79e641d88c38dffcf233f185b3a8d03bcda9 [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
Denis Vlasenko27e15012008-09-28 17:19:02 +000046
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020047# If glibc, don't build static
48if test x"$LIBC" = x"glibc"; then
49 cat .config \
50 | grep -v CONFIG_STATIC \
51 >.config.new
52 mv .config.new .config
53 echo '# CONFIG_STATIC is not set' >>.config
54fi
Denis Vlasenko27e15012008-09-28 17:19:02 +000055
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020056# If glibc, build static, and remove some things
57# likely to not work on uclibc.
58if test x"$LIBC" = x"uclibc"; then
59 cat .config \
60 | grep -v CONFIG_STATIC \
61 | grep -v CONFIG_BUILD_LIBBUSYBOX \
62 | grep -v CONFIG_TASKSET \
63 | grep -v CONFIG_UNICODE_SUPPORT \
64 | grep -v CONFIG_PIE \
65 >.config.new
66 mv .config.new .config
67 echo 'CONFIG_STATIC=y' >>.config
68fi
69
70# If STATIC, remove some things.
Denis Vlasenko27e15012008-09-28 17:19:02 +000071# PAM with static linking is probably pointless
72# (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 +020073if grep -q "^CONFIG_STATIC=y" .config; then
74 cat .config \
75 | grep -v CONFIG_PAM \
76 >.config.new
77 mv .config.new .config
78fi
Denis Vlasenko27e15012008-09-28 17:19:02 +000079
Denis Vlasenko27e15012008-09-28 17:19:02 +000080# Regenerate .config with default answers for yanked-off options
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020081# (most of default answers are "no").
82{ yes "" | make oldconfig >/dev/null; } || { echo "oldconfig error"; exit 1; }
Denis Vlasenko27e15012008-09-28 17:19:02 +000083
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020084# Build!
85nice -n 10 make $MAKEOPTS 2>&1 | tee make.log
Denis Vlasenko27e15012008-09-28 17:19:02 +000086
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020087# Return exitcode 1 if busybox executable does not exist
88test -x busybox