Mercurial > hg > octave-lyh
annotate liboctave/mk-ops.awk @ 14396:08e48e7a4c8a stable
maint: avoid $(echo ...) in shell script string (bug #35572)
* mk-ops.awk, sparse-mk-ops.awk: Print lists of source files on one line.
* config-ops.sh: Don't call $(echo ...) inside string.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Feb 2012 15:40:44 -0500 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 # Copyright (C) 2003-2012 John W. Eaton |
7019 | 2 # |
3 # This file is part of Octave. | |
4 # | |
5 # Octave is free software; you can redistribute it and/or modify it | |
6 # under the terms of the GNU General Public License as published by the | |
7 # Free Software Foundation; either version 3 of the License, or (at | |
8 # your option) any later version. | |
9 # | |
10 # Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 # for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with Octave; see the file COPYING. If not, see | |
17 # <http://www.gnu.org/licenses/>. | |
18 | |
4544 | 19 BEGIN { |
20 declare_types = 0; | |
21 generate_ops = 0; | |
22 ntypes = 0; | |
4547 | 23 } { |
24 if (NR == 1 && make_inclusive_header) | |
4544 | 25 { |
4547 | 26 print "// DO NOT EDIT -- generated by mk-ops"; |
4544 | 27 tmp = make_inclusive_header; |
4547 | 28 gsub (/[\.-]/, "_", tmp); |
4544 | 29 printf ("#if !defined (octave_%s)\n", tmp); |
30 printf ("#define octave_%s 1\n", tmp); | |
31 } | |
32 } | |
4547 | 33 /^#/ { |
34 if ($2 == "types") | |
35 declare_types = 1; | |
36 else if ($2 == "ops") | |
37 { | |
38 generate_ops = 1; | |
39 declare_types = 0; | |
40 } | |
41 next; | |
42 } { | |
4544 | 43 if (declare_types) |
44 { | |
45 ntypes++; | |
46 | |
6119 | 47 if (NF == 6 || NF == 7) |
4544 | 48 { |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
49 if (NF == 7) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
50 core_type[ntypes] = $7; |
6119 | 51 |
5030 | 52 scalar_zero_val[ntypes] = $6; |
4544 | 53 fwd_decl_ok[ntypes] = $5 == "YES"; |
54 header[ntypes] = $4 == "NONE" ? "" : $4; | |
55 class[ntypes] = $3; | |
56 type[ntypes] = $2; | |
57 tag[ntypes] = $1; | |
58 rev_tag[$1] = ntypes; | |
59 } | |
60 else | |
61 printf ("skipping line %d: %s\n", NR, $0); | |
62 } | |
63 else if (generate_ops) | |
64 { | |
65 if (NF >= 4) | |
66 { | |
67 result_tag = $1; | |
68 lhs_tag = $2; | |
69 rhs_tag = $3; | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
70 op_type = $4; |
4544 | 71 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
72 bin_ops = index (op_type, "B") != 0; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
73 cmp_ops = index (op_type, "C") != 0; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
74 bool_ops = index (op_type, "L") != 0; |
4544 | 75 |
76 n = 4; | |
77 | |
78 lhs_conv = cmp_ops ? $(++n) : ""; | |
79 rhs_conv = cmp_ops ? $(++n) : ""; | |
80 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
81 if (lhs_conv == "NONE") |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
82 lhs_conv = ""; |
4544 | 83 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
84 if (rhs_conv == "NONE") |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
85 rhs_conv = ""; |
4544 | 86 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
87 k = 0 |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
88 while (NF > n) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
89 bool_headers[k++] = $(++n); |
4544 | 90 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
91 cc_file = sprintf ("%s-%s-%s.cc", prefix, lhs_tag, rhs_tag); |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
92 h_file = sprintf ("%s-%s-%s.h", prefix, lhs_tag, rhs_tag); |
4544 | 93 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
94 if (list_cc_files) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
95 { |
14396
08e48e7a4c8a
maint: avoid $(echo ...) in shell script string (bug #35572)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
96 printf (" %s", cc_file); |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
97 next; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
98 } |
4544 | 99 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
100 if (list_h_files) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
101 { |
14396
08e48e7a4c8a
maint: avoid $(echo ...) in shell script string (bug #35572)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
102 printf (" %s", h_file); |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
103 next; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
104 } |
4544 | 105 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
106 if (make_inclusive_header) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
107 { |
4547 | 108 printf ("#include \"%s\"\n", h_file); |
109 next; | |
110 } | |
4544 | 111 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
112 h_guard = sprintf ("octave_%s_%s_%s_h", prefix, lhs_tag, rhs_tag); |
4544 | 113 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
114 result_num = rev_tag[result_tag]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
115 lhs_num = rev_tag[lhs_tag]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
116 rhs_num = rev_tag[rhs_tag]; |
4544 | 117 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
118 result_type = type[result_num]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
119 lhs_type = type[lhs_num]; |
4544 | 120 rhs_type = type[rhs_num]; |
121 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
122 lhs_core_type = core_type[lhs_num]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
123 rhs_core_type = core_type[rhs_num]; |
6119 | 124 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
125 result_scalar_zero_val = scalar_zero_val[result_num]; |
5030 | 126 lhs_scalar_zero_val = scalar_zero_val[lhs_num]; |
127 rhs_scalar_zero_val = scalar_zero_val[rhs_num]; | |
128 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
129 result_header = header[result_num]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
130 lhs_header = header[lhs_num]; |
4544 | 131 rhs_header = header[rhs_num]; |
132 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
133 lhs_class = class[lhs_num]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
134 rhs_class = class[rhs_num]; |
4544 | 135 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
136 print "// DO NOT EDIT -- generated by mk-ops" > h_file; |
4544 | 137 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
138 printf ("#if !defined (%s)\n", h_guard) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
139 printf ("#define %s 1\n", h_guard) >> h_file; |
4544 | 140 |
141 if (result_header) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
142 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
143 if (result_fwd_decl_ok) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
144 printf ("class %s\n", result_type) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
145 else |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
146 printf ("#include \"%s\"\n", result_header) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
147 } |
4544 | 148 |
149 if (lhs_header && ! (lhs_header == result_header)) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
150 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
151 if (result_fwd_decl_ok) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
152 printf ("class %s\n", lhs_type) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
153 else |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
154 printf ("#include \"%s\"\n", lhs_header) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
155 } |
4544 | 156 |
157 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
158 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
159 if (result_fwd_decl_ok) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
160 printf ("class %s\n", rhs_type) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
161 else |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
162 printf ("#include \"%s\"\n", rhs_header) >> h_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
163 } |
4544 | 164 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
165 printf ("#include \"mx-op-decl.h\"\n") >> h_file; |
4544 | 166 |
4964 | 167 if (bin_ops) |
6708 | 168 printf ("%s%s_BIN_OP_DECLS (%s, %s, %s, OCTAVE_API)\n", lhs_class, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
169 rhs_class, result_type, lhs_type, rhs_type) >> h_file |
4964 | 170 |
171 if (cmp_ops) | |
6708 | 172 printf ("%s%s_CMP_OP_DECLS (%s, %s, OCTAVE_API)\n", lhs_class, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
173 rhs_class, lhs_type, rhs_type) >> h_file |
4964 | 174 |
175 if (bool_ops) | |
6708 | 176 printf ("%s%s_BOOL_OP_DECLS (%s, %s, OCTAVE_API)\n", lhs_class, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
177 rhs_class, lhs_type, rhs_type) >> h_file |
4964 | 178 |
4544 | 179 |
180 print "#endif" >> h_file; | |
181 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
182 close (h_file); |
4544 | 183 |
184 | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
185 print "// DO NOT EDIT -- generated by mk-ops" > cc_file; |
4544 | 186 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
187 print "#ifdef HAVE_CONFIG_H" >> cc_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
188 print "#include <config.h>" >> cc_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
189 print "#endif" >> cc_file; |
4544 | 190 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
191 print "#include \"Array-util.h\"" >> cc_file; |
4669 | 192 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
193 printf ("#include \"%s\"\n", h_file) >> cc_file; |
4544 | 194 |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
195 printf ("#include \"mx-op-defs.h\"\n") >> cc_file; |
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
196 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
197 for (i in bool_headers) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
198 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
199 printf ("#include \"%s\"\n", bool_headers[i]) >> cc_file; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
200 delete bool_headers[i]; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
201 } |
4544 | 202 |
203 if (result_header) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
204 printf ("#include \"%s\"\n", result_header) >> cc_file; |
4544 | 205 |
206 if (lhs_header && ! (lhs_header == result_header)) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
207 printf ("#include \"%s\"\n", lhs_header) >> cc_file; |
4544 | 208 |
209 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
210 printf ("#include \"%s\"\n", rhs_header) >> cc_file; |
4544 | 211 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
212 if (bin_ops) |
4544 | 213 { |
214 if ((lhs_class == "DM" && rhs_class == "M") || (lhs_class == "M" && rhs_class == "DM")) | |
215 printf ("%s%s_BIN_OPS (%s, %s, %s, %s)\n", | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
216 lhs_class, rhs_class, result_type, |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
217 lhs_type, rhs_type, result_scalar_zero_val) >> cc_file |
4544 | 218 else |
219 printf ("%s%s_BIN_OPS (%s, %s, %s)\n", | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
220 lhs_class, rhs_class, result_type, |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
221 lhs_type, rhs_type) >> cc_file |
4544 | 222 } |
223 | |
224 if (cmp_ops) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
225 printf ("%s%s_CMP_OPS (%s, %s)\n", |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
226 lhs_class, rhs_class, lhs_type, rhs_type) >> cc_file |
4544 | 227 |
228 if (bool_ops) | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
229 printf ("%s%s_BOOL_OPS (%s, %s)\n", lhs_class, rhs_class, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9578
diff
changeset
|
230 lhs_type, rhs_type) >> cc_file |
4544 | 231 |
232 | |
233 close (cc_file); | |
234 } | |
235 else | |
236 printf ("skipping line %d: %s\n", NR, $0); | |
237 } | |
238 } | |
239 END { | |
240 if (make_inclusive_header) | |
241 print "#endif"; | |
4547 | 242 } |