include bootstrap.mk

null :=
space := ${null} ${null}
${space} := ${space}

AUTOGENERATED_MAKEFILES=@OUTPUT_FILES@

EC_DIRS= \
	tools/EventClients

DVDPCODECS_DIRS= \
	lib \
	lib/libdvd 

ifeq (@USE_LIBSTAGEFRIGHT@,1)
DVDPCODECS_DIRS += xbmc/cores/dvdplayer/DVDCodecs/Video/libstagefrightICS
endif

DVDPLAYER_ARCHIVES=xbmc/cores/dvdplayer/DVDPlayer.a \
                   xbmc/cores/dvdplayer/DVDCodecs/DVDCodecs.a \
                   xbmc/cores/dvdplayer/DVDCodecs/Audio/Audio.a \
                   xbmc/cores/dvdplayer/DVDCodecs/Overlay/Overlay.a \
                   xbmc/cores/dvdplayer/DVDCodecs/Video/Video.a \
                   xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxers.a \
                   xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreams.a \
                   xbmc/cores/dvdplayer/DVDSubtitles/DVDSubtitles.a

DIRECTORY_ARCHIVES=$(DVDPLAYER_ARCHIVES) \
                   xbmc/addons/addons.a \
                   xbmc/cdrip/cdrip.a \
                   xbmc/contrib/kissfft/kissfft.a \
                   xbmc/cores/AudioEngine/audioengine.a \
                   xbmc/cores/DllLoader/dllloader.a \
                   xbmc/cores/DllLoader/exports/exports.a \
                   xbmc/cores/DllLoader/exports/util/exports_utils.a \
                   xbmc/cores/ExternalPlayer/ExternalPlayer.a \
                   xbmc/cores/VideoRenderers/VideoRenderer.a \
                   xbmc/cores/VideoRenderers/VideoShaders/VideoShaders.a \
                   xbmc/cores/cores.a \
                   xbmc/cores/paplayer/paplayer.a \
                   xbmc/cores/playercorefactory/playercorefactory.a \
                   xbmc/dbwrappers/dbwrappers.a \
                   xbmc/dialogs/dialogs.a \
                   xbmc/epg/epg.a \
                   xbmc/events/events.a \
                   xbmc/filesystem/MusicDatabaseDirectory/musicdatabasedirectory.a \
                   xbmc/filesystem/VideoDatabaseDirectory/videodatabasedirectory.a \
                   xbmc/filesystem/filesystem.a \
                   xbmc/guilib/guilib.a \
                   xbmc/input/input.a \
                   xbmc/interfaces/builtins/builtins.a \
                   xbmc/interfaces/generic/interfaces-generic.a \
                   xbmc/interfaces/info/info.a \
                   xbmc/interfaces/interfaces.a \
                   xbmc/interfaces/json-rpc/json-rpc.a \
                   xbmc/interfaces/legacy/legacy.a \
                   xbmc/interfaces/python/python_binding.a \
                   xbmc/linux/linux.a \
                   xbmc/listproviders/listproviders.a \
                   xbmc/main/posix/MessagePrinter.a \
                   xbmc/media/media.a \
                   xbmc/messaging/messaging.a \
                   xbmc/messaging/helpers/messagingHelpers.a \
                   xbmc/music/dialogs/musicdialogs.a \
                   xbmc/music/infoscanner/musicscanner.a \
                   xbmc/music/music.a \
                   xbmc/music/tags/musictags.a \
                   xbmc/music/windows/musicwindows.a \
                   xbmc/network/dacp/dacp.a \
                   xbmc/network/websocket/websocket.a \
                   xbmc/network/network.a \
                   xbmc/peripherals/bus/peripheral-bus.a \
                   xbmc/peripherals/devices/peripheral-devices.a \
                   xbmc/peripherals/dialogs/peripheral-dialogs.a \
                   xbmc/peripherals/peripherals.a \
                   xbmc/pictures/pictures.a \
                   xbmc/playlists/playlists.a \
                   xbmc/powermanagement/powermanagement.a \
                   xbmc/profiles/profiles.a \
                   xbmc/profiles/dialogs/profiles_dialogs.a \
                   xbmc/profiles/windows/profiles_windows.a \
                   xbmc/programs/programs.a \
                   xbmc/pvr/addons/pvraddons.a \
                   xbmc/pvr/channels/pvrchannels.a \
                   xbmc/pvr/dialogs/pvrdialogs.a \
                   xbmc/pvr/pvr.a \
                   xbmc/pvr/recordings/pvrrecordings.a \
                   xbmc/pvr/timers/pvrtimers.a \
                   xbmc/pvr/windows/pvrwindows.a \
                   xbmc/rendering/rendering.a \
                   xbmc/settings/settings.a \
                   xbmc/settings/dialogs/settings_dialogs.a \
                   xbmc/settings/lib/settings_lib.a \
                   xbmc/settings/windows/settings_windows.a \
                   xbmc/storage/storage.a \
                   xbmc/utils/utils.a \
                   xbmc/video/dialogs/videodialogs.a \
                   xbmc/video/jobs/video-jobs.a \
                   xbmc/video/videosync/videosync.a \
                   xbmc/video/video.a \
                   xbmc/video/windows/videowindows.a \
                   xbmc/view/view.a \
                   xbmc/windowing/windowing.a \
                   xbmc/windows/windows.a \
                   xbmc/xbmc.a \

