-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (109 loc) · 3.82 KB
/
Copy pathMakefile
File metadata and controls
138 lines (109 loc) · 3.82 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
134
135
136
137
138
# Makefile for YASH project
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200809L -I./include -g -O0
TEST_CFLAGS = $(CFLAGS) -I$(UNITYDIR)/src -I$(UNITYDIR)/extras/fixture/src
LDFLAGS =
# Directories
SRCDIR = src
INCDIR = include
OBJDIR = build/obj
BINDIR = .
DOCDIR = docs
TESTDIR = tests
UNITYDIR = $(TESTDIR)/unity
TESTSRCDIR = $(TESTDIR)/test_src
TESTBINDIR = build/test
# Target executable name
TARGET = yash
# Source files (automatically find all .c files in src/)
SOURCES = $(wildcard $(SRCDIR)/*.c)
TEST_SOURCES = $(wildcard $(TESTSRCDIR)/*.c)
# Object files (replace .c with .o and add obj/ prefix)
OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
TEST_OBJECTS = $(TEST_SOURCES:$(TESTSRCDIR)/%.c=$(OBJDIR)/%.o)
# Unity source files
UNITY_SOURCES = $(UNITYDIR)/src/unity.c
UNITY_OBJECTS = $(UNITY_SOURCES:$(UNITYDIR)/src/%.c=$(OBJDIR)/%.o)
# Default target (what gets built when you just run 'make')
all: $(BINDIR)/$(TARGET)
# Generate compile_commands.json for clangd
compile_commands.json: clean
@echo "Generating compile_commands.json for clangd..."
@bear -- make all
@echo "compile_commands.json generated successfully!"
# Build everything including tests
all-setup: clean all test
@echo ""
@echo "You can now:"
@echo " - Run tests: make test"
@echo " - Build project: make all"
@echo " - Format code: make format"
@echo " - Generate docs: make docs"
# Create the executable
$(BINDIR)/$(TARGET): $(OBJECTS) | $(BINDIR)
$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
# Compile source files to object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create necessary directories
$(OBJDIR):
mkdir -p $(OBJDIR)
$(BINDIR):
mkdir -p $(BINDIR)
$(TESTBINDIR):
mkdir -p $(TESTBINDIR)
# Clean up compiled files
clean:
rm -rf build
rm -f $(BINDIR)/$(TARGET)
# Clean and rebuild
rebuild: clean all
# Test targets
test: $(TESTBINDIR)/test_runner
@echo "Running all tests..."
@$(TESTBINDIR)/test_runner
# Build test runner executable
$(TESTBINDIR)/test_runner: $(OBJDIR)/test_runner.o $(TEST_OBJECTS) $(UNITY_OBJECTS) $(OBJDIR)/parse.o | $(TESTBINDIR)
$(CC) $(OBJDIR)/test_runner.o $(filter-out $(OBJDIR)/test_runner.o,$(TEST_OBJECTS)) $(UNITY_OBJECTS) $(OBJDIR)/parse.o -o $@ $(LDFLAGS)
# Compile test source files
$(OBJDIR)/test_%.o: $(TESTSRCDIR)/test_%.c | $(OBJDIR)
$(CC) $(TEST_CFLAGS) -c $< -o $@
# Compile Unity source files
$(OBJDIR)/unity.o: $(UNITYDIR)/src/unity.c | $(OBJDIR)
$(CC) $(TEST_CFLAGS) -c $< -o $@
# Install the executable (optional)
install: $(BINDIR)/$(TARGET)
cp $(BINDIR)/$(TARGET) /usr/local/bin/
# Uninstall (optional)
uninstall:
rm -f /usr/local/bin/$(TARGET)
rm -f $(BINDIR)/$(TARGET)
# Documentation targets
docs: $(DOCDIR)/html/index.html
$(DOCDIR)/html/index.html: $(wildcard $(INCDIR)/*.h) $(wildcard $(SRCDIR)/*.c) Doxyfile
doxygen Doxyfile
docs-clean:
rm -rf $(DOCDIR)/html $(DOCDIR)/latex
# Format code
format:
@echo "Formatting source files..."
clang-format -i $(wildcard $(SRCDIR)/*.c) $(wildcard $(INCDIR)/*.h)
@echo "Formatting complete!"
# Show help
help:
@echo "Available targets:"
@echo " all-setup - Build everything and run tests (RECOMMENDED)"
@echo " all - Build the project (default)"
@echo " clean - Remove all compiled files"
@echo " rebuild - Clean and build"
@echo " test - Run all unit tests"
@echo " format - Format source code with clang-format"
@echo " docs - Generate documentation"
@echo " docs-clean - Remove generated documentation"
@echo " compile_commands.json - Generate clangd configuration"
@echo " install - Install to /usr/local/bin"
@echo " uninstall - Remove from /usr/local/bin"
@echo " help - Show this help message"
# Declare phony targets (targets that don't create files)
.PHONY: all all-setup clean rebuild test format docs docs-clean install uninstall help