########################################################
# Common properties

pkg_name="meson"
pkg_license="apache"
pkg_maintainer="${USER} <${USER}@unknown>"
pkg_section="devel"
pkg_priority="optional"
pkg_arch="all"

pkg_commondesc="high-productivity build system"
pkg_longdesc="
Meson is a build system designed to increase programmer\n\
productivity. It does this by providing a fast, simple and easy to\n\
use interface for modern software development tools and practices.
"

pkg_giturl="${git_source_meson_debian}"
pkg_homeurl="http://mesonbuild.com"
pkg_gitbranch=${git_branch_meson}

git_commithash=${git_commithash_meson}
pkg_gitver="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"

pkg_installfile="./debian/install"
pkg_controlfile="./debian/control"
pkg_rulesfile="./debian/rules"
pkg_compatfile="./debian/compat"

########################################################
# Debian compatibility flag

pkg_debcompat="12"

########################################################
# Debian rules file section

pkg_debrules="\
#!/usr/bin/make -f
# Original script by Jussi Pakkanen

export MESON_PRINT_TEST_OUTPUT=1
export QT_SELECT=qt5
export LC_ALL=C.UTF-8
%:
	dh \$@ --with python3 --buildsystem=pybuild

override_dh_auto_configure:

override_dh_auto_build:

override_dh_auto_test:

override_dh_clean:
	dh_clean
	rm -f *.pyc
	rm -rf __pycache__
	rm -rf mesonbuild/__pycache__
	rm -rf mesonbuild/*/__pycache__
	rm -rf work\ area
	rm -rf install\ dir/*
	rm -f meson-test-run.txt meson-test-run.xml
	rm -rf meson.egg-info
	rm -rf build
	rm -rf .pybuild

override_dh_install:
# Helper script to autogenerate cross files.
	python3 setup.py install --root=\$\$(pwd)/debian/meson --prefix=/usr --install-layout=deb --install-lib=/usr/share/meson --install-scripts=/usr/share/meson
	rm -rf \$\$(pwd)/debian/meson/usr/share/meson/mesonbuild/__pycache__
	rm -rf \$\$(pwd)/debian/meson/usr/share/meson/mesonbuild/*/__pycache__
	rm \$\$(pwd)/debian/meson/usr/bin/meson
	ln -s ../share/meson/meson \$\$(pwd)/debian/meson/usr/bin/meson
"

########################################################
# Debian install file section

pkg_debinstall="empty"

########################################################
# Debian control file subfields

# Debian control file Overrides section
pkg_overrides=(
empty
)

# Debian control file Suggests section
pkg_suggests=(
empty
)

# Debian control file Conflicts section
pkg_conflicts=(
empty
)

# Debian control file Breaks section
pkg_breaks=(
empty
)

# Debian control file Replaces section
pkg_replaces=(
empty
)

# Debian control file Provides section
pkg_provides=(
empty
)

############################

# Build time dependencies
pkg_deps_build=(
'python3 (>= 3.5)'
'dh-python'
'python3-setuptools'
'ninja-build (>= 1.6)'
)

# Runtime dependencies
pkg_deps_runtime=(
'ninja-build (>=1.6)'
'python3'
)

# Extra fields for Debian control file Source (start) section
pkg_extra_1=(
'X-Python3-Version: >= 3.5'
)

# Extra fields for Debian control file Package (end) section
pkg_extra_2=(
empty
)

############################

# Deb builder execution field
# Do not build either debug symbols or doc files
pkg_debbuilder="DEB_BUILD_OPTIONS=\"strip nodocs noddebs nocheck\" dpkg-buildpackage -rfakeroot -b -us -uc -d"

########################################################
# Contents of Debian control file

# This is a necessary variable setting for array loops below
IFS=$'\n'

pkg_debcontrol="\
Source: ${pkg_name}
Section: ${pkg_section}
Priority: ${pkg_priority}
Maintainer: ${pkg_maintainer}
Build-Depends: debhelper (>=9), $(if [[ ${pkg_deps_build[0]} != "empty" ]]; then \
for w in ${pkg_deps_build[@]}; do printf '%s, ' ${w}; done; fi)
Standards-Version: 4.1.3
Homepage: ${pkg_homeurl}
$(if [[ ${pkg_extra_1[0]} != "empty" ]]; then for w in ${pkg_extra_1[@]}; do echo ${w}; done ; fi)

Package: ${pkg_name}
Architecture: ${pkg_arch}
Depends: \${shlibs:Depends}, \${misc:Depends}, $(if [[ ${pkg_deps_runtime[0]} != "empty" ]]; then \
for w in ${pkg_deps_runtime[@]}; do printf '%s, ' ${w}; done; fi)
Description: ${pkg_commondesc}
$(echo -e ${pkg_longdesc}   | sed 's/^/ /g; s/\n/\n /g')
$(if [[ ${pkg_extra_2[0]}   != "empty" ]]; then for w in ${pkg_extra_2[@]}; do echo ${w}; done ; fi)
$(if [[ ${pkg_suggests[0]}  != "empty" ]]; then echo "Suggests: $(echo ${_kg_suggests[*]}   | sed 's/\s/, /g')"; fi)
$(if [[ ${pkg_conflicts[0]} != "empty" ]]; then echo "Conflicts: $(echo ${pkg_overrides[*]} | sed 's/\s/, /g')"; fi)
$(if [[ ${pkg_breaks[0]}    != "empty" ]]; then echo "Breaks: $(echo ${pkg_overrides[*]}    | sed 's/\s/, /g')"; fi)
$(if [[ ${pkg_replaces[0]}  != "empty" ]]; then echo "Replaces: $(echo ${pkg_overrides[*]}  | sed 's/\s/, /g')"; fi)
$(if [[ ${pkg_provides[0]}  != "empty" ]]; then echo "Provides: $(echo ${pkg_overrides[*]}  | sed 's/\s/, /g')"; fi)
"

unset IFS