# Makefile.in: -*- Text -*-  Source for configure to make a Makefile from.
#
# Author: Brian J. Fox (bfox@ai.mit.edu).
#
# This file is part of <Meta-HTML>(tm), a system for the rapid deployment
# of Internet and Intranet applications via the use of the Meta-HTML
# language.
#
#  Copyright (c) 1995, 1996, Brian J. Fox (bfox@ai.mit.edu).
#  Copyright (c) 1996, Universal Access Inc. (http://www.ua.com).
#
# Meta-HTML is free software; you can redistribute it and/or modify
# it under the terms of the UAI Free Software License as published
# by Universal Access Inc.; either version 1, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# UAI Free Software License for more details.
#
# You should have received a copy of the UAI Free Software License
# along with this program; if you have not, you may obtain one by
# writing to:
#
# Universal Access Inc.
# 129 El Paseo Court
# Santa Barbara, CA
# 93101

# The version number of this package.
PACKNAME= metahtml
PACKVER = 5.04

# Items that were filled in by configure.
VPATH	= @srcdir@
srcdir	= @srcdir@
DEFS	= -DMHTML_VERSION=$(PACKVER)
INSTALL = @INSTALL@
FIND	= @FIND@
PLATFORM= @PLATFORM@
EXE	= @EXE@
WEBBASEDIR = @WEBBASEDIR@
MODULES_DIR = @MODULES_DIR@
MHTML_SYSTEM_TYPE = @MHTML_SYSTEM_TYPE@
prefix	= @prefix@
exec_prefix = @exec_prefix@
OS_LIBS	= @OS_LIBS@
DLLDFLAGS = @DLLDFLAGS@

# The real locations of programs.
RANLIB	= @RANLIB@
AR	= ar
MKDIR	= mkdir
TAR	= tar
LN	= ln
CP	= cp
RM	= rm -f
MV	= mv
BASH_SHELL = @BASH_SHELL@
bindir	= $(exec_prefix)/bin
libdir	= $(exec_prefix)/lib
docdir	= $(WEBBASEDIR)

# You should not compile with anything other than GCC.
# Of course, you actually can compile with any fully ANSI C compiler,
# and this could be an advantage, like, say, for example, you have to
# compile this code at UCSB, and the FUCKING LOSING MORON who
# installed GCC didn't do it right.
#
CC		= gcc $(GCC_WARN)
# GCC_WARN	= -Wall -Wstrict-prototypes -Wshadow
# PROFILE_FLAGS	= -pg
# DEBUG_FLAGS	= -g $(PROFILE_FLAGS)
OPTIMIZE_FLAGS	= -O69 -finline-functions
INCLUDE_FLAGS	= @EXTRAINC@
CFLAGS		= $(OPTIMIZE_FLAGS) $(DEBUG_FLAGS) $(INCLUDE_FLAGS)
LDFLAGS		= $(STATIC) $(DEBUG_FLAGS) $(DLLDFLAGS)

PROGDEFS	= AR='$(AR)' RANLIB='$(RANLIB)' LN='$(LN)' CP='$(CP)' \
		  RM='$(RM)' CC='$(CC)'

OTHERDEFS	= TOPDIR=$(srcdir) MHTML_VERSION=$(PACKVER) EXE=$(EXE)

PCFLAGS		= $(PROGDEFS) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' \
		  DEBUG_FLAGS='$(DEBUG_FLAGS)' $(OTHERDEFS) \
		  PROFILE_FLAGS='$(PROFILE_FLAGS)' \
		  OPTIMIZE_FLAGS='$(OPTIMIZE_FLAGS)'

LIBUTILS	= libutils/libutils.a
LIBMHTML	= libmhtml/libmhtml.a
LIBSERVER	= libserver/libserver.a

SUBDIRS		= libutils libmhtml libserver engine mhc server mdb \
		  doc sessions dbutils utilities $(MODULES_DIR)

SUBDIR_TARGETS  = engine mhc server mdb doc sessions dbutils utilities \
		  $(MODULES_DIR)

