sys-libs/efivar: Fix cross compilation
Add 3 patches:
- one by me to remove doc complilation, which is new and
seems broken anyways
- two from upstream to fix cross compilatoin
BUG=b/282731888
TEST=Local gmec-arm64-hw build
RELEASE_NOTE=None
Change-Id: I1a3b6f9a11bbdfbae0239c8e23c538e9be15e30d
Reviewed-on: https://cos-review.googlesource.com/c/third_party/overlays/portage-stable/+/50047
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
diff --git a/sys-libs/efivar/efivar-38-r1.ebuild b/sys-libs/efivar/efivar-38-r1.ebuild
new file mode 120000
index 0000000..e429e46
--- /dev/null
+++ b/sys-libs/efivar/efivar-38-r1.ebuild
@@ -0,0 +1 @@
+efivar-38.ebuild
\ No newline at end of file
diff --git a/sys-libs/efivar/efivar-38.ebuild b/sys-libs/efivar/efivar-38.ebuild
index 1c98786..3c7dbae 100644
--- a/sys-libs/efivar/efivar-38.ebuild
+++ b/sys-libs/efivar/efivar-38.ebuild
@@ -29,6 +29,7 @@
src_prepare() {
local PATCHES=(
+ "${FILESDIR}"/efivar-38-makeguids-cross-compile.patch
"${FILESDIR}"/efivar-38-march-native.patch
"${FILESDIR}"/efivar-38-Makefile-dep.patch
"${FILESDIR}"/efivar-38-binutils-2.36.patch
@@ -38,6 +39,8 @@
"${FILESDIR}"/efivar-38-efisecdb-musl.patch
"${FILESDIR}"/efivar-38-efisecdb-optarg.patch
"${FILESDIR}"/efivar-38-64bit-off_t.patch
+ "${FILESDIR}"/efivar-38-pkg-config-override.patch
+ "${FILESDIR}"/efivar-38-delete-doc-targets.patch
# Rejected upstream, keep this for ia64 support
"${FILESDIR}"/efivar-38-ia64-relro.patch
@@ -49,6 +52,8 @@
unset CROSS_COMPILE
export COMPILER=$(tc-getCC)
export HOSTCC=$(tc-getBUILD_CC)
+ export HOST_CFLAGS=
+ export PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG)
tc-ld-disable-gold
diff --git a/sys-libs/efivar/files/efivar-38-delete-doc-targets.patch b/sys-libs/efivar/files/efivar-38-delete-doc-targets.patch
new file mode 100644
index 0000000..b173b62
--- /dev/null
+++ b/sys-libs/efivar/files/efivar-38-delete-doc-targets.patch
@@ -0,0 +1,52 @@
+commit b8c73e328594bbbb934c9f36c126180a09627969
+Author: Ian K. Coolidge <icoolidge@google.com>
+Date: Tue May 16 15:52:35 2023 +0000
+
+ delete doc targets
+
+diff --git a/docs/Makefile b/docs/Makefile
+index c9bf585..d1499e1 100644
+--- a/docs/Makefile
++++ b/docs/Makefile
+@@ -5,39 +5,8 @@ include $(TOPDIR)/src/include/version.mk
+ include $(TOPDIR)/src/include/rules.mk
+ include $(TOPDIR)/src/include/defaults.mk
+
+-MAN1TARGETS = efisecdb.1 \
+- efivar.1
+-
+-MAN3TARGETS = efi_append_variable.3 \
+- efi_del_variable.3 \
+- efi_get_next_variable_name.3 \
+- efi_get_variable.3 \
+- efi_get_variable_attributes.3 \
+- efi_get_variable_size.3 \
+- efi_guid_to_id_guid.3 \
+- efi_guid_to_name.3 \
+- efi_guid_to_str.3 \
+- efi_guid_to_symbol.3 \
+- efi_name_to_guid.3 \
+- efi_set_variable.3 \
+- efi_str_to_guid.3 \
+- efi_symbol_to_guid.3 \
+- efi_variables_supported.3 \
+- efi_variable_t.3 \
+- efi_variable_import.3 \
+- efi_variable_export.3 \
+- efi_variable_alloc.3 \
+- efi_variable_free.3 \
+- efi_variable_set_name.3 \
+- efi_variable_get_name.3 \
+- efi_variable_set_guid.3 \
+- efi_variable_get_guid.3 \
+- efi_variable_set_data.3 \
+- efi_variable_get_data.3 \
+- efi_variable_get_attributes.3 \
+- efi_variable_set_attributes.3 \
+- efi_variable_realize.3
+-
++MAN1TARGETS =
++MAN3TARGETS =
+ all : $(MAN1TARGETS) $(MAN3TARGETS)
+
+ clean :
diff --git a/sys-libs/efivar/files/efivar-38-makeguids-cross-compile.patch b/sys-libs/efivar/files/efivar-38-makeguids-cross-compile.patch
new file mode 100644
index 0000000..8e2066d
--- /dev/null
+++ b/sys-libs/efivar/files/efivar-38-makeguids-cross-compile.patch
@@ -0,0 +1,32 @@
+commit ca48d3964d26f5e3b38d73655f19b1836b16bd2d
+Author: Alexander Kanavin <alex@linutronix.de>
+Date: Tue Jan 18 11:53:41 2022 +0100
+
+ src/Makefile: build util.c separately for makeguids
+
+ util.c needs to be built twice when cross-compiling:
+ for the build machine to be able to link with
+ makeguids which then runs during the same build,
+ and then for the actual target.
+
+ Signed-off-by: Alexander Kanavin <alex@linutronix.de>
+
+diff --git a/src/Makefile b/src/Makefile
+index 0e423c4..a86abdc 100644
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -28,10 +28,13 @@ EFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFIVAR_SOURCES)))
+ EFISECDB_SOURCES = efisecdb.c guid-symbols.c secdb-dump.c util.c
+ EFISECDB_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFISECDB_SOURCES)))
+ GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c
+-MAKEGUIDS_SOURCES = makeguids.c util.c
++MAKEGUIDS_SOURCES = makeguids.c util-makeguids.c
+ MAKEGUIDS_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(MAKEGUIDS_SOURCES)))
+ MAKEGUIDS_OUTPUT = $(GENERATED_SOURCES) guids.lds
+
++util-makeguids.c : util.c
++ cp util.c util-makeguids.c
++
+ ALL_SOURCES=$(LIBEFISEC_SOURCES) $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) \
+ $(MAKEGUIDS_SOURCES) $(GENERATED_SOURCES) $(EFIVAR_SOURCES) \
+ $(sort $(wildcard include/efivar/*.h))
diff --git a/sys-libs/efivar/files/efivar-38-pkg-config-override.patch b/sys-libs/efivar/files/efivar-38-pkg-config-override.patch
new file mode 100644
index 0000000..1bc53e5
--- /dev/null
+++ b/sys-libs/efivar/files/efivar-38-pkg-config-override.patch
@@ -0,0 +1,30 @@
+commit 328f5845d5145184258d5155226b2647c1291e25
+Author: Ted Brandston <tbrandston@google.com>
+Date: Wed Nov 2 11:01:30 2022 -0400
+
+ Allow overriding PKG_CONFIG
+
+ In my ChromiumOS build calling pkg-config without an appropriate
+ cross-compilation prefix is considered an error. The current method of
+ detecting PKG_CONFIG in efivar _always_ calls pkg-config, even if
+ PKG_CONFIG has already been set in the environment.
+
+ Allow overriding PKG_CONFIG, rather than always checking for the
+ cross-compiled version. This is more in-line with how the other tools
+ are chosen.
+
+ Signed-off-by: Ted Brandston <tbrandston@google.com>
+
+diff --git a/src/include/defaults.mk b/src/include/defaults.mk
+index bb9c997..630da23 100644
+--- a/src/include/defaults.mk
++++ b/src/include/defaults.mk
+@@ -107,7 +107,7 @@ override HOST_LDFLAGS = $(HOST_CFLAGS) -L. \
+ $(call pkg-config-ccldflags)
+ override HOST_CCLDFLAGS = $(HOST_LDFLAGS)
+
+-PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi)
++PKG_CONFIG ?= $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi)
+ INSTALL ?= install
+ AR := $(CROSS_COMPILE)$(COMPILER)-ar
+ NM := $(CROSS_COMPILE)$(COMPILER)-nm