#
# $Id: Makefile,v 1.5 1999/07/15 22:59:00 tanchs1 Exp $
#
# Copyright (C) 1998  Andreas Huber <ahuber@ping.at>
#
# 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
# of the License, 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

SHELL = sh

DIST_TAG = CVS_1_10

# Directory in which to install cvs.
export install_dir = e:/cvs

# srcdir is usually ".".
# Use $(shell pwd) if you need absolute paths for debugging.
srcdir := .

# top_srcdir is usually "..".
# Use $(shell (cd ..; pwd)) if you need absolute paths for debugging.
top_srcdir := ..

lib_dir = $(top_srcdir)/lib
cvs_srcdir = $(top_srcdir)/src
diff_srcdir = $(top_srcdir)/diff
zlib_dir = $(top_srcdir)/zlib

CC = gcc
INCLUDES = -I$(srcdir) -I$(lib_dir) -I$(cvs_srcdir) -I$(zlib_dir) -I$(diff_srcdir)
DEFINES = -DUNIX -DHAVE_CONFIG_H -DFSEEK_BUG
CPPFLAGS = $(INCLUDES) $(DEFINES)
DEBUGFLAGS =
CFLAGS = -O2 -pedantic -Wall -fno-builtin $(CPPFLAGS) $(DEBUGFLAGS)
LDFLAGS = -Zcrtdll $(DEBUGFLAGS)
LIBS = -lsocket -lufc

OS2_SOURCES = \
	$(srcdir)/filesubr.c \
	$(srcdir)/fnsubr.c \
	$(srcdir)/startserver.c \
	$(srcdir)/stripslash.c \
	$(top_srcdir)/windows-NT/rcmd.c \
	$(srcdir)/system.c \
	$(srcdir)/emxbugs.c \
	$(srcdir)/run.c
OS2_OBJECTS = $(OS2_SOURCES:%.c=%.o)
OS2_HEADERS = \
	$(srcdir)/config.h \
	$(srcdir)/config2.h \
	$(srcdir)/options.h \
	$(srcdir)/rcmd.h

COMMON_SOURCES = \
	$(cvs_srcdir)/add.c \
	$(cvs_srcdir)/admin.c \
	$(cvs_srcdir)/buffer.c \
	$(cvs_srcdir)/checkin.c \
	$(cvs_srcdir)/checkout.c \
	$(cvs_srcdir)/classify.c \
	$(cvs_srcdir)/client.c \
	$(cvs_srcdir)/commit.c \
	$(cvs_srcdir)/create_adm.c \
	$(cvs_srcdir)/cvsrc.c \
	$(cvs_srcdir)/diff.c \
	$(cvs_srcdir)/edit.c \
	$(cvs_srcdir)/entries.c \
	$(cvs_srcdir)/expand_path.c \
	$(cvs_srcdir)/fileattr.c \
	$(cvs_srcdir)/find_names.c \
	$(cvs_srcdir)/hash.c \
	$(cvs_srcdir)/history.c \
	$(cvs_srcdir)/ignore.c \
	$(cvs_srcdir)/import.c \
	$(cvs_srcdir)/lock.c \
	$(cvs_srcdir)/log.c \
	$(cvs_srcdir)/login.c \
	$(cvs_srcdir)/logmsg.c \
	$(cvs_srcdir)/main.c \
	$(cvs_srcdir)/mkmodules.c \
	$(cvs_srcdir)/modules.c \
	$(cvs_srcdir)/myndbm.c \
	$(cvs_srcdir)/no_diff.c \
	$(cvs_srcdir)/parseinfo.c \
	$(cvs_srcdir)/patch.c \
	$(cvs_srcdir)/rcs.c \
	$(cvs_srcdir)/rcscmds.c \
	$(cvs_srcdir)/recurse.c \
	$(cvs_srcdir)/release.c \
	$(cvs_srcdir)/remove.c \
	$(cvs_srcdir)/repos.c \
	$(cvs_srcdir)/root.c \
	$(cvs_srcdir)/rtag.c \
	$(cvs_srcdir)/scramble.c \
	$(cvs_srcdir)/server.c \
	$(cvs_srcdir)/status.c \
	$(cvs_srcdir)/tag.c \
	$(cvs_srcdir)/update.c \
	$(cvs_srcdir)/watch.c \
	$(cvs_srcdir)/wrapper.c \
	$(cvs_srcdir)/vers_ts.c \
	$(cvs_srcdir)/subr.c \
	$(cvs_srcdir)/version.c \
	$(cvs_srcdir)/error.c \
	$(cvs_srcdir)/zlib.c
