forked from sorindumitru/lkl-net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·169 lines (114 loc) · 2.89 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
CC=gcc
FLEX=flex
CFLAGS=-g -Wall -Ilklinclude -Iinclude
LDLIBS=-pthread -lreadline
# Environment {
HERE=$(PWD)
LINUX=$(HERE)/../linux-2.6
MKDIR=mkdir -p
# }
APR_CONF=$(shell apr-config --includes --cppflags)
EXTRA_FLAGS=-gstabs+
all: conf_test bridge hub test
# Include LKL {
lklinclude/asm:
-$(MKDIR) `dirname $@`
ln -s $(LINUX)/arch/lkl/include/asm lklinclude/asm
lklinclude/x86:
-$(MKDIR) `dirname $@`
ln -s $(LINUX)/arch/x86 lklinclude/x86
lklinclude/asm-generic:
-$(MKDIR) `dirname $@`
ln -s $(LINUX)/include/asm-generic lklinclude/asm-generic
lklinclude/linux:
-$(MKDIR) `dirname $@`
ln -s $(LINUX)/include/linux lklinclude/linux
INC=lklinclude/asm lklinclude/asm-generic lklinclude/x86 lklinclude/linux
# }
# LKL {
$(CROSS)lkl/.config: .config
mkdir -p lkl && \
cp $< $@
$(CROSS)lkl/lkl.a: lkl/.config
cd $(LINUX) && \
$(MAKE) O=$(HERE)/$(CROSS)lkl ARCH=lkl \
CROSS_COMPILE=$(CROSS) LKLENV_CFLAGS="$(APR_CONF)" \
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
lkl.a
# }
# Conf {
CONF_DIR=conf
CONF_SRC=$(CONF_DIR)/config.c $(CONF_DIR)/parser.c
CONF_OBJ=$(patsubst %c,%o,$(CONF_SRC))
.PHONY: conf_test
conf_test: bin/conf_test
bin/conf_test: $(CONF_OBJ)
$(CC) $(CFLAGS) $(CONF_OBJ) conf_test.c -o bin/conf_test
# }
# Flex parser {
conf/parser.c: conf/parser.l
$(FLEX) --outfile=$@ $<
conf/parser.o: conf/parser.c
$(CC) $(CFLAGS) -c -o $@ $<
PARSER=conf/parser.o
# }
# Bridge {
BRIDGE_DIR=bridge
BRIDGE_SRC=$(BRIDGE_DIR)/bridge.c packet.c
BRIDGE_OBJ=$(patsubst %c,%o,$(BRIDGE_SRC))
.PHONY: bridge
bridge: bin/bridge
bin/bridge: $(CONF_OBJ) $(BRIDGE_OBJ)
$(CC) $(CFLAGS) $(CONF_OBJ) $(BRIDGE_OBJ) -o bin/bridge
# }
# Switch {
SWITCH_DIR=switch
SWITCH_SRC=$(SWITCH_DIR)/switch.c interface.c topology.c console.c $(SWITCH_DIR)/switch_cmd.c
SWITCH_OBJ=$(patsubst %c,%o,$(SWITCH_SRC))
.PHONY: switch
switch: bin/switch
bin/switch: $(INC) $(CONF_OBJ) $(SWITCH_OBJ) $(CROSS)lkl/lkl.a
$(CC) $(CFLAGS) $(CONF_OBJ) $(SWITCH_OBJ) -o bin/switch lkl/lkl.a $(LDLIBS)
# }
# Router {
ROUTER_DIR=router
ROUTER_SRC=$(ROUTER_DIR)/router.c interface.c console.c switch/switch_cmd.c #topology.c
ROUTER_OBJ=$(patsubst %c,%o,$(ROUTER_SRC))
.PHONY: router
router: bin/router
bin/router: $(INC) $(CONF_OBJ) $(ROUTER_OBJ) $(CROSS)lkl/lkl.a
$(CC) $(CFLAGS) $(CONF_OBJ) $(ROUTER_OBJ) -o bin/router lkl/lkl.a $(LDLIBS)
# }
# Test {
TEST_DIR=apps;
TEST_SRC=$(TEST_DIR)/test.c
TEST_OBJ=$(patsubst %c,%o,$(TEST_SRC))
.PHONY: test
test: bin/test
bin/test: apps/test.c $(INC) $(CROSS)lkl/lkl.a
$(CC) $(CFLAGS) -o bin/test apps/test.c lkl/lkl.a -lpthread
# }
# Hub {
HUB_DIR=hub
HUB_SRC=$(HUB_DIR)/hub.c
HUB_OBJ=$(patsubst %c,%o,$(HUB_SRC))
.PHONY: hub
hub: bin/hub
bin/hub: $(HUB_OBJ)
$(CC) $(CFLAGS) $< -o $@
# }
# Clean up {
.PHONY: clean
clean:
-rm *.o
-rm conf/parser.c
-rm bin/conf_test
-rm bridge/*.o
-rm apps/*.o
-rm conf/*.o
-rm bin/bridge
-rm bin/switch
-rm bin/hub
clean-all: clean
-rm -rf lkl
# }