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) |
e9dbebfa |
# make tests ---------------- run the tests (see https://docs.ansible.com/ansible/devel/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) |
531d7f81 |
PREFIX ?= '/usr/local' |
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 |
89c97344 |
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 |
|
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
MAJOR_VERSION := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --majorversion)
CODENAME := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --codename)
# if a specific release was not requested, set to 1 (RPMs have "fancier" logic for this further down)
RELEASE ?= 1 |
9d0f2a6e |
|
a162fa70 |
# Get the branch information from git |
ec7c8eb8 |
ifneq ($(shell which git),) |
8d66a997 |
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) |
8d66a997 |
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
|
9d0f2a6e |
# RPM build parameters |
66f294d5 |
RPMSPECDIR= packaging/rpm
RPMSPEC = $(RPMSPECDIR)/ansible.spec |
a37b6a2a |
RPMDIST = $(shell rpm --eval '%{?dist}') |
e4edb284 |
|
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 |
e4edb284 |
RPMVERSION ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --baseversion)
RPMRELEASE ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --rpmrelease)
RPMNVR = "$(NAME)-$(RPMVERSION)-$(RPMRELEASE)$(RPMDIST)$(REPOTAG)" |
f0b02117 |
|
eede23ab |
# MOCK build parameters
MOCK_BIN ?= mock
MOCK_CFG ?=
|
e4edb284 |
# dynamically add repotag define only if specified
ifneq ($(REPOTAG),)
EXTRA_RPM_DEFINES += --define "repotag $(REPOTAG)"
endif
|
cd3fdca5 |
# ansible-test parameters |
76d71f03 |
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: 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 |
|
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: 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 |
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 |
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 |
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/
|
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
|
70c475da |
.PHONY: changelog
changelog:
packaging/release/changelogs/changelog.py release -vv && packaging/release/changelogs/changelog.py generate -vv |
e4edb284 |
|
3b4ff67b |
.PHONY: rpmcommon |
669630ea |
rpmcommon: sdist |
3f245498 |
@mkdir -p rpm-build
@cp dist/*.gz rpm-build/ |
e4edb284 |
@cp $(RPMSPEC) rpm-build/$(NAME).spec |
3f245498 |
|
3b4ff67b |
.PHONY: mock-srpm |
eede23ab |
mock-srpm: /etc/mock/$(MOCK_CFG).cfg rpmcommon |
e4edb284 |
$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --bootstrap-chroot --old-chroot --buildsrpm --spec rpm-build/$(NAME).spec --sources rpm-build/ \
--define "rpmversion $(RPMVERSION)" \
--define "upstream_version $(VERSION)" \
--define "rpmrelease $(RPMRELEASE)" \
$(EXTRA_RPM_DEFINES) |
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 |
e4edb284 |
$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --bootstrap-chroot --old-chroot --rebuild rpm-build/$(NAME)-*.src.rpm \
--define "rpmversion $(RPMVERSION)" \
--define "upstream_version $(VERSION)" \
--define "rpmrelease $(RPMRELEASE)" \
$(EXTRA_RPM_DEFINES) |
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}" \ |
e4edb284 |
--define "upstream_version $(VERSION)" \
--define "rpmversion $(RPMVERSION)" \
--define "rpmrelease $(RPMRELEASE)" \
$(EXTRA_RPM_DEFINES) \ |
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}" \ |
e4edb284 |
--define "_rpmfilename $(RPMNVR).%%{ARCH}.rpm" \ |
40ca1d4b |
--define "__python `which $(PYTHON)`" \ |
e4edb284 |
--define "upstream_version $(VERSION)" \
--define "rpmversion $(RPMVERSION)" \
--define "rpmrelease $(RPMRELEASE)" \
$(EXTRA_RPM_DEFINES) \ |
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)/ ; \ |
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 |
|
00a7ff79 |
.PHONY: generate_rst
generate_rst: lib/ansible/cli/*.py |
89c97344 |
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 |
|
00a7ff79 |
docs: generate_rst |
7847b149 |
$(MAKE) $(MANPAGES) |
e6cd0dba |
|
3b4ff67b |
.PHONY: alldocs |
e6cd0dba |
alldocs: docs webdocs |
18a7a1ec |
|
28fb0498 |
version:
@echo $(VERSION) |