xref: /linux/tools/include/nolibc/Makefile (revision 015a99fa76650e7d6efa3e36f20c0f5b346fe9ce)
124326164SWilly Tarreau# SPDX-License-Identifier: GPL-2.0
224326164SWilly Tarreau# Makefile for nolibc installation and tests
324326164SWilly Tarreauinclude ../../scripts/Makefile.include
424326164SWilly Tarreau
524326164SWilly Tarreau# we're in ".../tools/include/nolibc"
624326164SWilly Tarreauifeq ($(srctree),)
724326164SWilly Tarreausrctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR)))
824326164SWilly Tarreauendif
924326164SWilly Tarreau
106a3ad243SWilly Tarreau# when run as make -C tools/ nolibc_<foo> the arch is not set
116a3ad243SWilly Tarreauifeq ($(ARCH),)
126a3ad243SWilly Tarreauinclude $(srctree)/scripts/subarch.include
136a3ad243SWilly TarreauARCH = $(SUBARCH)
146a3ad243SWilly Tarreauendif
156a3ad243SWilly Tarreau
166a3ad243SWilly Tarreau# OUTPUT is only set when run from the main makefile, otherwise
176a3ad243SWilly Tarreau# it defaults to this nolibc directory.
186a3ad243SWilly TarreauOUTPUT ?= $(CURDIR)/
196a3ad243SWilly Tarreau
206a3ad243SWilly Tarreauifeq ($(V),1)
216a3ad243SWilly TarreauQ=
226a3ad243SWilly Tarreauelse
236a3ad243SWilly TarreauQ=@
246a3ad243SWilly Tarreauendif
256a3ad243SWilly Tarreau
2624326164SWilly Tarreaunolibc_arch := $(patsubst arm64,aarch64,$(ARCH))
2724326164SWilly Tarreauarch_file := arch-$(nolibc_arch).h
28e21a2eefSThomas Weißschuhall_files := \
29818924d1SThomas Weißschuh		compiler.h \
3017336755SZhangjin Wu		crt.h \
31e21a2eefSThomas Weißschuh		ctype.h \
32665fa8deSThomas Weißschuh		dirent.h \
332b45ceb9SThomas Weißschuh		elf.h \
34e21a2eefSThomas Weißschuh		errno.h \
35ecc091d9SThomas Weißschuh		fcntl.h \
36bae3cd70SThomas Weißschuh		getopt.h \
375caaa0aaSThomas Weißschuh		limits.h \
38bf5e8a78SThomas Weißschuh		math.h \
39e21a2eefSThomas Weißschuh		nolibc.h \
40dc2c656eSThomas Weißschuh		poll.h \
41256dc733SThomas Weißschuh		sched.h \
42e21a2eefSThomas Weißschuh		signal.h \
43e21a2eefSThomas Weißschuh		stackprotector.h \
44e21a2eefSThomas Weißschuh		std.h \
45b56a9492SThomas Weißschuh		stdarg.h \
46ae1f550eSThomas Weißschuh		stdbool.h \
47*2217abe0SThomas Weißschuh		stddef.h \
48e21a2eefSThomas Weißschuh		stdint.h \
49e21a2eefSThomas Weißschuh		stdlib.h \
50e21a2eefSThomas Weißschuh		string.h \
51e21a2eefSThomas Weißschuh		sys.h \
529e67941dSThomas Weißschuh		sys/auxv.h \
537281be58SThomas Weißschuh		sys/ioctl.h \
54cce27316SThomas Weißschuh		sys/mman.h \
556e7c805aSThomas Weißschuh		sys/mount.h \
563edd5365SThomas Weißschuh		sys/prctl.h \
57801f020bSThomas Weißschuh		sys/random.h \
582efb9050SThomas Weißschuh		sys/reboot.h \
5990895247SThomas Weißschuh		sys/resource.h \
60c6e6c2c4SThomas Weißschuh		sys/stat.h \
610fd55773SThomas Weißschuh		sys/syscall.h \
62e1211e22SThomas Weißschuh		sys/sysmacros.h \
63face777aSThomas Weißschuh		sys/time.h \
64da69cfb1SThomas Weißschuh		sys/timerfd.h \
65ffb94910SThomas Weißschuh		sys/types.h \
660f971358SThomas Weißschuh		sys/utsname.h \
676d1724ecSThomas Weißschuh		sys/wait.h \
68e21a2eefSThomas Weißschuh		time.h \
69e21a2eefSThomas Weißschuh		types.h \
70e21a2eefSThomas Weißschuh		unistd.h \
71e21a2eefSThomas Weißschuh		stdio.h \
72e21a2eefSThomas Weißschuh
7324326164SWilly Tarreau
7424326164SWilly Tarreau# install all headers needed to support a bare-metal compiler
75fe20cad4SWilly Tarreauall: headers
7624326164SWilly Tarreau
774f8126f3SWilly Tarreauinstall: help
784f8126f3SWilly Tarreau
794f8126f3SWilly Tarreauhelp:
804f8126f3SWilly Tarreau	@echo "Supported targets under nolibc:"
814f8126f3SWilly Tarreau	@echo "  all                 call \"headers\""
824f8126f3SWilly Tarreau	@echo "  clean               clean the sysroot"
834f8126f3SWilly Tarreau	@echo "  headers             prepare a sysroot in tools/include/nolibc/sysroot"
844f8126f3SWilly Tarreau	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
854f8126f3SWilly Tarreau	@echo "  help                this help"
864f8126f3SWilly Tarreau	@echo ""
874f8126f3SWilly Tarreau	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
884f8126f3SWilly Tarreau	@echo ""
894f8126f3SWilly Tarreau	@echo "Currently using the following variables:"
904f8126f3SWilly Tarreau	@echo "  ARCH    = $(ARCH)"
914f8126f3SWilly Tarreau	@echo "  OUTPUT  = $(OUTPUT)"
924f8126f3SWilly Tarreau	@echo ""
934f8126f3SWilly Tarreau
9424326164SWilly Tarreau# Note: when ARCH is "x86" we concatenate both x86_64 and i386
9524326164SWilly Tarreauheaders:
9624326164SWilly Tarreau	$(Q)mkdir -p $(OUTPUT)sysroot
9724326164SWilly Tarreau	$(Q)mkdir -p $(OUTPUT)sysroot/include
9806052530SThomas Weißschuh	$(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/
9924326164SWilly Tarreau	$(Q)if [ "$(ARCH)" = "x86" ]; then      \
10024326164SWilly Tarreau		sed -e                          \
10124326164SWilly Tarreau		  's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
10224326164SWilly Tarreau		  arch-x86_64.h;                \
10324326164SWilly Tarreau		sed -e                          \
10424326164SWilly Tarreau		  's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
10524326164SWilly Tarreau		  arch-i386.h;                  \
10624326164SWilly Tarreau	elif [ -e "$(arch_file)" ]; then        \
10724326164SWilly Tarreau		cat $(arch_file);               \
10824326164SWilly Tarreau	else                                    \
10924326164SWilly Tarreau		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
11024326164SWilly Tarreau		exit 1;                         \
11124326164SWilly Tarreau	fi > $(OUTPUT)sysroot/include/arch.h
11224326164SWilly Tarreau
11324326164SWilly Tarreauheaders_standalone: headers
11424326164SWilly Tarreau	$(Q)$(MAKE) -C $(srctree) headers
1156a3ad243SWilly Tarreau	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
11624326164SWilly Tarreau
117a6a054c8SThomas Weißschuh# GCC uses "s390", clang "systemz"
118a6a054c8SThomas WeißschuhCLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
119a6a054c8SThomas Weißschuh
120a6a054c8SThomas Weißschuhheaders_check: headers_standalone
121a6a054c8SThomas Weißschuh	for header in $(filter-out crt.h std.h,$(all_files)); do \
122a6a054c8SThomas Weißschuh		$(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
123a6a054c8SThomas Weißschuh			-I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \
124a6a054c8SThomas Weißschuh	done
125a6a054c8SThomas Weißschuh
12624326164SWilly Tarreauclean:
12724326164SWilly Tarreau	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
128