-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
91 lines (76 loc) · 1.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
CFLAGS += -Wall -Wextra -Werror -pedantic -Wno-unused-result
DEBUG_CFLAGS ?= -O0 -g -fsanitize=address,undefined,leak
RELEASE_CFLAGS ?= -O3 -flto -s
ifeq ($(DEBUG), 1)
CFLAGS += $(DEBUG_CFLAGS)
else
CFLAGS += $(RELEASE_CFLAGS)
endif
.PHONY: clean test strace ltrace qemu docker gdb valgrind firejail standalone
STRACE_EXISTS := $(shell command -v strace 2> /dev/null)
LTRACE_EXISTS := $(shell command -v ltrace 2> /dev/null)
QEMU_EXISTS := $(shell command -v qemu-x86_64 2> /dev/null)
DOCKER_EXISTS := $(shell command -v docker 2> /dev/null)
GDB_EXISTS := $(shell command -v gdb 2> /dev/null)
VALGRIND_EXISTS := $(shell command -v valgrind 2> /dev/null)
FIREJAIL_EXISTS := $(shell command -v firejail 2> /dev/null)
vmd: example.c vmd.h syscall.h
@$(CC) $(CFLAGS) -o $@ $<
strace:vmd
ifdef STRACE_EXISTS
@printf $@": "
@strace ./$< 2>/dev/null
else
@printf "Skipping test, strace not found\n"
endif
ltrace:vmd
ifdef LTRACE_EXISTS
@printf $@": "
@ltrace ./$< 2>/dev/null
else
@printf "Skipping test, ltrace not found\n"
endif
qemu: vmd
ifdef QEMU_EXISTS
@printf $@": "
@qemu-x86_64 -cpu max ./$<
else
@printf "Skipping test, qemu not found\n"
endif
docker: vmd
ifdef DOCKER_EXISTS
@printf $@": "
@docker build -qt $< .>/dev/null
@docker run -it $<
@docker rm -fv $$(docker stop $$(docker ps -a|fgrep $<|cut -d' ' -f1))>/dev/null
@-docker rmi -f $<>/dev/null
else
@printf "Skipping test, docker not found\n"
endif
gdb: vmd
ifdef GDB_EXISTS
@printf $@": "
@gdb -batch-silent -x gdbscript --args ./$< $(ARGS)
else
@printf "Skipping test, gdb not found\n"
endif
valgrind: vmd
ifdef VALGRIND_EXISTS
@printf $@": "
@valgrind ./$< 2>/dev/null
else
@printf "Skipping test, valgrind not found\n"
endif
firejail: vmd
ifdef FIREJAIL_EXISTS
@printf $@": "
@firejail ./$< 2>/dev/null
else
@printf "Skipping test, firejail not found\n"
endif
standalone: vmd
@printf $@": "
@./$<
test: vmd strace ltrace qemu docker gdb valgrind firejail standalone
clean: vmd
@-rm -vfr *~ $<