#############################################################
#
# autofs
#
#############################################################
AUTOFS_VER:=4.1.4
AUTOFS_SOURCE:=autofs-$(AUTOFS_VER).tar.bz2
AUTOFS_SITE:=ftp://ftp.kernel.org/pub/linux/daemons/autofs/v4/
AUTOFS_CAT:=bzcat
AUTOFS_DIR:=$(BUILD_DIR)/autofs-$(AUTOFS_VER)
AUTOFS_BINARY:=automount

$(DL_DIR)/$(AUTOFS_SOURCE):
	 $(WGET) -P $(DL_DIR) $(AUTOFS_SITE)/$(AUTOFS_SOURCE)

autofs-source: $(DL_DIR)/$(AUTOFS_SOURCE)

$(AUTOFS_DIR)/.unpacked: $(DL_DIR)/$(AUTOFS_SOURCE)
	$(AUTOFS_CAT) $(DL_DIR)/$(AUTOFS_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	toolchain/patch-kernel.sh $(AUTOFS_DIR) local/autofs/ autofs-*.patch
	touch $(AUTOFS_DIR)/.unpacked

$(AUTOFS_DIR)/.configured: $(AUTOFS_DIR)/.unpacked
	(cd $(AUTOFS_DIR); rm -rf config.cache; \
		$(TARGET_CONFIGURE_OPTS) CC_FOR_BUILD=$(HOSTCC) \
		CFLAGS="$(TARGET_CFLAGS)" \
		LDFLAGS="-L$(STAGING_DIR)/lib" \
		STRIP=$(TARGET_CROSS)strip \
		./configure \
		--target=$(GNU_TARGET_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--build=$(GNU_HOST_NAME) \
		--prefix=/usr \
		--exec-prefix=/usr \
		--bindir=/usr/bin \
		--sbindir=/usr/sbin \
		--libexecdir=/usr/lib \
		--sysconfdir=/etc \
		--datadir=/usr/share \
		--localstatedir=/var \
		--mandir=/usr/man \
		--infodir=/usr/info \
	);
	touch  $(AUTOFS_DIR)/.configured

$(AUTOFS_DIR)/daemon/$(AUTOFS_BINARY): $(AUTOFS_DIR)/.configured
	$(MAKE) CC=$(TARGET_CC) CC_FOR_BUILD=$(HOSTCC) STRIP=$(TARGET_CROSS)strip -C $(AUTOFS_DIR)

$(TARGET_DIR)/usr/sbin/$(AUTOFS_BINARY): \
		$(AUTOFS_DIR)/daemon/$(AUTOFS_BINARY)
	$(MAKE) INSTALLROOT=$(TARGET_DIR) CC=$(TARGET_CC) -C $(AUTOFS_DIR) install
	rm -rf $(TARGET_DIR)/usr/man
	rm -f $(TARGET_DIR)/etc/init.d/autofs
	rm -f $(TARGET_DIR)/etc/auto.master
	cp -dfpr local/autofs/overlay/. $(TARGET_DIR)

autofs: uclibc $(TARGET_DIR)/usr/sbin/$(AUTOFS_BINARY)

autofs-clean:
	-make -C $(AUTOFS_DIR) clean

autofs-dirclean:
	rm -rf $(AUTOFS_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_AUTOFS)),y)
TARGETS+=autofs
endif

