#
# File Makefile.postamble
#
# The postamble contains additional rules for building the library and
# installing the library, headers, and images.
#


# ==============================================================================


#
# The 'all' target should build the library as well as the palette.
#

all:: library


# ==============================================================================


#
# Precompiled headers don't seem to get a dependency.
#

$(PRECOMPS) : $(HFILES) 


# ==============================================================================


# 
# The rules below provide a library target to collect object files into an
# archive.  To use it, set LIBRARY to the name of the archive and LIB_OFILES
# to indicate the files that go into it.  The Makefile uses LIBTOOL if
# available, AR otherwise.
#
# The rules do some checking to make sure things configure properly under 3.0,
# 3.1 and 3.2.
#

LIBRARY = libIconKit.a
LIB_OFILES = IKAnnouncer.o IKBrowser.o IKBrowserCell.o IKBrowserManager.o\
             IKCell.o IKFolder.o IKIconPath.o IKList.o IKShelf.o\
			 IKSuitcase.o IKCellPS.o IKfunctions.o

LIBTOOL = /bin/libtool
AR = /bin/ar

library::
	@( \
	if [ -n '$(process_target_archs)' "" ]; then $(process_target_archs)_obj ; \
	elif [ -n '$(RC_ARCHS)' "" ]; then \
		evaled_rc_archs="$(RC_ARCHS)" ; \
		obj_dir=`echo $$evaled_rc_archs | sed 's/ /_/g'`_obj ; \
	fi ; \
	if [ -n '$(OBJROOT)' "" ]; then obj_root='$(OBJROOT)'; else obj_root=.; fi;\
	if [ -f '$(LIBTOOL)' ]; then \
		archive='$(LIBTOOL) -o $(LIBRARY) $(LIBTOOLFLAGS) $(LIB_OFILES)' ; else\
		archive='$(AR) rc $(LIBRARY) $(LIB_OFILES)' ; \
	fi ; \
	\
 	$(MAKE) $(LIBRARY) \
 		"OFILE_DIR = $$obj_root/$${obj_dir-obj}" \
 		"PROJ_CFLAGS = $(NORMAL_CFLAGS)" \
 		"MAKEFILEDIR = $(MAKEFILEDIR)" \
 		"RC_CFLAGS = $(RC_CFLAGS)" \
 		"SRCROOT = $(SRCROOT)" \
 		"OBJROOT = $$obj_root" \
 		"PRODUCT_ROOT = $(PRODUCT_ROOT)" \
 		"ARCHIVE = $$archive" \
 		"SYMROOT = $(SYMROOT)/sym" \
 		"SYM_DIR = $(SYMROOT)/sym" )

$(LIBRARY): $(INITIAL_TARGETS) $(LIB_OFILES)
	rm -f $(LIBRARY)
	$(ARCHIVE)
	$(RANLIB) $(RANLIBFLAGS) $(LIBRARY)
	$(CHMOD) a+r $(LIBRARY)


# ==============================================================================


#
# Here is the rule to install the header files, library, and images.
# Everything's already neatly collected, so we just copy it after uninstalling
# any previous versions that may exist.
#

INSTALL = /usr/bin/install

before_install:: uninstall

after_install:: library install_iconKit remake_iconkitp

install_iconKit:
	@$(MKDIRS) $(DSTROOT)$(INSTALLLIBDIR)
	@$(MKDIRS) $(DSTROOT)$(INSTALLHEADERDIR)
	@$(MKDIRS) $(DSTROOT)$(INSTALLIMAGEDIR)
	@$(MKDIRS) $(DSTROOT)$(INSTALLDOCDIR)
	@$(MKDIRS) $(DSTROOT)$(INSTALLEXAMPLEDIR)
	$(INSTALL) -r $(LIBRARY) $(DSTROOT)$(INSTALLLIBDIR)
	$(TAR) chf - iconkit | (cd $(DSTROOT)$(INSTALLHEADERDIR); $(TAR) xf -)
	rm $(DSTROOT)$(INSTALLHEADERDIR)/iconkit/iconkit.p
	(cd images; $(TAR) chf - .) | (cd $(DSTROOT)$(INSTALLIMAGEDIR); $(TAR) xf -)
	(cd documentation; $(TAR) cf - .) \
			| (cd $(DSTROOT)$(INSTALLDOCDIR); $(TAR) xf -)
	cd ../FileViewer; $(MAKE) installsrc \
			"SRCROOT = $(DSTROOT)$(INSTALLEXAMPLEDIR)/FileViewer"
	cd .. ; $(TAR) chf - Widgets \
			| (cd $(DSTROOT)$(INSTALLEXAMPLEDIR); $(TAR) xf -)
	$(MAKE) installsrc "SRCROOT = $(DSTROOT)$(INSTALLSRCDIR)"

remake_iconkitp: $(DSTROOT)$(INSTALLHEADERDIR)/iconkit/iconkit.p


# ==============================================================================


#
# The uninstall target deletes all the installed files.
#

uninstall:
	$(RM) -rf $(DSTROOT)$(INSTALLDIR)/$(NAME).palette
	$(RM) -rf $(DSTROOT)$(INSTALLLIBDIR)/$(LIBRARY)
	$(RM) -rf $(DSTROOT)$(INSTALLHEADERDIR)/iconkit
	$(RM) -rf $(DSTROOT)$(INSTALLIMAGEDIR)
	$(RM) -rf $(DSTROOT)$(INSTALLDOCDIR)
	$(RM) -rf $(DSTROOT)$(INSTALLEXAMPLEDIR)
	$(RM) -rf $(DSTROOT)$(INSTALLSRCDIR)
