Makefile rewrite

This commit is contained in:
Scarlett
2025-04-25 12:46:07 -04:00
parent 945dda59d0
commit 2c712ed221
10 changed files with 380 additions and 177 deletions

View File

@ -1,39 +1,73 @@
# ----- Definitions -----
CC := gcc
FLEX := flex
BISON = bison
CFLAGS := -ggdb
BISONFLAGS := -d
LEX := src/lexicalStructure.lex
YACC := src/grammar.y
EXE := alpha
CFLAGS :=
YACC := bison
OBJS := tmp/runner.o tmp/symbol_table.o tmp/grammar.tab.o tmp/lex.yy.o tmp/intermediate_code.o
# tmp/intermediate_code.o codegen.o
TESTS-S1 := $(wildcard tests/sprint1/test/*.alpha)
TESTS-S2 := $(wildcard tests/sprint2/test/*.alpha)
TESTS-S3 := $(wildcard tests/sprint3/test/*.alpha)
TESTS-S4 := $(wildcard tests/sprint4/test/*.alpha)
# ----------
compiler: clean runner
tmp/grammar.tab.c: src/grammar.y
# ----- Targets -----
all: compiler
compiler: clean tmp $(OBJS)
$(CC) $(CFLAGS) -o $(EXE) $(OBJS)
clean:
rm -f $(EXE)
rm -rf out
rm -rf tmp
tmp:
mkdir -p tmp
$(YACC) -d src/grammar.y
mv grammar.tab.c tmp/
mv grammar.tab.h tmp/
tmp/lex.yy.c: src/lexicalStructure.lex tmp/grammar.tab.c
tmp/grammar.tab.c tmp/grammar.tab.h: $(YACC)
$(BISON) $(BISONFLAGS) -o tmp/grammar.tab.c $(YACC)
tmp/lex.yy.c tmp/flex.h: $(LEX) tmp/grammar.tab.h
$(FLEX) -o tmp/lex.yy.c $(LEX)
mv flex.h tmp/
mv flex.h tmp/flex.h
# -----------
tmp/runner.o: src/runner.c src/runner.h tmp/flex.h
$(CC) $(CFLAGS) -o tmp/runner.o -c src/runner.c
# ----- Create Objs -----
tmp/grammar.tab.o: tmp/grammar.tab.c
$(CC) $(CFLAGS) -c tmp/grammar.tab.c -o tmp/grammar.tab.o
tmp/lex.yy.o: tmp/lex.yy.c
$(CC) $(CFLAGS) -c tmp/lex.yy.c -o tmp/lex.yy.o
tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h
$(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c
$(CC) $(CFLAGS) -c src/symbol_table.c -o tmp/symbol_table.o
runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o
$(CC) $(CFLAGS) -o $(EXE) -g -ggdb tmp/runner.o tmp/grammar.tab.c tmp/lex.yy.c
tmp/intermediate_code.o: src/intermediate_code.c src/intermediate_code.h
$(CC) $(CFLAGS) -c src/intermediate_code.c -o tmp/intermediate_code.o
debug: CFLAGS += -DDEBUG=1
debug: clean compiler
# tmp/codegen.o: src/codegen.c src/codegen.h
# $(CC) $(CFLAGS) -c src/codegen.c -o tmp/codegen.o
tmp/runner.o: src/runner.c src/runner.h tmp/flex.h tmp/grammar.tab.h
$(CC) $(CFLAGS) -c src/runner.c -o tmp/runner.o
# -----------
# ----- Tests -----
test:
chmod +x ./check.sh
chmod +x ./test.sh
@ -67,15 +101,6 @@ test-s4:
./test.sh sp4
./check.sh sp4
clean:
rm -f *.o
rm -f lex.yy.c
rm -f $(EXE)
rm -f flex.h
rm -f *.tok
rm -f grammar.tab.c
rm -f grammar.tab.h
rm -f *.st
rm -rf out
rm -rf tmp
rm -f parser
# Temprorary test ~ Scarlett
test-make: clean tmp tmp/grammar.tab.c tmp/grammar.tab.h tmp/lex.yy.c tmp/flex.h tmp/grammar.tab.o tmp/lex.yy.o tmp/symbol_table.o tmp/runner.o
# -----------