1
+ ROOT_DIR =$(shell pwd)
2
+ SPAWN_DIR =$(ROOT_DIR ) /spawn
3
+ SPAWN_PROTO_DIR =$(SPAWN_DIR ) /protos
4
+ SPAWN_PROTO_EXT_DIR =$(SPAWN_PROTO_DIR ) /eigr/functions/protocol/actors
5
+ GOOGLE_API_DIR =$(SPAWN_PROTO_DIR ) /google/api
6
+ GOOGLE_PROTOBUF_DIR =$(SPAWN_PROTO_DIR ) /google/protobuf
7
+ GRPC_DIR =$(SPAWN_PROTO_DIR ) /grpc/reflection/v1alpha
8
+ EXAMPLES_PROTO_DIR =$(ROOT_DIR ) /examples/protos
9
+ SPAWN_PROTO_OUT_DIR =$(SPAWN_DIR )
10
+ EXAMPLES_PROTO_OUT_DIR =$(ROOT_DIR ) /examples
11
+
12
+ IMAGE_NAME = eigr/spawn-example:latest
13
+ DOCKERFILE = Dockerfile
14
+
15
+ GO_CMD =go
16
+ GO_FLAGS =-v
17
+ GO_BUILD_FLAGS_DEBUG=-gcflags="all =-N -l"
18
+
19
+ # Diretório de saída para binários
20
+ BIN_DIR =./bin
21
+ EXAMPLES_BIN =$(BIN_DIR ) /examples/app
22
+ EXAMPLES_DIR =./examples
23
+
24
+ PROTOC =protoc
25
+ PROTOC_GEN_GO =$(shell go env GOPATH) /bin/protoc-gen-go
26
+
27
+ # Auxiliary variables
28
+ SPAWN_PROTO_FILES =$(wildcard $(SPAWN_PROTO_EXT_DIR ) /* .proto)
29
+ EXAMPLES_PROTO_FILES =$(wildcard $(EXAMPLES_PROTO_DIR ) /* .proto)
30
+
31
+ # Check if the Protobuf plugin is installed
32
+ $(PROTOC_GEN_GO ) :
33
+ @echo " Instalando protoc-gen-go..."
34
+ @go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
35
+
36
+ # Protobuf code generation for spawn
37
+ .PHONY : proto-spawn
38
+ proto-spawn : $(PROTOC_GEN_GO )
39
+ @echo " Generating Go code from spawn Protobuf files..."
40
+ @$(PROTOC ) \
41
+ --proto_path=$(SPAWN_PROTO_DIR ) \
42
+ --proto_path=$(GOOGLE_API_DIR ) \
43
+ --proto_path=$(GOOGLE_PROTOBUF_DIR ) \
44
+ --proto_path=$(GRPC_DIR ) \
45
+ --go_out=$(SPAWN_PROTO_OUT_DIR ) \
46
+ --go_opt=paths=source_relative \
47
+ $(SPAWN_PROTO_FILES )
48
+
49
+ # Protobuf code generation for examples
50
+ .PHONY : proto-examples
51
+ proto-examples : $(PROTOC_GEN_GO )
52
+ @echo " Generating Go code from the examples' Protobuf files..."
53
+ @$(PROTOC ) \
54
+ --proto_path=$(EXAMPLES_PROTO_DIR ) \
55
+ --proto_path=$(GOOGLE_API_DIR ) \
56
+ --proto_path=$(GOOGLE_PROTOBUF_DIR ) \
57
+ --go_out=$(EXAMPLES_PROTO_OUT_DIR ) \
58
+ --go_opt=paths=source_relative \
59
+ $(EXAMPLES_PROTO_FILES )
60
+
61
+ # Protobuf code generation for the entire project
62
+ .PHONY : proto
63
+ proto : proto-spawn proto-examples
64
+
65
+ # Spawn directory setup
66
+ .PHONY : setup-spawn
67
+ setup-spawn :
68
+ @echo " Setting dependencies for the spawn directory..."
69
+ @cd spawn && go mod tidy
70
+
71
+ # Examples directory setup
72
+ .PHONY : setup-examples
73
+ setup-examples :
74
+ @echo " Setting dependencies for the examples directory..."
75
+ @cd examples && go mod tidy
76
+
77
+ # Complete project setup
78
+ .PHONY : setup
79
+ setup : setup-spawn setup-examples
80
+
81
+ # Cleaning up files generated at spawn
82
+ .PHONY : clean-spawn
83
+ clean-spawn :
84
+ @echo " Removing files generated by Protobuf on spawn..."
85
+ @rm -f $(SPAWN_PROTO_OUT_DIR ) /* .pb.go
86
+
87
+ # Cleaning up files generated in the examples
88
+ .PHONY : clean-examples
89
+ clean-examples :
90
+ @echo " Removing Protobuf generated files in the examples..."
91
+ @rm -f $(EXAMPLES_PROTO_OUT_DIR ) /* .pb.go
92
+
93
+ # Cleaning the entire project
94
+ .PHONY : clean
95
+ clean : clean-spawn clean-examples
96
+
97
+ # Bbuild for the examples directory in development mode (debug)
98
+ build-debug :
99
+ @echo " Compiling the examples directory in debug mode..."
100
+ $(GO_CMD ) build $(GO_FLAGS ) $(GO_BUILD_FLAGS_DEBUG ) -o $(EXAMPLES_BIN ) $(EXAMPLES_DIR )
101
+ @echo " Build de debug finalizado em $( EXAMPLES_BIN) "
102
+
103
+ # Standard task to compile the examples
104
+ build : build-debug
105
+
106
+ # Task to run the generated binary
107
+ run :
108
+ @echo " Running the example binary..."
109
+ $(EXAMPLES_BIN )
110
+
111
+ # Task to compile the Dockerfile and generate the final image
112
+ docker-build :
113
+ docker build -t $(IMAGE_NAME ) -f $(DOCKERFILE ) .
114
+
115
+ # Task to run the binary inside the container
116
+ docker-run :
117
+ docker run --rm $(IMAGE_NAME )
0 commit comments