* libltdl/m4/libtool.m4 (_LT_PROG_FC): Report FC=no if the FC
[libtool.git] / tests / export.at
blob73fb45f7233b44d6b40f3cd983e716220db04494
1 # export.at -- test symbol exports                           -*- Autotest -*-
3 #   Copyright (C) 2007 Free Software Foundation, Inc.
4 #   Written by Ralf Wildenhues, 2007
6 #   This file is part of GNU Libtool.
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.
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.
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 ####
25 AT_SETUP([Export test])
26 AT_KEYWORDS([libtool])
28 AT_CHECK([$LIBTOOL --features | grep 'disable shared libraries' && (exit 77)],
29          [1], [ignore])
30 AT_CHECK([eval `$LIBTOOL --config | sed -n '/^archive_expsym_cmds=/,/^$/p'`
31           test -n "$archive_expsym_cmds" || echo false >can-hide
32           case $archive_expsym_cmds in
33           *-retain-symbols-file*) echo false >can-hide ;;
34           esac])
35 can_hide=:
36 test -s can-hide && can_hide=false
38 LDFLAGS="$LDFLAGS -no-undefined"
39 libdir=`pwd`/inst/lib
40 mkdir inst inst/lib
42 AT_DATA(a.c,
43 [[/* all kinds of data items */
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 int v1;
49 static int v2;
50 int v3 = 0;
51 int v4 = 1;
52 extern const int v5, v6;
53 extern const char *v7;
54 extern const char v8[];
55 extern int (*const v12) (void);
56 const int v5 = 0;
57 const int v6 = 1;
58 const char* v7 = "\01foo";
59 const char v8[] = "\01bar";
60 int v9(void) { return v2 + 1; }
61 int (*v10) (void);
62 int (*v11) (void) = v9;
63 int (*const v12) (void) = v9;
65 typedef struct { int arr[1000]; } large;
66 large v13;
67 large v14 = { { 0 } };
68 large v15 = { { 1 } };
70 int w1 (void) { return 0; }
72 #ifdef __cplusplus
74 #endif
75 ]])
77 AT_DATA(asyms,
78 [[v1
86 v10
87 v11
88 v12
89 v13
90 v14
91 v15
92 ]])
94 AT_DATA(main.c,
96 #if defined(LIBA_DLL_IMPORT)
97 #  if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__)
98 #    define LIBA_SCOPE extern __declspec(dllimport)
99 #  endif
100 #endif
101 #if !defined(LIBA_SCOPE)
102 #  define LIBA_SCOPE extern
103 #endif
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 extern int v1;
108 extern int v3, v4;
109 LIBA_SCOPE const int v5, v6;
110 extern const char* v7;
111 extern const char v8[];
112 extern int v9(void);
113 extern int (*v10) (void);
114 extern int (*v11) (void);
115 LIBA_SCOPE int (*const v12) (void);
116 #ifdef __cplusplus
118 #endif
120 typedef struct { int arr[1000]; } large;
121 extern large v13, v14, v15;
123 int main (void)
125   char s = v7[0] + v8[0];
126   return s + v1 + v3 + v4 + v5 + v6 + v9() + v11() + v12()
127            + v13.arr[0] + v14.arr[0] + v15.arr[0]
128            - 8;
132 AT_DATA([broken.c],
134 /* these symbols should not be exported */
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 extern int w1 (void);
139 #ifdef __cplusplus
141 #endif
142 int main (void)
144   return w1 ();
148 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c],[0],[ignore],[ignore])
149 AT_CHECK([$CC $CPPFLAGS -DLIBA_DLL_IMPORT $CFLAGS -c main.c],[0],[ignore],[ignore])
150 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c broken.c],[0],[ignore],[ignore])
152 for exportsyms in '' '-export-symbols-regex "v.*"' '-export-symbols asyms'
154   # case 1: shared library built from object.
155   LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo \
156                -rpath $libdir' $exportsyms], [], [ignore], [ignore])
157   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main main.$OBJEXT liba.la],
158            [], [ignore], [ignore])
159   LT_AT_EXEC_CHECK([./main])
160   if test -n "$exportsyms" && $can_hide; then
161     AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken broken.$OBJEXT liba.la
162               then (exit 1); else :; fi], [], [ignore], [ignore])
163   fi
165   # case 2: shared library built from convenience archive.
166   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libconv.la a.lo],
167            [], [ignore], [ignore])
168   LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la libconv.la \
169                -rpath $libdir' $exportsyms], [], [ignore], [ignore])
170   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main main.$OBJEXT liba.la],
171            [], [ignore], [ignore])
172   LT_AT_EXEC_CHECK([./main])
173   if test -n "$exportsyms" && $can_hide; then
174     AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken broken.$OBJEXT liba.la
175               then (exit 1); else :; fi], [], [ignore], [ignore])
176   fi
177 done
179 AT_CHECK([$can_hide || (exit 77)])
181 AT_CLEANUP