#
# Copyright (c) 2022 Genexis B.V.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#   Erik Karlsson - initial implementation
#

include $(TOPDIR)/rules.mk

PKG_NAME:=mosquitto-auth-plugin
PKG_VERSION:=1.2.0

PKG_MAINTAINER:=Erik Karlsson <erik.karlsson@genexis.eu>
PKG_LICENSE:=EPL-2.0

PKG_BUILD_PARALLEL:=1
PKG_CONFIG_DEPENDS:=CONFIG_MOSQUITTO_AUTH_PAM_SUPPORT

include $(INCLUDE_DIR)/package.mk

define Package/mosquitto-auth-plugin
  SECTION:=net
  CATEGORY:=Network
  TITLE:=mosquitto - /etc/shadow authentication plugin
  DEPENDS:=+mosquitto-ssl +MOSQUITTO_AUTH_PAM_SUPPORT:libpam
  USERID:=mosquitto=200:mosquitto=200 mosquitto=200:shadow=11
endef

define Package/mosquitto-auth-plugin/description
  Plugin for the mosquitto MQTT message broker that authenticates
  users using /etc/shadow
endef

define Package/mosquitto-auth-plugin/config
	source "$(SOURCE)/Config.in"
endef

ifeq ($(CONFIG_MOSQUITTO_AUTH_PAM_SUPPORT),y)
TARGET_CFLAGS+=-DENABLE_PAM_SUPPORT
endif

define Package/mosquitto-auth-plugin/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/mosquitto_auth_plugin.so $(1)/usr/lib/
	$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,mosquitto-auth-plugin))
