summaryrefslogtreecommitdiffhomepage
path: root/Makefile
blob: aff378ed37a28e0c1016e296984aa54ef8df726b (plain)
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
84
85
86
87
88
89
PROJECTNAME=minicc

CXX=clang++-9
#CXX=g++-8

CXXFLAGS=-O0 -g -D_DEBUG
# -fprofile-instr-generate -fcoverage-mapping
# gcc:--coverage
#CXXFLAGS=-O2 -DNDEBUG

CXXFLAGS+= -Wall -std=c++17 -I.

ifeq ($(CXX),clang++-9)
# currently broken:
# ld.lld-8: error: undefined symbol: boost::re_detail_106700::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const
#CXXFLAGS+= -stdlib=libc++
endif

CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock

LIBS=\
-lboost_context \
-lboost_coroutine \
-lboost_program_options \
-lboost_system \
-lboost_thread \
-lboost_filesystem \
-lboost_regex \
-lpthread

ifeq ($(CXX),clang++-9)
LIBS+= \
-fuse-ld=lld-8 \
-lstdc++ \
-lstdc++fs
#-lc++ \
#-lc++abi \
#-lc++fs
else
LIBS+= \
-lstdc++ \
-lstdc++fs
endif

SRC=\
    bnf.cpp \
    cpp.cpp \
    test-cpp.cpp \
    cppbnf.cpp \
    test-cppbnf.cpp \
    grammer.cpp \
    test-grammer.cpp \
    lexer.cpp \
    test-lexer.cpp \
    minicc.cpp \
    test-minicc.cpp \
    elf.cpp \
    test-elf.cpp \
    googletest/src/gtest-all.cpp \
    googlemock/src/gmock-all.cpp

all: test-$(PROJECTNAME)
	./test-$(PROJECTNAME)

# testsuite ----------------------------------------------
test-$(PROJECTNAME): $(SRC:.cpp=.o)
	$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@

googletest/src/%.o: googletest/src/%.cc
	$(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@

# dependencies

ADD_DEP=Makefile

# misc ---------------------------------------------------
clean:
	-rm -f test-$(PROJECTNAME)
	-find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm

zip: clean
	-rm -f ../$(PROJECTNAME).zip
	zip -r ../$(PROJECTNAME).zip *
	ls -l ../$(PROJECTNAME).zip

.PHONY: clean all zip