Home | History | Annotate | Download | only in quipper
      1 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 CXX ?= g++
      7 
      8 BASE_VER ?= 369476
      9 PKG_CONFIG ?= pkg-config
     10 PC_DEPS = openssl
     11 PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
     12 PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
     13 
     14 PROTOBUF = ../../third_party/protobuf
     15 GOOGLETEST = ../../third_party/googletest
     16 
     17 CXXFLAGS += -std=c++11 -g -Wall -Werror -Wall -Wno-error
     18 CPPFLAGS += -Imybase \
     19             -Icompat/non_cros \
     20             -I../../third_party \
     21             -I. -I.. $(PC_CFLAGS) $(PROTOBUF_CFLAGS) $(GTEST_INCLUDES)
     22 LDLIBS += -lpthread -lgcov -lelf $(PC_LIBS) $(PROTOBUF_LIBS)
     23 
     24 MAIN_SOURCES = quipper.cc perf_converter.cc
     25 PROGRAMS = $(MAIN_SOURCES:.cc=)
     26 
     27 LIBRARY_SOURCES = \
     28 	address_mapper.cc binary_data_utils.cc buffer_reader.cc buffer_writer.cc \
     29 	conversion_utils.cc compat/log_level.cc data_reader.cc \
     30 	data_writer.cc dso.cc file_reader.cc file_utils.cc \
     31 	mybase/base/logging.cc perf_option_parser.cc perf_data_utils.cc \
     32 	perf_parser.cc perf_protobuf_io.cc perf_reader.cc perf_recorder.cc \
     33 	perf_serializer.cc perf_stat_parser.cc run_command.cc \
     34 	sample_info_reader.cc scoped_temp_path.cc string_utils.cc \
     35   huge_page_deducer.cc
     36 GENERATED_SOURCES = perf_data.pb.cc perf_stat.pb.cc
     37 GENERATED_HEADERS = $(GENERATED_SOURCES:.pb.cc=.pb.h)
     38 
     39 COMMON_SOURCES = $(LIBRARY_SOURCES) $(GENERATED_SOURCES)
     40 COMMON_OBJECTS = $(COMMON_SOURCES:.cc=.o)
     41 TEST_COMMON_SOURCES = \
     42 	dso_test_utils.cc perf_test_files.cc test_perf_data.cc test_utils.cc
     43 TEST_COMMON_OBJECTS = $(TEST_COMMON_SOURCES:.cc=.o)
     44 
     45 TESTDATA_DIR = testdata
     46 INTEGRATION_TEST_SOURCES = conversion_utils_test.cc
     47 PERF_RECORDER_TEST_SOURCES = perf_recorder_test.cc
     48 UNIT_TEST_SOURCES = \
     49 	address_mapper_test.cc binary_data_utils_test.cc buffer_reader_test.cc \
     50 	buffer_writer_test.cc file_reader_test.cc \
     51 	perf_data_utils_test.cc \
     52 	perf_option_parser_test.cc perf_parser_test.cc perf_reader_test.cc \
     53 	perf_serializer_test.cc perf_stat_parser_test.cc run_command_test.cc \
     54 	sample_info_reader_test.cc scoped_temp_path_test.cc
     55 TEST_SOURCES = $(INTEGRATION_TEST_SOURCES) $(PERF_RECORDER_TEST_SOURCES) \
     56 	$(UNIT_TEST_SOURCES) $(TEST_COMMON_SOURCES) test_runner.cc
     57 TEST_OBJECTS = $(TEST_SOURCES:.cc=.o)
     58 TESTS = integration_tests perf_recorder_test unit_tests
     59 
     60 ALL_SOURCES = $(MAIN_SOURCES) $(COMMON_SOURCES) $(TEST_SOURCES)
     61 
     62 all: $(PROGRAMS) $(TESTS)
     63 	@echo Sources compiled!
     64 
     65 # Protobuf dependence configuration
     66 ifeq ($(wildcard ${PROTOBUF}/src/google/protobuf/descriptor.pb.h),)
     67 # Protobuf module hasn't been populated, attempt using local installation.
     68 PROTOC = protoc
     69 PROTOBUF_DEP =
     70 PROTOBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf)
     71 PROTOBUF_LIBS := $(shell $(PKG_CONFIG) --libs protobuf)
     72 else
     73 # Use protobuf compiler and libraries from submodule.
     74 PROTOC = ${PROTOBUF}/src/protoc
     75 PROTOBUF_CFLAGS := -I${PROTOBUF}/src
     76 PROTOBUF_LIBS := ${PROTOBUF}/src/.libs/libprotobuf.a  -lz
     77 PROTOBUF_DEP := ${PROTOBUF}/src/.libs/libprotobuf.a
     78 endif
     79 
     80 ${PROTOBUF}/configure:
     81 	echo "[AUTOGEN] Preparing protobuf"
     82 	(cd ${PROTOBUF} ; autoreconf -f -i -Wall,no-obsolete)
     83 
     84 ${PROTOBUF}/src/.libs/libprotobuf.a: ${PROTOBUF}/configure
     85 	echo "[MAKE]    Building protobuf"
     86 	(cd ${PROTOBUF} ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g \
     87   $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) \
     88   -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static \
     89   $(PROTOBUF_CONFIG_OPTS))
     90 	$(MAKE) -C ${PROTOBUF} clean
     91 	$(MAKE) -C ${PROTOBUF}
     92 
     93 # Googletest dependence configuration
     94 ifeq ($(wildcard ${GOOGLETEST}/googletest/include/gtest/gtest.h),)
     95 # Use local gtest includes, already on the system path
     96 GTEST_INCLUDES =
     97 GTEST_LIBS = -lgtest
     98 else
     99 # Pick up gtest includes from submodule.
    100 GTEST_INCLUDES = -I${GOOGLETEST}/googletest/include
    101 GTEST_LIBS = -I${GOOGLETEST}/googletest ${GOOGLETEST}/googletest/src/gtest-all.cc
    102 endif
    103 
    104 ifneq ($(MAKECMDGOALS),clean)
    105   -include $(ALL_SOURCES:.cc=.d)
    106 endif
    107 
    108 # Taken from:
    109 # http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites
    110 %.d: %.cc $(GENERATED_HEADERS)
    111 	@set -e; rm -f $@; \
    112 	$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
    113 	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
    114 	rm -f $@.$$$$
    115 
    116 # Rule for compiling protobufs.
    117 %.pb.h %.pb.cc: %.proto $(PROTOBUF_DEP)
    118 	$(PROTOC) --cpp_out=. -I`dirname $<` $<
    119 
    120 # Do not remove protobuf headers that were generated as dependencies of other
    121 # modules.
    122 .SECONDARY: $(GENERATED_HEADERS)
    123 
    124 $(PROGRAMS): %: %.o $(COMMON_OBJECTS)
    125 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
    126 
    127 INTEGRATION_TEST_OBJECTS = $(INTEGRATION_TEST_SOURCES:.cc=.o) test_runner.o
    128 integration_tests: LDLIBS += $(GTEST_LIBS)
    129 integration_tests: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) \
    130 		      $(INTEGRATION_TEST_OBJECTS) | $(TESTDATA_DIR)
    131 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
    132 
    133 PERF_RECORDER_TEST_OBJECTS = $(PERF_RECORDER_TEST_SOURCES:.cc=.o)
    134 perf_recorder_test: LDLIBS += $(GTEST_LIBS)
    135 perf_recorder_test: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) \
    136 		       $(PERF_RECORDER_TEST_OBJECTS)
    137 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
    138 
    139 UNIT_TEST_OBJECTS = $(UNIT_TEST_SOURCES:.cc=.o) test_runner.o
    140 unit_tests: LDLIBS += $(GTEST_LIBS) -lcap
    141 unit_tests: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) \
    142 		      $(UNIT_TEST_OBJECTS) | $(TESTDATA_DIR)
    143 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
    144 
    145 # With large perf.data files, the tests will spew a lot of logging.  The
    146 # following calls will pipe the logging to a log file.  To see test logging,
    147 # build with 'FEATURES="test noclean"' and go to the build directory.
    148 check: $(TESTS)
    149 	for test in $(TESTS); do \
    150 			./$$test 2> ./$$test.stderr.log && continue; \
    151 			echo "See $$test.stderr.log for errors"; \
    152 		exit 1; \
    153 	done
    154 
    155 clean:
    156 	rm -f *.o *.d *.d.* *.a $(PROGRAMS) $(TESTS) $(GENERATED_SOURCES) \
    157 		$(GENERATED_HEADERS);
    158