#
# This file is automatically generated, DO NOT EDIT!
#

.NOTPARALLEL:

CURDIR    ?= ${{.CURDIR}}
PATCH     := $(CURDIR)/../debian/tools/gitapply.sh
APPLY      = (cd "$(DESTDIR)" && $(PATCH))
APPLY_FILE = @echo "Applying $(1)"; $(APPLY) < "$(CURDIR)/$(1)"

#
# This Makefile understands the following targets:
#
# install (default):  apply patches to directory provided by DESTDIR
# install-git:        as above, but use 'git am' to apply the patches
# series:             create a 'series' file containing the patch order
# clean:              delete autogenerated and temporary files
#

PATCHLIST := \
{patchlist}

.PHONY: install
install: $(PATCHLIST)
	cat *.ok | sort | $(CURDIR)/../debian/tools/patchlist.sh | $(APPLY)
	cd $(DESTDIR) && autoreconf -f
	cd $(DESTDIR) && ./tools/make_requests

.PHONY: install-git
install-git: PATCH := git am
install-git: install

series: APPLY_FILE = @echo "$(1)" >> series
series: $(PATCHLIST)
	@cat *.ok | sort | $(CURDIR)/../debian/tools/patchlist.sh > patchlist.diff
	@echo "patchlist.diff" >> series
	@( \
		echo ""; \
		echo "The 'series' file was created in current directory. Please note that"; \
		echo "'patchlist.diff' is autogenerated based on your selection of patches and not"; \
		echo "included in this repository - keep in mind to update it on every release."; \
		echo ""; \
		echo "Moreover, depending on which patches you have selected, you will have to run"; \
		echo "'autoreconf -f' and/or './tools/make_requests' after applying them."; \
		echo ""; \
		binary=0; \
		while IFS= read -r line; do \
			if grep -q "^GIT binary patch" "$$line"; then \
				binary=1; break; \
			fi \
		done < series; \
		if [ "$$binary" -ne 0 ]; then \
			echo "The following files contain binary patches and cannot be applied with the"; \
			echo "regular 'patch' commandline tool:"; \
			echo ""; \
			while IFS= read -r line; do \
				grep -q "^GIT binary patch" "$$line" && echo "$$line"; \
			done < series; \
			echo ""; \
			echo "Please use 'git apply' or '../debian/tools/gitapply.sh' from this repository."; \
			echo ""; \
		fi \
	)

.PHONY: clean
clean:
	rm -f series patchlist.diff
	rm -f *.ok