]>
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 bzip library | |
9 | # | |
10 | # After 'using bzip2', the following targets are available: | |
11 | # | |
12 | # /bzip2//bzip2 -- The bzip 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 make ; | |
24 | import os ; | |
25 | import print ; | |
26 | import property ; | |
27 | import property-set ; | |
28 | ||
29 | header = bzlib.h ; | |
30 | names = bz2 ; | |
31 | ||
32 | sources = blocksort.c bzlib.c compress.c crctable.c | |
33 | decompress.c huffman.c randtable.c ; | |
34 | ||
35 | library-id = 0 ; | |
36 | ||
37 | if --debug-configuration in [ modules.peek : ARGV ] | |
38 | { | |
39 | .debug = true ; | |
40 | } | |
41 | ||
42 | # Initializes the bzip library. | |
43 | # | |
44 | # bzip can be configured either to use pre-existing binaries | |
45 | # or to build the library from source. | |
46 | # | |
47 | # Options for configuring a prebuilt bzip:: | |
48 | # | |
49 | # <search> | |
50 | # The directory containing the bzip binaries. | |
51 | # <name> | |
52 | # Overrides the default library name. | |
53 | # <include> | |
54 | # The directory containing the bzip headers. | |
55 | # | |
56 | # If none of these options is specified, then the environmental | |
57 | # variables BZIP2_LIBRARY_PATH, BZIP2_NAME, and BZIP2_INCLUDE will | |
58 | # be used instead. | |
59 | # | |
60 | # Options for building bzip from source:: | |
61 | # | |
62 | # <source> | |
63 | # The bzip source directory. Defaults to the environmental variable | |
64 | # BZIP2_SOURCE. | |
65 | # <tag> | |
66 | # A rule which computes the actual name of the compiled | |
67 | # libraries based on the build properties. Ignored | |
68 | # when using precompiled binaries. | |
69 | # <build-name> | |
70 | # The base name to use for the compiled library. Ignored | |
71 | # when using precompiled binaries. | |
72 | # | |
73 | # Examples:: | |
74 | # | |
75 | # # Find bzip in the default system location | |
76 | # using bzip2 ; | |
77 | # # Build bzip from source | |
78 | # using bzip2 : 1.0.6 : <source>/home/sergey/src/bzip2-1.0.6 ; | |
79 | # # Find bzip in /usr/local | |
80 | # using bzip2 : 1.0.6 | |
81 | # : <include>/usr/local/include <search>/usr/local/lib ; | |
82 | # # Build bzip from source for msvc and find | |
83 | # # prebuilt binaries for gcc. | |
84 | # using bzip2 : 1.0.6 : <source>C:/Devel/src/bzip2-1.0.6 : <toolset>msvc ; | |
85 | # using bzip2 : 1.0.6 : : <toolset>gcc ; | |
86 | # | |
87 | rule init ( | |
88 | version ? | |
89 | # The bzip version (currently ignored) | |
90 | ||
91 | : options * | |
92 | # A list of the options to use | |
93 | ||
94 | : requirements * | |
95 | # The requirements for the bzip target | |
96 | ||
97 | : is-default ? | |
98 | # Default configurations are only used when bzip | |
b32b8144 FG |
99 | # has not yet been configured. This option is |
100 | # deprecated. A configuration will be treated | |
101 | # as a default when none of <include>, <search>, | |
102 | # <name>, and <source> are present. | |
7c673cae FG |
103 | ) |
104 | { | |
105 | local caller = [ project.current ] ; | |
106 | ||
107 | if ! $(.initialized) | |
108 | { | |
109 | .initialized = true ; | |
110 | ||
111 | project.initialize $(__name__) ; | |
112 | .project = [ project.current ] ; | |
113 | project bzip2 ; | |
114 | } | |
115 | ||
116 | local library-path = [ property.select <search> : $(options) ] ; | |
117 | library-path = $(library-path:G=) ; | |
118 | local include-path = [ property.select <include> : $(options) ] ; | |
119 | include-path = $(include-path:G=) ; | |
120 | local source-path = [ property.select <source> : $(options) ] ; | |
121 | source-path = $(source-path:G=) ; | |
122 | local library-name = [ property.select <name> : $(options) ] ; | |
123 | library-name = $(library-name:G=) ; | |
124 | local tag = [ property.select <tag> : $(options) ] ; | |
125 | tag = $(tag:G=) ; | |
126 | local build-name = [ property.select <build-name> : $(options) ] ; | |
127 | build-name = $(build-name:G=) ; | |
128 | ||
b32b8144 FG |
129 | if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name) |
130 | { | |
131 | is-default = true ; | |
132 | } | |
133 | ||
7c673cae FG |
134 | condition = [ property-set.create $(requirements) ] ; |
135 | condition = [ property-set.create [ $(condition).base ] ] ; | |
136 | ||
137 | local no-build-from-source ; | |
138 | # Ignore environmental BZIP2_SOURCE if this initialization | |
139 | # requested to search for a specific pre-built library. | |
140 | if $(library-path) || $(include-path) || $(library-name) | |
141 | { | |
142 | if $(source-path) || $(tag) || $(build-name) | |
143 | { | |
144 | errors.user-error "incompatible options for bzip2:" | |
145 | [ property.select <search> <include> <name> : $(options) ] "and" | |
146 | [ property.select <source> <tag> <build-name> : $(options) ] ; | |
147 | } | |
148 | } | |
149 | else | |
150 | { | |
151 | source-path ?= [ modules.peek : BZIP2_SOURCE ] ; | |
152 | } | |
153 | ||
154 | if $(.configured.$(condition)) | |
155 | { | |
156 | if $(is-default) | |
157 | { | |
158 | if $(.debug) | |
159 | { | |
160 | ECHO "notice: [bzip2] bzip is already configured" ; | |
161 | } | |
162 | } | |
163 | else | |
164 | { | |
165 | errors.user-error "bzip is already configured" ; | |
166 | } | |
167 | return ; | |
168 | } | |
169 | else if $(source-path) | |
170 | { | |
171 | build-name ?= bz2 ; | |
172 | library-id = [ CALC $(library-id) + 1 ] ; | |
173 | tag = [ MATCH ^@?(.*)$ : $(tag) ] ; | |
174 | if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ] | |
175 | { | |
176 | tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ; | |
177 | } | |
178 | sources = [ path.glob $(source-path) : $(sources) ] ; | |
179 | def-file = [ path.glob $(source-path) : libbz2.def ] ; | |
180 | if $(.debug) | |
181 | { | |
182 | ECHO "notice: [bzip2] Building bzip from source as $(build-name)" ; | |
183 | if $(condition) | |
184 | { | |
185 | ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ; | |
186 | } | |
187 | if $(sources) | |
188 | { | |
189 | ECHO "notice: [bzip2] found bzip source in $(source-path)" ; | |
190 | } | |
191 | else | |
192 | { | |
193 | ECHO "warning: [bzip2] could not find bzip source in $(source-path)" ; | |
194 | } | |
195 | } | |
196 | local target ; | |
197 | if $(sources) | |
198 | { | |
199 | if ! $(.def-file-target) | |
200 | { | |
201 | .def-file-target = [ targets.create-metatarget make-target-class | |
202 | : $(.project) : libbz2.def : $(def-file) | |
203 | : <action>@bzip2.make-bz2-def-file ] | |
204 | ; | |
205 | } | |
206 | target = [ targets.create-typed-target LIB : $(.project) | |
207 | : $(build-name).$(library-id) | |
208 | : $(sources) | |
209 | : $(requirements) | |
210 | <tag>@$(tag) | |
211 | <include>$(source-path) | |
212 | <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE | |
213 | <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE | |
214 | <link>shared:<def-file>libbz2.def | |
215 | : | |
216 | : <include>$(source-path) ] ; | |
217 | } | |
218 | ||
219 | local mt = [ new ac-library bzip2 : $(.project) : $(condition) ] ; | |
220 | $(mt).set-header $(header) ; | |
221 | $(mt).set-default-names $(names) ; | |
222 | if $(target) | |
223 | { | |
224 | $(mt).set-target $(target) ; | |
225 | } | |
226 | targets.main-target-alternative $(mt) ; | |
227 | } | |
228 | else | |
229 | { | |
230 | if $(.debug) | |
231 | { | |
232 | ECHO "notice: [bzip2] Using pre-installed library" ; | |
233 | if $(condition) | |
234 | { | |
235 | ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ; | |
236 | } | |
237 | } | |
238 | ||
239 | local mt = [ new ac-library bzip2 : $(.project) : $(condition) : | |
240 | $(include-path) : $(library-path) : $(library-name) ] ; | |
241 | $(mt).set-header $(header) ; | |
242 | $(mt).set-default-names $(names) ; | |
243 | targets.main-target-alternative $(mt) ; | |
244 | } | |
245 | .configured.$(condition) = true ; | |
246 | } | |
247 | ||
248 | if [ os.name ] = NT | |
249 | { | |
250 | local rule read-file ( file ) | |
251 | { | |
252 | return [ SPLIT_BY_CHARACTERS [ SHELL "type \"$(file:G=)\" 2>nul" ] : "\n" ] ; | |
253 | } | |
254 | } | |
255 | else if [ os.name ] = VMS | |
256 | { | |
257 | local rule read-file ( file ) | |
258 | { | |
259 | return [ SPLIT_BY_CHARACTERS [ SHELL "PIPE TYPE $(file:W) 2>NL:" ] : "\n" ] ; | |
260 | } | |
261 | } | |
262 | else | |
263 | { | |
264 | local rule read-file ( file ) | |
265 | { | |
266 | return [ SPLIT_BY_CHARACTERS [ SHELL "cat \"$(file:G=)\" 2>/dev/null" ] : "\n" ] ; | |
267 | } | |
268 | } | |
269 | ||
270 | rule make-bz2-def-file ( target : source : properties * ) | |
271 | { | |
272 | print.output $(target) ; | |
273 | for local line in [ read-file $(source) ] | |
274 | { | |
275 | if ! [ MATCH "(LIBRARY[ \t]+LIBBZ2)" : $(line) ] | |
276 | { | |
277 | print.text $(line) : yes ; | |
278 | } | |
279 | } | |
280 | } |