#!/usr/bin/make -f

# Vendored nginx headers location
VENDOR_DIR = vendor/nginx-1.26.3
BUILDDIR = build
SRC_DIR = src

%:
	dh $@

override_dh_auto_build:
	mkdir -p $(BUILDDIR)
	
	echo "Building nginx-torblocker module with vendored headers..."
	echo "Vendor directory: $(VENDOR_DIR)"
	
	# Compile using vendored nginx headers
	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 \
		-I$(SRC_DIR) \
		-DNGX_COMPAT \
		-o $(BUILDDIR)/ngx_http_torblocker_module.so \
		src/ngx_http_torblocker_module.c
	
	echo "Build completed successfully."
	ls -l $(BUILDDIR)/ngx_http_torblocker_module.so

override_dh_auto_clean:
	rm -rf $(BUILDDIR)

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

override_dh_auto_test:
	# Skip tests
