# Top-level MiscKit Makefile Version 1.10.0
# Originally By Mike Ferris as Part of MOKit
# Modified by Don Yacktman for use by the MiscKit, by permission
# Copyright (C) 1994, 1995, 1996, 1997 by Don Yacktman, all rights reserved.

#########################################################################
# Here are the things that you can safely configure...                  #
#  1.  Where the MiscKit is installed                                   #
#  2.  Whether or not the audio alerts are played                       #
#  3.  Whether or not the README is forced upon you                     #
#  4.  Which target architectures which are compiled                    #
#  5.  Special flags used when building precompiled headers             #
#  6.  Where to find a "tar" command that can handle long filenames     #
#########################################################################

# Change root to somewhere in your account if you can't install to
# /LocalDeveloper...  Warning:  do not use a ~ in ROOT; it must be absolute!
ROOT = 

# Go ahead and change these to suit your taste--and patience.
AUDIOALERTS = YES # Anything but "YES" will shut them up.
SHOWREADME = YES # Anything but "YES" will supress automatic opening...

# Below, uncomment the architectures that you want.  Make sure your compiler
# actually supports the selected architectures for it to work!
# Comment out any that aren't useful to you or your compiler won't support.
MOTOROLA_ARCH = m68k # Motorola (680x0) architecture
INTEL_ARCH = i386 # Intel x86 architecture
HP_ARCH = hppa # PA-RISC architecture
SPARC_ARCH = sparc # SPARC architecture
POWER_ARCH = #m98k # Power PC architecture.  Yeah, this is wishful thinking!
ALPHA_ARCH = #alpha # DEC Alpha architecture.  Yeah, this is wishful thinking!
OTHER_ARCH = # Add other architectures here.  We can hope...

# Configure this to define anything special you might need when building
# the MiscKit precompiled headers.  For example, remove the pound sign
# below if you plan to use the MiscKit under NEXTSTEP-J.
PRECOMP_FLAGS = # -DKANJI

# GNU tar is preferred since some paths we will try to tar up for
# installation are longer than tar's 100 character limit.  Regular
# tar will NOT work for the install because of this!
TAR = /usr/bin/gnutar # for NS 3.2 or greater
#TAR = /usr/local/bin/gnutar
# This tar handles long filenames if you haven't got gnutar
#TAR = /NextAdmin/Installer.app/installer_bigtar

#########################################################################
# Don't mess with anything beyond this line or you might mess something #
# up beyond all hope of the gods and man.  Unless, of course, you       #
# actually do know what you're doing...which may well be the case...    #
#########################################################################

ARCHITECTURES = $(MOTOROLA_ARCH) $(INTEL_ARCH) $(HP_ARCH) \
		$(SPARC_ARCH) $(POWER_ARCH) $(ALPHA_ARCH) $(OTHER_ARCH)
ARCH_TOOL = /usr/lib/arch_tool
TOOL_MAKE = /NextDeveloper/Makefiles/app/tool.make
ARCHIFY = $(ARCH_TOOL) -archify_list
ARCH_FLAGS = `$(ARCHIFY) $(ARCHITECTURES)`

LN_S = ln -s
MAKE_PROG = /bin/make

NAME = MiscKit
INSTALLROOT = $(ROOT)/LocalDeveloper
DOC_INSTALL = $(INSTALLROOT)/Documentation/$(NAME)
LIB_INSTALL = $(INSTALLROOT)/Libraries
HEADER_INSTALL = $(INSTALLROOT)/Headers
PALETTE_INSTALL = $(INSTALLROOT)/Palettes
MAKEFILE_INSTALL = $(INSTALLROOT)/Makefiles
EXAMPLE_SRC_INSTALL = $(INSTALLROOT)/Examples/$(NAME)

# These next six targets are all that should need to be modified in
# order to add new MiscKit resources, as long as the resource has the
# proper Misc* prefix naming convention.
BUNDLES = MiscFindPanel MiscString MiscStringArray MiscDictionary
LIBRARIES = MiscKit MiscInspectorKit MiscMergeKit MiscString MiscGISKit
PALETTES_WITH_LIBS = MiscClockPalette MiscProgressPalette MiscDragViews \
			MiscThreeStateButton MiscArrowButtonPalette MiscColorWells \
			MiscValueFieldPalette MiscCircularSlider MiscLogSliderPalette\
			MiscCalendarPalette MiscSoundPalette MiscTeePalette \
			MiscDatePalette MiscClassDecoderPalette MiscShell \
			MiscTabMatrixPalette MiscSwapKitPalette MiscGaugePalette \
			MiscPaperViewPalette MiscClipTextPalette MiscTableScroll \
			MiscTreeBrowser MiscSplitBrowser MiscFormField \
			MiscTilingButton
PALETTES = $(PALETTES_WITH_LIBS) MiscCoolButtons MiscString IBMole ListPalette
# Examples that test the MiscKit but don't install to /LocalDeveloper/Examples
TESTAPP_EXAMPLES = MiscLockFile MiscLogFile MiscPriorityQueue MiscString \
			DragViewTest MiscStringRegex TestExplodingMenus TableParse \
			MailTest MiscDistributor MiscTreeBrowserTest MiscTree_Browser
# Makefile extensions that install to /LocalDeveloper/Makefiles
MAKEFILE_EXTENSIONS = submission.make language.make
# Examples that test the MiscKit and do install to /LocalDeveloper/Examples
EXAMPLEAPP_EXAMPLES = MiscStringService TreeView SearchBench TinyTerm \
			receiptfilter BrowserZoo generate-makefile cnvwrap \
			MiscClassDecoder qlipo UNIX-HatersTool UsersAndGroups \
			FileBrowser FileSearchTest BPM MergeTest MiscGISMapCoord \
			Robby ScrollDir image2m LazyScrollDir SplitView IconTester \
			DragScrollExample
# Example stuff that installs to /LocalDeveloper/Examples but doesn't compile
EXAMPLEOTHERS = Interfaces DocTemplates IBMole ProjectTemplates getset \
			AutoDoc format_comment cc3

include Makefiles/$(NAME).version # grabs the version number

help:
	@echo ""
	@echo "************  Welcome to the $(NAME)!  ************"
	@echo ""
	@echo "The following Makefile targets are available:"
	@echo "    make install   -- build and install the $(NAME)"
	@echo "    make lib       -- build the $(NAME) library"
	@echo "    make bundles   -- build the $(NAME) bundle projects"
	@echo "    make palettes  -- build the $(NAME) palette projects"
	@echo "    make examples  -- build the $(NAME) example applications"
	@echo "    make debug     -- build the $(NAME) debugging libraries"
	@echo "    make profile   -- build the $(NAME) profiling libraries"
	@echo "    make all       -- build all six of the above targets"
	@echo "    make uninstall -- remove the $(NAME) installation"
	@echo "    make distclean -- clean the $(NAME) to a pristine distribution"
	@echo ""
	@echo "See documentation for other targets such as:   help, prep,"
	@echo "build_debug_core, build_core, install_core, _install"
	@echo ""
	@echo "Read README.rtf first to catch any last minute gotchas!  Before"
	@echo "installing you should agree with the terms of the $(NAME)"
	@echo "license as it appears in License.rtf."
	@echo ""
	@echo "The $(NAME) Version $(FULL_VERSION) (C) $(COPYRIGHT_YEAR) by Don Yacktman"
	@echo ""
	@echo "Current Makefile configuration is to compile for the following"
	@echo "architectures:  $(ARCHITECTURES)"

all: lib bundles palettes examples debug profile

prep:
	@if (test -f .prepped) ; then echo "Prepped...OK" ; \
			else echo "Prepping for make..." ; \
			Makefiles/prepmake $(ARCH_TOOL) $(TOOL_MAKE) ; fi
	@touch .prepped

lib: prep
	@(if test $(SHOWREADME) = YES; then open README.rtf; fi)&
	@(if test $(AUDIOALERTS) = YES; then sndplay Makefiles/MiscBuild.snd; fi)&
	@echo "************ Libraries ************"
	@for i in $(LIBRARIES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i library" ; \
		(cd Source/$$i; $(MAKE_PROG) lib "TARGET_ARCHS=$(ARCHITECTURES)"; mv *.a ..) ; \
	done ;
	@echo "************ Check main Library ************"
	@echo "*** If there is text between this message and the end of main"
	@echo "*** library check message, then an object file could be"
	@echo "*** missing from the library.  Check the README.rtf for details."
	@-(cd Source; otool -O libMiscKit.a > .otool.out; \
		diff .otool.correct .otool.out; )
	@echo "************ End of main Library check ************"

debug: prep
	@echo "************ Debug Library ************"
	@for i in $(LIBRARIES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i library" ; \
		(cd Source/$$i; $(MAKE_PROG) debuglib "TARGET_ARCHS=$(ARCHITECTURES)"; mv *.a ..) ; \
	done ;

profile: prep
	@echo "************ Profile Library ************"
	@for i in $(LIBRARIES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i library" ; \
		(cd Source/$$i; $(MAKE_PROG) profilelib "TARGET_ARCHS=$(ARCHITECTURES)"; mv *.a ..) ; \
	done ;

bundles: prep
	@echo "************ Bundles ************"
	@for i in $(BUNDLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i class bundle" ; \
		(cd Bundles/$$i; $(MAKE_PROG) "TARGET_ARCHS=$(ARCHITECTURES)"; ) ; \
	done ;

examples: lib bundles palettes
	@echo "************ Examples ************"
	@for i in $(TESTAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i test app" ; \
		(cd Examples/$$i; $(MAKE_PROG) "TARGET_ARCHS=$(ARCHITECTURES)"; ) ; \
	done ;
	@for i in $(EXAMPLEAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i example app" ; \
		(cd Examples/$$i; $(MAKE_PROG) "TARGET_ARCHS=$(ARCHITECTURES)"; ) ; \
	done ;

palettes: bundles
	@echo "************ Palettes ************"
	@for i in $(PALETTES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		echo "*** Making $$i palette" ; \
		(cd Palettes/$$i; $(MAKE_PROG) "TARGET_ARCHS=$(ARCHITECTURES)"; ) ; \
	done ;

build_debug_core: prep
	@(if test $(SHOWREADME) = YES; then open README.rtf; fi)&
	@(if test $(AUDIOALERTS) = YES; then sndplay Makefiles/MiscBuild.snd; fi)&
	@echo "************ DEBUG Library ************"
	(cd Source/MiscKit; $(MAKE_PROG) debuglib "TARGET_ARCHS=$(ARCHITECTURES)"; \
			mv *.a ..) ;

build_core: prep
	@(if test $(SHOWREADME) = YES; then open README.rtf; fi)&
	@(if test $(AUDIOALERTS) = YES; then sndplay Makefiles/MiscBuild.snd; fi)&
	@echo "************ Library ************"
	(cd Source/MiscKit; $(MAKE_PROG) lib "TARGET_ARCHS=$(ARCHITECTURES)"; \
			mv *.a ..) ;
	@echo "************ Check main Library ************"
	@echo "*** If there is text between this message and the end of main"
	@echo "*** library check message, then an object file could be"
	@echo "*** missing from the library.  Check the README.rtf for details."
	@-(cd Source; otool -O libMiscKit.a > .otool.out; \
		diff .otool.correct .otool.out; )
	@echo "************ End of main Library check ************"

install_core: build_core
	@echo "*** Installing library to $(LIB_INSTALL)"
	mkdirs $(LIB_INSTALL)
	(cd Source; $(TAR) -cf - lib*.a | (cd $(LIB_INSTALL); $(TAR) -xf - ;))
	@echo "*** Installing headers to $(HEADER_INSTALL)"
	mkdirs $(HEADER_INSTALL)
	(cd Headers; $(TAR) -cf - * | (cd $(HEADER_INSTALL); $(TAR) -xf - ;))
	(cd $(HEADER_INSTALL)/misckit; \
			$(CC) -O -g -Wall -ObjC -I$(HEADER_INSTALL) -precomp \
			$(ARCH_FLAGS) $(PRECOMP_FLAGS) misckit.h -o misckit.p)

_install:
	@echo "************ Installing $(NAME) ************"
	@echo "*** Installing libraries to $(LIB_INSTALL)"
	mkdirs $(LIB_INSTALL)
	(cd Source; $(TAR) -cf - lib*.a | (cd $(LIB_INSTALL); $(TAR) -xf - ;))
	for i in $(PALETTES_WITH_LIBS) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Palettes/$$i; $(TAR) -cf - *.a | \
				(cd $(LIB_INSTALL); $(TAR) -xf - ;)) ; \
	done ;
	@echo "*** Installing headers to $(HEADER_INSTALL)"
	mkdirs $(HEADER_INSTALL)
	(cd Headers; $(TAR) -cf - * | (cd $(HEADER_INSTALL); $(TAR) -xf - ;))
	for i in $(PALETTES_WITH_LIBS) none ; do \
		if [ $$i = none ] ; then continue; fi; \
 		(cd Palettes/$$i; cp *.subproj/*.h $(HEADER_INSTALL)/misckit; ) \
	done ;
# build the precomp header
	(cd $(HEADER_INSTALL)/misckit; $(CC) -O -g -Wall -ObjC \
			-I$(HEADER_INSTALL) -precomp $(ARCH_FLAGS) \
			$(PRECOMP_FLAGS) misckit.h -o misckit.p)
	@echo "*** Installing documentation to $(DOC_INSTALL)"
	rm -rf $(DOC_INSTALL)
	mkdirs $(DOC_INSTALL)
	(cd Documentation; $(TAR) -cf - * .??* | (cd $(DOC_INSTALL); $(TAR) -xf - ;))
	@echo "*** Building index for documentation ***
	ixbuild -cs $(DOC_INSTALL)
	@echo "*** Installing palettes to $(PALETTE_INSTALL)"
	mkdirs $(PALETTE_INSTALL)
# this is inefficient speed-wise, but makes for smaller palettes than the
# tar method because it strips them.  Installs only happen once, and the
# saved space is significant, so we'll take the performance hit.
	for i in $(PALETTES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
 		(cd Palettes/$$i; $(MAKE_PROG) install INSTALLDIR=$(PALETTE_INSTALL) \
			"TARGET_ARCHS=$(ARCHITECTURES)"; ) \
	done ;
	@echo "*** Installing supplementary Makefiles to $(MAKEFILE_INSTALL)"
	mkdirs $(MAKEFILE_INSTALL)
	(cd Makefiles; $(TAR) -chf - $(MAKEFILE_EXTENSIONS) | \
				(cd $(MAKEFILE_INSTALL); $(TAR) -xf - ;))
	@echo "*** Installing example source code to $(EXAMPLE_SRC_INSTALL)"
	mkdirs $(EXAMPLE_SRC_INSTALL)
	(cd Examples; $(TAR) -chf - $(EXAMPLEAPP_EXAMPLES) $(EXAMPLEOTHERS) .??* | \
				(cd $(EXAMPLE_SRC_INSTALL); $(TAR) -xf - ;))
	@(if test $(AUDIOALERTS) = YES; then sndplay Makefiles/MiscFinish.snd; fi)&

install: lib palettes _install # the palletes target builds the bundles

uninstall:
	@echo "************ Uninstalling $(NAME) ************"
	rm -rf $(LIB_INSTALL)/libMisc*.a \
				$(HEADER_INSTALL)/misckit \
				$(HEADER_INSTALL)/daymisckit \
				$(HEADER_INSTALL)/ExtendedApp.h \
				$(PALETTE_INSTALL)/IBMole.palette \
				$(PALETTE_INSTALL)/Misc*.palette \
				$(DOC_INSTALL) $(EXAMPLE_SRC_INSTALL) \
				$(MAKEFILE_INSTALL)/submission.make \
				$(MAKEFILE_INSTALL)/language.make

distclean:
	@echo "************ Cleaning for distribution ************"
	@(cd Source; rm -f *.a .otool.out; )
	@for i in $(LIBRARIES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Source/$$i; $(MAKE_PROG) clean; ) \
	done ;
	@(cd Headers/misckit; rm -rf *.p; )
	@for i in $(BUNDLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Bundles/$$i; $(MAKE_PROG) clean; ) \
	done ;
	@for i in $(PALETTES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Palettes/$$i; $(MAKE_PROG) clean; ) \
	done ;
	@for i in $(TESTAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Examples/$$i; $(MAKE_PROG) clean; ) \
	done ;
	@for i in $(EXAMPLEAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Examples/$$i; $(MAKE_PROG) clean; ) \
	done ;
	rm -rf  Source/*/.lastBuildTime
# get rid of those pesky .dir3_0.wmd files, but keep the top level one.
	@cp .dir3_0.wmd .dir3_0.wmd~
	find ./ -name .dir3_0.wmd -print | xargs rm -f
	@cp .dir3_0.wmd~ .dir3_0.wmd
	@rm -f .dir3_0.wmd~ .prepped

cleanexamples:
	@echo "************ Cleaning examples ************"
	@for i in $(TESTAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Examples/$$i; $(MAKE_PROG) clean; ) \
	done ;
	@for i in $(EXAMPLEAPP_EXAMPLES) none ; do \
		if [ $$i = none ] ; then continue; fi; \
		(cd Examples/$$i; $(MAKE_PROG) clean; ) \
	done ;
