#!/bin/sh
#
# Created by  B. David Saunders <saunders@cis.udel.edu>
# Modified by G. Villard <Gilles.Villard@ens-lyon.fr> 
#   mar mai  6 18:15:17 CEST 2003
#   dim aou  3 01:22:55 CEST 2003

#####################################################################################   
# This Readme-make is actually a makefile illustrating two ways (A and B below)
# to compile programs which use LinBox.  
#
# Usage: "make -f Readme-make <file>"
#####################################################################################   
#
# Linbox is a C++ template source library using a two level directory structure.
# To include a linbox file write "#include <linbox/subdir/file.h>".
# For compiling code using linbox, three issues arise.
# 1. location of LinBox include directory (which contains linbox/subdir/file.h).
# 2. location of LinBox lib directory.  Some components of LinBox ( those in linbox/util/ ) 
#    are separately compiled and installed in this library.  It is possible to include 
#    sources from linbox/util/ rather than linking to this library.  Compile 
#    with "-DLinBoxSrcOnly".
# 3. LinBox depends on other packages for some of it's functionality.  The compiler must
#    find the include files and library objects for these packages.  
#    Of these GMP is necessary, the others are optional.
#
#   This makefile illustrates two ways to proceed (A and B below).
#
# ----> In both cases REPLACE ".." below with your LinBox top directory 
# e.g. LINBOX=/home/gvillard/Soft/linbox

LINBOX=@prefix@

# ---->  And put here your compiler's name and options

#CCC=g++
CPPFLAGS= -O0
LDFLAGS=


#########################################################################################
# A. 
#
# If your LinBox library is compiled, normally the rest of this makefile 
# needn't be modified.
#
# If the LinBox library is compiled, use `$(LINBOX_BIN)/linbox-config --cflags --libs`
# on the compile command to get the include and lib locations for LinBox and the 
# other packages it uses that were available when it was installed.  
# This is the simplest way to proceed.  
# This approach is used here for targets whose source suffix is .C
#

# no /bin if LinBox is uncompiled
LINBOX_BIN=$(LINBOX)/bin
#LINBOX_BIN=@bindir@

%:%.C 
	$(CXX) $(CPPFLAGS) $*.C -o $*  $(shell $(LINBOX_BIN)/linbox-config --cflags --libs)

CXXFLAGS+= $(shell $(LINBOX_BIN)/linbox-config --cflags)
LOADLIBES+= $(shell $(LINBOX_BIN)/linbox-config --libs)

#########################################################################################
# B. 
# You can compile from LinBox sources even without compiling LinBox.  This approach is used 
# in this makefile example for targets whose source suffix is .cc or .cpp.
# You must first indicate in this makefile the locations of LinBox and the packages used.

# ----> Simply REPLACE ".." below with your LinBox top and packages directories

GMP=..
#NTL=..
#GIVARO=..
#LIDIA=..
#SACLIB=..

# e.g.
#GMP=/usr/local/algebra/gmp
#NTL=/usr/local/algebra/ntl
#GIVARO=/usr/local/algebra/givaro
#LIDIA=/usr/local/algebra/lidia
#SACLIB=/usr/local/algebra/saclib


######################################################################################
# Normally the rest of this makefile needn't be modified.  Change remaining definitions 
# only when, in your installations, the includes or libs are not in the indicated places.
######################################################################################

LINBOX_INCL= -I$(LINBOX) -DLinBoxSrcOnly

# GMP is a necessary component, used throughout LinBox.
GMP_INCL= -I$(GMP)/include 
GMP_LIB= -L$(GMP)/lib -lgmp 
GMP_RLIB= -R$(GMP)/lib -lgmp 

# NTL is an optional component, used in a number of field classes.
NTL_INCL= -I$(NTL)/include 
NTL_LIB= -L$(NTL)/lib -lntl

# GIVARO is an optional component, used for instance in the Zech log fields
GIVARO_INCL= -I$(GIVARO)/include 
GIVARO_LIB= -L$(GIVARO)/lib 

# LIDIA is an optional component.
LIDIA_INCL= -I$(LIDIA)/include 
LIDIA_LIB= -L$(LIDIA)/lib 

# SACLIB is an optional component, not currently used.
SACLIB_INCL= -I$(SACLIB)/include 
SACLIB_LIB= -L$(SACLIB)/lib 

INCL= $(LINBOX_INCL) $(GMP_INCL) 
INCL+=$(NTL_INCL) $(GIVARO_INCL) $(LIDIA_INCL) $(SACLIB_INCL)

LIB= $(LINBOX_LIB) $(GMP_LIB) 
LIB+= $(NTL_LIB) $(GIVARO_LIB) $(LIDIA_LIB) $(SACLIB_LIB)
# fixme: this is udel specific.  
RLIB= $(LINBOX_RLIB) $(GMP_RLIB) -R/usr/local/gnu/gcc/lib

%:%.cc
	$(CCC) $(CPPFLAGS) $(LDFLAGS) $*.cc -o $* $(INCL) $(LIB) $(RLIB)
	
# ... or use separate compilation and linkage
%.o:%.cpp 
	$(CCC) $(CPPFLAGS) $(INCL) $*.cpp -c

%:%.o 
	$(CCC) $(LDFLAGS) $*.o -o $* $(LIB)
	
clean:
	rm -f *.o
