##############################################
# Makefile for Astronomical Almanac software #
##############################################

##############################
# define variables and paths #
##############################

#	tell make what default target is

ALMANAC : almanac

CC = gcc
LD = gcc

# where the executables go

BIN = /home/mhd/craig/bin

# where the gcc stuff is located

GCCHEAD = /usr/local/export/gnu

# where the include files are

HPATH = ../h

# where the libraries are located

LPATH = ../lib

# the almanac library

AALIB = $(LPATH)/aalib.a

CFLAGS = -O -I/usr/5include -I$(HPATH)

CFILES	= altaz.c angles.c annuab.c cmoon.c constel.c deflec.c deltat.c \
	diurab.c diurpx.c dms.c epsiln.c fk4fk5.c kepler.c kfiles.c \
	lightt.c lonlat.c nutate.c precess.c refrac.c rplanet.c rstar.c \
	sidrlt.c sun.c trnsit.c vearth.c oearth.c manoms.c \
	ojupiter.c omars.c omercury.c oneptune.c osaturn.c ouranus.c \
	ovenus.c cnstinit.c matan2.c kep.h aaproto.h satellite.h

OFILES	= altaz.o angles.o annuab.o cmoon.o constel.o deflec.o deltat.o \
	diurab.o diurpx.o dms.o epsiln.o fk4fk5.o kepler.o kfiles.o \
	lightt.o lonlat.o nutate.o precess.o refrac.o rplanet.o rstar.o \
	sidrlt.o sun.o trnsit.o vearth.o oearth.o manoms.o \
	ojupiter.o omars.o omercury.o oneptune.o osaturn.o ouranus.o \
	ovenus.o cnstinit.o matan2.o

# Set the include file directory search path

vpath %.h $(HPATH)

################
# Dependencies #
################

kepler.o kfiles.o lightt.o rplanet.o rstar.o sun.o vearth.o aa.o : kep.h
oearth.o ojupiter.o omars.o omercury.o oneptune.o osaturn.o : kep.h
ouranus.o ovenus.o : kep.h

aa.o $(OFILES) : aaproto.h

altaz.o cmoon.o deflec.o deltat.o diurab.o diurpx.o dms.o : satellite.h
epsiln.o fk4fk5.o kepler.o kfile.o nutate.o precess.o : satellite.h
refrac.o rplanet.o rstar.o sidrlt.o sun.o trnsit.o : satellite.h
oearth.o manoms.o ojupiter.o omars.o omercury.o : satellite.h
oneptune.o osaturn.o ouranus.o ovenus.o cnstinit.o : satellite.h
matan2.o : satellite.h

#########
# Rules #
#########

#	rule to build the almanac program

almanac : aa.o $(CFILES)
	make getfiles
	@echo " "
	$(LD) -o almanac aa.o $(AALIB) -lm
	mv almanac $(BIN)
	@touch almanac
	@rlog -t RCS/*,v > Filelist
	@echo " "
	@rm -f $(OFILES)

#	rule to build the aalib.a library archive

aalib.a : $(OFILES)
	@echo " "
	ar rc $(AALIB) $(OFILES)
	ranlib $(AALIB)
	@echo " "
	@touch aalib

#	get the object files from the library archive

getfiles : $(CFILES)
	@echo " "
	-csh -c "if (!(-e altaz.o) && -e $(AALIB)) ar xo $(AALIB) $(OFILES)"
	@echo " "
	make aalib.a
	@touch getfiles

#	rule to make sure the include files are current

# includes :
#	@echo " "
#	cd $(HPATH); $(MAKE)
#	@echo " "

#	default rule to make .o files from .c files

%.o : %.c
	@echo " "
####	generate code
	$(CC) $(CFLAGS) -ansi -pedantic -c -Wall $*.c

#	misc rules

clean :
	@echo " "
	rm -f $(OFILES) core *.BAK junk crud
