File: gen-ctl-io.in

package info (click to toggle)
libctl 3.2.2-4
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 2,304 kB
  • ctags: 1,178
  • sloc: sh: 11,466; ansic: 5,903; lisp: 2,311; makefile: 123
file content (226 lines) | stat: -rwxr-xr-x 6,181 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh

# libctl: flexible Guile-based control files for scientific software 
# Copyright (C) 1998, 1999, 2000, 2001, 2002, Steven G. Johnson
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA  02111-1307, USA.
#
# Steven G. Johnson can be contacted at stevenj@alum.mit.edu.

code=false
header=false
cxx=false
swig=false
output_file=""

while test $# -ge 1; do
    case $1 in
        -o) shift; output_file=$1 ;;
        --cxx) cxx=true ;;
        --code) code=true; header=false; swig=false ;;
        --header) header=true; code=false; swig=false ;;
        --swig) swig=true; header=false; code=false ;;
        *) break;;
    esac
    shift
done

if test $code = true; then
    if test $cxx = true; then
	default_output_file=ctl-io.cpp
    else
	default_output_file=ctl-io.c
    fi
elif test $header = true; then
    if test $cxx = true; then
	default_output_file=ctl-io.hpp
    else
	default_output_file=ctl-io.h
    fi
elif test $swig = true; then
    default_output_file=ctl-io.i
else
#   No output specified.  Backwards compatibility mode (code + header output).
    $0 --header $*
    $0 --code $*
    exit 0
fi

if test "x$output_file" = x; then
    output_file=$default_output_file
fi

spec_file=$1
if test ! -f "$spec_file"; then
    echo "cannot read specification file $spec_file"
    exit 1
fi

if test "$#" = "2"; then
    libctl_dir="$2"
else
    prefix="@prefix@"
    datarootdir="@datarootdir@"
    libctl_dir="@datadir@/libctl"
fi
case $libctl_dir in .*) libctl_dir=`pwd`/$libctl_dir ;; esac
if test ! -r $libctl_dir/utils/ctl-io.scm; then
    echo "couldn't find $libctl_dir/utils/ctl-io.scm"
    exit 1
fi

ok=yes

###########################################################################

if test $header = true; then

rm -f $output_file

cat > $output_file <<EOF
/* THIS FILE WAS AUTOMATICALLY GENERATED.  DO NOT MODIFY! */
/* generated from the file: $spec_file */

#ifndef CTL_IO_H
#define CTL_IO_H

#include <ctl.h>

EOF

if test $cxx = true; then
    cat >> $output_file <<EOF
#define CXX_CTL_IO 1
namespace ctlio {
EOF
else
    cat >> $output_file <<EOF
#ifdef __cplusplus
extern "C" {
#endif                          /* __cplusplus */
EOF
fi

echo >> $output_file

(@GUILE@ -l $libctl_dir/base/include.scm \
      -c "(include "'"'"$libctl_dir/base/ctl.scm"'"'") (include "'"'"$libctl_dir/utils/ctl-io.scm"'"'") (set"'!'" cxx $cxx) (include "'"'"$spec_file"'"'") (output-header)" >> $output_file) || ok=no

if test $ok = no; then rm -f $output_file; exit 1; fi

echo >> $output_file

if test $cxx = true; then
    cat >> $output_file <<EOF
} /* namespace */
EOF
else
    cat >> $output_file <<EOF
#ifdef __cplusplus
}                               /* extern "C" */
#endif                          /* __cplusplus */
EOF
fi

cat >> $output_file <<EOF

#endif                          /* CTL_IO_H */

EOF

if test $cxx = false; then
  @INDENT@ $output_file > /dev/null 2>&1
  rm -f ${output_file}~ ${output_file}.BAK
fi

fi # header = true

###########################################################################

if test $code = true; then

rm -f $output_file

cat > $output_file <<EOF
/* THIS FILE WAS AUTOMATICALLY GENERATED.  DO NOT MODIFY! */
/* generated from the file: $spec_file */

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "ctl-io.h"

#ifdef CXX_CTL_IO
using namespace ctlio;
#endif

EOF

(@GUILE@ -l $libctl_dir/base/include.scm \
      -c "(include "'"'"$libctl_dir/base/ctl.scm"'"'") (include "'"'"$libctl_dir/utils/ctl-io.scm"'"'") (set"'!'" cxx $cxx) (include "'"'"$spec_file"'"'") (output-source)" >> $output_file) || ok=no

if test $ok = no; then rm -f $output_file; exit 1; fi

if test $cxx = false; then
  @INDENT@ $output_file > /dev/null 2>&1
  rm -f ${output_file}~ ${output_file}.BAK
fi

fi # code = true

###########################################################################

if test $swig = true; then

    cat > $output_file <<EOF
/* THIS FILE WAS AUTOMATICALLY GENERATED.  DO NOT MODIFY! */
/* generated from the file: $spec_file */

EOF

    (@GUILE@ -l $libctl_dir/base/include.scm \
      -c "(include "'"'"$libctl_dir/base/ctl.scm"'"'") (include "'"'"$libctl_dir/utils/ctl-io.scm"'"'") (set"'!'" cxx $cxx) (include "'"'"$spec_file"'"'") (output-swig-header)" >> $output_file) || ok=no

    if test $ok = no; then rm -f $output_file; exit 1; fi

    cat >> $output_file <<EOF

/******* SWIG type-conversion mappings for basic libctl types *******/

%typemap(guile,in) vector3 { \$1 = ctl_convert_vector3_to_c(\$input); }
%typemap(guile,out) vector3 { \$result = ctl_convert_vector3_to_scm(\$1); }

%typemap(guile,in) matrix3x3 { \$1 = ctl_convert_matrix3x3_to_c(\$input); }
%typemap(guile,out) matrix3x3 { \$result = ctl_convert_matrix3x3_to_scm(\$1); }

%typemap(guile,in) cvector3 { \$1 = ctl_convert_cvector3_to_c(\$input); }
%typemap(guile,out) cvector3 { \$result = ctl_convert_cvector3_to_scm(\$1); }

%typemap(guile,in) cmatrix3x3 { \$1 = ctl_convert_cmatrix3x3_to_c(\$input); }
%typemap(guile,out) cmatrix3x3 { \$result = ctl_convert_cmatrix3x3_to_scm(\$1); }

%typemap(guile,in) cnumber { \$1 = ctl_convert_cnumber_to_c(\$input); }
%typemap(guile,out) cnumber { \$result = ctl_convert_cnumber_to_scm(\$1); }

%typemap(guile,in) function { \$1 = ctl_convert_function_to_c(\$input); }
%typemap(guile,out) function { \$result = ctl_convert_function_to_scm(\$1); }

%typemap(guile,in) object { \$1 = ctl_convert_object_to_c(\$input); }
%typemap(guile,out) object { \$result = ctl_convert_object_to_scm(\$1); }

EOF

fi