-
Notifications
You must be signed in to change notification settings - Fork 2
/
remake.sh
332 lines (271 loc) · 8.08 KB
/
remake.sh
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
# this script is used
# - enable / disable the build of particular modules
# - to create/update Makefiles
# ==================
# Configuration Area
# ==================
# Uncomment lines of stuffs to be enabled
# Lua callbacks and plugs-in
BUILD_LUA=1
if [ ${BUILD_LUA+x} ]; then
# Repetitive task
BUILD_EVERY=1
fi
# UPS / NUT server
BUILD_UPS=1
# Write to flat files
BUILD_OUTFILE=1
# Write to flat files
BUILD_ONOFF=1
# Dead Publisher Dectector
BUILD_DPD=1
# SHT31 local probe
BUILD_SHT31=1
# 1 wire probes handling
BUILD_1WIRE=1
# Alerting
BUILD_ALERT=1
# File system notification
BUILD_INOTIFY=1
# Meteo forcast using OpenWeatherMap
BUILD_METEOOWM=1
# Freebox v4/v5 figures
# BUILD_FREEBOXV5=1
# FreeboxOS figures
# BUILD_FREEBOXOS=1
# RFXcom handling
BUIlD_RFXTRX=1
# Example plugin
# This one is strictly NO-USE. Its only purpose is to demonstrate how to build a plugin
BUILD_DUMMY=1
###
# Development related
###
# Enable debugging messages
#DEBUG=1
# MCHECK - check memory concistency (see glibc's mcheck())
#MCHECK=1
# Where to generate ".so" plugins
# ---
# production's target directory
PLUGIN_DIR=/usr/local/lib/Marcel
# During development, being clean and keep everything in our own directory
#PLUGIN_DIR=$( pwd )
# -------------------------------------
# END OF CONFIGURATION AREA
# DON'T MODIFY ANYTHING AFTER THIS LINE
# DON'T MODIFY ANYTHING AFTER THIS LINE
# DON'T MODIFY ANYTHING AFTER THIS LINE
# DON'T MODIFY ANYTHING AFTER THIS LINE
# -------------------------------------
# Error is fatal
set -e
# =============================
# Configure external components
# =============================
echo -e "\nSet build options\n=================\n"
CFLAGS="-Wall -O2 -fPIC"
RDIR=$( pwd )
if [ ${BUILD_LUA+x} ]; then
# Hardcode test Lua version
# Development purpose only or if pkg-config doesn't work
#
# LUA_DIR=/home/laurent/Projets/lua-5.3.4/install
# LUA="-isystem $LUA_DIR/include"
# LUALIB="-L$LUA_DIR/lib"
#
# If used, uncomment the lines above and comment out system's Lua
# detection bellow.
# Find out system's installed Lua
VERLUA=$( lua -v 2>&1 | grep -o -E '[0-9]\.[0-9]' )
echo -n "Lua's version :" $VERLUA
if pkg-config --cflags lua$VERLUA > /dev/null 2>&1; then
echo " (Packaged)"
LUA="\$(shell pkg-config --cflags lua$VERLUA ) -DLUA"
LUALIB="\$(shell pkg-config --libs lua$VERLUA )"
elif pkg-config --cflags lua > /dev/null 2>&1; then
echo " (unpackaged)"
LUA="\$(shell pkg-config --cflags lua ) -DLUA"
LUALIB="\$(shell pkg-config --libs lua )"
else
echo " - No package found"
echo "Workaround : edit this remake file to hardcode where Lua is installed."
echo
exit 1
fi
else
echo "Lua not used"
fi
# Enable JSon-c for modules having to handle Json data as well as curl
if [ ${BUILD_METEOOWM+x} ]; then
JSON="\$(shell pkg-config --cflags json-c )"
JSONLIB="\$(shell pkg-config --libs json-c ) -lcurl"
else
echo 'No need for Curl and json'
fi
if [ ${DEBUG+x} ]; then
echo "Debuging code enabled"
DEBUG="-DDEBUG"
else
echo "DEBUG not defined"
fi
if [ ${MCHECK+x} ]; then
echo "Memory checking activated"
MCHECK='-DMCHECK="mcheck(NULL)"'
MCHECK_LIB="-lmcheck"
else
echo "No memory checking"
fi
# =================
# Rebuild Makefiles
# =================
echo -e "\nBuild Makefiles\n===============\n"
echo "# global Makefile that is calling sub directories ones" > Makefile
echo >> Makefile
echo "gotoall: all" >> Makefile
echo >> Makefile
echo "# Clean previous builds sequels" >> Makefile
echo "clean:" >> Makefile
echo -e "\trm -f *.so" >> Makefile
echo -e "\trm -f Modules/*/*.o" >> Makefile
echo >> Makefile
echo "# Build everything" >> Makefile
echo "all:" >> Makefile
if [ ${BUILD_LUA+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_Lua' >> Makefile
fi
if [ ${BUILD_EVERY+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_every' >> Makefile
fi
if [ ${BUILD_UPS+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_ups' >> Makefile
fi
if [ ${BUILD_OUTFILE+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_outfile' >> Makefile
fi
if [ ${BUILD_ONOFF+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_OnOff' >> Makefile
fi
if [ ${BUILD_DPD+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_dpd' >> Makefile
fi
if [ ${BUILD_SHT31+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_sht31' >> Makefile
fi
if [ ${BUILD_1WIRE+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_1wire' >> Makefile
fi
if [ ${BUILD_ALERT+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_alert' >> Makefile
fi
if [ ${BUILD_INOTIFY+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_inotify' >> Makefile
fi
if [ ${BUILD_METEOOWM+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_OpenWeatherMap' >> Makefile
fi
if [ ${BUILD_FREEBOXV5+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_freeboxV5' >> Makefile
fi
if [ ${BUILD_FREEBOXOS+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_freeboxOS' >> Makefile
fi
if [ ${BUIlD_RFXTRX+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_RFXtrx' >> Makefile
fi
if [ ${BUILD_DUMMY+x} ]; then
echo -e '\t$(MAKE) -C Modules/mod_dummy' >> Makefile
fi
echo -e '\t$(MAKE) -C Modules/Marcel' >> Makefile
# =============================
# Rebuild modules' own Makefile
# =============================
if [ ${BUILD_LUA+x} ]; then
cd Modules/mod_Lua
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK $LUALIB" *.c -so=../../mod_Lua.so > Makefile
cd ../..
fi
if [ ${BUILD_EVERY+x} ]; then
cd Modules/mod_every
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_every.so > Makefile
cd ../..
fi
if [ ${BUILD_UPS+x} ]; then
cd Modules/mod_ups
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_ups.so > Makefile
cd ../..
fi
if [ ${BUILD_OUTFILE+x} ]; then
cd Modules/mod_outfile
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_outfile.so > Makefile
cd ../..
fi
if [ ${BUILD_ONOFF+x} ]; then
cd Modules/mod_OnOff
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_OnOff.so > Makefile
cd ../..
fi
if [ ${BUILD_DPD+x} ]; then
cd Modules/mod_dpd
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_dpd.so > Makefile
cd ../..
fi
if [ ${BUILD_SHT31+x} ]; then
cd Modules/mod_sht31
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_sht31.so > Makefile
cd ../..
fi
if [ ${BUILD_1WIRE+x} ]; then
cd Modules/mod_1wire
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_1wire.so > Makefile
cd ../..
fi
if [ ${BUILD_ALERT+x} ]; then
cd Modules/mod_alert
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_alert.so > Makefile
cd ../..
fi
if [ ${BUILD_INOTIFY+x} ]; then
cd Modules/mod_inotify
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_inotify.so > Makefile
cd ../..
fi
if [ ${BUILD_METEOOWM+x} ]; then
cd Modules/mod_OpenWeatherMap
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $JSON $DEBUG $MCHECK" *.c -so=../../mod_owm.so > Makefile
cd ../..
fi
if [ ${BUILD_FREEBOXV5+x} ]; then
cd Modules/mod_freeboxV5
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_freeboxV5.so > Makefile
cd ../..
fi
if [ ${BUILD_FREEBOXOS+x} ]; then
cd Modules/mod_freeboxOS
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_freeboxOS.so > Makefile
cd ../..
fi
if [ ${BUIlD_RFXTRX+x} ]; then
cd Modules/mod_RFXtrx
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_RFXtrx.so > Makefile
cd ../..
fi
if [ ${BUILD_DUMMY+x} ]; then
cd Modules/mod_dummy
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $LUA $DEBUG $MCHECK" *.c -so=../../mod_dummy.so > Makefile
cd ../..
fi
# ==============================
# Rebuild Marcel's core Makefile
# ==============================
cd Modules/Marcel
LFMakeMaker -v +f=Makefile --opts="$CFLAGS $DEBUG $MCHECK $LUALIB $JSONLIB \
-DPLUGIN_DIR='\"$PLUGIN_DIR\"' -L$PLUGIN_DIR \
-L$RDIR -lpaho-mqtt3c -lm -ldl -Wl,--export-dynamic -lpthread \
" *.c -t=../../Marcel > Makefile
#echo
#echo "Don't forget if you want to run it without installing first"
#echo export LD_LIBRARY_PATH=$PLUGIN_DIR:$LD_LIBRARY_PATH
echo
echo "Makefiles are created"