+define PKG_build
+
+ifneq ($(BR2_PACKAGE_$(1)),)
+BUILD_TARGETS += $(PKG_INSTALL_DIR)/$(2)/hostapd
+endif
+
+$(PKG_INSTALL_DIR)/$(2)/hostapd: $(PKG_BUILD_DIR)/.prepared
+ -$(MAKE) -C $(PKG_BUILD_DIR) clean
+ $(CP) ./files/$(2).config $(PKG_BUILD_DIR)/.config
+ $(MAKE) -C $(PKG_BUILD_DIR) \
+ $(TARGET_CONFIGURE_OPTS) \
+ OPTFLAGS="$(TARGET_CFLAGS)" \
+ CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include/madwifi" \
+ LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
+ hostapd
+ mkdir -p $(PKG_INSTALL_DIR)/$(2)
+ $(CP) $(PKG_BUILD_DIR)/hostapd $(PKG_INSTALL_DIR)/$(2)/
+ touch $$@
+
+$$(IPKG_$(1)): $(PKG_INSTALL_DIR)/$(2)/hostapd
+ install -m0755 -d $$(IDIR_$(1))/etc
+ install -m0600 $(PKG_BUILD_DIR)/madwifi.conf $$(IDIR_$(1))/etc/hostapd.conf
+ install -m0755 -d $$(IDIR_$(1))/usr/sbin
+ install -m0755 $(PKG_INSTALL_DIR)/$(2)/hostapd $$(IDIR_$(1))/usr/sbin/
+ $(RSTRIP) $$(IDIR_$(1))
+ $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
+
+endef
+