# ------------------------------------------------------------------------
# 	Makefile for static version of BLT library
# ------------------------------------------------------------------------

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

BLT_LIBRARY =	@BLT_LIBRARY@
CC =		@CC@
CFLAGS =	@CFLAGS@ 
DEFINES =	@DEFINES@
EXTRA_CFLAGS =	@GCCFLAGS@
LDFLAGS =	@LDFLAGS@
version =	@BLT_MAJOR_VERSION@@BLT_MINOR_VERSION@

# ------------------------------------------------------------------------
# 	Source and targer installation directories 
# ------------------------------------------------------------------------

bindir =	$(exec_prefix)/bin
exec_prefix =	@exec_prefix@
incdir =	$(prefix)/include
libdir =	$(exec_prefix)/lib
prefix =	@prefix@
srcdir =	@srcdir@

instdirs =	$(prefix) $(exec_prefix) $(bindir) $(libdir) $(incdir)

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

INCLUDES =	-I. -I$(srcdir) @INCLUDES@

# ------------------------------------------------------------------------
#       Libraries directives for Tcl, Tk, X11, and BLT
# ------------------------------------------------------------------------

LIBS =		@LIB_SPECS@ @EXTRA_LIB_SPECS@
TCL_ONLY_LIBS = @TCL_ONLY_LIB_SPECS@ @EXTRA_LIB_SPECS@

# ------------------------------------------------------------------------
# 	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 =	bltBgexec.o bltChain.o bltDebug.o bltList.o \
		bltNsUtil.o bltParse.o bltSpline.o bltTree.o \
		bltTreeCmd.o bltUnixPipe.o bltUtil.o bltVector.o \
		bltWatch.o 

OBJS =		$(GRAPH_OBJS) \
		$(TCL_ONLY_OBJS) \
		bltBeep.o \
		bltBind.o \
		bltBitmap.o \
		bltBusy.o \
		bltCanvEps.o \
		bltColor.o \
		bltConfig.o \
		bltContainer.o \
		bltCutbuffer.o \
		bltDnd.o \
		bltHierbox.o \
		bltHiertable.o \
		bltHtCmd.o \
		bltHtColumn.o \
		bltHtText.o \
		bltHtext.o \
		bltImage.o \
		bltPs.o \
		bltTable.o \
		bltTabnotebook.o \
		bltTabset.o \
		bltText.o \
		bltTile.o \
		bltUnixDnd.o \
		bltWindow.o \
		bltWinop.o \
		$(TK_OBJS) $(N_OBJS) 

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

bltwish =	bltwish
bltsh =		bltsh
headers =	blt.h bltChain.h bltVector.h bltTree.h
lib_a =		libBLT.a
libvers_a =	libBLT$(version).a
tcl_only_lib_a =  libBLTlite.a
tcl_only_libvers_a = libBLTlite$(version).a

CC_SWITCHES =	$(EXTRA_CFLAGS) $(CFLAGS) $(DEFINES) $(INCLUDES)
INSTALL =	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@
RANLIB =	@RANLIB@
SHELL =		/bin/sh
AR =		ar rc
RM =		rm -f
LINT =		lint
LINTFLAGS =	-axhbns
LN_S =		@LN_S@
VPATH =		$(srcdir)

all: $(bltwish) $(bltsh) @SHLIB_TARGET@

build_shared:
	(cd shared; $(MAKE) CFLAGS="$(CFLAGS)" all) 

$(bltwish): $(lib_a)
	$(RM) $(bltwish)
	$(CC) $(CC_SWITCHES) $(LDFLAGS) -o $(bltwish) \
		$(srcdir)/bltUnixMain.c $(lib_a) $(LIBS) 

$(bltsh): $(tcl_only_lib_a)
	$(RM) $(bltsh)
	$(CC) $(CC_SWITCHES) $(LDFLAGS) -DTCL_ONLY -o $(bltsh) \
		$(srcdir)/bltUnixMain.c $(tcl_only_lib_a) $(TCL_ONLY_LIBS) 

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

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

install: install_dirs install_lib install_demo install_headers

install_demo: $(bltwish) $(bltsh)
	$(INSTALL) -m 0755 $(bltwish) $(bindir)
	$(INSTALL) -m 0755 $(bltsh) $(bindir)

install_lib: $(lib_a)
	$(INSTALL_DATA) $(lib_a) $(libdir)/$(libvers_a)
	(cd $(libdir); $(RM) $(lib_a) ; $(LN_S) $(libvers_a) $(lib_a))
	$(RANLIB) $(libdir)/$(libvers_a)
	$(INSTALL_DATA) $(tcl_only_lib_a) $(libdir)/$(tcl_only_libvers_a)
	(cd $(libdir); $(RM) $(tcl_only_lib_a) ; $(LN_S) $(tcl_only_libvers_a) $(tcl_only_lib_a))
	$(RANLIB) $(libdir)/$(tcl_only_libvers_a)
	(cd shared; $(MAKE) install) 

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

install_headers:
	@for i in $(headers) ; do \
	    echo "installing $(incdir)/$$i..." ; \
	    $(INSTALL_DATA) -m 0444 $(srcdir)/$$i $(incdir) ; \
	done

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

clean:
	$(RM) $(OBJS) bltInit.o $(lib_a) $(tcl_only_lib_a) \
		$(bltsh)* $(bltwish)* *pure* .pure*
	(cd shared; $(MAKE) clean) 

distclean: clean
	$(RM) $(srcdir)/*.bak $(srcdir)/*\~ $(srcdir)/"#"*  Makefile
	$(RM) bltConfig.h Makefile TAGS


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

PUREFLAGS=
pure: $(lib_a)
	$(PURIFYHOME)/purify $(PUREFLAGS) $(CC) $(CC_SWITCHES) \
		$(srcdir)/bltUnixMain.c -o bltwish $(lib_a) $(LIBS)

QUANTIFYFLAGS=
quant: $(lib_a)
	$(QUANTIFYHOME)/quantify $(QUANTIFYFLAGS) $(CC) $(CC_SWITCHES) \
		$(srcdir)/bltUnixMain.c -o bltwish $(lib_a) $(LIBS)
