2 # Extract the initialization actions from source files.
4 # Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc.
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)
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.
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
23 # Usage: guile-snarf [--compat=1.4] [-o OUTFILE] INFILE [CPP-OPTIONS ...]
25 # Process INFILE using the C pre-processor and some other programs.
26 # Write output to a file, named OUTFILE if specified, or STEM.x if
27 # INFILE looks like STEM.c and no OUTFILE is specified. Ignore
28 # lines from the input matching grep(1) regular expression:
30 # ^#include ".*OUTFILE"
32 # If there are errors during processing, delete OUTFILE and exit with
35 # Optional arg "--compat=1.4" means emulate guile-1.4 guile-snarf.
36 # This option is easily misunderstood -- see Guile reference manual.
38 # If env var CPP is set, use its value instead of the C pre-processor
39 # determined at Guile configure-time: "@CPP@".
45 modern_snarf
() # writes stdout
47 ${cpp} -DSCM_MAGIC_SNARF_INITS "$@" > ${temp} && cpp_ok_p
=true
48 grep "^ *\^ *\^" ${temp} |
sed -e "s/^ *\^ *\^//"
51 compat_mode_clean_xxx
() # modifies $1
55 sed -e 's/SCM_CONST_LONG/SCM_GLOBAL_VCELL_INIT/g' \
56 -e 's/SCM_GLOBAL_VCELL_INIT/SCM_GLOBAL_VARIABLE_INIT/g' \
57 -e 's/SCM_GLOBAL_VCELL/SCM_GLOBAL_VARIABLE/g' \
58 -e 's/SCM_VCELL_INIT/SCM_VARIABLE_INIT/g' \
59 -e 's/SCM_VCELL/SCM_VARIABLE/g' \
66 # process command line
67 if [ x
"$1" = x--help
] ; then
68 @AWK@
'/^#.Commentary:/,/^#.Code:/' $0 |
grep -v Code
: \
69 |
sed -e 1,2d
-e 's/^. *//g'
72 if [ x
"$1" = x--compat
=1.4 ]
73 then compat_mode_p
=true
; shift
74 else compat_mode_p
=false
77 then outfile
=$2 ; shift ; shift ; infile
=$1 ; shift
78 else infile
=$1 ; shift ; outfile
=`basename $infile .c`.x
81 [ x
"$infile" = x
] && { echo $0: No input
file ; exit 1 ; }
82 [ ! -f "$infile" ] && { echo $0: No such
file: $infile ; exit 1 ; }
84 # set vars and handler -- handle CPP override
87 if [ x
"$CPP" = x
] ; then cpp
="@CPP@" ; else cpp
="$CPP" ; fi
88 self_blind_regexp
='^#include ".*'`basename $outfile`'"'
89 clean_infile
=$infile.clean.c
# temp file in same dir as infile
90 # so that #include "foo" works
91 # (e.g., see libguile/eval.c).
92 # use .c to satisfy cpp heuristics.
93 trap "rm -f $temp $clean_infile" 0 1 2 15
96 grep -v "$self_blind_regexp" $infile > $clean_infile
97 $compat_mode_p && compat_mode_clean_xxx
$clean_infile
99 # do the snarfing -- output something extra for needy cpp programs (AIX)
100 { echo "/* source: $infile */" ;
101 echo "/* cpp-options: $@ */" ;
102 modern_snarf
"$@" $clean_infile ;
105 # zonk outfile if errors occurred
113 # guile-snarf ends here