#
# Makefile.am for xbgmsharp.exe
#
# Authors:
#   Francois Lacroix (xbgm@kayaweed.net)
#

MCS=mcs
MONORESGEN=monoresgen

SOURCES = \
./AssemblyInfo.cs \
./Main.cs \
./MyWindow.cs \
./Translation.cs \
./FTP/FTPClient.cs \
./FTP/FTPControlSocket.cs \
./FTP/FTPException.cs \
./FTP/FTPReply.cs \
./Dialog/DeleteDialog.cs \
./Dialog/RenameDialog.cs \
./Dialog/AboutDialog.cs \
./Dialog/ProgressDialog.cs \
./Dialog/Popup.cs \
./Dialog/Toolbar.cs \
./Dialog/ChooserDialog.cs \
./Xiso/xisoinfo.cs \
./Xiso/xisothread2.cs \
./Core/Export.cs \
./Core/FtpToXbox.cs \
./Core/Messages.cs \
./Core/Parser.cs \
./Core/ZipExtract.cs \
./Core/GameInfo.cs \
./Core/FtpLogger.cs \
./Core/ConfigXml.cs \
./Core/CheckEnvOS.cs \
./Config.cs \
./Dialog/PrefGaldeDialog.cs \
./Dialog/UploadDirGladeDialog.cs \
./Dialog/ProgressUploadDirGlade.cs \
./File/FileData.cs \
./File/FileExplorer.cs \
./File/Filethread.cs

RESOURCES = \
./pixmap/reboot.png \
./pixmap/shutdown.png \
./pixmap/infoicon.png \
./pixmap/xbgmicon.ico \
./pixmap/edit.png \
./pixmap/play.png \
./pixmap/xbgm.png \
./pixmap/xbgmicon.png \
./pixmap/xbmc.png \
./pixmap/xbox.png \
./pref.glade \
./Glade/uploaddir.glade \
$(STRINGFILES)

STRINGFILES= String/strings.resources \
	 String/strings.fr.resources

CLEANFILES = String/*.resources
	 
RESOURCES_BUILD = $(foreach res,$(RESOURCES), $(addprefix -resource:,$(res)),$(notdir $(res)))

PKG_REFERENCES = \
	gtk-sharp-2.0 \
	glade-sharp-2.0

PKG_REFERENCES_BUILD = $(addprefix -pkg:, $(PKG_REFERENCES))

PKG_REFERENCES_CHECK = $(addsuffix .pkgcheck, $(PKG_REFERENCES))

SYSTEM_REFERENCES = \
System.Data.dll \
ICSharpCode.SharpZipLib.dll 

SYSTEM_REFERENCES_BUILD = $(addprefix -r:, $(SYSTEM_REFERENCES))

SYSTEM_REFERENCES_CHECK = $(addsuffix .check, $(SYSTEM_REFERENCES))

CLEANFILES = String/*.resources

#MCS_OPTIONS = -define:DEBUG
MCS_OPTIONS = -debug

all: xbgmsharp.exe

xbgmsharp.exe: $(SOURCES) $(RESOURCES) $(STRINGFILES)
	mcs $(MCS_OPTIONS) -target:exe -out:"xbgmsharp.exe" $(RESOURCES_BUILD) $(PKG_REFERENCES_BUILD) $(SYSTEM_REFERENCES_BUILD) $(SOURCES) 

resources/strings.txt: $(SOURCES)
	perl getstrings.pl ./Dialog/Toolbar.cs > String/strings.txt

depcheck: PKG_depcheck SYSTEM_depcheck

PKG_depcheck: $(PKG_REFERENCES_CHECK)

%.pkgcheck:
	@echo -n Checking for package $(subst .pkgcheck,,$@)...
	@if pkg-config --libs $(subst .pkgcheck,,$@) &> /dev/null; then \
		echo yes; \
	else \
		echo no; \
		exit 1; \
	fi

SYSTEM_depcheck: $(SYSTEM_REFERENCES_CHECK)

%.check:
	@echo -n Checking for $(subst .check,,$@)...
	@if [ ! -e `pkg-config --variable=libdir mono`/mono/2.0/$(subst .check,,$@) ]; then \
		echo no; \
		exit 1; \
	else \
		echo yes; \
	fi

resources/strings.resources: String/strings.txt

resources/strings.fr.resources: String/strings.fr.txt

%.resources: %.txt
    $(MONORESGEN) $< || (echo -e "\nERROR: You should either" \
		"enable binfmt-misc with mono support or define \n" \
		"RUNTIME=mono and MONORESGEN=yourpathto/monoresgen.exe\n" \
		&& exit 1)

clean:
	rm -f xbgmsharp.exe xbgmsharp.exe.mdb

purge: clean
	$(CLEANFILES)
