# -*- Mode: Makefile; indent-tabs-mode: nil -*-
# vim: set filetype=makefile tabstop=8 shiftwidth=4 expandtab:

#
#			Makefile for ECL core library
#
top_srcdir= @top_srcdir@
srcdir	= @srcdir@
VPATH	= @srcdir@

# Programs used by "make":
#
CC	= @CC@
TRUE_CC = $(CC)
CFLAGS = -Wall -Wno-missing-braces -I. -I@true_builddir@ -I$(srcdir)    \
-I../ecl/ -DECL_BUILD -DECL_API -DECL_NO_LEGACY @CPPFLAGS@ @CFLAGS@     \
@ECL_CFLAGS@ -c

# The following flags could be added and used by GCC
#  -Wall -W -Wfloat-equal -Wundef -Wendif-labels -Wpointer-arith -Wcast-align \
#  -Wwrite-strings -Wconversion -Wsign-compare -Wmissing-prototypes \
#  -Wredundant-decls -Wunreachable-code -Winline

SHELL	= /bin/sh
RM	= @RM@
EXE	= @EXEEXT@
DPP	= ./dpp$(EXE)
RANLIB	= @RANLIB@
AR	= @AR@

# Data for installation
#
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

# Files

HDIR	= ../ecl
HFILES = $(HDIR)/config.h $(HDIR)/ecl.h $(HDIR)/ecl-cmp.h               \
	$(HDIR)/object.h $(HDIR)/cs.h $(HDIR)/stacks.h                  \
	$(HDIR)/external.h $(HDIR)/cons.h $(HDIR)/legacy.h              \
	$(HDIR)/number.h $(HDIR)/page.h
CLOS_OBJS = clos/cache.o clos/accessor.o clos/instance.o clos/gfun.o
OBJS = main.o symbol.o package.o cons.o list.o apply.o eval.o           \
	interpreter.o compiler.o disassembler.o $(CLOS_OBJS)            \
	reference.o character.o file.o read.o print.o error.o           \
	string.o cfun.o reader/parse_integer.o reader/parse_number.o    \
	printer/float_to_digits.o printer/float_to_string.o             \
	printer/integer_to_string.o printer/write_ugly.o                \
	printer/write_object.o printer/write_symbol.o                   \
	printer/write_array.o printer/write_list.o                      \
	printer/write_code.o printer/write_sse.o                        \
	printer/print_unreadable.o ffi/libraries.o ffi/backtrace.o      \
	ffi/mmap.o ffi/cdata.o numbers/cos.o numbers/sin.o              \
	numbers/tan.o numbers/atan.o numbers/cosh.o numbers/sinh.o      \
	numbers/tanh.o numbers/exp.o numbers/expt.o numbers/log.o       \
	numbers/sqrt.o numbers/abs.o numbers/zerop.o numbers/plusp.o    \
	numbers/minusp.o numbers/negate.o numbers/conjugate.o           \
	numbers/one_plus.o numbers/one_minus.o numbers/plus.o           \
	numbers/minus.o numbers/times.o numbers/divide.o                \
	numbers/number_compare.o numbers/number_equalp.o                \
	numbers/minmax.o numbers/floor.o numbers/ceiling.o              \
	numbers/round.o numbers/truncate.o typespec.o assignment.o      \
	predicate.o number.o num_pred.o num_arith.o num_co.o            \
	num_log.o num_rand.o array.o vector_push.o sequence.o           \
	cmpaux.o macros.o backq.o stacks.o time.o unixint.o mapfun.o    \
	multival.o hash.o format.o pathname.o structure.o load.o        \
	unixfsys.o unixsys.o serialize.o ffi.o sse2.o @EXTRA_OBJS@      \
	threads/atomic.o

.SUFFIXES: .c .o .d .s
.PHONY: all

ifndef VERBOSE
.SILENT:
endif

all: $(DPP) ../libeclmin.a ../cinit.o

.d.c: $(DPP)
	if test -f ../CROSS-DPP ; then ../CROSS-DPP $< $@ ; else $(DPP) $< $@ ; fi
.d.o: $(DPP)
	if test -f ../CROSS-DPP ; then ../CROSS-DPP $< $@.c ; else $(DPP) $< $@.c ; fi
	$(CC) -DECLDIR="\"@ecldir@\"" $(CFLAGS) -o $@ $@.c
.c.o: $(HFILES)
	$(CC) -DECLDIR="\"@ecldir@\"" $(CFLAGS) -o $@ $<
# .d.s: $(HFILES)
# 	if test -f ../CROSS-DPP ; then ../CROSS-DPP $< $@.c ; else $(DPP) $< $@.c ; fi
# 	$(CC) -DECLDIR="\"@ecldir@\"" $(CFLAGS) -S -o $@ $@.c

../libeclmin.a: $(OBJS) all_symbols.o all_symbols2.o
	$(RM) $@
	$(AR) cr $@ $(OBJS)
	$(RANLIB) $@

clean:
	$(RM) $(DPP) *.c *.h $(OBJS) all_symbols.o all_symbols2.o ../libecl.a ../cinit.o core a.out tmp.c

# Build rules

$(DPP): $(srcdir)/dpp.c $(srcdir)/symbols_list.h
	if test -f ../CROSS-DPP; then touch dpp; else \
	$(TRUE_CC) -I$(srcdir) -I@true_builddir@ -I./ $(srcdir)/dpp.c @CPPFLAGS@ @CFLAGS@ @ECL_CFLAGS@ -o $@ ; \
	fi

$(OBJS): $(DPP)

#
# This reduces the overhead of jumping to other functions
#
# apply.c: $(DPP)
# apply.o: apply.c $(HFILES)
# 	$(CC) $(CFLAGS) apply.c -o $@

#
# These files are interrelated
#
all_symbols.c: $(DPP)
all_symbols.o: all_symbols.c
	$(CC) $(CFLAGS) -I./ all_symbols.c -o $@
all_symbols2.o: all_symbols.c
	$(CC) $(CFLAGS) -DECL_FINAL -I./ all_symbols.c -o $@

#
# This is in another directory
#
cinit.c: $(DPP)
../cinit.o: cinit.c $(HFILES)
	$(CC) $(CFLAGS) -I./ cinit.c -o $@
