
# ------------------------------------------------------------------------
# 	Makefile for BLT library using VC++.
# ------------------------------------------------------------------------

include	      e:/src/blt/win/makedefs

TOOLS32       =	c:/Program\ Files/Microsoft\ Visual\ Studio/Vc98
AR            =	lib.exe -link50compat
LD            =	link.exe
CC            =	cl.exe
rc32          =	rc.exe

ifeq ($(WITH_JPEG),0)
EXTRA_DEFINES = 
endif
ifeq ($(WITH_JPEG),1)
EXTRA_DEFINES = -DHAVE_JPEGLIB_H=1
JPEGDIR       =	$(srcdir)/../../jpeg-6b
JPEGLIB =	$(JPEGDIR)/libjpeg.lib
JPEGINC	      = $(JPEGDIR)
endif
ifeq ($(WITH_JPEG),2)
EXTRA_DEFINES = -DHAVE_IJL_H=1 
JPEGDIR       =	c:/Program\ Files/Intel/IJL
JPEGLIB	      =	$(JPEGDIR)/lib/ijl15l.lib
JPEGINC	      = $(JPEGDIR)/Include
endif

# ------------------------------------------------------------------------
# 	C Compiler options 
# ------------------------------------------------------------------------

DEFINES       =	-D_X86_=1 -D__STDC__ -DWIN32 -DCONSOLE -D_MT \
		$(DEBUG_DEFINES) $(SHLIB_DEFINES) $(EXTRA_DEFINES) 

ifeq ($(SHARED),1)
SHLIB_DEFINES =	-D_DLL
SHLIB_TARGET  =	build-dll
LIBS          =	$(COMMON_LIBS) 
else
SHLIB_DEFINES =	-D_CTYPE_DISABLE_MACROS
LIBS          =	$(COMMON_LIBS) $(EXTRA_LIBS)
endif

ifeq ($(DEBUG),1)
CFLAGS        =	-Z7 -Od
DEBUG_LDFLAGS =	-debug:full -debugtype:cv  
DEBUG_DEFINES = -DUSE_TCLALLOC=0
TK_LIB        =	$(TKDIR)/win/Debug/tk$(v2)d.lib  
TCL_LIB       =	$(TCLDIR)/win/Debug/tcl$(v2)d.lib 
MSVCRT        =	msvcrtd.lib
else
CFLAGS        =	-Ox -GB -GD 
DEBUG_LDFLAGS =	-debug:full -debugtype:cv  
TK_LIB        =	$(TKDIR)/win/Release/tk$(v2).lib  
TCL_LIB       =	$(TCLDIR)/win/Release/tcl$(v2).lib 
MSVCRT        =	msvcrt.lib
endif

EXTRA_CFLAGS  =	-nologo -W3 

# ------------------------------------------------------------------------
# 	Linker flags and options 
# ------------------------------------------------------------------------

COMMON_LDFLAGS = -nodefaultlib -release -nologo -warn:3 \
		-machine:IX86 -align:0x1000 \
		$(DEBUG_LDFLAGS)

DLLENTRY      =	@12
SHLIB_LDFLAGS = $(COMMON_LDFLAGS) \
		-subsystem:console -entry:mainCRTStartup \
		-subsystem:windows -entry:WinMainCRTStartup \
		-entry:_DllMainCRTStartup$(DLLENTRY) -dll  

LDFLAGS       =	$(COMMON_LDFLAGS) \
		-fixed:NO -stack:2300000 

COMMON_LIBS   =	$(TK_LIB) $(TCL_LIB) \
		$(MSVCRT) \
		kernel32.lib user32.lib 

EXTRA_LIBS    =	$(OLELIB) \
		$(JPEGLIB) \
		gdi32.lib \
		oldnames.lib \
		advapi32.lib \
		winspool.lib \
		comdlg32.lib

TCL_ONLY_LIBS = $(TCL_LIB) $(MSVCRT)  kernel32.lib user32.lib advapi32.lib 


# ------------------------------------------------------------------------
# 	Source and target installation directories 
# ------------------------------------------------------------------------

srcdir        =	.
instdirs      =	$(prefix) $(exec_prefix) $(bindir) $(libdir) \
			$(includedir)
instdirs      =	$(exec_prefix) $(prefix) $(libdir)

# ------------------------------------------------------------------------
# 	Directories containing Tcl and Tk include files and libraries
# ------------------------------------------------------------------------

