@@ -13,6 +13,7 @@ import feature ;
1313import os ;
1414import param ;
1515import project ;
16+ import property-set ;
1617import regex ;
1718import sequence ;
1819import string ;
@@ -96,7 +97,8 @@ pkg-config.import my-package
9697|# # end::doc[]
9798
9899
99- rule import
100+ # will be re-exported as 'import'
101+ local rule do-import
100102 ( target-name
101103 : sources *
102104 : requirements *
@@ -127,7 +129,7 @@ with the `using` rule:
127129
128130[source, jam]
129131----
130- using pkg-config : [config] : [command] ... : [ options ] ... ;
132+ using pkg-config : [config] : [command] ... : [ options ] ... : [condition] ... ;
131133----
132134
133135
@@ -149,20 +151,57 @@ using pkg-config : [config] : [command] ... : [ options ] ... ;
149151 multiple occurences are allowed.
150152 * `<variable>`: adds a variable definition argument to command invocation;
151153 multiple occurences are allowed.
154+ * `condition`: properties that distinguish this configuration.
152155
153156|# # end::doc[]
154157
155- rule init ( config ? : command * : options * )
158+ rule init ( config ? : command * : options * : condition * )
156159{
157- config ?= [ default-config ] ;
160+ echo using pkg-config $(config) ":" $(command) ":" $(options) ;
161+
162+ if ! $(.initialized)
163+ {
164+ .initialized = true ;
165+
166+ project.initialize $(__name__) ;
167+ project $(__name__) ;
168+
169+ # project.initialize replaces import rule in this module, so we
170+ # put it back
171+ IMPORT $(__name__) : do-import : $(__name__) : import ;
172+ EXPORT $(__name__) : import ;
173+ }
174+
175+ if ! $(config)
176+ {
177+ config = [ default-config ] ;
178+ if $(config) in [ $(.configs).used ]
179+ {
180+ config = ;
181+ }
182+ }
183+ if ! $(config) && ! $(condition)
184+ {
185+ return ;
186+ }
158187
159188 local tool = [ os.environ PKG_CONFIG ] ;
160189 tool ?= pkg-config ;
161- command =
162- [ common.get-invocation-command pkg-config : $(tool) : $(command) ] ;
190+ command = [ common.get-invocation-command pkg-config : $(tool)
191+ : $(command) ] ;
163192
164193 configure $(config) : $(command) : $(options) ;
165194 $(.configs).use $(config) ;
195+
196+ local project = [ project.target $(__name__) ] ;
197+ targets.main-target-alternative
198+ [ new alias-target-class prefix
199+ : $(project)
200+ :
201+ : [ property-set.create $(condition) ]
202+ :
203+ : [ property-set.create <pkg-config>$(config) ]
204+ ] ;
166205}
167206
168207
@@ -223,7 +262,7 @@ class pkg-config-target : alias-target-class
223262
224263 rule construct ( name : sources * : property-set )
225264 {
226- local config = [ $(property-set).get <pkg-config> ] ;
265+ local config = [ get-config $(property-set) ] ;
227266 local args = [ common-arguments $(name) : $(property-set) ] ;
228267 return
229268 [ property-set.create
@@ -234,7 +273,7 @@ class pkg-config-target : alias-target-class
234273
235274 rule version ( property-set )
236275 {
237- local config = [ $(property-set).get <pkg-config> ] ;
276+ local config = [ get-config $(property-set) ] ;
238277 local args = [ common-arguments [ name ] : $(property-set) ] ;
239278 local version = [ pkg-config.run $(config) : --modversion $(args) ] ;
240279 return [ regex.split $(version) "\\." ] ;
@@ -300,6 +339,21 @@ class pkg-config-target : alias-target-class
300339 local flags = [ pkg-config.run $(config) : --cflags $(args) ] ;
301340 return <cflags>$(flags) ;
302341 }
342+
343+ local rule get-config ( property-set )
344+ {
345+ local result = [ $(property-set).get <pkg-config> ] ;
346+ if $(result)
347+ {
348+ return $(result) ;
349+ }
350+
351+
352+ local project = [ project.target pkg-config ] ;
353+ property-set = [ targets.generate-from-reference /pkg-config//prefix
354+ : $(project) : $(property-set) ] ;
355+ return [ $(property-set[1]).get <pkg-config> ] ;
356+ }
303357}
304358
305359
0 commit comments