2
0

compile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #! /bin/sh
  2. # Wrapper for compilers which do not understand `-c -o'.
  3. scriptversion=2005-05-14.22
  4. # Copyright (C) 1999, 2000, 2003, 2004, 2005 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, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  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. case $1 in
  28. '')
  29. echo "$0: No command. Try \`$0 --help' for more information." 1>&2
  30. exit 1;
  31. ;;
  32. -h | --h*)
  33. cat <<\EOF
  34. Usage: compile [--help] [--version] PROGRAM [ARGS]
  35. Wrapper for compilers which do not understand `-c -o'.
  36. Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
  37. arguments, and rename the output as expected.
  38. If you are trying to build a whole package this is not the
  39. right script to run: please start by reading the file `INSTALL'.
  40. Report bugs to <bug-automake@gnu.org>.
  41. EOF
  42. exit $?
  43. ;;
  44. -v | --v*)
  45. echo "compile $scriptversion"
  46. exit $?
  47. ;;
  48. esac
  49. ofile=
  50. cfile=
  51. eat=
  52. for arg
  53. do
  54. if test -n "$eat"; then
  55. eat=
  56. else
  57. case $1 in
  58. -o)
  59. # configure might choose to run compile as `compile cc -o foo foo.c'.
  60. # So we strip `-o arg' only if arg is an object.
  61. eat=1
  62. case $2 in
  63. *.o | *.obj)
  64. ofile=$2
  65. ;;
  66. *)
  67. set x "$@" -o "$2"
  68. shift
  69. ;;
  70. esac
  71. ;;
  72. *.c)
  73. cfile=$1
  74. set x "$@" "$1"
  75. shift
  76. ;;
  77. *)
  78. set x "$@" "$1"
  79. shift
  80. ;;
  81. esac
  82. fi
  83. shift
  84. done
  85. if test -z "$ofile" || test -z "$cfile"; then
  86. # If no `-o' option was seen then we might have been invoked from a
  87. # pattern rule where we don't need one. That is ok -- this is a
  88. # normal compilation that the losing compiler can handle. If no
  89. # `.c' file was seen then we are probably linking. That is also
  90. # ok.
  91. exec "$@"
  92. fi
  93. # Name of file we expect compiler to create.
  94. cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
  95. # Create the lock directory.
  96. # Note: use `[/.-]' here to ensure that we don't use the same name
  97. # that we are using for the .o file. Also, base the name on the expected
  98. # object file name, since that is what matters with a parallel build.
  99. lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
  100. while true; do
  101. if mkdir "$lockdir" >/dev/null 2>&1; then
  102. break
  103. fi
  104. sleep 1
  105. done
  106. # FIXME: race condition here if user kills between mkdir and trap.
  107. trap "rmdir '$lockdir'; exit 1" 1 2 15
  108. # Run the compile.
  109. "$@"
  110. ret=$?
  111. if test -f "$cofile"; then
  112. mv "$cofile" "$ofile"
  113. elif test -f "${cofile}bj"; then
  114. mv "${cofile}bj" "$ofile"
  115. fi
  116. rmdir "$lockdir"
  117. exit $ret
  118. # Local Variables:
  119. # mode: shell-script
  120. # sh-indentation: 2
  121. # eval: (add-hook 'write-file-hooks 'time-stamp)
  122. # time-stamp-start: "scriptversion="
  123. # time-stamp-format: "%:y-%02m-%02d.%02H"
  124. # time-stamp-end: "$"
  125. # End: