-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (55 loc) · 1.87 KB
/
Makefile
File metadata and controls
70 lines (55 loc) · 1.87 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
# Compiler and Flags
CC = gcc
CFLAGS = -Iinclude -Wall -Wextra -std=c99 -g
# -Iinclude: Look for headers in the 'include' folder
# -Wall -Wextra: Enable all warnings (good for learning/debugging)
# -std=c99: Use C99 standard
# -g: Add debug symbols (for gdb/lldb)
# Directories
SRC_DIR = src
BUILD_DIR = build
# Source files (Wildcard matches all .c files in src/)
SRCS = $(wildcard $(SRC_DIR)/*.c)
# Object files (Replace src/%.c with build/%.o)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
# Final Library Name
TARGET_LIB = $(BUILD_DIR)/libtxtengine.a
# Example Binaries
EXAMPLE_SRC = examples/demo.c
EXAMPLE_BIN = $(BUILD_DIR)/demo
# Test Binaries
TEST_SRC = tests/test_scanner.c
TEST_BIN = $(BUILD_DIR)/test_scanner
# Default target (what runs when you just type 'make')
all: directories $(TARGET_LIB) $(EXAMPLE_BIN)
# Rule to make directories
directories:
@mkdir -p $(BUILD_DIR)
# Rule to build the static library
# 'ar' is the archiver tool to create .a files
# 'rcs' means Replace, Create, Sort-index
$(TARGET_LIB): $(OBJS)
ar rcs $@ $^
@echo "Library compiled successfully: $@"
# Rule to build the example program
# Links against the static library (-Lbuild -ltxtengine)
$(EXAMPLE_BIN): $(EXAMPLE_SRC) $(TARGET_LIB)
$(CC) $(CFLAGS) $< -L$(BUILD_DIR) -ltxtengine -o $@
@echo "Example compiled successfully: $@"
# Rule to build the test program
test: $(TEST_BIN)
@echo "Running Tests..."
@./$(TEST_BIN)
$(TEST_BIN): $(TEST_SRC) $(TARGET_LIB)
$(CC) $(CFLAGS) $< -L$(BUILD_DIR) -ltxtengine -o $@
@echo "Test compiled successfully: $@"
# Rule to compile .c to .o
# $< is the source file, $@ is the target object file
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up build artifacts
clean:
rm -rf $(BUILD_DIR)
@echo "Cleaned build directory."
# Phony targets help avoid conflicts with files named 'clean' or 'all'
.PHONY: all clean directories