Bump to 1.14.1
[platform/upstream/augeas.git] / tests / havelib / rpathcfg.sh
1 #!/bin/sh
2 # Prints information for maintaining config.rpath.
3
4 # The caller should set the environment variables
5 # top_srcdir, srcdir, CONFIG_SHELL, CC, GCC, LDFLAGS, LD, LIBDIRSTEM, with_gnu_ld, host.
6
7 if test -f $top_srcdir/build-aux/config.rpath; then
8   build_aux_dir=$top_srcdir/build-aux
9 else
10   build_aux_dir=$top_srcdir/../build-aux
11 fi
12
13 echo "=============== rpathcfg for $host ==============="
14 echo
15 echo "--------------- config.rpath output ---------------"
16 ${CONFIG_SHELL-/bin/sh} $build_aux_dir/config.rpath "$host" | sed -e 's/^acl_cv_//'
17 echo "--------------- experimentally determined ---------------"
18 builddir=`pwd`
19 global_top_auxdir=`cd "$top_srcdir"/build-aux && pwd`
20 export global_top_auxdir
21
22 tstdir='tst/dir'
23 test -d $tstdir || { mkdir tst && mkdir $tstdir; }
24
25 rm -rf tstprefix $tstdir/build tstlib
26
27 eval `${CONFIG_SHELL-/bin/sh} $build_aux_dir/config.rpath "$host" | grep '^acl_cv_wl='`
28 wl="$acl_cv_wl"
29
30 # Static library suffix (normally "a").
31 mkdir tstprefix
32 mkdir $tstdir/build
33 (cd $srcdir/rpathx && tar cf - *) | (cd $tstdir/build && tar xf -)
34 (cd $tstdir/build
35  ${CONFIG_SHELL-/bin/sh} ./configure --disable-shared --prefix=$builddir/tstprefix --libdir=$builddir/tstprefix/${LIBDIRSTEM-lib} > configure.log 2>&1
36  make > make.log 2>&1
37  make install > install.log 2>&1
38 )
39 rm -rf $tstdir/build
40 libext=
41 cd tstprefix/lib
42 for f in *; do
43   case $f in
44     *.la) ;;
45     *[0-9]) ;;
46     *) libext=`echo $f | sed -e 's/^.*\.//'`;;
47   esac
48   if test -n "$libext"; then
49     break
50   fi
51 done
52 cd ../..
53 rm -rf tstprefix
54
55 # Shared library suffix (normally "so").
56 mkdir tstprefix
57 mkdir $tstdir/build
58 (cd $srcdir/rpathx && tar cf - *) | (cd $tstdir/build && tar xf -)
59 (cd $tstdir/build
60  ${CONFIG_SHELL-/bin/sh} ./configure --disable-static --prefix=$builddir/tstprefix --libdir=$builddir/tstprefix/${LIBDIRSTEM-lib} > configure.log 2>&1
61  make > make.log 2>&1
62  make install > install.log 2>&1
63 )
64 rm -rf $tstdir/build
65 shlibext=
66 cd tstprefix/lib || exit 1
67 for f in *; do
68   case $f in
69     *.la) ;;
70     *[0-9]) ;;
71     *) shlibext=`echo $f | sed -e 's/^.*\.//'`;;
72   esac
73   if test -n "$shlibext"; then
74     break
75   fi
76 done
77 cd ../..
78 rm -rf tstprefix
79
80 # Prepare hardcoding tests.
81 mkdir tstprefix
82 mkdir $tstdir/build
83 (cd $srcdir/rpathx && tar cf - *) | (cd $tstdir/build && tar xf -)
84 (cd $tstdir/build
85  ${CONFIG_SHELL-/bin/sh} ./configure --disable-static --prefix=$builddir/tstprefix --libdir=$builddir/tstprefix/${LIBDIRSTEM-lib} > configure.log 2>&1
86  make > make.log 2>&1
87  make install > install.log 2>&1
88 )
89 rm -rf $tstdir/build
90
91 # Flag to hardcode \$libdir into a binary during linking.
92 # This must work even if \$libdir does not exist.
93 hardcode_libdir_flag_spec=
94 for spec in \
95     '-L$libdir' \
96     '-R$libdir' \
97     '-rpath $libdir' '${wl}-rpath ${wl}$libdir' \
98     '${wl}+b ${wl}$libdir' \
99     '${wl}-R $libdir:/usr/lib:/lib' \
100     '${wl}-blibpath:$libdir:/usr/lib:/lib' \
101     '${wl}-bnolibpath ${wl}-blibpath:$libdir:/usr/lib:/lib' \
102   ; do
103   mv tstprefix/lib tstlib
104   libdir=`pwd`/tstprefix/lib
105   eval flag=\"$spec\"
106   echo 1>&2
107   echo "$CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag -o a.out" 1>&2
108   $CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag -o a.out
109   if test $? = 0; then
110     mv tstlib tstprefix/lib
111     echo "ok, running created a.out." 1>&2
112     if ./a.out; then
113       hardcode_libdir_flag_spec="$hardcode_libdir_flag_spec$spec
114 "
115     fi
116   else
117     mv tstlib tstprefix/lib
118   fi
119   rm -f a.out
120 done
121
122 # Whether we need a single -rpath flag with a separated argument.
123 hardcode_libdir_separator=
124 if test -n "$hardcode_libdir_flag_spec"; then
125   spec=`echo "$hardcode_libdir_flag_spec" | sed -e '2,$d'`
126   # Try with multiple -rpath flags.
127   mv tstprefix/lib tstlib
128   libdir=`pwd`/tstprefix/lib
129   eval flag1=\"$spec\"
130   libdir=/tmp
131   eval flag2=\"$spec\"
132   echo 1>&2
133   echo "$CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag1 $flag2 -o a.out" 1>&2
134   $CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag1 $flag2 -o a.out
135   if test $? = 0; then
136     mv tstlib tstprefix/lib
137     echo "ok, running created a.out." 1>&2
138     if ./a.out; then
139       hardcode_libdir_separator=NONE
140     fi
141   else
142     mv tstlib tstprefix/lib
143   fi
144   rm -f a.out
145   if test -z "$hardcode_libdir_separator"; then
146     # Try with a single -rpath flag.
147     mv tstprefix/lib tstlib
148     libdir=`pwd`/tstprefix/lib:/tmp
149     eval flag=\"$spec\"
150     echo 1>&2
151     echo "$CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag -o a.out" 1>&2
152     $CC $LDFLAGS $srcdir/rpathlx/usex.c tstlib/librpathx.$shlibext $flag -o a.out
153     if test $? = 0; then
154       mv tstlib tstprefix/lib
155       echo "ok, running created a.out." 1>&2
156       if ./a.out; then
157         hardcode_libdir_separator=:
158       fi
159     else
160       mv tstlib tstprefix/lib
161     fi
162     rm -f a.out
163   fi
164   if test -z "$hardcode_libdir_separator"; then
165     echo "hardcode_libdir_separator test failed!" 1>&2
166   else
167     if test "$hardcode_libdir_separator" = NONE; then
168       hardcode_libdir_separator=
169     fi
170   fi
171 fi
172
173 # Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
174 # resulting binary.
175 hardcode_direct=no
176 echo 1>&2
177 echo "$CC $LDFLAGS $srcdir/rpathlx/usex.c tstprefix/lib/librpathx.$shlibext -o a.out" 1>&2
178 $CC $LDFLAGS $srcdir/rpathlx/usex.c tstprefix/lib/librpathx.$shlibext -o a.out
179 if test $? = 0; then
180   echo "ok, running created a.out." 1>&2
181   if ./a.out; then
182     hardcode_direct=yes
183   fi
184 fi
185 rm -f a.out
186
187 # Set to yes if using the -LDIR flag during linking hardcodes DIR into the
188 # resulting binary.
189 hardcode_minus_L=no
190 echo 1>&2
191 echo "$CC $LDFLAGS $srcdir/rpathlx/usex.c -Ltstprefix/lib -lrpathx -o a.out" 1>&2
192 $CC $LDFLAGS $srcdir/rpathlx/usex.c -Ltstprefix/lib -lrpathx -o a.out
193 if test $? = 0; then
194   echo "ok, running created a.out." 1>&2
195   if ./a.out; then
196     hardcode_minus_L=yes
197   fi
198 fi
199 rm -f a.out
200
201 # Clean up.
202 rm -rf tstprefix $tstdir
203
204 sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
205 escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
206 escaped_sys_lib_search_path_spec=`echo "X$sys_lib_search_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
207 escaped_sys_lib_dlsearch_path_spec=`echo "X$sys_lib_dlsearch_path_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
208
209 cat <<EOF
210
211 # Static library suffix (normally "a").
212 libext="$libext"
213
214 # Shared library suffix (normally "so").
215 shlibext="$shlibext"
216
217 # Flag to hardcode \$libdir into a binary during linking.
218 # This must work even if \$libdir does not exist.
219 hardcode_libdir_flag_spec="$escaped_hardcode_libdir_flag_spec"
220
221 # Whether we need a single -rpath flag with a separated argument.
222 hardcode_libdir_separator="$hardcode_libdir_separator"
223
224 # Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
225 # resulting binary.
226 hardcode_direct="$hardcode_direct"
227
228 # Set to yes if using the -LDIR flag during linking hardcodes DIR into the
229 # resulting binary.
230 hardcode_minus_L="$hardcode_minus_L"
231
232 EOF