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

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

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

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

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

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

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

42 43
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)
44
else
45
DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
46
endif
47

Michael DeHaan committed
48
# RPM build parameters
Tim Bielawa committed
49 50
RPMSPECDIR= packaging/rpm
RPMSPEC = $(RPMSPECDIR)/ansible.spec
51
RPMDIST = $(shell rpm --eval '%{?dist}')
52
RPMRELEASE = 1
53
ifneq ($(OFFICIAL),yes)
54 55 56
    RPMRELEASE = 0.git$(DATE)
endif
RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
57

58 59 60 61
# MOCK build parameters
MOCK_BIN ?= mock
MOCK_CFG ?=

62
NOSETESTS ?= nosetests
63

Michael DeHaan committed
64 65
########################################################

66 67
all: clean python

68
tests:
69
	PYTHONPATH=./lib ANSIBLE_LIBRARY=./library  $(NOSETESTS) -d -w test/units -v
70

71 72
authors:
	sh hacking/authors.sh
73

74 75 76
# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
# recently than %.1.asciidoc.
%.1.asciidoc: %.1.asciidoc.in
77
	sed "s/%VERSION%/$(VERSION)/" $< > $@
78

79 80 81
# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
%.1: %.1.asciidoc VERSION
82 83
	$(ASCII2MAN)

84 85 86
loc:
	sloccount lib library bin

87 88 89 90
pep8:
	@echo "#############################################"
	@echo "# Running PEP8 Compliance Tests"
	@echo "#############################################"
Michael DeHaan committed
91 92
	-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261,E241 lib/ bin/
	-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261,E241 --filename "*" library/
93

94
pyflakes:
95
	pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
96

97
clean:
98
	@echo "Cleaning up distutils stuff"
99 100
	rm -rf build
	rm -rf dist
101
	@echo "Cleaning up byte compiled python stuff"
102
	find . -type f -regex ".*\.py[co]$$" -delete
103 104
	@echo "Cleaning up editor backup files"
	find . -type f \( -name "*~" -or -name "#*" \) -delete
105
	find . -type f \( -name "*.swp" \) -delete
106
	@echo "Cleaning up manpage stuff"
107
	find ./docs/man -type f -name "*.xml" -delete
108
	find ./docs/man -type f -name "*.asciidoc" -delete
109
	find ./docs/man/man3 -type f -name "*.3" -delete
110
	@echo "Cleaning up output from test runs"
111
	rm -rf test/test_data
112
	@echo "Cleaning up RPM building stuff"
113
	rm -rf MANIFEST rpm-build
Henry Graham committed
114 115 116
	@echo "Cleaning up Debian building stuff"
	rm -rf debian
	rm -rf deb-build
117 118
	rm -rf docs/json
	rm -rf docs/js
119 120
	@echo "Cleaning up authors file"
	rm -f AUTHORS.TXT
121

122
python:
123
	$(PYTHON) setup.py build
124

125
install:
126
	$(PYTHON) setup.py install
127

128
sdist: clean docs
129
	$(PYTHON) setup.py sdist
130

131
rpmcommon: $(MANPAGES) sdist
132 133
	@mkdir -p rpm-build
	@cp dist/*.gz rpm-build/
134
	@sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}#' $(RPMSPEC) >rpm-build/$(NAME).spec
135

136 137 138 139 140 141 142
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 "#############################################"

143
mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
144 145 146 147 148 149
	$(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 "#############################################"

150 151 152 153 154
srpm: rpmcommon
	@rpmbuild --define "_topdir %(pwd)/rpm-build" \
	--define "_builddir %{_topdir}" \
	--define "_rpmdir %{_topdir}" \
	--define "_srcrpmdir %{_topdir}" \
Tim Bielawa committed
155
	--define "_specdir $(RPMSPECDIR)" \
156
	--define "_sourcedir %{_topdir}" \
157 158
	-bs rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
159 160 161 162 163 164 165 166 167 168
	@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
169
	--define "_specdir $(RPMSPECDIR)" \
170
	--define "_sourcedir %{_topdir}" \
171
	--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
172
	--define "__python `which $(PYTHON)`" \
173 174
	-ba rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
175 176
	@echo "#############################################"
	@echo "Ansible RPM is built:"
177
	@echo "    rpm-build/$(RPMNVR).noarch.rpm"
178
	@echo "#############################################"
179

Henry Graham committed
180 181 182 183 184 185 186
debian: sdist
deb: debian
	cp -r packaging/debian ./
	chmod 755 debian/rules
	fakeroot debian/rules clean
	fakeroot dh_install
	fakeroot debian/rules binary
187 188 189

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

190
webdocs: $(MANPAGES)
191
	(cd docsite/; make docs)
192

193
docs: $(MANPAGES)