Home | History | Annotate | Download | only in src
      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 
     28 CXX ?= g++
     29 
     30 BASE_VER ?= 369476
     31 PKG_CONFIG ?= pkg-config
     32 PC_DEPS = openssl
     33 PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
     34 PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
     35 
     36 CWP = quipper
     37 PROTOBUF = ../third_party/protobuf
     38 GOOGLETEST = ../third_party/googletest
     39 
     40 CXXFLAGS += -std=c++11 -g -Wall -Werror -Wall -Wno-error
     41 CPPFLAGS += -Icompat -I${CWP}/mybase \
     42 		-I${CWP}/compat/ext \
     43 		-I${CWP} \
     44 		-I../third_party \
     45 		-I. $(PC_CFLAGS) $(PROTOBUF_CFLAGS) $(GTEST_INCLUDES)
     46 LDLIBS += -lelf -lpthread $(PC_LIBS) $(PROTOBUF_LIBS)
     47 
     48 PROGRAMS = perf_to_profile
     49 MAIN_SOURCES = $(PROGRAMS:%=%.cc)
     50 MAIN_OBJECTS = $(MAIN_SOURCES:%.cc=%.o)
     51 
     52 QUIPPER_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
     61 QUIPPER_LIBRARY_SOURCES := \
     62 	$(QUIPPER_LIBRARY_SOURCES:%=${CWP}/%)
     63 CONVERTER_LIBRARY_SOURCES = perf_data_converter.cc perf_data_handler.cc \
     64 														builder.cc perf_to_profile_lib.cc
     65 LIBRARY_SOURCES = $(QUIPPER_LIBRARY_SOURCES) $(CONVERTER_LIBRARY_SOURCES)
     66 
     67 QUIPPER_PROTOS = perf_data.proto perf_stat.proto
     68 QUIPPER_PROTOS := $(QUIPPER_PROTOS:%=${CWP}/%)
     69 CONVERTER_PROTOS = profile.proto
     70 QUIPPER_GENERATED_SOURCES = $(QUIPPER_PROTOS:.proto=.pb.cc)
     71 QUIPPER_GENERATED_HEADERS = $(QUIPPER_PROTOS:.proto=.pb.h)
     72 GENERATED_SOURCES = $(CONVERTER_PROTOS:.proto=.pb.cc) \
     73 	$(QUIPPER_GENERATED_SOURCES)
     74 GENERATED_HEADERS = $(CONVERTER_PROTOS:.proto=.pb.h) \
     75 	$(QUIPPER_GENERATED_HEADERS)
     76 
     77 COMMON_SOURCES = $(GENERATED_SOURCES) $(LIBRARY_SOURCES)
     78 COMMON_OBJECTS = $(COMMON_SOURCES:.cc=.o)
     79 
     80 TEST_SOURCES = intervalmap_test.cc perf_data_converter_test.cc \
     81 	perf_data_handler_test.cc perf_to_profile_lib_test.cc
     82 TEST_BINARIES = $(TEST_SOURCES:.cc=)
     83 TEST_OBJECTS = $(TEST_SOURCES:.cc=.o)
     84 
     85 ALL_SOURCES = $(MAIN_SOURCES) $(COMMON_SOURCES) $(TEST_SOURCES)
     86 
     87 INTERMEDIATES = $(ALL_SOURCES:.cc=.d*)
     88 
     89 all: $(PROGRAMS)
     90 	@echo Sources compiled!
     91 
     92 # Protobuf dependence configuration
     93 ifeq ($(wildcard ${PROTOBUF}/src/google/protobuf/descriptor.pb.h),)
     94 # Protobuf module hasn't been populated, attempt using local installation.
     95 PROTOC = protoc
     96 PROTOBUF_DEP =
     97 PROTOBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf)
     98 PROTOBUF_LIBS := $(shell $(PKG_CONFIG) --libs protobuf)
     99 else
    100 # Use protobuf compiler and libraries from submodule.
    101 PROTOC = ${PROTOBUF}/src/protoc
    102 PROTOBUF_CFLAGS := -I${PROTOBUF}/src
    103 PROTOBUF_LIBS := ${PROTOBUF}/src/.libs/libprotobuf.a  -lz
    104 PROTOBUF_DEP := ${PROTOBUF}/src/.libs/libprotobuf.a
    105 endif
    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
    118 ifeq ($(wildcard ${GOOGLETEST}/googletest/include/gtest/gtest.h),)
    119 # Use local gtest includes, already on the system path
    120 GTEST_INCLUDES =
    121 GTEST_LIBS = -lgtest -lgmock
    122 else
    123 # Pick up gtest includes from submodule.
    124 GTEST_INCLUDES = -I${GOOGLETEST}/googlemock/include -I${GOOGLETEST}/googletest/include
    125 GTEST_LIBS = -I${GOOGLETEST}/googlemock ${GOOGLETEST}/googlemock/src/gmock-all.cc -I${GOOGLETEST}/googletest ${GOOGLETEST}/googletest/src/gtest-all.cc
    126 endif
    127 
    128 ifneq ($(MAKECMDGOALS),clean)
    129   -include $(ALL_SOURCES:.cc=.d)
    130 endif
    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
    155 tests: $(TEST_BINARIES)
    156 
    157 # make run_(test binary name) runs the unit test.
    158 UNIT_TEST_RUN_BINARIES = $(TEST_BINARIES:%=run_%)
    159 $(UNIT_TEST_RUN_BINARIES): run_%: %
    160 	./$^
    161 
    162 # run all unit tests
    163 check: $(UNIT_TEST_RUN_BINARIES)
    164 
    165 clean:
    166 	rm -f *.d $(TESTS) $(GENERATED_SOURCES)  $(GENERATED_HEADERS) \
    167 		$(TEST_OBJECTS) $(COMMON_OBJECTS) $(INTERMEDIATES) \
    168 		$(MAIN_OBJECTS) $(PROGRAMS) $(TEST_BINARIES)
    169 
    170 print-%:
    171 	@echo $* = $($*)
    172