Export <slot> from GOOPS
[bpt/guile.git] / libguile / guile-snarf.in
CommitLineData
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
49modern_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
c3c30326 55 sed -ne 's/ *\^ *\^ */\
95c1cfb5 56/
c3c30326 57s/.*\n//
95c1cfb5
BT
58t x
59d
60: x
c3c30326
MW
61s/ *\^ *: *\^ */;\
62/
95c1cfb5 63t y
c3c30326
MW
64N
65s/\n\(#.*\)/ /
66s/\n/ /
67t x
95c1cfb5 68: y
c3c30326 69P
95c1cfb5 70D' ${temp}
9bc6fb0a
TTN
71}
72
9bc6fb0a
TTN
73## main
74
75# process command line
76if [ x"$1" = x--help ] ; then
77 @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
78 | sed -e 1,2d -e 's/^. *//g'
79 exit 0
80fi
9bc6fb0a 81if [ x"$1" = x-o ]
34690e53
MV
82 then outfile="$2" ; shift ; shift ;
83 else outfile="-" ;
9bc6fb0a
TTN
84fi
85
9bc6fb0a
TTN
86# set vars and handler -- handle CPP override
87cpp_ok_p=false
5b5179f8
LC
88
89if [ x"$TMPDIR" = x ]; then TMPDIR="/tmp" ; else : ; fi
90tempdir="$TMPDIR/guile-snarf.$$"
d9623da1
MV
91(umask 077 && mkdir $tempdir) || exit 1
92temp="$tempdir/tmp"
5b5179f8 93
9bc6fb0a 94if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
66c4b109 95
d9623da1 96trap "rm -rf $tempdir" 0 1 2 15
66c4b109 97
34690e53
MV
98if [ ! "$outfile" = "-" ] ; then
99 modern_snarf "$@" > $outfile
66c4b109 100else
34690e53 101 modern_snarf "$@"
66c4b109 102fi
77b26c93 103
9bc6fb0a
TTN
104# zonk outfile if errors occurred
105if $cpp_ok_p ; then
106 exit 0
107else
66c4b109 108 [ ! "$outfile" = "-" ] && rm -f $outfile
9bc6fb0a
TTN
109 exit 1
110fi
63a646c5 111
9bc6fb0a 112# guile-snarf ends here