-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
57 lines (44 loc) · 1.57 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
CC = gcc # version?
CXX = g++
CPPFLAGS = -std=c++17 -Wall -Wextra -Wconversion -Werror -fno-rtti -fno-exceptions -fdata-sections -ffunction-sections -g $(EXTRA_CPPFLAGS)
CLANG_FORMAT ?= clang-format
LLVM_CONFIG ?= llvm-config
LLVM_CONFIG_CXX_FLAGS = $(shell $(LLVM_CONFIG) --cxxflags)
LLVM_CONFIG_LD_FLAGS = $(shell $(LLVM_CONFIG) --ldflags)
LLVM_CONFIG_SYSTEM_LIBS = $(shell $(LLVM_CONFIG) --system-libs)
LLVM_CONFIG_LIBS = $(shell $(LLVM_CONFIG) --libs core)
UNAME = $(shell uname -s)
ifeq ($(UNAME),Linux)
PLATFORM_SPECIFIC_LDFLAGS = -Wl,--gc-sections
endif
ifeq ($(UNAME),Darwin)
PLATFORM_SPECIFIC_LDFLAGS = -Wl,dead_strip
endif
CPPFLAGS := $(LLVM_CONFIG_CXX_FLAGS) $(CPPFLAGS)
LDFLAGS := $(LLVM_CONFIG_LD_FLAGS) $(LLVM_CONFIG_SYSTEM_LIBS) $(LLVM_CONFIG_LIBS) $(LDFLAGS) $(PLATFORM_SPECIFIC_LDFLAGS)
# Add new source files here.
SRCS = lexer.cpp parser.cpp compiler.cpp
HDRS = xos.h
OBJS = $(SRCS:.cpp=.o)
EXE = main
TEST = test
.PHONY: all clean format format-checks
all: $(EXE)
$(EXE): $(OBJS) main.o
$(CXX) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)
%.o: %.cpp $(HDRS)
$(CXX) $(CPPFLAGS) -c $< -o $@
test.o: test.cpp $(HDRS)
$(CXX) $(CPPFLAGS) -c $< -o $@ -I$(GTEST_HDR)
# This is run with:
#
# $ make test GTEST_HDR=<path to include dir> GTEST_LIB=<path to lib dir>
#
$(TEST): test.o $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@ -lgtest_main -lgtest -L$(GTEST_LIB) $(LDFLAGS) -lpthread
clean:
rm -rf $(EXE) *.o $(TEST)
format:
$(CLANG_FORMAT) --style=google -i $(SRCS) main.cpp test.cpp $(HDRS)
format-check:
$(CLANG_FORMAT) --style=google $(SRCS) main.cpp test.cpp $(HDRS) --dry-run -Werror