#
# Makefile for lighttpd
#

LIGHTTPD_DIR = ${shell pwd}

SRC_DIR = lighttpd-1.4.19
INSTALL_DIR = preinstall

MAKETARGET = ${shell $(SRC_DIR)/config.sub $(CROSS)gnu}

PKG_CONFIG = true

CONF_OPT = --host=$(MAKETARGET) --prefix=/usr --libdir=/usr/lib/lighttpd --with-openssl --without-bzip2

all: build

$(SRC_DIR)/Makefile:
	touch ${SRC_DIR}/src/mod_auth.h
	if [ ! -e $(SRC_DIR)/Makefile ]; then \
		(cd $(SRC_DIR); \
		 ./configure $(CONF_OPT)); \
	fi

build: $(SRC_DIR)/Makefile
	make -C $(SRC_DIR)
	mkdir -p $(INSTALL_DIR)
	DESTDIR=${LIGHTTPD_DIR}/${INSTALL_DIR} make -C $(SRC_DIR) install

romfs: build
	@[ "$(ROOTDIR)" != "" ] || echo "ERROR!! Can't find ROOTDIR"; exit
	@[ "$(ROMFSDIR)" != "" ] || echo "ERROR!! Can't find ROMFSDIR"; exit
	@mkdir -p $(ROMFSDIR)
	@mkdir -p $(ROMFSDIR)/usr
	@mkdir -p $(ROMFSDIR)/usr/bin
	@mkdir -p $(ROMFSDIR)/usr/sbin
	@mkdir -p $(ROMFSDIR)/usr/lib
	@mkdir -p $(ROMFSDIR)/usr/lib/lighttpd

	$(ROMFSINST) /usr/sbin/lighttpd
	$(ROMFSINST) /usr/bin/spawn-fcgi

	cp -a $(INSTALL_DIR)/usr/bin/spawn-fcgi \
		$(ROMFSDIR)/usr/bin/
	cp -a $(INSTALL_DIR)/usr/sbin/lighttpd \
		$(ROMFSDIR)/usr/sbin/
	cp -a $(INSTALL_DIR)/usr/lib/lighttpd/*.so \
		$(ROMFSDIR)/usr/lib/lighttpd/

clean:
	make -C $(SRC_DIR) clean

distclean: clean
	make -C $(SRC_DIR) distclean
	rm -rf $(INSTALL_DIR)
