# Copyright (c) 2010 Vladimir Prus. # # Use, modification and distribution is subject to the Boost Software # License Version 1.0. (See accompanying file LICENSE_1_0.txt or # http://www.boost.org/LICENSE_1_0.txt) # Supports the zlib library # # After 'using zlib', the following targets are available: # # /zlib//zlib -- The zlib library # In addition to direct purpose of supporting zlib, this module also # serves as canonical example of how third-party condiguration works # in Boost.Build. The operation is as follows # # - For each 'using zlib : condition ... : ...' we create a target alternative # for zlib, with the specified condition. # - There's one target alternative for 'zlib' with no specific condition # properties. # # Two invocations of 'using zlib' with the same condition but different # properties are not permitted, e.g.: # # using zlib : condition windows : include foo ; # using zlib : condition windows : include bar ; # # is in error. One exception is for empty condition, 'using' without any # parameters is overridable. That is: # # using zlib ; # using zlib : include foo ; # # Is OK then the first 'using' is ignored. Likewise if the order of the statements # is reversed. # # When 'zlib' target is built, a target alternative is selected as usual for # Boost.Build. The selected alternative is a custom target class, which: # # - calls ac.find-include-path to find header path. If explicit path is provided # in 'using', only that path is checked, and if no header is found there, error # is emitted. Otherwise, we check a directory specified using ZLIB_INCLUDE # environment variable, and failing that, in standard directories. # [TODO: document sysroot handling] # - calls ac.find-library to find the library, in an identical fashion. # import project ; import ac ; import errors ; import "class" : new ; import targets ; project.initialize $(__name__) ; project = [ project.current ] ; project zlib ; header = zlib.h ; names = z zlib zll zdll ; .default-alternative = [ new ac-library zlib : $(project) ] ; $(.default-alternative).set-header $(header) ; $(.default-alternative).set-default-names $(names) ; targets.main-target-alternative $(.default-alternative) ; rule init ( * : * ) { if ! $(condition) { # Special case the no-condition case so that 'using' without parameters # can mix with more specific 'using'. $(.default-alternative).reconfigure $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; } else { # FIXME: consider if we should allow overriding definitions for a given # condition -- e.g. project-config.jam might want to override whatever is # in user-config.jam. local mt = [ new ac-library zlib : $(project) : $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; $(mt).set-header $(header) ; $(mt).set-default-names $(names) ; targets.main-target-alternative $(mt) ; } }