SOURCE=lighttpd-1.4.19

.PHONY: all clean distclean openSource install
all: openSource
clean:
	make -C $(SOURCE) clean

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

openSource: $(SOURCE)/.configured
	make -C $(SOURCE)

$(SOURCE)/.configured:
	[ "$$PJ_PREFIX" != "" ]
	[ "$$PJ_TARGET" != "" ]
	[ "$$PJ_HOST" != "" ]
	cd $(SOURCE) \
		&& LDFLAGS="-s -L$(PJ_PREFIX)/lib -lpcre" \
		   CFLAGS="-Os" \
		   CPPFLAGS="-I$(PJ_PREFIX)/include" \
		   ./configure \
			--prefix=$$PJ_PREFIX \
			--target=$$PJ_TARGET \
			--host=$$PJ_TARGET \
			--build=$$PJ_HOST \
			--program-prefix="" \
			--disable-lfs \
			--disable-ipv6 \
			--without-mysql \
			--without-ldap \
			--without-attr \
			--without-valgrind \
			--without-openssl \
			--without-kerberos5 \
			--with-pcre \
			--without-bzip2 \
			--without-zlib \
			--without-webdav-props \
			--without-webdav-locks \
			--without-gdbm \
			--without-memcache \
			--without-lua \
		&& echo "#define HAVE_LIBPCRE" >> config.h \
		&& echo "#define HAVE_PCRE_H" >> config.h
	touch $(SOURCE)/.configured

ETC_DIR := $(PJ_PREFIX)/etc/lighttpd
INIT_DIR := $(PJ_PREFIX)/etc/rc.d/init.d
install: $(SOURCE)/.configured
	make -C $(SOURCE) install-strip
	install -d -m 0755 $(ETC_DIR)/
	cp conf.d/lighttpd.conf $(ETC_DIR)/
	ln -sf /tmp/lighttpd-inc.conf $(ETC_DIR)/lighttpd-inc.conf
	install -d -m 0755 $(INIT_DIR)/
	cp conf.d/lighttpd.sh $(INIT_DIR)/
