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.
100 local caller = [ project.current ] ;
104 .initialized = true ;
106 project.initialize $(__name__) ;
107 .project = [ project.current ] ;
111 local library-path = [ property.select <search> : $(options) ] ;
112 library-path = $(library-path:G=) ;
113 local include-path = [ property.select <include> : $(options) ] ;
114 include-path = $(include-path:G=) ;
115 local source-path = [ property.select <source> : $(options) ] ;
116 source-path = $(source-path:G=) ;
117 local library-name = [ property.select <name> : $(options) ] ;
118 library-name = $(library-name:G=) ;
119 local tag = [ property.select <tag> : $(options) ] ;
121 local build-name = [ property.select <build-name> : $(options) ] ;
122 build-name = $(build-name:G=) ;
124 condition = [ property-set.create $(requirements) ] ;
125 condition = [ property-set.create [ $(condition).base ] ] ;
127 local no-build-from-source ;
128 # Ignore environmental ZLIB_SOURCE if this initialization
129 # requested to search for a specific pre-built library.
130 if $(library-path) || $(include-path) || $(library-name)
132 if $(source-path) || $(tag) || $(build-name)
134 errors.user-error "incompatible options for zlib:"
135 [ property.select <search> <include> <name> : $(options) ] "and"
136 [ property.select <source> <tag> <build-name> : $(options) ] ;
140 no-build-from-source = true ;
144 source-path ?= [ modules.peek : ZLIB_SOURCE ] ;
146 if $(.configured.$(condition))
152 ECHO "notice: [zlib] zlib is already configured" ;
157 errors.user-error "zlib is already configured" ;
161 else if $(source-path) && ! $(no-build-from-source)
164 library-id = [ CALC $(library-id) + 1 ] ;
165 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
166 if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ]
168 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
170 sources = [ path.glob $(source-path) : $(sources) ] ;
173 ECHO "notice: [zlib] Building zlib from source as $(build-name)" ;
176 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
180 ECHO "notice: [zlib] found zlib source in $(source-path)" ;
184 ECHO "warning: [zlib] could not find zlib source in $(source-path)" ;
189 target = [ targets.create-typed-target LIB : $(.project)
190 : $(build-name).$(library-id)
194 <include>$(source-path)
195 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
196 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
197 <link>shared:<define>ZLIB_DLL
199 : <include>$(source-path) ] ;
202 local mt = [ new ac-library zlib : $(.project) : $(condition) ] ;
203 $(mt).set-header $(header) ;
204 $(mt).set-default-names $(names) ;
207 $(mt).set-target $(target) ;
209 targets.main-target-alternative $(mt) ;
213 ECHO "notice: [zlib] Using pre-installed library" ;
216 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
220 local mt = [ new ac-library zlib : $(.project) : $(condition) :
221 $(include-path) : $(library-path) : $(library-name) : $(root) ] ;
222 $(mt).set-header $(header) ;
223 $(mt).set-default-names $(names) ;
224 targets.main-target-alternative $(mt) ;
226 .configured.$(condition) = true ;