/*
$Id: rules.def,v 1.4 1996/10/18 07:42:52 bheide Exp $

$Log: rules.def,v $
Revision 1.4  1996/10/18 07:42:52  bheide
added UseGcc macro

Revision 1.3  1996/10/17 14:01:51  hleitner
Removed: all the *SunOSShared* stuff (no more needed with our new
shared library support).

Added: shared library support; new imake rules and defines are:

AllSharedTarget, DependSharedTarget, MakeSharedObjectFromSrcFlags,
MakeSharedObjectFromSrc, InstallLibrary, InstallSharedProgram.

Revision 1.2  1996/09/26 05:29:13  jfasch
MakeObjectRule bug (dst..c)

Revision 1.1  1995/11/13 10:54:24  hleitner
Initial revision

*/

XCOMM -----------------------------------------------------------------------
XCOMM rules.def


/*
 * The following macros are defined for the various templates and Imakefiles
 * 
 * MakeCPU                      ()
 * MakeNormalWorld              (flags)
 * MakeSpecialWorld             (special,flags)
 * MakeWorld                    (flags)
 * MakefileTarget               ()
 * MakefilesSubdirs             (dirs)
 * MakefileObjectCodeDir        (dir) 
 * IntoSubdirs                  (name,dirs,verb)
 * DependSubdirs                (dirs)
 * MakeSubdirs                  (dirs)
 * InstallSubdirs               (dirs)
 * CleanSubdirs                 (dirs)
 * FormatSubdirs                (dirs)
 * PrintSubdirs                 (dirs)
 * SpecialTargets               (special,imakeflags)
 * MakeInSubdirs                (dirs)
 * MakeInObjectCodeDir          ()
 * AllTarget                    (deps)
 * DependTarget                 ()
 * CleanTarget                  ()
 * Use_libInterViews            () 
 * MakeObjectRule               (dst,src,flags)
 * MakeObjectFromSrcFlags       (file,flags)
 * MakeObjectFromSrc            (file)	
 * RanLibrary                   (args)
 * NormalSharedLibraryTarget    (libname,rev,depobjs,ldobjs)
 * NormalNonSharedLibraryTarget (libname,depobjs,ldobjs)
 * NormalLibraryTarget          (libname,rev,depobjs,ldobjs)
 * MakeLibrary                  (name,rev)
 * RemoveIfUnwritable           (program)
 * BuildProgram                 (program,depobjs,ldobjs,deplibs,ldlibs)
 * ComplexProgramTarget         (program)
 * SimpleProgramTarget          (program)
 * TroffSources                 (formatted)
 * CppScriptTarget              (dst,src,defs,deplist)
 * MakeDirectories              (step,dirs)
 * MakeDir                      (dir)
 * InstallProgramWithFlags      (program,destdir,destname,flags)
 * InstallProgram               (program,destdir,destname)
 * InstallScript                (script,dest)
 * InstallMultipleFlags         (list,dest,flags)
 * InstallMultiple              (list,dest)
 *
 */



/*
 * Print the name you should assign to CPU.
 */
#ifndef MakeCPU
#define MakeCPU()							@@\
CPU:									@@\
	@$(SHELL) $(SCRIPTSRC)/cpu.sh $(CONFIGSRC)/InterViews/arch.def
#endif

/*
 * Make everything in the normal object code subdirectories.
 */
#ifndef MakeNormalWorld
#define MakeNormalWorld(flags)						@@\
World::									@@\
	@echo ""							@@\
	@echo "Building InterViews 3.0 on `date`"			@@\
	@echo ""							@@\
	$(MAKE) Makefile XCONFIGDIR=$(XCONFIGDIR)			@@\
	@echo ""							@@\
	$(MAKE) Makefiles						@@\
	@echo ""							@@\
	$(MAKE) depend							@@\
	@echo ""							@@\
	$(MAKE) flags all						@@\
	@echo ""							@@\
	@echo "InterViews build completed on `date`"			@@\
	@echo ""
#endif

/*
 * Make everything in special object code subdirectories.
 */
#ifndef MakeSpecialWorld
#define MakeSpecialWorld(special,flags)					@@\
Concat(World,special)::							@@\
	@echo ""							@@\
	@echo "Building InterViews 3.0 on `date`"			@@\
	@echo ""							@@\
	$(MAKE) Makefile XCONFIGDIR=$(XCONFIGDIR)			@@\
	@echo ""							@@\
	$(MAKE) Concat(Makefiles,special)				@@\
	@echo ""							@@\
	$(MAKE) Concat(depend,special)					@@\
	@echo ""							@@\
	$(MAKE) flags Concat(all,special)				@@\
	@echo ""							@@\
	@echo "InterViews build completed on `date`"			@@\
	@echo ""
#endif

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

/*
 * Make the Makefile in the current directory.
 */
#ifndef MakefileTarget
#define MakefileTarget()						@@\
Makefile::								@@\
	-@if [ -f Makefile ]; then \					@@\
		$(RM) Makefile.bak; \					@@\
		$(MV) Makefile Makefile.bak; \				@@\
	else exit 0; fi							@@\
	$(IMAKE) $(IMAKEFLAGS) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
#endif

/*
 * Make the Makefiles in the list of subdirectories.
 */
#ifndef MakefilesSubdirs
#define MakefilesSubdirs(dirs)						@@\
Makefiles::								@@\
	-@for i in dirs; \						@@\
	do \								@@\
		if [ -d $$i ]; then ( \					@@\
			echo "Making Makefiles" \			@@\
			"for $(ARCH) in $(CURRENT_DIR)/$$i"; \		@@\
			if [ -f $$i/Makefile ]; then \			@@\
				$(RM) $$i/Makefile.bak; \		@@\
				$(MV) $$i/Makefile $$i/Makefile.bak; \	@@\
			fi; \						@@\
			$(IMAKE) $(IMAKEFLAGS) \			@@\
			-DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/$$i \@@\
			-f $$i/Imakefile -s $$i/Makefile; \		@@\
			cd $$i; \					@@\
			$(MAKE) $(PASSARCH) Makefiles; \		@@\
		) else continue; fi; \					@@\
	done
#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) \					@@\
	-DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/dir \		@@\
	-DInObjectCodeDir -s dir/Makefile
#endif

/*
 * Make the given target in the list of subdirectories.
 */
#ifndef IntoSubdirs
#define IntoSubdirs(name,dirs,verb)					@@\
name::									@@\
	-@for i in dirs; \						@@\
	do \								@@\
		if [ -d $$i ]; then ( \					@@\
			echo verb \					@@\
			"for $(ARCH) in $(CURRENT_DIR)/$$i"; \		@@\
			cd $$i; \					@@\
			$(MAKE) $(PASSARCH) name; \			@@\
		) else continue; fi; \					@@\
	done
#endif

#ifndef DependSubdirs
#define DependSubdirs(dirs)						@@\
IntoSubdirs(depend,dirs,"depending")
#endif

#ifndef MakeSubdirs
#define MakeSubdirs(dirs)						@@\
IntoSubdirs(all,dirs,"making all")
#endif

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

#ifndef CleanSubdirs
#define CleanSubdirs(dirs)						@@\
IntoSubdirs(clean,dirs,"cleaning")
#endif

#ifndef FormatSubdirs
#define FormatSubdirs(dirs)						@@\
IntoSubdirs(format,dirs,"formatting")
#endif

#ifndef PrintSubdirs
#define PrintSubdirs(dirs)						@@\
IntoSubdirs(print,dirs,"printing")
#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								@@\
clean.special:								@@\
	@$(MAKE) ARCH="$(ARCH).special" \				@@\
	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) imakeflags" \		@@\
	clean
#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

/*
 * 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 given dependencies during make all.
 */
#ifndef AllTarget
#define AllTarget(deps)							@@\
all:: deps
#endif

#ifndef AllSharedTarget
#ifndef HaveShared 
#define AllSharedTarget(deps)
#else
#define AllSharedTarget(deps)							@@\
all:: deps
#endif
#endif

/*
 * Add automatically generated dependencies to the Makefile.
 */
#ifndef DependTarget
#define DependTarget()							@@\
DEPDEP1 = $(wildcard $(SRC)/RCS$(SLASH)*.$(CCSUFFIX),v $(SRC)/RCS$(SLASH)*.h,v)	@@\
DEPDEP2 = $(DEPDEP1:,v=)						@@\
DEPDEP = $(subst $(SLASH)RCS$(SLASH),$(SLASH),$(DEPDEP2))		@@\
depend:: $(DEPDEP)							@@\
	$(DEPEND) -s "# DO NOT DELETE" -- $(DEPEND_CCFLAGS) -- $(SRCS)
#endif

/*
 * Add automatically generated dependencies to the Makefile (shared).
 */
#ifndef DependSharedTarget
#define DependSharedTarget()							@@\
DEPDEP1 = $(wildcard $(SRC)/RCS$(SLASH)*.$(CCSUFFIX),v $(SRC)/RCS$(SLASH)*.h,v)	@@\
DEPDEP2 = $(DEPDEP1:,v=)						@@\
DEPDEP = $(subst $(SLASH)RCS$(SLASH),$(SLASH),$(DEPDEP2))		@@\
depend:: $(DEPDEP)							@@\
	$(DEPEND) -s "# DO NOT DELETE (SHARED)" -- -SHARED $(DEPEND_CCFLAGS) -- $(SRCS)
#endif

/*
 * Remove garbage files.  The #* cannot go in the definition of RM_CMD
 * because System V will treat the pound sign as a comment.
 */
#ifndef CleanTarget
#define CleanTarget()							@@\
clean::									@@\
	@$(RM_CMD) "#"*
#endif

/*
 * Set up $(CCDEPLIBS) and $(CCLDLIBS) for a program using libIV.
 */
#ifndef Use_libInterViews
#define Use_libInterViews() 						@@\
         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 UseGcc
#define UseGcc()                                                        @@\
         CCDRIVER = cc                                                  @@\
         CCSUFFIX = c
#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

/*
 * Shorthands for making an object file.
 */
#ifndef MakeObjectFromSrcFlags
#define MakeObjectFromSrcFlags(file,flags)				@@\
MakeObjectRule(file,$(SRC)/file,flags)
#endif

#ifndef MakeObjectFromSrc
#define MakeObjectFromSrc(file)						@@\
MakeObjectFromSrcFlags(file,NullParameter)
#endif

/*
 * Shorthands for making a shared object file.
 */
#ifndef MakeSharedObjectFromSrcFlags
#ifndef HaveShared
#define MakeSharedObjectFromSrcFlags(file,flags)
#else
#define MakeSharedObjectFromSrcFlags(file,flags)				@@\
MakeSharedObjectRule(file,$(SRC)/file,flags)
#endif
#endif

#ifndef MakeSharedObjectFromSrc
#define MakeSharedObjectFromSrc(file)						@@\
MakeSharedObjectFromSrcFlags(file,NullParameter)
#endif

/*
 * Convert an archive to a random library.
 */
#ifndef RanLibrary
#if HasRanlibCmd
#define RanLibrary(args) $(RANLIB) args
#else
#define RanLibrary(args) /**/
#endif
#endif

/*
 * Make a shared library.
 */
#ifndef NormalSharedLibraryTarget
#define NormalSharedLibraryTarget(libname,rev,depobjs,ldobjs)	@@\
AOUT = Concat(lib,libname.so.rev)					@@\
SHARED_CCFLAGS = SharedCCFlags						@@\
									@@\
AllTarget(Concat(lib,libname.so.rev))					@@\
									@@\
Concat(lib,libname.so.rev): depobjs					@@\
	@echo "building $@"						@@\
	$(RM) $@~							@@\
	$(LD) -o $@~ -assert pure-text ldobjs				@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
									@@\
clean::									@@\
	$(RM) Concat(lib,libname.so.rev)
#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 either a shared library or a non-shared library.
 */
#ifndef NormalLibraryTarget
#define NormalLibraryTarget(libname,rev,depobjs,ldobjs)			@@\
NormalNonSharedLibraryTarget(libname,depobjs,ldobjs)
#endif

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


#ifndef InstallLibrary
#define InstallLibrary(libname,rev,dest)				@@\
InstallNonSharedLibrary(libname,dest)
#endif

/*
 * Removing an executable before relinking it wastes time if the user's using
 * an incremental linker smart enough to write only the modified sections.
 */
#ifndef RemoveIfUnwritable
#define RemoveIfUnwritable(program) \
-@if [ ! -w program ]; then $(RM) program; else exit 0; fi
#endif

/*
 * Build a program.
 */
#ifndef BuildProgram
#define BuildProgram(program,depobjs,ldobjs,deplibs,ldlibs)		@@\
program: depobjs deplibs						@@\
	RemoveIfUnwritable($@)						@@\
	$(CCDRIVER) $(CCLDFLAGS) -o $@ ldobjs ldlibs
#endif

/*
 * Shorthand for building and installing a complex program.
 */
#ifndef ComplexProgramTarget
#define ComplexProgramTarget(program)					@@\
PROGRAM	= program							@@\
									@@\
AllTarget($(AOUT))							@@\
BuildProgram($(AOUT),NullParameter,$(OBJS),$(CCDEPLIBS),$(CCLDLIBS))	@@\
InstallProgram($(AOUT),$(BINDIR),$(PROGRAM))				@@\
DependTarget()
#endif

/*
 * Shorthand for building and installing a simple program.
 */
#ifndef SimpleProgramTarget
#define SimpleProgramTarget(program)					@@\
SRCS	= $(SRC)/program.$(CCSUFFIX)					@@\
OBJS	= program.o							@@\
									@@\
ComplexProgramTarget(program)						@@\
MakeObjectFromSrc(program)
#endif

/*
 * Format or print troff sources.
 */
#ifndef TroffSources
#define TroffSources(formatted)						@@\
print:									@@\
	$(TROFF) $(TROFFFLAGS) $(TROFFSRCS)				@@\
									@@\
format: formatted							@@\
									@@\
formatted: $(TROFFSRCS)							@@\
	$(RM) formatted							@@\
	$(TROFF) -t $(TROFFFLAGS) $(TROFFSRCS) > formatted		@@\
									@@\
clean::									@@\
	$(RM) formatted
#endif

/*
 * Generate a script using cpp.
 */
#ifndef CppScriptTarget
#if ExecableScripts		/* can use #! instead of colon */
#define CppScriptTarget(dst,src,defs,deplist)				@@\
dst::  src deplist							@@\
	$(RM) $@							@@\
	$(CPP) defs <src | \						@@\
		sed -e '/^#  *[0-9][0-9]*  *.*$$/d' >$@			@@\
	chmod a+x $@
#else
#define CppScriptTarget(dst,src,defs,deplist)				@@\
dst::  src deplist							@@\
	$(RM) $@							@@\
	echo \: >$@							@@\
	sed '1d' src | $(CPP) defs  | \					@@\
		sed -e '/^#  *[0-9][0-9]*  *.*$$/d' >>$@		@@\
	chmod a+x $@
#endif
#endif

/*
 * Create directories if necessary at a step in the build (now
 * superseded by MakeDir in each of the individual install rules).
 */
#ifndef MakeDirectories
#define MakeDirectories(step,dirs)					@@\
step::									@@\
	$(MKDIRHIER) dirs
#endif

/*
 * Create a directory if necessary.
 */
#ifndef MakeDir
#define MakeDir(dir) -@if [ -d dir ]; then exit 0; \			@@\
		else (set -x; $(MKDIRHIER) dir); 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
#else
#define InstallProgramWithFlags(program,destdir,destname,flags)		@@\
install:: program							@@\
	MakeDir(destdir)						@@\
	$(INSTALL) -c $(INSTPGMFLAGS) flags program destdir/destname
#endif
#endif

#ifndef InstallProgram
#define InstallProgram(program,destdir,destname)			@@\
InstallProgramWithFlags(program,destdir,destname,$(INSTBINFLAGS))
#endif

#ifndef InstallSharedProgram
#ifndef HaveShared 
#define InstallSharedProgram(program,destdir,destname)
#else
#define InstallSharedProgram(program,destdir,destname)			@@\
InstallProgramWithFlags(program,destdir,destname,$(INSTBINFLAGS))
#endif
#endif

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

/*
 * Install multiple files.
 */
#ifndef InstallMultipleFlags
#define InstallMultipleFlags(list,dest,flags)				@@\
install:: list								@@\
	MakeDir(dest)							@@\
	@for i in list; do \						@@\
		(set -x; $(INSTALL) -c flags $$i dest); \		@@\
	done
#endif

#ifndef InstallMultiple
#define InstallMultiple(list,dest)					@@\
InstallMultipleFlags(list,dest,$(INSTALLFLAGS))
#endif


