Makefile 5.38 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 24
MANPAGES := docs/man/man1/ansible.1 docs/man/man1/ansible-playbook.1 docs/man/man1/ansible-pull.1 docs/man/man1/ansible-doc.1
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 53 54 55 56
RPMRELEASE = 1
ifeq ($(OFFICIAL),)
    RPMRELEASE = 0.git$(DATE)
endif
RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
57

58 59
NOSETESTS := nosetests

Michael DeHaan committed
60 61
########################################################

62 63
all: clean python

64
tests:
65
	PYTHONPATH=./lib ANSIBLE_LIBRARY=./library  $(NOSETESTS) -d -v
66

67 68
authors:
	sh hacking/authors.sh
69

70 71 72
# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
# recently than %.1.asciidoc.
%.1.asciidoc: %.1.asciidoc.in
73
	sed "s/%VERSION%/$(VERSION)/" $< > $@
74

75 76 77
# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
%.1: %.1.asciidoc VERSION
78 79
	$(ASCII2MAN)

80 81 82
loc:
	sloccount lib library bin

83 84 85 86
pep8:
	@echo "#############################################"
	@echo "# Running PEP8 Compliance Tests"
	@echo "#############################################"
Michael DeHaan committed
87 88
	-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/
89

90
pyflakes:
91
	pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
92

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

118
python:
119
	$(PYTHON) setup.py build
120

121
install:
122
	$(PYTHON) setup.py install
123

124
sdist: clean docs
125
	$(PYTHON) setup.py sdist -t MANIFEST.in
126

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

srpm: rpmcommon
	@rpmbuild --define "_topdir %(pwd)/rpm-build" \
	--define "_builddir %{_topdir}" \
	--define "_rpmdir %{_topdir}" \
	--define "_srcrpmdir %{_topdir}" \
Tim Bielawa committed
137
	--define "_specdir $(RPMSPECDIR)" \
138
	--define "_sourcedir %{_topdir}" \
139 140
	-bs rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
141 142 143 144 145 146 147 148 149 150
	@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
151
	--define "_specdir $(RPMSPECDIR)" \
152
	--define "_sourcedir %{_topdir}" \
153
	--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
154
	--define "__python `which $(PYTHON)`" \
155 156
	-ba rpm-build/$(NAME).spec
	@rm -f rpm-build/$(NAME).spec
157 158
	@echo "#############################################"
	@echo "Ansible RPM is built:"
159
	@echo "    rpm-build/$(RPMNVR).noarch.rpm"
160
	@echo "#############################################"
161

Henry Graham committed
162 163 164 165 166 167 168
debian: sdist
deb: debian
	cp -r packaging/debian ./
	chmod 755 debian/rules
	fakeroot debian/rules clean
	fakeroot dh_install
	fakeroot debian/rules binary
169 170 171

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

172
webdocs: $(MANPAGES)
173
	(cd docsite/; make docs)
174