Makefile 2.96 KB
Newer Older
1 2 3 4
# use bash instead of shell we'll
# need the ability to create arrays
SHELL=/bin/bash

zauberstuhl's avatar
zauberstuhl committed
5
package := git.feneas.org/ganggo/ganggo
6
srcdir := $(GOPATH)/src/$(package)
7

Lukas Matt's avatar
Lukas Matt committed
8
go := $(shell command -v go 2> /dev/null)
9
godep := $(shell command -v dep 2> /dev/null)
10
gobin := $(shell command -v go-bindata 2> /dev/null)
Lukas Matt's avatar
Lukas Matt committed
11 12 13 14
npm := $(shell command -v npm 2> /dev/null)
revel := $(shell command -v revel 2> /dev/null)
train := $(shell command -v train 2> /dev/null)

15 16 17
ifndef go
	$(error "go is not available: https://golang.org/dl/")
endif
18

19 20
define version_info
	Please define a version you want to build e.g. VERSION=v0 make
Lukas Matt's avatar
Lukas Matt committed
21 22
endef

23
define install-tools
Ghost User's avatar
Ghost User committed
24
	# go dependency tool
25
	go get -u github.com/golang/dep/cmd/dep
Ghost User's avatar
Ghost User committed
26 27
	# download all dependencies
	cd $(srcdir) && dep ensure
28
	# web framework
Ghost User's avatar
Ghost User committed
29 30
	cd $(srcdir)/vendor/github.com/revel/cmd/revel && \
		go build -o $$GOPATH/bin/revel
31
	# asset compilation
Ghost User's avatar
Ghost User committed
32 33
	cd $(srcdir)/vendor/github.com/shaoshing/train/cmd && \
		go build -o $$GOPATH/bin/train
34
	# embedding binary data e.g. assets
Ghost User's avatar
Ghost User committed
35 36 37
	cd $(srcdir)/vendor/github.com/kevinburke/go-bindata/go-bindata && \
		go build -o $$GOPATH/bin/go-bindata
	rm -r $(srcdir)/vendor/github.com/kevinburke/go-bindata/testdata
Lukas Matt's avatar
Lukas Matt committed
38 39
endef

Lukas Matt's avatar
Lukas Matt committed
40
install: clean install-deps
41

Lukas Matt's avatar
Lukas Matt committed
42
release: precompile compile u2d-wrapper
Lukas Matt's avatar
Lukas Matt committed
43 44 45 46

install-deps:
ifndef npm
	$(error "npm is not available please install it first!")
47 48 49
endif
ifndef godep
	$(install-tools)
Lukas Matt's avatar
Lukas Matt committed
50
endif
51
	# Install CSS and Javascript dependencies
52
	cd $(srcdir) && npm install --prefix .
Lukas Matt's avatar
Lukas Matt committed
53

54
clean:
55
	rm -r tmp vendor node_modules \
56
		test-results updater/bindata.go \
57
		updater.*.bin *.tar.gz || true
58

Lukas Matt's avatar
Lukas Matt committed
59 60
precompile:
ifndef train
61
	$(install-tools)
Lukas Matt's avatar
Lukas Matt committed
62
endif
63
	cd $(srcdir) && train -out public -source app/assets
64 65 66 67
	# Append vendor files to manifest
	sed -n '/^.*:node_modules.*/p' .include_vendor \
		| while read line; do \
			obj=($${line/:/ }); \
68
			dir=$(srcdir)/public/assets/vendor/$${obj[0]}; \
69 70 71
			mkdir -p $$dir && echo $$dir; \
			cp -v $${obj[1]} $$dir; \
		done
Lukas Matt's avatar
Lukas Matt committed
72 73

compile:
74
ifndef VERSION
75 76
	$(error $(version_info))
endif
Lukas Matt's avatar
Lukas Matt committed
77
ifndef revel
78
	$(install-tools)
Lukas Matt's avatar
Lukas Matt committed
79
endif
80
	cp $(srcdir)/conf/app.conf.example $(srcdir)/conf/app.conf
81
	cd $(srcdir) && \
82
		APP_VERSION=$(VERSION) revel package $(package)
83

84
test:
85
ifndef revel
86
	$(install-tools)
87
endif
88 89
	cd $(srcdir) && \
		go tool vet -v -all app/
90
	cp $(srcdir)/conf/app.conf.example $(srcdir)/conf/app.conf
91 92
	# XXX revel will not print error stacks to console
	# (see https://github.com/revel/cmd/issues/121)
Lukas Matt's avatar
Lukas Matt committed
93
	revel test $(package) ci || { \
94
		cd $(srcdir) && bash ci/scripts/test_results.sh ;\
95 96
		exit 1 ;\
	}
97

98
u2d-wrapper:
99
ifndef VERSION
100 101
	$(error $(version_info))
endif
102
ifndef gobin
103
	$(install-tools)
104
endif
105 106 107
	mkdir -p $(srcdir)/tmp && cd $$_ && { \
		tar -x -f "../ganggo.tar.gz" ;\
		[ -f "ganggo.exe" ] && mv ganggo.exe ganggo ;\
108 109
		go-bindata -o ../updater/bindata.go ganggo \
			src/github.com/revel/... \
110
			src/$(package)/../api/... \
111
			src/$(package)/{app,conf,messages,public}/... ;\
112
	}
113
	cd $(srcdir)/updater && go build \
114
		-ldflags "-X main.version=$(VERSION)" \
115
		-o ../updater.$$GOOS-$$GOARCH$$GOARM.bin updater.go bin*.go