PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/xmms-scrobbler-0.4.0/compile

#
Shell | 99 lines | 48 code | 12 blank | 39 comment | 6 complexity | d62ab7d10a79b295897b39e4b8565fd7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. #! /bin/sh
  2. # Wrapper for compilers which do not understand `-c -o'.
  3. # Copyright 1999, 2000 Free Software Foundation, Inc.
  4. # Written by Tom Tromey <tromey@cygnus.com>.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  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. # Usage:
  24. # compile PROGRAM [ARGS]...
  25. # `-o FOO.o' is removed from the args passed to the actual compile.
  26. prog=$1
  27. shift
  28. ofile=
  29. cfile=
  30. args=
  31. while test $# -gt 0; do
  32. case "$1" in
  33. -o)
  34. # configure might choose to run compile as `compile cc -o foo foo.c'.
  35. # So we do something ugly here.
  36. ofile=$2
  37. shift
  38. case "$ofile" in
  39. *.o | *.obj)
  40. ;;
  41. *)
  42. args="$args -o $ofile"
  43. ofile=
  44. ;;
  45. esac
  46. ;;
  47. *.c)
  48. cfile=$1
  49. args="$args $1"
  50. ;;
  51. *)
  52. args="$args $1"
  53. ;;
  54. esac
  55. shift
  56. done
  57. if test -z "$ofile" || test -z "$cfile"; then
  58. # If no `-o' option was seen then we might have been invoked from a
  59. # pattern rule where we don't need one. That is ok -- this is a
  60. # normal compilation that the losing compiler can handle. If no
  61. # `.c' file was seen then we are probably linking. That is also
  62. # ok.
  63. exec "$prog" $args
  64. fi
  65. # Name of file we expect compiler to create.
  66. cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
  67. # Create the lock directory.
  68. # Note: use `[/.-]' here to ensure that we don't use the same name
  69. # that we are using for the .o file. Also, base the name on the expected
  70. # object file name, since that is what matters with a parallel build.
  71. lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
  72. while true; do
  73. if mkdir $lockdir > /dev/null 2>&1; then
  74. break
  75. fi
  76. sleep 1
  77. done
  78. # FIXME: race condition here if user kills between mkdir and trap.
  79. trap "rmdir $lockdir; exit 1" 1 2 15
  80. # Run the compile.
  81. "$prog" $args
  82. status=$?
  83. if test -f "$cofile"; then
  84. mv "$cofile" "$ofile"
  85. fi
  86. rmdir $lockdir
  87. exit $status