#//////////////////////////////////////////////////////////////////////////
#
# 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.
#
#  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.
WEBSITE=~/Projects/sandroid.org/public_html/GutenMark/wasftp.GutenMark/SoftwareSnapshots
DATE:=`date +%Y%m%d`

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

.phony: default
default: GutenMark GUItenMark/GUItenMark Installer

.phony: Installer
Installer:
	-rm ~/.GutenMark/uninstall ~/.GutenMark/Outputs/* ~/.GutenMark/GUIConfigs/*
	# 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.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
	cp InstallJammer/output/*Setup.exe ${WEBSITE}/GUItenMark-Win32-setup.exe
	ls -l ${WEBSITE}/GUItenMark*

GUItenMark/GUItenMark:
	-${MAKE} -C GUItenMark

# 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 $(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: snapshot
snapshot:
	${MAKE} clean
	${MAKE} -C GUItenMark clean
	tar --directory=.. --exclude="*/.snprj" --exclude="*/CVS" \
		--exclude="*~" --exclude="*.bak" --exclude="InstallJammer/output" \
		--exclude="InstallJammer/build" --exclude="InstallJammer/temp.mpi" \
		--exclude="InstallJammer/build.log" \
		-czf ${WEBSITE}/GutenMark_source_dev-${DATE}.tar.gz GutenMark-source
	ls -ltr ${WEBSITE}/*source*.tar.gz 

# 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

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 GutenMark GutenMark.exe
	-erase GutenMark.exe
	${MAKE} -C GutenUtilities clean
	${MAKE} -C GUItenMark clean
	
	

