######################################################################
#
#  Name ........................................ src/c_kernel makefile 
#
#  Architecture : sparc7, sparc8, mips, linux, hp, os2
#  Compiler     : gcc, g++ 
#  Flags        : -g -O2
#  Program Flags: -DDEBUG, -DMEMORY, -DERRIGN 
#  Author       : Papanikolaou Thomas & Stefan Neis
#  Release      : 1.0 
#  Last Change  : Mon Apr 11 16:09:08 MET DST 1994 
#  Copyright    : by the University of Saarland, 1994 
#

#
# include the configuration file
#

include ../../../config/CONFIG

#
# Variables
#

#
# Digit functions, C-versions
#

CDOBJ=idigit.o idigitvec.o idigitkara.o

#
# Integer functions
#

IOBJ=imem.o iadd.o ibit.o idiv.o igcd.o iio.o ilib.o imul.o iutil.o

#
# Functions for random numbers and time measurements
#

ROBJ=irandom.o timing.o $(HAS_RANDOM)

#
# Modular arithmetic for odd Modulus, based on Montgomerys
# multiplication technique.
#

MOBJ=imod.o

#
# flag for static linking:
#STATIC=-static
#

STATIC=

#
# Rules
#

.c.o:
	$(CC) -c $(CFLAGS) $(KERNEL_FLAGS) -I$(LIDIA_INC) $<

default:
	cd C $(SEP) make
	make DOBJ=C/*.o $(libp)LiDIA.a

all:	$(libp)LiDIA.a

appl:	itest$(EXE) itimes$(EXE) mtest$(EXE)

#
#	
#

#C version
c:
	cd C $(SEP) make
	make DOBJ=C/*.o $(libp)LiDIA.a

#Dec Alpha
alpha:
	cd C $(SEP) make
	make DOBJ=C/*.o $(libp)LiDIA.a

rs6000:
	cd C $(SEP) make
	make DOBJ=C/*.o $(libp)LiDIA.a

#HP-UX
hppa1.1:
	cd C $(SEP) make
	make DOBJ=C/*.o $(libp)LiDIA.a

#intel 386
i386:
	cd Intel486 $(SEP) make
	make DOBJ=Intel486/*.o $(libp)LiDIA.a

#intel 486
i486:
	cd Intel486 $(SEP) make
	make DOBJ=Intel486/*.o $(libp)LiDIA.a

#intel pentium
i586:
	cd Intel486 $(SEP) make
	make DOBJ=Intel486/*.o $(libp)LiDIA.a

#OS/2
os2:
	cd Intel486 $(SEP) make
	cd Intel486 $(SEP) $(AR) $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a *.o
	$(RANLIB) $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a 
	make DOBJ= $(libp)LiDIA.a
# Special handling of the subdirectory to avoid the prefix
# Intel486 when naming library files (because names are
# truncated after 13 letters by 'ar')

sparc:
	cd Sparc7 $(SEP) make
	make DOBJ=Sparc7/*.o $(libp)LiDIA.a

sparc7:
	cd Sparc7 $(SEP) make
	make DOBJ=Sparc7/*.o $(libp)LiDIA.a

sparc8:
	cd Sparc8 $(SEP) make
	make DOBJ=Sparc8/*.o $(libp)LiDIA.a

mips:
	cd Mips $(SEP) make 
	make DOBJ="Mips/*.o" $(libp)LiDIA.a

#
# Dependencies
#

idigit.o:	iint.h idigit.h
idigitvec.o:	iint.h idigit.h
idigitkara.o:	iint.h idigit.h

imem.o:		iint.h imem.h
iadd.o:		iint.h idigit.h imem.h
ibit.o:		iint.h idigit.h imem.h
idiv.o:		iint.h idigit.h imem.h
igcd.o:		iint.h idigit.h imem.h
iio.o:		iint.h idigit.h imem.h
ilib.o:		iint.h idigit.h imem.h
imul.o:		iint.h idigit.h imem.h
iutil.o:	iint.h idigit.h imem.h

irandom.o: 	iint.h imem.h timing.h
timing.o:	timing.h

imod.o:		imod.h iint.h idigit.h timing.h

#
# The library of all these functions
#

$(libp)LiDIA.a:	$(DOBJ) $(IOBJ) $(ROBJ) $(MOBJ) $(CCOBJ)
	$(AR) $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a $(DOBJ) $(IOBJ) $(ROBJ) $(MOBJ) $(CCOBJ)
	$(RANLIB) $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a 

#
# Test of some of the functions with random numbers
#

itest$(EXE):		$(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a iint.h itest.o
	$(CC) $(CFLAGS) $(STATIC) -o itest$(EXE) itest.o $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a $(C_LIB)

itimes$(EXE):		$(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a iint.h itimes.o
	$(CC) $(CFLAGS) $(STATIC)  -o itimes$(EXE) itimes.o $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a $(C_LIB)

mtest$(EXE):		$(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a iint.h imod.h mtest.o
	$(CC) $(CFLAGS) $(STATIC) -o mtest$(EXE) mtest.o $(LIDIA_LIB)$(DIRSEP)$(libp)LiDIA.a $(C_LIB)

#
# Installation commands
#

install:        installh

installh:	iint.h timing.h imod.h 
	$(CP) iint.h $(LIDIA_INC)$(DIRSEP)LiDIA 
	$(CHMOD) 644  $(LIDIA_INC)$(DIRSEP)LiDIA$(DIRSEP)iint.h
	$(CP) timing.h  $(LIDIA_INC)$(DIRSEP)LiDIA
	$(CHMOD) 644  $(LIDIA_INC)$(DIRSEP)LiDIA$(DIRSEP)timing.h
	$(CP) imod.h  $(LIDIA_INC)$(DIRSEP)LiDIA
	$(CHMOD) 644  $(LIDIA_INC)$(DIRSEP)LiDIA$(DIRSEP)imod.h

#
# Clean
#

clean:
	-cd C $(SEP) make clean
	-cd Sparc7 $(SEP) make clean
	-cd Sparc8 $(SEP) make clean
	-cd Mips $(SEP) make clean
	-cd Intel486 $(SEP) make clean
	-$(RM) *.o *% *.out mtest$(EXE) itest$(EXE) itimes$(EXE)

veryclean:	clean
