Makefile
83d1028a
 # WARN: gmake syntax
9d0f2a6e
 ########################################################
 # Makefile for Ansible
 #
 # useful targets:
15c58cf3
 #   make clean ---------------- clean up
 #   make webdocs -------------- produce ansible doc at docs/docsite/_build/html
9d0f2a6e
 #   make sdist ---------------- produce a tarball
41131149
 #   make deb-src -------------- produce a DEB source
e3b2521f
 #   make deb ------------------ produce a DEB
9d0f2a6e
 #   make docs ----------------- rebuild the manpages (results are checked in)
e9dbebfa
 #   make tests ---------------- run the tests (see https://docs.ansible.com/ansible/devel/dev_guide/testing_units.html for requirements)
9d0f2a6e
 
 ########################################################
 # variable section
 
04ec7216
 NAME = ansible-base
83d1028a
 OS = $(shell uname -s)
531d7f81
 PREFIX ?= '/usr/local'
5f227fe2
 SDIST_DIR ?= 'dist'
9d0f2a6e
 
3f9a41b2
 # This doesn't evaluate until it's called. The -D argument is the
 # directory of the target file ($@), kinda like `dirname`.
00a7ff79
 MANPAGES ?= $(patsubst %.rst.in,%,$(wildcard ./docs/man/man1/ansible*.1.rst.in))
 ifneq ($(shell which rst2man 2>/dev/null),)
 ASCII2MAN = rst2man $< $@
 else ifneq ($(shell which rst2man.py 2>/dev/null),)
 ASCII2MAN = rst2man.py $< $@
badb4139
 else
00a7ff79
 ASCII2MAN = @echo "ERROR: rst2man from docutils command is not installed but is required to build $(MANPAGES)" && exit 1
badb4139
 endif
9d0f2a6e
 
785068df
 PYTHON=python
019d078a
 GENERATE_CLI = hacking/build-ansible.py generate-man
5ba7063f
 
e4edb284
 # fetch version from project release.py as single source-of-truth
 VERSION := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --raw || echo error)
 ifeq ($(findstring error,$(VERSION)), error)
 $(error "version_helper failed")
 endif
 
a162fa70
 # Get the branch information from git
ec7c8eb8
 ifneq ($(shell which git),)
97edfccc
 GIT_DATE := $(shell git log -n 1 --format="%ci")
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)
97edfccc
 DATE := $(shell date -j -r $(shell git log -n 1 --format="%ct") +%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")
e4edb284
 DEB_VERSION ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --debversion)
41131149
 ifeq ($(OFFICIAL),yes)
e4edb284
     DEB_RELEASE ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --debrelease)ppa
41131149
     # Sign OFFICIAL builds using 'DEBSIGN_KEYID'
     # DEBSIGN_KEYID is required when signing
     ifneq ($(DEBSIGN_KEYID),)
         DEBUILD_OPTS += -k$(DEBSIGN_KEYID)
     endif
 else
e4edb284
     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
 
cd3fdca5
 # ansible-test parameters
ac492476
 ANSIBLE_TEST ?= bin/ansible-test
cd3fdca5
 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: integration
be113931
 integration:
cd3fdca5
 	$(ANSIBLE_TEST) integration -v --docker $(IMAGE) $(TARGET) $(TEST_FLAGS)
be113931
 
00a7ff79
 # Regenerate %.1.rst if %.1.rst.in has been modified more
 # recently than %.1.rst.
 %.1.rst: %.1.rst.in
3f9a41b2
 	sed "s/%VERSION%/$(VERSION)/" $< > $@
00a7ff79
 	rm $<
f0b02117
 
e4edb284
 # Regenerate %.1 if %.1.rst or release.py has been modified more
00a7ff79
 # recently than %.1. (Implicitly runs the %.1.rst recipe)
e4edb284
 %.1: %.1.rst lib/ansible/release.py
f0b02117
 	$(ASCII2MAN)
 
3b4ff67b
 .PHONY: clean
f0b02117
 clean:
2d052fce
 	@echo "Cleaning up distutils stuff"
3f9a41b2
 	rm -rf build
 	rm -rf dist
7323d5dd
 	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
00a7ff79
 	find ./docs/man -type f -name "*.rst" -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*
