From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mediacenter.hi.pengutronix.de ([2001:6f8:1178:2::65]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1SexZE-0007yM-E2 for ptxdist@pengutronix.de; Thu, 14 Jun 2012 02:05:40 +0200 Received: from mol by mediacenter.hi.pengutronix.de with local (Exim 4.72) (envelope-from ) id 1SexZE-0000bZ-D4 for ptxdist@pengutronix.de; Thu, 14 Jun 2012 02:05:40 +0200 Date: Thu, 14 Jun 2012 02:05:40 +0200 From: Michael Olbrich Message-ID: <20120614000540.GD14446@pengutronix.de> References: <1339340732-8741-1-git-send-email-bernhard@bwalle.de> <1339340732-8741-3-git-send-email-bernhard@bwalle.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1339340732-8741-3-git-send-email-bernhard@bwalle.de> Subject: Re: [ptxdist] [PATCH 2/2] ptxd_make_world_install_post: Darwin: Edit install name of binaries Reply-To: ptxdist@pengutronix.de List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: ptxdist-bounces@pengutronix.de Errors-To: ptxdist-bounces@pengutronix.de To: ptxdist@pengutronix.de On Sun, Jun 10, 2012 at 05:05:32PM +0200, Bernhard Walle wrote: > This patch should solve the problem that binaries in > $PTXDIST_SYSROOT_HOST/bin must be able to find their libraries in > $PTXDIST_SYSROOT_HOST/lib. On ELF systems that problem is solved > by using rpath. However, rpath doesn't exist (works different) on > Darwin that uses the Mach-O binary format. > = > After copying the files to $PTXDIST_SYSROOT_HOST, we do following: > = > - For every library (lib/*.*.dylib), we change the install name > from /lib/libfoo.x.dylib to $PTXDIST_SYSROOT_HOST/lib/libfoo.x.dylib. > That way programs linked against that library can be executed > immediately, even in the build directory before installation > to $PTXDIST_SYSROOT_HOST. > = > That's the call of "install_name_tool -id". > = > - For every library (lib/*.*.dylib) and executable (bin/*), we > change the install name of dependent libraries to point to > $PTXDIST_SYSROOT_HOST/lib. The call of "otool -L" lists the > dependent libraries (like "readelf -d" on ELF systems) and > the call "install_name_tool -change" changes it. That step > is necessary because multiple libraries and binaries can be > built and installed at the same time, so the binary is already > built before "install_name_tool -id" is invoked. > = > That way I'm finally able to build host-qemu with host-glib and > host-gettext-dummy (that provides -lintl which host-glib uses). > = > Signed-off-by: Bernhard Walle > --- > scripts/lib/ptxd_make_world_install.sh | 5 ++ > .../lib/ptxd_make_world_install_library_path.sh | 92 ++++++++++++++= ++++++ > 2 Dateien ge=E4ndert, 97 Zeilen hinzugef=FCgt(+) > create mode 100644 scripts/lib/ptxd_make_world_install_library_path.sh > = > diff --git a/scripts/lib/ptxd_make_world_install.sh b/scripts/lib/ptxd_ma= ke_world_install.sh > index 3d5d5e5..e0418dc 100644 > --- a/scripts/lib/ptxd_make_world_install.sh > +++ b/scripts/lib/ptxd_make_world_install.sh > @@ -175,5 +175,10 @@ ptxd_make_world_install_post() { > done && > = > cp -dprf -- "${pkg_pkg_dir}"/* "${pkg_sysroot_dir}" > + > + # only for host packages > + if [ "${pkg_sysroot_dir}" =3D "${PTXDIST_SYSROOT_HOST}" ] ; then > + ptxd_make_world_install_library_path "${pkg_pkg_dir}" > + fi if [ "${pkg_type}" !=3D "target" ]; then ptxd_make_world_install_library_path fi for cross packages too, and use pkg_pkg_dir directly below. > } > export -f ptxd_make_world_install_post > diff --git a/scripts/lib/ptxd_make_world_install_library_path.sh b/script= s/lib/ptxd_make_world_install_library_path.sh > new file mode 100644 > index 0000000..32b4b45 > --- /dev/null > +++ b/scripts/lib/ptxd_make_world_install_library_path.sh > @@ -0,0 +1,92 @@ > +#!/bin/bash > +# > +# (c) 2012 Bernhard Walle > +# > + > +# This function is Darwin (Mac OS) specific. Helper function for > +# ptxd_make_world_install_library_path. > +# > +# It should be invoked on one binary in ptxdist platform-*/sysroot-host = (both > +# for executables and libraries after installation. For binaries and lib= raries, > +# edits the dependent shared library install name to point to sysroot-ho= st/lib. > +# For libraries only it changes also the install name (-id). That way the > +# binaries linked against a library in sysroot-target/lib can be executed > +# directly without setting environment variables. > +# > +# Arguments: $1 - the binary > +ptxd_make_world_install_library_path_one() > +{ > + local binary=3D"$1" > + local filename installfile > + > + if ! [ -r "${binary}" ] ; then > + return > + fi this was already checked, right? > + > + for used_library in $(otool -LX "${binary}" | awk '{print $1}') ; do > + filename=3D${used_library##*/} # basename filename=3D"$(basename "${used_library}")" > + > + # if the library exists in sysroot-host, we use that one > + # using @executable_path even keeps the tree relocatable. > + installfile=3D"${PTXDIST_SYSROOT_HOST}/lib/${filename}" > + if [ -r "${installfile}" ] ; then > + install_name_tool -change \ > + "${used_library}" "${installfile}" \ > + "${binary}" > + fi > + > + # if it's a library, change also the ID so that binaries > + # that link against the binary get it right in the first > + # place (so they can get executed before installation) > + if [[ ${installfile} =3D=3D *.dylib ]] ; then > + install_name_tool -id "${binary}" "${binary}" > + fi > + done > +} > +export -f ptxd_make_world_install_library_path_one > + > +# This function is Darwin (Mac OS) specific. It does nothing on other > +# operating systems. > +# > +# The function gets invoked in install.post stage after the binaries > +# have been copied from the package dir to the sysroot-host directory. > +# The function must be called with the package directory as argument. > +# For every binary (library and executable) in that package directory > +# it translates the path to the correspondent path after copying > +# to the sysroot-host and invokes ptxd_make_world_install_library_path_o= ne > +# which finally edits the install path of libaries/executables. > +# > +# Arguments: $1 - pkgdir of a package > +ptxd_make_world_install_library_path() > +{ > + if [ "$(uname -s)" !=3D Darwin ] ; then > + return > + fi > + > + local pkgdir=3D"$1" use pkg_pkg_dir directly everywhere > + local file > + local installed_file > + > + echo "install.post: Fixup library paths" > + for file in ${pkgdir}/bin/* ${pkgdir}/lib/*.*.dylib ; do > + > + # for unexpanded wildcards > + if ! [ -r "${file}" ] ; then > + continue > + fi use "find "${pkgdir}" -type f" and = file "${file}" | grep -q 'dynamically linked' || continue or something like that. Otherwise you might miss something. > + > + installed_file=3D$(echo $file | sed -e "s@${pkgdir}@${PTXDIST_SYSROOT_H= OST}@g") use ${pkg_sysroot_dir} (works for cross too) > + > + # sanity check > + if ! [ -r "${installed_file}" ] ; then > + echo >&2 "File '${file}' exists but '${installed_file}' does not af= ter coping???" > + continue > + fi imho not needed. The files where copied just before calling this. > + > + echo "${installed_file}" remove. Michael > + ptxd_make_world_install_library_path_one "${installed_file}" > + done > + > + echo "install.post: Fixup library paths: done" > +} > +export -f ptxd_make_world_install_library_path > -- = > 1.7.10.4 > = > = > -- = > ptxdist mailing list > ptxdist@pengutronix.de -- = Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- = ptxdist mailing list ptxdist@pengutronix.de