# Makefile -- MiNTLib.
# Copyright (C) 1999 Guido Flohr <gufl0000@stud.uni-sb.de>
#
# This file is part of the MiNTLib project, and may only be used
# modified and distributed under the terms of the MiNTLib project
# license, COPYMINT.  By continuing to use, modify, or distribute
# this file you indicate that you have read the license and
# understand and accept it fully.

SHELL = /bin/sh

SUBDIRS = include src startup lib tz

srcdir = .
top_srcdir = .

include $(top_srcdir)/configvars

ifeq ($(WITH_DEBUG_LIB), yes)
  override SUBDIRS += lib_g
endif

ifeq ($(WITH_PROFILE_LIB), yes)
  override SUBDIRS += lib_p
endif

ifeq ($(WITH_SHARED_TEXT), yes)
  ifeq ($(WITH_SHORT_INTS), yes)
    override SUBDIRS += libb lib16 libb16
  else
    override SUBDIRS += libb
  endif
else
 ifeq ($(WITH_SHORT_INTS), yes)
   override SUBDIRS += lib16
 endif
endif

include $(srcdir)/BINFILES
include $(srcdir)/SRCFILES
include $(srcdir)/MISCFILES

default: all

include phony

all: all-here all-recursive

filecheck: filecheck-here filecheck-recursive

filecheck-here:
	checkfiles

all-here:

install: all-here install-recursive zoneswarning

uninstall: uninstall-recursive

install-lib: all install-lib-recursive

install-include: all install-include-recursive

install-man: all install-man-recursive

clean: clean-recursive

bakclean: bakclean-recursive

DISTFILES = $(MISCFILES) $(SRCFILES)
BINDISTFILES = $(MISCFILES) $(BINFILES)

distdir = mintlib-$(VERSION)
bindistdir = $(distdir)-bin
topdistdir = $(distdir)
topbindistdir = $(topdistdir)-bin

dist-check:
	@echo "WARNING: This will take VERY long and will consume"
	@echo "VERY much diskspace!!!"
	@$(MAKE) dist && tar xzf $(distdir).tar.gz && cd $(distdir) \
		&& $(MAKE) && $(MAKE) bin-dist \
		&& echo "##################################################" \
		&& echo "# $(distdir) is ready for distribution." \
		&& echo "##################################################"
	@rm -f $(distdir)

dist: distdir
	-chmod -R a+r $(distdir)
	GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)
	-rm -rf $(distdir)

distdir: $(DISTFILES)
	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \
	  echo "NEWS not updated; not releasing" 1>&2; \
	  exit 1; \
	fi
	@if test $(LOCALTIME) != "Factory"; then \
	  echo "Wake up Guido, reset LOCALTIME; not releasing" 1>&2; \
	  exit 1; \
	fi
	@if test $(POSIXRULES) != "America/New_York"; then \
	  echo "Wake up Guido, reset POSIXRULES; not releasing" 1>&2; \
	  exit 1; \
	fi
	-rm -rf $(distdir)
	mkdir $(distdir)
	-chmod 777 $(distdir)
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  test -f $(distdir)/$$file \
	  || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	  || cp -p -r $$d/$$file $(distdir)/$$file; \
	done
	for subdir in $(SUBDIRS); do \
	  test -d $(distdir)/$$subdir \
	  || mkdir $(distdir)/$$subdir \
	  || exit 1; \
	  chmod 777 $(distdir)/$$subdir; \
	  (cd $$subdir && $(MAKE) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \
	    || exit 1; \
	done

bin-dist: bindistdir
	-chmod -R a+r $(bindistdir)
	GZIP=$(GZIP) $(TAR) chozf $(bindistdir).tar.gz $(bindistdir)
	-rm -rf $(bindistdir)

bindistdir: $(BINDISTFILES)
	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \
	  echo "NEWS not updated; not releasing" 1>&2; \
	  exit 1; \
	fi
	-rm -rf $(bindistdir)
	mkdir $(bindistdir)
	-chmod 777 $(bindistdir)
	@for file in $(BINDISTFILES); do \
	  d=$(srcdir); \
	  test -f $(bindistdir)/$$file \
	  || ln $$d/$$file $(bindistdir)/$$file 2> /dev/null \
	  || cp -p -r $$d/$$file $(bindistdir)/$$file; \
	done
	for subdir in $(SUBDIRS); do \
	  test "$$subdir" = "src" && continue; \
	  (cd $$subdir && $(MAKE) top_distdir=../$(bindistdir) binbasedir=../$(bindistdir) bindistdir) \
	    || exit 1; \
	done

all-recursive clean-recursive bakclean-recursive filecheck-recursive \
install-recursive uninstall-recursive install-lib-recursive \
install-include-recursive install-man-recursive uninstall-lib-recursive \
uninstall-include-recursive uninstall-man-recursive dist-recursive \
bindist-recursive:
	@set fnord $(MAKEFLAGS); amf=$$2; \
	list='$(SUBDIRS)'; for subdir in $$list; do \
	  target=`echo $@ | sed s/-recursive//`; \
	  echo "Making $$target in $$subdir"; \
	  (cd $$subdir && $(MAKE) $$target) \
	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"

help:
	@echo "This Makefile (and most of the Makefiles in the subdirectories)"
	@echo "supports the following main targets:"
	@echo 
	@echo "     help         show this help page (toplevel Makefile only)"
	@echo "     all          build everyting (default)"
	@echo "     install      install everything"
	@echo "     uninstall    uninstall all files"
	@echo "     zonenames    list possible values for time zone"
	@echo 
	@echo "The following targets are intended for use by the"
	@echo "maintainer:"
	@echo 
	@echo "     dist         make a source distribution (toplevel Makefile"
	@echo "                  only)"
	@echo "     bin-dist     make a binary distribution (toplevel Makefile"
	@echo "                  only)"
	@echo "     filecheck    some consistency checks that should be run"
	@echo "                  before making distributions"
	@echo
	@echo "Please read the file INSTALL before running make.  Edit"
	@echo "the file configvars so that it matches the needs of "
	@echo "your site."

zonenames:
	cd $(top_srcdir)/tz && $(MAKE) zonenames

zoneswarning:
	@if test $(LOCALTIME) = Factory; then \
	  echo "WARNING: Installed tz database with localtime set to" ;\
	  echo "dummy time zone \`Factory'.  Run \`zic -l' with the" ;\
	  echo "correct timezone later or re-install after editing" ;\
	  echo "the \`LOCALTIME' variable in \`$(top_srcdir)/configvars." ;\
	fi
	@if test $(POSIXRULES) = Factory; then \
	  echo "WARNING: Installed tz database with posixrules set to" ;\
	  echo "dummy time zone \`Factory'.  Run \`zic -p' with the" ;\
	  echo "correct timezone later or re-install after editing" ;\
	  echo "the \`POSIXRULES' variable in \`$(top_srcdir)/configvars." ;\
	fi

