[PATCH] Support custom pkg-config executable names

[PATCH] Support custom pkg-config executable names

From: Alyssa Ross
When cross-compiling, it's common to have executables prefixed with
the name of the architecture you're building for,
e.g. aarch64-unknown-linux-musl-cc or x86_64-unknown-freebsd-pkg-config.
Lots of build tools support a PKG_CONFIG environment variable to
enable this use case.

With this change, I was able to successfully cross-compile and run
catgirl.
---
 configure | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 4199980..46500a3 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,9 @@
 #!/bin/sh
 set -eu
 
+pkg_config() {
+    ${PKG_CONFIG:-pkg-config} $@
+}
 cflags() {
 	echo "CFLAGS += $*"
 }
@@ -8,16 +11,16 @@ defstr() {
 	cflags "-D'$1=\"$2\"'"
 }
 defvar() {
-	defstr "$1" "$(pkg-config --variable=$3 $2)${4:-}"
+	defstr "$1" "$(pkg_config --variable=$3 $2)${4:-}"
 }
 ldadd() {
 	lib=$1; shift
 	echo "LDADD.${lib} = $*"
 }
 config() {
-	pkg-config --print-errors "$@"
-	cflags $(pkg-config --cflags "$@")
-	for lib; do ldadd $lib $(pkg-config --libs $lib); done
+	pkg_config --print-errors "$@"
+	cflags $(pkg_config --cflags "$@")
+	for lib; do ldadd $lib $(pkg_config --libs $lib); done
 }
 
 exec >config.mk
-- 
2.33.0

Re: [PATCH] Support custom pkg-config executable names

From: june
> On Nov 19, 2021, at 16:52, Alyssa Ross <hi@alyssa.is> wrote:
> 
> When cross-compiling, it's common to have executables prefixed with
> the name of the architecture you're building for,
> e.g. aarch64-unknown-linux-musl-cc or x86_64-unknown-freebsd-pkg-config.
> Lots of build tools support a PKG_CONFIG environment variable to
> enable this use case.

Oh, I've implemented this before in another project. I'm going to
edit this to be consistent with how I did it there. Thanks!