1# relocatable.m4 serial 3 (gettext-0.15)
2dnl Copyright (C) 2003, 2005 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9dnl Support for relocateble programs.
10AC_DEFUN([AC_RELOCATABLE],
11[
12  AC_REQUIRE([AC_PROG_INSTALL])
13  AC_BEFORE([AC_PROG_INSTALL],[AC_RELOCATABLE])
14  AC_REQUIRE([AC_LIB_LIBPATH])
15  AC_REQUIRE([AC_RELOCATABLE_LIBRARY])
16  is_noop=no
17  use_elf_origin_trick=no
18  if test $RELOCATABLE = yes; then
19    # --enable-relocatable implies --disable-rpath
20    enable_rpath=no
21    AC_LIBOBJ([relocatable])
22    AC_DEFINE([ENABLE_RELOCATABLE], 1,
23      [Define to 1 if the package shall run at any location in the filesystem.])
24    case "$host_os" in
25      mingw*) is_noop=yes ;;
26      linux*) use_elf_origin_trick=yes ;;
27    esac
28    if test $is_noop = yes; then
29      SET_RELOCATABLE="RELOCATABLE_LDFLAGS = :"
30    else
31      if test $use_elf_origin_trick = yes; then
32        dnl Use the dynamic linker's support for relocatable programs.
33        case "$ac_aux_dir" in
34          /*) reloc_ldflags="$ac_aux_dir/reloc-ldflags" ;;
35          *) reloc_ldflags="\$(top_builddir)/$ac_aux_dir/reloc-ldflags" ;;
36        esac
37        SET_RELOCATABLE="RELOCATABLE_LDFLAGS = \"$reloc_ldflags\" \"\$(host)\" \"\$(RELOCATABLE_LIBRARY_PATH)\""
38      else
39        dnl Unfortunately we cannot define INSTALL_PROGRAM to a command
40        dnl consisting of more than one word - libtool doesn't support this.
41        dnl So we abuse the INSTALL_PROGRAM_ENV hook, originally meant for the
42        dnl 'install-strip' target.
43        SET_RELOCATABLE="INSTALL_PROGRAM_ENV = RELOC_LIBRARY_PATH_VAR=\"$shlibpath_var\" RELOC_LIBRARY_PATH_VALUE=\"\$(RELOCATABLE_LIBRARY_PATH)\" RELOC_PREFIX=\"\$(prefix)\" RELOC_COMPILE_COMMAND=\"\$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(LDFLAGS)\" RELOC_SRCDIR=\"\$(RELOCATABLE_SRC_DIR)\" RELOC_BUILDDIR=\"\$(RELOCATABLE_BUILD_DIR)\" RELOC_CONFIG_H_DIR=\"\$(RELOCATABLE_CONFIG_H_DIR)\" RELOC_INSTALL_PROG=\"$INSTALL_PROGRAM\""
44        case "$ac_aux_dir" in
45          /*) INSTALL_PROGRAM="$ac_aux_dir/install-reloc" ;;
46          *) INSTALL_PROGRAM="\$(top_builddir)/$ac_aux_dir/install-reloc" ;;
47        esac
48      fi
49    fi
50  else
51    SET_RELOCATABLE=
52  fi
53  AC_SUBST([SET_RELOCATABLE])
54  AM_CONDITIONAL([RELOCATABLE_VIA_LD],
55    [test $is_noop = yes || test $use_elf_origin_trick = yes])
56])
57
58dnl Support for relocatable libraries.
59AC_DEFUN([AC_RELOCATABLE_LIBRARY],
60[
61  AC_REQUIRE([AC_RELOCATABLE_NOP])
62  dnl Easier to put this here once, instead of into the DEFS of each Makefile.
63  if test "X$prefix" = "XNONE"; then
64    reloc_final_prefix="$ac_default_prefix"
65  else
66    reloc_final_prefix="$prefix"
67  fi
68  AC_DEFINE_UNQUOTED([INSTALLPREFIX], ["${reloc_final_prefix}"],
69    [Define to the value of ${prefix}, as a string.])
70])
71
72dnl Support for relocatable packages for which it is a nop.
73AC_DEFUN([AC_RELOCATABLE_NOP],
74[
75  AC_MSG_CHECKING([whether to activate relocatable installation])
76  AC_ARG_ENABLE(relocatable,
77    [  --enable-relocatable    install a package that can be moved in the filesystem],
78    [if test "$enableval" != no; then
79       RELOCATABLE=yes
80     else
81       RELOCATABLE=no
82     fi
83    ], RELOCATABLE=no)
84  AC_SUBST(RELOCATABLE)
85  AC_MSG_RESULT([$RELOCATABLE])
86])
87
88dnl Determine the platform dependent parameters needed to use relocatability:
89dnl shlibpath_var.
90AC_DEFUN([AC_LIB_LIBPATH],
91[
92  AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD
93  AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
94  AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
95  AC_CACHE_CHECK([for shared library path variable], acl_cv_libpath, [
96    LD="$LD" \
97    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.libpath" "$host" > conftest.sh
98    . ./conftest.sh
99    rm -f ./conftest.sh
100    acl_cv_libpath=${acl_cv_shlibpath_var:-none}
101  ])
102  shlibpath_var="$acl_cv_shlibpath_var"
103])
104