default: skycalc
help:
	@echo "make options: (default)"

include ../../Makefile.System
HOME	=	$(ROOT)/src/skycalc
BIN	= 	$(HOME)/bin
LIB	=	$(HOME)/lib
SRC	=	$(HOME)/src
MAN	= 	$(HOME)/doc
INC	=	$(HOME)/include
include ../../Makefile.Common

# programs may add their own internal requirements here
FULL_CFLAGS   = $(BASE_CFLAGS)
FULL_CPPFLAGS = $(BASE_CPPFLAGS)
FULL_LDFLAGS  = $(BASE_LDFLAGS)

skycalc: $(DESTLIB)/libskycalc.a
install: $(DESTINC)/skycalc.h $(DESTLIB)/libskycalc.a

all: moondata dusktime sundata

OBJ = 	$(SRC)/time.$(ARCH).o		$(SRC)/geometry.$(ARCH).o \
	$(SRC)/astro.$(ARCH).o		$(SRC)/sun.$(ARCH).o \
	$(SRC)/moon.$(ARCH).o

$(OBJ): $(INC)/skycalc.h $(INC)/skycalc_internal.h

$(LIB)/libskycalc.$(ARCH).a: $(OBJ)
	@if [ ! -d $(LIB) ]; then mkdir -p $(LIB); fi
	rm -f $(LIB)/libskycalc.$(ARCH).a
	ar rcv $(LIB)/libskycalc.$(ARCH).a $(OBJ)
	$(RANLIB) $(LIB)/libskycalc.$(ARCH).a

$(DESTLIB)/libskycalc.a: $(LIB)/libskycalc.$(ARCH).a 
	@if [ ! -d $(DESTLIB) ]; then mkdir -p $(DESTLIB); fi
	rm -f  $(DESTLIB)/libskycalc.a
	cp $(LIB)/libskycalc.$(ARCH).a $(DESTLIB)/libskycalc.a

$(DESTINC)/skycalc.h: $(INC)/skycalc.h
	@if [ ! -d $(DESTINC) ]; then mkdir -p $(DESTINC); fi
	rm -f $(DESTINC)/skycalc.h
	cp $(INC)/skycalc.h $(DESTINC)/

test:
	$(CC) $(CCFLAGS) -g -o skylib $(SRC)/skylib.c -lskycalc -lm

dusktime: skycalc
	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
	$(CC) $(CCFLAGS) -g -o $(BIN)/dusktime.$(ARCH) $(SRC)/dusktime.c -lskycalc -lm -lohana
	cp $(BIN)/dusktime.$(ARCH) $(DESTBIN)/dusktime

moondata: skycalc
	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
	$(CC) $(CCFLAGS) -g -o $(BIN)/moondata.$(ARCH) $(SRC)/moondata.c -lskycalc -lm -lohana
	cp $(BIN)/moondata.$(ARCH) $(DESTBIN)/moondata

sundata: skycalc
	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
	$(CC) $(CCFLAGS) -g -o $(BIN)/sundata.$(ARCH) $(SRC)/sundata.c -lskycalc -lm -lohana
	cp $(BIN)/sundata.$(ARCH) $(DESTBIN)/sundata

clean:	
	rm -f `find . -name "*.o"`
	rm -f `find . -name "*.a"`
	rm -f `find . -name "*~"`
	rm -f `find . -name "#*"`

.SUFFIXES: .$(ARCH).o

.c.$(ARCH).o:
	$(CC) $(CFLAGS) -c $<

