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