# Dropbear
DROPBEAR_VERSION ?= 2012.55
DROPBEAR_NAME    := dropbear-$(DROPBEAR_VERSION)
DROPBEAR_PATH    := $(SRC_PATH)/$(DROPBEAR_NAME)
DROPBEAR_AR      := tar.gz
DROPBEAR_URL     := https://matt.ucc.asn.au/dropbear/releases/$(DROPBEAR_NAME).$(DROPBEAR_AR)
DROPBEAR_ORIG    := $(DROPBEAR_NAME)
DROPBEAR_BUILD_OPTS ?= CC=$(TOOLCHAIN_CC) AR=$(TOOLCHAIN_CROSS)ar PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" STATIC=0 MULTI=1
DROPBEAR_CFLAGS = " -O3  -W -Wall -mlittle-endian -mxl-barrel-shift -mxl-pattern-compare -mno-xl-soft-div -mcpu=v8.20.b -mno-xl-soft-mul -mxl-multiply-high"
#LDFLAGS=-static

download-dropbear: $(call download-path,DROPBEAR)
$(call download-path,DROPBEAR):
	$(Q) $(call download,DROPBEAR)
unpack-dropbear: download-dropbear $(DROPBEAR_PATH)
$(DROPBEAR_PATH):
	$(Q) $(call unpack,DROPBEAR)

configure-dropbear:
	$(Q) $(TOOLCHAIN_ENV) cd $(DROPBEAR_PATH); $(TOOLCHAIN_ENV) ./configure --disable-zlib; cd ../..
	sed -i s/"-Os -W -Wall"/$(DROPBEAR_CFLAGS)/ $(DROPBEAR_PATH)/Makefile

build-dropbear:
	$(Q) $(call common-build,DROPBEAR) 
	$(Q) $(TOOLCHAIN_ENV) $(TOOLCHAIN_CROSS)strip $(DROPBEAR_PATH)/dropbearmulti

install-dropbear:
	$(Q) cp -v $(DROPBEAR_PATH)/dropbearmulti $(GENRAMFS_PATH)/usr/bin
	$(Q) cp -v $(DROPBEAR_PATH)/dropbear $(GENRAMFS_PATH)/usr/bin
	$(Q) cp -v $(DROPBEAR_PATH)/dbclient $(GENRAMFS_PATH)/usr/bin
	$(Q) cp -v $(DROPBEAR_PATH)/scp $(GENRAMFS_PATH)/usr/bin
	$(Q) cp -v $(DROPBEAR_PATH)/dropbearkey $(GENRAMFS_PATH)/usr/bin
	$(Q) cp -v $(DROPBEAR_PATH)/dropbearconvert $(GENRAMFS_PATH)/usr/bin

clean-dropbear:
	$(Q) $(call common-clean,DROPBEAR)

distclean-dropbear: clean-dropbear

download-body: download-dropbear
download-fini: unpack-dropbear
configure-body: configure-dropbear
build-body: build-dropbear
install-body: install-dropbear
clean-body: clean-dropbear
distclean-body: distclean-dropbear
