Repository navigation
Expand file tree
/
Copy pathmakefile
More file actions
76 lines (61 loc) · 1.86 KB
/
Copy pathmakefile
File metadata and controls
76 lines (61 loc) · 1.86 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
GOCMD=go
GOBUILD=$(GOCMD) build
.POSIX:
.PHONY: *
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=GoHeishaMon
BINARY_UNIX=$(BINARY_NAME)_AMD64
BINARY_MIPS=$(BINARY_NAME)_MIPS
BINARY_ARM=$(BINARY_NAME)_ARM
BINARY_MIPSUPX=$(BINARY_NAME)_MIPSUPX
.DEFAULT: help
help: ## show this help menu.
@echo "Usage: make [TARGET ...]"
@echo ""
@@grep -hE "#[#]" $(MAKEFILE_LIST) | sed -e 's/\\$$//' | awk 'BEGIN {FS = "[:=].*?#[#] "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
all: ## test and build for all platforms
all: test build-linux build-mips build-rpi
build: ## build binary
build:
$(GOBUILD) -o $(BINARY_NAME) -v
test: ## run go tests
test:
$(GOTEST) -v ./...
clean: ## clean dist dir
clean:
$(GOCLEAN)
rm -f dist/*
run: ## run main program
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
deps: ## create dist
deps:
$(GOGET) github.com/eclipse/paho.mqtt.golang
$(GOGET) go.bug.st/serial
$(GOGET) github.com/BurntSushi/toml
$(GOGET) github.com/rs/xid
mkdir dist
build-linux: ## build for linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o dist/$(BINARY_UNIX)
build-mips: ## build for MIPS
build-mips:
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat $(GOBUILD) -ldflags "-s -w" -a -o dist/$(BINARY_MIPS)
build-rpi: ## build for ARM
build-rpi:
GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) -o dist/$(BINARY_ARM)
upx: ## package binary
upx:
upx -f --brute -o dist/$(BINARY_MIPSUPX) dist/$(BINARY_MIPS)
install: ## install in TARGET_HOST
install:
scp dist/GoHeishaMon_MIPSUPX root@${TARGET_HOST}:/usr/bin/
ssh root@${TARGET_HOST} reboot
compilesquash: ## create root file system
compilesquash:
cp dist/$(BINARY_MIPSUPX) OS/RootFS/usr/bin/$(BINARY_MIPSUPX)
mksquashfs OS/RootFS dist/openwrt-ar71xx-generic-cus531-16M-rootfs-squashfs.bin -comp xz -noappend -always-use-fragments