xref: /linux/tools/include/nolibc/Makefile (revision 44bf8bbe29fd50ed2b8dfd1873bd22f76ca2f4d9)
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		inttypes.h \
37		limits.h \
38		math.h \
39		nolibc.h \
40		poll.h \
41		sched.h \
42		signal.h \
43		stackprotector.h \
44		std.h \
45		stdarg.h \
46		stdbool.h \
47		stddef.h \
48		stdint.h \
49		stdlib.h \
50		string.h \
51		sys.h \
52		sys/auxv.h \
53		sys/ioctl.h \
54		sys/mman.h \
55		sys/mount.h \
56		sys/prctl.h \
57		sys/random.h \
58		sys/reboot.h \
59		sys/resource.h \
60		sys/select.h \
61		sys/stat.h \
62		sys/syscall.h \
63		sys/sysmacros.h \
64		sys/time.h \
65		sys/timerfd.h \
66		sys/types.h \
67		sys/uio.h \
68		sys/utsname.h \
69		sys/wait.h \
70		time.h \
71		types.h \
72		unistd.h \
73		stdio.h \
74
75
76# install all headers needed to support a bare-metal compiler
77all: headers
78
79install: help
80
81help:
82	@echo "Supported targets under nolibc:"
83	@echo "  all                 call \"headers\""
84	@echo "  clean               clean the sysroot"
85	@echo "  headers             prepare a sysroot in \$${OUTPUT}sysroot"
86	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
87	@echo "  help                this help"
88	@echo ""
89	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
90	@echo ""
91	@echo "Currently using the following variables:"
92	@echo "  ARCH    = $(ARCH)"
93	@echo "  OUTPUT  = $(OUTPUT)"
94	@echo ""
95
96headers:
97	$(Q)mkdir -p $(OUTPUT)sysroot
98	$(Q)mkdir -p $(OUTPUT)sysroot/include
99	$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
100	$(Q)if [ "$(ARCH)" = "i386" -o "$(ARCH)" = "x86_64" ]; then \
101		cat arch-x86.h;                 \
102	elif [ -e "$(arch_file)" ]; then        \
103		cat $(arch_file);               \
104	else                                    \
105		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
106		exit 1;                         \
107	fi > $(OUTPUT)sysroot/include/arch.h
108
109headers_standalone: headers
110	$(Q)$(MAKE) -C $(srctree) headers
111	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
112
113headers_check: headers_standalone
114	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
115		$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
116			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
117	done
118
119clean:
120	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
121