include  $(COSMOSTOP)/site.config


EXTHDRS	      = $(COSMOSINC)/Zcondc.h \
		$(COSMOSINC)/Zcoord.h \
		$(COSMOSINC)/Zdirec.h \
		$(COSMOSINC)/Zearth.h \
		$(COSMOSINC)/Zglobalc.h \
		$(COSMOSINC)/Zmagfield.h \
		$(COSMOSINC)/Zmagfieldtp.h \
		$(COSMOSINC)/Zpos.h \
		$(COSMOSINC)/Zptcl.h \
		$(COSMOSINC)/Ztrack.h \
		$(COSMOSINC)/Zunionmap.h

HDRS	      =


MAKEFILE      = Makefile

OBJS	      = cgeomag.o \
		cmagneticDef.o \
		cprintMagF.o \
		csetMagField.o \
		ctransMagTo.o

PRINT	      = pr

SHELL	      = /bin/sh

SRCS	      = cgeomag.f \
		cmagneticDef.f \
		cprintMagF.f \
		csetMagField.f \
		ctransMagTo.f

SYSHDRS	      =

all:
	make	Checkdir $(LIBRARY) SeeSubDir "TARGET=$@"

clean:
	@rm -f $(OBJS) core  *~ a.out temp*.o temp*.f
	make SeeSubDir "TARGET=$@"


clobber:
	@rm -f $(OBJS) $(LIBRARY) core tags
	make SeeSubDir "TARGET=$@"

depend:
	@mkmf -f $(MAKEFILE) ROOT=$(ROOT)
	make SeeSubDir "TARGET=$@"

echo:
	@echo $(HDRS) $(SRCS)
	make SeeSubDir "TARGET=$@"

extract:
	@ar x $(LIBRARY)


index:
	@ctags -wx $(HDRS) $(SRCS)
	make SeeSubDir "TARGET=$@"

install:	$(LIBRARY)
		@echo "****" Installing $(LIBRARY) into $(DEST)
		$(INSTALL) -f  $(DEST) $(LIBRARY)
		@echo "****" Installing Template files into $(TEMPLATE)
		cp -r  $(COSMOSTOP)/Data  $(COSMOSTOP)/Util *
		 $(COSMOSTOP)/UserHook  $(COSMOSTOP)/Scrpt *
		 $(COSMOSTOP)/Doc        $(TEMPLATE)/
		cp $(COSMOSTOP)/site.config $(TEMPLATE)/
		@echo "****" Installing header files into $(HEADER)
		cp -r $(COSMOSTOP)/cosmos  $(HEADER)/
		@echo "****" Installation ended.
		@echo "****" Owner and group should be changed by hand

print:
	@$(PRINT) $(HDRS) $(SRCS)
	make SeeSubDir "TARGET=$@"

tags:           $(HDRS) $(SRCS)
	@ctags $(HDRS) $(SRCS)
	make SeeSubDir "TARGET=$@"


Checkdir:
	@( cd $(COSMOSTOP)/lib; if [ ! -d  $(ARCH) ]; then  mkdir $(ARCH); fi)



SeeSubDir:
	@for i in  * \
	;do   \
		if [ -d  $$i ] ; then \
			(cd $$i; \
			if [ -f Makefile  -a  $$i != Test \
			-a $$i != Util -a $$i != UC  \
	                -a $$i != Ana  -a $$i != Ceren \
	                -a $$i != Data  -a $$i != cosmos \
	                -a $$i != Misc  -a $$i != MuUg \
	                -a $$i != Obso  -a $$i != TeX \
	                -a $$i != lib  -a $$i != UserHook \
	                -a $$i != Doc  -a $$i != Betterone \
	                -a $$i != Scrpt -a $$i != NotForExport ] ; then \
		            $(MAKE) $(TARGET) \
			;fi) \
		; fi \
	done
###
$(LIBRARY)(cgeomag.o): $(COSMOSINC)/Zglobalc.h \
	$(COSMOSINC)/Zcoord.h \
	$(COSMOSINC)/Zunionmap.h \
	$(COSMOSINC)/Zmagfield.h \
	$(COSMOSINC)/Zearth.h
$(LIBRARY)(cmagneticDef.o): $(COSMOSINC)/Ztrack.h \
	$(COSMOSINC)/Zcondc.h \
	$(COSMOSINC)/Zptcl.h \
	$(COSMOSINC)/Zunionmap.h \
	$(COSMOSINC)/Zcoord.h \
	$(COSMOSINC)/Zpos.h \
	$(COSMOSINC)/Zdirec.h \
	$(COSMOSINC)/Zmagfield.h
$(LIBRARY)(cprintMagF.o): $(COSMOSINC)/Zmagfield.h \
	$(COSMOSINC)/Zunionmap.h
$(LIBRARY)(csetMagField.o): $(COSMOSINC)/Zmagfield.h \
	$(COSMOSINC)/Zunionmap.h \
	$(COSMOSINC)/Zmagfieldtp.h
$(LIBRARY)(ctransMagTo.o): $(COSMOSINC)/Zcoord.h \
	$(COSMOSINC)/Zunionmap.h \
	$(COSMOSINC)/Zmagfield.h \
	$(COSMOSINC)/Zglobalc.h

$(LIBRARY):         \
               $(LIBRARY)(cgeomag.o) \
               $(LIBRARY)(cmagneticDef.o) \
               $(LIBRARY)(cprintMagF.o) \
               $(LIBRARY)(csetMagField.o) \
               $(LIBRARY)(ctransMagTo.o) 
