# $Id: thesiscd_Makefile,v 1.3 2007/01/25 09:48:53 mcv21 Exp $

# This Makefile is part of the library of graph analysis and disease
# simulation functions submitted along with the thesis "Spatial Spread
# of Farm Animal Diseases" for the degree of Doctor of Philosophy at the
# University of Cambridge
# 
# The library is Copyright (C) 2007 Matthew Vernon <matthew@debian.org>
# 
# 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 of the License,
# 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 program (as gpl.txt); if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA


#You might wish to compile with optimisations turned on instead.
CFLAGS = -fPIC -g -Wall -Werror -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wwrite-strings -Wnested-externs
CC=gcc

LDLIBS=-lm

all: library
.PHONY: all library

UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
 CFLAGS += -Wno-long-double
library: libgsalgs.dylib.0.1
else
library: libgsalgs.so.0.1
LFLAGS =,-soname,libgsalgs.so.0
endif

ifeq ($(UNAME),SunOS)
 CFLAGS += -DSOLARIS -mcpu=v9 -m64
#Override the above lflags
 LFLAGS =,-64,-G,-h,libgsalgs.so.0,-R,/opt/local/lib/sparcv9
 LDFLAGS =-mcpu=v9 -m64
endif

GENNETOBJ=gens.o g_bm.o g_im.o g_al.o g_special.o genalg.o specalg.o census.o io.o utils.o adjlist.o iutil.o
UPOBJ=dll.o fheap.o sll.o stack.o ferror.o fifo.o

libgsalgs.dylib.0.1: $(GENNETOBJ) $(UPOBJ)
	rm -f libgsalgs.so.0
	gcc $(CFLAGS) -dynamiclib $(GENNETOBJ) $(UPOBJ) -current_version 1.0 \
-compatibility_version 1.0 -install_name libgsalgs.dylib.0 \
-o libgsalgs.dylib.0.1
	ln -s libgsalgs.dylib.0.1 libgsalgs.dylib.0

libgsalgs.so.0.1: $(GENNETOBJ) $(UPOBJ)
	rm -f libgsalgs.so.0
	gcc $(CFLAGS) -shared -Wl$(LFLAGS) $(GENNETOBJ) $(UPOBJ)  -o libgsalgs.so.0.1
	ln -s libgsalgs.so.0.1 libgsalgs.so.0

clean:
	rm -f *.o $(UPOBJ) libgsalgs.dylib.* libgsalgs.so.*
