Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / src / tools / package.jam
1 # Copyright (c) 2005 Vladimir Prus.
2 # Copyright 2006 Rene Rivera.
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 # 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
11 # all.
12
13 # Example usage:
14 #
15 #   package.install boost : <properties>
16 #                         : <binaries>
17 #                         : <libraries>
18 #                         : <headers>
19 #                         ;
20 #
21 # This will install binaries, libraries and headers to the 'proper' location,
22 # given by command line options --prefix, --exec-prefix, --bindir, --libdir and
23 # --includedir.
24 #
25 # The rule is just a convenient wrapper, avoiding the need to define several
26 # 'install' targets.
27 #
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.
32
33 import "class" : new ;
34 import option ;
35 import project ;
36 import feature ;
37 import property ;
38 import stage ;
39 import targets ;
40 import modules ;
41
42 feature.feature install-default-prefix : : free incidental ;
43
44 rule install ( name package-name ? : requirements * : binaries * : libraries * : headers * )
45 {
46     package-name ?= $(name) ;
47     if [ MATCH --prefix=(.*) : [ modules.peek : ARGV ] ]
48     {
49         # If --prefix is explicitly specified on the command line,
50         # then we need wipe away any settings of libdir/includir that
51         # is specified via options in config files.
52         option.set bindir : ;
53         option.set libdir : ;
54         option.set includedir : ;
55     }
56             
57     # If <install-source-root> is not specified, all headers are installed to
58     # prefix/include, no matter what their relative path is. Sometimes that is
59     # what is needed.
60     local install-source-root = [ property.select <install-source-root> :
61         $(requirements) ] ;
62     install-source-root = $(install-source-root:G=) ;
63     requirements = [ property.change $(requirements) : <install-source-root> ] ;
64
65     local install-header-subdir = [ property.select <install-header-subdir> :
66         $(requirements) ] ;
67     install-header-subdir = /$(install-header-subdir:G=) ;
68     install-header-subdir ?= "" ;
69     requirements = [ property.change $(requirements) : <install-header-subdir> ]
70         ;
71
72     # First, figure out all locations. Use the default if no prefix option
73     # given.
74     local prefix = [ get-prefix $(name) : $(requirements) ] ;
75
76     # Architecture dependent files.
77     local exec-locate = [ option.get exec-prefix : $(prefix) ] ;
78
79     # Binaries.
80     local bin-locate = [ option.get bindir : $(prefix)/bin ] ;
81
82     # Object code libraries.
83     local lib-locate = [ option.get libdir : $(prefix)/lib ] ;
84
85     # Source header files.
86     local include-locate = [ option.get includedir : $(prefix)/include ] ;
87
88     stage.install $(name)-bin : $(binaries) : $(requirements)
89         <location>$(bin-locate) ;
90     alias $(name)-lib : $(name)-lib-shared $(name)-lib-static ;
91     
92     # Since the install location of shared libraries differs on universe
93     # and cygwin, use target alternatives to make different targets.
94     # We should have used indirection conditioanl requirements, but it's
95     # awkward to pass bin-locate and lib-locate from there to another rule.
96     alias $(name)-lib-shared : $(name)-lib-shared-universe ;
97     alias $(name)-lib-shared : $(name)-lib-shared-cygwin : <target-os>cygwin ;
98     
99     # For shared libraries, we install both explicitly specified one and the
100     # shared libraries that the installed executables depend on.
101     stage.install $(name)-lib-shared-universe : $(binaries) $(libraries) : $(requirements)
102       <location>$(lib-locate) <install-dependencies>on <install-type>SHARED_LIB ;
103     stage.install $(name)-lib-shared-cygwin : $(binaries) $(libraries) : $(requirements)
104       <location>$(bin-locate) <install-dependencies>on <install-type>SHARED_LIB ;
105
106     # For static libraries, we do not care about executable dependencies, since
107     # static libraries are already incorporated into them.
108     stage.install $(name)-lib-static : $(libraries) : $(requirements)
109         <location>$(lib-locate) <install-dependencies>on <install-type>STATIC_LIB ;
110     stage.install $(name)-headers : $(headers) : $(requirements)
111         <location>$(include-locate)$(install-header-subdir)
112         <install-source-root>$(install-source-root) ;
113     alias $(name) : $(name)-bin $(name)-lib $(name)-headers ;
114
115     local c = [ project.current ] ;
116     local project-module = [ $(c).project-module ] ;
117     module $(project-module)
118     {
119         explicit $(1)-bin $(1)-lib $(1)-headers $(1) $(1)-lib-shared $(1)-lib-static 
120           $(1)-lib-shared-universe $(1)-lib-shared-cygwin ;
121     }
122 }
123
124 rule install-data ( target-name : package-name : data * : requirements * )
125 {
126     package-name ?= target-name ;
127     if [ MATCH --prefix=(.*) : [ modules.peek : ARGV ] ]
128     {
129         # If --prefix is explicitly specified on the command line,
130         # then we need wipe away any settings of datarootdir
131         option.set datarootdir : ;
132     }   
133     
134     local prefix = [ get-prefix $(package-name) : $(requirements) ] ;
135     local datadir = [ option.get datarootdir : $(prefix)/share ] ;
136
137     stage.install $(target-name) 
138         : $(data)
139         : $(requirements) <location>$(datadir)/$(package-name)
140         ;
141     
142     local c = [ project.current ] ;
143     local project-module = [ $(c).project-module ] ;
144     module $(project-module)
145     {
146         explicit $(1) ;
147     }
148 }
149
150 local rule get-prefix ( package-name : requirements * )
151 {
152     local prefix = [ option.get prefix : [ property.select
153         <install-default-prefix> : $(requirements) ] ] ;
154     prefix = $(prefix:G=) ;
155     requirements = [ property.change $(requirements) : <install-default-prefix>
156         ] ;
157     # Or some likely defaults if neither is given.
158     if ! $(prefix)
159     {
160         if [ modules.peek : NT ] { prefix = C:\\$(package-name) ; }
161         else if [ modules.peek : UNIX ] { prefix = /usr/local ; }        
162     }
163     return $(prefix) ;
164 }           
165