#//////////////////////////////////////////////////////////////////////////
#
# Filename:	Makefile 
# Purpose:	This is the makefile for GutenMark.  It will probably
#		work only with GNU make, and as far as compilers are 
#		concerned, is intended to be used with
#		GNU gcc on *NIX or on mingw32 on Win32.
# Mods:		09/01/01 RSB	Began.
#		09/03/01 RSB	Added AutoMarkWin
#		11/02/01 RSB	Name changed from AutoMark to 
#				GutenMark, and GPL status clarified.
#				gcc-compilation produces two 
#				identical files, GutenMark and 
#				GutenMark.exe.  This is a courtesy
#				thing for compiling with mingw32
#				in Win32.
#		11/22/01 RSB	Added MatchWordlists.  Also, reorganized
#				a lot, to use a single list of source files.
#				Added libz.  Borland compiler probably
#				doesn't work any longer.
#		11/28/01 RSB	Simplified somewhat.
#		11/29/01 RSB	Added regression test.
#		12/01/01 RSB	Final fixups for 12/01/01 release.
#		12/28/01 RSB	Added -funsigned_char to the compiler options.
#		01/21/04 RSB	Now automatically builds GutenUtilities.
#				Also, if mingw32 is installed (on Linux)
#				always tries to build Win32 versions in 
#				addition to the Linux versions ... but doesn't
#				abort on failure.
#		02/21/04 RSB	A "make clean" in Linux now removes GutenMark.exe.
#		04/20/08 RSB	Added 'snapshot' target.  
#		04/21/08 RSB	Corrected cross-compiler to account for IMCROSS 
#				project.
#		04/23/08 RSB	Altered the way the installers are built, to 
#				eliminate the Linux-only files in the Windows
#				install, and vice-versa.  The intaller programs
#				will thus be a little smaller now.
#		05/09/08 RSB	Added GutenMark-macosx target for a Mac OS X 
#				cross-compile, based on IMCROSS.  InstallJammer
#				doesn't work properly for Mac OS X yet, so I 
#				create a tarball for the Mac OS X platforms.
#
#  Copyright 2001,2004,2008 Ronald S. Burkey <info@sandroid.org>
#
#  This file is part of GutenMark.
#
#  GutenMark is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  GutenMark is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with GutenMark; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#//////////////////////////////////////////////////////////////////////////

# This is where software snapshots will be put. It's of no use to anyone 
# but me.
FTPSITE=~/Projects/sandroid.org/public_html/GutenMark/wasftp.GutenMark
WEBSITE=${FTPSITE}/SoftwareSnapshots
DATE:=`date +%Y%m%d`

