From f2e25504ecce901ca35456fba39817cdd27f1174 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 4 Feb 2005 20:20:08 +0000 Subject: [PATCH] General system for get-xxxx() constants implemented [SVN r27099] --- v2/util/os.jam | 53 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/v2/util/os.jam b/v2/util/os.jam index 19d96e653..b661e3823 100644 --- a/v2/util/os.jam +++ b/v2/util/os.jam @@ -4,13 +4,54 @@ # warranty, and with no claim as to its suitability for any purpose. import modules ; -name = [ modules.peek : OS ] ; -platform = [ modules.peek : OSPLAT ] ; -version = [ modules.peek : OSVER ] ; +.name = [ modules.peek : OS ] ; +.platform = [ modules.peek : OSPLAT ] ; +.version = [ modules.peek : OSVER ] ; -rule name { return $(name) ; } -rule platform { return $(platform) ; } -rule version { return $(version) ; } +local rule constant ( c ) +{ + # First look for platform-specific name, then general value + local variables = .$(c)-$(.name) .$(c) ; + local result = $($(variables)) ; + return $(result[1]) ; +} + +rule get-constant ( ) +{ + # Find the name of the constant being accessed, which is + # equal to the name used to invoke us. + local bt = [ BACKTRACE 1 ] ; + local rulename = [ MATCH ([^.]*)$ : $(bt[4]) ] ; + return [ constant $(rulename) ] ; +} + + +# export all the common constants +.constants = name platform version shared-library-path-variable path-separator ; +for local constant in $(.constants) +{ + IMPORT $(__name__) : get-constant : $(__name__) : $(constant) ; +} +EXPORT $(__name__) : $(.constants) ; + +.shared-library-path-variable-NT = PATH ; +.path-separator-NT = ";" ; +.expand-variable-prefix-NT = % ; +.expand-variable-suffix-NT = % ; + +.shared-library-path-variable = LD_LIBRARY_PATH ; +.path-separator = ":" ; +.expand-variable-prefix = $ ; +.expand-variable-suffix = "" ; + +# Return the string needed to represent the expansion of the named +# shell variable. +rule expand-variable ( variable ) +{ + local prefix = [ constant expand-variable-prefix ] ; + local suffix = [ constant expand-variable-suffix ] ; + return $(prefix)$(variable)$(suffix) ; +} # Returns true if running on windows, whether in cygwin or not. rule on-windows