1 ###########################
2 # this handles the magic we need to do for installing
3 # with all the configure options that affect rpath and shared
7 from TaskGen
import feature
, before
, after
8 from samba_utils
import *
10 @feature('install_bin')
12 @before('apply_link', 'apply_obj_vars')
13 def install_binary(self
):
14 '''install a binary, taking account of the different rpath varients'''
17 # get the ldflags we will use for install and build
18 install_ldflags
= install_rpath(self
)
19 build_ldflags
= build_rpath(bld
)
21 if not Options
.is_install
:
22 # just need to set rpath if we are not installing
23 self
.env
.RPATH
= build_ldflags
26 # work out the install path, expanding variables
27 install_path
= getattr(self
, 'samba_inst_path', None) or '${BINDIR}'
28 install_path
= bld
.EXPAND_VARIABLES(install_path
)
30 orig_target
= os
.path
.basename(self
.target
)
32 if install_ldflags
!= build_ldflags
:
33 # we will be creating a new target name, and using that for the
34 # install link. That stops us from overwriting the existing build
35 # target, which has different ldflags
36 self
.target
+= '.inst'
38 # setup the right rpath link flags for the install
39 self
.env
.RPATH
= install_ldflags
41 if not self
.samba_install
:
42 # this binary is marked not to be installed
45 # tell waf to install the right binary
46 bld
.install_as(os
.path
.join(install_path
, orig_target
),
47 os
.path
.join(self
.path
.abspath(bld
.env
), self
.target
),
52 @feature('install_lib')
54 @before('apply_link', 'apply_obj_vars')
55 def install_library(self
):
56 '''install a library, taking account of the different rpath varients'''
57 if getattr(self
, 'done_install_library', False):
62 default_env
= bld
.all_envs
['default']
64 if self
.env
['IS_EXTRA_PYTHON']:
65 bld
.all_envs
['default'] = bld
.all_envs
['extrapython']
67 install_ldflags
= install_rpath(self
)
68 build_ldflags
= build_rpath(bld
)
70 if not Options
.is_install
or not getattr(self
, 'samba_install', True):
71 # just need to set the build rpath if we are not installing
72 self
.env
.RPATH
= build_ldflags
75 # setup the install path, expanding variables
76 install_path
= getattr(self
, 'samba_inst_path', None)
77 if install_path
is None:
78 if getattr(self
, 'private_library', False):
79 install_path
= '${PRIVATELIBDIR}'
81 install_path
= '${LIBDIR}'
82 install_path
= bld
.EXPAND_VARIABLES(install_path
)
84 target_name
= self
.target
86 if install_ldflags
!= build_ldflags
:
87 # we will be creating a new target name, and using that for the
88 # install link. That stops us from overwriting the existing build
89 # target, which has different ldflags
90 self
.done_install_library
= True
91 t
= self
.clone(self
.env
)
94 self
.env
.RPATH
= build_ldflags
98 t
.env
.RPATH
= install_ldflags
102 # in the following the names are:
103 # - inst_name is the name with .inst. in it, in the build
105 # - install_name is the name in the install directory
106 # - install_link is a symlink in the install directory, to install_name
108 if getattr(self
, 'samba_realname', None):
109 install_name
= self
.samba_realname
111 if getattr(self
, 'soname', ''):
112 install_link
= self
.soname
113 if getattr(self
, 'samba_type', None) == 'PYTHON':
114 inst_name
= bld
.make_libname(t
.target
, nolibprefix
=True, python
=True)
116 inst_name
= bld
.make_libname(t
.target
)
118 vnum_base
= self
.vnum
.split('.')[0]
119 install_name
= bld
.make_libname(target_name
, version
=self
.vnum
)
120 install_link
= bld
.make_libname(target_name
, version
=vnum_base
)
121 inst_name
= bld
.make_libname(t
.target
)
122 if not self
.private_library
:
123 # only generate the dev link for non-bundled libs
124 dev_link
= bld
.make_libname(target_name
)
125 elif getattr(self
, 'soname', ''):
126 install_name
= bld
.make_libname(target_name
)
127 install_link
= self
.soname
128 inst_name
= bld
.make_libname(t
.target
)
130 install_name
= bld
.make_libname(target_name
)
132 inst_name
= bld
.make_libname(t
.target
)
135 # ensure we get the right names in the library
137 t
.env
.append_value('LINKFLAGS', t
.env
.SONAME_ST
% install_link
)
139 t
.env
.append_value('LINKFLAGS', t
.env
.SONAME_ST
% install_name
)
142 # tell waf to install the library
143 bld
.install_as(os
.path
.join(install_path
, install_name
),
144 os
.path
.join(self
.path
.abspath(bld
.env
), inst_name
),
146 if install_link
and install_link
!= install_name
:
147 # and the symlink if needed
148 bld
.symlink_as(os
.path
.join(install_path
, install_link
), os
.path
.basename(install_name
))
150 bld
.symlink_as(os
.path
.join(install_path
, dev_link
), os
.path
.basename(install_name
))
152 bld
.all_envs
['default'] = default_env
156 @after('apply_implib')
157 @before('apply_vnum')
158 def apply_soname(self
):
159 '''install a library, taking account of the different rpath varients'''
161 if self
.env
.SONAME_ST
and getattr(self
, 'soname', ''):
162 self
.env
.append_value('LINKFLAGS', self
.env
.SONAME_ST
% self
.soname
)
163 self
.env
.SONAME_ST
= ''
166 @after('apply_implib')
167 @before('apply_vnum')
168 def apply_vscript(self
):
169 '''add version-script arguments to library build'''
171 if self
.env
.HAVE_LD_VERSION_SCRIPT
and getattr(self
, 'version_script', ''):
172 self
.env
.append_value('LINKFLAGS', "-Wl,--version-script=%s" %
174 self
.version_script
= None
177 ##############################
178 # handle the creation of links for libraries and binaries in the build tree
180 @feature('symlink_lib')
182 def symlink_lib(self
):
183 '''symlink a shared lib'''
185 if self
.target
.endswith('.inst'):
188 blddir
= os
.path
.dirname(self
.bld
.srcnode
.abspath(self
.bld
.env
))
189 libpath
= self
.link_task
.outputs
[0].abspath(self
.env
)
191 # calculat the link target and put it in the environment
193 vnum
= getattr(self
, 'vnum', None)
195 soext
= '.' + vnum
.split('.')[0]
197 link_target
= getattr(self
, 'link_name', '')
198 if link_target
== '':
199 basename
= os
.path
.basename(self
.bld
.make_libname(self
.target
, version
=soext
))
200 if getattr(self
, "private_library", False):
201 link_target
= '%s/private/%s' % (LIB_PATH
, basename
)
203 link_target
= '%s/%s' % (LIB_PATH
, basename
)
205 link_target
= os
.path
.join(blddir
, link_target
)
207 if os
.path
.lexists(link_target
):
208 if os
.path
.islink(link_target
) and os
.readlink(link_target
) == libpath
:
210 os
.unlink(link_target
)
212 link_container
= os
.path
.dirname(link_target
)
213 if not os
.path
.isdir(link_container
):
214 os
.makedirs(link_container
)
216 os
.symlink(libpath
, link_target
)
219 @feature('symlink_bin')
221 def symlink_bin(self
):
222 '''symlink a binary into the build directory'''
224 if self
.target
.endswith('.inst'):
227 blddir
= os
.path
.dirname(self
.bld
.srcnode
.abspath(self
.bld
.env
))
228 if not self
.link_task
.outputs
or not self
.link_task
.outputs
[0]:
229 raise Utils
.WafError('no outputs found for %s in symlink_bin' % self
.name
)
230 binpath
= self
.link_task
.outputs
[0].abspath(self
.env
)
231 bldpath
= os
.path
.join(self
.bld
.env
.BUILD_DIRECTORY
, self
.link_task
.outputs
[0].name
)
233 if os
.path
.lexists(bldpath
):
234 if os
.path
.islink(bldpath
) and os
.readlink(bldpath
) == binpath
:
237 os
.symlink(binpath
, bldpath
)