default: conditional_build 


CURR_DIR := $(shell pwd)
BUILD_DIR:=$(subst /userspace, /userspace,$(CURR_DIR))
BUILD_DIR:=$(word 1, $(BUILD_DIR))
include $(BUILD_DIR)/make.common


ifneq ($(strip $(CONFIG_PACKAGE_dnidnsmasq)),)
conditional_build: all
else
conditional_build:
	@echo "skipping $(CURR_DIR)"
endif


PKG_NAME:=dnidnsmasq
PKG_VERSION:=2.78
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(CURR_DIR)/$(PKG_NAME)

include $(BUILD_DIR)/dni/make.dni
LDFLAGS += $(FPIE)
CFLAGS += $(FPIE)

config-$(CONFIG_DNSMASQ_SUP_PARENTAL_CTL)		+= --enable-parental_ctl_support
config-$(CONFIG_DNSMASQ_SUP_STATIC_PPTP)		+= --enable-static_pptp_support
config-$(CONFIG_DNSMASQ_SUP_USBSHARE_DOMAIN)		+= --enable-usbshare_domain_support
config-$(CONFIG_DNSMASQ_SUP_IPV6_FEATURE)		+= --enable-dni_ipv6_feature
config-$(CONFIG_DNSMASQ_BIND_SRVSOCK_TO_WAN)		+= --enable-bind_srvsock_to_wan
config-$(CONFIG_DNSMASQ_START_WHEN_BOOT_UP)		+= --enable-start_dnsmasq_when_boot_up
config-$(CONFIG_DNSMASQ_MUL_PPPOE_SUPPORT)              += --enable-mul_pppoe_support

config-y += --enable-doh_unhijack_support
config-y += --enable-xunyou_support
config-y += --enable-sso_support

define Package/dnidnsmasq
  SECTION:=net
  CATEGORY:=DNI Packages
  DEPENDS:=datalib
  TITLE:=A lightweight DNS and DHCP server
  URL:=http://www.thekelleys.org.uk/dnsmasq/
endef

define Package/dnidnsmasq/conffiles
/etc/dnsmasq.conf
endef

define Package/dnidnsmasq/description
 It is intended to provide coupled DNS and DHCP service to a LAN.
endef

define Build/Prepare
endef

define Build/Configure
	(cd $(PKG_BUILD_DIR); \
		./configure \
			$(config-y) \
	);
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS) -DNO_INOTIFY" \
		LDFLAGS="-L$(BCM_FSBUILD_DIR)/private/lib -L$(BCM_FSBUILD_DIR)/lib -lconfig" \
		BINDIR="/usr/sbin" MANDIR="/usr/man" \
		all
endef

define Package/install
	$(INSTALL_BDIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/dns-hijack $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/dnsmasq $(1)/usr/sbin/
	$(INSTALL_BDIR) $(1)/etc/init.d
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/dnsmasq.conf $(1)/etc/dnsmasq.conf
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/dnsmasq.init $(1)/etc/init.d/dnsmasq
	$(INSTALL_BDIR) $(1)/sbin
	$(INSTALL_BIN) ./files/mul_pppoe_dns $(1)/sbin/
endef

prepare:
	$(call Build/Prepare)

compile:
	$(call Build/Configure)
	$(call Build/Compile)
	$(call Build/InstallDev,$(BCM_FSBUILD_DIR))
	$(call Package/install,$(INSTALL_DIR))

all:
ifneq ($(HAVEBUILT),built)
	$(call Build/Prepare)
	$(call Build/Configure)
	$(call Build/Compile)
	$(call Build/InstallDev,$(BCM_FSBUILD_DIR))
	$(call Package/install,$(INSTALL_DIR))
	@touch $(STAMP_BUILT)
endif


clean:
	rm -rf $(PKG_BUILD_DIR)


shell:
	bash -i

