Makefile 7.6 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
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
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                        \
         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                           \
52
         test-jvmti.bin				\
53 54
         test-sched_getcpu.bin			\
         test-setns.bin
55

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

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

63 64
all: $(FILES)

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

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

71 72
###############################

73
$(OUTPUT)test-all.bin:
74
	$(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
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

135
$(OUTPUT)test-libunwind-debug-frame.bin:
136
	$(BUILD) -lelf
137 138 139 140 141 142 143 144 145 146 147 148
$(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

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

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

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

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

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

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

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

170 171 172 173 174 175 176 177 178
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)

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

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

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

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

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

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

197
$(OUTPUT)test-cplus-demangle.bin:
198 199
	$(BUILD) -liberty

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

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

206
$(OUTPUT)test-libdw-dwarf-unwind.bin:
207 208
	$(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind)

209
$(OUTPUT)test-libbabeltrace.bin:
210
	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
211

212
$(OUTPUT)test-sync-compare-and-swap.bin:
213
	$(BUILD)
214

215 216
$(OUTPUT)test-compile-32.bin:
	$(CC) -m32 -o $@ test-compile.c
217

218 219
$(OUTPUT)test-compile-x32.bin:
	$(CC) -mx32 -o $@ test-compile.c
220

221
$(OUTPUT)test-zlib.bin:
222 223
	$(BUILD) -lz

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

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

230
$(OUTPUT)test-bpf.bin:
231 232
	$(BUILD)

233 234 235
$(OUTPUT)test-sdt.bin:
	$(BUILD)

236 237 238
$(OUTPUT)test-cxx.bin:
	$(BUILDXX) -std=gnu++11

239 240 241
$(OUTPUT)test-jvmti.bin:
	$(BUILD)

242
$(OUTPUT)test-llvm.bin:
243
	$(BUILDXX) -std=gnu++11 				\
244 245 246 247 248
		-I$(shell $(LLVM_CONFIG) --includedir) 		\
		-L$(shell $(LLVM_CONFIG) --libdir)		\
		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
		$(shell $(LLVM_CONFIG) --system-libs)

249 250 251 252
$(OUTPUT)test-llvm-version.bin:
	$(BUILDXX) -std=gnu++11 				\
		-I$(shell $(LLVM_CONFIG) --includedir)

253
$(OUTPUT)test-clang.bin:
254
	$(BUILDXX) -std=gnu++11 				\
255 256 257 258 259 260 261 262
		-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)

263
-include $(OUTPUT)*.d
264

265 266 267
###############################

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