Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate implementation from headers #31

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
TARGET := vitaminc
CXX := g++
CXXFLAGS = -g3 -std=c++14 -Wall
CC = $(CXX)
CXXFLAGS = -g3 -std=c++14 -Wall -MMD -Iinclude
CFLAGS = $(CXXFLAGS)
LEX = lex
# C++ features are used, yacc doesn't suffice
YACC = bison
# -d: generate header with default name
YFLAGS = --verbose --debug -d

# Note that lex.yy.c is excluded deliberately, as "lex.yy.c" is considered a
# header file (it's included by "y.tab.c").
OBJS := $(shell find . -name "*.cpp") y.tab.o
OBJS := $(OBJS:.cpp=.o)
DEPS = $(OBJS:.o=.d)

.PHONY: all clean test

all: $(TARGET) test

test: $(TARGET)
make -C test/

$(TARGET): main.cpp lex.yy.c y.tab.c ast.hpp type.hpp scope.hpp symbol.hpp
$(CXX) $(CXXFLAGS) $< y.tab.c -o $@
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(OBJS) -o $@

lex.yy.c: lexer.l
$(LEX) -o $@ $^
$(LEX) -o $@ $<

y.tab.h: y.tab.c
y.tab.c: parser.y lex.yy.c
$(YACC) $(YFLAGS) $< -o $@

y.tab.c: parser.y
$(YACC) $(YFLAGS) $^ -o $@
#
# Please note that although we're handling dependencies automatically with -MMD,
# files that includes Flex or Bison-generated files still have to make such
# dependency explicit to enforce the ordering.
#

main.o: %.o: %.cpp y.tab.h

clean:
rm -rf *.s *.o lex.yy.c y.tab.c y.tab.h *.output *.ssa $(TARGET)
rm -rf *.s *.o lex.yy.c y.tab.c y.tab.h *.output *.ssa $(TARGET) $(OBJS) $(DEPS)
make -C test/ clean

-include $(DEPS)
Loading