diff mbox series

[6/6] package/tpm2-pkcs11: install tool script (tpm2_ptool)

Message ID 20240627075441.4116645-7-romain.naour@smile.fr
State Accepted
Headers show
Series add missing tpm2-openssl package and tpm2_ptool script | expand

Commit Message

Romain Naour June 27, 2024, 7:54 a.m. UTC
tpm2_ptool script appear on several TPM2 tutorial and it's packaged as
"tpm2-pkcs11-tools" package on several Linux distribution.

Add a new tpm2-pkcs11 option to install tpm2_ptool script along with
its dependencies.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
---
 package/tpm2-pkcs11/Config.in      | 22 ++++++++++++++++++++++
 package/tpm2-pkcs11/tpm2-pkcs11.mk | 20 ++++++++++++++++++++
 2 files changed, 42 insertions(+)
diff mbox series

Patch

diff --git a/package/tpm2-pkcs11/Config.in b/package/tpm2-pkcs11/Config.in
index 5d45703223..93aa4a847a 100644
--- a/package/tpm2-pkcs11/Config.in
+++ b/package/tpm2-pkcs11/Config.in
@@ -11,5 +11,27 @@  config BR2_PACKAGE_TPM2_PKCS11
 
 	  https://github.com/tpm2-software/tpm2-pkcs11
 
+if BR2_PACKAGE_TPM2_PKCS11
+
+config BR2_PACKAGE_TPM2_PKCS11_PYTHON_TOOLS
+	bool "Install python tools (tpm2_ptool)"
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS # python-bcrypt, python-cryptography
+	depends on BR2_PACKAGE_PYTHON3
+	select BR2_PACKAGE_PYTHON_BCRYPT # runtime
+	select BR2_PACKAGE_PYTHON_CRYPTOGRAPHY # runtime
+	select BR2_PACKAGE_PYTHON_PYASN1 # runtime
+	select BR2_PACKAGE_PYTHON_PYASN1_MODULES # runtime
+	select BR2_PACKAGE_PYTHON_PYYAML # runtime
+	select BR2_PACKAGE_PYTHON_TPM2_PYTSS # runtime
+	select BR2_PACKAGE_PYTHON3_SQLITE # runtime
+	help
+	  Enable Python-related tools (tpm2_ptool)
+
+comment "python tools needs python3"
+	depends on !BR2_PACKAGE_PYTHON3
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+
+endif
+
 comment "tpm2-pkcs11 needs a toolchain w/ dynamic library, threads"
 	depends on BR2_STATIC_LIBS || !BR2_TOOLCHAIN_HAS_THREADS
diff --git a/package/tpm2-pkcs11/tpm2-pkcs11.mk b/package/tpm2-pkcs11/tpm2-pkcs11.mk
index 18f04157e3..c6218d772e 100644
--- a/package/tpm2-pkcs11/tpm2-pkcs11.mk
+++ b/package/tpm2-pkcs11/tpm2-pkcs11.mk
@@ -44,4 +44,24 @@  TPM2_PKCS11_CONF_OPTS += \
 	--with-p11kitconfigdir=/usr/share/p11-kit/modules
 endif
 
+ifeq ($(BR2_PACKAGE_TPM2_PKCS11_PYTHON_TOOLS),y)
+TPM2_PKCS11_DEPENDENCIES += python-tpm2-pytss
+
+define TPM2_PKCS11_BUILD_TOOLS
+	(cd $(@D)/tools; \
+	$(PKG_PYTHON_SETUPTOOLS_ENV) \
+		$(HOST_DIR)/bin/python setup.py build)
+endef
+TPM2_PKCS11_POST_BUILD_HOOKS += TPM2_PKCS11_BUILD_TOOLS
+
+define TPM2_PKCS11_INSTALL_TARGET_TOOLS
+	(cd $(@D)/tools; \
+	$(PKG_PYTHON_SETUPTOOLS_ENV) \
+		$(HOST_DIR)/bin/python setup.py install \
+		$(PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) \
+		--root=$(TARGET_DIR))
+endef
+TPM2_PKCS11_POST_INSTALL_TARGET_HOOKS += TPM2_PKCS11_INSTALL_TARGET_TOOLS
+endif
+
 $(eval $(autotools-package))