forked from Viasat/nhd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
278 lines (229 loc) · 8.38 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#*******************************************************************************
#
# Mach3 NHD Makefile
#
# Makefile:
#
# Create dependecies, compile and link:
# "make all"
#
# Wipe out all backup files, object files, etc:
# "make distclean"
#
# NOTE: GNU Tools must be located in the $(GNU) directory.
# Object Generation Tools (compiler, linker, etc.) must be located
# in the $(BIN) directory.
#
# TAB NOTE: Although tabs are ugly, they MUST be present in this file for the
# GNU make utility to function properly. They are used for
# separation of targets and target commmands ONLY.
#
# Programmer: Tim Martin
# Modified by Cliff Burdick
# Creation Date: November 5 2019
#
#*******************************************************************************
REPO=CHANGEME
OS_FULLPATH=CHANGEME
NHD_VERSION:=$(shell cat nhd-version)
NHD_FULLPATH=$(REPO)nhd:$(NHD_VERSION)
NHD_LATEST_VERSION=latest
NHD_LATEST_FULLPATH=$(REPO)nhd:$(NHD_LATEST_VERSION)
#**********************************************************************
# Preamble stuff - Skip down to Setup Project
#**********************************************************************
ifndef CONFIG
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
CONFIG := LINUX
endif
ifeq ($(UNAME),Darwin)
CONFIG := OSX
endif
endif
ifndef CONFIG
$(error Unable to detect operating system, please manually define CONFIG)
endif
# Baseline empty, fill in with += later
PROTO_INCLUDE =
# Output directories
MAKEROOT := ./
OBJ = $(MAKEROOT)obj/
PROTO_OBJ = $(MAKEROOT)nhd/proto/
TMP = $(MAKEROOT)tmp/
#**********************************************************************
# Setup Project
#**********************************************************************
# GPRC compiler
# Source/include directories and setup main target
MAKEFILE = $(MAKEROOT)Makefile
NHD_SRC = $(MAKEROOT)nhd/
PROTO_SRC = $(NHD_SRC)proto/
NHD_WHEEL = dist/NHD-$(NHD_VERSION).tar.gz
TARGET = $(NHD_WHEEL)
# Docker dependencies can't be autogenerated...
DOCKER_DEPENDS = deploy/Dockerfile.nhd
DOCKER_DEPENDS += deploy/requirements.txt
all: $(TARGET)
#**********************************************************************
# gRPC proto compilation
#**********************************************************************
$(PROTO_OBJ)%_pb2.py \
$(PROTO_OBJ)%_pb2_grpc.py : $(PROTO_SRC)%.proto $(MAKEFILE)
$(ECHO) Processing [$<] to [$@]
$(PROTOC) -I $(PROTO_SRC) --python_out=$(PROTO_OBJ) --grpc_python_out=$(PROTO_OBJ) $<
$(PROTO_OBJ)__init__.py:
$(ECHO) [$@]
$(MKDIR) $(PROTO_OBJ)
$(ECHO) "import sys" >> $@
$(ECHO) "from pathlib import Path" >> $@
$(ECHO) "sys.path.append(str(Path(__file__).parent))" >> $@
GRPC_AUTOGEN_FILES += $(PROTO_OBJ)__init__.py
GRPC_AUTOGEN_FILES += $(patsubst $(PROTO_SRC)%.proto, $(PROTO_OBJ)%_pb2.py, $(foreach SUBDIR, $(PROTO_SRC), $(FIND_GRPC_PROTO_FILES)))
GRPC_AUTOGEN_FILES += $(patsubst $(PROTO_SRC)%.proto, $(PROTO_OBJ)%_pb2_grpc.py, $(foreach SUBDIR, $(PROTO_SRC), $(FIND_GRPC_PROTO_FILES)))
#**********************************************************************
#
# Shouldn't need to touch anything below here...
#
#**********************************************************************
#**********************************************************************
# Setup Portable Directory Locations
#**********************************************************************
ifeq ($(CONFIG),CYGWIN)
GNU = /bin/
CCBIN = /usr/bin/
BIN = /usr/bin/
endif
ifeq ($(CONFIG),LINUX)
GNU = /bin/
CCBIN = /usr/bin/
BIN = /usr/bin/
endif
ifeq ($(CONFIG),OSX)
GNU = /bin/
CCBIN = /usr/bin/
BIN = /usr/bin/
endif
#**********************************************************************
# Setup Compiler and Binutils
#**********************************************************************
CROSS_COMPILE =
PROTOC = @$(PROTO_COMPILER)
PROTOC = python3 -m grpc_tools.protoc
ECHO = @$(GNU)echo
CURL = @$(BIN)curl
RM = $(GNU)rm -f
MV = @$(GNU)mv
CP = @$(GNU)cp
CPP = @$(GNU)cpp
RMDIR = -$(GNU)rmdir
MKDEP = @$(BIN)$(CROSS_COMPILE)g++ -MM -MG -MP
MKDIR = @$(GNU)mkdir -p
WGET = @$(BIN)wget
INLINEWGET = $(BIN)wget
#**********************************************************************
# Setup Compiler and Linker flags
#**********************************************************************
PROTO_INCLUDE += $(foreach DIR, $(PROTO_SRC), -I $(DIR))
#**********************************************************************
# Setup Targets
#**********************************************************************
# Cleans up mostly object files
EDIT_DIRS = $(PROTO_SRC) $(NHD_SRC) $(MAKEROOT)
clean:
$(ECHO)
$(ECHO) Removing backup and temporary files
$(ECHO)
$(RM) $(foreach DIR, $(EDIT_DIRS), $(wildcard $(DIR)*.bak))
$(RM) $(foreach DIR, $(EDIT_DIRS), $(wildcard $(DIR)*.~*))
$(RM) $(foreach DIR, $(EDIT_DIRS), $(wildcard $(DIR)*.tmp))
$(RM) $(foreach DIR, $(EDIT_DIRS), $(wildcard $(DIR).*.swp))
$(ECHO)
$(ECHO) Removing protobufs/gRPC generated source files
$(ECHO)
$(RM) -r $(OBJ)__pycache__
$(RM) $(wildcard $(OBJ)*)
$(RM) $(PROTO_OBJ)*.py
$(RM) setup.py
$(ECHO)
# Cleans up all temporary files, including object files.
distclean: clean
$(ECHO)
$(ECHO) Removing files in TEMP directory
$(ECHO)
$(RM) $(wildcard $(TMP)*)
$(ECHO)
$(ECHO) Removing build/dist directories
$(ECHO)
$(RM) -r build
$(RM) -r dist
$(ECHO)
$(ECHO) Removing makefile generated directories
$(ECHO)
$(RM) -r $(TMP)
$(RM) -r $(OBJ)
#**********************************************************************
# All objects
#**********************************************************************
# GRPC Stuff
FIND_GRPC_PROTO_FILES = $(wildcard $(SUBDIR)*.proto)
GRPC_PROTO_FILES := $(foreach SUBDIR, $(PROTO_SRC), $(FIND_GRPC_PROTO_FILES))
FIND_NHD_FILES = $(wildcard $(DIR)*.py)
NHD_FILES := $(foreach DIR, $(NHD_SRC), $(FIND_NHD_FILES))
#**********************************************************************
# NHD Wheel
#**********************************************************************
NHD_WHEEL_DEPENDS = $(GRPC_AUTOGEN_FILES) $(NHD_FILES) setup_template.py nhd-version bin/nhd
$(NHD_WHEEL): $(MAKEFILE) $(NHD_WHEEL_DEPENDS)
$(RM) -r $(TMP)bdist
$(RM) -r $(BUILD_DIR)
$(CP) setup_template.py setup.py
sed -ri "s/.*version=.*/ version=\"$(NHD_VERSION)\",/g" setup.py
python3 setup.py sdist bdist_wheel
#**********************************************************************
# Makefile file generation
#**********************************************************************
$(TMP)tmpdir.txt:
$(ECHO) [$@]
$(MKDIR) $(dir $(TMP))
$(ECHO) "# This is the Temporary File Directory." > $@
$(OBJ)objdir.txt:
$(ECHO) [$@]
$(MKDIR) $(dir $(OBJ))
$(ECHO) "# This is the OBJ File Directory." > $@
#**********************************************************************
# Object Linking and Target Output
#**********************************************************************
.phony: release
.phony: docker
docker: $(TMP)docker
release: $(TMP)release
$(TMP)docker: $(DOCKER_DEPENDS) $(NHD_WHEEL)
docker build -f ./deploy/Dockerfile.nhd --build-arg OS_FULLPATH=$(OS_FULLPATH) --build-arg NHD_VERSION=$(NHD_VERSION) -t $(NHD_FULLPATH) ./
docker push $(NHD_FULLPATH)
touch $@
$(TMP)release: $(TMP)docker
docker tag $(NHD_FULLPATH) $(NHD_LATEST_FULLPATH)
docker push $(NHD_LATEST_FULLPATH)
touch $@
ifeq (, $(filter $(MAKECMDGOALS), clean distclean))
# Things to execute if we aren't cleaning/distcleaning
include $(TMP)tmpdir.txt
include $(OBJ)objdir.txt
-include $(DEPENDS)
endif
#**********************************************************************
# Help
#**********************************************************************
.phony: help
help:
$(ECHO) NHD_VERSION $(NHD_VERSION)
$(ECHO) EDIT_DIRS: $(EDIT_DIRS)
$(ECHO) PROTO_SRC: $(PROTO_SRC)
$(ECHO) NHD_SRC: $(NHD_SRC)
$(ECHO) GRPC_PROTO_FILES: $(GRPC_PROTO_FILES)
$(ECHO) GRPC_AUTOGEN_FILES: $(GRPC_AUTOGEN_FILES)
$(ECHO) NHD_FILES: $(NHD_FILES)
$(ECHO) NHD_FULLPATH: $(NHD_FULLPATH)
$(ECHO) NHD_LATEST_FULLPATH: $(NHD_LATEST_FULLPATH)
$(ECHO) NHD_VERSION: $(NHD_VERSION)