TCLDIR        =	$(srcdir)/../../tcl$(v3)
TKDIR         =	$(srcdir)/../../tk$(v3)
INCLUDES      =	-I. -I$(srcdir) \
		-I$(TOOLS32)/include \
		-I$(JPEGINC) \
		-I$(TCLDIR)/win -I$(TCLDIR)/generic \
		-I$(TKDIR)/win -I$(TKDIR)/generic -I$(TKDIR)/xlib \

#-I$(TCLROOT)/include

SHLIB_LD_LIBS =	$(COMMON_LIBS) $(EXTRA_LIBS)

# ------------------------------------------------------------------------
# 	You don't need to edit anything beyond this point
# ------------------------------------------------------------------------

N_OBJS       =	bltTed.o
V3_OBJS       =	bltTri.o bltGrMt.o 

TK_OBJS       =	tkButton.o tkFrame.o tkScrollbar.o 

GRAPH_OBJS =	bltGrAxis.o \
		bltGrBar.o \
		bltGrElem.o \
		bltGrGrid.o \
		bltGrHairs.o \
		bltGrLegd.o \
		bltGrLine.o \
		bltGrMarker.o \
		bltGrMisc.o \
		bltGrPen.o \
		bltGrPs.o \
		bltGraph.o 

TCL_ONLY_OBJS =	bltAlloc.o \
		bltArrayObj.o \
		bltBgexec.o \
		bltChain.o \
		bltDebug.o \
		bltHash.o \
		bltList.o \
		bltNsUtil.o \
		bltParse.o \
		bltPool.o \
		bltSpline.o \
		bltSwitch.o \
		bltTree.o \
		bltTreeCmd.o \
		bltUtil.o \
		bltVecCmd.o \
		bltVecMath.o \
		bltVecObjCmd.o \
		bltVector.o \
		bltWatch.o  \
		bltWinPipe.o \
		bltWinUtil.o \
		bltWinDde.o \
		pure_api.o

DEMO_OBJS     =	tkConsole.o bltWinMain.o

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
		bltBitmap.o \
		bltBusy.o \
		bltCanvEps.o \
		bltConfig.o \
		bltContainer.o \
		bltDragdrop.o \
		bltHierbox.o \
		bltHtext.o \
		bltImage.o \
		bltWinImage.o \
		bltPs.o \
		bltTable.o \
		bltTabnotebook.o \
		bltTabset.o \
		bltText.o \
		bltTile.o \
		bltTreeView.o \
		bltTreeViewCmd.o \
		bltTreeViewEdit.o \
		bltTreeViewColumn.o \
		bltTreeViewStyle.o \
		bltWinDraw.o \
		bltWinPrnt.o \
		bltWindow.o \
		bltObjConfig.o \
		bltWinop.o \
		$(TK_OBJS) $(N_OBJS) 

NOT_YET       =	bltContainer.o bltCutBuffer.o bltColor.o

HEADERS       =	blt.h bltChain.h bltVector.h bltTree.h bltPool.h bltHash.h

# GNU Make-specific macro
SRCS          =	$(patsubst %.o,$(srcdir)/%.c,$(OBJS)) 

shell_name    = bltwish
version       =	$(BLT_MAJOR_VERSION)$(BLT_MINOR_VERSION)
bltwish =	bltwish.exe
bltsh =		bltsh.exe
bltwish2 =	bltwish$(version).exe
bltsh2 =	bltsh$(version).exe

lib_name =	BLT$(version)
lib_a =		BLT$(version).lib
lib_so =	BLT$(version).dll		
tcl_only_lib_a = BLTlite$(version).lib
tcl_only_lib_so = BLTlite$(version).dll		

CC_SWITCHES   =	$(CFLAGS) $(EXTRA_CFLAGS) $(DEFINES) $(INCLUDES)
VPATH         =	$(srcdir)

all: build-library $(SHLIB_TARGET) build-demos

install: all install-dirs install-headers install-binaries install-demos

build-demos: $(SHLIB_TARGET) $(bltwish) $(bltsh)

build-library: $(lib_a) $(tcl_only_lib_a)

build-dll: build-library $(lib_so) $(tcl_only_lib_so)

$(bltwish): $(lib_a) tkConsole.o  bltWinMain.c
	$(RM) $(bltwish) 
	$(CC) -c $(CC_SWITCHES) -DTCLLIBPATH=\"$(TCLLIBPATH)\" \
		-FobltWinMain.o $(srcdir)/bltWinMain.c
	LIB=$(TOOLS32)/lib \
	$(LD) $(LDFLAGS) tkConsole.o bltWinMain.o -out:$(bltwish) \
		$(lib_a) $(LIBS) 

$(bltsh): $(tcl_only_lib_a) bltWinMain.c
	$(RM) $(bltsh) 
	$(CC) -c $(CC_SWITCHES) -DTCL_ONLY \
		-DTCLLIBPATH=\"$(TCLLIBPATH)\" \
		-FobltWinMain.o $(srcdir)/bltWinMain.c
	LIB=$(TOOLS32)/lib \
	$(LD) $(LDFLAGS) bltWinMain.o -out:$(bltsh) \
		$(tcl_only_lib_a) $(TCL_ONLY_LIBS) 

$(lib_a):  bltHash.h $(OBJS) bltInit.c
	$(RM) bltInit.o
	$(CC) -c $(CC_SWITCHES)  -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		-FobltInit.o $(srcdir)/bltInit.c
	$(RM) $@
	$(AR) -out:$@ bltInit.o $(OBJS)

$(lib_so): $(lib_a) $(OBJS) bltInit.c
	$(RM) bltInit.o
	$(CC) -c $(CC_SWITCHES) -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		-FobltInit.o $(srcdir)/bltInit.c
	$(RM) $@
	LIB=$(TOOLS32)/lib \
	$(LD) $(SHLIB_LDFLAGS) -out:$@ bltInit.o $(OBJS) $(SHLIB_LD_LIBS)

$(tcl_only_lib_a):  bltHash.h $(TCL_ONLY_OBJS) bltInit.c
	$(RM) bltInit.o
	$(CC) -c $(CC_SWITCHES) -DTCL_ONLY -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		-FobltInit.o $(srcdir)/bltInit.c
	$(RM) $@
	$(AR) -out:$@ bltInit.o $(TCL_ONLY_OBJS) 

$(tcl_only_lib_so): $(tcl_only_lib_a) $(TCL_ONLY_OBJS) bltInit.c
	$(RM) bltInit.o
	$(CC) -c $(CC_SWITCHES) -DTCL_ONLY -DBLT_LIBRARY=\"$(BLT_LIBRARY)\" \
		-FobltInit.o $(srcdir)/bltInit.c
	$(RM) $@
	LIB=$(TOOLS32)/lib \
	$(LD) $(SHLIB_LDFLAGS) -out:$@ bltInit.o $(TCL_ONLY_OBJS) \
		$(TCL_ONLY_LIBS) 

bltHash.h: bltHash.h.in
	sed -e 's/@SIZEOF_VOID_P@/4/' \
	    -e 's/@SIZEOF_INT@/4/' \
	    -e 's/@SIZEOF_LONG@/4/' \
	    -e 's/@SIZEOF_LONG_LONG@/8/' \
	    -e 's/@HAVE_INTTYPES_H@/0/' \
	    bltHash.h.in > bltHash.h

install-dirs:
	@for i in $(instdirs) ; do \
	    if test ! -d "$$i" ; then \
		echo " mkdir $$i" ; \
		mkdir "$$i" ; \
	    fi ; \
        done

install-binaries: install-lib install-demos 

install-demos: build-demos
	$(INSTALL) $(bltwish) $(bindir)/$(bltwish)
	$(INSTALL) $(bltwish) $(bindir)/$(bltwish2)
	$(INSTALL) $(bltsh) $(bindir)/$(bltsh)
	$(INSTALL) $(bltsh) $(bindir)/$(bltsh2)

install-lib: $(lib_so) $(lib_a) 
	$(INSTALL_DATA) $(lib_so) $(bindir)
	$(INSTALL_DATA) $(lib_a) $(libdir)
	$(INSTALL_DATA) $(tcl_only_lib_so) $(bindir)
	$(INSTALL_DATA) $(tcl_only_lib_a) $(libdir)

install-headers:
	for i in $(HEADERS) ; do \
	    $(INSTALL_DATA) "$(srcdir)/$$i" $(includedir) ; \
	done

lint:
	$(LINT) $(LINTFLAGS) $(DEFINES) $(INCLUDES) $(SRCS)

clean:
	$(RM) *.o *.pdb *.exp \
		$(lib_a) $(lib_so) $(tcl_only_lib_a) $(tcl_only_lib_so) \
		$(bltwish) $(bltsh) $(bltwish2) $(bltsh2)
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  

distclean: clean
	$(RM) Makefile

.c.o:
	$(CC) -c $(CC_SWITCHES) -Fo$*.o $<

