# Make file for mailx directory
#
# Things you might want to change.  Pass them in on the command line:
# ROOT - should point to the root where the commands will be installed
#        (e.g. /deliver/INETSVCS/indnetwk)

ROOT=

PRODUCTS=/usr/bin/mailx \
	/usr/lbin/rmmail \
	/usr/lib/nls/msg/C/mailx.cat \
	/usr/share/lib/mailx.rc \
	/usr/bin/metamail \
	/usr/bin/showaudio \
	/usr/bin/showexternal \
	/usr/bin/shownonascii \
	/usr/bin/showpicture \
	/usr/newconfig/etc/mail/mailcap 

# Defaults file containing the shell, compiler options, etc
BUILDRULES=/source/INETSVCS/$(LOGNAME)/config/defaults

include ${BUILDRULES}

#Commands used by this Makefile

HDR=hdr
FINDMSG=/usr/bin/findmsg
GENCAT=/usr/bin/gencat
MV=/usr/bin/mv
YACC=/opt/langtools/bin/yacc

INCLUDES=-I../include -I/usr/include -I$(HDR)
CCFLAGS=$(INCLUDES) -DUSG -DUSG_TTY -DNLS -DVMUNIX $(CFLAGS) $(LDFLAGS) -lV3

#Install database name
INSTALLDB=/source/INETSVCS/$(LOGNAME)/config/installdb

#Script called to parse the install deliverable
INSTALLSCPT=/source/INETSVCS/$(LOGNAME)/config/install_script

XSTR=./xstr
OBJS=   aux.o cmd1.o cmd2.o cmd3.o cmd4.o cmdtab.o codes.o collect.o config.o \
	edit.o fio.o getdate.o getname.o hostname.o head.o usg.local.o \
	lock.o lex.o list.o main.o names.o optim.o popen.o quit.o send.o \
	stralloc.o temp.o tty.o vars.o lpaths.o extern.o \
	hpux_rel.o system.o str.o               # str.o must be last

MM_OBJS= metamail.o codes.o uue.o shared.o

SRCS=   aux.c cmd1.c cmd2.c cmd3.c cmd4.c cmdtab.c codes.o collect.c config.c \
	edit.c fio.c getdate.c getname.c hostname.c head.c usg.local.c \
	lock.c lex.c list.c main.c names.c optim.c popen.c quit.c send.c \
	stralloc.c temp.c tty.c vars.c lpaths.c extern.c \
	hpux_rel.c system.c

HDRS=   $(HDR)/rcv.h \
	$(HDR)/configdefs.h \
	$(HDR)/def.h \
	$(HDR)/glob.h \
	$(HDR)/usg.local.h \
	$(HDR)/local.h \
	$(HDR)/uparm.h \
	$(HDR)/sigretro.h

#
# List sources with NLS message catalogs in MSGSRC
#
MSGSRC= aux.msg cmd1.msg cmd2.msg cmd3.msg cmd4.msg collect.msg edit.msg \
	fio.msg hostname.msg lex.msg list.msg main.msg metamail.msg \
	optim.msg quit.msg send.msg stralloc.msg temp.msg tty.msg \
	vars.msg rmmail.msg head.msg

#
# Special massaging of C files for sharing of strings
#
.c.o:
	$(CC) -E $(CCFLAGS) $*.c | $(XSTR) -c -
	$(CC) -c $(CCFLAGS) x.c
	$(MV) x.o $*.o
	$(RM) -f x.c

default: all

all: clean build install

clean:
	$(RM) -f *.o
	$(RM) -f *.msg
	$(RM) -f a.out x.c xs.c core strings getdate.c
	$(RM) -f mailx rmmail $(XSTR) mailx.cat metamail

install:
	for file in $(PRODUCTS) ; do \
		$(INSTALLSCPT) $$file $(INSTALLDB) ;  \
	done

build: mailx rmmail mailx.cat metamail 

mailx: $(XSTR) $(OBJS) $(HDRS)
	$(ECHO) "Building... mailx"
	$(CC) $(CCFLAGS) -o $@ $(OBJS)
 
metamail: $(MM_OBJS)
	$(ECHO) "Building... metamail"
	$(CC) $(CCFLAGS) -o $@ $(MM_OBJS)
rmmail:
	$(ECHO) "Building... rmmail"
	slibs="";
	#ifdef SecureWare
		slibs="-lsec";
	#endif
	#ifdef B1
		slibs="-lsec";
	#endif
	#ifdef TRUSTED
		slibs="-lsec";
	#endif
	$(CC) $(CCFLAGS) -o $@ rmmail.c $$slibs

mailx.cat: $(MSGSRC)
	$(ECHO) "Building... mailx.cat"
	$(GENCAT) $@ $(MSGSRC)

strings: $(XSTR)

str.o:	strings
	$(XSTR)
	$(CC) -c $(CCFLAGS) xs.c
	$(MV) xs.o str.o
	$(RM) -f xs.c

$(XSTR):        xstr.c
	$(CC) $(ARCV_LDFLAGS) $(CFLAGS) -o $(XSTR) xstr.c

cmdtab.o:	cmdtab.c
	$(CC) $(CCFLAGS) -c cmdtab.c

codes.o:	codes.c
	$(CC) $(CCFLAGS) -c codes.c

getdate.o:	getdate.y
	$(YACC) getdate.y
	$(MV) y.tab.c getdate.c
	$(CC) $(CCFLAGS) -c getdate.c

metamail.o:	metamail.c $(HDR)/config.h
	$(CC) $(CCFLAGS) -c metamail.c

shared.o:	shared.c $(HDR)/config.h
	$(CC) $(CCFLAGS) -c shared.c

uue.o:	uue.c
	$(CC) $(CCFLAGS) -c uue.c

.c.msg:
	$(FINDMSG) $*.c > $*.msg

.msg.cat:
	$(GENCAT) $*.cat $*.msg

.SUFFIXES: .cat .msg