TARGETS		= $(LIBUTILS) $(LIBMHTML) $(LIBSERVER) engine mhc \
		  server mdb doc sessions dbutils utilities \
		  $(MODULES_DIR) build-download

ALLMAKEFILES = Makefile mhc/Makefile server/Makefile engine/Makefile \
	       mdb/Makefile mdb/readline/Makefile sessions/Makefile \
	       dbutils/Makefile libmhtml/Makefile libutils/Makefile \
	       libutils/compat/Makefile libserver/Makefile utilities/Makefile

all:	$(TARGETS)

debug: FORCE
	$(MAKE) OPTIMIZE_FLAGS= DEBUG_FLAGS=-g

purify: FORCE
	$(MAKE) CC='purify $(CC)' OPTIMIZE_FLAGS= DEBUG_FLAGS=-g

$(TARGETS): $(ALLMAKEFILES)

$(LIBUTILS): FORCE
	(cd libutils; $(MAKE) $(PCFLAGS))

$(LIBMHTML): FORCE
	(cd libmhtml; $(MAKE) $(PCFLAGS))

$(LIBSERVER): FORCE
	(cd libserver; $(MAKE) $(PCFLAGS))

$(SUBDIR_TARGETS): $(LIBUTILS) $(LIBMHTML)

$(SUBDIR_TARGETS): FORCE
	(cd $@; $(MAKE) $(PCFLAGS))

doc: dbutils

static: clean-executables build-download
	$(MAKE) clean-executables
	$(MAKE) STATIC=--static

build-download: build-download.in Makefile
	cat build-download.in | \
	sed -e 's%@VERSION@%$(PACKVER)%' \
	    -e 's%@BUILD_PLATFORM@%$(PLATFORM)%' \
	    -e 's%@BASH@%$(BASH_SHELL)%' >build-download
	chmod a+x build-download

clean-executables: FORCE
	for dir in mhc server engine mdb sessions ; do \
	   (cd $$dir; $(MAKE) clean-executables); \
	done

install: $(TARGETS) install_force

install_force: FORCE
	if [ ! -d $(bindir) ]; then mkdir $(bindir); fi
	(cd mhc; $(MAKE) install bindir=$(bindir))
	(cd engine; $(MAKE) install bindir=$(bindir))
	(cd server; $(MAKE) install bindir=$(bindir))
	(cd mdb; $(MAKE) install bindir=$(bindir))
	(cd sessions; $(MAKE) install bindir=$(bindir))
	(cd dbutils; $(MAKE) install bindir=$(bindir))
	(cd utilities; $(MAKE) install bindir=$(bindir))
	if [ "$(MODULES_DIR)" ]; then \
	  (cd $(MODULES_DIR); $(MAKE) install libdir=$(libdir)); \
	fi
	@echo "To install the server or the engine, type \`./install-site'"

install-docs:
	(cd doc; $(MAKE) install WEBBASEDIR=$(WEBBASEDIR))

tagsets: tagsets/default.lib
	(cd tagsets; $(MAKE) )

clean:  FORCE
	for dir in $(SUBDIRS); do \
	  (cd $$dir; $(MAKE) $@ ); \
	done

distclean realclean: clean
	for dir in $(SUBDIRS); do \
	  (cd $$dir; $(MAKE) $@ ); \
	done
	(cd tagsets; $(MAKE) $@ )
	(cd applications; $(MAKE) $@ )
	$(RM) -rf downloads =* build-download
	$(FIND) . -name "*~" -exec $(RM) \{\} \;
	$(FIND) . -name "*.gz" -exec $(RM) \{\} \;
	$(FIND) . -name "foo\.*" -exec $(RM) \{\} \;
	$(FIND) . -name "bar\.*" -exec $(RM) \{\} \;
	$(FIND) . -name "baz\.*" -exec $(RM) \{\} \;
	$(FIND) . -name "core" -exec $(RM) \{\} \;
	$(FIND) . -name "core.*" -exec $(RM) \{\} \;
	$(FIND) . -name "*.core*" -exec $(RM) \{\} \;
	$(FIND) ./release -name "*.db" -exec $(RM) \{\} \;
	$(FIND) . -name "*DISTFILES" -exec $(RM) \{\} \;
	$(RM) -f config.cache config.status config.h *.log Makefile TAGS

