@@ -6,34 +6,56 @@ PYTHON := python3
66
77# Compiler and linker flags
88CFLAGS := -Wall -Wextra -Wpedantic -Werror -O2 -Wuninitialized
9- LDFLAGS := -lfl -lm
9+ LDFLAGS := -lfl -lm -ldl -rdynamic
10+ SO_CFLAGS := -fPIC -shared
1011
1112# Source files and directories
1213SRC_DIR := lib
1314DEBUG_FLAGS := -g
14- SRCS := $(SRC_DIR ) /hm.c $(SRC_DIR ) /mem.c $(SRC_DIR ) /input.c $( SRC_DIR ) / arena.c ast.c visitor.c semantic_analyzer.c interpreter.c stdrot.c
15+ SRCS := $(SRC_DIR ) /hm.c $(SRC_DIR ) /mem.c $(SRC_DIR ) /arena.c ast.c visitor.c semantic_analyzer.c interpreter.c stdrot.c
1516GENERATED_SRCS := lang.tab.c lex.yy.c
1617ALL_SRCS := $(SRCS ) $(GENERATED_SRCS )
1718
19+ # stdrot shared library
20+ STDROT_DIR := stdrot
21+ STDROT_SRCS := $(wildcard $(STDROT_DIR ) /* .c) $(SRC_DIR ) /input.c
22+ STDROT_LIB := libstdrot.so
23+
1824# Output files
1925TARGET := brainrot
2026BISON_OUTPUT := lang.tab.c
2127FLEX_OUTPUT := lex.yy.c
2228
2329# Default target
2430.PHONY : all
25- all : $(TARGET )
31+ all : $(STDROT_LIB ) $(TARGET )
32+
33+ # Ensure shared library exists for runtime targets
34+ .PHONY : ensure-stdrot
35+ ensure-stdrot :
36+ @if [ ! -f $( STDROT_LIB) ]; then \
37+ echo " $( STDROT_LIB) not found. Building it now..." ; \
38+ $(MAKE ) $(STDROT_LIB ) ; \
39+ fi
40+
41+ # Build only the standard library
42+ .PHONY : lib
43+ lib : $(STDROT_LIB )
2644
2745# Debug target
2846.PHONY : debug
2947debug : CFLAGS += $(DEBUG_FLAGS )
30- debug : clean $( TARGET )
48+ debug : clean all
3149 @echo " Debug build compiled with -g. Time to sigma grind with GDB."
3250
51+ # stdrot shared library build
52+ $(STDROT_LIB ) : $(STDROT_SRCS )
53+ $(CC ) $(SO_CFLAGS ) -I. -o $@ $^ -lm
54+ @echo " libstdrot.so compiled with max rizz."
3355
3456# Main executable build
35- $(TARGET ) : $(ALL_SRCS )
36- $(CC ) $(CFLAGS ) -o $@ $^ $(LDFLAGS )
57+ $(TARGET ) : $(ALL_SRCS ) $( STDROT_LIB )
58+ $(CC ) $(CFLAGS ) -o $@ $( ALL_SRCS ) $(LDFLAGS )
3759 @echo " Skibidi toilet: $( TARGET) compiled with max gyatt."
3860
3961# Generate parser files using Bison
@@ -48,26 +70,26 @@ $(FLEX_OUTPUT): lang.l
4870
4971# Run tests
5072.PHONY : test
51- test :
73+ test : ensure-stdrot $( TARGET )
5274 $(PYTHON ) -m pytest -v
5375 @echo " Tests ran bussin', no cap."
5476
5577# Clean build artifacts
5678.PHONY : clean
5779clean :
58- rm -f $(TARGET ) $(GENERATED_SRCS ) lang.tab.h
80+ rm -f $(TARGET ) $(STDROT_LIB ) $( GENERATED_SRCS ) lang.tab.h
5981 rm -f * .o
6082 @echo " Blud cleaned up the mess like a true sigma coder."
6183
6284# Run Valgrind on all .brainrot tests
6385.PHONY : valgrind
64- valgrind :
86+ valgrind : ensure-stdrot $( TARGET )
6587 @./run_valgrind_tests.sh
6688 @echo " Valgrind check done. If anything was sus, it'll show up with a non-zero exit code. No cap."
6789
6890# Install target
6991.PHONY : install
70- install :
92+ install : ensure-stdrot $( TARGET )
7193 install -d /usr/local/bin
7294 install -m 755 $(TARGET ) /usr/local/bin/
7395 @echo " $( TARGET) installed successfully. You're goated with the sauce!"
0 commit comments