SOURCES := $(wildcard *.c) $(wildcard libGutenSpell/*.c)

.phony: default
default: GutenMark
	-${MAKE} -C GUItenMark

.phony: snapshot
snapshot: source-snapshot default
	# Put stuff in the proper directory, which is a temporary directory we make
	# underneath InstallJammer, called InstallJammer/input.
	-rm InstallJammer/input InstallJammer/output -rf
	mkdir InstallJammer/input InstallJammer/output
	mkdir InstallJammer/input/binary
	mkdir InstallJammer/input/GUIConfigs
	mkdir InstallJammer/input/GutConfigs
	mkdir InstallJammer/input/Outputs
	cp \
		GUItenMark/*.jpg GUItenMark/*.png GUItenMark/*.ico \
		${FTPSITE}/Wordlists/* \
		GutenUtilities/espa~nol_filter \
		GutenUtilities/GutenSplit \
		GutenUtilities/GutenSplit.exe \
		GutenUtilities/GutenSplit-macosx \
		GutenUtilities/gztest \
		GutenUtilities/hk2_deutsch \
		GutenUtilities/names_english \
		GutenUtilities/NIMA \
		GutenUtilities/NoDups \
		GutenUtilities/norsk \
		GutenUtilities/string2line \
		GutenUtilities/USGS \
		GutenUtilities/utf8 \
		GutenUtilities/words197 \
		GUItenMark/GUItenMark \
		GUItenMark/GUItenMark.exe \
		GUItenMark/GUItenMark-macosx \
		GutenMark \
		GutenMark.exe \
		GutenMark-macosx \
		GutenMark.foreign.gz \
		GutenMark.native.gz \
		InstallJammer/input/binary
	cp GutenMark-install.cfg InstallJammer/input/GutConfigs/GutenMark.cfg
	# First, Linux ---------------------------------------------------
	# Before running the installer, we need to doctor the project
	# file a little to update the embedded version code.
	sed "s+PROGRAM_VERSION+${DATE}+" InstallJammer/InstallJammer-Linux.mpi >InstallJammer/temp.mpi
	# NOW run the installer builder.
	cd InstallJammer && /usr/local/installjammer/installjammer --build temp.mpi
	cp InstallJammer/output/*Linux* ${WEBSITE}/GUItenMark-Linux-Install
	# Next, Windows --------------------------------------------------
	# Before running the installer, we need to doctor the project
	# file a little to update the embedded version code.
	sed "s+PROGRAM_VERSION+${DATE}+" InstallJammer/InstallJammer-Windows.mpi >InstallJammer/temp.mpi
	# NOW run the installer builder.
	cd InstallJammer && /usr/local/installjammer/installjammer --build temp.mpi
	cp InstallJammer/output/*Setup.exe ${WEBSITE}/GUItenMark-Win32-setup.exe
	# Now, Mac OS X --------------------------------------------------
	#sed "s+PROGRAM_VERSION+${DATE}+" InstallJammer/InstallJammer-MacOSX.mpi >InstallJammer/temp.mpi
	# NOW run the installer builder.
	#cd InstallJammer && /usr/local/installjammer/installjammer --build temp.mpi
	#cp InstallJammer/output/*MacOS-X* ${WEBSITE}/GUItenMark-MacOS-X-Install
	cd InstallJammer && cp -a input .GutenMark
	-cd InstallJammer/.GutenMark/binary && rm \
		*.exe GutenMark GUItenMark string2line utf8 NoDups USGS hk2_deutsch \
		names_english espa~nol_filter norsk words197 NIMA gztest GutenSplit
	-rm ${WEBSITE}/GUItenMark-MacOS-X.tar.gz
	cd InstallJammer && tar -czf ${WEBSITE}/GUItenMark-MacOS-X.tar.gz .GutenMark
	# All done!
	ls -ltr ${WEBSITE}

# For generic *nix.  If the cc command isn't gcc, this might not work, 
# and I guess you'll want to substitute "gcc" for "cc".  The reason it's 
# set to "cc" rather than directly to "gcc" is for the benefit of MacOS-X. 
GutenMark: Utilities GutenMarkX.exe GutenMark-macosx $(SOURCES) AutoMark.h
	cc -O3 -Wall -funsigned-char \
		-o GutenMark $(SOURCES) -lz
	strip $@
	./GutenMark bldhb10.txt bldhb10.html
	-diff bldhb10.html bldhb10.txt.html

# For making a software snapshot.
.phony: source-snapshot
source-snapshot:
	${MAKE} clean
	${MAKE} -C GUItenMark clean
	tar --directory=.. --exclude="*/.snprj" --exclude="*.proj" --exclude="*/CVS" \
		--exclude="*~" --exclude="*.bak" --exclude="InstallJammer/output" \
		--exclude="InstallJammer/build" --exclude="InstallJammer/temp.mpi" \
		--exclude="InstallJammer/build.log" --exclude="InstallJammer/input" \
		--exclude="*.tmp" --exclude="*.save" --exclude="*.save2" \
		-czf ${WEBSITE}/GutenMark_source_dev-${DATE}.tar.gz GutenMark-source

# Temporary target for making an installation zipfile.  Won't be used
# at all once there's an installer.
.phony: zip
zip:
	${MAKE} clean
	${MAKE} -C GUItenMark clean
	-rm ${WEBSITE}/GUItenMark-demo.zip
	cd ~ && \
	zip -o -r ${WEBSITE}/GUItenMark-demo.zip .GutenMark \
		-x ".GutenMark/GUIConfigs/*" -x ".GutenMark/Outputs/*"

Utilities:
	${MAKE} -C GutenUtilities

# Builds a Win32 version of GutenMark, using mingw32 as installed on a Linux
# computer.  The assumption is that cross-compilers have been installed using 
# the IMCROSS ("I'm Cross!", www.sandroid.org/imcross) project.
# I've had to use a wrong target name to keep the rule from conflicting
# with a similar rule below (for ACTUALLY using mingw32 on Windows).  Therefore,
# this will attempt to build every time, whether or not it's up to date.
GutenMarkX.exe: $(SOURCES) AutoMark.h
	-i386-mingw32-gcc -O3 -Wall -funsigned-char -o GutenMark.exe $(SOURCES) -lz
	-i386-mingw32-strip GutenMark.exe

# And the same, but for Mac OS X.
GutenMark-macosx: $(SOURCES) AutoMark.h
	powerpc-apple-darwin8-gcc \
		-arch i386 -arch ppc \
		-O3 -Wall -funsigned-char -o $@ $(SOURCES) \
		-lz
	-powerpc-apple-darwin8-strip $@

debug: $(SOURCES) AutoMark.h
	cc -g -O0 -Wall -funsigned-char -DDEBUGGING \
		-o GutenMark $(SOURCES) -lz
	./GutenMark bldhb10.txt bldhb10.html
	-diff bldhb10.html bldhb10.txt.html

# For Win32 with mingw32.	
GutenMark.exe: $(SOURCES) AutoMark.h
	gcc -O3 -Wall -funsigned-char -I. -I.. -Izlib_w32 -Lzlib_w32 \
		-o GutenMark.exe $(SOURCES) -lz
	strip $@
	GutenMark bldhb10.txt bldhb10.html
	-fc bldhb10.html bldhb10.txt.html
	
clean:
	-rm InstallJammer/.GutenMark -rf
	-rm GutenMark GutenMark.exe GutenMark-macosx
	${MAKE} -C GutenUtilities clean
	${MAKE} -C GUItenMark clean
	
	

