xref: /openbmc/linux/tools/include/nolibc/Makefile (revision 17336755)
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 \
30*17336755SZhangjin Wu		crt.h \
31e21a2eefSThomas Weißschuh		ctype.h \
32e21a2eefSThomas Weißschuh		errno.h \
33e21a2eefSThomas Weißschuh		nolibc.h \
34e21a2eefSThomas Weißschuh		signal.h \
35e21a2eefSThomas Weißschuh		stackprotector.h \
36e21a2eefSThomas Weißschuh		std.h \
37e21a2eefSThomas Weißschuh		stdint.h \
38e21a2eefSThomas Weißschuh		stdlib.h \
39e21a2eefSThomas Weißschuh		string.h \
40e21a2eefSThomas Weißschuh		sys.h \
41e21a2eefSThomas Weißschuh		time.h \
42e21a2eefSThomas Weißschuh		types.h \
43e21a2eefSThomas Weißschuh		unistd.h \
44e21a2eefSThomas Weißschuh		stdio.h \
45e21a2eefSThomas Weißschuh
4624326164SWilly Tarreau
4724326164SWilly Tarreau# install all headers needed to support a bare-metal compiler
48fe20cad4SWilly Tarreauall: headers
4924326164SWilly Tarreau
504f8126f3SWilly Tarreauinstall: help
514f8126f3SWilly Tarreau
524f8126f3SWilly Tarreauhelp:
534f8126f3SWilly Tarreau	@echo "Supported targets under nolibc:"
544f8126f3SWilly Tarreau	@echo "  all                 call \"headers\""
554f8126f3SWilly Tarreau	@echo "  clean               clean the sysroot"
564f8126f3SWilly Tarreau	@echo "  headers             prepare a sysroot in tools/include/nolibc/sysroot"
574f8126f3SWilly Tarreau	@echo "  headers_standalone  like \"headers\", and also install kernel headers"
584f8126f3SWilly Tarreau	@echo "  help                this help"
594f8126f3SWilly Tarreau	@echo ""
604f8126f3SWilly Tarreau	@echo "These targets may also be called from tools as \"make nolibc_<target>\"."
614f8126f3SWilly Tarreau	@echo ""
624f8126f3SWilly Tarreau	@echo "Currently using the following variables:"
634f8126f3SWilly Tarreau	@echo "  ARCH    = $(ARCH)"
644f8126f3SWilly Tarreau	@echo "  OUTPUT  = $(OUTPUT)"
654f8126f3SWilly Tarreau	@echo ""
664f8126f3SWilly Tarreau
6724326164SWilly Tarreau# Note: when ARCH is "x86" we concatenate both x86_64 and i386
6824326164SWilly Tarreauheaders:
6924326164SWilly Tarreau	$(Q)mkdir -p $(OUTPUT)sysroot
7024326164SWilly Tarreau	$(Q)mkdir -p $(OUTPUT)sysroot/include
7124326164SWilly Tarreau	$(Q)cp $(all_files) $(OUTPUT)sysroot/include/
7224326164SWilly Tarreau	$(Q)if [ "$(ARCH)" = "x86" ]; then      \
7324326164SWilly Tarreau		sed -e                          \
7424326164SWilly Tarreau		  's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
7524326164SWilly Tarreau		  arch-x86_64.h;                \
7624326164SWilly Tarreau		sed -e                          \
7724326164SWilly Tarreau		  's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
7824326164SWilly Tarreau		  arch-i386.h;                  \
7924326164SWilly Tarreau	elif [ -e "$(arch_file)" ]; then        \
8024326164SWilly Tarreau		cat $(arch_file);               \
8124326164SWilly Tarreau	else                                    \
8224326164SWilly Tarreau		echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
8324326164SWilly Tarreau		exit 1;                         \
8424326164SWilly Tarreau	fi > $(OUTPUT)sysroot/include/arch.h
8524326164SWilly Tarreau
8624326164SWilly Tarreauheaders_standalone: headers
8724326164SWilly Tarreau	$(Q)$(MAKE) -C $(srctree) headers
886a3ad243SWilly Tarreau	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
8924326164SWilly Tarreau
9024326164SWilly Tarreauclean:
9124326164SWilly Tarreau	$(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"
92