windows下使用make命令(makefile)

今天讲一讲windows下如何使用make命令

在学kratos时发现有个很好用的命令,即make,比如:

make api

但是你会发现这东西默认只能在linux和Mac上能用,作为windows用户就很难受了,那么要怎么在windows使用make命令呢?,你要是不难受就敲完整命令吧,比如($(API_PROTO_FILES)即你的proto文件路径):

protoc --proto_path=./api \
    --proto_path=./third_party \
    --go_out=paths=source_relative:./api \
    --go-http_out=paths=source_relative:./api \
    --go-grpc_out=paths=source_relative:./api \
    --openapi_out=fq_schema_naming=true,default_response=false:. \
    $(API_PROTO_FILES)

反正我是受不了,为啥别人Mac能用,我不能用,就因为我买不起Mac吗,我不服。

解决方案:

1、首先下载MinGw(干什么用的自行百度):Download MinGW - Minimalist GNU for Windows from SourceForge.net

2、点击安装后打开将Base Setup全部mark,然后点击installation->Apply Changes,等待安装完就行(时间可能有点长)。

3、然后将bin目录添加进环境变量,比如我的路径是C:\MinGW\bin,该目录下有一个mingw-get.exe,这就是我上面说的命令可执行文件了。

4、作为有强迫症的我肯定不愿意执行mingw-get这样的命令,我是想用make这样的命令,所以复制一份mingw-get.exe,将其改为make.exe,到此为止就大功告成了。

5、但是有时候你在kratos里执行make api时会发现要报错,他会提示C:\不是内部或外部命令,也不是可运行的程序,这里是因为你的git安装到的是默认目录,即C:\Program Files\Git,因为实际上kratos里的makefile文件里用到了Git_Bash,而这个路径正好是你的git-bash.exe的路径,可能是C:\Program Files\Git这个路径Program Files中空格无法解析的原因(我猜的),我的方法就是将Git重新安装,然后自定义目录,如C:\install\Git,这样就完美解决了。

GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
​
ifeq ($(GOHOSTOS), windows)
    #the `find.exe` is different from `find` in bash/shell.
    #to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
    #changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
    Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
    INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
    API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
else
    INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
    API_PROTO_FILES=$(shell find api -name *.proto)
endif

  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值