/*
$Id: hg-special.def,v 1.9 1996/11/05 15:21:16 hleitner Exp $

$Log: hg-special.def,v $
Revision 1.9  1996/11/05 15:21:16  hleitner
removed some nested comment lines.

Revision 1.8  1996/10/17 13:17:48  hleitner
Added shared library support:

1) new Makefile varaibles: HGSHAREDLIBDIR, HGINSTSHAREDBIN,
   HARINSTSHAREDBIN, SHARED_CCFLAGS, SHARED_CCLDFLAGS,
   SHARED_CCLDLIBFLAGS, SHAREDLIBEXT

2) new imake rules: InstallSharedLibrary, NormalNonSharedLibraryTarget,
   NormalSharedLibraryTarget, MakeSharedObjectRule, MakeSharedHgLibrary,
   InstallSharedHgProgram, InstallHarProgram, InstallSharedHarProgram,
   BuildSharedProgram, BuildSharedProgObjsLibs, BuildSharedProgObjs,
   BuildSharedProg, HgSharedLibName

3) removed: SpecialUseShared, InstallSunOSSharedLibrary, NormalLibraryTarget

Revision 1.7  1996/09/23 15:40:35  hleitner
added iv_nls to IvCCDefines for I18N version of Interviews.

Revision 1.6  1996/02/19 16:34:26  hleitner
Changed macro InstallHgProgram: now HGINSTBIN specifies destination
directory.

Revision 1.5  1996/02/13 14:06:04  gpani
InstallProgramWithFlags: target changed "install:: install.destname"

Revision 1.4  1996/02/09 07:41:48  gpani
InstallProgramWithFlags: additional target 'install.destname: program'

Revision 1.3  1995/11/16 18:02:44  hleitner
Definitions of HGINSTROOT, HGINSTBIN, HARINSTROOT and HARINSTBIN were
added to hg-special.def.

Revision 1.2  1995/11/16 17:38:02  hleitner
Hyper-G specific path definitions were deleted from hg-special.def;
now these definitions (RootDir, HgBinDir, ...) are located in hg_path.def.

Revision 1.1  1995/11/13 09:58:14  hleitner
Initial revision

*/

XCOMM -----------------------------------------------------------------------
XCOMM hg-special.def

/*
 * The following macros are defined for the various templates and Imakefiles
 * 
 * Concat                       (a,b)
 * Concat3                      (a,b,c)
 * Concat4                      (a,b,c,d)
 * MConcat                      (a,b)
 * MConcat3                     (a,b,c)
 * Use_libInterViews            ()
 * Use_libInterViews30          ()
 * RmDir                        (dir)
 * InstallProgramWithFlags      (program,destdir,destname,flags)
 * InstallHgInclude             (includefile,destdir)
 * InstallSharedLibrary         (libname,rev,dest)
 * InstallNonSharedLibrary      (libname,dest)
 * InstallSubdirs               (dirs)
 * MakeHgLibrary                (name,rev)
 * InstallRenScript             (script,dest,destname)
 * InstallScript                (script,dest)
 * InstallHgScript              (script)
 * InstallHgManPage             (manpage,dest,destname)	
 * InstallHgProgram             (program,destname)
 * BuildProgram                 (program,depobjs,ldobjs,deplibs,ldlibs)
 * BuildProgObjsLibs            (program,depobjs,ldobjs,deplibs,ldlibs)
 * BuildProgObjs                (program,objs)
 * BuildProg                    (program)
 * SpecialTargets               (special,imakeflags)
 * MakeLexRule                  (dst,src,flags)
 * MakeSourceFromLexSrcFlags    (file,flags)
 * MakeSourceFromLexSrc         (file)
 * MakeYaccHeaderRule           (hdr,dst,src)
 * MakeSourceHeaderFromYaccSrc  (file)
 * MakeInObjectCodeDir          ()
 * MakefileObjectCodeDir        (dir)
 * LibName                      (name,rev)
 * HgLibName                    (name,rev)
 * MakeWorld                    (flags)
 * MakeInSubdirs                (dirs)
 *
 */


#if (__STDC__ && !defined(UnixCpp)) || defined(AnsiCpp)
#  define Concat(a,b)a##b
#  define Concat3(a,b,c)a##b##c
#  define Concat4(a,b,c,d)a##b##c##d
#  define MConcat(a,b)a##b
#  define MConcat3(a,b,c)a##b##c
#else
#  define Concat(a,b)a/**/b
#  define Concat3(a,b,c)a/**/b/**/c
#  define Concat4(a,b,c,d)a/**/b/**/c/**/d
#  define MConcat(a,b)a/**/b
#  define MConcat3(a,b,c)a/**/b/**/c
#endif

#ifndef StaticFlag
#define StaticFlag -Bstatic
#endif

#ifndef DynamicFlag
#define DynamicFlag -Bdynamic
#endif

/*
 * Reuse some parameters that may have been defined in the X11 .cf file.
 */
#if defined(DoRanlibCmd) && !defined(HasRanlibCmd)
#define HasRanlibCmd DoRanlibCmd
#endif

#if defined(DebuggableCDebugFlags) && !defined(DebugCCFlags)
#define DebugCCFlags DebuggableCDebugFlags
#endif

#if defined(OptimizedCDebugFlags) && !defined(OptimizeCCFlags)
#define OptimizeCCFlags OptimizedCDebugFlags
#endif

#if defined(DefaultCCOptions) && !defined(ExtraCCFlags)
#define ExtraCCFlags DefaultCCOptions
#endif

#if defined(StandardDefines) && !defined(ExtraCCDefines)
#define ExtraCCDefines StandardDefines
#endif

#if defined(StandardIncludes) && !defined(ExtraCCIncludes)
#define ExtraCCIncludes StandardIncludes
#endif

#if defined(ExtraLoadFlags) && !defined(ExtraCCLdFlags)
#define ExtraCCLdFlags ExtraLoadFlags
#endif

#if defined(ExtraLibraries) && !defined(ExtraCCLdLibs)
#define ExtraCCLdLibs ExtraLibraries
#endif


/*
 * Prevent the X11 .cf file from unintentionally overriding an IV rule
 * with the same name since most of the IV rules are different.
 */
#undef AllTarget
#undef CleanSubdirs
#undef CleanTarget
#undef ComplexProgramTarget
#undef CppScriptTarget
#undef DependSubdirs
#undef DependTarget
#undef InstallMultiple
#undef InstallMultipleFlags
#undef InstallProgram
#undef InstallProgramWithFlags
#undef InstallScript
#undef InstallSubdirs
#undef MakeDir
#undef MakeDirectories
#undef MakeSubdirs
#undef MakefileTarget
#undef RanLibrary
#undef SimpleProgramTarget


/* common targets */
/* */
/* Changed: 23.07.92 Gerald Pani, IICM */

/*
 * Define how to regenerate Makefiles, update their dependencies, and
 * execute recursive make commands.
 */
#ifndef ImakeCmd
#define ImakeCmd hgimake
#endif

/* 	TurnOnOptimizing YES */

#if SystemV
#ifndef TurnOnOptimizing
#define TurnOnOptimizing	NO	/* no optimizing by default */
#endif
#else
#ifndef TurnOnOptimizing
#define TurnOnOptimizing	YES	/* no optimizing by default */
#endif
#endif


#ifndef DependCmd
#define DependCmd makedepend.pl
#endif


#ifdef InstallCmd
#undef InstallCmd
#endif


#if SystemV || SystemV4
#    undef BourneShell
#    define KornShell /bin/ksh
#    define BourneShell KornShell
#    define InstallCmd hginstall -n -f
#else
/* ----- SUN ---- */
#  ifdef SunArchitecture
#      undef BourneShell
#      define KornShell /bin/sh
#      define BourneShell KornShell
#      define InstallCmd hginstall -n -f
/* ----- not SUN ---- */
#  else
#      undef BourneShell
#      define KornShell /bin/sh
#      define BourneShell KornShell
#      define InstallCmd hginstall -n -f
#  endif
#endif



all::

uninstall::

#ifndef CCDefines
#define CCDefines $(APP_CCDEFINES) $(LANGUAGE_CCDEFINES) $(IV_CCDEFINES) $(EXTRA_CCDEFINES)
#endif

#ifndef IvCCDefines
#define IvCCDefines -DInterViews -Div_nls $(BACKWARD_CCDEFINES)
#endif



