1# Copyright (c) 2016, Google Inc. 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# * Redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer. 8# * Redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution. 11# * Neither the name of Google Inc. nor the 12# names of its contributors may be used to endorse or promote products 13# derived from this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18# DISCLAIMED. IN NO EVENT SHALL Google Inc. BE LIABLE FOR ANY 19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25# 26################################################################################ 27 28CXX ?= g++ 29 30BASE_VER ?= 369476 31PKG_CONFIG ?= pkg-config 32PC_DEPS = openssl 33PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS)) 34PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS)) 35 36CWP = quipper 37PROTOBUF = ../third_party/protobuf 38GOOGLETEST = ../third_party/googletest 39 40CXXFLAGS += -std=c++11 -g -Wall -Werror -Wall -Wno-error 41CPPFLAGS += -Icompat -I${CWP}/mybase \ 42 -I${CWP}/compat/ext \ 43 -I${CWP} \ 44 -I../third_party \ 45 -I. $(PC_CFLAGS) $(PROTOBUF_CFLAGS) $(GTEST_INCLUDES) 46LDLIBS += -lelf -lpthread $(PC_LIBS) $(PROTOBUF_LIBS) 47 48PROGRAMS = perf_to_profile 49MAIN_SOURCES = $(PROGRAMS:%=%.cc) 50MAIN_OBJECTS = $(MAIN_SOURCES:%.cc=%.o) 51 52QUIPPER_LIBRARY_SOURCES = \ 53 address_mapper.cc binary_data_utils.cc buffer_reader.cc buffer_writer.cc \ 54 conversion_utils.cc compat/log_level.cc data_reader.cc \ 55 data_writer.cc dso.cc file_reader.cc file_utils.cc \ 56 mybase/base/logging.cc perf_option_parser.cc perf_data_utils.cc \ 57 perf_parser.cc perf_protobuf_io.cc perf_reader.cc perf_recorder.cc \ 58 perf_serializer.cc perf_stat_parser.cc run_command.cc \ 59 sample_info_reader.cc scoped_temp_path.cc string_utils.cc \ 60 huge_page_deducer.cc 61QUIPPER_LIBRARY_SOURCES := \ 62 $(QUIPPER_LIBRARY_SOURCES:%=${CWP}/%) 63CONVERTER_LIBRARY_SOURCES = perf_data_converter.cc perf_data_handler.cc \ 64 builder.cc perf_to_profile_lib.cc 65LIBRARY_SOURCES = $(QUIPPER_LIBRARY_SOURCES) $(CONVERTER_LIBRARY_SOURCES) 66 67QUIPPER_PROTOS = perf_data.proto perf_stat.proto 68QUIPPER_PROTOS := $(QUIPPER_PROTOS:%=${CWP}/%) 69CONVERTER_PROTOS = profile.proto 70QUIPPER_GENERATED_SOURCES = $(QUIPPER_PROTOS:.proto=.pb.cc) 71QUIPPER_GENERATED_HEADERS = $(QUIPPER_PROTOS:.proto=.pb.h) 72GENERATED_SOURCES = $(CONVERTER_PROTOS:.proto=.pb.cc) \ 73 $(QUIPPER_GENERATED_SOURCES) 74GENERATED_HEADERS = $(CONVERTER_PROTOS:.proto=.pb.h) \ 75 $(QUIPPER_GENERATED_HEADERS) 76 77COMMON_SOURCES = $(GENERATED_SOURCES) $(LIBRARY_SOURCES) 78COMMON_OBJECTS = $(COMMON_SOURCES:.cc=.o) 79 80TEST_SOURCES = intervalmap_test.cc perf_data_converter_test.cc \ 81 perf_data_handler_test.cc perf_to_profile_lib_test.cc 82TEST_BINARIES = $(TEST_SOURCES:.cc=) 83TEST_OBJECTS = $(TEST_SOURCES:.cc=.o) 84 85ALL_SOURCES = $(MAIN_SOURCES) $(COMMON_SOURCES) $(TEST_SOURCES) 86 87INTERMEDIATES = $(ALL_SOURCES:.cc=.d*) 88 89all: $(PROGRAMS) 90 @echo Sources compiled! 91 92# Protobuf dependence configuration 93ifeq ($(wildcard ${PROTOBUF}/src/google/protobuf/descriptor.pb.h),) 94# Protobuf module hasn't been populated, attempt using local installation. 95PROTOC = protoc 96PROTOBUF_DEP = 97PROTOBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) 98PROTOBUF_LIBS := $(shell $(PKG_CONFIG) --libs protobuf) 99else 100# Use protobuf compiler and libraries from submodule. 101PROTOC = ${PROTOBUF}/src/protoc 102PROTOBUF_CFLAGS := -I${PROTOBUF}/src 103PROTOBUF_LIBS := ${PROTOBUF}/src/.libs/libprotobuf.a -lz 104PROTOBUF_DEP := ${PROTOBUF}/src/.libs/libprotobuf.a 105endif 106 107${PROTOBUF}/configure: 108 echo "[AUTOGEN] Preparing protobuf" 109 (cd ${PROTOBUF} ; autoreconf -f -i -Wall,no-obsolete) 110 111${PROTOBUF}/src/.libs/libprotobuf.a: ${PROTOBUF}/configure 112 echo "[MAKE] Building protobuf" 113 (cd ${PROTOBUF} ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static $(PROTOBUF_CONFIG_OPTS)) 114 $(MAKE) -C ${PROTOBUF} clean 115 $(MAKE) -C ${PROTOBUF} 116 117# Googletest dependence configuration 118ifeq ($(wildcard ${GOOGLETEST}/googletest/include/gtest/gtest.h),) 119# Use local gtest includes, already on the system path 120GTEST_INCLUDES = 121GTEST_LIBS = -lgtest -lgmock 122else 123# Pick up gtest includes from submodule. 124GTEST_INCLUDES = -I${GOOGLETEST}/googlemock/include -I${GOOGLETEST}/googletest/include 125GTEST_LIBS = -I${GOOGLETEST}/googlemock ${GOOGLETEST}/googlemock/src/gmock-all.cc -I${GOOGLETEST}/googletest ${GOOGLETEST}/googletest/src/gtest-all.cc 126endif 127 128ifneq ($(MAKECMDGOALS),clean) 129 -include $(ALL_SOURCES:.cc=.d) 130endif 131 132# Taken from: 133# http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites 134%.d: %.cc $(GENERATED_HEADERS) 135 @set -e; rm -f $@; \ 136 $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \ 137 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ 138 rm -f $@.$$$$ 139 140# Rule for compiling protobufs. 141%.pb.h %.pb.cc: %.proto $(PROTOBUF_DEP) 142 $(PROTOC) --cpp_out=`dirname $<` -I`dirname $<` $< 143 144# Do not remove protobuf headers that were generated as dependencies of other 145# modules. 146.SECONDARY: $(GENERATED_HEADERS) 147 148$(PROGRAMS): %: %.o $(COMMON_OBJECTS) 149 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) 150 151$(TEST_BINARIES): %: %.o $(COMMON_OBJECTS) 152 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(GTEST_LIBS) 153 154# build all unit tests 155tests: $(TEST_BINARIES) 156 157# make run_(test binary name) runs the unit test. 158UNIT_TEST_RUN_BINARIES = $(TEST_BINARIES:%=run_%) 159$(UNIT_TEST_RUN_BINARIES): run_%: % 160 ./$^ 161 162# run all unit tests 163check: $(UNIT_TEST_RUN_BINARIES) 164 165clean: 166 rm -f *.d $(TESTS) $(GENERATED_SOURCES) $(GENERATED_HEADERS) \ 167 $(TEST_OBJECTS) $(COMMON_OBJECTS) $(INTERMEDIATES) \ 168 $(MAIN_OBJECTS) $(PROGRAMS) $(TEST_BINARIES) 169 170print-%: 171 @echo $* = $($*) 172