symbols.awk revision 1.3
1# $OpenBSD: symbols.awk,v 1.3 2024/04/17 22:48:17 tb Exp $
2
3# Copyright (c) 2018,2020,2023 Theo Buehler <tb@openbsd.org>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17# usage: awk -f symbols.awk < Symbols.list > symbols.c
18
19BEGIN {
20	printf("#include <stdio.h>\n\n")
21
22	printf("#include <openssl/dtls1.h>\n")
23	printf("#include <openssl/ssl.h>\n")
24	printf("#include <openssl/ssl2.h>\n")
25	printf("#include <openssl/ssl23.h>\n")
26	printf("#include <openssl/ssl3.h>\n")
27	printf("#include <openssl/tls1.h>\n\n")
28
29	printf("#include <openssl/srtp.h>\n\n")		# depends on ssl.h
30}
31
32{
33	symbols[$0] = $0
34
35	# Undefine aliases, so we don't accidentally leave them in Symbols.list.
36	printf("#ifdef %s\n#undef %s\n#endif\n", $0, $0)
37}
38
39END {
40	printf("\nint\nmain(void)\n{\n")
41	printf("\tsize_t i;\n");
42
43	printf("\tstruct {\n")
44	printf("\t\tconst char *const name;\n")
45	printf("\t\tconst void *addr;\n")
46	printf("\t} symbols[] = {\n")
47
48	for (symbol in symbols) {
49		printf("\t\t{\n")
50		printf("\t\t\t.name = \"%s\",\n", symbol)
51		printf("\t\t\t.addr = &%s,\n", symbol)
52		printf("\t\t},\n")
53	}
54
55	printf("\t\};\n\n")
56
57	printf("\tfor (i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++)\n")
58	printf("\t\tfprintf(stderr, \"%%s: %%p\\n\", symbols[i].name, symbols[i].addr);\n")
59	printf("\n\tprintf(\"OK\\n\");\n")
60	printf("\n\treturn 0;\n}\n")
61}
62