forked from pief/python-netsnmpagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·150 lines (135 loc) · 4.53 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
# python-netsnmpagent module
# Copyright (c) 2013-2016 Pieter Hollants <pieter@hollants.com>
# Licensed under the GNU Lesser Public License (LGPL) version 3
#
# Makefile for Git repository-based builds
#
# The version is derived from the latest git tag set
VERSION := $(shell git describe)
# Some features should be available for proper releases with a x.y.z tag only
ifeq ($(shell echo $(VERSION) | sed 's,^[[:digit:]]\+\.[[:digit:]]\+\(\.[[:digit:]]\+\)\?,,'),)
TAGGED := 1
else
VERSION := $(shell echo $(VERSION) | sed 's,-,_next,;s,-,_,')
endif
all: help
help:
@echo
@echo " python-netsnmpagent Module"
@echo " Copyright (c) 2013-2016 Pieter Hollants <pieter@hollants.com>"
@echo
@echo "Version from \"git describe\": $(VERSION)"
@echo
@echo "Targets:"
@echo " tests - Run local code tests (net-snmp integration tests)"
@echo " install - Install locally"
@echo " srcdist - Create source distribution archive in .tar.gz format"
ifeq ($(TAGGED),1)
@echo " upload - Upload source distribution archive to PyPI"
endif
@echo " rpms - Build RPMs for the current distribution"
@echo " clean - Clean up"
@echo
.PHONY: tests
tests:
@if [ `which nosetests 2>/dev/null` ] ; then \
cd tests && \
for FILE in test_*.py ; do \
echo "----------------------------------------------------------------------"; \
echo $$FILE; \
echo "----------------------------------------------------------------------"; \
nosetests -vx $$FILE || exit 1; \
done \
else \
echo "Can't find the \"nosetests\" command, please install the \"nose\" Python module!"; \
exit 1; \
fi
setup.py: setup.py.in
sed 's/@NETSNMPAGENT_VERSION@/$(VERSION)/' setup.py.in >$@
chmod u+x setup.py
install: setup.py
python setup.py install
.PHONY: ChangeLog
ChangeLog:
@[ -e $@ ] && rm $@ || true
@CURRENT=`git describe`; \
set -- `git tag -l | egrep ^[[:digit:]]+.[[:digit:]]+\(.[[:digit:]]+\)?$ | sort -r`; \
if [ "$$CURRENT" == "$$1" ] ; then shift; fi; \
until [ -z "$$CURRENT" ] ; do \
if [ -n "$$1" ] ; then \
LINE="Changes from v$$1 to v$$CURRENT"; \
PREV="$$1.."; \
else \
LINE="Initial version $$CURRENT"; \
PREV=""; \
fi; \
echo >>$@; \
echo $$LINE >>$@; \
printf "%*s\n" $${#LINE} | tr ' ' '=' >>$@; \
echo >>$@; \
git log \
--no-merges \
--format="* %ad - %aN <%ae>%n%n%+w(75,2,2)%s%n%+b%n(Git commit %H)%n" \
$$PREV$$CURRENT >>$@; \
CURRENT=$$1; \
shift || true; \
done
dist:
@mkdir dist
.PHONY: python-netsnmpagent.spec.changelog
python-netsnmpagent.spec.changelog: dist
@[ -e $@ ] && rm $@ || true
@PKGREMAIL=`git config user.email`; \
if [ -z "$$PKGREMAIL" ] ; then \
PKGREMAIL="`whoami`@`hostname`"; \
fi; \
CURRENT=`git describe`; \
set -- `git tag -l | egrep ^[[:digit:]]+.[[:digit:]]+\(.[[:digit:]]+\)?$ | sort -r`; \
if [ "$$CURRENT" == "$$1" ] ; then shift; fi; \
until [ -z "$$CURRENT" ] ; do \
if [ -n "$$1" ] ; then \
LINE="Update to v$$CURRENT"; \
else \
LINE="Initial version $$CURRENT"; \
fi; \
GITDATE=`git log --format="%ad" --date=iso -n1 $$CURRENT`; \
OURDATE=`LANG=C date -d "$$GITDATE" +"%a %b %d %Y"`; \
echo >>$@ "* $$OURDATE $$PKGREMAIL"; \
echo >>$@ "- $$LINE"; \
echo >>$@; \
CURRENT=$$1; \
shift || true; \
done
dist/python-netsnmpagent.spec: dist python-netsnmpagent.spec.changelog python-netsnmpagent.spec.in
@sed "s/@NETSNMPAGENT_VERSION@/$(VERSION)/" \
python-netsnmpagent.spec.in \
>$@
@cat >>$@ python-netsnmpagent.spec.changelog
srcdist: setup.py ChangeLog dist/python-netsnmpagent.spec
python setup.py sdist
@echo Created source distribution archive as dist/netsnmpagent-$(VERSION).tar.gz
@echo A suitable RPM .spec file can be found at dist/python-netsnmpagent.spec
upload: setup.py
ifeq ($(TAGGED),1)
python setup.py sdist upload
else
@echo "Upload not available for untagged versions!"
endif
rpms: dist srcdist
@mkdir -p dist/RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} || exit 1
@cp -a dist/python-netsnmpagent.spec dist/RPMBUILD/SPECS/ || exit 1
@cp -a dist/netsnmpagent-$(VERSION).tar.gz dist/RPMBUILD/SOURCES/ || exit 1
@cd dist/RPMBUILD && \
rpmbuild \
--define "%_topdir $$(pwd)" \
-ba SPECS/python-netsnmpagent.spec || exit 1
@find dist/RPMBUILD -name *.rpm -exec cp -a {} dist/ \; || exit 1
@rm -r dist/RPMBUILD || true
@echo RPMs can be found in the dist/ directory
clean:
@[ -e "*.pyc" ] && rm *.pyc || true
@[ -e setup.py ] && (python setup.py clean; rm setup.py) || true
@[ -e ChangeLog ] && rm ChangeLog || true
@[ -e build ] && rm -rf build || true
@[ -e dist ] && rm -rf dist || true