blob: e348fd85c25795a0901126509ecb71d3341167f3 [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 \
Mike Frysingerd70a9652016-03-17 04:14:27 -040018 -Ithird_party/googletest/googletest/include \
19 -Ithird_party/googletest/googlemock/include \
Jacob Marble7e724372016-01-07 16:16:47 -080020 -Ithird_party/libuweave \
21 -Ithird_party/modp_b64/modp_b64
22
23CFLAGS := \
24 -fno-exceptions \
25 -fPIC \
26 -fvisibility=hidden \
27 -Wall \
28 -Werror \
29 -Wextra \
Vitaly Buka50a147a2016-01-22 12:33:59 -080030 -Wformat=2 \
Jacob Marble7e724372016-01-07 16:16:47 -080031 -Wl,--exclude-libs,ALL \
Jacob Marble7e724372016-01-07 16:16:47 -080032 -Wno-missing-field-initializers \
Jacob Marble7e724372016-01-07 16:16:47 -080033 -Wno-unused-parameter \
Jacob Marble7e724372016-01-07 16:16:47 -080034
35CFLAGS_Debug := \
Jacob Marbleddb87592016-02-02 12:35:23 -080036 -O0 \
Jacob Marble7e724372016-01-07 16:16:47 -080037 -g3
38
39CFLAGS_Release := \
40 -Os
41
42CFLAGS_C := \
43 -std=c99
44
45CFLAGS_CC := \
46 -std=c++11
47
Jacob Marblef1ac1d42016-01-12 16:34:39 -080048comma := ,
49ifeq (1, $(CLANG))
50 CC = $(shell which clang-3.6)
51 CXX = $(shell which clang++-3.6)
52 CFLAGS := $(filter-out -Wl$(comma)--exclude-libs$(comma)ALL,$(CFLAGS))
53 CFLAGS += \
54 -fno-omit-frame-pointer \
Jacob Marblef1ac1d42016-01-12 16:34:39 -080055 -Wno-inconsistent-missing-override
56 ifeq (Debug, $(BUILD_MODE))
57 CFLAGS += \
58 -fsanitize=address
59 LDFLAGS += \
60 -fsanitize=address
61 endif
62endif
63
Vitaly Bukae0b0c6d2016-01-14 18:22:43 -080064# Headers dependencies.
65CFLAGS += -MMD
66OBJFILES = $(shell find out/$(BUILD_MODE)/ -type f -name '*.o')
67-include $(OBJFILES:.o=.d)
68
Vitaly Bukae03c0942016-01-22 20:16:21 -080069DEFS_TEST := \
70 $(DEFS_$(BUILD_MODE)) \
71 -DHAS_GTEST=1
72
Jacob Marble7e724372016-01-07 16:16:47 -080073###
74# libweave.so
75
76out/$(BUILD_MODE)/libweave.so : out/$(BUILD_MODE)/libweave_common.a
77 $(CXX) -shared -Wl,-soname=libweave.so -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive -lcrypto -lexpat -lpthread -lrt
78
Mike Frysinger3e4d8832016-03-22 17:49:53 -040079include cross.mk file_lists.mk third_party/third_party.mk examples/examples.mk tests.mk
Jacob Marblee785ec92016-01-13 13:49:44 -080080
Jacob Marble7e724372016-01-07 16:16:47 -080081###
82# src/
83
84weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
85
Vitaly Bukae03c0942016-01-22 20:16:21 -080086$(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc
Jacob Marble7e724372016-01-07 16:16:47 -080087 mkdir -p $(dir $@)
88 $(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
89
90out/$(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)
91 rm -f $@
92 $(AR) crsT $@ $^
93
Mike Frysingerd70a9652016-03-17 04:14:27 -040094all-libs : out/$(BUILD_MODE)/libweave.so
95all-tests : out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner
96
97all : all-libs all-examples all-tests
Jacob Marble7e724372016-01-07 16:16:47 -080098
99clean :
100 rm -rf out
101
Jacob Marble33135582016-01-28 10:29:23 -0800102cleanall : clean clean-gtest clean-libevhtp
Jacob Marble7e724372016-01-07 16:16:47 -0800103
104.PHONY : clean cleanall all
Jacob Marblec3d77142016-02-01 12:30:57 -0800105.DEFAULT_GOAL := all
Jacob Marble7e724372016-01-07 16:16:47 -0800106