ARCH=@ARCH@
CC=@CC@
CXX=@CXX@

DVDNAV_A = $(DVD_PREFIX)/usr/lib/libdvdnav.a
DVDREAD_A = $(DVD_PREFIX)/usr/lib/libdvdread.a
DVDCSS_A = $(DVD_PREFIX)/usr/lib/libdvdcss.a

WRAPPER = @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
WRAPPER_DEF = @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def

SO_LDFLAGS = $(LDFLAGS) -shared -fPIC -rdynamic

SYSDIR = @abs_top_srcdir@/system/players/VideoPlayer
SOS = libdvdcss-$(ARCH).so libdvdnav-$(ARCH).so
SLIB = $(addprefix $(SYSDIR)/, $(SOS))

all: $(SLIB)

$(SYSDIR)/libdvdcss-$(ARCH).so: $(WRAPPER) $(WRAPPER_DEF) $(DVDCSS_A)
	mkdir -p libdvdcss; cd libdvdcss; $(AR) x $(DVDCSS_A)
	$(CC) -o $@ $(SO_LDFLAGS) -Wl,--soname,$@ libdvdcss/*.o -Wl,--unresolved-symbols=ignore-all -lm \
                `cat $(WRAPPER_DEF)` $(WRAPPER)

$(SYSDIR)/libdvdnav-$(ARCH).so: $(WRAPPER) $(WRAPPER_DEF) $(DVDNAV_A) $(DVDREAD_A) $(DVDCSS_A)
	mkdir -p libdvdread; cd libdvdread; $(AR) x $(DVDREAD_A)
	mkdir -p libdvdnav; cd libdvdnav; $(AR) x $(DVDNAV_A)
	mkdir -p libdvdcss; cd libdvdcss; $(AR) x $(DVDCSS_A)
	$(CC) -o $@ $(SO_LDFLAGS) -Wl,--soname,$@ libdvdread/*.o libdvdnav/*.o libdvdcss/*.o -lm -Wl,--unresolved-symbols=ignore-all \
                `cat  $(WRAPPER_DEF)` $(WRAPPER)

$(WRAPPER_DEF):
	$(MAKE) -C @abs_top_srcdir@/xbmc/cores/DllLoader/exports wrapper.def

