# generated by makefile_builder.pl using [arch path -t all msg -t install msg -t clean msg]

include ../../path.mk
include $(TOPDIR)/arch.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/.config

BUILD_DIR:=$(shell pwd)
PKG_NAME:=wireless-tools

ifeq ($(ELBOX_PROGS_GPL_WIRELESS_TOOLS_INTEL_29),y)
PKG_VERSION:=29
PKG_MINOR:=
PKG_RELEASE:=6
PKG_VENDOR:=intel
endif

PKG_SOURCE:=wireless_tools.$(PKG_VERSION)$(PKG_MINOR).tar.gz
PKG_SOURCE_URL:=https://hewlettpackard.github.io/wireless-tools
PKG_HASH:=6fb80935fe208538131ce2c4178221bab1078a1656306bce8909c19887e2e5a1
TAR_OPTIONS += || true

PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
PKG_LICENSE:=GPL-2.0

PKG_BUILD_DIR:=$(BUILD_DIR)/wireless_tools_$(PKG_VENDOR).$(PKG_VERSION)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/install_dir


TARGET_CFLAGS:=-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro

UTILS_LINUX_CONFIG_OPTS+=AR="mips-openwrt-linux-musl-gcc-ar" \
                         AS="mips-openwrt-linux-musl-gcc" \
                         LD="mips-openwrt-linux-musl-ld" \
                         NM="mips-openwrt-linux-musl-gcc-nm" \
                         CC="mips-openwrt-linux-musl-gcc" \
                         GCC="mips-openwrt-linux-musl-gcc" \
                         CXX="mips-openwrt-linux-musl-g++" \
                         RANLIB="mips-openwrt-linux-musl-gcc-ranlib" \
                         STRIP="mips-openwrt-linux-musl-strip" \
                         OBJCOPY="mips-openwrt-linux-musl-objcopy" \
                         OBJDUMP="mips-openwrt-linux-musl-objdump" \
                         SIZE="mips-openwrt-linux-musl-size" \
                         CROSS="mips-openwrt-linux-musl-" \
                         ARCH="mips"


current_dir := $(shell pwd)
targets :=
############################# section all #############################
targets += all
# file and directory selectors

all:
	$(call color_print,Compiling objects in $(current_dir) ...,green)
	rm -rf $(PKG_INSTALL_DIR)
	mkdir -p $(PKG_INSTALL_DIR)
	$(MAKE) -C $(PKG_BUILD_DIR) \
		$(strip $(UTILS_LINUX_CONFIG_OPTS)) \
		CFLAGS="$(TARGET_CFLAGS) -I." \
		BUILD_WE_ESSENTIAL=y \
		LIBS="-lm -Wl,--gc-sections" \
		libiw.so.$(PKG_VERSION) iwmulticall
	$(MAKE) -C $(PKG_BUILD_DIR) \
		PREFIX="$(PKG_INSTALL_DIR)" \
		INSTALL_DIR="$(PKG_INSTALL_DIR)/usr/sbin" \
		INSTALL_LIB="$(PKG_INSTALL_DIR)/usr/lib" \
		install-iwmulticall
	$(Q)[ -L $(PKG_BUILD_DIR)/libiw.so ] || ln -s libiw.so.29 $(PKG_BUILD_DIR)/libiw.so

############################# section clean #############################
targets += clean
# file and directory selectors

clean:
	$(call color_print,Cleaning objects in $(current_dir) ...,green)
	$(Q)$(MAKE) -C $(PKG_BUILD_DIR) clean
	rm -rf $(PKG_INSTALL_DIR)

############################# section install #############################
targets += install
# file and directory selectors


install:
	$(call color_print,Installing objects in $(current_dir) ...,green)
	$(Q)[ -d $(TARGET)/usr/sbin ] || mkdir -p $(TARGET)/usr/sbin
	$(Q)[ -d $(TARGET)/usr/lib ] || mkdir -p $(TARGET)/usr/lib
	$(Q)install $(PKG_BUILD_DIR)/libiw.so.*    $(TARGET)/usr/lib
	$(Q)$(STRIP) $(PKG_INSTALL_DIR)/usr/sbin/iwconfig
	$(Q)install $(PKG_INSTALL_DIR)/usr/sbin/*    $(TARGET)/usr/sbin
	$(Q)[ -L $(TARGET)/usr/lib/libiw.so ] || ln -s libiw.so.29 $(TARGET)/usr/lib/libiw.so










.PHONY: $(targets)
