- use default MEMSIZE in check_for_ppc
[platform/upstream/build.git] / common_functions
1 #!/bin/bash
2
3 : ${CACHE_DIR:=/var/cache/build}
4
5 set_build_arch()
6 {
7     : ${BUILD_HOST_ARCH:=`uname -m`}
8
9     if [ -z "$BUILD_ARCH" ]; then
10         BUILD_ARCH="$BUILD_HOST_ARCH"
11         test i686 != "$BUILD_ARCH" || BUILD_ARCH=i586 # XXX: why?
12     fi
13
14     case $BUILD_ARCH in
15       i686) BUILD_ARCH="i686:i586:i486:i386" ;;
16       i586) BUILD_ARCH="i586:i486:i386" ;;
17       i486) BUILD_ARCH="i486:i386" ;;
18       i386) BUILD_ARCH="i386" ;;
19       x86_64) BUILD_ARCH="x86_64:i686:i586:i486:i386" ;;
20       sparc64v) BUILD_ARCH="sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc" ;;
21       sparc64) BUILD_ARCH="sparc64:sparcv9:sparcv8:sparc" ;;
22       sparcv9v) BUILD_ARCH="sparcv9v:sparcv9:sparcv8:sparc" ;;
23       sparcv9) BUILD_ARCH="sparcv9:sparcv8:sparc" ;;
24       sparcv8) BUILD_ARCH="sparcv8:sparc" ;;
25       sparc) BUILD_ARCH="sparc" ;;
26     esac
27     if test "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
28         cpuflags=`grep ^flags /proc/cpuinfo`
29         cpuflags="$cpuflags "
30         if test "$cpuflags" = "${cpuflags/ cx8 /}" -o "$cpuflags" = "${cpuflags/ cmov /}"; then
31             echo "Your cpu doesn't support i686 rpms. Exit."
32             cleanup_and_exit 1
33         fi
34     fi
35 }
36
37 check_exit()
38 {
39     if test -e $BUILD_ROOT/exit; then
40         echo "exit ..."
41         cleanup_and_exit 1
42     fi
43 }
44
45 is_emulator_arch()
46 {
47     local arch
48     for arch in $EMULATOR_ARCHS; do
49         if test "$BUILD_ARCH" = "$arch" -a "$BUILD_HOST_ARCH" != "$arch"; then
50             return 0
51         fi
52     done
53     return 1
54 }
55
56 check_use_emulator()
57 {
58     is_emulator_arch || return
59
60     if [ -z "$VM_TYPE" ]; then
61         return 0
62     fi
63
64     # to run the qemu initialization in the XEN chroot, we need to
65     # register it with a static program or shell script
66     case "$BUILD_HOST_ARCH" in
67         i?86|x86_64)
68             if test -e $BUILD_DIR/initvm && \
69                 test -e $BUILD_DIR/qemu-reg; then
70                 return 0        # prefer initvm to handle registration
71             elif test -e /bin/bash-static \
72                 -a -e /bin/mount-static \
73                 -a -e /usr/sbin/qemu-binfmt-conf.sh; then
74                 return 0        # as backup use /usr/sbin/qemu-binfmt.conf.sh
75             else
76                 # XXX: error?
77                 echo "Warning: cross compile not possible due to missing static binaries"
78             fi
79         ;;
80     esac
81     return 1
82 }
83
84 # usage:
85 # progress_setup LIST
86 # for I in $LIST; do
87 #    progress_step LIST
88 #    action $I 
89 # done
90
91 # $1 name of a textual list
92 progress_setup() {
93     eval "$1__ARRAY__=(\$$1)"
94     eval "$1__INDEX__=1"
95     eval "$1__LENGTH__=\${#$1__ARRAY__[@]}"
96 }
97
98 # $1 name of a textual list
99 # $2 optional, printf format for 2 numeric arguments (current, total)
100 progress_step() {
101     local IDX=$1__INDEX__
102     local LEN=$1__LENGTH__
103     printf "${2-[%d/%d] }" $(($IDX++)) ${!LEN}
104 }