-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
115 lines (97 loc) · 3.37 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
# Generate version from RTMFP.h file
TMP=$(shell printf "%d" $(shell grep RTMFP_LIB_VERSION include/RTMFP.h | grep -o '\b0x\w*'))
MAJ=$(shell expr $(TMP) / 16777216)
INTER=$(shell expr \( $(TMP) - $(MAJ) \* 16777216 \) / 65536)
MIN=$(shell expr $(TMP) - $(MAJ) \* 16777216 - $(INTER) \* 65536)
VERSION="$(MAJ).$(INTER).$(MIN)"
prefix=/usr
LIBDIR=$(prefix)/lib/
ifeq ($(shell uname -m), x86_64)
ifneq "$(wildcard $(prefix)/lib64)" ""
LIBDIR="$(prefix)/lib64/"
else ifneq "$(wildcard $(prefix)/lib/x86_64-linux-gnu)" ""
LIBDIR="$(prefix)/lib/x86_64-linux-gnu/"
endif
endif
PKGCONFIGPATH=$(shell pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)
ifeq ($(PKGCONFIGPATH), )
PKGCONFIGPATH=$(LIBDIR)/pkgconfig
endif
# pkgconfig description variables
CRYPTO_REQ=libssl,libcrypto
PUBLIC_LIBS=
PRIVATE_LIBS=
# Constants
OS = $(shell uname -s)
ifeq ($(shell printf '\1' | od -dAn | xargs),1)
BIG_ENDIAN = 0
else
BIG_ENDIAN = 1
endif
# Variables with default values
GPP?=g++
# Variables extendable
override CFLAGS+=-D_GLIBCXX_USE_C99 -std=c++14 -D__BIG_ENDIAN__=$(BIG_ENDIAN) -D_FILE_OFFSET_BITS=64 -Wall -Wno-reorder -Wno-terminate -Wunknown-pragmas -Wno-unknown-warning-option -Wno-exceptions
ifeq ($(OS),FreeBSD)
CFLAGS+=-D_GLIBCXX_USE_C99
endif
override INCLUDES+=-I./include/
LIBS+=-Wl,-Bdynamic -lcrypto -lssl -lpthread
INCDIR=/usr/include/librtmfp/
# Variables fixed
ifeq ($(OS),Darwin)
LIBNAME=librtmfp.dylib
SHARED=-dynamiclib -install_name ./../LibRTMFP/$(LIB)
else
LIBNAME=librtmfp.so
AR=lib/librtmfp.a
SHARED=-shared
endif
LIB=lib/$(LIBNAME)
# Variables fixed
SOURCES = $(wildcard sources/*.cpp sources/Base/*.cpp)
OBJECT = $(SOURCES:sources/%.cpp=tmp/Release/%.o)
OBJECTD = $(SOURCES:sources/%.cpp=tmp/Debug/%.o)
.PHONY: debug release librtmfp.pc
release:
mkdir -p tmp/Release/Base
mkdir -p lib
@$(MAKE) -k $(OBJECT)
@echo creating dynamic lib $(LIB)
@$(GPP) $(CFLAGS) $(LIBDIRS) -fPIC $(SHARED) -o $(LIB) $(OBJECT) $(LIBS)
@if [ "$(OS)" != "Darwin" ]; then\
echo "creating static lib $(AR)";\
ar rcs $(AR) $(OBJECT);\
fi
debug:
mkdir -p tmp/Debug/Base
mkdir -p lib
@$(MAKE) -k $(OBJECTD)
@echo creating dynamic debug lib $(LIB)
@$(GPP) -g -D_DEBUG $(CFLAGS) $(LIBDIRS) -fPIC $(SHARED) -o $(LIB) $(OBJECTD) $(LIBS)
@if [ "$(OS)" != "Darwin" ]; then\
echo "creating static lib $(AR)";\
ar rcs $(AR) $(OBJECTD);\
fi
librtmfp.pc:
@echo "compiling librtmfp.pc.in with version $(VERSION)"
sed -e "s;@prefix@;$(prefix);" -e "s;@libdir@;$(LIBDIR);" \
-e "s;@VERSION@;$(VERSION);" \
-e "s;@CRYPTO_REQ@;$(CRYPTO_REQ);" \
-e "s;@PUBLIC_LIBS@;$(PUBLIC_LIBS);" \
-e "s;@PRIVATE_LIBS@;$(PRIVATE_LIBS);" librtmfp.pc.in > $@
install: librtmfp.pc
-mkdir -p $(INCDIR)
cp ./include/librtmfp.h $(INCDIR) && chmod 644 $(INCDIR)/librtmfp.h
cp $(LIB) $(LIBDIR) && chmod 755 $(LIBDIR)/$(LIBNAME)
test -d "$(PKGCONFIGPATH)" || mkdir -p "$(PKGCONFIGPATH)" && cp librtmfp.pc $(PKGCONFIGPATH) && chmod 644 $(PKGCONFIGPATH)/librtmfp.pc
$(OBJECT): tmp/Release/%.o: sources/%.cpp
@echo compiling $(@:tmp/Release/%.o=sources/%.cpp)
@$(GPP) $(CFLAGS) -fpic $(INCLUDES) -c -o $(@) $(@:tmp/Release/%.o=sources/%.cpp)
$(OBJECTD): tmp/Debug/%.o: sources/%.cpp
@echo compiling $(@:tmp/Debug/%.o=sources/%.cpp)
@$(GPP) -g -D_DEBUG $(CFLAGS) -fpic $(INCLUDES) -c -o $(@) $(@:tmp/Debug/%.o=sources/%.cpp)
clean:
@echo cleaning project librtmfp
@rm -f $(OBJECT) $(LIB)
@rm -f $(OBJECTD) $(LIB)