#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@

override_dh_auto_configure:
	# Configure wssshd2 build
	cd ../wssshd2 && ./configure.sh

override_dh_auto_build:
	# Build wssshd2 C binary
	cd ../wssshd2 && make clean && make

override_dh_auto_install:
	# Create necessary directories
	mkdir -p debian/wsssh-server/usr/bin/
	mkdir -p debian/wsssh-server/etc/init.d/
	mkdir -p debian/wsssh-server/etc/default/
	mkdir -p debian/wsssh-server/usr/share/wsssh/
	mkdir -p debian/wsssh-server/usr/share/man/man1/
	mkdir -p debian/wsssh-server/usr/share/wsssh/logos
	mkdir -p debian/wsssh-server/var/lib/wssshd
	mkdir -p debian/wsssh-server/var/log/wssshd
	mkdir -p debian/wsssh-server/etc/wssshd
	mkdir -p debian/wsssh-server/usr/sbin
	mkdir -p debian/wsssh-server/etc/logrotate.d

	# Install C binary
	install -m 755 ../wssshd2/wssshd debian/wsssh-server/usr/bin/

	# Install init script
	install -m 755 ../wssshd.init debian/wsssh-server/etc/init.d/wssshd

	# Install watchdog script
	install -m 755 debian/wssshd-watchdog debian/wsssh-server/usr/sbin/wssshd-watchdog

	# Install configuration files
	install -m 644 debian/wssshd.default debian/wsssh-server/etc/default/wssshd
	install -m 644 ../wssshd.conf.example debian/wsssh-server/usr/share/wsssh/

	# Install man page
	install -m 644 debian/wssshd.1 debian/wsssh-server/usr/share/man/man1/

	# Install logrotate configuration
	install -m 644 debian/wssshd.logrotate debian/wsssh-server/etc/logrotate.d/wssshd

	# Install systemd service file
	mkdir -p debian/wsssh-server/lib/systemd/system
	install -m 644 debian/wssshd.service debian/wsssh-server/lib/systemd/system/

	# Install static files
	cp -r ../logos/* debian/wsssh-server/usr/share/wsssh/logos/

override_dh_auto_clean:
	rm -rf build *.spec dist
	dh_auto_clean