NWAOBJSXBMC=	xbmc/threads/threads.a \
		xbmc/commons/commons.a


ifeq (@USE_WEB_SERVER@,1)
DIRECTORY_ARCHIVES += xbmc/interfaces/legacy/wsgi/legacy-wsgi.a
DIRECTORY_ARCHIVES += xbmc/network/httprequesthandler/httprequesthandlers.a
DIRECTORY_ARCHIVES += xbmc/network/httprequesthandler/python/httprequesthandlers-python.a
endif

ifeq (@USE_OPENGL@,1)
DIRECTORY_ARCHIVES += xbmc/rendering/gl/rendering_gl.a
endif

ifeq (@USE_OPENGLES@,1)
DIRECTORY_ARCHIVES += xbmc/rendering/gles/rendering_gles.a
DIRECTORY_ARCHIVES += xbmc/windowing/egl/windowing_egl.a
endif

ifeq (@USE_UPNP@,1)
DIRECTORY_ARCHIVES += lib/libUPnP/libupnp.a \
                      xbmc/network/upnp/upnp.a
endif

ifeq (@USE_MDNSEMBEDDED@,1)
DIRECTORY_ARCHIVES += xbmc/network/mdns/mdns.a
endif

ifeq ($(findstring osx,@ARCH@),osx)
DIRECTORY_ARCHIVES += xbmc/osx/osx.a
DIRECTORY_ARCHIVES += xbmc/network/osx/network.a
DIRECTORY_ARCHIVES += xbmc/network/linux/network_linux.a
DIRECTORY_ARCHIVES += xbmc/powermanagement/osx/powermanagement.a
DIRECTORY_ARCHIVES += xbmc/storage/osx/storage.a
DIRECTORY_ARCHIVES += xbmc/windowing/osx/windowing_osx.a
INSTALL_FILTER += .*repository\.pvr-android\.xbmc\.org.*
INSTALL_FILTER += .*repository\.pvr-ios\.xbmc\.org.*
INSTALL_FILTER += .*repository\.pvr-win32\.xbmc\.org.*
else
INSTALL_FILTER += .*repository\.pvr-ios\.xbmc\.org.*
INSTALL_FILTER += .*repository\.pvr-win32\.xbmc\.org.*
INSTALL_FILTER += .*repository\.pvr-osx.*\.xbmc\.org.*
ifeq (@USE_ANDROID@,1)
DIRECTORY_ARCHIVES += xbmc/input/linux/input_linux.a
DIRECTORY_ARCHIVES += xbmc/input/touch/input_touch.a
DIRECTORY_ARCHIVES += xbmc/input/touch/generic/input_touch_generic.a
DIRECTORY_ARCHIVES += xbmc/network/linux/network_linux.a
DIRECTORY_ARCHIVES += xbmc/powermanagement/android/powermanagement_android.a
DIRECTORY_ARCHIVES += xbmc/storage/android/storage_android.a
DIRECTORY_ARCHIVES += xbmc/windowing/X11/windowing_X11.a
else
DIRECTORY_ARCHIVES += xbmc/input/linux/input_linux.a
DIRECTORY_ARCHIVES += xbmc/input/touch/input_touch.a
DIRECTORY_ARCHIVES += xbmc/input/touch/generic/input_touch_generic.a
DIRECTORY_ARCHIVES += xbmc/network/linux/network_linux.a
DIRECTORY_ARCHIVES += xbmc/powermanagement/linux/powermanagement_linux.a
DIRECTORY_ARCHIVES += xbmc/storage/linux/storage_linux.a
DIRECTORY_ARCHIVES += xbmc/windowing/X11/windowing_X11.a
INSTALL_FILTER += .*repository\.pvr-android\.xbmc\.org.*
endif
endif

