]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Copyright (c) 2010 Vladimir Prus. |
2 | # Copyright (c) 2013 Steven Watanabe | |
3 | # | |
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) | |
7 | ||
8 | # Supports the zlib library | |
9 | # | |
10 | # After 'using zlib', the following targets are available: | |
11 | # | |
12 | # /zlib//zlib -- The zlib library | |
13 | ||
14 | import project ; | |
15 | import ac ; | |
16 | import errors ; | |
17 | import "class" : new ; | |
18 | import targets ; | |
19 | import path ; | |
20 | import modules ; | |
21 | import errors ; | |
22 | import indirect ; | |
23 | import property ; | |
24 | import property-set ; | |
25 | ||
26 | header = zlib.h ; | |
27 | names = z zlib zll zdll ; | |
28 | ||
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 ; | |
32 | ||
33 | library-id = 0 ; | |
34 | ||
35 | if --debug-configuration in [ modules.peek : ARGV ] | |
36 | { | |
37 | .debug = true ; | |
38 | } | |
39 | ||
40 | # Initializes the zlib library. | |
41 | # | |
42 | # zlib can be configured either to use pre-existing binaries | |
43 | # or to build the library from source. | |
44 | # | |
45 | # Options for configuring a prebuilt zlib:: | |
46 | # | |
47 | # <search> | |
48 | # The directory containing the zlib binaries. | |
49 | # <name> | |
50 | # Overrides the default library name. | |
51 | # <include> | |
52 | # The directory containing the zlib headers. | |
53 | # | |
54 | # If none of these options is specified, then the environmental | |
55 | # variables ZLIB_LIBRARY_PATH, ZLIB_NAME, and ZLIB_INCLUDE will | |
56 | # be used instead. | |
57 | # | |
58 | # Options for building zlib from source:: | |
59 | # | |
60 | # <source> | |
61 | # The zlib source directory. Defaults to the environmental variable | |
62 | # ZLIB_SOURCE. | |
63 | # <tag> | |
64 | # A rule which computes the actual name of the compiled | |
65 | # libraries based on the build properties. Ignored | |
66 | # when using precompiled binaries. | |
67 | # <build-name> | |
68 | # The base name to use for the compiled library. Ignored | |
69 | # when using precompiled binaries. | |
70 | # | |
71 | # Examples:: | |
72 | # | |
73 | # # Find zlib in the default system location | |
74 | # using zlib ; | |
75 | # # Build zlib from source | |
76 | # using zlib : 1.2.7 : <source>/home/steven/zlib-1.2.7 ; | |
77 | # # Find zlib in /usr/local | |
78 | # using zlib : 1.2.7 | |
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 ; | |
84 | # | |
85 | rule init ( | |
86 | version ? | |
87 | # The zlib version (currently ignored) | |
88 | ||
89 | : options * | |
90 | # A list of the options to use | |
91 | ||
92 | : requirements * | |
93 | # The requirements for the zlib target | |
94 | ||
95 | : is-default ? | |
96 | # Default configurations are only used when zlib | |
b32b8144 FG |
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. | |
7c673cae FG |
101 | ) |
102 | { | |
103 | local caller = [ project.current ] ; | |
104 | ||
105 | if ! $(.initialized) | |
106 | { | |
107 | .initialized = true ; | |
108 | ||
109 | project.initialize $(__name__) ; | |
110 | .project = [ project.current ] ; | |
111 | project zlib ; | |
112 | } | |
113 | ||
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) ] ; | |
123 | tag = $(tag:G=) ; | |
124 | local build-name = [ property.select <build-name> : $(options) ] ; | |
125 | build-name = $(build-name:G=) ; | |
126 | ||
b32b8144 FG |
127 | if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name) |
128 | { | |
129 | is-default = true ; | |
130 | } | |
131 | ||
7c673cae FG |
132 | condition = [ property-set.create $(requirements) ] ; |
133 | condition = [ property-set.create [ $(condition).base ] ] ; | |
134 | ||
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) | |
139 | { | |
140 | if $(source-path) || $(tag) || $(build-name) | |
141 | { | |
142 | errors.user-error "incompatible options for zlib:" | |
143 | [ property.select <search> <include> <name> : $(options) ] "and" | |
144 | [ property.select <source> <tag> <build-name> : $(options) ] ; | |
145 | } | |
146 | } | |
147 | else | |
148 | { | |
149 | source-path ?= [ modules.peek : ZLIB_SOURCE ] ; | |
150 | } | |
151 | ||
152 | if $(.configured.$(condition)) | |
153 | { | |
154 | if $(is-default) | |
155 | { | |
156 | if $(.debug) | |
157 | { | |
158 | ECHO "notice: [zlib] zlib is already configured" ; | |
159 | } | |
160 | } | |
161 | else | |
162 | { | |
163 | errors.user-error "zlib is already configured" ; | |
164 | } | |
165 | return ; | |
166 | } | |
167 | else if $(source-path) | |
168 | { | |
169 | build-name ?= z ; | |
170 | library-id = [ CALC $(library-id) + 1 ] ; | |
171 | tag = [ MATCH ^@?(.*)$ : $(tag) ] ; | |
172 | if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ] | |
173 | { | |
174 | tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ; | |
175 | } | |
176 | sources = [ path.glob $(source-path) : $(sources) ] ; | |
177 | if $(.debug) | |
178 | { | |
179 | ECHO "notice: [zlib] Building zlib from source as $(build-name)" ; | |
180 | if $(condition) | |
181 | { | |
182 | ECHO "notice: [zlib] Condition" [ $(condition).raw ] ; | |
183 | } | |
184 | if $(sources) | |
185 | { | |
186 | ECHO "notice: [zlib] found zlib source in $(source-path)" ; | |
187 | } | |
188 | else | |
189 | { | |
190 | ECHO "warning: [zlib] could not find zlib source in $(source-path)" ; | |
191 | } | |
192 | } | |
193 | local target ; | |
194 | if $(sources) | |
195 | { | |
196 | target = [ targets.create-typed-target LIB : $(.project) | |
197 | : $(build-name).$(library-id) | |
198 | : $(sources) | |
199 | : $(requirements) | |
200 | <tag>@$(tag) | |
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 | |
205 | : | |
206 | : <include>$(source-path) ] ; | |
207 | } | |
208 | ||
209 | local mt = [ new ac-library zlib : $(.project) : $(condition) ] ; | |
210 | $(mt).set-header $(header) ; | |
211 | $(mt).set-default-names $(names) ; | |
212 | if $(target) | |
213 | { | |
214 | $(mt).set-target $(target) ; | |
215 | } | |
216 | targets.main-target-alternative $(mt) ; | |
217 | } | |
218 | else | |
219 | { | |
220 | if $(.debug) | |
221 | { | |
222 | ECHO "notice: [zlib] Using pre-installed library" ; | |
223 | if $(condition) | |
224 | { | |
225 | ECHO "notice: [zlib] Condition" [ $(condition).raw ] ; | |
226 | } | |
227 | } | |
228 | ||
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) ; | |
234 | } | |
235 | .configured.$(condition) = true ; | |
236 | } |