# Makefile for g++ library version 1.35.0
#   Copyright (C) 1989 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, 675 Mass Ave, Cambridge, MA 02139, USA.

###########################################################################
#
# Directories, paths and program names.
#
# Please make sure these are correct.
#
# You will require write-permission on the destination directories
# in order to `make install'
#

# set `prefix' to something nonnull if you want to install things
# in nonstandard places

prefix =

# libg++.a destination
LIBDIR = $(prefix)/usr/gnu/lib

# executables directory: location to install the genclass class generator
#BINDIR = $(prefix)/usr/gnu
BINDIR = $(prefix)/usr/gnu/bin

# location to install include file directory
IDIR = $(prefix)/usr/gnu/lib/g++-include

# GNU C++ compiler name
GXX = g++

# GNU CC compiler name (needed for some .c files in libg++.a)
CC = gcc

# how to install -- use the second form for SYSV
INSTALL=install -c
#INSTALL=cp

# not used, but convenient for those who preprocess things while compiling
SHELL=/bin/sh

# uncomment, & set PWD to *this* directory if you are not using gnu make
#PWD=

libg++.a:
	(cd src; make GXX="$(GXX)" CC="$(CC)")

all: libg++.a install tests etc gperf

install:  install-libg++ install-genclass install-include-files install-sys-include-files

install-libg++: src/libg++.a
	(cd src; $(INSTALL) libg++.a $(LIBDIR))
	ranlib $(LIBDIR)/libg++.a

install-genclass: genclass
	$(INSTALL) genclass $(BINDIR)

install-sys-include-files:
	-mkdir $(IDIR)/sys
	-cd $(PWD)/g++-include/sys; \
	FILES=`find . -type f -print`; \
	cd $(IDIR)/sys; \
	rm -fr $$FILES; \
	cd $(PWD)/g++-include/sys; \
	FILES=`find . -type f -print`; \
	for file in $$FILES; do \
		rm -f $(IDIR)/$$file; \
		cp $$file $(IDIR)/$$file; \
		chmod 0444 $(IDIR)/$$file; \
		echo $$file installed; \
	done

install-include-files:
	-mkdir $(IDIR)
	-cd $(PWD)/g++-include; \
	FILES=`find . -type f -print`; \
	cd $(IDIR); \
	rm -fr $$FILES; \
	cd $(PWD)/g++-include; \
	FILES=`find . -type f -print`; \
	for file in $$FILES; do \
		rm -f $(IDIR)/$$file; \
		cp $$file $(IDIR)/$$file; \
		chmod 0444 $(IDIR)/$$file; \
		echo $$file installed; \
	done

genclass: genclass.sh
	echo "/^PROTODIR=/c\\" > sedscript
	echo "PROTODIR=$(IDIR)" >> sedscript
	sed < genclass.sh > genclass -f sedscript
	chmod 0755 genclass
	rm -f sedscript

tests: libg++.a 
	(cd tests;	make GXX="$(GXX)" LIBDIR="$(LIBDIR)")

etc: libg++.a 
	(cd etc;	make GXX="$(GXX)" CC="$(CC)" LIBDIR=$(LIBDIR))

gperf: libg++.a 
	(cd gperf;	make GXX="$(GXX)" CC="$(CC)" LIBDIR=$(LIBDIR))

clean:
	(cd src; make clean)
	(cd tests; make clean)
	(cd etc; make clean)
	(cd gperf; make realclean)
	-rm -f genclass libg++.info* libg++.?? libg++.??s libg++.log libg++.toc libg++.*aux
	rm -f *~ src/*~ tests/*~ etc/*~ g++-include/*~ g++-include/sys/*~

# Some helpful things for folks on Suns, from Ron Guilmette
# NOTE: these do not refer to libg++, but might be helpful in configuration
# with MCC/ESKIT systems

SUN_INCLUDE_SUBDIRS=\
	arpa \
	pixrect \
	rpcsvc \
	sun \
	sundev \
	suntool \
	sunwindow \
	sys

# WARNING! If you add sys/time.h to the list below, it will mess up the generation
# of the sun-incl-patches file (see below).

SUN_INCLUDE_FILES=\
	netdb.h \
	signal.h \
	strings.h \
	time.h \
	arpa/inet.h \
	pixrect/memvar.h \
	pixrect/pixfont.h \
	pixrect/pixrect.h \
	pixrect/pixrect_hs.h \
	pixrect/traprop.h \
	rpcsvc/rstat.h \
	sun/fbio.h \
	sundev/kbio.h \
	sundev/msio.h \
	sundev/vuid_event.h \
	suntool/canvas.h \
	suntool/icon.h \
	suntool/icon_load.h \
	suntool/panel.h \
	suntool/scrollbar.h \
	suntool/sunview.h \
	suntool/walkmenu.h \
	suntool/window.h \
	suntool/wmgr.h \
	sunwindow/attr.h \
	sunwindow/notify.h \
	sunwindow/pixwin.h \
	sunwindow/win_cursor.h \
	sys/dir.h \
	sys/fcntl.h \
	sys/ioctl.h \
	sys/stat.h \
	sys/vfs.h \
	sys/wait.h \
	sys/resource.h \
	sys/ttychars.h \
	sys/types.h \
	sys/param.h

sun-include-files:
	cd g++-include; \
	rm -fr $(SUN_INCLUDE_SUBDIRS); \
	mkdir $(SUN_INCLUDE_SUBDIRS); \
	for file in $(SUN_INCLUDE_FILES); do \
		cp /usr/include/$$file ./$$file; \
	done; \
	sh -x ../sun-incl-patches

# Note that there is a problem if you use "diff -re".  The problem is that if
# there are sundirectories, the shell script which is produced fails to have
# the whole (relative) pathname of the files to be edited in the "ed - "
# command lines.  Thus, we have to edit the patches file to put these full
# relative pathnames in.  This is done automagically below.

sun-incl-patches:
	-rm -fr sun-include
	-mkdir sun-include
	cd sun-include; \
	for DIR in $(SUN_INCLUDE_SUBDIRS); do \
		mkdir $$DIR; \
	done
	for FILE in $(SUN_INCLUDE_FILES); do \
		ln g++-include/$$FILE sun-include/$$FILE; \
	done
	-rm -f /tmp/sun-incl-patches /tmp/patches-patches ./sun-incl-patches
	-cd sun-include; \
	diff -re /usr/include . > /tmp/sun-incl-patches
	-rm -fr sun-include
	touch /tmp/patches-patches
	for PATH in $(SUN_INCLUDE_FILES); do \
		BASE=`/usr/bin/basename $$PATH`; \
		echo 's%^ed - '$$BASE'%ed - '$$PATH'%' >> /tmp/patches-patches; \
	done
	sed -f /tmp/patches-patches /tmp/sun-incl-patches > ./sun-incl-patches
	-rm -f /tmp/sun-incl-patches /tmp/patches-patches
