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 26*01e8a6d0SThomas Weißschuharch_file := arch-$(ARCH).h 27e21a2eefSThomas Weißschuhall_files := \ 28818924d1SThomas Weißschuh compiler.h \ 2917336755SZhangjin Wu crt.h \ 30e21a2eefSThomas Weißschuh ctype.h \ 31665fa8deSThomas Weißschuh dirent.h \ 322b45ceb9SThomas Weißschuh elf.h \ 33e21a2eefSThomas Weißschuh errno.h \ 34ecc091d9SThomas Weißschuh fcntl.h \ 35bae3cd70SThomas Weißschuh getopt.h \ 365caaa0aaSThomas Weißschuh limits.h \ 37bf5e8a78SThomas Weißschuh math.h \ 38e21a2eefSThomas Weißschuh nolibc.h \ 39dc2c656eSThomas Weißschuh poll.h \ 40256dc733SThomas Weißschuh sched.h \ 41e21a2eefSThomas Weißschuh signal.h \ 42e21a2eefSThomas Weißschuh stackprotector.h \ 43e21a2eefSThomas Weißschuh std.h \ 44b56a9492SThomas Weißschuh stdarg.h \ 45ae1f550eSThomas Weißschuh stdbool.h \ 462217abe0SThomas Weißschuh stddef.h \ 47e21a2eefSThomas Weißschuh stdint.h \ 48e21a2eefSThomas Weißschuh stdlib.h \ 49e21a2eefSThomas Weißschuh string.h \ 50e21a2eefSThomas Weißschuh sys.h \ 519e67941dSThomas Weißschuh sys/auxv.h \ 527281be58SThomas Weißschuh sys/ioctl.h \ 53cce27316SThomas Weißschuh sys/mman.h \ 546e7c805aSThomas Weißschuh sys/mount.h \ 553edd5365SThomas Weißschuh sys/prctl.h \ 56801f020bSThomas Weißschuh sys/random.h \ 572efb9050SThomas Weißschuh sys/reboot.h \ 5890895247SThomas Weißschuh sys/resource.h \ 59c6e6c2c4SThomas Weißschuh sys/stat.h \ 600fd55773SThomas Weißschuh sys/syscall.h \ 61e1211e22SThomas Weißschuh sys/sysmacros.h \ 62face777aSThomas Weißschuh sys/time.h \ 63da69cfb1SThomas Weißschuh sys/timerfd.h \ 64ffb94910SThomas Weißschuh sys/types.h \ 650f971358SThomas Weißschuh sys/utsname.h \ 666d1724ecSThomas Weißschuh sys/wait.h \ 67e21a2eefSThomas Weißschuh time.h \ 68e21a2eefSThomas Weißschuh types.h \ 69e21a2eefSThomas Weißschuh unistd.h \ 70e21a2eefSThomas Weißschuh stdio.h \ 71e21a2eefSThomas Weißschuh 7224326164SWilly Tarreau 7324326164SWilly Tarreau# install all headers needed to support a bare-metal compiler 74fe20cad4SWilly Tarreauall: headers 7524326164SWilly Tarreau 764f8126f3SWilly Tarreauinstall: help 774f8126f3SWilly Tarreau 784f8126f3SWilly Tarreauhelp: 794f8126f3SWilly Tarreau @echo "Supported targets under nolibc:" 804f8126f3SWilly Tarreau @echo " all call \"headers\"" 814f8126f3SWilly Tarreau @echo " clean clean the sysroot" 824f8126f3SWilly Tarreau @echo " headers prepare a sysroot in tools/include/nolibc/sysroot" 834f8126f3SWilly Tarreau @echo " headers_standalone like \"headers\", and also install kernel headers" 844f8126f3SWilly Tarreau @echo " help this help" 854f8126f3SWilly Tarreau @echo "" 864f8126f3SWilly Tarreau @echo "These targets may also be called from tools as \"make nolibc_<target>\"." 874f8126f3SWilly Tarreau @echo "" 884f8126f3SWilly Tarreau @echo "Currently using the following variables:" 894f8126f3SWilly Tarreau @echo " ARCH = $(ARCH)" 904f8126f3SWilly Tarreau @echo " OUTPUT = $(OUTPUT)" 914f8126f3SWilly Tarreau @echo "" 924f8126f3SWilly Tarreau 9324326164SWilly Tarreauheaders: 9424326164SWilly Tarreau $(Q)mkdir -p $(OUTPUT)sysroot 9524326164SWilly Tarreau $(Q)mkdir -p $(OUTPUT)sysroot/include 9606052530SThomas Weißschuh $(Q)cp --parents $(all_files) $(OUTPUT)sysroot/include/ 97cc6dc5fbSWilly Tarreau $(Q)if [ "$(ARCH)" = "i386" -o "$(ARCH)" = "x86_64" ]; then \ 98cc6dc5fbSWilly Tarreau cat arch-x86.h; \ 9924326164SWilly Tarreau elif [ -e "$(arch_file)" ]; then \ 10024326164SWilly Tarreau cat $(arch_file); \ 10124326164SWilly Tarreau else \ 10224326164SWilly Tarreau echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \ 10324326164SWilly Tarreau exit 1; \ 10424326164SWilly Tarreau fi > $(OUTPUT)sysroot/include/arch.h 10524326164SWilly Tarreau 10624326164SWilly Tarreauheaders_standalone: headers 10724326164SWilly Tarreau $(Q)$(MAKE) -C $(srctree) headers 1086a3ad243SWilly Tarreau $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot 10924326164SWilly Tarreau 110a6a054c8SThomas Weißschuhheaders_check: headers_standalone 111f7c8bb6cSThomas Weißschuh $(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \ 112a6a054c8SThomas Weißschuh $(CC) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \ 113a6a054c8SThomas Weißschuh -I$(or $(objtree),$(srctree))/usr/include -include $$header -include $$header || exit 1; \ 114a6a054c8SThomas Weißschuh done 115a6a054c8SThomas Weißschuh 11624326164SWilly Tarreauclean: 11724326164SWilly Tarreau $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot" 118