2017-12-13 14 views
1

これは、メイクファイルです:このMakefileはどのように機能しますか?

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) 

私はログの最初の2行を理解することができます:

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 [email protected] $? 


streaming_transcribe: streaming_transcribe.o parse_arguments.o googleapis.ar 
    $(CXX) $^ $(LDFLAGS) -o [email protected] 

これは、ログの結果を生成します。どのようにこれらのファイル:

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

ファイルがコンパイルされますか?彼らは GOOGLEAPIS_CCS 変数に含まれているし、それが唯一

ar r [email protected] $? 

文字列でメイクファイルで使用されています。これが実際にどのように機能するかを段階的に説明できますか?

+0

メイクファイルがどこから来たのかを示すようにタイトルを更新すると、この質問を他のユーザーに検索しやすくすることができます。 – lockcmpxchg8b

答えて

4

次のルールが発見されたすべてのソース・ファイルをコンパイルからなり、オブジェクトファイルに依存して静的ライブラリを作る:この作品

googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o) 
    ar r [email protected] $? 

方法は$(GOOGLEAPIS_CCS:.cc=.o)は、「変数GOOGLEAPIS_CCSを取る意味で、その中には、のすべての出現を.o "と置き換えてください。つまり、検出されたソースのリストを、それらから生成されるオブジェクトファイルのリストに変換します。これは前提条件行にあるため、makeは、これらのオブジェクトの生成方法のルールを見つけようとします。

.oファイルをビルドするためのMakefileに明示的なルールはないので、makeは、暗黙的に定義された組み込みのパターンルールのうちの1つを使用します。具体的には:

%.o: %.cc 
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o [email protected] $^ 

このようにすると、出力に表示されるすべてのコンパイルが行われます。一旦これらがビルドされると、上で見てきたルールはそれらを静的ライブラリにアーカイブします。その静的ライブラリは、メインビルドターゲットの前提条件の1つです。これは、上記のすべてを評価するものです。

完全であるように、初期変数宣言のすべては$(shell find ...)を使用しています。これは、文字通りシェルを介してfindコマンドを実行して、指定されたディレクトリを再帰的に走査し、与えられたパターンに一致するファイルをリストする(例えば、*.cc)。その結果、これらの変数は一致するファイル名のリストとして定義されます。

+0

ありがとう!あなたは、どんな旗** - co **がやっていることを示唆することができますか? ** - c **はコンパイル用、** - o **はリンク用です。彼らはなぜ一緒に1か所にいますか? – Roman

+0

だから '-o'は"出力ファイルにこの名前を使う "という意味です。これは特にそれ自体をリンクするためのものではありませんが、それはあなたが通常それを気にかけているときです。 'g ++ 'がとにかく生成するデフォルトを指定するために使われるので、ここでは不要です。私は暗黙のパターンルールが '-o $ @'を使用することに少し驚いています。それを含めるように私の答えを更新します。 – lockcmpxchg8b

+2

makefileでコンパイルするときは常に '-o $ @'オプションを使うことをお勧めします。これにより、出力ファイルが期待通りのものになります。これは真でない場合には一般的な問題です。 'vpath'や' VPATH'がある場合、 '$ <'と '$ @'は組み込みのパターンルールであっても接尾辞を除いては同じではない可能性があることに注意してください。 – MadScientist

関連する問題