What is Golang make ?
Golang make is a tool that helps implement an effective build system in Go projects. It manages files in the folder, executes tests and compile commands, builds binaries, and manages any other tasks associated with managing software. All of this happens in a single build step, which is how Golang make achieves its integration with the go command. The fact that it is part of the Go standard library enables it to be used in projects without worrying about third-party packages.
An example build using Golang make would look like this:
The build will create a binary named “some_binary” and place it in your specified output folder. If you have other files or folders they will be created as well and given their respective names. It also examines the input folder and creates a file called “Makefile” in order to future builds.
Golang make allows for nine tasks to be run:
There are also two other tasks that can be used in order to work with the build system itself.
How to install Golang make ?
On Linux, there are various ways to install the dependencies required to build golang-make using the go get command. Here, we provide a detailed guide on how to install “Golang make” using the Golang tool go get.
It is common to need more than one Golang make executable.
If you have issues while installing golang make, please try the following steps:
– Download your OS Package from this list of official builds and ensure it matches your architecture. For example, download Debian x64 for amd64-pc-linux .
– Unpack the tarball, skip to step 4 if you have already done this.
– If you don’t have root access, run the following command as root:
1) For Debian/Ubuntu
sudo apt-get install golang
apt-get install golang-go get golang-github-golang-dev (To install latest version of “golang make”, use the above command. Then, you can use the following command to install develop branch)
2) For Red Hat/CentOS
sudo yum groupinstall “Development Tools”
sudo yum install golang (To install latest version of “golang make”, use the above command. Then, you can use the following command to install develop branch)
How to use Golang make ?
Golang Make is used to create a go.mod file. Go Modify, as it is more commonly referred to, is a file that contains information about third-party and local packages in your code repository. It is a modular build system written in Go. Golang make use of the go command to run the commands.
In order to generate a go.mod file, Golang Make need 3 things:
“A folder containing your code that includes a package declaration.”,
In our example, we have a package main in our folder that contains the declare keyword, therefore Golang Make can create a go.mod file into our project directory. If we have a folder named “go” in our project directory with the files “main.go”, “module.go” and “foo.go”, then we will have the file “go.mod” in our project directory.
A package declaration is a statement at the beginning of a file, in which you specify which package the code belongs to. The syntax is: