xref: /linux/tools/testing/selftests/nolibc/Makefile (revision 015a99fa76650e7d6efa3e36f20c0f5b346fe9ce)
1362aecb2SWilly Tarreau# SPDX-License-Identifier: GPL-2.0
2362aecb2SWilly Tarreau# Makefile for nolibc tests
31a1200b6SThomas Weißschuh# we're in ".../tools/testing/selftests/nolibc"
41a1200b6SThomas Weißschuhifeq ($(srctree),)
51a1200b6SThomas Weißschuhsrctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
61a1200b6SThomas Weißschuhendif
71a1200b6SThomas Weißschuh
81a1200b6SThomas Weißschuhinclude $(srctree)/tools/scripts/utilities.mak
91bd75aebSThomas Weißschuh# We need this for the "__cc-option" macro.
101bd75aebSThomas Weißschuhinclude $(srctree)/scripts/Makefile.compiler
11362aecb2SWilly Tarreau
1269620b3aSThomas Weißschuhifneq ($(O),)
1369620b3aSThomas Weißschuhifneq ($(call is-absolute,$(O)),y)
1469620b3aSThomas Weißschuh$(error Only absolute O= parameters are supported)
1569620b3aSThomas Weißschuhendif
16ae574ae3SThomas Weißschuhobjtree := $(O)
17ae574ae3SThomas Weißschuhelse
18ae574ae3SThomas Weißschuhobjtree ?= $(srctree)
1969620b3aSThomas Weißschuhendif
2069620b3aSThomas Weißschuh
21362aecb2SWilly Tarreauifeq ($(ARCH),)
22362aecb2SWilly Tarreauinclude $(srctree)/scripts/subarch.include
23362aecb2SWilly TarreauARCH = $(SUBARCH)
24362aecb2SWilly Tarreauendif
25362aecb2SWilly Tarreau
261bd75aebSThomas Weißschuhcc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
271bd75aebSThomas Weißschuh
28c6c3734fSZhangjin Wu# XARCH extends the kernel's ARCH with a few variants of the same
29c6c3734fSZhangjin Wu# architecture that only differ by the configuration, the toolchain
30c6c3734fSZhangjin Wu# and the Qemu program used. It is copied as-is into ARCH except for
31c6c3734fSZhangjin Wu# a few specific values which are mapped like this:
32c6c3734fSZhangjin Wu#
33c6c3734fSZhangjin Wu#  XARCH        | ARCH      | config
34c6c3734fSZhangjin Wu#  -------------|-----------|-------------------------
35c6c3734fSZhangjin Wu#  ppc          | powerpc   | 32 bits
36c6c3734fSZhangjin Wu#  ppc64        | powerpc   | 64 bits big endian
37c6c3734fSZhangjin Wu#  ppc64le      | powerpc   | 64 bits little endian
38c6c3734fSZhangjin Wu#
39c6c3734fSZhangjin Wu# It is recommended to only use XARCH, though it does not harm if
40c6c3734fSZhangjin Wu# ARCH is already set. For simplicity, ARCH is sufficient for all
41c6c3734fSZhangjin Wu# architectures where both are equal.
42c6c3734fSZhangjin Wu
43c6c3734fSZhangjin Wu# configure default variants for target kernel supported architectures
44587e9845SZhangjin WuXARCH_powerpc    = ppc
45c4c20a7dSThomas WeißschuhXARCH_mips       = mips32le
46a47b4b9fSThomas WeißschuhXARCH_riscv      = riscv64
47c6c3734fSZhangjin WuXARCH            = $(or $(XARCH_$(ARCH)),$(ARCH))
48c6c3734fSZhangjin Wu
49c6c3734fSZhangjin Wu# map from user input variants to their kernel supported architectures
50cb839e0cSThomas WeißschuhARCH_armthumb    = arm
51587e9845SZhangjin WuARCH_ppc         = powerpc
52faeb4e09SZhangjin WuARCH_ppc64       = powerpc
538a5040cbSZhangjin WuARCH_ppc64le     = powerpc
54c4c20a7dSThomas WeißschuhARCH_mips32le    = mips
55b4b9fb91SThomas WeißschuhARCH_mips32be    = mips
5660fe1823SThomas WeißschuhARCH_riscv32     = riscv
57a47b4b9fSThomas WeißschuhARCH_riscv64     = riscv
583d1e67c6SThomas WeißschuhARCH_s390x       = s390
598e193029SThomas WeißschuhARCH_sparc32     = sparc
608e193029SThomas WeißschuhARCH_sparc64     = sparc
61c6c3734fSZhangjin WuARCH            := $(or $(ARCH_$(XARCH)),$(XARCH))
62c6c3734fSZhangjin Wu
63d248cabfSWilly Tarreau# kernel image names by architecture
64d248cabfSWilly TarreauIMAGE_i386       = arch/x86/boot/bzImage
65f9b06695SWilly TarreauIMAGE_x86_64     = arch/x86/boot/bzImage
66d248cabfSWilly TarreauIMAGE_x86        = arch/x86/boot/bzImage
67d248cabfSWilly TarreauIMAGE_arm64      = arch/arm64/boot/Image
68d248cabfSWilly TarreauIMAGE_arm        = arch/arm/boot/zImage
69cb839e0cSThomas WeißschuhIMAGE_armthumb   = arch/arm/boot/zImage
70c4c20a7dSThomas WeißschuhIMAGE_mips32le   = vmlinuz
71b4b9fb91SThomas WeißschuhIMAGE_mips32be   = vmlinuz
72587e9845SZhangjin WuIMAGE_ppc        = vmlinux
73faeb4e09SZhangjin WuIMAGE_ppc64      = vmlinux
748a5040cbSZhangjin WuIMAGE_ppc64le    = arch/powerpc/boot/zImage
75d248cabfSWilly TarreauIMAGE_riscv      = arch/riscv/boot/Image
7660fe1823SThomas WeißschuhIMAGE_riscv32    = arch/riscv/boot/Image
77a47b4b9fSThomas WeißschuhIMAGE_riscv64    = arch/riscv/boot/Image
783d1e67c6SThomas WeißschuhIMAGE_s390x      = arch/s390/boot/bzImage
799c812b01SThomas WeißschuhIMAGE_s390       = arch/s390/boot/bzImage
806cd77defSFeiyang ChenIMAGE_loongarch  = arch/loongarch/boot/vmlinuz.efi
818e193029SThomas WeißschuhIMAGE_sparc32    = arch/sparc/boot/image
828e193029SThomas WeißschuhIMAGE_sparc64    = arch/sparc/boot/image
8366a4f9bbSDaniel PalmerIMAGE_m68k       = vmlinux
8469620b3aSThomas WeißschuhIMAGE            = $(objtree)/$(IMAGE_$(XARCH))
85d248cabfSWilly TarreauIMAGE_NAME       = $(notdir $(IMAGE))
86d248cabfSWilly Tarreau
875c43fd79SWilly Tarreau# default kernel configurations that appear to be usable
885c43fd79SWilly TarreauDEFCONFIG_i386       = defconfig
89f9b06695SWilly TarreauDEFCONFIG_x86_64     = defconfig
905c43fd79SWilly TarreauDEFCONFIG_x86        = defconfig
915c43fd79SWilly TarreauDEFCONFIG_arm64      = defconfig
925c43fd79SWilly TarreauDEFCONFIG_arm        = multi_v7_defconfig
93cb839e0cSThomas WeißschuhDEFCONFIG_armthumb   = multi_v7_defconfig
94c4c20a7dSThomas WeißschuhDEFCONFIG_mips32le   = malta_defconfig
95e16214dcSThomas WeißschuhDEFCONFIG_mips32be   = malta_defconfig generic/eb.config
96587e9845SZhangjin WuDEFCONFIG_ppc        = pmac32_defconfig
97faeb4e09SZhangjin WuDEFCONFIG_ppc64      = powernv_be_defconfig
988a5040cbSZhangjin WuDEFCONFIG_ppc64le    = powernv_defconfig
995c43fd79SWilly TarreauDEFCONFIG_riscv      = defconfig
10060fe1823SThomas WeißschuhDEFCONFIG_riscv32    = rv32_defconfig
101a47b4b9fSThomas WeißschuhDEFCONFIG_riscv64    = defconfig
1023d1e67c6SThomas WeißschuhDEFCONFIG_s390x      = defconfig
1039c812b01SThomas WeißschuhDEFCONFIG_s390       = defconfig compat.config
1046cd77defSFeiyang ChenDEFCONFIG_loongarch  = defconfig
1058e193029SThomas WeißschuhDEFCONFIG_sparc32    = sparc32_defconfig
1068e193029SThomas WeißschuhDEFCONFIG_sparc64    = sparc64_defconfig
10766a4f9bbSDaniel PalmerDEFCONFIG_m68k       = virt_defconfig
108c6c3734fSZhangjin WuDEFCONFIG            = $(DEFCONFIG_$(XARCH))
1095c43fd79SWilly Tarreau
11066a4f9bbSDaniel PalmerEXTRACONFIG_m68k      = -e CONFIG_BLK_DEV_INITRD
1113ab1e9dbSThomas WeißschuhEXTRACONFIG           = $(EXTRACONFIG_$(XARCH))
112*256dc733SThomas WeißschuhEXTRACONFIG_arm       = -e CONFIG_NAMESPACES
113*256dc733SThomas WeißschuhEXTRACONFIG_armthumb  = -e CONFIG_NAMESPACES
1143ab1e9dbSThomas Weißschuh
115662ea60eSWilly Tarreau# optional tests to run (default = all)
116662ea60eSWilly TarreauTEST =
117662ea60eSWilly Tarreau
118662ea60eSWilly Tarreau# QEMU_ARCH: arch names used by qemu
119662ea60eSWilly TarreauQEMU_ARCH_i386       = i386
120f9b06695SWilly TarreauQEMU_ARCH_x86_64     = x86_64
121662ea60eSWilly TarreauQEMU_ARCH_x86        = x86_64
122662ea60eSWilly TarreauQEMU_ARCH_arm64      = aarch64
123662ea60eSWilly TarreauQEMU_ARCH_arm        = arm
124cb839e0cSThomas WeißschuhQEMU_ARCH_armthumb   = arm
125c4c20a7dSThomas WeißschuhQEMU_ARCH_mips32le   = mipsel  # works with malta_defconfig
126b4b9fb91SThomas WeißschuhQEMU_ARCH_mips32be  = mips
127587e9845SZhangjin WuQEMU_ARCH_ppc        = ppc
128faeb4e09SZhangjin WuQEMU_ARCH_ppc64      = ppc64
12917362f3dSThomas WeißschuhQEMU_ARCH_ppc64le    = ppc64
130662ea60eSWilly TarreauQEMU_ARCH_riscv      = riscv64
13160fe1823SThomas WeißschuhQEMU_ARCH_riscv32    = riscv32
132a47b4b9fSThomas WeißschuhQEMU_ARCH_riscv64    = riscv64
1333d1e67c6SThomas WeißschuhQEMU_ARCH_s390x      = s390x
1349c812b01SThomas WeißschuhQEMU_ARCH_s390       = s390x
1356cd77defSFeiyang ChenQEMU_ARCH_loongarch  = loongarch64
1368e193029SThomas WeißschuhQEMU_ARCH_sparc32    = sparc
1378e193029SThomas WeißschuhQEMU_ARCH_sparc64    = sparc64
13866a4f9bbSDaniel PalmerQEMU_ARCH_m68k       = m68k
139c6c3734fSZhangjin WuQEMU_ARCH            = $(QEMU_ARCH_$(XARCH))
140662ea60eSWilly Tarreau
141d7233e2bSThomas WeißschuhQEMU_ARCH_USER_ppc64le = ppc64le
142d7233e2bSThomas WeißschuhQEMU_ARCH_USER         = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH_$(XARCH)))
143d7233e2bSThomas Weißschuh
144bdeeeabaSThomas WeißschuhQEMU_BIOS_DIR = /usr/share/edk2/
145bdeeeabaSThomas WeißschuhQEMU_BIOS_loongarch = $(QEMU_BIOS_DIR)/loongarch64/OVMF_CODE.fd
146bdeeeabaSThomas Weißschuh
147bdeeeabaSThomas Weißschuhifneq ($(QEMU_BIOS_$(XARCH)),)
148bdeeeabaSThomas WeißschuhQEMU_ARGS_BIOS = -bios $(QEMU_BIOS_$(XARCH))
149bdeeeabaSThomas Weißschuhendif
150bdeeeabaSThomas Weißschuh
151662ea60eSWilly Tarreau# QEMU_ARGS : some arch-specific args to pass to qemu
152662ea60eSWilly TarreauQEMU_ARGS_i386       = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
153f9b06695SWilly TarreauQEMU_ARGS_x86_64     = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
154662ea60eSWilly TarreauQEMU_ARGS_x86        = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
155662ea60eSWilly TarreauQEMU_ARGS_arm64      = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
156662ea60eSWilly TarreauQEMU_ARGS_arm        = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
157cb839e0cSThomas WeißschuhQEMU_ARGS_armthumb   = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
158c4c20a7dSThomas WeißschuhQEMU_ARGS_mips32le   = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
159b4b9fb91SThomas WeißschuhQEMU_ARGS_mips32be   = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
160587e9845SZhangjin WuQEMU_ARGS_ppc        = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
161faeb4e09SZhangjin WuQEMU_ARGS_ppc64      = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1628a5040cbSZhangjin WuQEMU_ARGS_ppc64le    = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
163662ea60eSWilly TarreauQEMU_ARGS_riscv      = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
16460fe1823SThomas WeißschuhQEMU_ARGS_riscv32    = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
165a47b4b9fSThomas WeißschuhQEMU_ARGS_riscv64    = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1663d1e67c6SThomas WeißschuhQEMU_ARGS_s390x      = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1679c812b01SThomas WeißschuhQEMU_ARGS_s390       = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1686cd77defSFeiyang ChenQEMU_ARGS_loongarch  = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1698e193029SThomas WeißschuhQEMU_ARGS_sparc32    = -M SS-5 -m 256M -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1708e193029SThomas WeißschuhQEMU_ARGS_sparc64    = -M sun4u -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
17166a4f9bbSDaniel PalmerQEMU_ARGS_m68k       = -M virt -append "console=ttyGF0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
172ad0558f3SThomas WeißschuhQEMU_ARGS            = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
173662ea60eSWilly Tarreau
174362aecb2SWilly Tarreau# OUTPUT is only set when run from the main makefile, otherwise
175362aecb2SWilly Tarreau# it defaults to this nolibc directory.
176362aecb2SWilly TarreauOUTPUT ?= $(CURDIR)/
177362aecb2SWilly Tarreau
178362aecb2SWilly Tarreauifeq ($(V),1)
179362aecb2SWilly TarreauQ=
180362aecb2SWilly Tarreauelse
181362aecb2SWilly TarreauQ=@
182362aecb2SWilly Tarreauendif
183362aecb2SWilly Tarreau
18495315486SThomas WeißschuhCFLAGS_i386 = $(call cc-option,-m32)
185f8bedb30SThomas WeißschuhCFLAGS_arm = -marm
186cb839e0cSThomas WeißschuhCFLAGS_armthumb = -mthumb -march=armv6t2
187587e9845SZhangjin WuCFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
188faeb4e09SZhangjin WuCFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
1898a5040cbSZhangjin WuCFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
1903d1e67c6SThomas WeißschuhCFLAGS_s390x = -m64
1919c812b01SThomas WeißschuhCFLAGS_s390 = -m31
19254410245SThomas WeißschuhCFLAGS_mips32le = -EL -mabi=32 -fPIC
193b4b9fb91SThomas WeißschuhCFLAGS_mips32be = -EB -mabi=32
1948e193029SThomas WeißschuhCFLAGS_sparc32 = $(call cc-option,-m32)
195fd293cb8SThomas Weißschuhifeq ($(origin XARCH),command line)
196fd293cb8SThomas WeißschuhCFLAGS_XARCH = $(CFLAGS_$(XARCH))
197fd293cb8SThomas Weißschuhendif
1980093c2daSThomas WeißschuhCFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
1998509b5c9SThomas WeißschuhCFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all)
20045f65f8dSThomas WeißschuhCFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
2014da4e35eSThomas Weißschuh		$(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \
2028509b5c9SThomas Weißschuh		$(CFLAGS_XARCH) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_SANITIZER) $(CFLAGS_EXTRA)
203711edef8SThomas WeißschuhLDFLAGS :=
204362aecb2SWilly Tarreau
205801cf69cSThomas WeißschuhLIBGCC := -lgcc
206801cf69cSThomas Weißschuh
207801cf69cSThomas Weißschuhifneq ($(LLVM),)
208801cf69cSThomas Weißschuh# Not needed for clang
209801cf69cSThomas WeißschuhLIBGCC :=
210801cf69cSThomas Weißschuhendif
211801cf69cSThomas Weißschuh
212ae574ae3SThomas Weißschuh# Modify CFLAGS based on LLVM=
213ae574ae3SThomas Weißschuhinclude $(srctree)/tools/scripts/Makefile.include
214ae574ae3SThomas Weißschuh
2158404af7eSThomas Weißschuh# GCC uses "s390", clang "systemz"
2168404af7eSThomas WeißschuhCLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
2178404af7eSThomas Weißschuh
2184beb9be8SZhangjin WuREPORT  ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
2197d92e893SZhangjin Wu		END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \
220ddae1d7fSThomas Weißschuh		if (f || !p) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \
2217d92e893SZhangjin Wu		printf("\nSee all results in %s\n", ARGV[1]); }'
2225ef95663SZhangjin Wu
223ffc297feSWilly Tarreauhelp:
224ffc297feSWilly Tarreau	@echo "Supported targets under selftests/nolibc:"
225ffc297feSWilly Tarreau	@echo "  all               call the \"run\" target below"
226ffc297feSWilly Tarreau	@echo "  help              this help"
227ffc297feSWilly Tarreau	@echo "  sysroot           create the nolibc sysroot here (uses \$$ARCH)"
228ffc297feSWilly Tarreau	@echo "  nolibc-test       build the executable (uses \$$CC and \$$CROSS_COMPILE)"
229fc82d7dbSThomas Weißschuh	@echo "  libc-test         build an executable using the compiler's default libc instead"
230c6c3734fSZhangjin Wu	@echo "  run-user          runs the executable under QEMU (uses \$$XARCH, \$$TEST)"
23145839d09SThomas Weißschuh	@echo "  initramfs.cpio    prepare the initramfs archive with nolibc-test"
23245839d09SThomas Weißschuh	@echo "  initramfs         prepare the initramfs tree with nolibc-test"
233c6c3734fSZhangjin Wu	@echo "  defconfig         create a fresh new default config (uses \$$XARCH)"
23445839d09SThomas Weißschuh	@echo "  kernel            (re)build the kernel (uses \$$XARCH)"
23545839d09SThomas Weißschuh	@echo "  kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH)"
236c6c3734fSZhangjin Wu	@echo "  run               runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)"
237c6c3734fSZhangjin Wu	@echo "  rerun             runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)"
238ffc297feSWilly Tarreau	@echo "  clean             clean the sysroot, initramfs, build and output files"
239ffc297feSWilly Tarreau	@echo ""
240ffc297feSWilly Tarreau	@echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST."
241ffc297feSWilly Tarreau	@echo ""
242ffc297feSWilly Tarreau	@echo "Currently using the following variables:"
243ffc297feSWilly Tarreau	@echo "  ARCH          = $(ARCH)"
244c6c3734fSZhangjin Wu	@echo "  XARCH         = $(XARCH)"
245ffc297feSWilly Tarreau	@echo "  CROSS_COMPILE = $(CROSS_COMPILE)"
246ffc297feSWilly Tarreau	@echo "  CC            = $(CC)"
247ffc297feSWilly Tarreau	@echo "  OUTPUT        = $(OUTPUT)"
248ffc297feSWilly Tarreau	@echo "  TEST          = $(TEST)"
249c6c3734fSZhangjin Wu	@echo "  QEMU_ARCH     = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from \$$XARCH]"
250c6c3734fSZhangjin Wu	@echo "  IMAGE_NAME    = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from \$$XARCH]"
251ffc297feSWilly Tarreau	@echo ""
252ffc297feSWilly Tarreau
253ffc297feSWilly Tarreauall: run
254362aecb2SWilly Tarreau
255b25c5284SWilly Tarreausysroot: sysroot/$(ARCH)/include
256b25c5284SWilly Tarreau
257cdbf0f19SThomas Weißschuhsysroot/$(ARCH)/include:
2584a95be7eSWilly Tarreau	$(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot
259b25c5284SWilly Tarreau	$(QUIET_MKDIR)mkdir -p sysroot
26069620b3aSThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) outputmakefile
261443c6467SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone headers_check
262b25c5284SWilly Tarreau	$(Q)mv sysroot/sysroot sysroot/$(ARCH)
263b25c5284SWilly Tarreau
264850fad7dSZhangjin Wuifneq ($(NOLIBC_SYSROOT),0)
265b8c60e8fSThomas Weißschuhnolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
266362aecb2SWilly Tarreau	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
267801cf69cSThomas Weißschuh	  -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
268850fad7dSZhangjin Wuelse
269b8c60e8fSThomas Weißschuhnolibc-test: nolibc-test.c nolibc-test-linkage.c
270850fad7dSZhangjin Wu	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
271801cf69cSThomas Weißschuh	  -nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
272850fad7dSZhangjin Wuendif
273362aecb2SWilly Tarreau
274b8c60e8fSThomas Weißschuhlibc-test: nolibc-test.c nolibc-test-linkage.c
275b8c60e8fSThomas Weißschuh	$(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c
276fc82d7dbSThomas Weißschuh
277b8143407SZhangjin Wu# local libc-test
278cfb672f9SZhangjin Wurun-libc-test: libc-test
279cfb672f9SZhangjin Wu	$(Q)./libc-test > "$(CURDIR)/run.out" || :
280cfb672f9SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
281cfb672f9SZhangjin Wu
282b8143407SZhangjin Wu# local nolibc-test
283b8143407SZhangjin Wurun-nolibc-test: nolibc-test
284b8143407SZhangjin Wu	$(Q)./nolibc-test > "$(CURDIR)/run.out" || :
285b8143407SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
286b8143407SZhangjin Wu
287c54ba417SWilly Tarreau# qemu user-land test
288c54ba417SWilly Tarreaurun-user: nolibc-test
289d7233e2bSThomas Weißschuh	$(Q)qemu-$(QEMU_ARCH_USER) ./nolibc-test > "$(CURDIR)/run.out" || :
2905ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
291c54ba417SWilly Tarreau
29245839d09SThomas Weißschuhinitramfs.cpio: kernel nolibc-test
29369620b3aSThomas Weißschuh	$(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/usr/gen_init_cpio - > initramfs.cpio
29445839d09SThomas Weißschuh
295362aecb2SWilly Tarreauinitramfs: nolibc-test
296362aecb2SWilly Tarreau	$(QUIET_MKDIR)mkdir -p initramfs
297362aecb2SWilly Tarreau	$(call QUIET_INSTALL, initramfs/init)
298362aecb2SWilly Tarreau	$(Q)cp nolibc-test initramfs/init
299362aecb2SWilly Tarreau
3005c43fd79SWilly Tarreaudefconfig:
30125d5ef9eSThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(DEFCONFIG)
3023ab1e9dbSThomas Weißschuh	$(Q)if [ -n "$(EXTRACONFIG)" ]; then \
3033ab1e9dbSThomas Weißschuh		$(srctree)/scripts/config --file $(objtree)/.config $(EXTRACONFIG); \
3043ab1e9dbSThomas Weißschuh		$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig < /dev/null; \
3053ab1e9dbSThomas Weißschuh	fi
3065c43fd79SWilly Tarreau
307d7d271ecSThomas Weißschuhkernel: | defconfig
30889b212d4SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) < /dev/null
30945839d09SThomas Weißschuh
310d7d271ecSThomas Weißschuhkernel-standalone: initramfs | defconfig
31189b212d4SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null
312d248cabfSWilly Tarreau
313662ea60eSWilly Tarreau# run the tests after building the kernel
31445839d09SThomas Weißschuhrun: kernel initramfs.cpio
31569620b3aSThomas Weißschuh	$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
3165ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
317662ea60eSWilly Tarreau
318662ea60eSWilly Tarreau# re-run the tests from an existing kernel
319662ea60eSWilly Tarreaurerun:
32069620b3aSThomas Weißschuh	$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
3215ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
322662ea60eSWilly Tarreau
323ce1bb82bSZhangjin Wu# report with existing test log
324ce1bb82bSZhangjin Wureport:
325ce1bb82bSZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
326ce1bb82bSZhangjin Wu
327362aecb2SWilly Tarreauclean:
328b25c5284SWilly Tarreau	$(call QUIET_CLEAN, sysroot)
329b25c5284SWilly Tarreau	$(Q)rm -rf sysroot
330362aecb2SWilly Tarreau	$(call QUIET_CLEAN, nolibc-test)
331362aecb2SWilly Tarreau	$(Q)rm -f nolibc-test
332fc82d7dbSThomas Weißschuh	$(call QUIET_CLEAN, libc-test)
333fc82d7dbSThomas Weißschuh	$(Q)rm -f libc-test
33445839d09SThomas Weißschuh	$(call QUIET_CLEAN, initramfs.cpio)
33545839d09SThomas Weißschuh	$(Q)rm -rf initramfs.cpio
336362aecb2SWilly Tarreau	$(call QUIET_CLEAN, initramfs)
337362aecb2SWilly Tarreau	$(Q)rm -rf initramfs
338662ea60eSWilly Tarreau	$(call QUIET_CLEAN, run.out)
339662ea60eSWilly Tarreau	$(Q)rm -rf run.out
3404a95be7eSWilly Tarreau
3414a95be7eSWilly Tarreau.PHONY: sysroot/$(ARCH)/include
342