sshpoke/Makefile

77 lines
2.5 KiB
Makefile
Raw Normal View History

2023-11-16 20:09:40 +03:00
SHELL = /bin/bash -o pipefail
export PATH := $(shell go env GOPATH)/bin:$(PATH)
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR=$(ROOT_DIR)/build
BIN=$(BUILD_DIR)/sshpoke
GO_VERSION=$(shell go version | sed -e 's/go version //')
2023-11-19 13:13:38 +03:00
VERSION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0.0-%h" -n 1 || echo "v0.0.0-unknown")
LDFLAGS="-X 'github.com/Neur0toxine/sshpoke/cmd.Version=${VERSION}'"
2023-11-16 20:09:40 +03:00
.PHONY: run clean_backend clone_sshlib
2023-11-16 20:09:40 +03:00
2023-11-22 23:31:35 +03:00
build: deps fmt
2023-11-16 20:09:40 +03:00
@echo " ► Building with ${GO_VERSION}"
2023-11-19 13:13:38 +03:00
@CGO_ENABLED=0 go build -tags=release -ldflags ${LDFLAGS} -o $(BIN) .
2023-11-16 20:09:40 +03:00
@echo $(BIN)
test: deps fmt
@echo " ► Running tests"
@go test -timeout 1m ./... -v -cpu 4
fmt:
@echo " ► Running gofmt"
@gofmt -l -s -w `go list -f '{{.Dir}}' ${ROOT_DIR}/... | grep -v /vendor/`
deps:
@echo " ► Installing dependencies"
@go mod tidy
@go mod vendor
run:
@$(BIN)
clean:
@rm -rf $(BUILD_DIR)
2023-11-17 20:39:00 +03:00
2023-11-22 23:31:35 +03:00
generate: install_swag install_protobuf
2023-11-17 20:39:00 +03:00
@echo " ► Performing code generation"
2023-11-22 23:31:35 +03:00
@cd $(ROOT_DIR) && go generate `go list -f '{{.Dir}}' ${ROOT_DIR}/... | grep -v /vendor/`
2023-11-17 20:39:00 +03:00
install_protobuf:
2023-11-22 23:31:35 +03:00
ifeq (, $(shell command -v protoc-gen-go 2> /dev/null))
@echo " ► Installing protoc-gen-go"
2023-11-17 20:39:00 +03:00
@go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
2023-11-22 23:31:35 +03:00
endif
ifeq (, $(shell command -v protoc-gen-go-grpc 2> /dev/null))
@echo " ► Installing protoc-gen-go-grpc"
2023-11-17 20:39:00 +03:00
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
2023-11-22 23:31:35 +03:00
endif
install_swag:
ifeq (, $(shell command -v swag 2> /dev/null))
@echo " ► Installing swag tool"
@go install github.com/swaggo/swag/cmd/swag@latest
endif
2023-11-18 21:51:44 +03:00
clone_cryptolib:
2023-11-18 21:51:44 +03:00
@rm -rf cryptolib && \
git clone https://go.googlesource.com/crypto cryptolib && \
mv cryptolib/internal/poly1305 cryptolib/ssh/internal/ && \
find cryptolib/ssh -type f -name '*.go' -exec sed -i 's?golang.org/x/crypto/ssh?github.com/Neur0toxine/sshpoke/pkg/proto/ssh?g' {} \; && \
find cryptolib/ssh -type f -name '*.go' -exec sed -i 's?golang.org/x/crypto/internal/poly1305?github.com/Neur0toxine/sshpoke/pkg/proto/ssh/internal/poly1305?g' {} \; && \
find cryptolib/ssh -type f -name '*_test.go' -delete && \
rm -rf cryptolib/ssh/test && \
rm -rf cryptolib/ssh/testdata
update_sshlib_patch:
@diff -Naru cryptolib/ssh pkg/proto/ssh > patch/ssh_proto_patches.patch
update_sshlib: clone_cryptolib
@mv pkg/proto/ssh pkg/proto/ssh.bak && \
2023-11-18 21:51:44 +03:00
mv cryptolib/ssh pkg/proto/ && \
patch -p0 < patch/ssh_proto_patches.patch && \
rm -rf pkg/proto/ssh.bak && \
2023-11-18 21:51:44 +03:00
rm -rf cryptolib