forked from baresip/baresip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
374 lines (307 loc) · 9.05 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
#
# Makefile
#
# Copyright (C) 2010 Creytiv.com
#
#
# Internal features:
#
# USE_TLS Enable SIP over TLS transport
#
PROJECT := baresip
VERSION := 1.0.0
DESCR := "Baresip is a modular SIP User-Agent with audio and video support"
# Verbose and silent build modes
ifeq ($(V),)
HIDE=@
endif
ifndef LIBRE_MK
LIBRE_MK := $(shell [ -f ../re/mk/re.mk ] && \
echo "../re/mk/re.mk")
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f ../re-$(VERSION)/mk/re.mk ] && \
echo "../re-$(VERSION)/mk/re.mk")
endif
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/share/re/re.mk ] && \
echo "/usr/share/re/re.mk")
endif
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/local/share/re/re.mk ] && \
echo "/usr/local/share/re/re.mk")
endif
endif
include $(LIBRE_MK)
include mk/modules.mk
ifeq ($(SYSROOT_LOCAL),)
ifeq ($(SYSROOT),/usr)
SYSROOT_LOCAL := $(shell [ -d /usr/local/include ] && echo "/usr/local")
endif
endif
ifndef LIBREM_PATH
LIBREM_PATH := $(shell [ -d ../rem ] && echo "../rem")
endif
ifeq ($(LIBREM_PATH),)
ifneq ($(SYSROOT_LOCAL),)
LIBREM_PATH := $(shell [ -f $(SYSROOT_LOCAL)/include/rem/rem.h ] && \
echo "$(SYSROOT_LOCAL)")
endif
endif
ifeq ($(LIBREM_PATH),)
LIBREM_PATH := $(shell [ -f $(SYSROOT)/include/rem/rem.h ] && \
echo "$(SYSROOT)")
endif
# Include path
LIBREM_INC := $(shell [ -f $(LIBREM_PATH)/include/rem.h ] && \
echo "$(LIBREM_PATH)/include")
ifeq ($(LIBREM_INC),)
LIBREM_INC := $(shell [ -f $(LIBREM_PATH)/include/rem/rem.h ] && \
echo "$(LIBREM_PATH)/include/rem")
endif
ifeq ($(LIBREM_INC),)
LIBREM_INC := $(shell [ -f /usr/local/include/rem/rem.h ] && \
echo "/usr/local/include/rem")
endif
ifeq ($(LIBREM_INC),)
LIBREM_INC := $(shell [ -f /usr/include/rem/rem.h ] && echo "/usr/include/rem")
endif
# Library path
ifeq ($(LIBREM_SO),)
LIBREM_SO := $(shell [ -f $(LIBREM_PATH)/librem.a ] && \
echo "$(LIBREM_PATH)")
endif
ifeq ($(LIBREM_SO),)
LIBREM_SO :=$(shell [ -f $(LIBREM_PATH)/librem$(LIB_SUFFIX) ] && \
echo "$(LIBREM_PATH)")
endif
ifeq ($(LIBREM_SO),)
LIBREM_SO := $(shell [ -f $(LIBREM_PATH)/lib/librem$(LIB_SUFFIX) ] && \
echo "$(LIBREM_PATH)/lib")
endif
ifeq ($(LIBREM_SO),)
LIBREM_SO := $(shell [ -f /usr/local/lib/librem$(LIB_SUFFIX) ] \
&& echo "/usr/local/lib")
endif
ifeq ($(LIBREM_SO),)
LIBREM_SO := $(shell [ -f /usr/lib/librem$(LIB_SUFFIX) ] && \
echo "/usr/lib")
endif
ifeq ($(LIBREM_SO),)
LIBREM_SO := $(shell [ -f /usr/lib64/librem$(LIB_SUFFIX) ] && \
echo "/usr/lib64")
endif
CFLAGS += -I. -Iinclude -I$(LIBRE_INC)
CFLAGS += -I$(LIBREM_INC)
CXXFLAGS += -I. -Iinclude -I$(LIBRE_INC)
CXXFLAGS += -I$(LIBREM_INC)
CXXFLAGS += $(EXTRA_CXXFLAGS)
# XXX: common for C/C++
CPPFLAGS += -DHAVE_INTTYPES_H
CLANG_OPTIONS += -I$(LIBREM_INC)
ifeq ($(OS),win32)
STATIC := yes
endif
ifneq ($(SYSROOT),)
ifeq ($(OS),freebsd)
CFLAGS += -I$(SYSROOT)/local/include
endif
ifeq ($(OS),openbsd)
CFLAGS += -isystem $(SYSROOT)/local/include
endif
endif
# Optional dependencies
ifneq ($(STATIC),)
CFLAGS += -DSTATIC=1
CXXFLAGS += -DSTATIC=1
endif
INSTALL := install
ifeq ($(DESTDIR),)
PREFIX := /usr/local
else
PREFIX := /usr
endif
BINDIR := $(PREFIX)/bin
INCDIR := $(PREFIX)/include
BIN := $(PROJECT)$(BIN_SUFFIX)
TEST_BIN := selftest$(BIN_SUFFIX)
SHARED := lib$(PROJECT)$(LIB_SUFFIX)
STATICLIB := libbaresip.a
ifeq ($(STATIC),)
MOD_BINS:= $(patsubst %,%$(MOD_SUFFIX),$(MODULES))
endif
APP_MK := src/srcs.mk
TEST_MK := test/srcs.mk
MOD_MK := $(patsubst %,modules/%/module.mk,$(MODULES))
MOD_BLD := $(patsubst %,$(BUILD)/modules/%,$(MODULES))
LIBDIR := $(PREFIX)/lib
MOD_PATH := $(LIBDIR)/$(PROJECT)/modules
SHARE_PATH := $(PREFIX)/share/$(PROJECT)
CFLAGS += -DPREFIX=\"$(PREFIX)\"
CFLAGS += -DMOD_PATH=\"$(MOD_PATH)\"
CFLAGS += -DSHARE_PATH=\"$(SHARE_PATH)\"
all: sanity $(MOD_BINS) $(BIN)
.PHONY: modules
modules: $(MOD_BINS)
include $(APP_MK)
include $(TEST_MK)
include $(MOD_MK)
OBJS := $(patsubst %.c,$(BUILD)/src/%.o,$(filter %.c,$(SRCS)))
OBJS += $(patsubst %.m,$(BUILD)/src/%.o,$(filter %.m,$(SRCS)))
OBJS += $(patsubst %.S,$(BUILD)/src/%.o,$(filter %.S,$(SRCS)))
APP_OBJS := $(OBJS) $(patsubst %.c,$(BUILD)/src/%.o,$(APP_SRCS)) $(MOD_OBJS)
LIB_OBJS := $(OBJS) $(MOD_OBJS)
TEST_OBJS := $(patsubst %.c,$(BUILD)/test/%.o,$(filter %.c,$(TEST_SRCS)))
TEST_OBJS += $(patsubst %.cpp,$(BUILD)/test/%.o,$(filter %.cpp,$(TEST_SRCS)))
LIBS += -L$(LIBREM_SO)
# Static build: include module linker-flags in binary
ifneq ($(STATIC),)
LIBS += $(MOD_LFLAGS)
else
ifneq ($(SYSROOT_LOCAL),)
LIBS += -L$(SYSROOT_LOCAL)/lib
MOD_LFLAGS += -L$(SYSROOT_LOCAL)/lib
endif
endif
LIBS += -lrem -lm
#LIBS += -L$(SYSROOT)/lib
ifeq ($(OS),win32)
TEST_LIBS += -static-libgcc
endif
-include $(APP_OBJS:.o=.d)
-include $(TEST_OBJS:.o=.d)
sanity:
ifeq ($(LIBRE_MK),)
@echo "ERROR: Missing common makefile for libre. Check LIBRE_MK"
@exit 2
endif
ifeq ($(LIBRE_INC),)
@echo "ERROR: Missing header files for libre. Check LIBRE_INC"
@exit 2
endif
ifeq ($(LIBRE_SO),)
@echo "ERROR: Missing library files for libre. Check LIBRE_SO"
@exit 2
endif
Makefile: mk/*.mk $(MOD_MK) $(LIBRE_MK)
$(SHARED): $(LIB_OBJS)
@echo " LD $@"
$(HIDE)$(LD) $(LFLAGS) $(SH_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@
$(STATICLIB): $(LIB_OBJS)
@echo " AR $@"
@rm -f $@; $(AR) $(AFLAGS) $@ $^
ifneq ($(RANLIB),)
@echo " RANLIB $@"
$(HIDE)$(RANLIB) $@
endif
libbaresip.pc:
@echo 'prefix='$(PREFIX) > libbaresip.pc
@echo 'exec_prefix=$${prefix}' >> libbaresip.pc
@echo 'libdir=$${prefix}/lib' >> libbaresip.pc
@echo 'includedir=$${prefix}/include' >> libbaresip.pc
@echo '' >> libbaresip.pc
@echo 'Name: libbaresip' >> libbaresip.pc
@echo 'Description: $(DESCR)' >> libbaresip.pc
@echo 'Version: '$(VERSION) >> libbaresip.pc
@echo 'URL: http://www.creytiv.com/baresip.html' >> libbaresip.pc
@echo 'Libs: -L$${libdir} -lbaresip' >> libbaresip.pc
@echo 'Cflags: -I$${includedir}' >> libbaresip.pc
$(BIN): $(APP_OBJS)
@echo " LD $@"
$(HIDE)$(LD) $(LFLAGS) $(APP_LFLAGS) $^ \
-L$(LIBRE_SO) -lre $(LIBS) -o $@
#
# List of modules used by selftest
#
ifneq ($(STATIC),)
TEST_MODULES :=
else
TEST_MODULES := g711.so
endif
.PHONY: test
test: $(TEST_BIN)
./$(TEST_BIN)
$(TEST_BIN): $(STATICLIB) $(TEST_OBJS) $(TEST_MODULES)
@echo " LD $@"
$(HIDE)$(LD) $(LFLAGS) $(APP_LFLAGS) $(TEST_OBJS) \
-L$(LIBRE_SO) -L. \
-l$(PROJECT) -lre $(LIBS) $(TEST_LIBS) -o $@
$(BUILD)/%.o: %.c $(BUILD) Makefile $(APP_MK)
@echo " CC $@"
$(HIDE)$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD)/%.o: %.cpp $(BUILD) Makefile $(APP_MK)
@echo " CXX $@"
$(HIDE)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD)/%.o: %.m $(BUILD) Makefile $(APP_MK)
@echo " OC $@"
$(HIDE)$(CC) $(CFLAGS) $(OBJCFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD)/%.o: %.S $(BUILD) Makefile $(APP_MK)
@echo " AS $@"
$(HIDE)$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD): Makefile
@mkdir -p $(BUILD)/src $(MOD_BLD) $(BUILD)/test/mock $(BUILD)/test/sip
@touch $@
install: $(BIN) $(MOD_BINS)
@mkdir -p $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(BINDIR)
ifeq ($(STATIC),)
@mkdir -p $(DESTDIR)$(MOD_PATH)
$(INSTALL) -m 0644 $(MOD_BINS) $(DESTDIR)$(MOD_PATH)
endif
@mkdir -p $(DESTDIR)$(SHARE_PATH)
$(INSTALL) -m 0644 share/* $(DESTDIR)$(SHARE_PATH)
install-dev: install-shared install-static
install-shared: $(SHARED) libbaresip.pc
@mkdir -p $(DESTDIR)$(INCDIR)
$(INSTALL) -Cm 0644 include/baresip.h $(DESTDIR)$(INCDIR)
@mkdir -p $(DESTDIR)$(LIBDIR) $(DESTDIR)$(LIBDIR)/pkgconfig
$(INSTALL) -m 0644 $(SHARED) $(DESTDIR)$(LIBDIR)
$(INSTALL) -m 0644 libbaresip.pc $(DESTDIR)$(LIBDIR)/pkgconfig
install-static: $(STATICLIB)
@mkdir -p $(DESTDIR)$(INCDIR)
$(INSTALL) -Cm 0644 include/baresip.h $(DESTDIR)$(INCDIR)
@mkdir -p $(DESTDIR)$(LIBDIR)
$(INSTALL) -m 0644 $(STATICLIB) $(DESTDIR)$(LIBDIR)
uninstall:
@rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
@rm -rf $(DESTDIR)$(MOD_PATH)
@rm -f $(DESTDIR)$(PREFIX)/lib/$(SHARED)
@rm -f $(DESTDIR)$(PREFIX)/lib/$(STATICLIB)
@rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/libbaresip.pc
.PHONY: clean
clean:
@rm -rf $(BIN) $(MOD_BINS) $(SHARED) $(BUILD) $(TEST_BIN) \
$(STATICLIB) libbaresip.pc
@rm -f *stamp \
`find . -name "*.[od]"` \
`find . -name "*~"` \
`find . -name "\.\#*"`
.PHONY: ccheck
ccheck:
@test/ccheck.py $(MOD_CCHECK_OPT)
version:
@perl -pi -e 's/BARESIP_VERSION.*/BARESIP_VERSION \"$(VERSION)"/' \
include/baresip.h
@perl -pi -e "s/PROJECT_NUMBER = .*/\
PROJECT_NUMBER = $(VERSION)/" \
mk/Doxyfile
@echo "updating version number to $(VERSION)"
src/static.c: $(BUILD) Makefile $(APP_MK) $(MOD_MK)
@echo " SH $@"
@echo "/* static.c - autogenerated by makefile */" > $@
@echo "#include <re_types.h>" >> $@
@echo "#include <re_mod.h>" >> $@
@echo "" >> $@
@for n in $(MODULES); do \
echo "extern const struct mod_export exports_$${n};" >> $@ ; \
done
@echo "" >> $@
@echo "const struct mod_export *mod_table[] = {" >> $@
@for n in $(MODULES); do \
echo " &exports_$${n}," >> $@ ; \
done
@echo " NULL" >> $@
@echo "};" >> $@
bareinfo: info
@echo " LIBREM_PATH: $(LIBREM_PATH)"
@echo " LIBREM_INC: $(LIBREM_INC)"
@echo " LIBREM_SO: $(LIBREM_SO)"