Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / src / tools / zlib.jam
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
97     # has not yet been configured.
98     )
99 {
100     local caller = [ project.current ] ;
101
102     if ! $(.initialized)
103     {
104         .initialized = true ;
105
106         project.initialize $(__name__) ;
107         .project = [ project.current ] ;
108         project zlib ;
109     }
110
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) ] ;
120     tag = $(tag:G=) ;
121     local build-name = [ property.select <build-name> : $(options) ] ;
122     build-name = $(build-name:G=) ;
123
124     condition = [ property-set.create $(requirements) ] ;
125     condition = [ property-set.create [ $(condition).base ] ] ;
126
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)
131     {
132         if $(source-path) || $(tag) || $(build-name)
133         {
134             errors.user-error "incompatible options for zlib:"
135                 [ property.select <search> <include> <name> : $(options) ] "and"
136                 [ property.select <source> <tag> <build-name> : $(options) ] ;
137         }
138         else
139         {
140             no-build-from-source = true ;
141         }
142     }
143
144     source-path ?= [ modules.peek : ZLIB_SOURCE ] ;
145
146     if $(.configured.$(condition))
147     {
148         if $(is-default)
149         {
150             if $(.debug)
151             {
152                 ECHO "notice: [zlib] zlib is already configured" ;
153             }
154         }
155         else
156         {
157             errors.user-error "zlib is already configured" ;
158         }
159         return ;
160     }
161     else if $(source-path) && ! $(no-build-from-source)
162     {
163         build-name ?= z ;
164         library-id = [ CALC $(library-id) + 1 ] ;
165         tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
166         if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ]
167         {
168             tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
169         }
170         sources = [ path.glob $(source-path) : $(sources) ] ;
171         if $(.debug)
172         {
173             ECHO "notice: [zlib] Building zlib from source as $(build-name)" ;
174             if $(condition)
175             {
176                 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
177             }
178             if $(sources)
179             {
180                 ECHO "notice: [zlib] found zlib source in $(source-path)" ;
181             }
182             else
183             {
184                 ECHO "warning: [zlib] could not find zlib source in $(source-path)" ;
185             }
186         }
187         local target ;
188         if $(sources) {
189             target = [ targets.create-typed-target LIB : $(.project)
190               : $(build-name).$(library-id)
191               : $(sources)
192               : $(requirements)
193                 <tag>@$(tag)
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
198               :
199               : <include>$(source-path) ] ;
200         }
201
202         local mt = [ new ac-library zlib : $(.project) : $(condition) ] ;
203         $(mt).set-header $(header) ;
204         $(mt).set-default-names $(names) ;
205         if $(target)
206         {
207             $(mt).set-target $(target) ;
208         }
209         targets.main-target-alternative $(mt) ;
210     } else {
211         if $(.debug)
212         {
213             ECHO "notice: [zlib] Using pre-installed library" ;
214             if $(condition)
215             {
216                 ECHO "notice: [zlib] Condition" [ $(condition).raw ] ;
217             }
218         }
219
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) ;
225     }
226     .configured.$(condition) = true ;
227 }