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 bzip library
10 # After 'using bzip2', the following targets are available:
12 # /bzip2//bzip2 -- The bzip library
17 import "class" : new ;
32 sources = blocksort.c bzlib.c compress.c crctable.c
33 decompress.c huffman.c randtable.c ;
37 if --debug-configuration in [ modules.peek : ARGV ]
42 # Initializes the bzip library.
44 # bzip can be configured either to use pre-existing binaries
45 # or to build the library from source.
47 # Options for configuring a prebuilt bzip::
50 # The directory containing the bzip binaries.
52 # Overrides the default library name.
54 # The directory containing the bzip headers.
56 # If none of these options is specified, then the environmental
57 # variables BZIP2_LIBRARY_PATH, BZIP2_NAME, and BZIP2_INCLUDE will
60 # Options for building bzip from source::
63 # The bzip source directory. Defaults to the environmental variable
66 # A rule which computes the actual name of the compiled
67 # libraries based on the build properties. Ignored
68 # when using precompiled binaries.
70 # The base name to use for the compiled library. Ignored
71 # when using precompiled binaries.
75 # # Find bzip in the default system location
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
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 ;
89 # The bzip version (currently ignored)
92 # A list of the options to use
95 # The requirements for the bzip target
98 # Default configurations are only used when bzip
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.
105 local caller = [ project.current ] ;
109 .initialized = true ;
111 project.initialize $(__name__) ;
112 .project = [ project.current ] ;
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) ] ;
126 local build-name = [ property.select <build-name> : $(options) ] ;
127 build-name = $(build-name:G=) ;
129 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
134 condition = [ property-set.create $(requirements) ] ;
135 condition = [ property-set.create [ $(condition).base ] ] ;
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)
142 if $(source-path) || $(tag) || $(build-name)
144 errors.user-error "incompatible options for bzip2:"
145 [ property.select <search> <include> <name> : $(options) ] "and"
146 [ property.select <source> <tag> <build-name> : $(options) ] ;
151 source-path ?= [ modules.peek : BZIP2_SOURCE ] ;
154 if $(.configured.$(condition))
160 ECHO "notice: [bzip2] bzip is already configured" ;
165 errors.user-error "bzip is already configured" ;
169 else if $(source-path)
172 library-id = [ CALC $(library-id) + 1 ] ;
173 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
174 if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ]
176 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
178 sources = [ path.glob $(source-path) : $(sources) ] ;
179 def-file = [ path.glob $(source-path) : libbz2.def ] ;
182 ECHO "notice: [bzip2] Building bzip from source as $(build-name)" ;
185 ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ;
189 ECHO "notice: [bzip2] found bzip source in $(source-path)" ;
193 ECHO "warning: [bzip2] could not find bzip source in $(source-path)" ;
199 if ! $(.def-file-target)
201 .def-file-target = [ targets.create-metatarget make-target-class
202 : $(.project) : libbz2.def : $(def-file)
203 : <action>@bzip2.make-bz2-def-file ]
206 target = [ targets.create-typed-target LIB : $(.project)
207 : $(build-name).$(library-id)
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
216 : <include>$(source-path) ] ;
219 local mt = [ new ac-library bzip2 : $(.project) : $(condition) ] ;
220 $(mt).set-header $(header) ;
221 $(mt).set-default-names $(names) ;
224 $(mt).set-target $(target) ;
226 targets.main-target-alternative $(mt) ;
232 ECHO "notice: [bzip2] Using pre-installed library" ;
235 ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ;
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) ;
245 .configured.$(condition) = true ;
250 local rule read-file ( file )
252 return [ SPLIT_BY_CHARACTERS [ SHELL "type \"$(file:G=)\" 2>nul" ] : "\n" ] ;
255 else if [ os.name ] = VMS
257 local rule read-file ( file )
259 return [ SPLIT_BY_CHARACTERS [ SHELL "PIPE TYPE $(file:W) 2>NL:" ] : "\n" ] ;
264 local rule read-file ( file )
266 return [ SPLIT_BY_CHARACTERS [ SHELL "cat \"$(file:G=)\" 2>/dev/null" ] : "\n" ] ;
270 rule make-bz2-def-file ( target : source : properties * )
272 print.output $(target) ;
273 for local line in [ read-file $(source) ]
275 if ! [ MATCH "(LIBRARY[ \t]+LIBBZ2)" : $(line) ]
277 print.text $(line) : yes ;