Makefile 7.8 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9 10 11 12 13 14 15
FILES=                                          \
         test-all.bin                           \
         test-backtrace.bin                     \
         test-bionic.bin                        \
         test-dwarf.bin                         \
         test-dwarf_getlocations.bin            \
         test-fortify-source.bin                \
         test-sync-compare-and-swap.bin         \
         test-glibc.bin                         \
         test-gtk2.bin                          \
         test-gtk2-infobar.bin                  \
         test-hello.bin                         \
         test-libaudit.bin                      \
         test-libbfd.bin                        \
16
         test-disassembler-four-args.bin        \
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
         test-liberty.bin                       \
         test-liberty-z.bin                     \
         test-cplus-demangle.bin                \
         test-libelf.bin                        \
         test-libelf-getphdrnum.bin             \
         test-libelf-gelf_getnote.bin           \
         test-libelf-getshdrstrndx.bin          \
         test-libelf-mmap.bin                   \
         test-libnuma.bin                       \
         test-numa_num_possible_cpus.bin        \
         test-libperl.bin                       \
         test-libpython.bin                     \
         test-libpython-version.bin             \
         test-libslang.bin                      \
         test-libcrypto.bin                     \
         test-libunwind.bin                     \
         test-libunwind-debug-frame.bin         \
         test-libunwind-x86.bin                 \
         test-libunwind-x86_64.bin              \
         test-libunwind-arm.bin                 \
         test-libunwind-aarch64.bin             \
         test-libunwind-debug-frame-arm.bin     \
         test-libunwind-debug-frame-aarch64.bin \
         test-pthread-attr-setaffinity-np.bin   \
         test-stackprotector-all.bin            \
         test-timerfd.bin                       \
         test-libdw-dwarf-unwind.bin            \
         test-libbabeltrace.bin                 \
         test-compile-32.bin                    \
         test-compile-x32.bin                   \
         test-zlib.bin                          \
         test-lzma.bin                          \
         test-bpf.bin                           \
         test-get_cpuid.bin                     \
         test-sdt.bin                           \
         test-cxx.bin                           \
53
         test-jvmti.bin				\
54 55
         test-sched_getcpu.bin			\
         test-setns.bin
56

57 58
FILES := $(addprefix $(OUTPUT),$(FILES))

59 60 61
CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
62
LLVM_CONFIG ?= llvm-config
63

64 65
all: $(FILES)

66
__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
67
  BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
68

69
__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
70 71
  BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1

72 73
###############################

