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.

347 lines
7.2 KiB

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