-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (73 loc) · 3.51 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
PROJECT := shook
GIT_COMMIT := $(shell git describe --abbrev=0 --dirty --always --tags)
BUILD_DATE := $(shell date '+%Y%m%d-%H%M%S')
TARGET_ARCH := x86_64
TARGET_PROJECT_CFLAGS := -g -Wall -Werror -DPROJECT=$(PROJECT) -DTARGET_ARCH_$(TARGET_ARCH)=1
TARGET_PROJECT_LDFLAGS :=
ifeq ($(ASAN), 1)
TARGET_PROJECT_CFLAGS += -fsanitize=address
TARGET_PROJECT_LDFLAGS += -fsanitize=address
endif
ifeq ($(OPT), 1)
TARGET_PROJECT_CFLAGS += -O2
TARGET_PROJECT_LDFLAGS +=
endif
TARGET_CFLAGS = $(TARGET_PROJECT_CFLAGS) -Wstrict-prototypes -MT $@ -MMD -MP -MF $@.d
TARGET_CXXFLAGS = $(TARGET_PROJECT_CFLAGS) -Wmissing-declarations -std=c++11 -MT $@ -MMD -MP -MF $@.d
TARGET_LDFLAGS = $(TARGET_PROJECT_LDFLAGS)
TARGET_CC = gcc
TARGET_CXX = g++
TARGET_PYTHON_CFLAGS := $(shell pkg-config --cflags python3)
TARGET_PYTHON_LDFLAGS := $(shell pkg-config --libs python3)
TARGET_DIR_out := target.dbg.linux.$(TARGET_ARCH)
TARGET_SET_dir := bin src tests share/shook/scripts
.PHONY: all target_mkdir
TARGET_SET_tests := time getifaddrs thread signal sockaddr
TARGET_SET_scripts := shook_utils stracer netlink
TARGET_SET_lib :=
TARGET_CFLAGS_EXTRA := \
-D__X_DEVELOPER__=1
all: $(TARGET_DIR_out)/bin/$(PROJECT) \
$(TARGET_SET_tests:%=$(TARGET_DIR_out)/tests/%) \
$(TARGET_SET_scripts:%=$(TARGET_DIR_out)/share/shook/scripts/%.py)
TARGET_SET_src := main version vdso \
python syscallent log timerq utils \
$(TARGET_DIR_out)/bin/$(PROJECT): $(TARGET_SET_src:%=$(TARGET_DIR_out)/src/%.o) $(TARGET_SET_lib:%=$(TARGET_DIR_out)/lib%.a)
$(TARGET_CXX) -g $(TARGET_LDFLAGS) -o $@ $^ $(TARGET_PYTHON_LDFLAGS) -lunwind-x86_64 -lunwind-ptrace
$(TARGET_DIR_out)/src/version.o: src/version.cxx
$(TARGET_CXX) -c $(TARGET_CXXFLAGS) $(TARGET_PYTHON_CFLAGS) -DGIT_COMMIT=\"$(GIT_COMMIT)\" -DBUILD_DATE=\"$(BUILD_DATE)\" -DBUILD_ARCH=\"$(TARGET_ARCH)\" -o $@ $<
$(TARGET_DIR_out)/src/version.o: $(TARGET_SET_src:%=src/%.cxx)
$(TARGET_DIR_out)/src/%.o: src/%.cxx | target_mkdir
$(TARGET_CXX) -c $(TARGET_CXXFLAGS) $(TARGET_PYTHON_CFLAGS) -o $@ $<
$(TARGET_SET_src:%=$(TARGET_DIR_out)/src/%.o): Makefile
$(TARGET_SET_tests:%=$(TARGET_DIR_out)/tests/%) : %: %.o $(TARGET_SET_lib:%=$(TARGET_DIR_out)/lib%.a) | target_mkdir
$(TARGET_CXX) -g $(TARGET_LDFLAGS) -o $@ $^ -lpthread -lresolv -ldl
$(TARGET_DIR_out)/tests/%.o: tests/%.cxx | target_mkdir
$(TARGET_CXX) -c $(TARGET_CXXFLAGS) $(TARGET_CFLAGS_EXTRA) -o $@ $<
TARGET_DEPFILES := $(TARGET_SET_tests:%=$(TARGET_DIR_out)/tests/%.o.d) $(TARGET_SET_src:%=$(TARGET_DIR_out)/src/%.o.d)
$(TARGET_DIR_out)/share/shook/scripts/%.py: scripts/%.py | target_mkdir
install -m 644 $< $(TARGET_DIR_out)/share/shook/scripts
include $(wildcard $(TARGET_DEPFILES))
target_mkdir: $(TARGET_SET_dir:%=$(TARGET_DIR_out)/%)
$(TARGET_SET_dir:%=$(TARGET_DIR_out)/%): %:
mkdir -p $@
.PHONY:
clean:
rm -rf $(TARGET_DIR_out)
define install_files
@echo "install files to $(1)"
install -d $(1)/bin/ $(1)/share/shook/scripts
install -m 755 $(TARGET_DIR_out)/bin/shook $(1)/bin/
install -m 644 $(TARGET_SET_scripts:%=scripts/%.py) $(1)/share/shook/scripts
endef
DESTDIR ?= /usr/local
install: all
$(call install_files,$(DESTDIR))
tarball: $(TARGET_DIR_out)/shook.tar.gz
$(TARGET_DIR_out)/shook.tar.gz: $(TARGET_DIR_out)/bin/$(PROJECT) $(TARGET_SET_scripts:%=$(TARGET_DIR_out)/share/shook/scripts/%.py)
tar czf $(TARGET_DIR_out)/shook.tar.gz -C $(TARGET_DIR_out) bin share
test:
./tests/run-tests $(TARGET_DIR_out)
test: $(TARGET_DIR_out)/bin/$(PROJECT) $(TARGET_SET_scripts:%=$(TARGET_DIR_out)/share/shook/scripts/%.py)