# makefile for testing and installing the gnussl library

# version number
VERSION = 0.2.1
NAME = gnussl-$(VERSION)

# global installation directory
prefix = /usr/local

# this is the installation directory for include files
includedir = $(prefix)/include

# this is the installation directory for the C library
libdir = $(prefix)/lib

# installation program

INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)

# library archive program
AR = /usr/local/bin/ar

# if your system does not use ranlib, set this to empty
RANLIB = /usr/local/bin/ranlib

# compiler options
cc = gcc
CC = g++
# flags for building the library
CFLAGS =-g -O
# these are the flags for the test programs: it is suggested that 
# optimization be turned off, otherwise compilation takes a long time
TESTFLAGS = -fhandle-exceptions

########### The following should not need to be changed ###############

SHELL = sh

LIBS = -lm

# file for excluding things from the distribution (not portable)
#EXCLUDE = exclude

MAKE = make cc=$(cc) CC=$(CC) CFLAGS="$(CFLAGS)" \
	includedir=$(includedir) libdir=$(libdir) LIBS="$(LIBS)"

TESTMAKE = make cc=$(cc) CC=$(CC) CFLAGS="$(TESTFLAGS)" \
	includedir=$(includedir) libdir=$(libdir) LIBS="$(LIBS)"

lscmd := $(foreach f,$(wildcard */*.* */Makefile),$(NAME)/$f )

all: C C++

# build the C-library components
C:
	$(MAKE) -C src

# build the C++-library components
C++:

doc:
	$(MAKE) -C docs

dvi:
	$(MAKE) -C docs dvi

check: C-check C++-check

C-check: C
	$(MAKE) -C tests C-check

C++-check: C++
	$(TESTMAKE) -C tests C++-check

install: C++-install C-install

C-install: C
	$(MAKE) INSTALL_DATA=$(INSTALL_DATA) -C src C-install
	$(MAKE) INSTALL_DATA=$(INSTALL_DATA) -C include C-install

C++-install: C++
	$(MAKE) INSTALL_DATA=$(INSTALL_DATA) -C src C++-install
	$(MAKE) INSTALL_DATA=$(INSTALL_DATA) -C array_include install
	$(MAKE) INSTALL_DATA=$(INSTALL_DATA) -C include C++-install

uninstall: 
	$(MAKE) -C include uninstall
	$(MAKE) -C array_include uninstall
	$(MAKE) -C src uninstall

dist:
	$(MAKE) clean
	cd ..; rm -f ../$(NAME) ../$(NAME).tar ../$(NAME).tar.gz
	ln -s `pwd` ../$(NAME)
	chmod -R a+rX ../$(NAME)
	cd ..; tar cvf $(NAME).tar $(lscmd)
	cd ..; tar uvfh $(NAME).tar $(NAME)/COPY*
	cd ..; tar uvfh $(NAME).tar $(NAME)/INSTALL
	cd ..; tar uvfh $(NAME).tar $(NAME)/README
	cd ..; tar uvfh $(NAME).tar $(NAME)/Makefile
	cd ..; tar uvfh $(NAME).tar $(NAME)/tests/output
	cd ..; rm -f $(NAME)
	gzip "../$(NAME).tar"


#	rm -f $(NAME) $(NAME).tar $(NAME).tar.gz
#	echo $(NAME)/$(EXCLUDE) >> $(EXCLUDE)
#	echo $(NAME)/$(NAME) >> $(EXCLUDE)
#	echo $(NAME)/$(NAME).tar >> $(EXCLUDE)
#	chmod -R a+rX `pwd`
#	ln -s `pwd` $(NAME)
#	tar cXvFFfh $(EXCLUDE) $(NAME).tar $(NAME)
#	rm -f $(EXCLUDE) $(NAME)
#	gzip "$(NAME).tar"

clean:
	$(MAKE) -C src clean
	$(MAKE) -C tests clean
	$(MAKE) -C docs clean