COMMON_OBJECTS = $(COMMON_SOURCES:%.c=%.o)
COMMON_HEADERS = \
	$(cvs_srcdir)/buffer.h \
	$(cvs_srcdir)/client.h \
	$(cvs_srcdir)/cvs.h \
	$(cvs_srcdir)/edit.h \
	$(cvs_srcdir)/error.h \
	$(cvs_srcdir)/fileattr.h \
	$(cvs_srcdir)/hardlink.h \
	$(cvs_srcdir)/hash.h \
	$(cvs_srcdir)/myndbm.h \
	$(cvs_srcdir)/rcs.h \
	$(cvs_srcdir)/server.h \
	$(cvs_srcdir)/update.h \
	$(cvs_srcdir)/watch.h

DIFF_SOURCES = \
	$(diff_srcdir)/analyze.c \
	$(diff_srcdir)/cmpbuf.c \
	$(diff_srcdir)/context.c \
	$(diff_srcdir)/diff.c \
	$(diff_srcdir)/diff3.c \
	$(diff_srcdir)/dir.c \
	$(diff_srcdir)/ed.c \
	$(diff_srcdir)/ifdef.c \
	$(diff_srcdir)/io.c \
	$(diff_srcdir)/normal.c \
	$(diff_srcdir)/side.c \
	$(diff_srcdir)/util.c \
	$(diff_srcdir)/version.c 
DIFF_OBJECTS = $(DIFF_SOURCES:%.c=%.o)
DIFF_HEADERS = \
	$(diff_srcdir)/cmpbuf.h \
	$(diff_srcdir)/diff.h \
	$(diff_srcdir)/diffrun.h \
	$(diff_srcdir)/system.h

# vasprintf was removed 
#LIB_SOURCES = \
#	$(lib_dir)/vasprintf.c \
#	$(lib_dir)/argmatch.c \
#	$(lib_dir)/getline.c \
#	$(lib_dir)/getopt.c \
#	$(lib_dir)/getopt1.c \
#	$(lib_dir)/md5.c \
#	$(lib_dir)/regex.c \
#	$(lib_dir)/sighandle.c \
#	$(lib_dir)/valloc.c \
#	$(lib_dir)/yesno.c \
#	$(lib_dir)/getdate.c \
#	$(lib_dir)/savecwd.c

LIB_SOURCES = \
	$(lib_dir)/argmatch.c \
	$(lib_dir)/getline.c \
	$(lib_dir)/getopt.c \
	$(lib_dir)/getopt1.c \
	$(lib_dir)/md5.c \
	$(lib_dir)/regex.c \
	$(lib_dir)/sighandle.c \
	$(lib_dir)/valloc.c \
	$(lib_dir)/yesno.c \
	$(lib_dir)/getdate.c \
	$(lib_dir)/savecwd.c

LIB_OBJECTS = $(LIB_SOURCES:%.c=%.o)
LIB_HEADERS = \
	$(lib_dir)/fnmatch.h \
	$(lib_dir)/getline.h \
	$(lib_dir)/getopt.h \
	$(lib_dir)/md5.h \
	$(lib_dir)/regex.h \
	$(lib_dir)/savecwd.h \
	$(lib_dir)/system.h \
	$(lib_dir)/wait.h

ZLIB_SOURCES = \
	$(zlib_dir)/adler32.c \
	$(zlib_dir)/compress.c \
	$(zlib_dir)/crc32.c \
	$(zlib_dir)/gzio.c \
	$(zlib_dir)/uncompr.c \
	$(zlib_dir)/deflate.c \
	$(zlib_dir)/trees.c \
	$(zlib_dir)/zutil.c \
	$(zlib_dir)/inflate.c \
	$(zlib_dir)/infblock.c \
	$(zlib_dir)/inftrees.c \
	$(zlib_dir)/infcodes.c \
	$(zlib_dir)/infutil.c \
	$(zlib_dir)/inffast.c
ZLIB_OBJECTS = $(ZLIB_SOURCES:%.c=%.o)
ZLIB_HEADERS = \
	$(zlib_dir)/deflate.h \
	$(zlib_dir)/infblock.h \
	$(zlib_dir)/infcodes.h \
	$(zlib_dir)/inffast.h \
	$(zlib_dir)/inftrees.h \
	$(zlib_dir)/infutil.h \
	$(zlib_dir)/zconf.h \
	$(zlib_dir)/zlib.h \
	$(zlib_dir)/zutil.h

CVS_SOURCES = $(COMMON_SOURCES) $(OS2_SOURCES) $(DIFF_SOURCES)
CVS_OBJECTS = $(CVS_SOURCES:%.c=%.o)
CVS_HEADERS = $(COMMON_HEADERS) $(OS2_HEADERS) $(DIFF_HEADERS)

SOURCES = $(CVS_SOURCES) $(LIB_SOURCES) $(ZLIB_SOURCES)
OBJECTS = $(SOURCES:%.c=%.o)
HEADERS = $(CVS_HEADERS) $(LIB_HEADERS) $(ZLIB_HEADERS)

.PHONY: all
all: cvs
	$(MAKE) $(MAKEFLAGS) -C book
	$(MAKE) $(MAKEFLAGS) -C cvspw
	$(MAKE) $(MAKEFLAGS) -C rxrun

.PHONY: cvs
cvs: $(srcdir)/cvs.exe

.PHONY: debug
debug:
	$(MAKE) $(MAKEFLAGS) DEBUGFLAGS=-g cvs

$(srcdir)/cvs.exe: $(CVS_OBJECTS) $(lib_dir)/libcvs.a $(zlib_dir)/libz.a
	$(CC) $(LDFLAGS) $+ $(LIBS) -o $@

%.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<

$(lib_dir)/libcvs.a: $(LIB_OBJECTS)
	$(AR) cruos $@ $+

$(zlib_dir)/libz.a: $(ZLIB_OBJECTS)
	$(AR) cruos $@ $+

.PHONY: clean-cvs
clean-cvs:
	rm -f $(srcdir)/cvs.exe
	rm -f $(srcdir)/depend
	rm -f $(srcdir)/*.o
	rm -f $(diff_srcdir)/*.o
	rm -f $(lib_dir)/*.o $(lib_dir)/*.a
	rm -f $(zlib_dir)/*.o $(zlib_dir)/*.a
	rm -f $(cvs_srcdir)/*.o

.PHONY: distclean-cvs
distclean-cvs: clean-cvs

.PHONY: clean
clean: clean-cvs
	$(MAKE) $(MAKEFLAGS) -C book clean
	$(MAKE) $(MAKEFLAGS) -C cvspw clean
	$(MAKE) $(MAKEFLAGS) -C rxrun clean
	$(MAKE) $(MAKEFLAGS) -C sanity clean

.PHONY: distclean
distclean: distclean-cvs
	$(MAKE) $(MAKEFLAGS) -C book distclean
	$(MAKE) $(MAKEFLAGS) -C cvspw distclean
	$(MAKE) $(MAKEFLAGS) -C rxrun distclean
	$(MAKE) $(MAKEFLAGS) -C sanity distclean

.PHONY: dist
dist: install distclean
	mkdir -p $(install_dir)/src
	cp BUILD $(install_dir)/src
	cd ..; cvs -Q diff -c -r $(DIST_TAG) | \
		awk -f emx-new/scripts/fix-diff.awk >$(install_dir)/src/diffs
	rm -f $(install_dir)/src/emx-new.zip
	cd ..; zip -r9 $(install_dir)/src/emx-new "emx-new/*" \
		-x "*/CVS/*" -x "*/.#*"
	
.PHONY: installdirs
installdirs:
	mkdir -p $(install_dir)/bin
	mkdir -p $(install_dir)/book
	mkdir -p $(install_dir)/scripts

.PHONY: install-cvs
install-cvs: $(srcdir)/cvs.exe
	cp $(srcdir)/cvs.exe $(install_dir)/bin
	cp COPYING README $(install_dir)

.PHONY: install
install: all installdirs install-cvs
	$(MAKE) $(MAKEFLAGS) -C book install
	$(MAKE) $(MAKEFLAGS) -C cvspw install
	$(MAKE) $(MAKEFLAGS) -C rxrun install
	$(MAKE) $(MAKEFLAGS) -C scripts install

.PHONY: check
check: cvs
	$(MAKE) $(MAKEFLAGS) -C sanity check

.PHONY: remotecheck
remotecheck: cvs
	$(MAKE) $(MAKEFLAGS) -C sanity remotecheck

$(srcdir)/depend: $(SOURCES) $(HEADERS)
	$(CC) $(CPPFLAGS) -MM $(SOURCES) >$@

-include $(srcdir)/depend

