summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/config_mk.pl
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-05-13 10:20:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:53:36 -0500
commitf236700ef67d4f93ec56ec7808584552e94e0dfe (patch)
tree3572ba5a82860e9dc60661161997b77704867cdc /source4/build/smb_build/config_mk.pl
parentb2d1f7890765fca5a119d43f4906e885c245005f (diff)
downloadsamba-f236700ef67d4f93ec56ec7808584552e94e0dfe.tar.gz
samba-f236700ef67d4f93ec56ec7808584552e94e0dfe.tar.bz2
samba-f236700ef67d4f93ec56ec7808584552e94e0dfe.zip
r665: merge over the new build system from my tmp branch
to the main SAMBA_4_0 tree. NOTE: that it's not completely ready, but it's functional:-) metze (This used to be commit c78a2ddb28ec50d6570a83b1f66f18a5c3621731)
Diffstat (limited to 'source4/build/smb_build/config_mk.pl')
-rw-r--r--source4/build/smb_build/config_mk.pl434
1 files changed, 434 insertions, 0 deletions
diff --git a/source4/build/smb_build/config_mk.pl b/source4/build/smb_build/config_mk.pl
new file mode 100644
index 0000000000..ba580c7c65
--- /dev/null
+++ b/source4/build/smb_build/config_mk.pl
@@ -0,0 +1,434 @@
+###########################################################
+### SMB Build System ###
+### - config.mk parsing functions ###
+### ###
+### Copyright (C) Stefan (metze) Metzmacher 2004 ###
+### Released under the GNU GPL ###
+###########################################################
+
+###########################################################
+# The parsing function which parses the file
+#
+# $result = _parse_config_mk($filename)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $result - the resulting structure
+#
+# $result->{ERROR_CODE} - the error_code, '0' means success
+# $result->{ERROR_STR} - the error string
+#
+# $result->{$key}{KEY} - the key == the variable which was parsed
+# $result->{$key}{VAL} - the value of the variable
+sub _parse_config_mk($)
+{
+ my $filename = shift;
+ my $result;
+ my $linenum = -1;
+ my $waiting = 0;
+ my $section = "GLOBAL";
+ my $key;
+
+ $result->{ERROR_CODE} = -1;
+
+ open(CONFIG_MK, "< $filename") || die ("Can't open $filename\n");
+
+ while (<CONFIG_MK>) {
+ my $line = $_;
+ my $val;
+
+ $linenum++;
+
+ #
+ # lines beginnig with '#' are ignored
+ #
+ if ($line =~ /^\#.*$/) {
+ next;
+ }
+
+ #
+ #
+ #
+ if (($waiting == 0) && ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)) {
+ $section = $1;
+ next;
+ }
+
+ #
+ # 1.) lines with an aplhanumeric character indicate
+ # a new variable,
+ # 2.) followed by zero or more whitespaces or tabs
+ # 3.) then one '=' character
+ # 4.) followed by the value of the variable
+ # 5.) a newline ('\n') can be escaped by a '\' before the newline
+ # and the next line needs to start with a tab ('\t')
+ #
+ if (($waiting == 0) && ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/)) {
+ $key = $1;
+ $val = $2;
+
+ #
+ # when we have a '\' before the newline
+ # then skip it and wait for the next line.
+ #
+ if ($val =~ /(.*)(\\)$/) {
+ $val = $1;
+ $waiting = 1;
+ } else {
+ $waiting = 0;
+ }
+
+ $result->{$section}{$key}{KEY} = $key;
+ $result->{$section}{$key}{VAL} = $val;
+ next;
+ }
+
+ #
+ # when we are waiting for a value to continue then
+ # check if it has a leading tab.
+ #
+ if (($waiting == 1) && ($line =~ /^\t(.*)$/)) {
+ $val = $1;
+
+ #
+ # when we have a '\' before the newline
+ # then skip it and wait for the next line.
+ #
+ if ($val =~ /(.*)( \\)$/) {
+ $val = $1;
+ $waiting = 1;
+ } else {
+ $waiting = 0;
+ }
+
+ $result->{$section}{$key}{VAL} .= " ";
+ $result->{$section}{$key}{VAL} .= $val;
+ next;
+ }
+
+ #
+ # catch empty lines they're ignored
+ # and we're no longer waiting for the value to continue
+ #
+ if ($line =~ /^$/) {
+ $waiting = 0;
+ next;
+ }
+
+ close(CONFIG_MK);
+
+ $result->{ERROR_STR} = "Bad line while parsing $filename\n$filename:$linenum: $line";
+
+ return $result;
+ }
+
+ close(CONFIG_MK);
+
+ $result->{ERROR_CODE} = 0;
+
+ return $result;
+}
+
+###########################################################
+# A caching function to avoid to parse
+# a file twice or more
+#
+# $result = _get_parse_results($filename)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $result - the resulting structure
+#
+# $result->{ERROR_CODE} - the error_code, '0' means success
+# $result->{ERROR_STR} - the error string
+#
+# $result->{$key}{KEY} - the key == the variable which was parsed
+# $result->{$key}{VAL} - the value of the variable
+my $_get_parse_results_cache;
+sub _get_parse_results($)
+{
+ my $filename = shift;
+
+ if ((!defined($_get_parse_results_cache->{$filename}{ERROR_CODE}))
+ ||($_get_parse_results_cache->{$filename}{ERROR_CODE} != 0)) {
+ $_get_parse_results_cache->{$filename} = _parse_config_mk($filename);
+ }
+
+ return $_get_parse_results_cache->{$filename};
+}
+
+###########################################################
+# The fetching function to fetch the value of a variable
+# out of the file
+#
+# $value = _fetch_var_from_config_mk($filename,$section,$variable)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $section - the section name of the variable
+#
+# $variable - the variable name of which we want the value
+#
+# $value - the value of the variable
+sub _fetch_var_from_config_mk($$$)
+{
+ my $filename = shift;
+ my $section = shift;
+ my $key = shift;
+ my $val = "";
+ my $result;
+
+ $result = _get_parse_results($filename);
+
+ if ($result->{ERROR_CODE} != 0) {
+ die ($result->{ERROR_STR});
+ }
+
+ if (defined($result->{$section}{$key})) {
+ $val = $result->{$section}{$key}{VAL};
+ } elsif (defined($result->{DEFAULT}{$key})) {
+ $val = $result->{DEFAULT}{$key}{VAL};
+ }
+
+ return $val;
+}
+
+###########################################################
+# The fetching function to fetch the array of values of a variable
+# out of the file
+#
+# $array = _fetch_array_from_config_mk($filename,$section,$variable)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $section - the section name of the variable
+#
+# $variable - the variable name of which we want the value
+#
+# $array - the array of values of the variable
+sub _fetch_array_from_config_mk($$$)
+{
+ my $filename = shift;
+ my $section = shift;
+ my $key = shift;
+ my @val = ();
+ my $result;
+
+ $result = _get_parse_results($filename);
+
+ if ($result->{ERROR_CODE} != 0) {
+ die ($result->{ERROR_STR});
+ }
+
+ if (defined($result->{$section}{$key})) {
+ @val = str2array($result->{$section}{$key}{VAL});
+ } elsif (defined($result->{DEFAULT}{$key})) {
+ @val = str2array($result->{DEFAULT}{$key}{VAL});
+ }
+
+ return @val;
+}
+
+###########################################################
+# A function for fetching MODULE_<module>_<parameter>
+# variables out of a config.mk file
+#
+# $value = module_get_var($filename,$module,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $module - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $value - the value of the variable
+sub module_get_var($$$)
+{
+ my $filename = shift;
+ my $module = shift;
+ my $var = shift;
+
+ my $section = "MODULE::".$module;
+
+ return _fetch_var_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching MODULE_<module>_<parameter>
+# variables out of a config.mk file
+#
+# $array = module_get_array($filename,$module,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $module - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $array - the array of values of the variable
+sub module_get_array($$$)
+{
+ my $filename = shift;
+ my $module = shift;
+ my $var = shift;
+
+ my $section = "MODULE::".$module;
+
+ return _fetch_array_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching SUBSYSTEM_<subsystem>_<parameter>
+# variables out of a config.mk file
+#
+# $value = subsystem_get_var($filename,$subsystem,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $subsystem - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $value - the value of the variable
+sub subsystem_get_var($$$)
+{
+ my $filename = shift;
+ my $subsystem = shift;
+ my $var = shift;
+
+ my $section = "SUBSYSTEM::".$subsystem;
+
+ return _fetch_var_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching SUBSYSTEM_<subsystem>_<parameter>
+# variables out of a config.mk file
+#
+# $array = subsystem_get_array($filename,$subsystem,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $subsystem - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $array - the array of values of the variable
+sub subsystem_get_array($$$)
+{
+ my $filename = shift;
+ my $subsystem = shift;
+ my $var = shift;
+
+ my $section = "SUBSYSTEM::".$subsystem;
+
+ return _fetch_array_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching LIBRARY_<library>_<parameter>
+# variables out of a config.mk file
+#
+# $value = library_get_var($filename,$library,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $library - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $value - the value of the variable
+sub library_get_var($$$)
+{
+ my $filename = shift;
+ my $library = shift;
+ my $var = shift;
+
+ my $section = "LIBRARY::".$library;
+
+ return _fetch_var_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching LIBRARY_<library>_<parameter>
+# variables out of a config.mk file
+#
+# $array = library_get_array($filename,$library,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $library - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $array - the array of values of the variable
+sub library_get_array($$$)
+{
+ my $filename = shift;
+ my $library = shift;
+ my $var = shift;
+
+ my $section = "LIBRARY::".$library;
+
+ return _fetch_array_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching BINARY_<binary>_<parameter>
+# variables out of a config.mk file
+#
+# $value = binary_get_var($filename,$binary,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $binary - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $value - the value of the variable
+sub binary_get_var($$$)
+{
+ my $filename = shift;
+ my $binary = shift;
+ my $var = shift;
+
+ my $section = "BINARY::".$binary;
+
+ return _fetch_var_from_config_mk($filename,$section,$var);
+}
+
+###########################################################
+# A function for fetching BINARY_<binary>_<parameter>
+# variables out of a config.mk file
+#
+# $array = binary_get_array($filename,$binary,$parameter)
+#
+# $filename - the path of the config.mk file
+# which should be parsed
+#
+# $binary - the middle part of the variable name of which we want the value
+#
+# $parameter - the last part of the variable name of which we want the value
+#
+# $array - the array of values of the variable
+sub binary_get_array($$$)
+{
+ my $filename = shift;
+ my $binary = shift;
+ my $var = shift;
+
+ my $section = "BINARY::".$binary;
+
+ return _fetch_array_from_config_mk($filename,$section,$var);
+}