###########################################################################
#
# Makefile for testing DOM code
#
###########################################################################

####### Sense whether we are on a DOS box or cross-compiling
ifdef ComSpec
BUILD=native
DOSSHELL=CMD_EXE
else
ifdef COMSPEC
BUILD=native
DOSSHELL=COMMAND_COM
else
BUILD=cross
endif
endif




##########################################################################
# FILE SEPARATORS
# $(S) will be set to one of these
##########################################################################
BSLASH := \\#
FSLASH := /



##########################################################################
# CROSS / NATIVE    SWITCHES
##########################################################################
ifeq ($(BUILD),cross)



##########################################################################
# CROSS COMPILER SETTINGS
##########################################################################

CC      = i686-pc-mingw32-gcc
CXX     = i686-pc-mingw32-g++
AS      = i686-pc-mingw32-as
AR      = i686-pc-mingw32-ar
RANLIB  = i686-pc-mingw32-ranlib
WINDRES = i686-pc-mingw32-windres
LD      = i686-pc-mingw32-ld
DLLWRAP = i686-pc-mingw32-dllwrap
DLLTOOL = i686-pc-mingw32-dlltool

####### file separator
S = $(FSLASH)

####### escape character for echo
E = /

####### file manipulation programs
CP     = cp
RMDIR  = rm -rf 
MKDIR  = mkdir
CPDIR  = cp -rf 
MSGFMT = msgfmt
RMREC  = find ./inkscape -type f -name 
RMREC1 = |xargs $(RM)
RMDIRREC = find ./inkscape -type d -name
RMDIRREC1 = |xargs $(RMDIR)

####### Where is your GTK directory?
GTK=/target

####### Same thing, file system style
GTKDOS=$(GTK)

DTG := $(shell date +%y%m%d.%H%M)

else

##########################################################################
# NATIVE COMPILER SETTINGS
##########################################################################

CC      = i686-pc-mingw32-gcc
CXX     = i686-pc-mingw32-g++
AS      = as
AR      = mingw32-ar
RANLIB  = ranlib
WINDRES = windres
DLLWRAP = dllwrap
DLLTOOL = dlltool

####### file separator
S = $(BSLASH)

####### escape character for echo
E = 

####### file manipulation programs
CP = copy

####### are we on WinNt and beyond?
ifeq ($(DOSSHELL),CMD_EXE)
RMDIR = rmdir /s /q
RM    = del
else
RMDIR = deltree /y
RM    = del
endif
MKDIR = mkdir
CPDIR = xcopy /e /i
RMREC = cd  inkscape & $(RM) /s /q 
RMREC1 = & cd ..
RMDIRREC = cd inkscape & $(RMDIR) /s 
RMDIRREC1 = & cd ..

#######  Where is your GTK directory?
GTK=c:/gtk28

####### Same thing, DOS style
GTKDOS=c:\gtk28

####### Command to process .po files --> .mo
MSGFMT = $(GTKDOS)$(S)bin$(S)msgfmt

####### change me!!
DTG := 20050626

endif
##########################################################################
# END    CROSS / NATIVE    SWITCHES
##########################################################################




INC = -I. -I..
CFLAGS = -Wall -g -DXP_WIN 
LIBS = -lws2_32

DOMOBJ = \
cssparser.o       \
domimpl.o         \
domptr.o          \
domstring.o       \
jsengine.o        \
jsdombind.o       \
lsimpl.o          \
smilimpl.o        \
uri.o             \
xmlreader.o       \
xpathimpl.o       \
xpathparser.o     \
xpathtoken.o      \
io/base64stream.o \
io/domstream.o    \
io/bufferstream.o \
io/gzipstream.o   \
io/httpclient.o   \
io/stringstream.o \
io/uristream.o    \
io/socket.o       \
odf/odfdocument.o \
svgimpl.o         \
svgparser.o       \
ucd.o             \
util/thread.o     \
util/ziptool.o



TESTOBJ = \
work/testdom.o   \
work/testodf.o   \
work/testsvg.o   \
work/testuri.o   \
work/testxpath.o \
work/testzip.o

OBJ = $(DOMOBJ)

all: testdom.exe testhttp.exe testjs.exe \
testsvg.exe testuri.exe testxpath.exe testzip.exe

testdom.exe: libdom.a work/testdom.o
	$(CXX) -o $@ work/testdom.o libdom.a $(LIBS)

testhttp.exe: libdom.a work/testhttp.o
	$(CXX) -o $@ work/testhttp.o libdom.a $(LIBS)

testjs.exe: libdom.a work/testjs.o
	$(CXX) -o $@ work/testjs.o libdom.a $(LIBS)

testodf.exe: libdom.a work/testodf.o
	$(CXX) -o $@ work/testodf.o libdom.a $(LIBS)

testsvg.exe: libdom.a work/testsvg.o
	$(CXX) -o $@ work/testsvg.o libdom.a $(LIBS)

testuri.exe: libdom.a work/testuri.o
	$(CXX) -o $@ work/testuri.o libdom.a $(LIBS)

testxpath.exe: libdom.a work/testxpath.o
	$(CXX) -o $@ work/testxpath.o libdom.a $(LIBS)

testzip.exe: libdom.a work/testzip.o
	$(CXX) -o $@ work/testzip.o libdom.a $(LIBS)


libdom.a: $(OBJ)
	ar crv $@ $(OBJ)


.cpp.o:
	$(CXX) $(CFLAGS) $(INC) -c -o $@ $<

clean:
	$(foreach a, $(OBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	$(foreach a, $(TESTOBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	-$(RM) *.a
	-$(RM) *.gch
	-$(RM) testdom
	-$(RM) testdom.exe
	-$(RM) testjs
	-$(RM) testjs.exe
	-$(RM) testsvg
	-$(RM) testsvg.exe
	-$(RM) testuri
	-$(RM) testuri.exe
	-$(RM) testxpath
	-$(RM) testxpath.exe
	-$(RM) testzip
	-$(RM) testzip.exe
	-$(RM) core.*

###########################################################################
# E N D    O F    F I L E
###########################################################################

