summaryrefslogtreecommitdiffstats
path: root/mk/generate.mk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mk/generate.mk127
1 files changed, 127 insertions, 0 deletions
diff --git a/mk/generate.mk b/mk/generate.mk
new file mode 100644
index 0000000..ec33cdc
--- /dev/null
+++ b/mk/generate.mk
@@ -0,0 +1,127 @@
+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