# Makefile for GNU C++ class library (libg++)
#   Copyright (C) 1989, 1992, 1993 Free Software Foundation, Inc.
#   written by Doug Lea (dl@rocky.oswego.edu)

#This file is part of GNU libg++.

#GNU libg++ 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 1, or (at your option)
#any later version.

#GNU libg++ 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 libg++; see the file COPYING.  If not, write to the Free
#Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

srcdir = .

# We specify exactly what we want to pass down; don't let GNU make
# 3.63 overload the command line.
MAKEOVERRIDES=

###**######################################################################
#
# Directories, paths, compilation flags and program names.
#
# If a macro needs to have a different value, then change it in the
# site/architecture specific makefile in the directory config !
#
# This file contains the documentation for the macros and possible values.
# Don't remove them even, if they are only comments !

VERSION = 2.7.2
LIBG++_DIST_VERSION = $(VERSION)

# ------- System-dependent defines

# g++ so specific flags
OSFLAG=

# ld or ld++ os specific libraries
#OSLIBS =

# Comment out the next line to disable incremental linking test
# (this test NOT included in 1.39.0, so don't re-enable) ??? H.S.
#TEST0=test0
#TEST0=

# targets for test-install
TEST_INSTALL 		= test-90S-then-clean # test-90D-then-clean
VERIFY_GXX_INSTALLATION = foo_main # dfoo_main


# You can override gperf to not build it at all
GPERF = gperf
NON_IO_SUBDIRS	=  genclass src $(GPERF) utils tests etc test-install
SUBDIRS	=  $(NON_IO_SUBDIRS)
ALL_SUBDIRS = $(NON_IO_SUBDIRS) old-stream no-stream

UTILS   =  # utils

# C++ compiler to use when testing that installation has succeeded.
INSTALLED_CXX=$(bindir)/gcc

ARLIB   = libg++.a
SHLIB   = libg++.so.$(VERSION)
SHARLIB = libg++-sh.a
SHLINK  = libg++.so
MSHLINK = foo
SHFLAGS =
SHDEPS  = -L../libstdc++ -lstdc++ -lm -lc

BUILD_LIBS = $(ARLIB)

RX_OBJ  = ../librx/rx.o

#### package, host, target, and site dependent Makefile fragments come in here.
##

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

###**######################################################################
#
# compilation actions

.PHONY: rest-in-parallel
rest-in-parallel: .stmp-genclass .stmp-tests .stmp-etc .stmp-gperf .stmp-utils

libs: $(BUILD_LIBS)

# FIXME: Need to multilib librx.
list: src/libgxx.list $(RX_OBJ)
	-rm -f tlist
	touch tlist
	for f in `cat src/libgxx.list`; do \
	  echo "src/$$f" >> tlist ; \
	done
	echo "$(RX_OBJ)" >> tlist
	mv tlist list

piclist: list
	-rm -f piclist
	if [ -z "$(PICFLAG)" ]; then \
	  cp list piclist; \
	else \
	  sed 's,\([0-9A-Za-z_]*\.o\),pic/\1,g' list > piclist ; \
	fi

$(ARLIB): list
	-rm -f t$(ARLIB)
	$(AR) $(AR_FLAGS) t$(ARLIB) `cat list`
	mv t$(ARLIB) $(ARLIB)
	$(RANLIB) $(ARLIB)

