aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 0eff8e1784a1e7899012902566a7da08b35a0ced (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2015 The Weave Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Disable all builtin rules first as we don't use any of them (we define all
# rules/targets ourselves, nor do we want to rely on them.
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:

# Run make with BUILD_MODE=Release for release.
BUILD_MODE ?= Debug

DEFS_Debug := \
	-D_DEBUG

DEFS_Release := \
	-DNDEBUG

INCLUDES := \
	-I. \
	-Iinclude \
	-Ithird_party/chromium \
	-Ithird_party/googletest/googletest/include \
	-Ithird_party/googletest/googlemock/include \
	-Ithird_party/libuweave \
	-Ithird_party/modp_b64/modp_b64

CFLAGS := \
	-fno-exceptions \
	-fPIC \
	-fvisibility=hidden \
	-Wall \
	-Werror \
	-Wextra \
	-Wformat=2 \
	-Wl,--exclude-libs,ALL \
	-Wno-missing-field-initializers \
	-Wno-unused-parameter \

CFLAGS_Debug := \
	-O0 \
	-g3

CFLAGS_Release := \
	-Os

CFLAGS_C := \
	-std=c99

CFLAGS_CC := \
	-std=c++11

comma := ,
ifeq (1, $(CLANG))
  CC = $(shell which clang-3.6)
  CXX = $(shell which clang++-3.6)
  CFLAGS := $(filter-out -Wl$(comma)--exclude-libs$(comma)ALL,$(CFLAGS))
  CFLAGS += \
    -fno-omit-frame-pointer \
    -Wno-inconsistent-missing-override
  ifeq (Debug, $(BUILD_MODE))
    CFLAGS += \
      -fsanitize=address
    LDFLAGS += \
      -fsanitize=address
  endif
endif

# Headers dependencies.
CFLAGS += -MMD
OBJFILES = $(shell find out/$(BUILD_MODE)/ -type f -name '*.o')
-include $(OBJFILES:.o=.d)

DEFS_TEST := \
	$(DEFS_$(BUILD_MODE)) \
	-DHAS_GTEST=1

###
# libweave.so

out/$(BUILD_MODE)/libweave.so : out/$(BUILD_MODE)/libweave_common.a
	$(CXX) -shared -Wl,-soname=libweave.so -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive -lcrypto -lexpat -lpthread -lrt

include cross.mk file_lists.mk third_party/third_party.mk examples/examples.mk tests.mk tests_schema/tests_schema.mk

###
# src/

weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)

$(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc
	mkdir -p $(dir $@)
	$(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<

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)
	rm -f $@
	$(AR) crsT $@ $^

all-libs : out/$(BUILD_MODE)/libweave.so
all-tests : out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner

all : all-libs all-examples all-tests all-testdevices

clean :
	rm -rf out

cleanall : clean clean-gtest clean-libevhtp

.PHONY : clean cleanall all
.DEFAULT_GOAL := all