# Copyright (C) 1994, 1995, 1998 Free Software Foundation

# This file is part of the GNU ANSI C++ 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 this library; see the file COPYING.  If not, write to the Free
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

VERSION = 2.8.1.1

OBJS  = cstringi.o stdexcepti.o cstdlibi.o cmathi.o stlinst.o
SUBLIBS = $(STAMP)-string $(STAMP)-complx

# C++ headers with no extension
HEADERS= cassert cctype cerrno cfloat ciso646 climits clocale cmath complex \
	 csetjmp csignal cstdarg cstddef cstdio cstdlib cstring ctime \
	 cwchar cwctype string stdexcept \
	 algorithm deque functional hash_map hash_set iterator list map \
	 memory numeric pthread_alloc queue rope set slist stack utility \
	 vector fstream iomanip iostream strstream iosfwd

ARLIB   = libstdc++.a
SHLIB   = libstdc++.so.$(VERSION)
SHARLIB = libstdc++-sh.a
SHLINK  = libstdc++.so
MSHLINK = libstdc++.so.`echo $(VERSION) | sed 's/\([0-9][.][0-9]\).*/\1/'`
SHFLAGS = 
SHDEPS  =

STAMP   = bigstmp

LIBS    = $(ARLIB)

#### package, host, target, and site dependent Makefile fragments come in here.
##
CC = gcc
CXX = gcc
CFLAGS = -O2 -D__ST_MT_ERRNO__ -DEMX
CXXFLAGS = -O2 -D__ST_MT_ERRNO__ -DEMX
CINCLUDES = -I.
CXXINCLUDES = -I.
COMPILE.cc=$(CXX) -c $(CXXFLAGS) $(CXXINCLUDES)
AR_FLAGS = rcJ

.c.o:
	$(CC) -c $(CFLAGS) $(CINCLUDES) $<
.cc.o:
	$(CXX) -c $(CXXFLAGS) $(CXXINCLUDES) $<

srcdir = .

IO_DIR    = ../libio
LIBIBERTY_DIR = ../libiberty

LIBIBERTY_OBJS = `cat $(LIBIBERTY_DIR)/needed-list` strerror.o

tooldir = $(exec_prefix)/$(target)
INSTALLDIR = $(libdir)

MOSTLYCLEAN_JUNK = *stmp-* tlib*.a *.s *.ii stdlist piclist
CLEAN_JUNK = $(LIBS)


.PHONY: libs
libs: $(LIBS)

stdlist: $(IO_DIR)/iostream.list $(OBJS) $(SUBLIBS) $(LIBIBERTY_DIR)/libiberty.a
	-rm -f tlist
	dir *.o /b >tlist
	sed -f list.sed $(IO_DIR)/iostream.list | tr " " \n | sed -e "s!^!$(IO_DIR)/!" >>tlist
	mv tlist stdlist

piclist: stdlist

$(ARLIB): stdlist
	-rm -f t$(ARLIB)
	$(AR) $(AR_FLAGS) t$(ARLIB) @stdlist
	mv t$(ARLIB) $(ARLIB)
	$(RANLIB) $(ARLIB)

$(SHLIB): piclist
	$(CC) $(LIBCXXFLAGS) $(SHFLAGS) -shared -o $(SHLIB) `cat piclist` $(SHDEPS)

$(SHARLIB): $(SHLIB)
	-rm -f t$(SHARLIB)
	$(AR) $(AR_FLAGS) t$(SHARLIB) $(SHLIB)
	mv t$(SHARLIB) $(SHARLIB)
	$(RANLIB) $(SHARLIB)

$(SHLINK):
	ln -f -s $(SHLIB) $(SHLINK)

mshlink:
	@$(MAKE) $(MSHLINK) "SHLINK=$(MSHLINK)"

$(IO_DIR)/iostream.list:
	cd $(IO_DIR) ; $(MAKE) $(FLAGS_TO_PASS) iostream.list

$(LIBIBERTY_DIR)/libiberty.a:
	cd $(LIBIBERTY_DIR) ; $(MAKE) $(FLAGS_TO_PASS)

STRFUNCS = REP MAIN TRAITS ADDSS ADDPS ADDCS ADDSP ADDSC \
	   EQSS EQPS EQSP NESS NEPS NESP LTSS LTPS LTSP GTSS GTPS GTSP \
	   LESS LEPS LESP GESS GEPS GESP
STRIO	 = EXTRACT INSERT GETLINE

# These are here for SunOS VPATH.
cstringi.o: cstringi.cc
cstdlibi.o: cstdlibi.cc
cmathi.o: cmathi.cc
stdexcepti.o: stdexcepti.cc
stlinst.o: stlinst.cc

