/*
 *	$Id: Rules,v 1.43 2004-08-18 16:39:11 haley Exp $
 */
/* 
   This file contains Makefile macros.  Proper spacing is achieved
   through the use of the right square brackets, which are later expanded
   into appropriate newlines and tabs by "ymake-filter".
*/

#define	NullArgument

/*
 * Macro:	PrintError
 *
 * Description:	This macro is used to report any rules that are in a yMakefile
 *		that are out of date.
 */
#ifndef	PrintError
#define PrintError(rule,rulename,message)\
]\
rule:]\
	@echo -n "YMAKE Error-"rulename "used in $(CURRENT_DIR)/yMakefile "]\
	@echo message]\
]\
Makefiles:: rule]
#endif	/* PrintError */

/*
 * Macro:	InternalMakefileTarget
 *
 * Description:	yMake uses this internally in the Template file - It should
 *		not be used in an actual yMakefile.
 */
#ifndef	InternalMakefileTarget
#define InternalMakefileTarget \
]\
YmakeDependency(local-Makefile)\
]\
local-Makefile::]\
	@echo "Making Makefile in $(CURRENT_DIR)"]\
	@$(YMAKE) -Topdir $(TOP) -Curdir $(CURRENT_DIR)]\
]\
me: local-Makefile]
#endif	/* InternalMakefileTarget */

/*
 * Macro:	SubdirTarget
 *
 * Description:	This rule takes a target name and applies it to all the
 *		dirs passed to it.
 */
#ifndef	SubdirTarget
#define	SubdirTarget(dirs,target,dependency,margs)\
]\
all::]\
]\
target::dependency]\
	margs/**/tname\=target; \ ]\
	for dir in dirs ; do \ ]\
	if (test -d $$dir) then \ ]\
	(cd $$dir; echo "Making $$tname in $(CURRENT_DIR)/$$dir";\ ]\
	$(MAKE) $(MFLAGS) target);\ ]\
	else echo "NOT Making $$tname in $(CURRENT_DIR)/$$dir"; fi \ ]\
	done]\
]
#endif

/*
 * Macro:	InstallTarget
 *
 * Description:	install a number of files to dest - It will try and create
 *		dest if it doesn't currently exist. The all is there so that
 *		install doesn't end up being the default target since nothing
 *		should be installed on an all target.
 */
#ifndef	InstallTarget
#define InstallTarget(names, mode, dest)\
all::]\
]\
all-local:: names]\
]\
install-local:: names]\
	MakeDir(dest)]\
	@for name in names; do \ ]\
	if (test -f $$name.$(EXE_SUFFIX)) then \ ]\
	(echo "Installing $$name.$(EXE_SUFFIX)";\ ]\
	$(INSTALL) -m mode $$name.$(EXE_SUFFIX) dest);\ ]\
	else \ ]\
	(echo "Installing $$name";\ ]\
	$(INSTALL) -m mode $$name dest); fi \ ]\
	done]
#endif	/* InstallTarget */

/*
 * Macro:	ConditionalInstallTarget
 *
 * Description:	like InstallTarget, but only installs if the dest_prefix exists.
 *		Used, e.g., to install PyNIO libsrc and grib_codetables only if
 *              there is a pynio directory under the top level directory.
 */
#ifndef ConditionalInstallTarget
#define ConditionalInstallTarget(names, mode, dest_prefix,dest)\
all::]\
]\
all-local:: names]\
]\
install-local:: names]\
	@if (test -d dest_prefix); then \ ]\
	(if (test ! -d dest); then ($(MKDIRHIER) dest); fi; \ ]\
	echo "installing to " dest; \ ]\
	for name in names; do \ ]\
	(echo "Installing $$name";\ ]\
	$(INSTALL) -m mode $$name dest); \ ]\
	done;) \ ]\
	fi
#endif  /* ConditionalInstallTarget */

/*
 * Macro:	InstallLibTarget
 *
 * Description:	Install a library - It installs the lib and then runs RANLIB.
 */
#ifndef	InstallLibTarget
#define InstallLibTarget(library)\
InstallTarget(library,$(INSTALL_LIB),$(LIBPATH))\
]\
all::]\
]\
install-local::]\
	$(RANLIB) $(LIBPATH)/library]
#endif	/* InstallLibTarget */

/*
 * Macro:	InternalMakeSubdirs
 *
 * Description:	ymake uses this rule internally in Template - It should not
 *		be used in an actual yMakefile.
 */
#ifndef	InternalMakeSubdirs
#define InternalMakeSubdirs(dirs)\
]\
makesubdirs:]\
	@for dir in dirs ; do \ ]\
	if (test -d $$dir) then \ ]\
	(cd $$dir; echo "Making $(CURRENT_DIR)/$$dir";\ ]\
	$(MAKE) $(MFLAGS));sleep 1;\ ]\
	else echo "NOT Making $(CURRENT_DIR)/$$dir"; fi \ ]\
	done]\
]\
all:: all-local makesubdirs]
#endif	/* InternalMakeSubdirs */

/*
 * Macro:	InternalCleanSubdirs
 *
 * Description:	ymake uses this rule internally in Template - It should not
 *		be used in an actual yMakefile.
 */
#ifndef	InternalCleanSubdirs
#define InternalCleanSubdirs(dirs)\
SubdirTarget(dirs,clean,clean-local,-@)
#endif	/* InternalCleanSubdirs */

/*
 * Macro:	InternalDistCleanSubdirs
 *
 * Description:	ymake uses this rule internally in Template to totally clean
 *		the distribution - including Makefiles.
 */
#ifndef	InternalDistCleanSubdirs
#define	InternalDistCleanSubdirs(dirs)\
SubdirTarget(dirs,dist-clean,clean-local,-@)\
]\
dist-clean::]\
	-@$(RM) Makefile]\
	@echo "dist-clean in $(CURRENT_DIR)"]\

#endif	/* InternalDistCleanSubdirs */

/*
 * Macro:	InternalInstallSubdirs
 *
 * Description:	ymake uses this rule internally in Template - It should not
 *		be used in an actual yMakefile.
 */
#ifndef	InternalInstallSubdirs
#define InternalInstallSubdirs(dirs)\
SubdirTarget(dirs,install,install-local,@)
#endif	/* InternalInstallSubdirs */

/*
 * Macro:	YmakeDependency
 *
 * Description:	ymake uses this rule internally to build ymake if it isn't
 *		built.
 */
#ifndef	YmakeDependency
#ifdef	UseInstalled
#define	YmakeDependency(target) /**/
#else
#define	YmakeDependency(target)\
target:: $(YMAKEDEP)]\
]\
$(YMAKEDEP):]\
	@(cd $(CONFIGSRC); if (test -f Makefile) then \ ]\
	echo "checking ymake in $(CONFIGSRC) first..."; $(MAKE) all; else \ ]\
	echo "making ymake from Makefile.ini in $(CONFIGSRC) first..."; \ ]\
	$(MAKE) -f Makefile.ini clean all; fi; \ ]\
	echo "continuing in $(CURRENT_DIR)")]
#endif	/* UseInstalled */
#endif	/* YmakeDependency */

/*
 * Macro:	InternalMakefilesSubdirs
 *
 * Description:	ymake uses this rule internally in Template - It should not
 *		be used in an actual yMakefile.
 */
#ifndef	InternalMakefilesSubdirs
#define InternalMakefilesSubdirs(dirs)\
]\
Makefiles::]\
	@for dir in dirs ; do \ ]\
	if (test -d $$dir) then \ ]\
	(cd $$dir; echo "Making Makefiles in $(CURRENT_DIR)/$$dir";\ ]\
	$(NEWYMAKE) -Topdir ../$(TOP) -Curdir $(CURRENT_DIR)/$$dir;\ ]\
	$(MAKE) $(MFLAGS) Makefiles);\ ]\
	else echo "NOT Making Makefiles in $(CURRENT_DIR)/$$dir"; fi \ ]\
	done]\
]\
Makefiles-local::]\
	@for dir in dirs ; do \ ]\
	if (test -d $$dir) then \ ]\
	(cd $$dir; echo "Making Makefile in $(CURRENT_DIR)/$$dir";\ ]\
	$(NEWYMAKE) -Topdir ../$(TOP) -Curdir $(CURRENT_DIR)/$$dir;)\ ]\
	else echo "NOT Making Makefile in $(CURRENT_DIR)/$$dir"; fi \ ]\
	done]
#endif	/* InternalMakefilesSubdirs */

#ifndef	BuildRelObj
#define	BuildRelObj(name,objects)\
]\
all::]\
]\
all-local::	name]\
]\
name:	objects]\
	$(LD_REL) -r -o name objects]
#endif
/*
 * Macro:	RelocatableTarget
 *
 * Description:	Builds a .o and installs it in the ROBJPATH.
 */
#ifndef	RelocatableTarget
#define RelocatableTarget(name,objects)\
BuildRelObj(name,objects)\
InstallTarget(name,$(INSTALL_LIB),$(ROBJPATH))\
CleanFilesTarget(name objects)
#endif	/* RelocatableTarget */

/*
 * Macro:	FortranProgram
 *
 * Description:	This rule is basically the same as FortranTarget but it
 *		allows you to specify dependent libraries - so a make all
 *		will rebuild if the library has been updated.
 */
#ifndef	FortranProgram
#define FortranProgram(program,objects,deplibs)\
]\
all::]\
]\
all-local:: program]\
]\
_FortranLinkProgram(program,objects,deplibs)\
InstallTarget(program,$(INSTALL_BIN),$(BINPATH))
#endif	/* FortranProgram */

/*
 * Macro:	FortranTarget
 *
 * Description:	This rule is build's and installs a Fortran program - if
 *		possible the FortranProgram rule should be used instead so
 *		the program will re-build if the libraries are rebuilt.
 */
#ifndef	FortranTarget
#define FortranTarget(program,objects)\
]\
all::]\
]\
all-local:: program]\
]\
_FortranLinkProgram(program,objects,NullArgument)\
InstallTarget(program,$(INSTALL_BIN),$(BINPATH))
#endif	/* FortranTarget */

/*
 * Macro:	_FortranLinkProgram
 *
 * Description:	This rule is used to link a fortran program - it may be
 *		different for each archectecture so that shared-nonshared
 *		libraries can be linked properly.
 */
#ifndef	_FortranLinkProgram
#define	_FortranLinkProgram(program,objects,deplib)\
program: objects deplib]\
	$(F77_LD) $(FC_LDOPTIONS) -o program objects $(PROG_LIBS) $(LDLIBS) $(EXTRA_LDLIBS)]\
]\
CleanFilesTarget(program objects)
#endif	/* _FortranLinkProgram */


/*
 * Macro:	FNotInstalledTarget
 *
 * Description:	This rule is used to build a fortran program that is used
 *		in the distribution, but should not be installed.
 */
#ifndef	FNotInstalledTarget
#define	FNotInstalledTarget(program,objects)\
]\
all::]\
]\
all-local:: program]\
]\
_FortranLinkProgram(program,objects,NullArgument)
#endif	/* FNotInstalledTarget */


/*
 * Macro:	BuildAndInstallCProgram
 *
 * Description:	This rule is basically the same as CProgram, but it
 *		installs the C program without having to do an "install".
 */
#ifndef	BuildAndInstallCProgram
#define	BuildAndInstallCProgram(program,objects,deplibs)\
]\
all::]\
]\
all-local:: program]\
]\
_CLinkAndInstallProgram(program,objects,deplibs)\
CleanFilesTarget(program objects)
#endif	/* BuildAndInstallCProgram */

/*
 * Macro:	CProgram
 *
 * Description:	This rule is basically the same as CTarget but it
 *		allows you to specify dependent libraries - so a make all
 *		will rebuild if the library has been updated.
 */
#ifndef	CProgram
#define	CProgram(program,objects,deplibs)\
]\
all::]\
]\
all-local:: program]\
]\
_CLinkProgram(program,objects,deplibs)\
]\
InstallTarget(program,$(INSTALL_BIN),$(BINPATH))
#endif	/* CProgram */

/*
 * Macro:	CProgramXQF
 *
 * Description:	This rule is basically the same as CProgram, except
 *              it handles a special "ncl" build that requires a
 *              fix for a cairo/xquartz issue. See NCL-1530.
 */
#ifndef	CProgramXQF
#define	CProgramXQF(program,objects,deplibs)\
]\
all::]\
]\
all-local:: program]\
]\
_CLinkProgramXQF(program,objects,deplibs)\
]\
InstallTarget(program,$(INSTALL_BIN),$(BINPATH))
#endif	/* CProgram */

/*
 * Macro:	CTarget
 *
 * Description:	This rule is build's and installs a C program - if
 *		possible the CProgram rule should be used instead so
 *		the program will re-build if the libraries are rebuilt.
 */
#ifndef	CTarget
#define CTarget(program,objects)\
]\
all::]\
]\
all-local:: program]\
]\
_CLinkProgram(program,objects,NullArgument)\
InstallTarget(program,$(INSTALL_BIN),$(BINPATH))
#endif	/* CTarget */

/*
 * Macro:	_CLinkAndInstallProgram
 *
 * Description:	This rule is used to link and insetall a C program - 
 *      It may be different
 *		for each architecture to resolve the differences in linking
 *		some libraries statically and some dynamically on different
 *		systems.
 */
#ifndef	_CLinkAndInstallProgram
#define	_CLinkAndInstallProgram(program,objects,deplib)\
program: objects deplib]\
	$(CC_LD) $(CC_LDOPTIONS) -o program objects $(PROG_LIBS) $(LDLIBS) $(EXTRA_LDLIBS)]\
	MakeDir($(BINPATH))]\
	$(INSTALL) -m $(INSTALL_BIN) program $(BINPATH)]
#endif	/* _CLinkAndInstallProgram */

/*
 * Macro:	_CLinkProgram
 *
 * Description:	This rule is used to link a C program - It may be different
 *		for each architecture to resolve the differences in linking
 *		some libraries statically and some dynamically on different
 *		systems.
 */
#ifndef	_CLinkProgram
#ifdef	BuildShared
#define	_CLinkProgram(program,objects,deplib)\
BuildRelObj(program.obj.o,objects)\
program: program.obj.o deplib]\
	$(CC_LD) $(CC_LDOPTIONS) -o program program.obj.o $(PROG_LIBS) $(LDLIBS) $(EXTRA_LDLIBS)]\
]\
CleanFilesTarget(program program.obj.o objects)
#else
#define	_CLinkProgram(program,objects,deplib)\
program: objects deplib]\
	$(CC_LD) $(CC_LDOPTIONS) -o program objects $(PROG_LIBS) $(LDLIBS) $(EXTRA_LDLIBS)]\
]\
CleanFilesTarget(program objects)
#define	_CLinkProgramXQF(program,objects,deplib)\
program: objects deplib]\
	$(CC_LD) $(CC_LDOPTIONS) -o program objects $(PROG_XQFLIBS) $(LDLIBS) $(EXTRA_LDLIBS)]\
]\
CleanFilesTarget(program objects)
#endif	/* BuildShared */
#endif	/* _CLinkProgram */

/*
 * Macro:	CNotInstalledTarget
 *
 * Description:	This rule is used to build a C program that is used
 *		in the distribution, but should not be installed.
 */
#ifndef	CNotInstalledTarget
#define	CNotInstalledTarget(program,objects)\
]\
all::]\
]\
all-local:: program]\
]\
_CLinkProgram(program,objects,NullArgument)
#endif	/* CNotInstalledTarget */

/*
 * Macro:	BuildLibTarget
 *
 * Description: Build a library
 */
#ifndef	BuildLibTarget
#define	BuildLibTarget(library,objects)\
]\
all::]\
]\
all-local:: library.a]\
]\
library.a:: objects]\
	-$(RM) library.a]\
	@$(AR_QUICK) library.a objects]\
	$(RANLIB) library.a]\
]\
CleanFilesTarget(library.a objects)
#endif	/* BuildLibTarget */

/*
 * Macro:	BuildSharedPartialFromArch
 *
 * Description:	Build a shared lib that should only be linked from
 *		another shared lib - it may have unresolved references.
 */
#ifndef	BuildSharedPartialFromArch
#ifdef	BuildShared
#define	BuildSharedPartialFromArch(library,arch,major,minor,reqlibs)\
PrintError(BuildSharedPartialFromArch,"BuildSharedPartialFromArch","Rule hasn't been defined.")
#else
#define BuildSharedPartialFromArch(library,arch,major,minor,reqlibs)	/**/
#endif	/* BuildShared */
#endif	/* BuildSharedPartialFromArch */

/*
 * Macro:	BuildSharedFromArch
 *
 * Description:	Build a shared library from a .a file
 */
#ifndef	BuildSharedFromArch
#ifdef	BuildShared
#define	BuildSharedFromArch(library,arch,major,minor,reqlibs)\
PrintError(BuildSharedFromArch,"BuildSharedFromArch","Rule hasn't been defined.")
#else
#define BuildSharedFromArch(library,arch,major,minor,reqlibs)	/**/
#endif	/* BuildShared */
#endif	/* BuildSharedFromArch */

/*
 * Macro:	BuildSharedPartialLib
 *
 * Description: Build a shared library that may contain unresolved references.
 *		It should not be linked in directly from users - this should
 *		only be used by other libraries, and it should contain
 *		ABSOLUTELY NO USER ENTRY POINTS - it should be created
 *		default - delay loaded.
 */
#ifndef	BuildSharedPartialLib
#ifdef	BuildShared
#define	BuildSharedPartialLib(library,objects,major,minor,reqlibs)\
PrintError(BuildSharedPartialLib,"BuildSharedPartialLib","Rule hasn't been defined.")
#else
#define BuildSharedPartialLib(library,objects,major,minor,reqlibs)	/**/
#endif	/* BuildShared */
#endif	/* BuildSharedPartialLib */

/*
 * Macro:	BuildSharedLibTarget
 *
 * Description: Build a shared library
 */
#ifndef	BuildSharedLibTarget
#ifdef	BuildShared
#define	BuildSharedLibTarget(library,objects,major,minor,reqlibs)\
PrintError(BuildSharedLibTarget,"BuildSharedLibTarget","Rule hasn't been defined.")
#else
#define BuildSharedLibTarget(library,objects,major,minor,reqlibs)	/**/
#endif	/* BuildShared */
#endif	/* BuildSharedLibTarget */

/*
 * Macro:	BuildAndInstallLibraryTarget
 *
 * Description:	This rule builds and installs a library without
 * waiting for the "install" command.
 */
#ifndef	BuildAndInstallLibraryTarget
#define BuildAndInstallLibraryTarget(library,objects)\
]\
all::]\
]\
all-local:: library.a]\
]\
library.a:: objects]\
	-$(RM) library.a]\
	@$(AR_QUICK) library.a objects]\
	$(RANLIB) library.a]\
	MakeDir($(LIBPATH))]\
	$(INSTALL) -m $(INSTALL_LIB) library.a $(LIBPATH)]\
	$(RANLIB) $(LIBPATH)/library.a]\
CleanFilesTarget(library.a objects)
#endif	/* BuildAndInstallLibraryTarget */

/*
 * Macro:	LibraryTarget
 *
 * Description:	This rule is build's and installs a library.
 */
#ifndef	LibraryTarget
#define LibraryTarget(library,objects)\
BuildLibTarget(library,objects)]\
InstallLibTarget(library.a)
#endif	/* LibraryTarget */

/*
 * Macro:	SourceLibraryTarget
 *
 * Description:	This rule is build's and installs a source library.
 */
#ifndef	SourceLibraryTarget
#ifdef  BuildNCARGSourceLibrary
#define	SourceLibraryTarget(name,library,sources)\
]\
all::]\
]\
all-local:: library]\
]\
library:: sources]\
	@echo sources > name;\ ]\
	$(RM) library;\ ]\
	$(AR_SRC_QUICK) library name sources;\ ]\
	$(RANLIB) library;\ ]\
	$(RM) name]\
]\
.F.f:]\
	@$(FCPP) $< $*.f]\
]\
InstallLibTarget(library)\
CleanFilesTarget(library)
#else	/* BuildNCARGSourceLibrary */
#define SourceLibraryTarget(name,library,sources) /**/
#endif	/* BuildNCARGSourceLibrary */
#endif	/* SourceLibraryTarget */

/*
 * Macro:	PartialSourceLibraryRoot
 *
 * Description:	PartialSourceLibraryRoot is used to manage the source library
 *		created in this directory by all the subdirs.  Each of the
 *		sub-dirs should be using the PartialSourceLibraryTarget rule.
 */
#ifndef	PartialSourceLibraryRoot
#ifdef	BuildNCARGSourceLibrary
#define PartialSourceLibraryRoot(library,dirs)\
PartialLibraryRoot(library,dirs)
#else	/* BuildNCARGSourceLibrary */
#define PartialSourceLibraryRoot(library,dirs)	/**/
#endif	/* BuildNCARGSourceLibrary */
#endif	/* PartialSourceLibraryRoot */

/*
 * Macro:	PartialSourceLibraryTarget
 *
 * Description:	This rule is build's a source library in the directory
 *		directly above it.  The directory above should be using
 *		the PartialSourceLibraryRoot rule.
 */
#ifndef	PartialSourceLibraryTarget
#ifdef  BuildNCARGSourceLibrary
#define PartialSourceLibraryTarget(name,library,sources)\
]\
all::]\
]\
all-local:: ../library]\
]\
../library: sources]\
	@echo sources > name]\
	$(AR_SRC_QUICK) ../library name sources]\
	$(RM) name]\
]\
.F.f:]\
	@$(FCPP) $< $*.f]\
]\
install-local:: ../library]\
	@echo sources > name]\
	$(AR_SRC_CHECK) ../library name sources]\
	$(RANLIB) ../library]\
	$(RM) name]
#else	/* !BuildNCARGSourceLibrary */
#define PartialSourceLibraryTarget(name,library,sources) /**/
#endif	/* BuildNCARGSourceLibrary */
#endif	/* PartialSourceLibraryTarget */

/*
 * Macro:	CleanFilesTarget
 *
 * Description:	Removes the given files.
 */
#ifndef	CleanFilesTarget
#define CleanFilesTarget(files)\
]\
all::]\
]\
clean-local::]\
	-@$(RM) files]
#endif	/* CleanFilesTarget */

/*
 * Macro:	PartialLibraryTarget
 *
 * Description:	This rule builds a library in the directory directly above
 *		it with the same name as the current directory. The directory
 *		above should be using the PartialLibraryRoot rule.
 */
#ifndef	PartialLibraryTarget
#define PartialLibraryTarget(library,objects)\
]\
all::]\
]\
all-local::../library]\
]\
../library:: objects]\
	$(AR_REG) ../library objects]\
]\
CleanFilesTarget(objects)
#endif	/* PartialLibraryTarget */

/*
 * Macro:	PartialLibraryRoot
 *
 * Description:	PartialLibraryRoot is used to manage the library created
 *		in this directory by all the subdirs.  Each of the sub-dirs
 *		should be using the PartialLibraryTarget rule.
 */
#ifndef	PartialLibraryRoot
#define PartialLibraryRoot(library,dirs)\
]\
all::]\
]\
all-local:: library]\
]\
library::]\
	@echo "Making in dirs First..."]\
]\
library:: makesubdirs]\
	@echo "Continuing in $(CURRENT_DIR)"]\
]\
library::]\
	$(RANLIB) library]\
]\
InstallLibTarget(library)\
CleanFilesTarget(library)
#endif	/* PartialLibraryRoot */

/*
 * Macro:	CExampleTarget
 *
 * Description:	Sources for CExampleTarget are any of the ncargex or
 *      ng4ex C example files.
 */
#ifndef	CExampleTarget
#define CExampleTarget(program,objects)\
]\
examples:: program]\
]\
_CLinkProgram(program,objects,NullArgument)\
]\
CleanFilesTarget(program objects)
#endif	/* CExampleTarget */

/*
 * Macro:	FExampleTarget
 *
 * Description:	Sources for FExampleTarget are any of the ncargex or
 *      ng4ex Fortran example files.
 */
#ifndef	FExampleTarget
#define FExampleTarget(program,objects)\
]\
examples:: program]\
]\
_FortranLinkProgram(program,objects,NullArgument)\
]\
CleanFilesTarget(program objects)
#endif	/* FExampleTarget */

/*
 * Macro:	DependTarget
 *
 * Description:	This rule is used to add dependencies to the Makefile.
 */
#ifndef	DependTarget
#ifdef	NoMakeDepend
#define	DependTarget(srcs)\
all::]\
depend-local::]
#else
#define	DependTarget(srcs)\
all::]\
]\
depend-local:: srcs]\
	$(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- srcs
#endif /* NoMakeDepend */
#endif /* DependTarget */

/*
 * Macro:	InternalDependSubdirs
 *
 * Description:	Used internally in ymake - It should not be used in a yMakefile.
 */
#ifndef	InternalDependSubdirs
#ifdef	NoMakeDepend
#define InternalDependSubdirs(dirs)\
depend::]
#else
#define InternalDependSubdirs(dirs)\
SubdirTarget(dirs,depend,depend-local,@)
#endif	/* NoMakeDepend */
#endif	/* InternalDependSubdirs */

/*
 * Macro:	MakeDir
 *
 * Description:	This rule creates a directory - if a parent dir doesn't exist
 *		it attempts to create it.
 */
#ifndef	MakeDir
#define	MakeDir(dir)	@if (test ! -d dir); then ($(MKDIRHIER) dir); else continue; fi
#endif

/*
 * Macro:	BuildIncludes
 *
 * Description:	This rule creates a symbolic include tree that point to
 *		the current directory.  It allows the dependancies to work
 *		by only re-compiling if the header file in the current
 *		directory has changed.
 */
#ifndef	BuildIncludes
#define	BuildIncludes(srclist,dstsubdir,dstupdir)\
]\
all::]\
]\
includes-local::]\
	MakeDir($(BUILDINCDIR)/dstsubdir)]\
	@cd $(BUILDINCDIR)/dstsubdir;\ ]\
	$(RM) srclist; \ ]\
	for i in srclist; do \ ]\
	(echo "$(LN) dstupdir/$(BUILDINCTOP)/$(CURRENT_DIR)/$$i .";\ ]\
	$(LN) dstupdir/$(BUILDINCTOP)/$(CURRENT_DIR)/$$i .;)\ ]\
	done]
#endif	/* BuildIncludes */

/*
 * Macro:	InternalIncludesSubdirs
 *
 * Description:	Used internally in ymake - It should not be used in a yMakefile.
 */
#ifndef	InternalIncludesSubdirs
#define	InternalIncludesSubdirs(dirs)\
SubdirTarget(dirs,includes,includes-local,@)
#endif	/* InternalIncludesSubdirs */

/*
 * Macro:	InstallManPages
 *
 * Description:	This rule is used to install a manpage
 */
#ifndef InstallManPages
#define InstallManPages(files,suffix,destdir,section)\
]\
all::]\
]\
all-local::]\
]\
install-local::]\
	MakeDir(destdir)]\
	@for file in files; do \ ]\
	echo "Installing $${file}.section"; \ ]\
	$(INSTALL) -m $(INSTALL_MAN) $${file}suffix destdir/$${file}.section;\ ]\
	done
#endif	/* InstallManPages */

/*
 * Macro:	InstallManPageAliases
 *
 * Description:	* This rule is used to install man page aliases
 */
#ifndef InstallManPageAliases
#define InstallManPageAliases(file,destdir,section,aliases)\
]\
all::]\
]\
all-local::]\
]\
install-local:: destdir/file.section]\
	@(cd destdir;\ ]\
	for alias in aliases ; do \ ]\
	$(RM) $$alias.section;\ ]\
	echo "Installing $$alias.section";\ ]\
	$(LN) file.section $$alias.section;\ ]\
	done)]
#endif	/* InstallManPageAliases */

/*
 * Macro:	FormatManPages
 *
 * Description:	This rule is used to create preformatted man pages
 */
#ifndef	FormatManPages
#define	FormatManPages(manpages,mansuffix,catsuffix)\
]\
all::]\
]\
preformatted-local::]\
	@for name in manpages; do \ ]\
	echo "Formatting $${name}mansuffix";\ ]\
	$(TBL) $${name}mansuffix | $(NROFF) | $(COL) > $${name}catsuffix;\ ]\
	done]
#endif	/* FormatManPages */

/*
 * Macro:	FormatManPagesSubdirs
 *
 * Description:	This rule propagates the "preformatted" target threw the
 *		build tree.
 */
#ifndef	FormatManPagesSubdirs
#define	FormatManPagesSubdirs(dirs)\
preformatted-local::]\
]\
SubdirTarget(dirs,preformatted,preformatted-local,@)
#endif	/* FormatManPagesSubdirs */

/*
 * Macro:	InstallXappFiles
 *
 * Description:	This rule is used to install X app defaults files - It gives
 *		a warning if it is overriding an existing file and moves
 *		that file to "file".bak in case there are local mods to
 *		the file.
 */
#ifndef	InstallXappFiles
#define	InstallXappFiles(appfiles)\
]\
all::]\
]\
all-local::]\
]\
install-local::]\
	MakeDir($(XAPPPATH))]\
	@for name in appfiles; do \ ]\
	if (test -f $(XAPPPATH)/$$name) then \ ]\
		echo "Warning - replacing $(XAPPPATH)/$$name"; \ ]\
		$(MV) $(XAPPPATH)/$$name $(XAPPPATH)/$$name.bak ; fi; \ ]\
	(echo "Installing $$name.ad"; \ ]\
	$(INSTALL) -m $(INSTALL_APP) $$name.ad $(XAPPPATH)/$$name); \ ]\
	done]
#endif	/* InstallXappFiles */


#ifndef ParseHTIncs
#define	ParseHTIncs(files,oldsuffix,newsuffix,dest)\
]\
all::]\
]\
all-local:: ]\
	@for file in files ; do \ ] \
	echo "Creating $$file.newsuffix"; \ ] \
	$(PERL) -n -e 'if(/^<inc srv "(\S+)">$$/)' \ ]\
	-e '{open(INCFILE,$$1) || die "problem opening $$1";' \ ]\
	-e 'while(<INCFILE>){print;}close(INCFILE);}' \ ]\
	-e 'else{print;}' \ ]\
	$$file.oldsuffix > $$file.newsuffix; \ ]\
	done]\
]\
clean-local:: ]\
	@for file in files ; do \ ]\
	echo "$(RM) $$file.newsuffix"; \ ]\
	$(RM) $$file.newsuffix; \ ]\
	done]\
]\
install-local::]\
	MakeDir(dest)]\
	@for file in files; do\ ]\
	(echo "Installing $$file.newsuffix";\ ]\
	$(INSTALL) -m $(INSTALL_INC) $$file.newsuffix dest);\ ]\
	done]
#endif	/* ParseHTIncs */

#ifndef ParseHTIsmaps
#define	ParseHTIsmaps(files,suffix,dest)\
]\
all::]\
]\
all-local:: ]\
	@for file in files ; do \ ] \
	echo "Creating $$file.suffix"; \ ] \
	$(PERL) -n -e 'if(/^<inc srv "(\S+)">$$/)' \ ]\
	-e '{open(INCFILE,$$1) || die "problem opening $$1";' \ ]\
	-e 'while(<INCFILE>){print;}close(INCFILE);}' \ ]\
	-e 'else{print;}' \ ]\
	$$file > $$file.suffix; \ ]\
	done]\
]\
clean-local:: ]\
	@for file in files ; do \ ]\
	echo "$(RM) $$file.suffix"; \ ]\
	$(RM) $$file.suffix; \ ]\
	done]\
]\
install-local::]\
	MakeDir(dest)]\
	@for file in files; do\ ]\
	(echo "Installing $$file.suffix";\ ]\
	$(INSTALL) -m $(INSTALL_INC) $$file.suffix dest);\ ]\
	done]
#endif	/* ParseHTIsmaps */
