Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
26arch_file := arch-$(ARCH).h
27all_files := \
28 compiler.h \
29 crt.h \
30 ctype.h \
31 dirent.h \
32 elf.h \
33 errno.h \
34 fcntl.h \
35 getopt.h \
36 limits.h \
37 math.h \
38 nolibc.h \
39 poll.h \
40 sched.h \
41 signal.h \
42 stackprotector.h \
43 std.h \
44 stdarg.h \
45 stdbool.h \
46 stddef.h \
47 stdint.h \
48 stdlib.h \
49 string.h \
50 sys.h \
51 sys/auxv.h \
52 sys/ioctl.h \
53 sys/mman.h \
54 sys/mount.h \
55 sys/prctl.h \
56 sys/random.h \
57 sys/reboot.h \
58 sys/resource.h \
59 sys/stat.h \
60 sys/syscall.h \
61 sys/sysmacros.h \
62 sys/time.h \
63 sys/timerfd.h \
64 sys/types.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 sysroot in tools/include/nolibc/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
93headers:
94 $(Q)mkdir -p $(OUTPUT)sysroot
95 $(Q)mkdir -p $(OUTPUT)sysroot/include
96 $(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
97 $(Q)if [ "$(ARCH)" = "i386" -o "$(ARCH)" = "x86_64" ]; then \
98 cat arch-x86.h; \
99 elif [ -e "$(arch_file)" ]; then \
100 cat $(arch_file); \
101 else \
102 echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
103 exit 1; \
104 fi > $(OUTPUT)sysroot/include/arch.h
105
106headers_standalone: headers
107 $(Q)$(MAKE) -C $(srctree) headers
108 $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
109
110headers_check: headers_standalone
111 $(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
112 $(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
113 -I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
114 done
115
116clean:
117 $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"