1# depdemo.at -- Library interdependencies -*- Autotest -*- 2# 3# Copyright (C) 2003-2004, 2011-2015 Free Software Foundation, Inc. 4# Written by Gary V. Vaughan, 2003 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 25 26AT_BANNER([Library interdependencies.]) 27 28## ------------------------------------------- ## 29## Some functions shared by later tests cases. ## 30## ------------------------------------------- ## 31 32func_restore_files () 33{ 34 test "`echo _fnord/temp/libs/*`" = "_fnord/temp/libs/*" \ 35 || mv -f _fnord/temp/libs/* "l3/$objdir" 36 mv -f "_fnord/temp/libl3.la" "l3" 37 test -f "_fnord/temp/lt-depdemo$EXEEXT" \ 38 && mv -f "_fnord/temp/lt-depdemo$EXEEXT" "$objdir" 39 test -f "_fnord/temp/depdemo$EXEEXT" \ 40 && mv -f "_fnord/temp/depdemo$EXEEXT" "$objdir" 41 rm -rf "_fnord" 42} 43 44func_save_files () 45{ 46 test -n "$objdir" || exit 1 47 $lt_INSTALL -d "_fnord/temp/libs" 48 test -f "$objdir/lt-depdemo$EXEEXT" \ 49 && cp -f "$objdir/lt-depdemo$EXEEXT" "_fnord/temp" 50 test -f "$objdir/depdemo$EXEEXT" \ 51 && cp -f "$objdir/depdemo$EXEEXT" "_fnord/temp" 52 cp -f l3/libl3.la "_fnord/temp" 53 cp -f l3/"$objdir"/* "_fnord/temp/libs" 54} 55 56 57# _LT_SETUP 58# --------- 59m4_define([_LT_SETUP], 60[AT_DATA([configure.ac], 61[[AC_INIT([depdemo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[) 62AC_CONFIG_AUX_DIR([build-aux]) 63AC_CONFIG_MACRO_DIRS([m4]) 64AM_INIT_AUTOMAKE 65AC_PROG_CC 66 67LT_INIT([win32-dll]) 68AC_SUBST([LIBTOOL_DEPS]) 69STATIC= 70test yes = "$enable_static" && STATIC=-static 71AC_SUBST([STATIC]) 72 73LT_LIB_M 74AC_CONFIG_FILES([Makefile l1/Makefile l2/Makefile l3/Makefile l4/Makefile]) 75AC_CONFIG_HEADERS([config.h:config.in.h]) 76AC_OUTPUT 77]]) 78 79AT_DATA([Makefile.am], 80[[AUTOMAKE_OPTIONS = no-dependencies foreign 81ACLOCAL_AMFLAGS = -I m4 82 83SUBDIRS = l1 l2 l3 l4 84 85bin_PROGRAMS = depdemo depdemo_static 86 87depdemo_SOURCES = main.c 88depdemo_LDADD = $(top_builddir)/l1/libl1.la $(top_builddir)/l2/libl2.la \ 89 $(top_builddir)/l4/libl4.la 90depdemo_DEPENDENCIES = $(top_builddir)/l1/libl1.la \ 91 $(top_builddir)/l2/libl2.la $(top_builddir)/l4/libl4.la 92 93depdemo_static_SOURCES = $(depdemo_SOURCES) 94depdemo_static_LDADD = $(depdemo_LDADD) 95depdemo_static_DEPENDENCIES = $(depdemo_DEPENDENCIES) 96depdemo_static_LDFLAGS = $(STATIC) 97 98libtool: $(LIBTOOL_DEPS) 99 $(SHELL) ./config.status --recheck 100]]) 101 102AT_DATA([main.c], 103[[#include <config.h> 104#include <stdio.h> 105#include <string.h> 106 107#include "l1/l1.h" 108#include "l2/l2.h" 109#include "l4/l4.h" 110 111#define STREQ !strcmp 112 113int main (int argc, char **argv) 114{ 115 printf("dependencies:\n"); 116 func_l1(0); 117 func_l2(0); 118 func_l4(0); 119 if (argc == 2 && STREQ (argv[1], "-alt") 120 && var_l1 + var_l2 + var_l4 == 8) 121 return 0; 122 printf("var_l1(%d) + var_l2(%d) + var_l4(%d) == %d\n", 123 var_l1,var_l2,var_l4, var_l1 + var_l2 + var_l4); 124 if (var_l1 + var_l2 + var_l4 != 19) 125 { 126 printf("var_l1(%d) + var_l2(%d) + var_l4(%d) != 19\n", 127 var_l1,var_l2,var_l4); 128 return 1; 129 } 130 return 0; 131} 132]]) 133 134# Create 4 directorys of mostly identical files. 135for i in 1 2 3 4; do 136 mkdir l$i 137 138 # l$i/Makefile.am: 139 { 140 $ECHO 'AUTOMAKE_OPTIONS = no-dependencies foreign' 141 $ECHO 'AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL'$i 142 $ECHO 'lib_LTLIBRARIES = libl'$i'.la' 143 $ECHO 'libl'$i'_la_SOURCES = l'$i'.c l'$i'.h' 144 $ECHO 'libl'$i'_la_LDFLAGS = -no-undefined' 145 $ECHO 'libl'$i'_la_LIBADD =' 146 if test 4 != $i; then 147 j=1; while test "$j" -lt "$i"; do 148 $ECHO 'libl'$i'_la_LIBADD += $(top_builddir)/l'$j'/libl'$j'.la' 149 j=`expr 1 + $j` 150 done 151 else 152 j=3 153 $ECHO 'libl'$i'_la_LIBADD += $(top_builddir)/l'$j'/libl'$j'.la $(LIBM)' 154 fi 155 } > l$i/Makefile.am 156 157 # l$i/l$i.h 158 [{ 159 $ECHO '#ifndef L'$i'_H' 160 $ECHO '#define L'$i'_H' 161 $ECHO 162 $ECHO '#if (defined _WIN32 || defined _WIN32_WCE) && !defined __GNUC__' 163 $ECHO '# ifdef BUILDING_LIBL'$i 164 $ECHO '# ifdef DLL_EXPORT' 165 $ECHO '# define LIBL'$i'_SCOPE extern __declspec (dllexport)' 166 $ECHO '# endif' 167 $ECHO '# else' 168 $ECHO '# define LIBL'$i'_SCOPE extern __declspec (dllimport)' 169 $ECHO '# endif' 170 $ECHO '#endif' 171 $ECHO '#ifndef LIBL'$i'_SCOPE' 172 $ECHO '# define LIBL'$i'_SCOPE extern' 173 $ECHO '#endif' 174 $ECHO 175 $ECHO '#ifdef __cplusplus' 176 $ECHO 'extern "C" {' 177 $ECHO '#endif' 178 $ECHO 179 $ECHO ' LIBL'$i'_SCOPE int var_l'$i';' 180 $ECHO ' int func_l'$i' (int);' 181 $ECHO 182 $ECHO '#ifdef __cplusplus' 183 $ECHO '}' 184 $ECHO '#endif' 185 $ECHO '#endif' 186 }] > l$i/l$i.h 187 188 # l$i/l$i.c: 189 { 190 if test 4 -ne $i; then 191 $ECHO '#include <config.h>' 192 $ECHO '#include <stdio.h>' 193 $ECHO 194 $ECHO '#include "l'$i'/l'$i'.h"' 195 j=1; while test "$j" -lt "$i"; do 196 $ECHO '#include "l'$j'/l'$j'.h"' 197 j=`expr 1 + $j` 198 done 199 $ECHO 200 $ECHO 'int var_l'$i' = 0;' 201 $ECHO 'int func_l'$i' (int indent) {' 202 $ECHO ' int i;' 203 $ECHO ' for (i = 0; i < indent; i++)' 204 $ECHO " putchar (' ');" 205 $ECHO ' printf ("l'$i' (%i)\n", var_l'$i');' 206 if test 1 -eq $i; then 207 $ECHO ' var_l1++;' 208 else 209 j=1; while test "$j" -lt "$i"; do 210 $ECHO ' func_l'$j'(indent+1);' 211 $ECHO ' var_l'$i' += var_l'$j';' 212 j=`expr 1 + $j` 213 done 214 fi 215 $ECHO ' return 0;' 216 $ECHO '}' 217 else 218 j=3 219 $ECHO '#include <config.h>' 220 $ECHO '#include <stdio.h>' 221 $ECHO '#include <math.h>' 222 $ECHO '#include "l'$i'/l'$i'.h"' 223 $ECHO '#include "l'$j'/l'$j'.h"' 224 $ECHO 225 $ECHO 'int var_l'$i' = 0;' 226 $ECHO 'int func_l'$i' (int indent) {' 227 $ECHO ' int i;' 228 $ECHO ' for (i = 0; i < indent; i++)' 229 $ECHO " putchar (' ');" 230 $ECHO ' printf ("l'$i' (%i)\n", var_l'$i');' 231 $ECHO ' func_l'$j'(indent+1);' 232 $ECHO ' for (i = 0; i < indent; i++)' 233 $ECHO " putchar (' ');" 234 $ECHO ' printf("libm [cos (0.0) = %g]\n", (double) cos ((double) 0.0));' 235 $ECHO ' var_l'$i' += var_l'$j';' 236 $ECHO ' return 0;' 237 $ECHO '}' 238 fi 239 } > l$i/l$i.c 240done 241 242 243LT_AT_HOST_DATA([expout], 244[[dependencies: 245l1 (0) 246l2 (0) 247 l1 (1) 248l4 (0) 249 l3 (0) 250 l1 (2) 251 l2 (2) 252 l1 (3) 253libm cos (0.0) = 1 254var_l1(4) + var_l2(6) + var_l4(9) == 19 255]]) 256 257prefix=`pwd`/_inst 258]) # _LT_SETUP 259 260 261 262# _LT_CHECK_EXECUTE([TARGETS]) 263# ---------------------------- 264# Run the listed make rules, and check that the built binaries work. 265m4_define([_LT_CHECK_EXECUTE], 266[LT_AT_CHECK_EXECUTE([$1], 267 [./depdemo_static], [./depdemo]) 268]) 269 270# _LT_CHECK_INSTALL 271# ----------------- 272# Run the make install rule, and check that installed binaries work too. 273m4_define([_LT_CHECK_INSTALL], 274[# Windows hosts search for dlls in the command path. 275PATH=$prefix/lib:$PATH 276LT_AT_CHECK_EXECUTE([install], 277 [$prefix/bin/depdemo_static], [$prefix/bin/depdemo]) 278]) 279 280 281## --------------- ## 282## Depdemo static. ## 283## --------------- ## 284 285AT_SETUP([static library interdependencies]) 286 287_LT_SETUP 288 289LT_AT_CHECK_CONFIG([--disable-shared], 290 [^build_old_libs=yes], [^build_libtool_libs=no]) 291_LT_CHECK_EXECUTE 292_LT_CHECK_INSTALL 293LT_AT_CHECK_UNINSTALL 294 295AT_CLEANUP 296 297 298## --------------- ## 299## Depdemo shared. ## 300## --------------- ## 301 302AT_SETUP([shared library interdependencies]) 303 304_LT_SETUP 305 306LT_AT_CHECK_CONFIG([--disable-static], 307 [^build_old_libs=no], [^build_libtool_libs=yes]) 308_LT_CHECK_EXECUTE 309_LT_CHECK_INSTALL 310LT_AT_CHECK_UNINSTALL 311 312AT_CLEANUP 313 314 315## ------------- ## 316## Depdemo conf. ## 317## ------------- ## 318 319AT_SETUP([shared and static interdependencies]) 320 321_LT_SETUP 322 323LT_AT_CHECK_CONFIG([], 324 [^build_old_libs=yes], [^build_libtool_libs=yes]) 325_LT_CHECK_EXECUTE 326_LT_CHECK_INSTALL 327LT_AT_CHECK_UNINSTALL 328 329AT_CLEANUP 330 331 332## --------------- ## 333## Depdemo nofast. ## 334## --------------- ## 335 336AT_SETUP([disable fast install]) 337 338_LT_SETUP 339 340LT_AT_CHECK_CONFIG([--enable-fast-install=no]) 341AT_CHECK([$EGREP '^hardcode_action=relink' libtool && (exit 77)], 1) 342 343_LT_CHECK_EXECUTE 344_LT_CHECK_INSTALL 345LT_AT_CHECK_UNINSTALL 346 347AT_CLEANUP 348 349 350## --------------- ## 351## Depdemo relink. ## 352## --------------- ## 353 354AT_SETUP([binary relinking at install time]) 355AT_KEYWORDS([interactive])dnl This test causes a popup on Windows 356 357_LT_SETUP 358 359LT_AT_CHECK_CONFIG 360_LT_CHECK_EXECUTE 361_LT_CHECK_INSTALL 362 363# Check to make sure we have a dynamic library. 364eval `$EGREP '^library_names=' l3/libl3.la` 365AT_CHECK([test -n "$library_names" || (exit 77)]) 366 367func_save_files 368 369# AIX 5.3 '/bin/sh' will invoke the trap for 0 at the end of a 370# function, so we set the trap outside of a function to be portable. 371trap func_restore_files 0 1 2 13 15 372 373eval "`$LIBTOOL --config | $EGREP '^shlibpath_overrides_runpath='`" 374eval "`$LIBTOOL --config | $EGREP '^hardcode_(action|direct|into_libs)='`" 375 376# Can't finish these tests reliably when cross-compiling. 377AT_CHECK([test "X$host" = "X$build" || (exit 77)]) 378 379# Allow the binary to link on-demand if need be. 380./depdemo$EXEEXT >/dev/null || : 381 382# Remove l3/libl3.la from build tree. 383rm -f l3/libl3.la "l3/$objdir"/libl3.* 384 385# Either: 386# - uninstalled ./depdem will run using the just installed libraries 387# when the uninstalled libs are missing; 388# - on AIX 4.1, when the installed copy of libl3 is loaded, it brings 389# with it the installed copies of libl1 and libl2, with disjoint 390# counters var_l1 and var_l2. This is arguably unacceptable behaviour 391# but definitely not enough of a reason for the test to fail; 392# - or relinking at install time is necessary, and the uninstalled 393# depdemo has only the uninstalled library paths hardcoded. 394AT_CHECK([./depdemo$EXEEXT >/dev/null || 395 ./depdemo$EXEEXT -alt || 396 test relink,yes = "$hardcode_action,$hardcode_direct"]) 397 398# Link an incomplete l3/libl3.la. 399(cd l3 && 400 LT_AT_MAKE([libl3.la], [libl3_la_OBJECTS=../l2/l2.lo]) 401) 402AT_CHECK([test -f l3/libl3.la]) 403 404# Try running uninstalled ./depdemo with only broken libl3.la in build tree. 405# If the following has normal exit status, shlibpath_overrides_runpath is 406# wrong, and should be set to 'no' on this host. 407# The unusual '|| (exit 1)' is to normalize all non-zero exit statuses. 408AT_CHECK([./depdemo$EXEEXT || (exit 1)], 1, [ignore], [ignore]) 409 410test relink = "$hardcode_action" || 411test yes = "$shlibpath_overrides_runpath" || 412{ 413 AT_CHECK([rm -f $objdir/lt-depdemo$EXEEXT]) 414 AT_CHECK([cp $objdir/depdemo$EXEEXT $objdir/lt-depdemo$EXEEXT]) 415 416 # Running depdemo with installed libl3.la. 417 # If the following check fails, then shlibpath_overrides_runpath is 418 # wrong, and should be set to 'yes' on this host. 419 LT_AT_CHECK([./depdemo], 0, [expout]) 420} 421 422# Undo the effect of the previous 'trap' command. Some shellology: 423# We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to 424# execute the command "-". "trap '' ..." is fine only for signal 0 (= normal 425# exit); for the others we need to call 'exit' explicitly. The value of $? is 426# 128 + signal number and is set before the trap-registered command is run. 427trap '' 0 428trap 'func_exit $?' 1 2 3 13 15 429 430AT_CLEANUP 431