/*
 * Delete this definition if your /tmp space is less than five megabytes.
 */
#undef HasLargeTmp
#define HasLargeTmp YES

#define CCSuffix C

#ifndef IvCCDefines
#define IvCCDefines -DInterViews $(LANGUAGE_CCDEFINES) $(BACKWARD_CCDEFINES)
#endif


/* #define CCIncludes -I$(SRC) $(APP_CCINCLUDES) $(HG_CCINCLUDES) $(IV_CCINCLUDES) $(EXTRA_CCINCLUDES) */
#define CCIncludes $(APP_CCINCLUDES) $(HG_CCINCLUDES) $(IV_CCINCLUDES) $(EXTRA_CCINCLUDES)
#define HgCCIncludes -I$(HGINCDIR)

          ROOTDIR = RootDir
         HGINCDIR = HgIncDir
         HGLIBDIR = HgLibDir
   HGSHAREDLIBDIR = HgSharedLibDir
         HGBINDIR = HgBinDir
       HGINSTROOT = HgInstRoot
        HGINSTBIN = HgInstBin
  HGINSTSHAREDBIN = HgInstSharedBin
      HARINSTROOT = HarInstRoot
       HARINSTBIN = HarInstBin
 HARINSTSHAREDBIN = HarInstSharedBin
      HGSCRIPTDIR = HgScriptDir
         HGMANDIR = HgManDir

    HG_CCINCLUDES = HgCCIncludes


/* ********************** new rules ******************* */
#ifndef Use_libInterViews
#define Use_libInterViews() 						@@\
    INSTALLEDROOT = InstalledRoot					@@\
									@@\
     IV_CCDEFINES = IvCCDefines						@@\
									@@\
    IV_CCINCLUDES = IvCCIncludes					@@\
									@@\
         DEPLIBIV = Dep_libIV						@@\
       DEPLIBXEXT = Dep_libXext						@@\
        DEPLIBX11 = Dep_libX11						@@\
          DEPLIBM = Dep_libm						@@\
									@@\
       LIBDIRPATH = LibDirPath						@@\
          LDLIBIV = Ld_libIV						@@\
      XLIBDIRPATH = XLibDirPath						@@\
        LDLIBXEXT = Ld_libXext						@@\
         LDLIBX11 = Ld_libX11						@@\
           LDLIBM = Ld_libm						@@\
    ABSLIBDIRPATH = AbsLibDirPath
#endif

/* We don't provide version 30 -- bheide230895
#ifndef Use_libInterViews30
#define Use_libInterViews30() 						@@\
    INSTALLEDROOT = InstalledRoot30					@@\
									@@\
     IV_CCDEFINES = IvCCDefines						@@\
									@@\
    IV_CCINCLUDES = IvCCIncludes					@@\
									@@\
         DEPLIBIV = Dep_libIV						@@\
       DEPLIBXEXT = Dep_libXext						@@\
        DEPLIBX11 = Dep_libX11						@@\
          DEPLIBM = Dep_libm						@@\
									@@\
       LIBDIRPATH = LibDirPath						@@\
          LDLIBIV = Ld_libIV						@@\
      XLIBDIRPATH = XLibDirPath						@@\
        LDLIBXEXT = Ld_libXext						@@\
         LDLIBX11 = Ld_libX11						@@\
           LDLIBM = Ld_libm						@@\
    ABSLIBDIRPATH = AbsLibDirPath
#endif
*/


#ifndef SpecialImakeFlags
#define SpecialImakeFlags \
 SpecialInObjectCodeDir SpecialUseDebug SpecialUseNonShared SpecialArchitectureFlags
#endif


#ifndef SpecialArch
#if defined(UseDebug) && defined(InObjectCodeDir)
#define SpecialArch .debug
#else
#if defined(UseNonShared) && defined(InObjectCodeDir)
#define SpecialArch /**/
#endif
#endif
#endif


#ifndef SharedCCFlags
#define SharedCCFlags -fPIC
#endif

#ifndef SharedCCLdLibFlags
#define SharedCCLdLibFlags -fPIC -shared
#endif

#ifndef SharedCCLdFlags
#define SharedCCLdFlags -Xlinker -R -Xlinker /usr/local/Hyper-G/shlib:/usr/local/Harmony/shlib -L$(HGSHAREDLIBDIR)
#endif

