xref: /linux/tools/include/nolibc/Makefile (revision 5e7392dc82ed7bf3e734cbca77a1c6fd044ec871)
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		stdint.h \
48		stdlib.h \
49		string.h \
50		sys.h \
51		sys/auxv.h \
52		sys/mman.h \
53		sys/random.h \
54		sys/stat.h \
55		sys/syscall.h \
56		sys/time.h \
57		sys/timerfd.h \
58		sys/types.h \
59		sys/wait.h \
60		time.h \
61		types.h \
62		unistd.h \
63		stdio.h \
64
65
66# install all headers needed to support a bare-metal compiler
67all: headers
68
69install: help
70
71help:
72	@echo "Supported targets under nolibc:"
73	@echo "  all                 call \"headers\""
74	@echo "  clean               clean the sysroot"
75	@echo "  headers             prepare a sysroot in tools/include/nolibc/sysroot"
76	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
77	@echo "  help                this help"
78	@echo ""
79	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
80	@echo ""
81	@echo "Currently using the following variables:"
82	@echo "  ARCH    = $(ARCH)"
83	@echo "  OUTPUT  = $(OUTPUT)"
84	@echo ""
85
86# Note: when ARCH is "x86" we concatenate both x86_64 and i386
87headers:
88	$(Q)mkdir -p $(OUTPUT)sysroot
89	$(Q)mkdir -p $(OUTPUT)sysroot/include
90	$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
91	$(Q)if [ "$(ARCH)" = "x86" ]; then      \
92		sed -e                          \
93		  's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
94		  arch-x86_64.h;                \
95		sed -e                          \
96		  's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
97		  arch-i386.h;                  \
98	elif [ -e "$(arch_file)" ]; then        \
99		cat $(arch_file);               \
100	else                                    \
101		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
102		exit 1;                         \
103	fi > $(OUTPUT)sysroot/include/arch.h
104
105headers_standalone: headers
106	$(Q)$(MAKE) -C $(srctree) headers
107	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
108
109# GCC uses "s390", clang "systemz"
110CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
111
112headers_check: headers_standalone
113	for header in $(filter-out crt.h std.h,$(all_files)); do \
114		$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
115			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
116	done
117
118clean:
119	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
120