APP := lib$(PROJECT)_$(MARCH).$(EXT)

# SRTP (Default: enabled)
ifeq ($(SRTP),no)
	LIBSRTP_CFLAGS := -DHAVE_SRTP=0
else
	LIBSRTP_CFLAGS := -DHAVE_SRTP=1
	LIBSRTP_LDFLAGS := -lsrtp
endif

THIRDPARTIES_INC := ../thirdparties/android/include
CFLAGS := $(CFLAGS_LIB) -I$(THIRDPARTIES_INC) $(LIBSRTP_CFLAGS) -I../tinySAK/src -I../tinyNET/src -I./include -I../tinyMEDIA/include
LDFLAGS := $(LDFLAGS_LIB) $(LIBSRTP_LDFLAGS) -ltinySAK_$(MARCH) -ltinyNET_$(MARCH) -ltinyMEDIA_$(MARCH)

all: $(APP)

OBJS = \
	src/trtp.o \
	src/trtp_manager.o \
	src/trtp_srtp.o
	
## RTCP
OBJS += src/rtcp/trtp_rtcp_header.o \
	src/rtcp/trtp_rtcp_packet.o \
	src/rtcp/trtp_rtcp_rblock.o \
	src/rtcp/trtp_rtcp_report.o \
	src/rtcp/trtp_rtcp_report_bye.o \
	src/rtcp/trtp_rtcp_report_fb.o \
	src/rtcp/trtp_rtcp_report_rr.o \
	src/rtcp/trtp_rtcp_report_sdes.o \
	src/rtcp/trtp_rtcp_report_sr.o \
	src/rtcp/trtp_rtcp_report_xr.o \
	src/rtcp/trtp_rtcp_sdes_chunck.o \
	src/rtcp/trtp_rtcp_sdes_item.o \
	src/rtcp/trtp_rtcp_session.o

## RTP
OBJS += src/rtp/trtp_rtp_header.o \
	src/rtp/trtp_rtp_packet.o \
	src/rtp/trtp_rtp_session.o
	

$(APP): $(OBJS)
ifeq ($(EXT), a)
	$(AR) rcs $@ $^
else
	$(CC) $(LDFLAGS) -o $@ $^
endif

%.o: %.c
	$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
	
install: $(APP)
	$(ANDROID_SDK_ROOT)/tools/adb remount
	$(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(LIB_DIR)/$(APP)
	$(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(LIB_DIR)/$(APP)
	
clean:
	@rm -f $(OBJS) $(APP)