-include ../arch.mk
-include ../../path.mk
-include ../../.config

APPLET		= smartmontools
SMARTMONTOOLS_PATH	= smartmontools-5.39.1
PREFIX		= /usr/sbin

all: smartmontools
smartmontools: 
	$(Q)if [ ! -f ./$(SMARTMONTOOLS_PATH)/Makefile ]; then \
		echo -e "\033[32msmartmontools hasn't be config before, configuring...\033[0m"; \
		cd ./$(SMARTMONTOOLS_PATH); \
		./configure --build=i386-linux --host=$(HOST_TYPE) CFLAGS="$(CFLAGS)"; \
	fi
	@echo -e "\033[32mCompiling smartmontools ...\033[0m"
	$(Q)make -C $(SMARTMONTOOLS_PATH) 

install:
	@echo -e "\033[32mInstalling smartmontools ...\033[0m"
	$(Q)$(STRIP) $(SMARTMONTOOLS_PATH)/smartctl
	$(Q)$(STRIP) $(SMARTMONTOOLS_PATH)/smartd
	$(Q)[ -d $(TARGET)$(PREFIX) ] || mkdir -p $(TARGET)$(PREFIX)
	$(Q)cp -f ./$(SMARTMONTOOLS_PATH)/smartctl ./$(SMARTMONTOOLS_PATH)/smartd $(TARGET)$(PREFIX)

ifeq ($(strip $(ELBOX_BSP_AR9344)), y)	
	$(Q)cp -af $(TPATH_UC)/usr/mips-linux-uclibc/lib/libstdc++.so.* $(TARGET)/lib/.
else
ifeq ($(strip $(ELBOX_BSP_UBICOM32_KERNEL_V2_6_36)), y)	
	$(Q)cp -af $(TPATH_UC)/ubicom32-linux-uclibc/lib/libstdc++.so.* $(TARGET)/lib/.
else
	$(Q)cp -af $(TPATH_UC)/lib/libstdc++.so.* $(TARGET)/lib/.
endif
endif	
	$(Q)chmod +x $(TARGET)$(PREFIX)/smartctl
	$(Q)chmod +x $(TARGET)$(PREFIX)/smartd

clean:
	@echo -e "\033[32mCleaning smartmontools ...\033[0m"
	$(Q) rm -f ./$(SMARTMONTOOLS_PATH)/*.o ./$(SMARTMONTOOLS_PATH)/smartctl ./$(SMARTMONTOOLS_PATH)/smartd ./$(SMARTMONTOOLS_PATH)/Makefile ./$(SMARTMONTOOLS_PATH)/config.h ./$(SMARTMONTOOLS_PATH)/config.log ./$(SMARTMONTOOLS_PATH)/config.status

.PHONY: all install clean

