Debian Codegraph @

common_functions

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/bash
2
3 ################################################################
4 #
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #
21 ################################################################
22
23 build_host_arch() {
24 : ${BUILD_HOST_ARCH:=`uname -m`}
25 # the linux kernel only knows armv7l, armv7hl is a userland definition
26 test armv7l == "$BUILD_HOST_ARCH" && BUILD_HOST_ARCH=armv7hl
27 test armv6l == "$BUILD_HOST_ARCH" && BUILD_HOST_ARCH=armv6hl
28
29 BUILD_INITVM_ARCH="$BUILD_HOST_ARCH"
30 # avoid multiple initvm.* helpers for i586 and i686
31 test i686 != "$BUILD_INITVM_ARCH" || BUILD_INITVM_ARCH=i586
32 }
33
34 extend_build_arch() {
35 case $BUILD_ARCH in
36 aarch64) BUILD_ARCH="aarch64:aarch64_ilp32:armv8l" ;;
37 aarch64_ilp32) BUILD_ARCH="aarch64_ilp32:aarch64:armv8l" ;;
38 armv8l) BUILD_ARCH="armv8l" ;; # armv8l is aarch64 in 32bit mode. not a superset of armv7
39 armv7hl) BUILD_ARCH="armv7hl:armv7l:armv6hl:armv6l:armv5tel" ;;
40 armv7l) BUILD_ARCH="armv7l:armv6l:armv5tel" ;;
41 armv6hl) BUILD_ARCH="armv6hl:armv6l:armv5tel" ;;
42 armv6l) BUILD_ARCH="armv6l:armv5tel" ;;
43 armv5tel) BUILD_ARCH="armv5tel" ;;
44 m68k) BUILD_ARCH="m68k" ;;
45 mips64) BUILD_ARCH="mips64:mips" ;;
46 mips) BUILD_ARCH="mips" ;;
47 i686) BUILD_ARCH="i686:i586:i486:i386" ;;
48 i586) BUILD_ARCH="i586:i486:i386" ;;
49 i486) BUILD_ARCH="i486:i386" ;;
50 i386) BUILD_ARCH="i386" ;;
51 ia64) BUILD_ARCH="ia64" ;;
52 parisc64) BUILD_ARCH="hppa64:hppa" ;;
53 parisc) BUILD_ARCH="hppa" ;;
54 ppc) BUILD_ARCH="ppc" ;;
55 ppc64) BUILD_ARCH="ppc64:ppc" ;;
56 ppc64le) BUILD_ARCH="ppc64le" ;;
57 riscv64) BUILD_ARCH="riscv64" ;;
58 s390x) BUILD_ARCH="s390x:s390" ;;
59 s390) BUILD_ARCH="s390" ;;
60 sparc64v) BUILD_ARCH="sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc" ;;
61 sparc64) BUILD_ARCH="sparc64:sparcv9:sparcv8:sparc" ;;
62 sparcv9v) BUILD_ARCH="sparcv9v:sparcv9:sparcv8:sparc" ;;
63 sparcv9) BUILD_ARCH="sparcv9:sparcv8:sparc" ;;
64 sparcv8) BUILD_ARCH="sparcv8:sparc" ;;
65 sparc) BUILD_ARCH="sparc" ;;
66 x86_64) BUILD_ARCH="x86_64:i686:i586:i486:i386" ;;
67 esac
68 }
69
70 set_build_arch() {
71 build_host_arch
72 if test -z "$BUILD_ARCH" ; then
73 BUILD_ARCH="$BUILD_HOST_ARCH"
74 fi
75 extend_build_arch
76 if test "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
77 cpuflags=`grep ^flags /proc/cpuinfo`
78 cpuflags="$cpuflags "
79 if test "$cpuflags" = "${cpuflags/ cx8 /}" -o "$cpuflags" = "${cpuflags/ cmov /}"; then
80 echo "Your cpu doesn't support i686 rpms. Exit."
81 cleanup_and_exit 1
82 fi
83 fi
84 }
85
86 check_exit() {
87 if test -e $BUILD_ROOT/exit; then
88 echo "exit ..."
89 cleanup_and_exit 1
90 fi
91 }
92
93 check_use_emulator() {
94 INITVM_NAME=
95 # check if the extended host arch contains the build arch
96 local old_build_arch="$BUILD_ARCH"
97 local arch="${BUILD_ARCH%%:*}"
98 BUILD_ARCH="$BUILD_HOST_ARCH"
99 extend_build_arch
100 BUILD_ARCH=":$BUILD_ARCH:"
101 if test "$BUILD_ARCH" != "${BUILD_ARCH/:$arch:/}" ; then
102 # native supported arch, no emulator
103 BUILD_ARCH="$old_build_arch"
104 return 1
105 fi
106 BUILD_ARCH="$old_build_arch"
107
108 # to run the qemu initialization in the vm, we need to
109 # register it with a static program or shell script
110 INITVM_NAME="initvm.$BUILD_INITVM_ARCH"
111 if test -e "$BUILD_DIR/$INITVM_NAME" -a -e "$BUILD_DIR/qemu-reg" ; then
112 chmod 0755 "$BUILD_DIR/$INITVM_NAME"
113 return 0 # chroot build, we need to run
114 fi
115 # XXX: error?
116 echo "Warning: cross compile not possible due to missing static binaries. please install build-initvm package for that purpose."
117 echo " check that the right architecture is available for your build host, you need $INITVM_NAME for this one."
118 INITVM_NAME=
119 return 1
120 }
121
122 # usage:
123 # progress_setup LIST
124 # for I in $LIST; do
125 # progress_step LIST
126 # action $I
127 # done
128
129 # $1 name of a textual list
130 progress_setup() {
131 eval "$1__ARRAY__=(\$$1)"
132 eval "$1__INDEX__=1"
133 eval "$1__LENGTH__=\${#$1__ARRAY__[@]}"
134 }
135
136 # $1 name of a textual list
137 # $2 optional, printf format for 2 numeric arguments (current, total)
138 progress_step() {
139 local IDX=$1__INDEX__
140 local LEN=$1__LENGTH__
141 printf "${2-[%d/%d] }" $(($IDX++)) ${!LEN}
142 }
143
144 # umount that does not follow symlinks
145 buildroot_umount() {
146 local d="$1"
147 local d2="/$d"
148 while test -n "$d2" ; do
149 test -L "$BUILD_ROOT$d2" && return
150 test -d "$BUILD_ROOT$d2" || return
151 d2="${d2%/*}"
152 done
153 # XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors?
154 umount -n "$BUILD_ROOT/$d" 2>/dev/null || true
155 }
156
157 # rm that makes sure the file is gone
158 buildroot_rm() {
159 rm -rf "$BUILD_ROOT/$1"
160 test -e "$BUILD_ROOT/$1" && cleanup_and_exit 1 "could not remove $BUILD_ROOT/$1"
161 }
162
163
164 assert_dirs() {
165 local d rl
166 if test -z "$1" ; then
167 set usr sbin usr/bin usr/sbin etc .build .build.oldpackages .init_b_cache .init_b_cache/scripts .init_b_cache/rpms .preinstall_image proc proc/sys proc/sys/fs proc/sys/fs/binfmt_misc sys dev dev/pts dev/shm mnt
168 fi
169 for d in "$@" ; do
170 if test -L "$BUILD_ROOT/$d" ; then
171 rl="$(readlink "$BUILD_ROOT/$d")"
172 test "$d" = sbin -a "x$rl" = "xusr/sbin" && continue
173 test "$d" = sbin -a "x$rl" = "xusr/bin" && continue
174 test "$d" = usr/sbin -a "x$rl" = "xbin" && continue
175 cleanup_and_exit 1 "$d: illegal symlink to $rl"
176 else
177 test -e "$BUILD_ROOT/$d" -a ! -d "$BUILD_ROOT/$d" && cleanup_and_exit 1 "$d: not a directory"
178 fi
179 done
180 }
181
182 assert_dir_path() {
183 test "$1" != "${1%/*}" && assert_dir_path "${1%/*}"
184 assert_dir "$1"
185 }