tags TAGS: FORCE
	etags --defines --typedefs --output TAGS */*.c */*/*.c

Makefile: Makefile.in config.status
	./config.status

mhc/Makefile: mhc/Makefile.in config.status
	./config.status

utilities/Makefile: utilities/Makefile.in config.status
	./config.status

utilities/imagemap/Makefile: utilities/imagemap/Makefile.in config.status
	./config.status

dbutils/Makefile: dbutils/Makefile.in config.status
	./config.status

sessions/Makefile: sessions/Makefile.in config.status
	./config.status

libutils/Makefile: libutils/Makefile.in config.status
	./config.status

libmthml/Makefile: libmhtml/Makefile.in config.status
	./config.status

libserver/Makefile: libserver/Makefile.in config.status
	./config.status

server/Makefile: server/Makefile.in config.status
	./config.status

engine/Makefile: engine/Makefile.in config.status
	./config.status

mdb/Makefile: mdb/Makefile.in config.status
	./config.status

mdb/readline/Makefile: mdb/readline/Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

DISTNAME = $(PACKNAME)-$(PACKVER)

dist: DISTFILES
	(cd doc; $(MAKE) dist)
	$(RM) -rf $(DISTNAME)
	$(MKDIR) $(DISTNAME)
	for d in `find . -type d -print`; do \
	  if [ "$$d" != "./$(DISTNAME)" -a "$$d" != "." ]; then \
	    echo "Making directory $(DISTNAME)/$$d"; \
	    mkdir $(DISTNAME)/$$d; \
	  fi; \
	done
	for f in `cat DISTFILES`; do \
	   $(LN) $(srcdir)/$$f $(DISTNAME)/$$f || \
		{ echo copying $$f; cp -rp $(srcdir)/$$f $(DISTNAME)/$$f ; } \
	done
	-(cd $(DISTNAME); $(MAKE) distclean)
	$(TAR) chvf - $(DISTNAME) | gzip >$(DISTNAME).tar.gz
	$(RM) -rf $(DISTNAME)

# Gets rid of most of the unwanted files.  Verify manually (if necessary)
# that this produces a list of all the files desired in the distribution. 
DISTFILES: FORCE
	$(RM) -rf $(DISTNAME)
	(cd $(srcdir); find . ! -type d -print) \
	| sed  '/\/RCS\//d; \
	        /\blackjack\//d; \
		/\/EMACS-BACKUPS\//d; \
		/\/downloads\//d; \
		/\.tar.*/d; \
		/\#*#$$/d; \
		/~$$/d; /\.o$$/d; /\/.*\.a$$/d; \
		/\/\.gdb_history$$/d; \
		/\/\.mdb_init$$/d; \
		/\/.*\.BAK$$/d; \
		/\/TAGS$$/d; \
		/\/core$$/d; /\/[a-z]*\.core$$/d; /\/core\.[a-z]*$$/d; \
		/\/a.out$$/d; \
		/\/=/d; \
		/\/conftest\.c$$/d; \
		/\/DISTFILES$$/d; \
		/\.toc$$/d; \
		/\.aux$$/d; /\.log$$/d; \
		/\.cps$$/d; /\.cp$$/d; \
		/\.fns$$/d; /\.fn$$/d; \
		/\.tps$$/d; /\.tp$$/d; \
		/\.vrs$$/d; /\.vr$$/d; \
		/\.pgs$$/d; /\.pg$$/d; \
		/\.kys$$/d; /\.ky$$/d; \
		s/^.\///; /^\.$$/d;' \
	| sort | uniq > DISTFILES

FORCE:

