~ctwm/ctwm/trunk

« back to all changes in this revision

Viewing changes to tools/mk_function_bits.sh

  • Committer: Matthew Fuller
  • Date: 2016-08-16 10:37:18 UTC
  • mfrom: (514.2.49 build)
  • Revision ID: fullermd@over-yonder.net-20160816103718-7ay3cpxxzlkaw1er
Implement a parallel minimal build system, which can at least yield a
runnable ctwm in situations where the cmake chain is unavailable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# $0 ../function_defs.list OUTDIR
4
 
#
5
 
# Generates output files with various defs and lookup arrays.
6
 
 
7
 
infile="$1"
8
 
outdir="$2"
9
 
 
10
 
if [ -z "${infile}" -o ! -r "${infile}" ]; then
11
 
        echo "No infile."
12
 
        exit 1
13
 
fi
14
 
 
15
 
if [ -z "${outdir}" -o ! -d "${outdir}" ]; then
16
 
        echo "No outdir."
17
 
        exit 1
18
 
fi
19
 
 
20
 
 
21
 
# We're all C here
22
 
print_header() {
23
 
        echo "/*"
24
 
        echo " * AUTOGENERATED FILE -- DO NOT EDIT"
25
 
        echo " * This file is generated automatically by $0"
26
 
        echo " * from '${infile}'"
27
 
        echo " * during the build process."
28
 
        echo " */"
29
 
        echo
30
 
}
31
 
 
32
 
 
33
 
# Getting one section out of the input file
34
 
getsect() {
35
 
        # We presume we always want to clear out the comments and blank lines
36
 
        # anyway, so stick that in here.  And I think we always end up
37
 
        # sorting too, so do that as well.
38
 
        sed -e "1,/^# START($1)/d" -e "/^# END($1)/,\$d" \
39
 
                -e 's/#.*//' -e '/^[[:space:]]*$/d' \
40
 
                ${infile} | sort
41
 
}
42
 
 
43
 
 
44
 
 
45
 
#
46
 
# First off, creating the F_ defines.
47
 
#
48
 
gf="${outdir}/functions_defs.h"
49
 
(
50
 
        print_header
51
 
        cat << EOF
52
 
#ifndef _CTWM_FUNCTIONS_DEFS_H
53
 
#define _CTWM_FUNCTIONS_DEFS_H
54
 
 
55
 
/* Definitions for functions */
56
 
 
57
 
#define F_NOP 0    /* Hardcoded magic value */
58
 
 
59
 
EOF
60
 
 
61
 
        counter=1
62
 
 
63
 
        echo "/* Standard functions */"
64
 
        while read func ctype ifdef
65
 
        do
66
 
                # f.nop is special cased to always be 0, so skip it when we
67
 
                # encounter it in here.
68
 
                if [ "X${func}" = "XNOP" ]; then
69
 
                        continue;
70
 
                fi
71
 
 
72
 
 
73
 
                # Output #define, possible guarded by #ifdef's, with a comment to
74
 
                # note the ones that take string args.
75
 
                if [ "X${ifdef}" != "X-" ]; then
76
 
                        echo "#ifdef ${ifdef}"
77
 
                fi
78
 
 
79
 
                cmt=" //"
80
 
                if [ "X${ctype}" = "XS" ]; then
81
 
                        cmt="${cmt} string"
82
 
                fi
83
 
                if [ "X${cmt}" = "X //" ]; then
84
 
                        cmt=""
85
 
                fi
86
 
 
87
 
                printf "#define F_%-21s %3d${cmt}\n" "${func}" "${counter}"
88
 
 
89
 
                if [ "X${ifdef}" != "X-" ]; then
90
 
                        echo "#endif"
91
 
                fi
92
 
                counter=$((counter+1))
93
 
        done << EOF
94
 
        $(getsect main \
95
 
                | awk '{printf "%s %s %s\n", toupper($1), $2, $4;}')
96
 
EOF
97
 
 
98
 
        echo
99
 
        echo "/* Synthetic functions */"
100
 
        while read func
101
 
        do
102
 
                printf "#define F_%-21s %3d\n" "${func}" "${counter}"
103
 
                counter=$((counter+1))
104
 
        done << EOF
105
 
        $(getsect synthetic \
106
 
                | awk '{printf "%s\n", toupper($1)}')
107
 
EOF
108
 
 
109
 
        cat << EOF
110
 
 
111
 
#endif // _CTWM_FUNCTIONS_DEFS_H
112
 
EOF
113
 
 
114
 
) > ${gf}
115
 
#echo "Generated ${gf}"
116
 
 
117
 
 
118
 
 
119
 
#
120
 
# Next, setup the deferral lookup struct for function execution
121
 
#
122
 
gf="${outdir}/functions_deferral.h"
123
 
(
124
 
        print_header
125
 
        cat << EOF
126
 
 
127
 
#ifndef _CTWM_FUNCTIONS_DEFERRAL_H
128
 
#define _CTWM_FUNCTIONS_DEFERRAL_H
129
 
 
130
 
/* Functions deferral lookup */
131
 
typedef enum {
132
 
        DC_NONE = 0,
133
 
        DC_SELECT,
134
 
        DC_MOVE,
135
 
        DC_DESTROY,
136
 
} _fdef_table_cursor;
137
 
 
138
 
static const _fdef_table_cursor fdef_table[] = {
139
 
EOF
140
 
 
141
 
        while read func curs
142
 
        do
143
 
                if [ "X${func}" = "X" ]; then
144
 
                        echo "Got no function!"
145
 
                        exit 1
146
 
                fi
147
 
 
148
 
                scurs=""
149
 
                if [ "X${curs}" = "XCS" ]; then scurs="DC_SELECT"; fi
150
 
                if [ "X${curs}" = "XCM" ]; then scurs="DC_MOVE"; fi
151
 
                if [ "X${curs}" = "XCD" ]; then scurs="DC_DESTROY"; fi
152
 
 
153
 
                if [ "X${scurs}" = "X" ]; then
154
 
                        echo "Invalid: unexpected cursor '${curs}' for '${func}'!"
155
 
                        exit 1
156
 
                fi
157
 
 
158
 
                printf "\t%-23s = %s,\n" "[F_${func}]" "${scurs}"
159
 
        done << EOF
160
 
        $(getsect main \
161
 
                | awk '{ if ($3 != "-") {printf "%s %s\n", toupper($1), $3;} }')
162
 
EOF
163
 
 
164
 
        cat << EOF
165
 
};
166
 
 
167
 
static const size_t fdef_table_max = (sizeof(fdef_table) / sizeof(fdef_table[0]));
168
 
 
169
 
#endif // _CTWM_FUNCTIONS_DEFERRAL_H
170
 
EOF
171
 
 
172
 
) > ${gf}
173
 
#echo "Generated ${gf}"
174
 
 
175
 
 
176
 
 
177
 
#
178
 
# Now the keyword table for the config file parser.  This is somewhat
179
 
# more involved because it needs the entries from the main as well as
180
 
# alias sections, but it needs to have them together in a single
181
 
# ASCIIbetized list.
182
 
#
183
 
gf="${outdir}/functions_parse_table.h"
184
 
