# This file is the Makefile for TkDesk.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix =	@prefix@
exec_prefix =	@exec_prefix@

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT =

# Directory from which TkDesk will reference its library of Tcl scripts:
TKDESK_LIBRARY =	$(prefix)/lib/TkDesk

# Path name to use when installing library scripts:
SCRIPT_INSTALL_DIR =	$(INSTALL_ROOT)$(TKDESK_LIBRARY)

# Directory where tkdesksh will look for its library scripts:
SCRIPT_SEARCH_DIR =	$(SCRIPT_INSTALL_DIR)

# Directory in which to install the program tkdesksh:
BIN_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/bin

# Directory where tkdesksh will look for the tkdesk script:
BIN_SEARCH_DIR =	$(BIN_INSTALL_DIR)

# Top-level directory in which to install manual entries:
MAN_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/man

# Directory in which to install manual entry for tkdesk:
MAN1_INSTALL_DIR =	$(MAN_INSTALL_DIR)/man1

# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CC_OPTS = -O

# To change the linker switches, for example to add -s,
# change the following line:
LD_OPTS = @LDFLAGS@

# Tcl used to let the configure script choose which program to use
# for installing, but there are just too many different versions of
# "install" around;  better to use the install-sh script that comes
# with the distribution, which is slower but guaranteed to work.

INSTALL =		@srcdir@/install-sh -c
INSTALL_PROGRAM =	${INSTALL} -m 755
INSTALL_DATA =		${INSTALL} -m 644

#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

# Location of Tcl header files:
TCL_INCLUDE_DIR =	@TCL_INCLUDE_PATH@

# Location of Tk header files:
TK_INCLUDE_DIR =	@TK_INCLUDE_PATH@

# Location of X11 header files:
X_INCLUDE_FLAG =	@TK_XINCLUDES@

# Specification of Tcl library:
TCL_LIB_SPEC   =	@TCL_LIB_SPEC@
TCL_LIB_STATIC =	@TCL_LIB_STATIC@

# Specification of Tk library:
TK_LIB_SPEC    =	@TK_LIB_SPEC@
TK_LIB_STATIC  =	@TK_LIB_STATIC@

# Specification if itcl library:
ITCL_LIB_SPEC   =       @ITCL_LIB_SPEC@
ITCL_LIB_STATIC =       @ITCL_LIB_STATIC@

# Directory in which to install libtcl.so or libtcl.a:
LIB_INSTALL_DIR =	@TK_EXEC_PREFIX@/lib

# Path to use at runtime to refer to LIB_INSTALL_DIR:
LIB_RUNTIME_DIR =	$(LIB_INSTALL_DIR)

# Complete library option string to pass to linker:
LIBS =			$(ITCL_LIB_SPEC) $(TK_LIB_SPEC) $(TCL_LIB_SPEC) @TK_LIBS@
LIBS_STATIC =		$(ITCL_LIB_STATIC) $(TK_LIB_STATIC) $(TCL_LIB_STATIC) @TK_LIBS@

# Miscellaneous settings:
AC_FLAGS =		@DEFS@
SRC_DIR =		@srcdir@
RANLIB =		@RANLIB@
CC =			@CC@
SHELL =                 /bin/sh

# Command for creating directories.  Alternatives include "mkdir"
# and "mkdirhier".
MKDIR =                 mkdir -p

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------

CFLAGS =	${CC_OPTS} ${AC_FLAGS} -I. -I${TCL_INCLUDE_DIR} -I${TK_INCLUDE_DIR} ${X_INCLUDE_FLAG}
LDFLAGS =	${LD_OPTS}

PKGNAME =	tkdesk
VERSION =	1.0
FVERSION =	10
PKGDIR =	$(PKGNAME)-$(VERSION)

all: shell client tkdesk_script
	@echo "========= Build complete."
	@echo " "
	@echo "You can try out TkDesk before installing it by commenting"
	@echo "out the sixth line in the file tkdesk and then executing:"
	@echo "./tkdesksh tkdesk -default"

shell: makelibs tkAppInit.o
	$(CC) $(LDFLAGS) @TCL_LD_SEARCH_FLAGS@ -o tkdesksh \
		tkAppInit.o libdesk/libdesk.a netscape-remote/libnetscape.a \
		blt/libBLT.a $(LIBS)

static: makelibs tkAppInit-static.o client tkdesk_script
	$(CC) $(LDFLAGS) @TCL_LD_SEARCH_FLAGS@ -o tkdesksh \
		tkAppInit-static.o libdesk/libdesk.a netscape-remote/libnetscape.a \
		blt/libBLT.a itcl/libitcl.a $(LIBS_STATIC)

tkAppInit-static.o: tkAppInit.c
	$(CC) $(CFLAGS) -DSTATIC_BUILD -DTKDESK_LIBRARY="\"@prefix@/lib/TkDesk\"" -c tkAppInit.c -o $@

makelibs: lib_blt @NEED_ITCL_LIB@ lib_netscape lib_libdesk

lib_blt:
	cd blt; $(MAKE) CC_OPTS="$(CC_OPTS)" LIB_DIR="$(SCRIPT_SEARCH_DIR)" lib

lib_itcl:
	cd itcl; $(MAKE) CC_OPTS="$(CC_OPTS)" lib

lib_netscape:
	cd netscape-remote; $(MAKE) CC_OPTS="$(CC_OPTS)" lib

lib_libdesk:
	cd libdesk; $(MAKE) CC_OPTS="$(CC_OPTS)" lib

client:
	cd tkdeskclient; $(MAKE) CC_OPTS="$(CC_OPTS)" LD_OPTS="$(LD_OPTS)" all

tkdesk_script:
	@echo '#!/bin/sh' >tkdesk
	@echo '#-*- tcl -*- \' >>tkdesk
	@echo "PATH=$(BIN_SEARCH_DIR):"'$$PATH ;#\' >>tkdesk
	@echo "exec tkdesksh \"\$$0\" \"\$$@\"" >>tkdesk
	@echo "" >>tkdesk
	@echo "set tkdesk(library) \"$(SCRIPT_SEARCH_DIR)\"" >>tkdesk
	@echo "set tkdesk(in_development) 0" >>tkdesk
	@echo "set tkdesk(no_auto_loading) 0" >>tkdesk
	@echo "set tkdesk(debug) 0" >>tkdesk
	@cat tkdesk.main >>tkdesk
	@chmod 755 tkdesk

rm_tkdesk_script:
	@rm -f tkdesk

install: shell client rm_tkdesk_script tkdesk_script dirs
	@chmod +x install-sh
	@echo "=== Installing the executables..."
	@for f in tkdesksh tkdesk tkdeskclient/tkdeskclient tools/pauseme tools/ed-tkdesk tools/cd-tkdesk tools/od-tkdesk tools/op-tkdesk tools/pop-tkdesk; do \
	    echo "installing $$f" ;\
	    rm -f $(BIN_INSTALL_DIR)/`basename $$f` ;\
	    $(INSTALL_PROGRAM) $$f $(BIN_INSTALL_DIR) ;\
	done
	@echo "=== Installing TkDesk's library..."
	@cd ./tcldesk; tar cf - * | (cd $(SCRIPT_INSTALL_DIR); tar xvf -)
	@echo "=== Setting permissions..."
	find $(SCRIPT_INSTALL_DIR) -type f -exec chmod a+r {} \;
	find $(SCRIPT_INSTALL_DIR) -type d -exec chmod a+rx {} \;
	@echo "=== Creating index..."
	cd $(SCRIPT_INSTALL_DIR); $(BIN_INSTALL_DIR)/tkdesksh mkindex
	@echo "=== Installing the manual pages..."
	@for f in tkdesk.1 cd-tkdesk.1 ed-tkdesk.1 od-tkdesk.1; do \
	    echo "installing $$f" ;\
	    rm -f $(MAN1_INSTALL_DIR)/$$f ;\
	    $(INSTALL_DATA) doc/$$f $(MAN1_INSTALL_DIR) ;\
	done
	@echo "=== Installation complete."

uninstall:
	@echo "=== Uninstalling TkDesk's library..."
	-rm -r $(SCRIPT_INSTALL_DIR)
	@echo "=== Uninstalling TkDesk's executables..."
	-rm $(BIN_INSTALL_DIR)/tkdesksh $(BIN_INSTALL_DIR)/tkdesk $(BIN_INSTALL_DIR)/pauseme $(BIN_INSTALL_DIR)/ed-tkdesk $(BIN_INSTALL_DIR)/cd-tkdesk $(BIN_INSTALL_DIR)/od-tkdesk $(BIN_INSTALL_DIR)/op-tkdesk $(BIN_INSTALL_DIR)/pop-tkdesk $(BIN_INSTALL_DIR)/tkdeskclient
	@echo "=== Done."

dirs:
	@for i in $(SCRIPT_INSTALL_DIR) $(BIN_INSTALL_DIR) $(MAN1_INSTALL_DIR); \
	    do \
	    	if [ ! -d $$i ] ; then \
		    echo "Making directory $$i"; \
		    $(MKDIR) $$i; \
		    chmod 755 $$i; \
		fi; \
	    done;


clean:
	cd blt; $(MAKE) clean
	cd itcl; $(MAKE) clean
	cd netscape-remote; $(MAKE) clean
	cd libdesk ; $(MAKE) clean
	cd tkdeskclient ; $(MAKE) clean
	cd tcldesk ; rm -f #*#
	rm -f *.o tkdesksh

tags:
	find . \( -name "*.c" -o -name "*.tcl" \) -print | etags -

export:
	@echo "Making distribution for $(PKGDIR) ..."
	@echo "Did you think about updating tkdesk.main and CFLAGS?"
	@(cd .. ;\
	mkdir $(PKGDIR) ;\
	mkdir $(PKGDIR)/blt ;\
	mkdir $(PKGDIR)/blt/cf ;\
	mkdir $(PKGDIR)/blt/src ;\
	mkdir $(PKGDIR)/doc ;\
	mkdir $(PKGDIR)/itcl ;\
	mkdir $(PKGDIR)/itcl/src ;\
	mkdir $(PKGDIR)/netscape-remote ;\
	mkdir $(PKGDIR)/tkdeskclient ;\
	mkdir $(PKGDIR)/libdesk ;\
	mkdir $(PKGDIR)/tcldesk ;\
	mkdir $(PKGDIR)/tcldesk/cb_tools ;\
	mkdir $(PKGDIR)/tcldesk/cb_tools/bitmaps ;\
	mkdir $(PKGDIR)/tcldesk/doc ;\
	mkdir $(PKGDIR)/tcldesk/images ;\
	mkdir $(PKGDIR)/tcldesk/images/ficons16 ;\
	mkdir $(PKGDIR)/tcldesk/images/ficons32 ;\
	mkdir $(PKGDIR)/tcldesk/images/be ;\
	mkdir $(PKGDIR)/tcldesk/images/next ;\
	mkdir $(PKGDIR)/tcldesk/images/xbm ;\
	mkdir $(PKGDIR)/tcldesk/sounds ;\
	mkdir $(PKGDIR)/tcldesk/configs ;\
	mkdir $(PKGDIR)/tcldesk/configs/.trash ;\
	mkdir $(PKGDIR)/tcldesk/tcl_lib ;\
	mkdir $(PKGDIR)/tcldesk/tk_lib ;\
	mkdir $(PKGDIR)/tools ;\
	mkdir $(PKGDIR)/contrib ;\
	cp TkDesk/{COPYING,INSTALL,*.in,TODO,license.terms,README,CREDITS} \
		TkDesk/{configure,*.c,tkdesk.main,install-sh} $(PKGDIR) ;\
	cp TkDesk/blt/{Makefile.in,README,README.BLT,*.h,*.c} \
		$(PKGDIR)/blt ;\
	cp TkDesk/doc/{guide.sgml,guide.txt,guide.ps,*.1} $(PKGDIR)/doc ;\
	cp TkDesk/itcl/{Makefile.in,README,*.c,*.h} \
		$(PKGDIR)/itcl ;\
	cp TkDesk/netscape-remote/{Makefile.in,COPYRIGHT,README,*.c} \
		$(PKGDIR)/netscape-remote ;\
	cp TkDesk/tkdeskclient/{Makefile.in,*.c} \
		$(PKGDIR)/tkdeskclient ;\
	cp TkDesk/libdesk/{Makefile.in,*.c,*.h} $(PKGDIR)/libdesk ;\
	cp TkDesk/tcldesk/{*.tcl,tclIndex,mkindex} $(PKGDIR)/tcldesk ;\
	cp TkDesk/tcldesk/cb_tools/{*.tcl,tclIndex,mkindex} \
		$(PKGDIR)/tcldesk/cb_tools ;\
	cp TkDesk/tcldesk/cb_tools/bitmaps/*.xbm \
		$(PKGDIR)/tcldesk/cb_tools/bitmaps ;\
	cp TkDesk/tcldesk/doc/{License,Guide,*.html} $(PKGDIR)/tcldesk/doc ;\
	cp TkDesk/tcldesk/doc/QuickStart $(PKGDIR)/tcldesk/doc ;\
	cp TkDesk/CHANGES $(PKGDIR)/tcldesk/doc ;\
	cp TkDesk/tcldesk/images/*.xpm $(PKGDIR)/tcldesk/images ;\
	cp TkDesk/tcldesk/images/ficons16/*.xpm \
		$(PKGDIR)/tcldesk/images/ficons16 ;\
	cp TkDesk/tcldesk/images/ficons32/*.xpm \
		$(PKGDIR)/tcldesk/images/ficons32 ;\
	cp TkDesk/tcldesk/images/be/*.xpm \
		$(PKGDIR)/tcldesk/images/be ;\
	cp TkDesk/tcldesk/images/next/*.xpm \
		$(PKGDIR)/tcldesk/images/next ;\
	cp TkDesk/tcldesk/images/xbm/*.xbm \
		$(PKGDIR)/tcldesk/images/xbm ;\
	cp TkDesk/tcldesk/sounds/*.au $(PKGDIR)/tcldesk/sounds ;\
	cp TkDesk/tcldesk/configs/{AppBar,AppBar_Be,AppBar_Games} \
                TkDesk/tcldesk/configs/{ButtonBar,Commands,Directories} \
		TkDesk/tcldesk/configs/{FileTags,Popups} \
		TkDesk/tcldesk/configs/{Sounds,System} \
		$(PKGDIR)/tcldesk/configs ;\
	cp TkDesk/tcldesk/tcl_lib/* $(PKGDIR)/tcldesk/tcl_lib ;\
	cp TkDesk/tcldesk/tk_lib/* $(PKGDIR)/tcldesk/tk_lib ;\
	cp TkDesk/tools/{*-tkdesk,pauseme} $(PKGDIR)/tools ;\
	cp TkDesk/contrib/* $(PKGDIR)/contrib ;\
	tar czvpf $(PKGDIR).tar.gz $(PKGDIR) ;\
	mv $(PKGDIR).tar.gz TkDesk ;\
	rm -rf $(PKGDIR) )

floppy:
	-mdel a:tkdsk$(FVERSION).tgz
	mcopy $(PKGNAME)-$(VERSION).tar.gz a:tkdsk$(FVERSION).tgz
	mdir a:
