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
17 import "class" : new ;
27 names = z zlib zll zdll ;
29 sources = adler32.c compress.c
30 crc32.c deflate.c gzclose.c gzio.c gzlib.c gzread.c gzwrite.c
31 infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c ;
35 if --debug-configuration in [ modules.peek : ARGV ]
40 # Initializes the zlib library.
42 # zlib can be configured either to use pre-existing binaries
43 # or to build the library from source.
45 # Options for configuring a prebuilt zlib::
48 # The directory containing the zlib binaries.
50 # Overrides the default library name.
52 # The directory containing the zlib headers.
54 # If none of these options is specified, then the environmental
55 # variables ZLIB_LIBRARY_PATH, ZLIB_NAME, and ZLIB_INCLUDE will
58 # Options for building zlib from source::
61 # The zlib source directory. Defaults to the environmental variable
64 # A rule which computes the actual name of the compiled
65 # libraries based on the build properties. Ignored
66 # when using precompiled binaries.
68 # The base name to use for the compiled library. Ignored
69 # when using precompiled binaries.
73 # # Find zlib in the default system location
75 # # Build zlib from source
76 # using zlib : 1.2.7 : <source>/home/steven/zlib-1.2.7 ;
77 # # Find zlib in /usr/local
79 # : <include>/usr/local/include <search>/usr/local/lib ;
80 # # Build zlib from source for msvc and find
81 # # prebuilt binaries for gcc.
82 # using zlib : 1.2.7 : <source>C:/Devel/src/zlib-1.2.7 : <toolset>msvc ;
83 # using zlib : 1.2.7 : : <toolset>gcc ;
87 # The zlib version (currently ignored)
90 # A list of the options to use
93 # The requirements for the zlib target
96 # Default configurations are only used when zlib
97 # has not yet been configured. This option is
98 # deprecated. A configuration will be treated
99 # as a default when none of <include>, <search>,
100 # <name>, and <source> are present.
103 local caller = [ project.current ] ;
107 .initialized = true ;
109 project.initialize $(__name__) ;
110 .project = [ project.current ] ;
114 local library-path = [ property.select <search> : $(options) ] ;
115 library-path = $(library-path:G=) ;
116 local include-path = [ property.select <include> : $(options) ] ;
117 include-path = $(include-path:G=) ;
118 local source-path = [ property.select <source> : $(options) ] ;
119 source-path = $(source-path:G=) ;
120 local library-name = [ property.select <name> : $(options) ] ;
121 library-name = $(library-name:G=) ;
122 local tag = [ property.select <tag> : $(options) ] ;
124 local build-name = [ property.select <build-name> : $(options) ] ;
125 build-name = $(build-name:G=) ;
127 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
132 condition = [ property-set.create $(requirements) ] ;
133 condition = [ property-set.create [ $(condition).base ] ] ;
135 local no-build-from-source ;
136 # Ignore environmental ZLIB_SOURCE if this initialization
137 # requested to search for a specific pre-built library.
138 if $(library-path) || $(include-path) || $(library-name)
140 if $(source-path) || $(tag) || $(build-name)
142 errors.user-error "incompatible options for zlib:"
143 [ property.select <search> <include> <name> : $(options) ] "and"
144 [ property.select <source> <tag> <build-name> : $(options) ] ;
149 source-path ?= [ modules.peek : ZLIB_SOURCE ] ;
152 if $(.configured.$(condition))
158 ECHO "notice: [zlib] zlib is already configured" ;
163 errors.user-error "zlib is already configured" ;
167 else if $(source-path)
170 library-id = [ CALC $(library-id) + 1 ] ;
171 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
172 if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ]
174 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
176 sources = [ path.glob $(source-path) : $(sources) ] ;
179 ECHO "notice: [zlib] Building zlib from source as $(build-name)" ;
182 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
186 ECHO "notice: [zlib] found zlib source in $(source-path)" ;
190 ECHO "warning: [zlib] could not find zlib source in $(source-path)" ;
196 target = [ targets.create-typed-target LIB : $(.project)
197 : $(build-name).$(library-id)
201 <include>$(source-path)
202 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
203 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
204 <link>shared:<define>ZLIB_DLL
206 : <include>$(source-path) ] ;
209 local mt = [ new ac-library zlib : $(.project) : $(condition) ] ;
210 $(mt).set-header $(header) ;
211 $(mt).set-default-names $(names) ;
214 $(mt).set-target $(target) ;
216 targets.main-target-alternative $(mt) ;
222 ECHO "notice: [zlib] Using pre-installed library" ;
225 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
229 local mt = [ new ac-library zlib : $(.project) : $(condition) :
230 $(include-path) : $(library-path) : $(library-name) ] ;
231 $(mt).set-header $(header) ;
232 $(mt).set-default-names $(names) ;
233 targets.main-target-alternative $(mt) ;
235 .configured.$(condition) = true ;