guile-snarf.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. # Extract the initialization actions from source files.
  3. #
  4. # Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004, 2006, 2008, 2009 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 Lesser General Public License as
  8. # published by the Free Software Foundation; either version 3, or (at
  9. # your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with this software; see the file COPYING.LESSER. If
  18. # not, write to the Free Software Foundation, Inc., 51 Franklin
  19. # Street, Fifth Floor, 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. sed -ne 's/ *\^ *: *\^/\
  49. /
  50. h
  51. s/\n.*//
  52. t x
  53. d
  54. : x
  55. s/.*\^ *\^ *\(.*\)/\1;/
  56. t y
  57. d
  58. : y
  59. p
  60. x
  61. D' ${temp}
  62. }
  63. ## main
  64. # process command line
  65. if [ x"$1" = x--help ] ; then
  66. @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  67. | sed -e 1,2d -e 's/^. *//g'
  68. exit 0
  69. fi
  70. if [ x"$1" = x-o ]
  71. then outfile="$2" ; shift ; shift ;
  72. else outfile="-" ;
  73. fi
  74. # set vars and handler -- handle CPP override
  75. cpp_ok_p=false
  76. if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
  77. tempdir="$TMPDIR/guile-snarf.$$"
  78. (umask 077 && mkdir $tempdir) || exit 1
  79. temp="$tempdir/tmp"
  80. if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
  81. trap "rm -rf $tempdir" 0 1 2 15
  82. if [ ! "$outfile" = "-" ] ; then
  83. modern_snarf "$@" > $outfile
  84. else
  85. modern_snarf "$@"
  86. fi
  87. # zonk outfile if errors occurred
  88. if $cpp_ok_p ; then
  89. exit 0
  90. else
  91. [ ! "$outfile" = "-" ] && rm -f $outfile
  92. exit 1
  93. fi
  94. # guile-snarf ends here