REPL Server: Don't establish a SIGINT handler.
[bpt/guile.git] / libguile / guile-snarf.in
CommitLineData
adb75a41 1#!/bin/sh
9bc6fb0a
TTN
2# Extract the initialization actions from source files.
3#
6eca5d2b 4# Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
d6a35f3f 5#
d6a35f3f 6# This program is free software; you can redistribute it and/or modify
53befeb7
NJ
7# it under the terms of the GNU Lesser General Public License as
8# published by the Free Software Foundation; either version 3, or (at
9# your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this software; see the file COPYING.LESSER. If
18# not, write to the Free Software Foundation, Inc., 51 Franklin
19# Street, Fifth Floor, Boston, MA 02110-1301 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
48modern_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
95c1cfb5
BT
54 sed -ne 's/ *\^ *: *\^/\
55/
56h
57s/\n.*//
58t x
59d
60: x
61s/.*\^ *\^ *\(.*\)/\1;/
62t y
63d
64: y
65p
66x
67D' ${temp}
9bc6fb0a
TTN
68}
69
9bc6fb0a
TTN
70## main
71
72# process command line
73if [ x"$1" = x--help ] ; then
74 @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
75 | sed -e 1,2d -e 's/^. *//g'
76 exit 0
77fi
9bc6fb0a 78if [ x"$1" = x-o ]
34690e53
MV
79 then outfile="$2" ; shift ; shift ;
80 else outfile="-" ;
9bc6fb0a
TTN
81fi
82
9bc6fb0a
TTN
83# set vars and handler -- handle CPP override
84cpp_ok_p=false
5b5179f8
LC
85
86if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
87tempdir="$TMPDIR/guile-snarf.$$"
d9623da1
MV
88(umask 077 && mkdir $tempdir) || exit 1
89temp="$tempdir/tmp"
5b5179f8 90
9bc6fb0a 91if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
66c4b109 92
d9623da1 93trap "rm -rf $tempdir" 0 1 2 15
66c4b109 94
34690e53
MV
95if [ ! "$outfile" = "-" ] ; then
96 modern_snarf "$@" > $outfile
66c4b109 97else
34690e53 98 modern_snarf "$@"
66c4b109 99fi
77b26c93 100
9bc6fb0a
TTN
101# zonk outfile if errors occurred
102if $cpp_ok_p ; then
103 exit 0
104else
66c4b109 105 [ ! "$outfile" = "-" ] && rm -f $outfile
9bc6fb0a
TTN
106 exit 1
107fi
63a646c5 108
9bc6fb0a 109# guile-snarf ends here