/* 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

/* bmarsch: InterViews wants to know which kits to compile */
#ifndef KitFlags
#define KitFlags \
-Dmotif_kit \
-Dsgi_motif_kit \
-Dopenlook_kit \
-Dbw_kit \
-Ddefault_kit=SMFKit
#endif

/* TIFF C compiler -- must be ANSI C for TIFF 3.3 */

#if defined(UltrixArchitecture)
#ifndef TIFFCDriver
#define TIFFCDriver c89
#endif
#endif
/* UltrixArchitecture */


#if defined(SunArchitecture)
#if (OSMajorVersion < 5) && !defined(HasGcc)
/* SunOS */  /* ooff, no ansi-cc on ganymed */
#define TIFFCDriver CC
#else
/* Solaris */  /* mpichler, 19941122: changed from CC to gcc */
#define TIFFCDriver gcc
#endif
#endif

#ifdef i386SVR4Architecture
#define ExtraCCLdLibs -lnsl -lsocket
#endif

#if defined(SGIArchitecture)
#ifndef TIFFCDriver
#define TIFFCDriver cc -ansi
#endif
#endif
/* SGIArchitecture */

#if defined(HPArchitecture) && !defined(HasGcc)
#ifndef TIFFCDriver
#define TIFFCDriver cc -Aa
#endif
#endif
/* HPArchitecture */

/* I think this should solve the problem for Linux -- hdg201094 */
#if defined(LinuxArchitecture)
/* hack to avoid redefined warnings
   I think the problem is with the define in SunArchitecture; see above */
#if defined(TIFFCDriver)
#undef TIFFCDriver
#endif
#define TIFFCDriver gcc
#endif

#if defined(SCOArchitecture) && !defined(HasGcc)
#ifndef TIFFCDriver
#define TIFFCDriver cc -Xc -a ansi -Dsco -DSCO -DSYSV
#endif
#endif
/* SCOArchitecture */


/* 	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


/* ----- HP-UX ---- */
/* kandrews 24 May 94   use static libraries */
#ifdef HPArchitecture
#ifndef NonSharedCCLdFlags
#define NonSharedCCLdFlags -Wl,-a,archive
#endif
#endif
/* ----- end HP-UX ---- */

/* ----- ALPHA_OSF1 ---- */
#if defined(AlphaArchitecture) && !defined(HasGcc)
#ifndef CppCmd
#define CppCmd   cxx -E
#endif
 
#ifndef CCDriver
#define CCDriver cxx
#endif

#endif


#if HasGcc
/*
 * Definitions for gcc/g++.
 */

#undef LanguageCCDefines
#define LanguageCCDefines -Dcplusplus_2_1
 
#ifndef CcCmd
#define CcCmd gcc
#endif

#ifndef CCDriver
#define CCDriver g++ -O2
#endif

#ifndef DependCCFlags
#define DependCCFlags -D__GNUC__ $(CCDEFINES) $(CCINCLUDES) -I/usr/local/lib/g++-include
#endif

#undef HasSunOSSharedLibraries
#define HasSunOSSharedLibraries NO

#ifndef NonSharedCCLdFlags
#define NonSharedCCLdFlags /**/
#endif

#endif
/*
 * end of Definitions for gcc/g++.
 */


/* ----- SUN ---- */
#ifdef SunArchitecture  

#define InstLibFlags -m 0664 -g graphic

#ifdef HasSunOSSharedLibraries
#undef HasSunOSSharedLibraries
#endif
 
#define HasSunOSSharedLibraries NO

#ifndef UseShared
#define UseNonShared
#endif

#define MakeSpecialShared YES



#if OSMajorVersion < 5

/* SunOS */
/* C-library shared */
#define HasRanlibCmd YES

#ifndef ExtraCCLdLibs
#define ExtraCCLdLibs -Bdynamic
#endif

#else

/* Solaris */
/* add /usr/openwin/lib to shared library load path */
#define RanlibCmd ar s

#ifdef HasGcc
#define ExtraCCLdLibs -lg++ -lnsl -lsocket -Xlinker -R -Xlinker /usr/openwin/lib
#else
#define ExtraCCLdLibs -R /usr/openwin/lib
#endif

#endif

#endif
/* ----- end SUN ---- */




#ifndef DependCmd
#define DependCmd makedepend.pl
#endif


#ifdef InstallCmd
#undef InstallCmd
#endif


#if SystemV || SystemV4

#ifdef UseInstalled

#undef BourneShell
#define KornShell /bin/ksh
#define BourneShell KornShell
/* gpani  9 Jan 95   always trust our hginstall !! */
/* #define InstallCmd hgbsdinstall -n -f */
#define InstallCmd hginstall -n -f

#else

#define InstallCmd $(SHELL) $(SCRIPTSRC)/bsdinst.sh

#endif

#else




/* ----- SUN ---- */
#ifdef SunArchitecture
#ifdef UseInstalled
#undef BourneShell
#define KornShell /bin/sh
#define BourneShell KornShell
#define InstallCmd hginstall -n -f
#else
#define InstallCmd install
#endif
/* ----- not SUN ---- */
#else
#ifdef UseInstalled
#undef BourneShell
#define KornShell /bin/sh
#define BourneShell KornShell
#define InstallCmd hginstall -n -f
#else
#define InstallCmd install
#endif
#endif
#endif



all::

uninstall::

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

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




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

/*
 * If you do not want to create a symbolic link called "/interviews"
 * that points at /..../iv/installed, you should replace /interviews
 * below with the name of the symbolic link you do want to use (say,
 * /usr/local/interviews).  If you don't want to create a symbolic
 * link at all, replace /interviews with the absolute pathname of
 * /..../iv/installed so InterViews applications still can find the
 * installed data files.
 */
#undef InstalledRoot
/* #define InstalledRoot /interviews */

#undef InstalledRoot30
#define InstalledRoot30 /interviews30

/*
 * If the X11 config files are not in /usr/lib/X11/config, the X11
 * includes are not in /usr/include, or the X11 libraries are not in
 * /lib, /usr/lib, or /usr/local/lib, then you should specify their
 * actual locations here.
 *
 * If you have to set XConfigDir, don't forget to override XCONFIGDIR
 * on the command line when saying "make World" for the first time.
 */

/*
#define XConfigDir /usr/X11R5/lib/X11/config
#define XIncDir /usr/X11R5/include
#define XLibDir /usr/X11R5/lib
*/

#define CCSuffix C

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

#ifndef RootDir
#define RootDir /usr2/harmony   /* is normally from (hg)imake via -DRootDir=... */
#endif

/* root for InterViews (lib and includes) */
#define InstalledRoot RootDir/iicmviews

#ifndef HgIncDir
#define HgIncDir $(ROOTDIR)/include
#endif

#ifndef HgLibDir
#define HgLibDir $(ROOTDIR)/lib/hyperg/$(ARCH)
#endif

#ifndef HgBinDir
#define HgBinDir $(ROOTDIR)/bin/$(ARCH)
#endif


#ifndef HgScriptDir
#define HgScriptDir $(ROOTDIR)/bin/scripts
#endif

#ifndef HgManDir
#define HgManDir $(ROOTDIR)/man
#endif

/* mpichler, 19951124: some X11 config files have already defined ConfigDir (e.g. Solaris)
 * this will lead to the local config environment beeing not found.
 * If you want to change the X11 config directory, change XConfigDir instead.
 */
#ifdef ConfigDir
#undef ConfigDir
#endif

#define ConfigDir $(ROOTDIR)/config

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

          ROOTDIR = RootDir
         HGINCDIR = HgIncDir
 	 HGLIBDIR = HgLibDir
 	 HGBINDIR = HgBinDir
      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

