summaryrefslogtreecommitdiff
path: root/functions/architectures.sh
blob: b7f8b979c8d8aa629e31bf418bf3a6df7dce716e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


Check_architectures ()
{
	local ARCHITECTURE
	for ARCHITECTURE in "${@}"
	do
		if [ "${ARCHITECTURE}" = "${LB_ARCHITECTURE}" ]
		then
			return
		fi

		if [ "${ARCHITECTURE}" = "${LB_BOOTSTRAP_QEMU_ARCHITECTURE}" ]
		then
			if [ ! -e "${LB_BOOTSTRAP_QEMU_STATIC}" ]
			then
				Echo_warning "skipping %s, qemu-static binary ${LB_BOOTSTRAP_QEMU_ARCHITECTURE} was not found" "${0}"
				continue
			fi

			if [ ! -x "${LB_BOOTSTRAP_QEMU_STATIC}" ]
			then
				Echo_warning "skipping %s, qemu-static binary ${LB_BOOTSTRAP_QEMU_STATIC} is not executable" "${0}"
				continue
			fi

			return
		fi
	done

	Echo_warning "skipping %s, foreign architecture(s)." "${0}"
	exit 0
}

Check_crossarchitectures ()
{
	local HOST
	if command -v dpkg >/dev/null
	then
		HOST="$(dpkg --print-architecture)"
	else
		HOST="$(uname -m)"
	fi

	local CROSS
	case "${HOST}" in
		amd64|i386|x86_64)
			CROSS="amd64 i386"
			;;

		powerpc|ppc64)
			CROSS="powerpc ppc64"
			;;

		*)
			CROSS="${HOST}"
			;;
	esac

	if [ "${LB_ARCHITECTURE}" = "${LB_BOOTSTRAP_QEMU_ARCHITECTURE}" ]
	then

		if [ ! -e "${LB_BOOTSTRAP_QEMU_STATIC}" ]
		then
			Echo_warning "skipping %s, qemu-static binary ${LB_BOOTSTRAP_QEMU_ARCHITECTURE} was not found" "${0}"
			exit 0
		fi

		if [ ! -x "${LB_BOOTSTRAP_QEMU_STATIC}" ]
		then
			Echo_warning "skipping %s, qemu-static binary ${LB_BOOTSTRAP_QEMU_STATIC} is not executable" "${0}"
			exit 0
		fi
		return
	fi


	Check_architectures "${CROSS}"
}