74
$(OUTPUT)test-all.bin:
75
	$(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma
76

77
$(OUTPUT)test-hello.bin:
78 79
	$(BUILD)

80
$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
81
	$(BUILD) -D_GNU_SOURCE -lpthread
82

83
$(OUTPUT)test-stackprotector-all.bin:
84
	$(BUILD) -fstack-protector-all
85

86
$(OUTPUT)test-fortify-source.bin:
87
	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
88

89
$(OUTPUT)test-bionic.bin:
90 91
	$(BUILD)

92
$(OUTPUT)test-libelf.bin:
93 94
	$(BUILD) -lelf

95
$(OUTPUT)test-glibc.bin:
96 97
	$(BUILD)

98 99 100
$(OUTPUT)test-sched_getcpu.bin:
	$(BUILD)

101 102 103
$(OUTPUT)test-setns.bin:
	$(BUILD)

104 105 106 107 108
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
endif

109
$(OUTPUT)test-dwarf.bin:
110
	$(BUILD) $(DWARFLIBS)
111

112 113 114
$(OUTPUT)test-dwarf_getlocations.bin:
	$(BUILD) $(DWARFLIBS)

115
$(OUTPUT)test-libelf-mmap.bin:
116 117
	$(BUILD) -lelf

118
$(OUTPUT)test-libelf-getphdrnum.bin:
119 120
	$(BUILD) -lelf

121 122 123
$(OUTPUT)test-libelf-gelf_getnote.bin:
	$(BUILD) -lelf

124 125 126
$(OUTPUT)test-libelf-getshdrstrndx.bin:
	$(BUILD) -lelf

127
$(OUTPUT)test-libnuma.bin:
128 129
	$(BUILD) -lnuma

130
$(OUTPUT)test-numa_num_possible_cpus.bin:
131 132
	$(BUILD) -lnuma

133
$(OUTPUT)test-libunwind.bin:
134
	$(BUILD) -lelf
135

136
$(OUTPUT)test-libunwind-debug-frame.bin:
137
	$(BUILD) -lelf
138 139 140 141 142 143 144 145 146 147 148 149
$(OUTPUT)test-libunwind-x86.bin:
	$(BUILD) -lelf -lunwind-x86

$(OUTPUT)test-libunwind-x86_64.bin:
	$(BUILD) -lelf -lunwind-x86_64

$(OUTPUT)test-libunwind-arm.bin:
	$(BUILD) -lelf -lunwind-arm

$(OUTPUT)test-libunwind-aarch64.bin:
	$(BUILD) -lelf -lunwind-aarch64

150 151 152 153 154
$(OUTPUT)test-libunwind-debug-frame-arm.bin:
	$(BUILD) -lelf -lunwind-arm

$(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
	$(BUILD) -lelf -lunwind-aarch64
155

156
$(OUTPUT)test-libaudit.bin:
157 158
	$(BUILD) -laudit

159
$(OUTPUT)test-libslang.bin:
160 161
	$(BUILD) -I/usr/include/slang -lslang

162 163 164
$(OUTPUT)test-libcrypto.bin:
	$(BUILD) -lcrypto

165
$(OUTPUT)test-gtk2.bin:
M
Mark Rutland 已提交
166
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
167

168
$(OUTPUT)test-gtk2-infobar.bin:
M
Mark Rutland 已提交
169
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
170

171 172 173 174 175 176 177 178 179
grep-libs  = $(filter -l%,$(1))
strip-libs = $(filter-out -l%,$(1))

PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)

180
$(OUTPUT)test-libperl.bin:
181 182
	$(BUILD) $(FLAGS_PERL_EMBED)

183
$(OUTPUT)test-libpython.bin:
184
	$(BUILD) $(FLAGS_PYTHON_EMBED)
185

186
$(OUTPUT)test-libpython-version.bin:
187
	$(BUILD)
188

189
$(OUTPUT)test-libbfd.bin:
190
	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
191

192 193 194
$(OUTPUT)test-disassembler-four-args.bin:
	$(BUILD) -lbfd -lopcodes

195 196
$(OUTPUT)test-liberty.bin:
	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
197

198 199
$(OUTPUT)test-liberty-z.bin:
	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
200

201
$(OUTPUT)test-cplus-demangle.bin:
202 203
	$(BUILD) -liberty

204
$(OUTPUT)test-backtrace.bin:
205 206
	$(BUILD)

207
$(OUTPUT)test-timerfd.bin:
208 209
	$(BUILD)

210
$(OUTPUT)test-libdw-dwarf-unwind.bin:
211 212
	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)

213
$(OUTPUT)test-libbabeltrace.bin:
214
	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
215

216
$(OUTPUT)test-sync-compare-and-swap.bin:
217
	$(BUILD)
218

219 220
$(OUTPUT)test-compile-32.bin:
	$(CC) -m32 -o $@ test-compile.c
221

222 223
$(OUTPUT)test-compile-x32.bin:
	$(CC) -mx32 -o $@ test-compile.c
224

225
$(OUTPUT)test-zlib.bin:
226 227
	$(BUILD) -lz

228
$(OUTPUT)test-lzma.bin:
229 230
	$(BUILD) -llzma

231
$(OUTPUT)test-get_cpuid.bin:
232 233
	$(BUILD)

234
$(OUTPUT)test-bpf.bin:
235 236
	$(BUILD)

237 238 239
$(OUTPUT)test-sdt.bin:
	$(BUILD)

240 241 242
$(OUTPUT)test-cxx.bin:
	$(BUILDXX) -std=gnu++11

243 244 245
$(OUTPUT)test-jvmti.bin:
	$(BUILD)

246
$(OUTPUT)test-llvm.bin:
247
	$(BUILDXX) -std=gnu++11 				\
248 249 250 251 252
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
		$(shell $(LLVM_CONFIG) --system-libs)

253 254 255 256
$(OUTPUT)test-llvm-version.bin:
	$(BUILDXX) -std=gnu++11 				\
		-I$(shell $(LLVM_CONFIG) --includedir)

257
$(OUTPUT)test-clang.bin:
258
	$(BUILDXX) -std=gnu++11 				\
259 260 261 262 263 264 265 266
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		-Wl,--start-group -lclangBasic -lclangDriver	\
		  -lclangFrontend -lclangEdit -lclangLex	\
		  -lclangAST -Wl,--end-group 			\
		$(shell $(LLVM_CONFIG) --libs Core option)	\
		$(shell $(LLVM_CONFIG) --system-libs)

267
-include $(OUTPUT)*.d
268

269 270 271
###############################

clean:
272
	rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)