# Makefile for vshttpd
# $@ = target file
# $< = first dependency
# $^ = all dependencies

find_exe = $(abspath $(strip $(firstword $(foreach dir,$(strip $(subst :, ,${PATH})),$(wildcard $(dir)/$(1))))))
OSTYPE := $(shell uname)
ifeq ($(OSTYPE),SunOS)
	TAR := gtar
else
	TAR := tar
endif

ifeq ($(call find_exe,$(TAR)),)
	$(info ****************************************)
	$(info We need GNU tar for the dist target)
	$(info ****************************************)
endif
ifeq ($(call find_exe,$(CC)),)
	$(info ****************************************)
	$(info We need a C compiler)
	$(info ****************************************)
	$(error )
endif


ifeq ($(OSTYPE),SunOS)
	LIBS := -lsocket -lnsl
else
	LIBS :=
endif
# First rule is the one executed when no parameters are fed to the Makefile
.PHONY: all clean run dist
all: vshttpd

vshttpd: vshttpd.c
	$(CC) -DIPV6 $^ $(LIBS) -o $@
noipv6: vshttpd.c
	$(CC) $^ $(LIBS) -o vshttpd
dist: clean
ifeq ($(call find_exe,$(TAR)),)
	$(info ****************************************)
	$(info We need GNU tar for target dist)
	$(info ****************************************)
	$(error )
else
	(cd ..;${TAR} -cvjf vshttpd.tbz2 vshttpd/vshttpd.c vshttpd/Makefile vshttpd/LICENSE vshttpd/FAQ.txt)
endif
clean:
	rm -f vshttpd
