# debian/rules integration for django-debian


# Required variables
DJANGO_DEBIAN_PACKAGE?=$(error DJANGO_DEBIAN_PACKAGE is not defined)


# Configuration
django_debian_dbtypes?=sqlite3
django_debian_purge_media_files?=no
django_debian_settings_module?=
django_debian_synchronize_db?=yes
django_debian_use_dbconfig_common?=yes
django_debian_use_south?=no
django_debian_upgrade_to_south?=true
django_debian_use_staticfiles?=no
django_debian_version?=1
django_debian_web_server_integration?=apache2
django_debian_web_server_integration_files?=standard
django_debian_settings_module?=$(error You need to define django_debian_settings_module)


# Internals

# Configuration exported to maintainer scripts
define _django_debian_configuration
    # COPY OF PACKAGE SPECIFIC CONFIGURATION
    django_debian_dbtypes="$(django_debian_dbtypes)"
    django_debian_purge_media_files="$(django_debian_purge_media_files)"
    django_debian_settings_module="$(django_debian_settings_module)"
    django_debian_synchronize_db="$(django_debian_synchronize_db)"
    django_debian_use_dbconfig_common="$(django_debian_use_dbconfig_common)"
    django_debian_use_south="$(django_debian_use_south)"
    django_debian_use_staticfiles="$(django_debian_use_staticfiles)"
    django_debian_version="$(django_debian_version)"
    django_debian_web_server_integration="$(django_debian_web_server_integration)"
    django_debian_web_server_integration_files="$(django_debian_web_server_integration_files)"
    # END OF COPY OF PACKAGE SPECIFIC CONFIGURATION
endef

# Config file template
define _django_debian_config_template
#!/bin/sh
set -e
# This script was generated with django-debian

# Source debconf library
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

# Source django-debian library, setup package specific
# variables and call the hook function
if [ -f /usr/share/django-debian/dpkg/config ]; then
    . /usr/share/django-debian/dpkg/config
$(_django_debian_configuration)
    django_debian_go $(DJANGO_DEBIAN_PACKAGE) $$@
fi
endef


# Post-installation script template
#
define _django_debian_postinst_template
#!/bin/sh
set -e
# This script was generated with django-debian

# Source debconf library
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

# Source django-debian library, setup package specific
# variables and call the hook function
if [ -f /usr/share/django-debian/dpkg/postinst ]; then
    . /usr/share/django-debian/dpkg/postinst
$(_django_debian_configuration)
    # South migration function
    django_debian_upgrade_to_south() {
$(django_debian_upgrade_to_south)
    }
    django_debian_go $(DJANGO_DEBIAN_PACKAGE) $$@
fi


exit 0
endef


# Pre-removal script template
#
#
define _django_debian_prerm_template
#!/bin/sh
set -e
# This script was generated with django-debian

# Source debconf library
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

# Source django-debian library, setup package specific
# variables and call the hook function
if [ -f /usr/share/django-debian/dpkg/prerm ]; then
    . /usr/share/django-debian/dpkg/prerm
$(_django_debian_configuration)
    django_debian_go $(DJANGO_DEBIAN_PACKAGE) $$@
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#


exit 0
endef


# Post-removal script template
#
#
define _django_debian_postrm_template
#!/bin/sh
set -e
# This script was generated with django-debian

# Source debconf library
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

# Source django-debian library, setup package specific
# variables and call the hook function
if [ -f /usr/share/django-debian/dpkg/postrm ]; then
    . /usr/share/django-debian/dpkg/postrm
$(_django_debian_configuration)
    django_debian_go $(DJANGO_DEBIAN_PACKAGE) $$@
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#


exit 0
endef


# Rules:
#
export _django_debian_config_template
override_dh_auto_build: debian/$(DJANGO_DEBIAN_PACKAGE).config
debian/$(DJANGO_DEBIAN_PACKAGE).config: debian/rules
	echo "$$_django_debian_config_template" > $@ 

export _django_debian_postinst_template
override_dh_auto_build: debian/$(DJANGO_DEBIAN_PACKAGE).postinst
debian/$(DJANGO_DEBIAN_PACKAGE).postinst: debian/rules
	echo "$$_django_debian_postinst_template" > $@ 

export _django_debian_prerm_template
override_dh_auto_build: debian/$(DJANGO_DEBIAN_PACKAGE).prerm
debian/$(DJANGO_DEBIAN_PACKAGE).prerm: debian/rules
	echo "$$_django_debian_prerm_template" > $@ 

export _django_debian_postrm_template
override_dh_auto_build: debian/$(DJANGO_DEBIAN_PACKAGE).postrm
debian/$(DJANGO_DEBIAN_PACKAGE).postrm: debian/rules
	echo "$$_django_debian_postrm_template" > $@ 

.PHONY: override_dh_auto_build
override_dh_auto_build:
	dh_auto_build

.PHONY: override_dh_clean
override_dh_clean:
	dh_clean
	rm -f debian/$(DJANGO_DEBIAN_PACKAGE).config
	rm -f debian/$(DJANGO_DEBIAN_PACKAGE).postinst
	rm -f debian/$(DJANGO_DEBIAN_PACKAGE).prerm
	rm -f debian/$(DJANGO_DEBIAN_PACKAGE).postrm
