#
# This code contains changes by
#      Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
#
# Conditions 1, 2, and 4 and the no-warranty notice below apply
# to these changes.
#
#
# Copyright (c) 1980, 1993
# 	The Regents of the University of California.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
# 	This product includes software developed by the University of
# 	California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#   Redistributions of source code and documentation must retain the
#    above copyright notice, this list of conditions and the following
#    disclaimer.
#   Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#   All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#      This product includes software developed or owned by Caldera
#      International, Inc.
#   Neither the name of Caldera International, Inc. nor the names of
#    other contributors may be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
# INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
# LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#	from Makefile	7.13.1.3 (2.11BSD GTE) 1996/10/23
#
#	@(#)Makefile	1.34 (gritter) 8/27/03
#

#
# Destinations for installation. $(BINDIR), $(LIBEXECDIR) and $(MANDIR) are
# located  below $(DESTDIR). $(PRESERVEDIR) is used for recovery files. It
# will get mode 1777.
#
BINDIR		= bin
LIBEXECDIR	= libexec
MANDIR		= man
DESTDIR		= /usr/local
PRESERVEDIR	= /var/preserve

#
# A BSD-like install program. GNU install will fit well here, too.
#
INSTALL		= /usr/ucb/install

#
# Compiler and linker flags.
#
#CFLAGS	=
#LDFLAGS	=
#LDADD	=

#
# The following features are quite recommended.
#
# Remove -DBIT8 to get a 7bit-only ex.
# Add -DNO_BE_BACKSLASH to make backslash a regular character inside RE
#     bracket expressions.
#
# Some historic comments:
#
# Ex is very large - this version will not fit on PDP-11's without overlay
# software.  Things that can be turned off to save
# space include LISPCODE (-l flag, showmatch and lisp options), CHDIR (the 
# undocumented chdir command.)
#
# If your system expands tabs to 4 spaces you should -DTABS=4 below
#
FEATURES	= -DLISPCODE -DCHDIR -DFASTTAG -DUCVISUAL -DBIT8

#
# This disables the LC_CTYPE locale settings and assumes all characters
# upwards from octal 0240 are printable ones, like in ISO 8859-1. It
# should only be used if the system's locales are broken.
#
#CHARSET	= -DISO8859_1

#
# If you want LC_MESSAGES support using catgets(), define this. To make
# any practical use of it, you also have to create a message catalogue,
# put it in a proper location and change UNKNOWN to its name. See your
# system's documentation on "gencat" or on language support in general
# for further information.
#
#LANGMSG		= -DLANGMSG -DCATNAME='"UNKNOWN"'

#
# To use the features of localized regular expressions ([:class:], [.c.],
# [=c=], \(re\)*, \(re\)\{m,n\}), you need Caldera's 'UNIX(R) Regular
# Expression Library' or a derivative of it. Comment out the three following
# lines if you don't have it or if it does not compile; it needs some
# advanced multibyte character support etc. which might not be present
# on your system.
#
REINC	= -I./libuxre -DUXRE
RELIB	= -L./libuxre -luxre
RETGT	= uxre

#
# These settings should be correct for any modern Unix.
# In older System V environments, replace -DPOSIX_1 by -DUSG3TTY.
# In older BSD environments, simply remove -DPOSIX_1.
#
# Historic comments:
#
# VMUNIX makes ex considerably larger, raising 
# many limits and improving speed and simplicity of maintenance.  It is 
# suitable only for a VAX or other large machine, and then probably only in 
# a paged system.
#
# Don't define VFORK unless your system has the VFORK system call,
# which is like fork but the two processes have only one data space until the
# child execs. This speeds up ex by saving the memory copy.
#
#      Note by Gunnar Ritter: vfork() is unreliable and one of the worst
#      hacks in Unix history. Do not define VFORK unless you have a
#      special good reason for that.
#
OSTYPE	= -DVMUNIX -DPOSIX_1

#
# On VMUNIX systems, ex can normally edit files up to 32 MB of size. LARGEF
# raises this limit to around 1 GB, but ex will consume much more of core
# and temp file space then.
#
#LARGEF	= -DLARGEF

# 
# The next setting is a crucial one since it determines the way ex
# gets its knowledge about the terminal's capabilities. If you get
# weird results, try using another library here. Uncomment exactly
# one entry.
#
# On System V, the terminfo library may be more accurate than the termcap
# file. To use it, link against the curses library.
#
#TERMLIB	= curses
#
# You may also get terminfo access by using the ncurses library.
#
#TERMLIB	= ncurses
#
# The preferred choice for ex on Linux and other systems that provide a good
# termcap file is the 2.11BSD termcap library included here.
#
TERMLIB	= termlib

#
# Since ex uses sbrk() internally, a conflict with the libc's version of
# malloc() must be avoided. There are two ways to work around this problem.
# The first is to allocate a static pool for all malloc purposes. This will
# work on any kind of system.
#
#MALLOC=malloc.o
#
# If mmap() can be used to allocate anonymous memory, this is the preferred
# choice as it allows to grow memory dynamically as it is needed.
MALLOC=mapmalloc.o

