#!/usr/bin/make -f

# Copyright (c) 2015, 2022, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program 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, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

%:
	dh $@

export DH_VERBOSE=1
export CFLAGS=
export CXXFLAGS=

override_dh_auto_configure:
	@echo "RULES.$@"

	
	mkdir debug && cd debug && \
	cmake .. \
    -DWITH_BOOST=/usr/global/share -DWITH_UNIT_TESTS=false \
		-DBUILD_CONFIG=mysql_release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Debug \
		-DMYSQL_MAINTAINER_MODE=0 \
		-DINSTALL_DOCDIR=share/mysql/docs \
		-DINSTALL_DOCREADMEDIR=share/mysql \
		-DINSTALL_INCLUDEDIR=include/mysql \
		-DINSTALL_INFODIR=share/mysql/docs \
		-DINSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		-DINSTALL_MANDIR=share/man \
		-DINSTALL_MYSQLSHAREDIR=share/mysql \
		-DINSTALL_MYSQLTESTDIR=lib/mysql-test \
		-DINSTALL_PLUGINDIR=lib/mysql/plugin \
		-DINSTALL_SBINDIR=sbin \
		-DINSTALL_SUPPORTFILESDIR=share/mysql \
		-DSYSCONFDIR=/etc/mysql \
		-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DWITH_SSL=/var/lib/pb2/sb_1-8318433-1662380579.07/dep2 \
		-DWITH_INNODB_MEMCACHED=1 \
		-DWITH_MECAB=system \
		-DWITH_NUMA=ON \
		-DCOMPILATION_COMMENT="MySQL Cluster Community Server (GPL)" \
		-DINSTALL_LAYOUT=DEB \
-DNDB_NODEJS_EXTRAS_PATH=/var/lib/pb2/sb_1-8318433-1662380579.07/master-export-1921728 \
		-DDEB_PRODUCT=cluster-community \
		


	mkdir release && cd release && \
	cmake .. \
    -DWITH_BOOST=/usr/global/share -DWITH_UNIT_TESTS=false \
		-DBUILD_CONFIG=mysql_release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINSTALL_DOCDIR=share/mysql/docs \
		-DINSTALL_DOCREADMEDIR=share/mysql \
		-DINSTALL_INCLUDEDIR=include/mysql \
		-DINSTALL_INFODIR=share/mysql/docs \
		-DINSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		-DINSTALL_MANDIR=share/man \
		-DINSTALL_MYSQLSHAREDIR=share/mysql \
		-DINSTALL_MYSQLTESTDIR=lib/mysql-test \
		-DINSTALL_PLUGINDIR=lib/mysql/plugin \
		-DINSTALL_SBINDIR=sbin \
		-DINSTALL_SUPPORTFILESDIR=share/mysql \
		-DSYSCONFDIR=/etc/mysql \
		-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DWITH_SSL=/var/lib/pb2/sb_1-8318433-1662380579.07/dep2 \
		-DWITH_INNODB_MEMCACHED=1 \
		-DWITH_MECAB=system \
		-DWITH_NUMA=ON \
		-DCOMPILATION_COMMENT="MySQL Cluster Community Server (GPL)" \
		-DINSTALL_LAYOUT=DEB \
-DNDB_NODEJS_EXTRAS_PATH=/var/lib/pb2/sb_1-8318433-1662380579.07/master-export-1921728 \
		-DDEB_PRODUCT=cluster-community \
		

	touch $@

override_dh_auto_build:
	@echo "RULES.$@"
	
	cd debug && \
	$(MAKE) -j8 VERBOSE=1

	cd release && \
	$(MAKE) -j8 VERBOSE=1
	touch $@

override_dh_auto_test:
	@echo "RULES.$@"
	export CTEST_OUTPUT_ON_FAILURE=1
	cd release && \
	make test || true
	touch $@



override_dh_auto_install:

	@echo "RULES.$@"
	# complete install first
	cd release && \
	$(MAKE) install DESTDIR=../debian/tmp
	
	# The ini file isn't built for debug, so copy over from the standard build
	install -g root -o root -m 0755 debian/tmp/usr/lib/mysql/plugin/daemon_example.ini debian/tmp/usr/lib/mysql/plugin/debug

	# add missing man pages
	install -g root -o root -m 0644 debian/extra/mysql_embedded.1 debian/tmp/usr/share/man/man1
	# Add helper functions for maintainer scripts
	install -m 0644 debian/extra/mysql-helpers debian/tmp/usr/share/mysql/
	# add apparmor profile
	
	# add systemd script
	install -m 0755 debian/extra/mysql-systemd-start debian/tmp/usr/share/mysql/

	touch $@

override_dh_installinit:
	@echo "RULES.$@"
	
	dh_systemd_enable --name=mysql
	dh_installinit --name=mysql -- defaults 19 21
	dh_installinit --name=mysql@ -- disable
	dh_systemd_start --restart-after-upgrade
	touch $@

override_dh_install:
	dh_install --fail-missing \
		-Xusr/bin/i_mysql_client_test \
		-Xusr/share/mysql/mysql.server \
		-Xusr/share/man/man1/mysql.server.1 \
		-Xusr/share/mysql/binary-configure \
		-Xusr/share/mysql/LICENSE-test \
		-Xusr/share/mysql/README-test \
		-Xusr/share/mysql/docs/mysql.info \
		-Xusr/share/man/man1/mysqlman.1 \
		-Xusr/share/man/man1/ndb_setup.py.1 \
		-X.h.pp