f9370c95
 	rm -rf test/results/*/*
e1416138
 	find test/ -type f -name '*.retry' -delete
21269a84
 	@echo "Cleaning up Debian building stuff"
 	rm -rf debian
 	rm -rf deb-build
ee679c01
 	rm -rf docs/json
 	rm -rf docs/js
aae9bbde
 	@echo "Cleaning up docsite"
 	$(MAKE) -C docs/docsite clean
f0b02117
 
3b4ff67b
 .PHONY: python
9049b0e7
 python:
785068df
 	$(PYTHON) setup.py build
55d256d8
 
3b4ff67b
 .PHONY: install
9049b0e7
 install:
785068df
 	$(PYTHON) setup.py install
55d256d8
 
531d7f81
 install_manpages:
 	gzip -9 $(wildcard ./docs/man/man1/ansible*.1)
 	cp $(wildcard ./docs/man/man1/ansible*.1.gz) $(PREFIX)/man/man1/
 
19c0511f
 .PHONY: sdist_check
 sdist_check:
73d343b7
 	$(PYTHON) -c 'import setuptools, sys; sys.exit(int(not (tuple(map(int, setuptools.__version__.split("."))) > (39, 2, 0))))'
19c0511f
 	$(PYTHON) packaging/sdist/check-link-behavior.py
 
3b4ff67b
 .PHONY: sdist
19c0511f
 sdist: sdist_check clean docs
5f227fe2
 	_ANSIBLE_SDIST_FROM_MAKEFILE=1 $(PYTHON) setup.py sdist --dist-dir=$(SDIST_DIR)
5ba7063f
 
 # Official releases generate the changelog as the last commit before the release.
 # Snapshots shouldn't result in new checkins so the changelog is generated as
 # part of creating the tarball.
 .PHONY: snapshot
b54fddb7
 snapshot: sdist_check clean docs changelog
5f227fe2
 	_ANSIBLE_SDIST_FROM_MAKEFILE=1 $(PYTHON) setup.py sdist --dist-dir=$(SDIST_DIR)
3f245498
 
3b4ff67b
 .PHONY: sdist_upload
a196c7d7
 sdist_upload: clean docs
 	$(PYTHON) setup.py sdist upload 2>&1 |tee upload.log
 
70c475da
 .PHONY: changelog
 changelog:
a114da80
 	PYTHONPATH=./lib antsibull-changelog release -vv --use-ansible-doc && PYTHONPATH=./lib antsibull-changelog generate -vv --use-ansible-doc
e4edb284
 
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)/ ; \
e4edb284
         sed -ie "s|%VERSION%|$(DEB_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} ; \
e4edb284
 	    $(PBUILDER_BIN) build $${PBUILDER_OPTS} deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}.dsc ; \
4ae0d5b8
 	done
 	@echo "#############################################"
 	@echo "Ansible DEB artifacts:"
 	@for DIST in $(DEB_DIST) ; do \
e4edb284
 	    echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
4ae0d5b8
 	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 \
e4edb284
 	    echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
41131149
 	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 \
0371e7c8
 	    echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
41131149
 	done
 	@echo "#############################################"
 
3b4ff67b
 .PHONY: deb-upload
41131149
 deb-upload: deb
 	@for DIST in $(DEB_DIST) ; do \
0371e7c8
 	    $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
41131149
 	done
 
3b4ff67b
 .PHONY: deb-src-upload
41131149
 deb-src-upload: deb-src
 	@for DIST in $(DEB_DIST) ; do \
0371e7c8
 	    $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
41131149
 	done
f72114c6
 
3b4ff67b
 .PHONY: epub
033fe554
 epub:
7847b149
 	(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:
7847b149
 	(cd docs/docsite/; CPUS=$(CPUS) $(MAKE) docs)
148d8859
 
f110bcd5
 .PHONY: linkcheckdocs
 linkcheckdocs:
 	(cd docs/docsite/; CPUS=$(CPUS) $(MAKE) linkcheckdocs)
 
00a7ff79
 .PHONY: generate_rst
 generate_rst: lib/ansible/cli/*.py
89c97344
 	mkdir -p ./docs/man/man1/ ; \
46b1a999
 	$(GENERATE_CLI) --template-file=docs/templates/man.j2 --output-dir=docs/man/man1/ --output-format man lib/ansible/cli/*.py
89c97344
 
7cd7f544
 
00a7ff79
 docs: generate_rst
7847b149
 	$(MAKE) $(MANPAGES)
e6cd0dba
 
3b4ff67b
 .PHONY: alldocs
e6cd0dba
 alldocs: docs webdocs
18a7a1ec
 
28fb0498
 version:
 	@echo $(VERSION)