Makefile 8.47 KB
Newer Older
1
#!/usr/bin/make
2
# WARN: gmake syntax
Michael DeHaan committed
3 4 5 6 7
########################################################
# Makefile for Ansible
#
# useful targets:
#   make sdist ---------------- produce a tarball
James Laska committed
8
#   make srpm ----------------- produce a SRPM
Michael DeHaan committed
9
#   make rpm  ----------------- produce RPMs
James Laska committed
10
#   make deb-src -------------- produce a DEB source
11
#   make deb ------------------ produce a DEB
Michael DeHaan committed
12 13
#   make docs ----------------- rebuild the manpages (results are checked in)
#   make tests ---------------- run the tests
14
#   make pyflakes, make pep8 -- source code checks
Michael DeHaan committed
15 16 17 18

########################################################
# variable section

19
NAME = ansible
20
OS = $(shell uname -s)
Michael DeHaan committed
21 22

# Manpages are currently built with asciidoc -- would like to move to markdown
23 24
# This doesn't evaluate until it's called. The -D argument is the
# directory of the target file ($@), kinda like `dirname`.
25
MANPAGES := docs/man/man1/ansible.1 docs/man/man1/ansible-playbook.1 docs/man/man1/ansible-pull.1 docs/man/man1/ansible-doc.1 docs/man/man1/ansible-galaxy.1 docs/man/man1/ansible-vault.1
26
ifneq ($(shell which a2x 2>/dev/null),)
27 28
ASCII2MAN = a2x -D $(dir $@) -d manpage -f manpage $<
ASCII2HTMLMAN = a2x -D docs/html/man/ -d manpage -f xhtml
29 30 31
else
ASCII2MAN = @echo "ERROR: AsciiDoc 'a2x' command is not installed but is required to build $(MANPAGES)" && exit 1
endif
Michael DeHaan committed
32

33 34
PYTHON=python
SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
Michael DeHaan committed
35 36

# VERSION file provides one place to update the software version
37
VERSION := $(shell cat VERSION)
Michael DeHaan committed
38

39
# Get the branch information from git
40 41 42
ifneq ($(shell which git),)
GIT_DATE := $(shell git log -n 1 --format="%ai")
endif
43

44 45
ifeq ($(shell echo $(OS) | egrep -c 'Darwin|FreeBSD|OpenBSD'),1)
DATE := $(shell date -j -r $(shell git log -n 1 --format="%at") +%Y%m%d%H%M)
46
else
47
DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
48
endif
49

James Laska committed
50 51 52 53
# DEB build parameters
DEBUILD_BIN ?= debuild
DEBUILD_OPTS = --source-option="-I"
DPUT_BIN ?= dput
54
DPUT_OPTS ?=
James Laska committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
ifeq ($(OFFICIAL),yes)
    DEB_RELEASE = 1ppa
    # Sign OFFICIAL builds using 'DEBSIGN_KEYID'
    # DEBSIGN_KEYID is required when signing
    ifneq ($(DEBSIGN_KEYID),)
        DEBUILD_OPTS += -k$(DEBSIGN_KEYID)
    endif
else
    DEB_RELEASE = 0.git$(DATE)
    # Do not sign unofficial builds
    DEBUILD_OPTS += -uc -us
    DPUT_OPTS += -u
endif
DEBUILD = $(DEBUILD_BIN) $(DEBUILD_OPTS)
DEB_PPA ?= ppa
# Choose the desired Ubuntu release: lucid precise saucy trusty
DEB_DIST ?= unstable

Michael DeHaan committed
73
# RPM build parameters
Tim Bielawa committed
74 75
RPMSPECDIR= packaging/rpm
RPMSPEC = $(RPMSPECDIR)/ansible.spec
76
RPMDIST = $(shell rpm --eval '%{?dist}')
77
RPMRELEASE = 1
78
ifneq ($(OFFICIAL),yes)
79 80 81
    RPMRELEASE = 0.git$(DATE)
endif
RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
82

83 84 85 86
# MOCK build parameters
MOCK_BIN ?= mock
MOCK_CFG ?=

87
NOSETESTS ?= nosetests
88

89 90
NOSETESTS3 ?= nosetests-3.3

Michael DeHaan committed
91 92
########################################################

93 94
all: clean python

95
tests:
96
	PYTHONPATH=./lib $(NOSETESTS) -d -w test/units -v # Could do: --with-coverage --cover-package=ansible
97 98

newtests:
99
	PYTHONPATH=./v2:./lib $(NOSETESTS) -d -w v2/test -v --with-coverage --cover-package=ansible --cover-branches
100

101
newtests-py3:
102
	PYTHONPATH=./v2:./lib $(NOSETESTS3) -d -w v2/test -v --with-coverage --cover-package=ansible --cover-branches
103

104 105
authors:
	sh hacking/authors.sh
106

107 108 109
# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
# recently than %.1.asciidoc.
%.1.asciidoc: %.1.asciidoc.in
110
	sed "s/%VERSION%/$(VERSION)/" $< > $@
111

112 113 114
# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
%.1: %.1.asciidoc VERSION
115 116
	$(ASCII2MAN)

117 118 119
loc:
	sloccount lib library bin

120 121 122 123
pep8:
	@echo "#############################################"
	@echo "# Running PEP8 Compliance Tests"
	@echo "#############################################"
Michael DeHaan committed
124
	-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261,E241 lib/ bin/
125
	# -pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261,E241 --filename "*" library/
126

127
pyflakes:
128
	pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
129

