Add --with-privatelibdir build option.
[obnox/samba/samba-obnox.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 Options
7 from TaskGen import feature, before, after
8 from samba_utils import *
9
10 @feature('install_bin')
11 @after('apply_core')
12 @before('apply_link', 'apply_obj_vars')
13 def install_binary(self):
14     '''install a binary, taking account of the different rpath varients'''
15     bld = self.bld
16
17     # get the ldflags we will use for install and build
18     install_ldflags = install_rpath(bld)
19     build_ldflags   = build_rpath(bld)
20
21     if not Options.is_install or not self.samba_install:
22         # just need to set rpath if we are not installing
23         self.env.RPATH = build_ldflags
24         return
25
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)
29
30     orig_target = os.path.basename(self.target)
31
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'
37
38     # setup the right rpath link flags for the install
39     self.env.RPATH = install_ldflags
40
41     # tell waf to install the right binary
42     bld.install_as(os.path.join(install_path, orig_target),
43                    os.path.join(self.path.abspath(bld.env), self.target),
44                    chmod=MODE_755)
45
46
47
48 @feature('install_lib')
49 @after('apply_core')
50 @before('apply_link', 'apply_obj_vars')
51 def install_library(self):
52     '''install a library, taking account of the different rpath varients'''
53     if getattr(self, 'done_install_library', False):
54         return
55
56     bld = self.bld
57
58     install_ldflags = install_rpath(bld)
59     build_ldflags   = build_rpath(bld)
60
61     if not Options.is_install or not getattr(self, 'samba_install', True):
62         # just need to set the build rpath if we are not installing
63         self.env.RPATH = build_ldflags
64         return
65
66     # setup the install path, expanding variables
67     install_path = getattr(self, 'samba_inst_path', None)
68     if install_path is None:
69         if getattr(self, 'private_library', False):
70             install_path = '${PRIVATELIBDIR}'
71         else:
72             install_path = '${LIBDIR}'
73     install_path = bld.EXPAND_VARIABLES(install_path)
74
75     if install_ldflags != build_ldflags:
76         # we will be creating a new target name, and using that for the
77         # install link. That stops us from overwriting the existing build
78         # target, which has different ldflags
79         self.done_install_library = True
80         t = self.clone('default')
81         t.posted = False
82         t.target += '.inst'
83         self.env.RPATH = build_ldflags
84     else:
85         t = self
86
87     t.env.RPATH = install_ldflags
88
89     dev_link     = None
90
91     if getattr(self, 'samba_realname', None):
92         install_name = self.samba_realname
93         install_link = None
94         if getattr(self, 'samba_type', None) == 'PYTHON':
95             inst_name    = bld.make_libname(t.target, nolibprefix=True, python=True)
96         else:
97             inst_name    = bld.make_libname(t.target)
98     elif self.vnum:
99         vnum_base    = self.vnum.split('.')[0]
100         install_name = bld.make_libname(self.target, version=self.vnum)
101         install_link = bld.make_libname(self.target, version=vnum_base)
102         inst_name    = bld.make_libname(t.target)
103         if not self.private_library:
104             # only generate the dev link for non-bundled libs
105             dev_link     = bld.make_libname(self.target)
106     elif getattr(self, 'soname', ''):
107         install_name = bld.make_libname(self.target)
108         install_link = self.soname
109         inst_name    = bld.make_libname(t.target)
110     else:
111         install_name = bld.make_libname(self.target)
112         install_link = None
113         inst_name    = bld.make_libname(t.target)
114
115     if t.env.SONAME_ST and install_link:
116         t.env.append_value('LINKFLAGS', t.env.SONAME_ST % install_link)
117         t.env.SONAME_ST = ''
118
119     # tell waf to install the library
120     bld.install_as(os.path.join(install_path, install_name),
121                    os.path.join(self.path.abspath(bld.env), inst_name))
122     if install_link:
123         # and the symlink if needed
124         bld.symlink_as(os.path.join(install_path, install_link),
125                        install_name)
126     if dev_link:
127         bld.symlink_as(os.path.join(install_path, dev_link),
128                        install_name)
129
130
131 @feature('cshlib')
132 @after('apply_implib')
133 @before('apply_vnum')
134 def apply_soname(self):
135     '''install a library, taking account of the different rpath varients'''
136
137     if self.env.SONAME_ST and getattr(self, 'soname', ''):
138         self.env.append_value('LINKFLAGS', self.env.SONAME_ST % self.soname)
139         self.env.SONAME_ST = ''
140
141 ##############################
142 # handle the creation of links for libraries and binaries in the build tree
143
144 @feature('symlink_lib')
145 @after('apply_link')
146 def symlink_lib(self):
147     '''symlink a shared lib'''
148
149     if self.target.endswith('.inst'):
150         return
151
152     blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env))
153     libpath = self.link_task.outputs[0].abspath(self.env)
154
155     # calculat the link target and put it in the environment
156     soext=""
157     vnum = getattr(self, 'vnum', None)
158     if vnum is not None:
159         soext = '.' + vnum.split('.')[0]
160
161     link_target = getattr(self, 'link_name', '')
162     if link_target == '':
163         link_target = '%s/%s' % (LIB_PATH, self.bld.make_libname(self.target, version=soext))
164
165     link_target = os.path.join(blddir, link_target)
166
167     if os.path.lexists(link_target):
168         if os.path.islink(link_target) and os.readlink(link_target) == libpath:
169             return
170         os.unlink(link_target)
171
172     link_container = os.path.dirname(link_target)
173     if not os.path.isdir(link_container):
174         os.makedirs(link_container)
175
176     os.symlink(libpath, link_target)
177
178
179 @feature('symlink_bin')
180 @after('apply_link')
181 def symlink_bin(self):
182     '''symlink a binary into the build directory'''
183
184     if self.target.endswith('.inst'):
185         return
186
187     blddir = os.path.dirname(self.bld.srcnode.abspath(self.bld.env))
188     binpath = self.link_task.outputs[0].abspath(self.env)
189     bldpath = os.path.join(self.bld.env.BUILD_DIRECTORY, self.link_task.outputs[0].name)
190
191     if os.path.lexists(bldpath):
192         if os.path.islink(bldpath) and os.readlink(bldpath) == binpath:
193             return
194         os.unlink(bldpath)
195     os.symlink(binpath, bldpath)