-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (123 loc) · 3.32 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
# BSD Makefile
# On GNU systems, use bmake.
.MAIN: .PHONY all
.ERROR: .PHONY
@echo
@echo 'Build failed.'
@echo 'Check Makefile.options and/or set appropriate'
@echo 'environment variables or command line options.'
.ifndef PLATFORM
PLATFORM != uname
.endif
.if $(PLATFORM) == "FreeBSD"
# Default configuration for FreeBSD
LUA_INCDIR ?= /usr/local/include/lua54
#LUA_LIBDIR ?= /usr/local/lib
LUA_LIBNAME ?= lua-5.4
LUA_CMD ?= lua54
PGSQL_INCDIR ?= /usr/local/include
PGSQL_LIBDIR ?= /usr/local/lib
KQUEUE_LIBNAME ?=
.elif $(PLATFORM) == "Linux"
# Distinguish between different Linux distributions
.ifndef DISTRIBUTION
DISTRIBUTION != lsb_release -i -s
.endif
.if $(DISTRIBUTION) == "Debian" || $(DISTRIBUTION) == "Raspbian"
# Default configuration for Debian
LUA_INCDIR ?= /usr/include/lua5.4
#LUA_LIBDIR ?= /usr/lib
LUA_LIBNAME ?= lua5.4
LUA_CMD ?= lua5.4
KQUEUE_LIBNAME ?= kqueue
.elif $(DISTRIBUTION) == "Ubuntu"
# Default configuration for Ubuntu
LUA_INCDIR ?= /usr/include/lua5.4
#LUA_LIBDIR ?= /usr/lib/x86_64-linux-gnu
LUA_LIBNAME ?= lua5.4
LUA_CMD ?= lua5.4
PGSQL_INCDIR ?= /usr/include/postgresql
PGSQL_LIBDIR ?= /usr/lib/x86_64-linux-gnu
KQUEUE_INCDIR ?= /usr/include/kqueue
KQUEUE_LIBNAME ?= kqueue
.else
.warning Could not determine Linux distribution.
.endif
.else
.warning Could not determine Platform.
.endif
# Default configuration (uses libkqueue by default)
LUA_INCDIR ?=
#LUA_LIBDIR ?=
LUA_LIBNAME ?= lua
LUA_CMD ?= lua
PGSQL_INCDIR ?=
PGSQL_LIBDIR ?=
PGSQL_LIBNAME ?= pq
KQUEUE_INCDIR ?=
KQUEUE_LIBDIR ?=
KQUEUE_LIBNAME ?= kqueue
CC ?= cc
CC_LINK_LIB_ARGS ?= -shared -Wall
CC_COMPILE_OBJ_ARGS ?= -c -Wall -O2 -fPIC
.include "Makefile.options"
# Name of Lua command, e.g. lua:
LUA_FILES != cd src && ls *.lua
.export LUA_CMD
all: .PHONY \
$(LUA_FILES:%=target/neumond/%) \
target/neumond/lkq.so \
target/neumond/nbio.so \
target/neumond/pgeff.so
@echo
@echo "# Build complete. See target/neumond directory."
@echo "# Several examples are found in the examples/ directory."
@echo
.for LUA_FILE in $(LUA_FILES)
target/neumond/$(LUA_FILE): src/$(LUA_FILE)
mkdir -p target/neumond
cp src/$(LUA_FILE) target/neumond/$(LUA_FILE)
.endfor
target/neumond/lkq.so: target/_obj/lkq.o
mkdir -p target/neumond
$(CC) $(CC_LINK_LIB_ARGS) \
-o target/neumond/lkq.so \
target/_obj/lkq.o \
$(KQUEUE_LIBDIR:%=-L%) $(KQUEUE_LIBNAME:%=-l%)
target/_obj/lkq.o: src/lkq.c
mkdir -p target/_obj
$(CC) $(CC_COMPILE_OBJ_ARGS) \
-o target/_obj/lkq.o \
$(LUA_INCDIR:%=-I%) \
$(KQUEUE_INCDIR:%=-I%) \
src/lkq.c
target/neumond/nbio.so: target/_obj/nbio.o
mkdir -p target/neumond
$(CC) $(CC_LINK_LIB_ARGS) \
-o target/neumond/nbio.so \
target/_obj/nbio.o
target/_obj/nbio.o: src/nbio.c
mkdir -p target/_obj
$(CC) $(CC_COMPILE_OBJ_ARGS) \
-o target/_obj/nbio.o \
$(LUA_INCDIR:%=-I%) \
src/nbio.c
target/neumond/pgeff.so: target/_obj/pgeff.o
mkdir -p target/neumond
$(CC) $(CC_LINK_LIB_ARGS) \
-o target/neumond/pgeff.so \
target/_obj/pgeff.o \
$(PGSQL_LIBDIR:%=-L%) $(PGSQL_LIBNAME:%=-l%)
target/_obj/pgeff.o: src/pgeff.c
mkdir -p target/_obj
$(CC) $(CC_COMPILE_OBJ_ARGS) \
-o target/_obj/pgeff.o \
$(LUA_INCDIR:%=-I%) \
$(PGSQL_INCDIR:%=-I%) \
src/pgeff.c
test: .PHONY all
cd testing && ./run-tests.sh tests/*.lua
test-pgsql: .PHONY all
cd testing && ./run-tests.sh tests-pgsql/*.lua
clean: .PHONY
rm -Rf target/