summaryrefslogtreecommitdiffstats
path: root/scripts/make_deb.sh
blob: a744a8360d074b0433aaac7b7ea5f2bf76429ec7 (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
89
90
91
92
93
94
95
96
#!/bin/bash

main() {
    while getopts "d:s:" opt; do
	case "${opt}" in
	    d)
		local deb="${OPTARG}"
		;;
	    s)
		local src="${OPTARG}"
	esac
    done

    if [ -z "${deb}" -o -z "${src}" ]; then
	exit 1
    fi

    local ifs_orig="${IFS}"
    IFS="_"
    set -- ${deb}
    IFS="${ifs_orig}"

    local package="${1##*/}"
    local inst="${1%${package}}"
    local version="${2}"
    local arch="${3%%.deb}"

    local prefix="opt/${src##*/opt/}"
    local destdir="${src%${prefix}}"
    local debian_tmp="${inst}/${package}-temp"
    if [ -e "${debian_tmp}" ]; then
	rm -rf "${debian_tmp}"
    fi

    mkdir -p "${debian_tmp}"/{tmp,debian}

    cat <<EOF > "${debian_tmp}/debian/control"
Source: oselas.toolchain
Maintainer: Pengutronix <ptxdist@pengutronix.de>
Uploaders: $(git config user.name) <$(git config user.email)>
Section: devel
Priority: optional
Origin: pengutronix
Homepage: http://www.pengutronix.de/oselas/toolchain/
Bugs: mailto:bugs@pengutronix.de

Package: ${package}
Architecture: ${arch}
Depends: \${shlibs:Depends}
Description: ${package}
EOF
    cat <<EOF > "${debian_tmp}/debian/changelog"
oselas.toolchain (${version}) unstable; urgency=low

  * New upstream release.

 -- $(git config user.name) <$(git config user.email)>  $(date -R)
EOF
    cat <<EOF > "${debian_tmp}/debian/compat"
9
EOF
    # copy data
    echo "Copy data..."
    tar -C "${destdir}" --exclude=gcc-first -c "${prefix}" | tar -C "${debian_tmp}/tmp" -x

    (
	cd "${debian_tmp}"

	# generate dependencies
	echo "Generate dependencies..."
	local sysroot="$(ptxd_get_ptxconf PTXCONF_SYSROOT_TARGET)"
	sysroot="${debian_tmp}/tmp${sysroot#${PTX_AUTOBUILD_DESTDIR}}"
	local other="$(ptxd_get_ptxconf PTXCONF_SYSROOT_CROSS)"
	other="${debian_tmp}/tmp${other#${PTX_AUTOBUILD_DESTDIR}}/$(ptxd_get_ptxconf PTXCONF_GNU_TARGET)"

	fakeroot dh_shlibdeps \
	    -P"${debian_tmp}/tmp" \
	    -l"${sysroot}/lib:${sysroot}/usr/lib:${sysroot}/usr/lib/gconv:${other}/lib" \
	    -- \
	    -T"${debian_tmp}/substvars" &&

	# generate DEBIAN/control
	dpkg-gencontrol \
	    -P"${debian_tmp}/tmp" \
	    -T"${debian_tmp}/substvars"
    ) || exit

    # make a deb out of it
    echo dpkg-deb --build -Zxz "${debian_tmp}/tmp" "${deb}" | fakeroot

    rm -rf "${debian_tmp}"
}


main "${@}"
exit $?