| 1 |
# SPDX-License-Identifier: GPL-2.0 |
| 2 |
# Makefile for nolibc installation and tests |
| 3 |
include ../../scripts/Makefile.include |
| 4 |
|
| 5 |
# we're in ".../tools/include/nolibc" |
| 6 |
ifeq ($(srctree),) |
| 7 |
srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR))) |
| 8 |
endif |
| 9 |
|
| 10 |
# when run as make -C tools/ nolibc_<foo> the arch is not set |
| 11 |
ifeq ($(ARCH),) |
| 12 |
include $(srctree)/scripts/subarch.include |
| 13 |
ARCH = $(SUBARCH) |
| 14 |
endif |
| 15 |
|
| 16 |
# OUTPUT is only set when run from the main makefile, otherwise |
| 17 |
# it defaults to this nolibc directory. |
| 18 |
OUTPUT ?= $(CURDIR)/ |
| 19 |
|
| 20 |
ifeq ($(V),1) |
| 21 |
Q= |
| 22 |
else |
| 23 |
Q=@ |
| 24 |
endif |
| 25 |
|
| 26 |
arch_files := arch.h $(wildcard arch-*.h) |
| 27 |
all_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 |
inttypes.h \ |
| 37 |
limits.h \ |
| 38 |
math.h \ |
| 39 |
nolibc.h \ |
| 40 |
poll.h \ |
| 41 |
sched.h \ |
| 42 |
signal.h \ |
| 43 |
stackprotector.h \ |
| 44 |
std.h \ |
| 45 |
stdarg.h \ |
| 46 |
stdbool.h \ |
| 47 |
stddef.h \ |
| 48 |
stdint.h \ |
| 49 |
stdlib.h \ |
| 50 |
string.h \ |
| 51 |
sys.h \ |
| 52 |
sys/auxv.h \ |
| 53 |
sys/ioctl.h \ |
| 54 |
sys/mman.h \ |
| 55 |
sys/mount.h \ |
| 56 |
sys/prctl.h \ |
| 57 |
sys/ptrace.h \ |
| 58 |
sys/random.h \ |
| 59 |
sys/reboot.h \ |
| 60 |
sys/resource.h \ |
| 61 |
sys/select.h \ |
| 62 |
sys/stat.h \ |
| 63 |
sys/syscall.h \ |
| 64 |
sys/sysmacros.h \ |
| 65 |
sys/time.h \ |
| 66 |
sys/timerfd.h \ |
| 67 |
sys/types.h \ |
| 68 |
sys/uio.h \ |
| 69 |
sys/utsname.h \ |
| 70 |
sys/wait.h \ |
| 71 |
time.h \ |
| 72 |
types.h \ |
| 73 |
unistd.h \ |
| 74 |
stdio.h \ |
| 75 |
|
| 76 |
|
| 77 |
# install all headers needed to support a bare-metal compiler |
| 78 |
all: headers |
| 79 |
|
| 80 |
install: help |
| 81 |
|
| 82 |
help: |
| 83 |
@echo "Supported targets under nolibc:" |
| 84 |
@echo " all call \"headers\"" |
| 85 |
@echo " clean clean the sysroot" |
| 86 |
@echo " headers prepare a multi-arch sysroot in \$${OUTPUT}sysroot" |
| 87 |
@echo " headers_standalone like \"headers\", and also install kernel headers" |
| 88 |
@echo " help this help" |
| 89 |
@echo "" |
| 90 |
@echo "These targets may also be called from tools as \"make nolibc_<target>\"." |
| 91 |
@echo "" |
| 92 |
@echo "Currently using the following variables:" |
| 93 |
@echo " ARCH = $(ARCH)" |
| 94 |
@echo " OUTPUT = $(OUTPUT)" |
| 95 |
@echo "" |
| 96 |
|
| 97 |
# installs headers for all archs at once. |
| 98 |
headers: |
| 99 |
$(Q)mkdir -p "$(OUTPUT)sysroot" |
| 100 |
$(Q)mkdir -p "$(OUTPUT)sysroot/include" |
| 101 |
$(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/" |
| 102 |
|
| 103 |
headers_standalone: headers |
| 104 |
$(Q)$(MAKE) -C $(srctree) headers |
| 105 |
$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot |
| 106 |
|
| 107 |
CFLAGS_s390 := -m64 |
| 108 |
CFLAGS := $(CFLAGS_$(ARCH)) |
| 109 |
|
| 110 |
headers_check: headers_standalone |
| 111 |
$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \ |
| 112 |
$(CC) $(CFLAGS) $(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 |
|
| 116 |
clean: |
| 117 |
$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot" |