# Makefile for Joe's Own Editor

###############
# Configuration
###############

# Set where you want joe to go, where you
# want joe's initialization file (joerc)
# to go and where you want the man page
# to go:

WHEREJOE = /usr/bin
WHERERC = /etc/joe
WHEREMAN = /usr/man/man1
DESTDIR = 
WHEREINSTALLJOE = $(DESTDIR)$(WHEREJOE)
WHEREINSTALLRC = $(DESTDIR)$(WHERERC)
WHEREINSTALLMAN = $(DESTDIR)$(WHEREMAN)

# If you want to use TERMINFO, you have to set
# the following variable to 1.  Also you have to
# include some additional libraries- see below.

TERMINFO = 0

# You may also have to add some additional
# defines to get the include files to work
# right on some systems.
#
# for some HPUX systems, you need to add:  -D_HPUX_SOURCE

# C compiler options: make's built-in rules use this variable

CFLAGS = -O2

# C compiler to use: make's built-in rules use this variable

CC = gcc

# You may have to include some extra libraries
# for some systems
#
# for Xenix, add (in this order!!): -ldir -lx
#
# For some systems you might have to add: -lbsd
# to get access to the timer system calls.
#
# If you wish to use terminfo, you have to
# add '-ltinfo', '-lcurses' or '-ltermlib',
# depending on the system.

EXTRALIBS =

# Object files

OBJS = b.o blocks.o bw.o cmd.o hash.o help.o kbd.o macro.o main.o menu.o \
 path.o poshist.o pw.o queue.o qw.o random.o rc.o regex.o scrn.o tab.o \
 termcap.o tty.o tw.o ublock.o uedit.o uerror.o ufile.o uformat.o uisrch.o \
 umath.o undo.o usearch.o ushell.o utag.o va.o vfile.o vs.o w.o zstr.o

# That's it!

# How to make joe from object files.  Object files are made from source
# files using make's built-in rules.

joe: $(OBJS)
	rm -f jmacs jstar rjoe jpico
	$(CC) $(CFLAGS) -o joe $(OBJS) $(EXTRALIBS)
	ln joe jmacs
	ln joe jstar
	ln joe rjoe
	ln joe jpico

# All object files depend on config.h

$(OBJS): config.h

# How to make config.h

config.h:
	$(CC) conf.c -o conf
	./conf $(WHERERC) $(TERMINFO)

# How to make termidx

termidx: termidx.o
	$(CC) $(CFLAGS) -o termidx termidx.o

# Install proceedure

install: joe termidx
	strip joe
	strip termidx
	if [ ! -d $(WHEREINSTALLJOE) ]; then mkdir $(WHEREINSTALLJOE); chmod a+rx $(WHEREINSTALLJOE); fi
	rm -f $(WHEREINSTALLJOE)/joe $(WHEREINSTALLJOE)/jmacs $(WHEREINSTALLJOE)/jstar $(WHEREINSTALLJOE)/jpico $(WHEREINSTALLJOE)/rjoe $(WHEREINSTALLJOE)/termidx
	mv joe $(WHEREINSTALLJOE)
	ln $(WHEREINSTALLJOE)/joe $(WHEREINSTALLJOE)/jmacs
	ln $(WHEREINSTALLJOE)/joe $(WHEREINSTALLJOE)/jstar
	ln $(WHEREINSTALLJOE)/joe $(WHEREINSTALLJOE)/rjoe
	ln $(WHEREINSTALLJOE)/joe $(WHEREINSTALLJOE)/jpico
	mv termidx $(WHEREINSTALLJOE)
	if [ ! -d $(WHEREINSTALLRC) ]; then mkdir $(WHEREINSTALLRC); chmod a+rx $(WHEREINSTALLRC); fi
	rm -f $(WHEREINSTALLRC)/joerc $(WHEREINSTALLRC)/jmacsrc $(WHEREINSTALLRC)/jstarrc $(WHEREINSTALLRC)/jpicorc $(WHEREINSTALLRC)/rjoerc $(WHEREINSTALLMAN)/joe.1
	cp joerc $(WHEREINSTALLRC)
	cp jmacsrc $(WHEREINSTALLRC)
	cp jstarrc $(WHEREINSTALLRC)
	cp rjoerc $(WHEREINSTALLRC)
	cp jpicorc $(WHEREINSTALLRC)
	cp joe.1 $(WHEREINSTALLMAN)
	chmod a+x $(WHEREINSTALLJOE)/joe
	chmod a+x $(WHEREINSTALLJOE)/jmacs
	chmod a+x $(WHEREINSTALLJOE)/jstar
	chmod a+x $(WHEREINSTALLJOE)/rjoe
	chmod a+x $(WHEREINSTALLJOE)/jpico
	chmod a+r $(WHEREINSTALLRC)/joerc
	chmod a+r $(WHEREINSTALLRC)/jmacsrc
	chmod a+r $(WHEREINSTALLRC)/jstarrc
	chmod a+r $(WHEREINSTALLRC)/rjoerc
	chmod a+r $(WHEREINSTALLRC)/jpicorc
	chmod a+r $(WHEREINSTALLMAN)/joe.1
	chmod a+x $(WHEREINSTALLJOE)/termidx
	rm -f $(WHEREINSTALLRC)/termcap
	cp termcap $(WHEREINSTALLRC)/termcap
	chmod a+r $(WHEREINSTALLRC)/termcap
	rm -f $(WHEREINSTALLRC)/terminfo
	cp terminfo $(WHEREINSTALLRC)/terminfo
	chmod a+r $(WHEREINSTALLRC)/terminfo

# Cleanup proceedure

clean:
	rm -f $(OBJS) termidx.o conf conf.o config.h
