guile-snarf.in 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # Extract the initialization actions from source files.
  3. #
  4. # Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
  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 software; see the file COPYING. If not, write to
  18. # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. # Boston, MA 02110-1301 USA
  20. # Commentary:
  21. # Usage: guile-snarf [-o OUTFILE] [CPP-ARGS ...]
  22. # Initialization actions are extracted to OUTFILE or to standard
  23. # output when no OUTFILE has been specified or when OUTFILE is "-".
  24. # The C preprocessor is called with CPP-ARGS (which usually include a
  25. # input file) and the output is filtered for the actions.
  26. #
  27. # If there are errors during processing, OUTFILE is deleted and the
  28. # program exits with non-zero status.
  29. #
  30. # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
  31. # defined. You can use this to avoid including snarfer output files
  32. # that don't yet exist by writing code like this:
  33. #
  34. # #ifndef SCM_MAGIC_SNARFER
  35. # #include "foo.x"
  36. # #endif
  37. #
  38. # If the environment variable CPP is set, use its value instead of the
  39. # C pre-processor determined at Guile configure-time: "@CPP@".
  40. # Code:
  41. ## funcs
  42. modern_snarf () # writes stdout
  43. {
  44. ## Apparently, AIX's preprocessor is unhappy if you try to #include an
  45. ## empty file.
  46. echo "/* cpp arguments: $@ */" ;
  47. ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
  48. grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//"
  49. }
  50. ## main
  51. # process command line
  52. if [ x"$1" = x--help ] ; then
  53. @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  54. | sed -e 1,2d -e 's/^. *//g'
  55. exit 0
  56. fi
  57. if [ x"$1" = x-o ]
  58. then outfile="$2" ; shift ; shift ;
  59. else outfile="-" ;
  60. fi
  61. # set vars and handler -- handle CPP override
  62. cpp_ok_p=false
  63. tempdir="/tmp/snarf.$$"
  64. (umask 077 && mkdir $tempdir) || exit 1
  65. temp="$tempdir/tmp"
  66. if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
  67. trap "rm -rf $tempdir" 0 1 2 15
  68. if [ ! "$outfile" = "-" ] ; then
  69. modern_snarf "$@" > $outfile
  70. else
  71. modern_snarf "$@"
  72. fi
  73. # zonk outfile if errors occurred
  74. if $cpp_ok_p ; then
  75. exit 0
  76. else
  77. [ ! "$outfile" = "-" ] && rm -f $outfile
  78. exit 1
  79. fi
  80. # guile-snarf ends here