tests: cosmetic changes in t/extra-sources.sh
[platform/upstream/automake.git] / t / compile6.sh
1 #! /bin/sh
2 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Make sure 'compile' searches libraries correctly
18
19 am_create_testdir=empty
20 required=xsi-lib-shell
21 . test-init.sh
22
23 get_shell_script compile
24
25 # Use a dummy cl, since cl isn't readily available on all systems
26 cat >cl <<'END'
27 #! /bin/sh
28 echo "$@"
29 END
30
31 chmod +x ./cl
32
33 # POSIX mandates that the compiler accepts a space between the -I,
34 # -l and -L options and their respective arguments.  Traditionally,
35 # this should work also without a space.  Try both usages.
36 for sp in '' ' '; do
37
38   rm -rf lib lib2 syslib "sys  lib2"
39
40   mkdir syslib
41   : > syslib/foo.lib
42
43   syslib=$(pwd)/syslib
44   LIB=$syslib
45   export LIB
46
47   mkdir lib
48   : > lib/bar.lib
49   : > lib/bar.dll.lib
50   : > lib/libbar.a
51   : > lib/libbaz.a
52
53   # Check if compile library search correctly
54   opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
55   test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
56
57   # Check if -static makes compile avoid bar.dll.lib
58   opts=$(./compile ./cl foo.c -o foo -L${sp}lib -static -l${sp}bar -l${sp}foo)
59   test x"$opts" = x"foo.c -Fefoo lib/bar.lib $syslib/foo.lib -link -LIBPATH:lib"
60
61   : > syslib/bar.lib
62   : > syslib/bar.dll.lib
63   : > syslib/libbar.a
64
65   # Check if compile finds bar.dll.lib in syslib
66   opts=$(./compile ./cl foo.c -o foo -l${sp}bar -l${sp}foo)
67   test x"$opts" = x"foo.c -Fefoo $syslib/bar.dll.lib $syslib/foo.lib"
68
69   # Check if compile prefers -L over $LIB
70   opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
71   test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
72
73   # Check if compile falls back to finding classic libname.a style libraries
74   # when name.lib or name.dll.lib isn't available.
75   opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}baz)
76   test x"$opts" = x"foo.c -Fefoo lib/libbaz.a -link -LIBPATH:lib"
77
78   mkdir lib2
79   : > lib2/bar.dll.lib
80
81   # Check if compile avoids bar.dll.lib in lib2 when -static
82   opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -static -l${sp}bar -l${sp}foo)
83   test x"$opts" = x"foo.c -Fefoo $syslib/bar.lib $syslib/foo.lib -link -LIBPATH:lib2"
84
85   # Check if compile gets two different bar libraries when -static
86   # is added in the middle
87   opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -static -l${sp}bar)
88   test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib lib/bar.lib -link -LIBPATH:lib2 -LIBPATH:lib"
89
90   # Check if compile gets the correct bar.dll.lib
91   opts=$(./compile ./cl foo.c -o foo -L${sp}lib -L${sp}lib2 -l${sp}bar -l${sp}foo)
92   test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib -LIBPATH:lib2"
93
94   # Check if compile gets the correct bar.dll.lib
95   opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -l${sp}foo)
96   test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib2 -LIBPATH:lib"
97
98   mkdir "sys  lib2"
99   : > "sys  lib2/foo.dll.lib"
100
101   syslib2="$(pwd)/sys  lib2"
102   LIB="$syslib2;$LIB"
103
104   # Check if compile handles spaces in $LIB and that it obeys the order
105   # in a multi-component $LIB.
106   opts=$(./compile ./cl foo.c -o foo -l${sp}foo)
107   test x"$opts" = x"foo.c -Fefoo $syslib2/foo.dll.lib"
108
109   # Check if compile handles the 2nd directory in a multi-component $LIB.
110   opts=$(./compile ./cl foo.c -o foo -static -l${sp}foo)
111   test x"$opts" = x"foo.c -Fefoo $syslib/foo.lib"
112
113 done
114
115 :