]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
scripts/makefile-getvar: add script to get values from Makefiles
authorRoss Burton <ross.burton@arm.com>
Wed, 12 Jun 2024 11:06:58 +0000 (11:06 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 13 Jun 2024 08:10:09 +0000 (09:10 +0100)
There is often a need to extract a value from a Makefile, and standard
GNU Make doesn't provide a way to do this.  This script lets you access
values from Makefiles directly:

$ makefile-getvar curl/tests/server/Makefile noinst_PROGRAMS
getpart resolve rtspd sockfilt sws tftpd fake_ntlm socksd disabled mqttd

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/makefile-getvar [new file with mode: 0755]

diff --git a/scripts/makefile-getvar b/scripts/makefile-getvar
new file mode 100755 (executable)
index 0000000..4a07055
--- /dev/null
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+# Get a variable's value from a makefile:
+#
+# $ makefile-getvar Makefile VARIABLE VARIABLE ...
+#
+# If multiple variables are specified, they will be printed one per line.
+#
+# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-License-Identifier: GPL-2.0-only
+
+set -eu
+
+MAKEFILE=$1
+shift
+
+for VARIABLE in $*; do
+       make -f - $VARIABLE.var <<EOF
+include $MAKEFILE
+
+%.var:
+       @echo \$(\$*)
+EOF
+done