-
Notifications
You must be signed in to change notification settings - Fork 5
/
Stirfile
89 lines (78 loc) · 3.46 KB
/
Stirfile
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
@toplevel
@strict
@fileinclude @ignore "opts.smk"
# You can modify these for compilation
$WITH_WERROR ?= @false
$CC ?= "cc"
$CFLAGS ?= ["-g", "-O2", "-Wall", "-Wextra", "-Wsign-conversion", "-Wno-missing-field-initializers", "-Wno-unused-parameter", "-Wshadow", "-Wstrict-prototypes", "-Wmissing-prototypes", "-Wpointer-arith", "-std=gnu11", "-fPIC"]
$WITH_NETMAP ?= @false
$NETMAP_INCDIR ?= ""
$WITH_ODP ?= @false
$ODP_DIR ?= "/usr/local"
$WITH_DPDK ?= @false
$WITH_LUA ?= @false
$DPDK_INCDIR ?= ""
$DPDK_LIBDIR ?= ""
$LIBS_ODPDEP ?= ["/usr/lib/x86_64-linux-gnu/libssl.a", "/usr/lib/x86_64-linux-gnu/libcrypto.a"]
$LDFLAGS ?= []
@if($WITH_WERROR)
$CFLAGS = [@$CFLAGS, "-Werror"]
@endif
# You can modify these during development
$MODS = ["tcpreass", "dynarr", "misc", "hashlist", "hashtable", "rbtree", "avltree", "timerrb", "timeravl", "linkedlist", "timerlinkheap", "timerskiplist", "timerwheel", "log", "iphdr", "ipfrag", "packet", "arp", "ports", "queue", "alloc", "random", "databuf", "tuntap", "portlist", "netmap", "iphash", "mypcap", "ldp", "libpptk"]
# You probably don't want to modify anything below this line
@function $LIST_TO_DICTS_SIMPLE($list, $param)
@locvar $i=0
@locvar $dicts=[]
@for($i=0,$i<$list[],$i=$i+1)
@append($dicts, {$param: $list[$i]})
@endfor
@return $dicts
@endfunction
@function $MODULE($lib, $src_lib, $src_prog, $libs, $unitdeps, $unitcmds)
@locvar $src = [@$src_lib, @$src_prog]
@locvar $obj_lib = @sufsuball($src_lib, ".c", ".o")
@locvar $obj_prog = @sufsuball($src_prog, ".c", ".o")
@locvar $obj = @sufsuball($src, ".c", ".o")
@locvar $dep = @sufsuball($src, ".c", ".d")
@locvar $prog = @sufsuball($src_prog, ".c", "")
@locvar $alldeps = [@$prog, $lib]
@locvar $i = 0
@addrule({"tgts": [{"name": "all"}], "attrs": {"phony": @true}, \
"deps": @L$LIST_TO_DICTS_SIMPLE($alldeps, "name")})
@addrule({"tgts": [{"name": "unit"}], "attrs": {"phony": @true}, \
"deps": @L$LIST_TO_DICTS_SIMPLE($unitdeps, "name"), \
"shells": [{"embed": @true, "cmds": $unitcmds}]})
@for($i=0,$i<$obj[],$i=$i+1)
@addrule({"tgts": [{"name": $obj[$i]}], \
"deps": [{"name": $src[$i]}, {"name": $dep[$i]}], \
"shells": [{"cmd": [ \
@D$(CC), @@D$(CFLAGS), "-c", "-o", $obj[$i], \
$src[$i]]}]})
@addrule({"tgts": [{"name": $dep[$i]}], \
"deps": [{"name": $src[$i]}], \
"shells": [{"cmd": [ \
@D$(CC), @@D$(CFLAGS), "-M", "-o", $dep[$i], \
$src[$i]]}]})
@endfor
@for($i=0,$i<$prog[],$i=$i+1)
@addrule({"tgts": [{"name": $prog[$i]}], \
"deps": [{"name": $obj_prog[$i]}, \
{"name": $lib}, \
@@L$LIST_TO_DICTS_SIMPLE($libs, "name")], \
"shells": [{"cmd": [ \
@D$(CC), @@D$(CFLAGS), "-o", $prog[$i], \
$obj_prog[$i], $lib, @$libs, @@D$(LDFLAGS), \
"-lpthread", "-ldl"]}]})
@endfor
@addrule({"tgts": [{"name": $lib}], \
"deps": @L$LIST_TO_DICTS_SIMPLE($obj_lib, "name"), \
"shells": [{"embed": @true, "cmds": [ \
["rm", "-f", $lib], \
["ar", "rvs", $lib, @$obj_lib]]}]})
@endfunction
$MODS_ALL = @sufsuball($MODS, "", "/all")
$MODS_UNIT = @sufsuball($MODS, "", "/unit")
@phonyrule: 'all': $MODS_ALL
@phonyrule: 'unit': $MODS_UNIT
@dirinclude $MODS