# makefile for Gambit-C system.

# Copyright (c) 1994-2009 by Marc Feeley, All Rights Reserved.

PACKAGE_SHORTNAME = @PACKAGE_SHORTNAME@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_TARNAME = @PACKAGE_TARNAME@

@SET_MAKE@

srcdir = @srcdir@
VPATH = @srcdir@
srcdirpfx = @srcdirpfx@

C_COMPILER = @C_COMPILER_MF@
C_PREPROC = @C_PREPROC_MF@
FLAGS_OBJ = @FLAGS_OBJ_MF@
FLAGS_DYN = @FLAGS_DYN_MF@
FLAGS_LIB = @FLAGS_LIB_MF@
FLAGS_EXE = @FLAGS_EXE_MF@
DEFS = @DEFS@
LIBS = @LIBS@

GAMBCLIB_DEFS = @GAMBCLIB_DEFS_MF@
LIB_PREFIX = @LIB_PREFIX@
LIB_EXTENSION = @LIB_EXTENSION@
GAMBCLIB = @GAMBCLIB@
GAMBCGSCLIB = @GAMBCGSCLIB@
GAMBCGSILIB = @GAMBCGSILIB@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_LIB = @INSTALL_LIB@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
LN_S = @LN_S@
RANLIB = @RANLIB@
RC = @RC@
GIT = @GIT@
HG = @HG@

prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
bindir = @bindir@
docdir = @docdir@
infodir = @infodir@
emacsdir = @emacsdir@
libexecdir = @libexecdir@
datarootdir = @datarootdir@
datadir = @datadir@
htmldir = @htmldir@
dvidir = @dvidir@
pdfdir = @pdfdir@
psdir = @psdir@
localedir = @localedir@
mandir = @mandir@

# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this makefile.
# To change the values of `make' variables: instead of editing makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
#     (which will cause the makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.

MDEFINES = prefix=$(prefix) exec_prefix=$(exec_prefix) \
includedir=$(includedir) libdir=$(libdir) \
bindir=$(bindir) docdir=$(docdir) \
infodir=$(infodir) emacsdir=$(emacsdir)

SUBDIRS = include lib gsi gsc bin misc doc tests examples prebuilt

RCFILES = README INSTALL.txt LICENSE-2.0.txt LGPL.txt \
makefile.in configure configure.ac config.guess config.sub install-sh mkidirs \
relpath

GITRCFILES = .gitignore
HGRCFILES = .hgignore .hgtags

GENDISTFILES =

DISTFILES = $(RCFILES) $(GENDISTFILES)

GITDISTFILES = $(GITRCFILES)
HGDISTFILES = $(HGRCFILES)

.SUFFIXES:

all:

all-pre:

all-post:
	test -f "gsc-comp@exe@" || cp gsc/gsc@exe@ gsc-comp@exe@

fake_target:

doc info pdf html txt: fake_target
	cd doc && $(MAKE) $(MDEFINES) $@

bootstrap: fake_target all
	cp gsc/gsc@exe@ gsc-comp@exe@

check: fake_target all
	cd tests && $(MAKE) $(MDEFINES) $@

examples: fake_target all
	cd examples && $(MAKE) $(MDEFINES) $@

prebuilt: dist dist-devel
	cd prebuilt && $(MAKE) $(MDEFINES) $@

stamp: fake_target
	cd include && $(MAKE) $(MDEFINES) $@

commit: fake_target stamp
	@if test "$(RC)" = "$(GIT)"; then \
	  $(GIT) commit -a; \
	else \
	  $(HG) commit; \
	fi

diff: fake_target
	@$(RC) diff | cat

log: fake_target
	@$(RC) log | cat

status: fake_target
	@$(RC) status || :

push: fake_target
	@if test "$(RC)" = "$(GIT)"; then \
	  $(GIT) push ssh://gambit@public-gambit-repo/~/HTML/repo/gambit.git/; \
	else \
	  $(HG) push; \
	fi

pull: fake_target
	@if test "$(RC)" = "$(GIT)"; then \
	  $(GIT) pull; \
	  $(GIT) fetch --tags; \
	else \
	  $(HG) pull; \
	fi

