build:wafsamba: Replace Options.is_install by bld.is_install
[sfrench/samba-autobuild/.git] / buildtools / wafsamba / samba_install.py
1 ###########################
2 # this handles the magic we need to do for installing
3 # with all the configure options that affect rpath and shared
4 # library use
5
6 import os
7 import Utils
8 from TaskGen import feature, before, after
9 from samba_utils import LIB_PATH, MODE_755, install_rpath, build_rpath
10
11 @feature('install_bin')
12 @after('apply_core')
13 @before('apply_link', 'apply_obj_vars')
14 def install_binary(self):
15     '''install a binary, taking account of the different rpath varients'''
16     bld = self.bld
17
18     # get the ldflags we will use for install and build
19     install_ldflags = install_rpath(self)
20     build_ldflags   = build_rpath(bld)
21
22     if not self.bld.is_install:
23         # just need to set rpath if we are not installing
24         self.env.RPATH = build_ldflags
25         return
26
27     # work out the install path, expanding variables
28     install_path = getattr(self, 'samba_inst_path', None) or '${BINDIR}'
29     install_path = bld.EXPAND_VARIABLES(install_path)
30
31     orig_target = os.path.basename(self.target)
32
33     if install_ldflags != build_ldflags:
34         # we will be creating a new target name, and using that for the
35         # install link. That stops us from overwriting the existing build
36         # target, which has different ldflags
37         self.target += '.inst'
38
39     # setup the right rpath link flags for the install
40     self.env.RPATH = install_ldflags
41
42     if not self.samba_install:
43         # this binary is marked not to be installed
44         return
45
46     # tell waf to install the right binary
47     bld.install_as(os.path.join(install_path, orig_target),
48                    os.path.join(self.path.abspath(bld.env), self.target),
49                    chmod=MODE_755)
50
51
52
53 @feature('install_lib')
54 @after('apply_core')
55 @before('apply_link', 'apply_obj_vars')
56 def install_library(self):
57     '''install a library, taking account of the different rpath varients'''
58     if getattr(self, 'done_install_library', False):
59         return
60
61     bld = self.bld
62
63     default_env = bld.all_envs['default']
64     try:
65         if self.env['IS_EXTRA_PYTHON']:
66             bld.all_envs['default'] = bld.all_envs['extrapython']
67
68         install_ldflags = install_rpath(self)
69         build_ldflags   = build_rpath(bld)
70
71         if not self.bld.is_install or not getattr(self, 'samba_install', True):
72             # just need to set the build rpath if we are not installing
73             self.env.RPATH = build_ldflags
74             return
75
76         # setup the install path, expanding variables
77         install_path = getattr(self, 'samba_inst_path', None)
78         if install_path is None:
79             if getattr(self, 'private_library', False):
80                 install_path = '${PRIVATELIBDIR}'
81             else:
82                 install_path = '${LIBDIR}'
83         install_path = bld.EXPAND_VARIABLES(install_path)
84
85         target_name = self.target
86
87         if install_ldflags != build_ldflags:
88             # we will be creating a new target name, and using that for the
89             # install link. That stops us from overwriting the existing build
90             # target, which has different ldflags
91             self.done_install_library = True
92             t = self.clone(self.env)
93             t.posted = False
94             t.target += '.inst'
95             self.env.RPATH = build_ldflags
96         else:
97             t = self
98
99         t.env.RPATH = install_ldflags
100
101         dev_link     = None
102
103         # in the following the names are:
104         # - inst_name is the name with .inst. in it, in the build
105         #   directory
106         # - install_name is the name in the install directory
107         # - install_link is a symlink in the install directory, to install_name
108
109         if getattr(self, 'samba_realname', None):
110             install_name = self.samba_realname
111             install_link = None
112             if getattr(self, 'soname', ''):
113                 install_link = self.soname
114             if getattr(self, 'samba_type', None) == 'PYTHON':
115                 inst_name    = bld.make_libname(t.target, nolibprefix=True, python=True)
116             else:
117                 inst_name    = bld.make_libname(t.target)
118         elif self.vnum:
119             vnum_base    = self.vnum.split('.')[0]
120             install_name = bld.make_libname(target_name, version=self.vnum)
121             install_link = bld.make_libname(target_name, version=vnum_base)
122             inst_name    = bld.make_libname(t.target)
123             if not self.private_library:
124                 # only generate the dev link for non-bundled libs
125                 dev_link     = bld.make_libname(target_name)
126         elif getattr(self, 'soname', ''):
127             install_name = bld.make_libname(target_name)
128             install_link = self.soname
129             inst_name    = bld.make_libname(t.target)
130         else:
131             install_name = bld.make_libname(target_name)
132             install_link = None
133             inst_name    = bld.make_libname(t.target)
134
135         if t.env.SONAME_ST:
136             # ensure we get the right names in the library
137             if install_link:
138                 t.env.append_value('LINKFLAGS', t.env.SONAME_ST % install_link)
139             else:
140                 t.env.append_value('LINKFLAGS', t.env.SONAME_ST % install_name)
141             t.env.SONAME_ST = ''
142
143         # tell waf to install the library
144         bld.install_as(os.path.join(install_path, install_name),
145                        os.path.join(self.path.abspath(bld.env), inst_name),
146                        chmod=MODE_755)
147         if install_link and install_link != install_name:
148             # and the symlink if needed
149             bld.symlink_as(os.path.join(install_path, install_link), os.path.basename(install_name))
150         if dev_link:
151             bld.symlink_as(os.path.join(install_path, dev_link), os.path.basename(install_name))
152     finally:
153         bld.all_envs['default'] = default_env
154
155
156 @feature('cshlib')
157 @after('apply_implib')
158 @before('apply_vnum')
159 def apply_soname(self):
160     '''install a library, taking account of the different rpath varients'''
161
162     if self.env.SONAME_ST and getattr(self, 'soname', ''):
163         self.env.append_value('LINKFLAGS', self.env.SONAME_ST % self.soname)
164         self.env.SONAME_ST = ''
165
166 @feature('cshlib')
167 @after('apply_implib')
168 @before('apply_vnum')
169 def apply_vscript(self):
170     '''add version-script arguments to library build'''
171
172     if self.env.HAVE_LD_VERSION_SCRIPT and getattr(self, 'version_script', ''):
173         self.env.append_value('LINKFLAGS', "-Wl,--version-script=%s" %
174             self.version_script)
175         self.version_script = None
176
177
178 ##############################
179 # handle the creation of links for libraries and binaries in the build tree
180
181 @feature('symlink_lib')
182 @after('apply_link')
183 def symlink_lib(self):
184     '''symlink a shared lib'''
185
186     if self.target.endswith('.inst'):
187         return
188
189     blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env))
190     libpath = self.link_task.outputs[0].abspath(self.env)
191
192     # calculat the link target and put it in the environment
193     soext=""
194     vnum = getattr(self, 'vnum', None)
195     if vnum is not None:
196         soext = '.' + vnum.split('.')[0]
197
198     link_target = getattr(self, 'link_name', '')
199     if link_target == '':
200         basename = os.path.basename(self.bld.make_libname(self.target, version=soext))
201         if getattr(self, "private_library", False):
202             link_target = '%s/private/%s' % (LIB_PATH, basename)
203         else:
204             link_target = '%s/%s' % (LIB_PATH, basename)
205
206     link_target = os.path.join(blddir, link_target)
207
208     if os.path.lexists(link_target):
209         if os.path.islink(link_target) and os.readlink(link_target) == libpath:
210             return
211         os.unlink(link_target)
212
213     link_container = os.path.dirname(link_target)
214     if not os.path.isdir(link_container):
215         os.makedirs(link_container)
216
217     os.symlink(libpath, link_target)
218
219
220 @feature('symlink_bin')
221 @after('apply_link')
222 def symlink_bin(self):
223     '''symlink a binary into the build directory'''
224
225     if self.target.endswith('.inst'):
226         return
227
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)
232
233     if os.path.lexists(bldpath):
234         if os.path.islink(bldpath) and os.readlink(bldpath) == binpath:
235             return
236         os.unlink(bldpath)
237     os.symlink(binpath, bldpath)