(
185
 
        # So we better start by pulling the main section, and stashing up
186
 
        # its rules.
187
 
        while read func ctype ifdef fdef
188
 
        do
189
 
                eval _STASH_${func}_ctype=\"$ctype\"
190
 
                eval _STASH_${func}_ifdef=\"$ifdef\"
191
 
                eval _STASH_${func}_fdef=\"$fdef\"
192
 
        done << EOF
193
 
        $(getsect main \
194
 
                | awk '{ printf "%s %s %s %s\n", $1, $2, $4, toupper($1) }')
195
 
EOF
196
 
        # Adding and stashing the extra toupper() there instead of calling
197
 
        # tr(1) in the loop below saves more than a quarter of a second
198
 
        # (which is ~quintuple the runtime without it).
199
 
 
200
 
 
201
 
        # Now run 'em both together and output
202
 
        print_header
203
 
        cat << EOF
204
 
#ifndef _CTWM_FUNCTIONS_PARSE_TABLE_H
205
 
#define _CTWM_FUNCTIONS_PARSE_TABLE_H
206
 
 
207
 
/* Parser table for functions */
208
 
static const TwmKeyword funckeytable[] = {
209
 
EOF
210
 
 
211
 
        while read func alias
212
 
        do
213
 
                # Look up pieces
214
 
                luf=$func
215
 
                cmt=""
216
 
                if [ "X${alias}" != "X" ]; then
217
 
                        luf=$alias
218
 
                        cmt=" // -> f.${alias}"
219
 
                fi
220
 
 
221
 
                eval _ctype=\$_STASH_${luf}_ctype
222
 
                eval ifdef=\$_STASH_${luf}_ifdef
223
 
                eval fdef=\$_STASH_${luf}_fdef
224
 
 
225
 
                ctype="FKEYWORD"
226
 
                if [ "X${_ctype}" = "XS" ]; then
227
 
                        ctype="FSKEYWORD"
228
 
                fi
229
 
 
230
 
 
231
 
                # Output
232
 
                if [ "X${ifdef}" != "X-" ]; then
233
 
                        echo "#ifdef ${ifdef}"
234
 
                fi
235
 
 
236
 
                printf "\t{ %-24s %10s %s },%s\n" "\"f.${func}\"," "${ctype}," \
237
 
                        "F_${fdef}" "${cmt}"
238
 
 
239
 
                if [ "X${ifdef}" != "X-" ]; then
240
 
                        echo "#endif"
241
 
                fi
242
 
        done << EOF
243
 
        $( ( getsect main    | awk '{printf "%s\n",    $1}' ;
244
 
             getsect aliases | awk '{printf "%s %s\n", $1, $2}'
245
 
           ) | sort)
246
 
EOF
247
 
 
248
 
        cat << EOF
249
 
};
250
 
        
251
 
static const size_t numfunckeywords = (sizeof(funckeytable) / sizeof(funckeytable[0]));
252
 
 
253
 
#endif // _CTWM_FUNCTIONS_PARSE_TABLE_H
254
 
EOF
255
 
 
256
 
) > ${gf}
257
 
#echo "Generated ${gf}"
258
 
 
259
 
 
260
 
 
261
 
#
262
 
# And finally, the dispatch table for executing functions.
263
 
#
264
 
gf="${outdir}/functions_dispatch_execution.h"
265
 
(
266
 
        # Everything we need for this is in the main section.
267
 
        # Now run 'em both together and output
268
 
        print_header
269
 
        cat << EOF
270
 
#ifndef _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
271
 
#define _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
272
 
 
273
 
/* Dispatcher table for executing functions */
274
 
static ExFunc * const func_dispatch[] = {
275
 
EOF
276
 
 
277
 
        while read func lcfunc ifdef
278
 
        do
279
 
                if [ "X${ifdef}" != "X-" ]; then
280
 
                        echo "#ifdef ${ifdef}"
281
 
                fi
282
 
 
283
 
                printf "\t%-23s = %s,\n" "[F_${func}]" "f_${lcfunc}_impl"
284
 
 
285
 
                if [ "X${ifdef}" != "X-" ]; then
286
 
                        echo "#endif"
287
 
                fi
288
 
        done << EOF
289
 
        $(getsect main \
290
 
                | awk '{ if ($5 != "N") {printf "%s %s %s\n", toupper($1), $1, $4} }'
291
 
          getsect synthetic \
292
 
                | awk '{ if ($2 != "N") {printf "%s %s -\n",  toupper($1), $1} }'
293
 
        )
294
 
EOF
295
 
 
296
 
        cat << EOF
297
 
};
298
 
        
299
 
static const size_t num_f_dis = (sizeof(func_dispatch) / sizeof(func_dispatch[0]));
300
 
 
301
 
#endif // _CTWM_FUNCTIONS_DISPATCH_EXECUTION_H
302
 
EOF
303
 
 
304
 
) > ${gf}
305
 
#echo "Generated ${gf}"