• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 libtiff library
9#
10# After 'using libtiff', the following targets are available:
11#
12# /libtiff//libtiff -- The libtiff library
13
14import project ;
15import ac ;
16import errors ;
17import feature ;
18import "class" : new ;
19import targets ;
20import path ;
21import modules ;
22import indirect ;
23import property ;
24import property-set ;
25
26header = tiff.h ;
27names = tiff ;
28
29sources =   tif_aux.c tif_close.c tif_codec.c tif_color.c tif_compress.c tif_dir.c tif_dirinfo.c
30	tif_dirread.c tif_dirwrite.c tif_dumpmode.c tif_error.c tif_extension.c tif_fax3.c tif_fax3sm.c
31	tif_getimage.c tif_jbig.c tif_jpeg.c tif_jpeg_12.c tif_ojpeg.c tif_flush.c tif_luv.c tif_lzw.c
32	tif_next.c tif_open.c tif_packbits.c tif_pixarlog.c tif_predict.c tif_print.c tif_read.c tif_stream.cxx
33	tif_swab.c tif_strip.c tif_thunder.c tif_tile.c tif_version.c tif_warning.c tif_write.c tif_zip.c ;
34
35library-id = 0 ;
36
37if --debug-configuration in [ modules.peek : ARGV ]
38{
39    .debug =  true ;
40}
41
42# Initializes the libtiff library.
43#
44# libtiff can be configured either to use pre-existing binaries
45# or to build the library from source.
46#
47# Options for configuring a prebuilt libtiff::
48#
49#   <search>
50#       The directory containing the libtiff binaries.
51#   <name>
52#       Overrides the default library name.
53#   <include>
54#       The directory containing the libtiff headers.
55#
56# If none of these options is specified, then the environmental
57# variables LIBTIFF_LIBRARY_PATH, LIBTIFF_NAME, and LIBTIFF_INCLUDE will
58# be used instead.
59#
60# Options for building libtiff from source::
61#
62#   <source>
63#       The libtiff source directory.  Defaults to the environmental variable
64#       LIBTIFF_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 libtiff in the default system location
76#   using libtiff ;
77#   # Build libtiff from source
78#   using libtiff : 4.0.1 : <source>/home/steven/libtiff-4.0.1 ;
79#   # Find libtiff in /usr/local
80#   using libtiff : 4.0.1
81#     : <include>/usr/local/include <search>/usr/local/lib ;
82#   # Build libtiff from source for msvc and find
83#   # prebuilt binaries for gcc.
84#   using libtiff : 4.0.1 : <source>C:/Devel/src/libtiff-4.0.1 : <toolset>msvc ;
85#   using libtiff : 4.0.1 : : <toolset>gcc ;
86#
87rule init (
88    version ?
89    # The libtiff version (currently ignored)
90
91    : options *
92    # A list of the options to use
93
94    : requirements *
95    # The requirements for the libtiff target
96
97    : is-default ?
98    # Default configurations are only used when libtiff
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.
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 libtiff ;
114    }
115
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) ] ;
122
123    if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
124    {
125        is-default = true ;
126    }
127
128    condition = [ property-set.create $(requirements) ] ;
129    condition = [ property-set.create [ $(condition).base ] ] ;
130
131    # Ignore environmental LIBTIFF_SOURCE if this initialization
132    # requested to search for a specific pre-built library.
133    if $(library-path) || $(include-path) || $(library-name)
134    {
135        if $(source-path) || $(tag) || $(build-name)
136        {
137            errors.user-error "incompatible options for libtiff:"
138                [ property.select <search> <include> <name> : $(options) ] "and"
139                [ property.select <source> <tag> <build-name> : $(options) ] ;
140        }
141    }
142    else
143    {
144        source-path ?= [ modules.peek : LIBTIFF_SOURCE ] ;
145    }
146
147    if $(.configured.$(condition))
148    {
149        if $(is-default)
150        {
151            if $(.debug)
152            {
153                ECHO "notice: [libtiff] libtiff is already configured" ;
154            }
155        }
156        else
157        {
158            errors.user-error "libtiff is already configured" ;
159        }
160        return ;
161    }
162    else if $(source-path)
163    {
164        build-name ?= tiff ;
165        library-id = [ CALC $(library-id) + 1 ] ;
166        tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
167        if $(tag)
168        {
169            tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
170        }
171        sources = [ path.glob $(source-path) : $(sources) ] ;
172        if $(.debug)
173        {
174            ECHO "notice: [libtiff] Building libtiff from source as $(build-name)" ;
175            if $(condition)
176            {
177                ECHO "notice: [libtiff] Condition" [ $(condition).raw ] ;
178            }
179            if $(sources)
180            {
181                ECHO "notice: [libtiff] found libtiff source in $(source-path)" ;
182            }
183            else
184            {
185                ECHO "warning: [libtiff] could not find libtiff source in $(source-path)" ;
186            }
187        }
188        local target ;
189        if $(sources) {
190            target = [ targets.create-typed-target LIB : $(.project)
191              : $(build-name).$(library-id)
192              : $(sources)
193              : $(requirements)
194                <tag>@$(tag)
195                <include>$(source-path)
196                <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
197                <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
198              :
199              : <include>$(source-path) ] ;
200        }
201
202        local mt = [ new ac-library libtiff : $(.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: [libtiff] Using pre-installed library" ;
214            if $(condition)
215            {
216                ECHO "notice: [libtiff] Condition" [ $(condition).raw ] ;
217            }
218        }
219
220        local mt = [ new ac-library libtiff : $(.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}
228