selftests/nolibc: add basic infrastructure to ease creation of nolibc tests
[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
15# OUTPUT is only set when run from the main makefile, otherwise
16# it defaults to this nolibc directory.
17OUTPUT ?= $(CURDIR)/
18
19ifeq ($(V),1)
20Q=
21else
22Q=@
23endif
24
25CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables
26LDFLAGS := -s
27
28all: nolibc-test
29
30nolibc-test: nolibc-test.c
31 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
32 -nostdlib -static -include ../../../include/nolibc/nolibc.h $^ -lgcc
33
34initramfs: nolibc-test
35 $(QUIET_MKDIR)mkdir -p initramfs
36 $(call QUIET_INSTALL, initramfs/init)
37 $(Q)cp nolibc-test initramfs/init
38
39clean:
40 $(call QUIET_CLEAN, nolibc-test)
41 $(Q)rm -f nolibc-test
42 $(call QUIET_CLEAN, initramfs)
43 $(Q)rm -rf initramfs