# Make.rules			-*- Makefile -*-
#
# Common rules for building stuff. All of the Makefiles include this
# file.
#
# $Id: Make.rules.in,v 1.22 2002/12/10 11:52:27 azummo Exp $

# Note: there aren't many portable Makefile constructs. In particular,
# various versions of 'make' don't recognize one or more of
#	VAR += VALUE
#	VAR ?= DEFAULT_VALUE
#	VAR != command
# so don't use these.

# The basics
PACKAGE =	@PACKAGE@
VERSION =	@VERSION@

# Various directories gleaned from `configure'
PREFIX =	@prefix@
# Grrr... Freakin' capitalization!
prefix =	${PREFIX}
PERL_PREFIX =	@PERL_PREFIX@
# GNU 'configure'-ism
exec_prefix =	@exec_prefix@
BINDIR =	@bindir@
SBINDIR =	@sbindir@
LIBEXECDIR =	@libexecdir@
CONDUITDIR =	@CONDUITDIR@
DATADIR =	@datadir@
LOCALEDIR =	${DATADIR}/locale
SYSCONFDIR =	@sysconfdir@
LIBDIR =	@libdir@
INCLUDEDIR =	@includedir@
INFODIR =	@infodir@
MANDIR =	@mandir@
MAN1DIR =	${MANDIR}/man1
MAN3DIR =	${MANDIR}/man3
MAN8DIR =	${MANDIR}/man8

# Subdirectory containing the Perl modules. Used by "configure --without-perl"
PERLDIR =	@PERLDIR@

# Compilation-related programs and flags
CC =		@CC@
CXX =		@CXX@
DEFINES =	@DEFS@
INCLUDES =	${INCLUDE} -I. -I${TOP} -I${TOP}/include
CXX_INCLUDEDIRS = \
		-I/usr/include/c++ -I/usr/include/g++ \
		-I${INCLUDEDIR}
CPPFLAGS =	${DEFINES} ${INCLUDES} @CPPFLAGS@
CFLAGS =	@CFLAGS@ ${CPPFLAGS}
CXXFLAGS =	@CXXFLAGS@ ${CPPFLAGS}
LEX =		@LEX@
LEXARGS =	@LEXARGS@
LIBLEX =	@LEXLIB@
YACC =		@YACC@
YACCARGS =	@YACCARGS@ -d
LIBYACC =	@LIBYACC@
LIBS =		@LIBS@ ${EXTRA_LIBS}
LDFLAGS =	@LDFLAGS@ ${LIBS}
LINT =		@LINT@
LINTARGS =	@LINTARGS@ ${CPPFLAGS}
RANLIB =	@RANLIB@

# Other programs and utilities
PERL =		@PERL@
# The name "POD2MAN_EXE" is because Perl uses "POD2MAN" for the actual
# rule that creates man pages from pods.
POD2MAN_EXE =	$(PERLRUN) "-MExtUtils::Command::MM" -e pod2man --
SED =		@SED@
TAR =		@TAR@
GZIP =		@GZIP@
DATE =		@DATE@
MKDEP =		@MKDEP@
MAKEINFO =	@MAKEINFO@
TEXI2DVI =	@TEXI2DVI@
TEXI2HTML =	@TEXI2HTML@
DVIPS =		@DVIPS@
MKID =		@MKID@
MKDIR =		${TOP}/mkinstalldirs

# I18n-related utilities
XGETTEXT =	@XGETTEXT@
GETTEXT =	@GETTEXT@
MSGMERGE =	@MSGMERGE@
MSGFMT =	@MSGFMT@
EXTRA_MSGFMT_ARGS =	@EXTRA_MSGFMT_ARGS@
INSTALL_I18N =	@INSTALL_I18N@

TOPDISTDIR =	${TOP}/${PACKAGE}-${VERSION}
DISTDIR =	${TOPDISTDIR}/${SUBDIR}
TARBALL =	${TOPDISTDIR}.tar.gz

INSTALL =	@INSTALL@
INSTALL_PROGRAM =	@INSTALL_PROGRAM@ -m 555
INSTALL_SCRIPT =	@INSTALL_SCRIPT@
INSTALL_DATA =		@INSTALL_DATA@
INSTALL_MAN =		${INSTALL_DATA}

# End of 'configure'-generated stuff.

.SUFFIXES:	.c .o .cc .ln
.SUFFIXES:	.a
.SUFFIXES:	.So .so

.c.o:
	${CC} ${CFLAGS} -c $<

# XXX - Shared library object. This is only known to work under
# FreeBSD 4.2 for now.
.c.So:
	${CC} -fpic -DPIC ${CFLAGS} -c $< -o $@
	${LD} -o $@.tmp -x -r $@
	mv $@.tmp $@

.cc.o:
	${CXX} ${CXXFLAGS} -c $<

.c.ln:
	${LINT} ${LINTARGS} -i $<

# Documentation-related rules
.SUFFIXES:	.dvi .info .ps .texi .html

.texi.info:
	${MAKEINFO} $<

.texi.dvi:
	${TEXI2DVI} $<

.dvi.ps:
	${DVIPS} -o $@ $<

# I18n-related rules
.SUFFIXES:	.po .mo

.po.mo:
	${MSGFMT} -v ${EXTRA_MSGFMT_ARGS} -o $@ $<

