1 # Copyright (c) 2010 Vladimir Prus.
2 # Copyright (c) 2013 Steven Watanabe
4 # Use, modification and distribution is subject to the Boost Software
5 # License Version 1.0. (See accompanying file LICENSE_1_0.txt or
6 # http://www.boost.org/LICENSE_1_0.txt)
8 # Supports the zlib library
10 # After 'using zlib', the following targets are available:
12 # /zlib//zlib -- The zlib library
18 import "class" : new ;
28 names = z zlib zll zdll ;
30 sources = adler32.c compress.c
31 crc32.c deflate.c gzclose.c gzio.c gzlib.c gzread.c gzwrite.c
32 infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c ;
36 if --debug-configuration in [ modules.peek : ARGV ]
41 # Initializes the zlib library.
43 # zlib can be configured either to use pre-existing binaries
44 # or to build the library from source.
46 # Options for configuring a prebuilt zlib::
49 # The directory containing the zlib binaries.
51 # Overrides the default library name.
53 # The directory containing the zlib headers.
55 # If none of these options is specified, then the environmental
56 # variables ZLIB_LIBRARY_PATH, ZLIB_NAME, and ZLIB_INCLUDE will
59 # Options for building zlib from source::
62 # The zlib source directory. Defaults to the environmental variable
65 # A rule which computes the actual name of the compiled
66 # libraries based on the build properties. Ignored
67 # when using precompiled binaries.
69 # The base name to use for the compiled library. Ignored
70 # when using precompiled binaries.
74 # # Find zlib in the default system location
76 # # Build zlib from source
77 # using zlib : 1.2.7 : <source>/home/steven/zlib-1.2.7 ;
78 # # Find zlib in /usr/local
80 # : <include>/usr/local/include <search>/usr/local/lib ;
81 # # Build zlib from source for msvc and find
82 # # prebuilt binaries for gcc.
83 # using zlib : 1.2.7 : <source>C:/Devel/src/zlib-1.2.7 : <toolset>msvc ;
84 # using zlib : 1.2.7 : : <toolset>gcc ;
88 # The zlib version (currently ignored)
91 # A list of the options to use
94 # The requirements for the zlib target
97 # Default configurations are only used when zlib
98 # has not yet been configured. This option is
99 # deprecated. A configuration will be treated
100 # as a default when none of <include>, <search>,
101 # <name>, and <source> are present.
104 local caller = [ project.current ] ;
108 .initialized = true ;
110 project.initialize $(__name__) ;
111 .project = [ project.current ] ;
115 local library-path = [ feature.get-values <search> : $(options) ] ;
116 local include-path = [ feature.get-values <include> : $(options) ] ;
117 local source-path = [ feature.get-values <source> : $(options) ] ;
118 local library-name = [ feature.get-values <name> : $(options) ] ;
119 local tag = [ feature.get-values <tag> : $(options) ] ;
120 local build-name = [ feature.get-values <build-name> : $(options) ] ;
122 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
127 condition = [ property-set.create $(requirements) ] ;
128 condition = [ property-set.create [ $(condition).base ] ] ;
130 # Ignore environmental ZLIB_SOURCE if this initialization
131 # requested to search for a specific pre-built library.
132 if $(library-path) || $(include-path) || $(library-name)
134 if $(source-path) || $(tag) || $(build-name)
136 errors.user-error "incompatible options for zlib:"
137 [ property.select <search> <include> <name> : $(options) ] "and"
138 [ property.select <source> <tag> <build-name> : $(options) ] ;
143 source-path ?= [ os.environ ZLIB_SOURCE ] ;
146 source-path = [ path.root [ path.make $(source-path) ]
151 if $(.configured.$(condition))
157 ECHO "notice: [zlib] zlib is already configured" ;
162 errors.user-error "zlib is already configured" ;
166 else if $(source-path)
169 library-id = [ CALC $(library-id) + 1 ] ;
170 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
173 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
175 sources = [ path.glob $(source-path) : $(sources) ] ;
178 ECHO "notice: [zlib] Building zlib from source as $(build-name)" ;
181 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
185 ECHO "notice: [zlib] found zlib source in $(source-path)" ;
189 ECHO "warning: [zlib] could not find zlib source in $(source-path)" ;
195 target = [ targets.create-typed-target LIB : $(.project)
196 : $(build-name).$(library-id)
200 <include>$(source-path)
201 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
202 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
203 <link>shared:<define>ZLIB_DLL
205 : <include>$(source-path) ] ;
208 local mt = [ new ac-library zlib : $(.project) : $(condition) ] ;
209 $(mt).set-header $(header) ;
210 $(mt).set-default-names $(names) ;
213 $(mt).set-target $(target) ;
215 targets.main-target-alternative $(mt) ;
221 ECHO "notice: [zlib] Using pre-installed library" ;
224 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
228 local mt = [ new ac-library zlib : $(.project) : $(condition) :
229 $(include-path) : $(library-path) : $(library-name) ] ;
230 $(mt).set-header $(header) ;
231 $(mt).set-default-names $(names) ;
232 targets.main-target-alternative $(mt) ;
234 .configured.$(condition) = true ;