-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (113 loc) · 3.36 KB
/
Makefile
File metadata and controls
133 lines (113 loc) · 3.36 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
131
132
133
# Makefile for AES Cryptanalysis Toolkit
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=c99 -Isrc
LDFLAGS = -lm
# Debug flags
DEBUG_FLAGS = -g -O0 -DDEBUG
SANITIZE_FLAGS = -fsanitize=address -fsanitize=undefined
# Directories
SRC_DIR = src
BUILD_DIR = build
BIN_DIR = bin
TEST_DIR = tests
EXAMPLES_DIR = examples
BENCH_DIR = benchmarks
# Source files
CORE_SOURCES = $(wildcard $(SRC_DIR)/core/*.c)
ATTACK_SOURCES = $(wildcard $(SRC_DIR)/attacks/*.c)
MAIN_SOURCE = $(SRC_DIR)/main.c
# Object files
CORE_OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(CORE_SOURCES))
ATTACK_OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(ATTACK_SOURCES))
MAIN_OBJECT = $(BUILD_DIR)/main.o
# Targets
TARGET = $(BIN_DIR)/aes_attack
ALL_OBJECTS = $(CORE_OBJECTS) $(ATTACK_OBJECTS) $(MAIN_OBJECT)
# Default target
.PHONY: all
all: $(TARGET)
# Create directories
$(BUILD_DIR) $(BIN_DIR) $(BUILD_DIR)/core $(BUILD_DIR)/attacks:
mkdir -p $@
# Compile object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) $(BUILD_DIR)/core $(BUILD_DIR)/attacks
$(CC) $(CFLAGS) -c $< -o $@
# Link executable
$(TARGET): $(ALL_OBJECTS) | $(BIN_DIR)
$(CC) $(ALL_OBJECTS) $(LDFLAGS) -o $@
@echo ""
@echo "Build successful! Executable: $(TARGET)"
@echo ""
# Debug build
.PHONY: debug
debug: CFLAGS += $(DEBUG_FLAGS)
debug: clean all
# Sanitizer build (for memory checking)
.PHONY: sanitize
sanitize: CFLAGS += $(DEBUG_FLAGS) $(SANITIZE_FLAGS)
sanitize: LDFLAGS += $(SANITIZE_FLAGS)
sanitize: clean all
# Run the attack with default settings
.PHONY: run
run: $(TARGET)
@echo "Running attack with random key..."
@$(TARGET) -r
# Run with verbose output
.PHONY: run-verbose
run-verbose: $(TARGET)
@$(TARGET) -r -v
# Clean build artifacts
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(BIN_DIR)
@echo "Cleaned build artifacts"
# Clean all generated files
.PHONY: distclean
distclean: clean
rm -rf data/attack_results/*
@echo "Cleaned all generated files"
# Install (copy to /usr/local/bin or specified prefix)
PREFIX ?= /usr/local
.PHONY: install
install: $(TARGET)
install -d $(PREFIX)/bin
install -m 755 $(TARGET) $(PREFIX)/bin/
@echo "Installed to $(PREFIX)/bin/"
# Uninstall
.PHONY: uninstall
uninstall:
rm -f $(PREFIX)/bin/aes_attack
@echo "Uninstalled from $(PREFIX)/bin/"
# Show variables (for debugging Makefile)
.PHONY: show
show:
@echo "CC: $(CC)"
@echo "CFLAGS: $(CFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "CORE_SOURCES: $(CORE_SOURCES)"
@echo "ATTACK_SOURCES: $(ATTACK_SOURCES)"
@echo "ALL_OBJECTS: $(ALL_OBJECTS)"
@echo "TARGET: $(TARGET)"
# Help
.PHONY: help
help:
@echo "AES Cryptanalysis Toolkit - Makefile"
@echo ""
@echo "Available targets:"
@echo " all - Build the project (default)"
@echo " debug - Build with debug symbols"
@echo " sanitize - Build with AddressSanitizer"
@echo " run - Build and run with random key"
@echo " run-verbose - Build and run with verbose output"
@echo " clean - Remove build artifacts"
@echo " distclean - Remove all generated files"
@echo " install - Install to PREFIX (default: /usr/local)"
@echo " uninstall - Uninstall from PREFIX"
@echo " show - Show Makefile variables"
@echo " help - Show this help message"
@echo ""
@echo "Variables:"
@echo " PREFIX - Installation prefix (default: /usr/local)"
@echo " CC - C compiler (default: gcc)"
@echo ""