# Magic Make File, created by felix and Larus. 
# Made to work with scheme be psilord
# Requires GNU make and makedepend
# Keep these up to date, and worry about *nothing*else*
# One directory per line (for readability)

# The scm_ and c_ prefixes are mandatory because otherwise an ffi.scm and ffi.c
# file will both map to a ffi.o file. In addition, ffi.c would be considered
# a translation of ffi.scm on the way to ffi.o! So, prefx the c files with
# c_ and the scheme files with scm_

# put all of your C files here...
C_SRCS = 
C_OBJS =

# put your scheme toplevel entry point file here
SCM_TOPLEVEL_SRCS = s_test.scm
SCM_TOPLEVEL_XLAT = s_test.c
SCM_TOPLEVEL_OBJS = s_test.o

# put all of your scheme library files here...
SCM_LIBRARY_SRCS =	s_test_utils.scml \
					s_test_integer.scml \
					s_test_rational.scml \
					s_test_float.scml
SCM_LIBRARY_XLAT =	s_test_utils.c \
					s_test_integer.c \
					s_test_rational.c \
					s_test_float.c
SCM_LIBRARY_OBJS =	s_test_utils.o \
					s_test_integer.o \
					s_test_rational.o \
					s_test_float.o

ALL_OBJS = $(C_OBJS) $(SCM_LIBRARY_OBJS) $(SCM_TOPLEVEL_OBJS)

#LIBS = -lm
LIBS = `chicken-config -libs` -lchickengmpffi -lgmp

LINKPATH = -L/usr/local/lib -L.

CC = gcc
CHICKEN = chicken
DEF_FLAGS = -g -Wall
INCLUDEPATH = -I/usr/local/include

CFLAGS = `chicken-config -cflags` $(DEF_FLAGS) $(INCLUDEPATH)

# turn on some debugging in the generated source code
CHICKEN_FLAGS = -debug-level 0 -optimize-level 2 -no-warnings -hygienic
#CHICKEN_FLAGS =

TARGET = de

################################################################################

.SUFFIXES: .scml .scm .c .o

# What a terrible thing to do....
.scml.o:
	$(CC) `$(CHICKEN) $< $(CHICKEN_FLAGS) -output-file $*.c -quiet -explicit-use` $(CFLAGS) -Wno-unused $*.c -c -o $*.o
	rm -f $*.c

.scm.o:
	$(CC) `$(CHICKEN) $< $(CHICKEN_FLAGS) -output-file $*.c -quiet` $(CFLAGS) -Wno-unused $*.c -c -o $*.o
	rm -f $*.c

.c.o:
	$(CC) $(CFLAGS) -c $< -o $*.o


all: lib $(TARGET)

$(TARGET):	$(ALL_OBJS)
	$(CC) $(CFLAGS) $(LINKPATH) $(ALL_OBJS) $(LIBS) -o $(TARGET)

lib: 
	(cd gmp_ffi; make)
	
clean:
	(cd gmp_ffi; make clean)
	- rm -f $(TARGET) core a.out $(SCM_LIBRARY_XLAT) $(SCM_TOPLEVEL_XLAT) *.o gmon.out STACKTRACE libchickengmpffi.a

lclean:
	(cd gmp_ffi; make clean)
	- rm -f $(TARGET) core a.out $(SCM_LIBRARY_XLAT) $(SCM_TOPLEVEL_XLAT) *.o gmon.out STACKTRACE libchickengmpffi.a

lines:
	wc -l *.scm *.scml *.scmh

# dumb rules to make everything work right. I need a scheme enabled makedepend

s_test.o: s_test.scm
s_test_integer.o: s_test_integer.scml
s_test_rational.o: s_test_rational.scml
s_test_utils.o: s_test_utils.scml



