# Makefile for all foreign-related libraires

srcdir = @srcdir@
builddir = @builddir@
CC = @CC@

LIBFFI_LOCAL_INCLUDE_ON = -Ilibffi/include
LIBFFI_LOCAL_INCLUDE_OFF =
CFLAGS = @CFLAGS@ @COMPFLAGS@ @PREFLAGS@ @PROFFLAGS@ @OPTIONS@ @MZOPTIONS@ \
         -I$(builddir)/../racket \
         -I$(srcdir)/../racket/include -I$(srcdir)/../racket/src \
         $(LIBFFI_LOCAL_INCLUDE_@OWN_LIBFFI@)
ARFLAGS = @ARFLAGS@
NOOP = :

# compile sub-libraries & foreign.c
all:
	$(MAKE) foreign.@LTO@
	$(MAKE) libffi_@OWN_LIBFFI@

libffi_ON:
	$(MAKE) libffi/libffi@FOREIGN_CONVENIENCE@.la

libffi_OFF:
	$(NOOP)

# just foreign.c, which will generate a stub module:
stub:
	$(MAKE) foreign.@LTO@

# Causes objects to be generated in libffi/src/
#  in inconvenience mode:
libffi/libffi@FOREIGN_CONVENIENCE@.la:
	cd libffi; $(MAKE) libffi@FOREIGN_CONVENIENCE@.la

foreign.@LTO@: $(srcdir)/foreign.c \
           $(srcdir)/../racket/include/scheme.h \
           $(srcdir)/../racket/include/schthread.h \
           $(srcdir)/../racket/src/schemef.h \
           $(srcdir)/../racket/src/stypes.h \
           $(srcdir)/../racket/src/schpriv.h
	$(CC) $(CFLAGS) -c $(srcdir)/foreign.c -o foreign.@LTO@

clean:
	rm -f foreign.@LTO@
	if [ -d libffi ] ; then cd libffi ; $(MAKE) clean ; fi