ifeq ($(findstring freebsd,@ARCH@),freebsd)
DIRECTORY_ARCHIVES += xbmc/freebsd/freebsd.a
endif

ifeq (@HAVE_XBMC_NONFREE@,1)
DIRECTORY_ARCHIVES += lib/UnrarXLib/UnrarXLib.a
endif

ifeq (@USE_ANDROID@,1)
DIRECTORY_ARCHIVES += xbmc/android/loader/AndroidDyload.a
DIRECTORY_ARCHIVES += xbmc/windowing/android/windowing_android.a
DIRECTORY_ARCHIVES += xbmc/android/bionic_supplement/bionic_supplement.a
DIRECTORY_ARCHIVES += xbmc/android/jni/jni.a
endif

ifeq (@USE_OMXPLAYER@,1)
DIRECTORY_ARCHIVES += xbmc/cores/omxplayer/omxplayer.a
endif

LIB_DIRS=\
	lib/cximage-6.0 \
	lib/libexif \
	lib/cpluff \
	lib/xbmc-dll-symbols

LIBADDON_DIRS=\
	lib/addons/library.xbmc.addon \
	lib/addons/library.kodi.adsp \
	lib/addons/library.kodi.audioengine \
	lib/addons/library.xbmc.codec \
	lib/addons/library.xbmc.pvr \
	lib/addons/library.kodi.guilib \

CONFLUENCE_MEDIA=addons/skin.confluence/media
SKIN_DIRS=$(CONFLUENCE_MEDIA)

ifeq (@USE_TOUCH_SKIN@,1)
TOUCH_SKIN_MEDIA=addons/skin.re-touched/media
SKIN_DIRS+=$(TOUCH_SKIN_MEDIA)
endif

LIBS=@LIBS@
CFLAGS=@CFLAGS@
CXXFLAGS=@CXXFLAGS@
LDFLAGS=@LDFLAGS@
INCLUDES=$(sort @INCLUDES@)

CLEAN_FILES=@APP_NAME_LC@.bin @APP_NAME_LC@-xrandr lib@APP_NAME_LC@.so

DISTCLEAN_FILES=config.h config.log config.status tools/Linux/@APP_NAME_LC@.sh \
        tools/Linux/@APP_NAME_LC@-standalone.sh autom4te.cache config.h.in~ \
        system/libcpluff-@ARCH@.so

ifeq (@USE_LIBXBMC@,1)
FINAL_TARGETS+=lib@APP_NAME_LC@.so
ifeq (@USE_ANDROID@,1)
FINAL_TARGETS+=skins
endif
else
FINAL_TARGETS=@APP_NAME_LC@.bin skins @APP_NAME_LC@-xrandr
endif
FINAL_TARGETS+=Makefile externals

GTEST_DIR = lib/gtest
GTEST_INCLUDES = -I$(GTEST_DIR)/include
GTEST_LIBS = $(GTEST_DIR)/lib/.libs/libgtest.a

CHECK_DIRS = xbmc/addons/test \
             xbmc/filesystem/test \
             xbmc/music/tags/test \
             xbmc/network/test \
             xbmc/utils/test \
             xbmc/video/test \
             xbmc/threads/test \
             xbmc/interfaces/python/test \
             xbmc/cores/AudioEngine/Sinks/test \
             xbmc/test
CHECK_LIBS = xbmc/addons/test/addonsTest.a \
             xbmc/filesystem/test/filesystemTest.a \
             xbmc/music/tags/test/tagsTest.a \
             xbmc/network/test/networkTest.a \
             xbmc/utils/test/utilsTest.a \
             xbmc/video/test/videoTest.a \
             xbmc/threads/test/threadTest.a \
             xbmc/interfaces/python/test/pythonSwigTest.a \
             xbmc/cores/AudioEngine/Sinks/test/AESinkTest.a \
             xbmc/test/xbmc-test.a

ifeq (@USE_WAYLAND@,1)
CHECK_LIBS += xbmc/windowing/tests/wayland/test_wayland.a

ifeq (@USE_WAYLAND_TEST_EXTENSION@,1)
WAYLAND_TEST_MODULE = xbmc/windowing/tests/wayland/xbmc-wayland-test-extension.so
$(WAYLAND_TEST_MODULE): force
	$(MAKE) -C $(@D) $(@F)
