forked from koenk/gbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (46 loc) · 1.29 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
# Binary and target CPU - add your source files here
BINNAME = gbit
BINSRC = main.c test_cpu.c
# Test framework (shared library)
LIBNAME = libgbit.so
LIBSRC = lib/tester.c lib/inputstate.c lib/ref_cpu.c lib/disassembler.c
# Build directory - stores intermediate object files
BDIR := build
CURDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
CFLAGS := -O2 -Wall -Wextra -g -MMD -I. -fPIC
CXXFLAGS := -O2 -Wall -Wextra -g -MMD -I. -fPIC
LDFLAGS := -Wl,-rpath="$(CURDIR)" -L. -lgbit
LIBOBJS := $(patsubst %.c,$(BDIR)/%.o,$(LIBSRC))
BINOBJS := $(patsubst %.c,$(BDIR)/%.o,$(patsubst %.cpp,$(BDIR)/%.o,$(BINSRC)))
# Verbosity control
ifndef V
LOG=@printf "\e[1;32m%s\e[0m $@\n"
MAKEFLAGS += --silent
else
LOG=@true
endif
.SUFFIXES: # Disable builtin rules
.PHONY: all run clean
all: $(LIBNAME) $(BINNAME)
run: $(BDIR)/$(BINNAME)
-$(BDIR)/$(BINNAME)
$(BDIR)/%.o: %.c | $(BDIR)
$(LOG) [CC]
$(CC) $(CFLAGS) -c -o $@ $<
$(BDIR)/%.o: %.cpp | $(BDIR)
$(LOG) [CXX]
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(LIBNAME): $(LIBOBJS) | $(BDIR)
$(LOG) [LINK]
$(CC) $^ -o $@ -shared
$(BINNAME): $(BINOBJS) | $(LIBNAME) $(BDIR)
$(LOG) [LINK]
$(CXX) $^ -o $@ $(LDFLAGS)
$(BDIR):
mkdir -p $@/lib
clean:
@$(RM) -rf $(BDIR)
@$(RM) -rf $(BINNAME)
@$(RM) -rf $(LIBNAME)
-include $(BDIR)/*.d
-include $(BDIR)/lib/*.d