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 20architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86 21arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures))) 22all_files := \ 23 compiler.h \ 24 crt.h \ 25 ctype.h \ 26 dirent.h \ 27 elf.h \ 28 err.h \ 29 errno.h \ 30 fcntl.h \ 31 getopt.h \ 32 inttypes.h \ 33 limits.h \ 34 math.h \ 35 nolibc.h \ 36 poll.h \ 37 sched.h \ 38 signal.h \ 39 stackprotector.h \ 40 std.h \ 41 stdarg.h \ 42 stdbool.h \ 43 stddef.h \ 44 stdint.h \ 45 stdlib.h \ 46 string.h \ 47 sys.h \ 48 sys/auxv.h \ 49 sys/ioctl.h \ 50 sys/mman.h \ 51 sys/mount.h \ 52 sys/prctl.h \ 53 sys/ptrace.h \ 54 sys/random.h \ 55 sys/reboot.h \ 56 sys/resource.h \ 57 sys/select.h \ 58 sys/stat.h \ 59 sys/syscall.h \ 60 sys/sysmacros.h \ 61 sys/time.h \ 62 sys/timerfd.h \ 63 sys/types.h \ 64 sys/uio.h \ 65 sys/utsname.h \ 66 sys/wait.h \ 67 time.h \ 68 types.h \ 69 unistd.h \ 70 stdio.h \ 71 72 73# install all headers needed to support a bare-metal compiler 74all: headers 75 76install: help 77 78help: 79 @echo "Supported targets under nolibc:" 80 @echo " all call \"headers\"" 81 @echo " clean clean the sysroot" 82 @echo " headers prepare a multi-arch sysroot in \$${OUTPUT}sysroot" 83 @echo " headers_standalone like \"headers\", and also install kernel headers" 84 @echo " help this help" 85 @echo "" 86 @echo "These targets may also be called from tools as \"make nolibc_<target>\"." 87 @echo "" 88 @echo "Currently using the following variables:" 89 @echo " ARCH = $(ARCH)" 90 @echo " OUTPUT = $(OUTPUT)" 91 @echo "" 92 93# installs headers for all archs at once. 94headers: 95 $(Q)mkdir -p "$(OUTPUT)sysroot/include" 96 $(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/" 97 98headers_standalone: headers 99 $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot 100 101CFLAGS_s390 := -m64 102CFLAGS := $(CFLAGS_$(ARCH)) 103 104headers_check: headers_standalone 105 $(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \ 106 $(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \ 107 -I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \ 108 done 109 110clean: 111 $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot" 112