CHECK_EXTENSIONS = $(WAYLAND_TEST_MODULE)
CHECK_LIBADD=@WAYLAND_TEST_LIBS@
endif
endif

ifeq (@USE_SSE4@,1)
LIBSSE4+=sse4
sse4 : force
	$(MAKE) -C xbmc/linux/sse4
endif

CHECK_PROGRAMS = @APP_NAME_LC@-test

CLEAN_FILES += $(CHECK_PROGRAMS) $(CHECK_EXTENSIONS)

all : $(FINAL_TARGETS)
	@echo '-----------------------'
	@echo '@APP_NAME@ built successfully'
	@echo '-----------------------'

include Makefile.include

.PHONY : dllloader exports eventclients \
	dvdpcodecs dvdpextcodecs imagelib codecs externals force skins libaddon check \
	testframework testsuite

# hack targets to keep build system up to date
Makefile : config.status $(addsuffix .in, $(AUTOGENERATED_MAKEFILES))
	@echo "Regenerating Makefiles..."
	@./config.status &> /dev/null
	@echo "done"

config.status: configure

# skin textures
ifeq (@USE_TEXTUREPACKER@,1)
skins: @TEXTUREPACKER@
	 $(MAKE) -C $(CONFLUENCE_MEDIA)
ifeq (@USE_TOUCH_SKIN@,1)
	 $(MAKE) -C $(TOUCH_SKIN_MEDIA)
endif
else
skins:
endif

# Setup some dependencies for subdir makes
xbmc/cores/paplayer/paplayer.a:
$(DVDPLAYER_ARCHIVES)         : dvdpcodecs

lib/cpluff/libcpluff/.libs/libcpluff.a: force
	$(MAKE) -C lib/cpluff/libcpluff
system/libcpluff-@ARCH@.so: lib/cpluff/libcpluff/.libs/libcpluff.a exports
ifeq ($(findstring osx,@ARCH@), osx)
  ifeq (@ARCH@, arm-osx)
	$(CXX) $(LDFLAGS) -all_load -bundle -flat_namespace -undefined dynamic_lookup -read_only_relocs suppress -o $@ $<
  else
	$(CXX) $(LDFLAGS) -all_load -bundle -flat_namespace -undefined dynamic_lookup -lexpat $(BUNDLE1_O) -o $@ $<
  endif
else
	$(CXX) $(LDFLAGS) -shared -o $@ -Wl,--whole-archive $< \
		-Wl,--no-whole-archive  \
		`cat xbmc/cores/DllLoader/exports/wrapper.def` xbmc/cores/DllLoader/exports/wrapper.o -lexpat
endif

exports: xbmc/cores/DllLoader/exports/exports.a xbmc/cores/DllLoader/exports/util/exports_utils.a
	$(MAKE) -C xbmc/cores/DllLoader/exports wrapper.def
dllloader: exports xbmc/cores/DllLoader/dllloader.a

libaddon: exports
	$(MAKE) -C lib/addons/library.xbmc.addon
	$(MAKE) -C lib/addons/library.kodi.adsp
	$(MAKE) -C lib/addons/library.kodi.audioengine
	$(MAKE) -C lib/addons/library.xbmc.codec
	$(MAKE) -C lib/addons/library.kodi.guilib
	$(MAKE) -C lib/addons/library.xbmc.pvr
dvdpcodecs: dllloader
	$(MAKE) -C lib/libdvd

ifeq (@USE_LIBSTAGEFRIGHT@,1)
dvdpextcodecs: lib@APP_NAME_LC@.so
	$(MAKE) -C xbmc/cores/dvdplayer/DVDCodecs/Video/libstagefrightICS
else
dvdpextcodecs:
endif

eventclients:
ifeq ($(findstring osx,@ARCH@), osx)
ifneq ($(findstring arm,@ARCH@), arm)
	$(MAKE) -C tools/EventClients/Clients/OSXRemote
endif
else
	$(MAKE) -C tools/EventClients
endif
libexif: dllloader
	$(MAKE) -C lib/libexif

imagelib: dllloader
	$(MAKE) -C lib/cximage-6.0

codecs: dvdpcodecs dvdpextcodecs

libs: $(LIBSSE4) imagelib libexif system/libcpluff-@ARCH@.so

externals: codecs libs libaddon

xcode_depends: \
	codecs libs eventclients skins libaddon

