From 71e5c385981ad456c893bf95d2c1ae01b2c78421 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 29 Oct 2010 10:23:25 +0200 Subject: [PATCH] xbps-src: added XBPS_LDFLAGS into the configuration file. This is to specify common LDFLAGS settings for all packages, by default it's set to '-Wl,--as-needed' to avoid linking extra libraries into the binaries. This helped to find such cases. --- xbps-src/etc/xbps-src.conf | 9 +++++++++ xbps-src/shutils/build_funcs.sh | 11 +++++++++-- xbps-src/shutils/chroot.sh.in | 1 + xbps-src/shutils/configure_funcs.sh | 11 +++++++++-- xbps-src/shutils/tmpl_funcs.sh.in | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/xbps-src/etc/xbps-src.conf b/xbps-src/etc/xbps-src.conf index 48448cb4eb9..c89382ef1d6 100644 --- a/xbps-src/etc/xbps-src.conf +++ b/xbps-src/etc/xbps-src.conf @@ -19,6 +19,15 @@ XBPS_MASTERDIR=$XBPS_DISTRIBUTIONDIR/masterdir XBPS_CFLAGS="-O2 -pipe" XBPS_CXXFLAGS="$XBPS_CFLAGS" +# +# Linker flags passed to the compiler. By default we use --as-needed to +# avoid linking extra libraries into binaries. See the following link +# for info: +# +# http://www.gentoo.org/proj/en/qa/asneeded.xml +# +XBPS_LDFLAGS="-Wl,--as-needed" + # # Number of jobs when running make(1)-alike commands. # diff --git a/xbps-src/shutils/build_funcs.sh b/xbps-src/shutils/build_funcs.sh index c2f484ac8d0..9099a9b65ea 100644 --- a/xbps-src/shutils/build_funcs.sh +++ b/xbps-src/shutils/build_funcs.sh @@ -30,6 +30,7 @@ build_src_phase() { local pkg="$pkgname-$version" pkgparam="$1" f lver + local mkldflags [ -z $pkgparam ] && [ -z $pkgname -o -z $version ] && return 1 @@ -57,7 +58,7 @@ build_src_phase() make_cmd="python" make_build_args="setup.py build" else - [ -z "$make_cmd" ] && make_cmd=/usr/bin/make + [ -z "$make_cmd" ] && make_cmd=make [ -n "$XBPS_MAKEJOBS" -a -z "$disable_parallel_build" ] && \ makejobs="-j$XBPS_MAKEJOBS" fi @@ -77,6 +78,7 @@ build_src_phase() msg_normal "Package '$pkgname ($lver)': running build phase." if [ "$build_style" = "custom-install" ]; then + [ -n "$XBPS_LDFLAGS" ] && export LDFLAGS="$XBPS_LDFLAGS" run_func do_build 2>${wrksrc}/.xbps_do_build.log if [ $? -ne 0 -a $? -ne 255 ]; then msg_error "Package '$pkgname': do_build phase failed!" @@ -85,7 +87,12 @@ build_src_phase() # # Build package via make. # - ${make_cmd} ${makejobs} ${make_build_args} \ + if [ "$build_style" = "gnu_makefile" ]; then + if [ -n "$XBPS_LDFLAGS" ]; then + mkldfags="$LDFLAGS $XBPS_LDFLAGS" + fi + fi + env LDFLAGS="$mkldflags" ${make_cmd} ${makejobs} ${make_build_args} \ ${make_build_target} || msg_error "Package '$pkgname': build phase failed!" fi diff --git a/xbps-src/shutils/chroot.sh.in b/xbps-src/shutils/chroot.sh.in index 443cab5a1b2..77d3a7af472 100644 --- a/xbps-src/shutils/chroot.sh.in +++ b/xbps-src/shutils/chroot.sh.in @@ -61,6 +61,7 @@ XBPS_DISTRIBUTIONDIR=/xbps XBPS_MASTERDIR=/ XBPS_CFLAGS="$XBPS_CFLAGS" XBPS_CXXFLAGS="$XBPS_CFLAGS" +XBPS_LDFLAGS="$XBPS_LDFLAGS" XBPS_FETCH_CMD="xbps-uhelper.static fetch" XBPS_COMPRESS_CMD="$XBPS_COMPRESS_CMD" _EOF diff --git a/xbps-src/shutils/configure_funcs.sh b/xbps-src/shutils/configure_funcs.sh index 01c1c906946..ef7b48dc58a 100644 --- a/xbps-src/shutils/configure_funcs.sh +++ b/xbps-src/shutils/configure_funcs.sh @@ -30,6 +30,7 @@ configure_src_phase() { local f lver error=0 + local conf_ldflags [ -z $pkgname ] && return 1 @@ -84,12 +85,17 @@ configure_src_phase() cd $build_wrksrc || return 1 fi + if [ -n "$XBPS_LDFLAGS" ]; then + conf_ldflags="$XBPS_LDFLAGS" + fi + case "$build_style" in gnu_configure|gnu-configure) # # Packages using GNU autoconf # - ${configure_script} --prefix=/usr --sysconfdir=/etc \ + env LDFLAGS="$LDFLAGS $conf_ldflags" \ + ${configure_script} --prefix=/usr --sysconfdir=/etc \ --infodir=/usr/share/info --mandir=/usr/share/man \ ${configure_args} || error=$? ;; @@ -97,7 +103,8 @@ configure_src_phase() # # Packages using custom configure scripts. # - ${configure_script} ${configure_args} || error=$? + env LDFLAGS="$LDFLAGS $conf_ldflags" ${configure_script} \ + ${configure_args} || error=$? ;; perl-module|perl_module) # diff --git a/xbps-src/shutils/tmpl_funcs.sh.in b/xbps-src/shutils/tmpl_funcs.sh.in index 8f6b77e7ffb..d4f5ab661f1 100644 --- a/xbps-src/shutils/tmpl_funcs.sh.in +++ b/xbps-src/shutils/tmpl_funcs.sh.in @@ -265,9 +265,9 @@ set_tmpl_common_vars() export CFLAGS="$XBPS_CFLAGS" export CXXFLAGS="$XBPS_CXXFLAGS" - export CPPFLAGS="-I$XBPS_MASTERDIR/usr/include" if [ -z "$in_chroot" ]; then + export CPPFLAGS="-I$XBPS_MASTERDIR/usr/include" if [ -d /usr/lib/libfakeroot ]; then LDLIBPATH="/usr/lib/libfakeroot:$XBPS_MASTERDIR/usr/lib" else