130
clean:
131
	@echo "Cleaning up distutils stuff"
132 133
	rm -rf build
	rm -rf dist
134
	@echo "Cleaning up byte compiled python stuff"
135
	find . -type f -regex ".*\.py[co]$$" -delete
136 137
	@echo "Cleaning up editor backup files"
	find . -type f \( -name "*~" -or -name "#*" \) -delete
138
	find . -type f \( -name "*.swp" \) -delete
139
	@echo "Cleaning up manpage stuff"
140
	find ./docs/man -type f -name "*.xml" -delete
141
	find ./docs/man -type f -name "*.asciidoc" -delete
142
	find ./docs/man/man3 -type f -name "*.3" -delete
143
	@echo "Cleaning up output from test runs"
144
	rm -rf test/test_data
145
	@echo "Cleaning up RPM building stuff"
146
	rm -rf MANIFEST rpm-build
Henry Graham committed
147 148 149
	@echo "Cleaning up Debian building stuff"
	rm -rf debian
	rm -rf deb-build
150 151
	rm -rf docs/json
	rm -rf docs/js
152 153
	@echo "Cleaning up authors file"
	rm -f AUTHORS.TXT
154

155
python:
156
	$(PYTHON) setup.py build
157

158
install:
159
	$(PYTHON) setup.py install
160

161
sdist: clean docs
162
	$(PYTHON) setup.py sdist
163

164
rpmcommon: $(MANPAGES) sdist
165 166
	@mkdir -p rpm-build
	@cp dist/*.gz rpm-build/
167
	@sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}#' $(RPMSPEC) >rpm-build/$(NAME).spec
168

169 170 171 172 173 174 175
mock-srpm: /etc/mock/$(MOCK_CFG).cfg rpmcommon
	$(MOCK_BIN) -r $(MOCK_CFG) --resultdir rpm-build/  --buildsrpm --spec rpm-build/$(NAME).spec --sources rpm-build/
	@echo "#############################################"
	@echo "Ansible SRPM is built:"
	@echo rpm-build/*.src.rpm
	@echo "#############################################"

176
mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
177 178 179 180 181 182
	$(MOCK_BIN) -r $(MOCK_CFG) --resultdir rpm-build/ --rebuild rpm-build/$(NAME)-*.src.rpm
	@echo "#############################################"
	@echo "Ansible RPM is built:"
	@echo rpm-build/*.noarch.rpm
	@echo "#############################################"

183 184 185 186 187
srpm: rpmcommon
	@rpmbuild --define "_topdir %(pwd)/rpm-build" \
	--define "_builddir %{_topdir}" \
	--define "_rpmdir %{_topdir}" \
	--define "_srcrpmdir %{_topdir}" \
Tim Bielawa committed
188
	--define "_specdir $(RPMSPECDIR)" \
189
	--define "_sourcedir %{_topdir}" \
190 191
	-bs rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
192 193 194 195 196 197 198 199 200 201
	@echo "#############################################"
	@echo "Ansible SRPM is built:"
	@echo "    rpm-build/$(RPMNVR).src.rpm"
	@echo "#############################################"

rpm: rpmcommon
	@rpmbuild --define "_topdir %(pwd)/rpm-build" \
	--define "_builddir %{_topdir}" \
	--define "_rpmdir %{_topdir}" \
	--define "_srcrpmdir %{_topdir}" \
Tim Bielawa committed
202
	--define "_specdir $(RPMSPECDIR)" \
203
	--define "_sourcedir %{_topdir}" \
204
	--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
205
	--define "__python `which $(PYTHON)`" \
206 207
	-ba rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
208 209
	@echo "#############################################"
	@echo "Ansible RPM is built:"
210
	@echo "    rpm-build/$(RPMNVR).noarch.rpm"
211
	@echo "#############################################"
212

Henry Graham committed
213
debian: sdist
James Laska committed
214 215 216 217 218 219 220
	@for DIST in $(DEB_DIST) ; do \
	    mkdir -p deb-build/$${DIST} ; \
	    tar -C deb-build/$${DIST} -xvf dist/$(NAME)-$(VERSION).tar.gz ; \
	    cp -a packaging/debian deb-build/$${DIST}/$(NAME)-$(VERSION)/ ; \
	    sed -ie "s#^$(NAME) (\([^)]*\)) \([^;]*\);#ansible (\1-$(DEB_RELEASE)~$${DIST}) $${DIST};#" deb-build/$${DIST}/$(NAME)-$(VERSION)/debian/changelog ; \
	done

Henry Graham committed
221
deb: debian
James Laska committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
	@for DIST in $(DEB_DIST) ; do \
	    (cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -b) ; \
	done
	@echo "#############################################"
	@echo "Ansible DEB artifacts:"
	@for DIST in $(DEB_DIST) ; do \
	    echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
	done
	@echo "#############################################"

deb-src: debian
	@for DIST in $(DEB_DIST) ; do \
	    (cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -S) ; \
	done
	@echo "#############################################"
	@echo "Ansible DEB artifacts:"
	@for DIST in $(DEB_DIST) ; do \
	    echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
	done
	@echo "#############################################"

deb-upload: deb
	@for DIST in $(DEB_DIST) ; do \
	    $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
	done

deb-src-upload: deb-src
	@for DIST in $(DEB_DIST) ; do \
	    $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
	done
252 253 254

# for arch or gentoo, read instructions in the appropriate 'packaging' subdirectory directory

255
webdocs: $(MANPAGES)
256
	(cd docsite/; make docs)
257

258
docs: $(MANPAGES)