xref: /openbmc/linux/tools/testing/selftests/exec/Makefile (revision 6f6249a599e52e1a5f0b632f8edff733cfa76450)
1# SPDX-License-Identifier: GPL-2.0
2CFLAGS = -Wall
3CFLAGS += -Wno-nonnull
4CFLAGS += -D_GNU_SOURCE
5
6ALIGNS := 0x1000 0x200000 0x1000000
7ALIGN_PIES        := $(patsubst %,load_address.%,$(ALIGNS))
8ALIGN_STATIC_PIES := $(patsubst %,load_address.static.%,$(ALIGNS))
9ALIGNMENT_TESTS   := $(ALIGN_PIES) $(ALIGN_STATIC_PIES)
10
11TEST_PROGS := binfmt_script.py
12TEST_GEN_PROGS := execveat non-regular $(ALIGNMENT_TESTS)
13TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
14# Makefile is a run-time dependency, since it's accessed by the execveat test
15TEST_FILES := Makefile
16
17TEST_GEN_PROGS += recursion-depth
18TEST_GEN_PROGS += null-argv
19
20EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/xxxxx*	\
21	       $(OUTPUT)/S_I*.test
22
23include ../lib.mk
24
25$(OUTPUT)/subdir:
26	mkdir -p $@
27$(OUTPUT)/script:
28	echo '#!/bin/sh' > $@
29	echo 'exit $$*' >> $@
30	chmod +x $@
31$(OUTPUT)/execveat.symlink: $(OUTPUT)/execveat
32	cd $(OUTPUT) && ln -s -f $(shell basename $<) $(shell basename $@)
33$(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
34	cp $< $@
35	chmod -x $@
36$(OUTPUT)/load_address.0x%: load_address.c
37	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=$(lastword $(subst ., ,$@)) \
38		-fPIE -pie $< -o $@
39$(OUTPUT)/load_address.static.0x%: load_address.c
40	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=$(lastword $(subst ., ,$@)) \
41		-fPIE -static-pie $< -o $@
42