blob: de69f40a9986bbb30483a23ebc3d722fb8ccbdc7 [file] [log] [blame]
Jacob Marble7e724372016-01-07 16:16:47 -08001# 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.
6BUILD_MODE ?= Debug
7
8DEFS_Debug := \
9 -D_DEBUG
10
11DEFS_Release := \
12 -DNDEBUG
13
14INCLUDES := \
15 -I. \
16 -Iinclude \
17 -Ithird_party/chromium \
18 -Ithird_party/include \
19 -Ithird_party/libuweave \
20 -Ithird_party/modp_b64/modp_b64
21
22CFLAGS := \
23 -fno-exceptions \
24 -fPIC \
25 -fvisibility=hidden \
26 -Wall \
27 -Werror \
28 -Wextra \
Vitaly Buka50a147a2016-01-22 12:33:59 -080029 -Wformat=2 \
Jacob Marble7e724372016-01-07 16:16:47 -080030 -Wl,--exclude-libs,ALL \
31 -Wno-char-subscripts \
Jacob Marble7e724372016-01-07 16:16:47 -080032 -Wno-missing-field-initializers \
33 -Wno-unused-local-typedefs \
34 -Wno-unused-parameter \
35 -Wpacked \
36 -Wpointer-arith \
37 -Wwrite-strings
38
39CFLAGS_Debug := \
40 -O0 \
41 -g3
42
43CFLAGS_Release := \
44 -Os
45
46CFLAGS_C := \
47 -std=c99
48
49CFLAGS_CC := \
50 -std=c++11
51
Jacob Marblef1ac1d42016-01-12 16:34:39 -080052comma := ,
53ifeq (1, $(CLANG))
54 CC = $(shell which clang-3.6)
55 CXX = $(shell which clang++-3.6)
56 CFLAGS := $(filter-out -Wl$(comma)--exclude-libs$(comma)ALL,$(CFLAGS))
57 CFLAGS += \
58 -fno-omit-frame-pointer \
59 -Wno-deprecated-register \
60 -Wno-inconsistent-missing-override
61 ifeq (Debug, $(BUILD_MODE))
62 CFLAGS += \
63 -fsanitize=address
64 LDFLAGS += \
65 -fsanitize=address
66 endif
67endif
68
Vitaly Bukae0b0c6d2016-01-14 18:22:43 -080069# Headers dependencies.
70CFLAGS += -MMD
71OBJFILES = $(shell find out/$(BUILD_MODE)/ -type f -name '*.o')
72-include $(OBJFILES:.o=.d)
73
Vitaly Bukae03c0942016-01-22 20:16:21 -080074DEFS_TEST := \
75 $(DEFS_$(BUILD_MODE)) \
76 -DHAS_GTEST=1
77
Jacob Marble7e724372016-01-07 16:16:47 -080078###
79# libweave.so
80
81out/$(BUILD_MODE)/libweave.so : out/$(BUILD_MODE)/libweave_common.a
82 $(CXX) -shared -Wl,-soname=libweave.so -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive -lcrypto -lexpat -lpthread -lrt
83
Jacob Marblee785ec92016-01-13 13:49:44 -080084include file_lists.mk third_party/third_party.mk examples/examples.mk tests.mk
85
Jacob Marble7e724372016-01-07 16:16:47 -080086###
87# src/
88
89weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
90
Jacob Marble2da7e942016-01-20 15:58:33 -080091# TODO(jacobmarble): There are too many gtest/gmock deps in non-test targets. Fix.
Vitaly Bukae03c0942016-01-22 20:16:21 -080092$(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc
Jacob Marble7e724372016-01-07 16:16:47 -080093 mkdir -p $(dir $@)
94 $(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
95
96out/$(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)
97 rm -f $@
98 $(AR) crsT $@ $^
99
Vitaly Bukae03c0942016-01-22 20:16:21 -0800100all : out/$(BUILD_MODE)/libweave.so all-examples out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner
Jacob Marble7e724372016-01-07 16:16:47 -0800101
102clean :
103 rm -rf out
104
105cleanall : clean clean-gtest clean-libevent
106
107.PHONY : clean cleanall all
108