forked from fliphess/miicam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
404 lines (339 loc) · 12.7 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
TOOLCHAINDIR := /usr/src/arm-linux-3.3/toolchain_gnueabi-4.4.0_ARMv5TE/usr/bin
PATH := $(TOOLCHAINDIR):$(PATH)
TARGET := arm-unknown-linux-uclibcgnueabi
PROCS := $(shell nproc --all )
DOWNLOADCMD := curl -qs --http1.1 -L --retry 10 --output
BUILDENV := \
AR=$(TARGET)-ar \
AS=$(TARGET)-as \
CC=$(TARGET)-gcc \
CXX=$(TARGET)-g++ \
LD=${TARGET}-ld \
NM=$(TARGET)-nm \
RANLIB=$(TARGET)-ranlib \
STRIP=$(TARGET)-strip \
CFLAGS="-fPIC" \
CPPFLAGS="-I$(PREFIXDIR)/include -L$(PREFIXDIR)/lib" \
LDFLAGS=" -I$(PREFIXDIR)/include -L$(PREFIXDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags"
TOPDIR := $(CURDIR)
SOURCEDIR := $(TOPDIR)/src
PREFIXDIR := $(TOPDIR)/prefix
BUILDDIR := $(TOPDIR)/build
TOOLSDIR := $(TOPDIR)/tools
PATCHESDIR := $(TOOLSDIR)/patches
GMLIBDIR := $(TOOLSDIR)/gm_lib
RTSPDDIR := $(TOOLSDIR)/rtsp_server
UTILSDIR := $(TOOLSDIR)/utils
BINARIESDIR := $(TOPDIR)/sdcard/firmware/bin
LIBRARIESDIR := $(TOPDIR)/sdcard/firmware/lib
WEBSOURCEDIR := $(TOPDIR)/web
WEBDESTDIR := $(TOPDIR)/sdcard/firmware/www
SOURCES := $(TOPDIR)/sources.json
#################################################################
## Functions ##
#################################################################
include tools/make/functions.mk
#################################################################
## Results ##
#################################################################
LIBS := \
$(BUILDDIR)/chuangmi_ircut \
$(BUILDDIR)/chuangmi_isp328 \
$(BUILDDIR)/chuangmi_pwm \
$(BUILDDIR)/chuangmi_led \
$(BUILDDIR)/chuangmi_utils
UTILS := \
$(BUILDDIR)/chuangmi_ctrl \
$(BUILDDIR)/take_snapshot \
$(BUILDDIR)/take_video \
$(BUILDDIR)/ir_cut \
$(BUILDDIR)/ir_led \
$(BUILDDIR)/blue_led \
$(BUILDDIR)/yellow_led \
$(BUILDDIR)/mirrormode \
$(BUILDDIR)/nightmode \
$(BUILDDIR)/flipmode \
$(BUILDDIR)/camera_adjust \
$(BUILDDIR)/auto_night_mode
GMUTILS := \
$(BUILDDIR)/audio_playback \
$(BUILDDIR)/encode_with_osd \
$(BUILDDIR)/osd
THIRD_PARTY_SOFTWARE := \
$(BUILDDIR)/zlib \
$(BUILDDIR)/libxml2 \
$(BUILDDIR)/libjpeg-turbo \
$(BUILDDIR)/libpng \
$(BUILDDIR)/libgd \
$(BUILDDIR)/pcre \
$(BUILDDIR)/popt \
$(BUILDDIR)/x264 \
$(BUILDDIR)/ncurses \
$(BUILDDIR)/readline \
$(BUILDDIR)/busybox \
$(BUILDDIR)/wget \
$(BUILDDIR)/dosfstools \
$(BUILDDIR)/libpcap \
$(BUILDDIR)/tcpdump \
$(BUILDDIR)/openssl \
$(BUILDDIR)/socat \
$(BUILDDIR)/fromdos \
$(BUILDDIR)/jq \
$(BUILDDIR)/logrotate \
$(BUILDDIR)/sftp \
$(BUILDDIR)/dropbear \
$(BUILDDIR)/lighttpd \
$(BUILDDIR)/nano \
$(BUILDDIR)/php \
$(BUILDDIR)/rsync \
$(BUILDDIR)/lsof \
$(BUILDDIR)/strace \
$(BUILDDIR)/ffmpeg
libs: $(LIBS)
third-party: $(THIRD_PARTY_SOFTWARE)
website: $(BUILDDIR)/website
utils: $(UTILS)
libs: $(LIBS)
gmutils: $(GMUTILS)
all: \
sources \
libs \
utils \
gmutils \
website \
sdcard/config.cfg \
sdcard/manufacture.bin \
sdcard/firmware/etc/os-release \
$(BUILDDIR)/rtspd \
third-party
#################################################################
## DIRS ##
#################################################################
$(SOURCEDIR):
@mkdir -p $(SOURCEDIR)
$(PREFIXDIR)/bin:
@mkdir -p $(PREFIXDIR)/bin
$(PREFIXDIR)/sbin:
@mkdir -p $(PREFIXDIR)/sbin
$(PREFIXDIR)/lib:
@mkdir -p $(PREFIXDIR)/lib
#################################################################
## RTSPD ##
#################################################################
$(BUILDDIR)/rtspd: $(PREFIXDIR)/bin
@mkdir -p $(BUILDDIR) $(TOOLSDIR)/bin
cd $(RTSPDDIR) \
&& $(TARGET)-gcc \
-DLOG_USE_COLOR \
-Wall \
-I$(GMLIBDIR)/inc \
$(RTSPDDIR)/$(@F).c \
$(RTSPDDIR)/log/log.c \
$(RTSPDDIR)/librtsp.a \
-L$(GMLIBDIR)/lib \
-lpthread -lm -lrt -lgm -o $(TOOLSDIR)/bin/rtspd && \
$(TARGET)-strip $(TOOLSDIR)/bin/rtspd
@touch $@
#################################################################
## LIBS ##
#################################################################
$(BUILDDIR)/chuangmi_utils:
$(call box,"Compiling miicam library $(@F)")
@mkdir -p $(BUILDDIR)
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc -shared -o $(TOOLSDIR)/lib/libchuangmi_utils.so -fPIC $(TOOLSDIR)/lib/chuangmi_utils.c
@touch $@
$(BUILDDIR)/chuangmi_ircut: $(BUILDDIR)/chuangmi_utils
$(call box,"Compiling miicam library $(@F)")
@mkdir -p $(BUILDDIR)
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc -shared -o $(TOOLSDIR)/lib/libchuangmi_ircut.so -fPIC $(TOOLSDIR)/lib/chuangmi_ircut.c
@touch $@
$(BUILDDIR)/chuangmi_isp328: $(BUILDDIR)/chuangmi_utils
$(call box,"Compiling miicam library $(@F)")
@mkdir -p $(BUILDDIR)
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc -shared -o $(TOOLSDIR)/lib/libchuangmi_isp328.so -fPIC $(TOOLSDIR)/lib/chuangmi_isp328.c
@touch $@
$(BUILDDIR)/chuangmi_pwm: $(BUILDDIR)/chuangmi_utils
$(call box,"Compiling miicam library $(@F)")
@mkdir -p $(BUILDDIR)
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc -shared -o $(TOOLSDIR)/lib/libchuangmi_pwm.so -fPIC $(TOOLSDIR)/lib/chuangmi_pwm.c
@touch $@
$(BUILDDIR)/chuangmi_led: $(BUILDDIR)/chuangmi_utils
$(call box,"Compiling miicam library $(@F)")
@mkdir -p $(BUILDDIR)
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc -shared -o $(TOOLSDIR)/lib/libchuangmi_led.so -fPIC $(TOOLSDIR)/lib/chuangmi_led.c
@touch $@
#################################################################
## UTILS ##
#################################################################
$(UTILS): $(PREFIXDIR)/bin $(LIBS) $(BUILDDIR)/popt
$(call box,"Compiling miicam utility $(@F)")
@mkdir -p $(BUILDDIR) $(TOOLSDIR)/bin
CPPFLAGS="-I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib" \
LDFLAGS=" -I$(TOOLSDIR)/lib -L$(TOOLSDIR)/lib -Wl,-rpath -Wl,/tmp/sd/firmware/lib -Wl,--enable-new-dtags" \
$(TARGET)-gcc \
-Wall \
-o $(TOOLSDIR)/bin/$(@F) $(UTILSDIR)/$(@F).c \
-I $(TOOLSDIR)/lib -L$(TOOLSDIR)/lib \
-I $(PREFIXDIR)/include -L$(PREFIXDIR)/lib \
-l popt \
-l chuangmi_ircut \
-l chuangmi_utils \
-l chuangmi_isp328 \
-l chuangmi_led \
-l chuangmi_pwm
@touch $(BUILDDIR)/$(@F)
#################################################################
## GM Utils ##
#################################################################
$(GMUTILS): $(BUILDDIR)/popt
$(call box,"Compiling miicam libraries")
@mkdir -p $(BUILDDIR) $(TOOLSDIR)/bin
cd $(GMLIBDIR) \
&& $(TARGET)-gcc \
-Wall \
-I $(GMLIBDIR)/inc \
-I $(TOOLSDIR)/lib \
-I $(PREFIXDIR)/include \
-L $(TOOLSDIR)/lib \
-L $(GMLIBDIR)/lib \
-L $(PREFIXDIR)/lib \
-o $(TOOLSDIR)/bin/$(@F)\
$(GMLIBDIR)/$(@F).c \
-l gm \
-l m \
-l popt \
-l rt \
-l pthread \
&& $(TARGET)-strip $(TOOLSDIR)/bin/$(@F)
@touch $@
#################################################################
## Firmware configuration files ##
#################################################################
sdcard/config.cfg:
$(TOPDIR)/sdcard/firmware/scripts/configupdate $(TOPDIR)/sdcard/config.cfg
sdcard/manufacture.bin:
tar -cf $(TOPDIR)/sdcard/manufacture.bin manufacture/test_drv
sdcard/firmware/etc/os-release:
$(TOPDIR)/bin/print-version | tee $@
#################################################################
## Third party tools ##
#################################################################
include tools/make/zlib.mk
include tools/make/libxml.mk
include tools/make/libjpeg.mk
include tools/make/libpng.mk
include tools/make/libgd.mk
include tools/make/pcre.mk
include tools/make/wget.mk
include tools/make/libpopt.mk
include tools/make/h264.mk
include tools/make/ncurses.mk
include tools/make/readline.mk
include tools/make/busybox.mk
include tools/make/dosfstools.mk
include tools/make/tcpdump.mk
include tools/make/openssl.mk
include tools/make/socat.mk
include tools/make/logrotate.mk
include tools/make/dropbear.mk
include tools/make/lighttpd.mk
include tools/make/php.mk
include tools/make/nano.mk
include tools/make/rsync.mk
include tools/make/strace.mk
include tools/make/lsof.mk
include tools/make/fromdos.mk
include tools/make/jq.mk
include tools/make/ffmpeg.mk
include tools/make/OUTPUT.mk
#################################################################
## WEB INTERFACE ##
#################################################################
$(BUILDDIR)/website:
$(call box,"Building webui from $(WEBSOURCEDIR) to $(WEBDESTDIR)")
@mkdir -p $(WEBDESTDIR)
@cd $(WEBSOURCEDIR) \
\
&& echo '*** Running composer install in $(WEBSOURCEDIR)' \
&& composer install --no-dev --ignore-platform-reqs --no-interaction --prefer-dist \
\
&& echo "***Removing all unneeded crap from the vendor dir" \
&& php $(HOME)/.composer/vendor/mediamonks/composer-vendor-cleaner/bin/clean --dir vendor/ >/dev/null \
\
&& echo "*** Recreating class mappings" \
&& composer dump-autoload --classmap-authoritative \
\
&& echo '*** Removing symlinks from $(WEBSOURCEDIR)/vendor to prevent fat32 symlink issues' \
&& find $(WEBSOURCEDIR)/vendor -type l -delete \
\
&& echo '*** Copying files to $(WEBDESTDIR)' \
&& cp -r app libs public vendor $(WEBDESTDIR)/. \
\
&& touch $@
#################################################################
## ##
#################################################################
.PHONY: sources install images clean
sources:
$(call box,"Downloading current third-party sources")
$(TOPDIR)/bin/download-sources.py --file $(SOURCES)
install: all
$(call box,"Running make install")
@mkdir -p $(BINARIESDIR) $(LIBRARIESDIR) \
\
&& echo "*** Copying third party binaries and extras to $(BINARIESDIR)" \
&& cd $(PREFIXDIR)/sbin && $(TARGET)-strip $(THIRD_PARTY_SBINS) && cp $(THIRD_PARTY_SBINS) $(BINARIESDIR)/. \
&& cd $(PREFIXDIR)/bin && $(TARGET)-strip $(THIRD_PARTY_BINS) && cp $(THIRD_PARTY_BINS) $(BINARIESDIR)/. \
&& cd $(PREFIXDIR)/bin && cp $(THIRD_PARTY_BIN_EXTRAS) $(BINARIESDIR)/. \
\
&& echo "*** Copying third party libraries and extras to $(LIBRARIESDIR)" \
&& cd $(PREFIXDIR)/lib && $(TARGET)-strip $(THIRD_PARTY_LIBS) && cp $(THIRD_PARTY_LIBS) $(LIBRARIESDIR)/. \
&& cd $(PREFIXDIR)/lib && cp $(THIRD_PARTY_LIB_EXTRAS) $(LIBRARIESDIR)/. \
\
&& echo "*** Copying our own binaries to $(BINARIESDIR)" \
&& cd $(TOOLSDIR)/bin && find . -maxdepth 1 -type f -exec $(TARGET)-strip {} \; -exec cp {} $(BINARIESDIR)/. \; \
\
&& echo "*** Copying our own libraries to $(BINARIESDIR)" \
&& cd $(TOOLSDIR)/lib && find . -maxdepth 1 -type f -name '*.so' -exec $(TARGET)-strip {} \; -exec cp {} $(LIBRARIESDIR) \;
images: all install
$(call box,"Running make images")
@cd $(TOPDIR) \
\
&& echo "*** Removing older version of MiiCam.tgz and MiiCam.zip" \
&& find $(TOPDIR) -maxdepth 1 -type f -name 'MiiCam.zip' -or -name 'MiiCam.tgz' -delete \
\
&& echo "*** Creating file listing before packing" \
&& find $(TOPDIR)/sdcard -type f -exec md5sum {} \; > sdcard/firmware/etc/files.db \
\
&& echo "*** Creating zip archive of sdcard/ to MiiCam.zip" \
&& zip -r --quiet MiiCam.zip README.md sdcard \
\
&& echo "*** Creating tar archive of sdcard/ to MiiCam.tgz" \
&& tar czf MiiCam.tgz -C $(TOPDIR) README.md sdcard \
\
&& md5sum MiiCam.tgz > MiiCam.tgz.md5sum \
&& md5sum MiiCam.zip > MiiCam.zip.md5sum \
\
&& echo "*** MiiCam.zip and MiiCam.tgz created"
clean:
$(call box,"Running make clean")
@cd $(TOPDIR) \
\
&& echo "*** Removing directories with build artifacts" \
&& rm -rf $(BINARIESDIR) $(LIBRARIESDIR) $(WEBDESTDIR) $(PREFIXDIR) $(BUILDDIR) \
\
&& echo "*** Removing all own-brewed binaries" \
&& find $(TOOLSDIR)/bin -maxdepth 1 -type f -delete \
\
&& echo "*** Removing all self-brewed libraries" \
&& find $(TOOLSDIR)/lib -maxdepth 1 -type f -name '*.so' -delete