#ifndef SharedLibExt
#define SharedLibExt so
#endif


#ifndef NonSharedCCLdFlags
#if defined(UseSysShared)
#define NonSharedCCLdFlags /**/
#else
#if defined(UseNonShared) && defined(InObjectCodeDir)
#define NonSharedCCLdFlags StaticFlag
#else
#define NonSharedCCLdFlags /**/
#endif
#endif
#endif


      SHARED_CCFLAGS = SharedCCFlags
    SHARED_CCLDFLAGS = SharedCCLdFlags
 SHARED_CCLDLIBFLAGS = SharedCCLdLibFlags
        SHAREDLIBEXT = SharedLibExt

/*
 * Remove a directory if necessary.
 */
#ifndef RmDir
#define RmDir(dir) -@if [ -d dir ] ; then \				@@\
			( x=`ls dir|wc -w`; \				@@\
			if [$$x -ne 0 ]; then \				@@\
				exit 0; \				@@\
			else \						@@\
				(set -x; rmdir dir); \ 			@@\
			fi ) ; \					@@\
		     else \						@@\
			exit 0; \					@@\
		     fi ;
#endif

/*
 * Install a program with renaming of the installed program.
 */
#ifndef InstallProgramWithFlags
#if RemoveAfterInstall
#define InstallProgramWithFlags(program,destdir,destname,flags)		@@\
install:: install.destname						@@\
install.destname:: program						@@\
	MakeDir(destdir)						@@\
	$(INSTALL) -c $(INSTPGMFLAGS) flags program destdir/destname	@@\
	$(RM) program							@@\
uninstall::								@@\
	$(RM) destdir/destname						@@\
	RmDir(destdir)
#else
#define InstallProgramWithFlags(program,destdir,destname,flags)		@@\
install:: install.destname						@@\
install.destname:: program						@@\
	MakeDir(destdir)						@@\
	$(INSTALL) -c $(INSTPGMFLAGS) flags program destdir/destname	@@\
uninstall::								@@\
	$(RM) destdir/destname						@@\
	RmDir(destdir)
#endif
#endif

/*
 * Install an includefile.
 */
#ifndef InstallHgInclude
#define InstallHgInclude(includefile,destdir)							@@\
install::											@@\
	MakeDir($(HGINCDIR)/hyperg/destdir)							@@\
	hgInstallHeader -p hyperg/destdir -s $(SRC)/includefile -d $(HGINCDIR)/hyperg/destdir/includefile @@\
uninstall::											@@\
	$(RM) $(HGINCDIR)/hyperg/destdir/includefile						@@\
	RmDir($(HGINCDIR)/hyperg/destdir)
#endif

/*
 * Install a library.
 */
#ifndef InstallSharedLibrary
#ifdef KornShell
#define InstallSharedLibrary(libname,rev,dest)				@@\
install:: Concat3(shared/,lib,libname.so.rev)				@@\
	MakeDir(dest)							@@\
	-@(if `testnewer Concat3(shared/,lib,libname.so.rev) Concat3(dest/,lib,libname.so.rev)` ; then \ @@\
	echo $(INSTALL) -c $(INSTLIBSHFLAGS) Concat(lib,libname.so.rev) dest ; \		@@\
	(cd shared; $(INSTALL) -c $(INSTLIBSHFLAGS) Concat(lib,libname.so.rev) dest) ; \	@@\
	(cd dest; rm -f Concat(lib,libname.$(SHAREDLIBEXT)); $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.$(SHAREDLIBEXT)))       ; \	@@\
	else \								@@\
		exit 0 ; \						@@\
	fi)								@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.so.rev)				@@\
	RmDir(dest)
#else
#define InstallSharedLibrary(libname,rev,dest)				@@\
install:: Concat3(shared/,lib,libname.so.rev)				@@\
	MakeDir(dest)							@@\
	echo $(INSTALL) -c $(INSTLIBSHFLAGS) Concat(lib,libname.so.rev) dest		@@\
	(cd shared; $(INSTALL) -c $(INSTLIBSHFLAGS) Concat(lib,libname.so.rev) dest)	@@\
	(cd dest; rm -f Concat(lib,libname.so); $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)) 		@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.so.rev)				@@\
	RmDir(dest)
#endif
#endif

#ifndef InstallNonSharedLibrary
#ifdef KornShell
#if HasRanlibCmd
#define InstallNonSharedLibrary(libname,dest)						@@\
install:: Concat(lib,libname.a)								@@\
	MakeDir(dest)									@@\
	-@(if `testnewer Concat(lib,libname.a) Concat3(dest/,lib,libname.a)` ; then \ 	@@\
		echo $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) dest ; \	@@\
		$(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) dest ; \		@@\
		echo RanLibrary($(RANLIBINSTFLAGS) Concat(dest/lib,libname.a)) ; \	@@\
		RanLibrary($(RANLIBINSTFLAGS) Concat(dest/lib,libname.a)) ; \		@@\
	else \								@@\
		exit 0 ; \						@@\
	fi)								@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.a)				@@\
	RmDir(dest)
#else
#define InstallNonSharedLibrary(libname,dest)						@@\
install:: Concat(lib,libname.a)								@@\
	MakeDir(dest)									@@\
	-@(if `testnewer Concat(lib,libname.a) Concat3(dest/,lib,libname.a)` ; then \ 	@@\
		echo $(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) dest ; \	@@\
		$(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) dest ; \		@@\
	else \								@@\
		exit 0 ; \						@@\
	fi)								@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.a)				@@\
	RmDir(dest)
#endif
#else
#define InstallNonSharedLibrary(libname,dest)				@@\
install:: Concat(lib,libname.a)						@@\
	MakeDir(dest)							@@\
	$(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.a) dest	@@\
	RanLibrary($(RANLIBINSTFLAGS) Concat(dest/lib,libname.a))	@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.a)				@@\
	RmDir(dest)
#endif
#endif



#ifndef InstallSubdirs
#define InstallSubdirs(dirs)							@@\
IntoSubdirs(install,dirs,"installing")						@@\
IntoSubdirs(uninstall,dirs,"uninstalling")
#endif



/*
 * Make a non-shared library archive.
 */
#ifndef NormalNonSharedLibraryTarget
#define NormalNonSharedLibraryTarget(libname,depobjs,ldobjs)		@@\
AOUT = Concat(lib,libname.a)						@@\
									@@\
AllTarget(Concat(lib,libname.a))					@@\
									@@\
Concat(lib,libname.a): depobjs						@@\
	@echo "building $@"						@@\
	$(RM) $@							@@\
	$(AR) $@ ldobjs							@@\
	RanLibrary($@)
#endif


/*
 * Make a shared library.
 */
#ifndef NormalSharedLibraryTarget
#define NormalSharedLibraryTarget(libname,rev,depobjs,ldobjs)		@@\
AOUT_SH = Concat3(shared/,lib,libname.so.rev)				@@\
SHARED_CCLDLIBFLAGS = SharedCCLdLibFlags				@@\
S_OBJS = $(patsubst %.o,shared/%.o,ldobjs)				@@\
S_DEP_OBJS = $(patsubst %.o,shared/%.o,depobjs)				@@\
									@@\
AllTarget(Concat3(shared/,lib,libname.so.rev))				@@\
									@@\
Concat3(shared/,lib,libname.so.rev): $(S_DEP_OBJS)			@@\
	@echo "building $@"						@@\
	$(RM) Concat(lib,libname.so.rev)				@@\
	$(CCCMD) $(SHARED_CCLDLIBFLAGS) -o Concat(lib,libname.so.rev)  $(S_OBJS)	@@\
	$(RM) $@~							@@\
	-@if [ -f $@ ] ; then \						@@\
	  	$(MV)  $@ $@~ ; \                              		@@\
	fi ;								@@\
	$(MV)  Concat(lib,libname.so.rev) $@           			@@\
	chmod +x  $@							@@\
									@@\
clean::									@@\
	$(RM) Concat3(shared/,lib,libname.so.rev) 			@@\
	$(RM) $(S_OBJS)
#endif


/*
 * Make an object file.  $(AOUT) is either a.out or a library and the
 * dependency allows Imakefiles to avoid having to define OBJS.
 */
#ifndef MakeObjectRule
#define MakeObjectRule(dst,src,flags)					@@\
$(AOUT): dst.o								@@\
dst.o: src.$(CCSUFFIX)							@@\
	@$(RM) dst.o dst..c						@@\
	$(CCDRIVER) $(CCFLAGS) flags -c src.$(CCSUFFIX)
#endif


#ifndef MakeSharedObjectRule
#define MakeSharedObjectRule(dst,src,flags)					@@\
$(AOUT_SH): shared/dst.o						@@\
shared/dst.o: src.$(CCSUFFIX)						@@\
	@$(RM) shared/dst.o dst..c					@@\
	$(CCDRIVER) $(SHARED_CCFLAGS) $(CCFLAGS) flags -c src.$(CCSUFFIX)  -o shared/dst.o
#endif


/*
 * Shorthand for building and installing a library in HGLIBDIR.
 */
#ifndef MakeHgLibrary
#define MakeHgLibrary(name,rev)					@@\
NormalNonSharedLibraryTarget(name,$(OBJS),$(OBJS))		@@\
InstallNonSharedLibrary(name,$(HGLIBDIR))			@@\
DependTarget()
#endif

#ifndef MakeSharedHgLibrary
#ifndef HaveShared 
#define MakeSharedHgLibrary(name,rev)
#else
#define MakeSharedHgLibrary(name,rev)				@@\
NormalSharedLibraryTarget(name,rev,$(SH_OBJS),$(SH_OBJS))	@@\
InstallSharedLibrary(name,rev,$(HGSHAREDLIBDIR))		@@\
DependSharedTarget()
#endif
#endif


/*
 * Install a script (which cannot be stripped like a program).
 */
#ifndef InstallRenScript
#define InstallRenScript(script,dest,destname)				@@\
install:: 								@@\
	MakeDir(dest)							@@\
	$(INSTALL) -c $(INSTBINFLAGS) $(SRC)/script dest/destname	@@\
uninstall::								@@\
	$(RM) dest/destname						@@\
	RmDir(dest)
#endif

#ifndef InstallScript
#define InstallScript(script,dest)					@@\
InstallRenScript(script,dest,script)
#endif

#ifndef InstallHgScript
#define InstallHgScript(script)					@@\
InstallRenScript(script,$(HGSCRIPTDIR),script)
#endif

#ifndef InstallHgManPage
#define InstallHgManPage(manpage,dest,destname)			@@\
InstallRenScript(manpage,$(HGMANDIR)/dest,destname)
#endif

#ifndef InstallHgProgram
#define InstallHgProgram(program,destname)			@@\
InstallProgram(program,$(HGINSTBIN),destname)
#endif

#ifndef InstallSharedHgProgram
#ifndef HaveShared 
#define InstallSharedHgProgram(program,destname)
#else
#define InstallSharedHgProgram(program,destname)		@@\
InstallProgram(program,$(HGINSTSHAREDBIN),destname)
#endif
#endif

#ifndef InstallHarProgram
#define InstallHarProgram(program,destname)			@@\
InstallProgram(program,$(HARINSTBIN),destname)
#endif

#ifndef InstallSharedHarProgram
#ifndef HaveShared 
#define InstallSharedHarProgram(program,destname)
#else
#define InstallSharedHarProgram(program,destname)		@@\
InstallProgram(program,$(HARINSTSHAREDBIN),destname)
#endif
#endif

/*
 * Build a program.
 */
#ifndef BuildProgram
#ifdef UseNoYP
#define BuildProgram(program,depobjs,ldobjs,deplibs,ldlibs)		@@\
program: depobjs deplibs						@@\
	RemoveIfUnwritable($@)						@@\
	$(CCDRIVER) $(CCLDFLAGS) -o $@ ldobjs ldlibs /usr/lib/shlib.etc/libc.a
#else
#define BuildProgram(program,depobjs,ldobjs,deplibs,ldlibs)		@@\
program: depobjs deplibs						@@\
	RemoveIfUnwritable($@)						@@\
	@echo "$(CCDRIVER) $(CCLDFLAGS) -o $@ ldobjs ldlibs"		@@\
	@$(CCDRIVER) $(CCLDFLAGS) -o $@ ldobjs ldlibs || ($(RM) $@; exit 1)
#endif
#endif

#ifndef BuildProgObjsLibs
#define BuildProgObjsLibs(program,depobjs,ldobjs,deplibs,ldlibs)	@@\
BuildProgram(program,depobjs,ldobjs,deplibs,ldlibs)
#endif

#ifndef BuildProgObjs
#define BuildProgObjs(program,objs)					@@\
BuildProgObjsLibs(program,objs,objs,$(CCDEPLIBS),$(CCLDLIBS))
#endif

#ifndef BuildProg
#define BuildProg(program)						@@\
BuildProgObjs(program,$(OBJS))
#endif

/*
 * Build a program with shared libraries.
 */
#ifndef BuildSharedProgram
#ifdef UseNoYP
#define BuildSharedProgram(program,depobjs,ldobjs,deplibs,ldlibs)	@@\
program: depobjs deplibs						@@\
	RemoveIfUnwritable($@)						@@\
	$(CCDRIVER) $(SHARED_CCLDFLAGS) $(CCLDFLAGS) -o $@ ldobjs ldlibs /usr/lib/shlib.etc/libc.a
#else
#define BuildSharedProgram(program,depobjs,ldobjs,deplibs,ldlibs)	@@\
program: depobjs deplibs						@@\
	RemoveIfUnwritable($@)						@@\
	@echo "$(CCDRIVER) $(SHARED_CCLDFLAGS) $(CCLDFLAGS) -o $@ ldobjs ldlibs"		@@\
	@$(CCDRIVER) $(SHARED_CCLDFLAGS) $(CCLDFLAGS) -o $@ ldobjs ldlibs || ($(RM) $@; exit 1)
#endif
#endif

#ifndef BuildSharedProgObjsLibs
#define BuildSharedProgObjsLibs(program,depobjs,ldobjs,deplibs,ldlibs)	@@\
BuildSharedProgram(program,depobjs,ldobjs,deplibs,ldlibs)
#endif

#ifndef BuildSharedProgObjs
#define BuildSharedProgObjs(program,objs)				@@\
BuildSharedProgObjsLibs(program,objs,objs,$(CCDEPLIBS),$(CCLDLIBS))
#endif

#ifndef BuildSharedProg
#define BuildSharedProg(program)					@@\
BuildSharedProgObjs(program,$(OBJS))
#endif

/*
 * Make the above targets in specialized versions of the appropriate
 * object code subdirectories.
 * We add a double point to allow more than one instances of a target
 * the warnings about redefinition -- bheide111095
 */
#ifndef SpecialTargets
#define SpecialTargets(special,imakeflags)				@@\
Makefiles.special::							@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	Makefiles							@@\
depend.special::								@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	depend								@@\
all.special::								@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	all								@@\
install.special::							@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	install								@@\
uninstall.special::							@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	uninstall							@@\
clean.special::								@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	clean
#endif


/* gpani ******************* */
/*
 * Make a C source from a lex source
 */
#ifndef MakeLexRule
#define	MakeLexRule(dst,src,flags)   	            			@@\
dst.c: src.l                            	         		@@\
	@echo "applying $(LEX) to src.l"               			@@\
	$(RM) $@                                     			@@\
	$(LEX) -t flags $(LFLAGS) src.l >dst.c       			@@\
	                                             			@@\
clean::                                          			@@\
	$(RM) dst.c
#endif /* MakeLexRule */

#ifndef MakeSourceFromLexSrcFlags
#define	MakeSourceFromLexSrcFlags(file,flags)				@@\
MakeLexRule(file,$(SRC)/file,flags)
#endif /* MakeSourceFromLexSrcFlags */

#ifndef MakeSourceFromLexSrc
#define	MakeSourceFromLexSrc(file)					@@\
MakeSourceFromLexSrcFlags(file,)
#endif /* MakeSourceFromLexSrc */


/*
 * Make a C source and header from a yacc source
 */
#ifndef MakeYaccHeaderRule
#define	MakeYaccHeaderRule(hdr,dst,src)                    		@@\
hdr.h: dst.c                                                   		@@\
	                                                       		@@\
dst.c: src.y                                                   		@@\
	@echo "applying $(YACC) to src.y"                           	@@\
	@echo "    produce hdr.h, dst.c"                           	@@\
	$(RM) dst.c                                              	@@\
	$(YACC) -d $(YFLAGS) src.y                               	@@\
	-@if [ -f y.tab.c ] ; then \					@@\
	  	$(MV) y.tab.c dst.c ; \                              	@@\
	else \								@@\
	  	$(MV) src.tab.c dst.c ; \				@@\
	fi ; \								@@\
	if [ ! -f hdr.h ] ; then \                             		@@\
	  	if [ -f y.tab.h ] ; then \				@@\
	    		$(MV) y.tab.h hdr.h ; \                         @@\
	  	else \							@@\
	    		$(MV) src.tab.h hdr.h ; \			@@\
	  	fi ; \							@@\
	elif [ -f y.tab.h ] ; then \					@@\
	  	if [ diff y.tab.h hdr.h >/dev/null ] ; then \        	@@\
	    		$(RM) y.tab.h ; \                               @@\
	  	else \                                               	@@\
	    		$(MV) y.tab.h hdr.h ; \                         @@\
	  	fi ; \							@@\
	else \								@@\
	  	if [ diff src.tab.h hdr.h >/dev/null ] ; then \         @@\
	    		$(RM) src.tab.h ; \                             @@\
	  	else \                                                	@@\
	    		$(MV) src.tab.h hdr.h ; \                       @@\
	  	fi ; \							@@\
	fi ;                                                   		@@\
	                                                       		@@\
clean::                                         	       		@@\
	$(RM) hdr.h dst.c
#endif /* MakeYaccHeaderRule */

#ifndef MakeSourceHeaderFromYaccSrc
#define	MakeSourceHeaderFromYaccSrc(file)   				@@\
MakeYaccHeaderRule(file,file,$(SRC)/file)
#endif /* MakeSourceHeaderFromYaccSrc */

/*
 * Shorthand for making all targets in the appropriate object code
 * subdirectory.
 */
#ifndef MakeInObjectCodeDir
#define MakeInObjectCodeDir()						@@\
MakefileObjectCodeDir($(ARCH))						@@\
DependSubdirs($(ARCH))							@@\
MakeSubdirs($(ARCH))							@@\
InstallSubdirs($(ARCH))							@@\
CleanSubdirs($(ARCH))							@@\
SpecialTargets(debug,-DUseDebug)
#endif

/*
 * Make the Makefile in the appropriate object code subdirectory.
 */
#ifndef MakefileObjectCodeDir
#define MakefileObjectCodeDir(dir)					@@\
Makefiles::								@@\
	@echo "Making Makefiles" \					@@\
	"for $(ARCH) in $(CURRENT_DIR)/dir"				@@\
	-@if [ ! -d dir ]; then \					@@\
		mkdir dir; \						@@\
		chmod g+w dir; \					@@\
	fi; \								@@\
	if [ ! -d dir/shared ]; then \					@@\
		mkdir dir/shared; \					@@\
		chmod g+w dir/shared; \					@@\
	fi; \								@@\
	if [ -f dir/Makefile ]; then \					@@\
		$(RM) dir/Makefile.bak; \				@@\
		$(MV) dir/Makefile dir/Makefile.bak; \			@@\
	fi; \								@@\
	$(IMAKE) $(IMAKEFLAGS) \					@@\
        -DSrcDir=`pwd` -DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/dir \		@@\
	-DInObjectCodeDir -s dir/Makefile
#endif


/*
 * LibName
 */
#ifndef LibName
#define LibName(name,rev)MConcat(lib,name.a)
#endif

/*
 * HgLibName
 */
#ifndef HgLibName
#define HgLibName(name,rev)MConcat(libHg,name.a)
#endif

/*
 * HgSharedLibName
 */
#ifndef HgSharedLibName
#define HgSharedLibName(name,rev)MConcat3(libHg,name.$(SHAREDLIBEXT),rev)
#endif

#ifndef MakeWorld
#define MakeWorld(flags)						@@\
MakeNormalWorld(flags)							@@\
MakeSpecialWorld(.debug,flags)
#endif

/*
 * Shorthand for making all targets in a list of subdirectories.
 */
#ifndef MakeInSubdirs
#define MakeInSubdirs(dirs)						@@\
MakefilesSubdirs(dirs)							@@\
DependSubdirs(dirs)							@@\
MakeSubdirs(dirs)							@@\
InstallSubdirs(dirs)							@@\
CleanSubdirs(dirs)							@@\
SpecialTargets(debug,-DUseDebug)
#endif

