1
0

compile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #! /bin/sh
  2. # Wrapper for compilers which do not understand `-c -o'.
  3. scriptversion=2003-11-09.00
  4. # Copyright (C) 1999, 2000, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 0
  43. ;;
  44. -v | --v*)
  45. echo "compile $scriptversion"
  46. exit 0
  47. ;;
  48. esac
  49. prog=$1
  50. shift
  51. ofile=
  52. cfile=
  53. args=
  54. while test $# -gt 0; do
  55. case "$1" in
  56. -o)
  57. # configure might choose to run compile as `compile cc -o foo foo.c'.
  58. # So we do something ugly here.
  59. ofile=$2
  60. shift
  61. case "$ofile" in
  62. *.o | *.obj)
  63. ;;
  64. *)
  65. args="$args -o $ofile"
  66. ofile=
  67. ;;
  68. esac
  69. ;;
  70. *.c)
  71. cfile=$1
  72. args="$args $1"
  73. ;;
  74. *)
  75. args="$args $1"
  76. ;;
  77. esac
  78. shift
  79. done
  80. if test -z "$ofile" || test -z "$cfile"; then
  81. # If no `-o' option was seen then we might have been invoked from a
  82. # pattern rule where we don't need one. That is ok -- this is a
  83. # normal compilation that the losing compiler can handle. If no
  84. # `.c' file was seen then we are probably linking. That is also
  85. # ok.
  86. exec "$prog" $args
  87. fi
  88. # Name of file we expect compiler to create.
  89. cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
  90. # Create the lock directory.
  91. # Note: use `[/.-]' here to ensure that we don't use the same name
  92. # that we are using for the .o file. Also, base the name on the expected
  93. # object file name, since that is what matters with a parallel build.
  94. lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
  95. while true; do
  96. if mkdir $lockdir > /dev/null 2>&1; then
  97. break
  98. fi
  99. sleep 1
  100. done
  101. # FIXME: race condition here if user kills between mkdir and trap.
  102. trap "rmdir $lockdir; exit 1" 1 2 15
  103. # Run the compile.
  104. "$prog" $args
  105. status=$?
  106. if test -f "$cofile"; then
  107. mv "$cofile" "$ofile"
  108. fi
  109. rmdir $lockdir
  110. exit $status
  111. # Local Variables:
  112. # mode: shell-script
  113. # sh-indentation: 2
  114. # eval: (add-hook 'write-file-hooks 'time-stamp)
  115. # time-stamp-start: "scriptversion="
  116. # time-stamp-format: "%:y-%02m-%02d.%02H"
  117. # time-stamp-end: "$"
  118. # End: