# vim:noexpandtab:sw=2 ts=2

.PHONY: all build install clean

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

ifndef NGINX_VERSION
NGINX_VERSION ?= 1.16.0
$(warning NGINX_VERSION was not defined; set to $(NGINX_VERSION))
endif

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) && CFLAGS="$(CFLAGS) -D_LARGEFILE_SOURCE -DBUILDING_NGINX" ./configure \
    --sbin-path=/usr/local/sbin \
    --add-dynamic-module=$(PWD) \
    $(EXTRA_CONFIG)

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

install:
	sudo $(MAKE) --directory=$(NGINXDIR) install
	sudo ldconfig

clean:
	-rm -rf $(NGINXDIR)

distclean:
	-rm -rf $(NGINXDIR)
