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