summaryrefslogblamecommitdiffstats
path: root/linux/errors.mk
blob: b34258a80050b8da3919a245581cee8faed2e615 (plain) (tree)
1
2

                                                     
















                                                                                           
                                                                               








                                                                                   
                                                                                                                                                    














                                                                                                  
                                                                                     







                                                                                                       
# See LICENSE file for copyright and license details.

libsyscalls_get_syscall_errors.o: generated/linux-errors.h linux/errors.c
libsyscalls_get_syscall_errors.lo: generated/linux-errors.h linux/errors.c

generated/linux-errors.tbl: $(LINUX_SOURCE) linux/errors.mk
	mkdir -p -- generated
	set -e; ( \
	get_gcc_or_clang () { \
		( \
			( \
				IFS=:; \
				for dir in $$PATH; do \
					if test ! -d "$$dir"; then continue; fi; \
					for file in "$$dir"/*; do \
						if test ! -x "$$file"; then continue; fi; \
						printf '%s\n' "$$file"; \
					done \
				done \
			) | grep '/\(gcc\|clang\)\(-[0-9.]\{1,\}\)\{0,1\}$$'; \
			printf '%s\n' gcc; \
		) | sed 1q; \
	}; \
	extract="$$(get_gcc_or_clang) -E -dM"; \
	toolsdir="linux-src/linux-$(LINUX_VERSION)/tools"; \
	process_arch() \
	{ \
		($$extract "-I$$toolsdir/include/uapi" "$$2" && \
		 cat -- "linux-src/linux-$(LINUX_VERSION)/include/linux/errno.h") \
		| sed -n 's/^$(s)*$(h)$(s)*define$(s)\{1,\}\(E[^[:space:]]\{1,\}\)$(s)\{1,\}\([0-9]\{1,\}\)$(s)*\(\/.*\)\{0,1\}$$/'"$$1"' \2 \1/p' \
		| sort -k 2 -nu; \
	}; \
	for arch in $$(printf '%s\n' "$$toolsdir/arch"/*/ | sed 's:^.*/\([^/]*\)/$$:\1:'); do \
		if test -f "$$toolsdir/arch/$$arch/include/uapi/asm/errno.h"; then \
			process_arch "$$arch" "$$toolsdir/arch/$$arch/include/uapi/asm/errno.h"; \
		fi; \
	done; \
	process_arch generic "$$toolsdir/include/uapi/asm-generic/errno.h"; \
	) > $@

generated/linux-errors.h: generated/linux-errors.tbl linux/errors.mk
	set -e; \
	for arch in $$(cut -d ' ' -f 1 < generated/linux-errors.tbl | uniq); do \
		ARCH="$$(printf '%s\n' "$$arch" | tr '[a-z]' '[A-Z]')"; \
		printf '#define LIST_LINUX_ERRORS_FOR_%s(X, D)\\\n' "$$ARCH"; \
		sed -n 's/^'"$$arch"' \([0-9]\{1,\}\) \(.*\)$$/\tX(\1, "\2") D\\/p' \
		< generated/linux-errors.tbl \
		| sed '$$s/ D\\//'; \
		printf 'static struct libsyscalls_named_number linux_errors_for_%s[] = {\n' "$$arch"; \
		printf '#define X(NR, NAME) {.number.s = NR, .name = NAME}\n'; \
		printf '\tLIST_LINUX_ERRORS_FOR_%s(X, COMMA)\n' "$$ARCH"; \
		printf '#undef X\n'; \
		printf '};\n'; \
	done > $@