#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 Use_libUnidraw
#define Use_libUnidraw() 						@@\
     IV_CCDEFINES = IvCCDefines						@@\
									@@\
    IV_CCINCLUDES = IvCCIncludes					@@\
									@@\
    DEPLIBUNIDRAW = Dep_libUnidraw					@@\
         DEPLIBIV = Dep_libIV						@@\
       DEPLIBXEXT = Dep_libXext						@@\
        DEPLIBX11 = Dep_libX11						@@\
          DEPLIBM = Dep_libm						@@\
									@@\
       LIBDIRPATH = LibDirPath						@@\
     LDLIBUNIDRAW = Ld_libUnidraw					@@\
          LDLIBIV = Ld_libIV						@@\
      XLIBDIRPATH = XLibDirPath						@@\
        LDLIBXEXT = Ld_libXext						@@\
         LDLIBX11 = Ld_libX11						@@\
           LDLIBM = Ld_libm						@@\
    ABSLIBDIRPATH = AbsLibDirPath
#endif

#ifndef Use_libgraphic
#define Use_libgraphic() 						@@\
     IV_CCDEFINES = IvCCDefines						@@\
									@@\
    IV_CCINCLUDES = IvCCIncludes					@@\
									@@\
    DEPLIBGRAPHIC = Dep_libgraphic					@@\
         DEPLIBIV = Dep_libIV						@@\
       DEPLIBXEXT = Dep_libXext						@@\
        DEPLIBX11 = Dep_libX11						@@\
          DEPLIBM = Dep_libm						@@\
									@@\
       LIBDIRPATH = LibDirPath						@@\
     LDLIBGRAPHIC = Ld_libgraphic					@@\
          LDLIBIV = Ld_libIV						@@\
      XLIBDIRPATH = XLibDirPath						@@\
        LDLIBXEXT = Ld_libXext						@@\
         LDLIBX11 = Ld_libX11						@@\
           LDLIBM = Ld_libm						@@\
    ABSLIBDIRPATH = AbsLibDirPath
#endif

#ifndef Use_2_6
#define Use_2_6()							@@\
 BACKWARD_CCDEFINES = BackwardCompatibilityCCDefines			@@\
       IV_CCDEFINES = IvCCDefines					@@\
									@@\
BACKWARD_CCINCLUDES = BackwardCompatibilityCCIncludes			@@\
      IV_CCINCLUDES = IvCCIncludes
#endif

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

#ifndef SpecialUseShared
#if defined(UseShared) && defined(InObjectCodeDir)
#define SpecialUseShared -DUseShared
#else
#define SpecialUseShared /**/
#endif
#endif

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

#ifndef SharedCCFlags
#if HasSunOSSharedLibraries
#define SharedCCFlags -pic
#else
#if defined(UseShared) && defined(InObjectCodeDir)
#define SharedCCFlags -pic
#else
#define SharedCCFlags /**/
#endif
#endif
#endif

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

/*
 * 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:: 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:: 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 InstallSunOSSharedLibrary
#define InstallSunOSSharedLibrary(libname,rev,dest)			@@\
install:: Concat(lib,libname.so.rev)					@@\
	MakeDir(dest)							@@\
	$(INSTALL) -c $(INSTLIBFLAGS) Concat(lib,libname.so.rev) dest	@@\
uninstall::								@@\
	$(RM) Concat3(dest/,lib,libname.so.rev)				@@\
	RmDir(dest)
#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 either a shared library or a non-shared library.
 */
#ifndef NormalLibraryTarget
#if HasSunOSSharedLibraries
#define NormalLibraryTarget(libname,rev,depobjs,ldobjs)			@@\
NormalSunOSSharedLibraryTarget(libname,rev,depobjs,ldobjs)
#else
#if defined(UseShared)
#define NormalLibraryTarget(libname,rev,depobjs,ldobjs)			@@\
NormalSunOSSharedLibraryTarget(libname,rev,depobjs,ldobjs)
#else
#define NormalLibraryTarget(libname,rev,depobjs,ldobjs)			@@\
NormalNonSharedLibraryTarget(libname,depobjs,ldobjs)
#endif
#endif
#endif

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

#ifndef InstallLibrary
#if HasSunOSSharedLibraries || defined(UseShared)
#define InstallLibrary(libname,rev,dest)				@@\
InstallSunOSSharedLibrary(libname,rev,dest)
#else
#define InstallLibrary(libname,rev,dest)				@@\
InstallNonSharedLibrary(libname,dest)
#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,$(HGBINDIR),destname)
#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

/*
 * Make the above targets in specialized versions of the appropriate
 * object code subdirectories.
 */
#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
#if HasSunOSSharedLibraries
#define MakeInObjectCodeDir()						@@\
MakefileObjectCodeDir($(ARCH))						@@\
DependSubdirs($(ARCH))							@@\
MakeSubdirs($(ARCH))							@@\
InstallSubdirs($(ARCH))							@@\
CleanSubdirs($(ARCH))							@@\
SpecialTargets(debug,-DUseDebug)					@@\
SpecialTargets(noshared,-DUseNonShared)
#else
#if MakeSpecialShared
#define MakeInObjectCodeDir()						@@\
MakefileObjectCodeDir($(ARCH))						@@\
DependSubdirs($(ARCH))							@@\
MakeSubdirs($(ARCH))							@@\
InstallSubdirs($(ARCH))							@@\
CleanSubdirs($(ARCH))							@@\
SpecialTargets(debug,-DUseDebug)					@@\
SpecialTargets(shared,-DUseShared)
#else
#define MakeInObjectCodeDir()						@@\
MakefileObjectCodeDir($(ARCH))						@@\
DependSubdirs($(ARCH))							@@\
MakeSubdirs($(ARCH))							@@\
InstallSubdirs($(ARCH))							@@\
CleanSubdirs($(ARCH))							@@\
SpecialTargets(debug,-DUseDebug)
#endif
#endif
#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 [ -f dir/Makefile ]; then \					@@\
		$(RM) dir/Makefile.bak; \				@@\
		$(MV) dir/Makefile dir/Makefile.bak; \			@@\
	fi; \								@@\
	$(IMAKE) $(IMAKEFLAGS) -DRootDir=$(ROOTDIR) \              	        @@\
        -DSrcDir=`pwd` -DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/dir \		@@\
	-DInObjectCodeDir -s dir/Makefile
#endif

#if __STDC__
#define MConcat(a,b)a##b
#else
#define MConcat(a,b)a/**/b
#endif

#if __STDC__
#define MConcat3(a,b,c)a##b##c
#else
#define MConcat3(a,b,c)a/**/b/**/c
#endif

#ifdef UnixCpp
#undef MConcat
#undef MConcat3
#define MConcat(a,b)a/**/b
#define MConcat3(a,b,c)a/**/b/**/c
#endif


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

/*
 * HgLibName
 */
#ifndef HgLibName
#if HasSunOSSharedLibraries || defined(UseShared)
#define HgLibName(name,rev)MConcat(libHg,name.so.rev)
#else
#define HgLibName(name,rev)MConcat(libHg,name.a)
#endif
#endif

#ifndef MakeWorld
#if HasSunOSSharedLibraries
#define MakeWorld(flags)						@@\
MakeNormalWorld(flags)							@@\
MakeSpecialWorld(.debug,flags)						@@\
MakeSpecialWorld(.noshared,flags)
#else
#if MakeSpecialShared
#define MakeWorld(flags)						@@\
MakeNormalWorld(flags)							@@\
MakeSpecialWorld(.debug,flags)						@@\
MakeSpecialWorld(.shared,flags)
#else
#define MakeWorld(flags)						@@\
MakeNormalWorld(flags)							@@\
MakeSpecialWorld(.debug,flags)
#endif
#endif
#endif

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

