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 := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \ 29 sys.h time.h types.h unistd.h 30 31# install all headers needed to support a bare-metal compiler 32all: 33 34# Note: when ARCH is "x86" we concatenate both x86_64 and i386 35headers: 36 $(Q)mkdir -p $(OUTPUT)sysroot 37 $(Q)mkdir -p $(OUTPUT)sysroot/include 38 $(Q)cp $(all_files) $(OUTPUT)sysroot/include/ 39 $(Q)if [ "$(ARCH)" = "x86" ]; then \ 40 sed -e \ 41 's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \ 42 arch-x86_64.h; \ 43 sed -e \ 44 's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \ 45 arch-i386.h; \ 46 elif [ -e "$(arch_file)" ]; then \ 47 cat $(arch_file); \ 48 else \ 49 echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \ 50 exit 1; \ 51 fi > $(OUTPUT)sysroot/include/arch.h 52 53headers_standalone: headers 54 $(Q)$(MAKE) -C $(srctree) headers 55 $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot 56 57clean: 58 $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot" 59