xref: /linux/tools/include/nolibc/Makefile (revision f94da2b42bc84bbcdb5d1f41551295fc946c7f7e)
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
20architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86
21arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures)))
22all_files := \
23		assert.h \
24		byteswap.h \
25		compiler.h \
26		crt.h \
27		ctype.h \
28		dirent.h \
29		elf.h \
30		endian.h \
31		err.h \
32		errno.h \
33		fcntl.h \
34		getopt.h \
35		inttypes.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/ptrace.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 multi-arch 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
96# installs headers for all archs at once.
97headers:
98	$(Q)mkdir -p "$(OUTPUT)sysroot/include"
99	$(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/"
100
101headers_standalone: headers
102	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
103
104CFLAGS_s390 := -m64
105CFLAGS := $(CFLAGS_$(ARCH))
106
107headers_check: headers_standalone
108	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
109		$(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
110			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
111	done
112
113clean:
114	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
115