#! /usr/bin/make -f

build-npapi: fetch-npapi
	$(MAKE) install-npapi

fetch-npapi:
	rm -f -- stamp-npapi.tmp
	if test -d npapi-vlc; then \
		cd npapi-vlc && \
		git fetch origin && \
		git reset --hard origin/master; \
	else \
		git clone git://git.videolan.org/npapi-vlc.git npapi-vlc ; \
	fi
	git --git-dir=npapi-vlc/.git describe --long --always > stamp-npapi.tmp
	if diff stamp-npapi.tmp stamp-npapi >/dev/null 2>&1; then \
		rm -f -- stamp-npapi.tmp ; \
	else \
		mv -f -- stamp-npapi.tmp stamp-npapi ; \
	fi

stamp-npapi:
	$(MAKE) fetch-npapi

npapi-vlc/configure: stamp-npapi
	cd npapi-vlc && \
	$(SHELL) ./autogen.sh
	touch $@

npapi-vlc/Makefile: npapi-vlc/configure
	cd npapi-vlc && \
	$(SHELL) ./configure \
		--prefix=/ \
		--host=$(host_alias) --build=$(build_alias) \
		CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" \
		CC="$(CC)" CFLAGS="$(CFLAGS)" \
		CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
		LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
		SHELL="$(SHELL)" \
		PKG_CONFIG_PATH="$(libdir)/pkgconfig:$(CONTRIB_DIR)/lib/pkgconfig"
	touch $@

npapi-vlc/npapi/npvlc.la: npapi-vlc/Makefile
	$(MAKE) -C npapi-vlc

install-npapi: npapi-vlc/npapi/npvlc.la
	$(MAKE) -C npapi-vlc \
		DESTDIR="$(abs_builddir)/npapi-vlc/installed" install
