-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (122 loc) · 4.71 KB
/
Makefile
File metadata and controls
143 lines (122 loc) · 4.71 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
139
140
141
142
143
# Compiler and tool configurations
CC := gcc
BISON := bison
FLEX := flex
PYTHON := python3
# Compiler and linker flags
CFLAGS := -Wall -Wextra -Wpedantic -Werror -O2 -Wuninitialized -fsanitize=address,undefined -fno-omit-frame-pointer -g
LDFLAGS := -lfl -lm -ldl -rdynamic
SO_CFLAGS := -fPIC -shared
# Source files and directories
SRC_DIR := lib
DEBUG_FLAGS := -g
SRCS := $(SRC_DIR)/hm.c $(SRC_DIR)/mem.c $(SRC_DIR)/arena.c ast.c visitor.c semantic_analyzer.c interpreter.c stdrot.c
GENERATED_SRCS := lang.tab.c lex.yy.c
ALL_SRCS := $(SRCS) $(GENERATED_SRCS)
# stdrot shared library
STDROT_DIR := stdrot
STDROT_SRCS := $(wildcard $(STDROT_DIR)/*.c) $(SRC_DIR)/input.c
STDROT_LIB := libstdrot.so
# Output files
TARGET := brainrot
BISON_OUTPUT := lang.tab.c
FLEX_OUTPUT := lex.yy.c
# Default target
.PHONY: all
all: $(STDROT_LIB) $(TARGET)
# Ensure shared library exists for runtime targets
.PHONY: ensure-stdrot
ensure-stdrot:
@if [ ! -f $(STDROT_LIB) ]; then \
echo "$(STDROT_LIB) not found. Building it now..."; \
$(MAKE) $(STDROT_LIB); \
fi
# Build only the standard library
.PHONY: lib
lib: $(STDROT_LIB)
# Debug target
.PHONY: debug
debug: CFLAGS += $(DEBUG_FLAGS)
debug: clean all
@echo "Debug build compiled with -g. Time to sigma grind with GDB."
# stdrot shared library build
$(STDROT_LIB): $(STDROT_SRCS)
$(CC) $(SO_CFLAGS) -I. -o $@ $^ -lm
@echo "libstdrot.so compiled with max rizz."
# Main executable build
$(TARGET): $(ALL_SRCS) $(STDROT_LIB)
$(CC) $(CFLAGS) -o $@ $(ALL_SRCS) $(LDFLAGS)
@echo "Skibidi toilet: $(TARGET) compiled with max gyatt."
# Generate parser files using Bison
$(BISON_OUTPUT): lang.y
$(BISON) -d -Wcounterexamples $< -o $@
@echo "Bison is sigma grinding with $(BISON_OUTPUT)."
# Generate lexer files using Flex
$(FLEX_OUTPUT): lang.l
$(FLEX) $<
@echo "Flex is literally hitting the griddy to generate $(FLEX_OUTPUT)."
# Run tests
.PHONY: test
test: ensure-stdrot $(TARGET)
$(PYTHON) -m pytest -v
@echo "Tests ran bussin', no cap."
# Clean build artifacts
.PHONY: clean
clean:
rm -f $(TARGET) $(STDROT_LIB) $(GENERATED_SRCS) lang.tab.h
rm -f *.o
@echo "Blud cleaned up the mess like a true sigma coder."
# Run Valgrind on all .brainrot tests
.PHONY: valgrind
valgrind: ensure-stdrot $(TARGET)
@./run_valgrind_tests.sh
@echo "Valgrind check done. If anything was sus, it'll show up with a non-zero exit code. No cap."
# Install target
.PHONY: install
install: ensure-stdrot $(TARGET)
install -d /usr/local/bin
install -m 755 $(TARGET) /usr/local/bin/
@echo "$(TARGET) installed successfully. You're goated with the sauce!"
# Uninstall target
.PHONY: uninstall
uninstall:
rm -f /usr/local/bin/$(TARGET)
@echo "$(TARGET) uninstalled successfully. Back to the grind."
# Check dependencies
.PHONY: check-deps
check-deps:
@command -v $(CC) >/dev/null 2>&1 || { echo "Error: gcc not found. Blud, install gcc!"; exit 1; }
@command -v $(BISON) >/dev/null 2>&1 || { echo "Error: bison not found. Duke Dennis did you pray today?"; exit 1; }
@command -v $(FLEX) >/dev/null 2>&1 || { echo "Error: flex not found. Ayo, where's flex?"; exit 1; }
@command -v $(PYTHON) >/dev/null 2>&1 || { echo "Error: python3 not found. Python in Ohio moment."; exit 1; }
@$(PYTHON) -c "import pytest" >/dev/null 2>&1 || { echo "Error: pytest not found. Install with: pip install pytest. That's the ocky way."; exit 1; }
# Development helper to rebuild everything from scratch
.PHONY: rebuild
rebuild: clean all
@echo "Whole bunch of turbulence cleared. Rebuilt everything."
# Format source files (requires clang-format)
.PHONY: format
format:
@command -v clang-format >/dev/null 2>&1 || { echo "Error: clang-format not found. Ratioed by clang."; exit 1; }
find . -name "*.c" -o -name "*.h" | xargs clang-format -i
@echo "Source files got the rizz treatment, goated with the sauce."
# Show help
.PHONY: help
help:
@echo "Available targets (rizzy edition):"
@echo " all : Build the main executable (default target). Sigma grindset activated."
@echo " install : Install the binary to /usr/local/bin. Certified W."
@echo " uninstall : Uninstall the binary from /usr/local/bin. Back to square one."
@echo " test : Run the test suite. Huggy Wuggy approves."
@echo " clean : Remove all generated files. Amogus sussy imposter mode."
@echo " check-deps : Verify all required bro apps are installed."
@echo " rebuild : Clean and re-grind the project."
@echo " format : Format source files using clang-format. No cringe, all kino."
@echo " valgrind : Checks for sussy memory leaks with Valgrind."
@echo " help : Show this help for n00bs."
@echo ""
@echo "Configuration (poggers):"
@echo " CC = $(CC)"
@echo " CFLAGS = $(CFLAGS)"
@echo " LDFLAGS = $(LDFLAGS)"
@echo " TARGET = $(TARGET)"