summaryrefslogtreecommitdiff
path: root/sys-firmware/gnuk/gnuk-1.2.20.ebuild
blob: e50c6343b580d437ae9587bfc9ef39b78154374e (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
PYTHON_COMPAT=( python3_{11..12} )
inherit git-r3 python-r1 udev

DESCRIPTION="An Implementation of USB Cryptographic Token for GnuPG"
HOMEPAGE="https://www.fsij.org/category/gnuk.html"
EGIT_REPO_URI="https://salsa.debian.org/gnuk-team/${PN}/${PN}"
EGIT_COMMIT="release/${PV}"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE="debug doc tools"

DEPEND="doc? ( dev-python/sphinx )"
RDEPEND="virtual/udev
	tools? (
		${PYTHON_DEPS}
		dev-python/pyusb[${PYTHON_USEDEP}]
		dev-python/colorama[${PYTHON_USEDEP}]
	)"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"

PATCHES=(
	"${FILESDIR}/${PV}-MINOR-Always-get-version-from-the-VERSION-file.patch"
	"${FILESDIR}/${PV}-build-initilize-empty-MCFLAGS-and-LDFLAGS.patch"
	"${FILESDIR}/${PV}-build-discard-compiler-default-specs.patch"
	"${FILESDIR}/${PV}-build-move-nostartfiles-earlier.patch"
	"${FILESDIR}/${PV}-build-do-not-produce-a-dynamically-linked-position-i.patch"
)

pkg_pretend() {
	if type -p arm-none-eabi-gcc > /dev/null 2>&1 ; then
		return 0
	fi

	eerror "Before you could build the firmware, you need to install arm-none-eabi toolchain"
	eerror "Run the following commands:"
	eerror "	emerge -vat crossdev"
	eerror "	crossdev --target arm-none-eabi"
	die "arm-none-eabi toolchain is needed"
}

src_prepare () {
	default

	mv tool/get_raw_public_key.py      "tool/${PN}-get_raw_public_key.py" || die
	mv tool/gnuk_get_random.py         "tool/${PN}-get_random.py"         || die
	mv tool/gnuk_put_binary_libusb.py  "tool/${PN}-put_binary_libusb.py"  || die
	mv tool/gnuk_remove_keys_libusb.py "tool/${PN}-remove_keys_libusb.py" || die
	mv tool/gnuk_upgrade.py            "tool/${PN}-upgrade.py"            || die
	mv tool/stlinkv2.py                "tool/${PN}-stlinkv2.py"           || die
	mv tool/upgrade_by_passwd.py       "tool/${PN}-upgrade_by_passwd.py"  || die
	mv tool/usb_strings.py             "tool/${PN}-usb_strings.py"        || die
}

src_configure() {
	cd "${S}/src"
	./configure \
		--target=FST_01 \
		--vidpid=234b:0000 \
		--enable-certdo \
		--enable-factory-reset \
		--enable-hid-card-change \
		$(use_enable debug) \
		|| die "configure failed"
}

src_compile() {
	cd "${S}/src"
	emake CROSS="arm-none-eabi-"

	if use doc ; then
		cd "${S}/doc"
		emake html
		emake man
	fi

	cd "${S}/regnual"
	emake TRGT="arm-none-eabi-"
}

src_install() {
	insinto "/usr/share/${PN}/firmware"
	doins "src/build/${PN}.bin"
	doins "regnual/regnual.bin"

	udev_dorules "${FILESDIR}/60-${PN}.rules"

	if use doc ; then
		HTML_DOCS=( doc/_build/html/* )
		doman doc/_build/man/*
	fi

	install_example() {
		local d="$(python_get_scriptdir)"
		insinto "${d#${EPREFIX}}"
		doins "${1}"
	}

	if use tools ; then
		python_foreach_impl python_domodule tool/gnuk_token.py
		python_foreach_impl python_domodule tool/gpg_agent.py
		python_foreach_impl python_domodule tool/kdf_calc.py
		python_foreach_impl python_domodule tool/rsa.py

		python_foreach_impl python_doscript "tool/${PN}-get_random.py"
		python_foreach_impl python_doscript "tool/${PN}-get_raw_public_key.py"
		python_foreach_impl python_doscript "tool/${PN}-put_binary_libusb.py"
		python_foreach_impl python_doscript "tool/${PN}-remove_keys_libusb.py"
		python_foreach_impl python_doscript "tool/${PN}-stlinkv2.py"
		python_foreach_impl python_doscript "tool/${PN}-upgrade.py"
		python_foreach_impl python_doscript "tool/${PN}-upgrade_by_passwd.py"
		python_foreach_impl python_doscript "tool/${PN}-usb_strings.py"
		python_foreach_impl install_example tool/rsa_example.key

		udev_dorules "${FILESDIR}/10-stlink.rules"
	fi

	dodoc AUTHORS ChangeLog NEWS README THANKS
	dodoc -r doc/note
}