-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
56 lines (41 loc) · 1.8 KB
/
Makefile
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
export WEL_HOME := $(shell pwd)
export GOPATH := $(WEL_HOME)/go
export GOSRC := $(GOPATH)/src
export GOPKG := $(GOPATH)/pkg
export TZ := UTC
SHELL = /bin/bash
.PHONY: all commands services tools fe
all: tools commands services fe
# Infer Go commands based on the pattern wel/commands/<cmd>/main/<cmd>.go
CMD_PKGS := $(subst ./,,$(shell cd $(GOSRC) && find . -type f -regex '.*/wel/commands/[^/]*/main/[^/]*\.go' | awk -F/main/ '{print $$1"/main"}' | uniq))
CMDS := $(sort $(foreach pkg,$(CMD_PKGS),$(lastword $(subst /, ,$(patsubst %/main,%,$(pkg))))))
# Infer Go services based on the pattern wel/services/<svc>/main/<cmd>.go
SVC_PKGS := $(subst ./,,$(shell cd $(GOSRC) && find . -type f -regex '.*/wel/services/[^/]*/main/[^/]*\.go' | awk -F/main/ '{print $$1"/main"}' | uniq))
SVCS := $(sort $(foreach pkg,$(SVC_PKGS),$(lastword $(subst /, ,$(patsubst %/main,%,$(pkg))))))
.PHONY: $(CMDS) $(SVCS)
# A recipe for each inferred go main binary.
# $1 is the simple name (e.g. colluder)
# $2 is the package name (e.g. wel/servivces/colluder/main)
define make-go-recipe
.PHONY: $1
$1:
go build -i -o $(WEL_HOME)/go/bin/$1 -ldflags="$(LDFLAGS)" $2
endef
$(eval $(foreach pkg,$(CMD_PKGS),$(call make-go-recipe,$(lastword $(subst /, ,$(patsubst %/main,%,$(pkg)))),$(pkg))))
$(eval $(foreach pkg,$(SVC_PKGS),$(call make-go-recipe,$(lastword $(subst /, ,$(patsubst %/main,%,$(pkg)))),$(pkg))))
commands: $(CMDS)
services: $(SVCS)
tools:
go build -o $(WEL_HOME)/go/bin/gorepoman github.com/fullstorydev/gorepoman/main/gorepoman
fe:
cd fe && npm run build
help:
@echo "This makefile can build the following:"
@echo " Commands:"
@$(foreach c,$(CMDS),echo " ${c}";)
@echo " Services:"
@$(foreach c,$(SVCS),echo " ${c}";)
clean:
rm -rf $(GOPATH)/bin/*
rm -rf $(GOPKG)/*
rm -rf ./fe/dist