OS=__$(shell uname)
BUILD=.

# Make.inc should be a symbolic link to wherever gpklib put it.
# That's defined in gpklib's make.inc file (as $ROOT).
# Often, that's /usr/local/include/gpklib/make.inc .
INCFILE=make.inc
include $(INCFILE)

LIB_INC=-I$(BUILD)/gpkio -I$(BUILD)
CC=$(CCLIB)


.PRECIOUS: libgpkio.a

OBJS = ATTSSW_read.o FITS_read.o FITS_write.o SIG_read.o	\
	SIG_write.o ascii_read.o ascii_write.o esps_write.o focas_read.o	\
	focas_write.o rbfile.o read.o rw_misc.o read_data.o sphere_write.o	\
	write.o sphere_read.o EST_read.o HTK_read.o HTK_write.o

HDRFILES1 = gpkio.h
HDRFILES2 = rbfile.h rw_misc.h read_data.h

LHDRS=$(HDRFILES2:%=$(BUILD)/gpkio/%)
HEADERS=$(HDRFILES1:%=$(INC)/%) $(HDRFILES2:%=$(INC)/gpkio/%)

.PHONY: all install

all : $(LHDRS) libgpkio.a libgpkio.so


install: $(HEADERS) $(BASE)/lib/libgpkio.a $(BASE)/lib/libgpkio.so

$(BASE)/lib/libgpkio.% : libgpkio.%
	$(INSTALL) libgpkio.$* $(BASE)/lib/libgpkio.$* -m 0444

libgpkio.a	:	libgpkio.a($(OBJS))

libgpkio.so	: libgpkio.a
	rm -rf tmp
	mkdir tmp
	cd tmp; $(AR) x ../libgpkio.a
	$(LDSHARE) -o libgpkio.so  tmp/*.o $(LIBS)

$(INC)/% : %
	$(INSTALL) $* $(INC)/$* -m 0444

$(INC)/gpkio/% : %
	$(INSTALL) $* $(INC)/gpkio/$* -m 0444
gpkio/% : %
	$(INSTALL) $* gpkio/$* -m 0444

$(INC)/gpkio/% : gpk%
	$(INSTALL) gpk$* $(INC)/gpkio/$* -m 0444
gpkio/% : gpk%
	$(INSTALL) gpk$* gpkio/$* -m 0444
	

test_root : test_root.o root.o $(BASE)/lib/libgpkio.a
	$(LD) -o test_root test_root.o root.o $(BASE)/lib/libgpkio.a

$(OBJS) : $(HDRFILES1)
$(OBJS) : $(LHDRS) internals.h
$(OBJS) : $(INC)/gpklib.h $(INC)/gpklib/ieee754.h
$(OBJS) : $(INC)/gpklib/NaN.h $(INC)/gpklib/image.h
$(OBJE) : $(INC)/gpklib/assert.h $(INC)/gpklib/err.h


clean:
	rm *.o *.a *.so
