# $Id$

SUFFIXES = .et .h .pc.in .pc

DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include

AM_CPPFLAGS = $(INCLUDES_roken) $(INCLUDE_openssl_crypto)

if do_roken_rename
ROKEN_RENAME = -DROKEN_RENAME
endif

AM_CFLAGS = $(WFLAGS)

CLANG_FORMAT_STYLE = '{BasedOnStyle: Mozilla, AlwaysBreakAfterReturnType: TopLevelDefinitions, IndentWidth: 4, SortIncludes: false}'

CP	= cp

## set build_HEADERZ to headers that should just be installed in build tree

buildinclude = $(top_builddir)/include

## these aren't detected by automake
LIB_XauReadAuth		= @LIB_XauReadAuth@
LIB_crypt		= @LIB_crypt@
LIB_dbm_firstkey	= @LIB_dbm_firstkey@
LIB_dbopen		= @LIB_dbopen@
LIB_dlopen		= @LIB_dlopen@
LIB_dn_expand		= @LIB_dn_expand@
LIB_el_init		= @LIB_el_init@
LIB_getattr		= @LIB_getattr@
LIB_gethostbyname	= @LIB_gethostbyname@
LIB_getpwent_r		= @LIB_getpwent_r@
LIB_getpwnam_r		= @LIB_getpwnam_r@
LIB_getsockopt		= @LIB_getsockopt@
LIB_odm_initialize	= @LIB_odm_initialize@
LIB_openpty		= @LIB_openpty@
LIB_pidfile		= @LIB_pidfile@
LIB_res_search		= @LIB_res_search@
LIB_setpcred		= @LIB_setpcred@
LIB_setsockopt		= @LIB_setsockopt@
LIB_socket		= @LIB_socket@
LIB_syslog		= @LIB_syslog@
LIB_tgetent		= @LIB_tgetent@
LIB_com_err		= @LIB_com_err@
LIB_door_create		= @LIB_door_create@

LIB_openssl_crypto      = @LIB_openssl_crypto@
INCLUDE_openssl_crypto  = @INCLUDE_openssl_crypto@

INCLUDE_krb4 = @INCLUDE_krb4@
LIB_krb4 = @LIB_krb4@

INCLUDE_openldap = @INCLUDE_openldap@
LIB_openldap = @LIB_openldap@

INCLUDE_readline = @INCLUDE_readline@
LIB_readline = @LIB_readline@

LEXLIB = @LEXLIB@

libexec_heimdaldir = $(libexecdir)/heimdal

install-suid-programs:
	@foo='$(bin_SUIDS)'; \
	for file in $$foo; do \
		x=$(DESTDIR)$(bindir)/$$file; \
		if chown 0:0 $$x && chmod u+s $$x; then :; else \
			echo "*"; \
			echo "* Failed to install $$x setuid root"; \
			echo "*"; \
		fi; \
	done

install-exec-local: install-suid-programs

codesign-all:
	@if [ X"$$CODE_SIGN_IDENTITY" != X ] ; then \
		foo='$(bin_PROGRAMS) $(sbin_PROGRAMS) $(libexec_PROGRAMS)' ; \
		for file in $$foo ; do \
			echo "CODESIGN $$file" ; \
			codesign -f -s "$$CODE_SIGN_IDENTITY" $$file || exit 1 ; \
		done ; \
	fi
	


all-local: codesign-all

