xref: /openbmc/linux/tools/include/nolibc/Makefile (revision 856caabf)
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		ctype.h \
31		errno.h \
32		nolibc.h \
33		signal.h \
34		stackprotector.h \
35		std.h \
36		stdint.h \
37		stdlib.h \
38		string.h \
39		sys.h \
40		time.h \
41		types.h \
42		unistd.h \
43		stdio.h \
44
45
46# install all headers needed to support a bare-metal compiler
47all: headers
48
49install: help
50
51help:
52	@echo "Supported targets under nolibc:"
53	@echo "  all                 call \"headers\""
54	@echo "  clean               clean the sysroot"
55	@echo "  headers             prepare a sysroot in tools/include/nolibc/sysroot"
56	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
57	@echo "  help                this help"
58	@echo ""
59	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
60	@echo ""
61	@echo "Currently using the following variables:"
62	@echo "  ARCH    = $(ARCH)"
63	@echo "  OUTPUT  = $(OUTPUT)"
64	@echo ""
65
66# Note: when ARCH is "x86" we concatenate both x86_64 and i386
67headers:
68	$(Q)mkdir -p $(OUTPUT)sysroot
69	$(Q)mkdir -p $(OUTPUT)sysroot/include
70	$(Q)cp $(all_files) $(OUTPUT)sysroot/include/
71	$(Q)if [ "$(ARCH)" = "x86" ]; then      \
72		sed -e                          \
73		  's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
74		  arch-x86_64.h;                \
75		sed -e                          \
76		  's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
77		  arch-i386.h;                  \
78	elif [ -e "$(arch_file)" ]; then        \
79		cat $(arch_file);               \
80	else                                    \
81		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
82		exit 1;                         \
83	fi > $(OUTPUT)sysroot/include/arch.h
84
85headers_standalone: headers
86	$(Q)$(MAKE) -C $(srctree) headers
87	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
88
89clean:
90	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
91