/* ********************************************************************** *\
 *         Copyright IBM Corporation 1988,1989 - All Rights Reserved      *
 *        For full copyright information see:'andrew/config/COPYRITE'     *
\* ********************************************************************** */
#define	IHaveSubdirs

#ifdef	AMS_ENV
AMS = ams atkams
#endif /* AMS_ENV */

#ifdef X11_ENV
MKFONTDIR = xmkfontd
#endif /* X11_ENV */

#ifdef CONTRIB_ENV
CONTRIB = contrib
#endif CONTRIB_ENV

#ifdef ODA_ENV
ODA = oda odatrans
#endif /* ODA_ENV */

#ifdef MK_HELP
HELP = helpindex helpaliases
#endif /* MK_HELP */

DIRS = $(DESTDIR)  \
	$(DESTDIR)/bin \
	$(DESTDIR)/config \
	$(DESTDIR)/etc \
	$(DESTDIR)/include \
	$(DESTDIR)/lib \
	$(DESTDIR)/doc \
	$(DESTDIR)/doc/atk \
	$(DESTDIR)/doc/ams \
	$(DESTDIR)/help \
	$(DESTDIR)/man \
	$(DESTDIR)/dlib \
	$(DESTDIR)/examples

SUBDIRS = overhead atk $(AMS) $(CONTRIB) $(ODA) $(MKFONTDIR) $(HELP)

depend::
	@echo 'Checking that BASEDIR is not the location of the source files.'
	@sh -c '(if [ "$(BASEDIR)" = "`pwd`" ]; then \
		echo "%% BASEDIR must be different from the location of the source files."; \
		echo "%% Currently, they are both $(BASEDIR) ."; \
		echo "%% This must be fixed before proceeding with installation."; \
		echo "%% (You may wish to move the source files to $(BASEDIR)/src .)"; \
		exit 1; \
	fi; exit 0)'


World::
	date
	make Makefiles
	make dependInstall

World::
	date


MkdirTarget($(DIRS))

#ifdef	WM_ENV
MkdirTarget($(DESTDIR)/fonts)
#endif

#ifdef	X11_ENV
MkdirTarget($(DESTDIR)/X11fonts)
#endif

#ifdef LINKINSTALL_ENV
install.time::
	${RM} ${DESTDIR}/bin/linkinst
	$(LN) `pwd`/config/linkinst $(DESTDIR)/bin/linkinst
#else /* LINKINSTALL_ENV */
#ifdef BUILDANDREWINSTALL_ENV
install.time:: installation

installation:
	make Makefiles SUBDIRS=install
	(cd install; make dependInstall)
#endif /* BUILDANDREWINSTALL_ENV */
#endif /* LINKINSTALL_ENV */


InstallFileToFile(config/ImakeMacros.d, $(INSTINCFLAGS), $(DESTDIR)/doc/ImakeMacros.d)
InstallFileToFile(config/andyenv.h,${INSTINCFLAGS},${DESTDIR}/include/andyenv.h)
InstallFileToFile(config/${SYSTEM_H_FILE},${INSTINCFLAGS},${DESTDIR}/include/system.h)
InstallFileToFile(config/andrewos.h,${INSTINCFLAGS},${DESTDIR}/include/andrewos.h)
InstallFileToFile(config/allsys.h,${INSTINCFLAGS},${DESTDIR}/include/allsys.h)
InstallFileToFile(config/site.h,${INSTINCFLAGS},${DESTDIR}/include/site.h)

install.time:: imake.tmp system.tmp
	@echo -n ''

imake.tmp: config/imake.tmpl
	@$(SED) -e 's;<.*/system\.mcr>;<system.mcr>;g' \
	-e 's;#define.*MacroIncludeFile.*;#define MacroIncludeFile system.mcr;g' \
	config/imake.tmpl > imake.tmp

system.tmp: config/MacroIncludeFile
	@$(SED) -e 's;<.*/system\.h>;<system.h>;g' \
	-e 's;SYSTEM_H_FILE =.*;SYSTEM_H_FILE = system.h;g' \
	config/MacroIncludeFile > system.tmp



install.time:: 
	(cd $(DESTDIR)/config; \
	${RM} andrewos.h andyenv.h system.h allsys.h site.h; \
	$(LN) ../include/andrewos.h andrewos.h; \
	$(LN) ../include/andyenv.h andyenv.h; \
	$(LN) ../include/system.h system.h; \
	$(LN) ../include/allsys.h allsys.h; \
	$(LN) ../include/site.h site.h; )

InstallFileToFile(imake.tmp, $(INSTINCFLAGS), $(DESTDIR)/config/imake.tmpl)
InstallFileToFile(system.tmp, $(INSTINCFLAGS), $(DESTDIR)/config/system.mcr)
InstallFileToFile(config/allsys.mcr, $(INSTINCFLAGS), $(DESTDIR)/config/allsys.mcr)
InstallFileToFile(config/site.mcr, $(INSTINCFLAGS), $(DESTDIR)/config/site.mcr)
InstallFileToFile(config/andrew.rls, $(INSTINCFLAGS), $(DESTDIR)/config/andrew.rls)
InstallFileToFile(config/depend.csh, $(INSTPROGFLAGS), $(DESTDIR)/config/depend.csh)
InstallFileToFile(config/loginstall, $(INSTPROGFLAGS), $(DESTDIR)/config/loginstall)
InstallFileToFile(config/COPYRITE, $(INSTINCFLAGS), $(DESTDIR)/config/COPYRITE)



