1 # Copyright (c) 2005 Vladimir Prus.
3 # Use, modification and distribution is subject to the Boost Software
4 # License Version 1.0. (See accompanying file LICENSE.txt or
5 # https://www.bfgroup.xyz/b2/LICENSE.txt)
9 # Set a value for a named option, to be used when not overridden on the command
11 rule set ( name : value ? )
13 .option.$(name) = $(value) ;
16 rule get ( name : default-value ? : implied-value ? )
18 local m = [ MATCH --$(name)=(.*) : [ modules.peek : ARGV ] ] ;
25 m = [ MATCH (--$(name)) : [ modules.peek : ARGV ] ] ;
26 if $(m) && $(implied-value)
28 return $(implied-value) ;
30 else if $(.option.$(name))
32 return $(.option.$(name)) ;
36 return $(default-value) ;
42 # Check command-line args as soon as possible. For each option try to load
43 # module named after option. Is that succeeds, invoke 'process' rule in the
44 # module. The rule may return "true" to indicate that the regular build process
45 # should not be attempted.
47 # Options take the general form of: --<name>[=<value>] [<value>]
51 local ARGV = [ modules.peek : ARGV ] ;
52 local BOOST_BUILD_PATH = [ modules.peek : BOOST_BUILD_PATH ] ;
55 local args = $(ARGV) ;
58 local arg = [ MATCH ^--(.*) : $(args[1]) ] ;
59 while $(args[2-]) && ! $(arg)
62 arg = [ MATCH ^--(.*) : $(args[1]) ] ;
68 local split = [ MATCH "^(([^-=]+)[^=]*)(=?)(.*)$" : $(arg) ] ;
69 local full-name = $(split[1]) ;
70 local prefix = $(split[2]) ;
75 values = $(split[4]) ;
77 if $(args) && ! [ MATCH ^(--).* : $(args[1]) ]
79 values += $(args[1]) ;
83 # Jook in options subdirectories of BOOST_BUILD_PATH for modules
84 # matching the full option name and then its prefix.
85 local plugin-dir = options ;
86 local option-files = [ GLOB $(plugin-dir:D=$(BOOST_BUILD_PATH)) :
87 $(full-name).jam $(prefix).jam ] ;
91 # Load the file into a module named for the option.
92 local f = $(option-files[1]) ;
93 local module-name = --$(f:D=:S=) ;
94 modules.load $(module-name) : $(f:D=) : $(f:D) ;
96 # If there is a process rule, call it with the full option name
97 # and its value (if any). If there was no "=" in the option, the
98 # value will be empty.
99 if process in [ RULENAMES $(module-name) ]
101 dont-build += [ modules.call-in $(module-name) : process
102 --$(full-name) : $(values) ] ;
108 return $(dont-build) ;