guile-snarf.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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,
  5. # 2009, 2014 Free Software Foundation, Inc.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as
  9. # published by the Free Software Foundation; either version 3, or (at
  10. # your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this software; see the file COPYING.LESSER. If
  19. # not, write to the Free Software Foundation, Inc., 51 Franklin
  20. # Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. # Commentary:
  22. # Usage: guile-snarf [-o OUTFILE] [CPP-ARGS ...]
  23. # Initialization actions are extracted to OUTFILE or to standard
  24. # output when no OUTFILE has been specified or when OUTFILE is "-".
  25. # The C preprocessor is called with CPP-ARGS (which usually include a
  26. # input file) and the output is filtered for the actions.
  27. #
  28. # If there are errors during processing, OUTFILE is deleted and the
  29. # program exits with non-zero status.
  30. #
  31. # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
  32. # defined. You can use this to avoid including snarfer output files
  33. # that don't yet exist by writing code like this:
  34. #
  35. # #ifndef SCM_MAGIC_SNARFER
  36. # #include "foo.x"
  37. # #endif
  38. #
  39. # If the environment variable CPP is set, use its value instead of the
  40. # C pre-processor determined at Guile configure-time: "@CPP@".
  41. # Code:
  42. ## funcs
  43. modern_snarf () # writes stdout
  44. {
  45. ## Apparently, AIX's preprocessor is unhappy if you try to #include an
  46. ## empty file.
  47. echo "/* cpp arguments: $@ */" ;
  48. ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
  49. sed -ne 's/ *\^ *\^ */\
  50. /
  51. s/.*\n//
  52. t x
  53. d
  54. : x
  55. s/ *\^ *: *\^ */;\
  56. /
  57. t y
  58. N
  59. s/\n\(#.*\)/ /
  60. s/\n/ /
  61. t x
  62. : y
  63. P
  64. D' ${temp}
  65. }
  66. ## main
  67. # process command line
  68. if [ x"$1" = x--help ] ; then
  69. @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  70. | sed -e 1,2d -e 's/^. *//g'
  71. exit 0
  72. fi
  73. if [ x"$1" = x-o ]
  74. then outfile="$2" ; shift ; shift ;
  75. else outfile="-" ;
  76. fi
  77. # set vars and handler -- handle CPP override
  78. cpp_ok_p=false
  79. if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
  80. tempdir="$TMPDIR/guile-snarf.$$"
  81. (umask 077 && mkdir $tempdir) || exit 1
  82. temp="$tempdir/tmp"
  83. if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
  84. trap "rm -rf $tempdir" 0 1 2 15
  85. if [ ! "$outfile" = "-" ] ; then
  86. modern_snarf "$@" > $outfile
  87. else
  88. modern_snarf "$@"
  89. fi
  90. # zonk outfile if errors occurred
  91. if $cpp_ok_p ; then
  92. exit 0
  93. else
  94. [ ! "$outfile" = "-" ] && rm -f $outfile
  95. exit 1
  96. fi
  97. # guile-snarf ends here