# Makefile for mod_reqin_log # Apache HTTPD module for logging HTTP requests as JSON to Unix socket # APXS tool path (can be overridden) APXS ?= apxs # Compiler settings CC ?= gcc CFLAGS ?= -Wall -Wextra -O2 # Directories SRC_DIR = src BUILD_DIR = build INSTALL_DIR = modules DIST_DIR = dist # Source files SRCS = $(SRC_DIR)/mod_reqin_log.c # Module name MODULE_NAME = mod_reqin_log # Package version VERSION ?= 1.0.0 .PHONY: all clean install uninstall test package package-deb package-rpm all: $(MODULE_NAME).so # Build the module using apxs # Note: Use -Wc to pass flags to the C compiler through apxs $(MODULE_NAME).so: $(SRCS) @mkdir -p $(BUILD_DIR) $(APXS) -c -Wc,"$(CFLAGS)" -o $(BUILD_DIR)/$(MODULE_NAME).so $(SRCS) @mkdir -p $(INSTALL_DIR) @if [ -f $(BUILD_DIR)/.libs/$(MODULE_NAME).so ]; then \ cp $(BUILD_DIR)/.libs/$(MODULE_NAME).so $(INSTALL_DIR)/; \ elif [ -f $(BUILD_DIR)/$(MODULE_NAME).so ]; then \ cp $(BUILD_DIR)/$(MODULE_NAME).so $(INSTALL_DIR)/; \ fi # Install the module install: $(MODULE_NAME).so @echo "Installing $(MODULE_NAME).so..." @mkdir -p $(DESTDIR)/usr/lib/apache2/modules cp $(BUILD_DIR)/$(MODULE_NAME).so $(DESTDIR)/usr/lib/apache2/modules/ @echo "Installation complete." @echo "Enable the module by adding to your httpd.conf:" @echo " LoadModule reqin_log_module modules/mod_reqin_log.so" # Uninstall the module uninstall: rm -f $(DESTDIR)/usr/lib/apache2/modules/$(MODULE_NAME).so @echo "Uninstallation complete." # Clean build artifacts clean: rm -rf $(BUILD_DIR) $(INSTALL_DIR) rm -f .libs/*.o .libs/*.la .libs/*.so rm -f *.o *.la *.lo rm -rf .libs # Run unit tests (requires cmocka) test: @mkdir -p build/tests cd build/tests && cmake ../../ -DCMAKE_BUILD_TYPE=Debug $(MAKE) -C build/tests run_tests # Build with debug symbols debug: CFLAGS += -g -DDEBUG debug: clean all # ============================================================================= # Packaging (DEB + RPM with Docker + fpm) # ============================================================================= ## package: Build all packages (deb + rpm) package: package-deb package-rpm ## package-deb: Build DEB package (requires Docker) package-deb: mkdir -p $(DIST_DIR)/deb $(DIST_DIR)/rpm docker build --target output -t mod_reqin_log-packager:latest \ --build-arg VERSION=$(VERSION) \ -f Dockerfile.package . @echo "Extracting packages from Docker image..." docker run --rm -v $(PWD)/$(DIST_DIR):/output mod_reqin_log-packager:latest \ sh -c 'cp -r /packages/deb /output/deb/ && cp -r /packages/rpm /output/rpm/' @echo "DEB packages created:" ls -la $(DIST_DIR)/deb/ @echo "RPM packages created:" ls -la $(DIST_DIR)/rpm/ ## package-rpm: Build RPM package (requires Docker) package-rpm: package-deb @echo "RPM built together with DEB in Dockerfile.package" ## test-package-deb: Test DEB package installation in Docker test-package-deb: package-deb docker run --rm -v $(PWD)/$(DIST_DIR)/deb:/packages:ro debian:latest \ sh -c "apt-get update && apt-get install -y /packages/*.deb && echo 'DEB install OK'" ## test-package-rpm: Test RPM package installation in Docker test-package-rpm: package-deb docker run --rm -v $(PWD)/$(DIST_DIR)/rpm:/packages:ro rockylinux:8 \ sh -c "dnf install -y /packages/*.rpm && echo 'RPM install OK'" ## test-package: Test all packages installation test-package: test-package-deb test-package-rpm # Help target help: @echo "mod_reqin_log Makefile" @echo "" @echo "Targets:" @echo " all - Build the module (default)" @echo " install - Install the module to DESTDIR" @echo " uninstall - Remove the module from DESTDIR" @echo " clean - Remove build artifacts" @echo " test - Run unit tests" @echo " debug - Build with debug symbols" @echo " package - Build all packages (deb + rpm)" @echo " package-deb - Build DEB package" @echo " package-rpm - Build RPM package" @echo " test-package - Test package installation" @echo "" @echo "Variables:" @echo " APXS - Path to apxs tool (default: apxs)" @echo " CC - C compiler (default: gcc)" @echo " CFLAGS - Compiler flags (default: -Wall -Wextra -O2)" @echo " DESTDIR - Installation destination (default: /)" @echo " VERSION - Package version (default: 1.0.0)"