Makefile
f0b02117
 #!/usr/bin/make
83d1028a
 # WARN: gmake syntax
9d0f2a6e
 ########################################################
 # Makefile for Ansible
 #
 # useful targets:
 #   make sdist ---------------- produce a tarball
2aa7ce00
 #   make srpm ----------------- produce a SRPM
9d0f2a6e
 #   make rpm  ----------------- produce RPMs
2aa7ce00
 #   make deb-src -------------- produce a DEB source
e3b2521f
 #   make deb ------------------ produce a DEB
9d0f2a6e
 #   make docs ----------------- rebuild the manpages (results are checked in)
 #   make tests ---------------- run the tests
85fb7c6d
 #   make pyflakes, make pep8 -- source code checks
9d0f2a6e
 
 ########################################################
 # variable section
 
84c40fc1
 NAME = ansible
83d1028a
 OS = $(shell uname -s)
9d0f2a6e
 
 # Manpages are currently built with asciidoc -- would like to move to markdown
3f9a41b2
 # This doesn't evaluate until it's called. The -D argument is the
 # directory of the target file ($@), kinda like `dirname`.
12c812f0
 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
badb4139
 ifneq ($(shell which a2x 2>/dev/null),)
f0b02117
 ASCII2MAN = a2x -D $(dir $@) -d manpage -f manpage $<
 ASCII2HTMLMAN = a2x -D docs/html/man/ -d manpage -f xhtml
badb4139
 else
 ASCII2MAN = @echo "ERROR: AsciiDoc 'a2x' command is not installed but is required to build $(MANPAGES)" && exit 1
 endif
9d0f2a6e
 
785068df
 PYTHON=python
 SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
9d0f2a6e
 
 # VERSION file provides one place to update the software version
3f9a41b2
 VERSION := $(shell cat VERSION)
9d0f2a6e
 
a162fa70
 # Get the branch information from git
ec7c8eb8
 ifneq ($(shell which git),)
 GIT_DATE := $(shell git log -n 1 --format="%ai")
 endif
83d1028a
 
338ecdd5
 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)
5072ed3b
 else
765061d4
 DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
83d1028a
 endif
ec7c8eb8
 
2aa7ce00
 # DEB build parameters
 DEBUILD_BIN ?= debuild
 DEBUILD_OPTS = --source-option="-I"
 DPUT_BIN ?= dput
2c6c1b99
 DPUT_OPTS ?=
2aa7ce00
 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
 
9d0f2a6e
 # RPM build parameters
66f294d5
 RPMSPECDIR= packaging/rpm
 RPMSPEC = $(RPMSPECDIR)/ansible.spec
a37b6a2a
 RPMDIST = $(shell rpm --eval '%{?dist}')
ec7c8eb8
 RPMRELEASE = 1
 ifeq ($(OFFICIAL),)
     RPMRELEASE = 0.git$(DATE)
 endif
 RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
f0b02117
 
84c40fc1
 # MOCK build parameters
 MOCK_BIN ?= mock
 MOCK_CFG ?=
 
a77ea0f9
 NOSETESTS ?= nosetests
a0678771
 
9d0f2a6e
 ########################################################
 
55d256d8
 all: clean python
 
85fb7c6d
 tests:
f0dd0403
 	PYTHONPATH=./lib ANSIBLE_LIBRARY=./library  $(NOSETESTS) -d -w test/units -v
05c5c852
 
fa550f3d
 authors:
 	sh hacking/authors.sh
f0b02117
 
d43cf592
 # Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
 # recently than %.1.asciidoc.
 %.1.asciidoc: %.1.asciidoc.in
3f9a41b2
 	sed "s/%VERSION%/$(VERSION)/" $< > $@
f0b02117
 
3f9a41b2
 # Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
 # recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
 %.1: %.1.asciidoc VERSION
f0b02117
 	$(ASCII2MAN)
 
3ad9db49
 loc:
 	sloccount lib library bin
 