update-nopull: fake_target
	@if test "$(RC)" = "$(GIT)"; then \
	  next_version=`$(GIT) tag | fgrep -e '-bootstrap' | sed -e 's/v//g' -e 's/-bootstrap.*//g' | sort -r -s -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n | sed 's/^/v/g' | sed -n '/^$(PACKAGE_VERSION)/{n;p;}'`; \
	else \
	  next_version=`$(HG) tags | fgrep -e '-bootstrap' | sed -e 's/v//g' -e 's/-bootstrap.*//g' | sort -r -s -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n | sed 's/^/v/g' | sed -n '/^$(PACKAGE_VERSION)/{n;p;}'`; \
	fi; \
	if test "$$next_version" = ""; then \
	  if test "$(RC)" = "$(GIT)"; then \
	    $(GIT) checkout master; \
	  else \
	    $(HG) checkout; \
	  fi; \
	else \
	  $(RC) checkout $$next_version-bootstrap; \
	  $(MAKE) bootstrap; \
	  $(RC) checkout $$next_version; \
	  $(MAKE) bootclean bootstrap update; \
	fi

update: pull update-nopull
	$(MAKE)

new-major: fake_target
	major=`echo $(PACKAGE_VERSION) | sed -e "s/v//g" -e "s/\.[^.]*\.[^.]*//g"`; \
	next_major=`eval expr 1 + $$major`; \
	next_version=v$$next_major.0.0; \
	$(MAKE) NEW_VERSION=$$next_version change-version

new-minor: fake_target
	major=`echo $(PACKAGE_VERSION) | sed -e "s/v//g" -e "s/\.[^.]*\.[^.]*//g"`; \
	minor=`echo $(PACKAGE_VERSION) | sed -e "s/v[^.]*\.//g" -e "s/\.[^.]*//g"`; \
	next_minor=`eval expr 1 + $$minor`; \
	next_version=v$$major.$$next_minor.0; \
	$(MAKE) NEW_VERSION=$$next_version change-version

new-revision: fake_target
	major=`echo $(PACKAGE_VERSION) | sed -e "s/v//g" -e "s/\.[^.]*\.[^.]*//g"`; \
	minor=`echo $(PACKAGE_VERSION) | sed -e "s/v[^.]*\.//g" -e "s/\.[^.]*//g"`; \
	revision=`echo $(PACKAGE_VERSION) | sed -e "s/v[^.]*\.[^.]*\.//g" -e "s///g"`; \
	next_revision=`eval expr 1 + $$revision`; \
	next_version=v$$major.$$minor.$$next_revision; \
	$(MAKE) NEW_VERSION=$$next_version change-version

change-version: fake_target
	major=`echo $(PACKAGE_VERSION) | sed -e "s/v//g" -e "s/\.[^.]*\.[^.]*//g"`; \
	minor=`echo $(PACKAGE_VERSION) | sed -e "s/v[^.]*\.//g" -e "s/\.[^.]*//g"`; \
	revision=`echo $(PACKAGE_VERSION) | sed -e "s/v[^.]*\.[^.]*\.//g" -e "s///g"`; \
	next_major=`echo $(NEW_VERSION) | sed -e "s/v//g" -e "s/\.[^.]*\.[^.]*//g"`; \
	next_minor=`echo $(NEW_VERSION) | sed -e "s/v[^.]*\.//g" -e "s/\.[^.]*//g"`; \
	next_revision=`echo $(NEW_VERSION) | sed -e "s/v[^.]*\.[^.]*\.//g" -e "s///g"`; \
	version_num=`eval expr "\( 100000 \\* $$major \) + \( 1000 \\* $$minor \) + $$revision"`; \
	new_version_num=`eval expr "\( 100000 \\* $$next_major \) + \( 1000 \\* $$next_minor \) + $$next_revision"`; \
	sed -e "/(define (compiler-version) $$version_num)/s/$$version_num/$$new_version_num/" gsc/_parms.scm > gsc/_parms.scm-new; \
	if ! diff gsc/_parms.scm gsc/_parms.scm-new > /dev/null; then \
	  mv gsc/_parms.scm-new gsc/_parms.scm; \
	  if test "$(RC)" = "$(GIT)"; then \
	    $(GIT) commit -a -m "[COMPILER CHANGES NEEDED FOR $(NEW_VERSION)] Changed version in compiler"; \
	  else \
	    $(HG) commit -m "[COMPILER CHANGES NEEDED FOR $(NEW_VERSION)] Changed version in compiler"; \
	  fi; \
	  $(RC) tag $(NEW_VERSION)-bootstrap; \
	  if $(MAKE) bootstrap; then \
	    misc/changev $$version_num $$new_version_num; \
	    touch doc/gambit-c.txi; \
	    cd tests; @SETDLPATH@ ../gsc/gsc -:~~bin=../bin,~~lib=../lib,~~include=../include -f -c mix.scm; mv mix.c test5.ok; cd ..; \
	    if $(MAKE) bootclean && $(MAKE) -j 2 && $(MAKE) check && $(MAKE) doc; then \
	      if test "$(RC)" = "$(GIT)"; then \
	        $(GIT) commit -a -m "[RUNTIME CHANGES NEEDED FOR $(NEW_VERSION)] Changed version of runtime using misc/changev"; \
	      else \
	        $(HG) commit -m "[RUNTIME CHANGES NEEDED FOR $(NEW_VERSION)] Changed version of runtime using misc/changev"; \
	      fi; \
	      $(RC) tag $(NEW_VERSION); \
	    fi; \
	  fi; \
	else \
	  echo Compiler version in gsc/_parms.scm is inconsistent with PACKAGE_VERSION; \
	fi

