forked from brendanhay/terrafomo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (69 loc) · 2.32 KB
/
Copy pathMakefile
File metadata and controls
93 lines (69 loc) · 2.32 KB
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
ifndef GOPATH
$(error GOPATH is undefined)
endif
SHELL := /usr/bin/env bash
MODEL_DIR := terrafomo-gen/model
GO_TEMPLATE := terrafomo-go/main.go
GO_VENDOR := $(GOPATH)/src/github.com/terraform-providers/terraform-provider
STYLISH := ./bin/stylish-haskell
GENERATE := ./bin/terrafomo-gen
CONFIGS := stack.yaml .travis.yml
PROVIDERS = $(basename $(notdir $(wildcard terrafomo-gen/config/*.yaml)))
default: build
build: format
@$(MAKE) $(CONFIGS)
stack build --fast
haddock: format
stack build --fast --haddock
format: $(addprefix format-,$(PROVIDERS))
@echo -e '\nFormatting...'
@find $(wildcard terrafomo*/src) -type f -name '*.hs' -print0 | \
xargs -0 -I % sh -c 'echo " -> %"; $(STYLISH) -i "%"'
clean: $(addprefix clean-,$(PROVIDERS))
rm -f $(GENERATE)
rm -f $(shell find provider -type f -name 'package.yaml' | grep -v terrafomo-builtins)
rm -f $(wildcard provider/terrafomo-*/*.cabal)
rm -rf $(wildcard provider/*/gen)
script/generate
commit:
@script/commit-packages
.PHONY: $(GENERATE)
stack.yaml:
script/generate-stack
.travis.yml:
script/generate-stack
$(GENERATE):
stack build terrafomo-gen
$(STYLISH):
stack build --copy-bins stylish-haskell
$(MODEL_DIR):
mkdir -p $@
define package
$(shell sed -n 's/^package-name: \(.*\)/\1/p' terrafomo-gen/config/$1.yaml)
endef
define provider
.PHONY: $1
$1: format-$1
stack build --fast $(call package,$1)
generate-$1: $(GENERATE) $(GO_VENDOR)-$1 $(MODEL_DIR)/$1.json
$(GENERATE) \
--template-dir=terrafomo-gen/template \
--ir-dir=terrafomo-gen/ir \
--config-yaml=terrafomo-gen/config/$1.yaml \
--provider-json=$(MODEL_DIR)/$1.json
haddock-$1: format-$1
stack build --haddock --fast $(call package,$1)
format-$1: $(STYLISH) generate-$1
@echo -e '\nFormatting...'
@find provider/$(call package,$1)/gen -type f -name '*.hs' -print0 | \
xargs -0 -I % sh -c 'echo " -> %"; $(STYLISH) -i "%"'
clean-$1:
rm -rf $(GO_VENDOR)-$1/gen.go $(MODEL_DIR)/$1.json
$(GO_VENDOR)-$1:
git clone https://github.com/terraform-providers/terraform-provider-$1 $$@
$(GO_VENDOR)-$1/gen.go: $(GO_VENDOR)-$1 $(GO_TEMPLATE)
sed "s/replace_provider/$1/g" $(GO_TEMPLATE) > $$@
$(MODEL_DIR)/$1.json: $(GO_VENDOR)-$1/gen.go $(MODEL_DIR)
go run $(GO_VENDOR)-$1/gen.go > $$@
endef
$(foreach p,$(PROVIDERS),$(eval $(call provider,$p)))