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