thisconfigdir=..
myfulldir=include
mydir=include
LOCAL_SUBDIRS=@maybe_kerberosIV@
BUILDTOP=$(REL)..
KRB5RCTMPDIR= @KRB5_RCTMPDIR@
##DOSBUILDTOP = ..
NO_OUTPRE=1

all-unix:: krb5/krb5.h

all-unix:: maybe-make-db.h-@DB_HEADER_VERSION@

generate-files-mac: krb5/krb5.h

maybe-make-db.h-k5:
	: db.h will be installed by util/db2
maybe-make-db.h-sys:
	: fall back to system db.h 
maybe-make-db.h-redirect:
	test -r db.h || echo '#include <@DB_HEADER@>' > db.h

ET_HEADERS = adm_err.h asn1_err.h kdb5_err.h krb5_err.h
BUILT_HEADERS = osconf.h

all-unix:: autoconf.h $(BUILT_HEADERS)
all-windows:: autoconf.h $(BUILT_HEADERS)

all-unix:: @MAINT@ verify-calling-conventions-krb5

$(srcdir)/autoconf.h.in: @MAINT@ $(srcdir)/autoconf.stmp
$(srcdir)/autoconf.stmp: $(srcdir)/$(thisconfigdir)/configure.in $(SRCTOP)/aclocal.m4
	$(RM) -r $(srcdir)/$(thisconfigdir)/autom4te.cache
	cd $(srcdir)/$(thisconfigdir) && $(AUTOHEADER) --include=$(CONFIG_RELTOPDIR) $(AUTOHEADERFLAGS)
	touch $(srcdir)/autoconf.stmp
	$(RM) -r $(srcdir)/$(thisconfigdir)/autom4te.cache

##DOS##autoconf.h: win-mac.h
##DOS##	$(CP) win-mac.h $@
##DOS##osconf.h: stock\osconf.h
##DOS##	$(CP) stock\osconf.h $@

###############################################################################
##DOS##!if 0
autoconf.h: autoconf.stamp
autoconf.stamp: $(srcdir)/autoconf.h.in $(thisconfigdir)/config.status
	(cd $(thisconfigdir) && $(SHELL) config.status $(mydir)/autoconf.h)
	touch autoconf.stamp

SYSCONFDIR = @sysconfdir@
LOCALSTATEDIR = @localstatedir@
BINDIR = @bindir@
SBINDIR = @sbindir@
LIBDIR  = @libdir@

PROCESS_REPLACE = -e "s+@KRB5RCTMPDIR+$(KRB5RCTMPDIR)+" \
		  -e "s+@PREFIX+$(INSTALL_PREFIX)+" \
		  -e "s+@EXEC_PREFIX+$(INSTALL_EXEC_PREFIX)+" \
		  -e "s+@BINDIR+$(BINDIR)+" \
		  -e "s+@LIBDIR+$(LIBDIR)+" \
		  -e "s+@SBINDIR+$(SBINDIR)+" \
		  -e "s+@MODULEDIR+$(MODULE_DIR)+" \
	-e 's+@LOCALSTATEDIR+$(LOCALSTATEDIR)+' \
	-e 's+@SYSCONFDIR+$(SYSCONFDIR)+' 

OSCONFSRC = $(srcdir)/stock/osconf.h

osconf.h: $(OSCONFSRC) Makefile
	cat $(OSCONFSRC) | sed $(PROCESS_REPLACE) > osconf.new
	@set -x ; if cmp -s osconf.new osconf.h ; then : osconf.h is current ; \
	else ($(RM) osconf.h ; $(CP) osconf.new osconf.h) fi
	$(RM) osconf.new
##DOS##!endif
###############################################################################

krb5/krb5.h: $(srcdir)/krb5/krb5.hin krb5_err.h kdb5_err.h kv5m_err.h krb524_err.h asn1_err.h
	test -d krb5 || mkdir krb5
	if test -r krb5.h; then \
	  if cmp -s krb5.h $(srcdir)/krb5.h; then :; else rm -f krb5.h; fi; \
	else :; fi
	echo "/* This file is generated, please don't edit it directly.  */" > krb5/krb5.h
	echo "#ifndef KRB5_KRB5_H_INCLUDED" >> krb5/krb5.h
	echo "#define KRB5_KRB5_H_INCLUDED" >> krb5/krb5.h
	cat $(srcdir)/krb5/krb5.hin krb5_err.h kdb5_err.h kv5m_err.h krb524_err.h \
		asn1_err.h >> krb5/krb5.h
	echo "#endif /* KRB5_KRB5_H_INCLUDED */" >> krb5/krb5.h

verify-calling-conventions-krb5: private-and-public-decls
	$(PERL) -w $(SRCTOP)/util/def-check.pl private-and-public-decls $(SRCTOP)/lib/krb5_32.def

HEADERS_TO_CHECK = krb5/krb5.h $(srcdir)/k5-int.h $(srcdir)/krb5/preauth_plugin.h

private-and-public-decls: $(HEADERS_TO_CHECK)
	cat $(HEADERS_TO_CHECK) > $@

#
# Build the error table include files:
# asn1_err.h kdb5_err.h krb5_err.h kv5m_err.h krb524_err.h

asn1_err.h kdb5_err.h krb5_err.h kv5m_err.h krb524_err.h: rebuild-error-tables
	: $@
rebuild-error-tables:
	(cd ../lib/krb5/error_tables && $(MAKE) includes)

.PHONY: force rebuild-error-tables
force:

asn1_err.h: $(SRCTOP)/lib/krb5/error_tables/asn1_err.et
kdb5_err.h: $(SRCTOP)/lib/krb5/error_tables/kdb5_err.et
krb5_err.h: $(SRCTOP)/lib/krb5/error_tables/krb5_err.et	
kv5m_err.h: $(SRCTOP)/lib/krb5/error_tables/kv5m_err.et
krb524_err.h: $(SRCTOP)/lib/krb5/error_tables/krb524_err.et

clean-unix::
	$(RM) krb5/krb5.h krb5_err.h kdb5_err.h kv5m_err.h krb524_err.h \
		asn1_err.h
	$(RM) $(ET_HEADERS) autoconf.stamp

clean-windows::
	$(RM) com_err.h profile.h
	$(RM) gssapi\gssapi.h gssapi\gssapi_generic.h gssapi\gssapi_krb5.h gssapi\timestamp
	if exist gssapi\nul rmdir gssapi
	$(RM) osconf.h autoconf.h autoconf.stamp
	@echo Making clean in include

clean::
	$(RM) osconf.new $(BUILT_HEADERS)

install-headers-unix install:: krb5/krb5.h profile.h
	$(INSTALL_DATA) $(srcdir)/krb5.h $(DESTDIR)$(KRB5_INCDIR)$(S)krb5.h
	$(INSTALL_DATA) krb5/krb5.h $(DESTDIR)$(KRB5_INCDIR)$(S)krb5$(S)krb5.h
	$(INSTALL_DATA) $(srcdir)/krb5/locate_plugin.h $(DESTDIR)$(KRB5_INCDIR)$(S)krb5$(S)locate_plugin.h
	$(INSTALL_DATA) profile.h $(DESTDIR)$(KRB5_INCDIR)$(S)profile.h
	$(INSTALL_DATA) $(srcdir)/gssapi.h $(DESTDIR)$(KRB5_INCDIR)$(S)gssapi.h
