# -*- Makefile -*-
#
# Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
#     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
#     2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
#     2015, 2016, 2017, 2018, 2019, 2020 Massachusetts Institute of
#     Technology
#
# This file is part of MIT/GNU Scheme.
#
# MIT/GNU Scheme is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# MIT/GNU Scheme is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MIT/GNU Scheme; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301, USA.

# **** BEGIN BOILERPLATE ****

SHELL = @SHELL@

@SET_MAKE@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datarootdir = @datarootdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

DESTDIR =
top_builddir = @top_builddir@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs

# **** END BOILERPLATE ****

# **** Tool configuration ****

MIT_SCHEME_ARCH = @MIT_SCHEME_ARCH@
MIT_SCHEME_VERSION = @MIT_SCHEME_VERSION@
AUXDIR_NAME = @AUXDIR_NAME@
EXE_NAME = mit-scheme-$(MIT_SCHEME_ARCH)-$(MIT_SCHEME_VERSION)
AUXDIR = $(libdir)/$(AUXDIR_NAME)

CC = @CC@
HOST_CC = @HOST_CC@
CCLD = @CCLD@
M4 = $(srcdir)/makegen/m4.sh @M4@
AS = @AS@
TAR = tar
GZIP_ENV = --best
PAXCTL = @PAXCTL@

DEFS = @DEFS@ @SCHEME_DEFS@ -DDEFAULT_LIBRARY_PATH=\"$(AUXDIR)\"
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@ -I. -I$(srcdir)
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
M4_FLAGS = @M4_FLAGS@
AS_FLAGS = @AS_FLAGS@

COMPILE = $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)
LINK = $(CCLD) $(LDFLAGS) -o $@
LINKTMP = $(CCLD) $(LDFLAGS) -o $@.tmp
EXPAND = $(M4) $(M4_FLAGS)
ASSEMBLE = $(AS) $(AS_FLAGS)

# **** File configuration ****

STD_SOURCES = @(write-sources "files-core")@ \
	@(write-sources "files-os-prim")@ \
	@(write-sources "files-unix")@ \
	$(OPTIONAL_SOURCES)
STD_OBJECTS = @(write-objects "files-core")@ \
	@(write-objects "files-os-prim")@ \
	@(write-objects "files-unix")@ \
	$(OPTIONAL_OBJECTS)

GC_HEAD_FILES = @GC_HEAD_FILES@
OPTIONAL_SOURCES = @OPTIONAL_SOURCES@
OPTIONAL_OBJECTS = @OPTIONAL_OBJECTS@

# **** Rules for C back end (part 1, variables) ****

@LIARC_VARS@

# **** Program definitions ****

aux_PROGRAMS = @AUX_PROGRAMS@
aux_LIBS = 
aux_DATA = @AUX_DATA@
EXTRA_PROGRAMS = findprim

scheme_SOURCES = $(STD_SOURCES) usrdef.c $(LIARC_SOURCES)
scheme_OBJECTS = $(STD_OBJECTS) usrdef.o $(LIARC_OBJECTS)
scheme_DEPENDENCIES = 
scheme_LDFLAGS = @SCHEME_LDFLAGS@
scheme_LIBS = $(LIBS)
SCHEME_EXE = scheme

findprim_SOURCES = findprim.c
findprim_OBJECTS = findprim.o
findprim_DEPENDENCIES = 
findprim_LDFLAGS = 
findprim_LIBS = $(LIBS)

ALL_PROGRAMS = $(aux_PROGRAMS) scheme
ALL_LIBS = $(aux_LIBS)
ALL_DATA = $(aux_DATA)

MOSTLYCLEAN_FILES = *.o usrdef.c compinit.c compinit.h cmpauxmd.s \
	$(LIARC_OBJECTS)

CLEAN_FILES = $(ALL_PROGRAMS) $(ALL_LIBS) $(ALL_DATA) $(EXTRA_PROGRAMS)

DISTCLEAN_FILES = Makefile config.h config.cache config.log config.status \
	cmpauxmd.m4 cmpauxmd.c cmpintmd.h makegen-cc \
	cmpintmd-config.h cmpintmd.c liarc-cc liarc-ld

MAINTAINER_CLEAN_FILES = Makefile.in Makefile.deps liarc-vars liarc-rules \
	config.h.in configure TAGS

# **** Implicit rules ****

.SUFFIXES:
.SUFFIXES: .c .o .s .m4

.c.o:
	$(COMPILE) -o $@ -c $<

