#
###########################
#                         #
#  The Razorback Library  #
#         ,     ,         #
# (C) Andras Aszodi 2000. #
#                         #
###########################
#
# Razorback C library Makefile
# ============================
#
# Supported architectures:-
# 	SGI:-
#		"irix32": N32 ABI, MIPS-III ISA (R4k,R5k,R8k,R10k,R12k)
#		"irix64": N64 ABI, MIPS-IV ISA (R8k,R10k,R12k)
#	PC:-
#		"linux": ELF Linux/GCC
#	Alpha:-
#		"alpha": Tru64 UNIX with native compilers
# 
# Directory layout
# ================
#
# razorback/c: root of the C hierarchy  <--YOU ARE HERE
#  |
#  +-- obj: compilation is performed in its $(ARCH) subdirectories!
#  |   |
#  |   +-- irix32: SGI N32/MIPS-III
#  |   |
#  |   +-- irix64: SGI N64/MIPS-IV
#  |   |
#  |   +-- linux: GCC/Linux ELF
#  |   |
#  |   +-- alpha: Tru64 UNIX
#  |
#  +-- include: contains symlinks to all C utility header files
#  |
#  +-- linalg: linear algebra library source
#  |   |
#  |   +-- incl: header files (*.h)
#  |   |
#  |   +-- src: function definition files (*.c)
#  |
#  +-- stat: statistics library source
#  |   |
#  |   +-- incl: header files (*.h)
#  |   |
#  |   +-- src: function definition files (*.c)
#  |
#  +-- bio: bioinformatics-related library source
#  |   |
#  |   +-- incl: header files (*.h)
#  |   |
#  |   +-- src: function definition files (*.c)
#  |
#  +-- miscutils: miscellaneous OS-related stuff
#      |
#      +-- incl: header files (*.h)
#      |
#      +-- src: function definition files (*.c)

# Usage:
# Invoked from the Razorback library Top Makefile in $RAZORBACK_ROOT.

# The shell
SHELL = /bin/sh

# The platform-dependent macro definitions, made by the configure script
# The ../ things are relative to the c/obj/<ARCH> subdirectory
# where the compilation is done.
include ../../../Makefile.defs

# ---- MAIN RULES ----

# Make the library (both static and shared by default).
all: librazorback.so.$(MAJOR).$(MINOR) librazorback.a

# cleanup
clean:
	rm -f *.a *.so *.so.$(MAJOR) *.so.$(MAJOR).$(MINOR) *.o

# ---- Linear algebra ----

# Source directory
LINALG_SRC = ../../linalg/src

# Object files
LINALG_OBJS = lu.o matrect.o mattri.o vect.o

# double-precision vectors
vect.o: $(LINALG_SRC)/vect.c $(INCLUDE)/vect.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(LINALG_SRC)/vect.c -o $@

# rectangular MxN matrices
matrect.o: $(LINALG_SRC)/matrect.c $(INCLUDE)/matrect.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(LINALG_SRC)/matrect.c -o $@

# symmetric (lower triangular) matrices
mattri.o: $(LINALG_SRC)/mattri.c $(INCLUDE)/mattri.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(LINALG_SRC)/mattri.c -o $@

# LU-decomposition
lu.o: $(LINALG_SRC)/lu.c $(INCLUDE)/lu.h $(INCLUDE)/matrect.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(LINALG_SRC)/lu.c -o $@

# ---- Statistics ----

# Source directory
STAT_SRC = ../../stat/src

# Object files
LIBSTAT_OBJS = cdf.o clu.o histo.o golsav.o kuiperkolms.o pdf.o pdf2.o \
   	paramest.o random.o statprob.o student.o stat2.o spl.o

# Cumulative distribution function
cdf.o: $(STAT_SRC)/cdf.c $(INCLUDE)/cdf.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/cdf.c -o $@

# Simple clustering
clu.o: $(STAT_SRC)/clu.c $(INCLUDE)/clu.h $(INCLUDE)/mattri.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/clu.c -o $@

# Histograms
histo.o: $(STAT_SRC)/histo.c $(INCLUDE)/histo.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/histo.c -o $@

# Golay-Savitzky data and derivative smoothing
golsav.o: $(STAT_SRC)/golsav.c $(INCLUDE)/golsav.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/golsav.c -o $@

