-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (66 loc) · 2.09 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
override CPPFLAGS += --std=c++1z
override CPPFLAGS += -MMD -MP
override CPPFLAGS += $(shell cat .cxxflags | xargs)
override CPPFLAGS += -I./include -I./source
override LDFLAGS += $(shell cat .ldflags | xargs)
override LDFLAGS += -L./lib
override LDLIBS += $(shell cat .ldlibs | xargs)
override LDLIBS += -lSDL2main -lSDL2 -lpthread
PREFIX := $(DESTDIR)/usr/local
BINDIR := $(PREFIX)/bin
NAME := melno
SRCDIR := ./source
TEMPDIR := temp
DISTDIR := out
SOURCES := $(shell find -wholename "$(SRCDIR)/*.cpp")
HEADERS := $(shell find -wholename "$(SRCDIR)/*.hpp" && find -wholename "$(SRCDIR)/*.h")
OUT := $(DISTDIR)/$(NAME)
TARGET := $(OUT:$(DISTDIR)/%=$(BINDIR)/%)
OBJECTS := $(SOURCES:%.cpp=$(TEMPDIR)/%.o)
OBJDIRS := $(shell dirname $(OBJECTS))
LOCALIB := $(wildcard lib/*.a)
DEPENDS := $(OBJECTS:.o=.d)
INSTALL_SRCDIR := $(PREFIX)/source
INSTALL_SOURCES := $(SOURCES:$(SRCDIR)/%=$(INSTALL_SRCDIR)/%) $(HEADERS:$(SRCDIR)/%=$(INSTALL_SRCDIR)/%)
INSTALL_SRCDIRS := $(shell dirname $(INSTALL_SOURCES))
build: $(OUT)
$(OUT): $(OBJECTS) $(LOCALIB) | $(DISTDIR)
$(CXX) $(LDFLAGS) $(OBJECTS) $(LOCALIB) $(LDLIBS) -o $@
$(TEMPDIR)/%.o: %.cpp | $(TEMPDIR)
@mkdir -p $(@D)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
$(TEMPDIR):
@mkdir -p $@
$(DISTDIR):
@mkdir -p $@
clean:
@rm $(DEPENDS) 2> /dev/null || true
@rm $(OBJECTS) 2> /dev/null || true
@rmdir -p $(OBJDIRS) 2> /dev/null || true
@rmdir -p $(TEMPDIR) 2> /dev/null || true
@echo Temporaries cleaned!
distclean: clean
@rm $(OUT) 2> /dev/null || true
@rmdir -p $(DISTDIR) 2> /dev/null || true
@echo All clean!
install: $(TARGET)
$(BINDIR)/%: $(DISTDIR)/% | $(BINDIR)
install --strip $< $@
$(BINDIR):
@mkdir $@
uninstall:
-rm $(TARGET)
@rmdir -p $(BINDIR) 2> /dev/null || true
@echo Uninstall complete!
install_source: $(INSTALL_SOURCES)
$(INSTALL_SRCDIR)/%: $(SRCDIR)/% ./COPYRIGHT
@mkdir -p $(@D)
cat ./COPYRIGHT > $@
cat $< >> $@
uninstall_source:
-rm $(INSTALL_SOURCES)
@rmdir -p $(INSTALL_SRCDIRS) 2> /dev/null || true
@echo Source code uninstalled!
-include $(DEPENDS)
.PRECIOUS : $(OBJECTS)
.PHONY : clean distclean uninstall uninstall_source