#!/usr/bin/make -f

# Vendored nginx headers location
VENDOR_DIR = vendor/nginx-1.27.0
BUILDDIR = build

%:
	dh $@

override_dh_auto_build:
	mkdir -p $(BUILDDIR)

	echo "Building nginx-gone module with vendored headers..."
	echo "Vendor directory: $(VENDOR_DIR)"

	# Compile using vendored nginx headers (no external library dependencies)
	gcc -shared -fPIC \
		-I$(VENDOR_DIR)/src/core \
		-I$(VENDOR_DIR)/src/event \
		-I$(VENDOR_DIR)/src/event/modules \
		-I$(VENDOR_DIR)/src/http \
		-I$(VENDOR_DIR)/src/http/modules \
		-I$(VENDOR_DIR)/src/os/unix \
		-I$(VENDOR_DIR)/objs \
		-DNGX_COMPAT \
		-o $(BUILDDIR)/ngx_http_gone_module.so \
		src/ngx_http_gone_module.c

	echo "Build completed successfully."
	ls -l $(BUILDDIR)/ngx_http_gone_module.so

override_dh_auto_clean:
	rm -rf $(BUILDDIR)

override_dh_auto_install:
	echo "Installing nginx module..."
	install -D -m 644 $(BUILDDIR)/ngx_http_gone_module.so \
		debian/nginx-gone/usr/lib/nginx/modules/ngx_http_gone_module.so

override_dh_auto_test:
	# Skip tests
