From 8c79a1e3d10b125ec74441cf6dce30a3977f794e Mon Sep 17 00:00:00 2001 From: sjqzhang Date: Fri, 3 Nov 2023 14:47:48 +0800 Subject: [PATCH] modify Makefile --- Makefile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index cbdb733..625b10d 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,19 @@ BUILD_DIR=build APP_NAME=fileserver sources=$(wildcard *.go) +ifeq ($(wildcard md5),) +md5sum=md5 +else +md5sum=md5sum +endif + build = GOOS=$(1) GOARCH=$(2) go build -o ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2) -ldflags "-w -s -X 'main.VERSION=${VERSION}' -X 'main.GO_VERSION=${GO_VERSION}' -X 'main.GIT_VERSION=${COMMIT}' -X 'main.BUILD_TIME=${BUILDDATE}'" main.go -md5 = md5sum ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2) > ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2)_checksum.txt +#判断md5sum命令是否存在,如果存在则执行md5sum命令,否则执行md5命令 +ifeq ($(wildcard md5),) + md5 = md5 ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2) > ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2)_checksum.txt +else + md5 = md5sum ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2) > ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2)_checksum.txt +endif tar = tar -cvzf ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2).tar.gz -C ${BUILD_DIR} $(APP_NAME)-$(1)-$(2) $(APP_NAME)-$(1)-$(2)_checksum.txt delete = rm -rf ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2) ${BUILD_DIR}/$(APP_NAME)-$(1)-$(2)_checksum.txt @@ -24,22 +35,26 @@ PROTO_SRC_PATH =${ROOT_DIR}/rpc ALL_LINUX = linux-amd64 \ linux-386 \ linux-arm \ - linux-arm64 \ - linux-loong64 + linux-arm64 + +OTHER_LINUX = linux-loong64 ALL = $(ALL_LINUX) \ darwin-amd64 \ - darwin-arm64 + darwin-arm64 \ + $(OTHER_LINUX) + +.DEFAULT_GOAL := build_all build_linux: $(ALL_LINUX:%=build/%) build_all: $(ALL:%=build/%) build/%: - $(call build,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) - $(call md5,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) - $(call tar,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) - $(call delete,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) + -$(call build,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) + -$(call $md5sum,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) + -$(call tar,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) + -$(call delete,$(firstword $(subst -, , $*)),$(word 2, $(subst -, ,$*))) clean: rm -rf ${BUILD_DIR}