You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
7.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #! /bin/sh
  2. # Wrapper for compilers which do not understand '-c -o'.
  3. scriptversion=2012-03-05.13; # UTC
  4. # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
  5. # Software Foundation, Inc.
  6. # Written by Tom Tromey <tromey@cygnus.com>.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. #
  13. # This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  20. # As a special exception to the GNU General Public License, if you
  21. # distribute this file as part of a program that contains a
  22. # configuration script generated by Autoconf, you may include it under
  23. # the same distribution terms that you use for the rest of that program.
  24. # This file is maintained in Automake, please report
  25. # bugs to <bug-automake@gnu.org> or send patches to
  26. # <automake-patches@gnu.org>.
  27. nl='
  28. '
  29. # We need space, tab and new line, in precisely that order. Quoting is
  30. # there to prevent tools from complaining about whitespace usage.
  31. IFS=" "" $nl"
  32. file_conv=
  33. # func_file_conv build_file lazy
  34. # Convert a $build file to $host form and store it in $file
  35. # Currently only supports Windows hosts. If the determined conversion
  36. # type is listed in (the comma separated) LAZY, no conversion will
  37. # take place.
  38. func_file_conv ()
  39. {
  40. file=$1
  41. case $file in
  42. / | /[!/]*) # absolute file, and not a UNC file
  43. if test -z "$file_conv"; then
  44. # lazily determine how to convert abs files
  45. case `uname -s` in
  46. MINGW*)
  47. file_conv=mingw
  48. ;;
  49. CYGWIN*)
  50. file_conv=cygwin
  51. ;;
  52. *)
  53. file_conv=wine
  54. ;;
  55. esac
  56. fi
  57. case $file_conv/,$2, in
  58. *,$file_conv,*)
  59. ;;
  60. mingw/*)
  61. file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
  62. ;;
  63. cygwin/*)
  64. file=`cygpath -m "$file" || echo "$file"`
  65. ;;
  66. wine/*)
  67. file=`winepath -w "$file" || echo "$file"`
  68. ;;
  69. esac
  70. ;;
  71. esac
  72. }
  73. # func_cl_dashL linkdir
  74. # Make cl look for libraries in LINKDIR
  75. func_cl_dashL ()
  76. {
  77. func_file_conv "$1"
  78. if test -z "$lib_path"; then
  79. lib_path=$file
  80. else
  81. lib_path="$lib_path;$file"
  82. fi
  83. linker_opts="$linker_opts -LIBPATH:$file"
  84. }
  85. # func_cl_dashl library
  86. # Do a library search-path lookup for cl
  87. func_cl_dashl ()
  88. {
  89. lib=$1
  90. found=no
  91. save_IFS=$IFS
  92. IFS=';'
  93. for dir in $lib_path $LIB
  94. do
  95. IFS=$save_IFS
  96. if $shared && test -f "$dir/$lib.dll.lib"; then
  97. found=yes
  98. lib=$dir/$lib.dll.lib
  99. break
  100. fi
  101. if test -f "$dir/$lib.lib"; then
  102. found=yes
  103. lib=$dir/$lib.lib
  104. break
  105. fi
  106. done
  107. IFS=$save_IFS
  108. if test "$found" != yes; then
  109. lib=$lib.lib
  110. fi
  111. }
  112. # func_cl_wrapper cl arg...
  113. # Adjust compile command to suit cl
  114. func_cl_wrapper ()
  115. {
  116. # Assume a capable shell
  117. lib_path=
  118. shared=:
  119. linker_opts=
  120. for arg
  121. do
  122. if test -n "$eat"; then
  123. eat=
  124. else
  125. case $1 in
  126. -o)
  127. # configure might choose to run compile as 'compile cc -o foo foo.c'.
  128. eat=1
  129. case $2 in
  130. *.o | *.[oO][bB][jJ])
  131. func_file_conv "$2"
  132. set x "$@" -Fo"$file"
  133. shift
  134. ;;
  135. *)
  136. func_file_conv "$2"
  137. set x "$@" -Fe"$file"
  138. shift
  139. ;;
  140. esac
  141. ;;
  142. -I)
  143. eat=1
  144. func_file_conv "$2" mingw
  145. set x "$@" -I"$file"
  146. shift
  147. ;;
  148. -I*)
  149. func_file_conv "${1#-I}" mingw
  150. set x "$@" -I"$file"
  151. shift
  152. ;;
  153. -l)
  154. eat=1
  155. func_cl_dashl "$2"
  156. set x "$@" "$lib"
  157. shift
  158. ;;
  159. -l*)
  160. func_cl_dashl "${1#-l}"
  161. set x "$@" "$lib"
  162. shift
  163. ;;
  164. -L)
  165. eat=1
  166. func_cl_dashL "$2"
  167. ;;
  168. -L*)
  169. func_cl_dashL "${1#-L}"
  170. ;;
  171. -static)
  172. shared=false
  173. ;;
  174. -Wl,*)
  175. arg=${1#-Wl,}
  176. save_ifs="$IFS"; IFS=','
  177. for flag in $arg; do
  178. IFS="$save_ifs"
  179. linker_opts="$linker_opts $flag"
  180. done
  181. IFS="$save_ifs"
  182. ;;
  183. -Xlinker)
  184. eat=1
  185. linker_opts="$linker_opts $2"
  186. ;;
  187. -*)
  188. set x "$@" "$1"
  189. shift
  190. ;;
  191. *.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
  192. func_file_conv "$1"
  193. set x "$@" -Tp"$file"
  194. shift
  195. ;;
  196. *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
  197. func_file_conv "$1" mingw
  198. set x "$@" "$file"
  199. shift
  200. ;;
  201. *)
  202. set x "$@" "$1"
  203. shift
  204. ;;
  205. esac
  206. fi
  207. shift
  208. done
  209. if test -n "$linker_opts"; then
  210. linker_opts="-link$linker_opts"
  211. fi
  212. exec "$@" $linker_opts
  213. exit 1
  214. }
  215. eat=
  216. case $1 in
  217. '')
  218. echo "$0: No command. Try '$0 --help' for more information." 1>&2
  219. exit 1;
  220. ;;
  221. -h | --h*)
  222. cat <<\EOF
  223. Usage: compile [--help] [--version] PROGRAM [ARGS]
  224. Wrapper for compilers which do not understand '-c -o'.
  225. Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
  226. arguments, and rename the output as expected.
  227. If you are trying to build a whole package this is not the
  228. right script to run: please start by reading the file 'INSTALL'.
  229. Report bugs to <bug-automake@gnu.org>.
  230. EOF
  231. exit $?
  232. ;;
  233. -v | --v*)
  234. echo "compile $scriptversion"
  235. exit $?
  236. ;;
  237. cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
  238. func_cl_wrapper "$@" # Doesn't return...
  239. ;;
  240. esac
  241. ofile=
  242. cfile=
  243. for arg
  244. do
  245. if test -n "$eat"; then
  246. eat=
  247. else
  248. case $1 in
  249. -o)
  250. # configure might choose to run compile as 'compile cc -o foo foo.c'.
  251. # So we strip '-o arg' only if arg is an object.
  252. eat=1
  253. case $2 in
  254. *.o | *.obj)
  255. ofile=$2
  256. ;;
  257. *)
  258. set x "$@" -o "$2"
  259. shift
  260. ;;
  261. esac
  262. ;;
  263. *.c)
  264. cfile=$1
  265. set x "$@" "$1"
  266. shift
  267. ;;
  268. *)
  269. set x "$@" "$1"
  270. shift
  271. ;;
  272. esac
  273. fi
  274. shift
  275. done
  276. if test -z "$ofile" || test -z "$cfile"; then
  277. # If no '-o' option was seen then we might have been invoked from a
  278. # pattern rule where we don't need one. That is ok -- this is a
  279. # normal compilation that the losing compiler can handle. If no
  280. # '.c' file was seen then we are probably linking. That is also
  281. # ok.
  282. exec "$@"
  283. fi
  284. # Name of file we expect compiler to create.
  285. cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
  286. # Create the lock directory.
  287. # Note: use '[/\\:.-]' here to ensure that we don't use the same name
  288. # that we are using for the .o file. Also, base the name on the expected
  289. # object file name, since that is what matters with a parallel build.
  290. lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
  291. while true; do
  292. if mkdir "$lockdir" >/dev/null 2>&1; then
  293. break
  294. fi
  295. sleep 1
  296. done
  297. # FIXME: race condition here if user kills between mkdir and trap.
  298. trap "rmdir '$lockdir'; exit 1" 1 2 15
  299. # Run the compile.
  300. "$@"
  301. ret=$?
  302. if test -f "$cofile"; then
  303. test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
  304. elif test -f "${cofile}bj"; then
  305. test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
  306. fi
  307. rmdir "$lockdir"
  308. exit $ret
  309. # Local Variables:
  310. # mode: shell-script
  311. # sh-indentation: 2
  312. # eval: (add-hook 'write-file-hooks 'time-stamp)
  313. # time-stamp-start: "scriptversion="
  314. # time-stamp-format: "%:y-%02m-%02d.%02H"
  315. # time-stamp-time-zone: "UTC"
  316. # time-stamp-end: "; # UTC"
  317. # End: