forked from stahnma/vmpool-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
74 lines (58 loc) · 2.21 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
PKGNAME=vmpool
UNAME:=$(shell uname)
ifeq ($(UNAME),Darwin)
TMP_PATTERN:=$(shell mktemp -d tmpbuild-XXXXXX)
TMPDIR:=$(shell pwd)/$(TMP_PATTERN)
TAR_TMP_DIR:=$(shell mktemp -d -t tmptarball)
else
TMP_PATTERN:=$(shell mktemp -d -u -p . -t rpmbuild-XXXXXXX)
TMPDIR:=$(shell pwd)/$(TMP_PATTERN)
TAR_TMP_DIR:=$(shell mktemp -d -u -t tarball-XXXXXXX)
endif
SPEC_FILE=$(PKGNAME).spec
PWD:=$(shell pwd)
RPMBUILD := $(shell if test -f /usr/bin/rpmbuild ; then echo /usr/bin/rpmbuild ; else echo "x" ; fi)
RPM_DEFINES = --define "_specdir $(TMPDIR)/SPECS" --define "_rpmdir $(TMPDIR)/RPMS" --define "_sourcedir $(TMPDIR)/SOURCES" --define "_srcrpmdir $(TMPDIR)/SRPMS" --define "_builddir $(TMPDIR)/BUILD"
MAKE_DIRS= $(TMPDIR)/SPECS $(TMPDIR)/SOURCES $(TMPDIR)/BUILD $(TMPDIR)/SRPMS $(TMPDIR)/RPMS
# If there is a VERSION file, use it.
# else use git describe
VERSION:=$(shell if [ -f "VERSION" ] ; then cat VERSION ; else git describe | sed -e 's/-/\./g' ; fi)
TARBALL=$(PKGNAME)-$(VERSION).tar.gz
build: vmpool
fmt:
go fmt *.go
vmpool:
go build -o vmpool -ldflags "-X main.version $(VERSION)" *.go
@rm -rf tmp*
install:
mkdir -p $(DESTDIR)/usr/local/bin
cp -pr vmpool $(DESTDIR)/usr/local/bin
linux:
# In order to get the cross-compile options on mac, install via
# brew install go --cross-compile-common
GOARCH=amd64 GOOS=linux go build
clean:
rm -rf vmpool *tar.gz rpmbuild-* *.src.rpm tmp* VERSION
uninstall:
rm -rf $(DESTDIR)/usr/local/bin/vmpool
tarball:
rm -rf tmp*
echo $(VERSION) > VERSION
mkdir -p $(TAR_TMP_DIR)/$(PKGNAME)-$(VERSION)
cd ..; cp -pr $(PWD)/* $(TAR_TMP_DIR)/$(PKGNAME)-$(VERSION); rm -rf $(TAR_TMP_DIR)/$(PKGNAME)-$(VERSION)/{contrib,*.spec}
cd $(TAR_TMP_DIR); tar pczf $(TARBALL) $(PKGNAME)-$(VERSION)
mv $(TAR_TMP_DIR)/$(TARBALL) .
rm -rf $(TAR_TMP_DIR) tmp*
# If you're on a system with rpm, you can build a srpm to throw at mock or something.
srpm: tarball
@mkdir -p $(MAKE_DIRS)
@cp -f $(TARBALL) $(TMPDIR)/SOURCES
@cp -f $(SPEC_FILE) $(TMPDIR)/SPECS
sed -i 's/==VERSION==/$(VERSION)/g' $(TMPDIR)/SPECS/$(SPEC_FILE)
@wait
@$(RPMBUILD) $(RPM_DEFINES) -bs $(TMPDIR)/SPECS/$(SPEC_FILE)
@mv -f $(TMPDIR)/SRPMS/* .
@rm -rf $(TMPDIR)
@echo
@ls *src.rpm
.PHONY: intall fmt clean tarball uninstall