forked from RedoXyde/mtl_linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
116 lines (81 loc) · 2.28 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# The name of the target file
SIMU_TARGET = mtl_simu
COMP_TARGET = mtl_compiler
VCOMP_TARGET = libvcomp.a
# OS
OS = linux
# User options
OPTIONS = -DVSIMU
# C Files to compile (take all)
SIMU_C_FILES = $(wildcard src/vm/*.c)
SIMU_C_FILES += $(wildcard src/simu/*.c)
SIMU_C_FILES += $(wildcard src/simu/$(OS)/*.c)
SIMU_CPP_FILES = $(wildcard src/vm/*.cpp)
SIMU_CPP_FILES += $(wildcard src/simu/*.cpp)
SIMU_CPP_FILES += $(wildcard src/simu/$(OS)/*.cpp)
COMP_C_FILES = $(wildcard src/comp/*.c)
COMP_CPP_FILES = $(wildcard src/comp/*.cpp)
VCOMP_C_FILES = $(wildcard src/vcomp/*.c)
VCOMP_CPP_FILES = $(wildcard src/vcomp/*.cpp)
# Compiler options
CFLAGS += -O0 -m32
CFLAGS += -g
CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wpointer-arith
#CFLAGS += -fdata-sections -ffunction-sections
CFLAGS += -fexceptions -fno-delete-null-pointer-checks
#CFLAGS += -MMD
CFLAGS += $(OPTIONS)
CFLAGS += -I./inc/ -I./inc/vm
CFLAGS += -I./inc/vcomp
CFLAGS += -I./inc/comp
CFLAGS += -I./inc/simu/$(OS)
CPP_FLAGS = $(CFLAGS)
# Linker options
LDFLAGS = -m32
# LDFLAGS += -Wl,--gc-sections
# LDFLAGS += -Wl,-s
SIMU_LDFLAGS = $(LDFLAGS)
COMP_LDFLAGS = $(LDFLAGS)
VCOMP_LDFLAGS = $(LDFLAGS)
# Additional libraries
LIBS = $(VCOMP_TARGET) -lm
# Compiler toolchain
CC = gcc
CPP = g++
FLEX = flex
OBJCOPY = objcopy
SIZE = size
NM = nm
DUMP = objdump
DEBUG = gdb
SIMU_OBJS = $(SIMU_CPP_FILES:%.cpp=obj/%.o)
SIMU_OBJS += $(SIMU_C_FILES:%.c=obj/%.o)
COMP_OBJS = $(COMP_CPP_FILES:%.cpp=obj/%.o)
COMP_OBJS += $(COMP_C_FILES:%.c=obj/%.o)
VCOMP_OBJS = $(VCOMP_CPP_FILES:%.cpp=obj/%.o)
VCOMP_OBJS += $(VCOMP_C_FILES:%.c=obj/%.o)
all: vcomp comp simu
vcomp: $(VCOMP_TARGET)
comp: vcomp $(COMP_TARGET)
simu: vcomp $(SIMU_TARGET)
obj/%.o : %.cpp
@test -d $(@D) || mkdir -pm 775 $(@D)
$(CPP) -c $(CPP_FLAGS) $< -o $@
obj/%.o : %.c
@test -d $(@D) || mkdir -pm 775 $(@D)
$(CC) -c $(CFLAGS) $< -o $@
$(SIMU_TARGET): $(SIMU_OBJS)
$(CPP) -lresolv $(LDFLAGS) -o $@ $^ $(LIBS)
$(COMP_TARGET): $(COMP_OBJS)
$(CPP) $(LDFLAGS) -o $@ $^ $(LIBS)
$(VCOMP_TARGET): $(VCOMP_OBJS)
$(AR) rcs $@ $^
# ranlib $@
clean:
@rm -f $(VCOMP_TARGET) $(COMP_TARGET) $(SIMU_TARGET)
@rm -Rf obj/
debug: $(TARGET)
$(DEBUG) $< < gdb_load
style:
astyle --style=bsd -s4 --indent-preprocessor --add-brackets --recursive *.h *.c*
.PHONY: clean debug elf style