简体   繁体   English

此Makefile如何工作?

[英]How does this Makefile work?

This is the makefile: 这是makefile:

GOOGLE_APPLICATION_CREDENTIALS=/home/roman/Documents/Google_Cloud/SpeechRec.json
GOOGLEAPIS_GENS_PATH=/home/roman/Downloads/GoogleAPIs/googleapis/gens

GOOGLEAPIS_GENS_PATH ?= $(HOME)/gitrepos/googleapis/gens
GOOGLEAPIS_API_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/google/api \
    -name '*.pb.cc')
GOOGLEAPIS_RPC_CCS = $(shell find $(GOOGLEAPIS_GENS_PATH)/google/rpc \
    -name '*.pb.cc')
GOOGLEAPIS_SPEECH_CCS = $(shell find \
    $(GOOGLEAPIS_GENS_PATH)/google/cloud/speech -name '*.pb.cc')
GOOGLEAPIS_LONGRUNNING_CCS = $(shell find \
    $(GOOGLEAPIS_GENS_PATH)/google/longrunning -name '*.pb.cc')
GOOGLEAPIS_CCS = $(GOOGLEAPIS_API_CCS) $(GOOGLEAPIS_RPC_CCS) \
    $(GOOGLEAPIS_LONGRUNNING_CCS) $(GOOGLEAPIS_SPEECH_CCS)

HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
CPPFLAGS += -I/usr/local/include -pthread -I$(GOOGLEAPIS_GENS_PATH) -g -O0
CXXFLAGS += -std=c++11 -g -O0
ifeq ($(SYSTEM),Darwin)
LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++ grpc`       \
           -lgrpc++_reflection                                    \
           -lprotobuf -lpthread -ldl
else
LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++ grpc`       \
           -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
           -lprotobuf -lpthread -ldl
endif

.PHONY: all

#all: transcribe async_transcribe streaming_transcribe streaming_transcribe_singlethread
all: streaming_transcribe

googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o)
    ar r $@ $?


streaming_transcribe: streaming_transcribe.o parse_arguments.o googleapis.ar
    $(CXX) $^ $(LDFLAGS) -o $@

It produces log result: 它产生日志结果:

23:20:19 **** Build of configuration Build (GNU) for project GoogleSpeechApi ****
make all 
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o streaming_transcribe.o streaming_transcribe.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o parse_arguments.o parse_arguments.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/log.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/log.grpc.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.grpc.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.grpc.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.grpc.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.grpc.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.pb.cc
g++ -std=c++11 -g -O0 -I/usr/local/include -pthread -I/home/roman/Downloads/GoogleAPIs/googleapis/gens -g -O0  -c -o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/httpbody.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/httpbody.grpc.pb.cc

ar r googleapis.ar /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/log.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/authorization_config.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/experimental/experimental.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/servicemanager.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicemanagement/v1/resources.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/httpbody.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/label.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/billing.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/quota_controller.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/service_controller.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/log_entry.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/metric_value.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/operation.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/operation.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/check_error.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/quota_controller.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/log_entry.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/check_error.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/metric_value.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/distribution.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/distribution.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/servicecontrol/v1/service_controller.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/httpbody.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/consumer.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/billing.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/config_change.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/monitored_resource.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/http.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/backend.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/documentation.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/metric.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/system_parameter.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/consumer.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/control.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/documentation.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/monitored_resource.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/logging.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/http.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/backend.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/annotations.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/auth.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/usage.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/metric.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/service.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/usage.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/log.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/service.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/auth.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/source_info.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/endpoint.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/endpoint.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/quota.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/system_parameter.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/annotations.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/context.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/logging.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/distribution.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/config_change.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/source_info.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/distribution.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/monitoring.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/control.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/quota.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/monitoring.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/label.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/api/context.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/error_details.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/status.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/code.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/code.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/status.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/rpc/error_details.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/longrunning/operations.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/longrunning/operations.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1beta1/cloud_speech.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1beta1/cloud_speech.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1/cloud_speech.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1/cloud_speech.grpc.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1_1beta1/cloud_speech.pb.o /home/roman/Downloads/GoogleAPIs/googleapis/gens/google/cloud/speech/v1_1beta1/cloud_speech.grpc.pb.o
ar: creating googleapis.ar
g++ streaming_transcribe.o parse_arguments.o googleapis.ar -L/usr/local/lib `pkg-config --libs grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -lprotobuf -lpthread -ldl -o streaming_transcribe

23:23:26 Build Finished (took 3m:7s.68ms)

I can only understand first two lines in the log. 我只能理解日志中的前两行。 How all this files: 所有这些文件如何:

/home/roman/Downloads/GoogleAPIs/googleapis/gens/google

files get to compiling? 文件开始编译? They are contained in GOOGLEAPIS_CCS variable and it is only used in makefile in 它们包含在GOOGLEAPIS_CCS变量中,并且仅在

ar r $@ $?

string. 串。 Can you explain step by step how this actually work? 您能否逐步说明这是如何工作的?

The following rule makes a static library that depends on the object files that will result from compiling all of the discovered source files: 以下规则创建了一个静态库,该库依赖于编译所有发现的源文件所产生的目标文件:

googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o)
    ar r $@ $?

The way this works is that $(GOOGLEAPIS_CCS:.cc=.o) means "take the variable GOOGLEAPIS_CCS , and within it, replace every occurance of .cc with .o ". 其工作方式是$(GOOGLEAPIS_CCS:.cc=.o)意味着“采用变量GOOGLEAPIS_CCS ,并在其中将所有出现的.cc替换为.o ”。 That is, convert the discovered lists of sources into a list of the object files that will be generated from them. 也就是说,将发现的源列表转换为将从其生成的目标文件列表。 Because this is on the prerequisite line, make will try to find a rule for how to produce these objects. 因为这是前提条件,所以make会尝试找到有关如何产生这些对象的规则。

There are no explicit rules in the Makefile for building the .o files, so make will use one of the built-in implicitly defined pattern rules. Makefile中没有用于构建.o文件的显式规则,因此make将使用内置的隐式定义的模式规则之一。 Specifically: 特别:

%.o: %.cc
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $^

So that causes all of the compilation you see in your output. 因此,这将导致您在输出中看到的所有编译。 Once these are built, the rule we were looking at above archives them into a static library. 一旦构建完成,我们上面所看的规则会将它们存档到静态库中。 That static library is one of the prerequisites for the main build target, which is what triggers all of the above to be evaluated. 该静态库是主要构建目标的先决条件之一,这是触发所有上述评估的原因。

It may be obvious, but for completeness, all of the initial variable declartions use $(shell find ...) . 可能很明显,但是为了完整起见,所有初始变量声明都使用$(shell find ...) This literally runs the find command via the shell to recursively traverse the specified directory, and list the files that match the given pattern (eg, *.cc ). 这实际上通过外壳运行find命令以递归地遍历指定目录,并列出与给定模式匹配的文件(例如*.cc )。 The result is that these variables are defined as the list of matching filenames. 结果是将这些变量定义为匹配文件名的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM