selftests/nolibc: add a "defconfig" target
[linux-block.git] / tools / testing / selftests / nolibc / Makefile
CommitLineData
362aecb2
WT
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for nolibc tests
3include ../../../scripts/Makefile.include
4
5# we're in ".../tools/testing/selftests/nolibc"
6ifeq ($(srctree),)
7srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
8endif
9
10ifeq ($(ARCH),)
11include $(srctree)/scripts/subarch.include
12ARCH = $(SUBARCH)
13endif
14
d248cabf
WT
15# kernel image names by architecture
16IMAGE_i386 = arch/x86/boot/bzImage
17IMAGE_x86 = arch/x86/boot/bzImage
18IMAGE_arm64 = arch/arm64/boot/Image
19IMAGE_arm = arch/arm/boot/zImage
20IMAGE_mips = vmlinuz
21IMAGE_riscv = arch/riscv/boot/Image
22IMAGE = $(IMAGE_$(ARCH))
23IMAGE_NAME = $(notdir $(IMAGE))
24
5c43fd79
WT
25# default kernel configurations that appear to be usable
26DEFCONFIG_i386 = defconfig
27DEFCONFIG_x86 = defconfig
28DEFCONFIG_arm64 = defconfig
29DEFCONFIG_arm = multi_v7_defconfig
30DEFCONFIG_mips = malta_defconfig
31DEFCONFIG_riscv = defconfig
32DEFCONFIG = $(DEFCONFIG_$(ARCH))
33
362aecb2
WT
34# OUTPUT is only set when run from the main makefile, otherwise
35# it defaults to this nolibc directory.
36OUTPUT ?= $(CURDIR)/
37
38ifeq ($(V),1)
39Q=
40else
41Q=@
42endif
43
44CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables
45LDFLAGS := -s
46
47all: nolibc-test
48
49nolibc-test: nolibc-test.c
50 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
51 -nostdlib -static -include ../../../include/nolibc/nolibc.h $^ -lgcc
52
53initramfs: nolibc-test
54 $(QUIET_MKDIR)mkdir -p initramfs
55 $(call QUIET_INSTALL, initramfs/init)
56 $(Q)cp nolibc-test initramfs/init
57
5c43fd79
WT
58defconfig:
59 $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
60
d248cabf
WT
61kernel: initramfs
62 $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
63
362aecb2
WT
64clean:
65 $(call QUIET_CLEAN, nolibc-test)
66 $(Q)rm -f nolibc-test
67 $(call QUIET_CLEAN, initramfs)
68 $(Q)rm -rf initramfs