Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / export.at
1 # export.at -- test symbol exports                           -*- Autotest -*-
2
3 #   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 #   Written by Ralf Wildenhues, 2007
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 AT_SETUP([Export test])
26 AT_KEYWORDS([libtool])
27
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
37
38 LDFLAGS="$LDFLAGS -no-undefined"
39 libdir=`pwd`/inst/lib
40 mkdir inst inst/lib
41
42 AT_DATA(a.c,
43 [[/* all kinds of data items */
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
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;
64
65 typedef struct { int arr[1000]; } large;
66 large v13;
67 large v14 = { { 0 } };
68 large v15 = { { 1 } };
69
70 int w1 (void) { return 0; }
71
72 #ifdef __cplusplus
73 }
74 #endif
75 ]])
76
77 AT_DATA(asyms,
78 [[v1
79 v3
80 v4
81 v5
82 v6
83 v7
84 v8
85 v9
86 v10
87 v11
88 v12
89 v13
90 v14
91 v15
92 ]])
93
94 AT_DATA(main.c,
95 [[
96 /* w32 fun.  With GCC, you can have auto-import, which will work for
97  * functions and non-const variables.  With MSVC, you have to explicitly
98  * import all variables.  Depending on the amount of portability, you
99  * need these annotations: LIBA_SCOPE for GCC, and also LIBA_SCOPE_VAR
100  * for MSVC.  Of course you can merge both to one, this test only avoids
101  * that in order to expose the auto-import feature on Cygwin.
102  *
103  * For users, it's best to realize that they should not provide any
104  * non-function API at all.
105  */
106 #if defined(LIBA_DLL_IMPORT)
107 #  if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__)
108 #    define LIBA_SCOPE extern __declspec(dllimport)
109 #    if defined(_MSC_VER)
110 #      define LIBA_SCOPE_VAR LIBA_SCOPE
111 #    endif
112 #  endif
113 #endif
114 #if !defined(LIBA_SCOPE)
115 #  define LIBA_SCOPE extern
116 #endif
117 #if !defined(LIBA_SCOPE_VAR)
118 #  define LIBA_SCOPE_VAR extern
119 #endif
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123 LIBA_SCOPE_VAR int v1;
124 LIBA_SCOPE_VAR int v3, v4;
125 LIBA_SCOPE const int v5, v6;
126 LIBA_SCOPE_VAR const char* v7;
127 LIBA_SCOPE_VAR const char v8[];
128 extern int v9(void);
129 LIBA_SCOPE_VAR int (*v10) (void);
130 LIBA_SCOPE_VAR int (*v11) (void);
131 LIBA_SCOPE int (*const v12) (void);
132 #ifdef __cplusplus
133 }
134 #endif
135
136 typedef struct { int arr[1000]; } large;
137 LIBA_SCOPE_VAR large v13, v14, v15;
138
139 int main (void)
140 {
141   char s = v7[0] + v8[0];
142   return s + v1 + v3 + v4 + v5 + v6 + v9() + v11() + v12()
143            + v13.arr[0] + v14.arr[0] + v15.arr[0]
144            - 8;
145 }
146 ]])
147
148 AT_DATA([broken.c],
149 [[
150 /* these symbols should not be exported */
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 extern int w1 (void);
155 #ifdef __cplusplus
156 }
157 #endif
158 int main (void)
159 {
160   return w1 ();
161 }
162 ]])
163
164 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c],[0],[ignore],[ignore])
165 AT_CHECK([$CC $CPPFLAGS -DLIBA_DLL_IMPORT $CFLAGS -c main.c],[0],[ignore],[ignore])
166 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c broken.c],[0],[ignore],[ignore])
167
168 for exportsyms in '' '-export-symbols-regex "v.*"' '-export-symbols asyms'
169 do
170   # case 1: shared library built from object.
171   LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo \
172                -rpath $libdir' $exportsyms], [], [ignore], [ignore])
173   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT liba.la],
174            [], [ignore], [ignore])
175   LT_AT_EXEC_CHECK([./main])
176   if test -n "$exportsyms" && $can_hide; then
177     AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken$EXEEXT broken.$OBJEXT liba.la
178               then (exit 1); else :; fi], [], [ignore], [ignore])
179   fi
180
181   # case 2: shared library built from convenience archive.
182   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libconv.la a.lo],
183            [], [ignore], [ignore])
184   LT_AT_CHECK([eval '$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la libconv.la \
185                -rpath $libdir' $exportsyms], [], [ignore], [ignore])
186   AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT liba.la],
187            [], [ignore], [ignore])
188   LT_AT_EXEC_CHECK([./main])
189   if test -n "$exportsyms" && $can_hide; then
190     AT_CHECK([if $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o broken$EXEEXT broken.$OBJEXT liba.la
191               then (exit 1); else :; fi], [], [ignore], [ignore])
192   fi
193 done
194
195 AT_CHECK([$can_hide || (exit 77)])
196
197 AT_CLEANUP