# vim:noexpandtab:sw=2 ts=2

.PHONY: all build install clean

PWD := $(abspath $(shell pwd))
UP := $(dir $(PWD))

NGINX_VERSION ?= 1.12.0
NGINX := nginx-$(NGINX_VERSION)
NGINXDIR := $(UP)$(NGINX)
NGINXTAR := $(UP)$(NGINX).tar.gz

all: build

# debug:
# -g -O0 ./configure
# --with-debug

$(NGINXDIR): $(NGINXTAR)
	cd $(UP) && tar zmxf $(NGINXTAR)
	cd $(NGINXDIR) &&  ./configure \
    --sbin-path=/usr/local/sbin \
    --add-dynamic-module=$(PWD) 

build: $(NGINXDIR)
	$(MAKE) --directory=$(NGINXDIR)

install:
	-sudo service nginx stop
	sudo $(MAKE) --directory=$(NGINXDIR) install
	sudo ldconfig
	sudo service nginx start

clean:
	-rm -rf $(NGINXDIR)

distclean:
	-rm -rf $(NGINXDIR)
