###########################################################################
#  $Id$
###########################################################################
# Makefile for building with MinGW
###########################################################################

include ../Makefile.mingw.common

all: generated outputs

###################################
# G E N E R A T E D    F I L E S
###################################

generated: helper/sp-marshal.h helper/sp-marshal.cpp inkscape_version.h



helper/sp-marshal.h: helper/sp-marshal.h.mingw
	$(CP) $(subst /,$(S), $<) $(subst /,$(S), $@)

helper/sp-marshal.cpp: helper/sp-marshal.cpp.mingw
	$(CP) $(subst /,$(S), $<) $(subst /,$(S), $@)

inkscape_version.h: inkscape_version.h.mingw
	$(CP) inkscape_version.h.mingw inkscape_version.h


###################################
# D E P E N D E N C I E S
###################################

include ./make.ofiles
include ./make.dep

INC += $(INCLUDEPATH)

OBJ = $(OBJECTS)



###################################
# O U T P U T S
###################################

outputs: inkscape.exe inkview.exe


RES=inkres.o

inkscape.exe: libinkscape.a main.o winmain.o $(RES) 
	$(CXX) --export-dynamic -o inkscape.exe main.o winmain.o $(RES) libinkscape.a $(LIBS)
	$(OBJCOPY) --only-keep-debug inkscape.exe inkscape.dbg
	strip inkscape.exe

# DLL version.  we need to make this work
#inkscape.exe: inkscape.dll main.o winmain.o $(RES) 
#	$(CXX) -o inkscape.exe main.o winmain.o $(RES) inkscape.la $(LIBS)
#	strip inkscape.exe

inkview.exe: libinkscape.a inkview.o $(RES) 
	$(CXX) -o inkview.exe inkview.o $(RES) libinkscape.a $(LIBS)
	$(OBJCOPY) --only-keep-debug inkview.exe inkview.dbg
	strip inkview.exe

# DLL version.  we need to make this work
# inkview.exe: inkscape.dll inkview.o $(RES) 
#	$(CXX) -o inkview.exe inkview.o $(RES) libinkscapedll.a $(LIBS)
#	strip inkview.exe

inkres.o: inkscape.rc
	$(WINDRES) inkscape.rc $(RES)

inkscape.dll: libinkscape.a inkscape.def
	$(DLLWRAP) --output-lib=inkscape.la \
	--def=inkscape.def --driver-name=g++ \
	-o inkscape.dll libinkscape.a $(LIBS)

inkscape.def: libinkscape.a
	perl makedef.pl
	
libinkscape.a: $(OBJ)
	-$(RM) libinkscape.a
	ar crv libinkscape.a $(OBJ)
	$(RANLIB) libinkscape.a

inkscape.la: inkscape.dll



###################################
# P L U G I N S
###################################

.o.dll: $<
	$(DLLWRAP) --def=plugin.def --driver-name=g++ \
	-o $@ $< $(LIBS)

PLUGS = extension/plugin/gimpgrad.dll

plugins: $(PLUGS)

extension/plugin/gimpgrad.dll: extension/plugin/gimpgrad.o inkscape.la
	$(DLLWRAP) --def=plugin.def --driver-name=g++ \
	-dllname $@ $< inkscape.la $(LIBS) -lgc
	strip $@




###################################
# C L E A N U P
###################################

clean:
	$(foreach a, $(OBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	-$(RM) main.o winmain.o inkview.o
	-$(RM) *.a
	-$(RM) *.la
	-$(RM) inkscape.def
	-$(RM) *.dll
	-$(RM) extension$(S)plugin$(S)*.o
	-$(RM) extension$(S)plugin$(S)*.dll


