Skip to content

Commit

Permalink
use make’s dependency handling to speed-up rebuilds
Browse files Browse the repository at this point in the history
make allows us to run build targets based on dependencies and will only
execute targets if the dependencies have changed. This drastically
speeds up rebuilds if some targets have already been executed and
are still up to date.
  • Loading branch information
kmohrf committed Jun 26, 2021
1 parent 07478a5 commit 89bfe74
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ VERSION := $(shell git describe --tags --abbrev=0)
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))

YARN ?= yarn
GOPATH ?= $(HOME)/go
STUFFBIN ?= $(GOPATH)/bin/stuffbin
FRONTEND_YARN_MODULES = frontend/node_modules
FRONTEND_DIST = frontend/dist
FRONTEND_DEPS = \
$(FRONTEND_YARN_MODULES) \
frontend/package.json \
frontend/vue.config.js \
frontend/babel.config.js \
$(shell find frontend/fontello frontend/public frontend/src -type f)

BIN := listmonk
STATIC := config.toml.sample \
Expand All @@ -13,26 +23,32 @@ STATIC := config.toml.sample \
frontend/dist/frontend:/frontend \
i18n:/i18n

# Install dependencies for building.
.PHONY: deps
deps:
.PHONY: build
build: $(BIN)

$(STUFFBIN):
go get -u github.com/knadh/stuffbin/...

$(FRONTEND_YARN_MODULES): frontend/package.json frontend/yarn.lock
cd frontend && $(YARN) install
touch --no-create $(FRONTEND_YARN_MODULES)

# Build the backend to ./listmonk.
.PHONY: build
build:
$(BIN): $(shell find cmd -type f -name "*.go")
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go

# Run the backend.
.PHONY: run
run: build
run: $(BIN)
./${BIN}

# Build the JS frontend into frontend/dist.
.PHONY: build-frontend
build-frontend:
$(FRONTEND_DIST): $(FRONTEND_DEPS)
export VUE_APP_VERSION="${VERSION}" && cd frontend && $(YARN) build
touch --no-create $(FRONTEND_DIST)

.PHONY: build-frontend
build-frontend: $(FRONTEND_DIST)

# Run the JS frontend server in dev mode.
.PHONY: run-frontend
Expand All @@ -47,14 +63,14 @@ test:
# Bundle all static assets including the JS frontend into the ./listmonk binary
# using stuffbin (installed with make deps).
.PHONY: dist
dist: build build-frontend
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
dist: $(STUFFBIN) build build-frontend
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}

# pack-releases runns stuffbin packing on the given binary. This is used
# in the .goreleaser post-build hook.
.PHONY: pack-bin
pack-bin:
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
pack-bin: $(STUFFBIN)
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}

# Use goreleaser to do a dry run producing local builds.
.PHONY: release-dry
Expand Down

0 comments on commit 89bfe74

Please sign in to comment.