]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Copyright (c) 2005 Vladimir Prus. |
2 | # | |
3 | # Use, modification and distribution is subject to the Boost Software | |
4 | # License Version 1.0. (See accompanying file LICENSE_1_0.txt or | |
5 | # http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | import modules ; | |
8 | ||
9 | # Set a value for a named option, to be used when not overridden on the command | |
10 | # line. | |
11 | rule set ( name : value ? ) | |
12 | { | |
13 | .option.$(name) = $(value) ; | |
14 | } | |
15 | ||
16 | rule get ( name : default-value ? : implied-value ? ) | |
17 | { | |
18 | local m = [ MATCH --$(name)=(.*) : [ modules.peek : ARGV ] ] ; | |
19 | if $(m) | |
20 | { | |
21 | return $(m[1]) ; | |
22 | } | |
23 | else | |
24 | { | |
25 | m = [ MATCH (--$(name)) : [ modules.peek : ARGV ] ] ; | |
26 | if $(m) && $(implied-value) | |
27 | { | |
28 | return $(implied-value) ; | |
29 | } | |
30 | else if $(.option.$(name)) | |
31 | { | |
32 | return $(.option.$(name)) ; | |
33 | } | |
34 | else | |
35 | { | |
36 | return $(default-value) ; | |
37 | } | |
38 | } | |
39 | } | |
40 | ||
41 | ||
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. | |
46 | # | |
47 | # Options take the general form of: --<name>[=<value>] [<value>] | |
48 | # | |
49 | rule process ( ) | |
50 | { | |
51 | local ARGV = [ modules.peek : ARGV ] ; | |
52 | local BOOST_BUILD_PATH = [ modules.peek : BOOST_BUILD_PATH ] ; | |
53 | ||
54 | local dont-build ; | |
55 | local args = $(ARGV) ; | |
56 | while $(args) | |
57 | { | |
58 | local arg = [ MATCH ^--(.*) : $(args[1]) ] ; | |
59 | while $(args[2-]) && ! $(arg) | |
60 | { | |
61 | args = $(args[2-]) ; | |
62 | arg = [ MATCH ^--(.*) : $(args[1]) ] ; | |
63 | } | |
64 | args = $(args[2-]) ; | |
65 | ||
66 | if $(arg) | |
67 | { | |
11fdf7f2 | 68 | local split = [ MATCH "^(([^-=]+)[^=]*)(=?)(.*)$" : $(arg) ] ; |
7c673cae FG |
69 | local full-name = $(split[1]) ; |
70 | local prefix = $(split[2]) ; | |
71 | local values ; | |
72 | ||
73 | if $(split[3]) | |
74 | { | |
75 | values = $(split[4]) ; | |
76 | } | |
77 | if $(args) && ! [ MATCH ^(--).* : $(args[1]) ] | |
78 | { | |
79 | values += $(args[1]) ; | |
80 | args = $(args[2-]) ; | |
81 | } | |
82 | ||
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 ] ; | |
88 | ||
89 | if $(option-files) | |
90 | { | |
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) ; | |
95 | ||
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) ] | |
100 | { | |
101 | dont-build += [ modules.call-in $(module-name) : process | |
102 | --$(full-name) : $(values) ] ; | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | return $(dont-build) ; | |
109 | } |