1 # Copyright (c) 2005 Vladimir Prus.
2 # Copyright 2006 Rene Rivera.
4 # Use, modification and distribution is subject to the Boost Software
5 # License Version 1.0. (See accompanying file LICENSE.txt or
6 # https://www.bfgroup.xyz/b2/LICENSE.txt)
8 # Provides mechanism for installing whole packages into a specific directory
9 # structure. This is opposed to the 'install' rule, that installs a number of
10 # targets to a single directory, and does not care about directory structure at
15 # package.install boost : <properties>
21 # This will install binaries, libraries and headers to the 'proper' location,
22 # given by command line options --prefix, --exec-prefix, --bindir, --libdir and
25 # The rule is just a convenient wrapper, avoiding the need to define several
28 # The only install-related feature is <install-source-root>. It will apply to
29 # headers only and if present, paths of headers relatively to source root will
30 # be retained after installing. If it is not specified, then "." is assumed, so
31 # relative paths in headers are always preserved.
33 import "class" : new ;
44 feature.feature install-default-prefix : : free incidental ;
53 rule __init__ ( default-prefix )
55 local explicit-options = [ MATCH --(prefix|bindir|libdir|includedir|datarootdir)=.*
56 : [ modules.peek : ARGV ] ] ;
57 self.has-$(explicit-options) = true ;
58 if prefix in $(explicit-options)
60 # If --prefix is explicitly specified on the command line,
61 # then we need wipe away any settings of libdir/includir that
62 # is specified via options in config files.
65 option.set includedir : ;
66 option.set datarootdir : ;
69 handle-path prefix : $(default-prefix) ;
70 handle-path libdir : $(self.prefix)/lib ;
71 handle-path bindir : $(self.prefix)/bin ;
72 handle-path includedir : $(self.prefix)/include ;
73 handle-path datarootdir : $(self.prefix)/share ;
76 local rule handle-path ( option : default-value )
78 local opt = [ option.get $(option) ] ;
81 opt = [ path.root [ path.make $(opt) ] [ path.pwd ] ] ;
85 opt = $(default-value) ;
87 self.$(option) = $(opt) ;
92 return $(self.prefix) ;
97 return $(self.libdir) ;
102 return $(self.bindir) ;
107 return $(self.includedir) ;
112 return $(self.datarootdir) ;
117 if ! $(self.$(option))
119 local info = [ modules.peek package : .options.$(option) ] ;
120 local default-value = $(info[1]) ;
121 local relative-to = $(info[2]) ;
122 if $(self.has-$(relative-to))
124 option.set $(option) ;
125 self.has-$(option) = true ;
127 if [ MATCH --$(option)=(.*) : [ modules.peek : ARGV ] ]
129 self.has-$(option) = true ;
131 local adjusted-default =
132 [ path.join [ get $(relative-to) ] $(default-value) ] ;
133 handle-path $(option) : $(adjusted-default) ;
135 return $(self.$(option)) ;
139 # Registers an additional path option. The option name
140 # can then be used with a package-paths object.
142 # default-path is the default path that will be used if
143 # the option is not set explicitly. It will be interpreted
144 # relative to another option. This allows options to be
145 # defined hierarchically with --prefix as the root.
147 # relative-to should be the name of another option. It defaults
152 # package.add-path-option cmakedir : cmake : libdir ;
153 # cmakedir = [ $(mypaths).get cmakedir ] ; # defaults to /usr/local/lib/cmake
155 rule add-path-option ( name : default-path : relative-to ? )
157 local value = $(default-path) $(relative-to:E=prefix) ;
158 if $(.options.$(name)) && $(.options.$(name)) != $(value)
161 errors.error Duplicate definition of $(name) ;
163 .options.$(name) = $(value) ;
167 # Returns a package-paths object that can be used
168 # to find the various install paths. If requirements
169 # contains <install-default-prefix> then that will be used
170 # as the default prefix, otherwise a platform specific
171 # default prefix will be used. All other properties
172 # in requirements are ignored.
174 rule paths ( package-name : requirements * )
176 local default-prefix = [ feature.get-values <install-default-prefix> : $(requirements) ] ;
177 # Or some likely defaults if neither is given.
178 if ! $(default-prefix)
180 if [ os.name ] = NT { default-prefix = C:\\$(package-name) ; }
181 else { default-prefix = /usr/local ; }
183 default-prefix = [ path.make $(default-prefix) ] ;
184 if ! $(.package-paths.$(default-prefix))
186 .package-paths.$(default-prefix) = [ new package-paths $(default-prefix) ] ;
188 return $(.package-paths.$(default-prefix)) ;
191 rule install ( name package-name ? : requirements * : binaries * : libraries * : headers * )
193 package-name ?= $(name) ;
195 # If <install-source-root> is not specified, all headers are installed to
196 # prefix/include, no matter what their relative path is. Sometimes that is
198 local install-source-root = [ property.select <install-source-root> :
200 install-source-root = $(install-source-root:G=) ;
201 requirements = [ property.change $(requirements) : <install-source-root> ] ;
203 local install-header-subdir = [ property.select <install-header-subdir> :
205 install-header-subdir = /$(install-header-subdir:G=) ;
206 install-header-subdir ?= "" ;
207 requirements = [ property.change $(requirements) : <install-header-subdir> ]
210 # First, figure out all locations. Use the default if no prefix option
212 local paths = [ paths $(package-name) : $(requirements) ] ;
215 local bin-locate = [ $(paths).bindir ] ;
217 # Object code libraries.
218 local lib-locate = [ $(paths).libdir ] ;
220 # Source header files.
221 local include-locate = [ $(paths).includedir ] ;
223 stage.install $(name)-bin : $(binaries) : $(requirements)
224 <location>$(bin-locate) ;
225 alias $(name)-lib : $(name)-lib-shared $(name)-lib-static ;
227 # Since the install location of shared libraries differs on universe
228 # and cygwin, use target alternatives to make different targets.
229 # We should have used indirection conditioanl requirements, but it's
230 # awkward to pass bin-locate and lib-locate from there to another rule.
231 alias $(name)-lib-shared : $(name)-lib-shared-universe ;
232 alias $(name)-lib-shared : $(name)-lib-shared-cygwin : <target-os>cygwin ;
234 # For shared libraries, we install both explicitly specified one and the
235 # shared libraries that the installed executables depend on.
236 stage.install $(name)-lib-shared-universe : $(binaries) $(libraries) : $(requirements)
237 <location>$(lib-locate) <install-dependencies>on <install-type>SHARED_LIB ;
238 stage.install $(name)-lib-shared-cygwin : $(binaries) $(libraries) : $(requirements)
239 <location>$(bin-locate) <install-dependencies>on <install-type>SHARED_LIB ;
241 # For static libraries, we do not care about executable dependencies, since
242 # static libraries are already incorporated into them.
243 stage.install $(name)-lib-static : $(libraries) : $(requirements)
244 <location>$(lib-locate) <install-dependencies>on <install-type>STATIC_LIB ;
245 stage.install $(name)-headers : $(headers) : $(requirements)
246 <location>$(include-locate)$(install-header-subdir)
247 <install-source-root>$(install-source-root) ;
248 alias $(name) : $(name)-bin $(name)-lib $(name)-headers ;
250 local c = [ project.current ] ;
251 modules.call-in [ $(c).project-module ] : explicit $(name) $(name)-bin
252 $(name)-lib $(name)-headers $(name)-lib-shared $(name)-lib-static
253 $(name)-lib-shared-universe $(name)-lib-shared-cygwin ;
256 rule install-data ( target-name : package-name ? : data * : requirements * )
258 package-name ?= $(target-name) ;
260 local paths = [ paths $(package-name) : $(requirements) ] ;
261 local datadir = [ $(paths).datarootdir ] ;
263 stage.install $(target-name)
265 : $(requirements) <location>$(datadir)/$(package-name)
268 local c = [ project.current ] ;
269 local project-module = [ $(c).project-module ] ;
270 module $(project-module)