Earlier quoted context omitted.
Make is available everywhere that matters, and is a simple declarative way to encompass build actions. What are the alternatives? Bash? Not declarative, and requires lots more code. Some go rewrite of Make? Not universal, possibly not maintained in the future. Rake? Ugh, Ruby. I strongly believe that make is the least worst way to build go projects, but please change my mind by suggesting some alternatives, not by co…
This is patently untrue. Make is not available by default on Windows, which - whether you like it or not - matters as a platform for a large number of developers. _Fortunately_ some CI images (certainly GitHub Actions and Azure DevOps) install GNU Make on their windows images by default, but it absolutely cannot be assumed for average developers.
Using Makefile(s) for Go
101–104 of 104 posts
Re: Using Makefile(s) for Go
#102Another thing you can add is:
.DEFAULT_GOAL := start
start: fmt swag vet build run
Helps define you default command soyou just need to run `make` and will run all inside of `start`
Since most of us use `.env` files for enviroment files, you can use something like:
# this allows to import into this file all current system envs
include .env
export
And it will inject all of .env file into the current running `process`
Also have some other shortcuts (variables):
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOFMT=gofmt -w
GOGET=$(GOCMD) mod download
GOVER=$(COCMD) vet
GOFILES=$(shell find . -name "*.go" -type f)
BINARY_NAME=my-cool-project
BINARY_UNIX=$(BINARY_NAME)_prod
Re: Using Makefile(s) for Go
#103This... isn't even using the `make` part of Makefiles at all. If you look at the final example, every [1] rule is marked as `.PHONY`. `make` bundles 2 capabilities: a dependency graph and an out-of-date check to rebuild files. This demonstration uses neither. The author would be better served with a shell script and a `case` block. The advantages: - Functions! The `check-environment` rule is really a function call in…
Re: Using Makefile(s) for Go
#104This... isn't even using the `make` part of Makefiles at all. If you look at the final example, every [1] rule is marked as `.PHONY`. `make` bundles 2 capabilities: a dependency graph and an out-of-date check to rebuild files. This demonstration uses neither. The author would be better served with a shell script and a `case` block. The advantages: - Functions! The `check-environment` rule is really a function call in…
I'm more confused as to why use .PHONY in so many places. Golang builds from .go files whos modification times are changed when written to, same as .c and .cpp files, so make is able to know when the go compiler needs to be called, or not.