# This file is part of the FreeWRT project. FreeWRT is copyrighted
# material, please see the LICENCE file in the top-level directory

include $(TOPDIR)/rules.mk

PKG_NAME:=		libnl
PKG_VERSION:=		3.11.0
PKG_RELEASE:=		1
PKG_MD5SUM:=		ec7da5ee1d399d841d7c0964575b1a66

PKG_SOURCE:=		$(PKG_NAME)3_11_0.tar.gz
PKG_SOURCE_URL:=	https://github.com/thom311/libnl/archive

WRKSRC=			$(WRKDIR)/$(PKG_NAME)-$(PKG_NAME)3_11_0

include $(TOPDIR)/mk/package.mk

$(eval $(call PKG_template,LIBNL,$(PKG_NAME),$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))

$(WRKBUILD)/.configured:
	(cd $(WRKBUILD); ./autogen.sh)
	(PATH="$(PATH):$(TARGET_PATH)"; cd $(WRKBUILD); ./configure \
		  --target=$(GNU_TARGET_NAME) \
		  --host=$(GNU_TARGET_NAME) \
		  --build=$(GNU_HOST_NAME) \
		  --program-prefix="" \
		  --program-suffix="" \
		  --prefix=/usr \
		  --exec-prefix=/usr \
		  --bindir=/usr/bin \
		  --datadir=/usr/share \
		  --includedir=/usr/include \
		  --infodir=/usr/share/info \
		  --libdir=/usr/lib \
		  --libexecdir=/usr/lib \
		  --localstatedir=/var \
		  --mandir=/usr/share/man \
		  --sbindir=/usr/sbin \
		  --sysconfdir=/etc \
		  --disable-nls \
		  --disable-static \
		  --disable-cli \
	);
	touch $@

$(WRKBUILD)/.built:
	rm -rf $(WRKINST)
	mkdir -p $(WRKINST)
	PATH="$(PATH):$(TARGET_PATH)" $(MAKE) CC=$(TARGET_CC) LD=$(TARGET_CC) \
		DESTDIR=$(WRKINST) \
		-C $(WRKBUILD) install
	touch $@

$(IPKG_LIBNL):
	install -d -m0755 $(IDIR_LIBNL)/etc/libnl
	$(CP) $(WRKINST)/etc/libnl/* $(IDIR_LIBNL)/etc/libnl
	install -d -m0755 $(IDIR_LIBNL)/usr/lib
	$(CP) $(WRKINST)/usr/lib/libnl* $(IDIR_LIBNL)/usr/lib
	$(RSTRIP) $(IDIR_LIBNL)
	$(IPKG_BUILD) $(IDIR_LIBNL) $(PACKAGE_DIR)

$(STAGING_DIR)/usr/lib/libnl-3.so: $(WRKBUILD)/.built
	mkdir -p $(STAGING_DIR)/usr/include
	$(CP) $(WRKINST)/usr/include/libnl3 $(STAGING_DIR)/usr/include/
	mkdir -p $(STAGING_DIR)/usr/lib
	$(CP) $(WRKINST)/usr/lib/libnl-*so* $(STAGING_DIR)/usr/lib/
	mkdir -p $(STAGING_DIR)/usr/lib/pkgconfig
	$(CP) $(WRKINST)/usr/lib/pkgconfig/libnl*.pc $(STAGING_DIR)/usr/lib/pkgconfig/

install-dev: $(STAGING_DIR)/usr/lib/libnl-3.so

uninstall-dev:
	rm -rf \
	  $(STAGING_DIR)/usr/include/libnl3 \
	  $(STAGING_DIR)/usr/lib/libnl-*so* \
	  $(STAGING_DIR)/usr/lib/pkgconfig/libnl*.pc

compile-targets: install-dev
clean-targets: uninstall-dev
