# -----------------------------------------------------------------------------=
# $Id: Makefile,v 1.12.2.1 2001/09/05 15:09:21 sewardj Exp $
#
# (c) The GHC Team 1997-2000
#

TOP = ..
include $(TOP)/mk/boilerplate.mk

PACKAGE = win32
PACKAGE_DEPS = lang

GCDIR		= ../../green-card
GCLIBDIR        = $(GCDIR)/lib/ghc

HS_SRCS		 = $(wildcard *.hs)

# JRS 05 Sept 01: this rule is buggy, since it fails to
# enumerate *_stub.o files derived from *_stub.c generated by
# compilation of haskell sources with f-x's in them.
# This causes *_stub.o to be omitted from link phases the
# at the first build.  On a second 'make' run *_stub.c are
# present (from the first run), and it's all ok.  
# To "fix" this I add the two *_stub.o files by hand and
# used $(sort ...) to get rid of any duplicates.
STUBOBJS	 += $(patsubst %.c, %.o, $(C_SRCS))

OBJS		 = $(addsuffix .$(way_)o,  $(basename $(HS_SRCS)))
HI_FILES         = $(addsuffix .$(way_)hi,  $(basename $(HS_SRCS)))
LIBOBJS		 += $(sort $(OBJS) Win32Dialogue_stub.o Win32Window_stub.o)

SRC_CC_OPTS      += -DTARGET_GHC
SRC_HC_OPTS      += -recomp -cpp -fglasgow-exts -fvia-C -optc-DTARGET_GHC
SRC_HC_OPTS      += -fglasgow-exts -fno-prune-tydecls # -package greencard
SRC_GC_OPTS  	 += --target ffi --include-dir $(GCLIBDIR)
SRC_BLD_DLL_OPTS += -luser32 -lgdi32 -ladvapi32 Win32Dialogue_stub.o Win32Window_stub.o

Win32Registry_HC_OPTS += -Onot

ifeq "$(DEBUG)" "YES"
SRC_GC_OPTS      += --stub-debug
SRC_CC_OPTS      += -DDEBUG -O
SRC_HC_OPTS      += -optc-DWIN32_LIB_DEBUG
endif

# Dependency generation
depend :: $(HS_SRCS) 
	$(HC) -M -optdep-f -optdep.depend $(HC_OPTS) $(MKDEPENDHS_OPTS) $(HS_SRCS)
	$(SED) -e 's#$(GCDIR)/lib/$(GC_TARGET)#$$(GCDIR)/lib/$$(GC_TARGET)#g' < .depend > .depend.fixed && $(RM) .depend && $(MV) .depend.fixed .depend

# Hard-wired dependencies
errors.o  : errors.c
dumpBMP.o : dumpBMP.c
WndProc.o : WndProc.c WndProc.h

# Split into two
# Keep HSstd.o as a pseudo-target (I think)
HACKY_ALLOBJS = $(sort $(LIBOBJS) $(STUBOBJS) \
			Win32Dialogue_stub.o Win32Window_stub.o)
HSwin32.o :: $(HACKY_ALLOBJS)
	ld -r -x -o HSwin321.o $(filter     Win32M% Win32N% Win32R% Win32W%, \
						$(HACKY_ALLOBJS))
	ld -r -x -o HSwin322.o $(filter-out Win32M% Win32N% Win32R% Win32W%, \
						$(HACKY_ALLOBJS))


include $(TOP)/mk/target.mk
