forked from xenserver/xe-guest-utilities
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
104 lines (91 loc) · 3.7 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
PRODUCT_MAJOR_VERSION=6
PRODUCT_MINOR_VERSION=6
PRODUCT_MICRO_VERSION=80
PRODUCT_VERSION = $(PRODUCT_MAJOR_VERSION).$(PRODUCT_MINOR_VERSION).$(PRODUCT_MICRO_VERSION)
GO_BUILD = go build
GO_FLAGS = -v
REPO = $(shell pwd)
SOURCEDIR = $(REPO)/mk
BUILDDIR = $(REPO)/build
GOBUILDDIR = $(BUILDDIR)/gobuild
STAGEDIR = $(BUILDDIR)/stage
OBJECTDIR = $(BUILDDIR)/obj
DISTDIR = $(BUILDDIR)/dist
VENDORDIR = $(REPO)/vendor/$(shell basename $(REPO))
OBJECTS :=
OBJECTS += $(OBJECTDIR)/xe-daemon
OBJECTS += $(OBJECTDIR)/xenstore
PACKAGE = xe-guest-utilities
VERSION = $(PRODUCT_VERSION)
RELEASE := $(shell git rev-list HEAD | wc -l)
ifeq ($(GOARCH),)
ARCH := $(shell go version|awk -F'/' '{print $$2}')
else
ARCH := $(GOARCH)
endif
ifeq ($(ARCH), amd64)
ARCH = x86_64
endif
XE_DAEMON_SOURCES :=
XE_DAEMON_SOURCES += xe-daemon/xe-daemon.go
XE_DAEMON_SOURCES += syslog/syslog.go
XE_DAEMON_SOURCES += system/system.go
XE_DAEMON_SOURCES += guestmetric/guestmetric.go
XE_DAEMON_SOURCES += guestmetric/guestmetric_linux.go
XE_DAEMON_SOURCES += xenstoreclient/xenstore.go
XENSTORE_SOURCES :=
XENSTORE_SOURCES += xenstore/xenstore.go
XENSTORE_SOURCES += xenstoreclient/xenstore.go
.PHONY: build
build: $(DISTDIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(ARCH).tgz
.PHONY: clean
clean:
$(RM) -rf $(BUILDDIR)
$(DISTDIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(ARCH).tgz: $(OBJECTS)
$(info ***** Create build direcotry *****)
( mkdir -p $(DISTDIR) ; \
install -d $(STAGEDIR)/etc/init.d/ ; \
install -m 755 $(SOURCEDIR)/xe-linux-distribution.init $(STAGEDIR)/etc/init.d/xe-linux-distribution ; \
install -d $(STAGEDIR)/usr/sbin/ ; \
install -m 755 $(SOURCEDIR)/xe-linux-distribution $(STAGEDIR)/usr/sbin/xe-linux-distribution ; \
install -m 755 $(OBJECTDIR)/xe-daemon $(STAGEDIR)/usr/sbin/xe-daemon ; \
install -d $(STAGEDIR)/usr/bin/ ; \
install -m 755 $(OBJECTDIR)/xenstore $(STAGEDIR)/usr/bin/xenstore ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-read ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-write ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-exists ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-rm ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-list ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-ls ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-chmod ; \
ln -sf xenstore $(STAGEDIR)/usr/bin/xenstore-watch ; \
install -d $(STAGEDIR)/etc/udev/rules.d/ ; \
install -m 644 $(SOURCEDIR)/xen-vcpu-hotplug.rules $(STAGEDIR)/etc/udev/rules.d/z10_xen-vcpu-hotplug.rules ; \
cd $(STAGEDIR) ; \
tar zcf $@ * \
)
$(OBJECTDIR)/xe-daemon: $(XE_DAEMON_SOURCES:%=$(GOBUILDDIR)/%)
$(info ***** Build xe-daemon ******)
(cd $(VENDORDIR) && ln -sfn ../../build/gobuild/guestmetric guestmetric)
(cd $(VENDORDIR) && ln -sfn ../../build/gobuild/syslog syslog)
(cd $(VENDORDIR) && ln -sfn ../../build/gobuild/system system)
(cd $(VENDORDIR) && ln -sfn ../../build/gobuild/xenstoreclient xenstoreclient)
mkdir -p $(OBJECTDIR)
$(GO_BUILD) $(GO_FLAGS) -o $@ $<
$(OBJECTDIR)/xenstore: $(XENSTORE_SOURCES:%=$(GOBUILDDIR)/%)
$(info ***** Build xenstore ******)
mkdir -p $(OBJECTDIR)
$(GO_BUILD) $(GO_FLAGS) -o $@ $<
(cd $(VENDORDIR) && ln -sfn ../../guestmetric guestmetric)
(cd $(VENDORDIR) && ln -sfn ../../syslog syslog)
(cd $(VENDORDIR) && ln -sfn ../../system system)
(cd $(VENDORDIR) && ln -sfn ../../xenstoreclient xenstoreclient)
$(GOBUILDDIR)/%: $(REPO)/%
$(info ****** Replace product version for: [$<] *****)
mkdir -p $$(dirname $@)
cat $< | \
sed -e "s/@PRODUCT_MAJOR_VERSION@/$(PRODUCT_MAJOR_VERSION)/g" | \
sed -e "s/@PRODUCT_MINOR_VERSION@/$(PRODUCT_MINOR_VERSION)/g" | \
sed -e "s/@PRODUCT_MICRO_VERSION@/$(PRODUCT_MICRO_VERSION)/g" | \
sed -e "s/@NUMERIC_BUILD_NUMBER@/$(RELEASE)/g" \
> $@