summaryrefslogtreecommitdiffstats
path: root/mk/generate.mk
blob: 17671f4cec3a348ef8cfba796de8c98093a18a38 (plain) (blame)
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
# See LICENSE file for copyright and license details.
NPARAMS != printf '%d\n' 1 $(NPARAMS) | sort -n | sed -n '$$p'

IMPORTANT_CPPFLAGS += -DNPARAMS="$(NPARAMS)"

GET_SYSCALL_RANGE_GEN != printf 'generated/get_syscall_range.%s.c\n' $(OPERATING_SYSTEMS)


libsyscalls_get_syscall_range.o: $(GET_SYSCALL_RANGE_GEN) generated/get_syscall_range.c
libsyscalls_get_syscall_range.lo: $(GET_SYSCALL_RANGE_GEN) generated/get_syscall_range.c

libsyscalls_get_syscall_display_info.o: generated/symbols.c
libsyscalls_get_syscall_display_info.lo: generated/symbols.c

libsyscalls_get_signals.o: generated/signals.c
libsyscalls_get_signals.lo: generated/signals.c

libsyscalls_get_syscall_errors.o: generated/errors.c
libsyscalls_get_syscall_errors.lo: generated/errors.c

libsyscalls_get_datatype_description.o: generated/types.c
libsyscalls_get_datatype_description.lo: generated/types.c


$(GET_SYSCALL_RANGE_GEN): get_syscall_range.template.c mk/generate.mk
	mkdir -p -- generated
	set -e; \
	lowercase="$$(printf '%s\n' "$@" | cut -d . -f 2)"; \
	uppercase="$$(printf '%s\n' "$$lowercase" | tr '[a-z]' '[A-Z]')"; \
	sed -e "s/zzz/$$lowercase/g" -e "s/ZZZ/$$uppercase/g" < get_syscall_range.template.c > $@

generated/get_syscall_range.c: Makefile mk/generate.mk
	printf '\43include "get_syscall_range.%s.c"\n' $(OPERATING_SYSTEMS) > $@

generated/symbols.c: Makefile mk/generate.mk
	mkdir -p -- generated
	printf '\43include "../%s/symbols.c"\n' $(OPERATING_SYSTEMS) > $@

generated/signals.c: Makefile mk/generate.mk
	mkdir -p -- generated
	printf '\43include "../%s/signals.c"\n' $(OPERATING_SYSTEMS) > $@

generated/errors.c: Makefile mk/generate.mk
	mkdir -p -- generated
	printf '\43include "../%s/errors.c"\n' $(OPERATING_SYSTEMS) > $@

generated/types.c: Makefile mk/generate.mk
	mkdir -p -- generated
	printf '\43include "../%s/types.c"\n' $(OPERATING_SYSTEMS) > $@

generated/arches.h: Makefile mk/generate.mk
	mkdir -p -- generated
	printf '\43include "%s-arches.h"\n' $(OPERATING_SYSTEMS) > $@

generated/oses.h: Makefile mk/generate.mk
	mkdir -p -- generated
	set -e;\
	for os in $(OPERATING_SYSTEMS); do\
		printf '%s\n' "$$(printf '%s\n' "$$os" | tr '[a-z]' '[A-Z]')" "$$os";\
	done |\
	(printf '\43define LIST_OSES(X, D)\\\n' &&\
	 xargs printf '\tX(%s, %s) D\\\n';\
	) | sed '$$s/ D\\//' > $@

generated/lowercase.h: libsyscalls.h mk/generate.mk
	mkdir -p -- generated
	sed -n 's/^\s*LIBSYSCALLS_CAT_\([A-Z0-9_]\+\).*$$/\1/p' < libsyscalls.h \
	| grep -v '^\(SUPPORT_PENDING\|NOT_IMPLEMENTED\)$$' \
	| while read uppercase; do \
		printf '\43define LOWERCASE_%s %s\n' \
			"$$uppercase" \
			"$$(printf '%s\n' "$$uppercase" | tr '[A-Z]' '[a-z]')"; \
	done > $@

libsyscalls/short-enums.h: libsyscalls.h mk/generate.mk
	rm -f -- $@
	printf '\43%s\n' > $@ \
		'ifndef LIBSYSCALLS_H' \
		' error Do not include this header file directly' \
		'endif'
	sed -n 's/^.*\b\(enum_libsyscalls_[A-Za-z0-9_]\+\)\([^A-Za-z0-9_].*\|\)$$/\1/p' < libsyscalls.h \
	| sort -u \
	| xargs printf 'typedef unsigned short int %s;\n' \
	>> $@
	chmod -- a-w $@

generated/macros.h: common.h mk/generate.mk
	set -e;\
	for find in COUNT_ARG_PAIRS PARAMS_BUILD_TYPES; do \
		text="$$(sed -n 's/^\s*\x23\s*define\s\+'"$$find"'_1(/&/p' < common.h)"; \
		i=1; while (( i <= $(NPARAMS) )); do \
			j=$$(( i + 1 )); \
			printf '%s\n' "$$text" | sed -e "s/_2/_$$j/g" -e "s/_1/_$$i/g"; \
			i=$$j; \
		done; \
	done > $@;
	 (set -e; \
	nparamspairs="$$(i=1; while (( i <= $(NPARAMS) )); do printf '%s\n' $$i $$i; : $$(( i++ )); done)"; \
	printf '\43define PARAMS_BUILD_MASK(MASK, ...)\\\n'; \
	printf '\t0 PARAMS_BUILD_MASK_(MASK, _, 0'; \
	printf ', _, %s%s' $$nparamspairs; \
	printf ')\n'; \
	printf '\43define PARAMS_BUILD_MASK_(MASK'; \
	printf ', A%s, x%s' $$nparamspairs; \
	printf ', ...)'; \
	printf '\\\n\tMASK\43\43_\43\43A%s(1U << %s)' $$nparamspairs; \
	printf '\n'; \
	) >> $@
	(set -e; \
	for a in IN OUT SYM; do b=; \
		for b in "$$b" "$$b"_IN; do \
		for b in "$$b" "$$b"_OUT; do \
		for b in "$$b" "$$b"_SYM; do \
			c=; if printf '%s\n' "$$b" | grep "$$a" >/dev/null; then \
				c=' |X'; \
			fi; \
			printf '\43define %s%s(X)%s\n' "$$a" "$$b" "$$c"; \
		done; done; done; \
	done) | sed 's/_IN_OUT/_BI/' | sed 's/\(\s[A-Z]\+\)(/\1__(/' >> $@


SELF_CHECK_COMMAND = test "$(NPARAMS)" -le 16
SELF_CHECK_RULE != if ! $(SELF_CHECK_COMMAND); then printf 'self-check\n'; fi
libsyscalls.a: $(SELF_CHECK_RULE)
libsyscalls.$(LIBEXT): $(SELF_CHECK_RULE)
self-check:; $(SELF_CHECK_COMMAND)

.PHONY: self-check