Resync Autoconf macros from rra-c-util 3.3
[openafs.git] / src / cf / lib-pathname.m4
1 dnl Determine the library path name.
2 dnl
3 dnl Red Hat systems and some other Linux systems use lib64 and lib32 rather
4 dnl than just lib in some circumstances.  This file provides an Autoconf
5 dnl macro, RRA_SET_LDFLAGS, which given a variable, a prefix, and an optional
6 dnl suffix, adds -Lprefix/lib, -Lprefix/lib32, or -Lprefix/lib64 to the
7 dnl variable depending on which directories exist and the size of a long in
8 dnl the compilation environment.  If a suffix is given, a slash and that
9 dnl suffix will be appended, to allow for adding a subdirectory of the library
10 dnl directory.
11 dnl
12 dnl This file also provides the Autoconf macro RRA_SET_LIBDIR, which sets the
13 dnl libdir variable to PREFIX/lib{,32,64} as appropriate.
14 dnl
15 dnl Written by Russ Allbery <rra@stanford.edu>
16 dnl Copyright 2008, 2009
17 dnl     The Board of Trustees of the Leland Stanford Junior University
18 dnl
19 dnl This file is free software; the authors give unlimited permission to copy
20 dnl and/or distribute it, with or without modifications, as long as this
21 dnl notice is preserved.
22
23 dnl Probe for the alternate library name that we should attempt on this
24 dnl architecture, given the size of an int, and set rra_lib_arch_name to that
25 dnl name.  Separated out so that it can be AC_REQUIRE'd and not run multiple
26 dnl times.
27 dnl
28 dnl There is an unfortunate abstraction violation here where we assume we know
29 dnl the cache variable name used by Autoconf.  Unfortunately, Autoconf doesn't
30 dnl provide any other way of getting at that information in shell that I can
31 dnl see.
32 AC_DEFUN([_RRA_LIB_ARCH_NAME],
33 [rra_lib_arch_name=lib
34  AC_CHECK_SIZEOF([long])
35  AS_IF([test "$ac_cv_sizeof_long" -eq 4 && test -d /usr/lib32],
36      [rra_lib_arch_name=lib32],
37      [AS_IF([test "$ac_cv_sizeof_long" -eq 8 && test -d /usr/lib64],
38          [rra_lib_arch_name=lib64])])])
39
40 dnl Set VARIABLE to -LPREFIX/lib{,32,64} or -LPREFIX/lib{,32,64}/SUFFIX as
41 dnl appropriate.
42 AC_DEFUN([RRA_SET_LDFLAGS],
43 [AC_REQUIRE([_RRA_LIB_ARCH_NAME])
44  AS_IF([test -d "$2/$rra_lib_arch_name"],
45     [AS_IF([test x"$3" = x],
46         [$1="[$]$1 -L$2/${rra_lib_arch_name}"],
47         [$1="[$]$1 -L$2/${rra_lib_arch_name}/$3"])],
48     [AS_IF([test x"$3" = x],
49         [$1="[$]$1 -L$2/lib"],
50         [$1="[$]$1 -L$2/lib/$3"])])
51  $1=`echo "[$]$1" | sed -e 's/^ *//'`])
52
53 dnl Set libdir to PREFIX/lib{,32,64} as appropriate.
54 AC_DEFUN([RRA_SET_LIBDIR],
55 [AC_REQUIRE([_RRA_LIB_ARCH_NAME])
56  AS_IF([test -d "$1/$rra_lib_arch_name"],
57     [libdir="$1/${rra_lib_arch_name}"],
58     [libdir="$1/lib"])])