include ./Makefile.common

name = ossim
#bindir = $(prefix)/bin
#datadir = $(prefix)
#docdir = $(datadir)/doc
version = $(OSSIM_VERSION)
OSSIM_ROOT	=	.

default: 
	(cd src; $(MAKE))
	(cd scripts; $(MAKE))


install:
	($(RM) -f $(TOP)/ossim-uninstall)
	($(INSTALL) -d \
		$(INST_BIN) \
		$(INST_LIB) \
		$(INST_LIB)/ossim \
		$(INST_SHARE)\
		$(INST_DOCS) \
		$(INST_TEMPLATES)\
		$(INST_INC) \
		$(INST_INC)/gui \
		$(INST_INC)/ogl)
#	if test "${SED}" != "" ; then \
#		${SED} -e s@${TOP}/src/packages/package_install@${prefix}@g ${TOP}/src/apps/ossim-config > ${prefix}/bin/ossim-config ; \
#		if test "${CHMOD}" != "" ; then \
#			${CHMOD} 755 ${prefix}/bin/ossim-config ; \
#		fi ; \
#	fi ;
	($(INSTALL) COPYING.GPL COPYING.LGPL README.txt $(INST_DOCS))
	(cd src; $(MAKE) install)
	$(INSTALL) src/ossim_core/ossimConfig.h $(INST_INC)/ossimConfig.h
	( cd lib; \
	  for libFile in * ; do \
		if test -f $$libFile ; then \
			echo installing $$libFile ... ; \
		 	cp -d $$libFile $(INST_LIB) ;\
		fi ; \
	  done ; \
	)
	( for bin in bin/* ; do \
		if test -f $$bin -a -x $$bin ; then \
			echo installing $$bin ... ; \
			$(INSTALL_PROGRAM) $$bin $(INST_BIN) ;\
			(echo "$(RM) -f $(prefix)/$$bin"  >> $(TOP)/ossim-uninstall) ; \
		fi ; \
	  done ; \
	)
	( for t in etc/templates/* ; do \
		if test x$$t != "etc/templates/CVS" ; then \
			echo installing $$t ... ; \
			install $$t $(INST_TEMPLATES) ; \
		fi ; \
	  done ; \
	)
	echo "$(RM) -rf $(prefix)/include/ossim"  >> $(TOP)/ossim-uninstall ;
	echo "$(RM) -rf $(prefix)/etc/ossim"  >> $(TOP)/ossim-uninstall ;
	echo "$(RM) -rf $(prefix)/share/ossim*"  >> $(TOP)/ossim-uninstall ;
	echo "$(RM) -rf $(prefix)/share/doc/ossim*"  >> $(TOP)/ossim-uninstall ;
	echo "$(RM) -f $(INST_BIN)/ossim-uninstall"  >> $(TOP)/ossim-uninstall ;
	$(INSTALL_PROGRAM) $(TOP)/ossim-uninstall $(INST_BIN) ;

shared:
	(cd src; $(MAKE) shared) ;

clean:	
	if test "${RM}" != "" ; then \
		for d in `find . -name "*.d"` ; do \
			if ! test -d $$d ; then \
				${RM} -f $$d ; \
			fi ; \
		done ; \
	fi ;
	(cd src; $(MAKE) clean) ;
	(cd lib; $(RM_CMD) *ossim* ; )
	(for d in bin/* ; do \
	    if test -f $$d; then \
		$(RM_CMD)  $$d ; \
	    fi ; \
	done ; \
	) ; 

depends: clean_depends
	(cd src; $(MAKE) depends) ;

clean_depends:
	(cd src; $(MAKE) clean_depends) ;

configure:	configure.in aclocal.m4
	aclocal
	autoconf

all:	default

RPMTOP=${TOP}/../rpmbuild
CYGWINDIST=${TOP}/../cygwin_ossim
DISTTOP=${TOP}/..

gzip-dist:
	cd ${DISTTOP} ; \
	${RM} -rf ${DISTTOP}/${OSSIM_ARCHIVE} ; \
	${RM} -rf ${DISTTOP}/${OSSIM_ARCHIVE_TGZ} ; \
	cp -r ossim ${OSSIM_ARCHIVE} ; \
	${RM} -f ${OSSIM_ARCHIVE}/lib/* ; \
	${RM} -f ${OSSIM_ARCHIVE}/bin/* ; \
	${RM} -rf `find ${DISTTOP}/${OSSIM_ARCHIVE} -name "*.o" -o -name "CVS" -o -name "cvs"` ; \
	cd ${DISTTOP} ; \
	tar cvfz $(OSSIM_ARCHIVE_TGZ) ${OSSIM_ARCHIVE} ;

cygwin-dist: gzip-dist
	@echo "*** Building cygwin-dist ***"
	${RM} -rf ${CYGWINDIST} ; \
	${INSTALL} -d ${CYGWINDIST} ; \
	${INSTALL} -d ${CYGWINDIST}/ossim_install ; \
	cp -f ${DISTTOP}/${OSSIM_ARCHIVE_TGZ} ${CYGWINDIST} ; \
	${RM} -f ${DISTTOP}/${OSSIM_ARCHIVE} ; \
	${RM} -rf ${DISTTOP}/${OSSIM_ARCHIVE}/ossim_install/* ; \
	cd ${CYGWINDIST} ; \
	tar -xvzf $(OSSIM_ARCHIVE_TGZ) ; \
	cd ${CYGWINDIST}/${OSSIM_ARCHIVE} ; \
	./configure --prefix=${CYGWINDIST}/ossim_install --enable-optimization --disable-debug --with-gdalconf="--with-hdf4=/usr/local"; \
	$(MAKE); $(MAKE) install; \
	if test "${SED}" != "" ; then \
		${SED}  -e s@$prefix=.*@prefix=/usr/local@g ${CYGWINDIST}/${OSSIM_ARCHIVE}/src/apps/ossim-config > ${INSTALL_BIN}/ossim-config; \
	fi ; \
	cd ${CYGWINDIST}/ossim_install ; \
	tar cvfz ossim-cygwin-${OSSIM_VERSION}.tgz include bin share etc lib;

rpm: gzip-dist
	@echo "*** Building RPMs ***"
	${INSTALL} -d  $(RPMTOP) \
			$(RPMTOP)/SOURCES \
			$(RPMTOP)/SPECS \
			$(RPMTOP)/BUILD \
			$(RPMTOP)/RPMS \
			$(RPMTOP)/SRPMS ;
	cp -f ${DISTTOP}/$(OSSIM_ARCHIVE_TGZ) $(RPMTOP)/SOURCES
	cp -f ${TOP}/ossim.spec $(RPMTOP)/SPECS
	rpmbuild -ba --define "_topdir ${RPMTOP}" $(RPMTOP)/SPECS/ossim.spec