# Later do wide strings, too.
stmp-string: ${srcdir}/sinst.cc ${srcdir}/std/bastring.h \
	     ${srcdir}/std/bastring.cc ${srcdir}/std/straits.h
	for name in $(STRFUNCS) $(STRIO); do \
	  echo c$${name}; \
	  if [ x"$(enable_shared)" = xyes ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DC -D$${name} ${srcdir}/sinst.cc \
	      -o pic/c$${name}.o; \
	  else true ; fi; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  $(COMPILE.cc) -DC -D$${name} ${srcdir}/sinst.cc -o c$${name}.o; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	done
	touch stmp-string

bigstmp-string: ${srcdir}/sinst.cc ${srcdir}/std/bastring.h \
	        ${srcdir}/std/bastring.cc ${srcdir}/std/straits.h
	for %n in ($(STRFUNCS) $(STRIO)) do @$(COMPILE.cc) -DC -D%n ${srcdir}/sinst.cc -o c%n.o
	touch bigstmp-string

COMFUNCS = MAIN ADDCC ADDCF ADDFC SUBCC SUBCF SUBFC MULCC MULCF MULFC DIVCC \
	   DIVCF DIVFC PLUS MINUS EQCC EQCF EQFC NECC NECF NEFC ABS ARG POLAR \
	   CONJ NORM COS COSH EXP LOG POWCC POWCF POWCI POWFC SIN SINH SQRT
COMIO    = EXTRACT INSERT

stmp-complx: ${srcdir}/cinst.cc ${srcdir}/std/complext.h \
	      ${srcdir}/std/complext.cc ${srcdir}/std/dcomplex.h \
	      ${srcdir}/std/ldcomplex.h
	for N in $(COMFUNCS) $(COMIO); do \
	  echo f$${N}; \
	  if [ x"$(enable_shared)" = xyes ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DF -D$${N} $(srcdir)/cinst.cc \
	      -o pic/f$${N}.o; \
	  else true ; fi; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  $(COMPILE.cc) -DF -D$${N} ${srcdir}/cinst.cc -o f$${N}.o; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  echo d$${N}; \
	  if [ x"$(enable_shared)" = xyes ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DD -D$${N} $(srcdir)/cinst.cc \
	      -o pic/d$${N}.o; \
	  else true ; fi; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  $(COMPILE.cc) -DD -D$${N} ${srcdir}/cinst.cc -o d$${N}.o; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  echo ld$${N}; \
	  if [ x"$(enable_shared)" = xyes ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DLD -D$${N} $(srcdir)/cinst.cc \
	      -o pic/ld$${N}.o; \
	  else true ; fi; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	  $(COMPILE.cc) -DLD -D$${N} ${srcdir}/cinst.cc -o ld$${N}.o; \
	  if [ $$? -eq 0 ]; then true; else exit 1; fi; \
	done
	touch stmp-complx

bigstmp-complx: ${srcdir}/cinst.cc ${srcdir}/std/complext.h \
	         ${srcdir}/std/complext.cc ${srcdir}/std/dcomplex.h \
	         ${srcdir}/std/ldcomplex.h
	for %n in ($(COMFUNCS) $(COMIO)) do @$(COMPILE.cc) -DF -D%n ${srcdir}/cinst.cc -o f%n.o
	for %n in ($(COMFUNCS) $(COMIO)) do @$(COMPILE.cc) -DD -D%n ${srcdir}/cinst.cc -o d%n.o
	for %n in ($(COMFUNCS) $(COMIO)) do @$(COMPILE.cc) -DLD -D%n ${srcdir}/cinst.cc -o ld%n.o
	touch bigstmp-complx

.PHONY: install
install:
	rootme=`pwd`/ ; export rootme ; \
	if [ -z "$(MULTISUBDIR)" ]; then \
	  cd $(srcdir); \
	  for FILE in $(HEADERS); do \
	    rm -f $(gxx_include_dir)/$$FILE ; \
	    if [ -f stl/$$FILE ]; then \
	      $(INSTALL_DATA) stl/$$FILE $(gxx_include_dir)/$$FILE ; \
	    else \
	      $(INSTALL_DATA) $$FILE $(gxx_include_dir)/$$FILE ; \
	    fi ; \
	    chmod a-x $(gxx_include_dir)/$$FILE ; \
	  done ; \
	  for FILE in *.h std/*.*; do \
	    rm -f $(gxx_include_dir)/$$FILE ; \
	    $(INSTALL_DATA) $$FILE $(gxx_include_dir)/$$FILE ; \
	    chmod a-x $(gxx_include_dir)/$$FILE ; \
	  done ; \
	  cd stl; \
	  for FILE in *.h; do \
	    rm -f $(gxx_include_dir)/$$FILE ; \
	    $(INSTALL_DATA) $$FILE $(gxx_include_dir)/$$FILE ; \
	    chmod a-x $(gxx_include_dir)/$$FILE ; \
	  done ; \
	else true ; \
	fi
	rootme=`pwd`/ ; export rootme ; \
	rm -f $(INSTALLDIR)$(MULTISUBDIR)/$(SHLINK) ; \
	for FILE in $(LIBS) ; do \
	  rm -f $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  if [ $$FILE = $(SHLINK) ] ; then \
	    ln -f -s $(SHLIB) $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  elif [ $$FILE = mshlink ]; then \
	    for FILE in $(MSHLINK) ; do \
	      rm -f $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	      ln -f -s $(SHLIB) $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	    done; \
	  elif [ $$FILE = $(SHLIB) ]; then \
	    $(INSTALL_PROGRAM) $$FILE $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	    : On the HP, shared libraries must be mode 555. ;\
	    chmod 555 $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  else \
	    $(INSTALL_DATA) $$FILE $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	    $(RANLIB) $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	    chmod a-x $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  fi ; \
	done
	@rootme=`pwd`/ ; export rootme ; \
	$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=install

.PHONY: force
force:

.PHONY: stuff
stuff:
	$(MAKE) clean
	$(MAKE) -C ../libio c++clean
	-$(MAKE) $(MAKEFLAGS) check
	-$(MAKE) -C ../libio check
	-$(MAKE) -C ../../gcc check-g++

stuff1:
	$(MAKE) clean
	$(MAKE) -C ../libio c++clean

stuff2:
	-$(MAKE) check
	-$(MAKE) -C ../libio check
	-$(MAKE) -C ../../gcc check-g++