.m4.s:
	-rm -f $@.tmp
	$(EXPAND) $< > $@.tmp && mv -f $@.tmp $@

.s.o:
	$(ASSEMBLE) -o $@ $<

# **** Main rules ****

all: $(ALL_PROGRAMS) $(ALL_LIBS) $(ALL_DATA)

scheme: $(scheme_OBJECTS) $(scheme_DEPENDENCIES)
	-rm -f $@
	$(LINKTMP) $(scheme_LDFLAGS) $(scheme_OBJECTS) $(scheme_LIBS)
	$(PAXCTL) +m $@.tmp
	mv -f $@.tmp $@

usrdef.c: $(STD_SOURCES) findprim Makefile
	-rm -f $@.tmp
	./findprim $(STD_SOURCES) > $@.tmp && mv -f $@.tmp $@

findprim: $(findprim_OBJECTS) $(findprim_DEPENDENCIES)
	-rm -f $@
	$(HOST_CC) -o $@ $(findprim_LDFLAGS) $(findprim_OBJECTS) \
		$(findprim_LIBS)

findprim.o: findprim.c config.h
	$(HOST_CC) -o $@ $(findprim_CFLAGS) -c findprim.c

gen-nonce: gen-nonce.o
	$(LINK) gen-nonce.o

extract-liarc-decls: extract-liarc-decls.o
	$(LINK) extract-liarc-decls.o

macosx-starter: macosx-starter.o
	$(LINK) macosx-starter.o

tags: TAGS
TAGS:
	./Tags.sh

mostlyclean:
	-rm -f $(MOSTLYCLEAN_FILES)

clean: mostlyclean
	-rm -f $(CLEAN_FILES)

distclean: clean
	-rm -f $(DISTCLEAN_FILES)
	-rm -rf autom4te.cache

maintainer-clean: c-clean distclean
	-rm -f $(MAINTAINER_CLEAN_FILES)
	( cd cmpauxmd && $(MAKE) $@ )

c-clean: clean
	-rm -f $(C_CLEAN_FILES)

install: install-auxPROGRAMS install-auxLIBS install-auxDATA @INSTALL_INCLUDE@
	$(mkinstalldirs) $(DESTDIR)$(bindir)
	$(INSTALL_PROGRAM) scheme $(DESTDIR)$(bindir)/$(EXE_NAME)
	../etc/install-bin-symlinks.sh $(DESTDIR)$(bindir) $(EXE_NAME) $(MIT_SCHEME_ARCH)

install-auxPROGRAMS: $(aux_PROGRAMS)
	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)
	@list='$(aux_PROGRAMS)'; \
	for p in $$list; do \
	    if test -f $$p; then \
		echo "$(INSTALL_PROGRAM) $$p $(DESTDIR)$(AUXDIR)/."; \
		$(INSTALL_PROGRAM) $$p $(DESTDIR)$(AUXDIR)/.; \
	    fi; \
	done

install-auxLIBS: $(aux_LIBS)
	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)/lib
	@list='$(aux_LIBS)'; \
	for p in $$list; do \
	    if test -f $$p; then \
		echo "$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/lib/."; \
		$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/lib/.; \
	    fi; \
	done

install-auxDATA: $(aux_DATA)
	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)
	@list='$(aux_DATA)'; \
	for p in $$list; do \
	    if test -f $$p; then \
		echo "$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/."; \
		$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/.; \
	    fi; \
	done
	$(INSTALL_DATA) pruxffi.h $(DESTDIR)$(AUXDIR)/mit-scheme.h

install-include:
	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)
	$(INSTALL_SCRIPT) liarc-cc $(DESTDIR)$(AUXDIR)/.
	sed -e "s&^SCHEME_EXE=.*&SCHEME_EXE=$(bindir)/$(EXE_NAME)&" < liarc-ld > liarc-ld.install
	$(INSTALL_SCRIPT) liarc-ld.install $(DESTDIR)$(AUXDIR)/liarc-ld
	rm -f liarc-ld.install
	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)/include
	$(INSTALL_DATA) *.h $(DESTDIR)$(AUXDIR)/include/.

.PHONY: default-target
.PHONY: all tags TAGS mostlyclean clean distclean maintainer-clean c-clean
.PHONY: install install-auxPROGRAMS install-auxLIBS install-auxDATA
.PHONY: install-include

# **** File dependencies ****

@(write-dependencies)@

# **** Rules for C back end (part 2, rules) ****

@LIARC_RULES@

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