use guile eval for elisp tree-il
[bpt/guile.git] / libguile / guile-snarf.in
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
22 # Commentary:
23
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 #
34 # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
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@".
44
45 # Code:
46
47 ## funcs
48
49 modern_snarf () # writes stdout
50 {
51 ## Apparently, AIX's preprocessor is unhappy if you try to #include an
52 ## empty file.
53 echo "/* cpp arguments: $@ */" ;
54 ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
55 sed -ne '/^#define /d
56 s/ *\^ *\^ */\
57 /
58 s/.*\n//
59 t x
60 d
61 : x
62 s/ *\^ *: *\^ */;\
63 /
64 t y
65 N
66 s/\n\(#.*\)/ /
67 s/\n/ /
68 t x
69 : y
70 P
71 D' ${temp}
72 }
73
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
82 if [ x"$1" = x-o ]
83 then outfile="$2" ; shift ; shift ;
84 else outfile="-" ;
85 fi
86
87 # set vars and handler -- handle CPP override
88 cpp_ok_p=false
89
90 if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
91 tempdir="$TMPDIR/guile-snarf.$$"
92 (umask 077 && mkdir $tempdir) || exit 1
93 temp="$tempdir/tmp"
94
95 if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
96
97 trap "rm -rf $tempdir" 0 1 2 15
98
99 if [ ! "$outfile" = "-" ] ; then
100 modern_snarf "$@" > $outfile
101 else
102 modern_snarf "$@"
103 fi
104
105 # zonk outfile if errors occurred
106 if $cpp_ok_p ; then
107 exit 0
108 else
109 [ ! "$outfile" = "-" ] && rm -f $outfile
110 exit 1
111 fi
112
113 # guile-snarf ends here