-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
76 lines (57 loc) · 2.59 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
define \n
endef
CC=clang
LD=ld
FRAMEWORKS:= -framework Foundation
LIBRARIES:= -lobjc
CFLAGS=-Wall -Werror -g -D MUD_AUTO_INIT -Ideps/uthash/
LDFLAGS=$(LIBRARIES) $(FRAMEWORKS)
BINDIR = build
TMP_DIR = tmp
MUD_CORE_DIR = src
MUD_CORE_INCLUDE = -include $(MUD_CORE_DIR)/mud.h
MUD_CORE_SRCS = $(wildcard $(MUD_CORE_DIR)/*.c)
MUD_CORE_OBJS = $(MUD_CORE_SRCS:$(MUD_CORE_DIR)/%.c=mud/%.o)
MUD_CORE_OPERATORS_DIR = operators
MUD_CORE_OPERATORS_SRCS = $(wildcard $(MUD_CORE_OPERATORS_DIR)/*.c)
BRIDGES_DIR = bridges
NS_BRIDGE_INCLUDE = -include bridges/ns/bridge.h
NS_BRIDGE_OPERATORS_DIR = bridges/ns/operators
NS_BRIDGE_OPERATORS_SRCS = $(wildcard $(NS_BRIDGE_OPERATORS_DIR)/*.m)
TEST_DIR = tests
TEST_SRCS = $(wildcard $(TEST_DIR)/*.m)
TEST_EXEC = $(TEST_SRCS:$(TEST_DIR)/%.m=$(TEST_DIR)/%)
make_dir:
mkdir -p $(BINDIR)
mkdir -p $(BINDIR)/operators
mkdir -p $(TMP_DIR)
clean:
rm -Rf $(BINDIR)
rm -Rf $(TMP_DIR)
make make_dir
mud_core: $(MUD_CORE_OBJS)
$(LD) -r $(MUD_CORE_OBJS:%.o=$(BINDIR)/%.o) -o $(BINDIR)/mud.o
$(MUD_CORE_OBJS):
@mkdir -p $(BINDIR)/$(@D)
$(CC) $(CFLAGS) $(MUD_CORE_INCLUDE) -c $(@:mud/%.o=$(MUD_CORE_DIR)/%.c) -o $(BINDIR)/$@
ns_bridge: make_dir
$(CC) $(CFLAGS) $(MUD_CORE_INCLUDE) $(NS_BRIDGE_INCLUDE) $(NS_BRIDGE_DEFINES) -c $(BRIDGES_DIR)/ns/bridge.m -o $(BINDIR)/ns_bridge.o
ns_operators: make_dir
./scripts/prepare_operators.rb -a $(MUD_CORE_OPERATORS_DIR) -a $(NS_BRIDGE_OPERATORS_DIR) -o $(TMP_DIR)
@rm -rf $(BINDIR)/operators
@mkdir -p $(BINDIR)/operators
$(CC) $(CFLAGS) $(MUD_CORE_INCLUDE) $(NS_BRIDGE_INCLUDE) -include $(TMP_DIR)/_operators.h -c $(TMP_DIR)/_operators.c -o $(BINDIR)/operators/_operators.o
$(foreach operator, $(MUD_CORE_OPERATORS_SRCS) $(NS_BRIDGE_OPERATORS_SRCS), \
@mkdir -p $(dir $(BINDIR)/operators/$(notdir $(basename $(operator)))) $(\n) \
$(CC) $(CFLAGS) $(MUD_CORE_INCLUDE) $(NS_BRIDGE_INCLUDE) -include $(TMP_DIR)/_operators.h -c $(operator) -o $(BINDIR)/operators/$(notdir $(basename $(operator))).o $(\n) \
)
$(LD) -r \
$(foreach operator, $(MUD_CORE_OPERATORS_SRCS) $(NS_BRIDGE_OPERATORS_SRCS), $(BINDIR)/operators/$(notdir $(basename $(operator))).o) \
$(BINDIR)/operators/_operators.o -o $(BINDIR)/ns_operators.o
$(TEST_EXEC): mud_core ns_bridge ns_operators
@mkdir -p $(BINDIR)/tests
$(CC) $(CFLAGS) $(LDFLAGS) $(MUD_CORE_INCLUDE) $(NS_BRIDGE_INCLUDE) -include $(TMP_DIR)/_operators.h \
$(BINDIR)/mud.o $(BINDIR)/ns_bridge.o $(BINDIR)/ns_operators.o \
$(TEST_DIR)/support.m $(@:$(TEST_DIR)/%=$(TEST_DIR)/%.m) \
-o $(BINDIR)/$@
./$(BINDIR)/$@