summaryrefslogtreecommitdiffstats
path: root/debian/bin/gencontrol.sh
blob: d9b9db388eee9dc6cd69ca95f81331e1c1c03261 (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
#!/bin/bash -e

die() {
	echo >&2 "$@"
	return 1
}

# This script assumes to have CWD = toplevel of OSELAS.Toolchain
test -f debian/changelog || die "debian/changelog not found"
vendor="$(dpkg-vendor --query Vendor)"
if [ "${vendor}" != "Debian" -a "${vendor}" != "Ubuntu" ]; then
	die "This script only works on Debian"
fi

toolchain_path_version=$(dpkg-parsechangelog -SVersion | sed -e 's/-.*$//')
toolchain_version="$(tr A-Z a-z <<< "${toolchain_path_version}")"
newcontrol=$(mktemp debian/control.XXXXXXXXX)
trap 'rm -v -- "$newcontrol"' INT QUIT EXIT

cat > "$newcontrol" << EOF
Source: oselas.toolchain
Section: devel
Priority: optional
Maintainer: PTXdist Devevelopers <ptxdist@pengutronix.de>
Homepage: https://www.pengutronix.de/software/toolchain.html
Bugs: mailto:bugs@pengutronix.de
Build-Depends: debhelper (>= 9), libncurses-dev, python3-dev | python3.8-dev, bison, flex
EOF

if [ $# -gt 0 ]; then
	configs=( "${@}" )
else
	configs=( ptxconfigs/*.ptxconfig )
fi
for configfile in "${configs[@]}"; do
	toolchain_name="$(basename "${configfile}" .ptxconfig | sed s/_/-/g)"
	pkg="oselas.toolchain-${toolchain_version}-${toolchain_name}"
	gnutriplet="$(sed -n 's/^PTXCONF_GNU_TARGET="\(.*\)"/\1/p' "$configfile")"

	cat >> "$newcontrol" << EOF

Package: $pkg
Architecture: any
Depends: \${shlibs:Depends}, \${misc:Depends}
Description: OSELAS Toolchain for ${gnutriplet}
 
Package: oselas.toolchain-${toolchain_version}-${gnutriplet/_/-}
Architecture: all
Depends: $pkg
Description: Meta package depending on latest OSELAS Toolchain for ${gnutriplet}

Package: oselas.toolchain-${toolchain_version%.*}-${gnutriplet/_/-}
Architecture: all
Depends: $pkg
Description: Meta package depending on latest OSELAS Toolchain for ${gnutriplet}
EOF

	echo "/opt/OSELAS.Toolchain-${toolchain_path_version}/${gnutriplet}" > "debian/${pkg}.install"
done

if ! cmp -s "$newcontrol" "debian/control"; then
	mv "$newcontrol" "debian/control"
	trap '' INT QUIT EXIT

	echo >&2 debian/control was updated successfully.
	echo >&2 Nevertheless return failure here to eventually abort
	echo >&2 building because the debian/control must not change
	echo >&2 during a build.

	exit 1
else
	touch "debian/control"
fi