-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (112 loc) · 4 KB
/
Copy pathMakefile
File metadata and controls
126 lines (112 loc) · 4 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Makefile for gonexus
#
# Common usage:
# make deps # one-time: install libhdf5-dev (Linux) via apt, or print
# # instructions for other platforms
# make tidy # generate/update go.sum (fixes "missing go.sum entry")
# make build # go build ./...
# make test # go test ./...
# make examples # build and run examples
# make fmt # gofmt -w on all Go source
# make vet # go vet ./...
# make clean # remove build artifacts
GO ?= go
MODULE := $(shell $(GO) list -m 2>/dev/null)
PKGS := ./...
BIN_DIR := bin
# HDF5 is a cgo dependency; its headers/libs often aren't on the default
# search path, so detect common macOS package managers and point CGO at
# them automatically.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
ifneq ($(wildcard /opt/local/include/hdf5.h),)
# MacPorts
export CGO_CFLAGS := -I/opt/local/include $(CGO_CFLAGS)
export CGO_LDFLAGS := -L/opt/local/lib $(CGO_LDFLAGS)
else
HDF5_PREFIX := $(shell brew --prefix hdf5 2>/dev/null)
ifneq ($(HDF5_PREFIX),)
# Homebrew
export CGO_CFLAGS := -I$(HDF5_PREFIX)/include $(CGO_CFLAGS)
export CGO_LDFLAGS := -L$(HDF5_PREFIX)/lib $(CGO_LDFLAGS)
endif
endif
endif
.PHONY: all
all: build
# ---------------------------------------------------------------------------
# System dependencies (the HDF5 C library gonum.org/v1/hdf5 links against)
# ---------------------------------------------------------------------------
.PHONY: deps
deps:
@echo "gonexus needs the HDF5 C library (>=1.8) and its headers to build."
@if command -v port >/dev/null 2>&1; then \
echo "Detected MacPorts - installing hdf5..."; \
sudo port install hdf5; \
elif command -v brew >/dev/null 2>&1; then \
echo "Detected Homebrew (macOS) - installing hdf5..."; \
brew install hdf5; \
elif command -v apt-get >/dev/null 2>&1; then \
echo "Detected apt (Debian/Ubuntu) - installing libhdf5-dev..."; \
sudo apt-get update && sudo apt-get install -y libhdf5-dev; \
elif command -v yum >/dev/null 2>&1; then \
echo "Detected yum (RHEL/CentOS/Fedora) - installing hdf5-devel..."; \
sudo yum install -y hdf5-devel; \
else \
echo "Could not detect a package manager. Install HDF5 >=1.8 manually,"; \
echo "e.g. from https://www.hdfgroup.org/downloads/hdf5, then re-run make."; \
exit 1; \
fi
# ---------------------------------------------------------------------------
# Go module bookkeeping
# ---------------------------------------------------------------------------
.PHONY: tidy
tidy:
$(GO) mod tidy
.PHONY: verify
verify:
$(GO) mod verify
# ---------------------------------------------------------------------------
# Build / test / lint
# ---------------------------------------------------------------------------
.PHONY: build
build: tidy
$(GO) build $(PKGS)
.PHONY: test
test: tidy
$(GO) test -v $(PKGS)
.PHONY: vet
vet: tidy
$(GO) vet $(PKGS)
.PHONY: fmt
fmt:
gofmt -l -w $$(find . -name '*.go' -not -path './vendor/*')
.PHONY: check
check: fmt vet test
# ---------------------------------------------------------------------------
# Example program
# ---------------------------------------------------------------------------
.PHONY: examples
examples: tidy
mkdir -p $(BIN_DIR)
$(GO) build -o $(BIN_DIR)/gonexus-io-example ./examples/io
$(GO) build -o $(BIN_DIR)/gonexus-reader-example ./examples/reader
# ---------------------------------------------------------------------------
# Housekeeping
# ---------------------------------------------------------------------------
.PHONY: clean
clean:
$(GO) clean $(PKGS)
rm -rf $(BIN_DIR) example.nxs
.PHONY: help
help:
@echo "Targets:"
@echo " deps install the HDF5 C library needed to build gonexus"
@echo " tidy go mod tidy (generates/updates go.sum)"
@echo " build go build ./..."
@echo " test go test ./..."
@echo " vet go vet ./..."
@echo " fmt gofmt -w on all .go files"
@echo " check fmt + vet + test"
@echo " examples build examples executables"
@echo " clean remove build artifacts"