xref: /linux/tools/include/nolibc/Makefile (revision 09c873c91fc10eeff5f7aecb408e1ac06ffbf83b)
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for nolibc installation and tests
3include ../../scripts/Makefile.include
4
5# we're in ".../tools/include/nolibc"
6ifeq ($(srctree),)
7srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR)))
8endif
9
10# when run as make -C tools/ nolibc_<foo> the arch is not set
11ifeq ($(ARCH),)
12include $(srctree)/scripts/subarch.include
13ARCH = $(SUBARCH)
14endif
15
16# OUTPUT is only set when run from the main makefile, otherwise
17# it defaults to this nolibc directory.
18OUTPUT ?= $(CURDIR)/
19
20ifeq ($(V),1)
21Q=
22else
23Q=@
24endif
25
26arch_file := arch-$(ARCH).h
27all_files := \
28		compiler.h \
29		crt.h \
30		ctype.h \
31		dirent.h \
32		elf.h \
33		errno.h \
34		fcntl.h \
35		getopt.h \
36		limits.h \
37		math.h \
38		nolibc.h \
39		poll.h \
40		sched.h \
41		signal.h \
42		stackprotector.h \
43		std.h \
44		stdarg.h \
45		stdbool.h \
46		stddef.h \
47		stdint.h \
48		stdlib.h \
49		string.h \
50		sys.h \
51		sys/auxv.h \
52		sys/ioctl.h \
53		sys/mman.h \
54		sys/mount.h \
55		sys/prctl.h \
56		sys/random.h \
57		sys/reboot.h \
58		sys/resource.h \
59		sys/stat.h \
60		sys/syscall.h \
61		sys/sysmacros.h \
62		sys/time.h \
63		sys/timerfd.h \
64		sys/types.h \
65		sys/uio.h \
66		sys/utsname.h \
67		sys/wait.h \
68		time.h \
69		types.h \
70		unistd.h \
71		stdio.h \
72
73
74# install all headers needed to support a bare-metal compiler
75all: headers
76
77install: help
78
79help:
80	@echo "Supported targets under nolibc:"
81	@echo "  all                 call \"headers\""
82	@echo "  clean               clean the sysroot"
83	@echo "  headers             prepare a sysroot in \$${OUTPUT}sysroot"
84	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
85	@echo "  help                this help"
86	@echo ""
87	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
88	@echo ""
89	@echo "Currently using the following variables:"
90	@echo "  ARCH    = $(ARCH)"
91	@echo "  OUTPUT  = $(OUTPUT)"
92	@echo ""
93
94headers:
95	$(Q)mkdir -p $(OUTPUT)sysroot
96	$(Q)mkdir -p $(OUTPUT)sysroot/include
97	$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
98	$(Q)if [ "$(ARCH)" = "i386" -o "$(ARCH)" = "x86_64" ]; then \
99		cat arch-x86.h;                 \
100	elif [ -e "$(arch_file)" ]; then        \
101		cat $(arch_file);               \
102	else                                    \
103		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
104		exit 1;                         \
105	fi > $(OUTPUT)sysroot/include/arch.h
106
107headers_standalone: headers
108	$(Q)$(MAKE) -C $(srctree) headers
109	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
110
111headers_check: headers_standalone
112	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
113		$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
114			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
115	done
116
117clean:
118	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
119