-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (60 loc) · 1.54 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
# Compilers
CC := gcc
CXX := g++
# Portability variables
ifdef ComSpec
# Windows variables
PATHSEP:=\\
rm:=del
mv:=ren
md:=mkdir
else
# UNIX variables
PATHSEP:=/
rm:=/bin/rm -f
mv:=/bin/mv -f
md:=mkdir -p
endif
# Target file to compile
target=Compiler
# Includes, source, object and binaries directories #
includedirs:=include
srcdir:=src
objdir:=obj
bindir:=bin
# Includes, source, object and dependecy files #
INCLUDES := $(addprefix -I,$(includedirs))
CPPSOURCES := $(wildcard $(srcdir)/*.c)
CPPOBJECTS := $(CPPSOURCES:$(srcdir)/%.c=$(objdir)/%.o)
CXXSOURCES := $(wildcard $(srcdir)/*.cpp)
CXXOBJECTS := $(CXXSOURCES:$(srcdir)/%.cpp=$(objdir)/%.o)
DEPS := $(wildcard $(objdir)/*.d)
# Compiler and flags variables #
CPPFLAGS += $(INCLUDES)
CXXFLAGS += $(INCLUDES)
all: $(CPPOBJECTS) $(CXXOBJECTS) $(target)
$(target): %: %.y
$(md) bin
@echo "Compiling yacc file:" $<
@echo "Output file:" $@
bison -o$@.tab.c -d $<
flex -o$@.l.c $@.l
#$(CC) $(CPPFLAGS) -w -o $(bindir)/$@ $@.tab.c $@.l.c $(CPPOBJECTS)
# Use the line below to compile with g++
$(CXX) $(CXXFLAGS) -w -o $(bindir)/$@ $@.tab.c $@.l.c $(CXXOBJECTS) $(CPPOBJECTS)
$(rm) $@.tab.c $@.tab.h $@.l.c
$(CPPOBJECTS): $(objdir)/%.o: $(srcdir)/%.c
$(md) obj
$(CC) $(CPPFLAGS) -c $(OUTPUT_OPTION) $<
$(CXXOBJECTS): $(objdir)/%.o: $(srcdir)/%.cpp
$(md) obj
$(CXX) $(CXXFLAGS) -c $(OUTPUT_OPTION) $<
.PHONY: clean
clean:
$(rm) $(target)
$(rm) $(bindir)$(PATHSEP)*.exe
$(rm) $(objdir)$(PATHSEP)*.o
$(rm) $(objdir)$(PATHSEP)*.d
$(rm) *.tab.h *.tab.c *.l.c *.tab.cc *.l.cc
$(rm) *.pyc
include $(DEPS)