Enforcing library version in a port Makefile?

b. f. bf1783 at googlemail.com
Sun Oct 11 05:16:00 UTC 2009


Alex Stangl wrote:
>I am trying to create a new port. The software I am trying to port uses
>scons which calls out to pkg-config to check for certain minimal library
>version #s (e.g., sndfile >= 1.0.18, libcurl >= 7).

>I would like to enforce these same checks upfront in the Makefile rather
>than letting the build potentially blow up in scons. Section 5.7.8 of the
>Porter's Handbook says that all of the _DEPENDS variables *except
>LIB_DEPENDS* can enforce minimal dependency versions. It's not clear why
>LIB_DEPENDS is excluded here, or what the correct alternative approach
>is. It doesn't seem like putting LIB_DEPENDS= curl.5 is equivalent to
>libcurl >= 7. Hopefully there's a straightforward way to accomplish
>this, without having to patch or scrap the scons config file.
>Unfortunately I have not been able to find the answers from
>searching the net, so I hope somebody here can help.

It's not enforced in quite the same way, but there is a check on the
version of the library if you specify it, only the check is for an
exact match, not an inequality.  You can see the precise means by
which this is accomplished by looking at the lib-depends target in
/usr/ports/Mk/bsd.port.mk   (beginning on line 5102 of version 1.629
of this file).  For example,

make -vn -C /usr/ports/math/R lib-depends

yields:


 for i in blas.2:/usr/ports/math/blas  lapack.4:/usr/ports/math/lapack
icui18n:/usr/ports/devel/icu jpeg.10:/usr/ports/graphics/jpeg
pcre.0:/usr/ports/devel/pcre png.5:/usr/ports/graphics/png
tk85:/usr/ports/x11-toolkits/tk85
iconv.3:/usr/ports/converters/libiconv; do  lib=${i%%:*};
pattern="`echo $lib | /usr/bin/sed -E -e 's/\./\\\\./g' -e
's/(\\\\)?\+/\\\\+/g'`" dir=${i#*:};  target=${i##*:};  if test $dir =
$target; then  target="install";  depends_args="";  else
dir=${dir%%:*};  fi;  echo -n "===>   R-2.9.2 depends on shared
library: $lib";  if /sbin/ldconfig  -r | /usr/bin/grep -vwF -e
"/usr/local/lib/compat/pkg" | /usr/bin/grep -qwE -e "-l$pattern"; then
 echo " - found";  if [ 0 = 1 ]; then  echo "       (but building it
anyway)";  notfound=1;  else  notfound=0;  fi;  else  echo " - not
found";  notfound=1;  fi;  if [ $notfound != 0 ]; then  echo "===>
Verifying $target for $lib in $dir";  if [ ! -d "$dir" ]; then  echo "
    => No directory for $lib.  Skipping..";  else  if [ X != "X" ];
then  subpkgfile=`(cd $dir; make $depends_args -V PKGFILE)`;  if [ -r
"${subpkgfile}" -a "$target" = "install" ]; then  echo "===>
Installing existing package ${subpkgfile}";  /usr/sbin/pkg_add
${subpkgfile};  else  (cd $dir; make -DINSTALLS_DEPENDS $target
$depends_args) ;  fi;  else  (cd $dir; make -DINSTALLS_DEPENDS $target
$depends_args) ;  fi;  echo "===>   Returning to build of R-2.9.2";
if ! /sbin/ldconfig  -r | /usr/bin/grep -vwF -e
"/usr/local/lib/compat/pkg" | /usr/bin/grep -qwE -e "-l$pattern"; then
 echo "Error: shared library \"$lib\" does not exist";  false;  fi;
fi;  fi;  done

So:
 i=blas.2:/usr/ports/math/blas   =>
lib=blas.2  =>
pattern=blas\\.2

leading to the check:

/sbin/ldconfig  -r | /usr/bin/grep -vwF -e "/usr/local/lib/compat/pkg"
| /usr/bin/grep -wE -e "-lblas\\.2"

which is version-specific.  Probably an inequality check was not
implemented because libraries with different major versions are
expected to have different and incompatible ABI/APIs.  The
corresponding version numbers of the port as a whole are not usually
relevant for LIB_DEPENDS, only the version of the shared library
itself, as the upstream maintainers are supposed to change a shared
library version if and only if they change the API/ABI of the library.
 If you are relying upon some feature of a port that may change while
it's relevant shared library versions remain the same, then you should
add the port to the other *_DEPENDS as needed, with appropriate checks
on the port version number in those variables.

b.


More information about the freebsd-ports mailing list