Skip to content

Commit

Permalink
chore: Update Makefile to match conventional standards
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Nov 14, 2021
1 parent 49bee8c commit 7c39a22
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
36 changes: 32 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
GO?=go
GOLANGCI_LINT_VERSION=$(shell grep GOLANGCI_LINT_VERSION: .github/workflows/main.yml | awk '{ print $$2 }')
ifdef VERSION
GO_LDFLAGS+=-X main.version=${VERSION}
endif
ifdef COMMIT
GO_LDFLAGS+=-X main.commit=${COMMIT}
endif
ifdef DATE
GO_LDFLAGS+=-X main.date=${DATE}
endif
ifdef BUILT_BY
GO_LDFLAGS+=-X main.builtBy=${BUILT_BY}
endif
PREFIX?=/usr/local

.PHONY: default
default: run build-all test lint format
default: build

.PHONY: smoketest
smoketest: run build-all test lint format

.PHONY: build
build:
ifeq (${GO_LDFLAGS},)
go build . || ( rm -f chezmoi ; false )
else
go build -ldflags "${GO_LDFLAGS}" . || ( rm -f chezmoi ; false )
endif

.PHONY: install
install:
install: build
install -m 755 chezmoi "${DESTDIR}${PREFIX}/bin"

.PHONY: install-from-git-working-copy
install-from-git-working-copy:
go install -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags) \
-X main.commit=$(shell git rev-parse HEAD) \
-X main.date=$(shell git show -s --format=%ct HEAD) \
-X main.builtBy=source"

.PHONY: build
build:
.PHONY: build-in-git-working-copy
build-in-git-working-copy:
go build -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags) \
-X main.commit=$(shell git rev-parse HEAD) \
-X main.date=$(shell git show -s --format=%ct HEAD) \
Expand Down
36 changes: 30 additions & 6 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [Generated code](#generated-code)
* [Contributing changes](#contributing-changes)
* [Managing releases](#managing-releases)
* [Building and installing with `make`](#building-and-installing-with-make)
* [Packaging](#packaging)
* [Updating the website](#updating-the-website)

Expand All @@ -26,12 +27,7 @@ chezmoi's source code.

chezmoi requires Go 1.16 or later.

chezmoi is a standard Go project, using standard Go tooling, with a few extra
tools. Ensure that these extra tools are installed with:

```console
$ make ensure-tools
```
chezmoi is a standard Go project, using standard Go tooling.

Build chezmoi:

Expand All @@ -56,6 +52,12 @@ Run chezmoi:
$ go run .
```

Run a set of smoketests, including cross-compilation, tests, and linting:

```console
$ make smoketest
```

---

## Generated code
Expand Down Expand Up @@ -167,6 +169,28 @@ $ brew bump-formula-pr --tag=v1.2.3 chezmoi

---

## Building and installing with `make`

chezmoi can be built with GNU make, assuming you have the Go toolchain
installed.

Running `make` will build a `chezmoi` binary in the current directory for the
host OS and architecture. To embed version information in the binary and control
installation the following variables are available:

| Variable | Example | Purpose |
| ----------- | ---------------------- | ----------------------------------------------- |
| `$VERSION` | `v2.0.0` | Set version. |
| `$COMMIT` | `3895680a`... | Set the git commit at which the code was built. |
| `$DATE` | `2019-11-23T18:29:25Z` | The time of the build. |
| `$BUILT_BY` | `homebrew` | The packaging system performing the build. |
| `$PREFIX` | `/usr` | Installation prefix. |
| `$DESTDIR` | `install-root` | Fake installation root. |

Running `make install` will install the `chezmoi` binary in `${DESTDIR}${PREFIX}/bin`.

---

## Packaging

If you're packaging chezmoi for an operating system or distribution:
Expand Down

0 comments on commit 7c39a22

Please sign in to comment.