release: fake_target
	$(MAKE) bootstrap
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) check
	$(MAKE) doc
	rm -f $(PACKAGE_TARNAME).tgz $(PACKAGE_TARNAME)-*.*
	$(MAKE) prebuilt

publish-release: fake_target
	misc/publish-release $(PACKAGE_VERSION) $(PACKAGE_TARNAME).tgz $(PACKAGE_TARNAME)-*.*

install-pre:
	@if test "@ENABLE_SHARED@" = "yes" -a "@ENABLE_ABSOLUTE_SHARED_LIBS@" = "yes" -a "$(DESTDIR)" != ""; then \
	  echo "*** The use of --enable-shared and --enable-absolute-shared-libs is"; \
	  echo "*** incompatible with the use of DESTDIR.  You can either specify an"; \
	  echo "*** empty DESTDIR or reconfigure with --disable-absolute-shared-libs."; \
	  exit 1; \
	fi

install-post: all
	if test "@ENABLE_MULTIPLE_VERSIONS@" = "yes"; then \
	  if test "@bat@" = ""; then \
	    $(srcdirpfx)./mkidirs $(DESTDIR)$(prefix); \
	    rm -f $(DESTDIR)$(prefix)/../current \
	      $(DESTDIR)$(prefix)/../current.lnk; \
	    (cd $(DESTDIR)$(prefix)/.. && $(LN_S) $(PACKAGE_VERSION) current); \
	  fi; \
	fi

uninstall-pre:

uninstall-post:
	if test "@ENABLE_MULTIPLE_VERSIONS@" = "yes"; then \
	  if test "@bat@" = ""; then \
	    (cd $(DESTDIR)$(prefix)/.. && \
	     rm -f current && \
	     rmdir $(PACKAGE_VERSION)); \
	  fi; \
	fi

mostlyclean-pre:

mostlyclean-post:

clean-pre: mostlyclean-pre

clean-post: mostlyclean-post

distclean-pre: clean-pre

distclean-post: clean-post

bootclean-pre: distclean-pre

bootclean-post: distclean-post

realclean-pre: bootclean-pre

realclean-post: bootclean-post
	rm -f config.log config.status makefile

rc-setup-pre:
	$(RC) init
	@if test "$(RC)" = "$(GIT)"; then \
	  $(GIT) add $(RCFILES) $(GITRCFILES); \
	  rm -f .git/config; \
	  echo '[core]' >> .git/config; \
	  echo '	repositoryformatversion = 0' >> .git/config; \
	  echo '	fileMode = false' >> .git/config; \
	  echo '	bare = false' >> .git/config; \
	  echo '	logallrefupdates = true' >> .git/config; \
	  echo '	ignorecase = true' >> .git/config; \
	  echo '	autocrlf = false' >> .git/config; \
	  echo '[remote "origin"]' >> .git/config; \
	  echo '	url = http://www.iro.umontreal.ca/~gambit/repo/gambit.git/' >> .git/config; \
	  echo '	fetch = +refs/heads/*:refs/remotes/origin/*' >> .git/config; \
	  echo '[branch "master"]' >> .git/config; \
	  echo '	remote = origin' >> .git/config; \
	  echo '	merge = refs/heads/master' >> .git/config; \
	else \
	  $(HG) add $(RCFILES) $(HGRCFILES); \
	  rm -f .hg/hgrc; \
	  echo "[paths]" > .hg/hgrc; \
	  echo "default-push = ssh://gambit@public-gambit-repo/HTML/repo/gambit" >> .hg/hgrc; \
	  echo "default = http://www.iro.umontreal.ca/~gambit/repo/gambit/" >> .hg/hgrc; \
	fi

rc-setup-post:
	@if test "$(RC)" = "$(GIT)"; then \
	  $(GIT) commit -a -m "Initial commit of $(PACKAGE_STRING)"; \
	else \
	  $(HG) commit -m "Initial commit of $(PACKAGE_STRING)"; \
	fi