install-build-headers:: $(include_HEADERS) $(dist_include_HEADERS) $(nodist_include_HEADERS) $(build_HEADERZ) $(nobase_include_HEADERS) $(noinst_HEADERS)
	@foo='$(include_HEADERS) $(dist_include_HEADERS) $(nodist_include_HEADERS) $(build_HEADERZ) $(noinst_HEADERS)'; \
	for f in $$foo; do \
		f=`basename $$f`; \
		if test -f "$(srcdir)/$$f"; then file="$(srcdir)/$$f"; \
		else file="$$f"; fi; \
		if cmp -s  $$file $(buildinclude)/$$f 2> /dev/null ; then \
		: ; else \
			echo " $(CP) $$file $(buildinclude)/$$f"; \
			$(CP) $$file $(buildinclude)/$$f || true; \
		fi ; \
	done ; \
	foo='$(nobase_include_HEADERS)'; \
	for f in $$foo; do \
		if test -f "$(srcdir)/$$f"; then file="$(srcdir)/$$f"; \
		else file="$$f"; fi; \
		$(mkdir_p) $(buildinclude)/`dirname $$f` ; \
		if cmp -s  $$file $(buildinclude)/$$f 2> /dev/null ; then \
		: ; else \
			echo " $(CP) $$file $(buildinclude)/$$f"; \
			$(CP) $$file $(buildinclude)/$$f; \
		fi ; \
	done

all-local: install-build-headers

check-local::
	@if test '$(CHECK_LOCAL)' = "no-check-local"; then \
	  foo=''; elif test '$(CHECK_LOCAL)'; then \
	  foo='$(CHECK_LOCAL)'; else \
	  foo='$(PROGRAMS)'; fi; \
	  if test "$$foo"; then \
	  failed=0; all=0; \
	  for i in $$foo; do \
	    all=`expr $$all + 1`; \
	    if (./$$i --version && ./$$i --help) > /dev/null 2>&1; then \
	      echo "PASS: $$i"; \
	    else \
	      echo "FAIL: $$i"; \
	      failed=`expr $$failed + 1`; \
	    fi; \
	  done; \
	  if test "$$failed" -eq 0; then \
	    banner="All $$all tests passed"; \
	  else \
	    banner="$$failed of $$all tests failed"; \
	  fi; \
	  dashes=`echo "$$banner" | sed s/./=/g`; \
	  echo "$$dashes"; \
	  echo "$$banner"; \
	  echo "$$dashes"; \
	  test "$$failed" -eq 0 || exit 1; \
	fi

SUFFIXES += .x .z

SUFFIXES += .1 .3 .5 .7 .8 .cat1 .cat3 .cat5 .cat7 .cat8

NROFF_MAN = groff -mandoc -Tascii
#NROFF_MAN = nroff -man
.1.cat1:
	$(NROFF_MAN) $< > $@
.3.cat3:
	$(NROFF_MAN) $< > $@
.5.cat5:
	$(NROFF_MAN) $< > $@
.7.cat7:
	$(NROFF_MAN) $< > $@
.8.cat8:
	$(NROFF_MAN) $< > $@

## MAINTAINERCLEANFILES += 

dist-cat1-mans:
	@foo='$(man1_MANS)'; \
	bar='$(man_MANS)'; \
	for i in $$bar; do \
	case $$i in \
	*.1) foo="$$foo $$i";; \
	esac; done ;\
	for i in $$foo; do \
		x=`echo $$i | sed 's/\.[^.]*$$/.cat1/'`; \
		echo "$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x"; \
		$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x; \
	done

dist-cat3-mans:
	@foo='$(man3_MANS)'; \
	bar='$(man_MANS)'; \
	for i in $$bar; do \
	case $$i in \
	*.3) foo="$$foo $$i";; \
	esac; done ;\
	for i in $$foo; do \
		x=`echo $$i | sed 's/\.[^.]*$$/.cat3/'`; \
		echo "$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x"; \
		$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x; \
	done

dist-cat5-mans:
	@foo='$(man5_MANS)'; \
	bar='$(man_MANS)'; \
	for i in $$bar; do \
	case $$i in \
	*.5) foo="$$foo $$i";; \
	esac; done ;\
	for i in $$foo; do \
		x=`echo $$i | sed 's/\.[^.]*$$/.cat5/'`; \
		echo "$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x"; \
		$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x; \
	done

