11BUILD_CHANNEL? =local
2- TOOL_BIN = bin/gotools/$(shell uname -s) -$(shell uname -m)
3- PATH_WITH_TOOLS ="` pwd ` /$(TOOL_BIN ) :$(HOME ) /go/bin/:${PATH}"
4- GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
5- TAG_VERSION? =$(shell git tag --points-at | sort -Vr | head -n1)
6- GO_BUILD_LDFLAGS = -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
2+ TOOL_BIN := $(shell pwd) /bin/tools/$(shell uname -s) -$(shell uname -m)
3+ GIT_REVISION := $(shell git rev-parse HEAD | tr -d '\n')
4+ TAG_VERSION ?= $(shell git tag --points-at | sort -Vr | head -n1)
5+ GO_BUILD_LDFLAGS := -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
6+ SHELL := /usr/bin/env bash
7+ export PATH := $(TOOL_BIN ) :$(PATH )
8+ export GOBIN := $(TOOL_BIN )
9+
10+ ifneq (, $(shell which brew) )
11+ EXTRA_CMAKE_FLAGS := -DCMAKE_PREFIX_PATH=$(shell brew --prefix) -DQt5_DIR=$(shell brew --prefix qt5)/lib/cmake/Qt5
12+ export PKG_CONFIG_PATH := $(shell brew --prefix openssl@3)/lib/pkgconfig
13+ endif
14+
15+ default : build
716
8- ARTIFACT ="~/go/bin/artifact"
17+ artifact-pull : $(TOOL_BIN ) /artifact
18+ artifact pull
919
10- artifact-pull :
11- PATH= ${PATH_WITH_TOOLS} artifact pull
20+ $( TOOL_BIN ) / artifact :
21+ go install go.viam.com/utils/artifact/cmd/artifact
1222
13- bufinstall :
14- sudo apt-get install -y protobuf-compiler-grpc libgrpc-dev libgrpc++-dev || brew install grpc openssl --quiet
23+ $( TOOL_BIN ) /buf :
24+ go install github.com/bufbuild/buf/cmd/buf@v1.8.0
1525
16- bufsetup :
17- GOBIN= ` pwd ` /grpc/bin go install github.com/bufbuild/buf/cmd/buf@v1.8.0
18- ln -sf ` which grpc_cpp_plugin` grpc/bin /protoc-gen-grpc-cpp
26+ $( TOOL_BIN ) /protoc-gen-grpc-cpp :
27+ mkdir -p " $( TOOL_BIN ) "
28+ which grpc_cpp_plugin && ln -sf ` which grpc_cpp_plugin` $( TOOL_BIN ) /protoc-gen-grpc-cpp
1929
20- buf : bufsetup
21- PATH= " ${PATH} : ` pwd ` /grpc/bin " buf generate --template ./buf/buf.gen.yaml buf.build/viamrobotics/api
22- PATH= " ${PATH} : ` pwd ` /grpc/bin " buf generate --template ./buf/buf.grpc.gen.yaml buf.build/viamrobotics/api
23- PATH= " ${PATH} : ` pwd ` /grpc/bin " buf generate --template ./buf/buf.gen.yaml buf.build/googleapis/googleapis
30+ buf : $( TOOL_BIN ) /buf $( TOOL_BIN ) /protoc-gen-grpc-cpp
31+ buf generate --template ./buf/buf.gen.yaml buf.build/viamrobotics/api
32+ buf generate --template ./buf/buf.grpc.gen.yaml buf.build/viamrobotics/api
33+ buf generate --template ./buf/buf.gen.yaml buf.build/googleapis/googleapis
2434
2535clean :
26- rm -rf grpc
27- rm -rf bin
28- rm -rf viam-cartographer/build
29- rm -rf viam-cartographer/cartographer/build
36+ rm -rf grpc bin viam-cartographer/build
3037
3138clean-all :
3239 git clean -fxd
40+ cd viam-cartographer/cartographer && git checkout . && git clean -fxd
3341
3442ensure-submodule-initialized :
3543 @if [ ! -d " viam-cartographer/cartographer/cartographer" ]; then \
@@ -38,21 +46,8 @@ ensure-submodule-initialized:
3846 else \
3947 echo " Submodule found successfully" ; \
4048 fi
41-
42- lint-setup-cpp :
43- ifeq ("Darwin", "$(shell uname -s) ")
44- brew install clang-format
45- else
46- sudo apt-get install -y clang-format
47- endif
48-
49- lint-setup-go :
50- GOBIN=` pwd` /$(TOOL_BIN ) go install \
51- github.com/edaniels/golinters/cmd/combined \
52- github.com/golangci/golangci-lint/cmd/golangci-lint \
53- github.com/rhysd/actionlint/cmd/actionlint
54-
55- lint-setup : lint-setup-cpp lint-setup-go
49+ grep -q viam-patched viam-cartographer/cartographer/CMakeLists.txt || \
50+ (cd viam-cartographer/cartographer && git checkout . && git apply ../cartographer_patches/carto.patch)
5651
5752lint-cpp :
5853 find . -type f -not -path \
@@ -63,42 +58,46 @@ lint-cpp:
6358 -and \( -iname ' *.h' -o -iname ' *.cpp' -o -iname ' *.cc' \) \
6459 | xargs clang-format -i --style=" {BasedOnStyle: Google, IndentWidth: 4}"
6560
66- lint-go :
61+ lint-go : $( TOOL_BIN ) /combined $( TOOL_BIN ) /golangci-lint $( TOOL_BIN ) /actionlint
6762 go vet -vettool=$(TOOL_BIN ) /combined ./...
68- GOGC=50 $(TOOL_BIN ) /golangci-lint run -v --fix --config=./etc/golangci.yaml
69- PATH=$(PATH_WITH_TOOLS ) actionlint
63+ GOGC=50 golangci-lint run -v --fix --config=./etc/golangci.yaml
64+ actionlint
65+
66+ $(TOOL_BIN ) /combined $(TOOL_BIN ) /golangci-lint $(TOOL_BIN ) /actionlint :
67+ go install \
68+ github.com/edaniels/golinters/cmd/combined \
69+ github.com/golangci/golangci-lint/cmd/golangci-lint \
70+ github.com/rhysd/actionlint/cmd/actionlint
7071
7172lint : ensure-submodule-initialized lint-cpp lint-go
7273
73- setup : ensure-submodule-initialized
74- ifeq ("Darwin", "$(shell uname -s) ")
75- cd viam-cartographer/scripts && ./setup_cartographer_macos.sh
74+ setup : install-dependencies ensure-submodule-initialized artifact-pull
75+
76+ install-dependencies :
77+ ifneq (, $(shell which brew) )
78+ brew update
79+ brew install abseil boost ceres-solver protobuf ninja cairo googletest lua@5.3 pkg-config cmake go@1.20 grpc clang-format
80+ brew link lua@5.3
81+ brew install openssl@3 eigen gflags glog suite-sparse sphinx-doc pcl nlopt-static
82+ else ifneq (, $(shell which apt-get))
83+ $(warning "Installing cartographer external dependencies via APT.")
84+ $(warning "Packages may be too old to work with this project.")
85+ sudo apt-get update
86+ sudo apt-get install -y cmake ninja-build libgmock-dev libboost-iostreams-dev liblua5.3-dev libcairo2-dev python3-sphinx libnlopt-dev \
87+ libabsl-dev libceres-dev libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libpcl-dev libgrpc-dev libgrpc++-dev clang-format
7688else
77- cd viam-cartographer/scripts && ./setup_cartographer_linux.sh
78- endif
79- @make artifact-pull
80-
81- build : build-module
82- ifneq ($(wildcard viam-cartographer/cartographer/build/.) ,)
83- cd viam-cartographer && ./scripts/build_viam_cartographer.sh
84- else
85- cd viam-cartographer && ./scripts/build_cartographer.sh && ./scripts/build_viam_cartographer.sh
89+ $(error "Unsupported system. Only apt and brew currently supported.")
8690endif
8791
88- build-debug : build-module
89- ifneq ($(wildcard viam-cartographer/cartographer/build/.) ,)
90- cd viam-cartographer && ./scripts/build_viam_cartographer_debug.sh
91- else
92- cd viam-cartographer && ./scripts/build_cartographer.sh && ./scripts/build_viam_cartographer_debug.sh
93- endif
92+ build : ensure-submodule-initialized buf build-module
93+ cd viam-cartographer && cmake -Bbuild -G Ninja ${EXTRA_CMAKE_FLAGS} && cmake --build build
94+
95+ build-debug : EXTRA_CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug -DFORCE_DEBUG_BUILD=True
96+ build-debug : build
9497
9598build-module :
9699 mkdir -p bin && go build $(GO_BUILD_LDFLAGS ) -o bin/cartographer-module module/main.go
97100
98- install-lua-files :
99- sudo mkdir -p /usr/local/share/cartographer/lua_files/
100- sudo cp viam-cartographer/lua_files/* /usr/local/share/cartographer/lua_files/
101-
102101test-cpp :
103102 viam-cartographer/build/unit_tests -p -l all
104103
@@ -122,7 +121,11 @@ test-go:
122121
123122test : test-cpp test-go
124123
125- install :
124+ install-lua-files :
125+ sudo mkdir -p /usr/local/share/cartographer/lua_files/
126+ sudo cp viam-cartographer/lua_files/* /usr/local/share/cartographer/lua_files/
127+
128+ install : install-lua-files
126129 sudo rm -f /usr/local/bin/carto_grpc_server
127130 sudo rm -f /usr/local/bin/cartographer-module
128131 sudo cp viam-cartographer/build/carto_grpc_server /usr/local/bin/carto_grpc_server
0 commit comments