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
18 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 = [ feature.get-values <search> : $(options) ] ;
117 local include-path = [ feature.get-values <include> : $(options) ] ;
118 local source-path = [ feature.get-values <source> : $(options) ] ;
119 local library-name = [ feature.get-values <name> : $(options) ] ;
120 local tag = [ feature.get-values <tag> : $(options) ] ;
121 local build-name = [ feature.get-values <build-name> : $(options) ] ;
123 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
128 condition = [ property-set.create $(requirements) ] ;
129 condition = [ property-set.create [ $(condition).base ] ] ;
131 local no-build-from-source ;
132 # Ignore environmental BZIP2_SOURCE if this initialization
133 # requested to search for a specific pre-built library.
134 if $(library-path) || $(include-path) || $(library-name)
136 if $(source-path) || $(tag) || $(build-name)
138 errors.user-error "incompatible options for bzip2:"
139 [ property.select <search> <include> <name> : $(options) ] "and"
140 [ property.select <source> <tag> <build-name> : $(options) ] ;
145 source-path ?= [ os.environ BZIP2_SOURCE ] ;
148 source-path = [ path.root [ path.make $(source-path) ]
153 if $(.configured.$(condition))
159 ECHO "notice: [bzip2] bzip is already configured" ;
164 errors.user-error "bzip is already configured" ;
168 else if $(source-path)
171 library-id = [ CALC $(library-id) + 1 ] ;
172 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
175 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
177 sources = [ path.glob $(source-path) : $(sources) ] ;
178 def-file = [ path.glob $(source-path) : libbz2.def ] ;
181 ECHO "notice: [bzip2] Building bzip from source as $(build-name)" ;
184 ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ;
188 ECHO "notice: [bzip2] found bzip source in $(source-path)" ;
192 ECHO "warning: [bzip2] could not find bzip source in $(source-path)" ;
198 if ! $(.def-file-target)
200 .def-file-target = [ targets.create-metatarget make-target-class
201 : $(.project) : libbz2.def : $(def-file)
202 : <action>@bzip2.make-bz2-def-file ]
205 target = [ targets.create-typed-target LIB : $(.project)
206 : $(build-name).$(library-id)
210 <include>$(source-path)
211 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
212 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
213 <link>shared:<def-file>libbz2.def
215 : <include>$(source-path) ] ;
218 local mt = [ new ac-library bzip2 : $(.project) : $(condition) ] ;
219 $(mt).set-header $(header) ;
220 $(mt).set-default-names $(names) ;
223 $(mt).set-target $(target) ;
225 targets.main-target-alternative $(mt) ;
231 ECHO "notice: [bzip2] Using pre-installed library" ;
234 ECHO "notice: [bzip2] Condition" [ $(condition).raw ] ;
238 local mt = [ new ac-library bzip2 : $(.project) : $(condition) :
239 $(include-path) : $(library-path) : $(library-name) ] ;
240 $(mt).set-header $(header) ;
241 $(mt).set-default-names $(names) ;
242 targets.main-target-alternative $(mt) ;
244 .configured.$(condition) = true ;
249 local rule read-file ( file )
251 return [ SPLIT_BY_CHARACTERS [ SHELL "type \"$(file:G=)\" 2>nul" ] : "\n" ] ;
254 else if [ os.name ] = VMS
256 local rule read-file ( file )
258 return [ SPLIT_BY_CHARACTERS [ SHELL "PIPE TYPE $(file:W) 2>NL:" ] : "\n" ] ;
263 local rule read-file ( file )
265 return [ SPLIT_BY_CHARACTERS [ SHELL "cat \"$(file:G=)\" 2>/dev/null" ] : "\n" ] ;
269 rule make-bz2-def-file ( target : source : properties * )
271 print.output $(target) ;
272 for local line in [ read-file $(source) ]
274 if ! [ MATCH "(LIBRARY[ \t]+LIBBZ2)" : $(line) ]
276 print.text $(line) : yes ;