--- /dev/null
+This directory contains the debian directories for backports to other debian
+platforms. These are built via the `3.0 (custom)' source format, which
+allows one to build a source package directly out of tarballs (e.g. an
+orig.tar.gz tarball and a debian.tar.gz file), at which point the format can
+be changed to a real format (e.g. `3.0 (quilt)').
+
+Source packages are assembled via targets of the same name as the system to
+which the backport is done (e.g. `precise'), included in debian/rules.
+
+To create a new debian backport:
+
+* Add its name to `KNOWN_BACKPORTS', defined in debian/rules.
+* Create a directory of the same name in debian/backports.
+* Add the files `exclude', `versionext', and `debian/source/format' under
+ this directory:
+ * `exclude' contains whitespace-separated paths (relative to the root of
+ the source dir) that should be excluded from the source package (e.g.
+ debian/patches).
+ * `versionext' contains the suffix added to the version number for this
+ backport's build. Distributions often have guidelines for what this
+ should be. If left empty, no new debian/changelog entry is created.
+ * `debian/source/format' should contain the source format of the resulting
+ source package. As of of the writing of this document the only supported
+ format is `3.0 (quilt)'.
+* Add appropriate files under the `debian/' subdirectory. These will be
+ included in the source package, overriding any top-level `debian/' files
+ with equivalent paths.
+
--- /dev/null
+.PHONY: backports $(KNOWN_BACKPORTS)
+
+# error out if these files are missing
+required_files = $(foreach backport,$(KNOWN_BACKPORTS), \
+ $(addprefix debian/backports/$(backport)/, \
+ debian/source/format \
+ versionext \
+ exclude))
+$(if $(filter-out $(wildcard $(required_files)),$(required_files)), \
+ $(error missing required backports files: \
+ $(filter-out $(wildcard $(required_files)),$(required_files)). \
+ see debian/backports/README) \
+)
+
+TARBALLDIR ?= $(shell dh_testdir debian/changelog && realpath ../)
+
+define backports-targets
+# if this file is empty, no automatic changelog entry is created
+VERSIONEXT_$(1) ?= $(strip \
+ $(shell cat $(wildcard debian/backports/$(1)/versionext)))
+DEBIAN_VERSION_$(1) = $(DEBIAN_VERSION)$$(VERSIONEXT_$(1))
+BACKPORTDIR_$(1) = $(realpath debian/backports/$(1))
+
+# as of right now, must be '3.0 (quilt)'
+SOURCEFORMAT_$(1) ?= $(strip \
+ $(shell cat debian/backports/$(1)/debian/source/format))
+
+# files checked for the dirhash (see below)
+FINDCMD_$(1) = find debian/backports/$(1)/debian \
+ -type f \
+ ! -path debian/backports/$(1)/debian/changelog
+
+# files *not* pulled from the root debian directory into the backport tarball:
+# debian/changelog (copied and edited for backport version entry)
+# debian/backports itself (relevant contents are copied out separately)
+# anything provided in the current backports debian dir
+# anything specified in the 'exclude' file in the current backports debian dir
+EXCLUDEROOT_$(1) = debian/changelog debian/backports \
+ $$(subst debian/backports/$(1)/,,$$(shell $$(FINDCMD_$(1)))) \
+ $$(shell cat debian/backports/$(1)/exclude)
+
+EXCLUDEROOT_TAR_$(1) = $$(foreach file,$$(EXCLUDEROOT_$(1)),--exclude $$(file))
+EXCLUDEROOT_FIND_$(1) = $$(foreach file,$$(EXCLUDEROOT_$(1)),-o -path $$(file))
+
+# find command resulting in all files that *will* be pulled into the backport
+# tarball.
+FINDCMDROOT_$(1) = find debian/ \
+ '(' -false $$(EXCLUDEROOT_FIND_$(1)) ')' -prune -o \
+ -type f -a '!' '(' -false $$(EXCLUDEROOT_FIND_$(1)) ')'
+
+# usually using `find' output for dependencies has the downfall of not tracking
+# file removal. Work around that by introducing a dependency on a file whose
+# name contains the hash of `find' output, so that the name will change when a
+# file is deleted.
+DIRHASH_$(1) = \
+ $$(shell $$(FINDCMD_$(1)) | sha1sum | sed -r 's/^(......).*/\1/')
+DIRHASHROOT_$(1) = \
+ $$(shell $$(FINDCMDROOT_$(1)) | sha1sum | sed -r 's/^(......).*/\1/')
+
+CONTROL_$(1) = $$(strip \
+ $$(if $$(wildcard $$(BACKPORTDIR_$(1))/debian/control), \
+ $$(BACKPORTDIR_$(1))/debian/control, \
+ $(realpath debian/control) \
+ ))
+
+# TARGETS:
+
+$(1): $(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc ;
+
+# we use 3.0 (custom) to build a source package directly from tarballs,
+# bypassing the usual checks (which wouldn't like our combination-of-
+# directories approach)
+$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc:
+ # -b directory unused (but required) for '3.0 (custom)' source format
+ dpkg-source -l$$(BACKPORTDIR_$(1))/debian/changelog \
+ -c$$(CONTROL_$(1)) \
+ --format='3.0 (custom)' \
+ --target-format='$$(SOURCEFORMAT_$(1))' \
+ --build . $$^
+
+ifeq ($$(SOURCEFORMAT_$(1)),3.0 (quilt))
+# this target depends on the orig.tar.gz file, for which there is no target in
+# this makefile. It is assumed to either already exist or be built by a target
+# provided elsewhere in debian/rules (e.g. via pristine-tar)
+$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc: \
+ $(TARBALLDIR)/$(SRCPKG)_$(ORIG_VERSION).orig.tar.gz \
+ $(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).debian.tar.xz
+else
+$$(error unsupported source format for $(1) backport: $$(SOURCEFORMAT_$(1)))
+endif #SOURCEFORMAT_$(1)
+
+# for 3.0 (quilt)
+$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).debian.tar.xz: \
+ $$(BACKPORTDIR_$(1))/debian/changelog \
+ $$(shell $$(FINDCMD_$(1))) \
+ $$(BACKPORTDIR_$(1))/$$(DIRHASH_$(1)).backport.dirhash \
+ $$(shell $$(FINDCMDROOT_$(1))) \
+ $$(BACKPORTDIR_$(1))/$$(DIRHASHROOT_$(1)).root.dirhash \
+ $$(BACKPORTDIR_$(1))/exclude
+ rm -f $$(subst .tar.xz,.tar,$$@) $$@
+ tar -cf $$(subst .tar.xz,.tar,$$@) \
+ --exclude-vcs $$(EXCLUDEROOT_TAR_$(1)) debian/
+ cd debian/backports/$(1) && tar -uf $$(subst .tar.xz,.tar,$$@) \
+ --exclude-vcs debian/
+ xz $$(subst .tar.xz,.tar,$$@)
+
+$$(BACKPORTDIR_$(1))/debian/changelog: \
+ debian/changelog \
+ debian/backports/$(1)/versionext
+ rm -f debian/backports/$(1)/debian/changelog
+ cp $$< $$@
+ $(if $$(VERSIONEXT_$(1)), \
+ dch -c $$@ -v '$$(DEBIAN_VERSION_$(1))' -b \
+ 'backport to $(1) systems', \
+ )
+
+$$(BACKPORTDIR_$(1))/$$(DIRHASH_$(1)).backport.dirhash:
+ rm -f debian/backports/$(1)/*.backport.dirhash
+ touch $$@
+
+$$(BACKPORTDIR_$(1))/$$(DIRHASHROOT_$(1)).root.dirhash:
+ rm -f debian/backports/$(1)/*.root.dirhash
+ touch $$@
+
+endef # backports-targets
+$(foreach backport,$(KNOWN_BACKPORTS),$(eval \
+ $(call backports-targets,$(backport))))
+
+backports: $(KNOWN_BACKPORTS)
--- /dev/null
+#!/usr/bin/make -f
+
+export DH_VERBOSE=1
+export DEB_BUILD_HARDENING=1
+export DH_OPTIONS=-v
+
+ifeq ($(WANT_SNMP), 1)
+ USE_SNMP=--enable-snmp
+ $(warning "DEBIAN: SNMP enabled, sorry for your inconvenience")
+else
+ $(warning "DEBIAN: SNMP disabled, see README.Debian")
+endif
+
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+ DEBIAN_JOBS := $(subst parallel=,,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+endif
+
+ifdef DEBIAN_JOBS
+MAKEFLAGS += -j$(DEBIAN_JOBS)
+endif
+
+%:
+ dh $@ --with=systemd,autoreconf --parallel --dbg-package=frr-dbg --list-missing
+
+override_dh_auto_configure:
+ # Frr needs /proc to check some BSD vs Linux specific stuff.
+ # Else it fails with an obscure error message pointing out that
+ # IPCTL_FORWARDING is an undefined symbol which is not very helpful.
+ @if ! [ -d /proc/1 ]; then \
+ echo "./configure needs a mounted /proc"; \
+ exit 1; \
+ fi
+
+ if ! [ -e config.status ]; then \
+ dh_auto_configure -- \
+ --enable-exampledir=/usr/share/doc/frr/examples/ \
+ --localstatedir=/var/run/frr \
+ --sbindir=/usr/lib/frr \
+ --sysconfdir=/etc/frr \
+ $(USE_SNMP) \
+ --enable-ospfapi=yes \
+ --enable-vtysh=yes \
+ --enable-isisd=yes \
+ --enable-multipath=256 \
+ --enable-user=frr \
+ --enable-group=frr \
+ --enable-vty-group=frrvty \
+ --enable-configfile-mask=0640 \
+ --enable-logfile-mask=0640 \
+ --enable-werror \
+ --enable-gcc-rdynamic \
+ --with-libpam \
+ --enable-systemd=yes \
+ --enable-poll=yes \
+ --enable-cumulus=yes \
+ --enable-pimd=yes \
+ --enable-dependency-tracking \
+ --enable-bgp-vnc=no; \
+ fi
+
+override_dh_auto_build:
+ #dh_auto_build
+ $(MAKE)
+ dh_auto_build -- -C doc draft-zebra-00.txt
+
+
+ # doc/ is a bit crazy
+ifeq ($(GENERATE_PDF), 1)
+ dh_auto_build -- -C doc frr.pdf || true # pdfetex fails with exit code 1 but still produces a good looking .pdf
+endif
+ rm -vf doc/frr.info
+ dh_auto_build -- -C doc frr.info
+ rm -vf doc/frr.info.html*
+
+override_dh_auto_test:
+
+override_dh_auto_install:
+ dh_auto_install
+
+ # cleaning up the info dir
+ rm -f debian/tmp/usr/share/info/dir*
+
+ # install config files
+ mkdir -p debian/tmp/etc/frr/
+ perl -pi -e 's#^!log file #!log file /var/log/frr/#' debian/tmp/usr/share/doc/frr/examples/*sample*
+
+ # installing the Frr specific SNMP MIB
+ install -D -m 644 ./zebra/GNOME-PRODUCT-ZEBRA-MIB debian/tmp/usr/share/snmp/mibs/GNOME-PRODUCT-ZEBRA-MIB
+
+ # cleaning .la files
+ sed -i "/dependency_libs/ s/'.*'/''/" debian/tmp/usr/lib/*.la
+
+override_dh_systemd_start:
+ dh_systemd_start frr.service
+
+override_dh_systemd_enable:
+ dh_systemd_enable frr.service
+