# vim: ft=make ts=4 sw=4 noet
.DEFAULT_GOAL := all
NAME    = openssh
VERSION = 10.3p1
GARTYPE = v2

MASTER_SITES =
DYNURLS = https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/$(DISTNAME).tar.gz
DISTFILES += $(DISTNAME).tar.gz

LICENSE = LICENCE

BUILD_DEP_PKGS              += OZSWopenssl OZSWzlib
RUNTIME_DEP_PKGS_OZSWopenssh += OZSWopenssl OZSWzlib

PACKAGES                   += OZSWopenssh
SPKG_DESC_OZSWopenssh       = OpenSSH remote login client and server
CATALOGNAME_OZSWopenssh     = openssh

# Exclude system-owned directories that already exist on the target system
EXTRA_PKGFILES_EXCLUDED += /var/empty
EXTRA_PKGFILES_EXCLUDED += /var/svc
EXTRA_PKGFILES_EXCLUDED += /var/svc/manifest

EXTRA_CONFIGURE_ARGS += --with-ssl-dir=$(prefix)
EXTRA_CONFIGURE_ARGS += --with-zlib=$(prefix)
EXTRA_CONFIGURE_ARGS += --sysconfdir=$(sysconfdir)/openssh
EXTRA_CONFIGURE_ARGS += --with-privsep-user=sshd
EXTRA_CONFIGURE_ARGS += --with-pid-dir=/var/run

post-configure:
	@find $(WORKSRC) -name "libtool" -type f -exec \
	    gsed -i 's/ECHO="print -r --"/ECHO="printf %s\\n"/g' {} \;
	@$(MAKECOOKIE)

# Install SMF method script and manifest into staging tree
post-install:
	ginstall -d $(DESTDIR)/lib/svc/method
	ginstall -m 755 $(FILEDIR)/ozone-sshd $(DESTDIR)/lib/svc/method/ozone-sshd
	ginstall -d $(DESTDIR)/opt/ozsw/share/smf
	ginstall -m 644 $(FILEDIR)/ozone-sshd.xml $(DESTDIR)/opt/ozsw/share/smf/ozone-sshd.xml
	@$(MAKECOOKIE)

# Copy our hand-written gspec into WORKDIR and add the computed pkgfile var.
# Without pkgfile, mkpackage produces a file named just '.gz'.
pre-package:
	cp $(FILEDIR)/OZSWopenssh.gspec $(WORKDIR)/OZSWopenssh.gspec
	echo "%var pkgfile $(call _pkgfile,OZSWopenssh)" >> $(WORKDIR)/OZSWopenssh.gspec
	@$(MAKECOOKIE)

include gar/category.mk
