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