#----------------------------------------------------------------------------
# makefile for nroff 07/21/90 wjr. this makefile _SHOULD_ handle minix, tos,
# and unix. PLEASE READ THE ENTIRE MAKEFILE BEFORE YOU MAKE!
#
# this makefile was designed for my own make(1) and may not work correctly
# with minix. but then i don't have to worry about 64k limits so it can be
# more robust. it should work with any reasonable make, though. nothing fancy
# here...
#
# note that i have set this up for minix, based on the old makefile but
# it has not been tested...
#
# please look at the makefile first to customize it to your environment.
#----------------------------------------------------------------------------
#
# MACRO DEFINITIONS:
#

# version (3 digits max):
#
VER		= 110

# compiler:
#
CC		= cc

# rename:
#
RENAME		= cp

# install:
#
INSTALL		= cp

#
# main target:
#
# for tos, make this ".ttp", otherwise blank
#
EXTN		=

# for testing, use "x", otherwise blank
#
XTST		=
TARGET		= $(XTST)nroff$(EXTN)

# manual page names:
#
# section of the manual (generally always "1")
#
SECTN		= 1
MANSRC		= nroff.man
CATPAGE		= nroff.cat
MANPAGE		= nroff.$(SECTN)
SECTN_an	= 7
MANSRC_an	= man.man
CATPAGE_an	= man.cat
MANPAGE_an	= man.$(SECTN_an)
SECTN_s		= 7
MANSRC_s	= ms.man
CATPAGE_s	= ms.cat
MANPAGE_s	= ms.$(SECTN_s)

# compile flags:
#
# for different versions, use only one of the following sets in VERSFLAGS:
# tos:		-Dtos -Dalcyon
# minix ST:	-Dminix -DatariST
# minix PC:	-Dminix
# unix:		-Dunix
#
# DEBUG can be "-g" under unix and OPTIMIZE can be "-O"
# note that minix may need other flags as well (i don't have minix)
#
VERSFLAGS	= -D_MINIX -D_POSIX_SOURCE
DEFS		= -F
DEBUG		=
OPTIMIZE	=
CFLAGS		= $(DEFS) $(VERSFLAGS) $(DEBUG) $(OPTIMIZE)

# link flags:
#
# for tos, i use "-s -stksiz", others may vary
#
LDFLAGS		= -i

# source files:
#
HEADERS		= config.h nroff.h version.h
SRCS1		= main.c command.c text.c io.c
SRCS2		= macros.c strings.c escape.c low.c
SRCS		= $(SRCS1) $(SRCS2)

# object targets:
#
# for normal systems (i.e. sun,apollo,hp,ibm,cray,etc):	O=o
# for minix (ACK is right!):				O=s (SHEESH!!!)
O		=s
OBJS		= main.$O command.$O text.$O io.$O macros.$O strings.$O \
		escape.$O low.$O

# other files in the distribution:
#
TESTS		= test.0
OTHERS		= README MANIFEST Makefile nroff.man man.man ms.man \
		tmac.an tmac.s $(TESTS)

# linked libraries:
#
# for tos, i use "-lterm"
#
LIBS		=

# arc archive:
#
ARCFILE		= nroff$(VER).arc

# executable uuencoded:
#
UUEFILE		= nroff$(VER).uue

# shar files:
#
SHARFLG		= -a
SHARF1		= nroff$(VER).01
SHARF2		= nroff$(VER).02
SHARF3		= nroff$(VER).03
SHARF4		= nroff$(VER).04
SHARF5		= nroff$(VER).05
SHARFILE	= nroff$(VER).shr

# macro library files:
#
MAN_MACRO	= tmac.an
MS_MACRO	= tmac.s
#ME_MACRO	= tmac.e

# final locations for things:
#
# set these as per your system (for "make install")
# tos:		TMACDIR = c:\lib\tmac		(for tmac.an)
# 		BINDIR  = c:\bin		(for nroff)
# 		MANDIR  = c:\man\man$(SECTN)	(for nroff.1)
# minix:	TMACDIR = /usr/lib/tmac
# 		BINDIR  = /usr/bin
# 		MANDIR  = /usr/man/man$(SECTN)
# unix:		TMACDIR = /usr/local/lib/tmac
# 		BINDIR  = /usr/local/bin
# 		MANDIR  = /usr/local/man/man$(SECTN)
#
TMACDIR		= /usr/lib/tmac
BINDIR		= /bin
MANDIR		= /usr/man/man$(SECTN)
MANDIR_an	= /usr/man/man$(SECTN_an)
MANDIR_s	= /usr/man/man$(SECTN_s)

# system path seperator:
#
# note that my make under tos uses <space>\ for line continuation so i can't
# put a space after the "=".
# for tos, use:		S=\ 		(NO SPACES!!!)
# for minix, unix, use:	S=/
#
S		=/

# testing:
#
# make sure to "setenv TMACDIR ." first...
#
RUNPARM		= -man test.0
RUNOUT		= >test.out

# a non-objecting rm command:
#
# unix/minix:	RM = rm -f
RM		= rm -f


#----------------------------------------------------------------------------
#
# ACTIONS:
#


# directions for making things is default target...
#
directions:
		@echo Please read the README file first. Also review makefile.
		@echo Type "make all" to build $(TARGET)
		@echo Type "make manpage" to build $(MANPAGE)
		@echo Type "make install" to build/install $(TARGET)
		@echo Type "make test" to test $(TARGET)
		@echo Type "make clean" to remove objects
		@echo Type "make clobber" to remove objects and $(TARGET)
		@echo Type "make arc" to make source archive $(ARCFILE)
		@echo Type "make shar" to make source shar file $(SHARFILE)
		@echo Type "make uue" to make uuencoded $(TARGET) $(UUEFILE)



# make main target...
#
all:		$(TARGET)

$(TARGET):	$(OBJS)
		$(CC) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
		@echo "done making $(TARGET)"



# make installable manpage...
#
# you may have to change this. i keep my manpages pre-nroffed so i use
# CATPAGE as my manpage. your man(1) may use nroff to display manpages,
# so you may want to do this instead:
#
# manpage:	$(MANPAGE) $(MANPAGE_an)
#
# $(MANPAGE):	$(MANSRC)
#		$(RENAME) $(MANSRC) $(MANPAGE)
#
# $(MANPAGE_an): $(MANSRC_an)
#		$(RENAME) $(MANSRC_an) $(MANPAGE_an)
#
manpage:	$(MANPAGE) $(MANPAGE_an) $(MANPAGE_s)
		@echo "done making manpages"

$(MANPAGE):	$(CATPAGE)
		$(RENAME) $(CATPAGE) $(MANPAGE)

$(MANPAGE_an):	$(CATPAGE_an)
		$(RENAME) $(CATPAGE_an) $(MANPAGE_an)

$(MANPAGE_s):	$(CATPAGE_s)
		$(RENAME) $(CATPAGE_s) $(MANPAGE_s)

$(CATPAGE):	$(MANSRC)	# note: uses built-in .man.cat rule!!!!!

$(CATPAGE_an):	$(MANSRC_an)

$(CATPAGE_s):	$(MANSRC_s)



# to test run it...
#
test:		$(TARGET)
		$(TARGET) $(RUNPARM) $(RUNOUT)
		@echo "done with test"


# install target, manpage, and lib stuff...
#
install:	install_bin install_man install_tmac
		@echo "install complete"

install_bin:	$(TARGET)
		$(INSTALL) $(TARGET) $(BINDIR)$S$(TARGET)
		@echo "done installing $(TARGET)"

install_man:	$(MANPAGE) $(MANPAGE_an) $(MANPAGE_s)
		$(INSTALL) $(MANPAGE) $(MANDIR)$S$(MANPAGE)
		$(INSTALL) $(MANPAGE_an) $(MANDIR_an)$S$(MANPAGE_an)
		$(INSTALL) $(MANPAGE_s) $(MANDIR_s)$S$(MANPAGE_s)
		@echo "done installing manpages"

install_tmac:
		$(INSTALL) $(MAN_MACRO) $(TMACDIR)$S$(MAN_MACRO)
		$(INSTALL) $(MS_MACRO) $(TMACDIR)$S$(MS_MACRO)
#		$(INSTALL) $(ME_MACRO) $(TMACDIR)$S$(ME_MACRO)
		@echo "done installing macro packages"



# clean up...
#
clean:
		$(RM) $(OBJS)

clobber:
		$(RM) $(OBJS)
		$(RM) $(TARGET)

cleansrc:
		$(RM) $(SRCS) $(HEADERS)

cleandocs:
		$(RM) docs.arc readme bugs $(MANPAGE) $(MAN_MACRO) $(MS_MACRO)



# various archives...
#
uue:
		$(UUENCODE) $(TARGET)
		@echo done making $(UUEFILE)

shar:		uue
		$(SHAR) $(SHARFLG) $(OTHERS) >$(SHARF1)
		$(SHAR) $(SHARFLG) $(SRCS1) >$(SHARF2)
		$(SHAR) $(SHARFLG) $(SRCS2) >$(SHARF3)
		$(SHAR) $(SHARFLG) $(HEADERS) >$(SHARF4)
		$(SHAR) $(SHARFLG) $(UUEFILE) >$(SHARF5)
		@echo done making $(SHARF1) $(SHARF2) $(SHARF3) $(SHARF4) $(SHARF5)

arc:
		$(ARC) a $(ARCFILE) $(OTHERS)
		$(ARC) a $(ARCFILE) $(HEADERS)
		$(ARC) a $(ARCFILE) $(SRCS)
		@echo done making $(ARCFILE)



# the following actions i use while developing so i can save disk space.

# use this to save space on disk
#
backup:		objs.arc srcs.arc docs.arc

objs.arc:
		$(ARC) a objs.arc $(OBJS) $(TARGET)
		@echo done making objs.arc. consider "make clean"

srcs.arc:
		$(ARC) a srcs.arc $(HEADERS)
		$(ARC) a srcs.arc $(SRCS)
		@echo done making srcs.arc. consider "make cleansrc"

docs.arc:
		$(ARC) a docs.arc readme bugs $(MANPAGE) $(MAN_MACRO) $(MS_MACRO)
		@echo done making docs.arc. consider "make cleandocs"

# use this to go back to work after "make backup"
#
restore:
		$(ARC) x srcs.arc $(HEADERS)
		$(ARC) x srcs.arc $(SRCS)
		$(ARC) x docs.arc $(MANPAGE) $(MAN_MACRO) $(MS_MACRO)
		$(ARC) x objs.arc $(OBJS)
		$(ARC) x objs.arc $(TARGET)
		@echo done with restore...ok to continue to hack
		@echo be sure to setenv TMACDIR during testing


#----------------------------------------------------------------------------
#
# DEPENDENCIES:
#
# note: nroff.h includes version.h and config.h. all sources include nroff.h
# and in addition, main.c includes config.h as well (first thing).

version.h:	patchlvl.h
		touch version.h

nroff.h:	version.h config.h
		touch nroff.h

main.$O:	main.c nroff.h
command.$O:	command.c nroff.h
text.$O:	text.c nroff.h
io.$O:		io.c nroff.h
macros.$O:	macros.c nroff.h
strings.$O:	strings.c nroff.h
escape.$O:	escape.c nroff.h
low.$O:		low.c nroff.h

# the end...
