...

/

Adding a Makefile for Multi-git

Adding a Makefile for Multi-git

See how a Makefile for multi-git can tie all these capabilities together and provide a one-stop shop for managing your program. We will also discuss the relationship between Makefiles and CI/CD pipelines as well as alternatives to Makefiles.

Creating a Makefile for multi-git

Let’s start with the most basic target: build. The comment with the double hashtags will become a nice help message later. Note the tabbed indentation, which is an infamous gotcha of Makefiles. Another important issue is escaping the Dollar sign by doubling it. This is necessary because a single Dollar sign is used by Makefile variables. The command itself is using the -ldflags to inject the git tag and timestamp to the program and writes the executable to the current directory while adding the OS and architecture.

### Build multi-git and inject the git tag and build time to variables in main
build:
	go build -ldflags "-X 'main.gitTag=$$(git describe --tags)' \
                       -X 'main.buildTimestamp=$$(date -u)'" \
                       -o multi-git_$$(go env GOOS)_$$(go env GOARCH)

On my amd64 Mac the final executable is called multi-git_darwin_amd4 (Darwin is the original name of the macOS).

The install target depends on the build target as in install: build. This means that when you run make install, it will first run the build target and then execute the commands of the install target.

### Install multi-git into /usr/local/bin (avoid standard go install)
install: build
	mv
...