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