|
1 | 1 | # Default target
|
2 | 2 | build:
|
3 | 3 |
|
| 4 | +# Project metadata (note: to package, VERSION *must* be set by the caller) |
| 5 | +NAME := git-bundle-server |
| 6 | +VERSION := |
| 7 | +PACKAGE_REVISION := 1 |
| 8 | + |
4 | 9 | # Helpful paths
|
5 | 10 | BINDIR := $(CURDIR)/bin
|
| 11 | +DISTDIR := $(CURDIR)/_dist |
6 | 12 |
|
7 | 13 | # Platform information
|
8 | 14 | GOOS := $(shell go env GOOS)
|
9 | 15 | GOARCH := $(shell go env GOARCH)
|
10 | 16 |
|
| 17 | +# Packaging information |
| 18 | +SUPPORTED_PACKAGE_GOARCHES := amd64 arm64 |
| 19 | +PACKAGE_ARCH := $(GOARCH) |
| 20 | + |
11 | 21 | # Build targets
|
12 | 22 | .PHONY: build
|
13 | 23 | build:
|
14 | 24 | $(RM) -r $(BINDIR)
|
15 | 25 | @mkdir -p $(BINDIR)
|
16 | 26 | GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build -o $(BINDIR) ./...
|
17 | 27 |
|
| 28 | +# Packaging targets |
| 29 | +.PHONY: check-arch |
| 30 | +check-arch: |
| 31 | + $(if $(filter $(GOARCH),$(SUPPORTED_PACKAGE_GOARCHES)), , \ |
| 32 | + $(error cannot create package for GOARCH "$(GOARCH)"; \ |
| 33 | + supported architectures are: $(SUPPORTED_PACKAGE_GOARCHES))) |
| 34 | + |
| 35 | +.PHONY: check-version |
| 36 | +check-version: |
| 37 | + $(if $(VERSION), , $(error version is undefined)) |
| 38 | + |
| 39 | +ifeq ($(GOOS),linux) |
| 40 | +# Linux binary .deb file |
| 41 | +# Steps: |
| 42 | +# 1. Layout files in _dist/deb/root/ as they'll be installed (unlike MacOS |
| 43 | +# .pkg packages, symlinks created in the payload are preserved, so we |
| 44 | +# create them here to avoid doing so in a post-install step). |
| 45 | +# 2. Create the binary deb package in _dist/deb/. |
| 46 | + |
| 47 | +# Platform-specific variables |
| 48 | +DEBDIR := $(DISTDIR)/deb |
| 49 | +DEB_FILENAME := $(DISTDIR)/$(NAME)_$(VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).deb |
| 50 | + |
| 51 | +# Targets |
| 52 | +$(DEBDIR)/root: check-arch build |
| 53 | + @echo |
| 54 | + @echo "======== Formatting package contents ========" |
| 55 | + @build/package/layout-unix.sh --bindir="$(BINDIR)" \ |
| 56 | + --include-symlinks \ |
| 57 | + --output="$(DEBDIR)/root" |
| 58 | + |
| 59 | +$(DEB_FILENAME): check-version $(DEBDIR)/root |
| 60 | + @echo |
| 61 | + @echo "======== Creating binary Debian package ========" |
| 62 | + @build/package/deb/pack.sh --payload="$(DEBDIR)/root" \ |
| 63 | + --arch="$(PACKAGE_ARCH)" \ |
| 64 | + --version="$(VERSION)" \ |
| 65 | + --output="$(DEB_FILENAME)" |
| 66 | + |
| 67 | +.PHONY: package |
| 68 | +package: $(DEB_FILENAME) |
| 69 | + |
| 70 | +else |
| 71 | +# Packaging not supported for platform, exit with error. |
| 72 | +.PHONY: package |
| 73 | +package: |
| 74 | + $(error cannot create package for GOOS "$(GOOS)") |
| 75 | + |
| 76 | +endif |
| 77 | + |
18 | 78 | # Cleanup targets
|
19 | 79 | .PHONY: clean
|
20 | 80 | clean:
|
21 | 81 | go clean ./...
|
22 | 82 | $(RM) -r $(BINDIR)
|
| 83 | + $(RM) -r $(DISTDIR) |
0 commit comments