1#//////////////////////////////////////////////////////////////////////////
2#
3# Filename:	Makefile
4# Purpose:	This is the makefile for GutenMark.  It will probably
5#		work only with GNU make, and as far as compilers are
6#		concerned, is intended to be used with
7#		GNU gcc on *NIX or on mingw32 on Win32.
8# Mods:		09/01/01 RSB	Began.
9#		09/03/01 RSB	Added AutoMarkWin
10#		11/02/01 RSB	Name changed from AutoMark to
11#				GutenMark, and GPL status clarified.
12#				gcc-compilation produces two
13#				identical files, GutenMark and
14#				GutenMark.exe.  This is a courtesy
15#				thing for compiling with mingw32
16#				in Win32.
17#		11/22/01 RSB	Added MatchWordlists.  Also, reorganized
18#				a lot, to use a single list of source files.
19#				Added libz.  Borland compiler probably
20#				doesn't work any longer.
21#		11/28/01 RSB	Simplified somewhat.
22#		11/29/01 RSB	Added regression test.
23#		12/01/01 RSB	Final fixups for 12/01/01 release.
24#		12/28/01 RSB	Added -funsigned_char to the compiler options.
25#		01/21/04 RSB	Now automatically builds GutenUtilities.
26#				Also, if mingw32 is installed (on Linux)
27#				always tries to build Win32 versions in
28#				addition to the Linux versions ... but doesn't
29#				abort on failure.
30#		02/21/04 RSB	A "make clean" in Linux now removes GutenMark.exe.
31#		04/20/08 RSB	Added 'snapshot' target.
32#		04/21/08 RSB	Corrected cross-compiler to account for IMCROSS
33#				project.
34#		04/23/08 RSB	Altered the way the installers are built, to
35#				eliminate the Linux-only files in the Windows
36#				install, and vice-versa.  The intaller programs
37#				will thus be a little smaller now.
38#		05/09/08 RSB	Added GutenMark-macosx target for a Mac OS X
39#				cross-compile, based on IMCROSS.  InstallJammer
40#				doesn't work properly for Mac OS X yet, so I
41#				create a tarball for the Mac OS X platforms.
42#		05/18/08 RSB	Created the Mac OS X application bundle.  Added
43#				some overrides, in case someone actually wants
44#				to perform the build on Mac OS X 10.5 rather
45#				than on Linux.
46#		05/26/08 RSB	Modified according to Jason Pollock's
47#				suggestion, to use ${CC} rather than hard-coding
48#				gcc as the compiler, and to have ${CC} default
49#				to cc.
50#		05/30/08 RSB	Fixed the PATH.  Also, added the ability to
51#				override the cross-compiled Mac executables if
52#				executables that had actually been built natively
53#				on the Mac were available: it's necessary to put
54#				files called GutenMark-maconmac, GutenSplit-maconmac,
55#				and GUItenMark-maconmac in this directory.
56#				When building natively on Mac OS X using
57#				'make BuildOnMacOSX' using my account (only),
58#				the executables are sent back to my Linux box
59#				so that they can be incorporated into the
60#				Mac application bundle in preference to the
61#				cross-compiled ones.
62#		06/01/2008 RSB	Replaced all ".phony" with ".PHONY", as I
63#				am informed (thanks, Jason Pollock!), that
64#				".phony" is not merely theoretically
65#				incorrect, but also doesn't work on all
66#				platforms.  Hopefully, fixed an abort that
67#				could occur if MinGW wasn't present.  Fixed some
68#				mistaken usage of PATH and some usage of
69#				"wx-config --static" that weren't as portable
70#				as I had hoped.
71#		03/09/09 RSB	Changed so that when *I* compile it, the
72#				native-Linux version compiles for 32-bit
73#				CPU even if I'm using a 64-bit machine
74#				to compile it.  Also, the default target
75#				now only compiles the native applications.
76#				The new 'all-archs' target compiles for
77#				Linux, Win32, and Mac OS X.  So, the normal
78#				native compile doesn't need IMCROSS.
79#		05/10/09 RSB	Added the 'buildbox' target.
80#
81#  Copyright 2001,2004,2008-2009 Ronald S. Burkey <info@sandroid.org>
82#
83#  This file is part of GutenMark.
84#
85#  GutenMark is free software; you can redistribute it and/or modify
86#  it under the terms of the GNU General Public License as published by
87#  the Free Software Foundation; either version 2 of the License, or
88#  (at your option) any later version.
89#
90#  GutenMark is distributed in the hope that it will be useful,
91#  but WITHOUT ANY WARRANTY; without even the implied warranty of
92#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
93#  GNU General Public License for more details.
94#
95#  You should have received a copy of the GNU General Public License
96#  along with GutenMark; if not, write to the Free Software
97#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
98#
99#//////////////////////////////////////////////////////////////////////////
100
101ifndef DARWIN_VERSION
102DARWIN_VERSION=darwin9
103endif
104
105ifndef CC
106CC=cc
107endif
108
109ifdef DEBUG
110DEBUG_LOG=-DDEBUG_LOG
111endif
112
113ifeq "${USER}" "rburkey"
114ARCH32=-m32
115endif
116
117IMCROSS_PATH=/home/${USER}/IMCROSS
118
119# These are the target architectures used for Mac OS X.
120MAC_TARGETS=-arch ppc -arch i386 -I${IMCROSS_PATH}/mac/include
121
122SUBMAKE:=${MAKE} "CC=${CC}" "IMCROSS_PATH=${IMCROSS_PATH}" "MAC_TARGETS=${MAC_TARGETS}"
123
124# This is where software snapshots will be put. It's of no use to anyone
125# but me.
126FTPSITE=/home/${USER}/Projects/sandroid.org/public_html/GutenMark/wasftp.GutenMark
127WEBSITE=${FTPSITE}/SoftwareSnapshots
128DATE:=`date +%Y%m%d`
129
130SOURCES := $(wildcard *.c) $(wildcard libGutenSpell/*.c)
131
132# The build is normally supposed to take place on a Linux box, even if
133# Win32 or Mac OS X executables are being built.  However, Those executables
134# presently don't work on Intel-based Mac OS X 10.5, so it's possible that
135# someone might want to actually perform a build on a Mac OS X 10.5 system.
136# The following step intercepts that case and substitutes different build
137# rules.  The actual rules are stuck at the end of this file to get them
138# out of the way of the "real" builds.
139ifeq (darwin9.0,$OSTYPE)
140.PHONY: OverrideDefault
141OverrideDefault:  BuildOnMacOSX
142endif
143
144.PHONY: default
145default: GutenMark
146	${SUBMAKE} -C GutenUtilities
147	-${SUBMAKE} -C GUItenMark
148
149# 'buildbox' is like 'snapshot', except that the building is done on the build-box
150# rather than on the local machine.  However, the files development-snapshot and
151# binary installers so-created are still moved to their proper places on the local
152# machine within the mirror image of the website.
153.PHONY: buildbox
154buildbox: source-snapshot
155	sh ./BuildBox.sh
156
157# We need to override the PATH, in order to make sure that the various cross-compiler
158# tools are located properly.  However, just changing the PATH variable here within
159# the Makefile isn't enough; the PATH has to be set properly before 'make' is entered.
160# Therefore, for various targets which require this, we have a special target that
161# changes the PATH within the shell and then immediately does 'make' on those targets,
162# which are renamed to be suffixed with '2'.  For example, if we do 'make default',
163# it actually changes the path and then does a 'make default2'. The targets for which
164# this occurs are listed in the following variable.
165PATHCHANGE_TARGETS=snapshot all-archs
166
167.PHONY: ${PATHCHANGE_TARGETS}
168${PATHCHANGE_TARGETS}:
169	export PATH=/usr/local/bin:${PATH}:${IMCROSS_PATH}/bin:${IMCROSS_PATH}/installjammer && \
170	${MAKE} $@2
171
172.PHONY: all-archs2
173all-archs2: GutenMark GutenMarkX.exe GutenMark-macosx
174	${SUBMAKE} -C GutenUtilities all-archs
175	${SUBMAKE} -C GUItenMark all-archs
176
177.PHONY: snapshot2
178snapshot2: source-snapshot all-archs2
179	# Put stuff in the proper directory, which is a temporary directory we make
180	# underneath InstallJammer, called InstallJammer/input.
181	-rm InstallJammer/input InstallJammer/output -rf
182	mkdir InstallJammer/input InstallJammer/output
183	mkdir InstallJammer/input/binary
184	mkdir InstallJammer/input/GUIConfigs
185	mkdir InstallJammer/input/GutConfigs
186	mkdir InstallJammer/input/Outputs
187	cp \
188		GUItenMark/*.jpg GUItenMark/*.png GUItenMark/*.ico \
189		${FTPSITE}/Wordlists/* \
190		GutenUtilities/espa~nol_filter \
191		GutenUtilities/GutenSplit \
192		GutenUtilities/GutenSplit.exe \
193		GutenUtilities/GutenSplit-macosx \
194		GutenUtilities/gztest \
195		GutenUtilities/hk2_deutsch \
196		GutenUtilities/names_english \
197		GutenUtilities/NIMA \
198		GutenUtilities/NoDups \
199		GutenUtilities/norsk \
200		GutenUtilities/string2line \
201		GutenUtilities/USGS \
202		GutenUtilities/utf8 \
203		GutenUtilities/words197 \
204		GUItenMark/GUItenMark \
205		GUItenMark/GUItenMark.exe \
206		GUItenMark/GUItenMark-macosx \
207		GutenMark \
208		GutenMark.exe \
209		GutenMark-macosx \
210		GutenMark.foreign.gz \
211		GutenMark.native.gz \
212		InstallJammer/input/binary
213	# In the remainder of this rule, we create installers.
214	cp GutenMark-install.cfg InstallJammer/input/GutConfigs/GutenMark.cfg
215	# First, Linux ---------------------------------------------------
216	# Before running the installer, we need to doctor the project
217	# file a little to update the embedded version code.
218	sed "s+PROGRAM_VERSION+${DATE}+" InstallJammer/InstallJammer-Linux.mpi >InstallJammer/temp.mpi
219	# NOW run the installer builder.
220	@echo PATH=${PATH}
221	cd InstallJammer && installjammer --build temp.mpi
222	cp InstallJammer/output/*Linux* ${WEBSITE}/GUItenMark-Linux-Install
223	# Next, Windows --------------------------------------------------
224	# Before running the installer, we need to doctor the project
225	# file a little to update the embedded version code.
226	sed "s+PROGRAM_VERSION+${DATE}+" InstallJammer/InstallJammer-Windows.mpi >InstallJammer/temp.mpi
227	# NOW run the installer builder.
228	cd InstallJammer && installjammer --build temp.mpi
229	cp InstallJammer/output/*Setup.exe ${WEBSITE}/GUItenMark-Win32-setup.exe
230	# Now, Mac OS X --------------------------------------------------
231	# Redo all of the copying, since a different directory structure
232	# is used to create the Apple application bundle, and since
233	# we don't run InstallJammer.  We create links for the executables
234	# the Resources directory of the application bundle, so that
235	# GutenMark and GutenSplit can be run from there.
236	-mkdir temp
237	cp -a GUItenMark.app temp
238	cp GutenMark-install.cfg temp/GUItenMark.app/Contents/Resources/GutenMark.cfg
239	cp -a ${FTPSITE}/Wordlists/* temp/GUItenMark.app/Contents/Resources
240	cp -a GutenMark*gz temp/GUItenMark.app/Contents/Resources
241	cp -a GutenUtilities/GutenSplit-macosx temp/GUItenMark.app/Contents/MacOS/GutenSplit
242	cp -a GUItenMark/GUItenMark-macosx temp/GUItenMark.app/Contents/MacOS/GUItenMark
243	cp -a GutenMark-macosx temp/GUItenMark.app/Contents/MacOS/GutenMark
244	# If we've gone out of our way to procure executables *actually* built on Mac OS X
245	# rather than cross-compiled, use them instead of the cross-compiled ones.
246	-cp -a GutenSplit-maconmac temp/GUItenMark.app/Contents/MacOS/GutenSplit
247	-cp -a GUItenMark-maconmac temp/GUItenMark.app/Contents/MacOS/GUItenMark
248	-cp -a GutenMark-maconmac temp/GUItenMark.app/Contents/MacOS/GutenMark
249	cp -a GUItenMark/*.jpg temp/GUItenMark.app/Contents/Resources
250	cd temp/GUItenMark.app/Contents/Resources && ln --force --symbolic ../MacOS/* .
251	-rm ${WEBSITE}/GUItenMark.app.tar.gz
252	tar -C temp -czf ${WEBSITE}/GUItenMark.app.tar.gz GUItenMark.app
253	# All done!
254	ls -ltr ${WEBSITE}
255
256# For generic *nix.  If the cc command isn't gcc, this might not work,
257# and I guess you'll want to substitute "gcc" for "cc".  The reason it's
258# set to "cc" rather than directly to "gcc" is for the benefit of MacOS-X.
259GutenMark: $(SOURCES) AutoMark.h
260	${CC} ${ARCH32} -pipe -O2 -fno-strict-aliasing  -Wall -funsigned-char \
261		-o GutenMark $(SOURCES) -lz
262	./GutenMark bldhb10.txt bldhb10.html
263	-diff bldhb10.html bldhb10.txt.html
264
265# For making a software snapshot.
266.PHONY: source-snapshot
267source-snapshot:
268	${MAKE} clean
269	tar --directory=.. --exclude="*/.snprj" --exclude="*.proj" --exclude="*/CVS" \
270		--exclude="*~" --exclude="*.bak" --exclude="InstallJammer/output" \
271		--exclude="InstallJammer/build" --exclude="InstallJammer/temp.mpi" \
272		--exclude="InstallJammer/build.log" --exclude="InstallJammer/input" \
273		--exclude="*.tmp" --exclude="*.save" --exclude="*.save2" --exclude="temp" \
274		-czf ${WEBSITE}/GutenMark_source_dev-${DATE}.tar.gz GutenMark-source
275
276# Temporary target for making an installation zipfile.  Won't be used
277# at all once there's an installer.
278.PHONY: zip
279zip:
280	${MAKE} clean
281	-rm ${WEBSITE}/GUItenMark-demo.zip
282	cd ~ && \
283	zip -o -r ${WEBSITE}/GUItenMark-demo.zip .GutenMark \
284		-x ".GutenMark/GUIConfigs/*" -x ".GutenMark/Outputs/*"
285
286Utilities:
287	${SUBMAKE} -C GutenUtilities
288
289# Builds a Win32 version of GutenMark, using mingw32 as installed on a Linux
290# computer.  The assumption is that cross-compilers have been installed using
291# the IMCROSS ("I'm Cross!", www.sandroid.org/imcross) project.
292# I've had to use a wrong target name to keep the rule from conflicting
293# with a similar rule below (for ACTUALLY using mingw32 on Windows).  Therefore,
294# this will attempt to build every time, whether or not it's up to date.
295GutenMarkX.exe: $(SOURCES) AutoMark.h
296	@echo PATH=${PATH}
297	-i386-mingw32-gcc -pipe -O2 -fno-strict-aliasing  -Wall -funsigned-char -o GutenMark.exe $(SOURCES) -lz
298
299# And the same, but for Mac OS X.
300GutenMark-macosx: $(SOURCES) AutoMark.h
301	-powerpc-apple-${DARWIN_VERSION}-gcc \
302		${MAC_TARGETS} -isysroot ${IMCROSS_PATH}/mac/SDKs/MacOSX10.4u.sdk \
303		-pipe -O2 -fno-strict-aliasing  -Wall -funsigned-char \
304		-o $@ $(SOURCES) -lz
305
306debug: $(SOURCES) AutoMark.h
307	cc -g -O0 -Wall -funsigned-char -DDEBUGGING \
308		-o GutenMark $(SOURCES) -lz
309	./GutenMark bldhb10.txt bldhb10.html
310	-diff bldhb10.html bldhb10.txt.html
311
312# For Win32 with mingw32.
313GutenMark.exe: $(SOURCES) AutoMark.h
314	gcc -pipe -O2 -fno-strict-aliasing  -Wall -funsigned-char -I. -I.. -Izlib_w32 -Lzlib_w32 \
315		-o GutenMark.exe $(SOURCES) -lz
316	GutenMark bldhb10.txt bldhb10.html
317	-fc bldhb10.html bldhb10.txt.html
318
319clean:
320	-rm InstallJammer/.GutenMark -rf
321	-rm GutenMark GutenMark.exe GutenMark-macosx
322	${SUBMAKE} -C GutenUtilities clean
323	${SUBMAKE} -C GUItenMark clean
324
325
326#################################################################################
327# The following rules have nothing to do with the normal build process, which is
328# Linux based.  However, they allow building *on* Mac OS X so that the programs
329# could be run on that specific machine.  For this process to work, the GUItenMark
330# application bundle must already have been installed on the desktop.  What the
331# rule BuildOnMacOSX does is to build all of the executables, and then to replace
332# the executables that are already in the installed app bundle.
333#
334# Furthermore, wxWidget 2.8 must be installed.  This is the default on Mac OS X
335# 10.5, but is NOT the case on 10.4 or prior.
336
337ifeq "${USER}" "rburkey"
338GUITENMARK_TARGETS=${MAC_TARGETS}
339endif
340
341.PHONY: BuildOnMacOSX
342BuildOnMacOSX:	${HOME}/Desktop/GUItenMark.app \
343		GutenMark-maconmac \
344		GutenSplit-maconmac \
345		GUItenMark-maconmac
346	# Patch the app bundle
347	for n in GutenMark GutenSplit GUItenMark ; \
348	do \
349		cp $$n-maconmac ${HOME}/Desktop/GUItenMark.app/Contents/MacOS/$$n ; \
350	done
351ifeq "${USER}" "rburkey"
352	# Phone home.
353	scp -p GUItenMark-maconmac rburkey@192.168.254.250:Projects/GutenMark/GutenMark-source
354endif
355
356GutenMark-maconmac: $(SOURCES) AutoMark.h
357	${CC} \
358		-pipe -O2 -fno-strict-aliasing  -Wall -funsigned-char \
359		-o $@ $(SOURCES) -lz
360	${PREP_BINARIES}
361
362GutenSplit-maconmac: GutenUtilities/GutenSplit.c
363	${CC} -O2 -Wall -o $@ $^
364	${PREP_BINARIES}
365
366CSOURCE=GUItenMark/main.cpp GUItenMark/GUItenMark.cpp
367CHEADERS=GUItenMark/GUItenMark.h
368GUItenMark-maconmac: ${CSOURCE} ${CHEADERS} Makefile
369	g++ \
370		${DEBUG_LOG} ${GUITENMARK_TARGETS} \
371		`wx-config --version=2.8 --cxxflags` \
372		${CSOURCE} \
373		`wx-config --version=2.8 --libs` \
374		-o $@
375	${PREP_BINARIES}
376
377
378