-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
executable file
·109 lines (86 loc) · 3.12 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
CC := gcc
CXX := g++
UNAME := $(shell uname -s)
OPTIMIZATION := -O3 -fPIC -DNDEBUG
WARNINGS := -Wall -Wunreachable-code -Wfloat-equal -Wredundant-decls -Winit-self -Wpedantic
CFLAGS := $(WARNINGS) $(OPTIMIZATION) -std=c99
CXXFLAGS := $(WARNINGS) $(OPTIMIZATION) -std=c++11
LDFLAGS := -shared -fPIC
OBJDIR := build
ifeq ($(UNAME),Darwin)
LIB_EXT :=.dylib
else
LIB_EXT :=.so
endif
CPPSOURCES := $(wildcard bad-mutex/*.cpp)
CSOURCES := $(wildcard bad-mutex/*.c)
BM_OBJECTS := $(addprefix $(OBJDIR)/, $(CPPSOURCES:.cpp=.o) $(CSOURCES:.c=.o))
BadMutex := $(OBJDIR)/libBadMutex$(LIB_EXT)
BadMutexLua := $(OBJDIR)/BadMutex.lua
CPPSOURCES := $(wildcard download-manager/*.cpp)
CSOURCES := $(wildcard download-manager/*.c)
DM_OBJECTS := $(addprefix $(OBJDIR)/, $(CPPSOURCES:.cpp=.o) $(CSOURCES:.c=.o))
DownloadManager := $(OBJDIR)/libDownloadManager$(LIB_EXT)
DownloadManagerLua := $(OBJDIR)/DownloadManager.lua
CPPSOURCES := $(wildcard precise-timer/*.cpp)
CSOURCES := $(wildcard precise-timer/*.c)
PT_OBJECTS := $(addprefix $(OBJDIR)/, $(CPPSOURCES:.cpp=.o) $(CSOURCES:.c=.o))
PreciseTimer := $(OBJDIR)/libPreciseTimer$(LIB_EXT)
PreciseTimerLua := $(OBJDIR)/PreciseTimer.lua
RequireFFILua := $(OBJDIR)/requireffi.lua
.PHONY: all debug BadMutex DownloadManager PreciseTimer lua clean
all: BadMutex DownloadManager PreciseTimer
debug: CFLAGS += -g -O1 -UNDEBUG
debug: CXXFLAGS += -g -O1 -UNDEBUG
debug: LDFLAGS += -g
debug: all
BadMutex: $(BadMutex)
DownloadManager: $(DownloadManager)
PreciseTimer: $(PreciseTimer)
$(BM_OBJECTS): | $(OBJDIR)/bad-mutex/
$(DM_OBJECTS): | $(OBJDIR)/download-manager/
$(PT_OBJECTS): | $(OBJDIR)/precise-timer/
$(BadMutex): $(BM_OBJECTS)
@printf "\e[1;32m LINK\e[m $@\n"
@$(CXX) $^ $(LDFLAGS) -o $@
$(DownloadManager): LDFLAGS += -lcurl
ifeq ($(UNAME),Darwin)
$(DownloadManager): LDFLAGS += -framework CoreFoundation -framework SystemConfiguration
else
# std::thread won't work without explicitly linking pthreads on linux.
$(DownloadManager): LDFLAGS += -pthread
endif
$(DownloadManager): $(DM_OBJECTS)
@printf "\e[1;32m LINK\e[m $@\n"
@$(CXX) $(LDFLAGS) -o $@ $^ -lcurl
$(PreciseTimer): $(PT_OBJECTS)
@printf "\e[1;32m LINK\e[m $@\n"
@$(CXX) $(LDFLAGS) -o $@ $^
$(OBJDIR)/%.o: %.c
@printf "\e[1;34m CC\e[m $<\n"
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: %.cpp
@printf "\e[1;34m CXX\e[m $<\n"
@$(CXX) $(CXXFLAGS) -c $< -o $@
$(OBJDIR):
@printf "\e[1;33mMKDIR\e[m $@\n"
@mkdir -p $@
$(OBJDIR)/%/: | $(OBJDIR)
@printf "\e[1;33mMKDIR\e[m $@\n"
@mkdir -p $@
$(BadMutexLua): bad-mutex/BadMutex.moon | $(OBJDIR)
@printf "\e[1;35mMOONC\e[m $@\n"
$(shell ./BuildLua.sh $< $@)
$(DownloadManagerLua): download-manager/DownloadManager.moon | $(OBJDIR)
@printf "\e[1;35mMOONC\e[m $@\n"
$(shell ./BuildLua.sh $< $@)
$(PreciseTimerLua): precise-timer/PreciseTimer.moon | $(OBJDIR)
@printf "\e[1;35mMOONC\e[m $@\n"
$(shell ./BuildLua.sh $< $@)
$(RequireFFILua): | $(OBJDIR)
@printf "\e[1;35mMOONC\e[m $@\n"
$(shell moonc -o $@ requireffi/requireffi.moon 2> /dev/null)
lua: $(BadMutexLua) $(DownloadManagerLua) $(PreciseTimerLua) $(RequireFFILua)
clean:
@printf "\e[1;31m RM\e[m $(OBJDIR)\n"
@rm -rf $(OBJDIR)