DYNOBJSXBMC= \
	xbmc/linux/linux.a \
	xbmc/network/network.a \
	xbmc/video/windows/videowindows.a \
	xbmc/utils/utils.a \
	xbmc/cores/DllLoader/exports/util/exports_utils.a \
	xbmc/cores/DllLoader/exports/exports.a \
	xbmc/settings/settings.a \
	xbmc/video/video.a \
	xbmc/pvr/addons/pvraddons.a \
	xbmc/pvr/windows/pvrwindows.a \
	xbmc/guilib/guilib.a # must be dynamic to avoid linker errors

ifeq ($(findstring freebsd,@ARCH@),freebsd)
DYNOBJSXBMC+= xbmc/freebsd/freebsd.a
endif

ifeq (@USE_STATIC_FFMPEG@,1)
FFMPEGOBJS = @FFMPEG_LIBDIR@/libavcodec.a \
             @FFMPEG_LIBDIR@/libavfilter.a \
             @FFMPEG_LIBDIR@/libswresample.a \
             @FFMPEG_LIBDIR@/libavformat.a \
             @FFMPEG_LIBDIR@/libavutil.a \
             @FFMPEG_LIBDIR@/libpostproc.a \
             @FFMPEG_LIBDIR@/libswscale.a
DYNOBJSXBMC+= $(FFMPEGOBJS)
LIBS+= @GNUTLS_ALL_LIBS@ @VORBISENC_ALL_LIBS@ @DCADEC_ALL_LIBS@

$(FFMPEGOBJS): dvdpcodecs
endif

ifeq (@USE_ANDROID@,1)
MAINOBJS+=xbmc/android/activity/activity.a
else
MAINOBJS+=xbmc/main/main.a
endif # USE_ANDROID


OBJSXBMC =$(DIRECTORY_ARCHIVES)
OBJSXBMC:=$(filter-out $(DYNOBJSXBMC), $(OBJSXBMC))

BIN_DIRS = $(dir $(DIRECTORY_ARCHIVES)) $(dir $(NWAOBJSXBMC)) $(dir $(MAINOBJS))

DIRS= $(BIN_DIRS) $(EC_DIRS) $(DVDPCODECS_DIRS) \
	$(LIB_DIRS) $(LIBADDON_DIRS) $(SKIN_DIRS) xbmc/main

$(NWAOBJSXBMC) $(DIRECTORY_ARCHIVES) $(MAINOBJS): force
	@$(MAKE) $(if $(V),,-s) -C $(@D)

# Binary Addon bindings
include xbmc/addons/addon-bindings.mk

lib@APP_NAME_LC@.so: $(OBJSXBMC) $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(MAINOBJS)
ifeq ($(findstring osx,@ARCH@), osx)
	$(SILENT_LD) $(CXX) $(LDFLAGS) -bundle -o $@ $(MAINOBJS) -Wl,-all_load,-ObjC $(MAINOBJS) $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(OBJSXBMC) $(LIBS) -read_only_relocs suppress
