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