-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmako.mk
144 lines (117 loc) · 3.75 KB
/
mako.mk
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
# Makefile for compiling the Mako Server for Linux
# Example: make -f mako.mk EPOLL=true
# The above compiles mako using the 'epoll' socket dispatcher. The
# default is to use the 'select' socket dispatcher.
# The makefile is designed for the "Embedded Linux Web Based Device
# Management" tutorial and will auto include the generated Lua
# bindings if found. The makefile will also auto include SQLite, Lua
# Protobuf, CBOR, and LPeg if found. LPeg can be installed as follows:
# wget http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.2.tar.gz
# cd src
# tar xvzf ../lpeg-1.0.2.tar.gz
# mv lpeg-1.0.2 lpeg
ifdef CROSS_COMPILE
CC = $(CROSS_COMPILE)gcc
endif
#Required
ifeq (,$(wildcard ../BAS-Resources/build/mako.sh))
$(error ../BAS-Resources not found. Repository https://github.com/RealTimeLogic/BAS-Resources required!)
endif
#Optional
export LPEGDIR=../LPeg
export PROTOBUFDIR=../lua-protobuf
export CBORDIR=../CBOR
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
XLIB=-ldl -framework IOKit -framework CoreFoundation;
CFLAGS += -D_OSX_ -DLUA_USE_MACOSX
endif
CFLAGS += -fmerge-all-constants -O3 -Os -Wall
# Add required macros and enable large-file support
CFLAGS += -DMAKO -DUSE_EMBEDDED_ZIP=0 -DLUA_USE_LINUX -DBA_FILESIZE64
# Add features
CFLAGS += -DUSE_LUAINTF=1
CFLAGS += -DUSE_DBGMON=1
CFLAGS += -DUSE_OPCUA=1
CFLAGS += -Iinc -Iinc/arch/Posix
ifdef EPOLL
SODISP = epoll
CFLAGS += -Iinc/arch/NET/epoll
else
SODISP = generic
CFLAGS += -Iinc/arch/NET/Posix
endif
VPATH = src:src/arch/Posix:src/arch/NET/$(SODISP):src/DiskIo/posix:examples/MakoServer/src
# Implicit rules for making .o files from .c files
%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<
SOURCE = BAS.c ThreadLib.c SoDisp.c BaFile.c MakoMain.c
#Do we have SQLite?
ifneq (,$(wildcard src/sqlite3.c))
$(info Including SQLite)
SOURCE += ls_sqlite3.c luasql.c sqlite3.c
else
$(info Excluding SQLite)
CFLAGS += -DUSE_SQL=0
endif
#Do we have LPEG?
#git clone https://github.com/roberto-ieru/LPeg.git
ifneq (,$(wildcard $(LPEGDIR)/lpcode.c))
$(info Including LPEG)
CFLAGS += -DUSE_LPEG=1
SOURCE += $(notdir $(wildcard $(LPEGDIR)/*.c))
VPATH := $(VPATH):$(LPEGDIR)
else
$(info Excluding LPEG)
endif
#Do we have Lua Protobuf?
#https://github.com/starwing/lua-protobuf
ifneq (,$(wildcard $(PROTOBUFDIR)/pb.c))
$(info Including Lua Protobuf)
CFLAGS += -DUSE_PROTOBUF=1
SOURCE += pb.c
VPATH := $(VPATH):$(PROTOBUFDIR)
else
$(info Excluding Lua Protobuf)
endif
#Do we have CBOR?
#https://github.com/spc476/CBOR
ifneq (,$(wildcard $(CBORDIR)/cbor_c.c))
$(info Including CBOR)
CFLAGS += -DUSE_CBOR=1
SOURCE += cbor_c.c dnf.c
VPATH := $(VPATH):$(CBORDIR)
else
$(info Excluding Lua CBOR)
endif
ifneq (,$(wildcard MyCustomBindings.c))
$(info including the Lua MyCustomBindings example)
VPATH += .
SOURCE += MyCustomBindings.c MyCustomBindings_wrap.c
CFLAGS += -DmyCustomBindings=luaopen_cpu
else
$(info Excluding Lua MyCustomBindings example)
endif
ENCRYPTION_KEY_HEADER = examples/MakoServer/src/NewEncryptionKey.h
PYTHON := $(shell command -v python3 2>/dev/null)
ifneq ($(PYTHON),)
CFLAGS += -DNewEncryptionKey
endif
OBJS = $(SOURCE:%.c=%.o)
mako: $(ENCRYPTION_KEY_HEADER) $(OBJS) mako.zip
$(CC) -o mako $(OBJS) -lpthread -lm -ldl $(XLIB)
# Must be in the same directory as the mako executable
mako.zip:
cd ../BAS-Resources/build&&./mako.sh
cp ../BAS-Resources/build/mako.zip .
MyCustomBindings_wrap.c : MyCustomBindings.i
swig -lua MyCustomBindings.i
clean:
rm -f mako *.o
$(ENCRYPTION_KEY_HEADER):
ifneq ($(PYTHON),)
@echo "Generating $(ENCRYPTION_KEY_HEADER)..."
@python3 examples/MakoServer/GenNewEncryptionKey.py
else
$(warning "Python3 is not installed. NewEncryptionKey.h not generated")
endif