SRC=samba-3.0.25c/source
TARGETS = $(SRC)/bin/smbmount $(SRC)/bin/smbmnt

STRCFLAGS = -Os -I$(TOP)/opensources/samba/

export LD_LIBRARY_PATH

.PHONY: all clean distclean $(TARGETS) install dist_install
all: $(TARGETS)
clean:
	make -C $(SRC) clean
	rm -f $(SRC)/.configured

distclean:
	-make -C $(SRC) distclean
	rm -f $(SRC)/.configured

$(SRC)/.configured:
	cd $(SRC) \
		&& LDFLAGS="-s -L$(PREFIX)/lib -lpcre" \
		   CFLAGS="$(STRCFLAGS) -include $(TOP)/opensources/include/legacy.h" \
		   CPPFLAGS="-I$(PREFIX)/include" \
		   LIBS="-lresolv" \
		   ac_cv_func_bzero=yes	\
		   ./configure \
                        --prefix=$(PREFIX) \
                        --target=$(TARGET_TYPE) \
                        --host=$(HOST_TYPE) \
                        --build=$(BUILD_TYPE) \
			--disable-cups \
			--disable-iprint \
			--disable-pie \
			--disable-fam \
			--with-ads=no \
			--with-ldap=no \
			--with-cifsmount=no \
			--with-logfilebase=/var/log \
			--with-libdir=/usr/lib  \
			--with-swatdir=/usr/local/swat \
			--with-rootsbindir=/sbin \
			--with-lockdir=/var/lock \
			--with-piddir=/var/lock \
			--with-privatedir=/etc/samba \
			--with-configdir=/etc/samba \
			--enable-static=yes \
			--enable-shared=no \
			--with-smbmount \
			--bindir=/bin \
			--sbindir=/sbin
	echo "#define HAVE_IFACE_IFCONF 1" >> $(SRC)/include/config.h
	touch $(SRC)/.configured

$(SRC)/include/proto.h : $(SRC)/.configured
	$(MAKE) -C $(SRC)/ proto

$(TARGETS): $(SRC)/include/proto.h 
	$(MAKE) -C $(SRC)

BIN_DIR := $(SHADOW-DIR)/bin
CONF_DIR := $(INITRD-DIR)/etc/samba
install: $(TARGETS)
	$(INSTALL) -d $(BIN_DIR)
	$(INSTALL) -m 0755 $(SRC)/bin/smbmount $(SRC)/bin/smbmnt $(BIN_DIR)

	$(INSTALL) -d $(CONF_DIR)	
	$(INSTALL) -m 0644 $(SRC)/smb.conf $(CONF_DIR)/

dist_install: $(TARGETS)
	$(INSTALL) -d $(PREFIX)/bin
	$(INSTALL) -m 0755 $(SRC)/bin/smbmount $(SRC)/bin/smbmnt $(PREFIX)/bin
