1# Copyright (C) 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15LOCAL_PATH := $(call my-dir)
16
17ifeq ($(TARGET_PRODUCT),sdk)
18supported_platforms := none
19else
20supported_platforms := linux darwin
21endif
22
23cur_platform := $(filter $(HOST_OS),$(supported_platforms))
24
25ifdef cur_platform
26
27perf_arch := $(TARGET_ARCH)
28ifeq ($(TARGET_ARCH), x86_64)
29perf_arch := x86
30endif
31
32ifeq ($(TARGET_ARCH), mips64)
33perf_arch := mips
34endif
35
36libperf_src_files := \
37    arch/common.c \
38    arch/$(perf_arch)/util/dwarf-regs.c \
39    tests/attr.c \
40    ui/helpline.c \
41    ui/hist.c \
42    ui/progress.c \
43    ui/setup.c \
44    ui/stdio/hist.c \
45    ui/util.c \
46    util/abspath.c \
47    util/alias.c \
48    util/annotate.c \
49    util/bitmap.c \
50    util/build-id.c \
51    util/callchain.c \
52    util/cgroup.c \
53    util/color.c \
54    util/config.c \
55    util/cpumap.c \
56    util/ctype.c \
57    util/debug.c \
58    util/dso.c \
59    util/dwarf-aux.c \
60    util/environment.c \
61    util/event.c \
62    util/evlist.c \
63    util/evsel.c \
64    util/exec_cmd.c \
65    util/header.c \
66    util/help.c \
67    util/hist.c \
68    util/hweight.c \
69    util/intlist.c \
70    util/levenshtein.c \
71    util/machine.c \
72    util/map.c \
73    util/pager.c \
74    util/parse-events.c \
75    util/parse-events-bison.c \
76    util/parse-events-flex.c \
77    util/parse-options.c \
78    util/path.c \
79    util/pmu.c \
80    util/pmu-bison.c \
81    util/pmu-flex.c \
82    util/probe-event.c \
83    util/probe-finder.c \
84    util/quote.c \
85    util/rblist.c \
86    util/record.c \
87    util/run-command.c \
88    util/sigchain.c \
89    util/session.c \
90    util/sort.c \
91    util/stat.c \
92    util/strbuf.c \
93    util/string.c \
94    util/strfilter.c \
95    util/strlist.c \
96    util/svghelper.c \
97    util/symbol.c \
98    util/symbol-elf.c \
99    util/sysfs.c \
100    util/target.c \
101    util/thread.c \
102    util/thread_map.c \
103    util/top.c \
104    util/trace-event-info.c \
105    util/trace-event-parse.c \
106    util/trace-event-read.c \
107    util/trace-event-scripting.c \
108    util/usage.c \
109    util/util.c \
110    util/values.c \
111    util/vdso.c \
112    util/wrapper.c \
113    util/xyarray.c \
114    ../lib/lk/debugfs.c \
115    ../lib/traceevent/event-parse.c \
116    ../lib/traceevent/parse-utils.c \
117    ../lib/traceevent/trace-seq.c \
118    ../../lib/rbtree.c
119
120common_perf_headers := $(LOCAL_PATH)/../lib $(LOCAL_PATH)/util/include \
121    $(LOCAL_PATH)/util $(LOCAL_PATH)/../../include/uapi
122
123common_elfutil_headers := external/elfutils external/elfutils/0.153/libelf \
124    external/elfutils/0.153/libdw external/elfutils/0.153/libdwfl
125
126common_compiler_flags := \
127    -DANDROID_PATCHES \
128    -Wno-error \
129    -std=gnu99 \
130    -Wno-return-type \
131
132ifeq ($(strip $(HOST_OS)),linux)
133common_compiler_flags += \
134    -Wno-attributes \
135    -Wno-implicit-function-declaration \
136    -Wno-int-to-pointer-cast \
137    -Wno-maybe-uninitialized \
138    -Wno-missing-field-initializers \
139    -Wno-pointer-arith \
140    -Wno-pointer-sign \
141    -Wno-sign-compare \
142    -Wno-unused-parameter \
143
144endif
145
146ifeq ($(strip $(HOST_OS)),darwin)
147host_compiler_flags := -include $(LOCAL_PATH)/host-darwin-fixup/AndroidFixup.h
148endif
149
150common_disabled_macros := -DNO_NEWT_SUPPORT -DNO_LIBPERL -DNO_LIBPYTHON \
151    -DNO_GTK2 -DNO_LIBNUMA -DNO_LIBAUDIT
152
153common_predefined_macros := -DDWARF_SUPPORT -DPYTHON='""' -DBINDIR='""' \
154    -DETC_PERFCONFIG='""' -DPREFIX='""' -DPERF_EXEC_PATH='""' \
155    -DPERF_HTML_PATH='""' -DPERF_MAN_PATH='""' -DPERF_INFO_PATH='""' \
156    -DPERF_VERSION='"perf.3.12_android"' -DHAVE_ELF_GETPHDRNUM \
157    -DLIBELF_SUPPORT -DLIBELF_MMAP
158
159perf_src_files := \
160    perf.c \
161    builtin-annotate.c \
162    builtin-buildid-cache.c \
163    builtin-buildid-list.c \
164    builtin-diff.c \
165    builtin-evlist.c \
166    builtin-help.c \
167    builtin-inject.c \
168    builtin-kmem.c \
169    builtin-list.c \
170    builtin-lock.c \
171    builtin-mem.c \
172    builtin-probe.c \
173    builtin-record.c \
174    builtin-report.c \
175    builtin-sched.c \
176    builtin-script.c \
177    builtin-stat.c \
178    builtin-timechart.c \
179    builtin-top.c \
180
181
182#
183# target libperf
184#
185include $(CLEAR_VARS)
186
187LOCAL_SRC_FILES := $(libperf_src_files)
188
189LOCAL_CFLAGS := $(common_disabled_macros)
190LOCAL_CFLAGS += $(common_predefined_macros)
191LOCAL_CFLAGS += $(common_compiler_flags)
192LOCAL_C_INCLUDES := $(common_perf_headers) $(common_elfutil_headers)
193
194LOCAL_MODULE := libperf
195LOCAL_MODULE_TAGS := eng
196LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
197
198include $(BUILD_STATIC_LIBRARY)
199
200#
201# host libperf
202#
203include $(CLEAR_VARS)
204
205LOCAL_SRC_FILES := $(libperf_src_files)
206
207LOCAL_CFLAGS := $(common_disabled_macros)
208LOCAL_CFLAGS += $(common_predefined_macros)
209LOCAL_CFLAGS += $(common_compiler_flags) $(host_compiler_flags)
210LOCAL_C_INCLUDES := $(common_perf_headers) $(common_elfutil_headers)
211LOCAL_C_INCLUDES += $(LOCAL_PATH)/host-$(HOST_OS)-fixup
212
213LOCAL_MODULE := libperf
214LOCAL_MODULE_TAGS := eng
215LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
216
217LOCAL_CLANG := false
218
219include $(BUILD_HOST_STATIC_LIBRARY)
220
221#
222# target perf
223#
224include $(CLEAR_VARS)
225
226LOCAL_SRC_FILES := $(perf_src_files)
227
228# TODO: this is only needed because of libebl below, which seems like a mistake on the target.
229LOCAL_SHARED_LIBRARIES := libdl
230
231# TODO: there's probably more stuff here than is strictly necessary on the target.
232LOCAL_STATIC_LIBRARIES := \
233    libperf \
234    libdwfl \
235    libdw \
236    libebl \
237    libelf \
238    libgccdemangle \
239
240LOCAL_CFLAGS := $(common_disabled_macros)
241LOCAL_CFLAGS += $(common_predefined_macros)
242LOCAL_CFLAGS += $(common_compiler_flags)
243LOCAL_C_INCLUDES := $(common_perf_headers) $(common_elfutil_headers)
244
245LOCAL_MODULE := perf
246LOCAL_MODULE_TAGS := eng
247LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
248
249include $(BUILD_EXECUTABLE)
250
251#
252# host perf
253#
254include $(CLEAR_VARS)
255
256LOCAL_SRC_FILES := $(perf_src_files)
257
258# TODO: libebl tries to dlopen libebl_$arch.so, which we don't actually build.
259# At the moment it's probably pulling in the ones from the host OS' perf, at
260# least on Linux. On the Mac it's probably just completely broken.
261LOCAL_STATIC_LIBRARIES := \
262    libperf \
263    libdwfl \
264    libdw \
265    libebl \
266    libelf \
267    libgccdemangle \
268
269LOCAL_CFLAGS := $(common_disabled_macros)
270LOCAL_CFLAGS += $(common_predefined_macros)
271LOCAL_CFLAGS += $(common_compiler_flags) $(host_compiler_flags)
272
273# available on linux-x86 but not darwin-x86
274ifeq ($(strip $(HOST_OS)),linux)
275LOCAL_CFLAGS += -DHAVE_ON_EXIT
276endif
277
278LOCAL_C_INCLUDES := $(common_perf_headers) $(common_elfutil_headers)
279LOCAL_C_INCLUDES += $(LOCAL_PATH)/host-$(HOST_OS)-fixup
280
281# for pthread_* and clock_gettime
282LOCAL_LDLIBS := -lpthread -ldl
283
284ifeq ($(strip $(HOST_OS)),linux)
285LOCAL_LDLIBS += -lrt
286endif
287
288LOCAL_MODULE := perfhost
289LOCAL_MODULE_TAGS := eng
290LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
291
292LOCAL_CLANG := false
293
294include $(BUILD_HOST_EXECUTABLE)
295
296endif #cur_platform
297