else
	$(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ -Wl,--whole-archive $(MAINOBJS) -Wl,--no-whole-archive,--start-group $(MAINOBJS) $(DYNOBJSXBMC) $(OBJSXBMC) -Wl,--end-group -Wl,--no-undefined $(NWAOBJSXBMC) $(LIBS) -Wl,-Bsymbolic
endif

@APP_NAME_LC@.bin: $(OBJSXBMC) $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(MAINOBJS)

ifeq ($(findstring osx,@ARCH@), osx)
	$(SILENT_LD) $(CXX) $(LDFLAGS) -o @APP_NAME_LC@.bin $(MAINOBJS) -Wl,-all_load,-ObjC $(MAINOBJS) $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(OBJSXBMC) $(LIBS) -rdynamic
else
	$(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o @APP_NAME_LC@.bin $(MAINOBJS) -Wl,--start-group $(MAINOBJS) $(DYNOBJSXBMC) $(OBJSXBMC) -Wl,--end-group $(NWAOBJSXBMC) $(LIBS) -rdynamic
endif

@APP_NAME_LC@-xrandr: xbmc-xrandr.c
ifneq (1,@USE_X11@)
	# xbmc-xrandr.c gets picked up by the default make rules
	@echo "excluding @APP_NAME_LC@-xrandr"
else
	$(SILENT_LD) $(CC) $(CFLAGS) $(LDFLAGS) -o @APP_NAME_LC@-xrandr xbmc-xrandr.c -lXrandr -lX11 -lm
endif


install-bin: @APP_NAME_LC@.bin # developement convenience target
	sudo install -d $(DESTDIR)$(libdir)
	sudo install @APP_NAME_LC@.bin $(DESTDIR)$(libdir)/@APP_NAME_LC@

ifeq ($(findstring osx,@ARCH@), osx)
	# TODO: add osx install
else
install: install-binaries install-arch install-datas

apk obb apk-unsigned apk-obb apk-obb-unsigned apk-noobb: install
	make -C tools/android/packaging $@

apk-clean apk-sign:
	make -C tools/android/packaging $@

install-binaries: install-scripts
	@echo "Copying @APP_NAME_LC@ binary to $(DESTDIR)$(libdir)/@APP_NAME_LC@/"
	@install -d $(DESTDIR)$(libdir)/@APP_NAME_LC@
	@cd $(DESTDIR)$(libdir); [ -L xbmc ] || [ -d xbmc ] || ln -s @APP_NAME_LC@ xbmc
ifeq (1,@USE_X11@)
	@install @APP_NAME_LC@-xrandr $(DESTDIR)$(libdir)/@APP_NAME_LC@/@APP_NAME_LC@-xrandr
endif
ifeq (@USE_LIBXBMC@,1)
	@install lib@APP_NAME_LC@.so $(DESTDIR)$(libdir)/@APP_NAME_LC@/lib@APP_NAME_LC@.so
else
	@install @APP_NAME_LC@.bin $(DESTDIR)$(libdir)/@APP_NAME_LC@/@APP_NAME_LC@.bin
	@echo "You can run @APP_NAME_LC@ with the command '@APP_NAME_LC@'"
endif
endif

install-arch:
	@# Arch dependent files
ifeq ($(findstring freebsd,@ARCH@), freebsd)
	@find -E system addons -type f -not -iregex ".*\.git.*" \
		-iregex ".*@ARCH@.*|.*\.vis|.*\.xbs" \
		-exec sh -c "install -d \"$(DESTDIR)$(libdir)/@APP_NAME_LC@/\`dirname '{}'\`\"" \; \
		-and \
		-exec install "{}" $(DESTDIR)$(libdir)/@APP_NAME_LC@/"{}" \; \
		-exec printf " -- %-75.75s\r" "{}" \;
else
ifeq ($(findstring Darwin,$(shell uname -s)),Darwin)
	@find -E system addons -type f -not -iregex ".*\.git.*" \
		-iregex ".*@ARCH@.*|.*\.vis|.*\.xbs" \
		-exec sh -c "install -d \"$(DESTDIR)$(libdir)/@APP_NAME_LC@/\`dirname '{}'\`\"" \; \
		-and \
		-exec install "{}" $(DESTDIR)$(libdir)/xbmc/"{}" \; \
		-exec printf " -- %-75.75s\r" "{}" \;
else
	@find system addons -regextype posix-extended -type f -not -iregex ".*\.git.*" -iregex ".*\.so|.*\.so\.[0-9].*|.*\.vis|.*\.xbs" -exec install -D "{}" $(DESTDIR)$(libdir)/@APP_NAME_LC@/"{}" \; -printf " -- %-75.75f\r"
	@find -L addons -regextype posix-extended -type f -not -iregex ".*\.git.*" -iregex ".*\.so|.*\.so\.[0-9].*" -exec cp -d "{}" $(DESTDIR)$(libdir)/@APP_NAME_LC@/"{}" \; -printf " -- %-75.75f\r"
endif
endif

install-scripts:
	@install -d $(DESTDIR)$(bindir)
	@install tools/Linux/@APP_NAME_LC@.sh $(DESTDIR)$(bindir)/@APP_NAME_LC@
	@cd $(DESTDIR)$(bindir); [ -L xbmc ] || [ -f xbmc ] || ln -s @APP_NAME_LC@ xbmc
	@install tools/Linux/@APP_NAME_LC@-standalone.sh $(DESTDIR)$(bindir)/@APP_NAME_LC@-standalone
	@cd $(DESTDIR)$(bindir); [ -L xbmc-standalone ] || [ -f xbmc-standalone ] ||  ln -s @APP_NAME_LC@-standalone xbmc-standalone
	@install -d $(DESTDIR)$(datarootdir)/@APP_NAME_LC@
	@cd $(DESTDIR)$(datarootdir); [ -L xbmc ] || [ -d xbmc ] || ln -s @APP_NAME_LC@ xbmc
	@install -d $(DESTDIR)$(datarootdir)/xsessions
	@install -m 0644 tools/Linux/@APP_NAME_LC@-xsession.desktop $(DESTDIR)$(datarootdir)/xsessions/@APP_NAME_LC@.desktop
	@cd $(DESTDIR)$(datarootdir)/xsessions; [ -L xbmc.desktop ] || [ -f xbmc.desktop ] || ln -s @APP_NAME_LC@.desktop xbmc.desktop

install-datas: install-scripts
	@echo "Copying support and legal files..."
	@install -d $(DESTDIR)$(docdir)
	@for FILE in `ls LICENSE.GPL *.txt`; do \
		install -m 0644 "$$FILE" "$(DESTDIR)$(docdir)/$$FILE"; done
	@install -m 0644 "docs/README.linux" "$(DESTDIR)$(docdir)/README.linux"
	@echo "Done!"
	@echo "Copying system files to $(DESTDIR)$(datarootdir)/@APP_NAME_LC@"
	@install -d $(DESTDIR)$(datarootdir)/@APP_NAME_LC@
	@# Arch independent files
ifeq ($(findstring bsd,@ARCH@), bsd)
	@find -E addons media userdata system -type f \
		-not -iregex ".*-@ARCH@.*|.*\.vis|.*\.xbs|.*\.git.*|.*\.so|.*\.so\.[0-9].*|.*\.dll|$(subst ${space},|,$(INSTALL_FILTER))" \
		-exec sh -c "install -d \"$(DESTDIR)$(datarootdir)/@APP_NAME_LC@/\`dirname '{}'\`\"" \; \
		-and \
		-exec install -m 0644 "{}" $(DESTDIR)$(datarootdir)/@APP_NAME_LC@/"{}" \; \
		-exec printf " -- %-75.75s\r" "{}" \;
else
ifeq ($(findstring Darwin,$(shell uname -s)),Darwin)
	@find -E addons media userdata system -type f \
		-not -iregex ".*-@ARCH@.*|.*\.vis|.*\.xbs|.*\.git.*|.*\.so|.*\.so\.[0-9].*|.*\.dll|$(subst ${space},|,$(INSTALL_FILTER))" \
		-exec sh -c "install -d \"$(DESTDIR)$(datarootdir)/xbmc/\`dirname '{}'\`\"" \; \
		-and \
		-exec install -m 0644 "{}" $(DESTDIR)$(datarootdir)/xbmc/"{}" \; \
		-exec printf " -- %-75.75s\r" "{}" \;
else
	@find addons media userdata system -regextype posix-extended -type f -not -iregex ".*-@ARCH@.*|.*\.vis|.*\.xbs|.*\.git.*|.*\.so|.*\.so\.[0-9].*|.*\.dll|$(subst ${space},|,$(INSTALL_FILTER))" -exec install -D -m 0644 "{}" $(DESTDIR)$(datarootdir)/@APP_NAME_LC@/"{}" \; -printf " -- %-75.75f\r"
endif
endif
	@# Icons and links
	@install -d $(DESTDIR)$(datarootdir)/applications
	@install -m 0644 tools/Linux/@APP_NAME_LC@.desktop $(DESTDIR)$(datarootdir)/applications/@APP_NAME_LC@.desktop

	@install -d $(DESTDIR)$(datadir)/icons/hicolor/16x16/apps
	@install -m 0644 tools/Linux/packaging/media/icon16x16.png $(DESTDIR)$(datadir)/icons/hicolor/16x16/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/22x22/apps
	@install -m 0644 tools/Linux/packaging/media/icon22x22.png $(DESTDIR)$(datadir)/icons/hicolor/22x22/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/24x24/apps
	@install -m 0644 tools/Linux/packaging/media/icon24x24.png $(DESTDIR)$(datadir)/icons/hicolor/24x24/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/32x32/apps
	@install -m 0644 tools/Linux/packaging/media/icon32x32.png $(DESTDIR)$(datadir)/icons/hicolor/32x32/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/48x48/apps
	@install -m 0644 tools/Linux/packaging/media/icon48x48.png $(DESTDIR)$(datadir)/icons/hicolor/48x48/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/64x64/apps
	@install -m 0644 tools/Linux/packaging/media/icon64x64.png $(DESTDIR)$(datadir)/icons/hicolor/64x64/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/128x128/apps
	@install -m 0644 tools/Linux/packaging/media/icon128x128.png $(DESTDIR)$(datadir)/icons/hicolor/128x128/apps/@APP_NAME_LC@.png
	@install -d $(DESTDIR)$(datadir)/icons/hicolor/256x256/apps
	@install -m 0644 tools/Linux/packaging/media/icon256x256.png $(DESTDIR)$(datadir)/icons/hicolor/256x256/apps/@APP_NAME_LC@.png

	@test -z "$(DESTDIR)" && gtk-update-icon-cache -f -q -t $(datadir)/icons/hicolor || :

	@echo "Copying bindings to $(DESTDIR)$(includedir)/@APP_NAME_LC@"
	@install -d $(DESTDIR)$(includedir)/@APP_NAME_LC@
	@for f in $(BINDINGS); do \
	  install -m 0644 $$f $(DESTDIR)$(includedir)/@APP_NAME_LC@ ; \
	done
	@for f in project/cmake/*.cmake; do \
	  install -m 0644 $$f $(DESTDIR)$(libdir)/@APP_NAME_LC@; \
	done
	@for f in project/cmake/scripts/common/*.cmake; do \
	  install -m 0644 $$f $(DESTDIR)$(libdir)/@APP_NAME_LC@; \
	done
	@cd $(DESTDIR)$(includedir); [ -L xbmc ] || [ -d xbmc ] || ln -s @APP_NAME_LC@ xbmc

uninstall:
	@echo "Removing @APP_NAME@..."
	@rm -rf $(DESTDIR)$(libdir)/@APP_NAME_LC@
	@rm -rf $(DESTDIR)$(datarootdir)/@APP_NAME_LC@ $(DESTDIR)$(bindir)/@APP_NAME_LC@
	@rm -rf $(DESTDIR)$(bindir)/@APP_NAME_LC@-standalone
	@rm -rf $(DESTDIR)$(datarootdir)/xsessions/@APP_NAME_LC@.desktop
	@rm -rf $(libdir)/lib@APP_NAME_LC@_*
	@rm -rf $(prefix)/include/@APP_NAME_LC@
	@echo "Done!"

clean-@APP_NAME_LC@.bin:
	rm -f @APP_NAME_LC@.bin
	for d in $(BIN_DIRS); do if test -f $$d/Makefile; then $(MAKE) -C $$d clean; fi; done
clean-eventclients:
	for d in $(EC_DIRS); do if test -f $$d/Makefile; then $(MAKE) -C $$d clean; fi; done
clean-dvdpcodecs:
	for d in $(DVDPCODECS_DIRS); do if test -f $$d/Makefile; then $(MAKE) -C $$d clean; fi; done
clean-libs:
	for d in $(LIB_DIRS); do if test -f $$d/Makefile; then $(MAKE) -C $$d clean; fi; done
clean-libaddons:
	for d in $(LIBADDON_DIRS); do if test -f $$d/Makefile; then $(MAKE) -C $$d clean; fi; done

clean-codecs: clean-dvdpcodecs

clean-externals: clean-codecs clean-eventclients clean-libs \
	clean-libaddons

ifeq (1,@GTEST_CONFIGURED@)
check: testsuite
	for check_program in $(CHECK_PROGRAMS); do $(CURDIR)/$$check_program; done

testsuite: $(CHECK_EXTENSIONS) $(CHECK_PROGRAMS)

testframework: $(GTEST_LIBS)

$(GTEST_LIBS): $(GTEST_DIR)/Makefile

$(GTEST_DIR)/Makefile: force
	$(MAKE) CXXFLAGS="$(CXXFLAGS) -DGTEST_USE_OWN_TR1_TUPLE=1" -C $(GTEST_DIR)

$(CHECK_LIBS): force
	@$(MAKE) CXXFLAGS="$(CXXFLAGS) -DGTEST_USE_OWN_TR1_TUPLE=1" $(if $(V),,-s) -C $(@D)

@APP_NAME_LC@-test: $(CHECK_LIBS) $(OBJSXBMC) $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(GTEST_LIBS)
ifeq ($(findstring osx,@ARCH@), osx)
	$(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) $(GTEST_INCLUDES) -o $@ -Wl,-all_load,-ObjC $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(OBJSXBMC) $(GTEST_LIBS) $(CHECK_LIBS) $(LIBS) $(CHECK_LIBADD) -rdynamic
else
	$(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) $(GTEST_INCLUDES) -o $@ -Wl,--whole-archive $(DYNOBJSXBMC) $(OBJSXBMC) $(GTEST_LIBS) $(CHECK_LIBS) -Wl,--no-whole-archive $(NWAOBJSXBMC) $(LIBS) $(CHECK_LIBADD) -rdynamic
endif
else
# Give a message that the framework is not configured, but don't fail.
check testsuite testframework:
	@echo "Google Test Framework not configured, skipping testsuite check."
endif
