###############################################################################
#  NeXT Makefile.postamble Template
#  Copyright 1993, NeXT Computer, Inc.
#
#  This Makefile is used for configuring the standard app makefiles associated
#  with ProjectBuilder.  
#  
#  Use this template to set attributes for a project, sub-project, bundle, or
#  palette.  Each node in the project's tree of sub-projects and bundles 
#  should have it's own Makefile.preamble and Makefile.postamble.  Additional
#  rules (e.g., after_install) that are defined by the developer should be
#  defined in this file.
#
###############################################################################
# 
# Here are the variables exported by the common "app" makefiles that can be 
# used in any customizations you make to the template below:
# 
#	PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app)
#	OFILE_DIR - Directory into which .o object files are generated.
#		    (Note that this name is calculated based on the target 
#		     architectures specified in Project Builder).
#	DERIVED_SRC_DIR - Directory used for all other derived files
#	ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations
#
#	NAME - name of application, bundle, subproject, palette, etc.
#	LANGUAGE - langage in which the project is written (default "English")
#	ENGLISH - boolean flag set iff $(LANGUAGE) = "English"
#	JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese"
#	LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project
#	GLOBAL_RESOURCES - non-localized resources of project
#	PROJECTVERSION - version of ProjectBuilder that output Makefile
#	APPICON - application icon file
#	DOCICONS - dock icon files
#	ICONSECTIONS - Specifies icon sections when linking executable 
#
#	CLASSES - Class implementation files in project.
#	HFILES - Header files in project.
#	MFILES - Other Objective-C source files in project. 
#	CFILES - Other C source files in project. 
#	PSWFILES - .psw files in the project
#	PSWMFILES - .pswm files in the project
#	SUBPROJECTS - Subprojects of this project
#	BUNDLES - Bundle subprojects of this project
#	OTHERSRCS - Other miscellaneous sources of this project
#	OTHERLINKED - Source files not matching a standard source extention
#
#	LIBS - Libraries to link with when making app target
#	DEBUG_LIBS - Libraries to link with when making debug target
#	PROF_LIBS - Libraries to link with when making profile target
#	OTHERLINKEDOFILES - Other relocatable files to (always) link in.
#
#	APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles
#	MAKEFILEDIR - Directory in which to find $(MAKEFILE)
#	MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make)
#	INSTALLDIR - Directory app will be installed into by 'install' target


# Change defaults assumed by the standard app makefiles here.  Edit the 
# following default values as appropriate. (Note that if no Makefile.postamble 
# exists, these values will have defaults set in common.make).

# Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if
# you would like changes to them to invalidate previous builds.  The project
# depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build.
#MAKEFILES = Makefile 

# Optimization flag passed to compiler:
#OPTIMIZATION_CFLAG = -O2

# Flags always passed to compiler:
#COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall  

# Flags passed to compiler in normal 'app' compiles:
#NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG)

# Flags passed to compiler in 'debug' compiles:
#DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG

# Flags passed to compiler in 'profile' compiles
#PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE

# Flags passed to yacc
#YFLAGS = -d

# Ownership and permissions of files installed by 'install' target
#INSTALL_AS_USER = root        # User to chown app to
#INSTALL_AS_GROUP = wheel      # Group to chgrp app to 
#INSTALL_PERMISSIONS =         # If set, 'install' chmod's executable to this

# Options to strip for bundles, apps with bundles, and apps without bundles, 
# respectively.
#RELOCATABLE_STRIP_OPTS = -x -u
#DYLD_APP_STRIP_OPTS = -A -n
#APP_STRIP_OPTS = 
#TOOL_STRIP_OPTS = 
#LIBRARY_STRIP_OPTS = -x -S   # Note: -S strips debugging symbols
# (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but
#  developers doing their own dynamic loading should set this to 
#  $(DYLD_APP_STRIP_OPTS)).


#########################################################################
# Put rules to extend the behavior of the standard Makefiles here.  Typical 
# user-defined rules are before_install and after_install (please don't 
# redefine things like install or app, as they are owned by the top-level 
# Makefile API), which are rules that get invoked before and after the install 
# target runs.  Such rules should be specified with the '::' syntax rather than 
# a single colon.

RCS_POSTAMBLE_ID = $Makefile.postamble,v 1.33 1998/07/03 23:39:46 tom Exp$


## Makefile.support parameters.

PKGTIFF = EM.tiff
PKGNAME = $(NAME)
PKGINFO = pkg.info

PKGTITLE = $(NAME) bundle
PKGVERSION = `sed '/CVSName=/!d; s/.*CVSName="\(.*\)".*/\1/; \
		 s/\\$$\Name: *\\$$//; s/[^0-9]*\([0-9].*[0-9]\).*/\1/; \
		 s/_/./g; s/^$$/X/' EnhanceMail.m | head -1`
PKGDATE = `sed -n 's|.*\([1-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]\).*|\1|p' \
	      README | head -1`

TAR_EXT = gnutar

EXTRA_TOPLEVEL_DOCS = hidden-defaults.txt .dir.tiff .opendir.tiff


include Makefile.support


## Rules specific for EnhanceMail.

clean::
	-$(RM) -rf $(NAME)*.info

# Copy images.

SOURCE_IMAGE_DIR = Images
DEST_IMAGE_DIR = $(PRODUCT_ROOT)/English.lproj/Images

