guile-snarf.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 '/^#define /d
  50. s/ *\^ *\^ */\
  51. /
  52. s/.*\n//
  53. t x
  54. d
  55. : x
  56. s/ *\^ *: *\^ */;\
  57. /
  58. t y
  59. N
  60. s/\n\(#.*\)/ /
  61. s/\n/ /
  62. t x
  63. : y
  64. P
  65. D' ${temp}
  66. }
  67. ## main
  68. # process command line
  69. if [ x"$1" = x--help ] ; then
  70. @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  71. | sed -e 1,2d -e 's/^. *//g'
  72. exit 0
  73. fi
  74. if [ x"$1" = x-o ]
  75. then outfile="$2" ; shift ; shift ;
  76. else outfile="-" ;
  77. fi
  78. # set vars and handler -- handle CPP override
  79. cpp_ok_p=false
  80. if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
  81. tempdir="$TMPDIR/guile-snarf.$$"
  82. (umask 077 && mkdir $tempdir) || exit 1
  83. temp="$tempdir/tmp"
  84. if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
  85. trap "rm -rf $tempdir" 0 1 2 15
  86. if [ ! "$outfile" = "-" ] ; then
  87. modern_snarf "$@" > $outfile
  88. else
  89. modern_snarf "$@"
  90. fi
  91. # zonk outfile if errors occurred
  92. if $cpp_ok_p ; then
  93. exit 0
  94. else
  95. [ ! "$outfile" = "-" ] && rm -f $outfile
  96. exit 1
  97. fi
  98. # guile-snarf ends here