# Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ EAPI=5 #multilib currently only used for get_libdir inherit eutils multilib versionator DESCRIPTION="Microsoft SQL Server ODBC Driver 1.0 for Linux" HOMEPAGE="http://www.microsoft.com/en-us/download/details.aspx?id=28160" SRC_URI="http://download.microsoft.com/download/6/A/B/6AB27E13-46AE-4CE9-AFFD-406367CADC1D/Linux6/${P}.tar.gz" #md5: 36aca6fdfaa6e87754c477e08969fed4 #sha1: ba8a27b1fc91b933a31d987805a6f78e29f893b4 LICENSE="MSsqlncli-11" RESTRICT="mirror" SLOT="0" KEYWORDS="~amd64" IUSE="doc examples" MERGE_TYPE=binary HDEPEND="dev-util/patchelf" # does not work with portage-2.1.11.50 DEPEND=${HDEPEND} # workaround # The somewhat strange looking dependencies are explained by: # sys-apps/util-linux <-libuuid.so # sys-libs/e2fsprogs-libs <-libcom_err.so RDEPEND="virtual/libc virtual/krb5 dev-libs/openssl >dev-db/unixODBC-2.3.1[iconv-char-enc-utf8(+),iconv-ucode-enc-utf16le(+)] sys-apps/util-linux sys-libs/e2fsprogs-libs" MY_PV=$(get_version_component_range 1-2) MY_BV=$(get_version_component_range 3-4) # MS build number? # libsqlncli must remain the first entry, it is later referenced QA_PREBUILT=" opt/microsoft/sqlncli/$(get_libdir)/libsqlncli-${MY_PV}.so.${MY_BV} opt/microsoft/sqlncli/bin/sqlcmd-${PV} opt/microsoft/sqlncli/bin/bcp-${PV} " src_prepare() { epatch "${FILESDIR}/${P}"-use-destdir-tempdir.patch if use examples; then mkdir -p "${S}/docs/examples" || die cp -a "${FILESDIR}/examples" "${S}/docs" || die fi } src_install() { # Microsoft's install.sh assumes that these directories already exist dodir "/usr/bin" dodir "/usr/$(get_libdir)" # run the verify step TEMPDIR="${T}" DESTDIR="${ED}" ./install.sh verify # run the install step TEMPDIR="${T}" DESTDIR="${ED}" ./install.sh install --accept-license --force # Remove image path from the driver configuration file which is somehow # generated by install.sh. It is later used by odbcinst called from # pkg_postinst() sed -i -e "s:${ED}:/:" "${ED}/opt/microsoft/sqlncli/${PV}/sqlncli.ini"||die # Overall strategy in order to avoid contamination of /usr/lib64: # 1.) create symlinks for the needed libraries in # /opt/microsoft/sqlncli/lib64, pointing their surrogates # available from /usr/lib64 # 2.) set DT_NEEDED in the precompiled binaries so each library # knows where to look for the needed libraries # 3.) create /usr/lib64/libsqlncli.so as a linker script so # folks can simply link the driver directly by -lsqlncli # So ... # 1.) Create symlinks # libs is an associative array of shared library names which # are needed by the pre-compiled Microsoft binaries ([key]) # and the names of the libraries the binaries should use # instead (value). This list was manually created using # scanelf --needed local -A libs=( [libcrypto.so.10]=libcrypto.so [libssl.so.10]=libssl.so [libodbc.so.1]=libodbc.so [libodbcinst.so.1]=libodbcinst.so ) # now, for each needed library create a symlink in /opt/... for i in ${!libs[*]}; do # e.g.: $i == libssl.so.10 local replacement=${EPREFIX}/usr/$(get_libdir)/${libs[${i}]} local needed=opt/microsoft/sqlncli/$(get_libdir)/${i} dosym "${replacement}" "${needed}" done # 2.) convert QA_PREBUILT into an array ... read -a binaries <<<${QA_PREBUILT} # .. and set DT_NEEDED for each of the files named in $binaries for prebuild in ${binaries[@]}; do local runpath=${EPREFIX}/opt/microsoft/sqlncli/$(get_libdir)/ patchelf --set-rpath "${runpath}" "${ED}/${prebuild}" || die done # 3.) enable folks to link the client library directly via -lsqlncli # w/o having to specify the full installation path (nice to have) local sqllib=${EPREFIX}/${binaries[0]} local usrlib=${ED}/usr/$(get_libdir)/libsqlncli.so echo "GROUP ( ${sqllib} )" > "${usrlib}" || die # better install package specific headers into /usr/include/sqlncli/ insinto /usr/include/sqlncli doins include/* # install MS produced documentation into /usr instead of /opt insinto usr/share/docs/{PF} if use doc; then dodoc "${ED}/opt/microsoft/sqlncli/${PV}/"{README,WARNING} dohtml -r "${ED}/opt/microsoft/sqlncli/${PV}/docs/en_US/"* fi # ... and finally also the example there if use examples; then docompress -x usr/share/doc/${PF}/examples dodoc -r "${S}"/docs/examples || die fi # Prevent inadequate scripts or copies of files already installed in # /usr/include or /usr/share/doc/sqlncli to get installed in # /opt/microsoft/sqlncli/ too. # All this stuff can't simply be removed already in src_prepare() because # that implies a complete rewrite of Microsoft's install.sh. local noins={include,docs,install.sh,build_dm.sh,LICENSE,README,WARNING} rm -r "${ED}/opt/microsoft/sqlncli/${PV}/"${noins} || die } pkg_postinst() { odbcinst -i -d -f "${EPREFIX}/opt/microsoft/sqlncli/${PV}/sqlncli.ini" || die read -a binaries <<<"${QA_PREBUILT}" cat<