# Kuiper's modification of the Kolmogorov/Smirnov statistics
kuiperkolms.o: $(STAT_SRC)/kuiperkolms.c $(INCLUDE)/kuiperkolms.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/kuiperkolms.c -o $@

# Parameter estimation (linear and nonlinear regression)
paramest.o: $(STAT_SRC)/paramest.c $(INCLUDE)/paramest.h \
    	    $(INCLUDE)/vect.h $(INCLUDE)/matrect.h $(INCLUDE)/mattri.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/paramest.c -o $@

# Probability density functions
pdf.o: $(STAT_SRC)/pdf.c $(INCLUDE)/pdf.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/pdf.c -o $@

# 2D probability density
pdf2.o: $(STAT_SRC)/pdf2.c $(INCLUDE)/pdf2.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/pdf2.c -o $@

# Random number generators
random.o: $(STAT_SRC)/random.c $(INCLUDE)/random.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/random.c -o $@

# Useful probabilities for statistics
statprob.o: $(STAT_SRC)/statprob.c $(INCLUDE)/statprob.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/statprob.c -o $@

# "Student's" distribution
student.o: $(STAT_SRC)/student.c $(INCLUDE)/student.h $(INCLUDE)/statprob.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/student.c -o $@

# Simple bivariate statistics (mean, sd, correlation)
stat2.o: $(STAT_SRC)/stat2.c $(INCLUDE)/stat2.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/stat2.c -o $@

# Cubic splines
spl.o: $(STAT_SRC)/spl.c $(INCLUDE)/spl.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(STAT_SRC)/spl.c -o $@

# ---- Bioinformatics ----

# Source directory
BIO_SRC = ../../bio/src

# Object files
LIBBIO_OBJS = dsspread.o gor.o pdbread.o

# DSSP file processing
dsspread.o: $(BIO_SRC)/dsspread.c $(INCLUDE)/dsspread.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(BIO_SRC)/dsspread.c -o $@

# GOR III secondary structure prediction
gor.o: $(BIO_SRC)/gor.c $(INCLUDE)/gor.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(BIO_SRC)/gor.c -o $@

# PDB I/O 
pdbread.o: $(BIO_SRC)/pdbread.c $(INCLUDE)/pdbread.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(BIO_SRC)/pdbread.c -o $@

# ---- Miscellaneous ----

# Source directory
MISCUTILS_SRC = ../../miscutils/src

# Object files
MISCUTILS_OBJS = cmdopt.o cmdlong.o dirfile.o tstamp.o

# Command-line options (multi-character with abbreviations)
cmdlong.o: $(MISCUTILS_SRC)/cmdlong.c $(INCLUDE)/cmdlong.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(MISCUTILS_SRC)/cmdlong.c -o $@

# Command-line options (one-character "classic")
cmdopt.o: $(MISCUTILS_SRC)/cmdopt.c $(INCLUDE)/cmdopt.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(MISCUTILS_SRC)/cmdopt.c -o $@

# directory and filename handling
dirfile.o: $(MISCUTILS_SRC)/dirfile.c $(INCLUDE)/dirfile.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(MISCUTILS_SRC)/dirfile.c -o $@

# Time stamps
tstamp.o: $(MISCUTILS_SRC)/tstamp.c $(INCLUDE)/tstamp.h
	$(CC) $(CFLAGS) $(PIC) -I$(INCLUDE) -c $(MISCUTILS_SRC)/tstamp.c -o $@

# =====================================================

# All C object files together 
RAZORBACK_COBJS = $(LINALG_OBJS) $(LIBSTAT_OBJS) \
    	$(LIBBIO_OBJS) $(MISCUTILS_OBJS)

# List external system libs the DSO might depend on
EXTLIBS = 

# The full Razorback C library DSO
# Symlinks will be built by the installation script
# as recommended in the Linux ELF Howto:-
# librazorback.so -> librazorback.so.MAJOR -> librazorback.so.MAJOR.MINOR
librazorback.so.$(MAJOR).$(MINOR): $(RAZORBACK_COBJS)
	$(CDSO_CMD) $(SONAME) librazorback.so.$(MAJOR) \
	    -o $@ $(RAZORBACK_COBJS) $(EXTLIBS)
	
# Static archive
librazorback.a: $(RAZORBACK_COBJS)
	$(AR) $(ARFLAGS) $@ $(RAZORBACK_COBJS)
