当前位置:网站首页>Writing a makefile for a golang project
Writing a makefile for a golang project
2022-06-29 21:36:00 【Learn programming notes】
by Golang Project preparation Makefile
| Golang
With the help of Makefile In the compilation process, we no longer need to manually input the compiled commands and compiled parameters every time , It can greatly simplify the project compilation process .
make Introduce
make Is a build automation tool , Will look for... In the current directory Makefile or makefile file . If the corresponding file exists , It will complete the construction task according to the defined rules .
Makefile Introduce
We can Makefile It simply defines the Compilation Rules of a project file . With the help of Makefile In the compilation process, we no longer need to manually input the compiled commands and compiled parameters every time , It can greatly simplify the project compilation process . Use at the same time Makefile You can also determine the specific Compilation Rules and processes in the project , Many open source projects define Makefile file .
This article will not cover in detail Makefile Various rules of , Only give Go In the project Makefile Example . About Makefile Recommended reading for details of Makefile course .
Rule overview
Makefile Composed of multiple rules , Each rule is mainly composed of two parts , They are dependency relations and commands executed .
Its structure is as follows :
[target] ... : [prerequisites] ...
<tab>[command]
...
...
among :
- targets: The goal of the rules
- prerequisites: Optional to generate targets The required files or targets .
- command:make Commands that need to be executed ( Any of the shell command ). There can be multiple commands , Each command takes one line .
for instance :
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o xx
Example
.PHONY: all build run gotool clean help
BINARY="bluebell"
all: gotool build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY}
run:
@go run ./
gotool:
go fmt ./
go vet ./
clean:
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
help:
@echo "make - format Go Code , And compile and generate binary files "
@echo "make build - compile Go Code , Generate binaries "
@echo "make run - Direct operation Go Code "
@echo "make clean - Remove binaries and vim swap files"
@echo "make gotool - function Go Tools 'fmt' and 'vet'"
among :
BINARY="bluebell"Is to define variables ..PHONYUsed to define pseudo targets . Do not create target file , But to execute the commands under this goal .
Reference link :https://www.liwenzhou.com/posts/Go/makefile/
边栏推荐
猜你喜欢

什么是 SYN 洪水攻击?如何防护?

高校如何基于云原生构建面向未来的智慧校园?全栈云原生VS传统技术架构

CORDIC based Signal Processor desgn

Water polo chart - using dynamic ripples to show percentages

【ROS进阶篇】第二讲 自定义头、源文件封装

Analysis on the true topic of "cost management" by Guangdong second-class cost engineer

Layer 3 loop brought by route Summary - solution experiment

leetcode:238. Product of arrays other than itself

Digital password lock Verilog design + simulation + on board verification

导航 习题【微机原理】【习题】
随机推荐
数字密码锁verilog设计+仿真+上板验证
TMUX settings
【ROS进阶篇】第三讲 ROS文件系统与分布式通信
习近平在湖北武汉考察时强调 把科技的命脉牢牢掌握在自己手中 不断提升我国发展独立性自主性安全性
Jump to open a new window
Navigation [microcomputer principle]
Common methods of string class
什么是 SYN 洪水攻击?如何防护?
PostgreSQL每周新闻—6月22日
WPF measurement string display size
PostgreSQL Weekly News - 22 juin
Summary of document level symbols under different systems
Rsync method of establishing multi directory module
Change detection and batch update
Implementing LDAP proxy service with haproxy + keepalive
亚马逊关键词搜索API接口(item_search-按关键字搜索亚马逊商品接口),亚马逊API接口
About Effect Size
Shutter bottomnavigationbar toggle page hold
leetcode:370. 区间加法
双目立体视觉摄像头的标定、矫正、世界坐标计算(opencv)