help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to switch behaviour according to glibc version?


From: David Boyce
Subject: Re: How to switch behaviour according to glibc version?
Date: Tue, 5 Apr 2016 06:23:03 -0700

This is primarily a shell coding question, not a make question. Once you've
worked out how to do it at the shell level you can wrap the result in the
$(shell ...) make function and, assuming proper escaping, it will work the
same. It looks to me like the version is the last word of the first line,
thus

% ldd --version | head -1 | awk '{print $NF}'
2.12

Though you could probably avoid the head -1 with smarter use of awk, perl,
etc. I have a make function for comparing dotted version numbers:

# Compares two dotted numeric strings (e.g 2.3.16.1) for $1 >= $2
define version_ge
$(findstring TRUE,$(shell bash -c 'sort -cu -t. -k1,1nr -k2,2nr -k3,3nr
-k4,4nr <(echo -e "$2\n$1") 2>&1 || echo TRUE'))
endef

Sample usage:

verstr := $(shell <command line such as above>)
ifeq ($(call version_ge,$(verstr),2.22),TRUE)
   # the version is sufficient
endif

FWIW glibc has a trick such that you can also execute it directly to get
the version number:

% /lib/libc.so.6 | head -1
GNU C Library stable release version 2.12, by Roland McGrath et al.

But ldd --version will almost certainly always agree with that and may be
easier to use.

> I'm not sure whether it's best to detect the o/s version or the glibc
version

If it's the glibc version that matters, it's almost always better to check
the glibc version. If you ever need to port to another glibc platform the
difference will matter.

-David B

On Tue, Apr 5, 2016 at 1:54 AM, David Aldrich <address@hidden>
wrote:

> Hi
>
> I am running gnu make 4.1 on Ubuntu.  Make builds my C++ application that
> requires glibc 2.22 or higher.  Ubuntu 14.04 has only glibc 2.19 so my
> makefile checks the host o/s and, if it's Ubuntu, it links to my private
> copy of glibc 2.22:
>
> GLIBC_FLAGS=
> ifeq ($(DISTRO),debian)
>     echo "Warning: detected Ubuntu o/s so using different glibc to that
> installed on this system"
>     GLIBC=$(MY_OPEN_SOURCE_LIBS)/glibc/v2_22/
>     GLIBC_FLAGS=
> -Wl,-rpath=${GLIBC}:${GLIBC}/math:${GLIBC}/elf:${GLIBC}/dlfcn:${GLIBC}/nss:${GLIBC}/nis:${GLIBC}/rt:${GLIBC}/resolv:${GLIBC}/crypt:${GLIBC}/nptl\
>     -Wl,--dynamic-linker=${GLIBC}/elf/ld.so
> endif
>
> Now, Ubuntu 16.04 has glibc 2.23, so there I can use the standard glibc
> packaged for the o/s.  So I want to change the makefile code to only use my
> private copy of glibc if glibc is <2.22.
>
> I'm not sure whether it's best to detect the o/s version or the glibc
> version.  I can do the latter with:
>
> ~$ ldd --version
> ldd (Ubuntu GLIBC 2.23-0ubuntu2) 2.23
> Copyright (C) 2016 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> Written by Roland McGrath and Ulrich Drepper.
>
> My question is, how can I extract the glibc version number from that ldd
> response and use it in my makefile to only set GLIBC and GLIBC_FLAGS if the
> glibc version is <2.22?
>
> Best regards
>
> David
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]