# @configure_input@ -*- makefile -*-
ifneq ($(CONFIG_MAKEFILE),)
$(error config.Makefile already loaded)
endif
CONFIG_MAKEFILE = loaded
.PHONY: all check initialize clean distclean install always reconfigure big-check

# Note: run our makefiles with GNU make, version 4 or larger.
#       Version 3.81, provided on Mac OS X, has a bug, but you can
#	use "homebrew" to install a modern version under the name "gmake"
ifeq ($(MAKE_VERSION),3.81)
$(error GNU make version $(MAKE_VERSION) is too old)
endif

all:

# clear this environment variable so the ambient system doesn't offer advice to
# our libraries that use autoconf about where to install install things.  The
# first example we encountered is under opensuse leap 42.1, which sets the
# autoconf variable libdir to ${exec_prefix}/lib64 instead of
# ${exec_prefix}/lib.  Our libraries' files are installed in only our private
# directories, so it's safe to ignore such system conventions.
export CONFIG_SITE =

SHELL = /bin/sh

.DELETE_ON_ERROR:

# here we set the variables that "make" uses
CC = @CC@
CXX = @CXX@
FC = @FC@
AR = @AR@
CFLAGS = @CFLAGS@
CPPFLAGS += @CPPFLAGS@
CXXFLAGS = @CXXFLAGS@
FCFLAGS = @FCFLAGS@
LDFLAGS = @LDFLAGS@
OPENMP_CXXFLAGS = @OPENMP_CXXFLAGS@

# here we set the variables that "configure" uses
# this is the only way to add libraries to the linking done by "gdbm", since it doesn't use LDLIBS or LOADLIBES
LIBS = @LIBS@

# Macaulay 2 file system layout definitions, dependent on $(prefix) and PackageName.
#  see http://www.pathname.com/fhs/
#      http://fink.sourceforge.net/doc/packaging/fslayout.php
#      http://cr.yp.to/unix.html, the section on "Filesystem layout"

### Here we set the make-variables that configure uses as make-variables inside configure-variables.
# The user may override only "prefix" and "exec_prefix"
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
docdir = @docdir@

# We assume relative positions of files within the tree are known to the configure script.
# Thus the user should not override these on the "make" command line, but may
# override them on the "configure" command line instead:
pre_prefix = @pre_prefix@
pre_exec_prefix = @pre_exec_prefix@
# we want to ignore the --datarootdir setting, whatever that means, so here we we mention it: @datarootdir@
abs_top_srcdir = @abs_top_srcdir@

INSTALL = @INSTALL@
BUILTLIBPATH = @abs_top_builddir@/usr-host
# this will be a symbolic link installed by libraries/gtest/Makefile:
GTEST_DIR = @abs_top_builddir@/libraries/final/gtest
CPPFLAGS :=									\
	-I@abs_top_srcdir@/include						\
	-I@abs_top_builddir@/include						\
	-I$(BUILTLIBPATH)/include						\
	$(CPPFLAGS)

vpath %.h $(BUILTLIBPATH)/include

# /// @dan move the info about libraries and submodules nearer to the submodules, perhaps in new included makefiles
LDFLAGS :=						\
	-L$(BUILTLIBPATH)/lib				\
	$(LDFLAGS)

vpath %.a $(BUILTLIBPATH)/lib
vpath %.o $(BUILTLIBPATH)/lib
vpath %.so $(BUILTLIBPATH)/lib
export PATH := @abs_top_srcdir@/usr-build/bin:${PATH}
-include @abs_top_srcdir@/usr-build/aclocal-path
-include @abs_top_srcdir@/usr-build/aclocal-path2

# it is a mistake to set PKG_CONFIG_PATH here, because when this makefile calls upon
# "configure", it should find only pre-installed libaries, not libraries installed by
# M2
M2_PKG_CONFIG_PATH := $(BUILTLIBPATH)/lib/pkgconfig:$(PKG_CONFIG_PATH)

ifeq (,$(findstring --no-print-directory,$(word 1,$(MAKEFLAGS))))
MAKEFLAGS += -w
endif

M2_CPPFLAGS += @M2_CPPFLAGS@
ifeq "@GCC@" "yes"
# if it's gcc, we can get stricter warning and error messages
ifneq ($(RELAX),yes)
# but sometimes that's bad, e.g., during configure scripts with loosely written test programs
# -Winline gives too many warning messages

M2_BOTH = -pipe -Wall -Wno-shadow -Wcast-qual -Wno-sign-conversion -Wno-sign-compare

ifeq "@__INTEL_COMPILER@" "yes"
X = -diag-disable 981,869,383,2259,444
CFLAGS += $X
CXXFLAGS += $X
ifeq "@DEBUG@" "yes"
CFLAGS += -debug
CXXFLAGS += -debug
LDFLAGS += -debug
endif
else
M2_BOTH += -Wno-parentheses
M2_BOTH += -Wno-sign-compare 
endif

ifeq "@OPTIMIZE@" "yes"
# gcc 3.3.2 doesn't accept this:
# M2_BOTH += -Werror=uninitialized
M2_BOTH += -Wuninitialized
endif

M2_CFLAGS   += $(M2_BOTH)
M2_CXXFLAGS += $(M2_BOTH)