$(DEST_IMAGE_DIR): $(SOURCE_IMAGE_DIR)
	$(MKDIRS) $@
	$(FASTCP) $(SOURCE_IMAGE_DIR)/*.tiff $@


# OTHER_PRODUCT_DEPENDS target:
images: $(DEST_IMAGE_DIR)

EXTRA_LOCAL_RESOURCES = Images

after_install::
	@$(DEBUGSH)\
	resource_root=$(DSTROOT)$(INSTALLDIR)/$(REL_PRODUCT_ROOT); \
	$(COPY_OTHER_LANGUAGES_RESOURCES); \
	$(RM) -rf $$resource_root/*.lproj/EnhanceHelp/_panels \
	    $$resource_root/*.lproj/EnhanceHelp/*~ $$resource_root/*.lproj/*~

after_install:: duplink_installed


# Create distribution package for base distribution that contains
# everything except non-English on-line help.

# remove Help directories (if any) from base binary package.
pkg_root::
	@$(RM) -rf $(PKGROOT)/$(PRODUCT_ROOT)/*.lproj/EnhanceHelp

# 3.3 Installer cannot handle accented (8-bits) characters in filenames,
# so exclude non-English Images/ directories -that are likely to contain
# localized filenames- from the base package.  Include it as a separate
# gnutar archive inside the .pkg instead--it will be installed by the
# post_install script.

pkg_root::
	@images='$(PRODUCT_ROOT)/*.lproj/Images'; \
	(cd $(PKGROOT); \
	 cmd="gnutar -cf - $$images | gzip -9 >Images.gnutar.gz"; \
	 echo "$$cmd"; eval "$$cmd"; \
	 $(RM) -rf $$images); \
	$(MV) $(PKGROOT)/Images.gnutar.gz .

dist_package::
	-$(MV) Images.gnutar.gz $(PKGNAME).pkg/


# exclude non-English Help directories/packages from base source distributions.
GNUTAR_DIST_EXCLUDE = --exclude '*/CVS' \
	    `echo ' $(LANGUAGE_DIRECTORIES)' | \
		 sed 's| English.lproj||; \
		      s|  *\([^ ]*\)\.lproj| --exclude \\\\*\1.pkg\\\\* --exclude \\\\*/\1.lproj/EnhanceHelp/\\\\*|g'`

# Additionally, exclude English Help directory from bin+src dist.
# (It is already in the *_English.pkg)

BS_DIST_GNUTAR_ARGS = --exclude '*/English.lproj/EnhanceHelp/*'

dist_package::
	@$(MAKE) $(MFLAGS) CC='$(CC)' TARGET_ARCHS="$(DIST_TARGET_ARCHS)" \
		LANGUAGE='English' pkg_lang

after_package::
	@pkg=$(NAME)_English.pkg; \
	$(RM) -rf ../$$pkg ; \
	mv $$pkg ..; \
	ln -s ../$$pkg .
	
# choose which archive(s) to create:
archive:: bs_archive s_archive #b_archive


# Language add-on package creation.

# Create separate packages for each non-English .lproj directory
# that contains on-line help.

pkg_lang: $(NAME)_$(LANGUAGE).pkg

# 3.3 Installer cannot handle accented (8-bits) characters in filenames,
# so exclude Images/ directory -that is likely to contain localized
# filenames- from the package.  Include it as a separate gnutar archive
# inside the .pkg instead--it will be installed by the post_install script.

$(NAME)_$(LANGUAGE).pkg: pkg_root_lang
	@$(MAKE) $(MFLAGS) LANGUAGE=$(LANGUAGE) \
		PKGNAME=$(NAME)_$(LANGUAGE) \
		PKGINFO=pkg_lang.info \
		base_pkg scripts_pkg gzip_pkg
	@if [ -d $(LANGUAGE).lproj/Images ]; then \
	    cmd="gnutar -cf - $(LANGUAGE).lproj/Images | \
		gzip -9 >$(NAME)_$(LANGUAGE).pkg/Images.gnutar.gz"; \
		echo "$$cmd"; eval "$$cmd"; \
	fi || true
	@-$(RM) -rf $(PKGROOT)	

pkg_root_lang:
	@$(MKDIRS) $(PKGROOT)
	@gnutar -cf - $(LANGUAGE).lproj \
		--exclude '*/_panels' --exclude '*/Images' | \
		(cd $(PKGROOT) && gnutar -xpf -)
	@-duplink --doit --quiet $(PKGROOT)

dist_lang_package: pkg_lang
	@$(DEBUGSH)$(_set_version); \
	archive=$(NAME)_$(LANGUAGE).lproj.$$version.d.pkg.tar.gz; \
	echo "Creating \`$$archive' in \``cd ../..;pwd`'..."; \
	pkg=$(NAME)_$(LANGUAGE).pkg; \
	$(RM) -rf ../$$pkg; \
	mv $$pkg ..; ln -s ../$$pkg .; \
	cd ..; \
	cmd="gnutar -cf - $$pkg | gzip -9v >../$$archive"; \
	echo "$$cmd"; eval "$$cmd"

dist_lang_packages:
	@$(DEBUGSH)\
	for lproj in $(LANGUAGE_DIRECTORIES) ""; do \
	    case "$$lproj" in English.lproj | "") continue; esac; \
	    [ -d $$lproj/EnhanceHelp ] || { continue; }; \
	    lang=`basename $$lproj .lproj`; \
	    $(MAKE) $(MFLAGS) LANGUAGE=$$lang dist_lang_package; \
	done

post_dist:: dist_lang_packages