dist-cat7-mans:
	@foo='$(man7_MANS)'; \
	bar='$(man_MANS)'; \
	for i in $$bar; do \
	case $$i in \
	*.7) foo="$$foo $$i";; \
	esac; done ;\
	for i in $$foo; do \
		x=`echo $$i | sed 's/\.[^.]*$$/.cat7/'`; \
		echo "$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x"; \
		$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x; \
	done

dist-cat8-mans:
	@foo='$(man8_MANS)'; \
	bar='$(man_MANS)'; \
	for i in $$bar; do \
	case $$i in \
	*.8) foo="$$foo $$i";; \
	esac; done ;\
	for i in $$foo; do \
		x=`echo $$i | sed 's/\.[^.]*$$/.cat8/'`; \
		echo "$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x"; \
		$(NROFF_MAN) $(srcdir)/$$i > $(distdir)/$$x; \
	done

dist-hook: dist-cat1-mans dist-cat3-mans dist-cat5-mans dist-cat7-mans dist-cat8-mans

install-cat-mans:
	$(SHELL) $(top_srcdir)/cf/install-catman.sh install "$(INSTALL_DATA)" "$(mkinstalldirs)" "$(srcdir)" "$(DESTDIR)$(mandir)" '$(CATMANEXT)' $(man_MANS) $(man1_MANS) $(man3_MANS) $(man5_MANS) $(man7_MANS) $(man8_MANS)

uninstall-cat-mans:
	$(SHELL) $(top_srcdir)/cf/install-catman.sh uninstall "$(INSTALL_DATA)" "$(mkinstalldirs)" "$(srcdir)" "$(DESTDIR)$(mandir)" '$(CATMANEXT)' $(man_MANS) $(man1_MANS) $(man3_MANS) $(man5_MANS) $(man7_MANS) $(man8_MANS)

install-data-hook: install-cat-mans
uninstall-hook: uninstall-cat-mans


.et.h:
	$(COMPILE_ET) $<
.et.c:
	$(COMPILE_ET) $<

if NO_AFS
LIB_kafs =
else
LIB_kafs = $(top_builddir)/lib/kafs/libkafs.la $(AIX_EXTRA_KAFS)
endif

if KRB5
LIB_krb5 = $(top_builddir)/lib/krb5/libkrb5.la \
	$(top_builddir)/lib/asn1/libasn1.la
LIB_gssapi = $(top_builddir)/lib/gssapi/libgssapi.la
endif

LIB_heimbase = $(top_builddir)/lib/base/libheimbase.la

if DCE
LIB_kdfs = $(top_builddir)/lib/kdfs/libkdfs.la
endif

#
# Useful target for debugging
#

check-valgrind:
	tobjdir=`cd $(top_builddir) && pwd` ; \
	tsrcdir=`cd $(top_srcdir) && pwd` ; \
	env TESTS_ENVIRONMENT="$${tsrcdir}/cf/maybe-valgrind.sh -s $${tsrcdir} -o $${tobjdir}" make check

check-helgrind:
	tobjdir=`cd $(top_builddir) && pwd` ; \
	tsrcdir=`cd $(top_srcdir) && pwd` ; \
	env TESTS_ENVIRONMENT="$${tsrcdir}/cf/maybe-helgrind.sh -s $${tsrcdir} -o $${tobjdir}" make check

#
# Target to please samba build farm, builds distfiles in-tree.
# Will break when automake changes...
#

distdir-in-tree: $(DISTFILES) $(INFO_DEPS)
	list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
	  if test "$$subdir" != .; then \
	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) distdir-in-tree) ; \
	  fi ; \
	done


#silent-rules

heim_verbose = $(heim_verbose_$(V))
heim_verbose_ = $(heim_verbose_$(AM_DEFAULT_VERBOSITY))
heim_verbose_0 = @echo "  GEN    "$@;

if ENABLE_GCOV
AM_CFLAGS += --coverage --no-inline
AM_LDFLAGS = -lgcov
endif
