-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
153 lines (128 loc) · 5.62 KB
/
Makefile
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GRPC_SRC_PATH ?= ./grpc
GOOGLEAPIS_SRC_PATH ?= ./googleapis
GOOGLEAPIS_GENS_PATH ?= $(GOOGLEAPIS_SRC_PATH)/gens
GOOGLEAPIS_ASSISTANT_PATH = google/assistant/embedded/v1alpha2
PROTOC ?= protoc
PROTOC_PLUGINS_PATH ?= /usr/local/bin
GOOGLEAPIS_API_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/google/api \
-name '*.pb.cc')
GOOGLEAPIS_ASSISTANT_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH) \
-name '*.pb.cc')
GOOGLEAPIS_TYPE_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/google/type \
-name '*.pb.cc')
GOOGLEAPIS_RPC_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/google/rpc \
-name '*.pb.cc')
GOOGLEAPIS_CCS = $(GOOGLEAPIS_API_CCS) $(GOOGLEAPIS_RPC_CCS) $(GOOGLEAPIS_TYPE_CCS)
GOOGLEAPIS_ASSISTANT_CCS = $(GOOGLEAPIS_GENS_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH)/embedded_assistant.pb.cc \
$(GOOGLEAPIS_GENS_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH)/embedded_assistant.grpc.pb.cc
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
PKG_CONFIG ?= pkg-config
HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
ifeq ($(HAS_PKG_CONFIG),true)
GRPC_GRPCPP_CFLAGS=`pkg-config --cflags grpc++ grpc`
GRPC_GRPCPP_LDLAGS=`pkg-config --libs grpc++ grpc`
ALSA_CFLAGS=`pkg-config --cflags alsa`
ALSA_LDFLAGS=`pkg-config --libs alsa`
else
GRPC_GRPCPP_CFLAGS ?=
GRPC_GRPCPP_LDLAGS ?=
ALSA_CFLAGS ?=
ALSA_LDFLAGS ?=
endif
FLORA_CFLAGS ?= "-I/usr/local/include -I/usr/local/include/caps"
FLORA_LDFLAGS ?= "-L/usr/local/lib -lflora-cli -lcaps -lmisc -lrlog"
CPPFLAGS += -I$(GOOGLEAPIS_GENS_PATH) \
-I$(GRPC_SRC_PATH) \
-I./src
CXXFLAGS += -std=c++11 $(GRPC_GRPCPP_CFLAGS) $(FLORA_CFLAGS)
# grpc_cronet is for JSON functions in gRPC library.
ifeq ($(SYSTEM),Darwin)
LDFLAGS += $(GRPC_GRPCPP_LDLAGS) \
$(FLORA_LDFLAGS) \
-lgrpc++_reflection -lgrpc_cronet \
-lprotobuf -lpthread -ldl
else
LDFLAGS += $(GRPC_GRPCPP_LDLAGS) \
$(FLORA_LDFLAGS) \
-lgrpc_cronet -Wl,--no-as-needed -lgrpc++_reflection \
-Wl,--as-needed -lprotobuf -lpthread -ldl
endif
AUDIO_SRCS =
ifeq ($(SYSTEM),Linux)
AUDIO_SRCS += ./src/assistant/audio_input_alsa.cc ./src/assistant/audio_output_alsa.cc
CXXFLAGS += $(ALSA_CFLAGS)
LDFLAGS += $(ALSA_LDFLAGS)
endif
CORE_SRCS = ./src/assistant/base64_encode.cc ./src/assistant/json_util.cc
AUDIO_INPUT_FILE_SRCS = ./src/assistant/audio_input_file.cc
ASSISTANT_AUDIO_SRCS = ./src/assistant/run_assistant_audio.cc
ASSISTANT_FILE_SRCS = ./src/assistant/run_assistant_file.cc
ASSISTANT_TEXT_SRCS = ./src/assistant/run_assistant_text.cc
ASSISTANT_FLORA_SRCS = ./src/assistant/run_assistant_flora.cc ./src/assistant/audio_output_flora.cc
ASSISTANT_O = $(CORE_SRCS:.cc=.o) \
$(AUDIO_SRCS:.cc=.o) \
$(AUDIO_INPUT_FILE_SRCS:.cc=.o) \
$(ASSISTANT_AUDIO_SRCS:.cc=.o) \
$(ASSISTANT_FILE_SRCS:.cc=.o) \
$(ASSISTANT_TEXT_SRCS:.cc=.o) \
$(ASSISTANT_FLORA_SRCS:.cc=.o)
ASSISTANT_AUDIO_O = $(CORE_SRCS:.cc=.o) \
$(AUDIO_SRCS:.cc=.o) \
$(AUDIO_INPUT_FILE_SRCS:.cc=.o) \
$(ASSISTANT_AUDIO_SRCS:.cc=.o)
ASSISTANT_FILE_O = $(CORE_SRCS:.cc=.o) \
$(AUDIO_INPUT_FILE_SRCS:.cc=.o) \
$(ASSISTANT_FILE_SRCS:.cc=.o)
ASSISTANT_TEXT_O = $(CORE_SRCS:.cc=.o) \
$(ASSISTANT_TEXT_SRCS:.cc=.o)
ASSISTANT_FLORA_O = $(CORE_SRCS:.cc=.o) \
$(ASSISTANT_FLORA_SRCS:.cc=.o)
.PHONY: all
all: run_assistant
googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o)
$(AR) r $@ $?
.PHONY: run_assistant
run_assistant: run_assistant_audio run_assistant_file run_assistant_text run_assistant_flora
run_assistant_audio: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
$(ASSISTANT_AUDIO_O)
$(CXX) $^ $(LDFLAGS) -o $@
run_assistant_file: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
$(ASSISTANT_FILE_O)
$(CXX) $^ $(LDFLAGS) -o $@
run_assistant_text: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
$(ASSISTANT_TEXT_O)
$(CXX) $^ $(LDFLAGS) -o $@
run_assistant_flora: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
$(ASSISTANT_FLORA_O)
$(CXX) $^ $(LDFLAGS) -o $@
json_util_test: ./src/assistant/json_util.o ./src/assistant/json_util_test.o
$(CXX) $^ $(LDFLAGS) -o $@
$(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h) $(GOOGLEAPIS_ASSISTANT_CCS):
$(PROTOC) -I=$(GOOGLEAPIS_SRC_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH) --proto_path=.:$(GOOGLEAPIS_SRC_PATH) \
--cpp_out=$(GOOGLEAPIS_GENS_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH) \
--grpc_out=$(GOOGLEAPIS_GENS_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH) \
--plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_PATH)/grpc_cpp_plugin \
$(GOOGLEAPIS_SRC_PATH)/$(GOOGLEAPIS_ASSISTANT_PATH)/embedded_assistant.proto $^
.PHONY: protobufs
protobufs: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h) $(GOOGLEAPIS_ASSISTANT_CCS)
.PHONY: clean
clean:
rm -f run_assistant_text run_assistant_audio run_assistant_file googleapis.ar \
$(GOOGLEAPIS_CCS:.cc=.o) \
$(GOOGLEAPIS_ASSISTANT_CCS) $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h) \
$(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) \
$(ASSISTANT_O)