default: install
help:
	@echo "make options: install libdvo clean dist"

include ../../Makefile.System
HOME 	=	$(ROOT)/src/libdvo
AUTO	=	$(ROOT)/src/libautocode
LIB	= 	$(HOME)/lib
SRC	=	$(HOME)/src
MAN	=	$(HOME)/doc
INC	=	$(HOME)/include
ASRC	=	$(AUTO)/src
AINC	=	$(AUTO)/include
ADEF	=	$(AUTO)/def
include ../../Makefile.Common

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

default: install
install: $(DESTLIB)/libdvo.a $(DESTLIB)/libdvo.$(DLLTYPE)
libdvo: $(LIB)/libdvo.$(ARCH).a $(LIB)/libdvo.$(ARCH).$(DLLTYPE)

DEFS = \
$(DESTINC)/loneos_defs.h \
$(DESTINC)/elixir_defs.h \
$(DESTINC)/panstarrs_dev_0_defs.h \
$(DESTINC)/panstarrs_dev_1_defs.h \
$(DESTINC)/ps1_dev_1_defs.h \
$(DESTINC)/ps1_dev_2_defs.h \
$(DESTINC)/ps1_dev_3_defs.h \
$(DESTINC)/ps1_v1_defs.h \
$(DESTINC)/ps1_ref_defs.h

INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h

OBJS = \
$(SRC)/version.$(ARCH).o	 \
$(SRC)/coordops.$(ARCH).o	 \
$(SRC)/dvosorts.$(ARCH).o	 \
$(SRC)/dvo_photcode_ops.$(ARCH).o \
$(SRC)/LoadPhotcodes.$(ARCH).o   \
$(SRC)/LoadPhotcodesText.$(ARCH).o   \
$(SRC)/LoadPhotcodesFITS.$(ARCH).o   \
$(SRC)/SavePhotcodesText.$(ARCH).o   \
$(SRC)/SavePhotcodesFITS.$(ARCH).o   \
$(SRC)/imreg_datatypes.$(ARCH).o \
$(SRC)/mosaic_astrom.$(ARCH).o   \
$(SRC)/fits_db.$(ARCH).o	 \
$(SRC)/photfits.$(ARCH).o        \
$(SRC)/dvo_image.$(ARCH).o       \
$(SRC)/dvo_image_raw.$(ARCH).o   \
$(SRC)/dvo_catalog.$(ARCH).o     \
$(SRC)/dvo_catalog_raw.$(ARCH).o       \
$(SRC)/dvo_catalog_mef.$(ARCH).o       \
$(SRC)/dvo_catalog_split.$(ARCH).o     \
$(SRC)/dvo_catalog_create.$(ARCH).o    \
$(SRC)/dvo_catalog_chipcoords.$(ARCH).o \
$(SRC)/dvo_convert.$(ARCH).o           \
$(SRC)/dvo_convert_elixir.$(ARCH).o    \
$(SRC)/dvo_convert_loneos.$(ARCH).o    \
$(SRC)/dvo_convert_panstarrs_DEV_0.$(ARCH).o \
$(SRC)/dvo_convert_panstarrs_DEV_1.$(ARCH).o \
$(SRC)/dvo_convert_PS1_DEV_1.$(ARCH).o \
$(SRC)/dvo_convert_PS1_DEV_2.$(ARCH).o \
$(SRC)/dvo_convert_PS1_DEV_3.$(ARCH).o \
$(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
$(SRC)/skyregion_io.$(ARCH).o    \
$(SRC)/skyregion_gsc.$(ARCH).o    \
$(SRC)/skyregion_ops.$(ARCH).o \
$(SRC)/cmf-ps1-v1-alt.$(ARCH).o

# $(SRC)/dvo_convert_panstarrs.$(ARCH).o \
# $(SRC)/dvo_convert_pmtest.$(ARCH).o \

include ../libautocode/Makefile.Targets

$(OBJS): $(INCS)

$(LIB)/libdvo.$(ARCH).a:  $(AOBJS) $(OBJS)
$(LIB)/libdvo.$(ARCH).$(DLLTYPE): $(AOBJS) $(OBJS)

$(DESTLIB)/libdvo.a:  $(LIB)/libdvo.$(ARCH).a
$(DESTLIB)/libdvo.$(DLLTYPE): $(LIB)/libdvo.$(ARCH).$(DLLTYPE)

# dependency rules for the autocode files

$(AOBJS): $(ADEF)/autocode.c $(DESTINC)/autocode.h

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

$(AINC)/autocode.h: $(AINCS) $(ADEF)/autocode.h $(ADEF)/common.h
	@echo "make $@ from $^"
	cd $(AUTO) && make $@

# generic rule for AINCS
$(AINC)/%.h : $(ADEF)/%.d $(ADEF)/autocode.h $(ADEF)/common.h
	@echo "make $@ from $^"
	cd $(AUTO) && make $@

# generic rule for ASRC
$(ASRC)/%.c : $(ADEF)/%.d $(ADEF)/autocode.c $(AINC)/%.h
	@echo "make $@ from $^"
	cd $(AUTO) && make $@

# generic rule for AOBJS
$(ASRC)/%.$(ARCH).o : $(ASRC)/%.c
	@echo "make $@ from $^"
	cd $(AUTO) && make $@

tabletest: install
	gcc -L$(LIBDIR) -I$(INCDIR) -o tabletest $(SRC)/tabletest.c -ldvo -lFITS -lohana -lm

clean: cleandef
cleandef:
	cd $(AUTO) && make clean

.PRECIOUS: $(ASRC)/%.c
