1# This Makefile is for library maintainers, not end-developers.
2# All the generated code is already checked in.
3
4API_JSON = $(wildcard ../*/*/*-api.json ../*/*/*/*-api.json)
5
6GENERATOR=./google-api-go-generator
7
8# Download all API specifications and rebuild Go bindings.
9# All downloaded files are cached in $TMPDIR for reuse with 'cached' below.
10all: SHELL:=/bin/bash
11all: $(GENERATOR)
12	cd ../internal/version; go generate
13	$(GENERATOR) -cache=false -install -api=* -gendir=..
14	go test . -v
15
16# Reuse cached API specifications in $TMPDIR and rebuild Go bindings.
17cached: $(GENERATOR)
18	$(GENERATOR) -cache=true -install -api=* -gendir=..
19
20# Only rebuild Go bindings, do not modify API specifications.
21# For every existing */*/*-api.json file, */*/*-gen.go will be built.
22local: $(API_JSON:-api.json=-gen.go)
23
24# Pattern rule for the 'local' target.
25# Translates otherwise unnamed targets with a -gen.go suffix into the
26# matching input file with a -api.json suffix. $< is the input file.
27%-gen.go: %-api.json $(GENERATOR)
28	$(GENERATOR) -api_json_file=$< -output=$@
29
30# Alias to rebuild and install $(GENERATOR)
31generator: $(GENERATOR)
32
33# Marked as .PHONY so that make always invokes go build.
34$(GENERATOR):
35	go build -o $@
36
37.PHONY: all cached local generator $(GENERATOR)
38