1# destdir.at -- test various DESTDIR issues                   -*- Autotest -*-
2
3#   Copyright (C) 2006-2007, 2011-2015 Free Software Foundation, Inc.
4#   Written by Ralf Wildenhues, 2006
5#
6#   This file is part of GNU Libtool.
7#
8# GNU Libtool is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; either version 2 of
11# the License, or (at your option) any later version.
12#
13# GNU Libtool is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with GNU Libtool; see the file COPYING.  If not, a copy
20# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
21# or obtained by writing to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23####
24
25AT_BANNER([DESTDIR tests])
26
27# Common setup for the next few tests.
28m4_pushdef([_LT_DIRSETUP],
29[# DESTDIR installs do not work with relink at install time.
30AT_XFAIL_IF([eval `$LIBTOOL --config | $GREP '^fast_install='`
31           case $fast_install in no) :;; *) false;; esac])
32LDFLAGS="$LDFLAGS -no-undefined"
33if test -n "$we_are_on_a_safe_system"; then # let's read shorter cmdlines.
34  DESTDIR=/tmp/dest
35  prefix=/tmp/inst
36  rm -rf $DESTDIR $prefix
37else
38  DESTDIR=`pwd`/dest
39  prefix=`pwd`/inst
40fi
41libdir=$prefix/lib
42bindir=$prefix/bin
43$mkdir_p src $prefix $DESTDIR $DESTDIR$prefix
44eval `$LIBTOOL --config | $EGREP '^(FGREP|OBJDUMP)='`
45])
46
47
48AT_SETUP([Simple DESTDIR install])
49AT_KEYWORDS([libtool])
50
51# A program that depends upon a library, both in the same package.
52_LT_DIRSETUP
53cd src
54echo 'int a() { return 0; }' > a.c
55$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c
56$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo -rpath $libdir
57echo 'extern int a(); int main() { return a(); }' > m.c
58$CC $CPPFLAGS $CFLAGS -c m.c
59$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o m$EXEEXT m.$OBJEXT liba.la
60mkdir $DESTDIR$libdir $DESTDIR$bindir
61AT_CHECK([$LIBTOOL --mode=install cp liba.la $DESTDIR$libdir/liba.la],
62	 [], [ignore], [ignore])
63AT_CHECK([$LIBTOOL --mode=install cp m$EXEEXT $DESTDIR$bindir/m$EXEEXT],
64	 [], [ignore], [ignore])
65$LIBTOOL --mode=clean rm -f liba.la m
66LT_AT_MVDIR(["$DESTDIR$libdir"], ["$libdir"])
67LT_AT_MVDIR(["$DESTDIR$bindir"], ["$bindir"])
68# We ignore failure on purpose here: we may not be root.
69AT_CHECK([$LIBTOOL --mode=finish $libdir], [ignore], [ignore], [ignore])
70LT_AT_EXEC_CHECK([$bindir/m$EXEEXT])
71
72AT_CLEANUP
73
74
75AT_SETUP([DESTDIR with in-package deplibs])
76AT_KEYWORDS([libtool])
77
78# A program that depends upon a library that depends upon another
79# library, all in the same package.  Use two deplibs, one in $libdir
80# and one in another directory.
81_LT_DIRSETUP
82cd src
83echo 'int a1dep() { return 0; }' > a1dep.c
84$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a1dep.c
85$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba1dep.la a1dep.lo -rpath $libdir
86echo 'int a2dep() { return 0; }' > a2dep.c
87$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a2dep.c
88$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba2dep.la a2dep.lo -rpath ${libdir}2
89echo 'extern int a1dep(), a2dep(); int a() { return a1dep() + a2dep(); }' > a.c
90$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c
91$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo -rpath $libdir liba1dep.la liba2dep.la
92echo 'extern int a(); int main() { return a(); }' > m.c
93$CC $CPPFLAGS $CFLAGS -c m.c
94$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o m$EXEEXT m.$OBJEXT liba.la
95mkdir $DESTDIR$libdir $DESTDIR${libdir}2 $DESTDIR$bindir
96AT_CHECK([$LIBTOOL --mode=install cp liba1dep.la $DESTDIR$libdir/liba1dep.la],
97	 [], [ignore], [ignore])
98AT_CHECK([$LIBTOOL --mode=install cp liba2dep.la $DESTDIR${libdir}2/liba2dep.la],
99	 [], [ignore], [ignore])
100AT_CHECK([$LIBTOOL --mode=install cp liba.la $DESTDIR$libdir/liba.la],
101	 [], [ignore], [ignore])
102AT_CHECK([$LIBTOOL --mode=install cp m$EXEEXT $DESTDIR$bindir/m$EXEEXT],
103	 [], [ignore], [ignore])
104$LIBTOOL --mode=clean rm -f liba1dep.la liba2dep.la liba.la m
105LT_AT_MVDIR(["$DESTDIR$libdir"], ["$libdir"])
106LT_AT_MVDIR(["$DESTDIR${libdir}2"], ["${libdir}2"])
107LT_AT_MVDIR(["$DESTDIR$bindir"], ["$bindir"])
108# We ignore failure on purpose here: we may not be root.
109AT_CHECK([$LIBTOOL --mode=finish $libdir ${libdir}2], [ignore], [ignore], [ignore])
110
111# put false libraries in the DESTDIR paths: if the installed program
112# refers to them, that is a bug.
113mkdir $DESTDIR$libdir $DESTDIR${libdir}2 $DESTDIR$bindir
114for lib in a1dep a2dep a; do
115  case $lib in
116  a2dep) ldir=${libdir}2;;
117  *)     ldir=$libdir;;
118  esac
119  echo "int this_should_not_be_linked_against () { return 0; }" > $lib.c
120  $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $lib.c
121  # Note the rpath argument includes $DESTDIR: the installed false libs
122  # should be functional (i.e., not need 'libtool --mode=finish').
123  $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o lib$lib.la $lib.lo -rpath $DESTDIR$ldir
124  $LIBTOOL --mode=install cp lib$lib.la $DESTDIR$ldir/lib$lib.la
125done
126
127LT_AT_EXEC_CHECK([$bindir/m$EXEEXT])
128
129# TODO: make this more portable:
130if test false != "$OBJDUMP" && ($OBJDUMP -p $bindir/m$EXEEXT) >/dev/null 2>&1; then
131  AT_CHECK([$OBJDUMP -p $bindir/m$EXEEXT | $EGREP -i "R(UN)?PATH.*$DESTDIR"], [1])
132  . $libdir/liba.la
133  set x $library_names
134  lname=$2
135  if test -n "$lname"; then
136    AT_CHECK([$OBJDUMP -p $libdir/$lname | $EGREP -i "R(UN)?PATH.*$DESTDIR"], [1])
137  fi
138fi
139
140AT_CLEANUP
141
142m4_popdef([_LT_DIRSETUP])
143