LIBRARY =	lib${LIBNAME}.a
SHLIB =		lib${LIBNAME}.so
SHLIBVER =	lib${LIBNAME}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}

# List of recursive targets, i.e., those where you build the target in
# each subdirectory.
RECURSIVE_TARGETS = \
		all depend clean distclean spotless distfiles-core distfiles \
		install lint TAGS

# This empty rule is so that `make' (build the first target) and `make
# all' will do the same thing. `all' is actually built according to
# the ${RECURSIVE_TARGETS} rule.
all::

# XXX - Should add "-R ${LIBDIR}" or "-rpath ${LIBDIR}" or "-Wl,-rpath
# ${LIBDIR}", whichever one the linker supports.
${PROG}:	${OBJS}
	${CC} ${CFLAGS} ${OBJS} -o $@ ${LDFLAGS}

${CXXPROG}:	${OBJS}
	${CXX} ${CXXFLAGS} ${OBJS} -o $@ ${LDFLAGS}

${LIBRARY}:	${LIBOBJS}
	ar cr $@ ${LIBOBJS}
	${RANLIB} $@

# XXX - Build a shared library from .So object files. This is only
# known to work under FreeBSD 4.2 for now.
${SHLIB} ${SHLIBVER}:	${SHLIBOBJS}
	-rm -f ${SHLIBVER} ${SHLIB}
	-ln -f -s ${SHLIBVER} ${SHLIB}
	${CC} -shared -Wl,-x -o ${SHLIBVER} -Wl,-soname,${SHLIBVER} \
		`lorder ${SHLIBOBJS} | tsort -q`

# lex.yy.o:	lex.yy.c
# 	${CC} ${CFLAGS} -c $<

lex.yy.c:	lexer.l y.tab.h
	${LEX} ${LEXARGS} lexer.l

# y.tab.o:	y.tab.c
# 	${CC} ${CFLAGS} -c $<

y.tab.c y.tab.h:	parser.y
	${YACC} ${YACCARGS} parser.y

# XXX - Ought to come up with a rule that'll do the Right Thing in all
# cases, whether you have C source, C++ source, or a mixture of both.
# depend::
# 	${MKDEP} ${CPPFLAGS} ${C_SRCS} ${CXX_INCLUDEDIRS} ${CXX_SRCS}

# Targets for building the distribution.
# See the comment by ${RECURSIVE_TARGETS}::.
distfiles-core::	${DISTFILES}
	@subdirs="${SUBDIRS}"; \
	for dir in "${subdirs}"; do \
		if test ! -d "${TOPDISTDIR}/${SUBDIR}/$$dir"; then \
			echo "mkdir ${TOPDISTDIR}/${SUBDIR}/$$dir"; \
			${MKDIR} "${TOPDISTDIR}/${SUBDIR}/$$dir"; \
		fi; \
	done
	@if test -n "${DISTFILES}"; then \
		echo "cp -p ${DISTFILES} ${TOPDISTDIR}/${SUBDIR}"; \
		cp -p ${DISTFILES} ${TOPDISTDIR}/${SUBDIR}; \
	fi

distfiles::	distfiles-core ${EXTRA_DISTFILES}
	@if test -n "${EXTRA_DISTFILES}"; then \
		echo "cp -p ${EXTRA_DISTFILES} ${TOPDISTDIR}/${SUBDIR}"; \
		cp -p ${EXTRA_DISTFILES} ${TOPDISTDIR}/${SUBDIR}; \
	fi

TAGS::
	files="${SRCS} ${HEADERS} ${OTHERTAGFILES}"; \
	for f in $$files; do \
		etags -a -o ${TOP}/TAGS $$f; \
	done

# Common rule for building recursive targets
# The completely redundant subdirs="${SUBDIRS}" assignment is there
# because Sun's 'sh' can't parse
#	for i in ; do echo $i; done
# It complains about a syntax error.
${RECURSIVE_TARGETS}::
	@subdirs="${SUBDIRS}"; \
	for dir in $$subdirs; do \
		echo "$@: Entering directory \`${SUBDIR}/$$dir'"; \
		(cd $$dir && \
		 ${MAKE} SUBDIR="${SUBDIR}/$$dir" TOP=${TOP}/.. \
		 	PREFIX="${PREFIX}" prefix="${prefix}" $@); \
		echo "$@: Leaving directory \`${SUBDIR}/$$dir'"; \
	done

# Targets for various progressive levels of cleanliness. Each one is
# cleaner than the previous. These need to go after the
# ${RECURSIVE_TARGETS} rule, because we want to clean up the lower
# directories before cleaning up the higher ones.
#
# clean:	Delete all the files added by the compilation process
#		(*.o, core, etc.)
# distclean:	Delete anything that wasn't part of the distribution
#		(clean + anything created by `configure')
# spotless:	Delete anything that can't be recreated (distclean +
#		`configure' itself, .ps files generated for the distribution
#		as a courtesy, etc.)

clean-here:
	-rm -f ${CLEAN}
clean::		clean-here

distclean-here:
	-rm -f ${CLEAN} ${DISTCLEAN}
distclean::	distclean-here

spotless-here:
	-rm -f ${CLEAN} ${DISTCLEAN} ${SPOTLESS}
spotless::	spotless-here 
