forked from themactep/strero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
455 lines (391 loc) · 14.6 KB
/
Makefile
File metadata and controls
455 lines (391 loc) · 14.6 KB
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# =============================================================================
# Thingino Streamer Makefile
# =============================================================================
#
# Modular Feature Support:
# To enable optional modules, set the following flags:
# ENABLE_AUDIO=1 - Enable audio capture and streaming module
# ENABLE_IMP_CONTROL=1 - Enable IMP image quality control module
# ENABLE_METRICS=1 - Enable system metrics collection and HTTP endpoints module
# ENABLE_MOTION=1 - Enable motion detection module
# ENABLE_OSD=1 - Enable OSD overlay module (enabled by default)
# ENABLE_PHOTOSENSING=1 - Enable automatic day/night mode switching module
# ENABLE_RTMP_CLIENT=1 - Enable RTMP streaming client module
# ENABLE_RTMP_SERVER=1 - Enable RTMP streaming server module
# ENABLE_RTSP=1 - Enable RTSP streaming server module (enabled by default)
# ENABLE_IMAGE_GRAB=1 - Enable image grabbing module (JPEG/NV12/YUV capture)
#
# Optional Audio Codec Support:
# To enable audio codec libraries, set the following flags:
# ENABLE_OPUS=1 - Enable Opus audio codec support
# ENABLE_FAAC=1 - Enable FAAC audio codec support
# ENABLE_HELIX_AAC=1 - Enable Helix AAC audio codec support
#
# Example: make ENABLE_AUDIO=1 ENABLE_OPUS=1 ENABLE_FAAC=1
# =============================================================================
# Module Configuration (Feature Flags)
# =====================================
ENABLE_AUDIO ?= 0
ENABLE_HTTP ?= 1
ENABLE_IMAGE_GRAB ?= 0
ENABLE_IMP_CONTROL ?= 1
ENABLE_METRICS ?= 1
ENABLE_MOTION ?= 1
ENABLE_ONVIF ?= 1
ENABLE_OSD ?= 1
ENABLE_PHOTOSENSING ?= 1
ENABLE_RTMP_CLIENT ?= 1
ENABLE_RTMP_SERVER ?= 0
ENABLE_RTSP ?= 1
RTMPS_BACKEND_OPENSSL ?= 0
RTMPS_BACKEND_MBEDTLS ?= 0
RTSPS_BACKEND_OPENSSL ?= 0
RTSPS_BACKEND_MBEDTLS ?= 0
# Compiler Configuration
# ----------------------
CC = ${CROSS_COMPILE}gcc
# Compiler Flags
# --------------
CFLAGS ?= -Wall -Wextra -Wno-unused-parameter -O2 -DNO_OPENSSL=1 -std=c99
LDFLAGS += -lrt -lpthread -latomic -Wl,--no-as-needed
# Kernel Version Support
# ----------------------
ifeq ($(KERNEL_VERSION_4),y)
CFLAGS += -DKERNEL_VERSION_4
endif
# Binary Type Configuration
# -------------------------
# Always use dynamic linking
override CFLAGS += -DBINARY_DYNAMIC
# Library Configuration
# =====================
# Audio codec libraries (optional - controlled by flags)
AUDIO_LIBS_STATIC =
AUDIO_LIBS_DYNAMIC =
ifdef ENABLE_OPUS
AUDIO_LIBS_STATIC += -l:libopus.a
AUDIO_LIBS_DYNAMIC += -l:libopus.so
CFLAGS += -DENABLE_OPUS=1
endif
ifdef ENABLE_FAAC
AUDIO_LIBS_STATIC += -l:libfaac.a
AUDIO_LIBS_DYNAMIC += -l:libfaac.so
CFLAGS += -DENABLE_FAAC=1
endif
ifdef ENABLE_HELIX_AAC
AUDIO_LIBS_STATIC += -l:libhelix-aac.a
AUDIO_LIBS_DYNAMIC += -l:libhelix-aac.so
CFLAGS += -DENABLE_HELIX_AAC=1
endif
# Check for libc type from CFLAGS, default to musl if not specified
# We add libmusl shim only when using musl (default if no libc type specified)
ifneq ($(MAKECMDGOALS),clean)
# Dynamic Binary Configuration
# ----------------------------
LIBS = -Wl,-Bdynamic \
-l:libimp.so \
-l:libjson-c.so \
-l:libsysutils.so \
-l:libwebsockets.so \
-latomic \
-lpthread -ldl -lm
# LIBS += -l:libalog.so
# Add TLS libraries based on backend selection
ifeq ($(RTMPS_BACKEND_OPENSSL),1)
LIBS += -l:libssl.so -l:libcrypto.so
endif
ifeq ($(RTMPS_BACKEND_MBEDTLS),1)
LIBS += -l:libmbedtls.so -l:libmbedx509.so
endif
ifneq (,$(findstring -DLIBC_GLIBC,$(CFLAGS)))
# GLIBC - no additional libraries needed
else ifneq (,$(findstring -DLIBC_UCLIBC,$(CFLAGS)))
# uClibc - no additional libraries needed
else
# Default to musl
LIBS += -l:libmuslshim.so -latomic
endif
endif
# Platform-Specific Include and Library Directories
# =================================================
ifneq (,$(findstring -DPLATFORM_C100,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/C100/2.1.0/en
LIBIMP_LIB_DIR = ./lib/C100/lib/2.1.0/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T10,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T20/3.12.0/zh
LIBIMP_LIB_DIR = ./lib/T20/lib/3.12.0/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T20,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T20/3.12.0/zh
LIBIMP_LIB_DIR = ./lib/T20/lib/3.12.0/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T21,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T21/1.0.33/zh
LIBIMP_LIB_DIR = ./lib/T21/lib/1.0.33/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T23,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T23/1.1.0/zh
LIBIMP_LIB_DIR = ./lib/T23/lib/1.1.0/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T30,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T30/1.0.5/zh
LIBIMP_LIB_DIR = ./lib/T30/lib/1.0.5/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T31,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T31/1.1.6/en
LIBIMP_LIB_DIR = ./lib/T31/lib/1.1.6/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T32,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T32/1.0.4/en
LIBIMP_LIB_DIR = ./lib/T32/lib/1.0.4/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T40,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T40/1.2.0/zh
LIBIMP_LIB_DIR = ./lib/T40/lib/1.2.0/uclibc/5.4.0
else ifneq (,$(findstring -DPLATFORM_T41,$(CFLAGS)))
LIBIMP_INC_DIR = ./include/T41/1.2.0/zh
LIBIMP_LIB_DIR = ./lib/T41/lib/1.2.0/uclibc/5.4.0
endif
# Directory Structure
# ===================
SRC_DIR = ./src
OBJ_DIR = ./obj
BIN_DIR = ./bin
THIRDPARTY_INC_DIR = ./3rdparty/install/include
# Source and Object Files
# =======================
# Core source files (always included)
C_SOURCES_CORE = $(SRC_DIR)/main.c \
$(SRC_DIR)/common.c \
$(SRC_DIR)/config.c \
$(SRC_DIR)/sensor.c \
$(SRC_DIR)/module_system.c \
$(SRC_DIR)/frame_manager.c \
$(SRC_DIR)/auth_utils.c \
$(SRC_DIR)/snapshot_fallback.c
# HAL sources (platform-selected)
ifneq (,$(findstring -DPLATFORM_T31,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t31.c
else ifneq (,$(findstring -DPLATFORM_T30,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t30.c
else ifneq (,$(findstring -DPLATFORM_T23,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t23.c
else ifneq (,$(findstring -DPLATFORM_T21,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t21.c
else ifneq (,$(findstring -DPLATFORM_T20,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t20.c
else ifneq (,$(findstring -DPLATFORM_T10,$(CFLAGS)))
C_SOURCES_CORE += $(SRC_DIR)/hal/imp/imp_t20.c
endif
# Module source files (conditionally included based on feature flags)
C_SOURCES_MODULES =
# Include audio module if enabled
ifeq ($(ENABLE_AUDIO),1)
CFLAGS += -DENABLE_AUDIO
LIBS += -l:libaudioProcess.so $(AUDIO_LIBS_DYNAMIC)
include src/modules/audio/Makefile.audio
# Add audio objects to build
EXTRA_OBJECTS += $(AUDIO_OBJECTS)
endif
# Include HTTP module if enabled (enabled by default)
ifeq ($(ENABLE_HTTP),1)
CFLAGS += -DENABLE_HTTP
include src/modules/http/Makefile.http
# Add HTTP objects to build
EXTRA_OBJECTS += $(HTTP_OBJECTS)
endif
# Include IMP control module if enabled (enabled by default)
ifeq ($(ENABLE_IMP_CONTROL),1)
CFLAGS += -DENABLE_IMP_CONTROL
include src/modules/imp_control/Makefile.imp_control
# Add IMP control objects to build
EXTRA_OBJECTS += $(IMP_CONTROL_OBJECTS)
endif
# Include metrics module if enabled
ifeq ($(ENABLE_METRICS),1)
CFLAGS += -DENABLE_METRICS
include src/modules/metrics/Makefile.metrics
# Add metrics objects to build
EXTRA_OBJECTS += $(METRICS_OBJECTS)
endif
# Include motion module if enabled
ifeq ($(ENABLE_MOTION),1)
CFLAGS += -DENABLE_MOTION_MODULE
include src/modules/motion/Makefile.motion
# Add motion objects to build
EXTRA_OBJECTS += $(MOTION_OBJECTS)
endif
# Include ONVIF module if enabled
ifeq ($(ENABLE_ONVIF),1)
CFLAGS += -DENABLE_ONVIF
include src/modules/onvif/Makefile.onvif
# Add ONVIF objects to build
EXTRA_OBJECTS += $(ONVIF_OBJECTS)
endif
# Include OSD module if enabled (enabled by default)
ifeq ($(ENABLE_OSD),1)
CFLAGS += -DENABLE_OSD
LIBS += -l:libschrift.so
include src/modules/osd/Makefile.osd
# Add OSD objects to build
EXTRA_OBJECTS += $(OSD_OBJECTS)
endif
# Include photosensing module if enabled
ifeq ($(ENABLE_PHOTOSENSING),1)
CFLAGS += -DENABLE_PHOTOSENSING
include src/modules/photosensing/Makefile.photosensing
# Add photosensing objects to build
EXTRA_OBJECTS += $(PHOTOSENSING_OBJECTS)
endif
# Include RTMP server module if enabled
ifeq ($(ENABLE_RTMP_SERVER),1)
CFLAGS += -DENABLE_RTMP_SERVER
include src/modules/rtmp_server/Makefile.rtmp_server
# Add RTMP server objects to build
EXTRA_OBJECTS += $(RTMP_SERVER_OBJECTS)
endif
# Include RTMP client module if enabled
ifeq ($(ENABLE_RTMP_CLIENT),1)
CFLAGS += -DENABLE_RTMP_CLIENT
include src/modules/rtmp_client/Makefile.rtmp_client
# Add RTMP client objects to build
EXTRA_OBJECTS += $(RTMP_CLIENT_OBJECTS)
endif
# Enable RTMPS (TLS) support if enabled
ifeq ($(ENABLE_RTMPS),1)
CFLAGS += -DENABLE_RTMPS
endif
# Include RTSP module if enabled (enabled by default)
ifeq ($(ENABLE_RTSP),1)
CFLAGS += -DENABLE_RTSP
include src/modules/rtsp/Makefile.rtsp
# Add RTSP objects to build
EXTRA_OBJECTS += $(RTSP_OBJECTS)
endif
# Include image grab module if enabled
ifeq ($(ENABLE_IMAGE_GRAB),1)
CFLAGS += -DENABLE_IMAGE_GRAB
include src/modules/image_grab/Makefile.image_grab
# Add image grab objects to build
EXTRA_OBJECTS += $(IMAGE_GRAB_OBJECTS)
endif
# Enable RTSPS (TLS) support if enabled
ifeq ($(ENABLE_RTSPS),1)
CFLAGS += -DENABLE_RTSPS
endif
# Add TLS backend flags
ifeq ($(RTMPS_BACKEND_OPENSSL),1)
CFLAGS += -DRTMPS_BACKEND_OPENSSL
endif
ifeq ($(RTMPS_BACKEND_MBEDTLS),1)
CFLAGS += -DRTMPS_BACKEND_MBEDTLS
endif
# Add RTSPS TLS backend flags (reuse RTMPS backend selection)
ifeq ($(ENABLE_RTSPS),1)
ifeq ($(RTMPS_BACKEND_OPENSSL),1)
CFLAGS += -DRTSPS_BACKEND_OPENSSL
endif
ifeq ($(RTMPS_BACKEND_MBEDTLS),1)
CFLAGS += -DRTSPS_BACKEND_MBEDTLS
endif
endif
# Use core source files plus enabled modules
C_SOURCES_WITH_STUBS = $(C_SOURCES_CORE) $(C_SOURCES_MODULES)
# Conditionally include compatibility shims based on libc type
# Use deferred evaluation to check CFLAGS at build time
C_SOURCES = $(C_SOURCES_WITH_STUBS) $(if $(findstring -DLIBC_UCLIBC,$(CFLAGS)),$(SRC_DIR)/glibc_uclibc_compat.c,$(if $(findstring -DLIBC_GLIBC,$(CFLAGS)),,$(SRC_DIR)/uclibc_musl_shim.c))
# Include only the files we need for pure C build
SOURCES = $(C_SOURCES)
OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(C_SOURCES)) $(EXTRA_OBJECTS)
$(info Building objects: $(OBJECTS))
# Target Configuration
# ====================
TARGET = $(BIN_DIR)/streamer
# Version Management
# ==================
ifndef commit_tag
commit_tag = $(shell git rev-parse --short HEAD)
endif
VERSION_FILE = $(LIBIMP_INC_DIR)/version.h
# Build Options
# =============
STRIP_FLAG := $(if $(filter 0,$(DEBUG_STRIP)),,"-s")
# =============================================================================
# Build Rules
# =============================================================================
# Version File Generation
# -----------------------
$(VERSION_FILE): src/version.tpl.h
@if ! grep -q "$(commit_tag)" $(VERSION_FILE) > /dev/null 2>&1; then \
echo "Updating version.h to $(commit_tag)"; \
sed 's/COMMIT_TAG/"$(commit_tag)"/g' src/version.tpl.h > $(VERSION_FILE); \
fi
# C Object Compilation
# --------------------
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(VERSION_FILE)
@mkdir -p $(@D)
$(CC) $(CFLAGS) \
-I$(LIBIMP_INC_DIR) \
-I$(LIBIMP_INC_DIR)/imp \
-I$(LIBIMP_INC_DIR)/sysutils \
-I./include \
-I./src \
-isystem $(THIRDPARTY_INC_DIR) \
-c $< -o $@
# Final Binary Linking
# --------------------
$(TARGET): $(OBJECTS) $(VERSION_FILE)
@mkdir -p $(@D)
$(CCACHE) $(CC) -L$(LIBIMP_LIB_DIR) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS) $(STRIP_FLAG)
# =============================================================================
# Phony Targets
# =============================================================================
.PHONY: all clean distclean t31 t23 t20 t21 t30 t10 install
# Default Target
# --------------
all: $(TARGET)
# Special Targets for Different Platform/SDK Combinations
# -------------------------------------------------------
# Standard T31 hardware with T31 SDK
t31:
@echo "Building for T31 hardware with T31 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T31" $(TARGET)
@echo "Build complete: T31 hardware + T31 SDK"
# Standard T23 hardware with T23 SDK
t23:
@echo "Building for T23 hardware with T23 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T23" $(TARGET)
@echo "Build complete: T23 hardware + T23 SDK"
# Standard T20 hardware with T20 SDK
t20:
@echo "Building for T20 hardware with T20 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T20" $(TARGET)
@echo "Build complete: T20 hardware + T20 SDK"
# Standard T10 hardware with T20 SDK
t10:
@echo "Building for T10 hardware with T20 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T10" $(TARGET)
@echo "Build complete: T10 hardware + T20 SDK"
# Standard T21 hardware with T21 SDK
t21:
@echo "Building for T21 hardware with T21 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T21" $(TARGET)
@echo "Build complete: T21 hardware + T21 SDK"
# Standard T30 hardware with T30 SDK
t30:
@echo "Building for T30 hardware with T30 SDK..."
$(MAKE) CFLAGS="$(CFLAGS) -DPLATFORM_T30" $(TARGET)
@echo "Build complete: T30 hardware + T30 SDK"
# Clean Build Artifacts
# ---------------------
clean:
@echo "Cleaning build artifacts..."
rm -rf $(OBJ_DIR)
rm -f $(LIBIMP_INC_DIR)/version.h
# Complete Clean
# --------------
distclean: clean
@echo "Cleaning all generated files..."
rm -rf $(BIN_DIR)
# Installation
# ------------
install: $(TARGET)
mkdir -p $(DESTDIR)/usr/bin
mkdir -p $(DESTDIR)/etc
mkdir -p $(DESTDIR)/etc/streamer.d
install -m 755 $(TARGET) $(DESTDIR)/usr/bin/
install -m 644 res/streamer.json $(DESTDIR)/etc/
install -m 644 res/config/*.json $(DESTDIR)/etc/streamer.d/