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