gpt4 book ai didi

linux - 这个 Makefile 是如何工作的?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:25 25 4
gpt4 key购买 nike

这是生成文件:

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 $@

它产生日志结果:

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)

我只能理解日志中的前两行。所有这些文件如何:

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

文件开始编译了吗?它们包含在 GOOGLEAPIS_CCS变量,它只在 makefile 中使用

ar r $@ $?

字符串。您能否逐步解释这实际上是如何工作的?

最佳答案

以下规则生成一个静态库,该库依赖于编译所有发现的源文件所产生的目标文件:

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

其工作方式是 $(GOOGLEAPIS_CCS:.cc=.o) 表示“获取变量 GOOGLEAPIS_CCS,并在其中替换 .cc.o”。也就是说,将发现的源列表转换为将从中生成的目标文件列表。因为这是先决条件行,make 将尝试找到如何生成这些对象的规则。

Makefile 中没有用于构建.o 文件的明确规则,因此make 将使用内置的隐式定义模式规则之一。具体来说:

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

所以这会导致您在输出中看到的所有编译。一旦这些被构建,我们在上面看到的规则将它们归档到一个静态库中。该静态库是主要构建目标的先决条件之一,这是触发对上述所有内容进行评估的原因。

这可能很明显,但为了完整起见,所有初始变量声明都使用 $(shell find ...)。这实际上是通过 shell 运行 find 命令以递归遍历指定目录,并列出与给定模式匹配的文件(例如,*.cc)。结果是这些变量被定义为匹配文件名的列表。

关于linux - 这个 Makefile 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47798125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com