#-----------------------------------------------------------
# GOGGLES BUILD SYSTEM
#-----------------------------------------------------------
#
# The actual make file
#
#-----------------------------------------------------------

include config.make

# Set suffixes
.SUFFIXES:
.SUFFIXES: .cpp .h .gif .png $(OBJEXT) $(BINEXT) $(LIBEXT)

.PHONY : all clean realclean cleanicons install install-desktop

CPPFLAGS+=-I./include
INSTALL=install


# Convert to Platform specific names
#----------------------------------------------------------
BINNAME=src/musicmanager$(BINEXT)    						# XXX on Linux, X.exe on Windows

# Installation Directory
ifdef DESTDIR
INSTALLDIR=$(DESTDIR)$(PREFIX)
else
INSTALLDIR=$(PREFIX)
endif

all: $(BINNAME)

ifeq ($(BUILDIN_ICONS),1)
  ICONS := $(wildcard icons/16x16*) $(wildcard icons/22x22*) $(wildcard icons/32x32*) $(wildcard icons/24x24*)
  ICONS += icons/cover.png icons/cursor_hand.gif icons/about.png icons/100x17_audioscrobbler.png icons/64x20_lastfm.png
else
ICONS := icons/cover.png \
icons/16x16_status_icon-load-error.gif \
icons/32x32_animations_process-working.png \
icons/16x16_actions_view-sort-descending.png \
icons/16x16_status_playing.png \
icons/16x16_mimetypes_source-playlist.png \
icons/22x22_mimetypes_source-playlist.png \
icons/about.png \
icons/32x32_apps_musicmanager.png \
icons/16x16_apps_musicmanager.png \
icons/16x16_categories_preferences-desktop.png \
icons/24x24_actions_chain.png \
icons/24x24_actions_chain-broken.png \
icons/100x17_audioscrobbler.png \
icons/64x20_lastfm.png \
icons/cursor_hand.gif
endif

ifeq ($(OLD_REMOTE),1)
  ICONS += icons/remote.png
endif


# Objects to Compile
#----------------------------------------------------------
SRCFILES := src/GMAbout.cpp \
src/GMAnimImage.cpp \
src/GMApp.cpp \
src/GMAudioScrobbler.cpp \
src/GMClipboard.cpp \
src/GMColumnDialog.cpp \
src/GMDatabase.cpp \
src/GMDatabaseSource.cpp \
src/GMFetch.cpp \
src/GMFilename.cpp \
src/GMHeaderButton.cpp \
src/GMEQDialog.cpp \
src/GMIconTheme.cpp \
src/GMImportDialog.cpp \
src/GMList.cpp \
src/GMMessageChannel.cpp \
src/GMPlayer.cpp \
src/GMPlayerManager.cpp \
src/GMPlayListSource.cpp \
src/GMPreferences.cpp \
src/GMPreferencesDialog.cpp \
src/GMQuery.cpp \
src/GMRemote.cpp \
src/GMSearch.cpp \
src/GMSource.cpp \
src/GMSourceView.cpp \
src/GMTag.cpp \
src/GMThread.cpp \
src/GMTrackDatabase.cpp \
src/GMTrackList.cpp \
src/GMTrackItem.cpp \
src/GMTrackView.cpp \
src/GMTrayIcon.cpp \
src/GMStreamSource.cpp \
src/GMURL.cpp \
src/GMWindow.cpp \
src/main.cpp \
src/md5.cpp \
src/icons.cpp

ifeq ($(DBUS),1)
	SRCFILES += src/fxdbus.cpp \
	src/GMNotifyDaemon.cpp
endif

ifeq ($(ASF),1)
  CPPFLAGS +=-I./src/taglib_asf
	SRCFILES += src/taglib_asf/asfresolve.cpp \
	src/taglib_asf/asfattribute.cpp \
	src/taglib_asf/asffile.cpp \
	src/taglib_asf/asfproperties.cpp \
	src/taglib_asf/asftag.cpp
endif

ifeq ($(MP4),1)
  CPPFLAGS +=-Isrc/taglib_mp4
	SRCFILES += src/taglib_mp4/mp4resolve.cpp \
	src/taglib_mp4/mp4atom.cpp \
	src/taglib_mp4/mp4file.cpp \
	src/taglib_mp4/mp4item.cpp \
	src/taglib_mp4/mp4properties.cpp \
	src/taglib_mp4/mp4tag.cpp
endif


OBJECTS := $(patsubst %.cpp,%$(OBJEXT),$(SRCFILES))
DEPENDENCIES = $(patsubst %.cpp,%.d,$(SRCFILES))

$(BINNAME): $(OBJECTS)
	@echo "    Linking $@ ..."
#	@echo "$(LINK) $(LDFLAGS) $(OUTPUTBIN)$(BINNAME) $(OBJECTS) $(LIBS)"
	@$(LINK) $(LDFLAGS) $(OUTPUTBIN)$(BINNAME) $(OBJECTS) $(LIBS)

%$(OBJEXT):	%.cpp
	@echo "    Compiling $< ..."
#	@echo "$(CXX) $(CFLAGS) $(DEFS) $(CPPFLAGS) -MM -o $*.d -MT $@ $<"
	@$(CXX) $(CFLAGS) $(DEFS) $(CPPFLAGS) -MM -o $*.d -MT $@ $<
#	@echo "$(CXX) $(CFLAGS) $(DEFS) $(CPPFLAGS) $(OUTPUTOBJ)$@ -c $<"
	@$(CXX) $(CFLAGS) $(DEFS) $(CPPFLAGS) $(OUTPUTOBJ)$@ -c $<

ifeq ($(DBUS),1)
include/gogglesmm_xml.h: include/gogglesmm.xml
	@echo "    Creating DBUS Introspection..."
	@$(RESWRAP_TEXT) -o $@ include/gogglesmm.xml
endif

include/icons.h: $(ICONS)
	@echo "    Creating Icon Resource Header"
	@$(RESWRAP_H) -o $@ $(ICONS)

src/icons.cpp: $(ICONS)
	@echo "    Creating Icon Resources"
	@$(RESWRAP_CPP) -o $@ $(ICONS)

ifeq ($(DBUS),1)
src/GMPlayerManager.cpp: include/gogglesmm_xml.h
endif

src/GMAbout.cpp: include/icons.h src/icons.cpp


LINGUAS ?= $(basename $(notdir $(wildcard po/*.mo)))


# Install
#----------------------------------------------------------
install: $(BINNAME)
	@echo "    Installing $(INSTALLDIR)/bin/gmm ..."
	@$(INSTALL) -d $(INSTALLDIR)/bin
	@$(INSTALL) -m 755 src/musicmanager $(INSTALLDIR)/bin/gmm
	@echo "    Installing $(INSTALLDIR)/share/applications/gmm.desktop"
	@$(INSTALL) -d $(INSTALLDIR)/share/applications
	@$(INSTALL) -m 644 extra/gmm.desktop $(INSTALLDIR)/share/applications/gmm.desktop
	@echo "    Installing $(INSTALLDIR)/share/icons/hicolor/48x48/apps/gmm.png"
	@$(INSTALL) -d $(INSTALLDIR)/share/icons/hicolor/48x48/apps
	@$(INSTALL) -m 644 extra/gmm.png $(INSTALLDIR)/share/icons/hicolor/48x48/apps/gmm.png
ifeq ($(NLS),1)
	@echo "    Installing Translations"
	@linguas='$(LINGUAS)'; \
	for tr in $$linguas ; do \
    echo "    Installing $(INSTALLDIR)/share/locale/$$tr/LC_MESSAGES/gogglesmm.mo" ;\
  	$(INSTALL) -m 644 -D po/$$tr.mo -T $(INSTALLDIR)/share/locale/$$tr/LC_MESSAGES/gogglesmm.mo ; \
	done;
endif

# Clean
#----------------------------------------------------------
clean :
	@echo "    Remove Executables ..."
	@rm -f $(BINNAME)

	@echo "    Remove Objects ..."
	@rm -f src/*$(OBJEXT)
	@rm -f src/*.d
	@rm -f src/taglib_asf/*$(OBJEXT)
	@rm -f src/taglib_asf/*.d
	@rm -f src/taglib_mp4/*$(OBJEXT)
	@rm -f src/taglib_mp4/*.d
	@echo "    Remove Generated Files ..."
	@rm -f src/icons.cpp
	@rm -f include/icons.h
	@rm -f include/gogglesmm_xml.h
#----------------------------------------------------------

realclean :
	@echo "    Remove Configuration ..."
	@rm -f config.make

# Clean Icons
#----------------------------------------------------------
cleanicons :
	@rm -f src/icons.*
	@rm -f include/icons.*
#----------------------------------------------------------

# How to make everything else
-include $(DEPENDENCIES)
