# 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 all of your scheme library files here...
SCM_LIBRARY_SRCS =	s_gmp_integer_ffi.scml \
					s_gmp_rational_ffi.scml \
					s_gmp_float_ffi.scml \
					s_gmp_utils_ffi.scml \
					s_gmp_random_ffi.scml \
					s_gmp_main_ffi.scml 
SCM_LIBRARY_XLAT =	s_gmp_integer_ffi.c \
					s_gmp_rational_ffi.c \
					s_gmp_float_ffi.c \
					s_gmp_utils_ffi.c \
					s_gmp_random_ffi.c \
					s_gmp_main_ffi.c 
SCM_LIBRARY_OBJS =	s_gmp_integer_ffi.o \
					s_gmp_rational_ffi.o \
					s_gmp_float_ffi.o \
					s_gmp_utils_ffi.o \
					s_gmp_random_ffi.o \
					s_gmp_main_ffi.o 

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

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

LINKPATH = -L/usr/local/lib

CC = gcc
AR = ar
AR_FLAGS = rs
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 = libchickengmpffi.a

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

.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:	$(TARGET)

$(TARGET):	$(ALL_OBJS)
	$(AR) $(AR_FLAGS) $(TARGET) $(ALL_OBJS)
	cp $(TARGET) ..

clean:
	- rm -f $(TARGET) core a.out $(SCM_LIBRARY_XLAT) $(SCM_TOPLEVEL_XLAT) *.o gmon.out STACKTRACE

lclean:
	- rm -f $(TARGET) core a.out $(SCM_LIBRARY_XLAT) $(SCM_TOPLEVEL_XLAT) *.o gmon.out STACKTRACE

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

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

s_gmp_integer_ffi.o: s_gmp_integer_ffi.scml s_gmp_types_ffi.scmh
s_gmp_rational_ffi.o: s_gmp_rational_ffi.scml s_gmp_types_ffi.scmh
s_gmp_float_ffi.o: s_gmp_float_ffi.scml s_gmp_types_ffi.scmh
s_gmp_random_ffi.o: s_gmp_random_ffi.scml s_gmp_types_ffi.scmh
s_gmp_utils_ffi.o: s_gmp_utils_ffi.scml s_gmp_types_ffi.scmh
s_gmp_main_ffi.o: s_gmp_main_ffi.scml s_gmp_types_ffi.scmh



