xref: /linux/tools/include/nolibc/Makefile (revision 015a99fa76650e7d6efa3e36f20c0f5b346fe9ce)
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
26nolibc_arch := $(patsubst arm64,aarch64,$(ARCH))
27arch_file := arch-$(nolibc_arch).h
28all_files := \
29		compiler.h \
30		crt.h \
31		ctype.h \
32		dirent.h \
33		elf.h \
34		errno.h \
35		fcntl.h \
36		getopt.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/stat.h \
61		sys/syscall.h \
62		sys/sysmacros.h \
63		sys/time.h \
64		sys/timerfd.h \
65		sys/types.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 tools/include/nolibc/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
94# Note: when ARCH is "x86" we concatenate both x86_64 and i386
95headers:
96	$(Q)mkdir -p $(OUTPUT)sysroot
97	$(Q)mkdir -p $(OUTPUT)sysroot/include
98	$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
99	$(Q)if [ "$(ARCH)" = "x86" ]; then      \
100		sed -e                          \
101		  's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
102		  arch-x86_64.h;                \
103		sed -e                          \
104		  's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
105		  arch-i386.h;                  \
106	elif [ -e "$(arch_file)" ]; then        \
107		cat $(arch_file);               \
108	else                                    \
109		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
110		exit 1;                         \
111	fi > $(OUTPUT)sysroot/include/arch.h
112
113headers_standalone: headers
114	$(Q)$(MAKE) -C $(srctree) headers
115	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
116
117# GCC uses "s390", clang "systemz"
118CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
119
120headers_check: headers_standalone
121	for header in $(filter-out crt.h std.h,$(all_files)); do \
122		$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
123			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
124	done
125
126clean:
127	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
128