Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 1 | # Copyright 2015 The Weave 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 | # Run make with BUILD_MODE=Release for release. |
| 6 | BUILD_MODE ?= Debug |
| 7 | |
| 8 | DEFS_Debug := \ |
| 9 | -D_DEBUG |
| 10 | |
| 11 | DEFS_Release := \ |
| 12 | -DNDEBUG |
| 13 | |
| 14 | INCLUDES := \ |
| 15 | -I. \ |
| 16 | -Iinclude \ |
| 17 | -Ithird_party/chromium \ |
| 18 | -Ithird_party/include \ |
| 19 | -Ithird_party/libuweave \ |
| 20 | -Ithird_party/modp_b64/modp_b64 |
| 21 | |
| 22 | CFLAGS := \ |
| 23 | -fno-exceptions \ |
| 24 | -fPIC \ |
| 25 | -fvisibility=hidden \ |
| 26 | -Wall \ |
| 27 | -Werror \ |
| 28 | -Wextra \ |
Vitaly Buka | 50a147a | 2016-01-22 12:33:59 -0800 | [diff] [blame] | 29 | -Wformat=2 \ |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 30 | -Wl,--exclude-libs,ALL \ |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 31 | -Wno-missing-field-initializers \ |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 32 | -Wno-unused-parameter \ |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 33 | |
| 34 | CFLAGS_Debug := \ |
Jacob Marble | ddb8759 | 2016-02-02 12:35:23 -0800 | [diff] [blame] | 35 | -O0 \ |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 36 | -g3 |
| 37 | |
| 38 | CFLAGS_Release := \ |
| 39 | -Os |
| 40 | |
| 41 | CFLAGS_C := \ |
| 42 | -std=c99 |
| 43 | |
| 44 | CFLAGS_CC := \ |
| 45 | -std=c++11 |
| 46 | |
Jacob Marble | f1ac1d4 | 2016-01-12 16:34:39 -0800 | [diff] [blame] | 47 | comma := , |
| 48 | ifeq (1, $(CLANG)) |
| 49 | CC = $(shell which clang-3.6) |
| 50 | CXX = $(shell which clang++-3.6) |
| 51 | CFLAGS := $(filter-out -Wl$(comma)--exclude-libs$(comma)ALL,$(CFLAGS)) |
| 52 | CFLAGS += \ |
| 53 | -fno-omit-frame-pointer \ |
Jacob Marble | f1ac1d4 | 2016-01-12 16:34:39 -0800 | [diff] [blame] | 54 | -Wno-inconsistent-missing-override |
| 55 | ifeq (Debug, $(BUILD_MODE)) |
| 56 | CFLAGS += \ |
| 57 | -fsanitize=address |
| 58 | LDFLAGS += \ |
| 59 | -fsanitize=address |
| 60 | endif |
| 61 | endif |
| 62 | |
Vitaly Buka | e0b0c6d | 2016-01-14 18:22:43 -0800 | [diff] [blame] | 63 | # Headers dependencies. |
| 64 | CFLAGS += -MMD |
| 65 | OBJFILES = $(shell find out/$(BUILD_MODE)/ -type f -name '*.o') |
| 66 | -include $(OBJFILES:.o=.d) |
| 67 | |
Vitaly Buka | e03c094 | 2016-01-22 20:16:21 -0800 | [diff] [blame] | 68 | DEFS_TEST := \ |
| 69 | $(DEFS_$(BUILD_MODE)) \ |
| 70 | -DHAS_GTEST=1 |
| 71 | |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 72 | ### |
| 73 | # libweave.so |
| 74 | |
| 75 | out/$(BUILD_MODE)/libweave.so : out/$(BUILD_MODE)/libweave_common.a |
| 76 | $(CXX) -shared -Wl,-soname=libweave.so -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive -lcrypto -lexpat -lpthread -lrt |
| 77 | |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 78 | include file_lists.mk third_party/third_party.mk examples/examples.mk tests.mk |
| 79 | |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 80 | ### |
| 81 | # src/ |
| 82 | |
| 83 | weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o) |
| 84 | |
Vitaly Buka | e03c094 | 2016-01-22 20:16:21 -0800 | [diff] [blame] | 85 | $(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 86 | mkdir -p $(dir $@) |
| 87 | $(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $< |
| 88 | |
| 89 | out/$(BUILD_MODE)/libweave_common.a : $(weave_obj_files) $(third_party_chromium_base_obj_files) $(third_party_chromium_crypto_obj_files) $(third_party_modp_b64_obj_files) $(third_party_libuweave_obj_files) |
| 90 | rm -f $@ |
| 91 | $(AR) crsT $@ $^ |
| 92 | |
Vitaly Buka | e03c094 | 2016-01-22 20:16:21 -0800 | [diff] [blame] | 93 | all : out/$(BUILD_MODE)/libweave.so all-examples out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 94 | |
| 95 | clean : |
| 96 | rm -rf out |
| 97 | |
Jacob Marble | 3313558 | 2016-01-28 10:29:23 -0800 | [diff] [blame] | 98 | cleanall : clean clean-gtest clean-libevhtp |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 99 | |
| 100 | .PHONY : clean cleanall all |
Jacob Marble | c3d7714 | 2016-02-01 12:30:57 -0800 | [diff] [blame] | 101 | .DEFAULT_GOAL := all |
Jacob Marble | 7e72437 | 2016-01-07 16:16:47 -0800 | [diff] [blame] | 102 | |