###############################################################################
#                                                                             #
# That's it. You do not normally need to change anything below here.          #
#                                                                             #
###############################################################################

#WARN	= -Wall -Wno-parentheses -Wno-format -Wno-return-type \
#			-Wno-implicit-int -Wtraditional -Werror

RECOVER	= -DEXRECOVER=\"$(DESTDIR)/$(LIBEXECDIR)/exrecover\" \
			-DEXPRESERVE=\"$(DESTDIR)/$(LIBEXECDIR)/expreserve\"
CCFLAGS	= $(CFLAGS) $(WARN) $(CPPFLAGS) $(FEATURES) $(CHARSET) $(OSTYPE) \
		$(LARGEF) $(RECOVER) $(LANGMSG) $(REINC)
TLIB	= libterm/libtermlib.a
INCLUDE	= /usr/include
OBJS	= ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o \
		ex_data.o ex_extern.o ex_get.o ex_io.o ex_put.o ex_re.o \
		ex_set.o ex_subr.o ex_tagio.o ex_temp.o ex_tty.o ex_unix.o \
		ex_v.o ex_vadj.o ex_vget.o ex_vmain.o ex_voper.o \
		ex_vops.o ex_vops2.o ex_vops3.o ex_vput.o ex_vwind.o \
		printf.o ex_version.o $(MALLOC)
HDRS	= ex.h ex_argv.h ex_re.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h \
		ex_vis.h libterm/libterm.h
SRC1	= ex.c ex_addr.c ex_cmds.c ex_cmds2.c ex_cmdsub.c
SRC2	= ex_data.c ex_get.c ex_io.c ex_put.c ex_re.c
SRC3	= ex_set.c ex_subr.c ex_tagio.c ex_temp.c ex_tty.c ex_unix.c
SRC4	= ex_v.c ex_vadj.c ex_vget.c ex_vmain.c ex_voper.c
SRC5	= ex_vops.c ex_vops2.c ex_vops3.c ex_vput.c ex_vwind.c
SRC6	= printf.c expreserve.c exrecover.c ex_version.c
SRC7	= mapmalloc.c malloc.c

.SUFFIXES: .o .c
.c.o: ; $(CC) $(CCFLAGS) -c $<

all: $(RETGT) exrecover expreserve ex

ex: $(TLIB) $(OBJS)
	$(CC) -o ex $(LDFLAGS) $(OBJS) $(LDADD) -Llibterm -l$(TERMLIB) $(RELIB)
	size ex

$(TLIB): libterm/termcap.c libterm/tgoto.c libterm/tputs.c libterm/libterm.h
	@cd libterm && $(MAKE) CC="$(CC)" \
		COPT="$(CFLAGS) $(WARN) $(CPPFLAGS) $(OSTYPE)"

exrecover: exrecover.o $(MALLOC)
	$(CC) -o exrecover $(LDFLAGS) exrecover.o $(MALLOC) $(LDADD)

expreserve: expreserve.o
	$(CC) -o expreserve $(LDFLAGS) expreserve.o $(LDADD)

ex_vars.h: ex_data.c
	sh makeoptions $(CCFLAGS)

uxre:
	@cd libuxre && $(MAKE) CC="$(CC)" \
		COPT="$(CFLAGS) $(WARN) $(CPPFLAGS) $(OSTYPE)"

clean:
	@cd libterm && $(MAKE) clean
	@test ! -d libuxre || (cd libuxre && $(MAKE) clean)
#	If we dont have ex we cant make it so don't rm ex_vars.h
	-rm -f ex exrecover expreserve *.o x*.[cs] core errs trace

# install in standard place

install-man:
	test -d $(DESTDIR) || mkdir $(DESTDIR)
	test -d $(DESTDIR)/$(MANDIR) || mkdir $(DESTDIR)/$(MANDIR)
	test -d $(DESTDIR)/$(MANDIR)/man1 || mkdir $(DESTDIR)/$(MANDIR)/man1
	rm -f $(DESTDIR)/$(MANDIR)/man1/ex.1 $(DESTDIR)/$(MANDIR)/man1/edit.1 \
		$(DESTDIR)/$(MANDIR)/man1/vedit.1 \
		$(DESTDIR)/$(MANDIR)/man1/vi.1 \
		$(DESTDIR)/$(MANDIR)/man1/view.1
	$(INSTALL) -c -m 644 ex.1 $(DESTDIR)/$(MANDIR)/man1/ex.1
	$(INSTALL) -c -m 644 vi.1 $(DESTDIR)/$(MANDIR)/man1/vi.1
	ln -s ex.1 $(DESTDIR)/$(MANDIR)/man1/edit.1
	ln -s vi.1 $(DESTDIR)/$(MANDIR)/man1/vedit.1
	ln -s vi.1 $(DESTDIR)/$(MANDIR)/man1/view.1

