################################################################################
#
# ggz.cygclass - functions for building GGZ packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2015 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/ggz.cygclass
#  DESCRIPTION
#  The GGZ Gaming Zone is a framework for hosting and playing multi-player
#  games over the Internet.  The project provides a server for self-hosting,
#  client libraries, and client games.
#
#  This cygclass is used for building GGZ upstream components and provides
#  functions for installing third-party clients.
#  NOTE
#  Upstream development seems to have ceased, and projects which previously
#  provided GGZ functionality have removed those dependencies.  Therefore, this
#  cygclass is deprecated and may be removed in the future.
#****

#****o* ggz.cygclass/CATEGORY (ggz)
#  DEFINITION
CATEGORY="Games"
#****
#****o* ggz.cygclass/SUMMARY (ggz)
#  DEFINITION
SUMMARY="GGZ Gaming Zone ${PN#ggz-} component"
#****
#****o* ggz.cygclass/HOMEPAGE (ggz)
#  DEFINITION
HOMEPAGE="http://dev.ggzgamingzone.org/"
#****
#****o* ggz.cygclass/SRC_URI (ggz)
#  DEFINITION
SRC_URI="http://ftp.ggzgamingzone.org/pub/ggz/${PV}/${P}.tar.gz "
#****

#****d* ggz.cygclass/GGZ_MODULES_DIR
#  DESCRIPTION
#  The directory where GGZ ModuleInfo description files are installed.
#****
GGZ_MODULES_DIR=/etc/ggz/modules

export ac_cv_header_winsock_h=no
export ac_cv_header_winsock2_h=no

#****I* ggz.cygclass/ggz_postinst
#  DESCRIPTION
#  Creates postinstall and preremove scripts which de/register GGZ ModuleInfo
#  description files with ggz-config.
#****
ggz_postinst() {
	local g

	rm -f ${D}/etc/ggz.modules

	if defined GGZMODS
	then
		doggzmod ${GGZMODS}
	fi

	for g in $(ls ${D}${GGZ_MODULES_DIR}/* 2> /dev/null)
	do
		dodir /etc/postinstall /etc/preremove

		cat >> ${D}/etc/postinstall/${PN}.sh <<-_EOF
			/usr/bin/ggz-config --force --install --modfile=${GGZ_MODULES_DIR}/${g##*/}
			_EOF

		cat >> ${D}/etc/preremove/${PN}.sh <<-_EOF
			/usr/bin/ggz-config --remove --modfile=${GGZ_MODULES_DIR}/${g##*/}
			_EOF
	done
}

#****I* ggz.cygclass/doggzmod
#  SYNOPSIS
#  doggzmod DESCRIPTION_FILE [DESCRIPTION_FILE] ...
#  DESCRIPTION
#  Installs the given GGZ ModuleInfo description file(s) into GGZ_MODULES_DIR.
#  As such files are often generically named (e.g. "module.dsc"), files are
#  automatically renamed to reflect the name of the program specified in their
#  CommandLine attribute.
#****
doggzmod() {
	local cl
	local m

	for m in ${@}
	do
		if [ ! -e ${m} ]
		then
			error "doggzmod: ${m}: file not found"
		fi

		cl=$(sed -n -e 's|^CommandLine *= *\([^ ]*\).*|\1|gp' ${m})

		insinto ${GGZ_MODULES_DIR}
		newins ${m} ${cl##*/}.dsc
	done
}

#****o* ggz.cygclass/src_install (ggz)
#  DEFINITION
src_install() {
	cd ${B}
	cyginstall
	ggz_postinst
}
#****

readonly -f ggz_postinst doggzmod
