xref: /linux/tools/include/nolibc/Makefile (revision cc6809f6728456c03db6750fcc94ed8b581a2cf8)
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_files := arch.h $(wildcard 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/ptrace.h \
58		sys/random.h \
59		sys/reboot.h \
60		sys/resource.h \
61		sys/select.h \
62		sys/stat.h \
63		sys/syscall.h \
64		sys/sysmacros.h \
65		sys/time.h \
66		sys/timerfd.h \
67		sys/types.h \
68		sys/uio.h \
69		sys/utsname.h \
70		sys/wait.h \
71		time.h \
72		types.h \
73		unistd.h \
74		stdio.h \
75
76
77# install all headers needed to support a bare-metal compiler
78all: headers
79
80install: help
81
82help:
83	@echo "Supported targets under nolibc:"
84	@echo "  all                 call \"headers\""
85	@echo "  clean               clean the sysroot"
86	@echo "  headers             prepare a multi-arch sysroot in \$${OUTPUT}sysroot"
87	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
88	@echo "  help                this help"
89	@echo ""
90	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
91	@echo ""
92	@echo "Currently using the following variables:"
93	@echo "  ARCH    = $(ARCH)"
94	@echo "  OUTPUT  = $(OUTPUT)"
95	@echo ""
96
97# installs headers for all archs at once.
98headers:
99	$(Q)mkdir -p "$(OUTPUT)sysroot"
100	$(Q)mkdir -p "$(OUTPUT)sysroot/include"
101	$(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/"
102
103headers_standalone: headers
104	$(Q)$(MAKE) -C $(srctree) headers
105	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
106
107CFLAGS_s390 := -m64
108CFLAGS := $(CFLAGS_$(ARCH))
109
110headers_check: headers_standalone
111	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
112		$(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
113			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
114	done
115
116clean:
117	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
118