forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (153 loc) · 6.53 KB
/
Makefile
File metadata and controls
197 lines (153 loc) · 6.53 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Do not use make's built-in rules
# (this improves performance and avoids hard-to-debug behaviour);
# also do not print "Entering directory..." messages from make
.SUFFIXES:
MAKEFLAGS += -r --no-print-directory
KCONFIG?=defconfig
ifneq ($(silent),1)
ifneq ($(V),1)
QUIET_AUTOCONF = @echo ' AUTOCONF '$@;
Q = @
endif
endif
PREFIX := /usr
BINDIR := $(PREFIX)/bin
INCDIR := $(PREFIX)/include
LIBDIR := $(PREFIX)/lib
ifeq (,$(srctree))
srctree := $(patsubst %/,%,$(dir $(shell pwd)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif
export srctree
include ../scripts/Makefile.include
# OUTPUT fixup should be *after* include ../scripts/Makefile.include
ifneq ($(OUTPUT),)
KERNEL_OUT_DIR := $(OUTPUT)
KOPT += O=$(KERNEL_OUT_DIR)
OUTPUT := $(OUTPUT)/tools/lkl/
else
OUTPUT := $(CURDIR)/
endif
export OUTPUT
all:
conf: $(OUTPUT)Makefile.conf
$(OUTPUT)Makefile.conf $(OUTPUT)/kernel.config: Makefile.autoconf
$(call QUIET_AUTOCONF, headers)$(MAKE) -f Makefile.autoconf -s
include $(OUTPUT)Makefile.conf
export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra \
-Wno-unused-parameter \
-Wno-missing-field-initializers -fno-strict-aliasing
include Targets
TARGETS := $(progs-y:%=$(OUTPUT)%$(EXESUF))
TARGETS := $(tests-y:%=$(OUTPUT)%$(EXESUF))
TARGETS += $(libs-y:%=$(OUTPUT)%$(SOSUF))
all: $(TARGETS)
# this workaround is for FreeBSD
bin/stat:
ifeq ($(LKL_HOST_CONFIG_BSD),y)
$(Q)ln -sf `which gnustat` bin/stat
$(Q)ln -sf `which gsed` bin/sed
else
$(Q)touch bin/stat
endif
DOT_CONFIG:=$(OUTPUT)../../.config
$(DOT_CONFIG): $(OUTPUT)/kernel.config
$(Q)$(MAKE) -C ../.. ARCH=lkl $(KOPT) $(KCONFIG)
$(call QUIET_INSTALL, kernel.config)cat $(OUTPUT)/kernel.config >> $(DOT_CONFIG)
$(Q)$(MAKE) -C ../.. ARCH=lkl $(KOPT) olddefconfig
$(Q)$(MAKE) -C ../.. ARCH=lkl $(KOPT) syncconfig
# rule to build lkl.o
$(OUTPUT)lib/lkl.o: bin/stat $(DOT_CONFIG)
# this workaround is for arm32 linker (ld.gold)
$(Q)export PATH="$(srctree)/tools/lkl/bin/:${PATH}" ;\
$(MAKE) -C ../.. ARCH=lkl $(KOPT)
$(MAKE) -C ../.. ARCH=lkl $(KOPT) install INSTALL_PATH=$(OUTPUT)
# rules to link hijack libs
$(OUTPUT)%$(SOSUF): LDFLAGS += -shared
$(OUTPUT)%$(SOSUF): $(priv-libs-y:%=$(OUTPUT)%-in.o) $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)
# liblkl is special
$(OUTPUT)lib/liblkl$(SOSUF): $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)
$(OUTPUT)liblkl.a: $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o
$(QUIET_AR)$(AR) -rc $@ $^
# rule to link programs
$(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)
# tests use a common private lib
$(tests-y:%=$(OUTPUT)%$(EXESUF)): $(tests-priv-y:%=$(OUTPUT)%-in.o)
# rule to build objects
$(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*)
$(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF)
$(Q)if ! [ -e $@ ]; then ln -s $< $@; fi
# START: fuzzing-related build-rules
FUZZ_TARGETS := $(fuzzers-y:%=$(OUTPUT)%$(EXESUF))
fuzzers: $(FUZZ_TARGETS)
# Enable libFuzzer fuzzing instrumentation for the LKL fuzzers
$(OUTPUT)fuzzers/%$(EXESUF): LDFLAGS += -fsanitize=fuzzer --coverage
# Binder fuzzer is special: built with C++ toolchain and linked with libprotobuf-mutator
$(OUTPUT)fuzzers/binder%$(EXESUF): $(OUTPUT)fuzzers/binder%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CXX) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)
# Track all the protoc generated files for 'clean' target
PROTOC_GENERATED_FILES :=
read_proto_deps = \
$(strip $(shell grep PROTOBUF_MUTATOR_PROTO $(1) | sed 's/^.*= //g'))
define gen_protobuf_deps =
$(eval FUZZER_SRC_DIR := $(dir $(srctree)/tools/lkl/$(1)))
$(eval FUZZER_PROTO_FILES := $(call read_proto_deps,$(FUZZER_SRC_DIR)Build))
$(eval FUZZER_PROTO_FILES := $(FUZZER_PROTO_FILES:.proto=.pb.cpp) \
$(FUZZER_PROTO_FILES:.proto=.pb.h))
$(eval FUZZER_PROTO_FILES := \
$(addprefix $(FUZZER_SRC_DIR),$(FUZZER_PROTO_FILES)))
PROTOC_GENERATED_FILES += $(FUZZER_PROTO_FILES)
$(OUTPUT)$(1)-in.o: $(FUZZER_PROTO_FILES)
endef
# Add generated .pb.cc and pb.h files for libprotobuf-mutator as prerequisites
# for the corresponding fuzz targets to have them made using the rule below.
$(foreach fuzzer,$(fuzzers-y),$(eval $(call gen_protobuf_deps,$(fuzzer))))
# TODO: Cannot depend on the corresponding $(srctree)/tools/lkl/%.proto file
# due to the pattern rule
# '$(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a' above. For POSIX
# target $(EXESUF) is an empty string, thus, target $(OUTPUT)%$(EXESUF) would
# match any source file and will try to make it.
# Update once https://github.com/lkl/linux/issues/573 is fixed.
$(srctree)/tools/lkl/%.pb.cpp $(srctree)/tools/lkl/%.pb.h&: FORCE
$(PROTOC_PATH) --cpp_out=$(@D) --proto_path=$(@D) $(@F:pb.cpp=proto)
mv $(@:.cpp=.cc) $@
# END: fuzzing-related build-rules
clean:
$(call QUIET_CLEAN, vmlinux)$(MAKE) -C ../.. ARCH=lkl $(KOPT) clean
$(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\
-delete -o -name '\.*.d' -delete
$(call QUIET_CLEAN, headers)$(RM) -r $(OUTPUT)/include/lkl/
$(call QUIET_CLEAN, liblkl.a)$(RM) $(OUTPUT)/liblkl.a
$(call QUIET_CLEAN, targets)$(RM) $(TARGETS) $(FUZZ_TARGETS) bin/stat
$(call QUIET_CLEAN, gen_protos)$(RM) $(PROTOC_GENERATED_FILES)
mrproper: clean
$(call QUIET_CLEAN, vmlinux)$(MAKE) -C ../.. ARCH=lkl $(KOPT) mrproper
clean-conf: mrproper
$(call QUIET_CLEAN, Makefile.conf)$(RM) $(OUTPUT)/Makefile.conf
$(call QUIET_CLEAN, kernel.config)$(RM) $(OUTPUT)/kernel.config
headers_install: $(TARGETS)
$(call QUIET_INSTALL, headers) \
install -d $(DESTDIR)$(INCDIR) ; \
install -m 644 include/lkl.h include/lkl_host.h $(OUTPUT)include/lkl_autoconf.h \
include/lkl_config.h $(DESTDIR)$(INCDIR) ; \
cp -r $(OUTPUT)include/lkl $(DESTDIR)$(INCDIR)
libraries_install: $(libs-y:%=$(OUTPUT)%$(SOSUF)) $(OUTPUT)liblkl.a
$(call QUIET_INSTALL, libraries) \
install -d $(DESTDIR)$(LIBDIR) ; \
install -m 644 $^ $(DESTDIR)$(LIBDIR)
programs_install: $(progs-y:%=$(OUTPUT)%$(EXESUF))
$(call QUIET_INSTALL, programs) \
install -d $(DESTDIR)$(BINDIR) ; \
install -m 755 $^ $(DESTDIR)$(BINDIR)
install: headers_install libraries_install programs_install
run-tests:
./tests/run.py $(tests)
FORCE: ;
.PHONY: all clean clean-conf mrproper FORCE run-tests
.PHONY: headers_install libraries_install programs_install install
.NOTPARALLEL : lib/lkl.o
.SECONDARY: