# makefile for sfio
#
# Written by Kiem-Phong Vo (4/24/91)
#
# Adapted to ZMailer's environment by Matti Aarnio <mea@nic.funet.fi>

srcdir = @srcdir@
VPATH = @srcdir@
@SET_MAKE@

INCDIR=	../../../include
LIBDIR=	../../../lib
BINDIR=	$(srcdir)/../../../bin

# Compiler and flags to use
CXFLAGS=
CCMODE=	 @CFLAGS@
CCFLAGS= -I. $(CCMODE) $(CXFLAGS)
AR=	@AR@
CC=	@CC@

# sfio
SRCS=	sfclose.c sfclrlock.c sfcvt.c sfdisc.c sfdlen.c sfexcept.c \
	sfextern.c sffilbuf.c sfflsbuf.c sfprints.c sfgetd.c sfgetl.c \
	sfgetr.c sfgetu.c sfllen.c sfmode.c sfmove.c sfnew.c \
	sfnotify.c sfnputc.c sfopen.c sfpkrd.c sfpool.c sfpopen.c \
	sfprintf.c sfputd.c sfputl.c sfputr.c sfputu.c sfrd.c sfread.c \
	sfscanf.c sfseek.c sfset.c sfsetbuf.c sfsetfd.c sfsize.c sfsk.c \
	sfstack.c sfstrtod.c sfsync.c sftable.c sftell.c sftmp.c \
	sfungetc.c sfvprintf.c sfvscanf.c sfwr.c sfwrite.c sfexit.c \
	sfpurge.c sfpoll.c sfreserve.c sfswap.c sfraise.c
OBJS=	sfclose.o sfclrlock.o sfcvt.o sfdisc.o sfdlen.o sfexcept.o \
	sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetl.o \
	sfgetr.o sfgetu.o sfllen.o sfmode.o sfmove.o sfnew.o \
	sfnotify.o sfnputc.o sfopen.o sfpkrd.o sfpool.o sfpopen.o \
	sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o \
	sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o \
	sfstack.o sfstrtod.o sfsync.o sftable.o sftell.o sftmp.o \
	sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfexit.o \
	sfpurge.o sfpoll.o sfreserve.o sfswap.o sfraise.o

# function versions of macros
SFIO_F=	Sfio_f/_sfclrerr.o Sfio_f/_sfeof.o Sfio_f/_sferror.o \
	Sfio_f/_sffileno.o Sfio_f/_sfgetc.o Sfio_f/_sfgetl.o \
	Sfio_f/_sfgetu.o Sfio_f/_sfputc.o Sfio_f/_sfslen.o \
	Sfio_f/_sfulen.o Sfio_f/_sfstacked.o Sfio_f/_sfvalue.o

# stdio-source compatibility code
STDIO_S=Stdio_s/stdgets.o Stdio_s/stdopen.o Stdio_s/stdprintf.o \
	Stdio_s/stdscanf.o Stdio_s/stdsprintf.o Stdio_s/stdvbuf.o \
	Stdio_s/stdgetc.o Stdio_s/stdputc.o

# IO disciplines
SFIO_DC=Sfio_dc/sfdcdio.o Sfio_dc/sfdcdos.o Sfio_dc/sfdcfilter.o \
	Sfio_dc/sfdclzw.o Sfio_dc/sfdcseekable.o Sfio_dc/sfdcslow.o \
	Sfio_dc/sfdcsubstream.o Sfio_dc/sfdctee.o Sfio_dc/sfdcunion.o

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

all:	install


install: $(LIBDIR)/libsfio.a $(LIBDIR)/libstdio.a \
	$(INCDIR)/ast_common.h $(INCDIR)/sfio.h  $(INCDIR)/sfio_t.h \
	$(INCDIR)/stdio.h 

$(LIBDIR)/libsfio.a: libsfio.a
	cp libsfio.a $(LIBDIR)
	-(ranlib $(LIBDIR)/libsfio.a; exit 0) >/dev/null 2>&1

$(LIBDIR)/libstdio.a: Stdio_b/libstdio.a
	cp  Stdio_b/libstdio.a $(LIBDIR)
	-(ranlib $(LIBDIR)/libstdio.a; exit 0) >/dev/null 2>&1

$(INCDIR)/ast_common.h: ast_common.h
	cp $? $@
$(INCDIR)/sfio.h: $(srcdir)/sfio.h
	cp $? $@
$(INCDIR)/sfio_t.h: $(srcdir)/sfio_t.h
	cp $? $@
$(INCDIR)/stdio.h: $(srcdir)/Stdio_s/stdio.h
	cp $? $@

libsfio.a: ast_common.h FEATURE/sfio $(OBJS) $(SFIO_F) $(STDIO_S) $(SFIO_DC)
	$(AR) cr libsfio.a $(OBJS) $(SFIO_F) $(STDIO_S) $(SFIO_DC)
	-(ranlib libsfio.a; exit 0) >/dev/null 2>&1

Stdio_b/libstdio.a: ast_common.h FEATURE/sfio
	cd Stdio_b; $(MAKE) -f Makefile SHELL=$(SHELL) CC="$(CC)" \
		CCMODE="$(CCMODE)" CXFLAGS="$(CXFLAGS)" $(MFLAGS)

FEATURE/sfio: $(srcdir)/features/sfio
	-if [ ! -d FEATURE ]; then mkdir FEATURE; else exit 0; fi
	$(BINDIR)/iffe - set cc $(CC) $(CCMODE) $(CXFLAGS) : run $(srcdir)/features/sfio > FEATURE/sfio.$$$$ && mv FEATURE/sfio.$$$$ FEATURE/sfio

ast_common.h: $(srcdir)/features/common
	$(BINDIR)/iffe - set cc $(CC) $(CCMODE) $(CXFLAGS) : run $(srcdir)/features/common > ast_common.h.$$$$ && mv ast_common.h.$$$$ ast_common.h

$(OBJS):  ast_common.h FEATURE/sfio

$(SFIO_F): ast_common.h  FEATURE/sfio
	cd Sfio_f; $(MAKE) -f Makefile SHELL=$(SHELL) CC="$(CC)" \
		CCMODE="$(CCMODE)" CXFLAGS="$(CXFLAGS)" $(MFLAGS) $(@F)
$(STDIO_S): ast_common.h  FEATURE/sfio
	cd Stdio_s; $(MAKE) -f Makefile SHELL=$(SHELL) CC="$(CC)" \
		CCMODE="$(CCMODE)" CXFLAGS="$(CXFLAGS)" $(MFLAGS) $(@F)
$(SFIO_DC): ast_common.h FEATURE/sfio
	cd Sfio_dc; $(MAKE) -f Makefile SHELL=$(SHELL) CC="$(CC)" \
		CCMODE="$(CCMODE)" CXFLAGS="$(CXFLAGS)" $(MFLAGS) $(@F)

clean:
	-rm -f FEATURE/* $(OBJS) ast_common.h libsfio.a
	cd Sfio_f; $(MAKE) -f Makefile SHELL=$(SHELL)  $(MFLAGS) clean
	cd Stdio_s; $(MAKE) -f Makefile SHELL=$(SHELL) $(MFLAGS) clean
	cd Stdio_b; $(MAKE) -f Makefile SHELL=$(SHELL) $(MFLAGS) clean
	cd Sfio_dc; $(MAKE) -f Makefile SHELL=$(SHELL) $(MFLAGS) clean