install: all install-man
	rm -f $(DESTDIR)/$(BINDIR)/ex $(DESTDIR)/$(BINDIR)/edit \
		$(DESTDIR)/$(BINDIR)/vedit $(DESTDIR)/$(BINDIR)/vi \
		$(DESTDIR)/$(BINDIR)/view
	test -d $(DESTDIR)/$(BINDIR) || mkdir $(DESTDIR)/$(BINDIR)
# special provisions for sticky install
	if test -f $(DESTDIR)/$(BINDIR)/ex; \
	then	test -f $(DESTDIR)/$(BINDIR)/ex.old.$$$$ && exit 1; \
		chmod 755 $(DESTDIR)/$(BINDIR)/ex; \
		echo q | $(DESTDIR)/$(BINDIR)/ex; \
		mv $(DESTDIR)/$(BINDIR)/ex $(DESTDIR)/$(BINDIR)/ex.old.$$$$; \
		rm -f $(DESTDIR)/$(BINDIR)/ex.old.$$$$; \
	fi
	$(INSTALL) -c -s -m 1755 ex $(DESTDIR)/$(BINDIR)/ex
	test -d $(DESTDIR)/$(LIBEXECDIR) || mkdir $(DESTDIR)/$(LIBEXECDIR)
	$(INSTALL) -c -s exrecover $(DESTDIR)/$(LIBEXECDIR)/exrecover
	$(INSTALL) -c -s expreserve $(DESTDIR)/$(LIBEXECDIR)/expreserve
	ln -s ex $(DESTDIR)/$(BINDIR)/edit
	ln -s ex $(DESTDIR)/$(BINDIR)/vedit
	ln -s ex $(DESTDIR)/$(BINDIR)/vi
	ln -s ex $(DESTDIR)/$(BINDIR)/view
	test -d $(PRESERVEDIR) || mkdir $(PRESERVEDIR)
	chmod 1777 $(PRESERVEDIR)

ex.o: config.h ex_argv.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h
ex.o: ex_vars.h libterm/libterm.h
ex_addr.o: config.h ex.h ex_proto.h ex_re.h ex_tune.h ex_vars.h
ex_cmds.o: config.h ex_argv.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h
ex_cmds.o: ex_vars.h ex_vis.h libterm/libterm.h
ex_cmds2.o: config.h ex_argv.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h
ex_cmds2.o: ex_vars.h ex_vis.h libterm/libterm.h
ex_cmdsub.o: config.h ex_argv.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h
ex_cmdsub.o: ex_vars.h ex_vis.h libterm/libterm.h
ex_data.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h
ex_data.o: libterm/libterm.h
ex_extern.o: config.h ex_argv.h ex.h ex_proto.h ex_re.h ex_temp.h ex_tty.h
ex_extern.o: ex_tune.h ex_vars.h ex_vis.h libterm/libterm.h
ex_get.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h
ex_get.o: libterm/libterm.h
ex_io.o: config.h ex_argv.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h
ex_io.o: ex_vars.h ex_vis.h libterm/libterm.h
ex_put.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_put.o: libterm/libterm.h
ex_re.o: config.h ex.h ex_proto.h ex_re.h ex_tune.h ex_vars.h
ex_set.o: config.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h
ex_set.o: libterm/libterm.h
ex_subr.o: config.h ex.h ex_proto.h ex_re.h ex_tty.h ex_tune.h ex_vars.h
ex_subr.o: ex_vis.h libterm/libterm.h
ex_tagio.o: config.h ex.h ex_proto.h ex_tune.h ex_vars.h
ex_temp.o: config.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h
ex_temp.o: ex_vis.h libterm/libterm.h
ex_tty.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h
ex_tty.o: libterm/libterm.h
ex_unix.o: config.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h
ex_unix.o: ex_vis.h libterm/libterm.h
ex_v.o: config.h ex.h ex_proto.h ex_re.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_v.o: libterm/libterm.h
ex_vadj.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vadj.o: libterm/libterm.h
ex_vget.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vget.o: libterm/libterm.h
ex_vmain.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vmain.o: libterm/libterm.h
ex_voper.o: config.h ex.h ex_proto.h ex_re.h ex_tty.h ex_tune.h ex_vars.h
ex_voper.o: ex_vis.h libterm/libterm.h
ex_vops.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vops.o: libterm/libterm.h
ex_vops2.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vops2.o: libterm/libterm.h
ex_vops3.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vops3.o: libterm/libterm.h
ex_vput.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vput.o: libterm/libterm.h
ex_vwind.o: config.h ex.h ex_proto.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
ex_vwind.o: libterm/libterm.h
expreserve.o: config.h
exrecover.o: config.h ex.h ex_proto.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h
exrecover.o: libterm/libterm.h
malloc.o: config.h
mapmalloc.o: config.h
printf.o: config.h
