forked from cartesi/server-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
169 lines (135 loc) · 6.2 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
# Copyright 2023 Cartesi Pte. Ltd.
#
# SPDX-License-Identifier: Apache-2.0
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
UNAME:=$(shell uname)
# Install settings
PREFIX= /opt/cartesi
BIN_INSTALL_PATH= $(PREFIX)/bin
LIB_INSTALL_PATH= $(PREFIX)/lib
INSTALL_PLAT = install-$(UNAME)
INSTALL= cp -RP
CHMOD_EXEC= chmod 0755
STRIP_EXEC= strip -x
SERVER_MANAGER_TO_BIN= server-manager
# Build settings
DEPDIR := third-party
SRCDIR := $(abspath src)
BUILDBASE := $(abspath build)
BUILDDIR = $(BUILDBASE)/$(UNAME)_$(shell uname -m)
SUBCLEAN := $(addsuffix .clean,$(SRCDIR))
DEPDIRS := $(addprefix $(DEPDIR)/,grpc)
DEPCLEAN := $(addsuffix .clean,$(DEPDIRS))
SERVER_MANAGER_PROTO := lib/grpc-interfaces/server-manager.proto
GRPC_VERSION ?= v1.50.0
# Docker image settings
TAG ?= devel
EMULATOR_TAG ?= 0.14.0
EMULATOR_REPOSITORY ?= cartesi/machine-emulator
# Mac OS X specific settings
ifeq ($(UNAME),Darwin)
LUA_PLAT ?= macosx
export CC = clang
export CXX = clang++
LIBRARY_PATH := "export DYLD_LIBRARY_PATH=$(BUILDDIR)/lib"
LIB_EXTENSION = dylib
DEP_TO_LIB += *.$(LIB_EXTENSION)
# Linux specific settings
else ifeq ($(UNAME),Linux)
LIBRARY_PATH := "export LD_LIBRARY_PATH=$(BUILDDIR)/lib:$(SRCDIR)"
LIB_EXTENSION := so
DEP_TO_LIB += *.$(LIB_EXTENSION)*
# Unknown platform
else
LIB_EXTENSION := dll
DEP_TO_LIB += *.$(LIB_EXTENSION)
endif
# Check if some binary dependencies already exists on build directory to skip
# downloading and building them.
DEPBINS := $(addprefix $(BUILDDIR)/,lib/libgrpc.$(LIB_EXTENSION))
all: source-default
env:
@echo $(LIBRARY_PATH)
@echo "export PATH='$(SRCDIR):$(BUILDDIR)/bin:/opt/cartesi/bin:${PATH}'"
@echo "export LUA_CPATH='./?.so;$(SRCDIR)/?.so;/opt/cartesi/lib/lua/5.3/?.so;$$(lua5.3 -e 'print(package.cpath)')'"
@echo "export LUA_PATH='./?.lua;$(SRCDIR)/?.lua;/opt/cartesi/share/lua/5.3/?.lua;$$(lua5.3 -e 'print(package.path)')'"
doc:
cd doc && doxygen Doxyfile
help:
@echo 'Common targets:'
@echo '* all - build the src/ code. To build from a clean clone, run: make submodules dep all'
@echo ' submodules - initialize and update submodules'
@echo ' dep - build dependencies'
@echo ' create-machines - create machines for the server-manager tests'
@echo ' test - run server-manager tests'
@echo ' create-and-test - create machines for the server-manager tests'
@echo ' doc - build the doxygen documentation (requires doxygen to be installed)'
@echo 'Docker targets:'
@echo ' image - Build the server-manager docker image'
@echo 'Cleaning targets:'
@echo ' clean - clean the src/ artifacts'
@echo ' depclean - clean + dependencies'
@echo ' distclean - depclean + profile information'
@echo ' clean-machines - clean machines created for the server-manager tests'
$(BUILDDIR) $(BIN_INSTALL_PATH) $(LIB_INSTALL_PATH) $(IMAGES_INSTALL_PATH):
mkdir -m 0755 -p $@
dep: $(DEPBINS)
@rm -f $(BUILDDIR)/lib/*.a
@$(STRIP_EXEC) \
$(BUILDDIR)/bin/grpc* \
$(BUILDDIR)/bin/protoc* \
$(BUILDDIR)/lib/*.$(LIB_EXTENSION)*
submodules:
git submodule update --init --recursive
$(SERVER_MANAGER_PROTO):
$(info gprc-interfaces submodule not initialized!)
@exit 1
test server-manager: | $(SERVER_MANAGER_PROTO)
test lint coverage-report check-format format server-manager create-machines create-and-test clean-machines run-test-server-manager:
@eval $$($(MAKE) -s --no-print-directory env); $(MAKE) -C $(SRCDIR) $@
source-default:
@eval $$($(MAKE) -s --no-print-directory env); $(MAKE) -C $(SRCDIR)
image:
docker build -t cartesi/server-manager:$(TAG) -f Dockerfile --build-arg EMULATOR_REPOSITORY=$(EMULATOR_REPOSITORY) --build-arg EMULATOR_TAG=$(EMULATOR_TAG) .
installer-stage-image:
docker build --target installer -t cartesi/server-manager:installer -f Dockerfile --build-arg EMULATOR_REPOSITORY=$(EMULATOR_REPOSITORY) --build-arg EMULATOR_TAG=$(EMULATOR_TAG) .
$(DEPDIR)/grpc $(BUILDDIR)/lib/libgrpc.$(LIB_EXTENSION): | $(BUILDDIR)
if [ ! -d $(DEPDIR)/grpc ]; then git clone --branch $(GRPC_VERSION) --depth 1 https://github.com/grpc/grpc.git $(DEPDIR)/grpc; fi
cd $(DEPDIR)/grpc && git submodule update --init --recursive --depth 1
mkdir -p $(DEPDIR)/grpc/cmake/build && cd $(DEPDIR)/grpc/cmake/build && cmake -C $(abspath $(DEPDIR))/grpc.cmake -DCMAKE_INSTALL_PREFIX=$(BUILDDIR) ../..
$(MAKE) -C $(DEPDIR)/grpc/cmake/build all install
mkdir -p $(BUILDDIR)/share/grpc/health/v1/ && cp -a $(DEPDIR)/grpc/src/proto/grpc/health/v1/health.proto $(BUILDDIR)/share/grpc/health/v1/
if [ "$(UNAME)" = "Darwin" ]; then install_name_tool -add_rpath @loader_path/../lib $(BUILDDIR)/bin/grpc_cpp_plugin; fi
$(SUBCLEAN) $(DEPCLEAN): %.clean:
$(MAKE) -C $* clean
clean: $(SUBCLEAN)
depclean: $(DEPCLEAN) clean
rm -rf $(BUILDDIR)
distclean: clean clean-profile
rm -rf $(BUILDBASE) $(DEPDIRS)
clean-profile:
$(MAKE) -C $(SRCDIR) $@
install-Darwin: install-strip
cd $(BIN_INSTALL_PATH) && \
for x in $(SERVER_MANAGER_TO_BIN); do \
install_name_tool -delete_rpath $(BUILDDIR)/lib -delete_rpath $(SRCDIR) -add_rpath $(LIB_INSTALL_PATH) $$x ;\
done
install-Linux: install-strip
cd $(BIN_INSTALL_PATH) && for x in $(SERVER_MANAGER_TO_BIN); do patchelf --set-rpath $(LIB_INSTALL_PATH) $$x ; done
install-binary: $(BIN_INSTALL_PATH)
cd src && $(INSTALL) $(SERVER_MANAGER_TO_BIN) $(BIN_INSTALL_PATH)
cd $(BIN_INSTALL_PATH) && $(CHMOD_EXEC) $(SERVER_MANAGER_TO_BIN)
install-strip: install-binary
cd $(BIN_INSTALL_PATH) && $(STRIP_EXEC) $(SERVER_MANAGER_TO_BIN)
install: $(INSTALL_PLAT)
.SECONDARY: $(DEPDIRS) $(SERVER_MANAGER_PROTO)
.PHONY: help all submodules doc clean distclean clean-profile downloads src test \
$(SUBDIRS) $(SUBCLEAN) $(DEPCLEAN)