# Copyright (C) 1994, 1995 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.7.0

OBJS = new.o cstring.o stddef.o typeinfo.o exception.o stdexcept.o
SUBLIBS = $(STAMP)-string $(STAMP)-complex

# 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 new stddef string exception stdexcept typeinfo \
	 algorithm deque list map queue set stack vector utility functional \
	 iterator memory numeric

ARLIB   = libstdc++.a
SHLIB   = libstdc++.so.$(VERSION)
SHARLIB = dummy
SHLINK  = libstdc++.so
SHFLAGS = 
SHDEPS  =

STAMP   = bigstmp

LIBS    = $(ARLIB)

IO_DIR    = ../libio
LIBIBERTY = libiberty

LIBIBERTY_OBJS =

#### package, host, target, and site dependent Makefile fragments come in here.
##
CC = gcc
CXX = gcc
CFLAGS = -O -D__ST_MT_ERRNO__
CXXFLAGS = -O -D__ST_MT_ERRNO__
CINCLUDES = -I.
CXXINCLUDES = -I.

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

AR = ar
AR_FLAGS = rcJ
SHELL = sh
STAMP = bigstmp
srcdir = .
PICFLAG =
COMPILE.cc = $(CXX) -c $(XCXXFLAGS) $(CXXINCLUDES)


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

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

# Remove these for public releases.
CXXFLAGS = -g -O3 -Wall -Wpointer-arith -Wnested-externs -Woverloaded-virtual -Wbad-function-cast -pedantic-errors -ansi -Winline
CFLAGS = -g -O3 -Wall -Wpointer-arith -Wnested-externs

.PHONY: libs
libs: $(LIBS)

stdlist: $(IO_DIR)/iostream.list $(OBJS) $(SUBLIBS) 
	-rm -f tlist
	touch tlist
	echo *.o >> tlist
	for f in `cat $(IO_DIR)/iostream.list` ; do \
	  echo "$(IO_DIR)/$$f" >> tlist ; \
	done
	for f in $(LIBIBERTY_OBJS) ; do \
	  echo "../$(LIBIBERTY)/$$f" >> tlist ; \
	done
	mv tlist stdlist

piclist: stdlist stl/stl.list
	-rm -f tlist
	cp stdlist tlist
	sed 's,\([A-Za-z_]*\.o\),stl/\1,g' stl/stl.list >> tlist
	if [ -n "$(PICFLAG)" ]; then \
	  sed 's,\([A-Za-z_]*\.o\),pic/\1,g' tlist > tlist2 ; \
	  mv tlist2 tlist ; \
	fi
	mv tlist piclist

$(ARLIB): stdlist stl/stl.list
	-rm -f t$(ARLIB)
	$(AR) $(AR_FLAGS) t$(ARLIB) `cat stdlist`
	cd stl;  $(AR) $(AR_FLAGS) ../t$(ARLIB) `cat stl.list`
	mv t$(ARLIB) $(ARLIB)
	$(RANLIB) $(ARLIB)

$(SHLIB): piclist
	$(CXX) $(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 -s $(SHLIB) $(SHLINK)

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

stl/stl.list:
	@rootme=`pwd`/ ; export rootme; cd stl ; \
	  $(MAKE) $(FLAGS_TO_PASS) stl.list

../$(LIBIBERTY)/libiberty.a:
	cd ../$(LIBIBERTY) ; $(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

typeinfo.o: ${srcdir}/typeinfo.cc ${srcdir}/std/typeinfo.h
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) ${srcdir}/typeinfo.cc -frtti -o pic/typeinfo.o; \
	fi
	$(COMPILE.cc) ${srcdir}/typeinfo.cc -frtti

stdexcept.o: ${srcdir}/stdexcept.cc ${srcdir}/std/stdexcept.h
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) ${srcdir}/stdexcept.cc -frtti -o pic/stdexcept.o; \
	fi
	$(COMPILE.cc) ${srcdir}/stdexcept.cc -frtti

# 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 [ -n "$(PICFLAG)" ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DC -D$${name} ${srcdir}/sinst.cc \
	      -o pic/c$${name}.o; \
	  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
	echo cstring
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DC \
	    `for N in $(STRFUNCS); do echo " -D$${N}"; done` \
	    $(srcdir)/sinst.cc -o pic/cstrmain.o; \
	fi
	$(COMPILE.cc) -DC `for N in $(STRFUNCS); do echo " -D$${N}"; done` \
	  $(srcdir)/sinst.cc -o cstrmain.o
	echo cstrio
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DC \
	    `for N in $(STRIO); do echo " -D$${N}"; done` \
	    $(srcdir)/sinst.cc -o pic/cstrio.o; \
	fi
	$(COMPILE.cc) -DC `for N in $(STRIO); do echo " -D$${N}"; done` \
	  $(srcdir)/sinst.cc -o cstrio.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-complex: ${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 [ -n "$(PICFLAG)" ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DF -D$${N} $(srcdir)/cinst.cc \
	      -o pic/f$${N}.o; \
	  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 [ -n "$(PICFLAG)" ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DD -D$${N} $(srcdir)/cinst.cc \
	      -o pic/d$${N}.o; \
	  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 [ -n "$(PICFLAG)" ]; then \
	    $(COMPILE.cc) $(PICFLAG) -DLD -D$${N} $(srcdir)/cinst.cc \
	      -o pic/ld$${N}.o; \
	  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-complex

bigstmp-complex: ${srcdir}/cinst.cc ${srcdir}/std/complext.h \
	         ${srcdir}/std/complext.cc ${srcdir}/std/dcomplex.h \
	         ${srcdir}/std/ldcomplex.h
	echo fcomplex
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DF \
	    `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/fcomplex.o; \
	fi
	$(COMPILE.cc) -DF `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o fcomplex.o
	echo fcomio
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DF \
	    `for N in $(COMIO); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/fcomio.o; \
	fi
	$(COMPILE.cc) -DF `for N in $(COMIO); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o fcomio.o
	echo dcomplex
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DD \
	    `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/dcomplex.o; \
	fi
	$(COMPILE.cc) -DD `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o dcomplex.o
	echo dcomio
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DD \
	    `for N in $(COMIO); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/dcomio.o; \
	fi
	$(COMPILE.cc) -DD `for N in $(COMIO); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o dcomio.o
	echo ldcomplex
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DLD \
	    `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/ldcomplex.o; \
	fi
	$(COMPILE.cc) -DLD `for N in $(COMFUNCS); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o ldcomplex.o
	echo ldcomio
	if [ -n "$(PICFLAG)" ]; then \
	  $(COMPILE.cc) $(PICFLAG) -DLD \
	    `for N in $(COMIO); do echo " -D$${N}"; done` \
	    $(srcdir)/cinst.cc -o pic/ldcomio.o; \
	fi
	$(COMPILE.cc) -DLD `for N in $(COMIO); do echo " -D$${N}"; done` \
	  $(srcdir)/cinst.cc -o ldcomio.o
	touch bigstmp-complex

.PHONY: install
install:
	cd $(srcdir); \
	for FILE in $(HEADERS) *.h std/*.*; do \
		rm -f $(gxx_includedir)/$$FILE ; \
		$(INSTALL_DATA) $$FILE $(gxx_includedir)/$$FILE ; \
		chmod a-x $(gxx_includedir)/$$FILE ; \
	done
	rootme=`pwd`/; export rootme; cd $(srcdir)/stl; \
	for FILE in *.h; do \
		rm -f $(gxx_includedir)/$$FILE ; \
		$(INSTALL_DATA) $$FILE $(gxx_includedir)/$$FILE ; \
		chmod a-x $(gxx_includedir)/$$FILE ; \
	done
	for FILE in $(LIBS) ; do \
		rm -f $(INSTALLDIR)/$$FILE ; \
		$(INSTALL_DATA) $$FILE $(INSTALLDIR)/$$FILE ; \
		if [ $$FILE = $(ARLIB) ] ; then \
			$(RANLIB) $(INSTALLDIR)/$$FILE ; \
		elif [ $$FILE = $(SHLINK) ] ; then \
			ln -s $(INSTALLDIR)/$(SHLIB) $(INSTALLDIR)/$$FILE ; \
		fi ; \
		chmod a-x $(INSTALLDIR)/$$FILE ; \
	done

.PHONY: force
force:

stamp-picdir:
	if [ -n "$(PICFLAG)" ] && [ ! -d pic ]; then \
	  mkdir pic; \
	fi
	touch stamp-picdir
