summaryrefslogtreecommitdiff
path: root/tests/depdemo.at
blob: 7794cf2303ed5d706b840e8ffb47e8811a93516c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# depdemo.at -- Library interdependencies		 -*- Autotest -*-
#
#   Copyright (C) 2003-2004, 2011-2019, 2021-2022 Free Software
#   Foundation, Inc.
#   Written by Gary V. Vaughan, 2003
#
#   This file is part of GNU Libtool.
#
# GNU Libtool is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# GNU Libtool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Libtool; see the file COPYING.  If not, a copy
# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
# or obtained by writing to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
####


AT_BANNER([Library interdependencies.])

## ------------------------------------------- ##
## Some functions shared by later tests cases. ##
## ------------------------------------------- ##

func_restore_files ()
{
    test "`echo _fnord/temp/libs/*`" = "_fnord/temp/libs/*" \
      || mv -f _fnord/temp/libs/* "l3/$objdir"
    mv -f "_fnord/temp/libl3.la" "l3"
    test -f "_fnord/temp/lt-depdemo$EXEEXT" \
      && mv -f "_fnord/temp/lt-depdemo$EXEEXT" "$objdir"
    test -f "_fnord/temp/depdemo$EXEEXT" \
      && mv -f "_fnord/temp/depdemo$EXEEXT" "$objdir"
    rm -rf "_fnord"
}

func_save_files ()
{
    test -n "$objdir" || exit 1
    $lt_INSTALL -d "_fnord/temp/libs"
    test -f "$objdir/lt-depdemo$EXEEXT" \
      && cp -f "$objdir/lt-depdemo$EXEEXT" "_fnord/temp"
    test -f "$objdir/depdemo$EXEEXT" \
      && cp -f "$objdir/depdemo$EXEEXT" "_fnord/temp"
    cp -f l3/libl3.la "_fnord/temp"
    cp -f l3/"$objdir"/* "_fnord/temp/libs"
}


# _LT_SETUP
# ---------
m4_define([_LT_SETUP],
[AT_DATA([configure.ac],
[[AC_INIT([depdemo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIRS([m4])
AM_INIT_AUTOMAKE
AC_PROG_CC

LT_INIT([win32-dll])
AC_SUBST([LIBTOOL_DEPS])
STATIC=
test yes = "$enable_static" && STATIC=-static
AC_SUBST([STATIC])

LT_LIB_M
AC_CONFIG_FILES([Makefile l1/Makefile l2/Makefile l3/Makefile l4/Makefile])
AC_CONFIG_HEADERS([config.h:config.in.h])
AC_OUTPUT
]])

AT_DATA([Makefile.am],
[[AUTOMAKE_OPTIONS = no-dependencies foreign
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = l1 l2 l3 l4

bin_PROGRAMS = depdemo depdemo_static

depdemo_SOURCES = main.c
depdemo_LDADD = $(top_builddir)/l1/libl1.la $(top_builddir)/l2/libl2.la \
		$(top_builddir)/l4/libl4.la
depdemo_DEPENDENCIES = $(top_builddir)/l1/libl1.la \
		$(top_builddir)/l2/libl2.la $(top_builddir)/l4/libl4.la

depdemo_static_SOURCES = $(depdemo_SOURCES)
depdemo_static_LDADD = $(depdemo_LDADD)
depdemo_static_DEPENDENCIES = $(depdemo_DEPENDENCIES)
depdemo_static_LDFLAGS = $(STATIC)

libtool: $(LIBTOOL_DEPS)
	$(SHELL) ./config.status --recheck
]])

AT_DATA([main.c],
[[#include <config.h>
#include <stdio.h>
#include <string.h>

#include "l1/l1.h"
#include "l2/l2.h"
#include "l4/l4.h"

#define STREQ !strcmp

int main (int argc, char **argv)
{
  printf("dependencies:\n");
  func_l1(0);
  func_l2(0);
  func_l4(0);
  if (argc == 2 && STREQ (argv[1], "-alt")
      && var_l1 + var_l2 + var_l4 == 8)
	return 0;
  printf("var_l1(%d) + var_l2(%d) + var_l4(%d) == %d\n",
         var_l1,var_l2,var_l4, var_l1 + var_l2 + var_l4);
  if (var_l1 + var_l2 + var_l4 != 19)
    {
	printf("var_l1(%d) + var_l2(%d) + var_l4(%d) != 19\n",
               var_l1,var_l2,var_l4);
	return 1;
    }
  return 0;
}
]])

# Create 4 directorys of mostly identical files.
for i in 1 2 3 4; do
  mkdir l$i

  # l$i/Makefile.am:
  {
    $ECHO     'AUTOMAKE_OPTIONS = no-dependencies foreign'
    $ECHO     'AM_CPPFLAGS = -I$(top_srcdir) -DBUILDING_LIBL'$i
    $ECHO     'lib_LTLIBRARIES = libl'$i'.la'
    $ECHO     'libl'$i'_la_SOURCES = l'$i'.c l'$i'.h'
    $ECHO     'libl'$i'_la_LDFLAGS = -no-undefined'
    $ECHO     'libl'$i'_la_LIBADD ='
    if test 4 != $i; then
      j=1; while test "$j" -lt "$i"; do
        $ECHO 'libl'$i'_la_LIBADD += $(top_builddir)/l'$j'/libl'$j'.la'
        j=`expr 1 + $j`
      done
    else
      j=3
      $ECHO   'libl'$i'_la_LIBADD += $(top_builddir)/l'$j'/libl'$j'.la $(LIBM)'
    fi
  } > l$i/Makefile.am

  # l$i/l$i.h
  [{
    $ECHO '#ifndef L'$i'_H'
    $ECHO '#define L'$i'_H'
    $ECHO
    $ECHO '#if (defined _WIN32 || defined _WIN32_WCE) && !defined __GNUC__'
    $ECHO '#  ifdef BUILDING_LIBL'$i
    $ECHO '#    ifdef DLL_EXPORT'
    $ECHO '#      define LIBL'$i'_SCOPE extern __declspec (dllexport)'
    $ECHO '#    endif'
    $ECHO '#  else'
    $ECHO '#    define LIBL'$i'_SCOPE extern __declspec (dllimport)'
    $ECHO '#  endif'
    $ECHO '#endif'
    $ECHO '#ifndef LIBL'$i'_SCOPE'
    $ECHO '#  define LIBL'$i'_SCOPE extern'
    $ECHO '#endif'
    $ECHO
    $ECHO '#ifdef __cplusplus'
    $ECHO 'extern "C" {'
    $ECHO '#endif'
    $ECHO
    $ECHO '  LIBL'$i'_SCOPE int var_l'$i';'
    $ECHO '  int func_l'$i' (int);'
    $ECHO
    $ECHO '#ifdef __cplusplus'
    $ECHO '}'
    $ECHO '#endif'
    $ECHO '#endif'
  }] > l$i/l$i.h

  # l$i/l$i.c:
  {
    if test 4 -ne $i; then
      $ECHO     '#include <config.h>'
      $ECHO     '#include <stdio.h>'
      $ECHO
      $ECHO     '#include "l'$i'/l'$i'.h"'
      j=1; while test "$j" -lt "$i"; do
        $ECHO   '#include "l'$j'/l'$j'.h"'
        j=`expr 1 + $j`
      done
      $ECHO
      $ECHO     'int var_l'$i' = 0;'
      $ECHO     'int func_l'$i' (int indent) {'
      $ECHO     '  int i;'
      $ECHO     '  for (i = 0; i < indent; i++)'
      $ECHO     "    putchar (' ');"
      $ECHO     '  printf ("l'$i' (%i)\n", var_l'$i');'
      if test 1 -eq $i; then
        $ECHO   '  var_l1++;'
      else
        j=1; while test "$j" -lt "$i"; do
          $ECHO '  func_l'$j'(indent+1);'
          $ECHO '  var_l'$i' += var_l'$j';'
          j=`expr 1 + $j`
        done
      fi
      $ECHO     '  return 0;'
      $ECHO     '}'
    else
      j=3
      $ECHO     '#include <config.h>'
      $ECHO     '#include <stdio.h>'
      $ECHO     '#include <math.h>'
      $ECHO     '#include "l'$i'/l'$i'.h"'
      $ECHO     '#include "l'$j'/l'$j'.h"'
      $ECHO
      $ECHO     'int var_l'$i' = 0;'
      $ECHO     'int func_l'$i' (int indent) {'
      $ECHO     '  int i;'
      $ECHO     '  for (i = 0; i < indent; i++)'
      $ECHO     "    putchar (' ');"
      $ECHO     '  printf ("l'$i' (%i)\n", var_l'$i');'
      $ECHO     '  func_l'$j'(indent+1);'
      $ECHO     '  for (i = 0; i < indent; i++)'
      $ECHO     "    putchar (' ');"
      $ECHO     '  printf("libm [cos (0.0) = %g]\n", (double) cos ((double) 0.0));'
      $ECHO     '  var_l'$i' += var_l'$j';'
      $ECHO     '  return 0;'
      $ECHO     '}'
    fi
  } > l$i/l$i.c
done


LT_AT_HOST_DATA([expout],
[[dependencies:
l1 (0)
l2 (0)
 l1 (1)
l4 (0)
 l3 (0)
  l1 (2)
  l2 (2)
   l1 (3)
libm cos (0.0) = 1
var_l1(4) + var_l2(6) + var_l4(9) == 19
]])

prefix=`pwd`/_inst
]) # _LT_SETUP



# _LT_CHECK_EXECUTE([TARGETS])
# ----------------------------
# Run the listed make rules, and check that the built binaries work.
m4_define([_LT_CHECK_EXECUTE],
[LT_AT_CHECK_EXECUTE([$1],
        [./depdemo_static], [./depdemo])
])

# _LT_CHECK_INSTALL
# -----------------
# Run the make install rule, and check that installed binaries work too.
m4_define([_LT_CHECK_INSTALL],
[# Windows hosts search for dlls in the command path.
PATH=$prefix/lib:$PATH
LT_AT_CHECK_EXECUTE([install],
        [$prefix/bin/depdemo_static], [$prefix/bin/depdemo])
])


## --------------- ##
## Depdemo static. ##
## --------------- ##

AT_SETUP([static library interdependencies])

_LT_SETUP

LT_AT_CHECK_CONFIG([--disable-shared],
                   [^build_old_libs=yes], [^build_libtool_libs=no])
_LT_CHECK_EXECUTE
_LT_CHECK_INSTALL
LT_AT_CHECK_UNINSTALL

AT_CLEANUP


## --------------- ##
## Depdemo shared. ##
## --------------- ##

AT_SETUP([shared library interdependencies])

_LT_SETUP

LT_AT_CHECK_CONFIG([--disable-static],
                   [^build_old_libs=no], [^build_libtool_libs=yes])
_LT_CHECK_EXECUTE
_LT_CHECK_INSTALL
LT_AT_CHECK_UNINSTALL

AT_CLEANUP


## ------------- ##
## Depdemo conf. ##
## ------------- ##

AT_SETUP([shared and static interdependencies])

_LT_SETUP

LT_AT_CHECK_CONFIG([],
                   [^build_old_libs=yes], [^build_libtool_libs=yes])
_LT_CHECK_EXECUTE
_LT_CHECK_INSTALL
LT_AT_CHECK_UNINSTALL

AT_CLEANUP


## --------------- ##
## Depdemo nofast. ##
## --------------- ##

AT_SETUP([disable fast install])

_LT_SETUP

LT_AT_CHECK_CONFIG([--enable-fast-install=no])
AT_CHECK([$EGREP '^hardcode_action=relink' libtool && (exit 77)], 1)

_LT_CHECK_EXECUTE
_LT_CHECK_INSTALL
LT_AT_CHECK_UNINSTALL

AT_CLEANUP


## --------------- ##
## Depdemo relink. ##
## --------------- ##

AT_SETUP([binary relinking at install time])
AT_KEYWORDS([interactive])dnl This test causes a popup on Windows

_LT_SETUP

LT_AT_CHECK_CONFIG
_LT_CHECK_EXECUTE
_LT_CHECK_INSTALL

# Check to make sure we have a dynamic library.
eval `$EGREP '^library_names=' l3/libl3.la`
AT_CHECK([test -n "$library_names" || (exit 77)])

func_save_files

# AIX 5.3 '/bin/sh' will invoke the trap for 0 at the end of a
# function, so we set the trap outside of a function to be portable.
trap func_restore_files 0 1 2 13 15

eval "`$LIBTOOL --config | $EGREP '^shlibpath_overrides_runpath='`"
eval "`$LIBTOOL --config | $EGREP '^hardcode_(action|direct|into_libs)='`"

# Can't finish these tests reliably when cross-compiling.
AT_CHECK([test "X$host" = "X$build" || (exit 77)])

# Allow the binary to link on-demand if need be.
./depdemo$EXEEXT >/dev/null || :

# Remove l3/libl3.la from build tree.
rm -f l3/libl3.la "l3/$objdir"/libl3.*

# Either:
#  - uninstalled ./depdem will run using the just installed libraries
#    when the uninstalled libs are missing;
#  - on AIX 4.1, when the installed copy of libl3 is loaded, it brings
#    with it the installed copies of libl1 and libl2, with disjoint
#    counters var_l1 and var_l2.  This is arguably unacceptable behaviour
#    but definitely not enough of a reason for the test to fail;
#  - or relinking at install time is necessary, and the uninstalled
#    depdemo has only the uninstalled library paths hardcoded.
AT_CHECK([./depdemo$EXEEXT >/dev/null ||
    ./depdemo$EXEEXT -alt ||
    test relink,yes = "$hardcode_action,$hardcode_direct"])

# Link an incomplete l3/libl3.la.
(cd l3 &&
 LT_AT_MAKE([libl3.la], [libl3_la_OBJECTS=../l2/l2.lo])
)
AT_CHECK([test -f l3/libl3.la])

# Try running uninstalled ./depdemo with only broken libl3.la in build tree.
# If the following has normal exit status, shlibpath_overrides_runpath is
# wrong, and should be set to 'no' on this host.
# The unusual '|| (exit 1)' is to normalize all non-zero exit statuses.
AT_CHECK([./depdemo$EXEEXT || (exit 1)], 1, [ignore], [ignore])

test relink = "$hardcode_action" ||
test yes = "$shlibpath_overrides_runpath" ||
{
    AT_CHECK([rm -f $objdir/lt-depdemo$EXEEXT])
    AT_CHECK([cp $objdir/depdemo$EXEEXT $objdir/lt-depdemo$EXEEXT])

    # Running depdemo with installed libl3.la.
    # If the following check fails, then shlibpath_overrides_runpath is
    # wrong, and should be set to 'yes' on this host.
    LT_AT_CHECK([./depdemo], 0, [expout])
}

# Undo the effect of the previous 'trap' command. Some shellology:
# We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
# execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
# exit); for the others we need to call 'exit' explicitly. The value of $? is
# 128 + signal number and is set before the trap-registered command is run.
trap '' 0
trap 'func_exit $?' 1 2 3 13 15

AT_CLEANUP