# @configure_input@
############################## main targets
ifneq (@ETAGS@,false)
all: tags
endif
all: scc1 scc-core.o
include ../../include/config.Makefile

# In this directory, we compile "scc1", the D to C translator, which we want to run
# on the "build" machine, in the sense of autoconf.  So we do not want the cross-compiling compiler:
# CC = @ CC_FOR_BUILD @

top_srcdir = @top_srcdir@
VPATH = @srcdir@
############################################
%.c        : %.y
	@YACC@ $(YFLAGS) $^
	mv y.tab.c $*.c
	rm -f y.tab.h y.output
############################################################
YFLAGS := -vdlt

# we don't include @LIBS@ here because including -llapack would make it also
# necessary to link with the fortran support libraries:
LOADLIBES += -lgdbm -lm

CNAMES := scc1.c readfile.c error.c dictionary.c list.c cprint.c type.c chk.c compat.c debugging.c
HFILES := $(CNAMES:.c=.h) scc.h grammar.h keywords.h
OFILES := $(CNAMES:.c=.o) grammar.o
SRCFILES := $(HFILES) $(CNAMES) grammar.y scc-core.h scc-core.c
CPPFLAGS := -I../../include -I/include -I@srcdir@/../../include -I@srcdir@ $(CPPFLAGS)

# we include -Wno-unknown-attributes because libgc incorrectly assumes that clang 6 accepts __attribute__((__alloc_size__(1))):
CFLAGS += -Wall -Wno-unknown-attributes

ifeq "@DEVELOPMENT@" "yes"
CFLAGS +=  -Werror
endif

ifeq "@__INTEL_COMPILER@" "no"
CFLAGS += -Wimplicit-function-declaration
endif
ifeq (@OS@,Linux)
LDFLAGS += -Wl,-rpath,$(BUILTLIBPATH)/lib
endif
LOADLIBES += -lgc

############################## compiling
scc1: $(OFILES) 
	$(CC)  $(LDFLAGS) $(CFLAGS)  $(OFILES) $(LOADLIBES) -o scc1

$(OFILES) : $(HFILES)
grammar.o: grammar.c; $(CC) $(CPPFLAGS) $(CFLAGS) -c $< $(OUTPUT_OPTION)
############################## debugging, and building *.d and *.dd test programs
all:.gdbinit
.gdbinit:.gdbinit.in;cp $^ $@
clean::; rm -f .gdbinit
foo-tmp.c foo.sig.tmp: scc1
# foo-tmp.c : SCCFLAGS += -noarraychks
foo.o : CPPFLAGS += -Wno-unused-function
foo-tmp.c : SCCFLAGS += -noline
foo-tmp.c : SCCFLAGS += -debug
scc-core.o : scc-core.h
foo: scc-core.o | scc1
run-foo:foo;./foo
clean::; rm -f foo 
.SECONDARY:
############################## tags
.PHONY: tags
tags: @srcdir@/TAGS
@srcdir@/TAGS: $(SRCFILES); cd @srcdir@ && @ETAGS@ $(SRCFILES)
wc : $(SRCFILES) ; wc -l $^
############################## cleaning
clean::; rm -f *.o scc1 scc.a grammar.output grammar.tab.h \
		scc.install scc core y.tab.h y.output grammar.c TAGS \
		*-exports.h *-exports.h.tmp *.sig *.sig.tmp typecode.db *.sym *.dep *.log *-tmp.c *.out *.dep.tmp
distclean: clean
	rm -f Makefile @srcdir@/TAGS

Makefile: Makefile.in
	cd ../..; ./config.status Macaulay2/c/Makefile

# Local Variables:
# compile-command: "make -C $M2BUILDDIR/Macaulay2/c "
# End:
.NOTPARALLEL:
