#
# default base directory for YAP installation
#
ROOTDIR = c:/Program\ Files/Yap
#
# where the binary should be
#
BINDIR = $(ROOTDIR)/bin
#
# where YAP should look for libraries
#
LIBDIR=$(ROOTDIR)/lib/Yap
#
#
CC=gcc  -mno-cygwin
CFLAGS= -march=pentiumpro -DBP_FREE -O3 -fomit-frame-pointer -Wall -Wstrict-prototypes -Wmissing-prototypes $(YAP_EXTRAS) $(DEFS) -I. -I../.. -I$(srcdir)/../../include
#
#
# You shouldn't need to change what follows.
#
INSTALL=/usr/bin/install -c
INSTALL_DATA=${INSTALL} -m 644
INSTALL_PROGRAM=${INSTALL}
SHELL=/bin/sh
RANLIB=ranlib
srcdir=.
SHLIB_CFLAGS=
SHLIB_SUFFIX=.dll
#4.1VPATH=../../../../work/library/system:../../../../work/library/system/OPTYap
CWD=$(PWD)
#


OBJS=complete.o console.o edit.o history.o registry.o
SOBJS=complete.so edit.so history.so registry.so console.so 

#in some systems we just create a single object, in others we need to
# create a libray

all: dll

sobjs: $(SOBJS) 

dll: win32cons.dll

complete.o: $(srcdir)/complete.c
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/complete.c -o complete.o

console.o: $(srcdir)/console.c
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/console.c -o console.o

edit.o: $(srcdir)/edit.c
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/edit.c -o edit.o

history.o: $(srcdir)/history.c
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/history.c -o history.o

registry.o: $(srcdir)/registry.c
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/registry.c -o registry.o

%.so: %.o
	@# -o $@ $<

complete.so: complete.o
	@SHLIB_LD@ -o complete.so complete.o

console.so: console.o
	@# -o console.so console.o

edit.so: edit.o
	@# -o edit.so edit.o

history.so: history.o
	@# -o history.so history.o

registry.so: registry.o
	@# -o registry.so registry.o

#
# create a new DLL library on cygwin environments
#
# DLLNAME: name of the new dll
# OBJS: list of object files I want to put in
# LIBS: list of libraries to link with
# DEFFILE is the name of the definitions file.
# BASEFILE temporary 
# EXPFILE  temporary
# ENTRY is the entry point  int WINAPI startup (HINSTANCE, DWORD, LPVOID)
# 
DLLTOOL=dlltool
DLLNAME=win32cons.dll
DLL_LIBS=-L /usr/lib/mingw -lcrtdll -luser32 -lshell32 -ladvapi32 -lkernel32 -lgdi32 -lcomdlg32
BASE_FILE=win32cons.base
EXP_FILE=win32cons.exp
DEF_FILE=$(srcdir)/win32cons.def
ENTRY_FUNCTION=_win32cons@12
#
win32cons.dll: $(OBJS)
	$(LD) -s --base-file $(BASE_FILE) --dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)
	$(DLLTOOL) --as=$(AS) --dllname $(DLLNAME) --def $(DEF_FILE) --base-file $(BASE_FILE) --output-exp $(EXP_FILE)
	$(LD) -s --base-file $(BASE_FILE) $(EXP_FILE) -dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)
	$(DLLTOOL) --as=$(AS) --dllname $(DLLNAME) --def $(DEF_FILE) --base-file $(BASE_FILE) --output-exp $(EXP_FILE)
	$(LD) $(EXP_FILE) --dll -o $(DLLNAME) $(OBJS) $(DLL_LIBS) -e $(ENTRY_FUNCTION)

install: all
	$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(LIBDIR)

install_mingw32: dll
	$(INSTALL_PROGRAM) -m 755 win32cons.dll $(LIBDIR)/win32cons.dll

clean:
	rm -f *.o *.so *~ $(OBJS) *.BAK

