-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
83 lines (64 loc) · 2.34 KB
/
Makefile
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
## Main compiler
CC := g++
BNFC := bnfc
## Directories
SRCDIR := src
HEADERDIR := include
BUILDDIR := build
BINDIR := bin
BNFDIR := bnf
GENSRCDIR := gensrc
## Targets
MAINTARGET := bin/oberon
TESTERTARGET := bin/tester
## Extensions
SRCEXT := cpp
HEADEREXT := hpp
## Source requisites
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
BNFSOURCE := $(GENSRCDIR)/Absyn.C $(GENSRCDIR)/Makefile $(GENSRCDIR)/oberon.y $(GENSRCDIR)/Printer.C $(GENSRCDIR)/Skeleton.C $(GENSRCDIR)/Test.C $(GENSRCDIR)/Absyn.H $(GENSRCDIR)/oberon.l $(GENSRCDIR)/Parser.H $(GENSRCDIR)/Printer.H $(GENSRCDIR)/Skeleton.H
## Tester requisites
TESTEROBJ := $(BUILDDIR)/BinExpression.o $(BUILDDIR)/Expression.o $(BUILDDIR)/Command.o $(BUILDDIR)/Environment.o $(BUILDDIR)/Procedure.o $(BUILDDIR)/VarRef.o $(BUILDDIR)/TCVisitor.o
## Objects targets
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
BNFOBJECTS := $(BUILDDIR)/Absyn.o $(BUILDDIR)/Lexer.o $(BUILDDIR)/Parser.o $(BUILDDIR)/Printer.o
## Flags
CXXFLAGS := -g -W -Wall -Wextra -Wno-unused-parameter -std=c++11 #-Wno-unused-parameter
LIB := -pthread -L lib
INC := -I $(HEADERDIR) -I $(GENSRCDIR)
GTEST := ${GTEST_DIR}
## Generate main program
$(MAINTARGET): $(OBJECTS) .bnfobjects .folders
$(CC) $(OBJECTS) $(BNFOBJECTS) -o $(MAINTARGET)
## Generate obj with dependency info
-include $(OBJECTS:.o=.d)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) .folders .bnfsource
$(CC) $(CXXFLAGS) $(INC) -c -o $@ $<
printf "$(BUILDDIR)/" "%s" > $(BUILDDIR)/$*.d
$(CC) $(CXXFLAGS) $(INC) -MM $< >> $(BUILDDIR)/$*.d
## Generate bnf source
.bnfsource: $(BNFDIR)/oberon.bnfc .folders
$(BNFC) -m -cpp $(BNFDIR)/oberon.bnfc -o $(GENSRCDIR)
touch .bnfsource
## Generate bnf obj
.bnfobjects: .bnfsource .folders
make -C $(GENSRCDIR) all
mv $(GENSRCDIR)/*.o $(BUILDDIR)
touch .bnfobjects
## Generate folders
.folders:
mkdir -p $(GENSRCDIR)
mkdir -p $(BUILDDIR)
mkdir -p $(BINDIR)
touch .folders
## Generate tester
tester: $(OBJECTS) .folders
$(CC) $(CXXFLAGS) $(LIB) test/TestOberonLang.cpp $(INC) -o $(TESTERTARGET) $(GTEST)/libgtest.a $(TESTEROBJ)
## Clean
clean:
rm -rf $(BUILDDIR) $(BINDIR) -R
rm -rf $(MAINTARGET) $(TESTERTARGET) $(BNFDIR)/*.bak .bnfobjects .folders
cleanAll:
rm -rf $(BUILDDIR) $(GENSRCDIR) $(BINDIR) -R
rm -rf $(MAINTARGET) $(TESTERTARGET) $(BNFDIR)/*.bak .bnfobjects .bnfsource .folders
.PHONY: clean