#-*- Makefile -*-
include ../../gnuwin32/MkRules

all: makeMakedeps DLL implib

CPPFLAGS=-I. -I../../gnuwin32 -I../../include
DEFS=-DGA_DLL_BUILD -DENABLE_NLS=1
CPPFLAGS+=$(DEFS)
CFLAGS=$(OPTFLAGS)
# -O3 gives ICE in gcc 4.3.0
gimage-CFLAGS=-O2
image-CFLAGS=-O2

SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:.c=.o)

DLL: libR.dll.a Rgraphapp.dll
	@cp Rgraphapp.dll ../../../$(BINDIR)


ifdef USE_IMPLIBS
implib: libRgraphapp.dll.a
	@$(MKDIR) -p ../../../lib
	@$(CP) libRgraphapp.dll.a ../../../lib
else
implib:
endif

libRgraphapp.dll.a: Rgraphapp.def

## MinGW symbols have trailing @, MinGW-w64 do not
Rgraphapp.def: $(OBJECTS)
	@$(ECHO) EXPORTS > $@
	@$(NM) $^ | $(SED) -n $(SYMPAT) | $(SED) -e 's/@16//' | $(SORT) | uniq > g.def
	@comm -23 g.def ga.hide >> $@
	@$(RM) g.def

Rgraphapp.dll: $(OBJECTS) dllversion.o Rgraphapp.def
	$(DLL) -shared -mwindows -o $@ Rgraphapp.def $(OBJECTS) dllversion.o -L. -lR -lcomctl32 -limm32

## need to break mutual dependence with R.dll
libR.dll.a: R.def

clean:
	$(RM) *.o Rgraphapp.def *~ \#*\# *.d Makedeps

distclean: clean
	$(RM) *.a  *.dll

# Dependencies
dllversion.o: ../../include/Rversion.h
DEPS=$(SOURCES:.c=.d)

makeMakedeps: $(DEPS)
	@$(RM) Makedeps
	@cat $(DEPS) >> Makedeps

-include Makedeps
