compile6.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #! /bin/sh
  2. # Copyright (C) 2010-2017 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. # Make sure 'compile' searches libraries correctly
  17. am_create_testdir=empty
  18. required=xsi-lib-shell
  19. . test-init.sh
  20. get_shell_script compile
  21. # Use a dummy cl, since cl isn't readily available on all systems
  22. cat >cl <<'END'
  23. #! /bin/sh
  24. echo "$@"
  25. END
  26. chmod +x ./cl
  27. # POSIX mandates that the compiler accepts a space between the -I,
  28. # -l and -L options and their respective arguments. Traditionally,
  29. # this should work also without a space. Try both usages.
  30. for sp in '' ' '; do
  31. rm -rf lib lib2 syslib "sys lib2"
  32. mkdir syslib
  33. : > syslib/foo.lib
  34. syslib=$(pwd)/syslib
  35. LIB=$syslib
  36. export LIB
  37. mkdir lib
  38. : > lib/bar.lib
  39. : > lib/bar.dll.lib
  40. : > lib/libbar.a
  41. : > lib/libbaz.a
  42. # Check if compile library search correctly
  43. opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
  44. test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
  45. # Check if -static makes compile avoid bar.dll.lib
  46. opts=$(./compile ./cl foo.c -o foo -L${sp}lib -static -l${sp}bar -l${sp}foo)
  47. test x"$opts" = x"foo.c -Fefoo lib/bar.lib $syslib/foo.lib -link -LIBPATH:lib"
  48. : > syslib/bar.lib
  49. : > syslib/bar.dll.lib
  50. : > syslib/libbar.a
  51. # Check if compile finds bar.dll.lib in syslib
  52. opts=$(./compile ./cl foo.c -o foo -l${sp}bar -l${sp}foo)
  53. test x"$opts" = x"foo.c -Fefoo $syslib/bar.dll.lib $syslib/foo.lib"
  54. # Check if compile prefers -L over $LIB
  55. opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo)
  56. test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib"
  57. # Check if compile falls back to finding classic libname.a style libraries
  58. # when name.lib or name.dll.lib isn't available.
  59. opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}baz)
  60. test x"$opts" = x"foo.c -Fefoo lib/libbaz.a -link -LIBPATH:lib"
  61. mkdir lib2
  62. : > lib2/bar.dll.lib
  63. # Check if compile avoids bar.dll.lib in lib2 when -static
  64. opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -static -l${sp}bar -l${sp}foo)
  65. test x"$opts" = x"foo.c -Fefoo $syslib/bar.lib $syslib/foo.lib -link -LIBPATH:lib2"
  66. # Check if compile gets two different bar libraries when -static
  67. # is added in the middle
  68. opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -static -l${sp}bar)
  69. test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib lib/bar.lib -link -LIBPATH:lib2 -LIBPATH:lib"
  70. # Check if compile gets the correct bar.dll.lib
  71. opts=$(./compile ./cl foo.c -o foo -L${sp}lib -L${sp}lib2 -l${sp}bar -l${sp}foo)
  72. test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib -LIBPATH:lib2"
  73. # Check if compile gets the correct bar.dll.lib
  74. opts=$(./compile ./cl foo.c -o foo -L${sp}lib2 -L${sp}lib -l${sp}bar -l${sp}foo)
  75. test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib2 -LIBPATH:lib"
  76. mkdir "sys lib2"
  77. : > "sys lib2/foo.dll.lib"
  78. syslib2="$(pwd)/sys lib2"
  79. LIB="$syslib2;$LIB"
  80. # Check if compile handles spaces in $LIB and that it obeys the order
  81. # in a multi-component $LIB.
  82. opts=$(./compile ./cl foo.c -o foo -l${sp}foo)
  83. test x"$opts" = x"foo.c -Fefoo $syslib2/foo.dll.lib"
  84. # Check if compile handles the 2nd directory in a multi-component $LIB.
  85. opts=$(./compile ./cl foo.c -o foo -static -l${sp}foo)
  86. test x"$opts" = x"foo.c -Fefoo $syslib/foo.lib"
  87. done
  88. :