-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
130 lines (99 loc) · 4.08 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0
# This Makefile serves to generate the gRPC interface and
# the related messages from .proto file.
# we want bash as shell
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x BASH_PATH="$(command -v bash)" ]; then echo $$BASH_PATH; \
else echo sh; fi; fi)
# Set O variable if not already done on the command line;
# or avoid confusing packages that can use the O=<dir> syntax for out-of-tree
# build by preventing it from being forwarded to sub-make calls.
ifneq ("$(origin O)", "command line")
O := $(CURDIR)/output
endif
# Remove the trailing '/.' from $(O) as it can be added by the makefile wrapper
# installed in the $(O) directory.
# Also remove the trailing '/' the user can set when on the command line.
override O := $(patsubst %/,%,$(patsubst %.,%,$(O)))
# Make sure $(O) actually exists before calling realpath on it; this is to
# avoid empty CANONICAL_O in case on non-existing entry.
CANONICAL_O := $(shell mkdir -p $(O) >/dev/null 2>&1)$(realpath $(O))
CANONICAL_CURDIR = $(realpath $(CURDIR))
PROTO_DIR = $(CANONICAL_CURDIR)/proto
RUST_LANG_DIR = $(CANONICAL_CURDIR)/rust
PYTHON_LANG_DIR = $(CANONICAL_CURDIR)/python
CPP_LANG_DIR = $(CANONICAL_CURDIR)/cpp
BASE_DIR := $(CANONICAL_O)
$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
# download-location
DL_DIR := $(shell mkdir -p $(BASE_DIR)/dl >/dev/null 2>&1)$(BASE_DIR)/dl
BUILD_DIR := $(BASE_DIR)/build
RUST_BUILD_DIR := $(BUILD_DIR)/rust
PYTHON_BUILD_DIR := $(BUILD_DIR)/python
CPP_BUILD_DIR := $(BUILD_DIR)/cpp
FILES=$(wildcard proto/astarteplatform/msghub/*.proto)
PROTOC_CHECK_SCRIPT=$(CANONICAL_CURDIR)/scripts/protoc_check.sh
RUST_LANG=$(RUST_BUILD_DIR)/astarte-message-hub-proto
RUST_CODEGEN_SCRIPT=$(CANONICAL_CURDIR)/scripts/rust_codegen.sh
PYTHON_LANG=$(PYTHON_BUILD_DIR)/astarteplatform
PYTHON_CODEGEN_SCRIPT=$(CANONICAL_CURDIR)/scripts/python_codegen.sh
CPP_LANG=$(CPP_BUILD_DIR)/astarteplatform
CPP_CODEGEN_SCRIPT=$(CANONICAL_CURDIR)/scripts/cpp_codegen.sh
# This is our default rule, so must come first
.PHONY: all
all : $(RUST_LANG) $(PYTHON_LANG) $(CPP_LANG)
$(RUST_LANG): $(FILES) $(RUST_CODEGEN_SCRIPT)
mkdir -p $(RUST_BUILD_DIR)
$(RUST_CODEGEN_SCRIPT) codegen $(PROTO_DIR) $(RUST_LANG_DIR) $(RUST_BUILD_DIR)
$(PYTHON_LANG): $(FILES) $(PYTHON_CODEGEN_SCRIPT)
mkdir -p $(PYTHON_BUILD_DIR)
$(PYTHON_CODEGEN_SCRIPT) codegen $(PROTO_DIR) $(PYTHON_LANG_DIR) $(PYTHON_BUILD_DIR) $(DL_DIR)
$(CPP_LANG): $(FILES) $(CPP_CODEGEN_SCRIPT)
mkdir -p $(CPP_BUILD_DIR)
$(CPP_CODEGEN_SCRIPT) codegen $(PROTO_DIR) $(CPP_LANG_DIR) $(CPP_BUILD_DIR)
.PHONY: protoc-check
protoc-check: $(PROTOC_CHECK_SCRIPT)
$(PROTOC_CHECK_SCRIPT)
.PHONY: rust
rust: protoc-check $(RUST_LANG)
.PHONY: python
python: protoc-check $(PYTHON_LANG)
.PHONY: cpp
cpp: protoc-check $(CPP_LANG)
.PHONY: rust-install
rust-install: $(RUST_LANG)
$(RUST_CODEGEN_SCRIPT) install_code $(RUST_BUILD_DIR) $(RUST_LANG_DIR)
.PHONY: python-install
python-install: $(PYTHON_LANG)
$(PYTHON_CODEGEN_SCRIPT) install_code $(PYTHON_BUILD_DIR) $(PYTHON_LANG_DIR)
.PHONY: cpp-install
cpp-install: $(CPP_LANG)
$(CPP_CODEGEN_SCRIPT) install_code $(CPP_BUILD_DIR) $(CPP_LANG_DIR)
.PHONY: install
install: rust-install python-install cpp-install
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: rust-dirclean
rust-dirclean:
rm -rf $(RUST_BUILD_DIR)
.PHONY: python-dirclean
python-dirclean:
rm -rf $(PYTHON_BUILD_DIR)
.PHONY: cpp-dirclean
cpp-dirclean:
rm -rf $(CPP_BUILD_DIR)
.PHONY: help
help:
@echo 'Cleaning:'
@echo ' clean - delete all files created by build'
@echo
@echo 'Build:'
@echo ' all - Build everything and generate the code for the various languages'
@echo ' install - Install files into repo folder'
@echo
@echo 'Language-specific:'
@echo ' <lang> - Build, install <lang> and all its dependencies and generate <lang> code'
@echo ' <lang>-install - Install <lang> files into the repo <lang> folder'
@echo ' <lang>-dirclean - Remove <lang> build directory'