-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (111 loc) · 4.37 KB
/
Copy pathMakefile
File metadata and controls
130 lines (111 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# ============================================================
# Main Makefile for OWLSM Project
# ============================================================
# ---- Configuration Variables ---------------------------------
# Set DEBUG=1 for debug builds: make DEBUG=1
# Leave unset for release builds: make
VERSION ?= 1.0.0
ARCH ?=
# Validate VERSION format (X.Y.Z)
ifneq ($(words $(subst ., ,$(VERSION))),3)
$(error VERSION must be Major.Minor.Patch, got '$(VERSION)')
endif
ifneq ($(ARCH),)
ifneq ($(ARCH),x86_64)
ifneq ($(ARCH),aarch64)
$(error ARCH must be x86_64 or aarch64, got '$(ARCH)')
endif
endif
endif
# ---- Export variables to sub-makefiles -----------------------
export DEBUG
export VERSION
# ---- Directories ---------------------------------------------
SRC_DIR := src
BUILD_DIR := build
KERNEL_DIR := $(SRC_DIR)/Kernel
USERSPACE_DIR := $(SRC_DIR)/Userspace
TEST_DIR := $(SRC_DIR)/Tests
UNIT_TEST_DIR := $(TEST_DIR)/unit_test
AUTOMATION_DIR := $(TEST_DIR)/Automation
AUTOMATION_RESOURCES_DIR := $(AUTOMATION_DIR)/resources
SCRIPTS_DIR := scripts
# ---- Binary Paths --------------------------------------------
USER_BIN := $(USERSPACE_DIR)/owlsm
TEST_BIN := $(UNIT_TEST_DIR)/unit_tests
# ---- Install Paths -------------------------------------------
INSTALL_DIR := $(BUILD_DIR)/owlsm
TEST_INSTALL_DIR := $(BUILD_DIR)/unit_tests
# ---- Phony Targets -------------------------------------------
.PHONY: all clean test tarball automation help kernel userspace rules_generator
.DEFAULT_GOAL := all
# ---- Build Targets -------------------------------------------
all: kernel userspace rules_generator
@python3 $(SCRIPTS_DIR)/package.py owlsm
kernel:
@echo "==> Building Kernel (eBPF)..."
@$(MAKE) -C $(KERNEL_DIR)
userspace: kernel
@echo "==> Building Userspace..."
@$(MAKE) -C $(USERSPACE_DIR)
rules_generator:
@echo "==> Building RulesGenerator binary..."
@bash Rules/RulesGenerator/build_py_to_bin.sh
test: kernel
@echo "==> Building unit tests..."
@$(MAKE) -C $(UNIT_TEST_DIR)
@python3 $(SCRIPTS_DIR)/package.py unit_tests
# Top-level directory inside the archive stays "owlsm".
ifdef ARCH
TARBALL_NAME := owlsm-$(ARCH)-v$(VERSION).tar.gz
else
TARBALL_NAME := owlsm-$(VERSION).tar.gz
endif
tarball: all
@echo "==> Creating tarball..."
@tar -czf $(BUILD_DIR)/$(TARBALL_NAME) -C $(BUILD_DIR) owlsm
@echo "==> Tarball created: $(BUILD_DIR)/$(TARBALL_NAME)"
automation:
@echo "==> Building automation resources..."
@$(MAKE) -C $(AUTOMATION_RESOURCES_DIR)
@rm -rf $(AUTOMATION_DIR)/owlsm
@cp -a $(INSTALL_DIR) $(AUTOMATION_DIR)/owlsm
clean:
@echo "==> Cleaning Kernel..."
@$(MAKE) -C $(KERNEL_DIR) clean
@echo "==> Cleaning Userspace..."
@$(MAKE) -C $(USERSPACE_DIR) clean
@echo "==> Cleaning Tests..."
@$(MAKE) -C $(UNIT_TEST_DIR) clean
@$(MAKE) -C $(AUTOMATION_RESOURCES_DIR) clean
@echo "==> Cleaning RulesGenerator binary..."
@rm -f Rules/RulesGenerator/rules_generator
@echo "==> Cleaning build directory..."
@rm -rf $(BUILD_DIR)
help:
@echo "OWLSM Build System"
@echo ""
@echo "Targets:"
@echo " all - Build and package owlsm (default) → build/owlsm/ (includes rules_generator)"
@echo " kernel - Build eBPF kernel code"
@echo " userspace - Build userspace binary"
@echo " test - Build and package unit tests → build/unit_tests/"
@echo " tarball - Create release tarball (depends on all)"
@echo " automation - Build and setup automation tests"
@echo " rules_generator - Build RulesGenerator binary → Rules/RulesGenerator/rules_generator"
@echo " clean - Clean all build artifacts"
@echo " help - Show this help message"
@echo ""
@echo "Variables:"
@echo " DEBUG - Set to 1 for debug build (default: unset = release)"
@echo " VERSION - Version string X.Y.Z (default: $(VERSION))"
@echo " ARCH - Optional tarball name arch: x86_64 or aarch64"
@echo " (build itself always uses the host arch)"
@echo ""
@echo "Examples:"
@echo " make -j\$$(nproc) # Release build (host arch)"
@echo " make DEBUG=1 -j\$$(nproc) # Debug build"
@echo " make tarball VERSION=2.0.0 # → build/owlsm-2.0.0.tar.gz"
@echo " make tarball ARCH=aarch64 VERSION=2.0.0 # → build/owlsm-aarch64-v2.0.0.tar.gz"
@echo " make test -j\$$(nproc) # Build + package unit tests"
@echo " make automation -j\$$(nproc) # Build + setup automation"