dist-pre:
	rm -rf $(PACKAGE_TARNAME)
	mkdir $(PACKAGE_TARNAME)
	chmod 777 $(PACKAGE_TARNAME)
	@echo "  Copying distribution files:"
	@for file in $(DISTFILES); do \
	  echo "    $$file"; \
	  ln $(srcdirpfx)$$file $(PACKAGE_TARNAME) 2> /dev/null \
	    || cp -p $(srcdirpfx)$$file $(PACKAGE_TARNAME); \
	done

dist-post:
	tar chof $(PACKAGE_TARNAME).tar $(PACKAGE_TARNAME)
	gzip -9 $(PACKAGE_TARNAME).tar
	mv $(PACKAGE_TARNAME).tar.gz $(PACKAGE_TARNAME).tgz
	rm -rf $(PACKAGE_TARNAME)

dist-devel-pre:
	rm -rf $(PACKAGE_TARNAME)
	mkdir $(PACKAGE_TARNAME)
	chmod 777 $(PACKAGE_TARNAME)
	@echo "  Copying distribution files:"
	@for file in $(DISTFILES); do \
	  echo "    $$file"; \
	  ln $(srcdirpfx)$$file $(PACKAGE_TARNAME) 2> /dev/null \
	    || cp -p $(srcdirpfx)$$file $(PACKAGE_TARNAME); \
	done
	@if test "$(RC)" = "$(GIT)"; then \
	  for file in $(GITDISTFILES); do \
	    echo "    $$file"; \
	    ln $(srcdirpfx)$$file $(PACKAGE_TARNAME) 2> /dev/null \
	      || cp -p $(srcdirpfx)$$file $(PACKAGE_TARNAME); \
	  done; \
	  echo "    .git"; \
	  ln $(srcdirpfx).git $(PACKAGE_TARNAME) 2> /dev/null \
	    || cp -p -R $(srcdirpfx).git $(PACKAGE_TARNAME); \
	else \
	  for file in $(HGDISTFILES); do \
	    echo "    $$file"; \
	    ln $(srcdirpfx)$$file $(PACKAGE_TARNAME) 2> /dev/null \
	      || cp -p $(srcdirpfx)$$file $(PACKAGE_TARNAME); \
	  done; \
	  echo "    .hg"; \
	  ln $(srcdirpfx).hg $(PACKAGE_TARNAME) 2> /dev/null \
	    || cp -p -R $(srcdirpfx).hg $(PACKAGE_TARNAME); \
	fi

dist-devel-post:
	rm -rf $(PACKAGE_TARNAME)-devel
	mv $(PACKAGE_TARNAME) $(PACKAGE_TARNAME)-devel
	tar chof $(PACKAGE_TARNAME)-devel.tar $(PACKAGE_TARNAME)-devel
	gzip -9 $(PACKAGE_TARNAME)-devel.tar
	mv $(PACKAGE_TARNAME)-devel.tar.gz $(PACKAGE_TARNAME)-devel.tgz
	rm -rf $(PACKAGE_TARNAME)-devel

all-recursive install-recursive uninstall-recursive mostlyclean-recursive clean-recursive distclean-recursive bootclean-recursive realclean-recursive rc-setup-recursive dist-recursive dist-devel-recursive:
	@for subdir in $(SUBDIRS); do \
	  target=`echo $@ | sed 's/-recursive//'`; \
	  echo making $$target in $$subdir; \
	  (cd $$subdir && $(MAKE) $$target) || exit 1; \
	done

all: all-post

all-post: all-recursive

all-recursive: all-pre

install: install-post

install-post: install-recursive

install-recursive: install-pre

uninstall: uninstall-post

uninstall-post: uninstall-recursive

uninstall-recursive: uninstall-pre

mostlyclean: mostlyclean-post

mostlyclean-post: mostlyclean-recursive

mostlyclean-recursive: mostlyclean-pre

clean: clean-post

clean-post: clean-recursive

clean-recursive: clean-pre

distclean: distclean-post

distclean-post: distclean-recursive

distclean-recursive: distclean-pre

bootclean: bootclean-post

bootclean-post: bootclean-recursive

bootclean-recursive: bootclean-pre

realclean: realclean-post

realclean-post: realclean-recursive

realclean-recursive: realclean-pre

rc-setup: rc-setup-post

rc-setup-post: rc-setup-recursive

rc-setup-recursive: rc-setup-pre

dist: dist-post

dist-post: dist-recursive

dist-recursive: dist-pre

dist-devel: dist-devel-post

dist-devel-post: dist-devel-recursive

dist-devel-recursive: dist-devel-pre

# For an explanation of the following makefile rules, see node
# `Automatic Remaking' in GNU Autoconf documentation.

makefile: makefile.in config.status
	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status

config.status: configure
	./config.status --recheck

configure: configure.ac
	cd $(srcdir) && autoconf configure.ac > configure && chmod 755 configure

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT: