You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.6 KiB
138 lines
3.6 KiB
# Root Makefile for uTun - Out-of-tree build wrapper |
|
# This Makefile provides convenient targets for building in a separate directory |
|
# while keeping binaries in the project root. |
|
|
|
# Build directory |
|
BUILD_DIR = build |
|
|
|
# Detect source directory (where this Makefile is located) |
|
SRC_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) |
|
|
|
# Check if build directory is configured |
|
BUILD_CONFIGURED := $(shell test -f $(BUILD_DIR)/Makefile && echo yes || echo no) |
|
|
|
# Default target: build everything |
|
.PHONY: all |
|
all: |
|
ifeq ($(BUILD_CONFIGURED),yes) |
|
@$(MAKE) -C $(BUILD_DIR) all |
|
else |
|
@echo "Build directory not configured. Run 'make setup' first." |
|
@exit 1 |
|
endif |
|
|
|
# Setup target: create build directory and configure |
|
.PHONY: setup |
|
setup: |
|
@echo "Setting up build in $(BUILD_DIR)/..." |
|
@mkdir -p $(BUILD_DIR) |
|
@if test ! -f $(BUILD_DIR)/Makefile; then \ |
|
echo "Running configure..."; \ |
|
cd $(BUILD_DIR) && $(SRC_DIR)/configure; \ |
|
else \ |
|
echo "Build already configured."; \ |
|
fi |
|
@echo "Setup complete. Run 'make' to build." |
|
|
|
# Reconfigure target |
|
.PHONY: reconfigure |
|
reconfigure: |
|
@rm -rf $(BUILD_DIR) |
|
@$(MAKE) setup |
|
|
|
# Build just the main binary (skip tests) |
|
.PHONY: utun |
|
utun: |
|
ifeq ($(BUILD_CONFIGURED),yes) |
|
@$(MAKE) -C $(BUILD_DIR)/lib |
|
@$(MAKE) -C $(BUILD_DIR)/src |
|
@echo "utun binary built successfully." |
|
else |
|
@echo "Build directory not configured. Run 'make setup' first." |
|
@exit 1 |
|
endif |
|
|
|
# Run tests (make all builds everything including tests) |
|
.PHONY: check test |
|
check: all |
|
ifeq ($(BUILD_CONFIGURED),yes) |
|
@$(MAKE) -C $(BUILD_DIR) check |
|
else |
|
@echo "Build directory not configured. Run 'make setup' first." |
|
@exit 1 |
|
endif |
|
|
|
test: check |
|
|
|
# Clean build directory |
|
.PHONY: clean |
|
clean: |
|
ifeq ($(BUILD_CONFIGURED),yes) |
|
@$(MAKE) -C $(BUILD_DIR) clean |
|
else |
|
@echo "Build directory not configured." |
|
endif |
|
|
|
# Full clean - remove build directory and generated files |
|
.PHONY: distclean |
|
distclean: |
|
@rm -rf $(BUILD_DIR) |
|
@echo "Build directory removed." |
|
|
|
# Install from build directory |
|
.PHONY: install |
|
install: all |
|
@$(MAKE) -C $(BUILD_DIR) install |
|
|
|
# Debug build setup |
|
.PHONY: setup-debug |
|
setup-debug: |
|
@echo "Setting up debug build in $(BUILD_DIR)/..." |
|
@mkdir -p $(BUILD_DIR) |
|
cd $(BUILD_DIR) && $(SRC_DIR)/configure --enable-debug |
|
|
|
# Release build setup |
|
.PHONY: setup-release |
|
setup-release: |
|
@echo "Setting up release build in $(BUILD_DIR)/..." |
|
@mkdir -p $(BUILD_DIR) |
|
cd $(BUILD_DIR) && $(SRC_DIR)/configure --disable-debug |
|
|
|
# Print help |
|
.PHONY: help |
|
help: |
|
@echo "uTun Build System (Out-of-tree build)" |
|
@echo "======================================" |
|
@echo "" |
|
@echo "Setup targets:" |
|
@echo " setup - Configure the build directory" |
|
@echo " setup-debug - Configure for debug build" |
|
@echo " setup-release - Configure for release build" |
|
@echo " reconfigure - Clean and reconfigure build" |
|
@echo "" |
|
@echo "Build targets:" |
|
@echo " all - Build everything: lib, src, tests" |
|
@echo " utun - Build only main utun binary (faster)" |
|
@echo " check - Run all tests (builds if needed)" |
|
@echo " test - Alias for check" |
|
@echo " install - Install binaries" |
|
@echo "" |
|
@echo "Maintenance:" |
|
@echo " clean - Clean build artifacts" |
|
@echo " distclean - Remove build directory completely" |
|
@echo " help - Show this help" |
|
@echo "" |
|
@echo "Build directory: $(BUILD_DIR)/" |
|
@echo "Source directory: $(SRC_DIR)/" |
|
@echo "" |
|
@echo "Usage: make setup && make" |
|
|
|
# Pass through any unknown targets to the build directory if configured |
|
.PHONY: % |
|
%: |
|
ifeq ($(BUILD_CONFIGURED),yes) |
|
@$(MAKE) -C $(BUILD_DIR) $@ |
|
else |
|
@echo "Build directory not configured. Run 'make setup' first." |
|
@exit 1 |
|
endif
|
|
|