$(SHLIB): piclist ../libstdc++/piclist
	$(CC) $(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 -f $(SHLIB) $(SHLINK)

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

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

../librx/rx.o: $(srcdir)/../librx/rx.c
	rootme=`pwd`/ ; export rootme ; cd ../librx; \
		$(MAKE) $(FLAGS_TO_PASS) rx.o

.PHONY: installcheck
installcheck: check

.stmp-genclass: $(BUILD_LIBS)
	@rootme=`pwd`/ ; export rootme ; cd genclass ; \
	  $(MAKE) $(FLAGS_TO_PASS) "gxx_includedir=$(gxx_includedir)"
	touch $@

.stmp-tests: $(BUILD_LIBS)
	@if [ -f tests/Makefile ]; then \
	   rootme=`pwd`/ ; export rootme ; cd tests ; \
	      $(MAKE) $(FLAGS_TO_PASS); \
	 else true; fi
	touch $@

.stmp-etc: $(BUILD_LIBS)
	@rootme=`pwd`/ ; export rootme ; cd etc ; \
	  $(MAKE) $(FLAGS_TO_PASS)
	touch $@

.stmp-gperf: $(BUILD_LIBS)
	@if [ "x$(GPERF)" != "x" ]; then \
	   rootme=`pwd`/ ; export rootme ; cd $(GPERF) ; \
	      $(MAKE) $(FLAGS_TO_PASS); \
	 else true; fi
	touch $@

.stmp-utils: $(BUILD_LIBS)
	@if [ "x$(UTILS)" != "x" ]; then \
	   rootme=`pwd`/ ; export rootme ; cd $(UTILS) ; \
	     $(MAKE) $(FLAGS_TO_PASS); \
	 else true; fi
	touch $@

#
#
# Installation
#

.PHONY: install
install:
	@if [ -f $(gxx_includedir)/unistd.h ] ; then echo; \
	  echo '*** You seem to have files in $(gxx_includedir)/g++-include'; \
	  echo '*** left over from an old release of libg++.  These must be removed.'; \
	  echo '*** Please see $(srcdir)/README for more information.'; \
	  echo; \
	else \
	  true; \
	fi
	rootme=`pwd`/ ; export rootme ; \
	for FILE in $(BUILD_LIBS) ; do \
	  rm -f $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  if [ $$FILE = $(SHLINK) ] || [ $$FILE = $(MSHLINK) ]; then \
	    ln -s -f $(SHLIB) $(INSTALLDIR)$(MULTISUBDIR)/$$FILE ; \
	  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
	@for D in src genclass $(UTILS) ; do \
		if [ -d $$D ] ; then \
			(rootme=`pwd`/ ; export rootme ; cd $$D;\
			  $(MAKE) $(FLAGS_TO_PASS) "gxx_includedir=$(gxx_includedir)" install) ; \
		else true ; \
		fi ; \
	done
	if [ "x$(GPERF)" != "x" ]; then \
	  rootme=`pwd`/ ; export rootme ; cd gperf ;\
	    $(MAKE) $(FLAGS_TO_PASS) install; \
	else true; fi
	@rootme=`pwd`/ ; export rootme ; \
	$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=install

installcheck:
	if [ "x$(TEST_INSTALL)" != "x" ]; then \
	  cd test-install; $(MAKE) $(TEST_INSTALL) \
	      CXX=$(INSTALLED_CXX) "CXXFLAGS=$(CXXFLAGS)" \
	      COMPILE_FLAGS="" LIBS=-lg++; \
	else true; fi

DIST_NAME = libg++-$(LIBG++_DIST_VERSION)

$(DIST_NAME).tar.gz: dist

# Making a dist:
# cvs rtag libgxx-x-yy libg++
# cvs co -r libgxx-x-yy libg++
# Sanitize
# cd {HERE}/..
# make -f Makefile.in libg++.tar.gz

diststuff: info g++FAQ.txt

g++FAQ.txt: $(srcdir)/g++FAQ.texi
	$(MAKEINFO) --no-split --no-headers $< -o - \
	  | sed -e '/^Concept Index/,$$d' \
	     -e 's|Making info file `[---]|Making info file `g++FAQ.txt|' \
	  >$@

# Preprocess the texi file so that the final document will have
# hyperlinks.
# It would be nice if texi2html could do something like this itself.
# Assumption 1: the FAQ puts all http: and ftp: links in a @file{...}.
# Assumption 2: email addresses match the regexp shown.

g++FAQ.html:	$(srcdir)/g++FAQ.texi
	mkdir work
	sed -e 's?@file{\([fth]*p://[^}]*\)}?@strong{<A HREF="\1">\1</A>}?' \
	    -e 's?\([.+a-zA-Z0-9-]*@@[.a-zA-Z0-9-]*[a-zA-Z0-9]\)?<A HREF="mailto:\1">\1</A>?' \
	    $< > work/g++FAQ.texi
	cd work; texi2html g++FAQ.texi
	mv work/*.html .
	rm -r work

force:
.PHONY: $(SUBDIRS) dist force
