-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
88 lines (67 loc) · 2.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/make -f
PKGS := $(shell go list ./cmd/...)
BINS = $(shell basename $(PKGS))
COVERAGE_REPORT_FILENAME ?= coverage.out
BUILDDIR ?= $(CURDIR)/build
CODESIGN_IDENTIY ?= none
ifeq (,$(findstring nostrip,$(BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
ifneq (,$(ldflags))
BUILD_FLAGS += -ldflags '$(ldflags)'
endif
# check for nostrip option
ifeq (,$(findstring nostrip,$(BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# Check for debug option
ifeq (debug,$(findstring debug,$(BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif
# Check for the verbose option
ifdef verbose
VERBOSE = -v
endif
all: version.txt build check
BUILD_TARGETS := build install
build: version.txt
build: BUILD_ARGS=-o $(BUILDDIR)/
$(BUILD_TARGETS): $(BUILDDIR)/
go $@ $(VERBOSE) -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
$(BUILDDIR)/:
mkdir -p $@
check: $(COVERAGE_REPORT_FILENAME)
$(COVERAGE_REPORT_FILENAME): version.txt
go test $(VERBOSE) -mod=readonly -race -cover -covermode=atomic -coverprofile=$@ ./...
distclean: clean
rm -rf dist/
rm -rf unixtools.dmg
clean:
rm -rf $(BUILDDIR)
rm -f \
$(COVERAGE_REPORT_FILENAME) \
version.txt
version.txt:
echo "Ensure dependencies have not been modified ..." >&2
go mod verify
go mod tidy
go generate ./...
cp -f ./internal/version/version.txt version.txt
list:
@echo $(BINS) | tr ' ' '\n'
macos-codesign: build
codesign --verbose -s $(CODESIGN_IDENTITY) --options=runtime $(BUILDDIR)/*
unixtools.pkg: version.txt macos-codesign
pkgbuild --identifier io.asscrypto.unixtools \
--install-location ./Library/ --root $(BUILDDIR) $@
unixtools.dmg: version.txt macos-codesign
VERSION=$(shell cat version.txt); \
mkdir -p dist/unixtools-$${VERSION}/bin ; \
cp -a $(BUILDDIR)/* dist/unixtools-$${VERSION}/bin/ ; \
chmod 0755 dist/unixtools-$${VERSION}/bin/* ; \
create-dmg --volname unixtools --codesign $(CODESIGN_IDENTITY) \
--sandbox-safe --no-internet-enable \
$@ dist/unixtools-$${VERSION}
.PHONY: all clean check distclean build list macos-codesign