Makefile
83d1028a
 # WARN: gmake syntax
9d0f2a6e
 ########################################################
 # Makefile for Ansible
 #
 # useful targets:
 #   make sdist ---------------- produce a tarball
41131149
 #   make srpm ----------------- produce a SRPM
9d0f2a6e
 #   make rpm  ----------------- produce RPMs
41131149
 #   make deb-src -------------- produce a DEB source
e3b2521f
 #   make deb ------------------ produce a DEB
9d0f2a6e
 #   make docs ----------------- rebuild the manpages (results are checked in)
ecbf8e93
 #   make tests ---------------- run the tests (see https://docs.ansible.com/ansible/dev_guide/testing_units.html for requirements)
85fb7c6d
 #   make pyflakes, make pep8 -- source code checks
9d0f2a6e
 
 ########################################################
 # variable section
 
eede23ab
 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`.
18a7a1ec
 
7cd7f544
 MANPAGES ?= $(patsubst %.asciidoc.in,%,$(wildcard ./docs/man/man1/ansible*.1.asciidoc.in))
badb4139
 ifneq ($(shell which a2x 2>/dev/null),)
20ef8d5a
 ASCII2MAN = a2x -L -D $(dir $@) -d manpage -f manpage $<
 ASCII2HTMLMAN = a2x -L -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
51949fde
 GENERATE_CLI = docs/bin/generate_man.py
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
1cf911d5
 VERSION := $(shell cat VERSION | cut -f1 -d' ')
 RELEASE := $(shell cat VERSION | cut -f2 -d' ')
9d0f2a6e
 
a162fa70
 # Get the branch information from git
ec7c8eb8
 ifneq ($(shell which git),)
 GIT_DATE := $(shell git log -n 1 --format="%ai")
df8dfdce
 GIT_HASH := $(shell git log -n 1 --format="%h")
af1f462b
 GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/[-_.\/]//g')
df8dfdce
 GITINFO = .$(GIT_HASH).$(GIT_BRANCH)
 else
bd0f9a4a
 GITINFO = ""
ec7c8eb8
 endif
83d1028a
 
b9e4a4de
 ifeq ($(shell echo $(OS) | egrep -c 'Darwin|FreeBSD|OpenBSD|DragonFly'),1)
338ecdd5
 DATE := $(shell date -j -r $(shell git log -n 1 --format="%at") +%Y%m%d%H%M)
0803c638
 CPUS ?= $(shell sysctl hw.ncpu|awk '{print $$2}')
5072ed3b
 else
765061d4
 DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
0803c638
 CPUS ?= $(shell nproc)
83d1028a
 endif
ec7c8eb8
 
41131149
 # DEB build parameters
 DEBUILD_BIN ?= debuild
 DEBUILD_OPTS = --source-option="-I"
 DPUT_BIN ?= dput
4046d1fd
 DPUT_OPTS ?=
3c1fe28b
 DEB_DATE := $(shell LC_TIME=C date +"%a, %d %b %Y %T %z")
41131149
 ifeq ($(OFFICIAL),yes)
1cf911d5
     DEB_RELEASE = $(RELEASE)ppa
41131149
     # Sign OFFICIAL builds using 'DEBSIGN_KEYID'
     # DEBSIGN_KEYID is required when signing
     ifneq ($(DEBSIGN_KEYID),)
         DEBUILD_OPTS += -k$(DEBSIGN_KEYID)
     endif
 else
329a134c
     DEB_RELEASE = 100.git$(DATE)$(GITINFO)
41131149
     # 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
 
4ae0d5b8
 # pbuilder parameters
 PBUILDER_ARCH ?= amd64
 PBUILDER_CACHE_DIR = /var/cache/pbuilder
 PBUILDER_BIN ?= pbuilder
 PBUILDER_OPTS ?= --debootstrapopts --variant=buildd --architecture $(PBUILDER_ARCH) --debbuildopts -b
 
9d0f2a6e
 # RPM build parameters
66f294d5
 RPMSPECDIR= packaging/rpm
 RPMSPEC = $(RPMSPECDIR)/ansible.spec
a37b6a2a
 RPMDIST = $(shell rpm --eval '%{?dist}')
1cf911d5
 RPMRELEASE = $(RELEASE)
346d02e3
 ifneq ($(OFFICIAL),yes)
329a134c
     RPMRELEASE = 100.git$(DATE)$(GITINFO)
ec7c8eb8
 endif
b54d00f2
 ifeq ($(PUBLISH),nightly)
     # https://fedoraproject.org/wiki/Packaging:Versioning#Snapshots
     RPMRELEASE = $(RELEASE).$(DATE)git.$(GIT_HASH)
 endif
ec7c8eb8
 RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
f0b02117
 
eede23ab
 # MOCK build parameters
 MOCK_BIN ?= mock
 MOCK_CFG ?=
 
cd3fdca5
 # ansible-test parameters
 ANSIBLE_TEST ?= test/runner/ansible-test
 TEST_FLAGS ?=
a0678771
 
cd3fdca5
 # ansible-test units parameters (make test / make test-py3)
 PYTHON_VERSION ?= $(shell python2 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
 PYTHON3_VERSION ?= $(shell python3 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
 
 # ansible-test integration parameters (make integration)
 IMAGE ?= centos7
 TARGET ?=
617352a3
 
9d0f2a6e
 ########################################################
 
3b4ff67b
 .PHONY: all
55d256d8
 all: clean python
 
3b4ff67b
 .PHONY: tests
85fb7c6d
 tests:
cd3fdca5
 	$(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS)
1aa338a3
 
3b4ff67b
 .PHONY: tests-py3
15d7f538
 tests-py3:
cd3fdca5
 	$(ANSIBLE_TEST) units -v --python $(PYTHON3_VERSION) $(TEST_FLAGS)
05c5c852
 
3b4ff67b
 .PHONY: tests-nonet
8f97aef1
 tests-nonet:
 	$(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS)  --exclude test/units/modules/network/
 
3b4ff67b
 .PHONY: integration
be113931
 integration:
cd3fdca5
 	$(ANSIBLE_TEST) integration -v --docker $(IMAGE) $(TARGET) $(TEST_FLAGS)
be113931
 
3b4ff67b
 .PHONY: authors
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)
 
3b4ff67b
 .PHONY: loc
3ad9db49
 loc:
 	sloccount lib library bin
 
3b4ff67b
 .PHONY: pep8
f0b02117
 pep8:
25cb281b
 	$(ANSIBLE_TEST) sanity --test pep8 --python $(PYTHON_VERSION) $(TEST_FLAGS)
f0b02117
 
3b4ff67b
 .PHONY: pyflakes
6541f338
 pyflakes:
906f7fd8
 	pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
6541f338
 
3b4ff67b
 .PHONY: clean
f0b02117
 clean:
2d052fce
 	@echo "Cleaning up distutils stuff"
3f9a41b2
 	rm -rf build
 	rm -rf dist
87926cbb
 	rm -rf lib/ansible.egg-info/
2d052fce
 	@echo "Cleaning up byte compiled python stuff"
3f9a41b2
 	find . -type f -regex ".*\.py[co]$$" -delete
a1a62103
 	find . -type d -name "__pycache__" -delete
2d052fce
 	@echo "Cleaning up editor backup files"
8dfefa22
 	find . -type f -not -path ./test/units/inventory_test_data/group_vars/noparse/all.yml~ \( -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
18a7a1ec
 	rm -f ./docs/man/man1/*
e835cd6f
 	@echo "Cleaning up output from test runs"
3f9a41b2
 	rm -rf test/test_data
e1416138
 	rm -rf shippable/
 	rm -rf logs/
 	rm -rf .cache/
 	rm -f test/units/.coverage*
 	rm -f test/results/*/*
 	find test/ -type f -name '*.retry' -delete
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
aae9bbde
 	@echo "Cleaning up docsite"
 	$(MAKE) -C docs/docsite clean
c0263b30
 	$(MAKE) -C docs/api clean
f0b02117
 
3b4ff67b
 .PHONY: python
9049b0e7
 python:
785068df
 	$(PYTHON) setup.py build
55d256d8
 
3b4ff67b
 .PHONY: install
9049b0e7
 install:
785068df
 	$(PYTHON) setup.py install
55d256d8
 
3b4ff67b
 .PHONY: sdist
2dcd0846
 sdist: clean docs
d287179f
 	$(PYTHON) setup.py sdist
3f245498
 
3b4ff67b
 .PHONY: sdist_upload
a196c7d7
 sdist_upload: clean docs
 	$(PYTHON) setup.py sdist upload 2>&1 |tee upload.log
 
3b4ff67b
 .PHONY: rpmcommon
669630ea
 rpmcommon: sdist
3f245498
 	@mkdir -p rpm-build
 	@cp dist/*.gz rpm-build/
b54d00f2
 	@sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}$(REPOTAG)#' $(RPMSPEC) >rpm-build/$(NAME).spec
3f245498
 
3b4ff67b
 .PHONY: mock-srpm
eede23ab
 mock-srpm: /etc/mock/$(MOCK_CFG).cfg rpmcommon
b54d00f2
 	$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/  --buildsrpm --spec rpm-build/$(NAME).spec --sources rpm-build/
eede23ab
 	@echo "#############################################"
 	@echo "Ansible SRPM is built:"
 	@echo rpm-build/*.src.rpm
 	@echo "#############################################"
 
3b4ff67b
 .PHONY: mock-rpm
4ee0898f
 mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
b54d00f2
 	$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --rebuild rpm-build/$(NAME)-*.src.rpm
eede23ab
 	@echo "#############################################"
 	@echo "Ansible RPM is built:"
 	@echo rpm-build/*.noarch.rpm
 	@echo "#############################################"
 
3b4ff67b
 .PHONY: srpm
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 "#############################################"
 
3b4ff67b
 .PHONY: rpm
3f245498
 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
 
3b4ff67b
 .PHONY: debian
21269a84
 debian: sdist
41131149
 	@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)/ ; \
bbc05a2c
         sed -ie "s|%VERSION%|$(VERSION)|g;s|%RELEASE%|$(DEB_RELEASE)|;s|%DIST%|$${DIST}|g;s|%DATE%|$(DEB_DATE)|g" deb-build/$${DIST}/$(NAME)-$(VERSION)/debian/changelog ; \
41131149
 	done
 
3b4ff67b
 .PHONY: deb
4ae0d5b8
 deb: deb-src
 	@for DIST in $(DEB_DIST) ; do \
 	    PBUILDER_OPTS="$(PBUILDER_OPTS) --distribution $${DIST} --basetgz $(PBUILDER_CACHE_DIR)/$${DIST}-$(PBUILDER_ARCH)-base.tgz --buildresult $(CURDIR)/deb-build/$${DIST}" ; \
 	    $(PBUILDER_BIN) create $${PBUILDER_OPTS} --othermirror "deb http://archive.ubuntu.com/ubuntu $${DIST} universe" ; \
 	    $(PBUILDER_BIN) update $${PBUILDER_OPTS} ; \
 	    $(PBUILDER_BIN) build $${PBUILDER_OPTS} deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}.dsc ; \
 	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 "#############################################"
 
 # Build package outside of pbuilder, with locally installed dependencies.
 # Install BuildRequires as noted in packaging/debian/control.
3b4ff67b
 .PHONY: local_deb
4ae0d5b8
 local_deb: debian
41131149
 	@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 "#############################################"
 
3b4ff67b
 .PHONY: deb-src
41131149
 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 "#############################################"
 
3b4ff67b
 .PHONY: deb-upload
41131149
 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
 
3b4ff67b
 .PHONY: deb-src-upload
41131149
 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
 
3b4ff67b
 .PHONY: epub
033fe554
 epub:
 	(cd docs/docsite/; CPUS=$(CPUS) make epub)
f72114c6
 
033fe554
 # for arch or gentoo, read instructions in the appropriate 'packaging' subdirectory directory
3b4ff67b
 .PHONY: webdocs
e6cd0dba
 webdocs:
c0263b30
 	(cd docs/docsite/; CPUS=$(CPUS) make docs)
148d8859
 
3b4ff67b
 .PHONY: generate_asciidoc
7cd7f544
 generate_asciidoc: lib/ansible/cli/*.py
51949fde
 	mkdir -p ./docs/man/man1/ ; \
 	PYTHONPATH=./lib $(GENERATE_CLI) --template-file=docs/templates/man.j2 --output-dir=docs/man/man1/ --output-format man lib/ansible/cli/*.py
 
7cd7f544
 
 docs: generate_asciidoc
18a7a1ec
 	make $(MANPAGES)
e6cd0dba
 
3b4ff67b
 .PHONY: alldocs
e6cd0dba
 alldocs: docs webdocs
18a7a1ec
 
28fb0498
 version:
 	@echo $(VERSION)