f0b02117
 pep8:
 	@echo "#############################################"
 	@echo "# Running PEP8 Compliance Tests"
 	@echo "#############################################"
00c28e28
 	-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/
f0b02117
 
6541f338
 pyflakes:
906f7fd8
 	pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
6541f338
 
f0b02117
 clean:
2d052fce
 	@echo "Cleaning up distutils stuff"
3f9a41b2
 	rm -rf build
 	rm -rf dist
2d052fce
 	@echo "Cleaning up byte compiled python stuff"
3f9a41b2
 	find . -type f -regex ".*\.py[co]$$" -delete
2d052fce
 	@echo "Cleaning up editor backup files"
 	find . -type f \( -name "*~" -or -name "#*" \) -delete
de3cff8c
 	find . -type f \( -name "*.swp" \) -delete
9541b47b
 	@echo "Cleaning up manpage stuff"
f1c8fc63
 	find ./docs/man -type f -name "*.xml" -delete
d43cf592
 	find ./docs/man -type f -name "*.asciidoc" -delete
9541b47b
 	find ./docs/man/man3 -type f -name "*.3" -delete
e835cd6f
 	@echo "Cleaning up output from test runs"
3f9a41b2
 	rm -rf test/test_data
3f245498
 	@echo "Cleaning up RPM building stuff"
3f9a41b2
 	rm -rf MANIFEST rpm-build
21269a84
 	@echo "Cleaning up Debian building stuff"
 	rm -rf debian
 	rm -rf deb-build
ee679c01
 	rm -rf docs/json
 	rm -rf docs/js
ec6236a1
 	@echo "Cleaning up authors file"
 	rm -f AUTHORS.TXT
f0b02117
 
9049b0e7
 python:
785068df
 	$(PYTHON) setup.py build
55d256d8
 
9049b0e7
 install:
785068df
 	$(PYTHON) setup.py install
55d256d8
 
2dcd0846
 sdist: clean docs
d287179f
 	$(PYTHON) setup.py sdist
3f245498
 
1270e235
 rpmcommon: $(MANPAGES) sdist
3f245498
 	@mkdir -p rpm-build
 	@cp dist/*.gz rpm-build/
ec7c8eb8
 	@sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}#' $(RPMSPEC) >rpm-build/$(NAME).spec
3f245498
 
84c40fc1
 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 "#############################################"
 
c35bbdaa
 mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
84c40fc1
 	$(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 "#############################################"
 
3f245498
 srpm: rpmcommon
 	@rpmbuild --define "_topdir %(pwd)/rpm-build" \
 	--define "_builddir %{_topdir}" \
 	--define "_rpmdir %{_topdir}" \
 	--define "_srcrpmdir %{_topdir}" \
66f294d5
 	--define "_specdir $(RPMSPECDIR)" \
3f245498
 	--define "_sourcedir %{_topdir}" \
ec7c8eb8
 	-bs rpm-build/$(NAME).spec
 	@rm -f rpm-build/$(NAME).spec
3f245498
 	@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}" \
66f294d5
 	--define "_specdir $(RPMSPECDIR)" \
3f245498
 	--define "_sourcedir %{_topdir}" \
d4b6aecd
 	--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
40ca1d4b
 	--define "__python `which $(PYTHON)`" \
ec7c8eb8
 	-ba rpm-build/$(NAME).spec
 	@rm -f rpm-build/$(NAME).spec
3f245498
 	@echo "#############################################"
 	@echo "Ansible RPM is built:"
6b774f8c
 	@echo "    rpm-build/$(RPMNVR).noarch.rpm"
3f245498
 	@echo "#############################################"
f72114c6
 
21269a84
 debian: sdist
2aa7ce00
 	@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
 
21269a84
 deb: debian
2aa7ce00
 	@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
f72114c6
 
 # for arch or gentoo, read instructions in the appropriate 'packaging' subdirectory directory
 
fe2d00d9
 webdocs: $(MANPAGES)
0cd09dd5
 	(cd docsite/; make docs)
148d8859
 
ba4fbd2b
 docs: $(MANPAGES)