|
| 1 | +# Default target |
| 2 | +build: |
| 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 | + |
| 9 | +# Helpful paths |
| 10 | +BINDIR := $(CURDIR)/bin |
| 11 | +DISTDIR := $(CURDIR)/_dist |
| 12 | +PKGDIR := $(DISTDIR)/pkg |
| 13 | +DEBDIR := $(DISTDIR)/deb |
| 14 | + |
| 15 | +# Platform information |
| 16 | +GOOS := $(shell go env GOOS) |
| 17 | +GOARCH := $(shell go env GOARCH) |
| 18 | + |
| 19 | +# Packaging information |
| 20 | +SUPPORTED_PACKAGE_GOARCHES := amd64 arm64 |
| 21 | +PACKAGE_ARCH := $(GOARCH) |
| 22 | +DEB_FILENAME := $(DISTDIR)/$(NAME)_$(VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).deb |
| 23 | +PKG_FILENAME := $(DISTDIR)/$(NAME)_$(VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).pkg |
| 24 | +ifeq ($(GOOS),linux) |
| 25 | + PACKAGE := $(DEB_FILENAME) |
| 26 | +else ifeq ($(GOOS),darwin) |
| 27 | + PACKAGE := $(PKG_FILENAME) |
| 28 | +else |
| 29 | + PACKAGE := |
| 30 | +endif |
| 31 | + |
| 32 | +# Build targets |
| 33 | +.PHONY: build |
| 34 | +build: |
| 35 | + $(RM) -r $(BINDIR) |
| 36 | + @mkdir -p $(BINDIR) |
| 37 | + GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build -o $(BINDIR) ./... |
| 38 | + |
| 39 | +# Package targets |
| 40 | +define check_arch |
| 41 | + $(if $(filter $(GOARCH),$(SUPPORTED_PACKAGE_GOARCHES)), , |
| 42 | + $(error cannot create package for GOARCH "$(GOARCH)", \ |
| 43 | + supported architectures are: $(SUPPORTED_PACKAGE_GOARCHES)")) |
| 44 | +endef |
| 45 | + |
| 46 | +.PHONY: check-arch |
| 47 | +check-arch: |
| 48 | + $(check_arch) |
| 49 | + |
| 50 | +define check_version |
| 51 | + $(if $(VERSION), , |
| 52 | + $(error version is undefined")) |
| 53 | +endef |
| 54 | + |
| 55 | +.PHONY: check-version |
| 56 | +check-version: |
| 57 | + $(check_version) |
| 58 | + |
| 59 | +# MacOS .pkg file |
| 60 | +# Steps: |
| 61 | +# 1. Layout files in _dist/pkg/payload/ as they'll be installed (including |
| 62 | +# uninstall.sh script). |
| 63 | +# 2. (Optional) Codesign the package contents in place. |
| 64 | +# 3. Create the component package in _dist/<name>.component.pkg. |
| 65 | +# 4. Create the product archive in _dist/pkg/. |
| 66 | +$(PKGDIR)/payload: GOOS := darwin |
| 67 | +$(PKGDIR)/payload: check-arch build |
| 68 | + @echo |
| 69 | + @echo "======== Formatting package contents ========" |
| 70 | + @build/package/layout-unix.sh --bindir="$(BINDIR)" \ |
| 71 | + --uninstaller="$(CURDIR)/build/package/pkg/uninstall.sh" \ |
| 72 | + --output="$(PKGDIR)/payload" |
| 73 | + |
| 74 | +.PHONY: codesign |
| 75 | +codesign: $(PKGDIR)/payload |
| 76 | + @echo |
| 77 | + @echo "======== Codesigning package contents ========" |
| 78 | + @build/package/pkg/codesign.sh --payload="$(PKGDIR)/payload" \ |
| 79 | + --developer-id="$(DEVELOPER_ID)" \ |
| 80 | + --entitlements="$(CURDIR)/build/package/pkg/entitlements.xml" |
| 81 | + |
| 82 | +ifdef NEED_CODESIGN |
| 83 | +$(PKG_FILENAME): codesign |
| 84 | +endif |
| 85 | + |
| 86 | +$(PKG_FILENAME): check-version $(PKGDIR)/payload |
| 87 | + @echo |
| 88 | + @echo "======== Creating product archive package ========" |
| 89 | + @build/package/pkg/pack.sh --version="$(VERSION)" \ |
| 90 | + --payload="$(PKGDIR)/payload" \ |
| 91 | + --output="$(PKG_FILENAME)" |
| 92 | + |
| 93 | +# Linux binary .deb file |
| 94 | +# Steps: |
| 95 | +# 1. Layout files in _dist/deb/root/ as they'll be installed (unlike MacOS |
| 96 | +# .pkg packages, symlinks created in the payload are preserved, so we |
| 97 | +# create them here to avoid doing so in a post-install step). |
| 98 | +# 2. Create the binary deb package in _dist/deb/. |
| 99 | +$(DEBDIR)/root: GOOS := linux |
| 100 | +$(DEBDIR)/root: check-arch build |
| 101 | + @echo |
| 102 | + @echo "======== Formatting package contents ========" |
| 103 | + @build/package/layout-unix.sh --bindir="$(BINDIR)" \ |
| 104 | + --include-symlinks \ |
| 105 | + --output="$(DEBDIR)/root" |
| 106 | + |
| 107 | +$(DEB_FILENAME): check-version $(DEBDIR)/root |
| 108 | + @echo |
| 109 | + @echo "======== Creating binary Debian package ========" |
| 110 | + @build/package/deb/pack.sh --payload="$(DEBDIR)/root" \ |
| 111 | + --arch="$(PACKAGE_ARCH)" \ |
| 112 | + --version="$(VERSION)" \ |
| 113 | + --distdir="$(DEBDIR)" \ |
| 114 | + --output="$(DEB_FILENAME)" |
| 115 | + |
| 116 | +.PHONY: package |
| 117 | +package: $(PACKAGE) |
| 118 | + |
| 119 | +# Cleanup targets |
| 120 | +.PHONY: clean |
| 121 | +clean: |
| 122 | + go clean ./... |
| 123 | + $(RM) -r $(BINDIR) |
| 124 | + $(RM) -r $(DISTDIR) |
0 commit comments