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