1 | #
|
---|
2 | # Makefile for assignment 2 of the Compiler Construction course.
|
---|
3 | # Fall 2007, LIACS, Leiden University.
|
---|
4 | #
|
---|
5 |
|
---|
6 | CC = g++
|
---|
7 | LEX = flex
|
---|
8 | YACC = bison --yacc
|
---|
9 |
|
---|
10 | WARNINGS = -Wall -ansi
|
---|
11 | OTHERS = -m32 -g
|
---|
12 | DEFINES = -DDEBUG
|
---|
13 | IDIRS = -I.
|
---|
14 |
|
---|
15 | CFLAGS = $(WARNINGS) $(OTHERS) $(DEFINES) $(IDIRS)
|
---|
16 | LFLAGS =
|
---|
17 | YFLAGS = --defines --debug --verbose
|
---|
18 | LDFLAGS = -m32 -g
|
---|
19 | LOADLIBS = -lfl -lm
|
---|
20 |
|
---|
21 | #
|
---|
22 | # If you want to add another C/C++ file to the compiler, add the name of the
|
---|
23 | # corresponding .o file to the OBJFILES macro below:
|
---|
24 | #
|
---|
25 | OBJFILES = debug.o messages.o coercion.o lookup.o
|
---|
26 | OBJDIR = gen/
|
---|
27 | OBJS = $(addprefix $(OBJDIR),$(OBJFILES))
|
---|
28 |
|
---|
29 | # Precompiled object files
|
---|
30 | POBJFILES = types.o SyntaxTree.o Node.o Symbol.o SymbolTable.o Scope.o
|
---|
31 | POBJDIR = obj/
|
---|
32 | POBJS = $(addprefix $(POBJDIR),$(POBJFILES))
|
---|
33 |
|
---|
34 | IMPORTANT = comp.[hly] *.h *.c *.cc \
|
---|
35 | Makefile
|
---|
36 |
|
---|
37 | .PHONY: all first clean backup dirs showdeps
|
---|
38 |
|
---|
39 | all: comp
|
---|
40 |
|
---|
41 | # To be executed before the very first build
|
---|
42 | first: dirs
|
---|
43 |
|
---|
44 | # Dependency stuff
|
---|
45 | comp: $(OBJDIR)y.tab.o $(OBJDIR)lex.yy.o $(OBJS) $(POBJS)
|
---|
46 | $(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBS)
|
---|
47 |
|
---|
48 | $(OBJDIR)y.tab.h $(OBJDIR)y.tab.c: comp.y
|
---|
49 | $(YACC) $(YFLAGS) $< -o $(OBJDIR)y.tab.c
|
---|
50 |
|
---|
51 | $(OBJDIR)lex.yy.c: comp.l
|
---|
52 | $(LEX) $(LFLAGS) -o$@ $<
|
---|
53 |
|
---|
54 | clean:
|
---|
55 | rm -f $(OBJDIR){lex.yy.c,y.tab.*,y.output,*.o} *~ comp \
|
---|
56 | `find . -name core -o -name \*\.bak`
|
---|
57 |
|
---|
58 | backup:
|
---|
59 | tar cfz ../CoCo-`date +'%y%m%d-%H%M'`.tar.gz $(IMPORTANT)
|
---|
60 |
|
---|
61 | dirs:
|
---|
62 | mkdir gen
|
---|
63 |
|
---|
64 | # Show dependencies between .c files
|
---|
65 | showdeps:
|
---|
66 | $(CC) -MM *.c *.cc
|
---|
67 |
|
---|
68 | # Dependency stuff
|
---|
69 | $(OBJDIR)lex.yy.o: $(OBJDIR)lex.yy.c $(OBJDIR)y.tab.h
|
---|
70 | $(OBJDIR)y.tab.o: $(OBJDIR)y.tab.c
|
---|
71 |
|
---|
72 | $(OBJDIR)%.o: %.c
|
---|
73 | $(CC) $(CFLAGS) -c -o $@ $<
|
---|
74 |
|
---|
75 | $(OBJDIR)%.o: %.cc
|
---|
76 | $(CC) $(CFLAGS) -c -o $@ $<
|
---|