summaryrefslogtreecommitdiffstats
path: root/Configure
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-03-06 03:00:53 +0100
committerRichard Levitte <levitte@openssl.org>2015-03-16 22:16:30 +0100
commit09816a2e339642e09c612ec48dde0754fec930d2 (patch)
tree342ee054ed14afff83176b1e13c2a62d262fb903 /Configure
parentaaf878cc97478b2f4e1f72f344f5ab6247a8084a (diff)
Add template reference processing.
Template references are words with double brackets, and refer to the same field in the target pointed at the the double bracketed word. For example, if a target's configuration has the following entry: 'cflags' => '-DFOO {{x86_debug}}' ... then {{x86_debug}} will be replaced with the 'cflags' value from target 'x86_debug'. Note: template references are resolved recursively, and circular references are not allowed Reviewed-by: Andy Polyakov <appro@openssl.org>
Diffstat (limited to 'Configure')
-rwxr-xr-xConfigure30
1 files changed, 30 insertions, 0 deletions
diff --git a/Configure b/Configure
index ed1e9859b2..481eeabbab 100755
--- a/Configure
+++ b/Configure
@@ -304,6 +304,31 @@ sub stringtohash {
return { map { shift @stringsequence => $_ } split /:/, $in };
};
+# Support function to look for and resolve template references.
+# It uses breadcrumbs to check for circular template references.
+#
+# Note: Any configuration value is also a template.
+sub lookup_templates {
+ my $tableref = shift;
+ my $target = shift;
+ my @breadcrumbs = @_;
+
+ if (grep { $_ eq $target } @breadcrumbs) {
+ die "Template loop! target backtrace:\n ",join("\n ",
+ $target,
+ @breadcrumbs),"\n";
+ }
+
+ foreach my $key (keys %{$tableref->{$target}}) {
+ my $value = $tableref->{$target}->{$key};
+ while ($value =~ /{{([-\w]+)}}/) {
+ lookup_templates($tableref, $1, $target, @breadcrumbs);
+ $value = $`.$tableref->{$1}->{$key}.$';
+ }
+ $tableref->{$target}->{$key} = $value;
+ }
+};
+
# Read configuration target stanzas from a file, so that people can have
# local files with their own definitions
@@ -445,6 +470,11 @@ sub read_config {
}
%table = (%table, %targets);
+
+ # Go through all new targets and resolve template references.
+ foreach (keys %targets) {
+ lookup_templates(\%table, $_);
+ }
}
my ($vol, $dir, $dummy) = File::Spec->splitpath($0);