Makefile 8.38 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9
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         \
10
         test-get_current_dir_name.bin          \
11 12 13 14 15 16
         test-glibc.bin                         \
         test-gtk2.bin                          \
         test-gtk2-infobar.bin                  \
         test-hello.bin                         \
         test-libaudit.bin                      \
         test-libbfd.bin                        \
17
         test-disassembler-four-args.bin        \
18
         test-reallocarray.bin			\
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
         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   \
43
         test-pthread-barrier.bin		\
44 45 46 47 48 49 50 51 52 53 54 55
         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                           \
56
         test-jvmti.bin				\
57
         test-sched_getcpu.bin			\
58
         test-setns.bin				\
59 60 61 62
         test-libopencsd.bin			\
         test-clang.bin				\
         test-llvm.bin				\
         test-llvm-version.bin
63

64 65
FILES := $(addprefix $(OUTPUT),$(FILES))

66 67 68
CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
69
LLVM_CONFIG ?= llvm-config
70

71 72
all: $(FILES)

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

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

79 80
###############################

81
$(OUTPUT)test-all.bin:
82
	$(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
83

84
$(OUTPUT)test-hello.bin:
85 86
	$(BUILD)

87
$(OUTPUT)test-pthread-attr-setaffinity-np.bin:
88
	$(BUILD) -D_GNU_SOURCE -lpthread
89

90 91 92
$(OUTPUT)test-pthread-barrier.bin:
	$(BUILD) -lpthread

93
$(OUTPUT)test-stackprotector-all.bin:
94
	$(BUILD) -fstack-protector-all
95

96
$(OUTPUT)test-fortify-source.bin:
97
	$(BUILD) -O2 -D_FORTIFY_SOURCE=2
98

99
$(OUTPUT)test-bionic.bin:
100 101
	$(BUILD)

102
$(OUTPUT)test-libelf.bin:
103 104
	$(BUILD) -lelf

105 106 107
$(OUTPUT)test-get_current_dir_name.bin:
	$(BUILD)

108
$(OUTPUT)test-glibc.bin:
109 110
	$(BUILD)

111 112 113
$(OUTPUT)test-sched_getcpu.bin:
	$(BUILD)

114 115 116
$(OUTPUT)test-setns.bin:
	$(BUILD)

117 118 119 120
$(OUTPUT)test-libopencsd.bin:
	$(BUILD) # -lopencsd_c_api -lopencsd provided by
		 # $(FEATURE_CHECK_LDFLAGS-libopencsd)

121 122 123 124 125
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
endif

126
$(OUTPUT)test-dwarf.bin:
127
	$(BUILD) $(DWARFLIBS)
128

129 130 131
$(OUTPUT)test-dwarf_getlocations.bin:
	$(BUILD) $(DWARFLIBS)

132
$(OUTPUT)test-libelf-mmap.bin:
133 134
	$(BUILD) -lelf

135
$(OUTPUT)test-libelf-getphdrnum.bin:
136 137
	$(BUILD) -lelf

138 139 140
$(OUTPUT)test-libelf-gelf_getnote.bin:
	$(BUILD) -lelf

141 142 143
$(OUTPUT)test-libelf-getshdrstrndx.bin:
	$(BUILD) -lelf

144
$(OUTPUT)test-libnuma.bin:
145 146
	$(BUILD) -lnuma

147
$(OUTPUT)test-numa_num_possible_cpus.bin:
148 149
	$(BUILD) -lnuma

150
$(OUTPUT)test-libunwind.bin:
151
	$(BUILD) -lelf
152

153
$(OUTPUT)test-libunwind-debug-frame.bin:
154
	$(BUILD) -lelf
155 156 157 158 159 160 161 162 163 164 165 166
$(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

167 168 169 170 171
$(OUTPUT)test-libunwind-debug-frame-arm.bin:
	$(BUILD) -lelf -lunwind-arm

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

173
$(OUTPUT)test-libaudit.bin:
174 175
	$(BUILD) -laudit

176
$(OUTPUT)test-libslang.bin:
177 178
	$(BUILD) -I/usr/include/slang -lslang

179 180 181
$(OUTPUT)test-libcrypto.bin:
	$(BUILD) -lcrypto

182
$(OUTPUT)test-gtk2.bin:
Mark Rutland's avatar
Mark Rutland committed
183
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
184

185
$(OUTPUT)test-gtk2-infobar.bin:
Mark Rutland's avatar
Mark Rutland committed
186
	$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
187

188 189 190 191 192 193 194 195 196
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)

197
$(OUTPUT)test-libperl.bin:
198 199
	$(BUILD) $(FLAGS_PERL_EMBED)

200
$(OUTPUT)test-libpython.bin:
201
	$(BUILD) $(FLAGS_PYTHON_EMBED)
202

203
$(OUTPUT)test-libpython-version.bin:
204
	$(BUILD)
205

206
$(OUTPUT)test-libbfd.bin:
207
	$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
208

209
$(OUTPUT)test-disassembler-four-args.bin:
210
	$(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes
211

212 213 214
$(OUTPUT)test-reallocarray.bin:
	$(BUILD)

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

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

221
$(OUTPUT)test-cplus-demangle.bin:
222 223
	$(BUILD) -liberty

224
$(OUTPUT)test-backtrace.bin:
225 226
	$(BUILD)

227
$(OUTPUT)test-timerfd.bin:
228 229
	$(BUILD)

230
$(OUTPUT)test-libdw-dwarf-unwind.bin:
231 232
	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)

233
$(OUTPUT)test-libbabeltrace.bin:
234
	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
235

236
$(OUTPUT)test-sync-compare-and-swap.bin:
237
	$(BUILD)
238

239 240
$(OUTPUT)test-compile-32.bin:
	$(CC) -m32 -o $@ test-compile.c
241

242 243
$(OUTPUT)test-compile-x32.bin:
	$(CC) -mx32 -o $@ test-compile.c
244

245
$(OUTPUT)test-zlib.bin:
246 247
	$(BUILD) -lz

248
$(OUTPUT)test-lzma.bin:
249 250
	$(BUILD) -llzma

251
$(OUTPUT)test-get_cpuid.bin:
252 253
	$(BUILD)

254
$(OUTPUT)test-bpf.bin:
255 256
	$(BUILD)

257 258 259
$(OUTPUT)test-sdt.bin:
	$(BUILD)

260 261 262
$(OUTPUT)test-cxx.bin:
	$(BUILDXX) -std=gnu++11

263 264 265
$(OUTPUT)test-jvmti.bin:
	$(BUILD)

266
$(OUTPUT)test-llvm.bin:
267
	$(BUILDXX) -std=gnu++11 				\
268 269 270
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
271 272
		$(shell $(LLVM_CONFIG) --system-libs)		\
		> $(@:.bin=.make.output) 2>&1
273

274 275
$(OUTPUT)test-llvm-version.bin:
	$(BUILDXX) -std=gnu++11 				\
276 277
		-I$(shell $(LLVM_CONFIG) --includedir)		\
		> $(@:.bin=.make.output) 2>&1
278

279
$(OUTPUT)test-clang.bin:
280
	$(BUILDXX) -std=gnu++11 				\
281 282 283 284 285 286
		-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)	\
287 288
		$(shell $(LLVM_CONFIG) --system-libs)		\
		> $(@:.bin=.make.output) 2>&1
289

290
-include $(OUTPUT)*.d
291

292 293 294
###############################

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