Let demo scripts declare their dependencies

Demo scripts should declare their build-time dependencies, to make
them more user-friendly. If a dependency is not met, users should see
an explicit message rather than an incomprehensible error.

Don't rely on the dependencies of individual programs because some
demo scripts use multiple programs and because some scripts might have
additional requirements.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/programs/demo_common.sh b/programs/demo_common.sh
index fcd0752..78763b8 100644
--- a/programs/demo_common.sh
+++ b/programs/demo_common.sh
@@ -6,6 +6,10 @@
 ## Include this file near the top of each demo script:
 ##   . "${0%/*}/../demo_common.sh"
 ##
+## Start with a "msg" call that explains the purpose of the script.
+## Then call the "depends_on" function to ensure that all config
+## dependencies are met.
+##
 ## As the last thing in the script, call the cleanup function.
 ##
 ## You can use the functions and variables described below.
@@ -79,6 +83,20 @@
   done
 }
 
+## depends_on SYMBOL...
+## Exit if the library configuration does not have all SYMBOLs set.
+depends_on () {
+  if ! config_has "$@"; then
+    cat >&2 <<EOF
+This demo script requires the following configuration options to be enabled
+at compile time:
+  $@
+EOF
+    # Exit with a success status so that this counts as a pass for run_demos.py.
+    exit
+  fi
+}
+
 ## Add the names of files to clean up to this whitespace-separated variable.
 ## The file names must not contain whitespace characters.
 files_to_clean=