#-----------------------------------------------------------------------
# Makefile for sort subroutines               Steve Chappell
# Last edited 20th Mar 1998
#-----------------------------------------------------------------------


#Subroutine Libraries.

LIB = ../sunsort_lib/libsortsubs.a
LIBDBX = ../sunsort_lib/libdbx_sortsubs.a

#Misc subroutine sources

OBJECTS1 = detector.o structure.o properties.o fortprop.o loadadcs.o markhits.o
OBJECTS2 = rp.o nrp.o reac.o files.o crhit.o nrhit.o corr.o event_dump.o coord.o missing_p.o

OBJECTS = $(OBJECTS1) $(OBJECTS2)
EXTRAOBJECTS = event-struct/ev.o event-struct/wrtev.o simulations/scanga.o simulations/scanga_inputs.o
#simulations/scanga.o

# Compiler flags etc.

COPTFLAGS = $(OPTFLAG)
FOPTFLAGS = -O4
FFLAGS = $(FOPTFLAGS) -e
CFLAGS = $(COPTFLAGS) -I../sunsort_lib -I../sunsort_src

# Standard targets.

$(LIB): $(OBJECTS) $(EXTRAOBJECTS)
	ar rv $(LIB) $(OBJECTS) $(EXTRAOBJECTS)
	@echo "make $(LIB) ... completed"

$(LIBDBX): $(OBJECTS) $(EXTRAOBJECTS)
	ar rv $(LIBDBX) $(OBJECTS) $(EXTRAOBJECTS)
	@echo "make $(LIBDBX) ... completed"

install:
	-rm -f $(OBJECTS)
	-test -d optimised || mkdir optimised
	for FILE in $(OBJECTS) ; do ln -s optimised/$$FILE ; done
	(cd event-struct; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) install)
	(cd simulations; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) install)
	$(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) $(LIB)
	-rm -f $(OBJECTS)	
	-test -d debug || mkdir debug
	for FILE in $(OBJECTS) ; do ln -s debug/$$FILE ; done
	(cd event-struct; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) dbx)
	(cd simulations; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) dbx)
	$(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) COPTFLAGS=-g FOPTFLAGS=-g $(LIBDBX)
	@echo "subroutine libraries installed ..."
	(cd simulations; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) program)
	(cd calib-routines; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) install)
	(cd ridgeproj; $(MAKE) CC=$(CC) OPTFLAG=$(OPTFLAG) install)
	@echo "calibration routines installed ..."
	@echo "make sort-subs completed ..."

clean :
	-rm -f *.o optimised/*.o debug/*.o core *~ *% bin/* $(LIB) $(LIBDBX)
	(cd event-struct; $(MAKE) clean)
	(cd simulations; $(MAKE) clean)
	(cd calib-routines; $(MAKE) clean)
	(cd ridgeproj; $(MAKE) clean)

subs.h: event-struct/ev.h reac.h files.h simulations/sim.h coord.h structure.h
detector.o: detector.c structure.h
fortprop.o: fortprop.c structure.h
loadadcs.o: loadadcs.c structure.h loadadcs.h fortprop.h
markhits.o: markhits.c structure.h fortprop.h
properties.o: properties.c structure.h fortprop.h
structure.o: structure.c structure.h properties.h
corr.o: corr.c subs.h
nrp.o: nrp.c subs.h
crhit.o: crhit.c subs.h
rp.o: rp.c subs.h
reac.o: reac.c subs.h
event_dump.o: event_dump.c subs.h
coord.o: coord.c subs.h
missing_p.o: missing_p.c subs.h
