#                       Copyright (c) 2002 by
#                       Advanced Visual Systems Inc.
#                       All Rights Reserved
#
#       This software comprises unpublished confidential information of
#       Advanced Visual Systems Inc. and may not be used, copied or made
#       available to anyone, except in accordance with the license
#       under which it is furnished.
#
#       This file is under Perforce control
#       $Id: //depot/express/fcs70/hdf5/Makefile#1 $
#

include ../include/stddefs.mk

default: subdirs

SRCDIR=$(XP_ROOT)/hdf5

# This is not quite as straightforward as it looks because
# multiple runs of configure will not necessarily touch
# src/H5config.h and the other files it generates.
#
# Also src/H5pubconf.h, src/H5Tinit.c
src/H5config.h: configure Makefile src/H5config.h.in
	CFLAGS="$(G) $(CFLAGS)" FFLAGS="$(FFLAGS)" CXXFLAGS="$(CXXFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
		./configure -C --prefix=$(SRCDIR) --libdir=$(XP_ROOT)/lib/$(MACHINE) \
		--enable-production --disable-trace --disable-stream-vfd \
		--with-zlib=$(XP_ROOT)/tool/zlib,$(XP_ROOT)/lib/$(MACHINE)
	touch src/H5config.h

# gcc -O2 (version 3.2) miscompiles parts of the HDF5 library (H5Spoint.c)
# if -O2 or -O3 is detected, reset optimization level to -O1.
# I'd rather just stick a no-optimize pragma in the relevant source file,
# but gcc doesn't support that.
subdirs: src/H5config.h
	if [ \( $(CC) = gcc \) -a \( \( "$(G)" = "-O2" \) -o \( "$(G)" = "-O3" \) \) ] ; then \
		cd src; $(MAKE) $(MFLAGS) G=-O1; \
	else \
		cd src; $(MAKE) $(MFLAGS); \
	fi
	cd xp_mods; $(MAKE) $(MFLAGS)

clean::
	$(RM) config.status config.cache config.log
	$(RM) -r config
	cd src; $(RM) H5config.h H5pubconf.h libhdf5.settings
	cd src; $(MAKE) clean
	cd xp_mods; $(MAKE) clean

#include $(XP_MACHRULE_PATH)
