# Copyright (C) 1993 Free Software Foundation
# 
# This file is part of the GNU IO Library.  This library is free
# software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU CC; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

srcdir = .
VERSION = 0.65
#### package, host, target, and site dependent Makefile fragments come in here.
##

INSTALLDIR = $(libdir)

IO_OBJECTS = filedoalloc.o floatconv.o genops.o fileops.o \
  iovfprintf.o \
  iovfscanf.o ioignore.o iopadn.o \
  iofgetpos.o iofread.o iofscanf.o \
  iofsetpos.o iogetline.o \
  ioprintf.o ioseekoff.o ioseekpos.o \
  outfloat.o strops.o iofclose.o iopopen.o ioungetc.o

# These emulate stdio functionality, but with a different name (_IO_ungetc
# instead of ungetc), and using _IO_FILE instead of FILE.
# They are not needed for C++ iostream, nor stdio, though some stdio
# files are build using the same source files (see stdio/configure.in).
# They are needed for iostdio.h.
# iofclose.o is not here, because it is needed for stdio (by pclose).
STDIO_WRAP_OBJECTS =  iofdopen.o iofflush.o iofgets.o iofopen.o iofprintf.o iofputs.o iofwrite.o iogets.o ioperror.o ioputs.o ioscanf.o iosetbuffer.o iosetvbuf.o iosprintf.o iosscanf.o ioftell.o iovsprintf.o iovsscanf.o stdfiles.o

IOSTREAM_OBJECTS = builtinbuf.o filebuf.o fstream.o \
  indstream.o isgetline.o isgetsb.o isscan.o ioextend.o iomanip.o iostream.o \
  osform.o procbuf.o sbform.o sbgetline.o sbscan.o \
  stdiostream.o stdstrbufs.o stdstreams.o stream.o streambuf.o strstream.o \
  PlotFile.o SFile.o parsestream.o pfstream.o editbuf.o

# These files define _IO_read etc, which are just wrappers for read(2) etc.
# They need to be changed to use name-space-clean (e.g. __read) versions
# for each specific libc.
OSPRIM_OBJECTS = ioprims.o iostrerror.o cleanup.o

LIBIOSTREAM_OBJECTS = $(IO_OBJECTS) $(IOSTREAM_OBJECTS) $(OSPRIM_OBJECTS)
LIBIO_OBJECTS = $(IO_OBJECTS) $(STDIO_WRAP_OBJECTS) $(OSPRIM_OBJECTS)

libio.a: _G_config.h $(LIBIO_OBJECTS)
	-rm -rf libio.a
	$(AR) $(AR_FLAGS) libio.a $(LIBIO_OBJECTS)
	$(RANLIB) libio.a

libiostream.a: _G_config.h $(LIBIOSTREAM_OBJECTS)
	-rm -rf libiostream.a
	$(AR) $(AR_FLAGS) libiostream.a $(LIBIOSTREAM_OBJECTS)
	$(RANLIB) libiostream.a

test: test.o libio.a
	$(CC) -o test test.o libio.a
tpipe: tpipe.o libio.a
	$(CC) -o tpipe tpipe.o libio.a

iostream.list: _G_config.h $(LIBIOSTREAM_OBJECTS)
	@echo "$(LIBIOSTREAM_OBJECTS)"> iostream.list

# The CC=$(CXX) is a kludge to force use of gcc.
_G_config.h: ${srcdir}/gen-params
	rootme=`pwd`/ ; export rootme; \
	CC="$(CXX)"; export CC; \
	CXX="$(CXX) $(NOSTDINC) $(CXXFLAGS)"; export CXX; \
	CONFIG_NM="$(NM)"; export CONFIG_NM; \
	$(SHELL) ${srcdir}/gen-params LIB_VERSION=$(VERSION) $(G_CONFIG_ARGS) >tmp-params.h
	mv tmp-params.h _G_config.h

USER_INCLUDES = *.h
install:
	rm -f $(tooldir)/include/_G_config.h ; \
	  $(INSTALL_DATA) _G_config.h $(tooldir)/include/_G_config.h || exit 1;
	cd $(srcdir); \
	for FILE in $(USER_INCLUDES) ; do \
		rm -f $(gxx_includedir)/$$FILE ; \
		$(INSTALL_DATA) $$FILE $(gxx_includedir)/$$FILE ; \
		chmod a-x $(gxx_includedir)/$$FILE ; \
	done
	$(INSTALL_DATA) libiostream.a $(INSTALLDIR)/libiostream.a
	$(RANLIB) $(INSTALLDIR)/libiostream.a
	chmod a-x $(INSTALLDIR)/libiostream.a

c++clean:
	rm -rf $(IOSTREAM_OBJECTS) _G_config.h
	@$(MAKE) $(FLAGS_TO_PASS) "DODIRS=tests" DO=clean subdir_do
