.SUFFIXES :
.SUFFIXES : .a .F90 .f .f90 .mod .c .o

# LSSUB Makefile secondaire

ifeq "$(BASE_ARCH)" "$(EC_ARCH)"
$(error FATAL: EC_ARCH is equal to BASE_ARCH, no compiler architecture is defined, ABORTING)
endif

SHELL = /bin/sh

AR      = s.ar
ZIP     = `which zip`
UNZIP   = `which unzip`

MPCPP   = 
MPF90   = 

STD     = 98
DIAGS   = $(DIAGNOSTIQUE)
DIAGLIB = diag_sq$(STD)_g

INCLUDES = $(DIAGS)/include

LIBS    = $(DIAGS)/lib/$(EC_ARCH)/lib$(DIAGLIB).a

OPTIM   = -O 0 -debug
DEBUG   = $(OPTIM)
CFLAGS  = $(DEBUG)
FFLAGS  = $(DEBUG) -includes $(INCLUDES)/$(EC_ARCH)

FICHIZ  = $(DIAGS)/lib/$(EC_ARCH)/lssub$(STD).f.zip

FCOMP   = s.compile $(FFLAGS) -src
CC      = s.compile $(CFLAGS) -src

FCOMPILE = fcompile.f
CCOMPILE = ccompile.c

default: $(LIBS)

.PRECIOUS: $(LIBS)

.DEFAULT:
	$(UNZIP) -Xo $(FICHIZ) $@

.f.a:
	$(FCOMP) $<
	if [ -f $@ ] ; then /bin/chmod 644 $@ ; fi
	$(AR) rv $@ $*.o
	$(ZIP) $(FICHIZ) $<
	/bin/rm -f $*.o

.c.a:
	$(CC) $<
	if [ -f $@ ] ; then /bin/chmod 644 $@ ; fi
	$(AR) rv $@ $*.o
	$(ZIP) $(FICHIZ) $<
	/bin/rm -f $*.o

.F90.a:
	s.f90 -c $<
	if [ -f $@ ] ; then /bin/chmod 644 $@ ; fi
	$(AR) rv $@ $*.o
	$(ZIP) $(FICHIZ) $<
	/bin/rm -f $*.o

.f90.a:
	$(FCOMP) $<
	if [ -f $@ ] ; then /bin/chmod 644 $@ ; fi
	$(AR) rv $@ $*.o
	$(ZIP) $(FICHIZ) $<
	/bin/rm -f $*.o

.f.o:
	$(FCOMP) $<

.F90.o:
	s.f90 -c $<

.f90.o:
	$(FCOMP) $<

.f90.mod:
	$(FCOMP) $<
	/bin/rm -f $*.o

.c.o:
	$(CC) $<

%.o: %.mod

CDECKS= \
	 divers.c

FDECKS= \
	 alp.f		 cofg.f		 convsub.f 	 coord.f 	 ddl.f \
	 dimgt.f 			 eapl.f		 eof.f		 fastaf.f \
	 fastaf2.f 	 ffgfw2.f 	 fftcray.f 	 fftini.f	 ffwfg2.f \
	 filev.f 	 four2.f 	 gcof.f \
	 gemdiag.f 	 get.f		 ggd.f		 gobits.f	 inctdia.f \
	 interp.f	 ism.f		 label.f 	 lgtst.f 	 lire_arg.f \
	 lowio.f 	 lowio92.f	 lssub.f 	 lwbw.f		 mem.f \
	 mrcdiag.f	 newtim.f  	 paccrn.f 	 pacc92.f	 pael.f \
	 pfa.f		 precon.f	 prob.f 	 put.f  	 rec.f		 sfft.f \
	 spectra.f 	 temperton.f	 trans1d.f	 util.f		vfft.f

F90DECKS= \
	gaussg.F90	util2.F90

f90DECKS= \
	diag_convert_ip123.f90 	diag_toc.f90	filter.f90

MODDECKS= \
	diag_convert_ip123.mod 	diag_toc.mod

convsub.o: convsub.f diag_toc.mod
diag_toc.o: diag_toc.f90 vgrid_descriptors.mod
get.o: get.f diag_toc.mod
util.o: util.f  diag_toc.mod
diag_convert_ip123.mod: diag_convert_ip123.f90
coord.o: coord.f	diag_convert_ip123.mod

#LISTE DES CIBLES DU FICHIER recettes

full: $(FDECKS) $(CDECKS) $(f90DECKS)
#Inclure tous les fichiers .f et .c dans les fichier FCOMPIL et CCOMPIL.
	cat *.f > $(FCOMPILE)
	cat *.f90 > $(F90COMPILE)
	cat *.c > $(CCOMPILE)

# Voir "Managing project with make" de O'Reilly & Associates, 1989,
# pages 51-53, pour les details de ce qui se passe dans ce qui suit
$(LIBS): $(FDECKS) $(CDECKS) $(f90DECKS) $(F90DECKS) $(MODDECKS) \
	$(LIBS)(alp.o)	 	\
	$(LIBS)(cofg.o)	 	\
	$(LIBS)(convsub.o)	\
	$(LIBS)(coord.o)		\
	$(LIBS)(ddl.o)	 	\
	$(LIBS)(diag_convert_ip123.o)		\
	$(LIBS)(diag_toc.o)		\
	$(LIBS)(dimgt.o)		\
	$(LIBS)(divers.o)		\
	$(LIBS)(eapl.o)	 	\
	$(LIBS)(eof.o)	 	\
	$(LIBS)(fastaf.o)		\
	$(LIBS)(fastaf2.o)	\
	$(LIBS)(ffgfw2.o)		\
	$(LIBS)(fftcray.o)	\
	$(LIBS)(fftini.o)		\
	$(LIBS)(ffwfg2.o)		\
	$(LIBS)(filev.o)		\
	$(LIBS)(filter.o)		\
	$(LIBS)(four2.o)		\
	$(LIBS)(gaussg.o)		\
	$(LIBS)(gcof.o)	 	\
	$(LIBS)(gemdiag.o)	\
	$(LIBS)(get.o)	 	\
	$(LIBS)(ggd.o)	 	\
	$(LIBS)(gobits.o)		\
	$(LIBS)(inctdia.o)	\
	$(LIBS)(interp.o)		\
	$(LIBS)(ism.o)	 	\
	$(LIBS)(label.o)		\
	$(LIBS)(lgtst.o)		\
	$(LIBS)(lire_arg.o)	\
	$(LIBS)(lowio.o)		\
	$(LIBS)(lowio92.o)	\
	$(LIBS)(lssub.o)		\
	$(LIBS)(lwbw.o)	 	\
	$(LIBS)(mem.o)	 	\
	$(LIBS)(mrcdiag.o)	\
	$(LIBS)(newtim.o)		\
	$(LIBS)(paccrn.o)		\
	$(LIBS)(pacc92.o)		\
	$(LIBS)(pael.o)	 	\
	$(LIBS)(pfa.o)	 	\
	$(LIBS)(precon.o)		\
	$(LIBS)(prob.o)	 	\
	$(LIBS)(put.o)	 	\
	$(LIBS)(rec.o)	 	\
	$(LIBS)(sfft.o)	 	\
	$(LIBS)(spectra.o)	\
	$(LIBS)(temperton.o) 	\
	$(LIBS)(trans1d.o)	 	\
	$(LIBS)(util.o)	 	\
	$(LIBS)(util2.o)	 	\
	$(LIBS)(vfft.o)

clean:
#Faire un petit menage. On enleve tous les .o
	/bin/rm -f *.o

