# Makefile for GNU CVS program.
# Do not use this makefile directly, but only from `../Makefile'.
# Copyright (C) 1986, 1988-1990 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, 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
# GNU General Public License for more details.

SHELL = /bin/sh

srcdir     = @srcdir@
top_srcdir = @top_srcdir@
VPATH      = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@

# Where to install the executables.
bindir = $(exec_prefix)/bin

# Where to put the system-wide .cvsrc file
libdir = $(prefix)/lib

# Where to put the manual pages.
mandir = $(prefix)/man

# Use cp if you don't have install.
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@

LIBS = @LIBS@

SOURCES = add.c admin.c buffer.c checkin.c checkout.c classify.c client.c \
commit.c create_adm.c cvsrc.c diff.c edit.c entries.c error.c expand_path.c \
fileattr.c find_names.c hardlink.c hash.c history.c ignore.c import.c \
lock.c log.c login.c logmsg.c main.c mkmodules.c modules.c myndbm.c no_diff.c \
parseinfo.c patch.c patchkit.c rcs.c rcscmds.c recurse.c release.c remove.c repos.c \
root.c rtag.c scramble.c server.c status.c subr.c filesubr.c run.c \
tag.c update.c watch.c wrapper.c vers_ts.c version.c zlib.c

OBJECTS = add.o admin.o buffer.o checkin.o checkout.o classify.o client.o \
commit.o create_adm.o cvsrc.o diff.o edit.o entries.o expand_path.o \
fileattr.o find_names.o hardlink.o hash.o history.o ignore.o import.o \
lock.o log.o login.o logmsg.o main.o mkmodules.o modules.o myndbm.o no_diff.o \
parseinfo.o patch.o patchkit.o rcs.o rcscmds.o recurse.o release.o remove.o repos.o \
root.o rtag.o scramble.o server.o status.o tag.o update.o \
watch.o wrapper.o vers_ts.o \
subr.o filesubr.o run.o version.o error.o zlib.o

HEADERS = buffer.h cvs.h rcs.h hardlink.h hash.h myndbm.h \
	update.h server.h client.h error.h fileattr.h edit.h watch.h

TAGFILES = $(HEADERS) options.h.in $(SOURCES)

DISTFILES = .cvsignore Makefile.in \
	    ChangeLog ChangeLog-97 ChangeLog-96 ChangeLog-9395 ChangeLog-9194 \
            sanity.sh cvsbug.sh $(TAGFILES) build_src.com

PROGS = cvs cvsbug

DEFS = @DEFS@ @includeopt@

CC	 = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS =
LDFLAGS = @LDFLAGS@

INCLUDES = -I. -I.. -I../lib -I$(srcdir) -I$(top_srcdir)/lib
.c.o:
	$(CC) $(CPPFLAGS) $(INCLUDES) $(DEFS) $(CFLAGS) -c $<

all: Makefile $(PROGS)
.PHONY: all

saber_cvs:
	@cd ..; $(MAKE) saber SUBDIRS=src

lint:
	@cd ..; $(MAKE) lint SUBDIRS=src

install: installdirs
	@for prog in $(PROGS); do \
	  echo Installing $$prog in $(bindir); \
	  $(INSTALL) $$prog $(bindir)/$$prog ; \
	done

installdirs:
	$(SHELL) $(top_srcdir)/mkinstalldirs $(bindir)

.PHONY: install installdirs

installcheck:
	$(SHELL) $(srcdir)/sanity.sh $(bindir)/cvs
.PHONY: installcheck

check: all
	$(SHELL) $(srcdir)/sanity.sh `pwd`/cvs
.PHONY: check

# I'm not sure there is any remaining reason for this to be separate from
# `make check'.
remotecheck: all
	$(SHELL) $(srcdir)/sanity.sh -r `pwd`/cvs
.PHONY: remotecheck

tags: $(TAGFILES)
	ctags $(TAGFILES)

TAGS: $(TAGFILES)
	etags `for i in $(TAGFILES); do echo $(srcdir)/$$i; done`

ls:
	@echo $(DISTFILES)
.PHONY: ls

clean:
	rm -f $(PROGS) *.o core check.log check.plog
.PHONY: clean

distclean: clean
	rm -f tags TAGS Makefile options.h
.PHONY: distclean

realclean: distclean
.PHONY: realclean

dist-dir:
	mkdir ${DISTDIR}
	for i in ${DISTFILES}; do \
	  ln $(srcdir)/$${i} ${DISTDIR}; \
	done
.PHONY: dist-dir

# Linking rules.

$(PROGS): ../lib/libcvs.a ../zlib/libz.a ../diff/libdiff.a

cvs: $(OBJECTS)
	$(CC) $(OBJECTS) ../lib/libcvs.a ../zlib/libz.a ../diff/libdiff.a $(LIBS) $(LDFLAGS) -o $@ 

xlint: $(SOURCES)
	files= ; \
	for i in $(SOURCES) ; do \
	  files="$$files $(srcdir)/$$i" ; \
	done ; \
	sh -c "lint $(DEFS) $(INCLUDES) $$files | grep -v \"possible pointer alignment problem\" \
	| grep -v \"argument closure unused\""

saber: $(SOURCES)
	# load $(CFLAGS) $(SOURCES)
	# load ../lib/libcvs.a $(LIBS)

cvsbug: cvsbug.sh $(srcdir)/version.c
	echo > .fname \
	  cvs-`sed < $(srcdir)/version.c \
		    -e '/version_string/!d' \
		    -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
		    -e q`
	sed -e 's,xLIBDIRx,$(libdir)/cvs,g' \
	    -e "s,xVERSIONx,`cat .fname`,g" $(srcdir)/$@.sh > $@-t
	rm -f .fname
	mv $@-t $@
	chmod a+x $@

# Compilation rules.

$(OBJECTS): $(HEADERS) options.h

rcscmds.o: rcscmds.c $(top_srcdir)/diff/diffrun.h
	$(CC) $(CPPFLAGS) $(INCLUDES) -I$(top_srcdir)/diff $(DEFS) $(CFLAGS) -c $(srcdir)/rcscmds.c

zlib.o: zlib.c $(top_srcdir)/zlib/zlib.h
	$(CC) $(CPPFLAGS) $(INCLUDES) -I$(top_srcdir)/zlib $(DEFS) $(CFLAGS) -c $(srcdir)/zlib.c

subdir = src
Makefile: ../config.status Makefile.in
	cd .. && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status

options.h: ../config.status options.h.in
	cd .. && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status

#../config.status: ../configure
#	cd .. ; $(SHELL) config.status --recheck

#../configure: ../configure.in
#	cd $(top_srcdir) ; autoconf
