blob: 0eff8e1784a1e7899012902566a7da08b35a0ced [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
Mike Frysingerfcffce32016-04-06 16:22:42 -04005# Disable all builtin rules first as we don't use any of them (we define all
6# rules/targets ourselves, nor do we want to rely on them.
7MAKEFLAGS += --no-builtin-rules
8.SUFFIXES:
9
Jacob Marble7e724372016-01-07 16:16:47 -080010# Run make with BUILD_MODE=Release for release.
11BUILD_MODE ?= Debug
12
13DEFS_Debug := \
14 -D_DEBUG
15
16DEFS_Release := \
17 -DNDEBUG
18
19INCLUDES := \
20 -I. \
21 -Iinclude \
22 -Ithird_party/chromium \
Mike Frysingerd70a9652016-03-17 04:14:27 -040023 -Ithird_party/googletest/googletest/include \
24 -Ithird_party/googletest/googlemock/include \
Jacob Marble7e724372016-01-07 16:16:47 -080025 -Ithird_party/libuweave \
26 -Ithird_party/modp_b64/modp_b64
27
28CFLAGS := \
29 -fno-exceptions \
30 -fPIC \
31 -fvisibility=hidden \
32 -Wall \
33 -Werror \
34 -Wextra \
Vitaly Buka50a147a2016-01-22 12:33:59 -080035 -Wformat=2 \
Jacob Marble7e724372016-01-07 16:16:47 -080036 -Wl,--exclude-libs,ALL \
Jacob Marble7e724372016-01-07 16:16:47 -080037 -Wno-missing-field-initializers \
Jacob Marble7e724372016-01-07 16:16:47 -080038 -Wno-unused-parameter \
Jacob Marble7e724372016-01-07 16:16:47 -080039
40CFLAGS_Debug := \
Jacob Marbleddb87592016-02-02 12:35:23 -080041 -O0 \
Jacob Marble7e724372016-01-07 16:16:47 -080042 -g3
43
44CFLAGS_Release := \
45 -Os
46
47CFLAGS_C := \
48 -std=c99
49
50CFLAGS_CC := \
51 -std=c++11
52
Jacob Marblef1ac1d42016-01-12 16:34:39 -080053comma := ,
54ifeq (1, $(CLANG))
55 CC = $(shell which clang-3.6)
56 CXX = $(shell which clang++-3.6)
57 CFLAGS := $(filter-out -Wl$(comma)--exclude-libs$(comma)ALL,$(CFLAGS))
58 CFLAGS += \
59 -fno-omit-frame-pointer \
Jacob Marblef1ac1d42016-01-12 16:34:39 -080060 -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
Surender Kodam39b96b62016-03-28 16:15:57 -070084include cross.mk file_lists.mk third_party/third_party.mk examples/examples.mk tests.mk tests_schema/tests_schema.mk
Jacob Marblee785ec92016-01-13 13:49:44 -080085
Jacob Marble7e724372016-01-07 16:16:47 -080086###
87# src/
88
89weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
90
Vitaly Bukae03c0942016-01-22 20:16:21 -080091$(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc
Jacob Marble7e724372016-01-07 16:16:47 -080092 mkdir -p $(dir $@)
93 $(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
94
95out/$(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)
96 rm -f $@
97 $(AR) crsT $@ $^
98
Mike Frysingerd70a9652016-03-17 04:14:27 -040099all-libs : out/$(BUILD_MODE)/libweave.so
100all-tests : out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner
101
Surender Kodam39b96b62016-03-28 16:15:57 -0700102all : all-libs all-examples all-tests all-testdevices
Jacob Marble7e724372016-01-07 16:16:47 -0800103
104clean :
105 rm -rf out
106
Jacob Marble33135582016-01-28 10:29:23 -0800107cleanall : clean clean-gtest clean-libevhtp
Jacob Marble7e724372016-01-07 16:16:47 -0800108
109.PHONY : clean cleanall all
Jacob Marblec3d77142016-02-01 12:30:57 -0800110.DEFAULT_GOAL := all
Jacob Marble7e724372016-01-07 16:16:47 -0800111