M2_CFLAGS += @M2_CFLAGS@
M2_CXXFLAGS += @M2_CXXFLAGS@

M2_CXXFLAGS += -Wno-error=pragmas

ifeq "@__INTEL_COMPILER@" "no"
M2_CFLAGS   += -Wimplicit-function-declaration
endif

# -Werror-implicit-function-declaration is important, because if we include the wrong include file and a function that
# returns a 64-bit pointer is not declared as such, then only 32 bits of the return value will be used.
endif
endif
STRIP = @STRIP@
MKDIR_P = @INSTALL@ -d
always:

# pari tends to display plots during its tests, and we don't want that:
export DISPLAY=

# Safe C language:
ifeq "@DEBUG@" "no"
SCCFLAGS += -O
endif
SCC1 = @abs_top_builddir@/Macaulay2/c/scc1

# scc1 output files

ifeq "$(NORULES)" ""

.SUFFIXES : .sig.tmp .sig .dep .d .dd -exports.h.tmp -exports.h -tmp.c -tmp.cc

%.sig: ;	test -e $*.sig && cmp -s $*.sig.tmp $*.sig || cp $*.sig.tmp $*.sig
%-exports.h: ;	test -e $*-exports.h && cmp -s $*-exports.h.tmp $*-exports.h || cp $*-exports.h.tmp $*-exports.h

%.sig.tmp %.dep: %.d
	$(SHOW)SCC1 -dep $*.d
	$(HIDE)$(SCC1) -dep $(SCCFLAGS) $<
	mv $*.dep.tmp $*.dep
	test -e $*.sig && cmp -s $*.sig.tmp $*.sig || cp $*.sig.tmp $*.sig
%.sig.tmp %.dep: %.dd
	$(SHOW)SCC1 -dep $*.dd
	$(HIDE)$(SCC1) -dep $(SCCFLAGS) $<
	mv $*.dep.tmp $*.dep
	test -e $*.sig && cmp -s $*.sig.tmp $*.sig || cp $*.sig.tmp $*.sig
%-tmp.c	 %-exports.h.tmp: %.d
	$(SHOW)SCC1 $*.d
	$(HIDE)$(SCC1) $(SCCFLAGS) $<
	test -e $*-exports.h && cmp -s $*-exports.h.tmp $*-exports.h || cp $*-exports.h.tmp $*-exports.h
%-tmp.cc %-exports.h.tmp: %.dd
	$(SHOW)SCC1 $*.dd
	$(HIDE)$(SCC1) $(SCCFLAGS) $<
	test -e $*-exports.h && cmp -s $*-exports.h.tmp $*-exports.h || cp $*-exports.h.tmp $*-exports.h
%.o: %-tmp.c  %-exports.h
	$(SHOW)CC $*-tmp.c
	$(HIDE)$(COMPILE.c) $(DCFLAGS) $< $(OUTPUT_OPTION)
%.o: %-tmp.cc %-exports.h
	$(SHOW)CXX $*-tmp.cc
	$(HIDE)$(COMPILE.cc) $(DCXXFLAGS) $< $(OUTPUT_OPTION)

# various compiler output files
.SUFFIXES : .ss .ii .s
%.ss: %.s; demangle <$< >$@
%.ii: %.cpp; $(PRE.cc)        $< $(OUTPUT_OPTION)
%.s : %.cpp; $(COMPILE.cc) -S $< $(OUTPUT_OPTION)
%.ii: %.cc; $(PRE.cc)        $< $(OUTPUT_OPTION)
%.s : %.cc; $(COMPILE.cc) -S $< $(OUTPUT_OPTION)
%.ii: %.c; $(PRE.c)        $< $(OUTPUT_OPTION)
%.s : %.c; $(COMPILE.c) -S $< $(OUTPUT_OPTION)

endif

# libgc
export GC_LARGE_ALLOC_WARN_INTERVAL=1

# status info
WHY = @ (if [ -f $@ ] ;						\
	 then echo "=== remaking $@ in $$(basename $$PWD) :" ;	\
	      ls -l $@ | sed 's/^/===   /' || : ;		\
	      ls -l $? | sed 's/^/===   /' ;			\
	 fi)

test:
	: "PKG_CONFIG_PATH    = $(PKG_CONFIG_PATH)"
	: "M2_PKG_CONFIG_PATH = $(M2_PKG_CONFIG_PATH)"
	:
	: "M2_CXXFLAGS           = $(M2_CXXFLAGS)"
	: "M2_BOTH               = $(M2_BOTH)"
	:
	: "M2_LIBRARIES          = $(M2_LIBRARIES)"

SHOW := $(if $(VERBOSE),@true "",@echo "")
HIDE := $(if $(VERBOSE),,@)

%.o: %.c
	$(SHOW)CC $*.c
	$(HIDE)$(COMPILE.c) $< $(OUTPUT_OPTION)

%.o: %.cc
	$(SHOW)CXX $*.cc
	$(HIDE)$(COMPILE.cc) $< $(OUTPUT_OPTION)

# Local Variables:
# compile-command: "set -x ; make -C $M2BUILDDIR include/config.Makefile DEPENDS=no && make -f $M2BUILDDIR/include/config.Makefile test "
# End:
